@flame0510/project-aether 1.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +150 -0
- package/agent-templates/README.md +37 -0
- package/agent-templates/argus/AGENTS.md +52 -0
- package/agent-templates/argus/IDENTITY.md +7 -0
- package/agent-templates/argus/MEMORY.md +9 -0
- package/agent-templates/argus/SOUL.md +24 -0
- package/agent-templates/argus/TOOLS.md +8 -0
- package/agent-templates/atlas/AGENTS.md +47 -0
- package/agent-templates/atlas/HEARTBEAT.md +10 -0
- package/agent-templates/atlas/IDENTITY.md +6 -0
- package/agent-templates/atlas/MEMORY.md +9 -0
- package/agent-templates/atlas/SOUL.md +21 -0
- package/agent-templates/atlas/TOOLS.md +4 -0
- package/agent-templates/base-image/.trigger +0 -0
- package/agent-templates/base-image/Dockerfile +90 -0
- package/agent-templates/base-image/entrypoint.sh +37 -0
- package/agent-templates/custom/AGENTS.md +29 -0
- package/agent-templates/custom/BOOTSTRAP.md +56 -0
- package/agent-templates/custom/MEMORY.md +8 -0
- package/agent-templates/prometheus/AGENTS.md +37 -0
- package/agent-templates/prometheus/IDENTITY.md +6 -0
- package/agent-templates/prometheus/MEMORY.md +9 -0
- package/agent-templates/prometheus/SOUL.md +21 -0
- package/agent-templates/prometheus/TOOLS.md +4 -0
- package/app/agents/ChannelManager.tsx +465 -0
- package/app/agents/ImageDownloadBanner.tsx +159 -0
- package/app/agents/PageClient.tsx +1285 -0
- package/app/agents/create/PageClient.tsx +437 -0
- package/app/agents/create/page.tsx +126 -0
- package/app/agents/loading.tsx +14 -0
- package/app/agents/page.tsx +5 -0
- package/app/api/agents/[id]/backup/route.ts +169 -0
- package/app/api/agents/[id]/channels/pairing/route.ts +69 -0
- package/app/api/agents/[id]/channels/route.ts +14 -0
- package/app/api/agents/[id]/channels/telegram/route.ts +50 -0
- package/app/api/agents/[id]/lifecycle/route.ts +94 -0
- package/app/api/agents/[id]/recreate/route.ts +199 -0
- package/app/api/agents/[id]/restart/route.ts +33 -0
- package/app/api/agents/[id]/restore/route.ts +81 -0
- package/app/api/agents/[id]/route.ts +280 -0
- package/app/api/agents/channels-summary/route.ts +39 -0
- package/app/api/agents/config-json/route.ts +58 -0
- package/app/api/agents/create/route.ts +488 -0
- package/app/api/agents/download-image/route.ts +32 -0
- package/app/api/agents/image-status/route.ts +126 -0
- package/app/api/agents/route.ts +213 -0
- package/app/api/agents/token/route.ts +94 -0
- package/app/api/agents-active/route.ts +190 -0
- package/app/api/agents-config/route.ts +629 -0
- package/app/api/alerts/smoke/route.ts +26 -0
- package/app/api/aliases/add/route.ts +28 -0
- package/app/api/aliases/remove/route.ts +27 -0
- package/app/api/assistant/route.ts +204 -0
- package/app/api/auth/check/route.ts +38 -0
- package/app/api/auth/login/route.ts +85 -0
- package/app/api/auth/logout/route.ts +7 -0
- package/app/api/auth/status/route.ts +33 -0
- package/app/api/config/env/route.ts +132 -0
- package/app/api/config/restart/route.ts +26 -0
- package/app/api/containers/route.ts +75 -0
- package/app/api/cost-override/route.ts +46 -0
- package/app/api/costs/route.ts +84 -0
- package/app/api/credentials/[id]/reveal/route.ts +21 -0
- package/app/api/credentials/[id]/route.ts +52 -0
- package/app/api/credentials/[id]/sync/route.ts +58 -0
- package/app/api/credentials/detect/route.ts +246 -0
- package/app/api/credentials/route.ts +33 -0
- package/app/api/crons/[id]/route.ts +69 -0
- package/app/api/crons/route.ts +12 -0
- package/app/api/crons/runs/route.ts +31 -0
- package/app/api/debug/route.ts +11 -0
- package/app/api/envcheck/route.ts +18 -0
- package/app/api/events/route.ts +24 -0
- package/app/api/gateway/agent/route.ts +154 -0
- package/app/api/gateway/provider/balance/route.ts +38 -0
- package/app/api/gateway/provider/keys.ts +38 -0
- package/app/api/gateway/provider/oauth/route.ts +304 -0
- package/app/api/gateway/provider/route.ts +209 -0
- package/app/api/gateway/route.ts +223 -0
- package/app/api/gateway/sync.ts +189 -0
- package/app/api/lineage/route.ts +54 -0
- package/app/api/memory-context/route.ts +15 -0
- package/app/api/metrics/route.ts +35 -0
- package/app/api/models/route.ts +77 -0
- package/app/api/plugins/route.js +37 -0
- package/app/api/provider/upstream.ts +142 -0
- package/app/api/provider/v1/chat/completions/route.ts +146 -0
- package/app/api/provider/v1/models/route.ts +167 -0
- package/app/api/provider-usage/route.ts +629 -0
- package/app/api/session/route.ts +39 -0
- package/app/api/sessions/[id]/route.ts +38 -0
- package/app/api/sessions/route.ts +23 -0
- package/app/api/setup/agent-image/route.ts +102 -0
- package/app/api/setup/password/route.ts +111 -0
- package/app/api/setup/restart/route.ts +76 -0
- package/app/api/skills/delete/route.js +105 -0
- package/app/api/skills/promote/route.js +129 -0
- package/app/api/skills/route.js +203 -0
- package/app/api/skills/save/route.js +142 -0
- package/app/api/stats/route.ts +34 -0
- package/app/api/stats-since/route.ts +20 -0
- package/app/api/stream/route.ts +70 -0
- package/app/api/system-health/route.ts +233 -0
- package/app/api/tool-calls/route.ts +24 -0
- package/app/api/tools-config/route.ts +163 -0
- package/app/api/update-check/route.ts +127 -0
- package/app/api/version/route.ts +25 -0
- package/app/api/wizard/complete/route.ts +32 -0
- package/app/api/wizard/reset/route.ts +28 -0
- package/app/api/wizard/status/route.ts +28 -0
- package/app/api/workspace/route.ts +392 -0
- package/app/api/workspace/stream/route.ts +136 -0
- package/app/components/AppShell.tsx +33 -0
- package/app/components/AuthGuard.tsx +91 -0
- package/app/components/CostBreakdown.tsx +37 -0
- package/app/components/DashboardHeader.tsx +73 -0
- package/app/components/DashboardLayout.tsx +76 -0
- package/app/components/DashboardToolbar.tsx +61 -0
- package/app/components/FloatingActions.tsx +33 -0
- package/app/components/Icons.tsx +78 -0
- package/app/components/LineageGraphPage.tsx +142 -0
- package/app/components/LiveFeed.tsx +48 -0
- package/app/components/MobileBottomNav.tsx +84 -0
- package/app/components/ModelPickerModal.tsx +94 -0
- package/app/components/PasswordInput.tsx +86 -0
- package/app/components/PulseChat.tsx +362 -0
- package/app/components/Rev4aLoader.tsx +48 -0
- package/app/components/SessionDrawer.tsx +263 -0
- package/app/components/SessionTopology.tsx +289 -0
- package/app/components/Sidebar.tsx +294 -0
- package/app/components/Skeleton.tsx +133 -0
- package/app/components/SystemCockpit.tsx +169 -0
- package/app/components/VersionBanner.tsx +105 -0
- package/app/components/WizardButton.tsx +30 -0
- package/app/components/ui/Badge.tsx +30 -0
- package/app/components/ui/Button.tsx +59 -0
- package/app/components/ui/ConfirmModal.tsx +46 -0
- package/app/components/ui/FilterBar.tsx +33 -0
- package/app/components/ui/Input.tsx +25 -0
- package/app/components/ui/ItemList.tsx +83 -0
- package/app/components/ui/LoadingSpinner.tsx +30 -0
- package/app/components/ui/Metric.tsx +22 -0
- package/app/components/ui/Modal.tsx +42 -0
- package/app/components/ui/Page.tsx +18 -0
- package/app/components/ui/Pill.tsx +6 -0
- package/app/components/ui/PropertyList.tsx +24 -0
- package/app/components/ui/Select.tsx +26 -0
- package/app/components/ui/StatusCard.tsx +32 -0
- package/app/components/ui/Surface.tsx +14 -0
- package/app/components/ui/Tabs.tsx +55 -0
- package/app/components/ui/TemplateOption.tsx +59 -0
- package/app/components/ui/Toast.tsx +44 -0
- package/app/components/ui/index.ts +19 -0
- package/app/components/ui/tokens.ts +18 -0
- package/app/config/PageClient.tsx +293 -0
- package/app/config/loading.tsx +10 -0
- package/app/config/page.tsx +7 -0
- package/app/containers/ContainersClient.tsx +129 -0
- package/app/containers/loading.tsx +21 -0
- package/app/containers/page.tsx +5 -0
- package/app/containers/terminal/[id]/TerminalClient.tsx +313 -0
- package/app/containers/terminal/[id]/page.tsx +6 -0
- package/app/credentials/PageClient.tsx +598 -0
- package/app/credentials/loading.tsx +10 -0
- package/app/credentials/page.tsx +7 -0
- package/app/crons/PageClient.tsx +538 -0
- package/app/crons/loading.tsx +10 -0
- package/app/crons/page.tsx +5 -0
- package/app/design-system.ts +57 -0
- package/app/gateway/PageClient.tsx +1048 -0
- package/app/gateway/loading.tsx +24 -0
- package/app/gateway/page.tsx +5 -0
- package/app/globals.css +1474 -0
- package/app/layout.tsx +45 -0
- package/app/lib/models-context.tsx +41 -0
- package/app/lineage/loading.tsx +10 -0
- package/app/lineage/page.tsx +13 -0
- package/app/loading.tsx +16 -0
- package/app/login/page.tsx +160 -0
- package/app/memory/MemoryContextPageClient.tsx +196 -0
- package/app/memory/loading.tsx +10 -0
- package/app/memory/page.tsx +8 -0
- package/app/page.tsx +31 -0
- package/app/plugins/PageClient.tsx +296 -0
- package/app/plugins/loading.tsx +10 -0
- package/app/plugins/page.tsx +5 -0
- package/app/setup/PageClient.tsx +227 -0
- package/app/setup/loading.tsx +21 -0
- package/app/setup/page.tsx +7 -0
- package/app/skills/PageClient.tsx +499 -0
- package/app/skills/loading.tsx +10 -0
- package/app/skills/page.tsx +5 -0
- package/app/tools/ToolsPageClient.tsx +308 -0
- package/app/tools/loading.tsx +10 -0
- package/app/tools/page.tsx +62 -0
- package/app/tools/tools-catalog.ts +141 -0
- package/app/wizard/PageClient.tsx +485 -0
- package/app/wizard/icons.tsx +89 -0
- package/app/wizard/loading.tsx +24 -0
- package/app/wizard/page.tsx +7 -0
- package/app/wizard/storage.ts +33 -0
- package/app/wizard/useWizard.ts +101 -0
- package/app/workspace/WorkspaceClient.tsx +633 -0
- package/app/workspace/loading.tsx +36 -0
- package/app/workspace/page.tsx +8 -0
- package/bin/docker-entrypoint.sh +21 -0
- package/bin/postinstall.js +20 -0
- package/bin/rev4a.js +696 -0
- package/daemon.js +783 -0
- package/docs/ARCHITECTURE.md +557 -0
- package/docs/CONTAINER-TERMINAL.md +280 -0
- package/docs/DESIGN-SYSTEM.md +99 -0
- package/docs/FRONTEND-ARCHITECTURE.md +119 -0
- package/docs/REV4A.md +504 -0
- package/docs/dev/API-REFERENCE.md +1835 -0
- package/docs/dev/DATABASE.md +224 -0
- package/docs/dev/GATEWAY.md +300 -0
- package/docs/dev/PROVIDERS.md +229 -0
- package/docs/dev/SESSION-MAINTENANCE-PLAN.md +607 -0
- package/docs/dev/WORKSPACE.md +199 -0
- package/docs/rag/DATA-FRESHNESS.md +109 -0
- package/docs/rag/GLOSSARY.md +125 -0
- package/docs/rag/REV4A-OVERVIEW.md +135 -0
- package/docs/rag/WHAT-I-CAN-ANSWER.md +124 -0
- package/lib/agent-setup.ts +130 -0
- package/lib/alerts.ts +115 -0
- package/lib/apiFetch.ts +7 -0
- package/lib/auth.ts +28 -0
- package/lib/billing.ts +100 -0
- package/lib/buildAgentImage.ts +346 -0
- package/lib/channelManager.ts +386 -0
- package/lib/container.ts +60 -0
- package/lib/credentials/db.ts +86 -0
- package/lib/credentials/delivery.ts +448 -0
- package/lib/credentials/detect.ts +149 -0
- package/lib/credentials/hash.ts +9 -0
- package/lib/credentials/providers.ts +110 -0
- package/lib/credentials/vault.ts +195 -0
- package/lib/db-bootstrap.d.ts +3 -0
- package/lib/db-bootstrap.mjs +144 -0
- package/lib/db.ts +25 -0
- package/lib/docker-utils.ts +60 -0
- package/lib/hooks/useDashboard.ts +264 -0
- package/lib/hooks/useRev4aTimezone.ts +28 -0
- package/lib/hooks/useScreenshot.ts +30 -0
- package/lib/memory-context.ts +385 -0
- package/lib/model-catalogue.ts +131 -0
- package/lib/model-pricing.ts +63 -0
- package/lib/openclaw-cron.ts +350 -0
- package/lib/patterns/ApiAdapter.ts +73 -0
- package/lib/patterns/ApiClient.ts +65 -0
- package/lib/patterns/EventBus.ts +113 -0
- package/lib/patterns/FilterStrategy.ts +79 -0
- package/lib/patterns/SessionFactory.ts +117 -0
- package/lib/patterns/sessionPresentation.ts +117 -0
- package/lib/provider-balance.ts +163 -0
- package/lib/requireAuth.tsx +38 -0
- package/lib/rev4a-auth.d.ts +3 -0
- package/lib/rev4a-auth.js +36 -0
- package/lib/rev4a-paths.ts +145 -0
- package/lib/timezone.ts +46 -0
- package/lib/types/index.ts +96 -0
- package/lib/utils/format.ts +82 -0
- package/lineage.js +56 -0
- package/model-pricing.json +482 -0
- package/models.config.json +844 -0
- package/next-env.d.ts +6 -0
- package/next.config.mjs +7 -0
- package/package.json +82 -0
- package/public/apple-touch-icon.png +0 -0
- package/public/favicon-64.png +0 -0
- package/public/favicon.svg +58 -0
- package/public/icon-192-maskable.png +0 -0
- package/public/icon-192.png +0 -0
- package/public/icon-512-maskable.png +0 -0
- package/public/icon-512.png +0 -0
- package/public/manifest.json +38 -0
- package/public/rev4a-logo.png +0 -0
- package/public/rev4a-logo.svg +58 -0
- package/rev4a-rules/AGENTS.md +37 -0
- package/scripts/add-auth.cjs +185 -0
- package/scripts/backup.sh +66 -0
- package/scripts/check-providers.mjs +143 -0
- package/scripts/docker/traefik/docker-compose.yml +32 -0
- package/scripts/docker/traefik/dynamic/.gitkeep +18 -0
- package/scripts/docker/traefik/traefik.yml +37 -0
- package/scripts/remove-auth-profile.js +56 -0
- package/scripts/restore.sh +82 -0
- package/terminal-ws-server.js +139 -0
- package/tsconfig.json +42 -0
|
@@ -0,0 +1,633 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { Button } from '../components/ui';
|
|
5
|
+
import { Skeleton, TreeSkeleton, CodeSkeleton } from '../components/Skeleton';
|
|
6
|
+
import { apiFetch } from '@/lib/apiFetch';
|
|
7
|
+
|
|
8
|
+
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
9
|
+
interface TreeEntry {
|
|
10
|
+
path: string;
|
|
11
|
+
relPath: string;
|
|
12
|
+
name: string;
|
|
13
|
+
type: 'file' | 'directory';
|
|
14
|
+
size: number;
|
|
15
|
+
mtimeMs: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface WorkspaceInfo {
|
|
19
|
+
id: string;
|
|
20
|
+
label: string;
|
|
21
|
+
type: 'host' | 'container';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type SaveState = 'idle' | 'saving' | 'saved' | 'error';
|
|
25
|
+
|
|
26
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
27
|
+
const EXT_LANG: Record<string, string> = {
|
|
28
|
+
'.md': 'markdown', '.ts': 'typescript', '.tsx': 'typescript',
|
|
29
|
+
'.js': 'javascript', '.json': 'json', '.sh': 'bash',
|
|
30
|
+
'.py': 'python', '.css': 'css', '.html': 'html',
|
|
31
|
+
'.yaml': 'yaml', '.yml': 'yaml', '.txt': 'text', '.env': 'env',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function extOf(name: string) { return name.slice(name.lastIndexOf('.')).toLowerCase(); }
|
|
35
|
+
function isMarkdown(name: string) { return extOf(name) === '.md'; }
|
|
36
|
+
function isPdfExt(name: string): boolean {
|
|
37
|
+
return name.slice(name.lastIndexOf('.')).toLowerCase() === '.pdf';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function isBinaryExt(name: string): boolean {
|
|
41
|
+
const ext = name.slice(name.lastIndexOf('.')).toLowerCase();
|
|
42
|
+
return ['.png','.jpg','.jpeg','.gif','.webp','.svg','.pdf','.ico'].includes(ext);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function fmtSize(bytes: number) {
|
|
46
|
+
if (bytes < 1024) return `${bytes}B`;
|
|
47
|
+
if (bytes < 1048576) return `${(bytes / 1024).toFixed(1)}KB`;
|
|
48
|
+
return `${(bytes / 1048576).toFixed(1)}MB`;
|
|
49
|
+
}
|
|
50
|
+
function fmtDate(ms: number) {
|
|
51
|
+
const d = new Date(ms);
|
|
52
|
+
return `${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,'0')}-${String(d.getDate()).padStart(2,'0')} ${String(d.getHours()).padStart(2,'0')}:${String(d.getMinutes()).padStart(2,'0')}`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ─── File type icon SVGs ──────────────────────────────────────────────────────
|
|
56
|
+
const COPPER = 'var(--violet)'; // #b8860b-ish
|
|
57
|
+
|
|
58
|
+
function FolderIcon({ expanded }: { expanded: boolean }) {
|
|
59
|
+
return (
|
|
60
|
+
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" style={{ flexShrink: 0 }}>
|
|
61
|
+
{expanded ? (
|
|
62
|
+
<>
|
|
63
|
+
<path d="M1.6 4a1.2 1.2 0 0 1 1.2-1.2H6l.8 1h4.4a1.2 1.2 0 0 1 1.2 1.2v5.8a1.2 1.2 0 0 1-1.2 1.2H2.8A1.2 1.2 0 0 1 1.6 10V4Z" fill={COPPER} stroke={COPPER} strokeWidth="0.3" strokeLinejoin="round" opacity="0.85"/>
|
|
64
|
+
<line x1="1.6" y1="5.5" x2="12.4" y2="5.5" stroke="#0A0A0B" strokeWidth="0.8"/>
|
|
65
|
+
</>
|
|
66
|
+
) : (
|
|
67
|
+
<>
|
|
68
|
+
<path d="M1.6 4a1.2 1.2 0 0 1 1.2-1.2H6l.8 1h4.4a1.2 1.2 0 0 1 1.2 1.2v5.8a1.2 1.2 0 0 1-1.2 1.2H2.8A1.2 1.2 0 0 1 1.6 10V4Z" fill={COPPER} stroke={COPPER} strokeWidth="0.3" strokeLinejoin="round" opacity="0.85"/>
|
|
69
|
+
</>
|
|
70
|
+
)}
|
|
71
|
+
</svg>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function FileIcon({ name, size }: { name: string; size?: number }) {
|
|
76
|
+
const ext = name.slice(name.lastIndexOf('.')).toLowerCase();
|
|
77
|
+
const s = size ?? 12;
|
|
78
|
+
const color = '#888';
|
|
79
|
+
const mono = (p: string) => <path d={p} stroke={color} strokeWidth="1.2" fill="none" strokeLinejoin="round"/>;
|
|
80
|
+
const dim = { width: s, height: s, viewBox: `0 0 ${s} ${s}`, fill: 'none', stroke: color, strokeWidth: '1.2', style: { flexShrink: 0, opacity: 0.5 } as React.CSSProperties };
|
|
81
|
+
const doc = <svg {...dim}><path d="M1 1h7L11 4v9H1z" strokeLinejoin="round"/><path d="M8 1v3h3" strokeLinejoin="round"/></svg>;
|
|
82
|
+
switch (ext) {
|
|
83
|
+
case '.md': return <svg {...dim}><path d="M1 1h7L11 4v9H1z" strokeLinejoin="round"/><path d="M8 1v3h3" strokeLinejoin="round"/><path d="M3 7h5M3 9h3" strokeLinecap="round"/></svg>;
|
|
84
|
+
case '.ts':
|
|
85
|
+
case '.tsx': return <svg {...dim}>{mono('M1 1h7L11 4v9H1z')}{mono('M8 1v3h3')}<text x="2.5" y="9" fontSize="5" fill="#3178c6" stroke="none" fontWeight="bold">TS</text></svg>;
|
|
86
|
+
case '.js': return <svg {...dim}>{mono('M1 1h7L11 4v9H1z')}{mono('M8 1v3h3')}<text x="2.5" y="9" fontSize="5" fill="#f7df1e" stroke="none" fontWeight="bold">JS</text></svg>;
|
|
87
|
+
case '.json': return <svg {...dim}>{mono('M1 1h7L11 4v9H1z')}{mono('M8 1v3h3')}<text x="2" y="9" fontSize="5" fill="#ecc" stroke="none">{'{ }'}</text></svg>;
|
|
88
|
+
case '.sh': return <svg {...dim}>{mono('M1 1h7L11 4v9H1z')}{mono('M8 1v3h3')}<line x1="4" y1="5" x2="7" y2="10" stroke={color} strokeWidth="1"/><line x1="7" y1="5" x2="4" y2="10" stroke={color} strokeWidth="1"/></svg>;
|
|
89
|
+
case '.py': return <svg {...dim}>{mono('M1 1h7L11 4v9H1z')}{mono('M8 1v3h3')}<rect x="3" y="6" width="5" height="4" rx="0.5" stroke={color} strokeWidth="0.8" fill="none"/></svg>;
|
|
90
|
+
case '.css': return <svg {...dim}>{mono('M1 1h7L11 4v9H1z')}{mono('M8 1v3h3')}<path d="M9 9l2-3H4l1 3z" fill="#264de4" stroke="none"/></svg>;
|
|
91
|
+
case '.html': return <svg {...dim}>{mono('M1 1h7L11 4v9H1z')}{mono('M8 1v3h3')}<path d="M3 7l1 3 1-3" stroke={color} strokeWidth="0.8" fill="none"/></svg>;
|
|
92
|
+
case '.pdf': return <svg {...dim}>{mono('M1 1h7L11 4v9H1z')}{mono('M8 1v3h3')}<rect x="2.5" y="6" width="6" height="4.5" rx="0.3" fill="#ef4444" stroke="none" opacity="0.6"/></svg>;
|
|
93
|
+
case '.png': case '.jpg': case '.jpeg': case '.gif': case '.webp': case '.svg':
|
|
94
|
+
return <svg {...dim}>{mono('M1 1h7L11 4v9H1z')}{mono('M8 1v3h3')}<circle cx="5" cy="7" r="2" fill={color} opacity="0.4" stroke="none"/><path d="M3 11l3-3 3 3" stroke={color} strokeWidth="0.8" fill="none"/></svg>;
|
|
95
|
+
case '.yaml': case '.yml': return <svg {...dim}>{mono('M1 1h7L11 4v9H1z')}{mono('M8 1v3h3')}<line x1="3" y1="7" x2="8" y2="7" stroke={color} strokeWidth="0.8"/><line x1="3" y1="9" x2="6" y2="9" stroke={color} strokeWidth="0.8"/></svg>;
|
|
96
|
+
case '.env': return <svg {...dim}>{mono('M1 1h7L11 4v9H1z')}{mono('M8 1v3h3')}<text x="3" y="9" fontSize="5" fill="#ffa" stroke="none">.env</text></svg>;
|
|
97
|
+
case '.txt': return <svg {...dim}>{mono('M1 1h7L11 4v9H1z')}{mono('M8 1v3h3')}<rect x="3" y="7" width="5" height="0.8" fill={color} opacity="0.5" stroke="none"/><rect x="3" y="9" width="5" height="0.8" fill={color} opacity="0.5" stroke="none"/></svg>;
|
|
98
|
+
default: return doc;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ─── Tree helpers ─────────────────────────────────────────────────────────────
|
|
103
|
+
interface TreeNode {
|
|
104
|
+
name: string;
|
|
105
|
+
relPath: string;
|
|
106
|
+
absPath: string;
|
|
107
|
+
type: 'file' | 'directory';
|
|
108
|
+
size: number;
|
|
109
|
+
mtimeMs: number;
|
|
110
|
+
children: TreeNode[];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function buildTree(entries: TreeEntry[]): TreeNode[] {
|
|
114
|
+
const root: TreeNode[] = [];
|
|
115
|
+
const map = new Map<string, TreeNode>();
|
|
116
|
+
|
|
117
|
+
for (const e of entries) {
|
|
118
|
+
const node: TreeNode = { name: e.name, relPath: e.relPath, absPath: e.path, type: e.type, size: e.size, mtimeMs: e.mtimeMs, children: [] };
|
|
119
|
+
map.set(e.relPath, node);
|
|
120
|
+
const parentPath = e.relPath.includes('/') ? e.relPath.slice(0, e.relPath.lastIndexOf('/')) : null;
|
|
121
|
+
if (parentPath && map.has(parentPath)) {
|
|
122
|
+
map.get(parentPath)!.children.push(node);
|
|
123
|
+
} else {
|
|
124
|
+
root.push(node);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return root;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ─── Markdown Renderer ────────────────────────────────────────────────────────
|
|
131
|
+
function renderMarkdown(text: string): string {
|
|
132
|
+
return text
|
|
133
|
+
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
|
134
|
+
.replace(/^#{6}\s+(.*)$/gm, '<h6>$1</h6>')
|
|
135
|
+
.replace(/^#{5}\s+(.*)$/gm, '<h5>$1</h5>')
|
|
136
|
+
.replace(/^#{4}\s+(.*)$/gm, '<h4>$1</h4>')
|
|
137
|
+
.replace(/^#{3}\s+(.*)$/gm, '<h3>$1</h3>')
|
|
138
|
+
.replace(/^#{2}\s+(.*)$/gm, '<h2>$1</h2>')
|
|
139
|
+
.replace(/^#{1}\s+(.*)$/gm, '<h1>$1</h1>')
|
|
140
|
+
.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
|
|
141
|
+
.replace(/\*(.+?)\*/g, '<em>$1</em>')
|
|
142
|
+
.replace(/`([^`]+)`/g, '<code>$1</code>')
|
|
143
|
+
.replace(/^```[\w]*\n?([\s\S]*?)```/gm, '<pre><code>$1</code></pre>')
|
|
144
|
+
.replace(/^---$/gm, '<hr/>')
|
|
145
|
+
.replace(/^\s*[-*]\s+(.*)$/gm, '<li>$1</li>')
|
|
146
|
+
.replace(/^\s*\d+\.\s+(.*)$/gm, '<li>$1</li>')
|
|
147
|
+
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2" target="_blank" rel="noreferrer">$1</a>')
|
|
148
|
+
.replace(/\n\n/g, '</p><p>')
|
|
149
|
+
.replace(/^(?!<[hHpPlLiIpPhRrC])/gm, '')
|
|
150
|
+
.split('\n').map(line => line.match(/^<(h[1-6]|li|pre|hr|\/p|p>)/) ? line : line || '').join('\n')
|
|
151
|
+
;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ─── Flatten tree into linear list for keyboard nav ───────────────────────────
|
|
155
|
+
interface FlatItem {
|
|
156
|
+
node: TreeNode;
|
|
157
|
+
depth: number;
|
|
158
|
+
visible: boolean;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function flattenTree(tree: TreeNode[], expanded: Set<string>): FlatItem[] {
|
|
162
|
+
const result: FlatItem[] = [];
|
|
163
|
+
function walk(nodes: TreeNode[], depth: number) {
|
|
164
|
+
for (const n of nodes) {
|
|
165
|
+
result.push({ node: n, depth, visible: true });
|
|
166
|
+
if (n.type === 'directory' && expanded.has(n.relPath)) {
|
|
167
|
+
walk(n.children, depth + 1);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
walk(tree, 0);
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// ─── TreeNodeRow ──────────────────────────────────────────────────────────────
|
|
176
|
+
function TreeNodeRow({
|
|
177
|
+
node, depth, selected, expanded, onToggle, onSelect,
|
|
178
|
+
id, focused,
|
|
179
|
+
}: {
|
|
180
|
+
node: TreeNode; depth: number; selected: string | null;
|
|
181
|
+
expanded: Set<string>; onToggle: (path: string, node?: TreeNode) => void; onSelect: (node: TreeNode) => void;
|
|
182
|
+
id?: string; focused?: boolean;
|
|
183
|
+
}) {
|
|
184
|
+
const isDir = node.type === 'directory';
|
|
185
|
+
const isExp = expanded.has(node.relPath);
|
|
186
|
+
const isSelected = selected === node.absPath;
|
|
187
|
+
const indent = depth * 14;
|
|
188
|
+
|
|
189
|
+
return (
|
|
190
|
+
<div
|
|
191
|
+
id={id}
|
|
192
|
+
tabIndex={-1}
|
|
193
|
+
onClick={() => isDir ? onToggle(node.relPath, node) : onSelect(node)}
|
|
194
|
+
style={{
|
|
195
|
+
display: 'flex', alignItems: 'center', gap: 6, padding: `3px 8px 3px ${8 + indent}px`,
|
|
196
|
+
cursor: 'pointer', userSelect: 'none', outline: 'none',
|
|
197
|
+
background: isSelected ? '#1a1030' : 'transparent',
|
|
198
|
+
color: isSelected ? 'var(--violet)' : isDir ? '#aaa' : '#ccc',
|
|
199
|
+
fontSize: 11, fontFamily: 'var(--font-mono-stack)',
|
|
200
|
+
borderLeft: isSelected ? '2px solid var(--violet)' : focused ? '2px solid #555' : '2px solid transparent',
|
|
201
|
+
transition: 'background 0.1s',
|
|
202
|
+
}}
|
|
203
|
+
onMouseEnter={(e) => { if (!isSelected && !focused) (e.currentTarget as HTMLElement).style.background = '#111'; }}
|
|
204
|
+
onMouseLeave={(e) => { if (!isSelected && !focused) (e.currentTarget as HTMLElement).style.background = 'transparent'; }}
|
|
205
|
+
>
|
|
206
|
+
{isDir ? (
|
|
207
|
+
<svg width="10" height="10" viewBox="0 0 10 10" fill={COPPER} style={{ flexShrink: 0, transition: 'transform 0.15s', transform: isExp ? 'rotate(90deg)' : 'none', opacity: 0.7 }}>
|
|
208
|
+
<path d="M3 2l4 3-4 3z"/>
|
|
209
|
+
</svg>
|
|
210
|
+
) : (
|
|
211
|
+
<span style={{ width: 10, flexShrink: 0 }} />
|
|
212
|
+
)}
|
|
213
|
+
{isDir ? (
|
|
214
|
+
<FolderIcon expanded={isExp} />
|
|
215
|
+
) : (
|
|
216
|
+
<FileIcon name={node.name} />
|
|
217
|
+
)}
|
|
218
|
+
<span style={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{node.name}</span>
|
|
219
|
+
{!isDir && node.size > 0 && (
|
|
220
|
+
<span style={{ marginLeft: 'auto', color: '#555', fontSize: 10, flexShrink: 0 }}>{fmtSize(node.size)}</span>
|
|
221
|
+
)}
|
|
222
|
+
</div>
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// ─── Main component ───────────────────────────────────────────────────────────
|
|
227
|
+
export default function WorkspaceClient() {
|
|
228
|
+
const [tree, setTree] = useState<TreeNode[]>([]);
|
|
229
|
+
const [treeLoading, setTreeLoading] = useState(true);
|
|
230
|
+
const [expanded, setExpanded] = useState<Set<string>>(new Set(['workspace-ops', 'workspace-prometheus', 'workspace-atlas', 'workspace']));
|
|
231
|
+
const [selectedPath, setSelectedPath] = useState<string | null>(null);
|
|
232
|
+
const [selectedNode, setSelectedNode] = useState<TreeNode | null>(null);
|
|
233
|
+
const [fileContent, setFileContent] = useState('');
|
|
234
|
+
const [fileLoading, setFileLoading] = useState(false);
|
|
235
|
+
const [editContent, setEditContent] = useState('');
|
|
236
|
+
const [saveState, setSaveState] = useState<SaveState>('idle');
|
|
237
|
+
const [previewMode, setPreviewMode] = useState(false);
|
|
238
|
+
const [sidebarWidth, setSidebarWidth] = useState(280);
|
|
239
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
240
|
+
const [mobileView, setMobileView] = useState<'tree' | 'editor'>('tree');
|
|
241
|
+
const dragStartX = useRef(0);
|
|
242
|
+
const dragStartWidth = useRef(0);
|
|
243
|
+
const [focusedIndex, setFocusedIndex] = useState<number>(-1);
|
|
244
|
+
const treeContainerRef = useRef<HTMLDivElement>(null);
|
|
245
|
+
const flatItemsRef = useRef<FlatItem[]>([]);
|
|
246
|
+
|
|
247
|
+
const [workspaces, setWorkspaces] = useState<WorkspaceInfo[]>([]);
|
|
248
|
+
const [wsLoading, setWsLoading] = useState(true);
|
|
249
|
+
const [selectedWorkspace, setSelectedWorkspace] = useState<string>('');
|
|
250
|
+
|
|
251
|
+
// Load workspaces list on mount
|
|
252
|
+
useEffect(() => {
|
|
253
|
+
void (async () => {
|
|
254
|
+
try {
|
|
255
|
+
const res = await apiFetch('/api/workspace?action=list');
|
|
256
|
+
if (!res.ok) { setWorkspaces([]); return; }
|
|
257
|
+
const data = await res.json() as { workspaces: WorkspaceInfo[] };
|
|
258
|
+
if (data.workspaces && data.workspaces.length > 0) {
|
|
259
|
+
setWorkspaces(data.workspaces);
|
|
260
|
+
if (!data.workspaces.find((w) => w.id === selectedWorkspace)) {
|
|
261
|
+
setSelectedWorkspace(data.workspaces[0].id);
|
|
262
|
+
}
|
|
263
|
+
} else {
|
|
264
|
+
setWorkspaces([]);
|
|
265
|
+
}
|
|
266
|
+
} catch {
|
|
267
|
+
setWorkspaces([]);
|
|
268
|
+
} finally {
|
|
269
|
+
setWsLoading(false);
|
|
270
|
+
}
|
|
271
|
+
})();
|
|
272
|
+
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
273
|
+
|
|
274
|
+
// Load tree
|
|
275
|
+
useEffect(() => {
|
|
276
|
+
let mounted = true;
|
|
277
|
+
let pollTimer: ReturnType<typeof setTimeout>;
|
|
278
|
+
|
|
279
|
+
const load = async (showLoader: boolean) => {
|
|
280
|
+
if (showLoader) setTreeLoading(true);
|
|
281
|
+
try {
|
|
282
|
+
const res = await apiFetch(`/api/workspace?workspace=${encodeURIComponent(selectedWorkspace)}&tree=1`);
|
|
283
|
+
if (!res.ok || !mounted) return;
|
|
284
|
+
const data = await res.json() as { entries: TreeEntry[] };
|
|
285
|
+
setTree(buildTree(data.entries));
|
|
286
|
+
} catch { /* ignore */ }
|
|
287
|
+
finally { if (showLoader && mounted) setTreeLoading(false); }
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
const scheduleNext = () => {
|
|
291
|
+
if (document.hidden) return; // don't poll when tab is hidden
|
|
292
|
+
pollTimer = setTimeout(async () => {
|
|
293
|
+
await load(false);
|
|
294
|
+
if (mounted) scheduleNext();
|
|
295
|
+
}, 5000);
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
const onVisibility = () => {
|
|
299
|
+
if (!document.hidden) { clearTimeout(pollTimer); scheduleNext(); }
|
|
300
|
+
};
|
|
301
|
+
document.addEventListener('visibilitychange', onVisibility);
|
|
302
|
+
|
|
303
|
+
void load(true);
|
|
304
|
+
scheduleNext();
|
|
305
|
+
|
|
306
|
+
return () => {
|
|
307
|
+
mounted = false;
|
|
308
|
+
clearTimeout(pollTimer);
|
|
309
|
+
document.removeEventListener('visibilitychange', onVisibility);
|
|
310
|
+
};
|
|
311
|
+
}, [selectedWorkspace]);
|
|
312
|
+
|
|
313
|
+
// Load file
|
|
314
|
+
const loadFile = useCallback(async (node: TreeNode) => {
|
|
315
|
+
if (node.type !== 'file') return;
|
|
316
|
+
setSelectedPath(node.absPath);
|
|
317
|
+
setSelectedNode(node);
|
|
318
|
+
setFileLoading(true);
|
|
319
|
+
syncFocusToNode(node);
|
|
320
|
+
setSaveState('idle');
|
|
321
|
+
setMobileView('editor');
|
|
322
|
+
try {
|
|
323
|
+
const ext = extOf(node.name);
|
|
324
|
+
if (isBinaryExt(node.name)) {
|
|
325
|
+
if (isPdfExt(node.name)) {
|
|
326
|
+
setFileContent('__pdf__');
|
|
327
|
+
} else {
|
|
328
|
+
setFileContent(`[binary: ${node.name}]`);
|
|
329
|
+
}
|
|
330
|
+
setEditContent('');
|
|
331
|
+
setFileLoading(false);
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const res = await apiFetch(`/api/workspace?workspace=${encodeURIComponent(selectedWorkspace)}&path=${encodeURIComponent(node.absPath)}`);
|
|
335
|
+
if (!res.ok) { setFileContent('[error loading file]'); setEditContent(''); return; }
|
|
336
|
+
const data = await res.json() as { content: string };
|
|
337
|
+
setFileContent(data.content);
|
|
338
|
+
setEditContent(data.content);
|
|
339
|
+
setPreviewMode(isMarkdown(node.name));
|
|
340
|
+
} catch { setFileContent('[error loading file]'); setEditContent(''); }
|
|
341
|
+
finally { setFileLoading(false); }
|
|
342
|
+
}, [selectedWorkspace]);
|
|
343
|
+
|
|
344
|
+
const saveFile = useCallback(async () => {
|
|
345
|
+
if (!selectedPath) return;
|
|
346
|
+
setSaveState('saving');
|
|
347
|
+
try {
|
|
348
|
+
const res = await apiFetch('/api/workspace', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ workspace: selectedWorkspace, path: selectedPath, content: editContent }) });
|
|
349
|
+
if (!res.ok) { setSaveState('error'); return; }
|
|
350
|
+
setFileContent(editContent);
|
|
351
|
+
setSaveState('saved');
|
|
352
|
+
setTimeout(() => setSaveState('idle'), 1500);
|
|
353
|
+
} catch { setSaveState('error'); }
|
|
354
|
+
}, [selectedPath, editContent, selectedWorkspace]);
|
|
355
|
+
|
|
356
|
+
// Keyboard navigation
|
|
357
|
+
const flatItems = useMemo(() => flattenTree(tree, expanded), [tree, expanded]);
|
|
358
|
+
flatItemsRef.current = flatItems;
|
|
359
|
+
|
|
360
|
+
const syncFocusToNode = useCallback((node: TreeNode) => {
|
|
361
|
+
const idx = flatItemsRef.current.findIndex((f) => f.node.relPath === node.relPath);
|
|
362
|
+
if (idx >= 0) {
|
|
363
|
+
setFocusedIndex(idx);
|
|
364
|
+
const el = document.getElementById(`tree-item-${node.relPath.replace(/[^a-zA-Z0-9_-]/g, '_')}`);
|
|
365
|
+
el?.scrollIntoView({ block: 'nearest' });
|
|
366
|
+
// Re-focus the tree container so keyboard nav works
|
|
367
|
+
treeContainerRef.current?.focus();
|
|
368
|
+
}
|
|
369
|
+
}, []);
|
|
370
|
+
|
|
371
|
+
const toggleDir = useCallback((relPath: string, node?: TreeNode) => {
|
|
372
|
+
setExpanded((prev) => { const next = new Set(prev); next.has(relPath) ? next.delete(relPath) : next.add(relPath); return next; });
|
|
373
|
+
if (node) syncFocusToNode(node);
|
|
374
|
+
}, [syncFocusToNode]);
|
|
375
|
+
|
|
376
|
+
const moveFocus = useCallback((direction: -1 | 1) => {
|
|
377
|
+
const items = flatItemsRef.current;
|
|
378
|
+
if (items.length === 0) return;
|
|
379
|
+
const current = focusedIndex < 0 ? (direction === 1 ? -1 : 0) : focusedIndex;
|
|
380
|
+
const next = Math.max(0, Math.min(current + direction, items.length - 1));
|
|
381
|
+
setFocusedIndex(next);
|
|
382
|
+
const el = document.getElementById(`tree-item-${items[next].node.relPath.replace(/[^a-zA-Z0-9_-]/g, '_')}`);
|
|
383
|
+
el?.scrollIntoView({ block: 'nearest' });
|
|
384
|
+
}, [focusedIndex]);
|
|
385
|
+
|
|
386
|
+
const activateCurrent = useCallback(() => {
|
|
387
|
+
const items = flatItemsRef.current;
|
|
388
|
+
if (focusedIndex < 0 || focusedIndex >= items.length) return;
|
|
389
|
+
const item = items[focusedIndex];
|
|
390
|
+
if (item.node.type === 'directory') {
|
|
391
|
+
toggleDir(item.node.relPath, item.node);
|
|
392
|
+
} else {
|
|
393
|
+
syncFocusToNode(item.node);
|
|
394
|
+
loadFile(item.node);
|
|
395
|
+
}
|
|
396
|
+
}, [focusedIndex, toggleDir, loadFile, syncFocusToNode]);
|
|
397
|
+
|
|
398
|
+
const expandCurrent = useCallback(() => {
|
|
399
|
+
const items = flatItemsRef.current;
|
|
400
|
+
if (focusedIndex < 0 || focusedIndex >= items.length) return;
|
|
401
|
+
const item = items[focusedIndex];
|
|
402
|
+
if (item.node.type === 'directory' && !expanded.has(item.node.relPath)) {
|
|
403
|
+
toggleDir(item.node.relPath, item.node);
|
|
404
|
+
}
|
|
405
|
+
}, [focusedIndex, expanded, toggleDir]);
|
|
406
|
+
|
|
407
|
+
const collapseCurrent = useCallback(() => {
|
|
408
|
+
const items = flatItemsRef.current;
|
|
409
|
+
if (focusedIndex < 0 || focusedIndex >= items.length) return;
|
|
410
|
+
const item = items[focusedIndex];
|
|
411
|
+
if (item.node.type === 'directory' && expanded.has(item.node.relPath)) {
|
|
412
|
+
toggleDir(item.node.relPath, item.node);
|
|
413
|
+
}
|
|
414
|
+
}, [focusedIndex, expanded, toggleDir]);
|
|
415
|
+
|
|
416
|
+
// Click on tree container focuses it for keyboard
|
|
417
|
+
const handleTreeContainerClick = useCallback(() => {
|
|
418
|
+
treeContainerRef.current?.focus();
|
|
419
|
+
}, []);
|
|
420
|
+
|
|
421
|
+
// Resize drag
|
|
422
|
+
const onMouseDown = useCallback((e: React.MouseEvent) => {
|
|
423
|
+
dragStartX.current = e.clientX; dragStartWidth.current = sidebarWidth;
|
|
424
|
+
setIsDragging(true);
|
|
425
|
+
}, [sidebarWidth]);
|
|
426
|
+
|
|
427
|
+
useEffect(() => {
|
|
428
|
+
if (!isDragging) return;
|
|
429
|
+
const onMove = (e: MouseEvent) => { const w = Math.max(180, Math.min(600, dragStartWidth.current + e.clientX - dragStartX.current)); setSidebarWidth(w); };
|
|
430
|
+
const onUp = () => setIsDragging(false);
|
|
431
|
+
window.addEventListener('mousemove', onMove); window.addEventListener('mouseup', onUp);
|
|
432
|
+
return () => { window.removeEventListener('mousemove', onMove); window.removeEventListener('mouseup', onUp); };
|
|
433
|
+
}, [isDragging]);
|
|
434
|
+
|
|
435
|
+
const saveBtnLabel = saveState === 'saving' ? 'Saving...' : saveState === 'saved' ? 'Saved ✓' : saveState === 'error' ? 'Error ✗' : 'SAVE';
|
|
436
|
+
const dirty = editContent !== fileContent && !fileLoading && selectedPath != null;
|
|
437
|
+
const lang = selectedNode ? (EXT_LANG[extOf(selectedNode.name)] ?? 'text') : 'text';
|
|
438
|
+
|
|
439
|
+
// Responsive breakpoints
|
|
440
|
+
const [isMobile, setIsMobile] = useState<'phone'|'tablet'|'desktop'>('desktop');
|
|
441
|
+
useEffect(() => {
|
|
442
|
+
const check = () => {
|
|
443
|
+
const w = window.innerWidth;
|
|
444
|
+
if (w < 768) setIsMobile('phone');
|
|
445
|
+
else if (w < 1024) setIsMobile('tablet');
|
|
446
|
+
else setIsMobile('desktop');
|
|
447
|
+
};
|
|
448
|
+
check();
|
|
449
|
+
window.addEventListener('resize', check);
|
|
450
|
+
return () => window.removeEventListener('resize', check);
|
|
451
|
+
}, []);
|
|
452
|
+
|
|
453
|
+
return (
|
|
454
|
+
<div style={{ flex: 1, display: 'flex', flexDirection: 'column', background: 'var(--bg)', color: 'var(--text)', fontFamily: 'var(--font-mono-stack)', overflow: 'hidden' }}>
|
|
455
|
+
{/* Header */}
|
|
456
|
+
<div style={{ height: 48, padding: '0 14px', borderBottom: '1px solid var(--border)', display: 'flex', alignItems: 'center', justifyContent: 'space-between', flexShrink: 0 }}>
|
|
457
|
+
{isMobile === 'phone' && mobileView === 'editor' ? (
|
|
458
|
+
<Button variant="ghost" size="sm" onClick={() => setMobileView('tree')}>
|
|
459
|
+
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round"><path d="M9 2L4 7l5 5"/></svg>
|
|
460
|
+
BACK
|
|
461
|
+
</Button>
|
|
462
|
+
) : (
|
|
463
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
|
|
464
|
+
<span style={{ fontFamily: 'var(--font-serif-stack)', fontSize: 20, letterSpacing: '4px', color: 'var(--violet)' }}>WORKSPACE</span>
|
|
465
|
+
{wsLoading ? (
|
|
466
|
+
<Skeleton width={160} height={24} accent />
|
|
467
|
+
) : workspaces.length === 0 ? (
|
|
468
|
+
<span style={{ fontSize: 11, color: '#555', fontFamily: 'var(--font-mono-stack)' }}>No workspaces</span>
|
|
469
|
+
) : (
|
|
470
|
+
<select
|
|
471
|
+
value={selectedWorkspace}
|
|
472
|
+
onChange={(e) => {
|
|
473
|
+
const newWs = e.target.value;
|
|
474
|
+
setSelectedWorkspace(newWs);
|
|
475
|
+
setTree([]);
|
|
476
|
+
setSelectedPath(null);
|
|
477
|
+
setSelectedNode(null);
|
|
478
|
+
setFileContent('');
|
|
479
|
+
setEditContent('');
|
|
480
|
+
setFocusedIndex(-1);
|
|
481
|
+
setMobileView('tree');
|
|
482
|
+
setSaveState('idle');
|
|
483
|
+
}}
|
|
484
|
+
className="ui-select-workspace"
|
|
485
|
+
style={{
|
|
486
|
+
background: 'var(--bg3)',
|
|
487
|
+
color: 'var(--violet)',
|
|
488
|
+
border: '1px solid var(--border)',
|
|
489
|
+
borderRadius: 0,
|
|
490
|
+
fontSize: 11,
|
|
491
|
+
padding: '3px 8px',
|
|
492
|
+
fontFamily: 'var(--font-mono-stack)',
|
|
493
|
+
maxWidth: 220,
|
|
494
|
+
cursor: 'pointer',
|
|
495
|
+
outline: 'none',
|
|
496
|
+
}}
|
|
497
|
+
>
|
|
498
|
+
{workspaces.map((w) => (
|
|
499
|
+
<option key={w.id} value={w.id}>{w.label}</option>
|
|
500
|
+
))}
|
|
501
|
+
</select>
|
|
502
|
+
)}
|
|
503
|
+
</div>
|
|
504
|
+
)}
|
|
505
|
+
{selectedPath && (
|
|
506
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
|
507
|
+
{isMarkdown(selectedNode?.name ?? '') && (
|
|
508
|
+
<Button variant={previewMode ? 'primary' : 'ghost'} size="sm" onClick={() => setPreviewMode(!previewMode)}>
|
|
509
|
+
{previewMode ? 'EDIT' : 'PREVIEW'}
|
|
510
|
+
</Button>
|
|
511
|
+
)}
|
|
512
|
+
<Button variant={saveState === 'saved' ? 'success' : 'primary'} size="sm" onClick={() => void saveFile()} disabled={!dirty || saveState === 'saving'} loading={saveState === 'saving'}>
|
|
513
|
+
{saveBtnLabel}
|
|
514
|
+
</Button>
|
|
515
|
+
</div>
|
|
516
|
+
)}
|
|
517
|
+
</div>
|
|
518
|
+
|
|
519
|
+
{/* Body */}
|
|
520
|
+
<div style={{ flex: 1, display: 'flex', minHeight: 0 }}>
|
|
521
|
+
{/* Sidebar tree */}
|
|
522
|
+
<div style={{ width: isMobile === 'phone' ? '100%' : isMobile === 'tablet' ? '40%' : sidebarWidth, minWidth: isMobile === 'phone' ? '100%' : isMobile === 'tablet' ? '200px' : sidebarWidth, borderRight: isMobile === 'phone' ? 'none' : '1px solid var(--border)', display: isMobile === 'phone' && mobileView === 'editor' ? 'none' : 'flex', flexDirection: 'column', overflow: 'hidden' }}>
|
|
523
|
+
<div
|
|
524
|
+
ref={treeContainerRef}
|
|
525
|
+
data-tree-container
|
|
526
|
+
tabIndex={0}
|
|
527
|
+
onClick={handleTreeContainerClick}
|
|
528
|
+
onKeyDown={(e) => {
|
|
529
|
+
if (e.key === 'ArrowDown') {
|
|
530
|
+
e.preventDefault();
|
|
531
|
+
moveFocus(1);
|
|
532
|
+
} else if (e.key === 'ArrowUp') {
|
|
533
|
+
e.preventDefault();
|
|
534
|
+
moveFocus(-1);
|
|
535
|
+
} else if (e.key === 'Enter') {
|
|
536
|
+
e.preventDefault();
|
|
537
|
+
activateCurrent();
|
|
538
|
+
} else if (e.key === 'ArrowRight') {
|
|
539
|
+
e.preventDefault();
|
|
540
|
+
expandCurrent();
|
|
541
|
+
} else if (e.key === 'ArrowLeft') {
|
|
542
|
+
e.preventDefault();
|
|
543
|
+
collapseCurrent();
|
|
544
|
+
}
|
|
545
|
+
}}
|
|
546
|
+
style={{ flex: 1, overflowY: 'auto', paddingTop: 6, paddingBottom: 24, outline: 'none' }}
|
|
547
|
+
>
|
|
548
|
+
{treeLoading ? (
|
|
549
|
+
<TreeSkeleton rows={16} />
|
|
550
|
+
) : tree.length === 0 ? (
|
|
551
|
+
<div style={{ padding: '20px 12px', color: '#555', fontSize: 11 }}>Empty workspace</div>
|
|
552
|
+
) : flatItems.map((item, index) => (
|
|
553
|
+
<TreeNodeRow
|
|
554
|
+
key={item.node.relPath}
|
|
555
|
+
id={`tree-item-${item.node.relPath.replace(/[^a-zA-Z0-9_-]/g, '_')}`}
|
|
556
|
+
node={item.node}
|
|
557
|
+
depth={item.depth}
|
|
558
|
+
selected={selectedPath}
|
|
559
|
+
expanded={expanded}
|
|
560
|
+
onToggle={(relPath: string) => {
|
|
561
|
+
const item = flatItems.find(f => f.node.relPath === relPath);
|
|
562
|
+
toggleDir(relPath, item?.node);
|
|
563
|
+
}}
|
|
564
|
+
onSelect={(node: TreeNode) => {
|
|
565
|
+
syncFocusToNode(node);
|
|
566
|
+
loadFile(node);
|
|
567
|
+
}}
|
|
568
|
+
focused={index === focusedIndex}
|
|
569
|
+
/>
|
|
570
|
+
))}
|
|
571
|
+
</div>
|
|
572
|
+
</div>
|
|
573
|
+
|
|
574
|
+
{/* Resize handle — desktop only */}
|
|
575
|
+
{isMobile === 'desktop' && (
|
|
576
|
+
<div
|
|
577
|
+
onMouseDown={onMouseDown}
|
|
578
|
+
style={{ width: 4, cursor: 'col-resize', background: isDragging ? 'var(--violet)' : 'transparent', transition: isDragging ? 'none' : 'background 0.15s', flexShrink: 0 }}
|
|
579
|
+
onMouseEnter={(e) => { (e.currentTarget as HTMLElement).style.background = '#333'; }}
|
|
580
|
+
onMouseLeave={(e) => { if (!isDragging) (e.currentTarget as HTMLElement).style.background = 'transparent'; }}
|
|
581
|
+
/>
|
|
582
|
+
)}
|
|
583
|
+
|
|
584
|
+
{/* Editor / Preview */}
|
|
585
|
+
<div style={{ flex: 1, minWidth: 0, display: isMobile === 'phone' && mobileView === 'tree' ? 'none' : 'flex', flexDirection: 'column', overflow: 'hidden' }}>
|
|
586
|
+
{!selectedPath ? (
|
|
587
|
+
<div style={{ flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#444', fontSize: 12 }}>
|
|
588
|
+
Select a file to view or edit
|
|
589
|
+
</div>
|
|
590
|
+
) : fileLoading ? (
|
|
591
|
+
<div style={{ flex: 1, display: 'flex', flexDirection: 'column', overflow: 'hidden' }}>
|
|
592
|
+
<div style={{ padding: '6px 14px', borderBottom: '1px solid var(--border)', display: 'flex', alignItems: 'center', gap: 10, flexShrink: 0, background: 'var(--bg2)' }}>
|
|
593
|
+
<div style={{ flex: 1 }} />
|
|
594
|
+
</div>
|
|
595
|
+
<CodeSkeleton lines={18} />
|
|
596
|
+
</div>
|
|
597
|
+
) : (
|
|
598
|
+
<>
|
|
599
|
+
{/* File meta bar */}
|
|
600
|
+
<div style={{ padding: '6px 14px', borderBottom: '1px solid var(--border)', display: 'flex', alignItems: 'center', gap: 10, flexShrink: 0, background: 'var(--bg2)' }}>
|
|
601
|
+
<span style={{ fontSize: 11, color: 'var(--violet)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', flex: 1 }}>{selectedPath?.replace('/data/.openclaw/', '')}</span>
|
|
602
|
+
<span style={{ fontSize: 10, color: '#555', flexShrink: 0 }}>{lang}</span>
|
|
603
|
+
{selectedNode && <span style={{ fontSize: 10, color: '#555', flexShrink: 0 }}>{fmtSize(selectedNode.size)}</span>}
|
|
604
|
+
{selectedNode && <span style={{ fontSize: 10, color: '#555', flexShrink: 0 }}>{fmtDate(selectedNode.mtimeMs)}</span>}
|
|
605
|
+
</div>
|
|
606
|
+
|
|
607
|
+
{/* Content */}
|
|
608
|
+
{fileContent === '__pdf__' && selectedPath ? (
|
|
609
|
+
<iframe
|
|
610
|
+
src={`/api/workspace?workspace=${encodeURIComponent(selectedWorkspace)}&path=${encodeURIComponent(selectedPath)}`}
|
|
611
|
+
style={{ flex: 1, width: '100%', border: 'none', background: '#fff' }}
|
|
612
|
+
title={selectedNode?.name ?? 'PDF'}
|
|
613
|
+
/>
|
|
614
|
+
) : previewMode ? (
|
|
615
|
+
<div
|
|
616
|
+
style={{ flex: 1, overflow: 'auto', padding: '20px 28px', fontSize: 13, lineHeight: 1.7, color: '#d0d0d0' }}
|
|
617
|
+
dangerouslySetInnerHTML={{ __html: `<p>${renderMarkdown(editContent)}</p>` }}
|
|
618
|
+
/>
|
|
619
|
+
) : (
|
|
620
|
+
<textarea
|
|
621
|
+
value={editContent}
|
|
622
|
+
onChange={(e) => setEditContent(e.target.value)}
|
|
623
|
+
spellCheck={false}
|
|
624
|
+
style={{ flex: 1, resize: 'none', background: 'var(--bg)', color: '#e0e0e0', border: 'none', outline: 'none', padding: '16px 20px', fontSize: 12, fontFamily: 'var(--font-mono-stack)', lineHeight: 1.6, tabSize: 2 }}
|
|
625
|
+
/>
|
|
626
|
+
)}
|
|
627
|
+
</>
|
|
628
|
+
)}
|
|
629
|
+
</div>
|
|
630
|
+
</div>
|
|
631
|
+
</div>
|
|
632
|
+
);
|
|
633
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Skeleton, TreeSkeleton, CodeSkeleton } from '../components/Skeleton';
|
|
2
|
+
|
|
3
|
+
export default function WorkspaceLoading() {
|
|
4
|
+
return (
|
|
5
|
+
<div style={{ flex: 1, display: 'flex', flexDirection: 'column', background: 'var(--bg)', color: 'var(--text)', overflow: 'hidden' }}>
|
|
6
|
+
{/* Header */}
|
|
7
|
+
<div style={{ height: 48, padding: '0 14px', borderBottom: '1px solid var(--border)', display: 'flex', alignItems: 'center', gap: 10, flexShrink: 0 }}>
|
|
8
|
+
<div style={{ fontFamily: 'var(--font-serif-stack)', fontSize: 20, letterSpacing: '4px', color: 'var(--violet)' }}>WORKSPACE</div>
|
|
9
|
+
<Skeleton width={160} height={24} accent variant="block" />
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
{/* Body */}
|
|
13
|
+
<div style={{ flex: 1, display: 'flex', minHeight: 0 }}>
|
|
14
|
+
{/* Sidebar tree skeleton */}
|
|
15
|
+
<div style={{ width: 280, borderRight: '1px solid var(--border)', display: 'flex', flexDirection: 'column', overflow: 'hidden' }}>
|
|
16
|
+
<TreeSkeleton rows={16} />
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
{/* Resize handle */}
|
|
20
|
+
<div style={{ width: 4, flexShrink: 0 }} />
|
|
21
|
+
|
|
22
|
+
{/* Editor skeleton */}
|
|
23
|
+
<div style={{ flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', overflow: 'hidden' }}>
|
|
24
|
+
{/* File meta bar */}
|
|
25
|
+
<div style={{ padding: '6px 14px', borderBottom: '1px solid var(--border)', display: 'flex', alignItems: 'center', gap: 10, flexShrink: 0, background: 'var(--bg2)' }}>
|
|
26
|
+
<Skeleton width="50%" height={12} accent />
|
|
27
|
+
<Skeleton width={32} height={12} />
|
|
28
|
+
<Skeleton width={40} height={12} />
|
|
29
|
+
<Skeleton width={60} height={12} />
|
|
30
|
+
</div>
|
|
31
|
+
<CodeSkeleton lines={18} />
|
|
32
|
+
</div>
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
);
|
|
36
|
+
}
|