@geminilight/mindos 0.6.25 → 0.6.27

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 (40) hide show
  1. package/README.md +19 -3
  2. package/README_zh.md +19 -3
  3. package/app/app/api/a2a/discover/route.ts +23 -0
  4. package/app/components/CreateSpaceModal.tsx +1 -0
  5. package/app/components/ImportModal.tsx +3 -0
  6. package/app/components/OnboardingView.tsx +1 -0
  7. package/app/components/RightAskPanel.tsx +4 -2
  8. package/app/components/SidebarLayout.tsx +11 -2
  9. package/app/components/agents/DiscoverAgentModal.tsx +149 -0
  10. package/app/components/ask/AskContent.tsx +21 -9
  11. package/app/components/ask/SessionTabBar.tsx +70 -0
  12. package/app/components/echo/EchoInsightCollapsible.tsx +4 -0
  13. package/app/components/panels/AgentsPanel.tsx +25 -2
  14. package/app/components/renderers/workflow/WorkflowRenderer.tsx +5 -0
  15. package/app/components/settings/AiTab.tsx +1 -0
  16. package/app/components/settings/KnowledgeTab.tsx +2 -0
  17. package/app/components/settings/SyncTab.tsx +2 -0
  18. package/app/components/setup/StepDots.tsx +5 -1
  19. package/app/data/skills/mindos/SKILL.md +186 -0
  20. package/app/data/skills/mindos-zh/SKILL.md +185 -0
  21. package/app/hooks/useA2aRegistry.ts +53 -0
  22. package/app/hooks/useAskSession.ts +44 -25
  23. package/app/lib/a2a/a2a-tools.ts +212 -0
  24. package/app/lib/a2a/client.ts +207 -0
  25. package/app/lib/a2a/index.ts +8 -0
  26. package/app/lib/a2a/orchestrator.ts +255 -0
  27. package/app/lib/a2a/types.ts +54 -0
  28. package/app/lib/agent/tools.ts +6 -4
  29. package/app/lib/i18n-en.ts +52 -0
  30. package/app/lib/i18n-zh.ts +52 -0
  31. package/app/next-env.d.ts +1 -1
  32. package/bin/cli.js +180 -171
  33. package/bin/commands/agent.js +110 -18
  34. package/bin/commands/api.js +5 -3
  35. package/bin/commands/ask.js +3 -3
  36. package/bin/commands/file.js +13 -13
  37. package/bin/commands/search.js +2 -2
  38. package/bin/commands/space.js +64 -10
  39. package/bin/lib/command.js +10 -0
  40. package/package.json +1 -1
