@xalia/agent 0.6.0 → 0.6.2
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/src/agent/agent.js +103 -54
- package/dist/agent/src/agent/agentUtils.js +22 -21
- package/dist/agent/src/agent/compressingContextManager.js +3 -2
- package/dist/agent/src/agent/dummyLLM.js +1 -3
- package/dist/agent/src/agent/imageGenLLM.js +67 -0
- package/dist/agent/src/agent/imageGenerator.js +43 -0
- package/dist/agent/src/agent/llm.js +27 -0
- package/dist/agent/src/agent/mcpServerManager.js +18 -6
- package/dist/agent/src/agent/nullAgentEventHandler.js +6 -0
- package/dist/agent/src/agent/openAILLM.js +3 -3
- package/dist/agent/src/agent/openAILLMStreaming.js +41 -6
- package/dist/agent/src/chat/client/chatClient.js +84 -13
- package/dist/agent/src/chat/client/sessionClient.js +47 -6
- package/dist/agent/src/chat/client/sessionFiles.js +102 -0
- package/dist/agent/src/chat/data/apiKeyManager.js +38 -7
- package/dist/agent/src/chat/data/database.js +83 -70
- package/dist/agent/src/chat/data/dbSessionFileModels.js +49 -0
- package/dist/agent/src/chat/data/dbSessionFiles.js +76 -0
- package/dist/agent/src/chat/data/dbSessionMessages.js +57 -0
- package/dist/agent/src/chat/data/mimeTypes.js +44 -0
- package/dist/agent/src/chat/protocol/messages.js +21 -0
- package/dist/agent/src/chat/server/chatContextManager.js +14 -7
- package/dist/agent/src/chat/server/connectionManager.js +14 -36
- package/dist/agent/src/chat/server/connectionManager.test.js +2 -16
- package/dist/agent/src/chat/server/conversation.js +69 -45
- package/dist/agent/src/chat/server/imageGeneratorTools.js +111 -0
- package/dist/agent/src/chat/server/openSession.js +205 -43
- package/dist/agent/src/chat/server/server.js +5 -8
- package/dist/agent/src/chat/server/sessionFileManager.js +171 -38
- package/dist/agent/src/chat/server/sessionRegistry.js +199 -32
- package/dist/agent/src/chat/server/test-utils/mockFactories.js +12 -11
- package/dist/agent/src/chat/server/tools.js +27 -6
- package/dist/agent/src/chat/utils/multiAsyncQueue.js +9 -1
- package/dist/agent/src/test/agent.test.js +15 -11
- package/dist/agent/src/test/chatContextManager.test.js +4 -0
- package/dist/agent/src/test/clientServerConnection.test.js +2 -2
- package/dist/agent/src/test/db.test.js +33 -70
- package/dist/agent/src/test/dbSessionFiles.test.js +179 -0
- package/dist/agent/src/test/dbSessionMessages.test.js +67 -0
- package/dist/agent/src/test/dbTestTools.js +6 -5
- package/dist/agent/src/test/imageLoad.test.js +1 -1
- package/dist/agent/src/test/mcpServerManager.test.js +1 -1
- package/dist/agent/src/test/multiAsyncQueue.test.js +50 -0
- package/dist/agent/src/test/testTools.js +12 -0
- package/dist/agent/src/tool/agentChat.js +25 -6
- package/dist/agent/src/tool/agentMain.js +1 -1
- package/dist/agent/src/tool/chatMain.js +113 -4
- package/dist/agent/src/tool/commandPrompt.js +7 -3
- package/dist/agent/src/tool/files.js +23 -15
- package/dist/agent/src/tool/options.js +2 -2
- package/package.json +1 -1
- package/scripts/test_chat +124 -66
- package/src/agent/agent.ts +145 -38
- package/src/agent/agentUtils.ts +27 -21
- package/src/agent/compressingContextManager.ts +5 -4
- package/src/agent/context.ts +1 -1
- package/src/agent/dummyLLM.ts +1 -3
- package/src/agent/iAgentEventHandler.ts +15 -2
- package/src/agent/imageGenLLM.ts +99 -0
- package/src/agent/imageGenerator.ts +60 -0
- package/src/agent/llm.ts +128 -4
- package/src/agent/mcpServerManager.ts +26 -7
- package/src/agent/nullAgentEventHandler.ts +6 -0
- package/src/agent/openAILLM.ts +3 -8
- package/src/agent/openAILLMStreaming.ts +60 -14
- package/src/chat/client/chatClient.ts +119 -14
- package/src/chat/client/sessionClient.ts +75 -9
- package/src/chat/client/sessionFiles.ts +145 -0
- package/src/chat/data/apiKeyManager.ts +55 -7
- package/src/chat/data/dataModels.ts +16 -7
- package/src/chat/data/database.ts +107 -92
- package/src/chat/data/dbSessionFileModels.ts +91 -0
- package/src/chat/data/dbSessionFiles.ts +99 -0
- package/src/chat/data/dbSessionMessages.ts +68 -0
- package/src/chat/data/mimeTypes.ts +58 -0
- package/src/chat/protocol/messages.ts +127 -13
- package/src/chat/server/chatContextManager.ts +36 -13
- package/src/chat/server/connectionManager.test.ts +1 -22
- package/src/chat/server/connectionManager.ts +18 -53
- package/src/chat/server/conversation.ts +96 -57
- package/src/chat/server/imageGeneratorTools.ts +138 -0
- package/src/chat/server/openSession.ts +287 -49
- package/src/chat/server/server.ts +5 -11
- package/src/chat/server/sessionFileManager.ts +223 -63
- package/src/chat/server/sessionRegistry.ts +285 -41
- package/src/chat/server/test-utils/mockFactories.ts +13 -13
- package/src/chat/server/tools.ts +43 -8
- package/src/chat/utils/agentSessionMap.ts +2 -2
- package/src/chat/utils/multiAsyncQueue.ts +11 -1
- package/src/test/agent.test.ts +23 -14
- package/src/test/chatContextManager.test.ts +7 -2
- package/src/test/clientServerConnection.test.ts +3 -3
- package/src/test/compressingContextManager.test.ts +1 -1
- package/src/test/context.test.ts +2 -1
- package/src/test/conversation.test.ts +1 -1
- package/src/test/db.test.ts +41 -83
- package/src/test/dbSessionFiles.test.ts +258 -0
- package/src/test/dbSessionMessages.test.ts +85 -0
- package/src/test/dbTestTools.ts +9 -5
- package/src/test/imageLoad.test.ts +2 -2
- package/src/test/mcpServerManager.test.ts +3 -1
- package/src/test/multiAsyncQueue.test.ts +58 -0
- package/src/test/testTools.ts +15 -1
- package/src/tool/agentChat.ts +35 -7
- package/src/tool/agentMain.ts +7 -7
- package/src/tool/chatMain.ts +126 -5
- package/src/tool/commandPrompt.ts +10 -5
- package/src/tool/files.ts +30 -13
- package/src/tool/options.ts +1 -1
- package/test_data/dummyllm_script_image_gen.json +19 -0
- package/test_data/dummyllm_script_invoke_image_gen_tool.json +30 -0
- package/test_data/image_gen_test_profile.json +5 -0
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DEFAULT_AGENT_LLM_MODEL = void 0;
|
|
6
7
|
exports.runChat = runChat;
|
|
7
8
|
const yocto_spinner_1 = __importDefault(require("yocto-spinner"));
|
|
8
9
|
const chalk_1 = __importDefault(require("chalk"));
|
|
@@ -15,6 +16,7 @@ const commandPrompt_1 = require("./commandPrompt");
|
|
|
15
16
|
const prompt_1 = require("./prompt");
|
|
16
17
|
const context_1 = require("../agent/context");
|
|
17
18
|
const logger = (0, sdk_1.getLogger)();
|
|
19
|
+
exports.DEFAULT_AGENT_LLM_MODEL = process.env["DEFAULT_LLM_MODEL"] || "anthropic/claude-sonnet-4.5";
|
|
18
20
|
async function write(msg) {
|
|
19
21
|
return new Promise((resolve, err) => {
|
|
20
22
|
process.stdout.write(msg, (e) => {
|
|
@@ -32,14 +34,15 @@ async function runChat(llmUrl, agentProfile, conversation, prompt, image, llmApi
|
|
|
32
34
|
// unless approveTools is set.
|
|
33
35
|
const spinner = (0, yocto_spinner_1.default)();
|
|
34
36
|
let first = true;
|
|
37
|
+
let reasoningFirst = true;
|
|
35
38
|
const onAgentMessage = async (msg, msgEnd) => {
|
|
36
39
|
if (first) {
|
|
37
40
|
first = false;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (spinner) {
|
|
41
|
-
spinner.stop().clear();
|
|
41
|
+
if (!reasoningFirst) {
|
|
42
|
+
await write(`${chalk_1.default.grey("]")}\n`);
|
|
42
43
|
}
|
|
44
|
+
await write("AGENT: ");
|
|
45
|
+
spinner.stop().clear();
|
|
43
46
|
}
|
|
44
47
|
if (msg) {
|
|
45
48
|
await write(msg);
|
|
@@ -47,8 +50,18 @@ async function runChat(llmUrl, agentProfile, conversation, prompt, image, llmApi
|
|
|
47
50
|
if (msgEnd) {
|
|
48
51
|
await write("\n");
|
|
49
52
|
first = true;
|
|
53
|
+
reasoningFirst = true;
|
|
50
54
|
}
|
|
51
55
|
};
|
|
56
|
+
const onReasoning = async (reasoning) => {
|
|
57
|
+
logger.debug(`[AgentChat.onReasoning]: ${reasoning}`);
|
|
58
|
+
if (reasoningFirst) {
|
|
59
|
+
spinner.stop().clear();
|
|
60
|
+
await write(chalk_1.default.grey("[REASONING: "));
|
|
61
|
+
reasoningFirst = false;
|
|
62
|
+
}
|
|
63
|
+
await write(chalk_1.default.grey(reasoning));
|
|
64
|
+
};
|
|
52
65
|
const repl = new prompt_1.Prompt();
|
|
53
66
|
const cmdPrompt = new commandPrompt_1.CommandPrompt(repl);
|
|
54
67
|
let remainingApprovedToolCalls = approveToolsUpTo;
|
|
@@ -66,15 +79,21 @@ async function runChat(llmUrl, agentProfile, conversation, prompt, image, llmApi
|
|
|
66
79
|
// CLI doesn't need to display tool results - they're handled internally
|
|
67
80
|
logger.debug(`Tool call result: ${JSON.stringify(result)}`);
|
|
68
81
|
};
|
|
82
|
+
const onImage = (image) => {
|
|
83
|
+
const dataUrl = image.image_url.url;
|
|
84
|
+
void nodePlatform_1.NODE_PLATFORM.renderHTML(`<img src="${dataUrl}" />`);
|
|
85
|
+
};
|
|
69
86
|
// Create event handler for CLI agent
|
|
70
87
|
const eventHandler = {
|
|
71
88
|
onCompletion: () => { },
|
|
89
|
+
onImage,
|
|
72
90
|
onAgentMessage,
|
|
91
|
+
onReasoning,
|
|
73
92
|
onToolCall,
|
|
74
93
|
onToolCallResult,
|
|
75
94
|
};
|
|
76
95
|
// Create agent
|
|
77
|
-
const [agent, sudoMcpServerManager] = await (0, agentUtils_1.createAgentWithSkills)(llmUrl, agentProfile, eventHandler, nodePlatform_1.NODE_PLATFORM, new context_1.ContextManager(agentProfile.system_prompt, conversation || []), llmApiKey, sudomcpConfig, tool_1.utils.FRONTEND_PROD_AUTHORIZED_URL, stream);
|
|
96
|
+
const [agent, sudoMcpServerManager] = await (0, agentUtils_1.createAgentWithSkills)(llmUrl, agentProfile, exports.DEFAULT_AGENT_LLM_MODEL, eventHandler, nodePlatform_1.NODE_PLATFORM, new context_1.ContextManager(agentProfile.system_prompt, conversation || []), llmApiKey, sudomcpConfig, tool_1.utils.FRONTEND_PROD_AUTHORIZED_URL, stream);
|
|
78
97
|
// Opening banner
|
|
79
98
|
console.log(chalk_1.default.green("SudoMCP Agent CLI"));
|
|
80
99
|
console.log(`(Type ${chalk_1.default.yellow("/h")} for help, ${chalk_1.default.yellow("/q")} to quit.)`);
|
|
@@ -93,7 +112,7 @@ async function runChat(llmUrl, agentProfile, conversation, prompt, image, llmApi
|
|
|
93
112
|
prompt = msg;
|
|
94
113
|
image = img;
|
|
95
114
|
}
|
|
96
|
-
image = (0, files_1.
|
|
115
|
+
image = (0, files_1.loadImageAsDataUrlOrUndefined)(image);
|
|
97
116
|
// Pass the prompt and image to the Agent
|
|
98
117
|
try {
|
|
99
118
|
spinner.start();
|
|
@@ -125,7 +125,7 @@ exports.agentMain = (0, cmd_ts_1.command)({
|
|
|
125
125
|
throw new Error("one-shot mode requires a prompt");
|
|
126
126
|
}
|
|
127
127
|
const prompt = await (0, files_1.loadFileOrStdin)(promptFile);
|
|
128
|
-
const { response, conversation } = await (0, agentUtils_1.runOneShot)(llmUrl, agentProfile, startingConversation, nodePlatform_1.NODE_PLATFORM, prompt, (0, files_1.
|
|
128
|
+
const { response, conversation } = await (0, agentUtils_1.runOneShot)(llmUrl, agentProfile, agentChat_1.DEFAULT_AGENT_LLM_MODEL, startingConversation, nodePlatform_1.NODE_PLATFORM, prompt, (0, files_1.loadImageAsDataUrlOrUndefined)(imageFile), llmApiKey, sudomcpConfig, approveToolsUpTo);
|
|
129
129
|
console.log(response);
|
|
130
130
|
if (conversationOutputFile) {
|
|
131
131
|
logger.debug(`writing conversation to ${conversationOutputFile}:`);
|
|
@@ -33,8 +33,12 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
return result;
|
|
34
34
|
};
|
|
35
35
|
})();
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
36
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
40
|
exports.chatMain = void 0;
|
|
41
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
38
42
|
const cmd_ts_1 = require("cmd-ts");
|
|
39
43
|
const process_1 = require("process");
|
|
40
44
|
const fs = __importStar(require("fs"));
|
|
@@ -44,11 +48,11 @@ const sdk_1 = require("@xalia/xmcp/sdk");
|
|
|
44
48
|
const client_1 = require("../chat/client");
|
|
45
49
|
const server_1 = require("../chat/server/server");
|
|
46
50
|
const messages_1 = require("../chat/protocol/messages");
|
|
51
|
+
const database_1 = require("../chat/data/database");
|
|
47
52
|
const prompt_1 = require("./prompt");
|
|
48
53
|
const options = __importStar(require("./options"));
|
|
49
54
|
const commandPrompt_1 = require("./commandPrompt");
|
|
50
55
|
const nodePlatform_1 = require("./nodePlatform");
|
|
51
|
-
const database_1 = require("../chat/data/database");
|
|
52
56
|
const files_1 = require("./files");
|
|
53
57
|
const logger = (0, sdk_1.getLogger)();
|
|
54
58
|
const listSessions = (0, cmd_ts_1.command)({
|
|
@@ -201,7 +205,24 @@ const client = (0, cmd_ts_1.command)({
|
|
|
201
205
|
}
|
|
202
206
|
return new prompt_1.Prompt();
|
|
203
207
|
})();
|
|
204
|
-
const
|
|
208
|
+
const helpText = `
|
|
209
|
+
${chalk_1.default.yellow("/aa <server> <tool> [1]")} Auto approve
|
|
210
|
+
${chalk_1.default.yellow("/error <msg>")} Force server error
|
|
211
|
+
${chalk_1.default.yellow("/ap <team> <user>")} Add-Participant
|
|
212
|
+
${chalk_1.default.yellow("/rp <team> <user>")} Remove-Participant
|
|
213
|
+
${chalk_1.default.yellow("/lp")} List-Participants
|
|
214
|
+
${chalk_1.default.yellow("/si [<file>]")} Write Session id to file
|
|
215
|
+
${chalk_1.default.yellow("/ct <name>")} Create Team
|
|
216
|
+
${chalk_1.default.yellow("/ci [<file>]")} Write team id to file
|
|
217
|
+
${chalk_1.default.yellow("/sw [file:a.png|data:....]")} Set workspace (no args = clear)
|
|
218
|
+
${chalk_1.default.yellow("/list-files")} List file-manager files
|
|
219
|
+
${chalk_1.default.yellow("/put-file <name> <file:...|data:...>")} Add file
|
|
220
|
+
${chalk_1.default.yellow("/delete-file <name>")} Delete file
|
|
221
|
+
${chalk_1.default.yellow("/get-file <name>")} Get file contents
|
|
222
|
+
${chalk_1.default.yellow("/share-session <file>")} Share and write access token
|
|
223
|
+
${chalk_1.default.yellow("/pause-agent <0|1>")} Pause (or unpause) the agent
|
|
224
|
+
`;
|
|
225
|
+
const cmdPrompt = new commandPrompt_1.CommandPrompt(repl, helpText);
|
|
205
226
|
const eventHandler = getCLIEventHandler(cmdPrompt);
|
|
206
227
|
const [client, sessionClient] = await (async () => {
|
|
207
228
|
const newClient = await client_1.ChatClient.init(url, apiKey, eventHandler);
|
|
@@ -217,7 +238,7 @@ const client = (0, cmd_ts_1.command)({
|
|
|
217
238
|
return [newClient, newSessionClient];
|
|
218
239
|
})();
|
|
219
240
|
logger.debug("client created");
|
|
220
|
-
const onUnknownCommand = (cmds) => {
|
|
241
|
+
const onUnknownCommand = async (cmds) => {
|
|
221
242
|
switch (cmds[0]) {
|
|
222
243
|
case "aa":
|
|
223
244
|
sessionClient.setAutoApproval(cmds[1], cmds[2], !!cmds[3]);
|
|
@@ -249,6 +270,24 @@ const client = (0, cmd_ts_1.command)({
|
|
|
249
270
|
case "sw": // Set workspace
|
|
250
271
|
setWorkspaceFromPrompt(sessionClient, cmds);
|
|
251
272
|
break;
|
|
273
|
+
case "list-files": // List files
|
|
274
|
+
listFiles(sessionClient, cmds[1]);
|
|
275
|
+
break;
|
|
276
|
+
case "put-file": // Add file
|
|
277
|
+
putFile(sessionClient, cmds.slice(1));
|
|
278
|
+
break;
|
|
279
|
+
case "delete-file": // Delete file
|
|
280
|
+
deleteFile(sessionClient, cmds[1]);
|
|
281
|
+
break;
|
|
282
|
+
case "get-file": // Get file contents
|
|
283
|
+
await getFileContents(sessionClient, cmds[1]);
|
|
284
|
+
break;
|
|
285
|
+
case "share-session":
|
|
286
|
+
await shareSession(sessionClient, cmds[1]);
|
|
287
|
+
break;
|
|
288
|
+
case "pause-agent":
|
|
289
|
+
pauseAgent(sessionClient, cmds[1]);
|
|
290
|
+
break;
|
|
252
291
|
default:
|
|
253
292
|
console.log(`error: Unknown command ${cmds[0]}`);
|
|
254
293
|
}
|
|
@@ -274,6 +313,48 @@ const client = (0, cmd_ts_1.command)({
|
|
|
274
313
|
}
|
|
275
314
|
},
|
|
276
315
|
});
|
|
316
|
+
function listFiles(sessionClient, filename) {
|
|
317
|
+
const sessionFiles = sessionClient.getSessionFiles();
|
|
318
|
+
const fileList = sessionFiles.listFiles();
|
|
319
|
+
const fileListStr = JSON.stringify(fileList, undefined, 2);
|
|
320
|
+
console.log(`Session files:\n${fileListStr}`);
|
|
321
|
+
if (filename) {
|
|
322
|
+
fs.writeFileSync(filename, fileListStr);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function putFile(sessionClient, tail) {
|
|
326
|
+
if (tail.length < 2) {
|
|
327
|
+
throw new Error(`usage: put-file <name> <content ....>`);
|
|
328
|
+
}
|
|
329
|
+
const name = tail[0];
|
|
330
|
+
let content = tail.slice(1).join(" ");
|
|
331
|
+
if (content.startsWith("file:")) {
|
|
332
|
+
content = (0, files_1.loadSessionFileAsDataUrl)(content.slice(5));
|
|
333
|
+
}
|
|
334
|
+
const sessionFiles = sessionClient.getSessionFiles();
|
|
335
|
+
sessionFiles.putFileContent(name, undefined, content);
|
|
336
|
+
}
|
|
337
|
+
function deleteFile(sessionClient, name) {
|
|
338
|
+
const sessionFiles = sessionClient.getSessionFiles();
|
|
339
|
+
sessionFiles.deleteFile(name);
|
|
340
|
+
}
|
|
341
|
+
async function getFileContents(sessionClient, name) {
|
|
342
|
+
const sessionFiles = sessionClient.getSessionFiles();
|
|
343
|
+
const dataUrl = await sessionFiles.getFileContent(name);
|
|
344
|
+
try {
|
|
345
|
+
void nodePlatform_1.NODE_PLATFORM.renderHTML(`<img src="${dataUrl}" />`);
|
|
346
|
+
}
|
|
347
|
+
catch {
|
|
348
|
+
console.log(`(render failed) file ${name}: ${dataUrl}`);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
async function shareSession(sessionClient, filename) {
|
|
352
|
+
const accessToken = await sessionClient.shareSession();
|
|
353
|
+
fs.writeFileSync(filename, accessToken);
|
|
354
|
+
}
|
|
355
|
+
function pauseAgent(sessionClient, pause) {
|
|
356
|
+
sessionClient.setAgentPaused(!!parseInt(pause));
|
|
357
|
+
}
|
|
277
358
|
function setWorkspaceFromPrompt(sessionClient, cmds) {
|
|
278
359
|
let msg = "";
|
|
279
360
|
let image = undefined;
|
|
@@ -282,7 +363,7 @@ function setWorkspaceFromPrompt(sessionClient, cmds) {
|
|
|
282
363
|
return;
|
|
283
364
|
}
|
|
284
365
|
if (cmds[1].startsWith("file:")) {
|
|
285
|
-
image = (0, files_1.
|
|
366
|
+
image = (0, files_1.loadImageAsDataUrl)(cmds[1].slice(5));
|
|
286
367
|
msg = cmds.slice(2).join(" ");
|
|
287
368
|
console.log(`setting workspace: ${msg} (image: ${image})`);
|
|
288
369
|
}
|
|
@@ -309,6 +390,7 @@ function getCLIEventHandler(cmdPrompt) {
|
|
|
309
390
|
console.error(message);
|
|
310
391
|
};
|
|
311
392
|
let startMsg = true;
|
|
393
|
+
let startReasoning = true;
|
|
312
394
|
const onMessage = async (msg, client) => {
|
|
313
395
|
let sessionClient = undefined;
|
|
314
396
|
try {
|
|
@@ -335,6 +417,9 @@ function getCLIEventHandler(cmdPrompt) {
|
|
|
335
417
|
break;
|
|
336
418
|
case "agent_msg_chunk":
|
|
337
419
|
if (startMsg) {
|
|
420
|
+
if (!startReasoning) {
|
|
421
|
+
process_1.stdout.write(chalk_1.default.grey("]\n"));
|
|
422
|
+
}
|
|
338
423
|
process_1.stdout.write("[AGENT]: ");
|
|
339
424
|
startMsg = false;
|
|
340
425
|
}
|
|
@@ -342,6 +427,16 @@ function getCLIEventHandler(cmdPrompt) {
|
|
|
342
427
|
if (msg.end) {
|
|
343
428
|
process_1.stdout.write("\n");
|
|
344
429
|
startMsg = true;
|
|
430
|
+
startReasoning = true;
|
|
431
|
+
}
|
|
432
|
+
break;
|
|
433
|
+
case "agent_reasoning_chunk":
|
|
434
|
+
if (startMsg) {
|
|
435
|
+
process_1.stdout.write(chalk_1.default.grey(`[${msg.reasoning}`));
|
|
436
|
+
startReasoning = false;
|
|
437
|
+
}
|
|
438
|
+
else {
|
|
439
|
+
process_1.stdout.write(chalk_1.default.grey(msg.reasoning));
|
|
345
440
|
}
|
|
346
441
|
break;
|
|
347
442
|
case "approve_tool_call":
|
|
@@ -353,6 +448,20 @@ function getCLIEventHandler(cmdPrompt) {
|
|
|
353
448
|
sessionClient.toolCallApprovalResult(msg.id, result, false /* auto-approve */);
|
|
354
449
|
}
|
|
355
450
|
break;
|
|
451
|
+
case "tool_call_result":
|
|
452
|
+
{
|
|
453
|
+
const metadata = msg.result.metadata;
|
|
454
|
+
if (metadata) {
|
|
455
|
+
console.log(`tool call result metadata: ${JSON.stringify(metadata)}`);
|
|
456
|
+
// SessionFiles should already hold the file information.
|
|
457
|
+
const sessionFiles = sessionClient.getSessionFiles();
|
|
458
|
+
const { name } = sessionFiles.decodeSessionFileUrl(msg.result.content);
|
|
459
|
+
if (!sessionFiles.descriptors.has(name)) {
|
|
460
|
+
throw new Error(`no ${name} in SessionFiles`);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
break;
|
|
356
465
|
case "render_html":
|
|
357
466
|
await nodePlatform_1.NODE_PLATFORM.renderHTML(msg.html);
|
|
358
467
|
break;
|
|
@@ -47,8 +47,9 @@ const tools_1 = require("../agent/tools");
|
|
|
47
47
|
* Commands are sent to an IMcpServerManager, ISkillManager and IConversation.
|
|
48
48
|
*/
|
|
49
49
|
class CommandPrompt {
|
|
50
|
-
constructor(prompt) {
|
|
50
|
+
constructor(prompt, otherHelp) {
|
|
51
51
|
this.prompt = prompt;
|
|
52
|
+
this.otherHelp = otherHelp || "";
|
|
52
53
|
}
|
|
53
54
|
shutdown() {
|
|
54
55
|
return this.prompt.shutdown();
|
|
@@ -128,6 +129,9 @@ class CommandPrompt {
|
|
|
128
129
|
case "wa":
|
|
129
130
|
this.writeAgentProfile(agent, cmds[1]);
|
|
130
131
|
break;
|
|
132
|
+
case "sleep":
|
|
133
|
+
await new Promise((r) => setTimeout(r, parseInt(cmds[1], 10)));
|
|
134
|
+
break;
|
|
131
135
|
case "h":
|
|
132
136
|
case "help":
|
|
133
137
|
case "?":
|
|
@@ -135,7 +139,7 @@ class CommandPrompt {
|
|
|
135
139
|
break;
|
|
136
140
|
default:
|
|
137
141
|
if (onUnknownCommand) {
|
|
138
|
-
onUnknownCommand(cmds);
|
|
142
|
+
await onUnknownCommand(cmds);
|
|
139
143
|
}
|
|
140
144
|
else {
|
|
141
145
|
console.log(`error: Unknown command ${cmds[0]}`);
|
|
@@ -155,7 +159,7 @@ class CommandPrompt {
|
|
|
155
159
|
write(` ${chalk_1.default.yellow("/da <server>")} Disable all tools`);
|
|
156
160
|
write(` ${chalk_1.default.yellow("/wc <file-name>")} Write conversation file`);
|
|
157
161
|
write(` ${chalk_1.default.yellow("/wa <file-name>")} Write agent profile file`);
|
|
158
|
-
write(` ${chalk_1.default.yellow("/q")} Quit`);
|
|
162
|
+
write(` ${chalk_1.default.yellow("/q")} Quit${this.otherHelp}`);
|
|
159
163
|
}
|
|
160
164
|
listTools(mcpServerManager) {
|
|
161
165
|
console.log("Mcp servers and tools (* - enabled):");
|
|
@@ -35,11 +35,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.loadFileOrUndefined = loadFileOrUndefined;
|
|
37
37
|
exports.loadFileOrStdin = loadFileOrStdin;
|
|
38
|
-
exports.
|
|
39
|
-
exports.
|
|
38
|
+
exports.loadImageAsDataUrl = loadImageAsDataUrl;
|
|
39
|
+
exports.loadSessionFileAsDataUrl = loadSessionFileAsDataUrl;
|
|
40
|
+
exports.loadImageAsDataUrlOrUndefined = loadImageAsDataUrlOrUndefined;
|
|
40
41
|
exports.loadServerUrls = loadServerUrls;
|
|
41
42
|
const fs = __importStar(require("fs"));
|
|
42
43
|
const path = __importStar(require("path"));
|
|
44
|
+
const dbSessionFileModels_1 = require("../chat/data/dbSessionFileModels");
|
|
45
|
+
const mimeTypes_1 = require("../chat/data/mimeTypes");
|
|
43
46
|
function loadFileOrUndefined(file) {
|
|
44
47
|
if (file) {
|
|
45
48
|
return fs.readFileSync(file, { encoding: "utf8" });
|
|
@@ -68,26 +71,31 @@ async function loadFileOrStdin(file) {
|
|
|
68
71
|
}
|
|
69
72
|
return fs.readFileSync(file, { encoding: "utf8" });
|
|
70
73
|
}
|
|
71
|
-
function
|
|
74
|
+
function loadImageAsDataUrl(file) {
|
|
72
75
|
const ext = path.extname(file).slice(1).toLowerCase();
|
|
73
|
-
const mimeType =
|
|
74
|
-
jpg: "image/jpeg",
|
|
75
|
-
jpeg: "image/jpeg",
|
|
76
|
-
png: "image/png",
|
|
77
|
-
gif: "image/gif",
|
|
78
|
-
svg: "image/svg+xml",
|
|
79
|
-
webp: "image/webp",
|
|
80
|
-
}[ext];
|
|
76
|
+
const mimeType = mimeTypes_1.EXTENSION_TO_IMAGE_MIME_TYPE[ext];
|
|
81
77
|
if (!mimeType) {
|
|
82
78
|
throw Error(`invalid file extension: ${ext}`);
|
|
83
79
|
}
|
|
84
80
|
const fileBuffer = fs.readFileSync(file);
|
|
85
|
-
|
|
86
|
-
return `data:${mimeType};base64,${imgB64}`;
|
|
81
|
+
return (0, mimeTypes_1.createDataUrlFromBuffer)(fileBuffer, mimeType);
|
|
87
82
|
}
|
|
88
|
-
function
|
|
83
|
+
function loadSessionFileAsDataUrl(file) {
|
|
84
|
+
const ext = path.extname(file).slice(1).toLowerCase();
|
|
85
|
+
const mimeType = dbSessionFileModels_1.EXTENSION_TO_SESSION_FILE_MIME_TYPE[ext];
|
|
86
|
+
if (!mimeType) {
|
|
87
|
+
throw Error(`invalid file extension: ${ext}`);
|
|
88
|
+
}
|
|
89
|
+
if ((0, dbSessionFileModels_1.isSessionFileTextMimeType)(mimeType)) {
|
|
90
|
+
const fileString = fs.readFileSync(file, { encoding: "utf8" });
|
|
91
|
+
return (0, dbSessionFileModels_1.createSessionFileDataUrl)(fileString, mimeType);
|
|
92
|
+
}
|
|
93
|
+
const fileBuffer = fs.readFileSync(file);
|
|
94
|
+
return (0, dbSessionFileModels_1.createSessionFileDataUrl)(fileBuffer, mimeType);
|
|
95
|
+
}
|
|
96
|
+
function loadImageAsDataUrlOrUndefined(file) {
|
|
89
97
|
if (file) {
|
|
90
|
-
return
|
|
98
|
+
return loadImageAsDataUrl(file);
|
|
91
99
|
}
|
|
92
100
|
return undefined;
|
|
93
101
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.pidFile = exports.supabaseKey = exports.supabaseUrl = exports.apiKey = exports.xmcpUrl = exports.llmUrl = exports.llmApiKey = exports.approveToolsUpTo = exports.approveTools = exports.oneShot = exports.llmModel = exports.systemPromptFile = exports.imageFile = exports.promptFile = void 0;
|
|
4
4
|
exports.secretOption = secretOption;
|
|
5
5
|
const cmd_ts_1 = require("cmd-ts");
|
|
6
|
-
const
|
|
6
|
+
const agent_1 = require("../agent/agent");
|
|
7
7
|
const database_1 = require("../chat/data/database");
|
|
8
8
|
/// Prevents env content from being displayed in the help text.
|
|
9
9
|
function secretOption({ long, short, env, description, }) {
|
|
@@ -76,7 +76,7 @@ exports.llmUrl = (0, cmd_ts_1.option)({
|
|
|
76
76
|
long: "llm-url",
|
|
77
77
|
description: "LLM provider URL (OpenAI compatible)",
|
|
78
78
|
env: "LLM_URL",
|
|
79
|
-
defaultValue: () =>
|
|
79
|
+
defaultValue: () => agent_1.DEFAULT_LLM_URL,
|
|
80
80
|
});
|
|
81
81
|
exports.xmcpUrl = (0, cmd_ts_1.option)({
|
|
82
82
|
type: cmd_ts_1.string,
|