@geminilight/mindos 0.6.28 → 0.6.29

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.
Files changed (64) hide show
  1. package/app/app/api/a2a/agents/route.ts +9 -0
  2. package/app/app/api/a2a/delegations/route.ts +9 -0
  3. package/app/app/api/a2a/discover/route.ts +2 -0
  4. package/app/app/api/a2a/route.ts +6 -6
  5. package/app/app/api/acp/detect/route.ts +91 -0
  6. package/app/app/api/acp/registry/route.ts +31 -0
  7. package/app/app/api/acp/session/route.ts +55 -0
  8. package/app/app/layout.tsx +2 -0
  9. package/app/components/DirView.tsx +64 -2
  10. package/app/components/FileTree.tsx +19 -0
  11. package/app/components/GuideCard.tsx +7 -17
  12. package/app/components/MarkdownView.tsx +2 -0
  13. package/app/components/SearchModal.tsx +234 -80
  14. package/app/components/agents/AgentDetailContent.tsx +3 -5
  15. package/app/components/agents/AgentsContentPage.tsx +21 -6
  16. package/app/components/agents/AgentsPanelA2aTab.tsx +445 -0
  17. package/app/components/agents/SkillDetailPopover.tsx +4 -9
  18. package/app/components/agents/agents-content-model.ts +2 -2
  19. package/app/components/help/HelpContent.tsx +9 -9
  20. package/app/components/panels/AgentsPanel.tsx +1 -0
  21. package/app/components/panels/AgentsPanelAgentDetail.tsx +5 -8
  22. package/app/components/panels/AgentsPanelHubNav.tsx +8 -1
  23. package/app/components/panels/EchoPanel.tsx +5 -1
  24. package/app/components/panels/EchoSidebarStats.tsx +136 -0
  25. package/app/components/settings/KnowledgeTab.tsx +3 -6
  26. package/app/components/settings/McpSkillsSection.tsx +4 -5
  27. package/app/components/settings/McpTab.tsx +6 -8
  28. package/app/components/setup/StepSecurity.tsx +4 -5
  29. package/app/components/setup/index.tsx +5 -11
  30. package/app/components/ui/Toaster.tsx +39 -0
  31. package/app/hooks/useA2aRegistry.ts +6 -1
  32. package/app/hooks/useAcpDetection.ts +65 -0
  33. package/app/hooks/useAcpRegistry.ts +51 -0
  34. package/app/hooks/useDelegationHistory.ts +49 -0
  35. package/app/lib/a2a/client.ts +49 -5
  36. package/app/lib/a2a/orchestrator.ts +0 -1
  37. package/app/lib/a2a/task-handler.ts +4 -4
  38. package/app/lib/a2a/types.ts +15 -0
  39. package/app/lib/acp/acp-tools.ts +93 -0
  40. package/app/lib/acp/bridge.ts +138 -0
  41. package/app/lib/acp/index.ts +24 -0
  42. package/app/lib/acp/registry.ts +135 -0
  43. package/app/lib/acp/session.ts +264 -0
  44. package/app/lib/acp/subprocess.ts +209 -0
  45. package/app/lib/acp/types.ts +136 -0
  46. package/app/lib/agent/tools.ts +2 -1
  47. package/app/lib/i18n/_core.ts +22 -0
  48. package/app/lib/i18n/index.ts +35 -0
  49. package/app/lib/i18n/modules/ai-chat.ts +215 -0
  50. package/app/lib/i18n/modules/common.ts +71 -0
  51. package/app/lib/i18n/modules/features.ts +153 -0
  52. package/app/lib/i18n/modules/knowledge.ts +425 -0
  53. package/app/lib/i18n/modules/navigation.ts +151 -0
  54. package/app/lib/i18n/modules/onboarding.ts +523 -0
  55. package/app/lib/i18n/modules/panels.ts +1052 -0
  56. package/app/lib/i18n/modules/settings.ts +585 -0
  57. package/app/lib/i18n-en.ts +2 -1518
  58. package/app/lib/i18n-zh.ts +2 -1542
  59. package/app/lib/i18n.ts +3 -6
  60. package/app/lib/toast.ts +79 -0
  61. package/bin/cli.js +25 -25
  62. package/bin/commands/file.js +29 -2
  63. package/bin/commands/space.js +249 -91
  64. package/package.json +1 -1
