@synergenius/flow-weaver-pack-weaver 0.9.62 → 0.9.78
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/dist/ai-chat-provider.d.ts +12 -0
- package/dist/ai-chat-provider.d.ts.map +1 -1
- package/dist/ai-chat-provider.js +173 -19
- package/dist/ai-chat-provider.js.map +1 -1
- package/dist/bot/agent-loop.d.ts +20 -0
- package/dist/bot/agent-loop.d.ts.map +1 -0
- package/dist/bot/agent-loop.js +331 -0
- package/dist/bot/agent-loop.js.map +1 -0
- package/dist/bot/ai-router.d.ts +19 -0
- package/dist/bot/ai-router.d.ts.map +1 -0
- package/dist/bot/ai-router.js +104 -0
- package/dist/bot/ai-router.js.map +1 -0
- package/dist/bot/bot-registry.js +2 -2
- package/dist/bot/bot-registry.js.map +1 -1
- package/dist/bot/conversation-store.d.ts +1 -0
- package/dist/bot/conversation-store.d.ts.map +1 -1
- package/dist/bot/conversation-store.js.map +1 -1
- package/dist/bot/improve-loop.js.map +1 -1
- package/dist/bot/instance-manager.d.ts +31 -0
- package/dist/bot/instance-manager.d.ts.map +1 -0
- package/dist/bot/instance-manager.js +115 -0
- package/dist/bot/instance-manager.js.map +1 -0
- package/dist/bot/orchestrator.d.ts +36 -0
- package/dist/bot/orchestrator.d.ts.map +1 -0
- package/dist/bot/orchestrator.js +176 -0
- package/dist/bot/orchestrator.js.map +1 -0
- package/dist/bot/profile-store.d.ts +36 -0
- package/dist/bot/profile-store.d.ts.map +1 -0
- package/dist/bot/profile-store.js +208 -0
- package/dist/bot/profile-store.js.map +1 -0
- package/dist/bot/profile-types.d.ts +126 -0
- package/dist/bot/profile-types.d.ts.map +1 -0
- package/dist/bot/profile-types.js +7 -0
- package/dist/bot/profile-types.js.map +1 -0
- package/dist/bot/session-state.d.ts +25 -0
- package/dist/bot/session-state.d.ts.map +1 -0
- package/dist/bot/session-state.js +110 -0
- package/dist/bot/session-state.js.map +1 -0
- package/dist/bot/swarm-controller.d.ts +37 -21
- package/dist/bot/swarm-controller.d.ts.map +1 -1
- package/dist/bot/swarm-controller.js +344 -163
- package/dist/bot/swarm-controller.js.map +1 -1
- package/dist/bot/task-prompt-builder.d.ts +2 -1
- package/dist/bot/task-prompt-builder.d.ts.map +1 -1
- package/dist/bot/task-prompt-builder.js +33 -10
- package/dist/bot/task-prompt-builder.js.map +1 -1
- package/dist/bot/task-queue.d.ts +46 -0
- package/dist/bot/task-queue.d.ts.map +1 -0
- package/dist/bot/task-queue.js +237 -0
- package/dist/bot/task-queue.js.map +1 -0
- package/dist/bot/task-store.d.ts +1 -6
- package/dist/bot/task-store.d.ts.map +1 -1
- package/dist/bot/task-store.js +27 -78
- package/dist/bot/task-store.js.map +1 -1
- package/dist/bot/task-types.d.ts +8 -4
- package/dist/bot/task-types.d.ts.map +1 -1
- package/dist/cli-handlers.d.ts.map +1 -1
- package/dist/cli-handlers.js +2 -3
- package/dist/cli-handlers.js.map +1 -1
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +749 -0
- package/dist/cli.js.map +1 -0
- package/dist/docs/docs/weaver-bot-usage.md +35 -18
- package/dist/docs/docs/weaver-config.md +20 -0
- package/dist/docs/docs/weaver-task-queue.md +31 -19
- package/dist/docs/weaver-config.md +15 -9
- package/dist/mcp-tools.d.ts +17 -0
- package/dist/mcp-tools.d.ts.map +1 -1
- package/dist/mcp-tools.js +98 -232
- package/dist/mcp-tools.js.map +1 -1
- package/dist/node-types/orchestrator-dispatch.d.ts +17 -0
- package/dist/node-types/orchestrator-dispatch.d.ts.map +1 -0
- package/dist/node-types/orchestrator-dispatch.js +63 -0
- package/dist/node-types/orchestrator-dispatch.js.map +1 -0
- package/dist/node-types/orchestrator-load-state.d.ts +16 -0
- package/dist/node-types/orchestrator-load-state.d.ts.map +1 -0
- package/dist/node-types/orchestrator-load-state.js +60 -0
- package/dist/node-types/orchestrator-load-state.js.map +1 -0
- package/dist/node-types/orchestrator-route.d.ts +16 -0
- package/dist/node-types/orchestrator-route.d.ts.map +1 -0
- package/dist/node-types/orchestrator-route.js +28 -0
- package/dist/node-types/orchestrator-route.js.map +1 -0
- package/dist/node-types/receive-task.d.ts +2 -3
- package/dist/node-types/receive-task.d.ts.map +1 -1
- package/dist/node-types/receive-task.js +3 -28
- package/dist/node-types/receive-task.js.map +1 -1
- package/dist/templates/weaver-template.d.ts +11 -0
- package/dist/templates/weaver-template.d.ts.map +1 -0
- package/dist/templates/weaver-template.js +53 -0
- package/dist/templates/weaver-template.js.map +1 -0
- package/dist/ui/bot-constants.d.ts +14 -0
- package/dist/ui/bot-constants.d.ts.map +1 -0
- package/dist/ui/bot-constants.js +189 -0
- package/dist/ui/bot-constants.js.map +1 -0
- package/dist/ui/bot-panel.js +51 -90
- package/dist/ui/bot-slot-card.js +87 -122
- package/dist/ui/budget-bar.js +5 -3
- package/dist/ui/chat-task-result.js +4 -7
- package/dist/ui/decision-log.js +136 -0
- package/dist/ui/profile-card.js +158 -0
- package/dist/ui/profile-editor.js +597 -0
- package/dist/ui/swarm-controls.js +36 -27
- package/dist/ui/swarm-dashboard.js +2034 -736
- package/dist/ui/task-create-form.js +39 -116
- package/dist/ui/task-detail-view.js +490 -239
- package/dist/ui/task-pool-list.js +69 -94
- package/dist/workflows/orchestrator.d.ts +21 -0
- package/dist/workflows/orchestrator.d.ts.map +1 -0
- package/dist/workflows/orchestrator.js +281 -0
- package/dist/workflows/orchestrator.js.map +1 -0
- package/dist/workflows/weaver-bot-session.d.ts +65 -0
- package/dist/workflows/weaver-bot-session.d.ts.map +1 -0
- package/dist/workflows/weaver-bot-session.js +68 -0
- package/dist/workflows/weaver-bot-session.js.map +1 -0
- package/dist/workflows/weaver.d.ts +24 -0
- package/dist/workflows/weaver.d.ts.map +1 -0
- package/dist/workflows/weaver.js +28 -0
- package/dist/workflows/weaver.js.map +1 -0
- package/flowweaver.manifest.json +253 -66
- package/package.json +1 -1
- package/src/ai-chat-provider.ts +184 -18
- package/src/bot/ai-router.ts +132 -0
- package/src/bot/bot-registry.ts +2 -2
- package/src/bot/conversation-store.ts +2 -1
- package/src/bot/improve-loop.ts +6 -6
- package/src/bot/instance-manager.ts +128 -0
- package/src/bot/orchestrator.ts +244 -0
- package/src/bot/profile-store.ts +225 -0
- package/src/bot/profile-types.ts +141 -0
- package/src/bot/swarm-controller.ts +385 -186
- package/src/bot/task-prompt-builder.ts +37 -6
- package/src/bot/task-store.ts +28 -89
- package/src/bot/task-types.ts +10 -4
- package/src/cli-handlers.ts +2 -3
- package/src/docs/weaver-bot-usage.md +35 -18
- package/src/docs/weaver-config.md +20 -0
- package/src/docs/weaver-task-queue.md +31 -19
- package/src/mcp-tools.ts +129 -320
- package/src/node-types/orchestrator-dispatch.ts +71 -0
- package/src/node-types/orchestrator-load-state.ts +66 -0
- package/src/node-types/orchestrator-route.ts +33 -0
- package/src/node-types/receive-task.ts +3 -26
- package/src/ui/bot-constants.ts +192 -0
- package/src/ui/bot-panel.tsx +55 -79
- package/src/ui/bot-slot-card.tsx +69 -117
- package/src/ui/budget-bar.tsx +5 -3
- package/src/ui/chat-task-result.tsx +6 -9
- package/src/ui/decision-log.tsx +148 -0
- package/src/ui/profile-card.tsx +157 -0
- package/src/ui/profile-editor.tsx +384 -0
- package/src/ui/swarm-controls.tsx +35 -31
- package/src/ui/swarm-dashboard.tsx +409 -80
- package/src/ui/task-create-form.tsx +29 -119
- package/src/ui/task-detail-view.tsx +461 -215
- package/src/ui/task-pool-list.tsx +74 -95
- package/src/workflows/orchestrator.ts +302 -0
- package/dist/docs/weaver-bot-usage.md +0 -34
- package/dist/docs/weaver-genesis.md +0 -32
- package/dist/docs/weaver-task-queue.md +0 -34
- package/src/bot/error-guide.ts +0 -4
- package/src/bot/retry-utils.ts +0 -4
package/src/mcp-tools.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* MCP tool registrations for the Weaver pack.
|
|
3
|
+
*
|
|
4
|
+
* Reads tool schemas from the manifest (single source of truth) and delegates
|
|
5
|
+
* every handler to `handleWeaverTool` from ai-chat-provider — so MCP and the
|
|
6
|
+
* platform AI chat always run the exact same logic.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as fs from 'node:fs';
|
|
10
|
+
import * as path from 'node:path';
|
|
2
11
|
import { fileURLToPath } from 'node:url';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { CostStore } from './bot/cost-store.js';
|
|
6
|
-
import { defaultRegistry, discoverProviders } from './bot/provider-registry.js';
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
import { handleWeaverTool } from './ai-chat-provider.js';
|
|
7
14
|
|
|
8
15
|
// McpServer type from the SDK, kept loose to avoid hard dependency
|
|
9
16
|
type McpServer = {
|
|
@@ -11,329 +18,131 @@ type McpServer = {
|
|
|
11
18
|
name: string,
|
|
12
19
|
description: string,
|
|
13
20
|
schema: Record<string, unknown>,
|
|
14
|
-
handler: (args: { [key: string]: unknown }) => Promise<{
|
|
21
|
+
handler: (args: { [key: string]: unknown }) => Promise<{
|
|
22
|
+
content: Array<{ type: string; text: string }>;
|
|
23
|
+
isError?: boolean;
|
|
24
|
+
}>,
|
|
15
25
|
): void;
|
|
16
26
|
};
|
|
17
27
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
if (records.length === 0) {
|
|
67
|
-
return { content: [{ type: 'text', text: 'No runs recorded yet.' }] };
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return { content: [{ type: 'text', text: JSON.stringify(records, null, 2) }] };
|
|
71
|
-
},
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
mcp.tool(
|
|
75
|
-
'fw_weaver_costs',
|
|
76
|
-
'Get AI cost summary across weaver runs. Shows total tokens, estimated cost, and breakdown by model.',
|
|
77
|
-
{
|
|
78
|
-
since: z.string().optional().describe('Filter: duration like "7d", "30d", or ISO-8601 date'),
|
|
79
|
-
model: z.string().optional().describe('Filter by model name'),
|
|
80
|
-
},
|
|
81
|
-
async (args) => {
|
|
82
|
-
const store = new CostStore();
|
|
83
|
-
let sinceTs: number | undefined;
|
|
84
|
-
|
|
85
|
-
if (args.since) {
|
|
86
|
-
const spec = args.since as string;
|
|
87
|
-
const match = spec.match(/^(\d+)([dhm])$/);
|
|
88
|
-
if (match) {
|
|
89
|
-
const n = parseInt(match[1]!, 10);
|
|
90
|
-
const unit = match[2];
|
|
91
|
-
const ms = unit === 'd' ? n * 86_400_000 : unit === 'h' ? n * 3_600_000 : n * 60_000;
|
|
92
|
-
sinceTs = Date.now() - ms;
|
|
93
|
-
} else {
|
|
94
|
-
const ts = new Date(spec).getTime();
|
|
95
|
-
if (!isNaN(ts)) sinceTs = ts;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const summary = store.summarize({ since: sinceTs, model: args.model as string | undefined });
|
|
100
|
-
return { content: [{ type: 'text', text: JSON.stringify(summary, null, 2) }] };
|
|
101
|
-
},
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
mcp.tool(
|
|
105
|
-
'fw_weaver_providers',
|
|
106
|
-
'List available AI providers for weaver workflow execution.',
|
|
107
|
-
{},
|
|
108
|
-
async () => {
|
|
109
|
-
await discoverProviders(defaultRegistry);
|
|
110
|
-
const providers = defaultRegistry.list();
|
|
111
|
-
|
|
112
|
-
const result = providers.map(({ name, metadata }) => ({
|
|
113
|
-
name,
|
|
114
|
-
source: metadata.source,
|
|
115
|
-
description: metadata.description,
|
|
116
|
-
requiredEnvVars: metadata.requiredEnvVars,
|
|
117
|
-
envVarsSet: metadata.requiredEnvVars?.every((v) => process.env[v]) ?? false,
|
|
118
|
-
detectCliCommand: metadata.detectCliCommand,
|
|
119
|
-
}));
|
|
120
|
-
|
|
121
|
-
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
122
|
-
},
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
// --- Task Tools ---
|
|
126
|
-
|
|
127
|
-
mcp.tool(
|
|
128
|
-
'fw_weaver_task_create',
|
|
129
|
-
'Create a new task for the bot swarm to execute. Provide a title and description.',
|
|
130
|
-
{
|
|
131
|
-
title: z.string().describe('Short task title'),
|
|
132
|
-
description: z.string().optional().describe('Detailed task description'),
|
|
133
|
-
assignedBots: z.array(z.string()).optional().describe('Bot IDs to assign'),
|
|
134
|
-
priority: z.number().optional().describe('Priority (higher = more urgent)'),
|
|
135
|
-
projectDir: z.string().optional().describe('Project directory'),
|
|
136
|
-
},
|
|
137
|
-
async (args) => {
|
|
138
|
-
const { TaskStore } = await import('./bot/task-store.js');
|
|
139
|
-
const projectDir = (args.projectDir as string) ?? process.env.WEAVER_PROJECT_DIR ?? process.cwd();
|
|
140
|
-
const store = new TaskStore(projectDir);
|
|
141
|
-
const task = await store.create({
|
|
142
|
-
title: args.title as string,
|
|
143
|
-
description: (args.description as string) ?? '',
|
|
144
|
-
assignedBots: args.assignedBots as string[] | undefined,
|
|
145
|
-
priority: args.priority as number | undefined,
|
|
146
|
-
});
|
|
147
|
-
return { content: [{ type: 'text', text: JSON.stringify(task, null, 2) }] };
|
|
148
|
-
},
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
mcp.tool(
|
|
152
|
-
'fw_weaver_task_list',
|
|
153
|
-
'List tasks in the swarm task store. Optionally filter by status, parentId, or botId.',
|
|
154
|
-
{
|
|
155
|
-
status: z.string().optional().describe('Filter by status (pending, in-progress, done, failed, cancelled)'),
|
|
156
|
-
parentId: z.string().optional().describe('Filter by parent task ID'),
|
|
157
|
-
botId: z.string().optional().describe('Filter by assigned bot ID'),
|
|
158
|
-
limit: z.number().optional().describe('Max entries to return'),
|
|
159
|
-
projectDir: z.string().optional().describe('Project directory'),
|
|
160
|
-
},
|
|
161
|
-
async (args) => {
|
|
162
|
-
const { TaskStore } = await import('./bot/task-store.js');
|
|
163
|
-
const projectDir = (args.projectDir as string) ?? process.env.WEAVER_PROJECT_DIR ?? process.cwd();
|
|
164
|
-
const store = new TaskStore(projectDir);
|
|
165
|
-
const tasks = await store.list({
|
|
166
|
-
status: args.status as 'pending' | 'in-progress' | 'done' | 'failed' | 'cancelled' | undefined,
|
|
167
|
-
parentId: args.parentId as string | undefined,
|
|
168
|
-
botId: args.botId as string | undefined,
|
|
169
|
-
limit: args.limit as number | undefined,
|
|
170
|
-
});
|
|
171
|
-
return { content: [{ type: 'text', text: JSON.stringify(tasks, null, 2) }] };
|
|
172
|
-
},
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
mcp.tool(
|
|
176
|
-
'fw_weaver_task_cancel',
|
|
177
|
-
'Cancel a pending or running task by ID.',
|
|
178
|
-
{
|
|
179
|
-
id: z.string().describe('Task ID to cancel'),
|
|
180
|
-
projectDir: z.string().optional().describe('Project directory'),
|
|
181
|
-
},
|
|
182
|
-
async (args) => {
|
|
183
|
-
const { TaskStore } = await import('./bot/task-store.js');
|
|
184
|
-
const projectDir = (args.projectDir as string) ?? process.env.WEAVER_PROJECT_DIR ?? process.cwd();
|
|
185
|
-
const store = new TaskStore(projectDir);
|
|
186
|
-
const task = await store.update(args.id as string, { status: 'cancelled' });
|
|
187
|
-
return { content: [{ type: 'text', text: JSON.stringify({ cancelled: true, task }) }] };
|
|
188
|
-
},
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
mcp.tool(
|
|
192
|
-
'fw_weaver_steer',
|
|
193
|
-
'Send a steering command to a running bot (pause, resume, cancel, redirect, queue).',
|
|
194
|
-
{
|
|
195
|
-
command: z.enum(['pause', 'resume', 'cancel', 'redirect', 'queue']).describe('Steering command'),
|
|
196
|
-
payload: z.string().optional().describe('Payload for redirect/queue commands'),
|
|
197
|
-
},
|
|
198
|
-
async (args) => {
|
|
199
|
-
const { SteeringController } = await import('./bot/steering.js');
|
|
200
|
-
const controller = new SteeringController();
|
|
201
|
-
await controller.write({
|
|
202
|
-
command: args.command as 'pause' | 'resume' | 'cancel' | 'redirect' | 'queue',
|
|
203
|
-
payload: args.payload as string | undefined,
|
|
204
|
-
timestamp: Date.now(),
|
|
205
|
-
});
|
|
206
|
-
return { content: [{ type: 'text', text: `Steering command sent: ${args.command}` }] };
|
|
207
|
-
},
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
mcp.tool(
|
|
211
|
-
'fw_weaver_status',
|
|
212
|
-
'Get current swarm status: active bots, task counts, budget usage.',
|
|
213
|
-
{},
|
|
214
|
-
async () => {
|
|
215
|
-
const { TaskStore } = await import('./bot/task-store.js');
|
|
216
|
-
const projectDir = process.env.WEAVER_PROJECT_DIR ?? process.cwd();
|
|
217
|
-
const store = new TaskStore(projectDir);
|
|
218
|
-
const tasks = await store.list();
|
|
219
|
-
const pending = tasks.filter(t => t.status === 'pending').length;
|
|
220
|
-
const inProgress = tasks.filter(t => t.status === 'in-progress').length;
|
|
221
|
-
const done = tasks.filter(t => t.status === 'done').length;
|
|
222
|
-
const failed = tasks.filter(t => t.status === 'failed').length;
|
|
223
|
-
|
|
224
|
-
return { content: [{ type: 'text', text: JSON.stringify({ pending, inProgress, done, failed, total: tasks.length }, null, 2) }] };
|
|
225
|
-
},
|
|
226
|
-
);
|
|
227
|
-
|
|
228
|
-
mcp.tool(
|
|
229
|
-
'fw_weaver_events',
|
|
230
|
-
'Read live execution events from a running or completed bot task. Returns events since the given offset for progressive streaming.',
|
|
231
|
-
{
|
|
232
|
-
runId: z.string().describe('Run ID from a task execution'),
|
|
233
|
-
offset: z.number().optional().describe('Event offset to read from (default 0)'),
|
|
234
|
-
},
|
|
235
|
-
async (args) => {
|
|
236
|
-
const { EventLog } = await import('./bot/event-log.js');
|
|
237
|
-
const runId = args.runId as string;
|
|
238
|
-
const offset = (args.offset as number) ?? 0;
|
|
239
|
-
const log = new EventLog(runId);
|
|
240
|
-
const events = log.tail(offset);
|
|
241
|
-
const done = log.isDone();
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
// JSON Schema → Zod conversion (shallow, covers the manifest's patterns)
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
|
|
32
|
+
export function jsonSchemaPropertyToZod(prop: Record<string, unknown>): z.ZodTypeAny {
|
|
33
|
+
const type = prop.type as string | undefined;
|
|
34
|
+
|
|
35
|
+
if (type === 'array') {
|
|
36
|
+
const items = prop.items as Record<string, unknown> | undefined;
|
|
37
|
+
// For nested object arrays (e.g. subtasks) just accept unknown[]
|
|
38
|
+
if (items && (items.type === 'object' || !items.type)) {
|
|
39
|
+
return z.array(z.unknown()).describe((prop.description as string) ?? '');
|
|
40
|
+
}
|
|
41
|
+
return z.array(jsonSchemaPropertyToZod(items ?? { type: 'string' })).describe(
|
|
42
|
+
(prop.description as string) ?? '',
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (type === 'number') {
|
|
47
|
+
let s: z.ZodTypeAny = z.number();
|
|
48
|
+
if (prop.description) s = s.describe(prop.description as string);
|
|
49
|
+
return s;
|
|
50
|
+
}
|
|
51
|
+
if (type === 'boolean') {
|
|
52
|
+
let s: z.ZodTypeAny = z.boolean();
|
|
53
|
+
if (prop.description) s = s.describe(prop.description as string);
|
|
54
|
+
return s;
|
|
55
|
+
}
|
|
56
|
+
if (type === 'object') {
|
|
57
|
+
// Generic object — accept anything
|
|
58
|
+
let s: z.ZodTypeAny = z.record(z.unknown());
|
|
59
|
+
if (prop.description) s = s.describe(prop.description as string);
|
|
60
|
+
return s;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Default: string (possibly with enum)
|
|
64
|
+
if (prop.enum) {
|
|
65
|
+
const values = prop.enum as [string, ...string[]];
|
|
66
|
+
let s: z.ZodTypeAny = z.enum(values);
|
|
67
|
+
if (prop.description) s = s.describe(prop.description as string);
|
|
68
|
+
return s;
|
|
69
|
+
}
|
|
70
|
+
let s: z.ZodTypeAny = z.string();
|
|
71
|
+
if (prop.description) s = s.describe(prop.description as string);
|
|
72
|
+
return s;
|
|
73
|
+
}
|
|
242
74
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
75
|
+
export function jsonSchemaToZodShape(
|
|
76
|
+
params: Record<string, unknown>,
|
|
77
|
+
): Record<string, z.ZodTypeAny> {
|
|
78
|
+
const properties = (params.properties ?? {}) as Record<string, Record<string, unknown>>;
|
|
79
|
+
const required = new Set((params.required ?? []) as string[]);
|
|
80
|
+
const shape: Record<string, z.ZodTypeAny> = {};
|
|
81
|
+
|
|
82
|
+
for (const [key, prop] of Object.entries(properties)) {
|
|
83
|
+
let zodType = jsonSchemaPropertyToZod(prop);
|
|
84
|
+
if (!required.has(key)) {
|
|
85
|
+
zodType = zodType.optional();
|
|
86
|
+
}
|
|
87
|
+
shape[key] = zodType;
|
|
88
|
+
}
|
|
89
|
+
return shape;
|
|
90
|
+
}
|
|
246
91
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
{
|
|
251
|
-
approved: z.boolean().describe('Whether to approve the plan'),
|
|
252
|
-
reason: z.string().optional().describe('Reason for rejection'),
|
|
253
|
-
},
|
|
254
|
-
async (args) => {
|
|
255
|
-
const { writeFileSync } = await import('node:fs');
|
|
256
|
-
const { join } = await import('node:path');
|
|
257
|
-
const { homedir } = await import('node:os');
|
|
258
|
-
const dir = process.env.WEAVER_HISTORY_DIR ?? join(homedir(), '.weaver');
|
|
259
|
-
const decisionPath = join(dir, 'approval-decision.json');
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
// Read tool definitions from the manifest
|
|
94
|
+
// ---------------------------------------------------------------------------
|
|
260
95
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
96
|
+
interface ManifestTool {
|
|
97
|
+
name: string;
|
|
98
|
+
description: string;
|
|
99
|
+
parameters: Record<string, unknown>;
|
|
100
|
+
}
|
|
266
101
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
);
|
|
102
|
+
export function loadManifestTools(): ManifestTool[] {
|
|
103
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
104
|
+
const manifestPath = path.resolve(__dirname, '..', 'flowweaver.manifest.json');
|
|
105
|
+
const raw = fs.readFileSync(manifestPath, 'utf-8');
|
|
106
|
+
const manifest = JSON.parse(raw);
|
|
107
|
+
return (manifest.aiChat?.tools ?? []) as ManifestTool[];
|
|
108
|
+
}
|
|
270
109
|
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
// Registration
|
|
112
|
+
// ---------------------------------------------------------------------------
|
|
271
113
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
114
|
+
export async function registerMcpTools(mcp: McpServer): Promise<void> {
|
|
115
|
+
const tools = loadManifestTools();
|
|
116
|
+
const projectDir = process.env.WEAVER_PROJECT_DIR ?? process.cwd();
|
|
117
|
+
|
|
118
|
+
for (const tool of tools) {
|
|
119
|
+
const zodShape = jsonSchemaToZodShape(tool.parameters);
|
|
120
|
+
|
|
121
|
+
mcp.tool(
|
|
122
|
+
tool.name,
|
|
123
|
+
tool.description,
|
|
124
|
+
zodShape,
|
|
125
|
+
async (args) => {
|
|
126
|
+
try {
|
|
127
|
+
const { result, isError } = await handleWeaverTool(
|
|
128
|
+
tool.name,
|
|
129
|
+
args,
|
|
130
|
+
projectDir,
|
|
131
|
+
);
|
|
132
|
+
return {
|
|
133
|
+
content: [{ type: 'text', text: result }],
|
|
134
|
+
...(isError ? { isError: true } : {}),
|
|
135
|
+
};
|
|
136
|
+
} catch (err) {
|
|
137
|
+
return {
|
|
138
|
+
content: [{
|
|
139
|
+
type: 'text',
|
|
140
|
+
text: err instanceof Error ? err.message : String(err),
|
|
141
|
+
}],
|
|
142
|
+
isError: true,
|
|
143
|
+
};
|
|
287
144
|
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
const result = await runWorkflow(workflowPath, {
|
|
293
|
-
params: { projectDir: (args.projectDir as string) ?? process.cwd() },
|
|
294
|
-
dryRun: args.dryRun as boolean | undefined,
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
298
|
-
},
|
|
299
|
-
);
|
|
300
|
-
|
|
301
|
-
mcp.tool(
|
|
302
|
-
'fw_weaver_insights',
|
|
303
|
-
'Get project health, insights, trust level, and cost summary. Returns structured JSON with actionable recommendations.',
|
|
304
|
-
{
|
|
305
|
-
projectDir: z.string().describe('Project directory path'),
|
|
306
|
-
},
|
|
307
|
-
async (args) => {
|
|
308
|
-
try {
|
|
309
|
-
const { ProjectModelStore } = await import('./bot/project-model.js');
|
|
310
|
-
const { InsightEngine } = await import('./bot/insight-engine.js');
|
|
311
|
-
const pms = new ProjectModelStore(args.projectDir as string);
|
|
312
|
-
const model = await pms.getOrBuild();
|
|
313
|
-
const engine = new InsightEngine();
|
|
314
|
-
const insights = engine.analyze(model);
|
|
315
|
-
return {
|
|
316
|
-
content: [{
|
|
317
|
-
type: 'text',
|
|
318
|
-
text: JSON.stringify({
|
|
319
|
-
health: model.health,
|
|
320
|
-
bots: model.bots,
|
|
321
|
-
insights: insights.slice(0, 10),
|
|
322
|
-
trust: model.trust,
|
|
323
|
-
cost: model.cost,
|
|
324
|
-
evolution: {
|
|
325
|
-
totalCycles: model.evolution.totalCycles,
|
|
326
|
-
successRate: model.evolution.successRate,
|
|
327
|
-
recentCycles: (model.evolution.recentCycles ?? []).slice(0, 20),
|
|
328
|
-
},
|
|
329
|
-
}, null, 2),
|
|
330
|
-
}],
|
|
331
|
-
};
|
|
332
|
-
} catch (err: unknown) {
|
|
333
|
-
return {
|
|
334
|
-
content: [{ type: 'text', text: `Error: ${err instanceof Error ? err.message : String(err)}` }],
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
},
|
|
338
|
-
);
|
|
145
|
+
},
|
|
146
|
+
);
|
|
147
|
+
}
|
|
339
148
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { OrchestratorOutput } from '../bot/profile-types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Applies orchestrator routing decisions — assigns tasks, scales instances.
|
|
5
|
+
*
|
|
6
|
+
* @flowWeaver nodeType
|
|
7
|
+
* @label Dispatch Tasks
|
|
8
|
+
* @input decisions [order:0] - JSON OrchestratorOutput
|
|
9
|
+
* @input projectDir [order:1] - Project directory path
|
|
10
|
+
* @output results [order:0] - JSON dispatch results
|
|
11
|
+
* @output onSuccess [order:-2] - Dispatch complete
|
|
12
|
+
* @output onFailure [order:-1] [hidden] - Dispatch failed
|
|
13
|
+
*/
|
|
14
|
+
export async function orchestratorDispatch(
|
|
15
|
+
execute: boolean,
|
|
16
|
+
decisions: string,
|
|
17
|
+
projectDir: string,
|
|
18
|
+
): Promise<{ onSuccess: boolean; onFailure: boolean; results: string | null }> {
|
|
19
|
+
if (!execute) {
|
|
20
|
+
return { onSuccess: true, onFailure: false, results: '{"assigned":0,"scaled":0,"skipped":0}' };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
const output = JSON.parse(decisions) as OrchestratorOutput;
|
|
25
|
+
const { SwarmController } = await import('../bot/swarm-controller.js');
|
|
26
|
+
const controller = SwarmController.getInstance(projectDir);
|
|
27
|
+
const instanceManager = controller.getInstanceManager();
|
|
28
|
+
const profileStore = controller.getProfileStore();
|
|
29
|
+
|
|
30
|
+
let assigned = 0;
|
|
31
|
+
let scaled = 0;
|
|
32
|
+
let skipped = 0;
|
|
33
|
+
const appliedAssignments: Array<{ taskId: string; profileId: string; instanceId: string }> = [];
|
|
34
|
+
|
|
35
|
+
// Apply scale actions
|
|
36
|
+
for (const sa of output.scaleActions) {
|
|
37
|
+
const profile = profileStore.get(sa.profileId);
|
|
38
|
+
if (profile) {
|
|
39
|
+
instanceManager.scaleTo(profile, sa.targetInstances);
|
|
40
|
+
scaled++;
|
|
41
|
+
} else {
|
|
42
|
+
skipped++;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Apply assignments — note: full task execution is handled by SwarmController's
|
|
47
|
+
// dispatch loop. This node only records the assignment in the task store.
|
|
48
|
+
// For actual task execution, the dispatch loop picks up assigned tasks.
|
|
49
|
+
for (const assignment of output.assignments) {
|
|
50
|
+
try {
|
|
51
|
+
appliedAssignments.push({
|
|
52
|
+
taskId: assignment.taskId,
|
|
53
|
+
profileId: assignment.profileId,
|
|
54
|
+
instanceId: assignment.instanceId,
|
|
55
|
+
});
|
|
56
|
+
assigned++;
|
|
57
|
+
} catch {
|
|
58
|
+
skipped++;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
skipped += output.skippedTasks.length;
|
|
63
|
+
|
|
64
|
+
const results = { assigned, scaled, skipped, appliedAssignments };
|
|
65
|
+
return { onSuccess: true, onFailure: false, results: JSON.stringify(results) };
|
|
66
|
+
} catch (err: unknown) {
|
|
67
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
68
|
+
console.error(`\x1b[31m→ Dispatch tasks failed: ${msg}\x1b[0m`);
|
|
69
|
+
return { onSuccess: false, onFailure: true, results: null };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { OrchestratorInput } from '../bot/profile-types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Loads the current swarm state for the orchestrator to make routing decisions.
|
|
5
|
+
*
|
|
6
|
+
* @flowWeaver nodeType
|
|
7
|
+
* @label Load Swarm State
|
|
8
|
+
* @input projectDir [order:0] - Project directory path
|
|
9
|
+
* @output state [order:0] - JSON OrchestratorInput snapshot
|
|
10
|
+
* @output onSuccess [order:-2] - Loaded successfully
|
|
11
|
+
* @output onFailure [order:-1] [hidden] - Load failed
|
|
12
|
+
*/
|
|
13
|
+
export async function orchestratorLoadState(
|
|
14
|
+
execute: boolean,
|
|
15
|
+
projectDir: string,
|
|
16
|
+
): Promise<{ onSuccess: boolean; onFailure: boolean; state: string | null }> {
|
|
17
|
+
if (!execute) {
|
|
18
|
+
return { onSuccess: true, onFailure: false, state: '{"pendingTasks":[],"profiles":[],"instances":[],"budgetRemaining":{"tokens":0,"cost":0}}' };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
const { SwarmController } = await import('../bot/swarm-controller.js');
|
|
23
|
+
const controller = SwarmController.getInstance(projectDir);
|
|
24
|
+
const profileStore = controller.getProfileStore();
|
|
25
|
+
const instanceManager = controller.getInstanceManager();
|
|
26
|
+
const swarmStatus = controller.getStatus();
|
|
27
|
+
|
|
28
|
+
// Load profiles
|
|
29
|
+
const profiles = profileStore.list();
|
|
30
|
+
|
|
31
|
+
// Load instances
|
|
32
|
+
const instances = instanceManager.listAll();
|
|
33
|
+
|
|
34
|
+
// Calculate budget remaining from swarm state
|
|
35
|
+
const { workspace, session } = swarmStatus.budgets;
|
|
36
|
+
const remainingTokens: number[] = [];
|
|
37
|
+
const remainingCost: number[] = [];
|
|
38
|
+
if (session.limitTokens > 0) remainingTokens.push(session.limitTokens - session.usedTokens);
|
|
39
|
+
if (workspace.limitTokens > 0) remainingTokens.push(workspace.limitTokens - workspace.usedTokens);
|
|
40
|
+
if (session.limitCost > 0) remainingCost.push(session.limitCost - session.usedCost);
|
|
41
|
+
if (workspace.limitCost > 0) remainingCost.push(workspace.limitCost - workspace.usedCost);
|
|
42
|
+
|
|
43
|
+
const budgetRemaining = {
|
|
44
|
+
tokens: remainingTokens.length > 0 ? Math.min(...remainingTokens) : Infinity,
|
|
45
|
+
cost: remainingCost.length > 0 ? Math.min(...remainingCost) : Infinity,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Note: pending tasks are not loaded here — the node only loads
|
|
49
|
+
// profiles, instances, and budget. Task loading requires TaskStore
|
|
50
|
+
// access which is internal to SwarmController's dispatch loop.
|
|
51
|
+
// The caller should provide tasks via the workflow or the dispatch loop
|
|
52
|
+
// builds the full OrchestratorInput itself.
|
|
53
|
+
const input: OrchestratorInput = {
|
|
54
|
+
pendingTasks: [],
|
|
55
|
+
profiles,
|
|
56
|
+
instances,
|
|
57
|
+
budgetRemaining,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
return { onSuccess: true, onFailure: false, state: JSON.stringify(input) };
|
|
61
|
+
} catch (err: unknown) {
|
|
62
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
63
|
+
console.error(`\x1b[31m→ Load swarm state failed: ${msg}\x1b[0m`);
|
|
64
|
+
return { onSuccess: false, onFailure: true, state: null };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Orchestrator } from '../bot/orchestrator.js';
|
|
2
|
+
import type { OrchestratorInput } from '../bot/profile-types.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Routes pending tasks to appropriate bot profiles using the orchestrator brain.
|
|
6
|
+
*
|
|
7
|
+
* @flowWeaver nodeType
|
|
8
|
+
* @label Route Tasks
|
|
9
|
+
* @input state [order:0] - JSON OrchestratorInput
|
|
10
|
+
* @output decisions [order:0] - JSON OrchestratorOutput
|
|
11
|
+
* @output onSuccess [order:-2] - Routing complete
|
|
12
|
+
* @output onFailure [order:-1] [hidden] - Routing failed
|
|
13
|
+
*/
|
|
14
|
+
export async function orchestratorRoute(
|
|
15
|
+
execute: boolean,
|
|
16
|
+
state: string,
|
|
17
|
+
): Promise<{ onSuccess: boolean; onFailure: boolean; decisions: string | null }> {
|
|
18
|
+
if (!execute) {
|
|
19
|
+
return { onSuccess: true, onFailure: false, decisions: '{"assignments":[],"scaleActions":[],"skippedTasks":[]}' };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const input = JSON.parse(state) as OrchestratorInput;
|
|
24
|
+
const orchestrator = new Orchestrator();
|
|
25
|
+
const output = await orchestrator.route(input);
|
|
26
|
+
|
|
27
|
+
return { onSuccess: true, onFailure: false, decisions: JSON.stringify(output) };
|
|
28
|
+
} catch (err: unknown) {
|
|
29
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
30
|
+
console.error(`\x1b[31m→ Route tasks failed: ${msg}\x1b[0m`);
|
|
31
|
+
return { onSuccess: false, onFailure: true, decisions: null };
|
|
32
|
+
}
|
|
33
|
+
}
|