@friendlyrobot/discord-pi-agent 0.19.4 → 0.19.5
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 +39 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -326,7 +326,8 @@ async function runAgentTurn(session, prompt, options = {}) {
|
|
|
326
326
|
if (event.toolName === "bash") {
|
|
327
327
|
logger4.debug({
|
|
328
328
|
toolName: event.toolName
|
|
329
|
-
}, `agent tool start: [${event.toolName}]
|
|
329
|
+
}, `agent tool start: [${event.toolName}]`);
|
|
330
|
+
debugPrint(input, "CMD");
|
|
330
331
|
} else {
|
|
331
332
|
logger4.debug({
|
|
332
333
|
toolName: event.toolName,
|
|
@@ -338,10 +339,6 @@ async function runAgentTurn(session, prompt, options = {}) {
|
|
|
338
339
|
const input = toolInputsByCallId.get(event.toolCallId);
|
|
339
340
|
toolInputsByCallId.delete(event.toolCallId);
|
|
340
341
|
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
342
|
debugPrint(extractToolOutput(event.result), event.isError ? "BASH TOOL ERROR OUTPUT" : "BASH TOOL OUTPUT");
|
|
346
343
|
} else {
|
|
347
344
|
logger4.debug({
|
|
@@ -379,14 +376,48 @@ function truncateForLog(value, maxLength = 400) {
|
|
|
379
376
|
}
|
|
380
377
|
function extractToolOutput(output) {
|
|
381
378
|
if (typeof output === "string") {
|
|
379
|
+
const parsed = tryParseJson(output);
|
|
380
|
+
if (parsed !== undefined && typeof parsed === "object" && parsed !== null) {
|
|
381
|
+
return extractTextFromObject(parsed) ?? output;
|
|
382
|
+
}
|
|
382
383
|
return output;
|
|
383
384
|
}
|
|
385
|
+
if (typeof output === "object" && output !== null) {
|
|
386
|
+
return extractTextFromObject(output) ?? JSON.stringify(output);
|
|
387
|
+
}
|
|
388
|
+
return String(output);
|
|
389
|
+
}
|
|
390
|
+
function tryParseJson(value) {
|
|
384
391
|
try {
|
|
385
|
-
return JSON.
|
|
392
|
+
return JSON.parse(value);
|
|
386
393
|
} catch {
|
|
387
|
-
return
|
|
394
|
+
return;
|
|
388
395
|
}
|
|
389
396
|
}
|
|
397
|
+
var TEXT_BEARING_FIELDS = [
|
|
398
|
+
"text",
|
|
399
|
+
"content",
|
|
400
|
+
"message",
|
|
401
|
+
"output",
|
|
402
|
+
"result"
|
|
403
|
+
];
|
|
404
|
+
function extractTextFromObject(obj) {
|
|
405
|
+
for (const field of TEXT_BEARING_FIELDS) {
|
|
406
|
+
if (field in obj) {
|
|
407
|
+
const value = obj[field];
|
|
408
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
409
|
+
return value;
|
|
410
|
+
}
|
|
411
|
+
if (typeof value === "object" && value !== null) {
|
|
412
|
+
const nested = extractTextFromObject(value);
|
|
413
|
+
if (nested !== null) {
|
|
414
|
+
return nested;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return null;
|
|
420
|
+
}
|
|
390
421
|
function getLatestAssistantText(messages) {
|
|
391
422
|
const latestAssistantMessage = [...messages].reverse().find((message) => {
|
|
392
423
|
return message.role === "assistant";
|
|
@@ -663,12 +694,7 @@ function parseStringArrayFromEnv(key) {
|
|
|
663
694
|
}
|
|
664
695
|
|
|
665
696
|
// src/discord-gateway-client.ts
|
|
666
|
-
import {
|
|
667
|
-
Client,
|
|
668
|
-
Events,
|
|
669
|
-
GatewayIntentBits,
|
|
670
|
-
Partials
|
|
671
|
-
} from "discord.js";
|
|
697
|
+
import { Client, Events, GatewayIntentBits, Partials } from "discord.js";
|
|
672
698
|
|
|
673
699
|
// src/session-commands.ts
|
|
674
700
|
function getSessionStatusText(session, promptQueue, extras) {
|