@@ -0,0 +1,255 @@
1
+ /**
2
+ * A2A Orchestrator — Multi-agent task decomposition and execution.
3
+ * Phase 3: Breaks complex requests into sub-tasks, matches to agents, executes, aggregates.
4
+ */
5
+
6
+ import { randomUUID } from 'crypto';
7
+ import type {
8
+ RemoteAgent,
9
+ SubTask,
10
+ OrchestrationPlan,
11
+ ExecutionStrategy,
12
+ SkillMatch,
13
+ AgentSkill,
14
+ } from './types';
15
+ import { getDiscoveredAgents, delegateTask } from './client';
16
+
17
+ /* ── Constants ─────────────────────────────────────────────────────────── */
18
+
19
+ const MAX_SUBTASKS = 10;
20
+
21
+ /* ── Skill Matcher ─────────────────────────────────────────────────────── */
22
+
23
+ /** Score how well a skill matches a task description (keyword overlap, deduplicated) */
24
+ function scoreSkillMatch(taskDesc: string, skill: AgentSkill): number {
25
+ const taskWords = new Set(taskDesc.toLowerCase().split(/\s+/));
26
+ // Deduplicate skill words to avoid double-counting from name + description overlap
27
+ const skillWords = new Set([
28
+ ...skill.name.toLowerCase().split(/\s+/),
29
+ ...skill.description.toLowerCase().split(/\s+/),
30
+ ...(skill.tags ?? []).map(t => t.toLowerCase()),
31
+ ]);
32
+ let matches = 0;
33
+ for (const w of skillWords) {
34
+ if (w.length > 2 && taskWords.has(w)) matches++;
35
+ }
36
+ return matches;
37
+ }
38
+
39
+ /**
40
+ * Find the best agent+skill match for a sub-task description.
41
+ * Returns null if no agent has a relevant skill.
42
+ */
43
+ export function matchSkill(taskDescription: string): SkillMatch | null {
44
+ const agents = getDiscoveredAgents().filter(a => a.reachable);
45
+ if (agents.length === 0) return null;
46
+
47
+ let best: SkillMatch | null = null;
48
+ let bestScore = 0;
49
+
50
+ for (const agent of agents) {
51
+ for (const skill of agent.card.skills) {
52
+ const score = scoreSkillMatch(taskDescription, skill);
53
+ if (score > bestScore) {
54
+ bestScore = score;
55
+ best = {
56
+ agentId: agent.id,
57
+ agentName: agent.card.name,
58
+ skillId: skill.id,
59
+ skillName: skill.name,
60
+ confidence: Math.min(score / 3, 1),
61
+ };
62
+ }
63
+ }
64
+ }
65
+
66
+ return best;
67
+ }
68
+
69
+ /* ── Task Decomposer ───────────────────────────────────────────────────── */
70
+
71
+ /**
72
+ * Decompose a complex request into sub-tasks.
73
+ * Uses simple heuristics: split on sentence boundaries and conjunctions.
74
+ * For LLM-based decomposition, the agent tool can call this with pre-decomposed parts.
75
+ */
76
+ export function decompose(request: string, subtaskDescriptions?: string[]): SubTask[] {
77
+ let descriptions: string[];
78
+
79
+ if (subtaskDescriptions && subtaskDescriptions.length > 0) {
80
+ descriptions = subtaskDescriptions;
81
+ } else {
82
+ descriptions = splitIntoSubtasks(request);
83
+ }
84
+
85
+ return descriptions.slice(0, MAX_SUBTASKS).map((desc, i) => ({
86
+ id: `st-${randomUUID().slice(0, 8)}`,
87
+ description: desc.trim(),
88
+ assignedAgentId: null,
89
+ matchedSkillId: null,
90
+ status: 'pending' as const,
91
+ result: null,
92
+ error: null,
93
+ dependsOn: [],
94
+ }));
95
+ }
96
+
97
+ /** Simple heuristic: split on "and then", "then", "also", numbered lists, semicolons */
98
+ function splitIntoSubtasks(text: string): string[] {
99
+ // Try numbered list first: split on "N. " pattern at boundaries
100
+ const numbered = text.split(/(?:^|\s)(?=\d+\.\s)/m).map(s => s.replace(/^\d+\.\s*/, '').trim()).filter(Boolean);
101
+ if (numbered.length >= 2) return numbered;
102
+
103
+ // Try splitting on conjunctions/semicolons
104
+ const parts = text.split(/;\s*|\.\s+(?:then|and then|also|next|finally)\s+/i).filter(Boolean);
105
+ if (parts.length >= 2) return parts;
106
+
107
+ // Fallback: treat as single task
108
+ return [text];
109
+ }
110
+
111
+ /* ── Execution Engine ──────────────────────────────────────────────────── */
112
+
113
+ /**
114
+ * Create an orchestration plan from a request.
115
+ */
116
+ export function createPlan(
117
+ request: string,
118
+ strategy: ExecutionStrategy = 'parallel',
119
+ subtaskDescriptions?: string[],
120
+ ): OrchestrationPlan {
121
+ const subtasks = decompose(request, subtaskDescriptions);
122
+
123
+ // Auto-match skills to agents
124
+ for (const st of subtasks) {
125
+ const match = matchSkill(st.description);
126
+ if (match) {
127
+ st.assignedAgentId = match.agentId;
128
+ st.matchedSkillId = match.skillId;
129
+ }
130
+ }
131
+
132
+ return {
133
+ id: `plan-${randomUUID().slice(0, 8)}`,
134
+ originalRequest: request,
135
+ strategy,
136
+ subtasks,
137
+ createdAt: new Date().toISOString(),
138
+ completedAt: null,
139
+ status: 'planning',
140
+ aggregatedResult: null,
141
+ };
142
+ }
143
+
144
+ /**
145
+ * Execute a single sub-task by delegating to its assigned agent.
146
+ */
147
+ async function executeSubtask(subtask: SubTask, token?: string): Promise<void> {
148
+ if (!subtask.assignedAgentId) {
149
+ subtask.status = 'failed';
150
+ subtask.error = 'No agent assigned to this subtask';
151
+ return;
152
+ }
153
+
154
+ subtask.status = 'running';
155
+
156
+ try {
157
+ // delegateTask has its own 30s RPC timeout via fetchWithTimeout in client.ts
158
+ const task = await delegateTask(subtask.assignedAgentId, subtask.description, token);
159
+
160
+ if (task.status.state === 'TASK_STATE_COMPLETED') {
161
+ subtask.status = 'completed';
162
+ subtask.result = task.artifacts?.[0]?.parts?.[0]?.text
163
+ ?? task.history?.find(m => m.role === 'ROLE_AGENT')?.parts?.[0]?.text
164
+ ?? 'Completed (no text result)';
165
+ } else if (task.status.state === 'TASK_STATE_FAILED') {
166
+ subtask.status = 'failed';
167
+ subtask.error = task.status.message?.parts?.[0]?.text ?? 'Agent reported failure';
168
+ } else {
169
+ subtask.status = 'completed';
170
+ subtask.result = `Task in progress (state: ${task.status.state})`;
171
+ }
172
+ } catch (err) {
173
+ subtask.status = 'failed';
174
+ subtask.error = (err as Error).message;
175
+ }
176
+ }
177
+
178
+ /**
179
+ * Execute all sub-tasks in an orchestration plan.
180
+ */
181
+ export async function executePlan(plan: OrchestrationPlan, token?: string): Promise<OrchestrationPlan> {
182
+ plan.status = 'executing';
183
+
184
+ const unassigned = plan.subtasks.filter(st => !st.assignedAgentId);
185
+ if (unassigned.length === plan.subtasks.length) {
186
+ plan.status = 'failed';
187
+ plan.aggregatedResult = 'No agents available for any subtask. Discover agents first using discover_agent.';
188
+ return plan;
189
+ }
190
+
191
+ // Mark unassigned subtasks as failed before execution
192
+ for (const st of plan.subtasks) {
193
+ if (!st.assignedAgentId) {
194
+ st.status = 'failed';
195
+ st.error = 'No matching agent found for this subtask';
196
+ }
197
+ }
198
+
199
+ const assignedTasks = plan.subtasks.filter(st => st.assignedAgentId);
200
+
201
+ if (plan.strategy === 'parallel') {
202
+ await Promise.allSettled(
203
+ assignedTasks.map(st => executeSubtask(st, token))
204
+ );
205
+ } else {
206
+ // Sequential or dependency-based
207
+ for (const st of plan.subtasks) {
208
+ if (!st.assignedAgentId) {
209
+ st.status = 'failed';
210
+ st.error = 'No agent assigned';
211
+ continue;
212
+ }
213
+
214
+ // Check dependencies
215
+ if (st.dependsOn.length > 0) {
216
+ const deps = st.dependsOn.map(id => plan.subtasks.find(s => s.id === id));
217
+ const allDone = deps.every(d => d?.status === 'completed');
218
+ if (!allDone) {
219
+ st.status = 'failed';
220
+ st.error = 'Dependencies not met';
221
+ continue;
222
+ }
223
+ }
224
+
225
+ await executeSubtask(st, token);
226
+
227
+ // Stop on failure in sequential mode
228
+ if (plan.strategy === 'sequential' && st.status === 'failed') break;
229
+ }
230
+ }
231
+
232
+ // Aggregate results
233
+ const completed = plan.subtasks.filter(st => st.status === 'completed');
234
+ const failed = plan.subtasks.filter(st => st.status === 'failed');
235
+
236
+ if (failed.length === plan.subtasks.length) {
237
+ plan.status = 'failed';
238
+ plan.aggregatedResult = `All ${failed.length} subtasks failed:\n` +
239
+ failed.map(st => `- ${st.description}: ${st.error}`).join('\n');
240
+ } else {
241
+ plan.status = 'completed';
242
+ const parts: string[] = [];
243
+ for (const st of plan.subtasks) {
244
+ if (st.status === 'completed' && st.result) {
245
+ parts.push(`## ${st.description}\n\n${st.result}`);
246
+ } else if (st.status === 'failed') {
247
+ parts.push(`## ${st.description}\n\n[Failed: ${st.error}]`);
248
+ }
249
+ }
250
+ plan.aggregatedResult = parts.join('\n\n---\n\n');
251
+ }
252
+
253
+ plan.completedAt = new Date().toISOString();
254
+ return plan;
255
+ }
@@ -156,3 +156,57 @@ export const A2A_ERRORS = {
156
156
  INVALID_PARAMS: { code: -32602, message: 'Invalid params' },
157
157
  INTERNAL_ERROR: { code: -32603, message: 'Internal error' },
158
158
  } as const;
