wave-agent-sdk 0.0.1 → 0.0.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 +37 -3
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +82 -5
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/managers/aiManager.d.ts +7 -1
- package/dist/managers/aiManager.d.ts.map +1 -1
- package/dist/managers/aiManager.js +11 -5
- package/dist/managers/messageManager.d.ts +8 -0
- package/dist/managers/messageManager.d.ts.map +1 -1
- package/dist/managers/messageManager.js +26 -2
- package/dist/managers/skillManager.d.ts +4 -5
- package/dist/managers/skillManager.d.ts.map +1 -1
- package/dist/managers/skillManager.js +6 -82
- package/dist/managers/subagentManager.d.ts +96 -0
- package/dist/managers/subagentManager.d.ts.map +1 -0
- package/dist/managers/subagentManager.js +261 -0
- package/dist/managers/toolManager.d.ts +33 -1
- package/dist/managers/toolManager.d.ts.map +1 -1
- package/dist/managers/toolManager.js +43 -5
- package/dist/services/aiService.d.ts +5 -0
- package/dist/services/aiService.d.ts.map +1 -1
- package/dist/services/aiService.js +58 -28
- package/dist/services/session.d.ts.map +1 -1
- package/dist/services/session.js +4 -0
- package/dist/tools/grepTool.d.ts.map +1 -1
- package/dist/tools/grepTool.js +8 -6
- package/dist/tools/readTool.d.ts.map +1 -1
- package/dist/tools/readTool.js +36 -6
- package/dist/tools/skillTool.d.ts +8 -0
- package/dist/tools/skillTool.d.ts.map +1 -0
- package/dist/tools/skillTool.js +72 -0
- package/dist/tools/taskTool.d.ts +8 -0
- package/dist/tools/taskTool.d.ts.map +1 -0
- package/dist/tools/taskTool.js +109 -0
- package/dist/tools/todoWriteTool.d.ts +6 -0
- package/dist/tools/todoWriteTool.d.ts.map +1 -0
- package/dist/tools/todoWriteTool.js +203 -0
- package/dist/types.d.ts +65 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +16 -0
- package/dist/utils/configResolver.d.ts +38 -0
- package/dist/utils/configResolver.d.ts.map +1 -0
- package/dist/utils/configResolver.js +106 -0
- package/dist/utils/configValidator.d.ts +36 -0
- package/dist/utils/configValidator.d.ts.map +1 -0
- package/dist/utils/configValidator.js +78 -0
- package/dist/utils/constants.d.ts +10 -0
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +10 -0
- package/dist/utils/fileFormat.d.ts +17 -0
- package/dist/utils/fileFormat.d.ts.map +1 -0
- package/dist/utils/fileFormat.js +35 -0
- package/dist/utils/messageOperations.d.ts +18 -0
- package/dist/utils/messageOperations.d.ts.map +1 -1
- package/dist/utils/messageOperations.js +43 -0
- package/dist/utils/subagentParser.d.ts +19 -0
- package/dist/utils/subagentParser.d.ts.map +1 -0
- package/dist/utils/subagentParser.js +159 -0
- package/package.json +11 -15
- package/src/agent.ts +130 -9
- package/src/index.ts +0 -1
- package/src/managers/aiManager.ts +22 -10
- package/src/managers/messageManager.ts +55 -1
- package/src/managers/skillManager.ts +7 -96
- package/src/managers/subagentManager.ts +368 -0
- package/src/managers/toolManager.ts +50 -5
- package/src/services/aiService.ts +92 -36
- package/src/services/session.ts +5 -0
- package/src/tools/grepTool.ts +9 -6
- package/src/tools/readTool.ts +40 -6
- package/src/tools/skillTool.ts +82 -0
- package/src/tools/taskTool.ts +128 -0
- package/src/tools/todoWriteTool.ts +232 -0
- package/src/types.ts +85 -1
- package/src/utils/configResolver.ts +142 -0
- package/src/utils/configValidator.ts +133 -0
- package/src/utils/constants.ts +10 -0
- package/src/utils/fileFormat.ts +40 -0
- package/src/utils/messageOperations.ts +80 -0
- package/src/utils/subagentParser.ts +223 -0
package/dist/agent.d.ts
CHANGED
|
@@ -3,7 +3,18 @@ import { type McpManagerCallbacks } from "./managers/mcpManager.js";
|
|
|
3
3
|
import { type BackgroundBashManagerCallbacks } from "./managers/backgroundBashManager.js";
|
|
4
4
|
import type { SlashCommand, CustomSlashCommand } from "./types.js";
|
|
5
5
|
import type { Message, Logger, McpServerStatus } from "./types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Configuration options for Agent instances
|
|
8
|
+
*
|
|
9
|
+
* IMPORTANT: This interface is used by both Agent constructor and Agent.create()
|
|
10
|
+
* Any changes to this interface must be compatible with both methods.
|
|
11
|
+
*/
|
|
6
12
|
export interface AgentOptions {
|
|
13
|
+
apiKey?: string;
|
|
14
|
+
baseURL?: string;
|
|
15
|
+
agentModel?: string;
|
|
16
|
+
fastModel?: string;
|
|
17
|
+
tokenLimit?: number;
|
|
7
18
|
callbacks?: AgentCallbacks;
|
|
8
19
|
restoreSessionId?: string;
|
|
9
20
|
continueLastSession?: boolean;
|
|
@@ -20,17 +31,28 @@ export interface AgentCallbacks extends MessageManagerCallbacks, BackgroundBashM
|
|
|
20
31
|
export declare class Agent {
|
|
21
32
|
private messageManager;
|
|
22
33
|
private aiManager;
|
|
23
|
-
private callbacks;
|
|
24
34
|
private bashManager;
|
|
25
35
|
private backgroundBashManager;
|
|
26
36
|
private logger?;
|
|
27
37
|
private toolManager;
|
|
28
38
|
private mcpManager;
|
|
39
|
+
private subagentManager;
|
|
29
40
|
private slashCommandManager;
|
|
30
41
|
private hookManager;
|
|
31
42
|
private workdir;
|
|
32
43
|
private systemPrompt?;
|
|
33
|
-
private
|
|
44
|
+
private gatewayConfig;
|
|
45
|
+
private modelConfig;
|
|
46
|
+
private tokenLimit;
|
|
47
|
+
/**
|
|
48
|
+
* Agent constructor - handles configuration resolution and validation
|
|
49
|
+
*
|
|
50
|
+
* IMPORTANT: Keep this constructor's signature exactly the same as Agent.create()
|
|
51
|
+
* to maintain API consistency. Both methods should accept the same AgentOptions.
|
|
52
|
+
*
|
|
53
|
+
* @param options - Configuration options for the Agent instance
|
|
54
|
+
*/
|
|
55
|
+
constructor(options: AgentOptions);
|
|
34
56
|
get sessionId(): string;
|
|
35
57
|
get messages(): Message[];
|
|
36
58
|
get latestTotalTokens(): number;
|
|
@@ -51,7 +73,15 @@ export declare class Agent {
|
|
|
51
73
|
} | null;
|
|
52
74
|
/** Kill background bash shell */
|
|
53
75
|
killBackgroundShell(id: string): boolean;
|
|
54
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Static async factory method for creating Agent instances
|
|
78
|
+
*
|
|
79
|
+
* IMPORTANT: Keep this method's signature exactly the same as the constructor
|
|
80
|
+
* to maintain consistency and avoid confusion for users of the API.
|
|
81
|
+
*
|
|
82
|
+
* @param options - Same AgentOptions interface used by constructor
|
|
83
|
+
* @returns Promise<Agent> - Fully initialized Agent instance
|
|
84
|
+
*/
|
|
55
85
|
static create(options: AgentOptions): Promise<Agent>;
|
|
56
86
|
/** Private initialization method, handles async initialization logic */
|
|
57
87
|
private initialize;
|
|
@@ -68,6 +98,10 @@ export declare class Agent {
|
|
|
68
98
|
abortBashCommand(): void;
|
|
69
99
|
/** Interrupt slash command execution */
|
|
70
100
|
abortSlashCommand(): void;
|
|
101
|
+
/** Interrupt all subagent execution */
|
|
102
|
+
abortSubagents(): void;
|
|
103
|
+
/** Interrupt specific subagent execution */
|
|
104
|
+
abortSubagent(subagentId: string): boolean;
|
|
71
105
|
/** Destroy managers, clean up resources */
|
|
72
106
|
destroy(): Promise<void>;
|
|
73
107
|
sendMessage(content: string, images?: Array<{
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,8BAA8B,CAAC;AAKtC,OAAO,EAAc,KAAK,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEhF,OAAO,EAEL,KAAK,8BAA8B,EACpC,MAAM,qCAAqC,CAAC;AAE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AAG,OAAO;IAIjD,2CAA2C;IAC9B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAcxB,WAAW,CACtB,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,GACjD,OAAO,CAAC,IAAI,CAAC;IAgEhB,iDAAiD;IACpC,UAAU,CACrB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,GAAG,MAAM,GACvB,OAAO,CAAC,IAAI,CAAC;IAqChB,gCAAgC;IACzB,aAAa,IAAI,eAAe,EAAE;IAIzC,yBAAyB;IACZ,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAInE,4BAA4B;IACf,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAMtE,uCAAuC;IAChC,gBAAgB,IAAI,YAAY,EAAE;IAIzC,oCAAoC;IAC7B,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAIlD,6BAA6B;IACtB,oBAAoB,IAAI,IAAI;IAInC,iCAAiC;IAC1B,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAI1E,8BAA8B;IACvB,iBAAiB,IAAI,kBAAkB,EAAE;CAGjD"}
|
package/dist/agent.js
CHANGED
|
@@ -1,27 +1,52 @@
|
|
|
1
1
|
import { MessageManager, } from "./managers/messageManager.js";
|
|
2
2
|
import { AIManager } from "./managers/aiManager.js";
|
|
3
3
|
import { ToolManager } from "./managers/toolManager.js";
|
|
4
|
+
import { SubagentManager } from "./managers/subagentManager.js";
|
|
4
5
|
import * as memory from "./services/memory.js";
|
|
5
6
|
import { McpManager } from "./managers/mcpManager.js";
|
|
6
7
|
import { BashManager } from "./managers/bashManager.js";
|
|
7
8
|
import { BackgroundBashManager, } from "./managers/backgroundBashManager.js";
|
|
8
9
|
import { SlashCommandManager } from "./managers/slashCommandManager.js";
|
|
9
10
|
import { HookManager } from "./hooks/index.js";
|
|
11
|
+
import { configResolver } from "./utils/configResolver.js";
|
|
12
|
+
import { configValidator } from "./utils/configValidator.js";
|
|
13
|
+
import { SkillManager } from "./managers/skillManager.js";
|
|
10
14
|
export class Agent {
|
|
11
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Agent constructor - handles configuration resolution and validation
|
|
17
|
+
*
|
|
18
|
+
* IMPORTANT: Keep this constructor's signature exactly the same as Agent.create()
|
|
19
|
+
* to maintain API consistency. Both methods should accept the same AgentOptions.
|
|
20
|
+
*
|
|
21
|
+
* @param options - Configuration options for the Agent instance
|
|
22
|
+
*/
|
|
12
23
|
constructor(options) {
|
|
13
24
|
this.bashManager = null;
|
|
14
25
|
const { callbacks = {}, logger, workdir, systemPrompt } = options;
|
|
15
|
-
|
|
26
|
+
// Resolve configuration from constructor args and environment variables
|
|
27
|
+
const gatewayConfig = configResolver.resolveGatewayConfig(options.apiKey, options.baseURL);
|
|
28
|
+
const modelConfig = configResolver.resolveModelConfig(options.agentModel, options.fastModel);
|
|
29
|
+
const tokenLimit = configResolver.resolveTokenLimit(options.tokenLimit);
|
|
30
|
+
// Validate resolved configuration
|
|
31
|
+
configValidator.validateGatewayConfig(gatewayConfig);
|
|
32
|
+
configValidator.validateTokenLimit(tokenLimit);
|
|
33
|
+
configValidator.validateModelConfig(modelConfig.agentModel, modelConfig.fastModel);
|
|
16
34
|
this.logger = logger; // Save the passed logger
|
|
17
35
|
this.workdir = workdir || process.cwd(); // Set working directory, default to current working directory
|
|
18
36
|
this.systemPrompt = systemPrompt; // Save custom system prompt
|
|
37
|
+
// Store resolved configuration
|
|
38
|
+
this.gatewayConfig = gatewayConfig;
|
|
39
|
+
this.modelConfig = modelConfig;
|
|
40
|
+
this.tokenLimit = tokenLimit;
|
|
19
41
|
this.backgroundBashManager = new BackgroundBashManager({
|
|
20
42
|
callbacks,
|
|
21
43
|
workdir: this.workdir,
|
|
22
44
|
});
|
|
23
45
|
this.mcpManager = new McpManager({ callbacks, logger: this.logger }); // Initialize MCP manager
|
|
24
|
-
this.toolManager = new ToolManager({
|
|
46
|
+
this.toolManager = new ToolManager({
|
|
47
|
+
mcpManager: this.mcpManager,
|
|
48
|
+
logger: this.logger,
|
|
49
|
+
}); // Initialize tool registry, pass MCP manager
|
|
25
50
|
this.hookManager = new HookManager(this.workdir, undefined, undefined, this.logger); // Initialize hooks manager
|
|
26
51
|
// Initialize MessageManager
|
|
27
52
|
this.messageManager = new MessageManager({
|
|
@@ -29,7 +54,18 @@ export class Agent {
|
|
|
29
54
|
workdir: this.workdir,
|
|
30
55
|
logger: this.logger,
|
|
31
56
|
});
|
|
32
|
-
// Initialize
|
|
57
|
+
// Initialize subagent manager with all dependencies in constructor
|
|
58
|
+
// IMPORTANT: Must be initialized AFTER MessageManager
|
|
59
|
+
this.subagentManager = new SubagentManager({
|
|
60
|
+
workdir: this.workdir,
|
|
61
|
+
parentToolManager: this.toolManager,
|
|
62
|
+
parentMessageManager: this.messageManager,
|
|
63
|
+
logger: this.logger,
|
|
64
|
+
gatewayConfig,
|
|
65
|
+
modelConfig,
|
|
66
|
+
tokenLimit,
|
|
67
|
+
});
|
|
68
|
+
// Initialize AI manager with resolved configuration
|
|
33
69
|
this.aiManager = new AIManager({
|
|
34
70
|
messageManager: this.messageManager,
|
|
35
71
|
toolManager: this.toolManager,
|
|
@@ -39,6 +75,9 @@ export class Agent {
|
|
|
39
75
|
callbacks,
|
|
40
76
|
workdir: this.workdir,
|
|
41
77
|
systemPrompt: this.systemPrompt,
|
|
78
|
+
gatewayConfig: this.gatewayConfig,
|
|
79
|
+
modelConfig: this.modelConfig,
|
|
80
|
+
tokenLimit: this.tokenLimit,
|
|
42
81
|
});
|
|
43
82
|
// Initialize command manager
|
|
44
83
|
this.slashCommandManager = new SlashCommandManager({
|
|
@@ -90,8 +129,17 @@ export class Agent {
|
|
|
90
129
|
killBackgroundShell(id) {
|
|
91
130
|
return this.backgroundBashManager.killShell(id);
|
|
92
131
|
}
|
|
93
|
-
/**
|
|
132
|
+
/**
|
|
133
|
+
* Static async factory method for creating Agent instances
|
|
134
|
+
*
|
|
135
|
+
* IMPORTANT: Keep this method's signature exactly the same as the constructor
|
|
136
|
+
* to maintain consistency and avoid confusion for users of the API.
|
|
137
|
+
*
|
|
138
|
+
* @param options - Same AgentOptions interface used by constructor
|
|
139
|
+
* @returns Promise<Agent> - Fully initialized Agent instance
|
|
140
|
+
*/
|
|
94
141
|
static async create(options) {
|
|
142
|
+
// Create Agent instance - configuration resolution and validation now happens in constructor
|
|
95
143
|
const instance = new Agent(options);
|
|
96
144
|
await instance.initialize({
|
|
97
145
|
restoreSessionId: options.restoreSessionId,
|
|
@@ -102,6 +150,23 @@ export class Agent {
|
|
|
102
150
|
}
|
|
103
151
|
/** Private initialization method, handles async initialization logic */
|
|
104
152
|
async initialize(options) {
|
|
153
|
+
// Initialize managers first
|
|
154
|
+
try {
|
|
155
|
+
// Initialize SkillManager
|
|
156
|
+
const skillManager = new SkillManager({ logger: this.logger });
|
|
157
|
+
await skillManager.initialize();
|
|
158
|
+
// Initialize SubagentManager (load and cache configurations)
|
|
159
|
+
await this.subagentManager.initialize();
|
|
160
|
+
// Initialize built-in tools with dependencies
|
|
161
|
+
this.toolManager.initializeBuiltInTools({
|
|
162
|
+
subagentManager: this.subagentManager,
|
|
163
|
+
skillManager: skillManager,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
this.logger?.error("Failed to initialize managers and tools:", error);
|
|
168
|
+
// Don't throw error to prevent app startup failure
|
|
169
|
+
}
|
|
105
170
|
// Initialize MCP servers with auto-connect
|
|
106
171
|
try {
|
|
107
172
|
await this.mcpManager.initialize(this.workdir, true);
|
|
@@ -149,6 +214,7 @@ export class Agent {
|
|
|
149
214
|
this.abortAIMessage();
|
|
150
215
|
this.abortBashCommand();
|
|
151
216
|
this.abortSlashCommand();
|
|
217
|
+
this.abortSubagents();
|
|
152
218
|
}
|
|
153
219
|
/** Add to input history */
|
|
154
220
|
addToInputHistory(input) {
|
|
@@ -162,16 +228,27 @@ export class Agent {
|
|
|
162
228
|
abortSlashCommand() {
|
|
163
229
|
this.slashCommandManager.abortCurrentCommand();
|
|
164
230
|
}
|
|
231
|
+
/** Interrupt all subagent execution */
|
|
232
|
+
abortSubagents() {
|
|
233
|
+
this.subagentManager.abortAllInstances();
|
|
234
|
+
}
|
|
235
|
+
/** Interrupt specific subagent execution */
|
|
236
|
+
abortSubagent(subagentId) {
|
|
237
|
+
return this.subagentManager.abortInstance(subagentId);
|
|
238
|
+
}
|
|
165
239
|
/** Destroy managers, clean up resources */
|
|
166
240
|
async destroy() {
|
|
167
241
|
this.messageManager.saveSession();
|
|
168
242
|
this.abortAIMessage();
|
|
169
243
|
this.abortBashCommand();
|
|
170
244
|
this.abortSlashCommand();
|
|
245
|
+
this.abortSubagents();
|
|
171
246
|
// Cleanup background bash manager
|
|
172
247
|
this.backgroundBashManager.cleanup();
|
|
173
248
|
// Cleanup MCP connections
|
|
174
249
|
await this.mcpManager.cleanup();
|
|
250
|
+
// Cleanup subagent manager
|
|
251
|
+
this.subagentManager.cleanup();
|
|
175
252
|
}
|
|
176
253
|
async sendMessage(content, images) {
|
|
177
254
|
try {
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,6 @@ export * from "./utils/mcpUtils.js";
|
|
|
9
9
|
export * from "./utils/messageOperations.js";
|
|
10
10
|
export * from "./utils/path.js";
|
|
11
11
|
export * from "./utils/stringUtils.js";
|
|
12
|
-
export * from "./utils/markdownParser.js";
|
|
13
12
|
export * from "./utils/customCommands.js";
|
|
14
13
|
export * from "./hooks/index.js";
|
|
15
14
|
export * from "./types.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,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AAGtC,cAAc,YAAY,CAAC;AAG3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AAGtC,cAAc,YAAY,CAAC;AAG3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAG1C,cAAc,kBAAkB,CAAC;AAGjC,cAAc,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -12,7 +12,6 @@ export * from "./utils/mcpUtils.js";
|
|
|
12
12
|
export * from "./utils/messageOperations.js";
|
|
13
13
|
export * from "./utils/path.js";
|
|
14
14
|
export * from "./utils/stringUtils.js";
|
|
15
|
-
export * from "./utils/markdownParser.js";
|
|
16
15
|
export * from "./utils/customCommands.js";
|
|
17
16
|
// Export hooks system
|
|
18
17
|
export * from "./hooks/index.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Logger } from "../types.js";
|
|
1
|
+
import type { Logger, GatewayConfig, ModelConfig } from "../types.js";
|
|
2
2
|
import type { ToolManager } from "./toolManager.js";
|
|
3
3
|
import type { MessageManager } from "./messageManager.js";
|
|
4
4
|
import type { BackgroundBashManager } from "./backgroundBashManager.js";
|
|
@@ -15,6 +15,9 @@ export interface AIManagerOptions {
|
|
|
15
15
|
callbacks?: AIManagerCallbacks;
|
|
16
16
|
workdir: string;
|
|
17
17
|
systemPrompt?: string;
|
|
18
|
+
gatewayConfig: GatewayConfig;
|
|
19
|
+
modelConfig: ModelConfig;
|
|
20
|
+
tokenLimit: number;
|
|
18
21
|
}
|
|
19
22
|
export declare class AIManager {
|
|
20
23
|
isLoading: boolean;
|
|
@@ -27,6 +30,9 @@ export declare class AIManager {
|
|
|
27
30
|
private hookManager?;
|
|
28
31
|
private workdir;
|
|
29
32
|
private systemPrompt?;
|
|
33
|
+
private gatewayConfig;
|
|
34
|
+
private modelConfig;
|
|
35
|
+
private tokenLimit;
|
|
30
36
|
constructor(options: AIManagerOptions);
|
|
31
37
|
private isCompressing;
|
|
32
38
|
private callbacks;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiManager.d.ts","sourceRoot":"","sources":["../../src/managers/aiManager.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"aiManager.d.ts","sourceRoot":"","sources":["../../src/managers/aiManager.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAExE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,MAAM,WAAW,kBAAkB;IACjC,wBAAwB,CAAC,EAAE,CAAC,aAAa,EAAE,OAAO,KAAK,IAAI,CAAC;CAC7D;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE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AAM,CAAC;QACf,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;KACpB,GACL,OAAO,CAAC,IAAI,CAAC;IA+PhB;;OAEG;YACW,gBAAgB;IAmC9B;;OAEG;YACW,sBAAsB;IA0CpC;;OAEG;YACW,uBAAuB;CA2CtC"}
|
|
@@ -2,7 +2,6 @@ import { callAgent, compressMessages } from "../services/aiService.js";
|
|
|
2
2
|
import { getMessagesToCompress } from "../utils/messageOperations.js";
|
|
3
3
|
import { convertMessagesForAPI } from "../utils/convertMessagesForAPI.js";
|
|
4
4
|
import * as memory from "../services/memory.js";
|
|
5
|
-
import { DEFAULT_TOKEN_LIMIT } from "../utils/constants.js";
|
|
6
5
|
export class AIManager {
|
|
7
6
|
constructor(options) {
|
|
8
7
|
this.isLoading = false;
|
|
@@ -17,6 +16,10 @@ export class AIManager {
|
|
|
17
16
|
this.workdir = options.workdir;
|
|
18
17
|
this.systemPrompt = options.systemPrompt;
|
|
19
18
|
this.callbacks = options.callbacks ?? {};
|
|
19
|
+
// Store resolved configuration
|
|
20
|
+
this.gatewayConfig = options.gatewayConfig;
|
|
21
|
+
this.modelConfig = options.modelConfig;
|
|
22
|
+
this.tokenLimit = options.tokenLimit;
|
|
20
23
|
}
|
|
21
24
|
/**
|
|
22
25
|
* Get filtered tool configuration
|
|
@@ -78,10 +81,9 @@ export class AIManager {
|
|
|
78
81
|
return;
|
|
79
82
|
// Update token statistics - display latest token usage
|
|
80
83
|
this.messageManager.setlatestTotalTokens(usage.total_tokens);
|
|
81
|
-
// Check if token limit exceeded
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
this.logger?.info(`Token usage exceeded ${tokenLimit}, compressing messages...`);
|
|
84
|
+
// Check if token limit exceeded - use injected configuration
|
|
85
|
+
if (usage.total_tokens > this.tokenLimit) {
|
|
86
|
+
this.logger?.info(`Token usage exceeded ${this.tokenLimit}, compressing messages...`);
|
|
85
87
|
// Check if messages need compression
|
|
86
88
|
const { messagesToCompress, insertIndex } = getMessagesToCompress(this.messageManager.getMessages(), 7);
|
|
87
89
|
// If there are messages to compress, perform compression
|
|
@@ -90,6 +92,8 @@ export class AIManager {
|
|
|
90
92
|
this.setIsCompressing(true);
|
|
91
93
|
try {
|
|
92
94
|
const compressedContent = await compressMessages({
|
|
95
|
+
gatewayConfig: this.gatewayConfig,
|
|
96
|
+
modelConfig: this.modelConfig,
|
|
93
97
|
messages: recentChatMessages,
|
|
94
98
|
abortSignal: abortController.signal,
|
|
95
99
|
});
|
|
@@ -138,6 +142,8 @@ export class AIManager {
|
|
|
138
142
|
const combinedMemory = await memory.getCombinedMemoryContent(this.workdir);
|
|
139
143
|
// Call AI service (non-streaming)
|
|
140
144
|
const result = await callAgent({
|
|
145
|
+
gatewayConfig: this.gatewayConfig,
|
|
146
|
+
modelConfig: this.modelConfig,
|
|
141
147
|
messages: recentMessages,
|
|
142
148
|
sessionId: this.messageManager.getSessionId(),
|
|
143
149
|
abortSignal: abortController.signal,
|
|
@@ -17,9 +17,12 @@ export interface MessageManagerCallbacks {
|
|
|
17
17
|
onCompressBlockAdded?: (insertIndex: number, content: string) => void;
|
|
18
18
|
onCompressionStateChange?: (isCompressing: boolean) => void;
|
|
19
19
|
onMemoryBlockAdded?: (content: string, success: boolean, type: "project" | "user", storagePath: string) => void;
|
|
20
|
+
onCustomCommandAdded?: (commandName: string, content: string, originalInput?: string) => void;
|
|
20
21
|
onAddCommandOutputMessage?: (command: string) => void;
|
|
21
22
|
onUpdateCommandOutputMessage?: (command: string, output: string) => void;
|
|
22
23
|
onCompleteCommandMessage?: (command: string, exitCode: number) => void;
|
|
24
|
+
onSubAgentBlockAdded?: (subagentId: string) => void;
|
|
25
|
+
onSubAgentBlockUpdated?: (subagentId: string, messages: Message[]) => void;
|
|
23
26
|
}
|
|
24
27
|
export interface MessageManagerOptions {
|
|
25
28
|
callbacks: MessageManagerCallbacks;
|
|
@@ -81,5 +84,10 @@ export declare class MessageManager {
|
|
|
81
84
|
addCommandOutputMessage(command: string): void;
|
|
82
85
|
updateCommandOutputMessage(command: string, output: string): void;
|
|
83
86
|
completeCommandMessage(command: string, exitCode: number): void;
|
|
87
|
+
addSubagentBlock(subagentId: string, subagentName: string, status?: "active" | "completed" | "error", subagentMessages?: Message[]): void;
|
|
88
|
+
updateSubagentBlock(subagentId: string, updates: Partial<{
|
|
89
|
+
status: "active" | "completed" | "error" | "aborted";
|
|
90
|
+
messages: Message[];
|
|
91
|
+
}>): void;
|
|
84
92
|
}
|
|
85
93
|
//# sourceMappingURL=messageManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageManager.d.ts","sourceRoot":"","sources":["../../src/managers/messageManager.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"messageManager.d.ts","sourceRoot":"","sources":["../../src/managers/messageManager.ts"],"names":[],"mappings":"AACA,OAAO,EAeL,KAAK,0BAA0B,EAChC,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AASnD,OAAO,EAAE,qCAAqC,EAAE,MAAM,qBAAqB,CAAC;AAE5E,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,wBAAwB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAEvD,kBAAkB,CAAC,EAAE,CACnB,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,KAC/C,IAAI,CAAC;IACV,uBAAuB,CAAC,EAAE,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QACf,MAAM,EAAE,QAAQ,GAAG,WAAW,GAAG,OAAO,GAAG,SAAS,CAAC;QACrD,QAAQ,EAAE,OAAO,EAAE,CAAC;KACrB,CAAC,GACD,IAAI;CAeR"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from "crypto";
|
|
2
|
-
import { addAssistantMessageToMessages, updateToolBlockInMessage, addErrorBlockToMessage, addDiffBlockToMessage, addUserMessageToMessages, extractUserInputHistory, addMemoryBlockToMessage, addCommandOutputMessage, updateCommandOutputInMessage, completeCommandInMessage, } from "../utils/messageOperations.js";
|
|
2
|
+
import { addAssistantMessageToMessages, updateToolBlockInMessage, addErrorBlockToMessage, addDiffBlockToMessage, addUserMessageToMessages, extractUserInputHistory, addMemoryBlockToMessage, addCommandOutputMessage, updateCommandOutputInMessage, completeCommandInMessage, addSubagentBlockToMessage, updateSubagentBlockInMessage, } from "../utils/messageOperations.js";
|
|
3
3
|
import { cleanupExpiredSessions, getLatestSession, loadSession, saveSession, getSessionFilePath, } from "../services/session.js";
|
|
4
4
|
export class MessageManager {
|
|
5
5
|
constructor(options) {
|
|
@@ -155,7 +155,7 @@ export class MessageManager {
|
|
|
155
155
|
},
|
|
156
156
|
});
|
|
157
157
|
this.setMessages(newMessages);
|
|
158
|
-
this.callbacks.
|
|
158
|
+
this.callbacks.onCustomCommandAdded?.(commandName, content, originalInput);
|
|
159
159
|
}
|
|
160
160
|
addAssistantMessage(content, toolCalls) {
|
|
161
161
|
const newMessages = addAssistantMessageToMessages(this.messages, content, toolCalls);
|
|
@@ -262,4 +262,28 @@ export class MessageManager {
|
|
|
262
262
|
this.setMessages(updatedMessages);
|
|
263
263
|
this.callbacks.onCompleteCommandMessage?.(command, exitCode);
|
|
264
264
|
}
|
|
265
|
+
// Subagent block methods
|
|
266
|
+
addSubagentBlock(subagentId, subagentName, status = "active", subagentMessages = []) {
|
|
267
|
+
const params = {
|
|
268
|
+
messages: this.messages,
|
|
269
|
+
subagentId,
|
|
270
|
+
subagentName,
|
|
271
|
+
status,
|
|
272
|
+
subagentMessages,
|
|
273
|
+
};
|
|
274
|
+
const updatedMessages = addSubagentBlockToMessage(params);
|
|
275
|
+
this.setMessages(updatedMessages);
|
|
276
|
+
this.callbacks.onSubAgentBlockAdded?.(params.subagentId);
|
|
277
|
+
}
|
|
278
|
+
updateSubagentBlock(subagentId, updates) {
|
|
279
|
+
const updatedMessages = updateSubagentBlockInMessage(this.messages, subagentId, updates);
|
|
280
|
+
this.setMessages(updatedMessages);
|
|
281
|
+
const params = {
|
|
282
|
+
messages: this.messages,
|
|
283
|
+
subagentId,
|
|
284
|
+
status: updates.status || "active",
|
|
285
|
+
subagentMessages: updates.messages || [],
|
|
286
|
+
};
|
|
287
|
+
this.callbacks.onSubAgentBlockUpdated?.(params.subagentId, params.messages);
|
|
288
|
+
}
|
|
265
289
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { SkillManagerOptions, SkillMetadata, Skill, SkillToolArgs, SkillInvocationContext } from "../types.js";
|
|
2
|
-
import type { ToolPlugin } from "../tools/types.js";
|
|
3
2
|
/**
|
|
4
3
|
* Manages skill discovery and loading
|
|
5
4
|
*/
|
|
@@ -15,6 +14,10 @@ export declare class SkillManager {
|
|
|
15
14
|
* Initialize the skill manager by discovering available skills
|
|
16
15
|
*/
|
|
17
16
|
initialize(): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Check if the skill manager is initialized
|
|
19
|
+
*/
|
|
20
|
+
isInitialized(): boolean;
|
|
18
21
|
/**
|
|
19
22
|
* Get all available skills metadata
|
|
20
23
|
*/
|
|
@@ -36,10 +39,6 @@ export declare class SkillManager {
|
|
|
36
39
|
* Find all directories that could contain skills
|
|
37
40
|
*/
|
|
38
41
|
private findSkillDirectories;
|
|
39
|
-
/**
|
|
40
|
-
* Create a tool plugin for registering with ToolManager
|
|
41
|
-
*/
|
|
42
|
-
createTool(): ToolPlugin;
|
|
43
42
|
/**
|
|
44
43
|
* Execute a skill by name
|
|
45
44
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skillManager.d.ts","sourceRoot":"","sources":["../../src/managers/skillManager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,mBAAmB,EACnB,aAAa,EACb,KAAK,EAGL,aAAa,EACb,sBAAsB,EAEvB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"skillManager.d.ts","sourceRoot":"","sources":["../../src/managers/skillManager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,mBAAmB,EACnB,aAAa,EACb,KAAK,EAGL,aAAa,EACb,sBAAsB,EAEvB,MAAM,aAAa,CAAC;AAGrB;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,MAAM,CAAC,CAAS;IAExB,OAAO,CAAC,aAAa,CAAoC;IACzD,OAAO,CAAC,YAAY,CAA4B;IAChD,OAAO,CAAC,WAAW,CAAS;gBAEhB,OAAO,GAAE,mBAAwB;IAO7C;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAwCjC;;OAEG;IACH,aAAa,IAAI,OAAO;IAIxB;;OAEG;IACH,kBAAkB,IAAI,aAAa,EAAE;IAQrC;;;OAGG;IACG,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;IAgBzD;;OAEG;YACW,cAAc;IAkB5B;;OAEG;YACW,uBAAuB;IAiFrC;;OAEG;YACW,oBAAoB;IAkBlC;;OAEG;IACG,YAAY,CAChB,IAAI,EAAE,aAAa,GAClB,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,sBAAsB,CAAA;KAAE,CAAC;IAqCjE;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAY1B;;OAEG;IACH,OAAO,CAAC,qBAAqB;CAa9B"}
|
|
@@ -47,6 +47,12 @@ export class SkillManager {
|
|
|
47
47
|
throw error;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Check if the skill manager is initialized
|
|
52
|
+
*/
|
|
53
|
+
isInitialized() {
|
|
54
|
+
return this.initialized;
|
|
55
|
+
}
|
|
50
56
|
/**
|
|
51
57
|
* Get all available skills metadata
|
|
52
58
|
*/
|
|
@@ -173,88 +179,6 @@ export class SkillManager {
|
|
|
173
179
|
}
|
|
174
180
|
return directories;
|
|
175
181
|
}
|
|
176
|
-
/**
|
|
177
|
-
* Create a tool plugin for registering with ToolManager
|
|
178
|
-
*/
|
|
179
|
-
createTool() {
|
|
180
|
-
// Initialize skill manager asynchronously
|
|
181
|
-
let initializationPromise = null;
|
|
182
|
-
const ensureInitialized = async () => {
|
|
183
|
-
if (!initializationPromise) {
|
|
184
|
-
initializationPromise = this.initialize();
|
|
185
|
-
}
|
|
186
|
-
await initializationPromise;
|
|
187
|
-
};
|
|
188
|
-
const getToolDescription = () => {
|
|
189
|
-
if (!this.initialized) {
|
|
190
|
-
return "Invoke a Wave skill by name. Skills are user-defined automation templates that can be personal or project-specific. Skills will be loaded during initialization.";
|
|
191
|
-
}
|
|
192
|
-
const availableSkills = this.getAvailableSkills();
|
|
193
|
-
if (availableSkills.length === 0) {
|
|
194
|
-
return "Invoke a Wave skill by name. Skills are user-defined automation templates that can be personal or project-specific. No skills are currently available.";
|
|
195
|
-
}
|
|
196
|
-
const skillList = availableSkills
|
|
197
|
-
.map((skill) => `• **${skill.name}** (${skill.type}): ${skill.description}`)
|
|
198
|
-
.join("\n");
|
|
199
|
-
return `Invoke a Wave skill by name. Skills are user-defined automation templates that can be personal or project-specific.\n\nAvailable skills:\n${skillList}`;
|
|
200
|
-
};
|
|
201
|
-
return {
|
|
202
|
-
name: "skill",
|
|
203
|
-
config: {
|
|
204
|
-
type: "function",
|
|
205
|
-
function: {
|
|
206
|
-
name: "skill",
|
|
207
|
-
description: getToolDescription(),
|
|
208
|
-
parameters: {
|
|
209
|
-
type: "object",
|
|
210
|
-
properties: {
|
|
211
|
-
skill_name: {
|
|
212
|
-
type: "string",
|
|
213
|
-
description: "Name of the skill to invoke",
|
|
214
|
-
enum: this.initialized
|
|
215
|
-
? this.getAvailableSkills().map((skill) => skill.name)
|
|
216
|
-
: [],
|
|
217
|
-
},
|
|
218
|
-
},
|
|
219
|
-
required: ["skill_name"],
|
|
220
|
-
},
|
|
221
|
-
},
|
|
222
|
-
},
|
|
223
|
-
execute: async (args) => {
|
|
224
|
-
try {
|
|
225
|
-
// Ensure skill manager is initialized
|
|
226
|
-
await ensureInitialized();
|
|
227
|
-
// Validate arguments
|
|
228
|
-
const skillName = args.skill_name;
|
|
229
|
-
if (!skillName || typeof skillName !== "string") {
|
|
230
|
-
return {
|
|
231
|
-
success: false,
|
|
232
|
-
content: "",
|
|
233
|
-
error: "skill_name parameter is required and must be a string",
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
// Execute the skill
|
|
237
|
-
const result = await this.executeSkill({ skill_name: skillName });
|
|
238
|
-
return {
|
|
239
|
-
success: true,
|
|
240
|
-
content: result.content,
|
|
241
|
-
shortResult: `Invoked skill: ${skillName}`,
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
catch (error) {
|
|
245
|
-
return {
|
|
246
|
-
success: false,
|
|
247
|
-
content: "",
|
|
248
|
-
error: error instanceof Error ? error.message : String(error),
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
},
|
|
252
|
-
formatCompactParams: (params) => {
|
|
253
|
-
const skillName = params.skill_name;
|
|
254
|
-
return skillName || "unknown-skill";
|
|
255
|
-
},
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
182
|
/**
|
|
259
183
|
* Execute a skill by name
|
|
260
184
|
*/
|