wave-agent-sdk 0.0.1
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/README.md +32 -0
- package/dist/agent.d.ts +96 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +286 -0
- package/dist/hooks/executor.d.ts +56 -0
- package/dist/hooks/executor.d.ts.map +1 -0
- package/dist/hooks/executor.js +312 -0
- package/dist/hooks/index.d.ts +17 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +14 -0
- package/dist/hooks/manager.d.ts +90 -0
- package/dist/hooks/manager.d.ts.map +1 -0
- package/dist/hooks/manager.js +395 -0
- package/dist/hooks/matcher.d.ts +49 -0
- package/dist/hooks/matcher.d.ts.map +1 -0
- package/dist/hooks/matcher.js +147 -0
- package/dist/hooks/settings.d.ts +46 -0
- package/dist/hooks/settings.d.ts.map +1 -0
- package/dist/hooks/settings.js +100 -0
- package/dist/hooks/types.d.ts +80 -0
- package/dist/hooks/types.d.ts.map +1 -0
- package/dist/hooks/types.js +59 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/managers/aiManager.d.ts +61 -0
- package/dist/managers/aiManager.d.ts.map +1 -0
- package/dist/managers/aiManager.js +415 -0
- package/dist/managers/backgroundBashManager.d.ts +27 -0
- package/dist/managers/backgroundBashManager.d.ts.map +1 -0
- package/dist/managers/backgroundBashManager.js +166 -0
- package/dist/managers/bashManager.d.ts +20 -0
- package/dist/managers/bashManager.d.ts.map +1 -0
- package/dist/managers/bashManager.js +66 -0
- package/dist/managers/mcpManager.d.ts +63 -0
- package/dist/managers/mcpManager.d.ts.map +1 -0
- package/dist/managers/mcpManager.js +378 -0
- package/dist/managers/messageManager.d.ts +85 -0
- package/dist/managers/messageManager.d.ts.map +1 -0
- package/dist/managers/messageManager.js +265 -0
- package/dist/managers/skillManager.d.ts +59 -0
- package/dist/managers/skillManager.d.ts.map +1 -0
- package/dist/managers/skillManager.js +317 -0
- package/dist/managers/slashCommandManager.d.ts +77 -0
- package/dist/managers/slashCommandManager.d.ts.map +1 -0
- package/dist/managers/slashCommandManager.js +208 -0
- package/dist/managers/toolManager.d.ts +23 -0
- package/dist/managers/toolManager.d.ts.map +1 -0
- package/dist/managers/toolManager.js +79 -0
- package/dist/services/aiService.d.ts +28 -0
- package/dist/services/aiService.d.ts.map +1 -0
- package/dist/services/aiService.js +180 -0
- package/dist/services/memory.d.ts +8 -0
- package/dist/services/memory.d.ts.map +1 -0
- package/dist/services/memory.js +128 -0
- package/dist/services/session.d.ts +54 -0
- package/dist/services/session.d.ts.map +1 -0
- package/dist/services/session.js +196 -0
- package/dist/tools/bashTool.d.ts +14 -0
- package/dist/tools/bashTool.d.ts.map +1 -0
- package/dist/tools/bashTool.js +351 -0
- package/dist/tools/deleteFileTool.d.ts +6 -0
- package/dist/tools/deleteFileTool.d.ts.map +1 -0
- package/dist/tools/deleteFileTool.js +67 -0
- package/dist/tools/editTool.d.ts +6 -0
- package/dist/tools/editTool.d.ts.map +1 -0
- package/dist/tools/editTool.js +168 -0
- package/dist/tools/globTool.d.ts +6 -0
- package/dist/tools/globTool.d.ts.map +1 -0
- package/dist/tools/globTool.js +113 -0
- package/dist/tools/grepTool.d.ts +6 -0
- package/dist/tools/grepTool.d.ts.map +1 -0
- package/dist/tools/grepTool.js +268 -0
- package/dist/tools/lsTool.d.ts +6 -0
- package/dist/tools/lsTool.d.ts.map +1 -0
- package/dist/tools/lsTool.js +160 -0
- package/dist/tools/multiEditTool.d.ts +6 -0
- package/dist/tools/multiEditTool.d.ts.map +1 -0
- package/dist/tools/multiEditTool.js +222 -0
- package/dist/tools/readTool.d.ts +6 -0
- package/dist/tools/readTool.d.ts.map +1 -0
- package/dist/tools/readTool.js +136 -0
- package/dist/tools/types.d.ts +35 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +4 -0
- package/dist/tools/writeTool.d.ts +6 -0
- package/dist/tools/writeTool.d.ts.map +1 -0
- package/dist/tools/writeTool.js +138 -0
- package/dist/types.d.ts +212 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +13 -0
- package/dist/utils/bashHistory.d.ts +46 -0
- package/dist/utils/bashHistory.d.ts.map +1 -0
- package/dist/utils/bashHistory.js +236 -0
- package/dist/utils/commandArgumentParser.d.ts +34 -0
- package/dist/utils/commandArgumentParser.d.ts.map +1 -0
- package/dist/utils/commandArgumentParser.js +123 -0
- package/dist/utils/constants.d.ts +27 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +28 -0
- package/dist/utils/convertMessagesForAPI.d.ts +9 -0
- package/dist/utils/convertMessagesForAPI.d.ts.map +1 -0
- package/dist/utils/convertMessagesForAPI.js +189 -0
- package/dist/utils/customCommands.d.ts +14 -0
- package/dist/utils/customCommands.d.ts.map +1 -0
- package/dist/utils/customCommands.js +71 -0
- package/dist/utils/fileFilter.d.ts +26 -0
- package/dist/utils/fileFilter.d.ts.map +1 -0
- package/dist/utils/fileFilter.js +177 -0
- package/dist/utils/markdownParser.d.ts +27 -0
- package/dist/utils/markdownParser.d.ts.map +1 -0
- package/dist/utils/markdownParser.js +109 -0
- package/dist/utils/mcpUtils.d.ts +24 -0
- package/dist/utils/mcpUtils.d.ts.map +1 -0
- package/dist/utils/mcpUtils.js +51 -0
- package/dist/utils/messageOperations.d.ts +118 -0
- package/dist/utils/messageOperations.d.ts.map +1 -0
- package/dist/utils/messageOperations.js +334 -0
- package/dist/utils/path.d.ts +25 -0
- package/dist/utils/path.d.ts.map +1 -0
- package/dist/utils/path.js +109 -0
- package/dist/utils/skillParser.d.ts +18 -0
- package/dist/utils/skillParser.d.ts.map +1 -0
- package/dist/utils/skillParser.js +147 -0
- package/dist/utils/stringUtils.d.ts +13 -0
- package/dist/utils/stringUtils.d.ts.map +1 -0
- package/dist/utils/stringUtils.js +44 -0
- package/package.json +51 -0
- package/src/agent.ts +405 -0
- package/src/hooks/executor.ts +440 -0
- package/src/hooks/index.ts +52 -0
- package/src/hooks/manager.ts +618 -0
- package/src/hooks/matcher.ts +187 -0
- package/src/hooks/settings.ts +129 -0
- package/src/hooks/types.ts +169 -0
- package/src/index.ts +24 -0
- package/src/managers/aiManager.ts +573 -0
- package/src/managers/backgroundBashManager.ts +203 -0
- package/src/managers/bashManager.ts +97 -0
- package/src/managers/mcpManager.ts +493 -0
- package/src/managers/messageManager.ts +415 -0
- package/src/managers/skillManager.ts +404 -0
- package/src/managers/slashCommandManager.ts +293 -0
- package/src/managers/toolManager.ts +106 -0
- package/src/services/aiService.ts +252 -0
- package/src/services/memory.ts +149 -0
- package/src/services/session.ts +265 -0
- package/src/tools/bashTool.ts +402 -0
- package/src/tools/deleteFileTool.ts +81 -0
- package/src/tools/editTool.ts +192 -0
- package/src/tools/globTool.ts +135 -0
- package/src/tools/grepTool.ts +326 -0
- package/src/tools/lsTool.ts +187 -0
- package/src/tools/multiEditTool.ts +268 -0
- package/src/tools/readTool.ts +165 -0
- package/src/tools/types.ts +47 -0
- package/src/tools/writeTool.ts +163 -0
- package/src/types.ts +260 -0
- package/src/utils/bashHistory.ts +303 -0
- package/src/utils/commandArgumentParser.ts +153 -0
- package/src/utils/constants.ts +37 -0
- package/src/utils/convertMessagesForAPI.ts +236 -0
- package/src/utils/customCommands.ts +85 -0
- package/src/utils/fileFilter.ts +202 -0
- package/src/utils/markdownParser.ts +156 -0
- package/src/utils/mcpUtils.ts +81 -0
- package/src/utils/messageOperations.ts +506 -0
- package/src/utils/path.ts +118 -0
- package/src/utils/skillParser.ts +188 -0
- package/src/utils/stringUtils.ts +50 -0
package/src/agent.ts
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MessageManager,
|
|
3
|
+
type MessageManagerCallbacks,
|
|
4
|
+
} from "./managers/messageManager.js";
|
|
5
|
+
import { AIManager } from "./managers/aiManager.js";
|
|
6
|
+
import { ToolManager } from "./managers/toolManager.js";
|
|
7
|
+
import * as memory from "./services/memory.js";
|
|
8
|
+
import { McpManager, type McpManagerCallbacks } from "./managers/mcpManager.js";
|
|
9
|
+
import { BashManager } from "./managers/bashManager.js";
|
|
10
|
+
import {
|
|
11
|
+
BackgroundBashManager,
|
|
12
|
+
type BackgroundBashManagerCallbacks,
|
|
13
|
+
} from "./managers/backgroundBashManager.js";
|
|
14
|
+
import { SlashCommandManager } from "./managers/slashCommandManager.js";
|
|
15
|
+
import type { SlashCommand, CustomSlashCommand } from "./types.js";
|
|
16
|
+
import type { Message, Logger, McpServerStatus } from "./types.js";
|
|
17
|
+
import { HookManager } from "./hooks/index.js";
|
|
18
|
+
|
|
19
|
+
export interface AgentOptions {
|
|
20
|
+
callbacks?: AgentCallbacks;
|
|
21
|
+
restoreSessionId?: string;
|
|
22
|
+
continueLastSession?: boolean;
|
|
23
|
+
logger?: Logger;
|
|
24
|
+
/**Add optional initial messages parameter for testing convenience */
|
|
25
|
+
messages?: Message[];
|
|
26
|
+
/**Working directory - if not specified, use process.cwd() */
|
|
27
|
+
workdir?: string;
|
|
28
|
+
/**Optional custom system prompt - if provided, replaces default system prompt */
|
|
29
|
+
systemPrompt?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface AgentCallbacks
|
|
33
|
+
extends MessageManagerCallbacks,
|
|
34
|
+
BackgroundBashManagerCallbacks,
|
|
35
|
+
McpManagerCallbacks {}
|
|
36
|
+
|
|
37
|
+
export class Agent {
|
|
38
|
+
private messageManager: MessageManager;
|
|
39
|
+
private aiManager: AIManager;
|
|
40
|
+
private callbacks: AgentCallbacks;
|
|
41
|
+
|
|
42
|
+
private bashManager: BashManager | null = null;
|
|
43
|
+
private backgroundBashManager: BackgroundBashManager;
|
|
44
|
+
private logger?: Logger; // Add optional logger property
|
|
45
|
+
private toolManager: ToolManager; // Add tool registry instance
|
|
46
|
+
private mcpManager: McpManager; // Add MCP manager instance
|
|
47
|
+
private slashCommandManager: SlashCommandManager; // Add slash command manager instance
|
|
48
|
+
private hookManager: HookManager; // Add hooks manager instance
|
|
49
|
+
private workdir: string; // Working directory
|
|
50
|
+
private systemPrompt?: string; // Custom system prompt
|
|
51
|
+
|
|
52
|
+
// Private constructor to prevent direct instantiation
|
|
53
|
+
private constructor(options: AgentOptions) {
|
|
54
|
+
const { callbacks = {}, logger, workdir, systemPrompt } = options;
|
|
55
|
+
|
|
56
|
+
this.callbacks = callbacks;
|
|
57
|
+
this.logger = logger; // Save the passed logger
|
|
58
|
+
this.workdir = workdir || process.cwd(); // Set working directory, default to current working directory
|
|
59
|
+
this.systemPrompt = systemPrompt; // Save custom system prompt
|
|
60
|
+
this.backgroundBashManager = new BackgroundBashManager({
|
|
61
|
+
callbacks,
|
|
62
|
+
workdir: this.workdir,
|
|
63
|
+
});
|
|
64
|
+
this.mcpManager = new McpManager({ callbacks, logger: this.logger }); // Initialize MCP manager
|
|
65
|
+
this.toolManager = new ToolManager({ mcpManager: this.mcpManager }); // Initialize tool registry, pass MCP manager
|
|
66
|
+
this.hookManager = new HookManager(
|
|
67
|
+
this.workdir,
|
|
68
|
+
undefined,
|
|
69
|
+
undefined,
|
|
70
|
+
this.logger,
|
|
71
|
+
); // Initialize hooks manager
|
|
72
|
+
|
|
73
|
+
// Initialize MessageManager
|
|
74
|
+
this.messageManager = new MessageManager({
|
|
75
|
+
callbacks,
|
|
76
|
+
workdir: this.workdir,
|
|
77
|
+
logger: this.logger,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Initialize AI manager
|
|
81
|
+
this.aiManager = new AIManager({
|
|
82
|
+
messageManager: this.messageManager,
|
|
83
|
+
toolManager: this.toolManager,
|
|
84
|
+
logger: this.logger,
|
|
85
|
+
backgroundBashManager: this.backgroundBashManager,
|
|
86
|
+
hookManager: this.hookManager,
|
|
87
|
+
callbacks,
|
|
88
|
+
workdir: this.workdir,
|
|
89
|
+
systemPrompt: this.systemPrompt,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Initialize command manager
|
|
93
|
+
this.slashCommandManager = new SlashCommandManager({
|
|
94
|
+
messageManager: this.messageManager,
|
|
95
|
+
aiManager: this.aiManager,
|
|
96
|
+
workdir: this.workdir,
|
|
97
|
+
logger: this.logger,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Initialize bash manager
|
|
101
|
+
this.bashManager = new BashManager({
|
|
102
|
+
messageManager: this.messageManager,
|
|
103
|
+
workdir: this.workdir,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Public getter methods
|
|
108
|
+
public get sessionId(): string {
|
|
109
|
+
return this.messageManager.getSessionId();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public get messages(): Message[] {
|
|
113
|
+
return this.messageManager.getMessages();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public get latestTotalTokens(): number {
|
|
117
|
+
return this.messageManager.getlatestTotalTokens();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public get userInputHistory(): string[] {
|
|
121
|
+
return this.messageManager.getUserInputHistory();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Get working directory */
|
|
125
|
+
public get workingDirectory(): string {
|
|
126
|
+
return this.workdir;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Get AI loading status */
|
|
130
|
+
public get isLoading(): boolean {
|
|
131
|
+
return this.aiManager.isLoading;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Get message compression status */
|
|
135
|
+
public get isCompressing(): boolean {
|
|
136
|
+
return this.aiManager.getIsCompressing();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Get bash command execution status */
|
|
140
|
+
public get isCommandRunning(): boolean {
|
|
141
|
+
return this.bashManager?.isCommandRunning ?? false;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Get background bash shell output */
|
|
145
|
+
public getBackgroundShellOutput(
|
|
146
|
+
id: string,
|
|
147
|
+
filter?: string,
|
|
148
|
+
): { stdout: string; stderr: string; status: string } | null {
|
|
149
|
+
return this.backgroundBashManager.getOutput(id, filter);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Kill background bash shell */
|
|
153
|
+
public killBackgroundShell(id: string): boolean {
|
|
154
|
+
return this.backgroundBashManager.killShell(id);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Static async factory method */
|
|
158
|
+
static async create(options: AgentOptions): Promise<Agent> {
|
|
159
|
+
const instance = new Agent(options);
|
|
160
|
+
await instance.initialize({
|
|
161
|
+
restoreSessionId: options.restoreSessionId,
|
|
162
|
+
continueLastSession: options.continueLastSession,
|
|
163
|
+
messages: options.messages,
|
|
164
|
+
});
|
|
165
|
+
return instance;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Private initialization method, handles async initialization logic */
|
|
169
|
+
private async initialize(options?: {
|
|
170
|
+
restoreSessionId?: string;
|
|
171
|
+
continueLastSession?: boolean;
|
|
172
|
+
messages?: Message[];
|
|
173
|
+
}): Promise<void> {
|
|
174
|
+
// Initialize MCP servers with auto-connect
|
|
175
|
+
try {
|
|
176
|
+
await this.mcpManager.initialize(this.workdir, true);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
this.logger?.error("Failed to initialize MCP servers:", error);
|
|
179
|
+
// Don't throw error to prevent app startup failure
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Initialize hooks configuration
|
|
183
|
+
try {
|
|
184
|
+
// Load hooks configuration from user and project settings
|
|
185
|
+
this.logger?.info("Loading hooks configuration...");
|
|
186
|
+
this.hookManager.loadConfigurationFromSettings();
|
|
187
|
+
this.logger?.debug("Hooks system initialized successfully");
|
|
188
|
+
} catch (error) {
|
|
189
|
+
this.logger?.error("Failed to initialize hooks system:", error);
|
|
190
|
+
// Don't throw error to prevent app startup failure
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Handle session restoration or set provided messages
|
|
194
|
+
if (options?.messages) {
|
|
195
|
+
// If messages are provided, use them directly (useful for testing)
|
|
196
|
+
this.messageManager.setMessages(options.messages);
|
|
197
|
+
} else {
|
|
198
|
+
// Otherwise, handle session restoration
|
|
199
|
+
await this.messageManager.handleSessionRestoration(
|
|
200
|
+
options?.restoreSessionId,
|
|
201
|
+
options?.continueLastSession,
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
public abortAIMessage(): void {
|
|
207
|
+
this.aiManager.abortAIMessage();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** Execute bash command */
|
|
211
|
+
public async executeBashCommand(command: string): Promise<void> {
|
|
212
|
+
// Add user message to history (but not displayed in UI)
|
|
213
|
+
this.addToInputHistory(`!${command}`);
|
|
214
|
+
await this.bashManager?.executeCommand(command);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Clear messages and input history */
|
|
218
|
+
public clearMessages(): void {
|
|
219
|
+
this.messageManager.clearMessages();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** Unified interrupt method, interrupts both AI messages and command execution */
|
|
223
|
+
public abortMessage(): void {
|
|
224
|
+
this.abortAIMessage();
|
|
225
|
+
this.abortBashCommand();
|
|
226
|
+
this.abortSlashCommand();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Add to input history */
|
|
230
|
+
private addToInputHistory(input: string): void {
|
|
231
|
+
this.messageManager.addToInputHistory(input);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** Interrupt bash command execution */
|
|
235
|
+
public abortBashCommand(): void {
|
|
236
|
+
this.bashManager?.abortCommand();
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Interrupt slash command execution */
|
|
240
|
+
public abortSlashCommand(): void {
|
|
241
|
+
this.slashCommandManager.abortCurrentCommand();
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Destroy managers, clean up resources */
|
|
245
|
+
public async destroy(): Promise<void> {
|
|
246
|
+
this.messageManager.saveSession();
|
|
247
|
+
this.abortAIMessage();
|
|
248
|
+
this.abortBashCommand();
|
|
249
|
+
this.abortSlashCommand();
|
|
250
|
+
// Cleanup background bash manager
|
|
251
|
+
this.backgroundBashManager.cleanup();
|
|
252
|
+
// Cleanup MCP connections
|
|
253
|
+
await this.mcpManager.cleanup();
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
public async sendMessage(
|
|
257
|
+
content: string,
|
|
258
|
+
images?: Array<{ path: string; mimeType: string }>,
|
|
259
|
+
): Promise<void> {
|
|
260
|
+
try {
|
|
261
|
+
// Handle slash command - check if it's a slash command (starts with /)
|
|
262
|
+
if (content.startsWith("/")) {
|
|
263
|
+
const command = content.trim();
|
|
264
|
+
if (!command || command === "/") return;
|
|
265
|
+
|
|
266
|
+
// Parse and validate slash command
|
|
267
|
+
const { isValid, commandId, args } =
|
|
268
|
+
this.slashCommandManager.parseAndValidateSlashCommand(command);
|
|
269
|
+
|
|
270
|
+
if (isValid && commandId !== undefined) {
|
|
271
|
+
// Execute valid slash command
|
|
272
|
+
await this.slashCommandManager.executeCommand(commandId, args);
|
|
273
|
+
|
|
274
|
+
// Add slash command to history
|
|
275
|
+
this.addToInputHistory(command);
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// If command doesn't exist, continue as normal message processing
|
|
280
|
+
// Don't add to history, let normal message processing logic below handle it
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Handle normal AI message
|
|
284
|
+
// Add user message to history
|
|
285
|
+
this.addToInputHistory(content);
|
|
286
|
+
|
|
287
|
+
// Execute UserPromptSubmit hooks before processing the prompt
|
|
288
|
+
if (this.hookManager) {
|
|
289
|
+
try {
|
|
290
|
+
await this.hookManager.executeHooks("UserPromptSubmit", {
|
|
291
|
+
event: "UserPromptSubmit",
|
|
292
|
+
projectDir: this.workdir,
|
|
293
|
+
timestamp: new Date(),
|
|
294
|
+
// UserPromptSubmit doesn't need toolName
|
|
295
|
+
sessionId: this.sessionId,
|
|
296
|
+
transcriptPath: this.messageManager.getTranscriptPath(),
|
|
297
|
+
cwd: this.workdir,
|
|
298
|
+
userPrompt: content,
|
|
299
|
+
});
|
|
300
|
+
} catch (error) {
|
|
301
|
+
this.logger?.warn("UserPromptSubmit hooks execution failed:", error);
|
|
302
|
+
// Continue processing even if hooks fail
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Add user message, will automatically sync to UI
|
|
307
|
+
this.messageManager.addUserMessage(
|
|
308
|
+
content,
|
|
309
|
+
images?.map((img) => ({
|
|
310
|
+
path: img.path,
|
|
311
|
+
mimeType: img.mimeType,
|
|
312
|
+
})),
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
// Send AI message
|
|
316
|
+
await this.aiManager.sendAIMessage();
|
|
317
|
+
} catch (error) {
|
|
318
|
+
console.error("Failed to add user message:", error);
|
|
319
|
+
// Loading state will be automatically updated by the useEffect that watches messages
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** Save memory to project or user memory file */
|
|
324
|
+
public async saveMemory(
|
|
325
|
+
message: string,
|
|
326
|
+
type: "project" | "user",
|
|
327
|
+
): Promise<void> {
|
|
328
|
+
try {
|
|
329
|
+
if (type === "project") {
|
|
330
|
+
await memory.addMemory(message, this.workdir);
|
|
331
|
+
} else {
|
|
332
|
+
await memory.addUserMemory(message);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Add successful MemoryBlock to the last assistant message
|
|
336
|
+
const memoryText = message.substring(1).trim();
|
|
337
|
+
const typeLabel = type === "project" ? "Project Memory" : "User Memory";
|
|
338
|
+
const storagePath = type === "project" ? "WAVE.md" : "user-memory.md";
|
|
339
|
+
|
|
340
|
+
this.messageManager.addMemoryBlock(
|
|
341
|
+
`${typeLabel}: ${memoryText}`,
|
|
342
|
+
true,
|
|
343
|
+
type,
|
|
344
|
+
storagePath,
|
|
345
|
+
);
|
|
346
|
+
} catch (error) {
|
|
347
|
+
// Add failed MemoryBlock to the last assistant message
|
|
348
|
+
const typeLabel = type === "project" ? "Project Memory" : "User Memory";
|
|
349
|
+
const storagePath = type === "project" ? "WAVE.md" : "user-memory.md";
|
|
350
|
+
|
|
351
|
+
this.messageManager.addMemoryBlock(
|
|
352
|
+
`${typeLabel} add failed: ${
|
|
353
|
+
error instanceof Error ? error.message : String(error)
|
|
354
|
+
}`,
|
|
355
|
+
false,
|
|
356
|
+
type,
|
|
357
|
+
storagePath,
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// ========== MCP Management Methods ==========
|
|
363
|
+
|
|
364
|
+
/** Get all MCP server status */
|
|
365
|
+
public getMcpServers(): McpServerStatus[] {
|
|
366
|
+
return this.mcpManager.getAllServers();
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** Connect MCP server */
|
|
370
|
+
public async connectMcpServer(serverName: string): Promise<boolean> {
|
|
371
|
+
return await this.mcpManager.connectServer(serverName);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/** Disconnect MCP server */
|
|
375
|
+
public async disconnectMcpServer(serverName: string): Promise<boolean> {
|
|
376
|
+
return await this.mcpManager.disconnectServer(serverName);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// ========== Slash Command Management Methods ==========
|
|
380
|
+
|
|
381
|
+
/** Get all available slash commands */
|
|
382
|
+
public getSlashCommands(): SlashCommand[] {
|
|
383
|
+
return this.slashCommandManager.getCommands();
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/** Check if slash command exists */
|
|
387
|
+
public hasSlashCommand(commandId: string): boolean {
|
|
388
|
+
return this.slashCommandManager.hasCommand(commandId);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** Reload custom commands */
|
|
392
|
+
public reloadCustomCommands(): void {
|
|
393
|
+
this.slashCommandManager.reloadCustomCommands();
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** Get custom command details */
|
|
397
|
+
public getCustomCommand(commandId: string): CustomSlashCommand | undefined {
|
|
398
|
+
return this.slashCommandManager.getCustomCommand(commandId);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** Get all custom commands */
|
|
402
|
+
public getCustomCommands(): CustomSlashCommand[] {
|
|
403
|
+
return this.slashCommandManager.getCustomCommands();
|
|
404
|
+
}
|
|
405
|
+
}
|