159
+
160
+ /* ── A2A Client Types (Phase 2) ────────────────────────────────────────── */
161
+
162
+ /** A discovered remote agent with its card and endpoint */
163
+ export interface RemoteAgent {
164
+ /** Unique identifier (derived from agent card URL) */
165
+ id: string;
166
+ /** The agent's card metadata */
167
+ card: AgentCard;
168
+ /** The JSON-RPC endpoint URL */
169
+ endpoint: string;
170
+ /** When this card was last fetched */
171
+ discoveredAt: string;
172
+ /** Whether the agent is currently reachable */
173
+ reachable: boolean;
174
+ }
175
+
176
+ /* ── Orchestration Types (Phase 3) ─────────────────────────────────────── */
177
+
178
+ /** A sub-task decomposed from a user request */
179
+ export interface SubTask {
180
+ id: string;
181
+ description: string;
182
+ assignedAgentId: string | null;
183
+ matchedSkillId: string | null;
184
+ status: 'pending' | 'running' | 'completed' | 'failed';
185
+ result: string | null;
186
+ error: string | null;
187
+ dependsOn: string[];
188
+ }
189
+
190
+ /** Execution strategy for sub-tasks */
191
+ export type ExecutionStrategy = 'parallel' | 'sequential' | 'dependency';
192
+
193
+ /** An orchestration plan produced by the decomposer */
194
+ export interface OrchestrationPlan {
195
+ id: string;
196
+ originalRequest: string;
197
+ strategy: ExecutionStrategy;
198
+ subtasks: SubTask[];
199
+ createdAt: string;
200
+ completedAt: string | null;
201
+ status: 'planning' | 'executing' | 'completed' | 'failed';
202
+ aggregatedResult: string | null;
203
+ }
204
+
205
+ /** Result of matching a sub-task to an agent skill */
206
+ export interface SkillMatch {
207
+ agentId: string;
208
+ agentName: string;
209
+ skillId: string;
210
+ skillName: string;
211
+ confidence: number;
212
+ }
@@ -9,6 +9,7 @@ import {
9
9
  } from '@/lib/fs';
