fix: convert frontend from submodule reference to normal directory
The frontend directory was incorrectly stored as a git submodule pointer (160000 commit), causing CI checkout to produce an empty directory. This converts it to a regular tracked directory. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
7a84f9e320
commit
c6ba353337
@ -1 +0,0 @@
|
||||
Subproject commit 9239a97721215a14ecac520c21e64d440dd36d98
|
||||
41
edge-ai-platform/frontend/.gitignore
vendored
Normal file
41
edge-ai-platform/frontend/.gitignore
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.*
|
||||
.yarn/*
|
||||
!.yarn/patches
|
||||
!.yarn/plugins
|
||||
!.yarn/releases
|
||||
!.yarn/versions
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# next.js
|
||||
/.next/
|
||||
/out/
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# env files (can opt-in for committing if needed)
|
||||
.env*
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
next-env.d.ts
|
||||
36
edge-ai-platform/frontend/README.md
Normal file
36
edge-ai-platform/frontend/README.md
Normal file
@ -0,0 +1,36 @@
|
||||
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
|
||||
|
||||
## Getting Started
|
||||
|
||||
First, run the development server:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
# or
|
||||
yarn dev
|
||||
# or
|
||||
pnpm dev
|
||||
# or
|
||||
bun dev
|
||||
```
|
||||
|
||||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
||||
|
||||
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
|
||||
|
||||
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
|
||||
|
||||
## Learn More
|
||||
|
||||
To learn more about Next.js, take a look at the following resources:
|
||||
|
||||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
||||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
||||
|
||||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
|
||||
|
||||
## Deploy on Vercel
|
||||
|
||||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
||||
|
||||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
|
||||
23
edge-ai-platform/frontend/components.json
Normal file
23
edge-ai-platform/frontend/components.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"$schema": "https://ui.shadcn.com/schema.json",
|
||||
"style": "new-york",
|
||||
"rsc": true,
|
||||
"tsx": true,
|
||||
"tailwind": {
|
||||
"config": "",
|
||||
"css": "src/app/globals.css",
|
||||
"baseColor": "neutral",
|
||||
"cssVariables": true,
|
||||
"prefix": ""
|
||||
},
|
||||
"iconLibrary": "lucide",
|
||||
"rtl": false,
|
||||
"aliases": {
|
||||
"components": "@/components",
|
||||
"utils": "@/lib/utils",
|
||||
"ui": "@/components/ui",
|
||||
"lib": "@/lib",
|
||||
"hooks": "@/hooks"
|
||||
},
|
||||
"registries": {}
|
||||
}
|
||||
18
edge-ai-platform/frontend/eslint.config.mjs
Normal file
18
edge-ai-platform/frontend/eslint.config.mjs
Normal file
@ -0,0 +1,18 @@
|
||||
import { defineConfig, globalIgnores } from "eslint/config";
|
||||
import nextVitals from "eslint-config-next/core-web-vitals";
|
||||
import nextTs from "eslint-config-next/typescript";
|
||||
|
||||
const eslintConfig = defineConfig([
|
||||
...nextVitals,
|
||||
...nextTs,
|
||||
// Override default ignores of eslint-config-next.
|
||||
globalIgnores([
|
||||
// Default ignores of eslint-config-next:
|
||||
".next/**",
|
||||
"out/**",
|
||||
"build/**",
|
||||
"next-env.d.ts",
|
||||
]),
|
||||
]);
|
||||
|
||||
export default eslintConfig;
|
||||
27
edge-ai-platform/frontend/next.config.ts
Normal file
27
edge-ai-platform/frontend/next.config.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import type { NextConfig } from "next";
|
||||
|
||||
const isDev = process.env.NODE_ENV === "development";
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
...(isDev
|
||||
? {
|
||||
async rewrites() {
|
||||
return [
|
||||
{
|
||||
source: "/api/:path*",
|
||||
destination: "http://localhost:3721/api/:path*",
|
||||
},
|
||||
{
|
||||
source: "/ws/:path*",
|
||||
destination: "http://localhost:3721/ws/:path*",
|
||||
},
|
||||
];
|
||||
},
|
||||
}
|
||||
: {
|
||||
output: "export",
|
||||
trailingSlash: true,
|
||||
}),
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
44
edge-ai-platform/frontend/package.json
Normal file
44
edge-ai-platform/frontend/package.json
Normal file
@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "eslint",
|
||||
"test": "vitest run",
|
||||
"test:watch": "vitest"
|
||||
},
|
||||
"dependencies": {
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"lucide-react": "^0.575.0",
|
||||
"next": "16.1.6",
|
||||
"next-themes": "^0.4.6",
|
||||
"radix-ui": "^1.4.3",
|
||||
"react": "19.2.3",
|
||||
"react-dom": "19.2.3",
|
||||
"recharts": "^3.7.0",
|
||||
"sonner": "^2.0.7",
|
||||
"tailwind-merge": "^3.5.0",
|
||||
"zustand": "^5.0.11"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/postcss": "^4",
|
||||
"@testing-library/jest-dom": "^6.9.1",
|
||||
"@testing-library/react": "^16.3.2",
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^19",
|
||||
"@types/react-dom": "^19",
|
||||
"@vitejs/plugin-react": "^5.1.4",
|
||||
"eslint": "^9",
|
||||
"eslint-config-next": "16.1.6",
|
||||
"jsdom": "^28.1.0",
|
||||
"shadcn": "^3.8.5",
|
||||
"tailwindcss": "^4",
|
||||
"tw-animate-css": "^1.4.0",
|
||||
"typescript": "^5",
|
||||
"vitest": "^4.0.18"
|
||||
}
|
||||
}
|
||||
9467
edge-ai-platform/frontend/pnpm-lock.yaml
generated
Normal file
9467
edge-ai-platform/frontend/pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
3
edge-ai-platform/frontend/pnpm-workspace.yaml
Normal file
3
edge-ai-platform/frontend/pnpm-workspace.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
ignoredBuiltDependencies:
|
||||
- sharp
|
||||
- unrs-resolver
|
||||
7
edge-ai-platform/frontend/postcss.config.mjs
Normal file
7
edge-ai-platform/frontend/postcss.config.mjs
Normal file
@ -0,0 +1,7 @@
|
||||
const config = {
|
||||
plugins: {
|
||||
"@tailwindcss/postcss": {},
|
||||
},
|
||||
};
|
||||
|
||||
export default config;
|
||||
1
edge-ai-platform/frontend/public/file.svg
Normal file
1
edge-ai-platform/frontend/public/file.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>
|
||||
|
After Width: | Height: | Size: 391 B |
1
edge-ai-platform/frontend/public/globe.svg
Normal file
1
edge-ai-platform/frontend/public/globe.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
1
edge-ai-platform/frontend/public/next.svg
Normal file
1
edge-ai-platform/frontend/public/next.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
1
edge-ai-platform/frontend/public/vercel.svg
Normal file
1
edge-ai-platform/frontend/public/vercel.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>
|
||||
|
After Width: | Height: | Size: 128 B |
1
edge-ai-platform/frontend/public/window.svg
Normal file
1
edge-ai-platform/frontend/public/window.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>
|
||||
|
After Width: | Height: | Size: 385 B |
40
edge-ai-platform/frontend/src/app/clusters/page.tsx
Normal file
40
edge-ai-platform/frontend/src/app/clusters/page.tsx
Normal file
@ -0,0 +1,40 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useClusterStore } from '@/stores/cluster-store';
|
||||
import { useDeviceStore } from '@/stores/device-store';
|
||||
import { ClusterList } from '@/components/cluster/cluster-list';
|
||||
import { ClusterCreateDialog } from '@/components/cluster/cluster-create-dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
export default function ClustersPage() {
|
||||
const { t } = useTranslation();
|
||||
const { clusters, loading, fetchClusters } = useClusterStore();
|
||||
const { fetchDevices } = useDeviceStore();
|
||||
const [showCreate, setShowCreate] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
fetchClusters();
|
||||
fetchDevices();
|
||||
}, [fetchClusters, fetchDevices]);
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold">{t('cluster.title')}</h1>
|
||||
<p className="text-muted-foreground">{t('cluster.subtitle')}</p>
|
||||
</div>
|
||||
<Button onClick={() => setShowCreate(true)}>
|
||||
{t('cluster.createCluster')}
|
||||
</Button>
|
||||
</div>
|
||||
<ClusterList clusters={clusters} loading={loading} />
|
||||
<ClusterCreateDialog
|
||||
open={showCreate}
|
||||
onOpenChange={setShowCreate}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,136 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { useResolvedParams } from '@/hooks/use-resolved-params';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { DeviceStatusBadge } from '@/components/devices/device-status';
|
||||
import { FlashDialog } from '@/components/devices/flash-dialog';
|
||||
import { DeviceHealthCard } from '@/components/devices/device-health-card';
|
||||
import { DeviceConnectionLog } from '@/components/devices/device-connection-log';
|
||||
import { DeviceSettingsCard } from '@/components/devices/device-settings-card';
|
||||
import { useDeviceStore } from '@/stores/device-store';
|
||||
import { useDevicePreferencesStore } from '@/stores/device-preferences-store';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
export default function DeviceDetailClient() {
|
||||
const { t } = useTranslation();
|
||||
const { id } = useResolvedParams();
|
||||
const { selectedDevice, fetchDevice, connectDevice, disconnectDevice } = useDeviceStore();
|
||||
const prefs = useDevicePreferencesStore((s) => s.getPreferences(id));
|
||||
|
||||
useEffect(() => {
|
||||
if (id) {
|
||||
fetchDevice(id);
|
||||
}
|
||||
}, [id, fetchDevice]);
|
||||
|
||||
if (!selectedDevice) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="h-8 w-48 animate-pulse rounded bg-muted" />
|
||||
<div className="h-48 animate-pulse rounded-lg border bg-muted" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const isConnected = selectedDevice.status === 'connected' || selectedDevice.status === 'flashing' || selectedDevice.status === 'inferencing';
|
||||
const displayName = prefs.alias || selectedDevice.name;
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center gap-2">
|
||||
<Link href="/devices">
|
||||
<Button variant="ghost" size="sm">{'← ' + t('common.back')}</Button>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div className="flex items-start justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold">{displayName}</h1>
|
||||
{prefs.alias && (
|
||||
<p className="text-sm text-muted-foreground">{selectedDevice.name}</p>
|
||||
)}
|
||||
<DeviceStatusBadge status={selectedDevice.status} />
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
{isConnected ? (
|
||||
<>
|
||||
<FlashDialog deviceId={id} />
|
||||
{selectedDevice.flashedModel && (
|
||||
<Link href={`/workspace/${id}`}>
|
||||
<Button variant="outline">{t('devices.detail.openWorkspace')}</Button>
|
||||
</Link>
|
||||
)}
|
||||
<Button variant="ghost" onClick={() => disconnectDevice(id)}>
|
||||
{t('common.disconnect')}
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<Button onClick={() => connectDevice(id)}>{t('common.connect')}</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Separator />
|
||||
|
||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('devices.detail.deviceInfo')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('devices.detail.id')}</span>
|
||||
<span className="font-mono text-sm">{selectedDevice.id}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('devices.detail.type')}</span>
|
||||
<span>{selectedDevice.type}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('devices.detail.firmware')}</span>
|
||||
<span>{selectedDevice.firmwareVersion || t('common.na')}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('devices.detail.port')}</span>
|
||||
<span className="font-mono text-sm">{selectedDevice.port}</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('devices.detail.modelStatus')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{selectedDevice.flashedModel ? (
|
||||
<div className="space-y-3">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('devices.flashedModel')}</span>
|
||||
<span className="font-medium">{selectedDevice.flashedModel}</span>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('devices.detail.readyForInference')}
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('devices.detail.noModelFlashed')}
|
||||
</p>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<DeviceHealthCard device={selectedDevice} />
|
||||
<DeviceConnectionLog deviceId={id} />
|
||||
</div>
|
||||
|
||||
<DeviceSettingsCard deviceId={id} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
11
edge-ai-platform/frontend/src/app/devices/[id]/page.tsx
Normal file
11
edge-ai-platform/frontend/src/app/devices/[id]/page.tsx
Normal file
@ -0,0 +1,11 @@
|
||||
import DeviceDetailClient from './device-detail-client';
|
||||
|
||||
// Provide a placeholder param for Next.js static export.
|
||||
// Actual routing is handled by Go SPA fallback — all dynamic paths serve index.html.
|
||||
export function generateStaticParams() {
|
||||
return [{ id: '_' }];
|
||||
}
|
||||
|
||||
export default function DeviceDetailPage() {
|
||||
return <DeviceDetailClient />;
|
||||
}
|
||||
36
edge-ai-platform/frontend/src/app/devices/page.tsx
Normal file
36
edge-ai-platform/frontend/src/app/devices/page.tsx
Normal file
@ -0,0 +1,36 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
import { useDeviceStore } from '@/stores/device-store';
|
||||
import { useDeviceEvents } from '@/hooks/use-device-events';
|
||||
import { DeviceList } from '@/components/devices/device-list';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { RefreshCw } from 'lucide-react';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
export default function DevicesPage() {
|
||||
const { t } = useTranslation();
|
||||
const { devices, loading, scanning, fetchDevices, scanDevices } = useDeviceStore();
|
||||
|
||||
useDeviceEvents();
|
||||
|
||||
useEffect(() => {
|
||||
fetchDevices();
|
||||
}, [fetchDevices]);
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold">{t('devices.title')}</h1>
|
||||
<p className="text-muted-foreground">{t('devices.subtitle')}</p>
|
||||
</div>
|
||||
<Button onClick={scanDevices} disabled={scanning} variant="outline">
|
||||
<RefreshCw className={`mr-2 h-4 w-4 ${scanning ? 'animate-spin' : ''}`} />
|
||||
{scanning ? t('devices.scanning') : t('devices.scan')}
|
||||
</Button>
|
||||
</div>
|
||||
<DeviceList devices={devices} loading={loading} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
BIN
edge-ai-platform/frontend/src/app/favicon.ico
Normal file
BIN
edge-ai-platform/frontend/src/app/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
126
edge-ai-platform/frontend/src/app/globals.css
Normal file
126
edge-ai-platform/frontend/src/app/globals.css
Normal file
@ -0,0 +1,126 @@
|
||||
@import "tailwindcss";
|
||||
@import "tw-animate-css";
|
||||
@import "shadcn/tailwind.css";
|
||||
|
||||
@custom-variant dark (&:is(.dark *));
|
||||
|
||||
@theme inline {
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
--font-sans: var(--font-geist-sans);
|
||||
--font-mono: var(--font-geist-mono);
|
||||
--color-sidebar-ring: var(--sidebar-ring);
|
||||
--color-sidebar-border: var(--sidebar-border);
|
||||
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
||||
--color-sidebar-accent: var(--sidebar-accent);
|
||||
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
||||
--color-sidebar-primary: var(--sidebar-primary);
|
||||
--color-sidebar-foreground: var(--sidebar-foreground);
|
||||
--color-sidebar: var(--sidebar);
|
||||
--color-chart-5: var(--chart-5);
|
||||
--color-chart-4: var(--chart-4);
|
||||
--color-chart-3: var(--chart-3);
|
||||
--color-chart-2: var(--chart-2);
|
||||
--color-chart-1: var(--chart-1);
|
||||
--color-ring: var(--ring);
|
||||
--color-input: var(--input);
|
||||
--color-border: var(--border);
|
||||
--color-destructive: var(--destructive);
|
||||
--color-accent-foreground: var(--accent-foreground);
|
||||
--color-accent: var(--accent);
|
||||
--color-muted-foreground: var(--muted-foreground);
|
||||
--color-muted: var(--muted);
|
||||
--color-secondary-foreground: var(--secondary-foreground);
|
||||
--color-secondary: var(--secondary);
|
||||
--color-primary-foreground: var(--primary-foreground);
|
||||
--color-primary: var(--primary);
|
||||
--color-popover-foreground: var(--popover-foreground);
|
||||
--color-popover: var(--popover);
|
||||
--color-card-foreground: var(--card-foreground);
|
||||
--color-card: var(--card);
|
||||
--radius-sm: calc(var(--radius) - 4px);
|
||||
--radius-md: calc(var(--radius) - 2px);
|
||||
--radius-lg: var(--radius);
|
||||
--radius-xl: calc(var(--radius) + 4px);
|
||||
--radius-2xl: calc(var(--radius) + 8px);
|
||||
--radius-3xl: calc(var(--radius) + 12px);
|
||||
--radius-4xl: calc(var(--radius) + 16px);
|
||||
}
|
||||
|
||||
:root {
|
||||
--radius: 0.625rem;
|
||||
--background: oklch(1 0 0);
|
||||
--foreground: oklch(0.145 0 0);
|
||||
--card: oklch(1 0 0);
|
||||
--card-foreground: oklch(0.145 0 0);
|
||||
--popover: oklch(1 0 0);
|
||||
--popover-foreground: oklch(0.145 0 0);
|
||||
--primary: oklch(0.205 0 0);
|
||||
--primary-foreground: oklch(0.985 0 0);
|
||||
--secondary: oklch(0.97 0 0);
|
||||
--secondary-foreground: oklch(0.205 0 0);
|
||||
--muted: oklch(0.97 0 0);
|
||||
--muted-foreground: oklch(0.556 0 0);
|
||||
--accent: oklch(0.97 0 0);
|
||||
--accent-foreground: oklch(0.205 0 0);
|
||||
--destructive: oklch(0.577 0.245 27.325);
|
||||
--border: oklch(0.922 0 0);
|
||||
--input: oklch(0.922 0 0);
|
||||
--ring: oklch(0.708 0 0);
|
||||
--chart-1: oklch(0.646 0.222 41.116);
|
||||
--chart-2: oklch(0.6 0.118 184.704);
|
||||
--chart-3: oklch(0.398 0.07 227.392);
|
||||
--chart-4: oklch(0.828 0.189 84.429);
|
||||
--chart-5: oklch(0.769 0.188 70.08);
|
||||
--sidebar: oklch(0.985 0 0);
|
||||
--sidebar-foreground: oklch(0.145 0 0);
|
||||
--sidebar-primary: oklch(0.205 0 0);
|
||||
--sidebar-primary-foreground: oklch(0.985 0 0);
|
||||
--sidebar-accent: oklch(0.97 0 0);
|
||||
--sidebar-accent-foreground: oklch(0.205 0 0);
|
||||
--sidebar-border: oklch(0.922 0 0);
|
||||
--sidebar-ring: oklch(0.708 0 0);
|
||||
}
|
||||
|
||||
.dark {
|
||||
--background: oklch(0.145 0 0);
|
||||
--foreground: oklch(0.985 0 0);
|
||||
--card: oklch(0.205 0 0);
|
||||
--card-foreground: oklch(0.985 0 0);
|
||||
--popover: oklch(0.205 0 0);
|
||||
--popover-foreground: oklch(0.985 0 0);
|
||||
--primary: oklch(0.922 0 0);
|
||||
--primary-foreground: oklch(0.205 0 0);
|
||||
--secondary: oklch(0.269 0 0);
|
||||
--secondary-foreground: oklch(0.985 0 0);
|
||||
--muted: oklch(0.269 0 0);
|
||||
--muted-foreground: oklch(0.708 0 0);
|
||||
--accent: oklch(0.269 0 0);
|
||||
--accent-foreground: oklch(0.985 0 0);
|
||||
--destructive: oklch(0.704 0.191 22.216);
|
||||
--border: oklch(1 0 0 / 10%);
|
||||
--input: oklch(1 0 0 / 15%);
|
||||
--ring: oklch(0.556 0 0);
|
||||
--chart-1: oklch(0.488 0.243 264.376);
|
||||
--chart-2: oklch(0.696 0.17 162.48);
|
||||
--chart-3: oklch(0.769 0.188 70.08);
|
||||
--chart-4: oklch(0.627 0.265 303.9);
|
||||
--chart-5: oklch(0.645 0.246 16.439);
|
||||
--sidebar: oklch(0.205 0 0);
|
||||
--sidebar-foreground: oklch(0.985 0 0);
|
||||
--sidebar-primary: oklch(0.488 0.243 264.376);
|
||||
--sidebar-primary-foreground: oklch(0.985 0 0);
|
||||
--sidebar-accent: oklch(0.269 0 0);
|
||||
--sidebar-accent-foreground: oklch(0.985 0 0);
|
||||
--sidebar-border: oklch(1 0 0 / 10%);
|
||||
--sidebar-ring: oklch(0.556 0 0);
|
||||
}
|
||||
|
||||
@layer base {
|
||||
* {
|
||||
@apply border-border outline-ring/50;
|
||||
}
|
||||
body {
|
||||
@apply bg-background text-foreground;
|
||||
}
|
||||
}
|
||||
54
edge-ai-platform/frontend/src/app/layout.tsx
Normal file
54
edge-ai-platform/frontend/src/app/layout.tsx
Normal file
@ -0,0 +1,54 @@
|
||||
import type { Metadata } from "next";
|
||||
import { Geist, Geist_Mono } from "next/font/google";
|
||||
import "./globals.css";
|
||||
import { Sidebar } from "@/components/layout/sidebar";
|
||||
import { Header } from "@/components/layout/header";
|
||||
import { Toaster } from "@/components/ui/sonner";
|
||||
import { ThemeSync } from "@/components/theme-sync";
|
||||
import { LangSync } from "@/components/lang-sync";
|
||||
import { StoreHydration } from "@/components/store-hydration";
|
||||
import { RelayTokenSync } from "@/components/relay-token-sync";
|
||||
|
||||
const geistSans = Geist({
|
||||
variable: "--font-geist-sans",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
const geistMono = Geist_Mono({
|
||||
variable: "--font-geist-mono",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Edge AI Platform",
|
||||
description: "Edge AI Development Platform for model deployment and inference",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body
|
||||
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
||||
>
|
||||
<div className="flex h-screen">
|
||||
<Sidebar />
|
||||
<div className="flex flex-1 flex-col overflow-hidden">
|
||||
<Header />
|
||||
<main className="flex-1 overflow-auto p-6">
|
||||
{children}
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
<StoreHydration />
|
||||
<RelayTokenSync />
|
||||
<ThemeSync />
|
||||
<LangSync />
|
||||
<Toaster richColors position="bottom-right" />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
import { useModelStore } from '@/stores/model-store';
|
||||
import { ModelDetail } from '@/components/models/model-detail';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import Link from 'next/link';
|
||||
import { useResolvedParams } from '@/hooks/use-resolved-params';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
export default function ModelDetailClient() {
|
||||
const { id } = useResolvedParams();
|
||||
const { selectedModel, loading, fetchModel } = useModelStore();
|
||||
const { t } = useTranslation();
|
||||
|
||||
useEffect(() => {
|
||||
if (id) {
|
||||
fetchModel(id);
|
||||
}
|
||||
}, [id, fetchModel]);
|
||||
|
||||
if (loading || !selectedModel) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="h-8 w-48 animate-pulse rounded bg-muted" />
|
||||
<div className="h-4 w-96 animate-pulse rounded bg-muted" />
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="h-48 animate-pulse rounded-lg border bg-muted" />
|
||||
<div className="h-48 animate-pulse rounded-lg border bg-muted" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<Link href="/models">
|
||||
<Button variant="ghost" size="sm">
|
||||
{'← ' + t('common.back')}
|
||||
</Button>
|
||||
</Link>
|
||||
<ModelDetail model={selectedModel} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
11
edge-ai-platform/frontend/src/app/models/[id]/page.tsx
Normal file
11
edge-ai-platform/frontend/src/app/models/[id]/page.tsx
Normal file
@ -0,0 +1,11 @@
|
||||
import ModelDetailClient from './model-detail-client';
|
||||
|
||||
// Provide a placeholder param for Next.js static export.
|
||||
// Actual routing is handled by Go SPA fallback — all dynamic paths serve index.html.
|
||||
export function generateStaticParams() {
|
||||
return [{ id: '_' }];
|
||||
}
|
||||
|
||||
export default function ModelDetailPage() {
|
||||
return <ModelDetailClient />;
|
||||
}
|
||||
69
edge-ai-platform/frontend/src/app/models/page.tsx
Normal file
69
edge-ai-platform/frontend/src/app/models/page.tsx
Normal file
@ -0,0 +1,69 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useModelStore } from '@/stores/model-store';
|
||||
import { ModelGrid } from '@/components/models/model-grid';
|
||||
import { ModelFilters } from '@/components/models/model-filters';
|
||||
import { ModelUploadDialog } from '@/components/models/model-upload-dialog';
|
||||
import { ModelComparisonDialog } from '@/components/models/model-comparison-dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
export default function ModelsPage() {
|
||||
const { models, loading, fetchModels, comparisonIds, clearComparison } = useModelStore();
|
||||
const [compareMode, setCompareMode] = useState(false);
|
||||
const [showComparison, setShowComparison] = useState(false);
|
||||
const { t } = useTranslation();
|
||||
|
||||
useEffect(() => {
|
||||
fetchModels();
|
||||
}, [fetchModels]);
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold">{t('models.title')}</h1>
|
||||
<p className="text-muted-foreground">{t('models.subtitle')}</p>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
variant={compareMode ? 'secondary' : 'outline'}
|
||||
onClick={() => {
|
||||
setCompareMode(!compareMode);
|
||||
if (compareMode) clearComparison();
|
||||
}}
|
||||
>
|
||||
{compareMode ? t('models.exitCompare') : t('models.compareModels')}
|
||||
</Button>
|
||||
<ModelUploadDialog />
|
||||
</div>
|
||||
</div>
|
||||
<ModelFilters />
|
||||
<ModelGrid models={models} loading={loading} compareMode={compareMode} />
|
||||
|
||||
{comparisonIds.length > 0 && (
|
||||
<div className="fixed bottom-6 left-1/2 -translate-x-1/2 z-50 flex items-center gap-4 rounded-lg border bg-card px-6 py-3 shadow-lg">
|
||||
<span className="text-sm font-medium">
|
||||
{t('models.comparison.selected', { n: comparisonIds.length })}
|
||||
</span>
|
||||
<Button
|
||||
size="sm"
|
||||
disabled={comparisonIds.length < 2}
|
||||
onClick={() => setShowComparison(true)}
|
||||
>
|
||||
{t('models.comparison.compare')}
|
||||
</Button>
|
||||
<Button size="sm" variant="ghost" onClick={clearComparison}>
|
||||
{t('models.comparison.clear')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<ModelComparisonDialog
|
||||
open={showComparison}
|
||||
onOpenChange={setShowComparison}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
87
edge-ai-platform/frontend/src/app/page.tsx
Normal file
87
edge-ai-platform/frontend/src/app/page.tsx
Normal file
@ -0,0 +1,87 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useModelStore } from '@/stores/model-store';
|
||||
import { useDeviceStore } from '@/stores/device-store';
|
||||
import { useActivityStore } from '@/stores/activity-store';
|
||||
import { StatCard } from '@/components/dashboard/stat-card';
|
||||
import { ActivityTimeline } from '@/components/dashboard/activity-timeline';
|
||||
import { ConnectedDevicesList } from '@/components/dashboard/connected-devices-list';
|
||||
import { Boxes, Cable, Zap, Upload } from 'lucide-react';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
import { OnboardingDialog } from '@/components/onboarding-dialog';
|
||||
|
||||
export default function DashboardPage() {
|
||||
const { t } = useTranslation();
|
||||
const { models, fetchModels } = useModelStore();
|
||||
const { devices, fetchDevices } = useDeviceStore();
|
||||
const activities = useActivityStore((s) => s.activities);
|
||||
|
||||
useEffect(() => {
|
||||
fetchModels();
|
||||
fetchDevices();
|
||||
}, [fetchModels, fetchDevices]);
|
||||
|
||||
const connectedCount = devices.filter(
|
||||
(d) => d.status === 'connected' || d.status === 'flashing' || d.status === 'inferencing',
|
||||
).length;
|
||||
const flashCount = activities.filter((a) => a.type === 'flash_complete').length;
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<OnboardingDialog />
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold">{t('dashboard.title')}</h1>
|
||||
<p className="text-muted-foreground">{t('dashboard.subtitle')}</p>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4">
|
||||
<StatCard title={t('dashboard.models')} value={models.length} icon={Boxes} iconColor="text-blue-600" />
|
||||
<StatCard title={t('dashboard.devices')} value={devices.length} icon={Cable} iconColor="text-purple-600" />
|
||||
<StatCard
|
||||
title={t('dashboard.connected')}
|
||||
value={connectedCount}
|
||||
icon={Cable}
|
||||
iconColor="text-green-600"
|
||||
/>
|
||||
<StatCard title={t('dashboard.flashes')} value={flashCount} icon={Zap} iconColor="text-yellow-600" />
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 gap-6 lg:grid-cols-2">
|
||||
<ConnectedDevicesList />
|
||||
<ActivityTimeline />
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('dashboard.quickActions')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex flex-wrap gap-3">
|
||||
<Link href="/models">
|
||||
<Button variant="outline">
|
||||
<Boxes className="mr-2 h-4 w-4" />
|
||||
{t('dashboard.browseModels')}
|
||||
</Button>
|
||||
</Link>
|
||||
<Link href="/devices">
|
||||
<Button variant="outline">
|
||||
<Cable className="mr-2 h-4 w-4" />
|
||||
{t('dashboard.manageDevices')}
|
||||
</Button>
|
||||
</Link>
|
||||
<Link href="/models">
|
||||
<Button>
|
||||
<Upload className="mr-2 h-4 w-4" />
|
||||
{t('dashboard.uploadModel')}
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
277
edge-ai-platform/frontend/src/app/settings/page.tsx
Normal file
277
edge-ai-platform/frontend/src/app/settings/page.tsx
Normal file
@ -0,0 +1,277 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { useSettingsStore } from '@/stores/settings-store';
|
||||
import { getApiBaseUrl, getWsBaseUrl, getBackendUrl, setBackendUrl, getRelayToken, setRelayToken, fetchAndCacheRelayToken } from '@/lib/constants';
|
||||
import { showSuccess } from '@/lib/toast';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
import { ServerLogViewer } from '@/components/server-log-viewer';
|
||||
import { ServerStatusDashboard } from '@/components/server-status-dashboard';
|
||||
import { api } from '@/lib/api';
|
||||
|
||||
export default function SettingsPage() {
|
||||
const { t } = useTranslation();
|
||||
const { theme, language, setTheme, setLanguage, resetToDefaults } = useSettingsStore();
|
||||
const [backendUrlInput, setBackendUrlInput] = useState('');
|
||||
const [apiUrl, setApiUrl] = useState('');
|
||||
const [wsUrl, setWsUrl] = useState('');
|
||||
const [relayTokenInput, setRelayTokenInput] = useState('');
|
||||
const [detecting, setDetecting] = useState(false);
|
||||
const [updateChecking, setUpdateChecking] = useState(false);
|
||||
const [updateInfo, setUpdateInfo] = useState<{
|
||||
currentVersion: string;
|
||||
latestVersion: string;
|
||||
updateAvailable: boolean;
|
||||
releaseUrl: string;
|
||||
releaseNotes: string;
|
||||
} | null>(null);
|
||||
const [updateError, setUpdateError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
setBackendUrlInput(getBackendUrl());
|
||||
setApiUrl(getApiBaseUrl());
|
||||
setWsUrl(getWsBaseUrl());
|
||||
setRelayTokenInput(getRelayToken());
|
||||
}, []);
|
||||
|
||||
function handleSaveBackendUrl() {
|
||||
setBackendUrl(backendUrlInput);
|
||||
setApiUrl(getApiBaseUrl());
|
||||
setWsUrl(getWsBaseUrl());
|
||||
showSuccess(t('settings.backendUrlSaved'));
|
||||
}
|
||||
|
||||
function handleSaveRelayToken() {
|
||||
setRelayToken(relayTokenInput);
|
||||
showSuccess(t('settings.relayTokenSaved'));
|
||||
}
|
||||
|
||||
async function handleCheckUpdate() {
|
||||
setUpdateChecking(true);
|
||||
setUpdateError(null);
|
||||
try {
|
||||
const result = await api.get<{
|
||||
currentVersion: string;
|
||||
latestVersion: string;
|
||||
updateAvailable: boolean;
|
||||
releaseUrl: string;
|
||||
releaseNotes: string;
|
||||
}>('/system/update-check');
|
||||
if (result.success && result.data) {
|
||||
setUpdateInfo(result.data);
|
||||
if (!result.data.latestVersion && !result.data.updateAvailable) {
|
||||
setUpdateError(t('settings.updateCheck.notConfigured'));
|
||||
}
|
||||
} else {
|
||||
setUpdateError(t('settings.updateCheck.checkFailed'));
|
||||
}
|
||||
} catch {
|
||||
setUpdateError(t('settings.updateCheck.checkFailed'));
|
||||
}
|
||||
setUpdateChecking(false);
|
||||
}
|
||||
|
||||
async function handleDetectRelayToken() {
|
||||
setDetecting(true);
|
||||
// Save old token in case detection fails
|
||||
const oldToken = getRelayToken();
|
||||
setRelayToken(''); // Clear to force re-fetch
|
||||
const token = await fetchAndCacheRelayToken();
|
||||
if (token) {
|
||||
setRelayTokenInput(token);
|
||||
showSuccess(t('settings.relayTokenAutoDetected'));
|
||||
} else {
|
||||
// Restore previous token if detection failed
|
||||
setRelayToken(oldToken);
|
||||
}
|
||||
setDetecting(false);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold">{t('settings.title')}</h1>
|
||||
<p className="text-muted-foreground">{t('settings.subtitle')}</p>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('settings.serverConfig')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label>{t('settings.backendUrl')}</Label>
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
value={backendUrlInput}
|
||||
onChange={(e) => setBackendUrlInput(e.target.value)}
|
||||
placeholder={t('settings.backendUrlPlaceholder')}
|
||||
className="flex-1"
|
||||
/>
|
||||
<Button onClick={handleSaveBackendUrl} size="sm">
|
||||
{t('settings.saveBackendUrl')}
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t('settings.backendUrlHint')}
|
||||
</p>
|
||||
</div>
|
||||
<Separator />
|
||||
<div className="space-y-2">
|
||||
<Label>{t('settings.relayToken')}</Label>
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
value={relayTokenInput}
|
||||
onChange={(e) => setRelayTokenInput(e.target.value)}
|
||||
placeholder={t('settings.relayTokenPlaceholder')}
|
||||
className="flex-1 font-mono text-sm"
|
||||
/>
|
||||
<Button onClick={handleDetectRelayToken} size="sm" variant="outline" disabled={detecting}>
|
||||
{t('settings.relayTokenDetect')}
|
||||
</Button>
|
||||
<Button onClick={handleSaveRelayToken} size="sm">
|
||||
{t('settings.relayTokenSave')}
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t('settings.relayTokenHint')}
|
||||
</p>
|
||||
</div>
|
||||
<Separator />
|
||||
<div className="space-y-2">
|
||||
<Label>{t('settings.apiUrl')}</Label>
|
||||
<Input value={apiUrl} readOnly className="bg-muted" />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>{t('settings.wsUrl')}</Label>
|
||||
<Input value={wsUrl} readOnly className="bg-muted" />
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t('settings.serverNote')}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<ServerStatusDashboard />
|
||||
|
||||
<ServerLogViewer />
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('settings.appearance')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label>{t('settings.theme')}</Label>
|
||||
<Select value={theme} onValueChange={(v) => setTheme(v as 'light' | 'dark')}>
|
||||
<SelectTrigger className="w-48">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="light">{t('settings.themeLight')}</SelectItem>
|
||||
<SelectItem value="dark">{t('settings.themeDark')}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('settings.language')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label>{t('settings.displayLanguage')}</Label>
|
||||
<Select value={language} onValueChange={(v) => setLanguage(v as 'zh-TW' | 'en')}>
|
||||
<SelectTrigger className="w-48">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="zh-TW">{t('settings.languageZhTW')}</SelectItem>
|
||||
<SelectItem value="en">{t('settings.languageEn')}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('settings.about')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<div className="flex justify-between text-sm">
|
||||
<span className="text-muted-foreground">{t('settings.versionLabel')}</span>
|
||||
<span className="font-medium">{updateInfo?.currentVersion || 'v0.1.0'}</span>
|
||||
</div>
|
||||
<div className="flex justify-between text-sm">
|
||||
<span className="text-muted-foreground">{t('settings.platform')}</span>
|
||||
<span className="font-medium">Edge AI Development Platform</span>
|
||||
</div>
|
||||
<Separator />
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-sm font-medium">{t('settings.updateCheck.title')}</span>
|
||||
<Button onClick={handleCheckUpdate} size="sm" variant="outline" disabled={updateChecking}>
|
||||
{updateChecking ? t('settings.updateCheck.checking') : t('settings.updateCheck.checkNow')}
|
||||
</Button>
|
||||
</div>
|
||||
{updateInfo?.updateAvailable && (
|
||||
<div className="rounded-md border border-blue-200 bg-blue-50 p-3 dark:border-blue-800 dark:bg-blue-950">
|
||||
<div className="flex items-center gap-2">
|
||||
<Badge variant="default">{t('settings.updateCheck.updateAvailable')}</Badge>
|
||||
<span className="text-sm font-medium">{updateInfo.latestVersion}</span>
|
||||
</div>
|
||||
{updateInfo.releaseNotes && (
|
||||
<p className="mt-2 text-xs text-muted-foreground line-clamp-3">{updateInfo.releaseNotes}</p>
|
||||
)}
|
||||
{updateInfo.releaseUrl && (
|
||||
<a
|
||||
href={updateInfo.releaseUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="mt-2 inline-block text-sm text-blue-600 hover:underline dark:text-blue-400"
|
||||
>
|
||||
{t('settings.updateCheck.downloadUpdate')} →
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{updateInfo && !updateInfo.updateAvailable && updateInfo.latestVersion && (
|
||||
<p className="text-sm text-muted-foreground">{t('settings.updateCheck.upToDate')}</p>
|
||||
)}
|
||||
{updateError && (
|
||||
<p className="text-sm text-muted-foreground">{updateError}</p>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Separator />
|
||||
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
resetToDefaults();
|
||||
showSuccess(t('settings.resetSuccess'));
|
||||
}}
|
||||
>
|
||||
{t('settings.resetToDefaults')}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
import WorkspaceClient from './workspace-client';
|
||||
|
||||
// Provide a placeholder param for Next.js static export.
|
||||
// Actual routing is handled by Go SPA fallback — all dynamic paths serve index.html.
|
||||
export function generateStaticParams() {
|
||||
return [{ deviceId: '_' }];
|
||||
}
|
||||
|
||||
export default function WorkspacePage() {
|
||||
return <WorkspaceClient />;
|
||||
}
|
||||
@ -0,0 +1,93 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { CameraInferenceView } from '@/components/camera/camera-inference-view';
|
||||
import { InferencePanel } from '@/components/inference/inference-panel';
|
||||
import { useDeviceStore } from '@/stores/device-store';
|
||||
import { useInferenceStore } from '@/stores/inference-store';
|
||||
import { useInferenceStream } from '@/hooks/use-inference-stream';
|
||||
import { useCameraStore } from '@/stores/camera-store';
|
||||
import { useResolvedParams } from '@/hooks/use-resolved-params';
|
||||
import { api } from '@/lib/api';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
export default function WorkspaceClient() {
|
||||
const { t } = useTranslation();
|
||||
const { deviceId } = useResolvedParams();
|
||||
const { selectedDevice, fetchDevice } = useDeviceStore();
|
||||
const { isRunning, setRunning, reset } = useInferenceStore();
|
||||
const { isStreaming, sourceType } = useCameraStore();
|
||||
|
||||
// For image/video mode, inference runs automatically as part of the pipeline
|
||||
const isMediaMode = sourceType === 'image' || sourceType === 'video' || sourceType === 'batch_image';
|
||||
|
||||
// Enable WebSocket stream when inference is running OR when media pipeline is active
|
||||
useInferenceStream(deviceId, isRunning || (isStreaming && isMediaMode));
|
||||
|
||||
// Auto-set isRunning when media upload starts streaming
|
||||
useEffect(() => {
|
||||
if (isStreaming && isMediaMode) {
|
||||
setRunning(true);
|
||||
}
|
||||
}, [isStreaming, isMediaMode, setRunning]);
|
||||
|
||||
const { fetchCameras } = useCameraStore();
|
||||
|
||||
useEffect(() => {
|
||||
if (deviceId) {
|
||||
fetchDevice(deviceId);
|
||||
fetchCameras();
|
||||
}
|
||||
return () => {
|
||||
reset();
|
||||
};
|
||||
}, [deviceId, fetchDevice, fetchCameras, reset]);
|
||||
|
||||
const handleStartInference = async () => {
|
||||
await api.post(`/devices/${deviceId}/inference/start`);
|
||||
setRunning(true);
|
||||
};
|
||||
|
||||
const handleStopInference = async () => {
|
||||
await api.post(`/devices/${deviceId}/inference/stop`);
|
||||
setRunning(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<Link href={`/devices/${deviceId}`}>
|
||||
<Button variant="ghost" size="sm">{'← ' + t('common.back')}</Button>
|
||||
</Link>
|
||||
<h1 className="text-xl font-bold">
|
||||
{t('inference.workspace') + ':'} {selectedDevice?.name || deviceId}
|
||||
</h1>
|
||||
</div>
|
||||
{/* Only show manual inference controls in camera mode */}
|
||||
{!isMediaMode && (
|
||||
<div className="flex gap-2">
|
||||
{isRunning ? (
|
||||
<Button variant="destructive" onClick={handleStopInference}>
|
||||
{t('inference.stopInference')}
|
||||
</Button>
|
||||
) : (
|
||||
<Button onClick={handleStartInference} disabled={!isStreaming}>
|
||||
{t('inference.startInference')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex gap-6">
|
||||
<div className="flex-1">
|
||||
<CameraInferenceView deviceId={deviceId} />
|
||||
</div>
|
||||
<InferencePanel />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,138 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { useClusterStore } from '@/stores/cluster-store';
|
||||
import { useClusterInferenceStream } from '@/hooks/use-cluster-inference-stream';
|
||||
import { ClusterPerformance } from '@/components/cluster/cluster-performance';
|
||||
import { useResolvedParams } from '@/hooks/use-resolved-params';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
export default function ClusterWorkspaceClient() {
|
||||
const { t } = useTranslation();
|
||||
const { clusterId } = useResolvedParams();
|
||||
const {
|
||||
selectedCluster,
|
||||
fetchCluster,
|
||||
inferenceRunning,
|
||||
startInference,
|
||||
stopInference,
|
||||
results,
|
||||
clearResults,
|
||||
} = useClusterStore();
|
||||
|
||||
useClusterInferenceStream(clusterId, inferenceRunning);
|
||||
|
||||
useEffect(() => {
|
||||
if (clusterId) {
|
||||
fetchCluster(clusterId);
|
||||
}
|
||||
return () => {
|
||||
clearResults();
|
||||
};
|
||||
}, [clusterId, fetchCluster, clearResults]);
|
||||
|
||||
const handleStart = async () => {
|
||||
await startInference(clusterId);
|
||||
};
|
||||
|
||||
const handleStop = async () => {
|
||||
await stopInference(clusterId);
|
||||
};
|
||||
|
||||
const latestResult = results.length > 0 ? results[results.length - 1] : null;
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<Link href="/clusters">
|
||||
<Button variant="ghost" size="sm">
|
||||
{'← ' + t('common.back')}
|
||||
</Button>
|
||||
</Link>
|
||||
<h1 className="text-xl font-bold">
|
||||
{t('cluster.workspace')}: {selectedCluster?.name || clusterId}
|
||||
</h1>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
{inferenceRunning ? (
|
||||
<Button variant="destructive" onClick={handleStop}>
|
||||
{t('cluster.stopInference')}
|
||||
</Button>
|
||||
) : (
|
||||
<Button onClick={handleStart}>
|
||||
{t('cluster.startInference')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 gap-6 lg:grid-cols-3">
|
||||
<div className="lg:col-span-2">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{t('inference.details')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{latestResult ? (
|
||||
<div className="space-y-3">
|
||||
<div className="grid grid-cols-3 gap-4 text-sm">
|
||||
<div>
|
||||
<p className="text-muted-foreground">{t('inference.task')}</p>
|
||||
<p className="font-medium">{latestResult.taskType}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-muted-foreground">{t('inference.latency')}</p>
|
||||
<p className="font-medium">{latestResult.latencyMs.toFixed(1)} ms</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-muted-foreground">{t('cluster.devices')}</p>
|
||||
<p className="font-medium">{latestResult.deviceId || '-'}</p>
|
||||
</div>
|
||||
</div>
|
||||
{latestResult.classifications && latestResult.classifications.length > 0 && (
|
||||
<div className="space-y-1">
|
||||
<p className="text-sm font-medium">{t('inference.classificationResults')}</p>
|
||||
{latestResult.classifications.map((c, i) => (
|
||||
<div key={i} className="flex justify-between text-sm">
|
||||
<span>{c.label}</span>
|
||||
<span className="text-muted-foreground">
|
||||
{(c.confidence * 100).toFixed(1)}%
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{latestResult.detections && latestResult.detections.length > 0 && (
|
||||
<div className="space-y-1">
|
||||
<p className="text-sm font-medium">Detections</p>
|
||||
{latestResult.detections.map((d, i) => (
|
||||
<div key={i} className="flex justify-between text-sm">
|
||||
<span>{d.label}</span>
|
||||
<span className="text-muted-foreground">
|
||||
{(d.confidence * 100).toFixed(1)}%
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-muted-foreground">
|
||||
{inferenceRunning ? t('common.loading') : t('cluster.startInference')}
|
||||
</p>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<ClusterPerformance />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
import ClusterWorkspaceClient from './cluster-workspace-client';
|
||||
|
||||
export function generateStaticParams() {
|
||||
return [{ clusterId: '_' }];
|
||||
}
|
||||
|
||||
export default function ClusterWorkspacePage() {
|
||||
return <ClusterWorkspaceClient />;
|
||||
}
|
||||
@ -0,0 +1,80 @@
|
||||
'use client';
|
||||
|
||||
import { useCameraStore } from '@/stores/camera-store';
|
||||
import { useInferenceStore } from '@/stores/inference-store';
|
||||
import { getBackendUrl, appendRelayToken } from '@/lib/constants';
|
||||
import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area';
|
||||
import { Progress } from '@/components/ui/progress';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
import { Check, Loader2 } from 'lucide-react';
|
||||
|
||||
export function BatchImageThumbnails() {
|
||||
const { t } = useTranslation();
|
||||
const {
|
||||
batchImages,
|
||||
batchSelectedIndex,
|
||||
batchProcessedCount,
|
||||
setBatchSelectedIndex,
|
||||
} = useCameraStore();
|
||||
const batchResults = useInferenceStore((s) => s.batchResults);
|
||||
|
||||
if (batchImages.length === 0) return null;
|
||||
|
||||
const progress = (batchProcessedCount / batchImages.length) * 100;
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Progress value={progress} className="flex-1" />
|
||||
<span className="text-xs text-muted-foreground whitespace-nowrap">
|
||||
{batchProcessedCount}/{batchImages.length}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<ScrollArea className="w-full">
|
||||
<div className="flex gap-2 pb-2">
|
||||
{batchImages.map((img, i) => {
|
||||
const hasResult = i in batchResults;
|
||||
const isProcessing = i === batchProcessedCount && !hasResult;
|
||||
const isSelected = i === batchSelectedIndex;
|
||||
|
||||
return (
|
||||
<button
|
||||
key={i}
|
||||
onClick={() => setBatchSelectedIndex(i)}
|
||||
className={cn(
|
||||
'relative flex-shrink-0 w-20 h-16 rounded-md overflow-hidden border-2 transition-all',
|
||||
isSelected
|
||||
? 'border-primary ring-2 ring-primary/30'
|
||||
: 'border-transparent hover:border-muted-foreground/30',
|
||||
!hasResult && !isProcessing && 'opacity-60'
|
||||
)}
|
||||
>
|
||||
<img
|
||||
src={appendRelayToken(`${getBackendUrl()}/api/media/batch-images/${i}`)}
|
||||
alt={img.filename}
|
||||
className="w-full h-full object-cover"
|
||||
/>
|
||||
<div className="absolute bottom-0 left-0 right-0 bg-black/60 px-1 py-0.5 flex items-center justify-center">
|
||||
{isProcessing && (
|
||||
<Loader2 className="h-3 w-3 text-yellow-400 animate-spin" />
|
||||
)}
|
||||
{hasResult && (
|
||||
<Check className="h-3 w-3 text-green-400" />
|
||||
)}
|
||||
{!hasResult && !isProcessing && (
|
||||
<span className="text-[10px] text-gray-400">
|
||||
{i + 1}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<ScrollBar orientation="horizontal" />
|
||||
</ScrollArea>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
'use client';
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useCameraStore } from '@/stores/camera-store';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
interface CameraControlsProps {
|
||||
deviceId: string;
|
||||
}
|
||||
|
||||
export function CameraControls({ deviceId }: CameraControlsProps) {
|
||||
const { t } = useTranslation();
|
||||
const { cameras, isStreaming, startPipeline, stopPipeline } = useCameraStore();
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-3">
|
||||
{isStreaming ? (
|
||||
<Button variant="destructive" onClick={stopPipeline}>
|
||||
{t('camera.stopCamera')}
|
||||
</Button>
|
||||
) : (
|
||||
<Button onClick={() => startPipeline(cameras[0]?.id ?? 'mock-cam-0', deviceId)}>
|
||||
{t('camera.startCamera')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,78 @@
|
||||
'use client';
|
||||
|
||||
import { useRef, useEffect } from 'react';
|
||||
import type { SourceType } from '@/types/camera';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
interface CameraFeedProps {
|
||||
streamUrl: string;
|
||||
width?: number;
|
||||
height?: number;
|
||||
sourceType?: SourceType | null;
|
||||
batchImageUrl?: string;
|
||||
onDimensionsChange?: (width: number, height: number) => void;
|
||||
/** Rendered as an absolute overlay inside the feed container (e.g. CameraOverlay) */
|
||||
overlay?: React.ReactNode;
|
||||
}
|
||||
|
||||
export function CameraFeed({ streamUrl, width = 640, height = 480, sourceType, batchImageUrl, onDimensionsChange, overlay }: CameraFeedProps) {
|
||||
const { t } = useTranslation();
|
||||
const imgRef = useRef<HTMLImageElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const img = imgRef.current;
|
||||
if (!img || !onDimensionsChange) return;
|
||||
|
||||
const observer = new ResizeObserver((entries) => {
|
||||
for (const entry of entries) {
|
||||
const { width: w, height: h } = entry.contentRect;
|
||||
if (w > 0 && h > 0) {
|
||||
onDimensionsChange(Math.round(w), Math.round(h));
|
||||
}
|
||||
}
|
||||
});
|
||||
observer.observe(img);
|
||||
return () => observer.disconnect();
|
||||
}, [onDimensionsChange]);
|
||||
|
||||
if (!streamUrl) {
|
||||
return (
|
||||
<div
|
||||
className="flex items-center justify-center rounded-lg border bg-muted"
|
||||
style={{ width, height }}
|
||||
>
|
||||
<div className="text-center text-muted-foreground">
|
||||
<p>{t('camera.noInputSource')}</p>
|
||||
<p className="text-xs mt-1">{t('camera.selectSourceHint')}</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const displayUrl = batchImageUrl || streamUrl;
|
||||
|
||||
const altText =
|
||||
sourceType === 'image' || sourceType === 'batch_image'
|
||||
? t('camera.uploadedImage')
|
||||
: sourceType === 'video'
|
||||
? t('camera.videoPlayback')
|
||||
: t('camera.cameraFeed');
|
||||
|
||||
return (
|
||||
<div className="relative overflow-hidden rounded-lg border">
|
||||
<img
|
||||
ref={imgRef}
|
||||
src={displayUrl}
|
||||
alt={altText}
|
||||
style={{ width, height: 'auto' }}
|
||||
className="block"
|
||||
/>
|
||||
{overlay}
|
||||
{sourceType && sourceType !== 'camera' && (
|
||||
<div className="absolute top-2 left-2 rounded bg-black/60 px-2 py-1 text-xs text-white z-10">
|
||||
{sourceType === 'image' ? t('camera.image') : sourceType === 'batch_image' ? t('camera.batchImages') : t('camera.video')}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useCallback } from 'react';
|
||||
import { CameraFeed } from './camera-feed';
|
||||
import { CameraOverlay } from './camera-overlay';
|
||||
import { SourceSelector } from './source-selector';
|
||||
import { BatchImageThumbnails } from './batch-image-thumbnails';
|
||||
import { useCameraStore } from '@/stores/camera-store';
|
||||
import { useInferenceStore } from '@/stores/inference-store';
|
||||
import { getBackendUrl, appendRelayToken } from '@/lib/constants';
|
||||
|
||||
interface CameraInferenceViewProps {
|
||||
deviceId: string;
|
||||
}
|
||||
|
||||
export function CameraInferenceView({ deviceId }: CameraInferenceViewProps) {
|
||||
const { isStreaming, streamUrl, sourceType, batchSelectedIndex } = useCameraStore();
|
||||
const { result, batchResults, confidenceThreshold } = useInferenceStore();
|
||||
|
||||
const displayWidth = 640;
|
||||
const [renderedSize, setRenderedSize] = useState({ w: 640, h: 480 });
|
||||
const isBatchMode = sourceType === 'batch_image';
|
||||
|
||||
const handleDimensionsChange = useCallback((w: number, h: number) => {
|
||||
setRenderedSize({ w, h });
|
||||
}, []);
|
||||
|
||||
// In batch mode, show the selected image's detections
|
||||
const selectedResult = isBatchMode
|
||||
? batchResults[batchSelectedIndex]
|
||||
: result;
|
||||
const detections = selectedResult?.detections || [];
|
||||
|
||||
// In batch mode, use static image endpoint for viewing selected image
|
||||
const batchImageUrl = isBatchMode
|
||||
? appendRelayToken(`${getBackendUrl()}/api/media/batch-images/${batchSelectedIndex}`)
|
||||
: undefined;
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<SourceSelector deviceId={deviceId} />
|
||||
{isBatchMode && isStreaming && <BatchImageThumbnails />}
|
||||
<CameraFeed
|
||||
streamUrl={isStreaming ? streamUrl : ''}
|
||||
width={displayWidth}
|
||||
sourceType={sourceType}
|
||||
batchImageUrl={batchImageUrl}
|
||||
onDimensionsChange={handleDimensionsChange}
|
||||
overlay={
|
||||
isStreaming ? (
|
||||
<CameraOverlay
|
||||
detections={detections}
|
||||
width={renderedSize.w}
|
||||
height={renderedSize.h}
|
||||
confidenceThreshold={confidenceThreshold}
|
||||
/>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useRef } from 'react';
|
||||
import type { DetectionResult } from '@/types/inference';
|
||||
|
||||
interface CameraOverlayProps {
|
||||
detections: DetectionResult[];
|
||||
width: number;
|
||||
height: number;
|
||||
confidenceThreshold: number;
|
||||
}
|
||||
|
||||
const COLORS = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEAA7', '#DDA0DD', '#98D8C8', '#F7DC6F'];
|
||||
|
||||
export function CameraOverlay({ detections, width, height, confidenceThreshold }: CameraOverlayProps) {
|
||||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const canvas = canvasRef.current;
|
||||
if (!canvas) return;
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (!ctx) return;
|
||||
|
||||
ctx.clearRect(0, 0, width, height);
|
||||
|
||||
const filtered = detections.filter((d) => d.confidence >= confidenceThreshold);
|
||||
|
||||
filtered.forEach((det, i) => {
|
||||
const color = COLORS[i % COLORS.length];
|
||||
// Convert normalized coordinates (0-1) to pixel values
|
||||
const px = det.bbox.x * width;
|
||||
const py = det.bbox.y * height;
|
||||
const pw = det.bbox.width * width;
|
||||
const ph = det.bbox.height * height;
|
||||
|
||||
// Draw bounding box
|
||||
ctx.strokeStyle = color;
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(px, py, pw, ph);
|
||||
|
||||
// Draw label background
|
||||
const label = `${det.label} ${(det.confidence * 100).toFixed(0)}%`;
|
||||
ctx.font = '14px sans-serif';
|
||||
const textWidth = ctx.measureText(label).width;
|
||||
ctx.fillStyle = color;
|
||||
ctx.fillRect(px, py - 20, textWidth + 8, 20);
|
||||
|
||||
// Draw label text
|
||||
ctx.fillStyle = '#fff';
|
||||
ctx.fillText(label, px + 4, py - 5);
|
||||
});
|
||||
}, [detections, width, height, confidenceThreshold]);
|
||||
|
||||
return (
|
||||
<canvas
|
||||
ref={canvasRef}
|
||||
width={width}
|
||||
height={height}
|
||||
style={{ width, height }}
|
||||
className="absolute left-0 top-0 pointer-events-none"
|
||||
/>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,254 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect, useRef } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import { useCameraStore } from '@/stores/camera-store';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface SourceSelectorProps {
|
||||
deviceId: string;
|
||||
}
|
||||
|
||||
export function SourceSelector({ deviceId }: SourceSelectorProps) {
|
||||
const { t } = useTranslation();
|
||||
const {
|
||||
cameras,
|
||||
isStreaming,
|
||||
sourceType,
|
||||
sourceFilename,
|
||||
isUploading,
|
||||
startPipeline,
|
||||
stopPipeline,
|
||||
uploadImage,
|
||||
uploadVideo,
|
||||
uploadBatchImages,
|
||||
startFromUrl,
|
||||
} = useCameraStore();
|
||||
|
||||
const [mounted, setMounted] = useState(false);
|
||||
const hasCameras = cameras.length > 0;
|
||||
const [cameraDisabled, setCameraDisabled] = useState(false);
|
||||
const [activeTab, setActiveTab] = useState<'camera' | 'image' | 'video'>('camera');
|
||||
|
||||
useEffect(() => {
|
||||
setMounted(true);
|
||||
}, []);
|
||||
|
||||
// After mount, check if cameras are available and switch tab if needed
|
||||
useEffect(() => {
|
||||
if (!hasCameras) {
|
||||
setCameraDisabled(true);
|
||||
if (activeTab === 'camera') {
|
||||
setActiveTab('image');
|
||||
}
|
||||
} else {
|
||||
setCameraDisabled(false);
|
||||
}
|
||||
}, [hasCameras, activeTab]);
|
||||
const [videoMode, setVideoMode] = useState<'file' | 'url'>('file');
|
||||
const [videoUrl, setVideoUrl] = useState('');
|
||||
const [isDragging, setIsDragging] = useState(false);
|
||||
const imageFileRef = useRef<HTMLInputElement>(null);
|
||||
const videoFileRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const handleImageSelect = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const files = Array.from(e.target.files || []);
|
||||
if (files.length === 0) return;
|
||||
if (files.length === 1) {
|
||||
await uploadImage(files[0], deviceId);
|
||||
} else {
|
||||
await uploadBatchImages(files, deviceId);
|
||||
}
|
||||
if (imageFileRef.current) imageFileRef.current.value = '';
|
||||
};
|
||||
|
||||
const handleDragOver = (e: React.DragEvent) => {
|
||||
e.preventDefault();
|
||||
setIsDragging(true);
|
||||
};
|
||||
const handleDragLeave = () => setIsDragging(false);
|
||||
const handleDrop = async (e: React.DragEvent) => {
|
||||
e.preventDefault();
|
||||
setIsDragging(false);
|
||||
const files = Array.from(e.dataTransfer.files).filter((f) =>
|
||||
['.jpg', '.jpeg', '.png'].some((ext) => f.name.toLowerCase().endsWith(ext))
|
||||
);
|
||||
if (files.length === 0) return;
|
||||
if (files.length === 1) {
|
||||
await uploadImage(files[0], deviceId);
|
||||
} else {
|
||||
await uploadBatchImages(files, deviceId);
|
||||
}
|
||||
};
|
||||
|
||||
const handleVideoSelect = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return;
|
||||
await uploadVideo(file, deviceId);
|
||||
if (videoFileRef.current) videoFileRef.current.value = '';
|
||||
};
|
||||
|
||||
const handleUrlSubmit = async () => {
|
||||
if (!videoUrl.trim()) return;
|
||||
await startFromUrl(videoUrl.trim(), deviceId);
|
||||
setVideoUrl('');
|
||||
};
|
||||
|
||||
const sourceLabel =
|
||||
sourceType === 'camera' ? t('camera.camera') : sourceType === 'image' ? t('camera.image') : sourceType === 'batch_image' ? t('camera.batchImages') : t('camera.video');
|
||||
|
||||
if (!mounted) return null;
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<Tabs
|
||||
value={activeTab}
|
||||
onValueChange={(v) => setActiveTab(v as typeof activeTab)}
|
||||
>
|
||||
<TabsList className="grid w-full grid-cols-3">
|
||||
<TabsTrigger value="camera" disabled={isStreaming || cameraDisabled}>
|
||||
{t('camera.camera')}
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="image" disabled={isStreaming}>
|
||||
{t('camera.image')}
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="video" disabled={isStreaming}>
|
||||
{t('camera.video')}
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
|
||||
<div className="flex items-center gap-3">
|
||||
{isStreaming ? (
|
||||
<>
|
||||
<Button variant="destructive" onClick={stopPipeline}>
|
||||
{sourceType === 'camera' ? t('camera.stopCamera') : sourceType === 'image' ? t('camera.stopImage') : sourceType === 'batch_image' ? t('camera.stopBatch') : t('camera.stopVideo')}
|
||||
</Button>
|
||||
{sourceFilename && (
|
||||
<span className="text-sm text-muted-foreground truncate max-w-48">
|
||||
{sourceFilename}
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{activeTab === 'camera' && (
|
||||
hasCameras ? (
|
||||
<Button onClick={() => startPipeline(cameras[0]?.id ?? '', deviceId)}>
|
||||
{t('camera.startCamera')}
|
||||
</Button>
|
||||
) : (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('camera.noCameraDetected')}
|
||||
</p>
|
||||
)
|
||||
)}
|
||||
|
||||
{activeTab === 'image' && (
|
||||
<div
|
||||
onDragOver={handleDragOver}
|
||||
onDragLeave={handleDragLeave}
|
||||
onDrop={handleDrop}
|
||||
className={cn(
|
||||
'flex-1 rounded-lg border-2 border-dashed p-3 transition-colors',
|
||||
isDragging ? 'border-primary bg-primary/5' : 'border-transparent'
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<Button
|
||||
onClick={() => imageFileRef.current?.click()}
|
||||
disabled={isUploading}
|
||||
>
|
||||
{isUploading ? t('common.uploading') : t('camera.selectImages')}
|
||||
</Button>
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{t('camera.jpgPngMultiple')}
|
||||
</span>
|
||||
</div>
|
||||
{isDragging && (
|
||||
<p className="mt-2 text-sm text-primary">{t('camera.dropImagesHere')}</p>
|
||||
)}
|
||||
<input
|
||||
ref={imageFileRef}
|
||||
type="file"
|
||||
accept=".jpg,.jpeg,.png"
|
||||
multiple
|
||||
className="hidden"
|
||||
onChange={handleImageSelect}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeTab === 'video' && (
|
||||
<div className="flex flex-col gap-2 w-full">
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant={videoMode === 'file' ? 'default' : 'outline'}
|
||||
size="sm"
|
||||
onClick={() => setVideoMode('file')}
|
||||
>
|
||||
{t('camera.uploadFile')}
|
||||
</Button>
|
||||
<Button
|
||||
variant={videoMode === 'url' ? 'default' : 'outline'}
|
||||
size="sm"
|
||||
onClick={() => setVideoMode('url')}
|
||||
>
|
||||
{t('camera.pasteUrl')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{videoMode === 'file' ? (
|
||||
<div className="flex items-center gap-3">
|
||||
<Button
|
||||
onClick={() => videoFileRef.current?.click()}
|
||||
disabled={isUploading}
|
||||
>
|
||||
{isUploading ? t('common.uploading') : t('camera.selectVideo')}
|
||||
</Button>
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{t('camera.mp4AviMov')}
|
||||
</span>
|
||||
<input
|
||||
ref={videoFileRef}
|
||||
type="file"
|
||||
accept=".mp4,.avi,.mov"
|
||||
className="hidden"
|
||||
onChange={handleVideoSelect}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
placeholder={t('camera.urlPlaceholder')}
|
||||
value={videoUrl}
|
||||
onChange={(e) => setVideoUrl(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') handleUrlSubmit();
|
||||
}}
|
||||
className="flex-1"
|
||||
/>
|
||||
<Button
|
||||
onClick={handleUrlSubmit}
|
||||
disabled={isUploading || !videoUrl.trim()}
|
||||
>
|
||||
{isUploading ? t('common.loading') : t('common.start')}
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t('camera.urlHelpText')}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,78 @@
|
||||
'use client';
|
||||
|
||||
import Link from 'next/link';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useClusterStore } from '@/stores/cluster-store';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
import type { Cluster } from '@/types/cluster';
|
||||
|
||||
interface ClusterCardProps {
|
||||
cluster: Cluster;
|
||||
}
|
||||
|
||||
const statusVariant: Record<string, 'default' | 'secondary' | 'destructive' | 'outline'> = {
|
||||
idle: 'secondary',
|
||||
inferencing: 'default',
|
||||
degraded: 'destructive',
|
||||
};
|
||||
|
||||
export function ClusterCard({ cluster }: ClusterCardProps) {
|
||||
const { t } = useTranslation();
|
||||
const { deleteCluster } = useClusterStore();
|
||||
const activeDevices = cluster.devices.filter((d) => d.status !== 'removed');
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex items-start justify-between">
|
||||
<CardTitle className="text-base">{cluster.name}</CardTitle>
|
||||
<Badge variant={statusVariant[cluster.status] || 'secondary'}>
|
||||
{t(`cluster.status.${cluster.status}`)}
|
||||
</Badge>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<div className="grid grid-cols-2 gap-2 text-sm">
|
||||
<div>
|
||||
<p className="text-muted-foreground">{t('cluster.devices')}</p>
|
||||
<p className="font-medium">{activeDevices.length}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-muted-foreground">{t('inference.model')}</p>
|
||||
<p className="font-medium">{cluster.modelId || t('common.na')}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
{activeDevices.map((m) => (
|
||||
<div key={m.deviceId} className="flex items-center justify-between text-xs">
|
||||
<span>{m.deviceName || m.deviceId}</span>
|
||||
<span className="text-muted-foreground">
|
||||
{m.deviceType} (w={m.weight})
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Link href={`/workspace/cluster/${cluster.id}`}>
|
||||
<Button size="sm" variant="outline">
|
||||
{t('cluster.openWorkspace')}
|
||||
</Button>
|
||||
</Link>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() => {
|
||||
if (confirm(t('cluster.deleteConfirm').replace('{name}', cluster.name))) {
|
||||
deleteCluster(cluster.id);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{t('common.delete')}
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,106 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { useClusterStore } from '@/stores/cluster-store';
|
||||
import { useDeviceStore } from '@/stores/device-store';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
interface ClusterCreateDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
}
|
||||
|
||||
export function ClusterCreateDialog({ open, onOpenChange }: ClusterCreateDialogProps) {
|
||||
const { t } = useTranslation();
|
||||
const { createCluster } = useClusterStore();
|
||||
const { devices } = useDeviceStore();
|
||||
const [name, setName] = useState('');
|
||||
const [selectedIds, setSelectedIds] = useState<string[]>([]);
|
||||
|
||||
const connectedDevices = devices.filter(
|
||||
(d) => d.status === 'connected' || d.status === 'inferencing',
|
||||
);
|
||||
|
||||
const toggleDevice = (id: string) => {
|
||||
setSelectedIds((prev) =>
|
||||
prev.includes(id) ? prev.filter((x) => x !== id) : [...prev, id],
|
||||
);
|
||||
};
|
||||
|
||||
const handleCreate = async () => {
|
||||
if (!name || selectedIds.length === 0) return;
|
||||
const result = await createCluster(name, selectedIds);
|
||||
if (result) {
|
||||
setName('');
|
||||
setSelectedIds([]);
|
||||
onOpenChange(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t('cluster.createCluster')}</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label>{t('cluster.clusterName')}</Label>
|
||||
<Input
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
placeholder={t('cluster.clusterNamePlaceholder')}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>{t('cluster.selectDevices')}</Label>
|
||||
{connectedDevices.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('cluster.noDevicesAvailable')}
|
||||
</p>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
{connectedDevices.map((device) => (
|
||||
<label
|
||||
key={device.id}
|
||||
className="flex items-center gap-3 rounded-md border px-3 py-2 cursor-pointer hover:bg-accent"
|
||||
>
|
||||
<Checkbox
|
||||
checked={selectedIds.includes(device.id)}
|
||||
onCheckedChange={() => toggleDevice(device.id)}
|
||||
/>
|
||||
<div className="flex-1">
|
||||
<p className="text-sm font-medium">{device.name}</p>
|
||||
<p className="text-xs text-muted-foreground">{device.type}</p>
|
||||
</div>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
||||
{t('common.cancel')}
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleCreate}
|
||||
disabled={!name || selectedIds.length === 0}
|
||||
>
|
||||
{t('cluster.createCluster')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
'use client';
|
||||
|
||||
import { ClusterCard } from './cluster-card';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
import type { Cluster } from '@/types/cluster';
|
||||
|
||||
interface ClusterListProps {
|
||||
clusters: Cluster[];
|
||||
loading?: boolean;
|
||||
}
|
||||
|
||||
export function ClusterList({ clusters, loading }: ClusterListProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{Array.from({ length: 3 }).map((_, i) => (
|
||||
<div key={i} className="h-48 animate-pulse rounded-lg border bg-muted" />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (clusters.length === 0) {
|
||||
return (
|
||||
<div className="flex h-64 items-center justify-center text-muted-foreground">
|
||||
{t('cluster.noClusters')}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{clusters.map((cluster) => (
|
||||
<ClusterCard key={cluster.id} cluster={cluster} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
'use client';
|
||||
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { useClusterStore } from '@/stores/cluster-store';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
export function ClusterPerformance() {
|
||||
const { t } = useTranslation();
|
||||
const { perDeviceStats, aggregateFps, selectedCluster } = useClusterStore();
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="pb-3">
|
||||
<CardTitle className="text-base">{t('cluster.aggregateFps')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="text-center">
|
||||
<p className="text-3xl font-bold">{aggregateFps.toFixed(1)}</p>
|
||||
<p className="text-sm text-muted-foreground">{t('inference.fps')}</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-3">
|
||||
<p className="text-sm font-medium">{t('cluster.perDeviceFps')}</p>
|
||||
{selectedCluster?.devices
|
||||
.filter((d) => d.status !== 'removed')
|
||||
.map((member) => {
|
||||
const stats = perDeviceStats[member.deviceId];
|
||||
return (
|
||||
<div
|
||||
key={member.deviceId}
|
||||
className="flex items-center justify-between text-sm"
|
||||
>
|
||||
<div>
|
||||
<p className="font-medium">
|
||||
{member.deviceName || member.deviceId}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{member.deviceType} (w={member.weight})
|
||||
</p>
|
||||
</div>
|
||||
<div className="text-right">
|
||||
<p className="font-medium">
|
||||
{stats ? stats.fps.toFixed(1) : '0.0'} fps
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{stats ? stats.latencyMs.toFixed(0) : '-'} ms
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
{Object.keys(perDeviceStats).length === 0 && (
|
||||
<p className="text-sm text-muted-foreground">-</p>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { useActivityStore, type ActivityType } from '@/stores/activity-store';
|
||||
import {
|
||||
Upload,
|
||||
Trash2,
|
||||
Cable,
|
||||
Unplug,
|
||||
Zap,
|
||||
CheckCircle,
|
||||
XCircle,
|
||||
type LucideIcon,
|
||||
} from 'lucide-react';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
const activityIcons: Record<ActivityType, LucideIcon> = {
|
||||
model_upload: Upload,
|
||||
model_delete: Trash2,
|
||||
device_connect: Cable,
|
||||
device_disconnect: Unplug,
|
||||
flash_start: Zap,
|
||||
flash_complete: CheckCircle,
|
||||
flash_error: XCircle,
|
||||
};
|
||||
|
||||
const activityColors: Record<ActivityType, string> = {
|
||||
model_upload: 'text-blue-600',
|
||||
model_delete: 'text-red-600',
|
||||
device_connect: 'text-green-600',
|
||||
device_disconnect: 'text-gray-500',
|
||||
flash_start: 'text-yellow-600',
|
||||
flash_complete: 'text-green-600',
|
||||
flash_error: 'text-red-600',
|
||||
};
|
||||
|
||||
export function ActivityTimeline() {
|
||||
const activities = useActivityStore((s) => s.activities).slice(0, 10);
|
||||
const { t } = useTranslation();
|
||||
const [now, setNow] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
setNow(Date.now());
|
||||
const timer = setInterval(() => setNow(Date.now()), 60_000);
|
||||
return () => clearInterval(timer);
|
||||
}, []);
|
||||
|
||||
function formatTime(timestamp: number) {
|
||||
if (now === 0) return '';
|
||||
const diff = now - timestamp;
|
||||
const minutes = Math.floor(diff / 60000);
|
||||
if (minutes < 1) return t('dashboard.justNow');
|
||||
if (minutes < 60) return t('dashboard.minutesAgo', { n: minutes });
|
||||
const hours = Math.floor(minutes / 60);
|
||||
if (hours < 24) return t('dashboard.hoursAgo', { n: hours });
|
||||
const days = Math.floor(hours / 24);
|
||||
return t('dashboard.daysAgo', { n: days });
|
||||
}
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('dashboard.recentActivity')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{activities.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">{t('dashboard.noActivity')}</p>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{activities.map((activity) => {
|
||||
const Icon = activityIcons[activity.type];
|
||||
const color = activityColors[activity.type];
|
||||
return (
|
||||
<div key={activity.id} className="flex gap-3 items-start">
|
||||
<Icon className={`h-4 w-4 mt-0.5 shrink-0 ${color}`} />
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-sm truncate">{activity.message}</p>
|
||||
<p className="text-xs text-muted-foreground" suppressHydrationWarning>
|
||||
{formatTime(activity.timestamp)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
'use client';
|
||||
|
||||
import Link from 'next/link';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { useDeviceStore } from '@/stores/device-store';
|
||||
import { Cable } from 'lucide-react';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
export function ConnectedDevicesList() {
|
||||
const { t } = useTranslation();
|
||||
const devices = useDeviceStore((s) => s.devices);
|
||||
const connectedDevices = devices.filter(
|
||||
(d) => d.status === 'connected' || d.status === 'flashing' || d.status === 'inferencing',
|
||||
);
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('dashboard.connectedDevices')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{connectedDevices.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">{t('dashboard.noConnectedDevices')}</p>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{connectedDevices.map((device) => (
|
||||
<div
|
||||
key={device.id}
|
||||
className="flex items-center justify-between rounded-lg border p-3"
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<Cable className="h-4 w-4 text-green-600" />
|
||||
<div>
|
||||
<p className="text-sm font-medium">{device.name}</p>
|
||||
<p className="text-xs text-muted-foreground">{device.type}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Badge variant="outline" className="text-xs">
|
||||
{device.status}
|
||||
</Badge>
|
||||
<Link href={`/devices/${device.id}`}>
|
||||
<Button size="sm" variant="ghost">
|
||||
{t('common.view')}
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
'use client';
|
||||
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import type { LucideIcon } from 'lucide-react';
|
||||
|
||||
interface StatCardProps {
|
||||
title: string;
|
||||
value: string | number;
|
||||
subtitle?: string;
|
||||
icon?: LucideIcon;
|
||||
iconColor?: string;
|
||||
}
|
||||
|
||||
export function StatCard({ title, value, subtitle, icon: Icon, iconColor }: StatCardProps) {
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="pb-2 flex flex-row items-center justify-between">
|
||||
<CardTitle className="text-sm font-medium text-muted-foreground">
|
||||
{title}
|
||||
</CardTitle>
|
||||
{Icon && <Icon className={`h-4 w-4 ${iconColor || 'text-muted-foreground'}`} />}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-3xl font-bold">{value}</div>
|
||||
{subtitle && <p className="text-sm text-muted-foreground mt-1">{subtitle}</p>}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,81 @@
|
||||
'use client';
|
||||
|
||||
import Link from 'next/link';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { DeviceStatusBadge } from './device-status';
|
||||
import { useDeviceStore } from '@/stores/device-store';
|
||||
import { useDevicePreferencesStore } from '@/stores/device-preferences-store';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
import type { Device } from '@/types/device';
|
||||
|
||||
interface DeviceCardProps {
|
||||
device: Device;
|
||||
}
|
||||
|
||||
export function DeviceCard({ device }: DeviceCardProps) {
|
||||
const { t } = useTranslation();
|
||||
const { connectDevice, disconnectDevice } = useDeviceStore();
|
||||
const prefs = useDevicePreferencesStore((s) => s.getPreferences(device.id));
|
||||
const displayName = prefs.alias || device.name;
|
||||
const isConnected = device.status === 'connected' || device.status === 'flashing' || device.status === 'inferencing';
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex items-start justify-between">
|
||||
<div>
|
||||
<CardTitle className="text-base">{displayName}</CardTitle>
|
||||
{prefs.alias && (
|
||||
<p className="text-xs text-muted-foreground">{device.name}</p>
|
||||
)}
|
||||
</div>
|
||||
<DeviceStatusBadge status={device.status} />
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<div className="grid grid-cols-2 gap-2 text-sm">
|
||||
<div>
|
||||
<p className="text-muted-foreground">{t('devices.type')}</p>
|
||||
<p className="font-medium">{device.type}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-muted-foreground">{t('devices.firmware')}</p>
|
||||
<p className="font-medium">{device.firmwareVersion || t('common.na')}</p>
|
||||
</div>
|
||||
{device.flashedModel && (
|
||||
<div className="col-span-2">
|
||||
<p className="text-muted-foreground">{t('devices.flashedModel')}</p>
|
||||
<p className="font-medium">{device.flashedModel}</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
{isConnected ? (
|
||||
<>
|
||||
<Link href={`/devices/${device.id}`}>
|
||||
<Button size="sm" variant="outline">
|
||||
{t('common.manage')}
|
||||
</Button>
|
||||
</Link>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() => disconnectDevice(device.id)}
|
||||
>
|
||||
{t('common.disconnect')}
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={() => connectDevice(device.id)}
|
||||
>
|
||||
{t('common.connect')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
'use client';
|
||||
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import { useDevicePreferencesStore } from '@/stores/device-preferences-store';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface DeviceConnectionLogProps {
|
||||
deviceId: string;
|
||||
}
|
||||
|
||||
export function DeviceConnectionLog({ deviceId }: DeviceConnectionLogProps) {
|
||||
const { t } = useTranslation();
|
||||
const connectionLog = useDevicePreferencesStore((s) => s.connectionLog);
|
||||
const deviceLogs = connectionLog
|
||||
.filter((entry) => entry.deviceId === deviceId)
|
||||
.reverse()
|
||||
.slice(0, 50);
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('devices.connectionLog.title')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{deviceLogs.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">{t('devices.connectionLog.noEvents')}</p>
|
||||
) : (
|
||||
<ScrollArea className="h-48">
|
||||
<div className="space-y-2">
|
||||
{deviceLogs.map((entry, i) => (
|
||||
<div key={i} className="flex items-center justify-between text-sm">
|
||||
<div className="flex items-center gap-2">
|
||||
<div
|
||||
className={cn(
|
||||
'h-2 w-2 rounded-full',
|
||||
entry.event === 'connected' ? 'bg-green-500' : 'bg-gray-400'
|
||||
)}
|
||||
/>
|
||||
<span>{entry.event === 'connected' ? t('devices.connectionLog.connected') : t('devices.connectionLog.disconnected')}</span>
|
||||
</div>
|
||||
<span className="text-muted-foreground text-xs" suppressHydrationWarning>
|
||||
{new Date(entry.timestamp).toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,79 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { DeviceStatusBadge } from './device-status';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
import type { Device } from '@/types/device';
|
||||
import { useDevicePreferencesStore } from '@/stores/device-preferences-store';
|
||||
|
||||
interface DeviceHealthCardProps {
|
||||
device: Device;
|
||||
}
|
||||
|
||||
function formatUptime(ms: number): string | null {
|
||||
if (ms <= 0) return null;
|
||||
const seconds = Math.floor(ms / 1000);
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const hours = Math.floor(minutes / 60);
|
||||
if (hours > 0) return `${hours}h ${minutes % 60}m`;
|
||||
if (minutes > 0) return `${minutes}m ${seconds % 60}s`;
|
||||
return `${seconds}s`;
|
||||
}
|
||||
|
||||
export function DeviceHealthCard({ device }: DeviceHealthCardProps) {
|
||||
const { t } = useTranslation();
|
||||
const connectionLog = useDevicePreferencesStore((s) => s.connectionLog);
|
||||
const deviceLogs = connectionLog.filter((e) => e.deviceId === device.id);
|
||||
|
||||
const lastConnected = [...deviceLogs]
|
||||
.reverse()
|
||||
.find((e) => e.event === 'connected');
|
||||
const lastSeen = deviceLogs.length > 0
|
||||
? deviceLogs[deviceLogs.length - 1].timestamp
|
||||
: null;
|
||||
|
||||
const isOnline = device.status === 'connected' || device.status === 'flashing' || device.status === 'inferencing';
|
||||
|
||||
const [uptimeMs, setUptimeMs] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
if (!lastConnected || !isOnline) {
|
||||
setUptimeMs(0);
|
||||
return;
|
||||
}
|
||||
setUptimeMs(Date.now() - lastConnected.timestamp);
|
||||
const timer = setInterval(() => {
|
||||
setUptimeMs(Date.now() - lastConnected.timestamp);
|
||||
}, 1000);
|
||||
return () => clearInterval(timer);
|
||||
}, [lastConnected, isOnline]);
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('devices.health.title')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('devices.health.status')}</span>
|
||||
<DeviceStatusBadge status={device.status} />
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('devices.health.firmwareVersion')}</span>
|
||||
<span className="font-medium">{device.firmwareVersion || t('common.na')}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('devices.health.uptime')}</span>
|
||||
<span className="font-medium" suppressHydrationWarning>{formatUptime(uptimeMs) || t('common.na')}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('devices.health.lastSeen')}</span>
|
||||
<span className="text-sm" suppressHydrationWarning>
|
||||
{lastSeen ? new Date(lastSeen).toLocaleString() : t('common.na')}
|
||||
</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
'use client';
|
||||
|
||||
import { HardDrive } from 'lucide-react';
|
||||
import { DeviceCard } from './device-card';
|
||||
import { EmptyState } from '@/components/ui/empty-state';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
import { useDeviceStore } from '@/stores/device-store';
|
||||
import type { Device } from '@/types/device';
|
||||
|
||||
interface DeviceListProps {
|
||||
devices: Device[];
|
||||
loading?: boolean;
|
||||
}
|
||||
|
||||
export function DeviceList({ devices, loading }: DeviceListProps) {
|
||||
const { t } = useTranslation();
|
||||
const { scanDevices } = useDeviceStore();
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{Array.from({ length: 3 }).map((_, i) => (
|
||||
<div key={i} className="h-48 animate-pulse rounded-lg border bg-muted" />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (devices.length === 0) {
|
||||
return (
|
||||
<EmptyState
|
||||
icon={HardDrive}
|
||||
title={t('emptyState.devicesTitle')}
|
||||
description={t('emptyState.devicesDesc')}
|
||||
action={{ label: t('emptyState.devicesScan'), onClick: scanDevices }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{devices.map((device) => (
|
||||
<DeviceCard key={device.id} device={device} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,65 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useDevicePreferencesStore } from '@/stores/device-preferences-store';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
import { showSuccess } from '@/lib/toast';
|
||||
|
||||
interface DeviceSettingsCardProps {
|
||||
deviceId: string;
|
||||
}
|
||||
|
||||
export function DeviceSettingsCard({ deviceId }: DeviceSettingsCardProps) {
|
||||
const { t } = useTranslation();
|
||||
const { getPreferences, setAlias, setNotes } = useDevicePreferencesStore();
|
||||
const prefs = getPreferences(deviceId);
|
||||
|
||||
const [alias, setAliasLocal] = useState(prefs.alias);
|
||||
const [notes, setNotesLocal] = useState(prefs.notes);
|
||||
|
||||
useEffect(() => {
|
||||
const p = getPreferences(deviceId);
|
||||
setAliasLocal(p.alias);
|
||||
setNotesLocal(p.notes);
|
||||
}, [deviceId, getPreferences]);
|
||||
|
||||
const handleSave = () => {
|
||||
setAlias(deviceId, alias);
|
||||
setNotes(deviceId, notes);
|
||||
showSuccess(t('devices.settings.settingsSaved'));
|
||||
};
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('devices.settings.title')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div>
|
||||
<label className="text-sm font-medium text-muted-foreground">{t('devices.settings.alias')}</label>
|
||||
<Input
|
||||
className="mt-1"
|
||||
placeholder={t('devices.settings.aliasPlaceholder')}
|
||||
value={alias}
|
||||
onChange={(e) => setAliasLocal(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="text-sm font-medium text-muted-foreground">{t('devices.settings.notes')}</label>
|
||||
<textarea
|
||||
className="mt-1 flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
||||
placeholder={t('devices.settings.notesPlaceholder')}
|
||||
value={notes}
|
||||
onChange={(e) => setNotesLocal(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<Button size="sm" onClick={handleSave}>
|
||||
{t('devices.settings.saveSettings')}
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
'use client';
|
||||
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
import type { DeviceStatus } from '@/types/device';
|
||||
|
||||
const statusColors: Record<string, string> = {
|
||||
detected: 'bg-gray-400',
|
||||
connecting: 'bg-yellow-400',
|
||||
connected: 'bg-green-500',
|
||||
flashing: 'bg-yellow-500',
|
||||
inferencing: 'bg-blue-500',
|
||||
error: 'bg-red-500',
|
||||
disconnected: 'bg-gray-400',
|
||||
};
|
||||
|
||||
export function DeviceStatusBadge({ status }: { status: DeviceStatus }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const statusLabels: Record<string, string> = {
|
||||
detected: t('devices.status.detected'),
|
||||
connecting: t('devices.status.connecting'),
|
||||
connected: t('devices.status.connected'),
|
||||
flashing: t('devices.status.flashing'),
|
||||
inferencing: t('devices.status.inferencing'),
|
||||
error: t('devices.status.error'),
|
||||
disconnected: t('devices.status.disconnected'),
|
||||
};
|
||||
|
||||
const color = statusColors[status] || statusColors.disconnected;
|
||||
const label = statusLabels[status] || statusLabels.disconnected;
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
<div className={cn('h-2.5 w-2.5 rounded-full', color)} />
|
||||
<span className="text-sm">{label}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,142 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { TriangleAlertIcon } from 'lucide-react';
|
||||
import { FlashProgress } from './flash-progress';
|
||||
import { useModelStore } from '@/stores/model-store';
|
||||
import { useFlashStore } from '@/stores/flash-store';
|
||||
import { useDeviceStore } from '@/stores/device-store';
|
||||
import { useFlashProgress } from '@/hooks/use-flash-progress';
|
||||
import { isModelCompatible, getHardwareType } from '@/lib/hardware-compat';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
interface FlashDialogProps {
|
||||
deviceId: string;
|
||||
}
|
||||
|
||||
export function FlashDialog({ deviceId }: FlashDialogProps) {
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [selectedModelId, setSelectedModelId] = useState('');
|
||||
const { models, fetchModels } = useModelStore();
|
||||
const { isFlashing, progress, error, startFlash, retryFlash, reset } = useFlashStore();
|
||||
const { fetchDevice, devices } = useDeviceStore();
|
||||
const { connectAndWait, disconnect } = useFlashProgress(deviceId);
|
||||
|
||||
const device = devices.find((d) => d.id === deviceId);
|
||||
const selectedModel = models.find((m) => m.id === selectedModelId);
|
||||
|
||||
const compatible = useMemo(() => {
|
||||
if (!selectedModel || !device) return true;
|
||||
return isModelCompatible(selectedModel.supportedHardware, device.type);
|
||||
}, [selectedModel, device]);
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
fetchModels();
|
||||
reset();
|
||||
setSelectedModelId('');
|
||||
} else {
|
||||
disconnect();
|
||||
}
|
||||
}, [open, fetchModels, reset, disconnect]);
|
||||
|
||||
const handleFlash = async () => {
|
||||
if (!selectedModelId) return;
|
||||
// 1. Create WebSocket and wait for it to open
|
||||
await connectAndWait();
|
||||
// 2. Then start flash (POST) — now WS is listening
|
||||
await startFlash(deviceId, selectedModelId);
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={(v) => {
|
||||
if (!v && isFlashing && !error) return;
|
||||
setOpen(v);
|
||||
}}>
|
||||
<DialogTrigger asChild>
|
||||
<Button>{t('devices.flash.flashModel')}</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t('devices.flash.flashToDevice')}</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
{!isFlashing && !progress && !error ? (
|
||||
<>
|
||||
<Select value={selectedModelId} onValueChange={setSelectedModelId}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder={t('devices.flash.selectModel')} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{models.map((m) => (
|
||||
<SelectItem key={m.id} value={m.id}>
|
||||
{m.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
{selectedModelId && !compatible && (
|
||||
<div className="rounded-md bg-yellow-50 p-3 border border-yellow-200">
|
||||
<div className="flex gap-2 items-start">
|
||||
<TriangleAlertIcon className="h-5 w-5 text-yellow-600 mt-0.5 shrink-0" />
|
||||
<div className="text-sm">
|
||||
<p className="font-medium text-yellow-800">{t('devices.flash.hardwareIncompatible')}</p>
|
||||
<p className="text-yellow-700">
|
||||
{t('devices.flash.incompatibleDesc', { device: device ? getHardwareType(device.type) : 'this device' })}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Button
|
||||
onClick={handleFlash}
|
||||
disabled={!selectedModelId || !compatible}
|
||||
className="w-full"
|
||||
>
|
||||
{!selectedModelId
|
||||
? t('devices.flash.selectModel')
|
||||
: !compatible
|
||||
? t('devices.flash.incompatibleCannotFlash')
|
||||
: t('devices.flash.startFlash')}
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<FlashProgress progress={progress} error={error} onRetry={retryFlash} />
|
||||
)}
|
||||
{((progress && progress.percent >= 100) || error) && (
|
||||
<Button
|
||||
variant="outline"
|
||||
className="w-full"
|
||||
onClick={() => {
|
||||
if (!error) fetchDevice(deviceId);
|
||||
disconnect();
|
||||
reset();
|
||||
setOpen(false);
|
||||
}}
|
||||
>
|
||||
{error ? t('common.close') : t('common.done')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
'use client';
|
||||
|
||||
import { Progress } from '@/components/ui/progress';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { XCircle } from 'lucide-react';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
import type { FlashProgress as FlashProgressType } from '@/types/device';
|
||||
|
||||
interface FlashProgressProps {
|
||||
progress: FlashProgressType | null;
|
||||
error?: string | null;
|
||||
onRetry?: () => void;
|
||||
}
|
||||
|
||||
export function FlashProgress({ progress, error, onRetry }: FlashProgressProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<div className="rounded-md bg-red-50 p-4 border border-red-200">
|
||||
<div className="flex gap-2 items-start">
|
||||
<XCircle className="h-5 w-5 text-red-600 mt-0.5 shrink-0" />
|
||||
<div className="flex-1">
|
||||
<p className="font-medium text-red-800">{t('devices.flash.flashFailed')}</p>
|
||||
<p className="text-sm text-red-700 mt-1">{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{onRetry && (
|
||||
<Button onClick={onRetry} className="w-full" variant="outline">
|
||||
{t('common.retry')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!progress) {
|
||||
return (
|
||||
<div className="space-y-2 text-center">
|
||||
<div className="animate-pulse text-sm text-muted-foreground">
|
||||
{t('devices.flash.preparingFlash')}
|
||||
</div>
|
||||
<Progress value={0} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center justify-between text-sm">
|
||||
<span className="font-medium">{progress.stage}</span>
|
||||
<span className="text-muted-foreground">{progress.percent}%</span>
|
||||
</div>
|
||||
<Progress value={progress.percent} />
|
||||
<p className="text-sm text-muted-foreground">{progress.message}</p>
|
||||
{progress.percent >= 100 && (
|
||||
<p className="text-sm font-medium text-green-600">{t('devices.flash.flashComplete')}</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
'use client';
|
||||
|
||||
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, ResponsiveContainer, Cell } from 'recharts';
|
||||
import type { ClassResult } from '@/types/inference';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
interface ClassificationResultProps {
|
||||
results: ClassResult[];
|
||||
confidenceThreshold: number;
|
||||
}
|
||||
|
||||
const COLORS = ['#8884d8', '#82ca9d', '#ffc658', '#ff7300', '#0088FE', '#00C49F', '#FFBB28', '#FF8042'];
|
||||
|
||||
export function ClassificationResult({ results, confidenceThreshold }: ClassificationResultProps) {
|
||||
const { t } = useTranslation();
|
||||
const filtered = results
|
||||
.filter((r) => r.confidence >= confidenceThreshold)
|
||||
.sort((a, b) => b.confidence - a.confidence)
|
||||
.slice(0, 8);
|
||||
|
||||
const data = filtered.map((r) => ({
|
||||
label: r.label,
|
||||
confidence: +(r.confidence * 100).toFixed(1),
|
||||
}));
|
||||
|
||||
if (data.length === 0) {
|
||||
return (
|
||||
<div className="flex h-48 items-center justify-center text-sm text-muted-foreground">
|
||||
{t('inference.noResultsAboveThreshold')}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<ResponsiveContainer width="100%" height={250}>
|
||||
<BarChart data={data} layout="vertical" margin={{ left: 80, right: 20, top: 5, bottom: 5 }}>
|
||||
<CartesianGrid strokeDasharray="3 3" />
|
||||
<XAxis type="number" domain={[0, 100]} unit="%" />
|
||||
<YAxis type="category" dataKey="label" width={70} fontSize={12} />
|
||||
<Bar dataKey="confidence" radius={[0, 4, 4, 0]}>
|
||||
{data.map((_, index) => (
|
||||
<Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} />
|
||||
))}
|
||||
</Bar>
|
||||
</BarChart>
|
||||
</ResponsiveContainer>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
'use client';
|
||||
|
||||
import { Slider } from '@/components/ui/slider';
|
||||
import { useInferenceStore } from '@/stores/inference-store';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
export function ConfidenceSlider() {
|
||||
const { t } = useTranslation();
|
||||
const { confidenceThreshold, setConfidenceThreshold } = useInferenceStore();
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between text-sm">
|
||||
<span>{t('inference.confidenceThreshold')}</span>
|
||||
<span className="font-medium">{(confidenceThreshold * 100).toFixed(0)}%</span>
|
||||
</div>
|
||||
<Slider
|
||||
value={[confidenceThreshold]}
|
||||
onValueChange={([v]) => setConfidenceThreshold(v)}
|
||||
min={0}
|
||||
max={1}
|
||||
step={0.05}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,98 @@
|
||||
'use client';
|
||||
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { ClassificationResult } from './classification-result';
|
||||
import { PerformanceMetrics } from './performance-metrics';
|
||||
import { ConfidenceSlider } from './confidence-slider';
|
||||
import { VideoProgress } from './video-progress';
|
||||
import { useInferenceStore } from '@/stores/inference-store';
|
||||
import { useCameraStore } from '@/stores/camera-store';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
export function InferencePanel() {
|
||||
const { t } = useTranslation();
|
||||
const { result, fps, avgLatency, isRunning, confidenceThreshold, batchResults } =
|
||||
useInferenceStore();
|
||||
const { sourceType, batchSelectedIndex, batchImages, batchProcessedCount } =
|
||||
useCameraStore();
|
||||
|
||||
const isVideoMode = sourceType === 'video';
|
||||
const isBatchMode = sourceType === 'batch_image';
|
||||
const displayResult = isBatchMode
|
||||
? batchResults[batchSelectedIndex]
|
||||
: result;
|
||||
const classifications = displayResult?.classifications || [];
|
||||
|
||||
return (
|
||||
<div className="w-80 space-y-4">
|
||||
<PerformanceMetrics fps={fps} avgLatency={avgLatency} isRunning={isRunning} />
|
||||
|
||||
{isVideoMode && isRunning && <VideoProgress />}
|
||||
|
||||
{isBatchMode && batchImages.length > 0 && (
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm">{t('inference.batchProgress')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-1 text-sm">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('inference.processed')}</span>
|
||||
<span>{batchProcessedCount} / {batchImages.length}</span>
|
||||
</div>
|
||||
{batchImages[batchSelectedIndex] && (
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('inference.currentImage')}</span>
|
||||
<span className="truncate max-w-32 text-right">
|
||||
{batchImages[batchSelectedIndex].filename}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm">{t('inference.confidenceFilter')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<ConfidenceSlider />
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm">{t('inference.classificationResults')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<ClassificationResult
|
||||
results={classifications}
|
||||
confidenceThreshold={confidenceThreshold}
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{displayResult && (
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm">{t('inference.details')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-1 text-sm">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('inference.model')}</span>
|
||||
<span>{displayResult.modelId}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('inference.task')}</span>
|
||||
<span>{displayResult.taskType}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('inference.latency')}</span>
|
||||
<span>{displayResult.latencyMs.toFixed(1)} ms</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
'use client';
|
||||
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
interface PerformanceMetricsProps {
|
||||
fps: number;
|
||||
avgLatency: number;
|
||||
isRunning: boolean;
|
||||
}
|
||||
|
||||
export function PerformanceMetrics({ fps, avgLatency, isRunning }: PerformanceMetricsProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<Card>
|
||||
<CardHeader className="pb-1">
|
||||
<CardTitle className="text-xs text-muted-foreground">{t('inference.fps')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">
|
||||
{isRunning ? fps.toFixed(0) : '--'}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="pb-1">
|
||||
<CardTitle className="text-xs text-muted-foreground">{t('inference.latency')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">
|
||||
{isRunning ? `${avgLatency.toFixed(0)} ms` : '--'}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,82 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useCallback } from 'react';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Slider } from '@/components/ui/slider';
|
||||
import { useCameraStore } from '@/stores/camera-store';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
function formatTime(seconds: number): string {
|
||||
const m = Math.floor(seconds / 60);
|
||||
const s = Math.floor(seconds % 60);
|
||||
return `${m}:${s.toString().padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
export function VideoProgress() {
|
||||
const { t } = useTranslation();
|
||||
const { videoFrameIndex, videoTotalFrames, videoDurationSeconds, seekVideo } =
|
||||
useCameraStore();
|
||||
|
||||
const [isSeeking, setIsSeeking] = useState(false);
|
||||
const [seekValue, setSeekValue] = useState(0);
|
||||
|
||||
const hasKnownDuration = videoTotalFrames > 0 && videoDurationSeconds > 0;
|
||||
|
||||
// Current time based on frame index
|
||||
const currentSeconds = hasKnownDuration
|
||||
? (videoFrameIndex / videoTotalFrames) * videoDurationSeconds
|
||||
: 0;
|
||||
|
||||
// Display value: use seek preview while dragging, otherwise real position
|
||||
const displaySeconds = isSeeking ? seekValue : currentSeconds;
|
||||
|
||||
const handleSeekChange = useCallback(([value]: number[]) => {
|
||||
setIsSeeking(true);
|
||||
setSeekValue(value);
|
||||
}, []);
|
||||
|
||||
const handleSeekCommit = useCallback(
|
||||
([value]: number[]) => {
|
||||
setIsSeeking(false);
|
||||
seekVideo(value);
|
||||
},
|
||||
[seekVideo],
|
||||
);
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm">{t('inference.videoProgress')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-2">
|
||||
{hasKnownDuration ? (
|
||||
<>
|
||||
<Slider
|
||||
value={[displaySeconds]}
|
||||
onValueChange={handleSeekChange}
|
||||
onValueCommit={handleSeekCommit}
|
||||
min={0}
|
||||
max={videoDurationSeconds}
|
||||
step={0.5}
|
||||
/>
|
||||
<div className="flex justify-between text-xs text-muted-foreground">
|
||||
<span>
|
||||
{formatTime(displaySeconds)} / {formatTime(videoDurationSeconds)}
|
||||
</span>
|
||||
<span>
|
||||
{videoFrameIndex} / {videoTotalFrames} {t('inference.frames')}
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div className="flex justify-between text-sm">
|
||||
<span className="text-muted-foreground">
|
||||
{t('inference.framesProcessed')}
|
||||
</span>
|
||||
<span>{videoFrameIndex + 1}</span>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
8
edge-ai-platform/frontend/src/components/lang-sync.tsx
Normal file
8
edge-ai-platform/frontend/src/components/lang-sync.tsx
Normal file
@ -0,0 +1,8 @@
|
||||
'use client';
|
||||
import { useEffect } from 'react';
|
||||
import { useSettingsStore } from '@/stores/settings-store';
|
||||
export function LangSync() {
|
||||
const language = useSettingsStore((s) => s.language);
|
||||
useEffect(() => { document.documentElement.lang = language; }, [language]);
|
||||
return null;
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { showSuccess, showError } from '@/lib/toast';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
import { getApiBaseUrl } from '@/lib/constants';
|
||||
import { getRelayHeaders, ensureRelayToken } from '@/lib/api';
|
||||
|
||||
export function ConnectionStatus() {
|
||||
const [connected, setConnected] = useState(false);
|
||||
const prevConnected = useRef<boolean | null>(null);
|
||||
const { t } = useTranslation();
|
||||
|
||||
useEffect(() => {
|
||||
let mounted = true;
|
||||
|
||||
async function check() {
|
||||
try {
|
||||
await ensureRelayToken();
|
||||
const res = await fetch(`${getApiBaseUrl()}/system/health`, { headers: getRelayHeaders() });
|
||||
const data = await res.json();
|
||||
if (mounted) setConnected(data.status === 'ok');
|
||||
} catch {
|
||||
if (mounted) setConnected(false);
|
||||
}
|
||||
}
|
||||
|
||||
check();
|
||||
const interval = setInterval(check, 5000);
|
||||
return () => {
|
||||
mounted = false;
|
||||
clearInterval(interval);
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (prevConnected.current === null) {
|
||||
prevConnected.current = connected;
|
||||
return;
|
||||
}
|
||||
if (prevConnected.current && !connected) {
|
||||
showError(t('errors.serverDisconnected'));
|
||||
} else if (!prevConnected.current && connected) {
|
||||
showSuccess(t('errors.serverReconnected'));
|
||||
}
|
||||
prevConnected.current = connected;
|
||||
}, [connected]);
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<div
|
||||
className={cn(
|
||||
'h-2.5 w-2.5 rounded-full',
|
||||
connected ? 'bg-green-500' : 'bg-red-500',
|
||||
)}
|
||||
/>
|
||||
<span className="text-muted-foreground">
|
||||
{connected ? t('nav.serverConnected') : t('nav.serverDisconnected')}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
17
edge-ai-platform/frontend/src/components/layout/header.tsx
Normal file
17
edge-ai-platform/frontend/src/components/layout/header.tsx
Normal file
@ -0,0 +1,17 @@
|
||||
'use client';
|
||||
|
||||
import { ConnectionStatus } from './connection-status';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
export function Header() {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<header className="flex h-14 items-center justify-between border-b bg-card px-6">
|
||||
<h1 className="text-lg font-semibold">{t('nav.platformTitle')}</h1>
|
||||
<div className="flex items-center gap-4">
|
||||
<ConnectionStatus />
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
60
edge-ai-platform/frontend/src/components/layout/sidebar.tsx
Normal file
60
edge-ai-platform/frontend/src/components/layout/sidebar.tsx
Normal file
@ -0,0 +1,60 @@
|
||||
'use client';
|
||||
|
||||
import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
export function Sidebar() {
|
||||
const pathname = usePathname();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const navItems = [
|
||||
{ href: '/', label: t('nav.dashboard'), icon: 'H' },
|
||||
{ href: '/models', label: t('nav.modelLibrary'), icon: 'M' },
|
||||
{ href: '/devices', label: t('nav.devices'), icon: 'D' },
|
||||
{ href: '/clusters', label: t('cluster.title'), icon: 'C' },
|
||||
{ href: '/settings', label: t('nav.settings'), icon: 'S' },
|
||||
];
|
||||
|
||||
return (
|
||||
<aside className="flex h-full w-60 flex-col border-r bg-card">
|
||||
<div className="flex h-14 items-center border-b px-4">
|
||||
<Link href="/" className="flex items-center gap-2 font-semibold">
|
||||
<div className="flex h-8 w-8 items-center justify-center rounded-lg bg-primary text-primary-foreground text-sm font-bold">
|
||||
E
|
||||
</div>
|
||||
<span className="text-lg">{t('nav.appName')}</span>
|
||||
</Link>
|
||||
</div>
|
||||
<nav className="flex-1 space-y-1 p-3">
|
||||
{navItems.map((item) => {
|
||||
const isActive =
|
||||
item.href === '/'
|
||||
? pathname === '/'
|
||||
: pathname.startsWith(item.href);
|
||||
return (
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
className={cn(
|
||||
'flex items-center gap-3 rounded-md px-3 py-2 text-sm font-medium transition-colors',
|
||||
isActive
|
||||
? 'bg-primary text-primary-foreground'
|
||||
: 'text-muted-foreground hover:bg-accent hover:text-accent-foreground',
|
||||
)}
|
||||
>
|
||||
<span className="flex h-6 w-6 items-center justify-center rounded text-xs font-bold">
|
||||
{item.icon}
|
||||
</span>
|
||||
{item.label}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
<div className="border-t p-3 text-xs text-muted-foreground">
|
||||
{t('nav.version')}
|
||||
</div>
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
'use client';
|
||||
|
||||
import Link from 'next/link';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { ModelSummary } from '@/types/model';
|
||||
import { TASK_TYPES } from '@/lib/constants';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
interface ModelCardProps {
|
||||
model: ModelSummary;
|
||||
selectable?: boolean;
|
||||
selected?: boolean;
|
||||
onToggleSelect?: (id: string) => void;
|
||||
}
|
||||
|
||||
export function ModelCard({ model, selectable, selected, onToggleSelect }: ModelCardProps) {
|
||||
const { t } = useTranslation();
|
||||
const taskLabel = TASK_TYPES[model.taskType as keyof typeof TASK_TYPES] || model.taskType;
|
||||
|
||||
const cardContent = (
|
||||
<Card className={cn(
|
||||
'h-full transition-shadow hover:shadow-md cursor-pointer',
|
||||
selected && 'ring-2 ring-primary'
|
||||
)}>
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex items-start justify-between">
|
||||
<CardTitle className="text-base leading-tight">{model.name}</CardTitle>
|
||||
{selectable && (
|
||||
<Checkbox
|
||||
checked={selected}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
onCheckedChange={() => onToggleSelect?.(model.id)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex gap-1">
|
||||
<Badge variant="secondary" className="w-fit text-xs">
|
||||
{taskLabel}
|
||||
</Badge>
|
||||
{model.isCustom && (
|
||||
<Badge className="w-fit text-xs bg-purple-500">{t('common.custom')}</Badge>
|
||||
)}
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<div className="grid grid-cols-2 gap-2 text-sm">
|
||||
<div>
|
||||
<p className="text-muted-foreground">{t('models.accuracy')}</p>
|
||||
<p className="font-medium">{(model.accuracy * 100).toFixed(0)}%</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-muted-foreground">{t('models.fps')}</p>
|
||||
<p className="font-medium">{model.fps}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-muted-foreground">{t('models.size')}</p>
|
||||
<p className="font-medium">{(model.modelSize / 1_000_000).toFixed(1)} MB</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-muted-foreground">{t('models.hardware')}</p>
|
||||
<p className="font-medium">{model.supportedHardware.join(', ')}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{model.categories.slice(0, 3).map((cat) => (
|
||||
<Badge key={cat} variant="outline" className="text-xs">
|
||||
{cat}
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
|
||||
if (selectable) {
|
||||
return (
|
||||
<div onClick={() => onToggleSelect?.(model.id)}>
|
||||
{cardContent}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Link href={`/models/${model.id}`}>
|
||||
{cardContent}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,176 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { useModelStore } from '@/stores/model-store';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { Model } from '@/types/model';
|
||||
import { TASK_TYPES } from '@/lib/constants';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
interface ModelComparisonDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
}
|
||||
|
||||
function getBestIndex(values: number[], mode: 'max' | 'min'): number {
|
||||
if (values.length === 0) return -1;
|
||||
if (mode === 'max') return values.indexOf(Math.max(...values));
|
||||
return values.indexOf(Math.min(...values));
|
||||
}
|
||||
|
||||
function MetricBar({ value, max, isBest }: { value: number; max: number; isBest: boolean }) {
|
||||
const pct = max > 0 ? (value / max) * 100 : 0;
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="h-2 flex-1 rounded-full bg-muted overflow-hidden">
|
||||
<div
|
||||
className={cn('h-full rounded-full', isBest ? 'bg-green-500' : 'bg-primary/30')}
|
||||
style={{ width: `${pct}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function ModelComparisonDialog({ open, onOpenChange }: ModelComparisonDialogProps) {
|
||||
const { fetchModelsForComparison } = useModelStore();
|
||||
const [models, setModels] = useState<Model[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const { t } = useTranslation();
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setLoading(true);
|
||||
fetchModelsForComparison().then((m) => {
|
||||
setModels(m);
|
||||
setLoading(false);
|
||||
});
|
||||
}
|
||||
}, [open, fetchModelsForComparison]);
|
||||
|
||||
const accuracies = models.map((m) => m.accuracy * 100);
|
||||
const fpsList = models.map((m) => m.fps);
|
||||
const latencies = models.map((m) => m.latencyMs);
|
||||
const sizes = models.map((m) => m.modelSize / 1_000_000);
|
||||
|
||||
const bestAccuracy = getBestIndex(accuracies, 'max');
|
||||
const bestFps = getBestIndex(fpsList, 'max');
|
||||
const bestLatency = getBestIndex(latencies, 'min');
|
||||
const bestSize = getBestIndex(sizes, 'min');
|
||||
|
||||
const maxAccuracy = Math.max(...accuracies, 1);
|
||||
const maxFps = Math.max(...fpsList, 1);
|
||||
|
||||
const rows: {
|
||||
label: string;
|
||||
render: (model: Model, idx: number) => React.ReactNode;
|
||||
}[] = [
|
||||
{
|
||||
label: t('models.comparison.taskType'),
|
||||
render: (m) => TASK_TYPES[m.taskType as keyof typeof TASK_TYPES] || m.taskType,
|
||||
},
|
||||
{
|
||||
label: t('models.accuracy'),
|
||||
render: (m, idx) => (
|
||||
<div className="space-y-1">
|
||||
<span className={cn('text-sm', idx === bestAccuracy && 'font-bold text-green-600')}>
|
||||
{(m.accuracy * 100).toFixed(1)}%
|
||||
</span>
|
||||
<MetricBar value={m.accuracy * 100} max={maxAccuracy} isBest={idx === bestAccuracy} />
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
label: t('models.fps'),
|
||||
render: (m, idx) => (
|
||||
<div className="space-y-1">
|
||||
<span className={cn('text-sm', idx === bestFps && 'font-bold text-green-600')}>
|
||||
{m.fps}
|
||||
</span>
|
||||
<MetricBar value={m.fps} max={maxFps} isBest={idx === bestFps} />
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
label: t('models.latency'),
|
||||
render: (m, idx) => (
|
||||
<span className={cn('text-sm', idx === bestLatency && 'font-bold text-green-600')}>
|
||||
{m.latencyMs} ms
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
label: t('models.comparison.modelSize'),
|
||||
render: (m, idx) => (
|
||||
<span className={cn('text-sm', idx === bestSize && 'font-bold text-green-600')}>
|
||||
{(m.modelSize / 1_000_000).toFixed(1)} MB
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
label: t('models.inputSize'),
|
||||
render: (m) => <span className="text-sm">{m.inputSize.width}x{m.inputSize.height}</span>,
|
||||
},
|
||||
{
|
||||
label: t('models.quantization'),
|
||||
render: (m) => <span className="text-sm">{m.quantization}</span>,
|
||||
},
|
||||
{
|
||||
label: t('models.framework'),
|
||||
render: (m) => <span className="text-sm">{m.framework}</span>,
|
||||
},
|
||||
{
|
||||
label: t('models.hardware'),
|
||||
render: (m) => <span className="text-sm">{m.supportedHardware.join(', ')}</span>,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-w-4xl max-h-[80vh] overflow-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t('models.comparison.title')}</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
{loading ? (
|
||||
<div className="flex h-48 items-center justify-center">
|
||||
<p className="text-muted-foreground">{t('common.loading')}</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-sm">
|
||||
<thead>
|
||||
<tr className="border-b">
|
||||
<th className="py-3 pr-4 text-left font-medium text-muted-foreground w-32">{t('models.comparison.metric')}</th>
|
||||
{models.map((m) => (
|
||||
<th key={m.id} className="py-3 px-4 text-left font-semibold">
|
||||
{m.name}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((row) => (
|
||||
<tr key={row.label} className="border-b last:border-0">
|
||||
<td className="py-3 pr-4 text-muted-foreground font-medium">{row.label}</td>
|
||||
{models.map((m, idx) => (
|
||||
<td key={m.id} className="py-3 px-4">
|
||||
{row.render(m, idx)}
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
182
edge-ai-platform/frontend/src/components/models/model-detail.tsx
Normal file
182
edge-ai-platform/frontend/src/components/models/model-detail.tsx
Normal file
@ -0,0 +1,182 @@
|
||||
'use client';
|
||||
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
} from '@/components/ui/alert-dialog';
|
||||
import type { Model } from '@/types/model';
|
||||
import { TASK_TYPES, HARDWARE_OPTIONS } from '@/lib/constants';
|
||||
import { useModelStore } from '@/stores/model-store';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import Link from 'next/link';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
interface ModelDetailProps {
|
||||
model: Model;
|
||||
}
|
||||
|
||||
export function ModelDetail({ model }: ModelDetailProps) {
|
||||
const { deleteModel } = useModelStore();
|
||||
const router = useRouter();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const handleDelete = async () => {
|
||||
const success = await deleteModel(model.id);
|
||||
if (success) router.push('/models');
|
||||
};
|
||||
const taskLabel = TASK_TYPES[model.taskType as keyof typeof TASK_TYPES] || model.taskType;
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-start justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold">{model.name}</h1>
|
||||
<p className="mt-1 text-muted-foreground">{model.description}</p>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
{model.isCustom && (
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button variant="destructive">{t('common.delete')}</Button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t('models.deleteCustomModel')}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t('models.deleteConfirm', { name: model.name })}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel')}</AlertDialogCancel>
|
||||
<AlertDialogAction variant="destructive" onClick={handleDelete}>{t('common.delete')}</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
)}
|
||||
<Link href="/devices">
|
||||
<Button>{t('models.deployToDevice')}</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Badge>{taskLabel}</Badge>
|
||||
{model.isCustom && <Badge className="bg-purple-500">{t('common.custom')}</Badge>}
|
||||
{model.categories.map((cat) => (
|
||||
<Badge key={cat} variant="outline">
|
||||
{cat}
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<Separator />
|
||||
|
||||
<div className="grid grid-cols-1 gap-6 md:grid-cols-2">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('models.performance')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('models.accuracy')}</span>
|
||||
<span className="font-medium">{(model.accuracy * 100).toFixed(1)}%</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('models.latency')}</span>
|
||||
<span className="font-medium">{model.latencyMs} ms</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('models.fps')}</span>
|
||||
<span className="font-medium">{model.fps}</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('models.specifications')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('models.framework')}</span>
|
||||
<span className="font-medium">{model.framework}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('models.inputSize')}</span>
|
||||
<span className="font-medium">{model.inputSize.width}x{model.inputSize.height}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('models.size')}</span>
|
||||
<span className="font-medium">{(model.modelSize / 1_000_000).toFixed(1)} MB</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('models.quantization')}</span>
|
||||
<span className="font-medium">{model.quantization}</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('models.hardwareCompatibility')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{HARDWARE_OPTIONS.map((hw) => {
|
||||
const isSupported = model.supportedHardware.includes(hw);
|
||||
return (
|
||||
<Badge
|
||||
key={hw}
|
||||
variant={isSupported ? 'default' : 'outline'}
|
||||
className={isSupported ? 'bg-green-600' : 'text-muted-foreground'}
|
||||
>
|
||||
{hw} {isSupported ? '✓' : '✗'}
|
||||
</Badge>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('models.metadata')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('models.version')}</span>
|
||||
<span className="font-medium">{model.version}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('models.author')}</span>
|
||||
<span className="font-medium">{model.author}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('models.license')}</span>
|
||||
<span className="font-medium">{model.license}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('models.hardware')}</span>
|
||||
<span className="font-medium">{model.supportedHardware.join(', ')}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">{t('models.labels')}</span>
|
||||
<span className="font-medium text-right max-w-xs truncate">{model.labels.slice(0, 5).join(', ')}{model.labels.length > 5 ? ` +${model.labels.length - 5}` : ''}</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
'use client';
|
||||
|
||||
import { Input } from '@/components/ui/input';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { useModelStore } from '@/stores/model-store';
|
||||
import { TASK_TYPES, HARDWARE_OPTIONS } from '@/lib/constants';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
export function ModelFilters() {
|
||||
const { filter, setFilter } = useModelStore();
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<Input
|
||||
placeholder={t('models.filters.searchPlaceholder')}
|
||||
value={filter.query}
|
||||
onChange={(e) => setFilter({ query: e.target.value })}
|
||||
className="w-64"
|
||||
/>
|
||||
<Select
|
||||
value={filter.taskType || 'all'}
|
||||
onValueChange={(v) => setFilter({ taskType: v === 'all' ? '' : v })}
|
||||
>
|
||||
<SelectTrigger className="w-44">
|
||||
<SelectValue placeholder={t('models.filters.taskType')} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">{t('models.filters.allTypes')}</SelectItem>
|
||||
{Object.entries(TASK_TYPES).map(([key, label]) => (
|
||||
<SelectItem key={key} value={key}>
|
||||
{label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Select
|
||||
value={filter.hardware || 'all'}
|
||||
onValueChange={(v) => setFilter({ hardware: v === 'all' ? '' : v })}
|
||||
>
|
||||
<SelectTrigger className="w-36">
|
||||
<SelectValue placeholder={t('models.hardware')} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">{t('models.filters.allHardware')}</SelectItem>
|
||||
{HARDWARE_OPTIONS.map((hw) => (
|
||||
<SelectItem key={hw} value={hw}>
|
||||
{hw}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
'use client';
|
||||
|
||||
import { Package } from 'lucide-react';
|
||||
import { ModelCard } from './model-card';
|
||||
import { EmptyState } from '@/components/ui/empty-state';
|
||||
import { useModelStore } from '@/stores/model-store';
|
||||
import type { ModelSummary } from '@/types/model';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
interface ModelGridProps {
|
||||
models: ModelSummary[];
|
||||
loading?: boolean;
|
||||
compareMode?: boolean;
|
||||
}
|
||||
|
||||
export function ModelGrid({ models, loading, compareMode }: ModelGridProps) {
|
||||
const { comparisonIds, toggleComparison, setFilter } = useModelStore();
|
||||
const { t } = useTranslation();
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
|
||||
{Array.from({ length: 8 }).map((_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="h-56 animate-pulse rounded-lg border bg-muted"
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (models.length === 0) {
|
||||
return (
|
||||
<EmptyState
|
||||
icon={Package}
|
||||
title={t('emptyState.modelsTitle')}
|
||||
description={t('emptyState.modelsDesc')}
|
||||
action={{ label: t('emptyState.modelsBrowse'), onClick: () => setFilter({ query: '', taskType: '', hardware: '' }) }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
|
||||
{models.map((model) => (
|
||||
<ModelCard
|
||||
key={model.id}
|
||||
model={model}
|
||||
selectable={compareMode}
|
||||
selected={comparisonIds.includes(model.id)}
|
||||
onToggleSelect={toggleComparison}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,213 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useRef } from 'react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { useModelStore } from '@/stores/model-store';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
export function ModelUploadDialog() {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
const [name, setName] = useState('');
|
||||
const [description, setDescription] = useState('');
|
||||
const [taskType, setTaskType] = useState('');
|
||||
const [labelsText, setLabelsText] = useState('');
|
||||
const [inputWidth, setInputWidth] = useState('640');
|
||||
const [inputHeight, setInputHeight] = useState('640');
|
||||
const [quantization, setQuantization] = useState('INT8');
|
||||
const [error, setError] = useState('');
|
||||
const fileRef = useRef<HTMLInputElement>(null);
|
||||
const { uploading, uploadModel } = useModelStore();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const resetForm = () => {
|
||||
setFile(null);
|
||||
setName('');
|
||||
setDescription('');
|
||||
setTaskType('');
|
||||
setLabelsText('');
|
||||
setInputWidth('640');
|
||||
setInputHeight('640');
|
||||
setQuantization('INT8');
|
||||
setError('');
|
||||
if (fileRef.current) fileRef.current.value = '';
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
setError('');
|
||||
|
||||
if (!file) { setError(t('models.upload.errors.noFile')); return; }
|
||||
if (!name.trim()) { setError(t('models.upload.errors.noName')); return; }
|
||||
if (!taskType) { setError(t('models.upload.errors.noTaskType')); return; }
|
||||
|
||||
// Parse labels from comma-separated text
|
||||
const labels = labelsText
|
||||
.split(',')
|
||||
.map((l) => l.trim())
|
||||
.filter((l) => l.length > 0);
|
||||
|
||||
if (labels.length === 0) { setError(t('models.upload.errors.noLabels')); return; }
|
||||
|
||||
const success = await uploadModel(file, {
|
||||
name: name.trim(),
|
||||
description: description.trim(),
|
||||
taskType,
|
||||
labels,
|
||||
inputWidth: parseInt(inputWidth) || 640,
|
||||
inputHeight: parseInt(inputHeight) || 640,
|
||||
quantization,
|
||||
});
|
||||
|
||||
if (success) {
|
||||
resetForm();
|
||||
setOpen(false);
|
||||
} else {
|
||||
setError(t('models.upload.errors.uploadFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={(v) => { setOpen(v); if (v) resetForm(); }}>
|
||||
<DialogTrigger asChild>
|
||||
<Button>{t('models.uploadModel')}</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t('models.upload.title')}</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
{/* File input */}
|
||||
<div>
|
||||
<label className="text-sm font-medium">{t('models.upload.modelFile')}</label>
|
||||
<div
|
||||
className="mt-1 flex items-center justify-center rounded-lg border-2 border-dashed p-6 cursor-pointer hover:border-primary/50"
|
||||
onClick={() => fileRef.current?.click()}
|
||||
>
|
||||
<div className="text-center">
|
||||
{file ? (
|
||||
<p className="text-sm font-medium">{file.name} ({(file.size / 1_000_000).toFixed(1)} MB)</p>
|
||||
) : (
|
||||
<p className="text-sm text-muted-foreground">{t('models.upload.clickToSelect')}</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<input
|
||||
ref={fileRef}
|
||||
type="file"
|
||||
accept=".nef"
|
||||
className="hidden"
|
||||
onChange={(e) => setFile(e.target.files?.[0] || null)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Name */}
|
||||
<div>
|
||||
<label className="text-sm font-medium">{t('models.upload.modelName')}</label>
|
||||
<Input
|
||||
className="mt-1"
|
||||
placeholder={t('models.upload.modelNamePlaceholder')}
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Description */}
|
||||
<div>
|
||||
<label className="text-sm font-medium">{t('models.upload.description')}</label>
|
||||
<Input
|
||||
className="mt-1"
|
||||
placeholder={t('models.upload.descriptionPlaceholder')}
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Task Type */}
|
||||
<div>
|
||||
<label className="text-sm font-medium">{t('models.upload.taskType')}</label>
|
||||
<Select value={taskType} onValueChange={setTaskType}>
|
||||
<SelectTrigger className="mt-1">
|
||||
<SelectValue placeholder={t('models.upload.taskTypePlaceholder')} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="object_detection">{t('models.upload.objectDetection')}</SelectItem>
|
||||
<SelectItem value="classification">{t('models.upload.classification')}</SelectItem>
|
||||
<SelectItem value="segmentation">{t('models.upload.segmentation')}</SelectItem>
|
||||
<SelectItem value="pose_estimation">{t('models.upload.poseEstimation')}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* Labels */}
|
||||
<div>
|
||||
<label className="text-sm font-medium">{t('models.upload.labels')}</label>
|
||||
<Input
|
||||
className="mt-1"
|
||||
placeholder={t('models.upload.labelsPlaceholder')}
|
||||
value={labelsText}
|
||||
onChange={(e) => setLabelsText(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Input Size */}
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label className="text-sm font-medium">{t('models.upload.inputWidth')}</label>
|
||||
<Input
|
||||
className="mt-1"
|
||||
type="number"
|
||||
value={inputWidth}
|
||||
onChange={(e) => setInputWidth(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="text-sm font-medium">{t('models.upload.inputHeight')}</label>
|
||||
<Input
|
||||
className="mt-1"
|
||||
type="number"
|
||||
value={inputHeight}
|
||||
onChange={(e) => setInputHeight(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Quantization */}
|
||||
<div>
|
||||
<label className="text-sm font-medium">{t('models.upload.quantization')}</label>
|
||||
<Select value={quantization} onValueChange={setQuantization}>
|
||||
<SelectTrigger className="mt-1">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="INT8">INT8</SelectItem>
|
||||
<SelectItem value="FP16">FP16</SelectItem>
|
||||
<SelectItem value="FP32">FP32</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{error && <p className="text-sm text-red-500">{error}</p>}
|
||||
|
||||
<Button onClick={handleSubmit} disabled={uploading} className="w-full">
|
||||
{uploading ? t('common.uploading') : t('common.upload')}
|
||||
</Button>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,93 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { HardDrive, Package, Play } from 'lucide-react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
import { useFirstVisit } from '@/hooks/use-first-visit';
|
||||
import type { LucideIcon } from 'lucide-react';
|
||||
|
||||
interface Step {
|
||||
icon: LucideIcon;
|
||||
titleKey: 'onboarding.step1Title' | 'onboarding.step2Title' | 'onboarding.step3Title';
|
||||
descKey: 'onboarding.step1Desc' | 'onboarding.step2Desc' | 'onboarding.step3Desc';
|
||||
}
|
||||
|
||||
const steps: Step[] = [
|
||||
{ icon: HardDrive, titleKey: 'onboarding.step1Title', descKey: 'onboarding.step1Desc' },
|
||||
{ icon: Package, titleKey: 'onboarding.step2Title', descKey: 'onboarding.step2Desc' },
|
||||
{ icon: Play, titleKey: 'onboarding.step3Title', descKey: 'onboarding.step3Desc' },
|
||||
];
|
||||
|
||||
export function OnboardingDialog() {
|
||||
const { t } = useTranslation();
|
||||
const [isFirstVisit, markComplete] = useFirstVisit();
|
||||
const [step, setStep] = useState(0);
|
||||
|
||||
if (!isFirstVisit) return null;
|
||||
|
||||
const current = steps[step];
|
||||
const Icon = current.icon;
|
||||
const isLast = step === steps.length - 1;
|
||||
|
||||
return (
|
||||
<Dialog open onOpenChange={(open) => { if (!open) markComplete(); }}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t('onboarding.welcome')}</DialogTitle>
|
||||
<DialogDescription className="sr-only">
|
||||
{t('onboarding.welcome')}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="flex flex-col items-center gap-4 py-6 text-center">
|
||||
{/* Step indicator */}
|
||||
<div className="flex gap-2">
|
||||
{steps.map((_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className={`h-2 w-8 rounded-full transition-colors ${
|
||||
i === step ? 'bg-primary' : 'bg-muted'
|
||||
}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="rounded-full bg-primary/10 p-4">
|
||||
<Icon className="h-10 w-10 text-primary" />
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<h3 className="text-lg font-semibold">{t(current.titleKey)}</h3>
|
||||
<p className="max-w-xs text-sm text-muted-foreground">{t(current.descKey)}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DialogFooter className="flex-row justify-between sm:justify-between">
|
||||
<div>
|
||||
{step > 0 ? (
|
||||
<Button variant="ghost" size="sm" onClick={() => setStep(step - 1)}>
|
||||
{t('onboarding.previous')}
|
||||
</Button>
|
||||
) : (
|
||||
<Button variant="ghost" size="sm" onClick={markComplete}>
|
||||
{t('onboarding.skipTour')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Button size="sm" onClick={() => isLast ? markComplete() : setStep(step + 1)}>
|
||||
{isLast ? t('onboarding.getStarted') : t('onboarding.next')}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
import { syncRelayTokenFromURL } from '@/lib/constants';
|
||||
|
||||
/**
|
||||
* Reads relay token from URL query param (?token=xxx) on mount,
|
||||
* caches it in localStorage, and cleans the URL.
|
||||
*/
|
||||
export function RelayTokenSync() {
|
||||
useEffect(() => {
|
||||
syncRelayTokenFromURL();
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
}
|
||||
132
edge-ai-platform/frontend/src/components/server-log-viewer.tsx
Normal file
132
edge-ai-platform/frontend/src/components/server-log-viewer.tsx
Normal file
@ -0,0 +1,132 @@
|
||||
'use client';
|
||||
|
||||
import { useRef, useEffect, useState, useMemo } from 'react';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import { useServerLogs } from '@/hooks/use-server-logs';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
|
||||
type LogLevel = 'INFO' | 'WARN' | 'ERROR' | 'DEBUG';
|
||||
|
||||
const ALL_LEVELS: LogLevel[] = ['INFO', 'WARN', 'ERROR', 'DEBUG'];
|
||||
|
||||
const LEVEL_COLORS: Record<LogLevel, string> = {
|
||||
INFO: 'text-blue-400',
|
||||
WARN: 'text-yellow-400',
|
||||
ERROR: 'text-red-400',
|
||||
DEBUG: 'text-gray-400',
|
||||
};
|
||||
|
||||
const LEVEL_BADGE_VARIANT: Record<LogLevel, 'default' | 'secondary' | 'destructive' | 'outline'> = {
|
||||
INFO: 'default',
|
||||
WARN: 'secondary',
|
||||
ERROR: 'destructive',
|
||||
DEBUG: 'outline',
|
||||
};
|
||||
|
||||
export function ServerLogViewer() {
|
||||
const { t } = useTranslation();
|
||||
const { logs, clearLogs } = useServerLogs();
|
||||
const [enabledLevels, setEnabledLevels] = useState<Set<LogLevel>>(
|
||||
new Set(ALL_LEVELS),
|
||||
);
|
||||
const [autoScroll, setAutoScroll] = useState(true);
|
||||
const scrollAreaRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const filteredLogs = useMemo(
|
||||
() => logs.filter((log) => enabledLevels.has(log.level)),
|
||||
[logs, enabledLevels],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!autoScroll || !scrollAreaRef.current) return;
|
||||
const viewport = scrollAreaRef.current.querySelector<HTMLDivElement>(
|
||||
'[data-slot="scroll-area-viewport"]',
|
||||
);
|
||||
if (viewport) {
|
||||
viewport.scrollTop = viewport.scrollHeight;
|
||||
}
|
||||
}, [filteredLogs, autoScroll]);
|
||||
|
||||
const toggleLevel = (level: LogLevel) => {
|
||||
setEnabledLevels((prev) => {
|
||||
const next = new Set(prev);
|
||||
if (next.has(level)) {
|
||||
next.delete(level);
|
||||
} else {
|
||||
next.add(level);
|
||||
}
|
||||
return next;
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-3">
|
||||
<CardTitle className="text-base">{t('settings.serverLogs.title')}</CardTitle>
|
||||
<Button variant="outline" size="sm" onClick={clearLogs}>
|
||||
{t('settings.serverLogs.clear')}
|
||||
</Button>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<div className="flex items-center gap-4 flex-wrap">
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{t('settings.serverLogs.filter')}:
|
||||
</span>
|
||||
{ALL_LEVELS.map((level) => (
|
||||
<div key={level} className="flex items-center gap-1.5">
|
||||
<Checkbox
|
||||
id={`log-level-${level}`}
|
||||
checked={enabledLevels.has(level)}
|
||||
onCheckedChange={() => toggleLevel(level)}
|
||||
/>
|
||||
<Label htmlFor={`log-level-${level}`} className="text-xs cursor-pointer">
|
||||
<Badge variant={LEVEL_BADGE_VARIANT[level]} className="text-xs">
|
||||
{level}
|
||||
</Badge>
|
||||
</Label>
|
||||
</div>
|
||||
))}
|
||||
<div className="flex items-center gap-1.5 ml-auto">
|
||||
<Checkbox
|
||||
id="auto-scroll"
|
||||
checked={autoScroll}
|
||||
onCheckedChange={(checked) => setAutoScroll(checked === true)}
|
||||
/>
|
||||
<Label htmlFor="auto-scroll" className="text-xs cursor-pointer">
|
||||
{t('settings.serverLogs.autoScroll')}
|
||||
</Label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ScrollArea ref={scrollAreaRef} className="h-80 rounded-md border bg-gray-950 dark:bg-gray-950">
|
||||
<div className="p-3 font-mono text-xs leading-relaxed">
|
||||
{filteredLogs.length === 0 ? (
|
||||
<p className="text-gray-500">{t('settings.serverLogs.noLogs')}</p>
|
||||
) : (
|
||||
filteredLogs.map((entry, i) => (
|
||||
<div key={i} className="flex gap-2 hover:bg-gray-900/50">
|
||||
<span className="text-gray-500 shrink-0 select-none">
|
||||
{entry.timestamp}
|
||||
</span>
|
||||
<span className={`shrink-0 font-bold ${LEVEL_COLORS[entry.level]}`}>
|
||||
[{entry.level.padEnd(5)}]
|
||||
</span>
|
||||
<span className="text-gray-200 break-all">{entry.message}</span>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{filteredLogs.length} / {logs.length} {t('settings.serverLogs.entries')}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,224 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { useServerHealth } from '@/hooks/use-server-health';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
} from '@/components/ui/alert-dialog';
|
||||
import { useTranslation } from '@/lib/i18n';
|
||||
import { getBackendUrl } from '@/lib/constants';
|
||||
|
||||
function formatUptime(seconds: number): string {
|
||||
const d = Math.floor(seconds / 86400);
|
||||
const h = Math.floor((seconds % 86400) / 3600);
|
||||
const m = Math.floor((seconds % 3600) / 60);
|
||||
const s = Math.floor(seconds % 60);
|
||||
if (d > 0) return `${d}d ${h}h ${m}m`;
|
||||
if (h > 0) return `${h}h ${m}m ${s}s`;
|
||||
if (m > 0) return `${m}m ${s}s`;
|
||||
return `${s}s`;
|
||||
}
|
||||
|
||||
function StatTile({ label, value }: { label: string; value: string }) {
|
||||
return (
|
||||
<div className="rounded-lg border bg-muted/50 p-3 text-center">
|
||||
<p className="text-xs text-muted-foreground">{label}</p>
|
||||
<p className="text-lg font-semibold">{value}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function ServerStatusDashboard() {
|
||||
const { t } = useTranslation();
|
||||
const { metrics, deps, loading, connected, restartState, triggerRestart, refetch } = useServerHealth();
|
||||
const [reconnecting, setReconnecting] = useState(false);
|
||||
|
||||
const handleReconnect = async () => {
|
||||
setReconnecting(true);
|
||||
await refetch();
|
||||
setReconnecting(false);
|
||||
};
|
||||
|
||||
if (loading && !metrics) {
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('settings.serverStatus.title')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="h-32 animate-pulse rounded-lg bg-muted" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
// Server offline
|
||||
if (!connected) {
|
||||
const backendUrl = getBackendUrl();
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('settings.serverStatus.title')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="h-3 w-3 rounded-full bg-red-500" />
|
||||
<span className="font-medium">{t('settings.serverStatus.offline')}</span>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('settings.serverStatus.offlineDesc')}
|
||||
</p>
|
||||
{backendUrl && (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('settings.serverStatus.backendAddress')}: <span className="font-mono">{backendUrl}</span>
|
||||
</p>
|
||||
)}
|
||||
<Button onClick={handleReconnect} disabled={reconnecting} size="sm">
|
||||
{reconnecting
|
||||
? t('settings.serverStatus.reconnecting')
|
||||
: t('settings.serverStatus.reconnect')}
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-4">
|
||||
<CardTitle className="text-base">{t('settings.serverStatus.title')}</CardTitle>
|
||||
<div>
|
||||
{restartState === 'idle' && (
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button variant="destructive" size="sm">
|
||||
{t('settings.serverStatus.restart')}
|
||||
</Button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{t('settings.serverStatus.restartConfirmTitle')}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t('settings.serverStatus.restartConfirmDesc')}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel')}</AlertDialogCancel>
|
||||
<AlertDialogAction onClick={triggerRestart}>
|
||||
{t('settings.serverStatus.restartConfirm')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
)}
|
||||
{restartState === 'restarting' && (
|
||||
<Badge variant="secondary">{t('settings.serverStatus.restarting')}</Badge>
|
||||
)}
|
||||
{restartState === 'waiting' && (
|
||||
<Badge variant="outline">{t('settings.serverStatus.waitingForServer')}</Badge>
|
||||
)}
|
||||
{restartState === 'back' && (
|
||||
<Badge className="bg-green-500 text-white">
|
||||
{t('settings.serverStatus.serverBack')}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-5">
|
||||
{metrics && (
|
||||
<>
|
||||
<div className="grid grid-cols-2 gap-3 text-sm sm:grid-cols-4">
|
||||
<div>
|
||||
<p className="text-muted-foreground">{t('settings.serverStatus.versionLabel')}</p>
|
||||
<p className="font-medium">{metrics.version}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-muted-foreground">{t('settings.serverStatus.platformLabel')}</p>
|
||||
<p className="font-medium">{metrics.platform}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-muted-foreground">{t('settings.serverStatus.buildTimeLabel')}</p>
|
||||
<p className="font-medium">{metrics.buildTime}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-muted-foreground">{t('settings.serverStatus.goVersionLabel')}</p>
|
||||
<p className="font-medium">{metrics.goVersion}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3 sm:grid-cols-3">
|
||||
<StatTile
|
||||
label={t('settings.serverStatus.uptimeLabel')}
|
||||
value={formatUptime(metrics.uptimeSeconds)}
|
||||
/>
|
||||
<StatTile
|
||||
label={t('settings.serverStatus.goroutinesLabel')}
|
||||
value={String(metrics.goroutines)}
|
||||
/>
|
||||
<StatTile
|
||||
label={t('settings.serverStatus.heapAllocLabel')}
|
||||
value={`${metrics.memHeapAllocMB.toFixed(1)} MB`}
|
||||
/>
|
||||
<StatTile
|
||||
label={t('settings.serverStatus.sysMemLabel')}
|
||||
value={`${metrics.memSysMB.toFixed(1)} MB`}
|
||||
/>
|
||||
<StatTile
|
||||
label={t('settings.serverStatus.gcCyclesLabel')}
|
||||
value={String(metrics.gcCycles)}
|
||||
/>
|
||||
<StatTile
|
||||
label={t('settings.serverStatus.nextGcLabel')}
|
||||
value={`${metrics.nextGcMB.toFixed(1)} MB`}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{deps.length > 0 && (
|
||||
<>
|
||||
<Separator />
|
||||
<div className="space-y-2">
|
||||
<p className="text-sm font-medium">{t('settings.serverStatus.depsTitle')}</p>
|
||||
{deps.map((dep) => (
|
||||
<div
|
||||
key={dep.name}
|
||||
className="flex items-center justify-between rounded-md border px-3 py-2"
|
||||
>
|
||||
<div>
|
||||
<p className="text-sm font-medium">{dep.name}</p>
|
||||
{dep.available && dep.version && (
|
||||
<p className="text-xs text-muted-foreground">{dep.version}</p>
|
||||
)}
|
||||
{!dep.available && dep.installHint && (
|
||||
<p className="text-xs text-muted-foreground">{dep.installHint}</p>
|
||||
)}
|
||||
</div>
|
||||
<Badge variant={dep.available ? 'default' : 'secondary'}>
|
||||
{dep.available
|
||||
? t('settings.serverStatus.depAvailable')
|
||||
: t('settings.serverStatus.depNotFound')}
|
||||
</Badge>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
21
edge-ai-platform/frontend/src/components/store-hydration.tsx
Normal file
21
edge-ai-platform/frontend/src/components/store-hydration.tsx
Normal file
@ -0,0 +1,21 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
import { useSettingsStore } from '@/stores/settings-store';
|
||||
import { useActivityStore } from '@/stores/activity-store';
|
||||
import { useDevicePreferencesStore } from '@/stores/device-preferences-store';
|
||||
|
||||
/**
|
||||
* Rehydrates all Zustand persist stores after client mount.
|
||||
* With skipHydration: true, stores start with default values during SSR/build,
|
||||
* then load from localStorage on the client — preventing hydration mismatches.
|
||||
*/
|
||||
export function StoreHydration() {
|
||||
useEffect(() => {
|
||||
useSettingsStore.persist.rehydrate();
|
||||
useActivityStore.persist.rehydrate();
|
||||
useDevicePreferencesStore.persist.rehydrate();
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
}
|
||||
19
edge-ai-platform/frontend/src/components/theme-sync.tsx
Normal file
19
edge-ai-platform/frontend/src/components/theme-sync.tsx
Normal file
@ -0,0 +1,19 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
import { useSettingsStore } from '@/stores/settings-store';
|
||||
|
||||
export function ThemeSync() {
|
||||
const theme = useSettingsStore((s) => s.theme);
|
||||
|
||||
useEffect(() => {
|
||||
const root = document.documentElement;
|
||||
if (theme === 'dark') {
|
||||
root.classList.add('dark');
|
||||
} else {
|
||||
root.classList.remove('dark');
|
||||
}
|
||||
}, [theme]);
|
||||
|
||||
return null;
|
||||
}
|
||||
196
edge-ai-platform/frontend/src/components/ui/alert-dialog.tsx
Normal file
196
edge-ai-platform/frontend/src/components/ui/alert-dialog.tsx
Normal file
@ -0,0 +1,196 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { AlertDialog as AlertDialogPrimitive } from "radix-ui"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Button } from "@/components/ui/button"
|
||||
|
||||
function AlertDialog({
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Root>) {
|
||||
return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />
|
||||
}
|
||||
|
||||
function AlertDialogTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Trigger>) {
|
||||
return (
|
||||
<AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
function AlertDialogPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Portal>) {
|
||||
return (
|
||||
<AlertDialogPrimitive.Portal data-slot="alert-dialog-portal" {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
function AlertDialogOverlay({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Overlay>) {
|
||||
return (
|
||||
<AlertDialogPrimitive.Overlay
|
||||
data-slot="alert-dialog-overlay"
|
||||
className={cn(
|
||||
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AlertDialogContent({
|
||||
className,
|
||||
size = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Content> & {
|
||||
size?: "default" | "sm"
|
||||
}) {
|
||||
return (
|
||||
<AlertDialogPortal>
|
||||
<AlertDialogOverlay />
|
||||
<AlertDialogPrimitive.Content
|
||||
data-slot="alert-dialog-content"
|
||||
data-size={size}
|
||||
className={cn(
|
||||
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 group/alert-dialog-content fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 data-[size=sm]:max-w-xs data-[size=default]:sm:max-w-lg",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</AlertDialogPortal>
|
||||
)
|
||||
}
|
||||
|
||||
function AlertDialogHeader({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="alert-dialog-header"
|
||||
className={cn(
|
||||
"grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-6 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AlertDialogFooter({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="alert-dialog-footer"
|
||||
className={cn(
|
||||
"flex flex-col-reverse gap-2 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AlertDialogTitle({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Title>) {
|
||||
return (
|
||||
<AlertDialogPrimitive.Title
|
||||
data-slot="alert-dialog-title"
|
||||
className={cn(
|
||||
"text-lg font-semibold sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AlertDialogDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Description>) {
|
||||
return (
|
||||
<AlertDialogPrimitive.Description
|
||||
data-slot="alert-dialog-description"
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AlertDialogMedia({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="alert-dialog-media"
|
||||
className={cn(
|
||||
"bg-muted mb-2 inline-flex size-16 items-center justify-center rounded-md sm:group-data-[size=default]/alert-dialog-content:row-span-2 *:[svg:not([class*='size-'])]:size-8",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AlertDialogAction({
|
||||
className,
|
||||
variant = "default",
|
||||
size = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Action> &
|
||||
Pick<React.ComponentProps<typeof Button>, "variant" | "size">) {
|
||||
return (
|
||||
<Button variant={variant} size={size} asChild>
|
||||
<AlertDialogPrimitive.Action
|
||||
data-slot="alert-dialog-action"
|
||||
className={cn(className)}
|
||||
{...props}
|
||||
/>
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
function AlertDialogCancel({
|
||||
className,
|
||||
variant = "outline",
|
||||
size = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Cancel> &
|
||||
Pick<React.ComponentProps<typeof Button>, "variant" | "size">) {
|
||||
return (
|
||||
<Button variant={variant} size={size} asChild>
|
||||
<AlertDialogPrimitive.Cancel
|
||||
data-slot="alert-dialog-cancel"
|
||||
className={cn(className)}
|
||||
{...props}
|
||||
/>
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogMedia,
|
||||
AlertDialogOverlay,
|
||||
AlertDialogPortal,
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
}
|
||||
48
edge-ai-platform/frontend/src/components/ui/badge.tsx
Normal file
48
edge-ai-platform/frontend/src/components/ui/badge.tsx
Normal file
@ -0,0 +1,48 @@
|
||||
import * as React from "react"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
import { Slot } from "radix-ui"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const badgeVariants = cva(
|
||||
"inline-flex items-center justify-center rounded-full border border-transparent px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
|
||||
secondary:
|
||||
"bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
|
||||
destructive:
|
||||
"bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
||||
outline:
|
||||
"border-border text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
|
||||
ghost: "[a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
|
||||
link: "text-primary underline-offset-4 [a&]:hover:underline",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function Badge({
|
||||
className,
|
||||
variant = "default",
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"span"> &
|
||||
VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot.Root : "span"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="badge"
|
||||
data-variant={variant}
|
||||
className={cn(badgeVariants({ variant }), className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Badge, badgeVariants }
|
||||
64
edge-ai-platform/frontend/src/components/ui/button.tsx
Normal file
64
edge-ai-platform/frontend/src/components/ui/button.tsx
Normal file
@ -0,0 +1,64 @@
|
||||
import * as React from "react"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
import { Slot } from "radix-ui"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const buttonVariants = cva(
|
||||
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
||||
destructive:
|
||||
"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
||||
outline:
|
||||
"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
||||
secondary:
|
||||
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
||||
ghost:
|
||||
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
||||
link: "text-primary underline-offset-4 hover:underline",
|
||||
},
|
||||
size: {
|
||||
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
||||
xs: "h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3",
|
||||
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
||||
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
||||
icon: "size-9",
|
||||
"icon-xs": "size-6 rounded-md [&_svg:not([class*='size-'])]:size-3",
|
||||
"icon-sm": "size-8",
|
||||
"icon-lg": "size-10",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function Button({
|
||||
className,
|
||||
variant = "default",
|
||||
size = "default",
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> &
|
||||
VariantProps<typeof buttonVariants> & {
|
||||
asChild?: boolean
|
||||
}) {
|
||||
const Comp = asChild ? Slot.Root : "button"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="button"
|
||||
data-variant={variant}
|
||||
data-size={size}
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Button, buttonVariants }
|
||||
92
edge-ai-platform/frontend/src/components/ui/card.tsx
Normal file
92
edge-ai-platform/frontend/src/components/ui/card.tsx
Normal file
@ -0,0 +1,92 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Card({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card"
|
||||
className={cn(
|
||||
"bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-header"
|
||||
className={cn(
|
||||
"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-title"
|
||||
className={cn("leading-none font-semibold", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-description"
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-action"
|
||||
className={cn(
|
||||
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-content"
|
||||
className={cn("px-6", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-footer"
|
||||
className={cn("flex items-center px-6 [.border-t]:pt-6", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Card,
|
||||
CardHeader,
|
||||
CardFooter,
|
||||
CardTitle,
|
||||
CardAction,
|
||||
CardDescription,
|
||||
CardContent,
|
||||
}
|
||||
32
edge-ai-platform/frontend/src/components/ui/checkbox.tsx
Normal file
32
edge-ai-platform/frontend/src/components/ui/checkbox.tsx
Normal file
@ -0,0 +1,32 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { CheckIcon } from "lucide-react"
|
||||
import { Checkbox as CheckboxPrimitive } from "radix-ui"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Checkbox({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
|
||||
return (
|
||||
<CheckboxPrimitive.Root
|
||||
data-slot="checkbox"
|
||||
className={cn(
|
||||
"peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<CheckboxPrimitive.Indicator
|
||||
data-slot="checkbox-indicator"
|
||||
className="grid place-content-center text-current transition-none"
|
||||
>
|
||||
<CheckIcon className="size-3.5" />
|
||||
</CheckboxPrimitive.Indicator>
|
||||
</CheckboxPrimitive.Root>
|
||||
)
|
||||
}
|
||||
|
||||
export { Checkbox }
|
||||
158
edge-ai-platform/frontend/src/components/ui/dialog.tsx
Normal file
158
edge-ai-platform/frontend/src/components/ui/dialog.tsx
Normal file
@ -0,0 +1,158 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { XIcon } from "lucide-react"
|
||||
import { Dialog as DialogPrimitive } from "radix-ui"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Button } from "@/components/ui/button"
|
||||
|
||||
function Dialog({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Root>) {
|
||||
return <DialogPrimitive.Root data-slot="dialog" {...props} />
|
||||
}
|
||||
|
||||
function DialogTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
|
||||
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
|
||||
}
|
||||
|
||||
function DialogPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Portal>) {
|
||||
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />
|
||||
}
|
||||
|
||||
function DialogClose({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Close>) {
|
||||
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />
|
||||
}
|
||||
|
||||
function DialogOverlay({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
|
||||
return (
|
||||
<DialogPrimitive.Overlay
|
||||
data-slot="dialog-overlay"
|
||||
className={cn(
|
||||
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogContent({
|
||||
className,
|
||||
children,
|
||||
showCloseButton = true,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
|
||||
showCloseButton?: boolean
|
||||
}) {
|
||||
return (
|
||||
<DialogPortal data-slot="dialog-portal">
|
||||
<DialogOverlay />
|
||||
<DialogPrimitive.Content
|
||||
data-slot="dialog-content"
|
||||
className={cn(
|
||||
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 outline-none sm:max-w-lg",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
{showCloseButton && (
|
||||
<DialogPrimitive.Close
|
||||
data-slot="dialog-close"
|
||||
className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
|
||||
>
|
||||
<XIcon />
|
||||
<span className="sr-only">Close</span>
|
||||
</DialogPrimitive.Close>
|
||||
)}
|
||||
</DialogPrimitive.Content>
|
||||
</DialogPortal>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="dialog-header"
|
||||
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogFooter({
|
||||
className,
|
||||
showCloseButton = false,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
showCloseButton?: boolean
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
data-slot="dialog-footer"
|
||||
className={cn(
|
||||
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
{showCloseButton && (
|
||||
<DialogPrimitive.Close asChild>
|
||||
<Button variant="outline">Close</Button>
|
||||
</DialogPrimitive.Close>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogTitle({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Title>) {
|
||||
return (
|
||||
<DialogPrimitive.Title
|
||||
data-slot="dialog-title"
|
||||
className={cn("text-lg leading-none font-semibold", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Description>) {
|
||||
return (
|
||||
<DialogPrimitive.Description
|
||||
data-slot="dialog-description"
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogOverlay,
|
||||
DialogPortal,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
}
|
||||
43
edge-ai-platform/frontend/src/components/ui/empty-state.tsx
Normal file
43
edge-ai-platform/frontend/src/components/ui/empty-state.tsx
Normal file
@ -0,0 +1,43 @@
|
||||
import type { LucideIcon } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
interface EmptyStateAction {
|
||||
label: string;
|
||||
onClick: () => void;
|
||||
}
|
||||
|
||||
interface EmptyStateProps {
|
||||
icon: LucideIcon;
|
||||
title: string;
|
||||
description: string;
|
||||
action?: EmptyStateAction;
|
||||
secondaryAction?: EmptyStateAction;
|
||||
}
|
||||
|
||||
export function EmptyState({ icon: Icon, title, description, action, secondaryAction }: EmptyStateProps) {
|
||||
return (
|
||||
<div className="flex h-64 flex-col items-center justify-center gap-4 text-center">
|
||||
<div className="rounded-full bg-muted p-4">
|
||||
<Icon className="h-8 w-8 text-muted-foreground" />
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<h3 className="text-base font-medium">{title}</h3>
|
||||
<p className="max-w-sm text-sm text-muted-foreground">{description}</p>
|
||||
</div>
|
||||
{(action || secondaryAction) && (
|
||||
<div className="flex gap-2">
|
||||
{action && (
|
||||
<Button onClick={action.onClick} size="sm">
|
||||
{action.label}
|
||||
</Button>
|
||||
)}
|
||||
{secondaryAction && (
|
||||
<Button onClick={secondaryAction.onClick} size="sm" variant="outline">
|
||||
{secondaryAction.label}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
21
edge-ai-platform/frontend/src/components/ui/input.tsx
Normal file
21
edge-ai-platform/frontend/src/components/ui/input.tsx
Normal file
@ -0,0 +1,21 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
||||
return (
|
||||
<input
|
||||
type={type}
|
||||
data-slot="input"
|
||||
className={cn(
|
||||
"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
||||
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
|
||||
"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Input }
|
||||
24
edge-ai-platform/frontend/src/components/ui/label.tsx
Normal file
24
edge-ai-platform/frontend/src/components/ui/label.tsx
Normal file
@ -0,0 +1,24 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { Label as LabelPrimitive } from "radix-ui"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Label({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
|
||||
return (
|
||||
<LabelPrimitive.Root
|
||||
data-slot="label"
|
||||
className={cn(
|
||||
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Label }
|
||||
31
edge-ai-platform/frontend/src/components/ui/progress.tsx
Normal file
31
edge-ai-platform/frontend/src/components/ui/progress.tsx
Normal file
@ -0,0 +1,31 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { Progress as ProgressPrimitive } from "radix-ui"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Progress({
|
||||
className,
|
||||
value,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ProgressPrimitive.Root>) {
|
||||
return (
|
||||
<ProgressPrimitive.Root
|
||||
data-slot="progress"
|
||||
className={cn(
|
||||
"bg-primary/20 relative h-2 w-full overflow-hidden rounded-full",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ProgressPrimitive.Indicator
|
||||
data-slot="progress-indicator"
|
||||
className="bg-primary h-full w-full flex-1 transition-all"
|
||||
style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
|
||||
/>
|
||||
</ProgressPrimitive.Root>
|
||||
)
|
||||
}
|
||||
|
||||
export { Progress }
|
||||
58
edge-ai-platform/frontend/src/components/ui/scroll-area.tsx
Normal file
58
edge-ai-platform/frontend/src/components/ui/scroll-area.tsx
Normal file
@ -0,0 +1,58 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { ScrollArea as ScrollAreaPrimitive } from "radix-ui"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function ScrollArea({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ScrollAreaPrimitive.Root>) {
|
||||
return (
|
||||
<ScrollAreaPrimitive.Root
|
||||
data-slot="scroll-area"
|
||||
className={cn("relative", className)}
|
||||
{...props}
|
||||
>
|
||||
<ScrollAreaPrimitive.Viewport
|
||||
data-slot="scroll-area-viewport"
|
||||
className="focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1"
|
||||
>
|
||||
{children}
|
||||
</ScrollAreaPrimitive.Viewport>
|
||||
<ScrollBar />
|
||||
<ScrollAreaPrimitive.Corner />
|
||||
</ScrollAreaPrimitive.Root>
|
||||
)
|
||||
}
|
||||
|
||||
function ScrollBar({
|
||||
className,
|
||||
orientation = "vertical",
|
||||
...props
|
||||
}: React.ComponentProps<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>) {
|
||||
return (
|
||||
<ScrollAreaPrimitive.ScrollAreaScrollbar
|
||||
data-slot="scroll-area-scrollbar"
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
"flex touch-none p-px transition-colors select-none",
|
||||
orientation === "vertical" &&
|
||||
"h-full w-2.5 border-l border-l-transparent",
|
||||
orientation === "horizontal" &&
|
||||
"h-2.5 flex-col border-t border-t-transparent",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ScrollAreaPrimitive.ScrollAreaThumb
|
||||
data-slot="scroll-area-thumb"
|
||||
className="bg-border relative flex-1 rounded-full"
|
||||
/>
|
||||
</ScrollAreaPrimitive.ScrollAreaScrollbar>
|
||||
)
|
||||
}
|
||||
|
||||
export { ScrollArea, ScrollBar }
|
||||
190
edge-ai-platform/frontend/src/components/ui/select.tsx
Normal file
190
edge-ai-platform/frontend/src/components/ui/select.tsx
Normal file
@ -0,0 +1,190 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react"
|
||||
import { Select as SelectPrimitive } from "radix-ui"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Select({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Root>) {
|
||||
return <SelectPrimitive.Root data-slot="select" {...props} />
|
||||
}
|
||||
|
||||
function SelectGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Group>) {
|
||||
return <SelectPrimitive.Group data-slot="select-group" {...props} />
|
||||
}
|
||||
|
||||
function SelectValue({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Value>) {
|
||||
return <SelectPrimitive.Value data-slot="select-value" {...props} />
|
||||
}
|
||||
|
||||
function SelectTrigger({
|
||||
className,
|
||||
size = "default",
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
|
||||
size?: "sm" | "default"
|
||||
}) {
|
||||
return (
|
||||
<SelectPrimitive.Trigger
|
||||
data-slot="select-trigger"
|
||||
data-size={size}
|
||||
className={cn(
|
||||
"border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<SelectPrimitive.Icon asChild>
|
||||
<ChevronDownIcon className="size-4 opacity-50" />
|
||||
</SelectPrimitive.Icon>
|
||||
</SelectPrimitive.Trigger>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectContent({
|
||||
className,
|
||||
children,
|
||||
position = "item-aligned",
|
||||
align = "center",
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Content>) {
|
||||
return (
|
||||
<SelectPrimitive.Portal>
|
||||
<SelectPrimitive.Content
|
||||
data-slot="select-content"
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",
|
||||
position === "popper" &&
|
||||
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
|
||||
className
|
||||
)}
|
||||
position={position}
|
||||
align={align}
|
||||
{...props}
|
||||
>
|
||||
<SelectScrollUpButton />
|
||||
<SelectPrimitive.Viewport
|
||||
className={cn(
|
||||
"p-1",
|
||||
position === "popper" &&
|
||||
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</SelectPrimitive.Viewport>
|
||||
<SelectScrollDownButton />
|
||||
</SelectPrimitive.Content>
|
||||
</SelectPrimitive.Portal>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectLabel({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Label>) {
|
||||
return (
|
||||
<SelectPrimitive.Label
|
||||
data-slot="select-label"
|
||||
className={cn("text-muted-foreground px-2 py-1.5 text-xs", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectItem({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Item>) {
|
||||
return (
|
||||
<SelectPrimitive.Item
|
||||
data-slot="select-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span
|
||||
data-slot="select-item-indicator"
|
||||
className="absolute right-2 flex size-3.5 items-center justify-center"
|
||||
>
|
||||
<SelectPrimitive.ItemIndicator>
|
||||
<CheckIcon className="size-4" />
|
||||
</SelectPrimitive.ItemIndicator>
|
||||
</span>
|
||||
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
||||
</SelectPrimitive.Item>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Separator>) {
|
||||
return (
|
||||
<SelectPrimitive.Separator
|
||||
data-slot="select-separator"
|
||||
className={cn("bg-border pointer-events-none -mx-1 my-1 h-px", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectScrollUpButton({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.ScrollUpButton>) {
|
||||
return (
|
||||
<SelectPrimitive.ScrollUpButton
|
||||
data-slot="select-scroll-up-button"
|
||||
className={cn(
|
||||
"flex cursor-default items-center justify-center py-1",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronUpIcon className="size-4" />
|
||||
</SelectPrimitive.ScrollUpButton>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectScrollDownButton({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.ScrollDownButton>) {
|
||||
return (
|
||||
<SelectPrimitive.ScrollDownButton
|
||||
data-slot="select-scroll-down-button"
|
||||
className={cn(
|
||||
"flex cursor-default items-center justify-center py-1",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronDownIcon className="size-4" />
|
||||
</SelectPrimitive.ScrollDownButton>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectGroup,
|
||||
SelectItem,
|
||||
SelectLabel,
|
||||
SelectScrollDownButton,
|
||||
SelectScrollUpButton,
|
||||
SelectSeparator,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
}
|
||||
28
edge-ai-platform/frontend/src/components/ui/separator.tsx
Normal file
28
edge-ai-platform/frontend/src/components/ui/separator.tsx
Normal file
@ -0,0 +1,28 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { Separator as SeparatorPrimitive } from "radix-ui"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Separator({
|
||||
className,
|
||||
orientation = "horizontal",
|
||||
decorative = true,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SeparatorPrimitive.Root>) {
|
||||
return (
|
||||
<SeparatorPrimitive.Root
|
||||
data-slot="separator"
|
||||
decorative={decorative}
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
"bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Separator }
|
||||
63
edge-ai-platform/frontend/src/components/ui/slider.tsx
Normal file
63
edge-ai-platform/frontend/src/components/ui/slider.tsx
Normal file
@ -0,0 +1,63 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { Slider as SliderPrimitive } from "radix-ui"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Slider({
|
||||
className,
|
||||
defaultValue,
|
||||
value,
|
||||
min = 0,
|
||||
max = 100,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SliderPrimitive.Root>) {
|
||||
const _values = React.useMemo(
|
||||
() =>
|
||||
Array.isArray(value)
|
||||
? value
|
||||
: Array.isArray(defaultValue)
|
||||
? defaultValue
|
||||
: [min, max],
|
||||
[value, defaultValue, min, max]
|
||||
)
|
||||
|
||||
return (
|
||||
<SliderPrimitive.Root
|
||||
data-slot="slider"
|
||||
defaultValue={defaultValue}
|
||||
value={value}
|
||||
min={min}
|
||||
max={max}
|
||||
className={cn(
|
||||
"relative flex w-full touch-none items-center select-none data-[disabled]:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<SliderPrimitive.Track
|
||||
data-slot="slider-track"
|
||||
className={cn(
|
||||
"bg-muted relative grow overflow-hidden rounded-full data-[orientation=horizontal]:h-1.5 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5"
|
||||
)}
|
||||
>
|
||||
<SliderPrimitive.Range
|
||||
data-slot="slider-range"
|
||||
className={cn(
|
||||
"bg-primary absolute data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full"
|
||||
)}
|
||||
/>
|
||||
</SliderPrimitive.Track>
|
||||
{Array.from({ length: _values.length }, (_, index) => (
|
||||
<SliderPrimitive.Thumb
|
||||
data-slot="slider-thumb"
|
||||
key={index}
|
||||
className="border-primary ring-ring/50 block size-4 shrink-0 rounded-full border bg-white shadow-sm transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50"
|
||||
/>
|
||||
))}
|
||||
</SliderPrimitive.Root>
|
||||
)
|
||||
}
|
||||
|
||||
export { Slider }
|
||||
40
edge-ai-platform/frontend/src/components/ui/sonner.tsx
Normal file
40
edge-ai-platform/frontend/src/components/ui/sonner.tsx
Normal file
@ -0,0 +1,40 @@
|
||||
"use client"
|
||||
|
||||
import {
|
||||
CircleCheckIcon,
|
||||
InfoIcon,
|
||||
Loader2Icon,
|
||||
OctagonXIcon,
|
||||
TriangleAlertIcon,
|
||||
} from "lucide-react"
|
||||
import { Toaster as Sonner, type ToasterProps } from "sonner"
|
||||
import { useSettingsStore } from "@/stores/settings-store"
|
||||
|
||||
const Toaster = ({ ...props }: ToasterProps) => {
|
||||
const theme = useSettingsStore((s) => s.theme)
|
||||
|
||||
return (
|
||||
<Sonner
|
||||
theme={theme}
|
||||
className="toaster group"
|
||||
icons={{
|
||||
success: <CircleCheckIcon className="size-4" />,
|
||||
info: <InfoIcon className="size-4" />,
|
||||
warning: <TriangleAlertIcon className="size-4" />,
|
||||
error: <OctagonXIcon className="size-4" />,
|
||||
loading: <Loader2Icon className="size-4 animate-spin" />,
|
||||
}}
|
||||
style={
|
||||
{
|
||||
"--normal-bg": "var(--popover)",
|
||||
"--normal-text": "var(--popover-foreground)",
|
||||
"--normal-border": "var(--border)",
|
||||
"--border-radius": "var(--radius)",
|
||||
} as React.CSSProperties
|
||||
}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Toaster }
|
||||
91
edge-ai-platform/frontend/src/components/ui/tabs.tsx
Normal file
91
edge-ai-platform/frontend/src/components/ui/tabs.tsx
Normal file
@ -0,0 +1,91 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
import { Tabs as TabsPrimitive } from "radix-ui"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Tabs({
|
||||
className,
|
||||
orientation = "horizontal",
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.Root>) {
|
||||
return (
|
||||
<TabsPrimitive.Root
|
||||
data-slot="tabs"
|
||||
data-orientation={orientation}
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
"group/tabs flex gap-2 data-[orientation=horizontal]:flex-col",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const tabsListVariants = cva(
|
||||
"rounded-lg p-[3px] group-data-[orientation=horizontal]/tabs:h-9 data-[variant=line]:rounded-none group/tabs-list text-muted-foreground inline-flex w-fit items-center justify-center group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-muted",
|
||||
line: "gap-1 bg-transparent",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function TabsList({
|
||||
className,
|
||||
variant = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.List> &
|
||||
VariantProps<typeof tabsListVariants>) {
|
||||
return (
|
||||
<TabsPrimitive.List
|
||||
data-slot="tabs-list"
|
||||
data-variant={variant}
|
||||
className={cn(tabsListVariants({ variant }), className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TabsTrigger({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.Trigger>) {
|
||||
return (
|
||||
<TabsPrimitive.Trigger
|
||||
data-slot="tabs-trigger"
|
||||
className={cn(
|
||||
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring text-foreground/60 hover:text-foreground dark:text-muted-foreground dark:hover:text-foreground relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-all group-data-[orientation=vertical]/tabs:w-full group-data-[orientation=vertical]/tabs:justify-start focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 group-data-[variant=default]/tabs-list:data-[state=active]:shadow-sm group-data-[variant=line]/tabs-list:data-[state=active]:shadow-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
"group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:border-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent",
|
||||
"data-[state=active]:bg-background dark:data-[state=active]:text-foreground dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 data-[state=active]:text-foreground",
|
||||
"after:bg-foreground after:absolute after:opacity-0 after:transition-opacity group-data-[orientation=horizontal]/tabs:after:inset-x-0 group-data-[orientation=horizontal]/tabs:after:bottom-[-5px] group-data-[orientation=horizontal]/tabs:after:h-0.5 group-data-[orientation=vertical]/tabs:after:inset-y-0 group-data-[orientation=vertical]/tabs:after:-right-1 group-data-[orientation=vertical]/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-[state=active]:after:opacity-100",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TabsContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.Content>) {
|
||||
return (
|
||||
<TabsPrimitive.Content
|
||||
data-slot="tabs-content"
|
||||
className={cn("flex-1 outline-none", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Tabs, TabsList, TabsTrigger, TabsContent, tabsListVariants }
|
||||
17
edge-ai-platform/frontend/src/hooks/use-camera-stream.ts
Normal file
17
edge-ai-platform/frontend/src/hooks/use-camera-stream.ts
Normal file
@ -0,0 +1,17 @@
|
||||
'use client';
|
||||
|
||||
import { useCameraStore } from '@/stores/camera-store';
|
||||
|
||||
export function useCameraStream() {
|
||||
const { isStreaming, streamUrl, startPipeline, stopPipeline, fetchCameras, cameras } =
|
||||
useCameraStore();
|
||||
|
||||
return {
|
||||
isStreaming,
|
||||
streamUrl,
|
||||
cameras,
|
||||
fetchCameras,
|
||||
startPipeline,
|
||||
stopPipeline,
|
||||
};
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useRef, useCallback } from 'react';
|
||||
import { createWebSocket } from '@/lib/ws';
|
||||
import type { ClusterFlashProgress } from '@/types/cluster';
|
||||
|
||||
export function useClusterFlashProgress(
|
||||
clusterId: string,
|
||||
onProgress: (progress: ClusterFlashProgress) => void,
|
||||
) {
|
||||
const onProgressRef = useRef(onProgress);
|
||||
onProgressRef.current = onProgress;
|
||||
const wsRef = useRef<ReturnType<typeof createWebSocket> | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
wsRef.current?.close();
|
||||
wsRef.current = null;
|
||||
};
|
||||
}, [clusterId]);
|
||||
|
||||
const connectAndWait = useCallback(
|
||||
() =>
|
||||
new Promise<void>((resolve) => {
|
||||
wsRef.current?.close();
|
||||
|
||||
let resolved = false;
|
||||
const doResolve = () => {
|
||||
if (!resolved) {
|
||||
resolved = true;
|
||||
resolve();
|
||||
}
|
||||
};
|
||||
|
||||
const ws = createWebSocket(
|
||||
`/ws/clusters/${clusterId}/flash-progress`,
|
||||
(data) => {
|
||||
onProgressRef.current(data as ClusterFlashProgress);
|
||||
},
|
||||
() => {
|
||||
doResolve();
|
||||
},
|
||||
);
|
||||
wsRef.current = ws;
|
||||
|
||||
setTimeout(doResolve, 3000);
|
||||
}),
|
||||
[clusterId],
|
||||
);
|
||||
|
||||
const disconnect = useCallback(() => {
|
||||
wsRef.current?.close();
|
||||
wsRef.current = null;
|
||||
}, []);
|
||||
|
||||
return { connectAndWait, disconnect };
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
'use client';
|
||||
|
||||
import { useWebSocket } from './use-websocket';
|
||||
import { useClusterStore } from '@/stores/cluster-store';
|
||||
import type { ClusterInferenceResult } from '@/types/cluster';
|
||||
|
||||
export function useClusterInferenceStream(clusterId: string, enabled = false) {
|
||||
const addResult = useClusterStore((s) => s.addResult);
|
||||
|
||||
useWebSocket(
|
||||
`/ws/clusters/${clusterId}/inference`,
|
||||
(data) => {
|
||||
addResult(data as ClusterInferenceResult);
|
||||
},
|
||||
enabled,
|
||||
);
|
||||
}
|
||||
32
edge-ai-platform/frontend/src/hooks/use-device-events.ts
Normal file
32
edge-ai-platform/frontend/src/hooks/use-device-events.ts
Normal file
@ -0,0 +1,32 @@
|
||||
'use client';
|
||||
|
||||
import { useWebSocket } from './use-websocket';
|
||||
import { useDeviceStore } from '@/stores/device-store';
|
||||
import { useDevicePreferencesStore } from '@/stores/device-preferences-store';
|
||||
import type { DeviceEvent } from '@/types/device';
|
||||
|
||||
export function useDeviceEvents() {
|
||||
const handleEvent = useDeviceStore((s) => s.handleEvent);
|
||||
const addConnectionLog = useDevicePreferencesStore((s) => s.addConnectionLog);
|
||||
|
||||
useWebSocket('/ws/devices/events', (data) => {
|
||||
const event = data as DeviceEvent;
|
||||
handleEvent(event);
|
||||
|
||||
if (event.event === 'updated') {
|
||||
if (event.device.status === 'connected') {
|
||||
addConnectionLog({
|
||||
deviceId: event.device.id,
|
||||
event: 'connected',
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
} else if (event.device.status === 'disconnected') {
|
||||
addConnectionLog({
|
||||
deviceId: event.device.id,
|
||||
event: 'disconnected',
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
28
edge-ai-platform/frontend/src/hooks/use-first-visit.ts
Normal file
28
edge-ai-platform/frontend/src/hooks/use-first-visit.ts
Normal file
@ -0,0 +1,28 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
const STORAGE_KEY = 'edge-ai-onboarding-complete';
|
||||
|
||||
/**
|
||||
* Hook to detect if the user is visiting for the first time.
|
||||
* Returns [isFirstVisit, markComplete] where markComplete() sets the
|
||||
* localStorage flag and updates the state.
|
||||
*/
|
||||
export function useFirstVisit(): [boolean, () => void] {
|
||||
const [isFirstVisit, setIsFirstVisit] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const done = localStorage.getItem(STORAGE_KEY);
|
||||
if (!done) {
|
||||
setIsFirstVisit(true);
|
||||
}
|
||||
}, []);
|
||||
|
||||
function markComplete() {
|
||||
localStorage.setItem(STORAGE_KEY, 'true');
|
||||
setIsFirstVisit(false);
|
||||
}
|
||||
|
||||
return [isFirstVisit, markComplete];
|
||||
}
|
||||
68
edge-ai-platform/frontend/src/hooks/use-flash-progress.ts
Normal file
68
edge-ai-platform/frontend/src/hooks/use-flash-progress.ts
Normal file
@ -0,0 +1,68 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useRef, useCallback } from 'react';
|
||||
import { createWebSocket } from '@/lib/ws';
|
||||
import { useFlashStore } from '@/stores/flash-store';
|
||||
import type { FlashProgress } from '@/types/device';
|
||||
|
||||
/**
|
||||
* Manages flash progress WebSocket.
|
||||
* Returns a `connectAndWait` callback that creates the WebSocket and
|
||||
* returns a promise that resolves once the WS is open.
|
||||
*/
|
||||
export function useFlashProgress(deviceId: string) {
|
||||
const updateProgress = useFlashStore((s) => s.updateProgress);
|
||||
const wsRef = useRef<ReturnType<typeof createWebSocket> | null>(null);
|
||||
|
||||
// Cleanup on unmount
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
wsRef.current?.close();
|
||||
wsRef.current = null;
|
||||
};
|
||||
}, [deviceId]);
|
||||
|
||||
/**
|
||||
* Creates the WebSocket connection and returns a promise that resolves
|
||||
* once the connection is open. This is called imperatively (not via
|
||||
* useEffect) to avoid React render-cycle timing issues.
|
||||
*/
|
||||
const connectAndWait = useCallback(
|
||||
() =>
|
||||
new Promise<void>((resolve) => {
|
||||
// Close any existing connection
|
||||
wsRef.current?.close();
|
||||
|
||||
let resolved = false;
|
||||
const doResolve = () => {
|
||||
if (!resolved) {
|
||||
resolved = true;
|
||||
resolve();
|
||||
}
|
||||
};
|
||||
|
||||
const ws = createWebSocket(
|
||||
`/ws/devices/${deviceId}/flash-progress`,
|
||||
(data) => {
|
||||
updateProgress(data as FlashProgress);
|
||||
},
|
||||
() => {
|
||||
doResolve();
|
||||
},
|
||||
);
|
||||
wsRef.current = ws;
|
||||
|
||||
// Safety timeout — don't block forever
|
||||
setTimeout(doResolve, 3000);
|
||||
}),
|
||||
[deviceId, updateProgress],
|
||||
);
|
||||
|
||||
/** Close the WebSocket connection. */
|
||||
const disconnect = useCallback(() => {
|
||||
wsRef.current?.close();
|
||||
wsRef.current = null;
|
||||
}, []);
|
||||
|
||||
return { connectAndWait, disconnect };
|
||||
}
|
||||
15
edge-ai-platform/frontend/src/hooks/use-hydrated.ts
Normal file
15
edge-ai-platform/frontend/src/hooks/use-hydrated.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { useSyncExternalStore } from 'react';
|
||||
|
||||
const emptySubscribe = () => () => {};
|
||||
const getSnapshot = () => true;
|
||||
const getServerSnapshot = () => false;
|
||||
|
||||
/**
|
||||
* Returns `true` once the component has mounted on the client.
|
||||
* During SSR / static export build, returns `false`.
|
||||
* Use this to guard content that depends on client-only state
|
||||
* (e.g. Zustand persist stores backed by localStorage).
|
||||
*/
|
||||
export function useHydrated() {
|
||||
return useSyncExternalStore(emptySubscribe, getSnapshot, getServerSnapshot);
|
||||
}
|
||||
44
edge-ai-platform/frontend/src/hooks/use-inference-stream.ts
Normal file
44
edge-ai-platform/frontend/src/hooks/use-inference-stream.ts
Normal file
@ -0,0 +1,44 @@
|
||||
'use client';
|
||||
|
||||
import { useWebSocket } from './use-websocket';
|
||||
import { useInferenceStore } from '@/stores/inference-store';
|
||||
import { useCameraStore } from '@/stores/camera-store';
|
||||
import type { InferenceResult } from '@/types/inference';
|
||||
|
||||
export function useInferenceStream(deviceId: string, enabled = false) {
|
||||
const addResult = useInferenceStore((s) => s.addResult);
|
||||
const addBatchResult = useInferenceStore((s) => s.addBatchResult);
|
||||
const setRunning = useInferenceStore((s) => s.setRunning);
|
||||
const setBatchProgress = useCameraStore((s) => s.setBatchProgress);
|
||||
const setVideoProgress = useCameraStore((s) => s.setVideoProgress);
|
||||
|
||||
useWebSocket(
|
||||
`/ws/devices/${deviceId}/inference`,
|
||||
(data) => {
|
||||
const msg = data as Record<string, unknown>;
|
||||
// Handle pipeline completion event
|
||||
if (msg.type === 'pipeline_complete') {
|
||||
setRunning(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const result = data as InferenceResult;
|
||||
|
||||
// Batch image result
|
||||
if (result.imageIndex !== undefined && result.totalImages !== undefined) {
|
||||
addBatchResult(result);
|
||||
setBatchProgress(result.imageIndex + 1);
|
||||
return;
|
||||
}
|
||||
|
||||
// Video result -- update frame progress
|
||||
if (result.frameIndex !== undefined) {
|
||||
setVideoProgress(result.frameIndex);
|
||||
}
|
||||
|
||||
// Standard single result (camera or video)
|
||||
addResult(result);
|
||||
},
|
||||
enabled,
|
||||
);
|
||||
}
|
||||
45
edge-ai-platform/frontend/src/hooks/use-resolved-params.ts
Normal file
45
edge-ai-platform/frontend/src/hooks/use-resolved-params.ts
Normal file
@ -0,0 +1,45 @@
|
||||
'use client';
|
||||
|
||||
import { useParams } from 'next/navigation';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
/**
|
||||
* Wraps useParams() to resolve placeholder values from generateStaticParams.
|
||||
*
|
||||
* Next.js static export pre-renders dynamic routes with a placeholder (e.g. '_').
|
||||
* When nginx SPA-fallback serves the root index.html for a dynamic URL like
|
||||
* /devices/kl720-0, useParams() initially returns the placeholder value from
|
||||
* the RSC payload instead of the actual URL segment.
|
||||
*
|
||||
* This hook detects that case and extracts the real param from window.location.
|
||||
*/
|
||||
export function useResolvedParams(): Record<string, string> {
|
||||
const params = useParams();
|
||||
|
||||
return useMemo(() => {
|
||||
const resolved: Record<string, string> = {};
|
||||
const pathSegments =
|
||||
typeof window !== 'undefined'
|
||||
? window.location.pathname.replace(/\/+$/, '').split('/')
|
||||
: [];
|
||||
|
||||
for (const [key, value] of Object.entries(params)) {
|
||||
if (typeof value === 'string' && value === '_' && pathSegments.length > 0) {
|
||||
// Resolve from URL: find the segment after the route prefix.
|
||||
// e.g. /devices/kl720-0 → ['', 'devices', 'kl720-0']
|
||||
// /models/yolov5 → ['', 'models', 'yolov5']
|
||||
// /workspace/kl720-0 → ['', 'workspace', 'kl720-0']
|
||||
// /workspace/cluster/c1 → ['', 'workspace', 'cluster', 'c1']
|
||||
// The dynamic param is always the last non-empty segment.
|
||||
const lastSegment = pathSegments[pathSegments.length - 1];
|
||||
resolved[key] = lastSegment || value;
|
||||
} else if (typeof value === 'string') {
|
||||
resolved[key] = value;
|
||||
} else if (Array.isArray(value)) {
|
||||
resolved[key] = value.join('/');
|
||||
}
|
||||
}
|
||||
|
||||
return resolved;
|
||||
}, [params]);
|
||||
}
|
||||
72
edge-ai-platform/frontend/src/hooks/use-server-health.ts
Normal file
72
edge-ai-platform/frontend/src/hooks/use-server-health.ts
Normal file
@ -0,0 +1,72 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { api, getRelayHeaders } from '@/lib/api';
|
||||
import { getApiBaseUrl } from '@/lib/constants';
|
||||
import type { ServerMetrics, Dependency } from '@/types/server-health';
|
||||
|
||||
export type RestartState = 'idle' | 'restarting' | 'waiting' | 'back';
|
||||
|
||||
export function useServerHealth(pollIntervalMs = 5000) {
|
||||
const [metrics, setMetrics] = useState<ServerMetrics | null>(null);
|
||||
const [deps, setDeps] = useState<Dependency[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [connected, setConnected] = useState(false);
|
||||
const [restartState, setRestartState] = useState<RestartState>('idle');
|
||||
|
||||
const fetchAll = useCallback(async () => {
|
||||
try {
|
||||
const [metricsRes, depsRes] = await Promise.all([
|
||||
api.get<ServerMetrics>('/system/metrics'),
|
||||
api.get<{ deps: Dependency[] }>('/system/deps'),
|
||||
]);
|
||||
if (metricsRes.success && metricsRes.data) {
|
||||
setMetrics(metricsRes.data);
|
||||
setConnected(true);
|
||||
}
|
||||
if (depsRes.success && depsRes.data) setDeps(depsRes.data.deps || []);
|
||||
} catch {
|
||||
setConnected(false);
|
||||
setMetrics(null);
|
||||
}
|
||||
setLoading(false);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchAll();
|
||||
const id = setInterval(fetchAll, pollIntervalMs);
|
||||
return () => clearInterval(id);
|
||||
}, [fetchAll, pollIntervalMs]);
|
||||
|
||||
// Poll health until server comes back after restart
|
||||
useEffect(() => {
|
||||
if (restartState !== 'waiting') return;
|
||||
const id = setInterval(async () => {
|
||||
try {
|
||||
const res = await fetch(`${getApiBaseUrl()}/system/health`, { headers: getRelayHeaders() });
|
||||
const data = await res.json();
|
||||
if (data.status === 'ok') {
|
||||
setRestartState('back');
|
||||
fetchAll();
|
||||
setTimeout(() => setRestartState('idle'), 3000);
|
||||
}
|
||||
} catch {
|
||||
// Server still down, keep waiting
|
||||
}
|
||||
}, 1000);
|
||||
return () => clearInterval(id);
|
||||
}, [restartState, fetchAll]);
|
||||
|
||||
const triggerRestart = useCallback(async () => {
|
||||
setRestartState('restarting');
|
||||
try {
|
||||
await api.post('/system/restart');
|
||||
setRestartState('waiting');
|
||||
} catch {
|
||||
// Network error means server shut down before response — still start waiting
|
||||
setRestartState('waiting');
|
||||
}
|
||||
}, []);
|
||||
|
||||
return { metrics, deps, loading, connected, restartState, triggerRestart, refetch: fetchAll };
|
||||
}
|
||||
25
edge-ai-platform/frontend/src/hooks/use-server-logs.ts
Normal file
25
edge-ai-platform/frontend/src/hooks/use-server-logs.ts
Normal file
@ -0,0 +1,25 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useCallback } from 'react';
|
||||
import { useWebSocket } from './use-websocket';
|
||||
import type { ServerLogEntry } from '@/types/server-log';
|
||||
|
||||
const MAX_LOGS = 1000;
|
||||
|
||||
export function useServerLogs(enabled = true) {
|
||||
const [logs, setLogs] = useState<ServerLogEntry[]>([]);
|
||||
|
||||
const handleMessage = useCallback((data: unknown) => {
|
||||
const entry = data as ServerLogEntry;
|
||||
setLogs((prev) => {
|
||||
const next = [...prev, entry];
|
||||
return next.length > MAX_LOGS ? next.slice(-MAX_LOGS) : next;
|
||||
});
|
||||
}, []);
|
||||
|
||||
useWebSocket('/ws/server-logs', handleMessage, enabled);
|
||||
|
||||
const clearLogs = useCallback(() => setLogs([]), []);
|
||||
|
||||
return { logs, clearLogs };
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user