@friendlyrobot/discord-pi-agent 0.19.3 → 0.19.4
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/index.js +43 -8
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -308,6 +308,7 @@ async function runAgentTurn(session, prompt, options = {}) {
|
|
|
308
308
|
let streamedText = "";
|
|
309
309
|
let eventCount = 0;
|
|
310
310
|
let toolCount = 0;
|
|
311
|
+
const toolInputsByCallId = new Map;
|
|
311
312
|
const model = session.model ? `${session.model.provider}/${session.model.id}` : "none";
|
|
312
313
|
debugPrint(prompt, "Full Prompt");
|
|
313
314
|
const unsubscribe = session.subscribe((event) => {
|
|
@@ -321,16 +322,34 @@ async function runAgentTurn(session, prompt, options = {}) {
|
|
|
321
322
|
if (event.type === "tool_execution_start") {
|
|
322
323
|
toolCount += 1;
|
|
323
324
|
const input = event.toolName === "bash" ? event.args.command : event.args;
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
325
|
+
toolInputsByCallId.set(event.toolCallId, input);
|
|
326
|
+
if (event.toolName === "bash") {
|
|
327
|
+
logger4.debug({
|
|
328
|
+
toolName: event.toolName
|
|
329
|
+
}, `agent tool start: [${event.toolName}] ${String(input)}`);
|
|
330
|
+
} else {
|
|
331
|
+
logger4.debug({
|
|
332
|
+
toolName: event.toolName,
|
|
333
|
+
input
|
|
334
|
+
}, `agent tool start: [${event.toolName}]`);
|
|
335
|
+
}
|
|
328
336
|
}
|
|
329
337
|
if (event.type === "tool_execution_end") {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
338
|
+
const input = toolInputsByCallId.get(event.toolCallId);
|
|
339
|
+
toolInputsByCallId.delete(event.toolCallId);
|
|
340
|
+
if (event.toolName === "bash") {
|
|
341
|
+
logger4.debug({
|
|
342
|
+
toolName: event.toolName,
|
|
343
|
+
isError: event.isError
|
|
344
|
+
}, `agent tool end: [${event.toolName}] ${truncateForLog(typeof input === "string" ? input : "")}`);
|
|
345
|
+
debugPrint(extractToolOutput(event.result), event.isError ? "BASH TOOL ERROR OUTPUT" : "BASH TOOL OUTPUT");
|
|
346
|
+
} else {
|
|
347
|
+
logger4.debug({
|
|
348
|
+
toolName: event.toolName,
|
|
349
|
+
input: truncateForLog(extractToolOutput(input)),
|
|
350
|
+
isError: event.isError
|
|
351
|
+
}, `agent tool end: [${event.toolName}]`);
|
|
352
|
+
}
|
|
334
353
|
}
|
|
335
354
|
});
|
|
336
355
|
try {
|
|
@@ -352,6 +371,22 @@ async function runAgentTurn(session, prompt, options = {}) {
|
|
|
352
371
|
}
|
|
353
372
|
return "No response generated.";
|
|
354
373
|
}
|
|
374
|
+
function truncateForLog(value, maxLength = 400) {
|
|
375
|
+
if (value.length <= maxLength) {
|
|
376
|
+
return value;
|
|
377
|
+
}
|
|
378
|
+
return `${value.slice(0, maxLength)}...`;
|
|
379
|
+
}
|
|
380
|
+
function extractToolOutput(output) {
|
|
381
|
+
if (typeof output === "string") {
|
|
382
|
+
return output;
|
|
383
|
+
}
|
|
384
|
+
try {
|
|
385
|
+
return JSON.stringify(output);
|
|
386
|
+
} catch {
|
|
387
|
+
return String(output);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
355
390
|
function getLatestAssistantText(messages) {
|
|
356
391
|
const latestAssistantMessage = [...messages].reverse().find((message) => {
|
|
357
392
|
return message.role === "assistant";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friendlyrobot/discord-pi-agent",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.4",
|
|
4
4
|
"description": "Reusable Discord gateway for persistent pi agent sessions",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
|
-
"test:watch": "vitest",
|
|
29
|
-
"test": "vitest run",
|
|
30
|
-
"test:coverage": "vitest run --coverage",
|
|
28
|
+
"test:watch": "LOG_LEVEL=debug vitest",
|
|
29
|
+
"test": "LOG_LEVEL=silent vitest run",
|
|
30
|
+
"test:coverage": "LOG_LEVEL=silent vitest run --coverage",
|
|
31
31
|
"format": "prettier --write .",
|
|
32
32
|
"build:01-clean": "rm -rf dist",
|
|
33
33
|
"build:02-tsgo": "tsgo -p tsconfig.build.json --emitDeclarationOnly --declaration --declarationMap false",
|