10
10
  import { readSkillContentByName, scanSkillDirs } from '@/lib/pi-integration/skills';
11
11
  import { callMcporterTool, createMcporterAgentTools, listMcporterServers, listMcporterTools } from '@/lib/pi-integration/mcporter';
12
+ import { a2aTools } from '@/lib/a2a/a2a-tools';
12
13
 
13
14
  // Max chars per file to avoid token overflow (~100k chars ≈ ~25k tokens)
14
15
  const MAX_FILE_CHARS = 20_000;
@@ -186,10 +187,11 @@ export function getOrganizeTools(): AgentTool<any>[] {
186
187
  }
187
188
 
188
189
  export async function getRequestScopedTools(): Promise<AgentTool<any>[]> {
190
+ const baseTools = [...knowledgeBaseTools, ...a2aTools];
189
191
  try {
190
192
  const result = await listMcporterServers();
191
193
  const okServers = (result.servers ?? []).filter((server) => server.status === 'ok');
192
- if (okServers.length === 0) return knowledgeBaseTools;
194
+ if (okServers.length === 0) return baseTools;
193
195
 
194
196
  const detailedServers = await Promise.all(okServers.map(async (server) => {
195
197
  try {
@@ -200,10 +202,10 @@ export async function getRequestScopedTools(): Promise<AgentTool<any>[]> {
200
202
  }));
201
203
 
202
204
  const dynamicMcpTools = createMcporterAgentTools(detailedServers);
203
- if (dynamicMcpTools.length === 0) return knowledgeBaseTools;
204
- return [...knowledgeBaseTools, ...dynamicMcpTools];
205
+ if (dynamicMcpTools.length === 0) return baseTools;
206
+ return [...baseTools, ...dynamicMcpTools];
205
207
  } catch {
206
- return knowledgeBaseTools;
208
+ return baseTools;
207
209
  }
208
210
  }
209
211
 
@@ -241,6 +241,27 @@ export const en = {
241
241
  agentDetailPanelAria: 'Agent connection configuration',
242
242
  agentDetailTransport: 'Transport',
243
243
  agentDetailSnippet: 'Config snippet',
244
+ // A2A
245
+ a2aLabel: 'A2A',
246
+ a2aReady: 'A2A Ready',
247
+ a2aChecking: 'Checking A2A...',
248
+ a2aUnavailable: 'A2A Unavailable',
249
+ a2aRemote: 'Remote',
250
+ a2aDiscover: 'Discover Remote Agent',
251
+ a2aDiscoverHint: 'Connect to an external A2A agent by URL',
252
+ a2aDiscoverPlaceholder: 'https://agent.example.com',
253
+ a2aDiscovering: 'Discovering...',
254
+ a2aDiscoverSuccess: 'Agent discovered!',
255
+ a2aDiscoverFailed: 'No A2A agent found at this URL',
256
+ a2aDiscoverFailedHint: 'The server may not support the A2A protocol. Check the URL and try again.',
257
+ a2aSkills: 'Skills',
258
+ a2aEndpoint: 'Endpoint',
259
+ a2aVersion: 'Version',
260
+ a2aCapabilities: 'A2A Capabilities',
261
+ a2aStatus: 'Status',
262
+ a2aConnected: 'Connected & A2A Ready',
263
+ a2aNoRemote: 'No remote agents',
264
+ a2aNoRemoteHint: 'Discover remote agents to enable cross-agent delegation.',
244
265
  },
245
266
  plugins: {
246
267
  title: 'Plugins',
@@ -1463,4 +1484,35 @@ prompt: "Here's my resume, read it and organize my info into MindOS.",
1463
1484
  ],
1464
1485
  },
1465
1486
  },