@@ -0,0 +1,136 @@
1
+ 'use client';
2
+
3
+ import { useState, useEffect } from 'react';
4
+ import { TrendingUp, MessageSquare, AlertCircle } from 'lucide-react';
5
+ import type { ContentChangeEvent } from '@/lib/fs';
6
+ import { apiFetch } from '@/lib/api';
7
+ import { useLocale } from '@/lib/LocaleContext';
8
+
9
+ interface EchoStats {
10
+ fileCount: number;
11
+ unreadChanges: number;
12
+ sessionCount: number;
13
+ }
14
+
15
+ export default function EchoSidebarStats() {
16
+ const [stats, setStats] = useState<EchoStats | null>(null);
17
+ const [recentEvents, setRecentEvents] = useState<ContentChangeEvent[]>([]);
18
+ const [loading, setLoading] = useState(true);
19
+ const { t } = useLocale();
20
+
21
+ useEffect(() => {
22
+ const loadStats = async () => {
23
+ try {
24
+ setLoading(true);
25
+ const [monitoring, changes, sessions] = await Promise.all([
26
+ apiFetch<any>('/api/monitoring'),
27
+ apiFetch<any>('/api/changes?op=list&limit=3'),
28
+ apiFetch<any>('/api/ask-sessions'),
29
+ ]);
30
+
31
+ setStats({
32
+ fileCount: monitoring?.knowledgeBase?.fileCount ?? 0,
33
+ unreadChanges: changes?.events?.length ?? 0,
34
+ sessionCount: Array.isArray(sessions) ? sessions.length : 0,
35
+ });
36
+
37
+ setRecentEvents((changes?.events ?? []).slice(0, 3));
38
+ } catch (err) {
39
+ console.warn('[EchoSidebarStats] Failed to load stats:', err);
40
+ setStats({ fileCount: 0, unreadChanges: 0, sessionCount: 0 });
41
+ setRecentEvents([]);
42
+ } finally {
43
+ setLoading(false);
44
+ }
45
+ };
46
+
47
+ loadStats();
48
+ const interval = setInterval(loadStats, 10000); // Refresh every 10s
49
+ return () => clearInterval(interval);
50
+ }, []);
51
+
52
+ if (loading || !stats) {
53
+ return (
54
+ <div className="px-3 py-2 text-xs text-muted-foreground">
55
+ <div className="h-2 w-20 bg-muted rounded animate-pulse" />
56
+ </div>
57
+ );
58
+ }
59
+
60
+ return (
61
+ <div className="flex flex-col gap-2 px-3 py-3 border-t border-border">
62
+ {/* Quick Stats */}
63
+ <div className="grid grid-cols-3 gap-2">
64
+ <div className="flex flex-col items-center p-1.5 rounded bg-muted/40 hover:bg-muted/60 transition-colors cursor-default">
65
+ <div className="text-sm font-semibold text-foreground">{stats.fileCount}</div>
66
+ <div className="text-xs text-muted-foreground truncate">Files</div>
67
+ </div>
68
+ <div className="flex flex-col items-center p-1.5 rounded bg-muted/40 hover:bg-muted/60 transition-colors cursor-default">
69
+ <div className="text-sm font-semibold text-foreground">{stats.unreadChanges}</div>
70
+ <div className="text-xs text-muted-foreground truncate">Changes</div>
71
+ </div>
72
+ <div className="flex flex-col items-center p-1.5 rounded bg-muted/40 hover:bg-muted/60 transition-colors cursor-default">
73
+ <div className="text-sm font-semibold text-foreground">{stats.sessionCount}</div>
74
+ <div className="text-xs text-muted-foreground truncate">Chats</div>
75
+ </div>
76
+ </div>
77
+
78
+ {/* Recent Activity */}
79
+ {recentEvents.length > 0 && (
80
+ <div className="flex flex-col gap-1">
81
+ <div className="text-xs font-medium text-muted-foreground px-0.5">Recent</div>
82
+ {recentEvents.map((evt) => {
83
+ const relTime = formatRelativeTime(evt.ts);
84
+ const iconType = getIconForOp(evt.op);
85
+ const fileName = evt.path.split('/').pop() || evt.path;
86
+ return (
87
+ <div key={evt.id} className="flex items-start gap-2 p-1.5 rounded hover:bg-muted/40 transition-colors text-xs">
88
+ <span className="text-muted-foreground shrink-0 mt-0.5">{iconType}</span>
89
+ <div className="min-w-0 flex-1">
90
+ <p className="text-foreground truncate font-medium" title={fileName}>{fileName}</p>
91
+ <p className="text-muted-foreground text-2xs">{relTime}</p>
92
+ </div>
93
+ </div>
94
+ );
95
+ })}
96
+ </div>
97
+ )}
98
+ </div>
99
+ );
100
+ }
101
+
102
+ function getIconForOp(op: string): React.ReactNode {
103
+ switch (op) {
104
+ case 'create':
105
+ return <TrendingUp size={12} className="text-success" />;
106
+ case 'write':
107
+ case 'append':
108
+ return <AlertCircle size={12} className="text-foreground" />;
109
+ case 'delete':
110
+ return <AlertCircle size={12} className="text-destructive" />;
111
+ case 'rename':
112
+ case 'move':
113
+ return <MessageSquare size={12} className="text-muted-foreground" />;
114
+ default:
115
+ return <AlertCircle size={12} className="text-muted-foreground" />;
116
+ }
117
+ }
118
+
119
+ function formatRelativeTime(isoString: string): string {
120
+ try {
121
+ const date = new Date(isoString);
122
+ const now = new Date();
123
+ const diffMs = now.getTime() - date.getTime();
124
+ const diffMins = Math.floor(diffMs / 60000);
125
+ const diffHours = Math.floor(diffMs / 3600000);
126
+ const diffDays = Math.floor(diffMs / 86400000);
127
+
128
+ if (diffMins < 1) return 'now';
129
+ if (diffMins < 60) return `${diffMins}m ago`;
130
+ if (diffHours < 24) return `${diffHours}h ago`;
131
+ if (diffDays < 7) return `${diffDays}d ago`;
132
+ return date.toLocaleDateString('en-US', { month: 'short', day: 'numeric' });
133
+ } catch {
134
+ return 'recently';
135
+ }
136
+ }
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { useState, useEffect, useCallback, useSyncExternalStore, useRef } from 'react';
4
4
  import { Copy, Check, RefreshCw, Trash2, Sparkles, ChevronDown, ChevronRight, Loader2, Cpu, Zap, Database as DatabaseIcon, HardDrive, RotateCcw } from 'lucide-react';
