wave-agent-sdk 0.13.1 → 0.13.3
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 +7 -0
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +37 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/managers/aiManager.d.ts.map +1 -1
- package/dist/managers/aiManager.js +65 -33
- package/dist/managers/backgroundTaskManager.d.ts +1 -0
- package/dist/managers/backgroundTaskManager.d.ts.map +1 -1
- package/dist/managers/backgroundTaskManager.js +49 -0
- package/dist/managers/forkedAgentManager.d.ts +49 -0
- package/dist/managers/forkedAgentManager.d.ts.map +1 -0
- package/dist/managers/forkedAgentManager.js +111 -0
- package/dist/managers/messageManager.d.ts +8 -1
- package/dist/managers/messageManager.d.ts.map +1 -1
- package/dist/managers/messageManager.js +14 -1
- package/dist/managers/notificationQueue.d.ts +8 -0
- package/dist/managers/notificationQueue.d.ts.map +1 -0
- package/dist/managers/notificationQueue.js +17 -0
- package/dist/managers/permissionManager.d.ts.map +1 -1
- package/dist/managers/permissionManager.js +2 -0
- package/dist/managers/subagentManager.d.ts +7 -9
- package/dist/managers/subagentManager.d.ts.map +1 -1
- package/dist/managers/subagentManager.js +101 -21
- package/dist/services/autoMemoryService.d.ts +1 -1
- package/dist/services/autoMemoryService.d.ts.map +1 -1
- package/dist/services/autoMemoryService.js +7 -8
- package/dist/services/interactionService.d.ts.map +1 -1
- package/dist/services/interactionService.js +12 -0
- package/dist/types/agent.d.ts +1 -0
- package/dist/types/agent.d.ts.map +1 -1
- package/dist/types/messaging.d.ts +9 -1
- package/dist/types/messaging.d.ts.map +1 -1
- package/dist/utils/containerSetup.d.ts.map +1 -1
- package/dist/utils/containerSetup.js +6 -0
- package/dist/utils/convertMessagesForAPI.d.ts.map +1 -1
- package/dist/utils/convertMessagesForAPI.js +8 -0
- package/dist/utils/messageOperations.d.ts +9 -0
- package/dist/utils/messageOperations.d.ts.map +1 -1
- package/dist/utils/messageOperations.js +17 -0
- package/dist/utils/notificationXml.d.ts +4 -0
- package/dist/utils/notificationXml.d.ts.map +1 -0
- package/dist/utils/notificationXml.js +40 -0
- package/dist/utils/pathEncoder.d.ts +0 -1
- package/dist/utils/pathEncoder.d.ts.map +1 -1
- package/dist/utils/pathEncoder.js +1 -5
- package/package.json +1 -1
- package/src/agent.ts +44 -0
- package/src/index.ts +1 -0
- package/src/managers/aiManager.ts +76 -41
- package/src/managers/backgroundTaskManager.ts +72 -1
- package/src/managers/forkedAgentManager.ts +193 -0
- package/src/managers/messageManager.ts +25 -0
- package/src/managers/notificationQueue.ts +19 -0
- package/src/managers/permissionManager.ts +2 -0
- package/src/managers/subagentManager.ts +135 -41
- package/src/services/autoMemoryService.ts +11 -17
- package/src/services/interactionService.ts +18 -0
- package/src/types/agent.ts +1 -0
- package/src/types/messaging.ts +11 -1
- package/src/utils/containerSetup.ts +8 -0
- package/src/utils/convertMessagesForAPI.ts +9 -0
- package/src/utils/messageOperations.ts +42 -1
- package/src/utils/notificationXml.ts +52 -0
- package/src/utils/pathEncoder.ts +1 -6
package/dist/agent.d.ts
CHANGED
|
@@ -12,12 +12,14 @@ export declare class Agent {
|
|
|
12
12
|
private permissionManager;
|
|
13
13
|
private planManager;
|
|
14
14
|
private subagentManager;
|
|
15
|
+
private forkedAgentManager;
|
|
15
16
|
private slashCommandManager;
|
|
16
17
|
private pluginManager;
|
|
17
18
|
private skillManager;
|
|
18
19
|
private cronManager;
|
|
19
20
|
private hookManager;
|
|
20
21
|
private reversionManager;
|
|
22
|
+
private notificationQueue;
|
|
21
23
|
private memoryRuleManager;
|
|
22
24
|
private liveConfigManager;
|
|
23
25
|
private taskManager;
|
|
@@ -150,6 +152,11 @@ export declare class Agent {
|
|
|
150
152
|
*/
|
|
151
153
|
restoreSession(sessionId: string): Promise<void>;
|
|
152
154
|
abortAIMessage(): void;
|
|
155
|
+
/**
|
|
156
|
+
* Process pending background task notifications by injecting them as user messages
|
|
157
|
+
* and triggering a new AI response cycle.
|
|
158
|
+
*/
|
|
159
|
+
private processPendingNotifications;
|
|
153
160
|
/** Execute bash command (bang command) */
|
|
154
161
|
bang(command: string): Promise<void>;
|
|
155
162
|
clearMessages(): Promise<void>;
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAkBA,OAAO,EACL,YAAY,EACZ,kBAAkB,EAElB,YAAY,EACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EACV,OAAO,EAEP,eAAe,EACf,aAAa,EACb,WAAW,EACX,KAAK,EACL,cAAc,EACd,cAAc,EACf,MAAM,kBAAkB,CAAC;AAe1B,qBAAa,KAAK;IAChB,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,SAAS,CAAY;IAE7B,OAAO,CAAC,WAAW,CAA4B;IAC/C,OAAO,CAAC,qBAAqB,CAAwB;IACrD,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,UAAU,CAAc;IAChC,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,kBAAkB,CAAqB;IAC/C,OAAO,CAAC,mBAAmB,CAAsB;IACjD,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,O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AIxD;;OAEG;IACI,iBAAiB,IAAI,cAAc;IAI1C;;;OAGG;IACI,iBAAiB,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI;IASpD;;;OAGG;IACU,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ1D;;OAEG;IACU,oBAAoB,IAAI,OAAO,CAAC;QAC3C,QAAQ,EAAE,OAAO,EAAE,CAAC;QACpB,UAAU,EAAE,MAAM,EAAE,CAAC;KACtB,CAAC;IAIF;;OAEG;IACI,eAAe,IAAI,MAAM,GAAG,SAAS;IAI5C;;OAEG;IACI,eAAe,IAAI,MAAM,EAAE;IAOlC;;OAEG;IACI,mBAAmB,IAAI,MAAM,EAAE;IAItC;;OAEG;IACU,eAAe,CAC1B,OAAO,EAAE,OAAO,wBAAwB,EAAE,qBAAqB,GAC9D,OAAO,CAAC,OAAO,wBAAwB,EAAE,kBAAkB,CAAC;IAI/D;;;OAGG;IACU,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI3D;;;;OAIG;IACI,mBAAmB,CACxB,UAAU,EAAE,MAAM,GACjB,OAAO,+BAA+B,EAAE,gBAAgB,GAAG,IAAI;IAIlE;;OAEG;IACH,IAAW,UAAU,IAAI,MAAM,CAE9B;CACF"}
|
package/dist/agent.js
CHANGED
|
@@ -2,6 +2,7 @@ import { LspManager } from "./managers/lspManager.js";
|
|
|
2
2
|
import { configValidator } from "./utils/configValidator.js";
|
|
3
3
|
import { btw } from "./services/aiService.js";
|
|
4
4
|
import { convertMessagesForAPI } from "./utils/convertMessagesForAPI.js";
|
|
5
|
+
import { parseTaskNotificationXml } from "./utils/notificationXml.js";
|
|
5
6
|
import { InitializationService } from "./services/initializationService.js";
|
|
6
7
|
import { InteractionService } from "./services/interactionService.js";
|
|
7
8
|
import { ConfigurationService } from "./services/configurationService.js";
|
|
@@ -100,11 +101,22 @@ export class Agent {
|
|
|
100
101
|
this.toolManager = this.container.get("ToolManager");
|
|
101
102
|
this.liveConfigManager = this.container.get("LiveConfigManager");
|
|
102
103
|
this.subagentManager = this.container.get("SubagentManager");
|
|
104
|
+
this.forkedAgentManager = this.container.get("ForkedAgentManager");
|
|
103
105
|
this.aiManager = this.container.get("AIManager");
|
|
104
106
|
this.slashCommandManager = this.container.get("SlashCommandManager");
|
|
105
107
|
this.pluginManager = this.container.get("PluginManager");
|
|
106
108
|
this.bangManager = this.container.get("BangManager");
|
|
107
109
|
this.cronManager = this.container.get("CronManager");
|
|
110
|
+
this.notificationQueue = this.container.get("NotificationQueue");
|
|
111
|
+
// Wire up notification queue to trigger AI when notifications arrive while idle
|
|
112
|
+
this.notificationQueue.onNotificationsEnqueued = () => {
|
|
113
|
+
// If the AI is NOT loading (idle), trigger a new AI cycle to process notifications
|
|
114
|
+
if (!this.aiManager.isLoading) {
|
|
115
|
+
this.processPendingNotifications().catch((error) => {
|
|
116
|
+
this.logger?.error("Failed to process pending notifications:", error);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
};
|
|
108
120
|
// Set initial permission mode if provided
|
|
109
121
|
if (options.permissionMode) {
|
|
110
122
|
this.setPermissionMode(options.permissionMode);
|
|
@@ -286,6 +298,29 @@ export class Agent {
|
|
|
286
298
|
abortAIMessage() {
|
|
287
299
|
this.aiManager.abortAIMessage();
|
|
288
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
* Process pending background task notifications by injecting them as user messages
|
|
303
|
+
* and triggering a new AI response cycle.
|
|
304
|
+
*/
|
|
305
|
+
async processPendingNotifications() {
|
|
306
|
+
const notifications = this.notificationQueue.dequeueAll();
|
|
307
|
+
if (notifications.length === 0)
|
|
308
|
+
return;
|
|
309
|
+
for (const notification of notifications) {
|
|
310
|
+
const block = parseTaskNotificationXml(notification);
|
|
311
|
+
if (block) {
|
|
312
|
+
this.messageManager.addNotificationMessage({
|
|
313
|
+
taskId: block.taskId,
|
|
314
|
+
taskType: block.taskType,
|
|
315
|
+
status: block.status,
|
|
316
|
+
summary: block.summary,
|
|
317
|
+
outputFile: block.outputFile,
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
// Trigger AI to process the notifications
|
|
322
|
+
await this.aiManager.sendAIMessage({ recursionDepth: 0 });
|
|
323
|
+
}
|
|
289
324
|
/** Execute bash command (bang command) */
|
|
290
325
|
async bang(command) {
|
|
291
326
|
await this.bangManager?.executeCommand(command);
|
|
@@ -344,6 +379,8 @@ export class Agent {
|
|
|
344
379
|
}
|
|
345
380
|
// Cleanup subagent manager
|
|
346
381
|
this.subagentManager.cleanup();
|
|
382
|
+
// Cleanup forked agent manager
|
|
383
|
+
this.forkedAgentManager.cleanup();
|
|
347
384
|
// Cleanup skill manager
|
|
348
385
|
await this.skillManager.destroy();
|
|
349
386
|
// Cleanup live configuration reload
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export * from "./utils/fileSearch.js";
|
|
|
9
9
|
export * from "./utils/globalLogger.js";
|
|
10
10
|
export * from "./utils/mcpUtils.js";
|
|
11
11
|
export * from "./utils/messageOperations.js";
|
|
12
|
+
export * from "./utils/notificationXml.js";
|
|
12
13
|
export * from "./utils/path.js";
|
|
13
14
|
export * from "./utils/promptHistory.js";
|
|
14
15
|
export * from "./utils/stringUtils.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,mBAAmB,CAAC;AAGlC,cAAc,sBAAsB,CAAC;AAGrC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAG1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,mBAAmB,CAAC;AAGlC,cAAc,sBAAsB,CAAC;AAGrC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAG1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export * from "./utils/fileSearch.js";
|
|
|
13
13
|
export * from "./utils/globalLogger.js";
|
|
14
14
|
export * from "./utils/mcpUtils.js";
|
|
15
15
|
export * from "./utils/messageOperations.js";
|
|
16
|
+
export * from "./utils/notificationXml.js";
|
|
16
17
|
export * from "./utils/path.js";
|
|
17
18
|
export * from "./utils/promptHistory.js";
|
|
18
19
|
export * from "./utils/stringUtils.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiManager.d.ts","sourceRoot":"","sources":["../../src/managers/aiManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"aiManager.d.ts","sourceRoot":"","sources":["../../src/managers/aiManager.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,KAAK,EAGN,MAAM,mBAAmB,CAAC;AAa3B,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAKlD,MAAM,WAAW,kBAAkB;IACjC,wBAAwB,CAAC,EAAE,CAAC,aAAa,EAAE,OAAO,KAAK,IAAI,CAAC;IAC5D,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACvC;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,kBAAkB,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,uEAAuE;IACvE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,kDAAkD;IAClD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,qBAAa,SAAS;IAYlB,OAAO,CAAC,SAAS;IAXZ,SAAS,EAAE,OAAO,CAAS;IAClC,OAAO,CAAC,eAAe,CAAgC;IACvD,OAAO,CAAC,mBAAmB,CAAgC;IAC3D,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,YAAY,CAAC,CAAS;IAC9B,OAAO,CAAC,YAAY,CAAC,CAAS;IAC9B,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,aAAa,CAAC,CAAS;gBAIrB,SAAS,EAAE,SAAS,EAC5B,OAAO,EAAE,gBAAgB;IAU3B,OAAO,KAAK,WAAW,GAEtB;IAED,OAAO,KAAK,cAAc,GAEzB;IAED,OAAO,KAAK,aAAa,GAIxB;IAED,OAAO,KAAK,WAAW,GAItB;IAED,OAAO,KAAK,qBAAqB,GAEhC;IAED,OAAO,KAAK,WAAW,GAEtB;IAED,OAAO,KAAK,gBAAgB,GAM3B;IAED,OAAO,KAAK,iBAAiB,GAE5B;IAED,OAAO,KAAK,oBAAoB,GAE/B;IAGM,gBAAgB,IAAI,aAAa;IAIjC,cAAc,IAAI,WAAW;IA6B7B,iBAAiB,IAAI,MAAM;IAI3B,WAAW,IAAI,MAAM,GAAG,SAAS;IAIjC,oBAAoB,IAAI,OAAO;IAItC,OAAO,CAAC,aAAa,CAAkB;IACvC,OAAO,CAAC,SAAS,CAAqB;IAEtC;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAevB,YAAY,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI;IAStC,cAAc,IAAI,IAAI;IAuB7B,OAAO,CAAC,qBAAqB;YAsBf,8BAA8B;IAgFrC,gBAAgB,IAAI,OAAO;IAI3B,gBAAgB,CAAC,aAAa,EAAE,OAAO,GAAG,IAAI;IAOrD,OAAO,KAAK,eAAe,GAE1B;IAED,OAAO,KAAK,YAAY,GAEvB;IAEY,aAAa,CACxB,OAAO,GAAE;QACP,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,oEAAoE;QACpE,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;QACxB,SAAS,CAAC,EAAE,MAAM,CAAC;KACf,GACL,OAAO,CAAC,IAAI,CAAC;IA+nBhB;;;;OAIG;YACW,gBAAgB;IAkF9B;;;OAGG;YACW,sBAAsB;IA+DpC;;OAEG;YACW,uBAAuB;CA0DtC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as aiService from "../services/aiService.js";
|
|
2
2
|
import { convertMessagesForAPI } from "../utils/convertMessagesForAPI.js";
|
|
3
|
+
import { parseTaskNotificationXml } from "../utils/notificationXml.js";
|
|
3
4
|
import { calculateComprehensiveTotalTokens } from "../utils/tokenCalculation.js";
|
|
4
5
|
import * as fs from "node:fs/promises";
|
|
5
6
|
import { buildSystemPrompt } from "../prompts/index.js";
|
|
@@ -93,6 +94,8 @@ export class AIManager {
|
|
|
93
94
|
}
|
|
94
95
|
setIsLoading(isLoading) {
|
|
95
96
|
this.isLoading = isLoading;
|
|
97
|
+
const options = this.container.get("AgentOptions");
|
|
98
|
+
options?.callbacks?.onLoadingChange?.(isLoading);
|
|
96
99
|
}
|
|
97
100
|
abortAIMessage() {
|
|
98
101
|
// Interrupt AI service
|
|
@@ -213,6 +216,13 @@ export class AIManager {
|
|
|
213
216
|
if (recursionDepth === 0 && this.isLoading) {
|
|
214
217
|
return;
|
|
215
218
|
}
|
|
219
|
+
// Set loading state early for the initial call, before any async work
|
|
220
|
+
if (recursionDepth === 0) {
|
|
221
|
+
this.setIsLoading(true);
|
|
222
|
+
if (allowedRules && allowedRules.length > 0) {
|
|
223
|
+
this.permissionManager?.addTemporaryRules(allowedRules);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
216
226
|
// Scan for file mentions in the last user message
|
|
217
227
|
if (recursionDepth === 0) {
|
|
218
228
|
const messages = this.messageManager.getMessages();
|
|
@@ -249,13 +259,6 @@ export class AIManager {
|
|
|
249
259
|
abortController = this.abortController;
|
|
250
260
|
toolAbortController = this.toolAbortController;
|
|
251
261
|
}
|
|
252
|
-
// Only set loading state for the initial call
|
|
253
|
-
if (recursionDepth === 0) {
|
|
254
|
-
this.setIsLoading(true);
|
|
255
|
-
if (allowedRules && allowedRules.length > 0) {
|
|
256
|
-
this.permissionManager?.addTemporaryRules(allowedRules);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
262
|
// Get recent message history
|
|
260
263
|
const recentMessages = convertMessagesForAPI(this.messageManager.getMessages());
|
|
261
264
|
try {
|
|
@@ -643,34 +646,63 @@ export class AIManager {
|
|
|
643
646
|
await this.messageManager.saveSession();
|
|
644
647
|
// Set loading to false first
|
|
645
648
|
this.setIsLoading(false);
|
|
646
|
-
//
|
|
647
|
-
this.
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
649
|
+
// Inject pending notifications from background tasks
|
|
650
|
+
const notificationQueue = this.container.has("NotificationQueue")
|
|
651
|
+
? this.container.get("NotificationQueue")
|
|
652
|
+
: undefined;
|
|
653
|
+
if (notificationQueue && notificationQueue.hasPending()) {
|
|
654
|
+
const notifications = notificationQueue.dequeueAll();
|
|
655
|
+
for (const notification of notifications) {
|
|
656
|
+
const block = parseTaskNotificationXml(notification);
|
|
657
|
+
if (block) {
|
|
658
|
+
this.messageManager.addNotificationMessage({
|
|
659
|
+
taskId: block.taskId,
|
|
660
|
+
taskType: block.taskType,
|
|
661
|
+
status: block.status,
|
|
662
|
+
summary: block.summary,
|
|
663
|
+
outputFile: block.outputFile,
|
|
664
|
+
});
|
|
659
665
|
}
|
|
660
666
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
667
|
+
// Recursively process the notifications
|
|
668
|
+
await this.sendAIMessage({
|
|
669
|
+
recursionDepth: 0,
|
|
670
|
+
model,
|
|
671
|
+
allowedRules,
|
|
672
|
+
maxTokens,
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
else {
|
|
676
|
+
// Clear temporary rules
|
|
677
|
+
this.permissionManager?.clearTemporaryRules();
|
|
678
|
+
// Clear abort controllers
|
|
679
|
+
this.abortController = null;
|
|
680
|
+
this.toolAbortController = null;
|
|
681
|
+
// Execute Stop/SubagentStop hooks only if the operation was not aborted
|
|
682
|
+
const isCurrentlyAborted = abortController.signal.aborted ||
|
|
683
|
+
toolAbortController.signal.aborted;
|
|
684
|
+
if (!isCurrentlyAborted) {
|
|
685
|
+
// Record committed snapshots to message history for the final turn
|
|
686
|
+
if (this.reversionManager) {
|
|
687
|
+
const snapshots = this.reversionManager.getAndClearCommittedSnapshots();
|
|
688
|
+
if (snapshots.length > 0) {
|
|
689
|
+
this.messageManager.addFileHistoryBlock(snapshots);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
const shouldContinue = await this.executeStopHooks();
|
|
693
|
+
// If Stop/SubagentStop hooks indicate we should continue (due to blocking errors),
|
|
694
|
+
// restart the AI conversation cycle
|
|
695
|
+
if (shouldContinue) {
|
|
696
|
+
logger?.info(`${this.subagentType ? "SubagentStop" : "Stop"} hooks indicate issues need fixing, continuing conversation...`);
|
|
697
|
+
// Restart the conversation to let AI fix the issues
|
|
698
|
+
// Use recursionDepth = 0 to set loading false again for continuation
|
|
699
|
+
await this.sendAIMessage({
|
|
700
|
+
recursionDepth: 0,
|
|
701
|
+
model,
|
|
702
|
+
allowedRules,
|
|
703
|
+
maxTokens,
|
|
704
|
+
});
|
|
705
|
+
}
|
|
674
706
|
}
|
|
675
707
|
}
|
|
676
708
|
}
|
|
@@ -15,6 +15,7 @@ export declare class BackgroundTaskManager {
|
|
|
15
15
|
private callbacks;
|
|
16
16
|
private workdir;
|
|
17
17
|
constructor(container: Container, options: BackgroundTaskManagerOptions);
|
|
18
|
+
private get notificationQueue();
|
|
18
19
|
private notifyTasksChange;
|
|
19
20
|
generateId(): string;
|
|
20
21
|
addTask(task: BackgroundTask): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backgroundTaskManager.d.ts","sourceRoot":"","sources":["../../src/managers/backgroundTaskManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAIzD,OAAO,
|
|
1
|
+
{"version":3,"file":"backgroundTaskManager.d.ts","sourceRoot":"","sources":["../../src/managers/backgroundTaskManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAIzD,OAAO,EACL,cAAc,EAGf,MAAM,uBAAuB,CAAC;AAG/B,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,CAAC,EAAE,MAAM,CAAC;KACnB,GAAG,IAAI;IAoCD,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IA+C7B,OAAO,IAAI,IAAI;CAUvB"}
|
|
@@ -12,6 +12,9 @@ export class BackgroundTaskManager {
|
|
|
12
12
|
this.callbacks = options.callbacks || {};
|
|
13
13
|
this.workdir = options.workdir;
|
|
14
14
|
}
|
|
15
|
+
get notificationQueue() {
|
|
16
|
+
return this.container.get("NotificationQueue");
|
|
17
|
+
}
|
|
15
18
|
notifyTasksChange() {
|
|
16
19
|
this.callbacks.onBackgroundTasksChange?.(Array.from(this.tasks.values()));
|
|
17
20
|
}
|
|
@@ -122,6 +125,15 @@ export class BackgroundTaskManager {
|
|
|
122
125
|
shell.endTime = Date.now();
|
|
123
126
|
shell.runtime = shell.endTime - startTime;
|
|
124
127
|
this.notifyTasksChange();
|
|
128
|
+
// Enqueue completion notification
|
|
129
|
+
const notificationQueue = this.container.has("NotificationQueue")
|
|
130
|
+
? this.container.get("NotificationQueue")
|
|
131
|
+
: undefined;
|
|
132
|
+
if (notificationQueue) {
|
|
133
|
+
const statusStr = shell.status;
|
|
134
|
+
const summary = `Command "${command}" ${statusStr} with exit code ${code ?? 0}`;
|
|
135
|
+
notificationQueue.enqueue(`<task-notification>\n<task-id>${id}</task-id>\n<task-type>shell</task-type>\n<output-file>${logPath}</output-file>\n<status>${statusStr}</status>\n<summary>${summary}</summary>\n</task-notification>`);
|
|
136
|
+
}
|
|
125
137
|
};
|
|
126
138
|
const onError = (error) => {
|
|
127
139
|
if (timeoutHandle) {
|
|
@@ -138,6 +150,14 @@ export class BackgroundTaskManager {
|
|
|
138
150
|
shell.endTime = Date.now();
|
|
139
151
|
shell.runtime = shell.endTime - startTime;
|
|
140
152
|
this.notifyTasksChange();
|
|
153
|
+
// Enqueue error notification
|
|
154
|
+
const notificationQueue = this.container.has("NotificationQueue")
|
|
155
|
+
? this.container.get("NotificationQueue")
|
|
156
|
+
: undefined;
|
|
157
|
+
if (notificationQueue) {
|
|
158
|
+
const summary = `Command "${command}" failed with error: ${stripAnsiColors(error.message)}`;
|
|
159
|
+
notificationQueue.enqueue(`<task-notification>\n<task-id>${id}</task-id>\n<task-type>shell</task-type>\n<output-file>${logPath}</output-file>\n<status>failed</status>\n<summary>${summary}</summary>\n</task-notification>`);
|
|
160
|
+
}
|
|
141
161
|
};
|
|
142
162
|
child.stdout?.on("data", onStdout);
|
|
143
163
|
child.stderr?.on("data", onStderr);
|
|
@@ -233,6 +253,15 @@ export class BackgroundTaskManager {
|
|
|
233
253
|
shell.endTime = Date.now();
|
|
234
254
|
shell.runtime = shell.endTime - startTime;
|
|
235
255
|
this.notifyTasksChange();
|
|
256
|
+
// Enqueue completion notification
|
|
257
|
+
const notificationQueue = this.container.has("NotificationQueue")
|
|
258
|
+
? this.container.get("NotificationQueue")
|
|
259
|
+
: undefined;
|
|
260
|
+
if (notificationQueue) {
|
|
261
|
+
const statusStr = shell.status;
|
|
262
|
+
const summary = `Command "${command}" ${statusStr} with exit code ${code ?? 0}`;
|
|
263
|
+
notificationQueue.enqueue(`<task-notification>\n<task-id>${id}</task-id>\n<task-type>shell</task-type>\n<output-file>${logPath}</output-file>\n<status>${statusStr}</status>\n<summary>${summary}</summary>\n</task-notification>`);
|
|
264
|
+
}
|
|
236
265
|
});
|
|
237
266
|
child.on("error", (error) => {
|
|
238
267
|
const stripped = `\nProcess error: ${stripAnsiColors(error.message)}`;
|
|
@@ -246,6 +275,14 @@ export class BackgroundTaskManager {
|
|
|
246
275
|
shell.endTime = Date.now();
|
|
247
276
|
shell.runtime = shell.endTime - startTime;
|
|
248
277
|
this.notifyTasksChange();
|
|
278
|
+
// Enqueue error notification
|
|
279
|
+
const notificationQueue = this.container.has("NotificationQueue")
|
|
280
|
+
? this.container.get("NotificationQueue")
|
|
281
|
+
: undefined;
|
|
282
|
+
if (notificationQueue) {
|
|
283
|
+
const summary = `Command "${command}" failed with error: ${stripAnsiColors(error.message)}`;
|
|
284
|
+
notificationQueue.enqueue(`<task-notification>\n<task-id>${id}</task-id>\n<task-type>shell</task-type>\n<output-file>${logPath}</output-file>\n<status>failed</status>\n<summary>${summary}</summary>\n</task-notification>`);
|
|
285
|
+
}
|
|
249
286
|
});
|
|
250
287
|
return id;
|
|
251
288
|
}
|
|
@@ -308,6 +345,18 @@ export class BackgroundTaskManager {
|
|
|
308
345
|
task.endTime = Date.now();
|
|
309
346
|
task.runtime = task.endTime - task.startTime;
|
|
310
347
|
this.notifyTasksChange();
|
|
348
|
+
// Enqueue killed notification
|
|
349
|
+
const notificationQueue = this.container.has("NotificationQueue")
|
|
350
|
+
? this.container.get("NotificationQueue")
|
|
351
|
+
: undefined;
|
|
352
|
+
if (notificationQueue) {
|
|
353
|
+
const description = task.description || "";
|
|
354
|
+
const command = task.command || "";
|
|
355
|
+
const summary = task.type === "subagent"
|
|
356
|
+
? `Agent task "${description}" was stopped`
|
|
357
|
+
: `Command "${command}" was stopped`;
|
|
358
|
+
notificationQueue.enqueue(`<task-notification>\n<task-id>${id}</task-id>\n<task-type>${task.type}</task-type>\n<status>killed</status>\n<summary>${summary}</summary>\n</task-notification>`);
|
|
359
|
+
}
|
|
311
360
|
return true;
|
|
312
361
|
}
|
|
313
362
|
cleanup() {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import type { Message } from "../types/index.js";
|
|
3
|
+
import { Container } from "../utils/container.js";
|
|
4
|
+
import { type SubagentInstance } from "./subagentManager.js";
|
|
5
|
+
import type { PermissionMode } from "../types/permissions.js";
|
|
6
|
+
export interface ForkedAgentEntry {
|
|
7
|
+
id: string;
|
|
8
|
+
instance: SubagentInstance;
|
|
9
|
+
logPath: string;
|
|
10
|
+
logStream?: fs.WriteStream;
|
|
11
|
+
status: "running" | "completed" | "failed";
|
|
12
|
+
}
|
|
13
|
+
export interface ForkedAgentManagerCallbacks {
|
|
14
|
+
onForkedAgentStatusChange?: (entries: ForkedAgentEntry[]) => void;
|
|
15
|
+
}
|
|
16
|
+
export declare class ForkedAgentManager {
|
|
17
|
+
private container;
|
|
18
|
+
private activeForks;
|
|
19
|
+
private callbacks;
|
|
20
|
+
constructor(container: Container, options?: {
|
|
21
|
+
callbacks?: ForkedAgentManagerCallbacks;
|
|
22
|
+
});
|
|
23
|
+
private get subagentManager();
|
|
24
|
+
/**
|
|
25
|
+
* Creates a forked subagent with conversation history and executes it asynchronously (fire-and-forget).
|
|
26
|
+
* Does NOT interact with BackgroundTaskManager.
|
|
27
|
+
*/
|
|
28
|
+
forkAndExecute(subagentType: string, messages: Message[], parameters: {
|
|
29
|
+
description: string;
|
|
30
|
+
allowedTools?: string[];
|
|
31
|
+
model?: string;
|
|
32
|
+
permissionModeOverride?: PermissionMode;
|
|
33
|
+
}, prompt: string): Promise<string>;
|
|
34
|
+
private executeFork;
|
|
35
|
+
/**
|
|
36
|
+
* Abort a running forked agent.
|
|
37
|
+
*/
|
|
38
|
+
stop(id: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Stop all running forked agents and clear the map.
|
|
41
|
+
*/
|
|
42
|
+
cleanup(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Returns list of active forked agents.
|
|
45
|
+
*/
|
|
46
|
+
getActiveForks(): ForkedAgentEntry[];
|
|
47
|
+
private notifyChange;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=forkedAgentManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forkedAgentManager.d.ts","sourceRoot":"","sources":["../../src/managers/forkedAgentManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAEzB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAmB,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,KAAK,EAAE,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
5
|
+
import { logger } from "../utils/globalLogger.js";
|
|
6
|
+
export class ForkedAgentManager {
|
|
7
|
+
constructor(container, options = {}) {
|
|
8
|
+
this.container = container;
|
|
9
|
+
this.activeForks = new Map();
|
|
10
|
+
this.callbacks = options.callbacks || {};
|
|
11
|
+
}
|
|
12
|
+
get subagentManager() {
|
|
13
|
+
return this.container.get("SubagentManager");
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a forked subagent with conversation history and executes it asynchronously (fire-and-forget).
|
|
17
|
+
* Does NOT interact with BackgroundTaskManager.
|
|
18
|
+
*/
|
|
19
|
+
async forkAndExecute(subagentType, messages, parameters, prompt) {
|
|
20
|
+
const id = randomUUID();
|
|
21
|
+
// Create log file for debugging
|
|
22
|
+
const logPath = path.join(os.tmpdir(), `wave-forked-agent-${id}.log`);
|
|
23
|
+
const logStream = fs.createWriteStream(logPath, { flags: "a" });
|
|
24
|
+
const entry = {
|
|
25
|
+
id,
|
|
26
|
+
instance: {}, // Temporary placeholder
|
|
27
|
+
logPath,
|
|
28
|
+
logStream,
|
|
29
|
+
status: "running",
|
|
30
|
+
};
|
|
31
|
+
this.activeForks.set(id, entry);
|
|
32
|
+
// Fire-and-forget execution
|
|
33
|
+
this.executeFork(entry, subagentType, messages, parameters, prompt).catch((error) => {
|
|
34
|
+
logger.error("Forked agent execution failed:", error);
|
|
35
|
+
});
|
|
36
|
+
return id;
|
|
37
|
+
}
|
|
38
|
+
async executeFork(entry, subagentType, messages, parameters, prompt) {
|
|
39
|
+
try {
|
|
40
|
+
const configuration = await this.subagentManager.findSubagent(subagentType);
|
|
41
|
+
if (!configuration) {
|
|
42
|
+
throw new Error(`Subagent type ${subagentType} not found`);
|
|
43
|
+
}
|
|
44
|
+
const instance = await this.subagentManager.createInstance(configuration, {
|
|
45
|
+
description: parameters.description,
|
|
46
|
+
subagent_type: subagentType,
|
|
47
|
+
prompt: "",
|
|
48
|
+
allowedTools: parameters.allowedTools,
|
|
49
|
+
model: parameters.model,
|
|
50
|
+
permissionModeOverride: parameters.permissionModeOverride,
|
|
51
|
+
}, false);
|
|
52
|
+
// Pre-load the message manager with conversation history
|
|
53
|
+
instance.messageManager.setMessages(messages);
|
|
54
|
+
instance.logStream = entry.logStream;
|
|
55
|
+
entry.instance = instance;
|
|
56
|
+
// Execute the agent asynchronously
|
|
57
|
+
const result = await this.subagentManager.executeAgent(instance, prompt, undefined, false);
|
|
58
|
+
// Write final response and completion to log
|
|
59
|
+
if (entry.logStream) {
|
|
60
|
+
entry.logStream.write(`[${new Date().toISOString()}] Final response:\n${result}\n`);
|
|
61
|
+
entry.logStream.write(`[${new Date().toISOString()}] Agent completed successfully\n`);
|
|
62
|
+
entry.logStream.end();
|
|
63
|
+
}
|
|
64
|
+
entry.status = "completed";
|
|
65
|
+
this.notifyChange();
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
69
|
+
if (entry.logStream) {
|
|
70
|
+
entry.logStream.write(`[${new Date().toISOString()}] Agent failed: ${errorMessage}\n`);
|
|
71
|
+
entry.logStream.end();
|
|
72
|
+
}
|
|
73
|
+
entry.status = "failed";
|
|
74
|
+
this.notifyChange();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Abort a running forked agent.
|
|
79
|
+
*/
|
|
80
|
+
stop(id) {
|
|
81
|
+
const entry = this.activeForks.get(id);
|
|
82
|
+
if (!entry) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
entry.instance?.aiManager?.abortAIMessage();
|
|
86
|
+
entry.logStream?.destroy();
|
|
87
|
+
this.activeForks.delete(id);
|
|
88
|
+
this.notifyChange();
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Stop all running forked agents and clear the map.
|
|
93
|
+
*/
|
|
94
|
+
cleanup() {
|
|
95
|
+
for (const [, entry] of this.activeForks) {
|
|
96
|
+
entry.instance?.aiManager?.abortAIMessage();
|
|
97
|
+
entry.logStream?.destroy();
|
|
98
|
+
}
|
|
99
|
+
this.activeForks.clear();
|
|
100
|
+
this.notifyChange();
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Returns list of active forked agents.
|
|
104
|
+
*/
|
|
105
|
+
getActiveForks() {
|
|
106
|
+
return Array.from(this.activeForks.values());
|
|
107
|
+
}
|
|
108
|
+
notifyChange() {
|
|
109
|
+
this.callbacks.onForkedAgentStatusChange?.(Array.from(this.activeForks.values()));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserMessageParams, type AgentToolBlockUpdateParams } from "../utils/messageOperations.js";
|
|
1
|
+
import { UserMessageParams, type AgentToolBlockUpdateParams, type AddNotificationMessageParams } from "../utils/messageOperations.js";
|
|
2
2
|
import type { Message, Usage } from "../types/index.js";
|
|
3
3
|
import { SessionData } from "../services/session.js";
|
|
4
4
|
import { ChatCompletionMessageFunctionToolCall } from "openai/resources.js";
|
|
@@ -22,6 +22,12 @@ export interface MessageManagerCallbacks {
|
|
|
22
22
|
onInfoBlockAdded?: (content: string) => void;
|
|
23
23
|
onShowRewind?: () => void;
|
|
24
24
|
onFileHistoryBlockAdded?: (snapshots: import("../types/reversion.js").FileSnapshot[]) => void;
|
|
25
|
+
onNotificationMessageAdded?: (params: {
|
|
26
|
+
taskId: string;
|
|
27
|
+
taskType: "shell" | "agent";
|
|
28
|
+
status: "completed" | "failed" | "killed";
|
|
29
|
+
summary: string;
|
|
30
|
+
}) => void;
|
|
25
31
|
}
|
|
26
32
|
export interface MessageManagerOptions {
|
|
27
33
|
callbacks: MessageManagerCallbacks;
|
|
@@ -120,6 +126,7 @@ export declare class MessageManager {
|
|
|
120
126
|
addBangMessage(command: string): void;
|
|
121
127
|
updateBangMessage(command: string, output: string): void;
|
|
122
128
|
completeBangMessage(command: string, exitCode: number, output?: string): void;
|
|
129
|
+
addNotificationMessage(params: Omit<AddNotificationMessageParams, "messages">): void;
|
|
123
130
|
/**
|
|
124
131
|
* Rebuild usage array from messages containing usage metadata
|
|
125
132
|
* Called during session restoration to reconstruct usage tracking
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageManager.d.ts","sourceRoot":"","sources":["../../src/managers/messageManager.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"messageManager.d.ts","sourceRoot":"","sources":["../../src/managers/messageManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,iBAAiB,EACjB,KAAK,0BAA0B,EAC/B,KAAK,4BAA4B,EAElC,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAIL,WAAW,EAEZ,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,qCAAqC,EAAE,MAAM,qBAAqB,CAAC;AAK5E,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,MAAM,WAAW,uBAAuB;IACtC,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACjD,iBAAiB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,yBAAyB,CAAC,EAAE,CAAC,iBAAiB,EAAE,MAAM,KAAK,IAAI,CAAC;IAChE,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,IAAI,CAAC;IAE3C,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAEzD,uBAAuB,CAAC,EAAE,MAAM,IAAI,CAAC;IAErC,yBAAyB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;IAEzE,2BAA2B,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,M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