wave-agent-sdk 0.0.7 → 0.0.8
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/agent.d.ts +32 -20
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +202 -20
- package/dist/constants/events.d.ts +28 -0
- package/dist/constants/events.d.ts.map +1 -0
- package/dist/constants/events.js +27 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/managers/aiManager.d.ts +34 -1
- package/dist/managers/aiManager.d.ts.map +1 -1
- package/dist/managers/aiManager.js +243 -128
- package/dist/managers/backgroundBashManager.d.ts.map +1 -1
- package/dist/managers/backgroundBashManager.js +7 -6
- package/dist/managers/hookManager.d.ts +9 -4
- package/dist/managers/hookManager.d.ts.map +1 -1
- package/dist/managers/hookManager.js +62 -30
- package/dist/managers/liveConfigManager.d.ts +58 -0
- package/dist/managers/liveConfigManager.d.ts.map +1 -0
- package/dist/managers/liveConfigManager.js +160 -0
- package/dist/managers/messageManager.d.ts +38 -13
- package/dist/managers/messageManager.d.ts.map +1 -1
- package/dist/managers/messageManager.js +163 -30
- package/dist/managers/slashCommandManager.d.ts.map +1 -1
- package/dist/managers/slashCommandManager.js +4 -1
- package/dist/managers/subagentManager.d.ts +51 -0
- package/dist/managers/subagentManager.d.ts.map +1 -1
- package/dist/managers/subagentManager.js +189 -18
- package/dist/services/aiService.d.ts +13 -5
- package/dist/services/aiService.d.ts.map +1 -1
- package/dist/services/aiService.js +350 -74
- package/dist/services/configurationWatcher.d.ts +120 -0
- package/dist/services/configurationWatcher.d.ts.map +1 -0
- package/dist/services/configurationWatcher.js +439 -0
- package/dist/services/fileWatcher.d.ts +69 -0
- package/dist/services/fileWatcher.d.ts.map +1 -0
- package/dist/services/fileWatcher.js +213 -0
- package/dist/services/hook.d.ts +91 -9
- package/dist/services/hook.d.ts.map +1 -1
- package/dist/services/hook.js +393 -43
- package/dist/services/jsonlHandler.d.ts +62 -0
- package/dist/services/jsonlHandler.d.ts.map +1 -0
- package/dist/services/jsonlHandler.js +257 -0
- package/dist/services/memory.d.ts +9 -0
- package/dist/services/memory.d.ts.map +1 -1
- package/dist/services/memory.js +81 -12
- package/dist/services/memoryStore.d.ts +81 -0
- package/dist/services/memoryStore.d.ts.map +1 -0
- package/dist/services/memoryStore.js +200 -0
- package/dist/services/session.d.ts +64 -49
- package/dist/services/session.d.ts.map +1 -1
- package/dist/services/session.js +310 -132
- package/dist/tools/bashTool.d.ts.map +1 -1
- package/dist/tools/bashTool.js +5 -4
- package/dist/tools/deleteFileTool.d.ts.map +1 -1
- package/dist/tools/deleteFileTool.js +2 -1
- package/dist/tools/editTool.d.ts.map +1 -1
- package/dist/tools/editTool.js +3 -2
- package/dist/tools/multiEditTool.d.ts.map +1 -1
- package/dist/tools/multiEditTool.js +4 -3
- package/dist/tools/readTool.d.ts.map +1 -1
- package/dist/tools/readTool.js +2 -1
- package/dist/tools/writeTool.d.ts.map +1 -1
- package/dist/tools/writeTool.js +5 -6
- package/dist/types/commands.d.ts +4 -0
- package/dist/types/commands.d.ts.map +1 -1
- package/dist/types/core.d.ts +35 -0
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/environment.d.ts +42 -0
- package/dist/types/environment.d.ts.map +1 -0
- package/dist/types/environment.js +21 -0
- package/dist/types/hooks.d.ts +8 -2
- package/dist/types/hooks.d.ts.map +1 -1
- package/dist/types/hooks.js +8 -2
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -0
- package/dist/types/memoryStore.d.ts +82 -0
- package/dist/types/memoryStore.d.ts.map +1 -0
- package/dist/types/memoryStore.js +7 -0
- package/dist/types/messaging.d.ts +14 -2
- package/dist/types/messaging.d.ts.map +1 -1
- package/dist/types/session.d.ts +20 -0
- package/dist/types/session.d.ts.map +1 -0
- package/dist/types/session.js +7 -0
- package/dist/utils/bashHistory.d.ts.map +1 -1
- package/dist/utils/bashHistory.js +27 -26
- package/dist/utils/cacheControlUtils.d.ts +121 -0
- package/dist/utils/cacheControlUtils.d.ts.map +1 -0
- package/dist/utils/cacheControlUtils.js +367 -0
- package/dist/utils/commandPathResolver.d.ts +52 -0
- package/dist/utils/commandPathResolver.d.ts.map +1 -0
- package/dist/utils/commandPathResolver.js +145 -0
- package/dist/utils/configPaths.d.ts +85 -0
- package/dist/utils/configPaths.d.ts.map +1 -0
- package/dist/utils/configPaths.js +121 -0
- package/dist/utils/configResolver.d.ts +37 -10
- package/dist/utils/configResolver.d.ts.map +1 -1
- package/dist/utils/configResolver.js +127 -23
- package/dist/utils/constants.d.ts +1 -1
- package/dist/utils/constants.js +1 -1
- package/dist/utils/convertMessagesForAPI.d.ts.map +1 -1
- package/dist/utils/convertMessagesForAPI.js +7 -5
- package/dist/utils/customCommands.d.ts.map +1 -1
- package/dist/utils/customCommands.js +66 -21
- package/dist/utils/fileUtils.d.ts +15 -0
- package/dist/utils/fileUtils.d.ts.map +1 -0
- package/dist/utils/fileUtils.js +61 -0
- package/dist/utils/globalLogger.d.ts +102 -0
- package/dist/utils/globalLogger.d.ts.map +1 -0
- package/dist/utils/globalLogger.js +136 -0
- package/dist/utils/mcpUtils.d.ts.map +1 -1
- package/dist/utils/mcpUtils.js +25 -3
- package/dist/utils/messageOperations.d.ts +20 -8
- package/dist/utils/messageOperations.d.ts.map +1 -1
- package/dist/utils/messageOperations.js +25 -16
- package/dist/utils/pathEncoder.d.ts +104 -0
- package/dist/utils/pathEncoder.d.ts.map +1 -0
- package/dist/utils/pathEncoder.js +272 -0
- package/dist/utils/subagentParser.d.ts.map +1 -1
- package/dist/utils/subagentParser.js +2 -1
- package/dist/utils/tokenCalculation.d.ts +26 -0
- package/dist/utils/tokenCalculation.d.ts.map +1 -0
- package/dist/utils/tokenCalculation.js +36 -0
- package/package.json +6 -3
- package/src/agent.ts +298 -34
- package/src/constants/events.ts +38 -0
- package/src/index.ts +2 -0
- package/src/managers/aiManager.ts +323 -170
- package/src/managers/backgroundBashManager.ts +7 -6
- package/src/managers/hookManager.ts +83 -40
- package/src/managers/liveConfigManager.ts +248 -0
- package/src/managers/messageManager.ts +230 -63
- package/src/managers/slashCommandManager.ts +4 -1
- package/src/managers/subagentManager.ts +283 -21
- package/src/services/aiService.ts +474 -83
- package/src/services/configurationWatcher.ts +622 -0
- package/src/services/fileWatcher.ts +301 -0
- package/src/services/hook.ts +538 -47
- package/src/services/jsonlHandler.ts +319 -0
- package/src/services/memory.ts +92 -12
- package/src/services/memoryStore.ts +279 -0
- package/src/services/session.ts +381 -157
- package/src/tools/bashTool.ts +5 -4
- package/src/tools/deleteFileTool.ts +2 -1
- package/src/tools/editTool.ts +3 -2
- package/src/tools/multiEditTool.ts +4 -3
- package/src/tools/readTool.ts +2 -1
- package/src/tools/writeTool.ts +7 -6
- package/src/types/commands.ts +6 -0
- package/src/types/core.ts +44 -0
- package/src/types/environment.ts +60 -0
- package/src/types/hooks.ts +21 -8
- package/src/types/index.ts +2 -0
- package/src/types/memoryStore.ts +94 -0
- package/src/types/messaging.ts +14 -2
- package/src/types/session.ts +25 -0
- package/src/utils/bashHistory.ts +27 -27
- package/src/utils/cacheControlUtils.ts +540 -0
- package/src/utils/commandPathResolver.ts +189 -0
- package/src/utils/configPaths.ts +163 -0
- package/src/utils/configResolver.ts +182 -22
- package/src/utils/constants.ts +1 -1
- package/src/utils/convertMessagesForAPI.ts +7 -5
- package/src/utils/customCommands.ts +90 -22
- package/src/utils/fileUtils.ts +65 -0
- package/src/utils/globalLogger.ts +145 -0
- package/src/utils/mcpUtils.ts +34 -3
- package/src/utils/messageOperations.ts +42 -20
- package/src/utils/pathEncoder.ts +379 -0
- package/src/utils/subagentParser.ts +2 -1
- package/src/utils/tokenCalculation.ts +43 -0
|
@@ -7,12 +7,39 @@ import type {
|
|
|
7
7
|
ModelConfig,
|
|
8
8
|
Usage,
|
|
9
9
|
} from "../types/index.js";
|
|
10
|
+
import type { SessionData } from "../services/session.js";
|
|
10
11
|
import { AIManager } from "./aiManager.js";
|
|
11
|
-
import {
|
|
12
|
-
MessageManager,
|
|
13
|
-
type MessageManagerCallbacks,
|
|
14
|
-
} from "./messageManager.js";
|
|
12
|
+
import { MessageManager } from "./messageManager.js";
|
|
15
13
|
import { ToolManager } from "./toolManager.js";
|
|
14
|
+
import { HookManager } from "./hookManager.js";
|
|
15
|
+
import {
|
|
16
|
+
UserMessageParams,
|
|
17
|
+
type AgentToolBlockUpdateParams,
|
|
18
|
+
} from "../utils/messageOperations.js";
|
|
19
|
+
|
|
20
|
+
export interface SubagentManagerCallbacks {
|
|
21
|
+
// Granular subagent message callbacks (015-subagent-message-callbacks)
|
|
22
|
+
/** Triggered when subagent adds user message */
|
|
23
|
+
onSubagentUserMessageAdded?: (
|
|
24
|
+
subagentId: string,
|
|
25
|
+
params: UserMessageParams,
|
|
26
|
+
) => void;
|
|
27
|
+
/** Triggered when subagent creates assistant message */
|
|
28
|
+
onSubagentAssistantMessageAdded?: (subagentId: string) => void;
|
|
29
|
+
/** Triggered during subagent content streaming updates */
|
|
30
|
+
onSubagentAssistantContentUpdated?: (
|
|
31
|
+
subagentId: string,
|
|
32
|
+
chunk: string,
|
|
33
|
+
accumulated: string,
|
|
34
|
+
) => void;
|
|
35
|
+
/** Triggered when subagent tool block is updated */
|
|
36
|
+
onSubagentToolBlockUpdated?: (
|
|
37
|
+
subagentId: string,
|
|
38
|
+
params: AgentToolBlockUpdateParams,
|
|
39
|
+
) => void;
|
|
40
|
+
/** Triggered when subagent messages change */
|
|
41
|
+
onSubagentMessagesChange?: (subagentId: string, messages: Message[]) => void;
|
|
42
|
+
}
|
|
16
43
|
|
|
17
44
|
export interface SubagentInstance {
|
|
18
45
|
subagentId: string;
|
|
@@ -22,16 +49,19 @@ export interface SubagentInstance {
|
|
|
22
49
|
toolManager: ToolManager;
|
|
23
50
|
status: "initializing" | "active" | "completed" | "error" | "aborted";
|
|
24
51
|
messages: Message[];
|
|
52
|
+
subagentType: string; // Store the subagent type for hook context
|
|
25
53
|
}
|
|
26
54
|
|
|
27
55
|
export interface SubagentManagerOptions {
|
|
28
56
|
workdir: string;
|
|
29
57
|
parentToolManager: ToolManager;
|
|
30
58
|
parentMessageManager: MessageManager;
|
|
59
|
+
callbacks?: SubagentManagerCallbacks; // Use SubagentManagerCallbacks instead of parentCallbacks
|
|
31
60
|
logger?: Logger;
|
|
32
61
|
gatewayConfig: GatewayConfig;
|
|
33
62
|
modelConfig: ModelConfig;
|
|
34
63
|
tokenLimit: number;
|
|
64
|
+
hookManager?: HookManager;
|
|
35
65
|
onUsageAdded?: (usage: Usage) => void;
|
|
36
66
|
}
|
|
37
67
|
|
|
@@ -42,20 +72,24 @@ export class SubagentManager {
|
|
|
42
72
|
private workdir: string;
|
|
43
73
|
private parentToolManager: ToolManager;
|
|
44
74
|
private parentMessageManager: MessageManager;
|
|
75
|
+
private callbacks?: SubagentManagerCallbacks; // Use SubagentManagerCallbacks instead of parentCallbacks
|
|
45
76
|
private logger?: Logger;
|
|
46
77
|
private gatewayConfig: GatewayConfig;
|
|
47
78
|
private modelConfig: ModelConfig;
|
|
48
79
|
private tokenLimit: number;
|
|
80
|
+
private hookManager?: HookManager;
|
|
49
81
|
private onUsageAdded?: (usage: Usage) => void;
|
|
50
82
|
|
|
51
83
|
constructor(options: SubagentManagerOptions) {
|
|
52
84
|
this.workdir = options.workdir;
|
|
53
85
|
this.parentToolManager = options.parentToolManager;
|
|
54
86
|
this.parentMessageManager = options.parentMessageManager;
|
|
87
|
+
this.callbacks = options.callbacks; // Store SubagentManagerCallbacks
|
|
55
88
|
this.logger = options.logger;
|
|
56
89
|
this.gatewayConfig = options.gatewayConfig;
|
|
57
90
|
this.modelConfig = options.modelConfig;
|
|
58
91
|
this.tokenLimit = options.tokenLimit;
|
|
92
|
+
this.hookManager = options.hookManager;
|
|
59
93
|
this.onUsageAdded = options.onUsageAdded;
|
|
60
94
|
}
|
|
61
95
|
|
|
@@ -126,24 +160,15 @@ export class SubagentManager {
|
|
|
126
160
|
const subagentId = randomUUID();
|
|
127
161
|
|
|
128
162
|
// Create isolated MessageManager for the subagent
|
|
129
|
-
const subagentCallbacks
|
|
130
|
-
// These callbacks will be handled by the parent agent
|
|
131
|
-
onMessagesChange: (messages: Message[]) => {
|
|
132
|
-
const instance = this.instances.get(subagentId);
|
|
133
|
-
if (instance) {
|
|
134
|
-
instance.messages = messages;
|
|
135
|
-
// Update parent's subagent block with latest messages
|
|
136
|
-
this.parentMessageManager.updateSubagentBlock(subagentId, {
|
|
137
|
-
messages: messages,
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
};
|
|
163
|
+
const subagentCallbacks = this.createSubagentCallbacks(subagentId);
|
|
142
164
|
|
|
143
165
|
const messageManager = new MessageManager({
|
|
144
166
|
callbacks: subagentCallbacks,
|
|
145
167
|
workdir: this.workdir,
|
|
146
168
|
logger: this.logger,
|
|
169
|
+
sessionType: "subagent",
|
|
170
|
+
parentSessionId: this.parentMessageManager.getSessionId(),
|
|
171
|
+
subagentType: parameters.subagent_type,
|
|
147
172
|
});
|
|
148
173
|
|
|
149
174
|
// Use the parent tool manager directly - tool restrictions will be handled by allowedTools parameter
|
|
@@ -162,6 +187,8 @@ export class SubagentManager {
|
|
|
162
187
|
logger: this.logger,
|
|
163
188
|
workdir: this.workdir,
|
|
164
189
|
systemPrompt: configuration.systemPrompt,
|
|
190
|
+
subagentType: parameters.subagent_type, // Pass subagent type for hook context
|
|
191
|
+
hookManager: this.hookManager,
|
|
165
192
|
gatewayConfig: this.gatewayConfig,
|
|
166
193
|
modelConfig: {
|
|
167
194
|
...this.modelConfig,
|
|
@@ -181,6 +208,7 @@ export class SubagentManager {
|
|
|
181
208
|
toolManager,
|
|
182
209
|
status: "initializing",
|
|
183
210
|
messages: [],
|
|
211
|
+
subagentType: parameters.subagent_type, // Store the subagent type
|
|
184
212
|
};
|
|
185
213
|
|
|
186
214
|
this.instances.set(subagentId, instance);
|
|
@@ -189,8 +217,9 @@ export class SubagentManager {
|
|
|
189
217
|
this.parentMessageManager.addSubagentBlock(
|
|
190
218
|
subagentId,
|
|
191
219
|
configuration.name,
|
|
220
|
+
messageManager.getSessionId(),
|
|
221
|
+
configuration,
|
|
192
222
|
"active",
|
|
193
|
-
[],
|
|
194
223
|
parameters,
|
|
195
224
|
);
|
|
196
225
|
|
|
@@ -226,7 +255,6 @@ export class SubagentManager {
|
|
|
226
255
|
this.updateInstanceStatus(instance.subagentId, "aborted");
|
|
227
256
|
this.parentMessageManager.updateSubagentBlock(instance.subagentId, {
|
|
228
257
|
status: "aborted",
|
|
229
|
-
messages: instance.messages,
|
|
230
258
|
});
|
|
231
259
|
});
|
|
232
260
|
}
|
|
@@ -292,11 +320,10 @@ export class SubagentManager {
|
|
|
292
320
|
);
|
|
293
321
|
const response = textBlocks.map((block) => block.content).join("\n");
|
|
294
322
|
|
|
295
|
-
// Update status to completed and update parent
|
|
323
|
+
// Update status to completed and update parent
|
|
296
324
|
this.updateInstanceStatus(instance.subagentId, "completed");
|
|
297
325
|
this.parentMessageManager.updateSubagentBlock(instance.subagentId, {
|
|
298
326
|
status: "completed",
|
|
299
|
-
messages: messages,
|
|
300
327
|
});
|
|
301
328
|
|
|
302
329
|
return response || "Task completed with no text response";
|
|
@@ -370,4 +397,239 @@ export class SubagentManager {
|
|
|
370
397
|
cleanup(): void {
|
|
371
398
|
this.instances.clear();
|
|
372
399
|
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Restore subagent instances from saved session data
|
|
403
|
+
* This method is called during agent initialization to restore previous subagent states
|
|
404
|
+
*/
|
|
405
|
+
async restoreSubagentSessions(
|
|
406
|
+
subagentSessions: Array<{
|
|
407
|
+
sessionData: SessionData;
|
|
408
|
+
subagentId: string;
|
|
409
|
+
configuration: SubagentConfiguration;
|
|
410
|
+
}>,
|
|
411
|
+
): Promise<void> {
|
|
412
|
+
for (const { sessionData, subagentId, configuration } of subagentSessions) {
|
|
413
|
+
try {
|
|
414
|
+
// Use the configuration from the SubagentBlock
|
|
415
|
+
|
|
416
|
+
// Create the subagent instance without executing - just restore the state
|
|
417
|
+
|
|
418
|
+
// Create MessageManager for the restored subagent
|
|
419
|
+
const subagentCallbacks = this.createSubagentCallbacks(subagentId);
|
|
420
|
+
const messageManager = new MessageManager({
|
|
421
|
+
callbacks: subagentCallbacks,
|
|
422
|
+
workdir: this.workdir,
|
|
423
|
+
logger: this.logger,
|
|
424
|
+
sessionType: "subagent",
|
|
425
|
+
parentSessionId: this.parentMessageManager.getSessionId(),
|
|
426
|
+
subagentType: configuration.name, // Use configuration name for restored sessions
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
// Use the parent tool manager
|
|
430
|
+
const toolManager = this.parentToolManager;
|
|
431
|
+
|
|
432
|
+
// Determine model to use
|
|
433
|
+
const modelToUse =
|
|
434
|
+
configuration.model && configuration.model !== "inherit"
|
|
435
|
+
? configuration.model
|
|
436
|
+
: this.modelConfig.agentModel;
|
|
437
|
+
|
|
438
|
+
// Create AIManager for the restored subagent
|
|
439
|
+
const aiManager = new AIManager({
|
|
440
|
+
messageManager,
|
|
441
|
+
toolManager,
|
|
442
|
+
logger: this.logger,
|
|
443
|
+
workdir: this.workdir,
|
|
444
|
+
systemPrompt: configuration.systemPrompt,
|
|
445
|
+
subagentType: configuration.name, // Use configuration name as subagent type for restored instances
|
|
446
|
+
hookManager: this.hookManager,
|
|
447
|
+
gatewayConfig: this.gatewayConfig,
|
|
448
|
+
modelConfig: {
|
|
449
|
+
...this.modelConfig,
|
|
450
|
+
agentModel: modelToUse,
|
|
451
|
+
},
|
|
452
|
+
tokenLimit: this.tokenLimit,
|
|
453
|
+
callbacks: {
|
|
454
|
+
onUsageAdded: this.onUsageAdded,
|
|
455
|
+
},
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
// Create restored instance
|
|
459
|
+
const instance: SubagentInstance = {
|
|
460
|
+
subagentId,
|
|
461
|
+
configuration,
|
|
462
|
+
aiManager,
|
|
463
|
+
messageManager,
|
|
464
|
+
toolManager,
|
|
465
|
+
status: "completed", // Restored sessions are considered completed
|
|
466
|
+
messages: sessionData.messages,
|
|
467
|
+
subagentType: configuration.name, // Use configuration name as subagent type for restored instances
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
// IMPORTANT: Store instance in map BEFORE calling setMessages
|
|
471
|
+
// This ensures the callback can find the instance
|
|
472
|
+
this.instances.set(subagentId, instance);
|
|
473
|
+
|
|
474
|
+
// Now restore the session data including sessionId, which will trigger the callback chain
|
|
475
|
+
const sessionDataObj = {
|
|
476
|
+
id: sessionData.id,
|
|
477
|
+
messages: sessionData.messages,
|
|
478
|
+
version: "1.0.0",
|
|
479
|
+
metadata: {
|
|
480
|
+
workdir: this.workdir,
|
|
481
|
+
startedAt: new Date().toISOString(),
|
|
482
|
+
lastActiveAt: new Date().toISOString(),
|
|
483
|
+
latestTotalTokens: 0,
|
|
484
|
+
},
|
|
485
|
+
};
|
|
486
|
+
messageManager.initializeFromSession(sessionDataObj);
|
|
487
|
+
} catch (error) {
|
|
488
|
+
this.logger?.warn(
|
|
489
|
+
`Failed to restore subagent session ${subagentId}:`,
|
|
490
|
+
error,
|
|
491
|
+
);
|
|
492
|
+
// Continue with other sessions even if one fails
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Create subagent callbacks for a specific subagent ID
|
|
499
|
+
* Extracted to reuse in both create and restore flows
|
|
500
|
+
*/
|
|
501
|
+
private createSubagentCallbacks(subagentId: string) {
|
|
502
|
+
return {
|
|
503
|
+
onUserMessageAdded: (params: UserMessageParams) => {
|
|
504
|
+
// Forward user message events to parent via SubagentManager callbacks
|
|
505
|
+
if (this.callbacks?.onSubagentUserMessageAdded) {
|
|
506
|
+
this.callbacks.onSubagentUserMessageAdded(subagentId, params);
|
|
507
|
+
}
|
|
508
|
+
},
|
|
509
|
+
|
|
510
|
+
onAssistantMessageAdded: () => {
|
|
511
|
+
// Forward assistant message events to parent via SubagentManager callbacks
|
|
512
|
+
if (this.callbacks?.onSubagentAssistantMessageAdded) {
|
|
513
|
+
this.callbacks.onSubagentAssistantMessageAdded(subagentId);
|
|
514
|
+
}
|
|
515
|
+
},
|
|
516
|
+
|
|
517
|
+
onAssistantContentUpdated: (chunk: string, accumulated: string) => {
|
|
518
|
+
// Forward assistant content updates to parent via SubagentManager callbacks
|
|
519
|
+
if (this.callbacks?.onSubagentAssistantContentUpdated) {
|
|
520
|
+
this.callbacks.onSubagentAssistantContentUpdated(
|
|
521
|
+
subagentId,
|
|
522
|
+
chunk,
|
|
523
|
+
accumulated,
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
},
|
|
527
|
+
|
|
528
|
+
onToolBlockUpdated: (params: AgentToolBlockUpdateParams) => {
|
|
529
|
+
// Forward tool block updates to parent via SubagentManager callbacks
|
|
530
|
+
if (this.callbacks?.onSubagentToolBlockUpdated) {
|
|
531
|
+
this.callbacks.onSubagentToolBlockUpdated(subagentId, params);
|
|
532
|
+
}
|
|
533
|
+
},
|
|
534
|
+
|
|
535
|
+
// These callbacks will be handled by the parent agent
|
|
536
|
+
onMessagesChange: (messages: Message[]) => {
|
|
537
|
+
const instance = this.instances.get(subagentId);
|
|
538
|
+
if (instance) {
|
|
539
|
+
instance.messages = messages;
|
|
540
|
+
// Forward subagent message changes to parent via callbacks
|
|
541
|
+
if (this.callbacks?.onSubagentMessagesChange) {
|
|
542
|
+
this.callbacks.onSubagentMessagesChange(subagentId, messages);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
},
|
|
546
|
+
|
|
547
|
+
onSessionIdChange: (newSessionId: string) => {
|
|
548
|
+
// Update the subagent block with the new session ID
|
|
549
|
+
this.parentMessageManager.updateSubagentBlock(subagentId, {
|
|
550
|
+
sessionId: newSessionId,
|
|
551
|
+
});
|
|
552
|
+
},
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Update configuration for SubagentManager and all active subagents
|
|
558
|
+
* This method updates configuration for live config reload support
|
|
559
|
+
* @param newGatewayConfig - New gateway configuration
|
|
560
|
+
* @param newModelConfig - New model configuration
|
|
561
|
+
* @param newTokenLimit - New token limit
|
|
562
|
+
*/
|
|
563
|
+
updateConfiguration(
|
|
564
|
+
newGatewayConfig: GatewayConfig,
|
|
565
|
+
newModelConfig: ModelConfig,
|
|
566
|
+
newTokenLimit: number,
|
|
567
|
+
): void {
|
|
568
|
+
this.logger?.info("Live Config: Updating SubagentManager configuration");
|
|
569
|
+
|
|
570
|
+
// Update stored configuration
|
|
571
|
+
this.gatewayConfig = newGatewayConfig;
|
|
572
|
+
this.modelConfig = newModelConfig;
|
|
573
|
+
this.tokenLimit = newTokenLimit;
|
|
574
|
+
|
|
575
|
+
// Update all active subagent AIManager instances
|
|
576
|
+
let updatedCount = 0;
|
|
577
|
+
for (const [subagentId, instance] of this.instances.entries()) {
|
|
578
|
+
if (instance.status === "active" || instance.status === "initializing") {
|
|
579
|
+
try {
|
|
580
|
+
// For subagents, we need to preserve their model if it was explicitly set
|
|
581
|
+
const subagentModelConfig = {
|
|
582
|
+
...newModelConfig,
|
|
583
|
+
// If subagent has its own model configured, preserve it
|
|
584
|
+
agentModel:
|
|
585
|
+
instance.configuration.model &&
|
|
586
|
+
instance.configuration.model !== "inherit"
|
|
587
|
+
? instance.configuration.model
|
|
588
|
+
: newModelConfig.agentModel,
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
instance.aiManager.updateConfiguration(
|
|
592
|
+
newGatewayConfig,
|
|
593
|
+
subagentModelConfig,
|
|
594
|
+
newTokenLimit,
|
|
595
|
+
);
|
|
596
|
+
updatedCount++;
|
|
597
|
+
|
|
598
|
+
this.logger?.debug(
|
|
599
|
+
`Live Config: Updated configuration for subagent ${subagentId}`,
|
|
600
|
+
);
|
|
601
|
+
} catch (error) {
|
|
602
|
+
this.logger?.error(
|
|
603
|
+
`Live Config: Failed to update configuration for subagent ${subagentId}: ${(error as Error).message}`,
|
|
604
|
+
);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
this.logger?.info(
|
|
610
|
+
`Live Config: SubagentManager configuration updated - ${updatedCount} active subagents updated`,
|
|
611
|
+
);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* Get current configuration for debugging
|
|
616
|
+
*/
|
|
617
|
+
getCurrentConfiguration(): {
|
|
618
|
+
gatewayConfig: GatewayConfig;
|
|
619
|
+
modelConfig: ModelConfig;
|
|
620
|
+
tokenLimit: number;
|
|
621
|
+
activeSubagents: number;
|
|
622
|
+
} {
|
|
623
|
+
const activeSubagents = Array.from(this.instances.values()).filter(
|
|
624
|
+
(instance) =>
|
|
625
|
+
instance.status === "active" || instance.status === "initializing",
|
|
626
|
+
).length;
|
|
627
|
+
|
|
628
|
+
return {
|
|
629
|
+
gatewayConfig: { ...this.gatewayConfig },
|
|
630
|
+
modelConfig: { ...this.modelConfig },
|
|
631
|
+
tokenLimit: this.tokenLimit,
|
|
632
|
+
activeSubagents,
|
|
633
|
+
};
|
|
634
|
+
}
|
|
373
635
|
}
|