1487
+
1488
+ /** Disabled-state and contextual tooltip hints */
1489
+ hints: {
1490
+ noValidFiles: 'No valid files selected',
1491
+ aiOrganizing: 'AI is organizing',
1492
+ importInProgress: 'Import in progress',
1493
+ templateInitializing: 'Another template is being initialized',
1494
+ configureAiKey: 'Configure API key in Settings → AI',
1495
+ syncInProgress: 'Sync already in progress',
1496
+ toggleInProgress: 'Toggle operation in progress',
1497
+ typeMessage: 'Type a message',
1498
+ mentionInProgress: 'Mention or command in progress',
1499
+ cleanupInProgress: 'Cleanup already in progress',
1500
+ tokenResetInProgress: 'Token reset in progress',
1501
+ aiNotConfigured: 'AI not configured or generation in progress',
1502
+ generationInProgress: 'Generation in progress or AI not configured',
1503
+ cannotJumpForward: 'Cannot jump forward in setup',
1504
+ testInProgressOrNoKey: 'Test in progress or no API key',
1505
+ workflowStepRunning: 'Workflow step already running',
1506
+ workflowRunning: 'Workflow step is running',
1507
+ sessionHistory: 'Session history',
1508
+ newSession: 'New session',
1509
+ attachFile: 'Attach local file',
1510
+ maximizePanel: 'Maximize panel',
1511
+ restorePanel: 'Restore panel',
1512
+ dockToSide: 'Dock to side panel',
1513
+ openAsPopup: 'Open as popup',
1514
+ closePanel: 'Close',
1515
+ newChat: 'New chat',
1516
+ closeSession: 'Close session',
1517
+ },
1466
1518
  } as const;