5
+ import { toast } from '@/lib/toast';
5
6
  import type { KnowledgeTabProps } from './types';
6
7
  import { Field, Input, EnvBadge, SectionLabel, Toggle } from './Primitives';
7
8
  import { ConfirmDialog } from '@/components/agents/AgentsPrimitives';
@@ -96,7 +97,6 @@ export function KnowledgeTab({ data, setData, t }: KnowledgeTabProps) {
96
97
  const [showPassword, setShowPassword] = useState(false);
97
98
  const isPasswordMasked = data.webPassword === '***set***';
98
99
 
99
- const [copied, setCopied] = useState(false);
100
100
  const [resetting, setResetting] = useState(false);
101
101
  // revealed holds the plaintext token after regenerate, until user navigates away
102
102
  const [revealedToken, setRevealedToken] = useState<string | null>(null);
@@ -130,10 +130,7 @@ export function KnowledgeTab({ data, setData, t }: KnowledgeTabProps) {
130
130
  const text = revealedToken ?? data.authToken ?? '';
131
131
  if (!text) return;
132
132
  copyToClipboard(text).then((ok) => {
133
- if (ok) {
134
- setCopied(true);
135
- setTimeout(() => setCopied(false), 2000);
136
- }
133
+ if (ok) toast.copy();
137
134
  });
138
135
  }
139
136
 
@@ -229,7 +226,7 @@ export function KnowledgeTab({ data, setData, t }: KnowledgeTabProps) {
229
226
  className="shrink-0 p-1 rounded text-muted-foreground hover:text-foreground transition-colors"
230
227
  title={k.authTokenCopy}
231
228
  >
232
- {copied ? <Check size={13} className="text-success" /> : <Copy size={13} />}
229
+ <Copy size={13} />
233
230
  </button>
234
231
  )}
235
232
  </div>
@@ -3,8 +3,9 @@
3
3
  import { useState, useEffect, useCallback, useMemo } from 'react';
