@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,263 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
// Replaces AgentDrawer.jsx — uses Rev4aApiClient (Facade) instead of raw fetch
|
|
3
|
+
|
|
4
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
5
|
+
import { useResponsive } from '../design-system';
|
|
6
|
+
import type { SessionDetail } from '@/lib/types';
|
|
7
|
+
import { Rev4aApiClient } from '@/lib/patterns/ApiClient';
|
|
8
|
+
import { deriveSessionDisplayLabel } from '@/lib/patterns/sessionPresentation';
|
|
9
|
+
import {
|
|
10
|
+
formatUsd,
|
|
11
|
+
formatUsdOrDash,
|
|
12
|
+
formatTokens,
|
|
13
|
+
formatTimeFromUnixSeconds,
|
|
14
|
+
formatDuration,
|
|
15
|
+
truncate,
|
|
16
|
+
statusColor,
|
|
17
|
+
parseEventData,
|
|
18
|
+
} from '@/lib/utils/format';
|
|
19
|
+
import Rev4aLoader from './Rev4aLoader';
|
|
20
|
+
|
|
21
|
+
interface SessionDrawerProps {
|
|
22
|
+
sessionId: string | null;
|
|
23
|
+
onClose: () => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default function SessionDrawer({ sessionId, onClose }: SessionDrawerProps) {
|
|
27
|
+
const [loading, setLoading] = useState(false);
|
|
28
|
+
const [error, setError] = useState('');
|
|
29
|
+
const [detail, setDetail] = useState<SessionDetail | null>(null);
|
|
30
|
+
const isMobile = useResponsive('md');
|
|
31
|
+
|
|
32
|
+
// ── Drag-to-close per bottom sheet mobile ─────────────────────────────
|
|
33
|
+
const dragStartY = useRef<number | null>(null);
|
|
34
|
+
const sheetRef = useRef<HTMLElement>(null);
|
|
35
|
+
|
|
36
|
+
const onDragStart = (e: React.TouchEvent) => {
|
|
37
|
+
dragStartY.current = e.touches[0].clientY;
|
|
38
|
+
if (sheetRef.current) sheetRef.current.style.transition = 'none';
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const onDragMove = (e: React.TouchEvent) => {
|
|
42
|
+
if (dragStartY.current === null || !sheetRef.current) return;
|
|
43
|
+
const dy = e.touches[0].clientY - dragStartY.current;
|
|
44
|
+
if (dy > 0) sheetRef.current.style.transform = `translateY(${dy}px)`;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const onDragEnd = (e: React.TouchEvent) => {
|
|
48
|
+
if (dragStartY.current === null || !sheetRef.current) return;
|
|
49
|
+
const dy = e.changedTouches[0].clientY - dragStartY.current;
|
|
50
|
+
sheetRef.current.style.transition = 'transform 0.25s ease';
|
|
51
|
+
if (dy > 80) {
|
|
52
|
+
sheetRef.current.style.transform = 'translateY(100%)';
|
|
53
|
+
setTimeout(onClose, 250);
|
|
54
|
+
} else {
|
|
55
|
+
sheetRef.current.style.transform = 'translateY(0)';
|
|
56
|
+
}
|
|
57
|
+
dragStartY.current = null;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (!sessionId) {
|
|
62
|
+
setDetail(null);
|
|
63
|
+
setError('');
|
|
64
|
+
setLoading(false);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const controller = new AbortController();
|
|
69
|
+
(async () => {
|
|
70
|
+
setLoading(true);
|
|
71
|
+
setError('');
|
|
72
|
+
try {
|
|
73
|
+
const data = await Rev4aApiClient.fetchSessionDetail(sessionId);
|
|
74
|
+
if (!controller.signal.aborted) setDetail(data);
|
|
75
|
+
} catch (e: unknown) {
|
|
76
|
+
if (!controller.signal.aborted) {
|
|
77
|
+
setDetail(null);
|
|
78
|
+
setError(e instanceof Error ? e.message : 'Unexpected error');
|
|
79
|
+
}
|
|
80
|
+
} finally {
|
|
81
|
+
if (!controller.signal.aborted) setLoading(false);
|
|
82
|
+
}
|
|
83
|
+
})();
|
|
84
|
+
|
|
85
|
+
return () => controller.abort();
|
|
86
|
+
}, [sessionId]);
|
|
87
|
+
|
|
88
|
+
if (!sessionId) return null;
|
|
89
|
+
|
|
90
|
+
const { session, events, children } = detail ?? { session: null, events: [], children: [] };
|
|
91
|
+
const endedOrUpdated = session?.ended_at ?? session?.updated_at ?? null;
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<>
|
|
95
|
+
{isMobile && (
|
|
96
|
+
<div
|
|
97
|
+
onClick={onClose}
|
|
98
|
+
style={{
|
|
99
|
+
position: 'fixed', inset: 0, zIndex: 299,
|
|
100
|
+
background: 'rgba(0,0,0,0.5)',
|
|
101
|
+
}}
|
|
102
|
+
/>
|
|
103
|
+
)}
|
|
104
|
+
<aside
|
|
105
|
+
ref={sheetRef}
|
|
106
|
+
style={isMobile ? {
|
|
107
|
+
position: 'fixed',
|
|
108
|
+
left: 0,
|
|
109
|
+
right: 0,
|
|
110
|
+
bottom: 0,
|
|
111
|
+
zIndex: 300,
|
|
112
|
+
width: '100%',
|
|
113
|
+
maxHeight: '75vh',
|
|
114
|
+
overflowY: 'auto',
|
|
115
|
+
background: 'var(--bg)',
|
|
116
|
+
borderTop: '1px solid var(--border)',
|
|
117
|
+
borderRadius: 0,
|
|
118
|
+
color: 'var(--text)',
|
|
119
|
+
padding: '20px 14px 28px',
|
|
120
|
+
transition: 'transform 0.25s ease',
|
|
121
|
+
touchAction: 'none',
|
|
122
|
+
} : {
|
|
123
|
+
position: 'fixed',
|
|
124
|
+
right: 0,
|
|
125
|
+
top: 0,
|
|
126
|
+
zIndex: 200,
|
|
127
|
+
width: 320,
|
|
128
|
+
maxWidth: '92vw',
|
|
129
|
+
height: '100vh',
|
|
130
|
+
overflowY: 'auto',
|
|
131
|
+
background: 'var(--bg)',
|
|
132
|
+
borderLeft: '1px solid var(--border)',
|
|
133
|
+
color: 'var(--text)',
|
|
134
|
+
padding: '20px 14px 14px',
|
|
135
|
+
}}
|
|
136
|
+
>
|
|
137
|
+
{isMobile && (
|
|
138
|
+
<div
|
|
139
|
+
onTouchStart={onDragStart}
|
|
140
|
+
onTouchMove={onDragMove}
|
|
141
|
+
onTouchEnd={onDragEnd}
|
|
142
|
+
style={{ display: 'flex', justifyContent: 'center', marginBottom: 12, marginTop: -8, padding: '8px 0', cursor: 'grab' }}>
|
|
143
|
+
<div style={{ width: 36, height: 4, borderRadius: 2, background: 'var(--border)' }} />
|
|
144
|
+
</div>
|
|
145
|
+
)}
|
|
146
|
+
<button
|
|
147
|
+
type="button"
|
|
148
|
+
onClick={onClose}
|
|
149
|
+
aria-label="Chiudi"
|
|
150
|
+
style={{
|
|
151
|
+
position: 'absolute',
|
|
152
|
+
top: isMobile ? 16 : 14,
|
|
153
|
+
right: 14,
|
|
154
|
+
border: 'none',
|
|
155
|
+
background: 'transparent',
|
|
156
|
+
color: 'var(--text-dim)',
|
|
157
|
+
fontSize: 18,
|
|
158
|
+
lineHeight: 1,
|
|
159
|
+
cursor: 'pointer',
|
|
160
|
+
padding: 4,
|
|
161
|
+
borderRadius: 0,
|
|
162
|
+
transition: 'color 0.15s',
|
|
163
|
+
}}
|
|
164
|
+
onMouseEnter={e => (e.currentTarget.style.color = 'var(--text)')}
|
|
165
|
+
onMouseLeave={e => (e.currentTarget.style.color = 'var(--text-dim)')}
|
|
166
|
+
>
|
|
167
|
+
✕
|
|
168
|
+
</button>
|
|
169
|
+
|
|
170
|
+
{loading && <Rev4aLoader label="LOADING SESSION" compact />}
|
|
171
|
+
{error && <div style={{ color: '#f07070' }}>{error}</div>}
|
|
172
|
+
|
|
173
|
+
{!loading && !error && session && (
|
|
174
|
+
<>
|
|
175
|
+
<Section>
|
|
176
|
+
<div style={{ color: 'var(--violet)', fontSize: 12, marginBottom: 8 }}>
|
|
177
|
+
{truncate(deriveSessionDisplayLabel(session), 40)}
|
|
178
|
+
</div>
|
|
179
|
+
<div style={{ color: 'var(--text-dim)', fontSize: 11, marginBottom: 10 }}>
|
|
180
|
+
{truncate(session.session_id, 60)}
|
|
181
|
+
</div>
|
|
182
|
+
<Grid>
|
|
183
|
+
<Row label="STATO">
|
|
184
|
+
<span style={{ color: statusColor(session.status) }}>●</span>{' '}
|
|
185
|
+
{session.status ?? 'idle'}
|
|
186
|
+
</Row>
|
|
187
|
+
<Row label="TIPO">
|
|
188
|
+
{session.session_id.includes(':cron:') ? 'cron' : 'sessione'}
|
|
189
|
+
</Row>
|
|
190
|
+
<Row label="MODELLO">{session.model ?? '-'}</Row>
|
|
191
|
+
<Row label="COSTO">{formatUsdOrDash(session.cost_usd)}</Row>
|
|
192
|
+
<Row label="TOKEN">
|
|
193
|
+
in: {formatTokens(session.tokens_in)} out: {formatTokens(session.tokens_out)}
|
|
194
|
+
</Row>
|
|
195
|
+
<Row label="INIZIO">{formatTimeFromUnixSeconds(session.started_at)}</Row>
|
|
196
|
+
<Row label="AGGIORN.">{formatTimeFromUnixSeconds(session.updated_at)}</Row>
|
|
197
|
+
<Row label="FINE">{formatTimeFromUnixSeconds(session.ended_at)}</Row>
|
|
198
|
+
<Row label="DURATA">{formatDuration(session.started_at, endedOrUpdated)}</Row>
|
|
199
|
+
<Row label="TASK">{truncate(session.task_preview ?? '-', 200)}</Row>
|
|
200
|
+
</Grid>
|
|
201
|
+
</Section>
|
|
202
|
+
|
|
203
|
+
<Section title="AZIONI RECENTI">
|
|
204
|
+
{events.length === 0 && <Muted>No events</Muted>}
|
|
205
|
+
{events.map((evt) => (
|
|
206
|
+
<div key={evt.id ?? `${evt.ts ?? 0}-${evt.type ?? 'event'}`} style={{ fontSize: 12 }}>
|
|
207
|
+
<span style={{ color: 'var(--text-dim)', marginRight: 6 }}>
|
|
208
|
+
{formatTimeFromUnixSeconds(evt.ts)}
|
|
209
|
+
</span>
|
|
210
|
+
<span style={{ marginRight: 6 }}>{evt.type ?? 'event'}</span>
|
|
211
|
+
<span style={{ color: 'var(--text-dim)' }}>
|
|
212
|
+
{truncate(parseEventData(evt.data), 80)}
|
|
213
|
+
</span>
|
|
214
|
+
</div>
|
|
215
|
+
))}
|
|
216
|
+
</Section>
|
|
217
|
+
|
|
218
|
+
<Section title="SESSIONI FIGLIE">
|
|
219
|
+
{children.length === 0 && <Muted>No child sessions</Muted>}
|
|
220
|
+
{children.map((child) => (
|
|
221
|
+
<div key={child.session_id} style={{ fontSize: 12 }}>
|
|
222
|
+
<div>{truncate(deriveSessionDisplayLabel(child), 44)}</div>
|
|
223
|
+
<Muted>
|
|
224
|
+
{child.status ?? 'idle'} {formatUsdOrDash(child.cost_usd)}
|
|
225
|
+
</Muted>
|
|
226
|
+
</div>
|
|
227
|
+
))}
|
|
228
|
+
</Section>
|
|
229
|
+
</>
|
|
230
|
+
)}
|
|
231
|
+
</aside>
|
|
232
|
+
</>
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// ── Small layout helpers ───────────────────────────────────────────────────
|
|
237
|
+
|
|
238
|
+
function Section({ title, children }: { title?: string; children: React.ReactNode }) {
|
|
239
|
+
return (
|
|
240
|
+
<div style={{ borderTop: title ? '1px solid var(--border)' : 'none', marginTop: title ? 14 : 0, paddingTop: title ? 10 : 0 }}>
|
|
241
|
+
{title && (
|
|
242
|
+
<div style={{ fontSize: 12, color: 'var(--violet)', marginBottom: 8 }}>{title}</div>
|
|
243
|
+
)}
|
|
244
|
+
<div style={{ display: 'grid', gap: 7 }}>{children}</div>
|
|
245
|
+
</div>
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function Grid({ children }: { children: React.ReactNode }) {
|
|
250
|
+
return <div style={{ display: 'grid', gap: 7, fontSize: 12 }}>{children}</div>;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function Row({ label, children }: { label: string; children: React.ReactNode }) {
|
|
254
|
+
return (
|
|
255
|
+
<div>
|
|
256
|
+
{label} {children}
|
|
257
|
+
</div>
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function Muted({ children }: { children: React.ReactNode }) {
|
|
262
|
+
return <div style={{ fontSize: 12, color: 'var(--text-dim)' }}>{children}</div>;
|
|
263
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
5
|
+
import { createPortal } from 'react-dom';
|
|
6
|
+
import * as d3 from 'd3';
|
|
7
|
+
import type { Session, TreeNode } from '@/lib/types';
|
|
8
|
+
import { buildSessionTree } from '@/lib/patterns/SessionFactory';
|
|
9
|
+
import { nodeLabel } from '@/lib/patterns/sessionPresentation';
|
|
10
|
+
|
|
11
|
+
interface SessionTopologyProps {
|
|
12
|
+
sessions: Session[];
|
|
13
|
+
filter: string;
|
|
14
|
+
onNodeClick: (sessionId: string) => void;
|
|
15
|
+
emptyMessage?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface SessionTopologyHandle {
|
|
19
|
+
resetView: () => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function formatCost(value: number | null | undefined): string {
|
|
23
|
+
return `$${Number(value ?? 0).toFixed(4)}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function draw(
|
|
27
|
+
svgEl: SVGSVGElement,
|
|
28
|
+
tooltipEl: HTMLDivElement | null,
|
|
29
|
+
width: number,
|
|
30
|
+
height: number,
|
|
31
|
+
treeData: TreeNode,
|
|
32
|
+
isTouch: boolean,
|
|
33
|
+
onNodeClick: (id: string) => void,
|
|
34
|
+
registerReset: (reset: () => void) => void,
|
|
35
|
+
) {
|
|
36
|
+
const svg = d3.select(svgEl);
|
|
37
|
+
svg.selectAll('*').remove();
|
|
38
|
+
svg.attr('viewBox', `0 0 ${width} ${height}`);
|
|
39
|
+
|
|
40
|
+
const g = svg.append('g');
|
|
41
|
+
const content = g.append('g').attr('transform', 'translate(40,20)');
|
|
42
|
+
|
|
43
|
+
const zoom = d3.zoom<SVGSVGElement, unknown>()
|
|
44
|
+
.scaleExtent([0.2, 5])
|
|
45
|
+
.on('zoom', (event) => g.attr('transform', event.transform));
|
|
46
|
+
svg.call(zoom).on('dblclick.zoom', null);
|
|
47
|
+
|
|
48
|
+
const root = d3.hierarchy<TreeNode>(treeData);
|
|
49
|
+
const treeLayout = d3.tree<TreeNode>().size([height - 40, width - 120]);
|
|
50
|
+
treeLayout(root);
|
|
51
|
+
|
|
52
|
+
const linkGen = d3
|
|
53
|
+
.linkHorizontal<d3.HierarchyPointLink<TreeNode>, d3.HierarchyPointNode<TreeNode>>()
|
|
54
|
+
.x((d) => d.y)
|
|
55
|
+
.y((d) => d.x);
|
|
56
|
+
|
|
57
|
+
content
|
|
58
|
+
.selectAll('.link')
|
|
59
|
+
.data(root.links().filter((l) => !l.source.data._virtualRoot))
|
|
60
|
+
.join('path')
|
|
61
|
+
.attr('class', 'link')
|
|
62
|
+
.attr('d', linkGen as any)
|
|
63
|
+
.attr('fill', 'none');
|
|
64
|
+
|
|
65
|
+
let lastActivation = { id: '', ts: 0 };
|
|
66
|
+
const activateNode = (d: d3.HierarchyPointNode<TreeNode>) => {
|
|
67
|
+
const id = d.data.session_id;
|
|
68
|
+
if (!id || d.data._virtualRoot || d.data._agentNode) return;
|
|
69
|
+
const now = Date.now();
|
|
70
|
+
if (lastActivation.id === id && now - lastActivation.ts < 250) return;
|
|
71
|
+
lastActivation = { id, ts: now };
|
|
72
|
+
onNodeClick(id);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const node = content
|
|
76
|
+
.selectAll<SVGGElement, d3.HierarchyPointNode<TreeNode>>('.node')
|
|
77
|
+
.data(root.descendants().filter((d) => !d.data._virtualRoot))
|
|
78
|
+
.join('g')
|
|
79
|
+
.attr('class', (d) => `node ${d.data.status ?? 'idle'}`)
|
|
80
|
+
.attr('transform', (d) => `translate(${d.y},${d.x})`)
|
|
81
|
+
.on('mousemove', (event: MouseEvent, d) => {
|
|
82
|
+
if (isTouch || !tooltipEl) return;
|
|
83
|
+
tooltipEl.style.display = 'block';
|
|
84
|
+
const tx = event.clientX + 18;
|
|
85
|
+
const ty = event.clientY + 18;
|
|
86
|
+
// Keep tooltip inside viewport
|
|
87
|
+
const tw = tooltipEl.offsetWidth || 200;
|
|
88
|
+
const th = tooltipEl.offsetHeight || 80;
|
|
89
|
+
tooltipEl.style.left = `${Math.min(tx, window.innerWidth - tw - 8)}px`;
|
|
90
|
+
tooltipEl.style.top = `${Math.min(ty, window.innerHeight - th - 8)}px`;
|
|
91
|
+
tooltipEl.innerHTML = [
|
|
92
|
+
`<div><strong>${nodeLabel(d.data)}</strong></div>`,
|
|
93
|
+
`<div>model: ${d.data.model ?? '-'}</div>`,
|
|
94
|
+
`<div>cost: ${formatCost(d.data.cost_usd)}</div>`,
|
|
95
|
+
`<div>status: ${d.data.status ?? 'idle'}</div>`,
|
|
96
|
+
].join('');
|
|
97
|
+
})
|
|
98
|
+
.on('mouseleave', () => {
|
|
99
|
+
if (tooltipEl) tooltipEl.style.display = 'none';
|
|
100
|
+
})
|
|
101
|
+
.on('pointerup', (_: PointerEvent, d) => activateNode(d))
|
|
102
|
+
.on('click', (_: MouseEvent, d) => activateNode(d));
|
|
103
|
+
|
|
104
|
+
node
|
|
105
|
+
.filter((d) => d.data.status === 'working' || d.data.status === 'active')
|
|
106
|
+
.append('circle')
|
|
107
|
+
.attr('class', 'pulse-ring')
|
|
108
|
+
.attr('r', 10);
|
|
109
|
+
|
|
110
|
+
node.append('circle').attr('r', 8);
|
|
111
|
+
|
|
112
|
+
node
|
|
113
|
+
.append('text')
|
|
114
|
+
.text((d) => nodeLabel(d.data))
|
|
115
|
+
.attr('dy', 22)
|
|
116
|
+
.attr('text-anchor', 'middle')
|
|
117
|
+
.style('font-size', '10px')
|
|
118
|
+
.style('fill', '#d6e2e8');
|
|
119
|
+
|
|
120
|
+
node
|
|
121
|
+
.filter((d) => Number(d.data.cost_usd ?? 0) > 0)
|
|
122
|
+
.append('text')
|
|
123
|
+
.text((d) => formatCost(d.data.cost_usd))
|
|
124
|
+
.attr('dy', 34)
|
|
125
|
+
.attr('text-anchor', 'middle')
|
|
126
|
+
.style('font-size', '10px')
|
|
127
|
+
.style('fill', '#89a1ad');
|
|
128
|
+
|
|
129
|
+
const resetView = () => {
|
|
130
|
+
const contentNode = content.node();
|
|
131
|
+
if (!contentNode) return;
|
|
132
|
+
|
|
133
|
+
const bbox = contentNode.getBBox();
|
|
134
|
+
if (!bbox.width || !bbox.height) {
|
|
135
|
+
svg.transition().duration(250).call(zoom.transform, d3.zoomIdentity.translate(40, 20));
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const padX = isTouch ? 24 : 48;
|
|
140
|
+
const padY = isTouch ? 24 : 36;
|
|
141
|
+
const scale = Math.max(
|
|
142
|
+
0.2,
|
|
143
|
+
Math.min(
|
|
144
|
+
1.5,
|
|
145
|
+
(width - padX * 2) / bbox.width,
|
|
146
|
+
(height - padY * 2) / bbox.height,
|
|
147
|
+
),
|
|
148
|
+
);
|
|
149
|
+
const tx = width / 2 - (bbox.x + bbox.width / 2) * scale;
|
|
150
|
+
const ty = height / 2 - (bbox.y + bbox.height / 2) * scale;
|
|
151
|
+
|
|
152
|
+
svg
|
|
153
|
+
.transition()
|
|
154
|
+
.duration(250)
|
|
155
|
+
.call(zoom.transform, d3.zoomIdentity.translate(tx, ty).scale(scale));
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
registerReset(resetView);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const SessionTopology = forwardRef<SessionTopologyHandle, SessionTopologyProps>(function SessionTopology(
|
|
162
|
+
{ sessions, filter, onNodeClick, emptyMessage = 'No sessions visible' },
|
|
163
|
+
ref,
|
|
164
|
+
) {
|
|
165
|
+
const svgRef = useRef<SVGSVGElement>(null);
|
|
166
|
+
const tooltipRef = useRef<HTMLDivElement>(null);
|
|
167
|
+
const resetRef = useRef<() => void>(() => {});
|
|
168
|
+
const prevFitKeyRef = useRef<string>('');
|
|
169
|
+
const fitFrameRef = useRef<number | null>(null);
|
|
170
|
+
const [isTouch, setIsTouch] = useState(false);
|
|
171
|
+
const [mounted, setMounted] = useState(false);
|
|
172
|
+
|
|
173
|
+
useEffect(() => { setMounted(true); }, []);
|
|
174
|
+
|
|
175
|
+
const treeData = useMemo(() => buildSessionTree(sessions, filter), [sessions, filter]);
|
|
176
|
+
const hasVisibleNodes = useMemo(() => (treeData.children ?? []).some((node) => node._agentNode ? (node.children?.length ?? 0) > 0 : true), [treeData]);
|
|
177
|
+
const fitKey = useMemo(() => JSON.stringify({
|
|
178
|
+
filter,
|
|
179
|
+
nodes: treeData.children ?? [],
|
|
180
|
+
}), [filter, treeData]);
|
|
181
|
+
|
|
182
|
+
useImperativeHandle(ref, () => ({
|
|
183
|
+
resetView: () => resetRef.current(),
|
|
184
|
+
}), []);
|
|
185
|
+
|
|
186
|
+
useEffect(() => {
|
|
187
|
+
const check = () => {
|
|
188
|
+
const coarse = window.matchMedia?.('(pointer: coarse)')?.matches;
|
|
189
|
+
setIsTouch(Boolean(coarse || window.innerWidth < 768));
|
|
190
|
+
};
|
|
191
|
+
check();
|
|
192
|
+
window.addEventListener('resize', check);
|
|
193
|
+
return () => window.removeEventListener('resize', check);
|
|
194
|
+
}, []);
|
|
195
|
+
|
|
196
|
+
useEffect(() => {
|
|
197
|
+
if (!hasVisibleNodes) {
|
|
198
|
+
resetRef.current = () => {};
|
|
199
|
+
prevFitKeyRef.current = '';
|
|
200
|
+
}
|
|
201
|
+
}, [hasVisibleNodes]);
|
|
202
|
+
|
|
203
|
+
useEffect(() => () => {
|
|
204
|
+
if (fitFrameRef.current !== null) {
|
|
205
|
+
cancelAnimationFrame(fitFrameRef.current);
|
|
206
|
+
}
|
|
207
|
+
}, []);
|
|
208
|
+
|
|
209
|
+
useEffect(() => {
|
|
210
|
+
const svgEl = svgRef.current;
|
|
211
|
+
const tooltipEl = tooltipRef.current;
|
|
212
|
+
if (!svgEl || !hasVisibleNodes) return;
|
|
213
|
+
const shouldAutoFit = fitKey !== prevFitKeyRef.current;
|
|
214
|
+
prevFitKeyRef.current = fitKey;
|
|
215
|
+
|
|
216
|
+
const scheduleAutoFit = () => {
|
|
217
|
+
if (!shouldAutoFit) return;
|
|
218
|
+
|
|
219
|
+
if (fitFrameRef.current !== null) {
|
|
220
|
+
cancelAnimationFrame(fitFrameRef.current);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
let attempts = 0;
|
|
224
|
+
const runFit = () => {
|
|
225
|
+
fitFrameRef.current = requestAnimationFrame(() => {
|
|
226
|
+
const contentNode = svgEl.querySelector('g > g');
|
|
227
|
+
const bbox = contentNode && typeof (contentNode as SVGGElement).getBBox === 'function'
|
|
228
|
+
? (contentNode as SVGGElement).getBBox()
|
|
229
|
+
: null;
|
|
230
|
+
|
|
231
|
+
if ((!svgEl.clientWidth || !svgEl.clientHeight || !bbox || !bbox.width || !bbox.height) && attempts < 6) {
|
|
232
|
+
attempts += 1;
|
|
233
|
+
runFit();
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
resetRef.current();
|
|
238
|
+
fitFrameRef.current = null;
|
|
239
|
+
});
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
runFit();
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
const render = (autoFit: boolean) => {
|
|
246
|
+
const width = svgEl.clientWidth || 900;
|
|
247
|
+
const height = svgEl.clientHeight || 480;
|
|
248
|
+
draw(svgEl, tooltipEl, width, height, treeData, isTouch, onNodeClick, (reset) => {
|
|
249
|
+
resetRef.current = reset;
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
if (autoFit) {
|
|
253
|
+
scheduleAutoFit();
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
render(shouldAutoFit);
|
|
258
|
+
const ro = new ResizeObserver(() => render(false));
|
|
259
|
+
ro.observe(svgEl);
|
|
260
|
+
return () => {
|
|
261
|
+
ro.disconnect();
|
|
262
|
+
if (fitFrameRef.current !== null) {
|
|
263
|
+
cancelAnimationFrame(fitFrameRef.current);
|
|
264
|
+
fitFrameRef.current = null;
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
}, [fitKey, hasVisibleNodes, isTouch, treeData, onNodeClick]);
|
|
268
|
+
|
|
269
|
+
return (
|
|
270
|
+
<>
|
|
271
|
+
<div className="graph-shell">
|
|
272
|
+
{hasVisibleNodes ? (
|
|
273
|
+
<svg ref={svgRef} id="graph-svg" />
|
|
274
|
+
) : (
|
|
275
|
+
<div className="empty-state">
|
|
276
|
+
<span className="empty-state-icon">◎</span>
|
|
277
|
+
<span className="empty-state-msg">{emptyMessage}</span>
|
|
278
|
+
</div>
|
|
279
|
+
)}
|
|
280
|
+
</div>
|
|
281
|
+
{mounted && createPortal(
|
|
282
|
+
<div ref={tooltipRef} className="graph-tooltip" />,
|
|
283
|
+
document.body
|
|
284
|
+
)}
|
|
285
|
+
</>
|
|
286
|
+
);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
export default SessionTopology;
|