wave-agent-sdk 0.12.9 → 0.12.11
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/managers/messageManager.d.ts +1 -5
- package/dist/managers/messageManager.d.ts.map +1 -1
- package/dist/managers/messageManager.js +1 -28
- package/dist/managers/slashCommandManager.d.ts.map +1 -1
- package/dist/managers/slashCommandManager.js +36 -48
- package/dist/types/messaging.d.ts +2 -11
- package/dist/types/messaging.d.ts.map +1 -1
- package/dist/utils/convertMessagesForAPI.d.ts.map +1 -1
- package/dist/utils/convertMessagesForAPI.js +2 -16
- package/dist/utils/messageOperations.d.ts +2 -27
- package/dist/utils/messageOperations.d.ts.map +1 -1
- package/dist/utils/messageOperations.js +6 -82
- package/package.json +1 -1
- package/src/managers/messageManager.ts +0 -40
- package/src/managers/slashCommandManager.ts +38 -51
- package/src/types/messaging.ts +1 -12
- package/src/utils/convertMessagesForAPI.ts +2 -17
- package/src/utils/messageOperations.ts +7 -115
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserMessageParams,
|
|
1
|
+
import { UserMessageParams, type AgentToolBlockUpdateParams } 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";
|
|
@@ -19,8 +19,6 @@ export interface MessageManagerCallbacks {
|
|
|
19
19
|
onAddBangMessage?: (command: string) => void;
|
|
20
20
|
onUpdateBangMessage?: (command: string, output: string) => void;
|
|
21
21
|
onCompleteBangMessage?: (command: string, exitCode: number) => void;
|
|
22
|
-
onAddSlashMessage?: (params: import("../utils/messageOperations.js").AddSlashParams) => void;
|
|
23
|
-
onUpdateSlashBlock?: (params: import("../utils/messageOperations.js").UpdateSlashParams) => void;
|
|
24
22
|
onInfoBlockAdded?: (content: string) => void;
|
|
25
23
|
onShowRewind?: () => void;
|
|
26
24
|
onFileHistoryBlockAdded?: (snapshots: import("../types/reversion.js").FileSnapshot[]) => void;
|
|
@@ -122,8 +120,6 @@ export declare class MessageManager {
|
|
|
122
120
|
addBangMessage(command: string): void;
|
|
123
121
|
updateBangMessage(command: string, output: string): void;
|
|
124
122
|
completeBangMessage(command: string, exitCode: number, output?: string): void;
|
|
125
|
-
addSlashMessage(params: Omit<AddSlashParams, "messages">): string;
|
|
126
|
-
updateSlashBlock(params: Omit<UpdateSlashParams, "messages">): void;
|
|
127
123
|
/**
|
|
128
124
|
* Rebuild usage array from messages containing usage metadata
|
|
129
125
|
* 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,EAWL,iBAAiB,EACjB,KAAK,0BAA0B,EAEhC,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,C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I;IAUxD,mBAAmB,CACxB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,MAAM,GACd,IAAI;IAWP;;;OAGG;IACI,wBAAwB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAW1D;;;OAGG;IACI,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAKnC;;OAEG;IACI,kBAAkB,IAAI,IAAI;IAIjC;;;;OAIG;IACI,2BAA2B,CAAC,qBAAqB,EAAE,MAAM,GAAG,IAAI;IA6CvE;;;OAGG;IACI,6BAA6B,CAAC,uBAAuB,EAAE,MAAM,GAAG,IAAI;IA8C3E;;;OAGG;IACI,qBAAqB,IAAI,IAAI;IAKvB,oBAAoB,IAAI,OAAO,CAAC;QAC3C,QAAQ,EAAE,OAAO,EAAE,CAAC;QACpB,UAAU,EAAE,MAAM,EAAE,CAAC;KACtB,CAAC;IAKF;;;;OAIG;IACU,eAAe,CAC1B,KAAK,EAAE,MAAM,EACb,gBAAgB,CAAC,EAAE,OAAO,uBAAuB,EAAE,gBAAgB,GAClE,OAAO,CAAC,IAAI,CAAC;IAkGhB;;OAEG;YACW,kBAAkB;IAoBhC,OAAO,CAAC,sBAAsB;CA4B/B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addAssistantMessageToMessages, updateToolBlockInMessage, addErrorBlockToMessage, addUserMessageToMessages, updateUserMessageInMessages, addBangMessage, updateBangInMessage, completeBangInMessage,
|
|
1
|
+
import { addAssistantMessageToMessages, updateToolBlockInMessage, addErrorBlockToMessage, addUserMessageToMessages, updateUserMessageInMessages, addBangMessage, updateBangInMessage, completeBangInMessage, removeLastUserMessage, addToolBlockToMessageInMessages, generateMessageId, } from "../utils/messageOperations.js";
|
|
2
2
|
import { join, isAbsolute, relative } from "path";
|
|
3
3
|
import { appendMessages, createSession, generateSessionId, SESSION_DIR, } from "../services/session.js";
|
|
4
4
|
import { pathEncoder } from "../utils/pathEncoder.js";
|
|
@@ -394,33 +394,6 @@ export class MessageManager {
|
|
|
394
394
|
this.setMessages(updatedMessages);
|
|
395
395
|
this.callbacks.onCompleteBangMessage?.(command, exitCode);
|
|
396
396
|
}
|
|
397
|
-
// Slash related message operations
|
|
398
|
-
addSlashMessage(params) {
|
|
399
|
-
const id = params.id || generateMessageId();
|
|
400
|
-
const updatedMessages = addSlashMessageToMessages({
|
|
401
|
-
messages: this.messages,
|
|
402
|
-
...params,
|
|
403
|
-
id,
|
|
404
|
-
});
|
|
405
|
-
this.setMessages(updatedMessages);
|
|
406
|
-
this.callbacks.onAddSlashMessage?.({
|
|
407
|
-
messages: updatedMessages,
|
|
408
|
-
...params,
|
|
409
|
-
id,
|
|
410
|
-
});
|
|
411
|
-
return id;
|
|
412
|
-
}
|
|
413
|
-
updateSlashBlock(params) {
|
|
414
|
-
const updatedMessages = updateSlashBlockInMessage({
|
|
415
|
-
messages: this.messages,
|
|
416
|
-
...params,
|
|
417
|
-
});
|
|
418
|
-
this.setMessages(updatedMessages);
|
|
419
|
-
this.callbacks.onUpdateSlashBlock?.({
|
|
420
|
-
messages: updatedMessages,
|
|
421
|
-
...params,
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
397
|
/**
|
|
425
398
|
* Rebuild usage array from messages containing usage metadata
|
|
426
399
|
* Called during session restoration to reconstruct usage tracking
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slashCommandManager.d.ts","sourceRoot":"","sources":["../../src/managers/slashCommandManager.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAQ1E,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAWlD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAKxD,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,mBAAmB;IAQ5B,OAAO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AO,KAAK,WAAW,GAEtB;IAED,OAAO,KAAK,YAAY,GAEvB;IAED,OAAO,KAAK,eAAe,GAE1B;IAED,OAAO,CAAC,yBAAyB;IAcjC;;OAEG;IACH,OAAO,CAAC,kBAAkB;IA2C1B;;OAEG;IACI,qBAAqB,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,IAAI;IAyK3D;;OAEG;IACI,sBAAsB,CAC3B,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,kBAAkB,EAAE,GAC7B,IAAI;IAyCP;;OAEG;IACI,oBAAoB,IAAI,IAAI;IAWnC;;OAEG;IACI,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAInD;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAIzB;;OAEG;IACI,WAAW,IAAI,YAAY,EAAE;IAIpC;;OAEG;IACI,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAI9D;;OAEG;IACU,cAAc,CACzB,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,OAAO,CAAC;IA2BnB;;;OAGG;IACI,4BAA4B,CAAC,KAAK,EAAE,MAAM,GAAG;QAClD,OAAO,EAAE,OAAO,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf;IAeD;;OAEG;IACI,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAI7C;;OAEG;IACI,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAI1E;;OAEG;IACI,iBAAiB,IAAI,kBAAkB,EAAE;IAIhD;;OAEG;YACW,+BAA+B;IA6C7C;;OAEG;IACI,mBAAmB,IAAI,IAAI;CAQnC"}
|
|
@@ -76,7 +76,7 @@ export class SlashCommandManager {
|
|
|
76
76
|
if (args) {
|
|
77
77
|
processedContent = substituteCommandParameters(processedContent, args);
|
|
78
78
|
}
|
|
79
|
-
await this.executeCustomCommandInMainAgent(command.name, processedContent, command.config
|
|
79
|
+
await this.executeCustomCommandInMainAgent(command.name, processedContent, command.config);
|
|
80
80
|
},
|
|
81
81
|
});
|
|
82
82
|
}
|
|
@@ -112,23 +112,22 @@ export class SlashCommandManager {
|
|
|
112
112
|
skill_name: skill.name,
|
|
113
113
|
args,
|
|
114
114
|
});
|
|
115
|
-
// 2. Add slash message immediately
|
|
116
|
-
const messageId = this.messageManager.addSlashMessage({
|
|
117
|
-
command: skill.name,
|
|
118
|
-
args,
|
|
119
|
-
content: prepared.content,
|
|
120
|
-
});
|
|
121
115
|
if (!prepared.skill) {
|
|
122
|
-
// If skill not found or invalid,
|
|
123
|
-
this.messageManager.
|
|
124
|
-
command: skill.name,
|
|
125
|
-
messageId,
|
|
126
|
-
stage: "error",
|
|
127
|
-
error: prepared.content,
|
|
128
|
-
});
|
|
116
|
+
// If skill not found or invalid, add error
|
|
117
|
+
this.messageManager.addErrorBlock(prepared.content);
|
|
129
118
|
return;
|
|
130
119
|
}
|
|
131
120
|
if (skill.context === "fork") {
|
|
121
|
+
// Forked skill execution: add user message with text + tool block
|
|
122
|
+
const messageId = this.messageManager.addUserMessage({
|
|
123
|
+
content: `/${skill.name}${args ? ` ${args}` : ""}`,
|
|
124
|
+
customCommandContent: prepared.content,
|
|
125
|
+
});
|
|
126
|
+
const toolBlockId = this.messageManager.addToolBlockToMessage(messageId, {
|
|
127
|
+
name: skill.name,
|
|
128
|
+
parameters: prepared.content,
|
|
129
|
+
stage: "running",
|
|
130
|
+
});
|
|
132
131
|
// Forked skill execution
|
|
133
132
|
const subagentConfigs = await this.subagentManager.loadConfigurations();
|
|
134
133
|
const subagentType = skill.agent || "general-purpose";
|
|
@@ -143,7 +142,7 @@ export class SlashCommandManager {
|
|
|
143
142
|
subagent_type: subagentType,
|
|
144
143
|
model: skill.model,
|
|
145
144
|
}, false, () => {
|
|
146
|
-
// Update the
|
|
145
|
+
// Update the tool block with progress
|
|
147
146
|
const subagent = this.subagentManager.getInstance(instance.subagentId);
|
|
148
147
|
if (subagent) {
|
|
149
148
|
const messages = subagent.messages;
|
|
@@ -159,8 +158,8 @@ export class SlashCommandManager {
|
|
|
159
158
|
shortResult += `${lastTools.join(", ")} `;
|
|
160
159
|
}
|
|
161
160
|
shortResult += summary;
|
|
162
|
-
this.messageManager.
|
|
163
|
-
|
|
161
|
+
this.messageManager.updateToolBlock({
|
|
162
|
+
id: toolBlockId,
|
|
164
163
|
messageId,
|
|
165
164
|
shortResult,
|
|
166
165
|
});
|
|
@@ -168,12 +167,12 @@ export class SlashCommandManager {
|
|
|
168
167
|
});
|
|
169
168
|
try {
|
|
170
169
|
const result = await this.subagentManager.executeAgent(instance, prepared.content, signal);
|
|
171
|
-
// Update the
|
|
172
|
-
this.messageManager.
|
|
173
|
-
|
|
170
|
+
// Update the ToolBlock with final result
|
|
171
|
+
this.messageManager.updateToolBlock({
|
|
172
|
+
id: toolBlockId,
|
|
174
173
|
messageId,
|
|
175
174
|
result,
|
|
176
|
-
stage: "
|
|
175
|
+
stage: "end",
|
|
177
176
|
});
|
|
178
177
|
}
|
|
179
178
|
finally {
|
|
@@ -181,31 +180,28 @@ export class SlashCommandManager {
|
|
|
181
180
|
}
|
|
182
181
|
}
|
|
183
182
|
catch (error) {
|
|
184
|
-
// Update the
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
command: skill.name,
|
|
183
|
+
// Update the ToolBlock with error
|
|
184
|
+
this.messageManager.updateToolBlock({
|
|
185
|
+
id: toolBlockId,
|
|
188
186
|
messageId,
|
|
189
|
-
stage:
|
|
187
|
+
stage: "end",
|
|
190
188
|
error: error instanceof Error ? error.message : String(error),
|
|
191
189
|
});
|
|
192
190
|
throw error; // Re-throw to be caught by outer catch for logging/error block
|
|
193
191
|
}
|
|
194
192
|
return;
|
|
195
193
|
}
|
|
196
|
-
//
|
|
194
|
+
// Non-forked skill: execute and trigger AI response
|
|
197
195
|
const result = await this.skillManager.executeSkill({
|
|
198
196
|
skill_name: skill.name,
|
|
199
197
|
args,
|
|
200
198
|
});
|
|
201
|
-
//
|
|
202
|
-
this.messageManager.
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
content: result.content,
|
|
206
|
-
stage: "success",
|
|
199
|
+
// Add user message with the processed content
|
|
200
|
+
this.messageManager.addUserMessage({
|
|
201
|
+
content: `/${skill.name}${args ? ` ${args}` : ""}`,
|
|
202
|
+
customCommandContent: result.content,
|
|
207
203
|
});
|
|
208
|
-
//
|
|
204
|
+
// Trigger AI response
|
|
209
205
|
await this.aiManager.sendAIMessage({
|
|
210
206
|
model: skill.model,
|
|
211
207
|
allowedRules: result.allowedTools,
|
|
@@ -241,7 +237,7 @@ export class SlashCommandManager {
|
|
|
241
237
|
if (args) {
|
|
242
238
|
processedContent = substituteCommandParameters(processedContent, args);
|
|
243
239
|
}
|
|
244
|
-
await this.executeCustomCommandInMainAgent(namespacedName, processedContent, command.config
|
|
240
|
+
await this.executeCustomCommandInMainAgent(namespacedName, processedContent, command.config);
|
|
245
241
|
},
|
|
246
242
|
});
|
|
247
243
|
}
|
|
@@ -353,14 +349,8 @@ export class SlashCommandManager {
|
|
|
353
349
|
/**
|
|
354
350
|
* Execute custom command in main agent instead of sub-agent
|
|
355
351
|
*/
|
|
356
|
-
async executeCustomCommandInMainAgent(commandName, content, config
|
|
352
|
+
async executeCustomCommandInMainAgent(commandName, content, config) {
|
|
357
353
|
try {
|
|
358
|
-
// Add slash command message immediately to show the command being executed
|
|
359
|
-
const messageId = this.messageManager.addSlashMessage({
|
|
360
|
-
command: commandName,
|
|
361
|
-
args,
|
|
362
|
-
content, // Initial content with bash placeholders
|
|
363
|
-
});
|
|
364
354
|
// Parse bash commands from the content
|
|
365
355
|
const { commands, processedContent } = parseBashCommands(content);
|
|
366
356
|
// Execute bash commands if any
|
|
@@ -369,12 +359,10 @@ export class SlashCommandManager {
|
|
|
369
359
|
const bashResults = await executeBashCommands(commands, this.workdir);
|
|
370
360
|
finalContent = replaceBashCommandsWithOutput(processedContent, bashResults);
|
|
371
361
|
}
|
|
372
|
-
//
|
|
373
|
-
this.messageManager.
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
content: finalContent,
|
|
377
|
-
stage: "success",
|
|
362
|
+
// Add user message with command name as display content, processed content for AI
|
|
363
|
+
this.messageManager.addUserMessage({
|
|
364
|
+
content: `/${commandName}`,
|
|
365
|
+
customCommandContent: finalContent,
|
|
378
366
|
});
|
|
379
367
|
// Execute the AI conversation with custom configuration
|
|
380
368
|
await this.aiManager.sendAIMessage({
|
|
@@ -15,22 +15,13 @@ export interface Message {
|
|
|
15
15
|
additionalFields?: Record<string, unknown>;
|
|
16
16
|
isMeta?: boolean;
|
|
17
17
|
}
|
|
18
|
-
export type MessageBlock = TextBlock | ErrorBlock | ToolBlock | ImageBlock | BangBlock |
|
|
18
|
+
export type MessageBlock = TextBlock | ErrorBlock | ToolBlock | ImageBlock | BangBlock | CompressBlock | ReasoningBlock | FileHistoryBlock;
|
|
19
19
|
export interface TextBlock {
|
|
20
20
|
type: "text";
|
|
21
21
|
content: string;
|
|
22
|
+
customCommandContent?: string;
|
|
22
23
|
source?: MessageSource;
|
|
23
24
|
}
|
|
24
|
-
export interface SlashBlock {
|
|
25
|
-
type: "slash";
|
|
26
|
-
command: string;
|
|
27
|
-
args?: string;
|
|
28
|
-
content?: string;
|
|
29
|
-
result?: string;
|
|
30
|
-
stage: "running" | "success" | "error" | "aborted";
|
|
31
|
-
error?: string;
|
|
32
|
-
shortResult?: string;
|
|
33
|
-
}
|
|
34
25
|
export interface ErrorBlock {
|
|
35
26
|
type: "error";
|
|
36
27
|
content: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messaging.d.ts","sourceRoot":"","sources":["../../src/types/messaging.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAEvC,oBAAY,aAAa;IACvB,IAAI,SAAS;IAC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C;IACrB,SAAS,EAAE,OAAO,gBAAgB,EAAE,YAAY,EAAE,CAAC;CACpD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertMessagesForAPI.d.ts","sourceRoot":"","sources":["../../src/utils/convertMessagesForAPI.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAIjD,OAAO,EAEL,0BAA0B,EAC3B,MAAM,qBAAqB,CAAC;AA0B7B;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,OAAO,EAAE,GAClB,0BAA0B,EAAE,
|
|
1
|
+
{"version":3,"file":"convertMessagesForAPI.d.ts","sourceRoot":"","sources":["../../src/utils/convertMessagesForAPI.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAIjD,OAAO,EAEL,0BAA0B,EAC3B,MAAM,qBAAqB,CAAC;AA0B7B;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,OAAO,EAAE,GAClB,0BAA0B,EAAE,CA+N9B"}
|
|
@@ -150,26 +150,12 @@ export function convertMessagesForAPI(messages) {
|
|
|
150
150
|
if (block.type === "text" &&
|
|
151
151
|
block.content &&
|
|
152
152
|
block.content.trim().length > 0) {
|
|
153
|
+
const textForApi = block.customCommandContent ?? block.content;
|
|
153
154
|
contentParts.push({
|
|
154
155
|
type: "text",
|
|
155
|
-
text:
|
|
156
|
+
text: textForApi,
|
|
156
157
|
});
|
|
157
158
|
}
|
|
158
|
-
// Handle SlashBlock
|
|
159
|
-
if (block.type === "slash") {
|
|
160
|
-
if (block.content && block.content.trim().length > 0) {
|
|
161
|
-
contentParts.push({
|
|
162
|
-
type: "text",
|
|
163
|
-
text: block.content,
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
if (block.result && block.result.trim().length > 0) {
|
|
167
|
-
contentParts.push({
|
|
168
|
-
type: "text",
|
|
169
|
-
text: `<local-command-stdout>\n${stripAnsiColors(block.result)}\n</local-command-stdout>`,
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
159
|
// If there is an image, add image content
|
|
174
160
|
if (block.type === "image" &&
|
|
175
161
|
block.imageUrls &&
|
|
@@ -3,6 +3,7 @@ import { MessageSource } from "../types/index.js";
|
|
|
3
3
|
import { ChatCompletionMessageFunctionToolCall } from "openai/resources.js";
|
|
4
4
|
export interface UserMessageParams {
|
|
5
5
|
content: string;
|
|
6
|
+
customCommandContent?: string;
|
|
6
7
|
images?: Array<{
|
|
7
8
|
path: string;
|
|
8
9
|
mimeType: string;
|
|
@@ -14,24 +15,6 @@ export interface AddUserMessageParams extends UserMessageParams {
|
|
|
14
15
|
messages: Message[];
|
|
15
16
|
id?: string;
|
|
16
17
|
}
|
|
17
|
-
export interface AddSlashParams {
|
|
18
|
-
messages: Message[];
|
|
19
|
-
command: string;
|
|
20
|
-
args?: string;
|
|
21
|
-
content?: string;
|
|
22
|
-
id?: string;
|
|
23
|
-
}
|
|
24
|
-
export interface UpdateSlashParams {
|
|
25
|
-
messages: Message[];
|
|
26
|
-
command: string;
|
|
27
|
-
messageId?: string;
|
|
28
|
-
args?: string;
|
|
29
|
-
content?: string;
|
|
30
|
-
result?: string;
|
|
31
|
-
stage?: "running" | "success" | "error" | "aborted";
|
|
32
|
-
error?: string;
|
|
33
|
-
shortResult?: string;
|
|
34
|
-
}
|
|
35
18
|
export interface UpdateToolBlockParams {
|
|
36
19
|
messages: Message[];
|
|
37
20
|
id: string;
|
|
@@ -86,15 +69,7 @@ export interface CompleteBangParams {
|
|
|
86
69
|
*/
|
|
87
70
|
export declare const convertImageToBase64: (imagePath: string) => string;
|
|
88
71
|
export declare const generateMessageId: () => string;
|
|
89
|
-
export declare const addUserMessageToMessages: ({ messages, content, images, source, id, isMeta, }: AddUserMessageParams) => Message[];
|
|
90
|
-
/**
|
|
91
|
-
* Add a slash command message to the conversation.
|
|
92
|
-
*/
|
|
93
|
-
export declare const addSlashMessageToMessages: ({ messages, command, args, content, id, }: AddSlashParams) => Message[];
|
|
94
|
-
/**
|
|
95
|
-
* Update a slash block in a message.
|
|
96
|
-
*/
|
|
97
|
-
export declare const updateSlashBlockInMessage: ({ messages, command, messageId, args, content, result, stage, error, shortResult, }: UpdateSlashParams) => Message[];
|
|
72
|
+
export declare const addUserMessageToMessages: ({ messages, content, customCommandContent, images, source, id, isMeta, }: AddUserMessageParams) => Message[];
|
|
98
73
|
/**
|
|
99
74
|
* Update a user message's content by its ID.
|
|
100
75
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageOperations.d.ts","sourceRoot":"","sources":["../../src/utils/messageOperations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAa,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,OAAO,EAAE,qCAAqC,EAAE,MAAM,qBAAqB,CAAC;AAI5E,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACnD,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAGD,MAAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC7D,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"messageOperations.d.ts","sourceRoot":"","sources":["../../src/utils/messageOperations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAa,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAm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C,WAAW,EAAE,MAAM,CAAA;CAuB5C,CAAC;AAGF,eAAO,MAAM,wBAAwB,GAAI,6KAgBtC,qBAAqB,KAAG,OAAO,EAsFjC,CAAC;AAGF,eAAO,MAAM,sBAAsB,GAAI,sBAGpC,mBAAmB,KAAG,OAAO,EAgC/B,CAAC;AAGF,eAAO,MAAM,cAAc,GAAI,wBAG5B,aAAa,KAAG,OAAO,EAgBzB,CAAC;AAGF,eAAO,MAAM,mBAAmB,GAAI,gCAIjC,gBAAgB,KAAG,OAAO,EAiB5B,CAAC;AAGF,eAAO,MAAM,qBAAqB,GAAI,0CAKnC,kBAAkB,KAAG,OAAO,EAqB9B,CAAC;AAEF;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM,CAU3D;AAED;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAI,UAAU,OAAO,EAAE,KAAG,OAAO,EASlE,CAAC;AAEF;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAoBtD;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,MAAM,CAUR;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAoB1D"}
|
|
@@ -44,12 +44,13 @@ export const convertImageToBase64 = (imagePath) => {
|
|
|
44
44
|
};
|
|
45
45
|
export const generateMessageId = () => `msg-${randomUUID()}`;
|
|
46
46
|
// Add user message
|
|
47
|
-
export const addUserMessageToMessages = ({ messages, content, images, source, id, isMeta, }) => {
|
|
47
|
+
export const addUserMessageToMessages = ({ messages, content, customCommandContent, images, source, id, isMeta, }) => {
|
|
48
48
|
const blocks = [];
|
|
49
|
-
// Create text block with optional source
|
|
49
|
+
// Create text block with optional source and customCommandContent
|
|
50
50
|
const textBlock = {
|
|
51
51
|
type: "text",
|
|
52
52
|
content,
|
|
53
|
+
...(customCommandContent && { customCommandContent }),
|
|
53
54
|
...(source && { source }),
|
|
54
55
|
};
|
|
55
56
|
blocks.push(textBlock);
|
|
@@ -69,82 +70,6 @@ export const addUserMessageToMessages = ({ messages, content, images, source, id
|
|
|
69
70
|
};
|
|
70
71
|
return [...messages, userMessage];
|
|
71
72
|
};
|
|
72
|
-
/**
|
|
73
|
-
* Add a slash command message to the conversation.
|
|
74
|
-
*/
|
|
75
|
-
export const addSlashMessageToMessages = ({ messages, command, args, content, id, }) => {
|
|
76
|
-
const slashMessage = {
|
|
77
|
-
id: id || generateMessageId(),
|
|
78
|
-
role: "user",
|
|
79
|
-
blocks: [
|
|
80
|
-
{
|
|
81
|
-
type: "slash",
|
|
82
|
-
command,
|
|
83
|
-
args,
|
|
84
|
-
content,
|
|
85
|
-
stage: "running",
|
|
86
|
-
},
|
|
87
|
-
],
|
|
88
|
-
};
|
|
89
|
-
return [...messages, slashMessage];
|
|
90
|
-
};
|
|
91
|
-
/**
|
|
92
|
-
* Update a slash block in a message.
|
|
93
|
-
*/
|
|
94
|
-
export const updateSlashBlockInMessage = ({ messages, command, messageId, args, content, result, stage, error, shortResult, }) => {
|
|
95
|
-
const newMessages = [...messages];
|
|
96
|
-
// If messageId is provided, target that specific message
|
|
97
|
-
if (messageId) {
|
|
98
|
-
const messageIndex = newMessages.findIndex((msg) => msg.id === messageId);
|
|
99
|
-
if (messageIndex !== -1) {
|
|
100
|
-
const slashBlockIndex = newMessages[messageIndex].blocks.findIndex((block) => block.type === "slash" && block.command === command);
|
|
101
|
-
if (slashBlockIndex !== -1) {
|
|
102
|
-
const slashBlock = newMessages[messageIndex].blocks[slashBlockIndex];
|
|
103
|
-
if (slashBlock.type === "slash") {
|
|
104
|
-
if (args !== undefined)
|
|
105
|
-
slashBlock.args = args;
|
|
106
|
-
if (content !== undefined)
|
|
107
|
-
slashBlock.content = content;
|
|
108
|
-
if (result !== undefined)
|
|
109
|
-
slashBlock.result = result;
|
|
110
|
-
if (stage !== undefined)
|
|
111
|
-
slashBlock.stage = stage;
|
|
112
|
-
if (error !== undefined)
|
|
113
|
-
slashBlock.error = error;
|
|
114
|
-
if (shortResult !== undefined)
|
|
115
|
-
slashBlock.shortResult = shortResult;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return newMessages;
|
|
120
|
-
}
|
|
121
|
-
// Find the last user message with a slash block for this command
|
|
122
|
-
for (let i = newMessages.length - 1; i >= 0; i--) {
|
|
123
|
-
const msg = newMessages[i];
|
|
124
|
-
if (msg.role === "user") {
|
|
125
|
-
const slashBlockIndex = msg.blocks.findIndex((block) => block.type === "slash" && block.command === command);
|
|
126
|
-
if (slashBlockIndex !== -1) {
|
|
127
|
-
const slashBlock = msg.blocks[slashBlockIndex];
|
|
128
|
-
if (slashBlock.type === "slash") {
|
|
129
|
-
if (args !== undefined)
|
|
130
|
-
slashBlock.args = args;
|
|
131
|
-
if (content !== undefined)
|
|
132
|
-
slashBlock.content = content;
|
|
133
|
-
if (result !== undefined)
|
|
134
|
-
slashBlock.result = result;
|
|
135
|
-
if (stage !== undefined)
|
|
136
|
-
slashBlock.stage = stage;
|
|
137
|
-
if (error !== undefined)
|
|
138
|
-
slashBlock.error = error;
|
|
139
|
-
if (shortResult !== undefined)
|
|
140
|
-
slashBlock.shortResult = shortResult;
|
|
141
|
-
}
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return newMessages;
|
|
147
|
-
};
|
|
148
73
|
/**
|
|
149
74
|
* Update a user message's content by its ID.
|
|
150
75
|
*/
|
|
@@ -156,6 +81,9 @@ export const updateUserMessageInMessages = (messages, id, params) => {
|
|
|
156
81
|
return {
|
|
157
82
|
...block,
|
|
158
83
|
...(params.content !== undefined && { content: params.content }),
|
|
84
|
+
...(params.customCommandContent !== undefined && {
|
|
85
|
+
customCommandContent: params.customCommandContent,
|
|
86
|
+
}),
|
|
159
87
|
...(params.source !== undefined && { source: params.source }),
|
|
160
88
|
};
|
|
161
89
|
}
|
|
@@ -486,10 +414,6 @@ export function getMessageContent(message) {
|
|
|
486
414
|
if (textBlock && "content" in textBlock) {
|
|
487
415
|
return textBlock.content;
|
|
488
416
|
}
|
|
489
|
-
const slashBlock = message.blocks.find((block) => block.type === "slash");
|
|
490
|
-
if (slashBlock && "command" in slashBlock) {
|
|
491
|
-
return `/${slashBlock.command}${slashBlock.args ? ` ${slashBlock.args}` : ""}`;
|
|
492
|
-
}
|
|
493
417
|
const bangBlock = message.blocks.find((block) => block.type === "bang");
|
|
494
418
|
if (bangBlock && "command" in bangBlock) {
|
|
495
419
|
return `!${bangBlock.command}`;
|
package/package.json
CHANGED
|
@@ -7,13 +7,9 @@ import {
|
|
|
7
7
|
addBangMessage,
|
|
8
8
|
updateBangInMessage,
|
|
9
9
|
completeBangInMessage,
|
|
10
|
-
addSlashMessageToMessages,
|
|
11
|
-
updateSlashBlockInMessage,
|
|
12
10
|
removeLastUserMessage,
|
|
13
11
|
addToolBlockToMessageInMessages,
|
|
14
12
|
UserMessageParams,
|
|
15
|
-
AddSlashParams,
|
|
16
|
-
UpdateSlashParams,
|
|
17
13
|
type AgentToolBlockUpdateParams,
|
|
18
14
|
generateMessageId,
|
|
19
15
|
} from "../utils/messageOperations.js";
|
|
@@ -54,13 +50,6 @@ export interface MessageManagerCallbacks {
|
|
|
54
50
|
onAddBangMessage?: (command: string) => void;
|
|
55
51
|
onUpdateBangMessage?: (command: string, output: string) => void;
|
|
56
52
|
onCompleteBangMessage?: (command: string, exitCode: number) => void;
|
|
57
|
-
// Slash callback
|
|
58
|
-
onAddSlashMessage?: (
|
|
59
|
-
params: import("../utils/messageOperations.js").AddSlashParams,
|
|
60
|
-
) => void;
|
|
61
|
-
onUpdateSlashBlock?: (
|
|
62
|
-
params: import("../utils/messageOperations.js").UpdateSlashParams,
|
|
63
|
-
) => void;
|
|
64
53
|
onInfoBlockAdded?: (content: string) => void;
|
|
65
54
|
// Rewind callbacks
|
|
66
55
|
onShowRewind?: () => void;
|
|
@@ -594,35 +583,6 @@ export class MessageManager {
|
|
|
594
583
|
this.callbacks.onCompleteBangMessage?.(command, exitCode);
|
|
595
584
|
}
|
|
596
585
|
|
|
597
|
-
// Slash related message operations
|
|
598
|
-
public addSlashMessage(params: Omit<AddSlashParams, "messages">): string {
|
|
599
|
-
const id = params.id || generateMessageId();
|
|
600
|
-
const updatedMessages = addSlashMessageToMessages({
|
|
601
|
-
messages: this.messages,
|
|
602
|
-
...params,
|
|
603
|
-
id,
|
|
604
|
-
});
|
|
605
|
-
this.setMessages(updatedMessages);
|
|
606
|
-
this.callbacks.onAddSlashMessage?.({
|
|
607
|
-
messages: updatedMessages,
|
|
608
|
-
...params,
|
|
609
|
-
id,
|
|
610
|
-
});
|
|
611
|
-
return id;
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
public updateSlashBlock(params: Omit<UpdateSlashParams, "messages">): void {
|
|
615
|
-
const updatedMessages = updateSlashBlockInMessage({
|
|
616
|
-
messages: this.messages,
|
|
617
|
-
...params,
|
|
618
|
-
});
|
|
619
|
-
this.setMessages(updatedMessages);
|
|
620
|
-
this.callbacks.onUpdateSlashBlock?.({
|
|
621
|
-
messages: updatedMessages,
|
|
622
|
-
...params,
|
|
623
|
-
});
|
|
624
|
-
}
|
|
625
|
-
|
|
626
586
|
/**
|
|
627
587
|
* Rebuild usage array from messages containing usage metadata
|
|
628
588
|
* Called during session restoration to reconstruct usage tracking
|
|
@@ -130,7 +130,6 @@ export class SlashCommandManager {
|
|
|
130
130
|
command.name,
|
|
131
131
|
processedContent,
|
|
132
132
|
command.config,
|
|
133
|
-
args,
|
|
134
133
|
);
|
|
135
134
|
},
|
|
136
135
|
});
|
|
@@ -171,25 +170,28 @@ export class SlashCommandManager {
|
|
|
171
170
|
args,
|
|
172
171
|
});
|
|
173
172
|
|
|
174
|
-
// 2. Add slash message immediately
|
|
175
|
-
const messageId = this.messageManager.addSlashMessage({
|
|
176
|
-
command: skill.name,
|
|
177
|
-
args,
|
|
178
|
-
content: prepared.content,
|
|
179
|
-
});
|
|
180
|
-
|
|
181
173
|
if (!prepared.skill) {
|
|
182
|
-
// If skill not found or invalid,
|
|
183
|
-
this.messageManager.
|
|
184
|
-
command: skill.name,
|
|
185
|
-
messageId,
|
|
186
|
-
stage: "error",
|
|
187
|
-
error: prepared.content,
|
|
188
|
-
});
|
|
174
|
+
// If skill not found or invalid, add error
|
|
175
|
+
this.messageManager.addErrorBlock(prepared.content);
|
|
189
176
|
return;
|
|
190
177
|
}
|
|
191
178
|
|
|
192
179
|
if (skill.context === "fork") {
|
|
180
|
+
// Forked skill execution: add user message with text + tool block
|
|
181
|
+
const messageId = this.messageManager.addUserMessage({
|
|
182
|
+
content: `/${skill.name}${args ? ` ${args}` : ""}`,
|
|
183
|
+
customCommandContent: prepared.content,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const toolBlockId = this.messageManager.addToolBlockToMessage(
|
|
187
|
+
messageId,
|
|
188
|
+
{
|
|
189
|
+
name: skill.name,
|
|
190
|
+
parameters: prepared.content,
|
|
191
|
+
stage: "running",
|
|
192
|
+
},
|
|
193
|
+
);
|
|
194
|
+
|
|
193
195
|
// Forked skill execution
|
|
194
196
|
const subagentConfigs =
|
|
195
197
|
await this.subagentManager.loadConfigurations();
|
|
@@ -214,7 +216,7 @@ export class SlashCommandManager {
|
|
|
214
216
|
},
|
|
215
217
|
false,
|
|
216
218
|
() => {
|
|
217
|
-
// Update the
|
|
219
|
+
// Update the tool block with progress
|
|
218
220
|
const subagent = this.subagentManager.getInstance(
|
|
219
221
|
instance.subagentId,
|
|
220
222
|
);
|
|
@@ -237,8 +239,8 @@ export class SlashCommandManager {
|
|
|
237
239
|
|
|
238
240
|
shortResult += summary;
|
|
239
241
|
|
|
240
|
-
this.messageManager.
|
|
241
|
-
|
|
242
|
+
this.messageManager.updateToolBlock({
|
|
243
|
+
id: toolBlockId,
|
|
242
244
|
messageId,
|
|
243
245
|
shortResult,
|
|
244
246
|
});
|
|
@@ -253,24 +255,22 @@ export class SlashCommandManager {
|
|
|
253
255
|
signal,
|
|
254
256
|
);
|
|
255
257
|
|
|
256
|
-
// Update the
|
|
257
|
-
this.messageManager.
|
|
258
|
-
|
|
258
|
+
// Update the ToolBlock with final result
|
|
259
|
+
this.messageManager.updateToolBlock({
|
|
260
|
+
id: toolBlockId,
|
|
259
261
|
messageId,
|
|
260
262
|
result,
|
|
261
|
-
stage: "
|
|
263
|
+
stage: "end",
|
|
262
264
|
});
|
|
263
265
|
} finally {
|
|
264
266
|
this.subagentManager.cleanupInstance(instance.subagentId);
|
|
265
267
|
}
|
|
266
268
|
} catch (error) {
|
|
267
|
-
// Update the
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
this.messageManager.updateSlashBlock({
|
|
271
|
-
command: skill.name,
|
|
269
|
+
// Update the ToolBlock with error
|
|
270
|
+
this.messageManager.updateToolBlock({
|
|
271
|
+
id: toolBlockId,
|
|
272
272
|
messageId,
|
|
273
|
-
stage:
|
|
273
|
+
stage: "end",
|
|
274
274
|
error: error instanceof Error ? error.message : String(error),
|
|
275
275
|
});
|
|
276
276
|
throw error; // Re-throw to be caught by outer catch for logging/error block
|
|
@@ -278,21 +278,19 @@ export class SlashCommandManager {
|
|
|
278
278
|
return;
|
|
279
279
|
}
|
|
280
280
|
|
|
281
|
-
//
|
|
281
|
+
// Non-forked skill: execute and trigger AI response
|
|
282
282
|
const result = await this.skillManager.executeSkill({
|
|
283
283
|
skill_name: skill.name,
|
|
284
284
|
args,
|
|
285
285
|
});
|
|
286
286
|
|
|
287
|
-
//
|
|
288
|
-
this.messageManager.
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
content: result.content,
|
|
292
|
-
stage: "success",
|
|
287
|
+
// Add user message with the processed content
|
|
288
|
+
this.messageManager.addUserMessage({
|
|
289
|
+
content: `/${skill.name}${args ? ` ${args}` : ""}`,
|
|
290
|
+
customCommandContent: result.content,
|
|
293
291
|
});
|
|
294
292
|
|
|
295
|
-
//
|
|
293
|
+
// Trigger AI response
|
|
296
294
|
await this.aiManager.sendAIMessage({
|
|
297
295
|
model: skill.model,
|
|
298
296
|
allowedRules: result.allowedTools,
|
|
@@ -352,7 +350,6 @@ export class SlashCommandManager {
|
|
|
352
350
|
namespacedName,
|
|
353
351
|
processedContent,
|
|
354
352
|
command.config,
|
|
355
|
-
args,
|
|
356
353
|
);
|
|
357
354
|
},
|
|
358
355
|
});
|
|
@@ -489,16 +486,8 @@ export class SlashCommandManager {
|
|
|
489
486
|
commandName: string,
|
|
490
487
|
content: string,
|
|
491
488
|
config?: { model?: string; allowedTools?: string[] },
|
|
492
|
-
args?: string,
|
|
493
489
|
): Promise<void> {
|
|
494
490
|
try {
|
|
495
|
-
// Add slash command message immediately to show the command being executed
|
|
496
|
-
const messageId = this.messageManager.addSlashMessage({
|
|
497
|
-
command: commandName,
|
|
498
|
-
args,
|
|
499
|
-
content, // Initial content with bash placeholders
|
|
500
|
-
});
|
|
501
|
-
|
|
502
491
|
// Parse bash commands from the content
|
|
503
492
|
const { commands, processedContent } = parseBashCommands(content);
|
|
504
493
|
|
|
@@ -512,12 +501,10 @@ export class SlashCommandManager {
|
|
|
512
501
|
);
|
|
513
502
|
}
|
|
514
503
|
|
|
515
|
-
//
|
|
516
|
-
this.messageManager.
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
content: finalContent,
|
|
520
|
-
stage: "success",
|
|
504
|
+
// Add user message with command name as display content, processed content for AI
|
|
505
|
+
this.messageManager.addUserMessage({
|
|
506
|
+
content: `/${commandName}`,
|
|
507
|
+
customCommandContent: finalContent,
|
|
521
508
|
});
|
|
522
509
|
|
|
523
510
|
// Execute the AI conversation with custom configuration
|
package/src/types/messaging.ts
CHANGED
|
@@ -25,7 +25,6 @@ export type MessageBlock =
|
|
|
25
25
|
| ToolBlock
|
|
26
26
|
| ImageBlock
|
|
27
27
|
| BangBlock
|
|
28
|
-
| SlashBlock
|
|
29
28
|
| CompressBlock
|
|
30
29
|
| ReasoningBlock
|
|
31
30
|
| FileHistoryBlock;
|
|
@@ -33,20 +32,10 @@ export type MessageBlock =
|
|
|
33
32
|
export interface TextBlock {
|
|
34
33
|
type: "text";
|
|
35
34
|
content: string;
|
|
35
|
+
customCommandContent?: string;
|
|
36
36
|
source?: MessageSource;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export interface SlashBlock {
|
|
40
|
-
type: "slash";
|
|
41
|
-
command: string;
|
|
42
|
-
args?: string;
|
|
43
|
-
content?: string; // The expanded prompt (template + args + bash output)
|
|
44
|
-
result?: string; // The final output (e.g., from a forked skill)
|
|
45
|
-
stage: "running" | "success" | "error" | "aborted";
|
|
46
|
-
error?: string;
|
|
47
|
-
shortResult?: string; // Progress summary (e.g., "3 tools | 1,234 tokens")
|
|
48
|
-
}
|
|
49
|
-
|
|
50
39
|
export interface ErrorBlock {
|
|
51
40
|
type: "error";
|
|
52
41
|
content: string;
|
|
@@ -191,28 +191,13 @@ export function convertMessagesForAPI(
|
|
|
191
191
|
block.content &&
|
|
192
192
|
block.content.trim().length > 0
|
|
193
193
|
) {
|
|
194
|
+
const textForApi = block.customCommandContent ?? block.content;
|
|
194
195
|
contentParts.push({
|
|
195
196
|
type: "text",
|
|
196
|
-
text:
|
|
197
|
+
text: textForApi,
|
|
197
198
|
});
|
|
198
199
|
}
|
|
199
200
|
|
|
200
|
-
// Handle SlashBlock
|
|
201
|
-
if (block.type === "slash") {
|
|
202
|
-
if (block.content && block.content.trim().length > 0) {
|
|
203
|
-
contentParts.push({
|
|
204
|
-
type: "text",
|
|
205
|
-
text: block.content,
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
if (block.result && block.result.trim().length > 0) {
|
|
209
|
-
contentParts.push({
|
|
210
|
-
type: "text",
|
|
211
|
-
text: `<local-command-stdout>\n${stripAnsiColors(block.result)}\n</local-command-stdout>`,
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
201
|
// If there is an image, add image content
|
|
217
202
|
if (
|
|
218
203
|
block.type === "image" &&
|
|
@@ -9,6 +9,7 @@ import { logger } from "./globalLogger.js";
|
|
|
9
9
|
// Base user message parameters interface
|
|
10
10
|
export interface UserMessageParams {
|
|
11
11
|
content: string;
|
|
12
|
+
customCommandContent?: string;
|
|
12
13
|
images?: Array<{ path: string; mimeType: string }>;
|
|
13
14
|
source?: MessageSource;
|
|
14
15
|
isMeta?: boolean;
|
|
@@ -20,26 +21,6 @@ export interface AddUserMessageParams extends UserMessageParams {
|
|
|
20
21
|
id?: string;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
export interface AddSlashParams {
|
|
24
|
-
messages: Message[];
|
|
25
|
-
command: string;
|
|
26
|
-
args?: string;
|
|
27
|
-
content?: string;
|
|
28
|
-
id?: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface UpdateSlashParams {
|
|
32
|
-
messages: Message[];
|
|
33
|
-
command: string;
|
|
34
|
-
messageId?: string;
|
|
35
|
-
args?: string;
|
|
36
|
-
content?: string;
|
|
37
|
-
result?: string;
|
|
38
|
-
stage?: "running" | "success" | "error" | "aborted";
|
|
39
|
-
error?: string;
|
|
40
|
-
shortResult?: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
24
|
export interface UpdateToolBlockParams {
|
|
44
25
|
messages: Message[];
|
|
45
26
|
id: string;
|
|
@@ -142,6 +123,7 @@ export const generateMessageId = (): string => `msg-${randomUUID()}`;
|
|
|
142
123
|
export const addUserMessageToMessages = ({
|
|
143
124
|
messages,
|
|
144
125
|
content,
|
|
126
|
+
customCommandContent,
|
|
145
127
|
images,
|
|
146
128
|
source,
|
|
147
129
|
id,
|
|
@@ -149,10 +131,11 @@ export const addUserMessageToMessages = ({
|
|
|
149
131
|
}: AddUserMessageParams): Message[] => {
|
|
150
132
|
const blocks: Message["blocks"] = [];
|
|
151
133
|
|
|
152
|
-
// Create text block with optional source
|
|
134
|
+
// Create text block with optional source and customCommandContent
|
|
153
135
|
const textBlock = {
|
|
154
136
|
type: "text" as const,
|
|
155
137
|
content,
|
|
138
|
+
...(customCommandContent && { customCommandContent }),
|
|
156
139
|
...(source && { source }),
|
|
157
140
|
};
|
|
158
141
|
blocks.push(textBlock);
|
|
@@ -175,95 +158,6 @@ export const addUserMessageToMessages = ({
|
|
|
175
158
|
return [...messages, userMessage];
|
|
176
159
|
};
|
|
177
160
|
|
|
178
|
-
/**
|
|
179
|
-
* Add a slash command message to the conversation.
|
|
180
|
-
*/
|
|
181
|
-
export const addSlashMessageToMessages = ({
|
|
182
|
-
messages,
|
|
183
|
-
command,
|
|
184
|
-
args,
|
|
185
|
-
content,
|
|
186
|
-
id,
|
|
187
|
-
}: AddSlashParams): Message[] => {
|
|
188
|
-
const slashMessage: Message = {
|
|
189
|
-
id: id || generateMessageId(),
|
|
190
|
-
role: "user",
|
|
191
|
-
blocks: [
|
|
192
|
-
{
|
|
193
|
-
type: "slash",
|
|
194
|
-
command,
|
|
195
|
-
args,
|
|
196
|
-
content,
|
|
197
|
-
stage: "running",
|
|
198
|
-
},
|
|
199
|
-
],
|
|
200
|
-
};
|
|
201
|
-
return [...messages, slashMessage];
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Update a slash block in a message.
|
|
206
|
-
*/
|
|
207
|
-
export const updateSlashBlockInMessage = ({
|
|
208
|
-
messages,
|
|
209
|
-
command,
|
|
210
|
-
messageId,
|
|
211
|
-
args,
|
|
212
|
-
content,
|
|
213
|
-
result,
|
|
214
|
-
stage,
|
|
215
|
-
error,
|
|
216
|
-
shortResult,
|
|
217
|
-
}: UpdateSlashParams): Message[] => {
|
|
218
|
-
const newMessages = [...messages];
|
|
219
|
-
|
|
220
|
-
// If messageId is provided, target that specific message
|
|
221
|
-
if (messageId) {
|
|
222
|
-
const messageIndex = newMessages.findIndex((msg) => msg.id === messageId);
|
|
223
|
-
if (messageIndex !== -1) {
|
|
224
|
-
const slashBlockIndex = newMessages[messageIndex].blocks.findIndex(
|
|
225
|
-
(block) => block.type === "slash" && block.command === command,
|
|
226
|
-
);
|
|
227
|
-
|
|
228
|
-
if (slashBlockIndex !== -1) {
|
|
229
|
-
const slashBlock = newMessages[messageIndex].blocks[slashBlockIndex];
|
|
230
|
-
if (slashBlock.type === "slash") {
|
|
231
|
-
if (args !== undefined) slashBlock.args = args;
|
|
232
|
-
if (content !== undefined) slashBlock.content = content;
|
|
233
|
-
if (result !== undefined) slashBlock.result = result;
|
|
234
|
-
if (stage !== undefined) slashBlock.stage = stage;
|
|
235
|
-
if (error !== undefined) slashBlock.error = error;
|
|
236
|
-
if (shortResult !== undefined) slashBlock.shortResult = shortResult;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return newMessages;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// Find the last user message with a slash block for this command
|
|
244
|
-
for (let i = newMessages.length - 1; i >= 0; i--) {
|
|
245
|
-
const msg = newMessages[i];
|
|
246
|
-
if (msg.role === "user") {
|
|
247
|
-
const slashBlockIndex = msg.blocks.findIndex(
|
|
248
|
-
(block) => block.type === "slash" && block.command === command,
|
|
249
|
-
);
|
|
250
|
-
if (slashBlockIndex !== -1) {
|
|
251
|
-
const slashBlock = msg.blocks[slashBlockIndex];
|
|
252
|
-
if (slashBlock.type === "slash") {
|
|
253
|
-
if (args !== undefined) slashBlock.args = args;
|
|
254
|
-
if (content !== undefined) slashBlock.content = content;
|
|
255
|
-
if (result !== undefined) slashBlock.result = result;
|
|
256
|
-
if (stage !== undefined) slashBlock.stage = stage;
|
|
257
|
-
if (error !== undefined) slashBlock.error = error;
|
|
258
|
-
if (shortResult !== undefined) slashBlock.shortResult = shortResult;
|
|
259
|
-
}
|
|
260
|
-
break;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
return newMessages;
|
|
265
|
-
};
|
|
266
|
-
|
|
267
161
|
/**
|
|
268
162
|
* Update a user message's content by its ID.
|
|
269
163
|
*/
|
|
@@ -279,6 +173,9 @@ export const updateUserMessageInMessages = (
|
|
|
279
173
|
return {
|
|
280
174
|
...block,
|
|
281
175
|
...(params.content !== undefined && { content: params.content }),
|
|
176
|
+
...(params.customCommandContent !== undefined && {
|
|
177
|
+
customCommandContent: params.customCommandContent,
|
|
178
|
+
}),
|
|
282
179
|
...(params.source !== undefined && { source: params.source }),
|
|
283
180
|
};
|
|
284
181
|
}
|
|
@@ -669,11 +566,6 @@ export function getMessageContent(message: Message): string {
|
|
|
669
566
|
return textBlock.content;
|
|
670
567
|
}
|
|
671
568
|
|
|
672
|
-
const slashBlock = message.blocks.find((block) => block.type === "slash");
|
|
673
|
-
if (slashBlock && "command" in slashBlock) {
|
|
674
|
-
return `/${slashBlock.command}${slashBlock.args ? ` ${slashBlock.args}` : ""}`;
|
|
675
|
-
}
|
|
676
|
-
|
|
677
569
|
const bangBlock = message.blocks.find((block) => block.type === "bang");
|
|
678
570
|
if (bangBlock && "command" in bangBlock) {
|
|
679
571
|
return `!${bangBlock.command}`;
|