omnara 0.1.3 → 0.1.4
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/bin/omnara.js +8 -3
- package/dist/auth/auth-provider.d.ts +2 -2
- package/dist/auth/auth-provider.js +13 -15
- package/dist/auth/auth-provider.js.map +1 -1
- package/dist/auth/cli-auth-service.d.ts +1 -1
- package/dist/auth/cli-auth-service.js +3 -6
- package/dist/auth/cli-auth-service.js.map +1 -1
- package/dist/auth/credential-manager.d.ts +1 -1
- package/dist/auth/credential-manager.js +7 -9
- package/dist/auth/credential-manager.js.map +1 -1
- package/dist/auth/credentials-store.js +14 -20
- package/dist/auth/credentials-store.js.map +1 -1
- package/dist/auth/login-flow.d.ts +2 -2
- package/dist/auth/login-flow.js +23 -29
- package/dist/auth/login-flow.js.map +1 -1
- package/dist/auth/loopback-listener.js +11 -15
- package/dist/auth/loopback-listener.js.map +1 -1
- package/dist/auth/pkce.js +4 -7
- package/dist/auth/pkce.js.map +1 -1
- package/dist/auth/supabase-client.d.ts +1 -1
- package/dist/auth/supabase-client.js +3 -6
- package/dist/auth/supabase-client.js.map +1 -1
- package/dist/auth/supabase-config.js +3 -6
- package/dist/auth/supabase-config.js.map +1 -1
- package/dist/cli.js +26 -25
- package/dist/cli.js.map +1 -1
- package/dist/commands/agent.js +36 -38
- package/dist/commands/agent.js.map +1 -1
- package/dist/commands/auth.js +13 -16
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/index.d.ts +2 -2
- package/dist/commands/index.js +2 -8
- package/dist/commands/index.js.map +1 -1
- package/dist/http/api-client.js +7 -11
- package/dist/http/api-client.js.map +1 -1
- package/dist/http/user-sessions.d.ts +13 -0
- package/dist/http/user-sessions.js +9 -0
- package/dist/http/user-sessions.js.map +1 -0
- package/dist/orchestrator/agent-orchestrator.d.ts +11 -6
- package/dist/orchestrator/agent-orchestrator.js +226 -57
- package/dist/orchestrator/agent-orchestrator.js.map +1 -1
- package/dist/orchestrator/ai-client.d.ts +5 -4
- package/dist/orchestrator/ai-client.js +17 -14
- package/dist/orchestrator/ai-client.js.map +1 -1
- package/dist/orchestrator/orchestrator-prompt.d.ts +2 -7
- package/dist/orchestrator/orchestrator-prompt.js +7 -154
- package/dist/orchestrator/orchestrator-prompt.js.map +1 -1
- package/dist/orchestrator/orchestrator-prompt.md +405 -0
- package/dist/orchestrator/session.d.ts +7 -3
- package/dist/orchestrator/session.js +56 -34
- package/dist/orchestrator/session.js.map +1 -1
- package/dist/orchestrator/tools/worker-status-tool.d.ts +7 -0
- package/dist/orchestrator/tools/worker-status-tool.js +41 -0
- package/dist/orchestrator/tools/worker-status-tool.js.map +1 -0
- package/dist/orchestrator/tools/worker-tools.d.ts +1 -1
- package/dist/orchestrator/tools/worker-tools.js +73 -89
- package/dist/orchestrator/tools/worker-tools.js.map +1 -1
- package/dist/orchestrator/types.d.ts +19 -29
- package/dist/orchestrator/types.js +22 -25
- package/dist/orchestrator/types.js.map +1 -1
- package/dist/orchestrator/utils/async-queue.d.ts +26 -0
- package/dist/orchestrator/utils/async-queue.js +70 -0
- package/dist/orchestrator/utils/async-queue.js.map +1 -0
- package/dist/orchestrator/utils/session-logger.d.ts +1 -1
- package/dist/orchestrator/utils/session-logger.js +8 -14
- package/dist/orchestrator/utils/session-logger.js.map +1 -1
- package/dist/orchestrator/worker-manager.d.ts +31 -15
- package/dist/orchestrator/worker-manager.js +186 -18
- package/dist/orchestrator/worker-manager.js.map +1 -1
- package/dist/relay/relay-bridge.d.ts +24 -3
- package/dist/relay/relay-bridge.js +382 -90
- package/dist/relay/relay-bridge.js.map +1 -1
- package/dist/relay/relay-service.d.ts +4 -7
- package/dist/relay/relay-service.js +5 -11
- package/dist/relay/relay-service.js.map +1 -1
- package/dist/repl/terminal-repl.js +34 -30
- package/dist/repl/terminal-repl.js.map +1 -1
- package/dist/schemas/generated.d.ts +244 -0
- package/dist/schemas/generated.js +5 -0
- package/dist/schemas/generated.js.map +1 -0
- package/dist/schemas/index.d.ts +2 -0
- package/dist/schemas/index.js +2 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/scripts/generate-schema-types.js +53 -0
- package/dist/scripts/generate-schema-types.js.map +1 -0
- package/dist/scripts/sync-schemas.d.ts +1 -0
- package/dist/scripts/sync-schemas.js +28 -0
- package/dist/scripts/sync-schemas.js.map +1 -0
- package/dist/utils/prompt.js +4 -10
- package/dist/utils/prompt.js.map +1 -1
- package/dist/voice/voice-service.d.ts +1 -1
- package/dist/voice/voice-service.js +2 -4
- package/dist/voice/voice-service.js.map +1 -1
- package/package.json +6 -2
- package/dist/commands/hello.d.ts +0 -2
- package/dist/commands/hello.js +0 -12
- package/dist/commands/hello.js.map +0 -1
- package/dist/generated/relay.d.ts +0 -240
- package/dist/generated/relay.js +0 -2376
- package/dist/generated/relay.js.map +0 -1
- package/dist/messaging/proto-codec.d.ts +0 -5
- package/dist/messaging/proto-codec.js +0 -387
- package/dist/messaging/proto-codec.js.map +0 -1
- package/dist/server/agent-server.d.ts +0 -46
- package/dist/server/agent-server.js +0 -429
- package/dist/server/agent-server.js.map +0 -1
- package/dist/server/ai-client.d.ts +0 -16
- package/dist/server/ai-client.js +0 -74
- package/dist/server/ai-client.js.map +0 -1
- package/dist/server/session.d.ts +0 -35
- package/dist/server/session.js +0 -272
- package/dist/server/session.js.map +0 -1
- package/dist/server/subagents.d.ts +0 -19
- package/dist/server/subagents.js +0 -42
- package/dist/server/subagents.js.map +0 -1
- package/dist/server/tools/worker-tools.d.ts +0 -2
- package/dist/server/tools/worker-tools.js +0 -37
- package/dist/server/tools/worker-tools.js.map +0 -1
- package/dist/server/types.d.ts +0 -120
- package/dist/server/types.js +0 -29
- package/dist/server/types.js.map +0 -1
- package/dist/server/utils/session-logger.d.ts +0 -7
- package/dist/server/utils/session-logger.js +0 -53
- package/dist/server/utils/session-logger.js.map +0 -1
- package/dist/server/worker-manager.d.ts +0 -67
- package/dist/server/worker-manager.js +0 -207
- package/dist/server/worker-manager.js.map +0 -1
- package/dist/test-agent.js +0 -63
- package/dist/test-agent.js.map +0 -1
- package/dist/utils/base64url.d.ts +0 -1
- package/dist/utils/base64url.js +0 -12
- package/dist/utils/base64url.js.map +0 -1
- package/dist/utils/random.d.ts +0 -1
- package/dist/utils/random.js +0 -9
- package/dist/utils/random.js.map +0 -1
- /package/dist/{test-agent.d.ts → scripts/generate-schema-types.d.ts} +0 -0
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { randomUUID } from 'crypto';
|
|
2
|
+
import { createSessionLogger } from './utils/session-logger.js';
|
|
3
|
+
export class Session {
|
|
4
|
+
id;
|
|
5
|
+
aiClient;
|
|
6
|
+
subscribers = new Map();
|
|
7
|
+
onEmpty;
|
|
8
|
+
onToolUse;
|
|
9
|
+
logger;
|
|
10
|
+
sdkSessionId = null;
|
|
11
|
+
inflight = null;
|
|
12
|
+
lastActivity = Date.now();
|
|
7
13
|
constructor(id, aiClient, onEmpty, onToolUse) {
|
|
8
|
-
this.subscribers = new Map();
|
|
9
|
-
this.sdkSessionId = null;
|
|
10
|
-
this.inflight = null;
|
|
11
|
-
this.lastActivity = Date.now();
|
|
12
14
|
this.id = id;
|
|
13
15
|
this.aiClient = aiClient;
|
|
14
16
|
this.onEmpty = onEmpty;
|
|
15
17
|
this.onToolUse = onToolUse;
|
|
16
|
-
this.logger =
|
|
18
|
+
this.logger = createSessionLogger(this.id);
|
|
17
19
|
}
|
|
18
20
|
announceInboundMessage(text, origin = 'user', workerId, workerTask) {
|
|
19
21
|
if (!text) {
|
|
@@ -30,7 +32,7 @@ class Session {
|
|
|
30
32
|
origin,
|
|
31
33
|
workerId,
|
|
32
34
|
workerTask,
|
|
33
|
-
messageId:
|
|
35
|
+
messageId: randomUUID(),
|
|
34
36
|
};
|
|
35
37
|
this.broadcast(message);
|
|
36
38
|
}
|
|
@@ -42,7 +44,7 @@ class Session {
|
|
|
42
44
|
}
|
|
43
45
|
subscribe(subscriber) {
|
|
44
46
|
this.subscribers.set(subscriber.id, subscriber);
|
|
45
|
-
this.safeSend(subscriber, { type: 'session_joined', sessionId: this.id, messageId:
|
|
47
|
+
this.safeSend(subscriber, { type: 'session_joined', sessionId: this.id, messageId: randomUUID() });
|
|
46
48
|
}
|
|
47
49
|
unsubscribe(subscriberId) {
|
|
48
50
|
this.subscribers.delete(subscriberId);
|
|
@@ -57,7 +59,7 @@ class Session {
|
|
|
57
59
|
this.subscribers.clear();
|
|
58
60
|
this.logger.close();
|
|
59
61
|
}
|
|
60
|
-
enqueueUserMessage(text) {
|
|
62
|
+
enqueueUserMessage(text, metadata) {
|
|
61
63
|
this.lastActivity = Date.now();
|
|
62
64
|
const previous = this.inflight;
|
|
63
65
|
const task = async () => {
|
|
@@ -69,7 +71,7 @@ class Session {
|
|
|
69
71
|
// Previous error already reported, continue with new message.
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
|
-
await this.processUserMessage(text);
|
|
74
|
+
await this.processUserMessage(text, metadata);
|
|
73
75
|
};
|
|
74
76
|
const promise = task()
|
|
75
77
|
.catch((error) => {
|
|
@@ -77,7 +79,7 @@ class Session {
|
|
|
77
79
|
type: 'error',
|
|
78
80
|
sessionId: this.id,
|
|
79
81
|
message: extractErrorMessage(error),
|
|
80
|
-
messageId:
|
|
82
|
+
messageId: randomUUID(),
|
|
81
83
|
});
|
|
82
84
|
})
|
|
83
85
|
.finally(() => {
|
|
@@ -96,11 +98,12 @@ class Session {
|
|
|
96
98
|
case 'content_block_delta': {
|
|
97
99
|
const delta = event.delta;
|
|
98
100
|
if (delta?.type === 'text_delta' && delta.text) {
|
|
101
|
+
console.log('[Session] Streaming text delta:', delta.text.substring(0, 50));
|
|
99
102
|
this.broadcast({
|
|
100
103
|
type: 'assistant_text',
|
|
101
104
|
sessionId: this.id,
|
|
102
105
|
text: delta.text,
|
|
103
|
-
messageId:
|
|
106
|
+
messageId: randomUUID(),
|
|
104
107
|
});
|
|
105
108
|
}
|
|
106
109
|
break;
|
|
@@ -109,7 +112,21 @@ class Session {
|
|
|
109
112
|
break;
|
|
110
113
|
}
|
|
111
114
|
}
|
|
112
|
-
async processUserMessage(text) {
|
|
115
|
+
async processUserMessage(text, metadata) {
|
|
116
|
+
// Broadcast metadata about this generation trigger
|
|
117
|
+
if (metadata?.triggeredBy === 'worker_completion') {
|
|
118
|
+
this.broadcast({
|
|
119
|
+
type: 'system',
|
|
120
|
+
sessionId: this.id,
|
|
121
|
+
subtype: 'generation_triggered',
|
|
122
|
+
metadata: {
|
|
123
|
+
triggeredBy: 'worker_completion',
|
|
124
|
+
workerId: metadata.workerId,
|
|
125
|
+
workerTask: metadata.workerTask,
|
|
126
|
+
},
|
|
127
|
+
messageId: randomUUID(),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
113
130
|
const options = this.sdkSessionId ? { resume: this.sdkSessionId } : undefined;
|
|
114
131
|
for await (const message of this.aiClient.streamUserMessage(text, options)) {
|
|
115
132
|
this.routeSdkMessage(message);
|
|
@@ -136,7 +153,7 @@ class Session {
|
|
|
136
153
|
type: 'user_text',
|
|
137
154
|
sessionId: this.id,
|
|
138
155
|
text: textContent,
|
|
139
|
-
messageId:
|
|
156
|
+
messageId: randomUUID(),
|
|
140
157
|
});
|
|
141
158
|
}
|
|
142
159
|
break;
|
|
@@ -150,6 +167,7 @@ class Session {
|
|
|
150
167
|
if (!Array.isArray(content)) {
|
|
151
168
|
return;
|
|
152
169
|
}
|
|
170
|
+
console.log('[Session] Processing assistant message with', content.length, 'blocks');
|
|
153
171
|
for (const block of content) {
|
|
154
172
|
if (!block || typeof block !== 'object') {
|
|
155
173
|
continue;
|
|
@@ -158,47 +176,52 @@ class Session {
|
|
|
158
176
|
const blockType = typed.type;
|
|
159
177
|
if (blockType === 'text' && typeof typed.text === 'string') {
|
|
160
178
|
if (typed.text.length > 0) {
|
|
179
|
+
console.log('[Session] Broadcasting assistant_text:', typed.text.substring(0, 100));
|
|
161
180
|
this.broadcast({
|
|
162
181
|
type: 'assistant_text',
|
|
163
182
|
sessionId: this.id,
|
|
164
183
|
text: typed.text,
|
|
165
|
-
messageId:
|
|
184
|
+
messageId: randomUUID(),
|
|
166
185
|
});
|
|
167
186
|
}
|
|
168
187
|
}
|
|
169
188
|
else if (blockType === 'tool_use') {
|
|
170
|
-
const toolUseId = typeof typed.id === 'string' ? typed.id :
|
|
189
|
+
const toolUseId = typeof typed.id === 'string' && typed.id ? typed.id : randomUUID();
|
|
190
|
+
console.log('[Session] Broadcasting tool_call:', typed.name, 'id:', toolUseId);
|
|
171
191
|
this.broadcast({
|
|
172
192
|
type: 'tool_call',
|
|
173
193
|
sessionId: this.id,
|
|
174
194
|
toolName: typeof typed.name === 'string' ? typed.name : 'unknown',
|
|
175
|
-
toolUseId
|
|
195
|
+
toolUseId,
|
|
176
196
|
input: typed.input,
|
|
177
|
-
messageId:
|
|
197
|
+
messageId: randomUUID(), // Always use a valid UUID for message_id
|
|
178
198
|
});
|
|
179
|
-
|
|
180
|
-
this.onToolUse?.(toolUseId, this.id);
|
|
181
|
-
}
|
|
199
|
+
this.onToolUse?.(toolUseId, this.id);
|
|
182
200
|
}
|
|
183
201
|
else if (blockType === 'tool_result') {
|
|
184
|
-
const toolResultId = typeof typed.tool_use_id === 'string' ? typed.tool_use_id :
|
|
202
|
+
const toolResultId = typeof typed.tool_use_id === 'string' && typed.tool_use_id ? typed.tool_use_id : randomUUID();
|
|
203
|
+
console.log('[Session] Broadcasting tool_result:', toolResultId);
|
|
185
204
|
this.broadcast({
|
|
186
205
|
type: 'tool_result',
|
|
187
206
|
sessionId: this.id,
|
|
188
|
-
toolUseId: toolResultId
|
|
207
|
+
toolUseId: toolResultId,
|
|
189
208
|
content: typed.content,
|
|
190
209
|
isError: Boolean(typed.is_error),
|
|
191
|
-
messageId:
|
|
210
|
+
messageId: randomUUID(), // Always use a valid UUID for message_id
|
|
192
211
|
});
|
|
193
212
|
}
|
|
194
213
|
}
|
|
195
214
|
}
|
|
196
215
|
handleResultMessage(message) {
|
|
197
|
-
|
|
216
|
+
const success = message.subtype === 'success';
|
|
198
217
|
this.broadcast({
|
|
199
|
-
type: '
|
|
218
|
+
type: 'agent_complete',
|
|
200
219
|
sessionId: this.id,
|
|
201
|
-
|
|
220
|
+
success,
|
|
221
|
+
durationMs: message.duration_ms,
|
|
222
|
+
costUsd: message.total_cost_usd,
|
|
223
|
+
message: success ? message.result : `Error: ${message.subtype}`,
|
|
224
|
+
messageId: randomUUID(),
|
|
202
225
|
});
|
|
203
226
|
}
|
|
204
227
|
handleSystemMessage(message) {
|
|
@@ -209,7 +232,7 @@ class Session {
|
|
|
209
232
|
type: 'system',
|
|
210
233
|
sessionId: this.id,
|
|
211
234
|
subtype: message.subtype,
|
|
212
|
-
messageId:
|
|
235
|
+
messageId: randomUUID(),
|
|
213
236
|
});
|
|
214
237
|
}
|
|
215
238
|
logInbound(payload) {
|
|
@@ -234,7 +257,6 @@ class Session {
|
|
|
234
257
|
}
|
|
235
258
|
}
|
|
236
259
|
}
|
|
237
|
-
exports.Session = Session;
|
|
238
260
|
function extractErrorMessage(error) {
|
|
239
261
|
if (error instanceof Error) {
|
|
240
262
|
return error.message;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/orchestrator/session.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/orchestrator/session.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAGpC,OAAO,EAAE,mBAAmB,EAAsB,MAAM,2BAA2B,CAAC;AASpF,MAAM,OAAO,OAAO;IACT,EAAE,CAAS;IAEH,QAAQ,CAAc;IACtB,WAAW,GAAG,IAAI,GAAG,EAA6B,CAAC;IACnD,OAAO,CAA8B;IACrC,SAAS,CAAmB;IAC5B,MAAM,CAAgB;IAE/B,YAAY,GAAkB,IAAI,CAAC;IACn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
+
export interface StatusUpdateEvent {
|
|
2
|
+
message: string;
|
|
3
|
+
metadata?: Record<string, unknown>;
|
|
4
|
+
timestamp: number;
|
|
5
|
+
}
|
|
6
|
+
export type StatusUpdateCallback = (event: StatusUpdateEvent) => void;
|
|
7
|
+
export declare function createWorkerStatusMcpServer(onStatusUpdate: StatusUpdateCallback): import("@anthropic-ai/claude-agent-sdk").McpSdkServerConfigWithInstance;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createSdkMcpServer, tool } from '@anthropic-ai/claude-agent-sdk';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export function createWorkerStatusMcpServer(onStatusUpdate) {
|
|
4
|
+
return createSdkMcpServer({
|
|
5
|
+
name: 'worker_status',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
tools: [
|
|
8
|
+
tool('send_status_update', `Send a status update message to notify about progress.
|
|
9
|
+
|
|
10
|
+
Use this tool to:
|
|
11
|
+
- Report progress on long-running tasks
|
|
12
|
+
- Notify about important milestones or decisions
|
|
13
|
+
- Provide context about what you're currently working on
|
|
14
|
+
- Signal warnings or issues that don't stop execution
|
|
15
|
+
|
|
16
|
+
The status update will be visible to the orchestrator and tracked in your task's progress history.`, {
|
|
17
|
+
message: z.string().min(1, 'message is required').describe('A concise status update message describing current progress or state'),
|
|
18
|
+
metadata: z.record(z.any()).optional().describe('Optional metadata to attach to this status update'),
|
|
19
|
+
}, async (args) => {
|
|
20
|
+
console.log('[StatusTool] send_status_update called:', {
|
|
21
|
+
message: args.message,
|
|
22
|
+
metadata: args.metadata,
|
|
23
|
+
});
|
|
24
|
+
onStatusUpdate({
|
|
25
|
+
message: args.message,
|
|
26
|
+
metadata: args.metadata,
|
|
27
|
+
timestamp: Date.now(),
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
content: [
|
|
31
|
+
{
|
|
32
|
+
type: 'text',
|
|
33
|
+
text: 'Status update sent successfully.',
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
}),
|
|
38
|
+
],
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=worker-status-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-status-tool.js","sourceRoot":"","sources":["../../../src/orchestrator/tools/worker-status-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB,MAAM,UAAU,2BAA2B,CAAC,cAAoC;IAC9E,OAAO,kBAAkB,CAAC;QACxB,IAAI,EAAE,eAAe;QACrB,OAAO,EAAE,OAAO;QAChB,KAAK,EAAE;YACL,IAAI,CACF,oBAAoB,EACpB;;;;;;;;mGAQ2F,EAC3F;gBACE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAAC,QAAQ,CAAC,sEAAsE,CAAC;gBAClI,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,mDAAmD,CAAC;aACrG,EACD,KAAK,EAAE,IAAI,EAAE,EAAE;gBACb,OAAO,CAAC,GAAG,CAAC,yCAAyC,EAAE;oBACrD,OAAO,EAAE,IAAI,CAAC,OAAO;oBACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ;iBACxB,CAAC,CAAC;gBAEH,cAAc,CAAC;oBACb,OAAO,EAAE,IAAI,CAAC,OAAO;oBACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ;oBACvB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;iBACtB,CAAC,CAAC;gBAEH,OAAO;oBACL,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,kCAAkC;yBACzC;qBACF;iBACF,CAAC;YACJ,CAAC,CACF;SACF;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { WorkerManager } from '../worker-manager';
|
|
1
|
+
import type { WorkerManager } from '../worker-manager.js';
|
|
2
2
|
interface WorkerMcpContext {
|
|
3
3
|
resolveSessionIdBySdk: (sdkSessionId?: string) => string | undefined;
|
|
4
4
|
resolveSessionIdByToolUse: (toolUseId: string) => string | undefined;
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const zod_1 = require("zod");
|
|
6
|
-
function createWorkerMcpServer(workerManager, context) {
|
|
7
|
-
return (0, claude_agent_sdk_1.createSdkMcpServer)({
|
|
1
|
+
import { createSdkMcpServer, tool } from '@anthropic-ai/claude-agent-sdk';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export function createWorkerMcpServer(workerManager, context) {
|
|
4
|
+
return createSdkMcpServer({
|
|
8
5
|
name: 'worker',
|
|
9
6
|
version: '1.0.0',
|
|
10
7
|
tools: [
|
|
11
|
-
|
|
8
|
+
tool('launch_worker', `Launch a background worker agent to handle tasks autonomously.
|
|
12
9
|
|
|
13
10
|
When to use this tool:
|
|
14
11
|
- Complex tasks requiring multiple steps or operations
|
|
@@ -23,9 +20,9 @@ Usage notes:
|
|
|
23
20
|
- Worker outputs should be trusted - they have the same capabilities as you
|
|
24
21
|
- The worker's result is returned to you, not the user - you must summarize or forward relevant information
|
|
25
22
|
- Worker progress status is automatically included in your context - you can see their current state without additional tools`, {
|
|
26
|
-
task:
|
|
27
|
-
prompt:
|
|
28
|
-
metadata:
|
|
23
|
+
task: z.string().min(1, 'task name is required').describe('A short, unique name for this task (e.g., "FizzBuzz Python", "Search codebase", "Fix bug #123"). Used to identify and track this worker.'),
|
|
24
|
+
prompt: z.string().min(1, 'prompt is required'),
|
|
25
|
+
metadata: z.record(z.any()).optional(),
|
|
29
26
|
}, async (args, extra) => {
|
|
30
27
|
const typedExtra = extra;
|
|
31
28
|
const toolUseIdRaw = typedExtra?._meta?.['claudecode/toolUseId'];
|
|
@@ -54,106 +51,93 @@ Usage notes:
|
|
|
54
51
|
],
|
|
55
52
|
};
|
|
56
53
|
}),
|
|
57
|
-
|
|
54
|
+
tool('message_worker', `Send a message to a running worker to provide additional context, requirements, or steering.
|
|
58
55
|
|
|
59
56
|
Use this tool to:
|
|
60
|
-
-
|
|
61
|
-
-
|
|
62
|
-
-
|
|
63
|
-
-
|
|
57
|
+
- Add new requirements or clarifications to an in-progress task
|
|
58
|
+
- Provide additional context the worker might need
|
|
59
|
+
- Correct or redirect the worker's current approach
|
|
60
|
+
- Answer implicit questions or resolve ambiguities
|
|
64
61
|
|
|
65
|
-
|
|
66
|
-
-
|
|
67
|
-
-
|
|
62
|
+
**When to use this tool:**
|
|
63
|
+
- User provides additional requirements while a task is in progress
|
|
64
|
+
- User clarifies or corrects their original request
|
|
65
|
+
- User adds context that would help the running worker
|
|
66
|
+
- A logically related request comes in for an existing task
|
|
68
67
|
|
|
69
|
-
|
|
70
|
-
-
|
|
71
|
-
-
|
|
72
|
-
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
**When to launch a NEW worker instead:**
|
|
69
|
+
- The request is for a completely different, unrelated task
|
|
70
|
+
- The user explicitly requests a separate task
|
|
71
|
+
- The new work would conflict with the current worker's objective
|
|
72
|
+
|
|
73
|
+
**Interrupt parameter:**
|
|
74
|
+
- interrupt=true: Stop current work immediately and redirect (use for critical corrections or significant changes in direction)
|
|
75
|
+
- interrupt=false: Queue message for after current turn completes (use for additions, clarifications, or supplementary context)
|
|
76
|
+
|
|
77
|
+
**Guidelines for interrupt:**
|
|
78
|
+
- Use interrupt=true ONLY if:
|
|
79
|
+
- User explicitly says to stop/interrupt current work
|
|
80
|
+
- The new requirement significantly contradicts the current direction
|
|
81
|
+
- The worker is heading down the wrong path and needs immediate correction
|
|
82
|
+
- Use interrupt=false (default) for:
|
|
83
|
+
- Adding requirements that build on current work
|
|
84
|
+
- Providing helpful context or clarifications
|
|
85
|
+
- Making additions that don't conflict with current progress
|
|
86
|
+
|
|
87
|
+
Example 1 (queue):
|
|
88
|
+
User: "Add authentication to my app"
|
|
89
|
+
Orchestrator: [launches worker: "add auth"]
|
|
90
|
+
User: "Make sure it works with Google OAuth"
|
|
91
|
+
Orchestrator: [message_worker: task="add auth", message="User wants Google OAuth integration", interrupt=false]
|
|
92
|
+
|
|
93
|
+
Example 2 (interrupt):
|
|
94
|
+
User: "Refactor the database layer"
|
|
95
|
+
Orchestrator: [launches worker: "refactor database"]
|
|
96
|
+
User: "Wait, actually don't touch the database - just refactor the API layer instead"
|
|
97
|
+
Orchestrator: [message_worker: task="refactor database", message="User wants to change scope - refactor API layer instead, leave database alone", interrupt=true]`, {
|
|
98
|
+
task: z.string().min(1, 'task name is required').describe('The task name of the worker to message'),
|
|
99
|
+
message: z.string().min(1, 'message is required').describe('The message to send to the worker. Be clear and specific about what has changed or what additional context is being provided.'),
|
|
100
|
+
interrupt: z.boolean().default(false).describe('If true, interrupt current generation immediately; if false (default), queue message for next turn'),
|
|
75
101
|
}, async (args) => {
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const checkWorkers = () => {
|
|
81
|
-
const results = args.tasks.map(task => {
|
|
82
|
-
const worker = workerManager.getWorkerByTask(task);
|
|
83
|
-
if (!worker) {
|
|
84
|
-
return {
|
|
85
|
-
found: false,
|
|
86
|
-
task,
|
|
87
|
-
message: `No worker found with task name: ${task}`,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
const isDone = worker.status === 'completed' || worker.status === 'error' || worker.status === 'canceled';
|
|
91
|
-
const latestMessage = worker.progress.length > 0
|
|
92
|
-
? worker.progress[worker.progress.length - 1]?.message
|
|
93
|
-
: undefined;
|
|
102
|
+
const success = await workerManager.messageWorker(args.task, args.message, args.interrupt);
|
|
103
|
+
if (!success) {
|
|
104
|
+
const worker = workerManager.getWorkerByTask(args.task);
|
|
105
|
+
if (!worker) {
|
|
94
106
|
return {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
lastUpdateAt: new Date(worker.lastUpdateAt).toISOString(),
|
|
107
|
+
content: [
|
|
108
|
+
{
|
|
109
|
+
type: 'text',
|
|
110
|
+
text: JSON.stringify({
|
|
111
|
+
success: false,
|
|
112
|
+
error: `No worker found with task name: ${args.task}`,
|
|
113
|
+
}),
|
|
114
|
+
},
|
|
115
|
+
],
|
|
105
116
|
};
|
|
106
|
-
}
|
|
107
|
-
const allComplete = results.every(r => !r.found || r.isDone);
|
|
108
|
-
return { workers: results, allComplete };
|
|
109
|
-
};
|
|
110
|
-
// Get initial status
|
|
111
|
-
const initialCheck = checkWorkers();
|
|
112
|
-
// If not waiting or all already done, return immediately
|
|
113
|
-
if (!shouldWait || initialCheck.allComplete) {
|
|
117
|
+
}
|
|
114
118
|
return {
|
|
115
119
|
content: [
|
|
116
120
|
{
|
|
117
121
|
type: 'text',
|
|
118
122
|
text: JSON.stringify({
|
|
119
|
-
|
|
120
|
-
|
|
123
|
+
success: false,
|
|
124
|
+
error: `Worker "${args.task}" is not running (status: ${worker.status})`,
|
|
121
125
|
}),
|
|
122
126
|
},
|
|
123
127
|
],
|
|
124
128
|
};
|
|
125
129
|
}
|
|
126
|
-
// Poll until all done or timeout
|
|
127
|
-
const startTime = Date.now();
|
|
128
|
-
const timeoutMs = timeout * 1000;
|
|
129
|
-
while (Date.now() - startTime < timeoutMs) {
|
|
130
|
-
await new Promise(resolve => setTimeout(resolve, pollIntervalMs));
|
|
131
|
-
const current = checkWorkers();
|
|
132
|
-
if (current.allComplete) {
|
|
133
|
-
return {
|
|
134
|
-
content: [
|
|
135
|
-
{
|
|
136
|
-
type: 'text',
|
|
137
|
-
text: JSON.stringify({
|
|
138
|
-
...current,
|
|
139
|
-
timedOut: false,
|
|
140
|
-
}),
|
|
141
|
-
},
|
|
142
|
-
],
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
// Timeout reached, return current status
|
|
147
|
-
const finalCheck = checkWorkers();
|
|
148
|
-
const stillRunning = finalCheck.workers.filter(w => w.found && !w.isDone).map(w => w.task);
|
|
149
130
|
return {
|
|
150
131
|
content: [
|
|
151
132
|
{
|
|
152
133
|
type: 'text',
|
|
153
134
|
text: JSON.stringify({
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
135
|
+
success: true,
|
|
136
|
+
task: args.task,
|
|
137
|
+
interrupted: args.interrupt,
|
|
138
|
+
message: args.interrupt
|
|
139
|
+
? `Message sent to worker "${args.task}" (interrupted current work)`
|
|
140
|
+
: `Message queued for worker "${args.task}" (will be delivered after current turn)`,
|
|
157
141
|
}),
|
|
158
142
|
},
|
|
159
143
|
],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-tools.js","sourceRoot":"","sources":["../../../src/orchestrator/tools/worker-tools.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"worker-tools.js","sourceRoot":"","sources":["../../../src/orchestrator/tools/worker-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAcxB,MAAM,UAAU,qBAAqB,CACnC,aAA4B,EAC5B,OAAyB;IAEzB,OAAO,kBAAkB,CAAC;QACxB,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,OAAO;QAChB,KAAK,EAAE;YACL,IAAI,CACF,eAAe,EACf;;;;;;;;;;;;;;8HAcsH,EACtH;gBACE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,uBAAuB,CAAC,CAAC,QAAQ,CAAC,0IAA0I,CAAC;gBACrM,MAA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,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gCACnB,OAAO,EAAE,IAAI;gCACb,IAAI,EAAE,IAAI,CAAC,IAAI;gCACf,WAAW,EAAE,IAAI,CAAC,SAAS;gCAC3B,OAAO,EAAE,IAAI,CAAC,SAAS;oCACrB,CAAC,CAAC,2BAA2B,IAAI,CAAC,IAAI,8BAA8B;oCACpE,CAAC,CAAC,8BAA8B,IAAI,CAAC,IAAI,0CAA0C;6BACtF,CAAC;yBACH;qBACF;iBACF,CAAC;YACJ,CAAC,CACF;SACF;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -76,7 +76,7 @@ export type OutboundMessage = {
|
|
|
76
76
|
metadata?: Record<string, unknown>;
|
|
77
77
|
messageId?: string;
|
|
78
78
|
} | {
|
|
79
|
-
type: '
|
|
79
|
+
type: 'session_init_ack';
|
|
80
80
|
sessionId: string;
|
|
81
81
|
parentSessionId?: string | null;
|
|
82
82
|
messageId?: string;
|
|
@@ -96,10 +96,13 @@ export type OutboundMessage = {
|
|
|
96
96
|
workerTask?: string;
|
|
97
97
|
messageId?: string;
|
|
98
98
|
} | {
|
|
99
|
-
type: '
|
|
99
|
+
type: 'agent_complete';
|
|
100
100
|
sessionId: string;
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
success: boolean;
|
|
102
|
+
durationMs?: number;
|
|
103
|
+
costUsd?: number;
|
|
104
|
+
message?: string;
|
|
105
|
+
metadata?: Record<string, unknown>;
|
|
103
106
|
messageId?: string;
|
|
104
107
|
} | {
|
|
105
108
|
type: 'tool_call';
|
|
@@ -107,6 +110,8 @@ export type OutboundMessage = {
|
|
|
107
110
|
toolName: string;
|
|
108
111
|
toolUseId: string;
|
|
109
112
|
input: unknown;
|
|
113
|
+
workerId?: string;
|
|
114
|
+
workerTask?: string;
|
|
110
115
|
messageId?: string;
|
|
111
116
|
} | {
|
|
112
117
|
type: 'tool_result';
|
|
@@ -114,48 +119,33 @@ export type OutboundMessage = {
|
|
|
114
119
|
toolUseId: string;
|
|
115
120
|
content: unknown;
|
|
116
121
|
isError?: boolean;
|
|
122
|
+
workerId?: string;
|
|
123
|
+
workerTask?: string;
|
|
124
|
+
messageId?: string;
|
|
125
|
+
} | {
|
|
126
|
+
type: 'agent_progress';
|
|
127
|
+
sessionId?: string;
|
|
128
|
+
status: string;
|
|
129
|
+
detail?: string;
|
|
130
|
+
metadata?: Record<string, unknown>;
|
|
117
131
|
messageId?: string;
|
|
118
132
|
} | {
|
|
119
133
|
type: 'system';
|
|
120
134
|
sessionId: string;
|
|
121
135
|
subtype: string;
|
|
136
|
+
metadata?: Record<string, unknown>;
|
|
122
137
|
messageId?: string;
|
|
123
138
|
} | {
|
|
124
139
|
type: 'error';
|
|
125
140
|
sessionId?: string;
|
|
126
141
|
message: string;
|
|
127
142
|
messageId?: string;
|
|
128
|
-
} | {
|
|
129
|
-
type: 'worker_update';
|
|
130
|
-
worker: WorkerUpdatePayload;
|
|
131
|
-
sessionId?: string;
|
|
132
|
-
messageId?: string;
|
|
133
143
|
} | {
|
|
134
144
|
type: 'pong';
|
|
135
145
|
messageId?: string;
|
|
136
|
-
} | {
|
|
137
|
-
type: 'result';
|
|
138
|
-
sessionId: string;
|
|
139
|
-
success: boolean;
|
|
140
|
-
durationMs?: number;
|
|
141
|
-
costUsd?: number;
|
|
142
|
-
message?: string;
|
|
143
|
-
messageId?: string;
|
|
144
146
|
};
|
|
145
147
|
export interface SessionSubscriber {
|
|
146
148
|
id: string;
|
|
147
149
|
send: (message: OutboundMessage) => void;
|
|
148
150
|
canSend?: () => boolean;
|
|
149
151
|
}
|
|
150
|
-
export interface WorkerUpdatePayload {
|
|
151
|
-
id: string;
|
|
152
|
-
task: string;
|
|
153
|
-
status: string;
|
|
154
|
-
prompt: string;
|
|
155
|
-
lastUpdateAt: number;
|
|
156
|
-
latestMessage?: string;
|
|
157
|
-
result?: string;
|
|
158
|
-
error?: string;
|
|
159
|
-
originSessionId?: string;
|
|
160
|
-
sessionId: string;
|
|
161
|
-
}
|