4
4
  import {
5
5
  Loader2, ChevronDown, ChevronRight,
6
- Plus, X, Search, Copy, Check,
6
+ Plus, X, Search, Copy,
7
7
  } from 'lucide-react';
8
+ import { toast } from '@/lib/toast';
8
9
  import { apiFetch } from '@/lib/api';
9
10
  import { useMcpDataOptional } from '@/hooks/useMcpData';
10
11
  import { ConfirmDialog } from '@/components/agents/AgentsPrimitives';
@@ -398,14 +399,12 @@ function SkillCliHint({ agents, skillName, m }: {
398
399
  m: Record<string, any> | undefined;
399
400
  }) {
400
401
  const [selectedAgent, setSelectedAgent] = useState('claude-code');
401
- const [copied, setCopied] = useState(false);
402
-
403
402
  const cmd = `npx skills add GeminiLight/MindOS --skill ${skillName} -a ${selectedAgent} -g -y`;
404
403
  const skillPath = `~/.agents/skills/${skillName}/SKILL.md`;
405
404
 
406
405
  const handleCopy = async () => {
407
406
  const ok = await copyToClipboard(cmd);
408
- if (ok) { setCopied(true); setTimeout(() => setCopied(false), 2000); }
407
+ if (ok) toast.copy();
409
408
  };
410
409
 
411
410
  // Group agents: connected first, then detected, then not found
@@ -447,7 +446,7 @@ function SkillCliHint({ agents, skillName, m }: {
447
446
  </code>
448
447
  <button onClick={handleCopy}
449
448
  className="p-1.5 rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors shrink-0">
450
- {copied ? <Check size={11} /> : <Copy size={11} />}
449
+ <Copy size={11} />
451
450
  </button>
452
451
  </div>
453
452
 
@@ -1,5 +1,6 @@
1
1
  import { useState, useMemo, useRef, useEffect } from 'react';
2
- import { Loader2, Copy, Check, Monitor, Globe, AlertCircle, RotateCcw, RefreshCw } from 'lucide-react';
2
+ import { Loader2, Copy, Monitor, Globe, AlertCircle, RotateCcw, RefreshCw } from 'lucide-react';
3
+ import { toast } from '@/lib/toast';
3
4
  import { useMcpDataOptional } from '@/hooks/useMcpData';
4
5
  import { generateSnippet } from '@/lib/mcp-snippets';
5
6
  import { copyToClipboard } from '@/lib/clipboard';
@@ -22,7 +23,6 @@ export function McpTab({ t }: McpTabProps) {
22
23
  const [restarting, setRestarting] = useState(false);
23
24
  const [selectedAgent, setSelectedAgent] = useState('');
24
25
  const [transport, setTransport] = useState<'stdio' | 'http'>('stdio');
25
- const [copied, setCopied] = useState(false);
26
26
  const restartPollRef = useRef<ReturnType<typeof setInterval>>(undefined);
27
27
 
28
28
  // Cleanup restart poll on unmount
@@ -99,10 +99,9 @@ export function McpTab({ t }: McpTabProps) {
99
99
  onSelectAgent={(key) => setSelectedAgent(key)}
100
100
  transport={transport}
101
101
  onTransportChange={setTransport}
102
- copied={copied}
103
102
  onCopy={async (snippet) => {
104
103
  const ok = await copyToClipboard(snippet);
105
- if (ok) { setCopied(true); setTimeout(() => setCopied(false), 2000); }
104
+ if (ok) toast.copy();
106
105
  }}
107
106
  m={m}
108
107
  />
@@ -177,7 +176,7 @@ function McpStatusCard({ status, restarting, onRestart, onRefresh, m }: {
177
176
 
178
177
  /* ── Agent Config Viewer (dropdown + snippet) ── */
179
178
 
180
- function AgentConfigViewer({ connectedAgents, detectedAgents, notFoundAgents, currentAgent, mcpStatus, selectedAgent, onSelectAgent, transport, onTransportChange, copied, onCopy, m }: {
179
+ function AgentConfigViewer({ connectedAgents, detectedAgents, notFoundAgents, currentAgent, mcpStatus, selectedAgent, onSelectAgent, transport, onTransportChange, onCopy, m }: {
181
180
  connectedAgents: AgentInfo[];
182
181
  detectedAgents: AgentInfo[];
183
182
  notFoundAgents: AgentInfo[];
@@ -187,7 +186,6 @@ function AgentConfigViewer({ connectedAgents, detectedAgents, notFoundAgents, cu
187
186
  onSelectAgent: (key: string) => void;
188
187
  transport: 'stdio' | 'http';
189
188
  onTransportChange: (t: 'stdio' | 'http') => void;
190
- copied: boolean;
191
189
  onCopy: (snippet: string) => void;
192
190
  m: Record<string, any> | undefined;
193
191
  }) {
@@ -292,8 +290,8 @@ function AgentConfigViewer({ connectedAgents, detectedAgents, notFoundAgents, cu
292
290
  <div className="flex items-center gap-3 text-xs">
293
291
  <button onClick={() => onCopy(snippet.snippet)}
294
292
  className="inline-flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors shrink-0">
295
- {copied ? <Check size={12} /> : <Copy size={12} />}
296
- {copied ? (m?.copied ?? 'Copied!') : (m?.copyConfig ?? 'Copy config')}
293
+ <Copy size={12} />
294
+ {m?.copyConfig ?? 'Copy config'}
297
295
  </button>
298
296
  <span className="text-muted-foreground">→</span>
299
297
  <span className="font-mono text-muted-foreground truncate text-2xs">{snippet.path}</span>
@@ -1,13 +1,12 @@
1
1
  'use client';
2
2
 
3
3
  import { useState } from 'react';
4
- import { Copy, Check, RefreshCw } from 'lucide-react';
4
+ import { Copy, RefreshCw } from 'lucide-react';
5
5
  import { Field, Input } from '@/components/settings/Primitives';
6
6
  import type { SetupMessages } from './types';
7
7
 
8
8
  export interface StepSecurityProps {
9
9
  authToken: string;
10
- tokenCopied: boolean;
11
10
  onCopy: () => void;
12
11
  onGenerate: (seed?: string) => void;
13
12
  webPassword: string;
@@ -16,7 +15,7 @@ export interface StepSecurityProps {
16
15
  }
17
16
 
18
17
  export default function StepSecurity({
19
- authToken, tokenCopied, onCopy, onGenerate, webPassword, onPasswordChange, s,
18
+ authToken, onCopy, onGenerate, webPassword, onPasswordChange, s,
20
19
  }: StepSecurityProps) {
21
20
  const [seed, setSeed] = useState('');
22
21
  const [showSeed, setShowSeed] = useState(false);
@@ -29,8 +28,8 @@ export default function StepSecurity({
29
28
  <button onClick={onCopy}
30
29
  className="flex items-center gap-1 px-3 py-2 text-xs rounded-lg border border-border hover:bg-muted transition-colors shrink-0"
31
30
  style={{ color: 'var(--foreground)' }}>
32
- {tokenCopied ? <Check size={14} /> : <Copy size={14} />}
33
- {tokenCopied ? s.copiedToken : s.copyToken}
31
+ <Copy size={14} />
32
+ {s.copyToken}
34
33
  </button>
35
34
  <button onClick={() => onGenerate()}
36
35
  aria-label={s.generateToken}
@@ -4,6 +4,7 @@ import { useState, useEffect, useCallback } from 'react';
4
4
  import { Sparkles, Loader2, ChevronLeft, ChevronRight } from 'lucide-react';
5
5
  import { useLocale } from '@/lib/LocaleContext';
6
6
  import { copyToClipboard } from '@/lib/clipboard';
7
+ import { toast } from '@/lib/toast';
7
8
  import type { SetupState, PortStatus, AgentEntry, AgentInstallStatus } from './types';
8
9
  import { TOTAL_STEPS, STEP_KB, STEP_PORTS, STEP_AGENTS } from './constants';
9
10
  import StepKB from './StepKB';
@@ -127,7 +128,6 @@ export default function SetupWizard() {
127
128
  webPassword: '',
128
129
  });
129
130
  const [homeDir, setHomeDir] = useState('~');
130
- const [tokenCopied, setTokenCopied] = useState(false);
131
131
  const [submitting, setSubmitting] = useState(false);
132
132
  const [completed, setCompleted] = useState(false);
133
133
  const [error, setError] = useState('');
@@ -230,15 +230,9 @@ export default function SetupWizard() {
230
230
  }, []);
231
231
 
232
232
  const copyToken = useCallback(() => {
233
- copyToClipboard(state.authToken)
234
- .then(() => {
235
- setTokenCopied(true);
236
- setTimeout(() => setTokenCopied(false), 2000);
237
- })
238
- .catch((err) => {
239
- console.error('[Setup] Token copy failed:', err);
240
- // Show error toast instead of success
241
- });
233
+ copyToClipboard(state.authToken).then((ok) => {
234
+ if (ok) toast.copy();
235
+ });
242
236
  }, [state.authToken]);
243
237
 
244
238
  const checkPort = useCallback(async (port: number, which: 'web' | 'mcp') => {
@@ -384,7 +378,7 @@ export default function SetupWizard() {
384
378
  )}
385
379
  {step === 3 && (
386
380
  <StepSecurity
387
- authToken={state.authToken} tokenCopied={tokenCopied}
381
+ authToken={state.authToken}
388
382
  onCopy={copyToken} onGenerate={generateToken}
389
383
  webPassword={state.webPassword} onPasswordChange={v => update('webPassword', v)}
390
384
  s={s}
@@ -0,0 +1,39 @@
1
+ 'use client';
2
+
3
+ import { useSyncExternalStore } from 'react';
4
+ import { Check, AlertCircle, Info, X } from 'lucide-react';
5
+ import { subscribe, getSnapshot, dismiss, type Toast } from '@/lib/toast';
6
+
7
+ const icons: Record<Toast['type'], React.ReactNode> = {
8
+ success: <Check size={15} className="text-success shrink-0" />,
9
+ error: <AlertCircle size={15} className="text-error shrink-0" />,
10
+ info: <Info size={15} className="text-muted-foreground shrink-0" />,
11
+ };
12
+
13
+ export default function Toaster() {
14
+ const toasts = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
15
+
16
+ if (toasts.length === 0) return null;
17
+
18
+ return (
19
+ <div className="fixed bottom-4 right-4 z-50 flex flex-col-reverse gap-2 pointer-events-none" aria-live="polite">
20
+ {toasts.map((t) => (
21
+ <div
22
+ key={t.id}
23
+ className="pointer-events-auto flex items-center gap-2.5 bg-card border border-border rounded-lg shadow-lg px-4 py-2.5 min-w-[180px] max-w-[320px] animate-in slide-in-from-right-4 fade-in duration-200"
24
+ >
25
+ {icons[t.type]}
26
+ <span className="text-sm text-foreground flex-1 truncate">{t.message}</span>
27
+ <button
28
+ type="button"
29
+ onClick={() => dismiss(t.id)}
30
+ className="shrink-0 p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors"
31
+ aria-label="Dismiss"
32
+ >
33
+ <X size={13} />
34
+ </button>
35
+ </div>
36
+ ))}
37
+ </div>
38
+ );
39
+ }
@@ -8,6 +8,7 @@ interface A2aRegistry {
8
8
  discovering: boolean;
9
9
  error: string | null;
10
10
  discover: (url: string) => Promise<RemoteAgent | null>;
11
+ remove: (id: string) => void;
11
12
  refresh: () => void;
12
13
  }
13
14
 
@@ -44,10 +45,14 @@ export function useA2aRegistry(): A2aRegistry {
44
45
  }
45
46
  }, []);
46
47
 
48
+ const remove = useCallback((id: string) => {
49
+ setAgents(prev => prev.filter(a => a.id !== id));
50
+ }, []);
51
+
47
52
  const refresh = useCallback(() => {
48
53
  setAgents([]);
49
54
  setError(null);
50
55
  }, []);
51
56
 
52
- return { agents, discovering, error, discover, refresh };
57
+ return { agents, discovering, error, discover, remove, refresh };
53
58
  }
@@ -0,0 +1,65 @@
1
+ 'use client';
2
+
3
+ import { useState, useEffect, useCallback } from 'react';
4
+
5
+ export interface DetectedAgent {
6
+ id: string;
7
+ name: string;
8
+ binaryPath: string;
9
+ }
10
+
11
+ export interface NotInstalledAgent {
12
+ id: string;
13
+ name: string;
14
+ installCmd: string;
15
+ }
16
+
17
+ interface AcpDetectionState {
18
+ installedAgents: DetectedAgent[];
19
+ notInstalledAgents: NotInstalledAgent[];
20
+ loading: boolean;
21
+ error: string | null;
22
+ refresh: () => void;
23
+ }
24
+
25
+ export function useAcpDetection(): AcpDetectionState {
26
+ const [installedAgents, setInstalledAgents] = useState<DetectedAgent[]>([]);
27
+ const [notInstalledAgents, setNotInstalledAgents] = useState<NotInstalledAgent[]>([]);
28
+ const [loading, setLoading] = useState(true);
29
+ const [error, setError] = useState<string | null>(null);
30
+ const [trigger, setTrigger] = useState(0);
31
+
32
+ const refresh = useCallback(() => {
33
+ setTrigger((n) => n + 1);
34
+ }, []);
35
+
36
+ useEffect(() => {
37
+ let cancelled = false;
38
+ setLoading(true);
39
+ setError(null);
40
+
41
+ fetch('/api/acp/detect')
42
+ .then((res) => {
43
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
44
+ return res.json();
45
+ })
46
+ .then((data) => {
47
+ if (cancelled) return;
48
+ setInstalledAgents(data.installed ?? []);
49
+ setNotInstalledAgents(data.notInstalled ?? []);
50
+ })
51
+ .catch((err) => {
52
+ if (cancelled) return;
53
+ setError((err as Error).message);
54
+ })
55
+ .finally(() => {
56
+ if (!cancelled) setLoading(false);
57
+ });
58
+
59
+ return () => {
60
+ cancelled = true;
61
+ };
62
+ }, [trigger]);
63
+
64
+ return { installedAgents, notInstalledAgents, loading, error, refresh };
65
+ }
@@ -0,0 +1,51 @@
1
+ 'use client';
2
+
3
+ import { useState, useEffect, useCallback } from 'react';
4
+ import type { AcpRegistryEntry } from '@/lib/acp/types';
5
+
6
+ interface AcpRegistryState {
7
+ agents: AcpRegistryEntry[];
8
+ loading: boolean;
9
+ error: string | null;
10
+ retry: () => void;
11
+ }
12
+
13
+ export function useAcpRegistry(): AcpRegistryState {
14
+ const [agents, setAgents] = useState<AcpRegistryEntry[]>([]);
15
+ const [loading, setLoading] = useState(true);
16
+ const [error, setError] = useState<string | null>(null);
17
+ const [trigger, setTrigger] = useState(0);
18
+
19
+ const retry = useCallback(() => {
20
+ setTrigger((n) => n + 1);
21
+ }, []);
22
+
23
+ useEffect(() => {
24
+ let cancelled = false;
25
+ setLoading(true);
26
+ setError(null);
27
+
28
+ fetch('/api/acp/registry')
29
+ .then((res) => {
30
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
31
+ return res.json();
32
+ })
33
+ .then((data) => {
34
+ if (cancelled) return;
35
+ setAgents(data.registry?.agents ?? []);
36
+ })
37
+ .catch((err) => {
38
+ if (cancelled) return;
39
+ setError((err as Error).message);
40
+ })
41
+ .finally(() => {
42
+ if (!cancelled) setLoading(false);
43
+ });
44
+
45
+ return () => {
46
+ cancelled = true;
47
+ };
48
+ }, [trigger]);
49
+
50
+ return { agents, loading, error, retry };
51
+ }
@@ -0,0 +1,49 @@
1
+ 'use client';
2
+
3
+ import { useState, useEffect, useCallback, useRef } from 'react';
4
+ import type { DelegationRecord } from '@/lib/a2a/types';
5
+
6
+ interface DelegationHistory {
7
+ delegations: DelegationRecord[];
8
+ loading: boolean;
9
+ refresh: () => void;
10
+ }
11
+
12
+ const POLL_INTERVAL_MS = 5_000;
13
+
14
+ export function useDelegationHistory(active: boolean): DelegationHistory {
15
+ const [delegations, setDelegations] = useState<DelegationRecord[]>([]);
16
+ const [loading, setLoading] = useState(false);
17
+ const mountedRef = useRef(true);
18
+
19
+ const fetchHistory = useCallback(async () => {
20
+ setLoading(true);
21
+ try {
22
+ const res = await fetch('/api/a2a/delegations');
23
+ if (!res.ok) return;
24
+ const data = await res.json();
25
+ if (mountedRef.current) {
26
+ setDelegations(data.delegations ?? []);
27
+ }
28
+ } catch {
29
+ // silently ignore fetch errors
30
+ } finally {
31
+ if (mountedRef.current) setLoading(false);
32
+ }
33
+ }, []);
34
+
35
+ useEffect(() => {
36
+ mountedRef.current = true;
37
+ return () => { mountedRef.current = false; };
38
+ }, []);
39
+
40
+ // Fetch on mount and poll while active
41
+ useEffect(() => {
42
+ if (!active) return;
43
+ fetchHistory();
44
+ const id = setInterval(fetchHistory, POLL_INTERVAL_MS);
45
+ return () => clearInterval(id);
46
+ }, [active, fetchHistory]);
47
+
48
+ return { delegations, loading, refresh: fetchHistory };
49
+ }
@@ -10,6 +10,7 @@ import type {
10
10
  JsonRpcRequest,
11
11
  JsonRpcResponse,
12
12
  SendMessageParams,
13
+ DelegationRecord,
13
14
  } from './types';
14
15
 
15
16
  /* ── Constants ─────────────────────────────────────────────────────────── */
@@ -22,6 +23,20 @@ const CARD_CACHE_TTL_MS = 5 * 60 * 1000; // 5 min
22
23
 
23
24
  const registry = new Map<string, RemoteAgent>();
24
25
 
26
+ /* ── Delegation History ────────────────────────────────────────────────── */
27
+
28
+ const delegationHistory: DelegationRecord[] = [];
29
+
30
+ /** Get all delegation history records */
31
+ export function getDelegationHistory(): DelegationRecord[] {
32
+ return [...delegationHistory];
33
+ }
34
+
35
+ /** Clear all delegation history records */
36
+ export function clearDelegationHistory(): void {
37
+ delegationHistory.length = 0;
38
+ }
39
+
25
40
  /** Derive a stable ID from a URL (includes protocol to avoid collisions) */
26
41
  function urlToId(url: string): string {
27
42
  try {
@@ -152,6 +167,19 @@ export async function delegateTask(
152
167
  if (!agent) throw new Error(`Agent not found: ${agentId}`);
153
168
  if (!agent.reachable) throw new Error(`Agent not reachable: ${agent.card.name}`);
154
169
 
170
+ const record: DelegationRecord = {
171
+ id: `del-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
172
+ agentId,
173
+ agentName: agent.card.name,
174
+ message,
175
+ status: 'pending',
176
+ startedAt: new Date().toISOString(),
177
+ completedAt: null,
178
+ result: null,
179
+ error: null,
180
+ };
181
+ delegationHistory.push(record);
182
+
155
183
  const params: SendMessageParams = {
156
184
  message: {
157
185
  role: 'ROLE_USER',
@@ -160,13 +188,29 @@ export async function delegateTask(
160
188
  configuration: { blocking: true },
161
189
  };
162
190
 
163
- const response = await jsonRpcCall(agent.endpoint, 'SendMessage', params, token);
191
+ try {
192
+ const response = await jsonRpcCall(agent.endpoint, 'SendMessage', params, token);
164
193
 
165
- if (response.error) {
166
- throw new Error(`A2A error [${response.error.code}]: ${response.error.message}`);
167
- }
194
+ if (response.error) {
195
+ record.status = 'failed';
196
+ record.completedAt = new Date().toISOString();
197
+ record.error = `A2A error [${response.error.code}]: ${response.error.message}`;
198
+ throw new Error(record.error);
199
+ }
168
200
 
169
- return response.result as A2ATask;
201
+ const task = response.result as A2ATask;
202
+ record.status = 'completed';
203
+ record.completedAt = new Date().toISOString();
204
+ record.result = task.artifacts?.[0]?.parts?.[0]?.text ?? null;
205
+ return task;
206
+ } catch (err) {
207
+ if (record.status === 'pending') {
208
+ record.status = 'failed';
209
+ record.completedAt = new Date().toISOString();
210
+ record.error = (err as Error).message;
211
+ }
212
+ throw err;
213
+ }
170
214
  }
171
215
 
172
216
  /**
@@ -5,7 +5,6 @@
5
5
 
6
6
  import { randomUUID } from 'crypto';
7
7
  import type {
8
- RemoteAgent,
9
8
  SubTask,
10
9
  OrchestrationPlan,
11
10
  ExecutionStrategy,