@@ -265,6 +265,27 @@ export const zh = {
265
265
  agentDetailPanelAria: '智能体连接配置',
266
266
  agentDetailTransport: '传输方式',
267
267
  agentDetailSnippet: '配置片段',
268
+ // A2A
269
+ a2aLabel: 'A2A',
270
+ a2aReady: 'A2A 就绪',
271
+ a2aChecking: '检测 A2A 中...',
272
+ a2aUnavailable: 'A2A 不可用',
273
+ a2aRemote: '远程',
274
+ a2aDiscover: '发现远程 Agent',
275
+ a2aDiscoverHint: '通过 URL 连接外部 A2A Agent',
276
+ a2aDiscoverPlaceholder: 'https://agent.example.com',
277
+ a2aDiscovering: '发现中...',
278
+ a2aDiscoverSuccess: 'Agent 已发现!',
279
+ a2aDiscoverFailed: '未在此 URL 找到 A2A Agent',
280
+ a2aDiscoverFailedHint: '该服务器可能不支持 A2A 协议,请检查 URL 后重试。',
281
+ a2aSkills: '技能',
282
+ a2aEndpoint: '端点',
283
+ a2aVersion: '版本',
284
+ a2aCapabilities: 'A2A 能力',
285
+ a2aStatus: '状态',
286
+ a2aConnected: '已连接,A2A 就绪',
287
+ a2aNoRemote: '无远程 Agent',
288
+ a2aNoRemoteHint: '发现远程 Agent 以启用跨 Agent 委派。',
268
289
  },
269
290
  plugins: {
270
291
  title: '插件',
@@ -1487,4 +1508,35 @@ prompt: '这是我的简历,读一下,把我的信息整理到 MindOS 里。
1487
1508
  ],
1488
1509
  },
1489
1510
  },
1511
+
1512
+ /** 禁用态和上下文提示文案 */
1513
+ hints: {
1514
+ noValidFiles: '未选择有效文件',
1515
+ aiOrganizing: 'AI 正在整理中',
1516
+ importInProgress: '正在导入',
1517
+ templateInitializing: '正在初始化另一个模板',
1518
+ configureAiKey: '请在 设置 → AI 中配置 API 密钥',
1519
+ syncInProgress: '正在同步中',
1520
+ toggleInProgress: '正在切换中',
1521
+ typeMessage: '请输入消息',
1522
+ mentionInProgress: '正在输入提及或命令',
1523
+ cleanupInProgress: '正在清理中',
1524
+ tokenResetInProgress: '正在重置令牌',
1525
+ aiNotConfigured: 'AI 未配置或正在生成',
1526
+ generationInProgress: '正在生成或 AI 未配置',
1527
+ cannotJumpForward: '无法跳过前序步骤',
1528
+ testInProgressOrNoKey: '正在测试或未配置 API 密钥',
1529
+ workflowStepRunning: '工作流步骤正在运行',
1530
+ workflowRunning: '工作流步骤正在运行',
1531
+ sessionHistory: '会话历史',
1532
+ newSession: '新会话',
1533
+ attachFile: '附加本地文件',
1534
+ maximizePanel: '最大化面板',
1535
+ restorePanel: '还原面板',
1536
+ dockToSide: '停靠到侧边栏',
1537
+ openAsPopup: '弹窗模式',
1538
+ closePanel: '关闭',
1539
+ newChat: '新对话',
1540
+ closeSession: '关闭会话',
1541
+ },
1490
1542
  } as const satisfies Widen<typeof en>;
package/app/next-env.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference types="next" />
2
2
  /// <reference types="next/image-types/global" />
3
- import "./.next/dev/types/routes.d.ts";
3
+ import "./.next/types/routes.d.ts";
4
4
 
5
5
  // NOTE: This file should not be edited
6
6
  // see https://nextjs.org/docs/app/api-reference/config/typescript for more information.