@friendlyrobot/discord-pi-agent 0.19.7 → 0.19.9
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 +14 -30
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -375,39 +375,23 @@ function truncateForLog(value, maxLength = 400) {
|
|
|
375
375
|
return `${value.slice(0, maxLength)}...`;
|
|
376
376
|
}
|
|
377
377
|
function extractToolOutput(output) {
|
|
378
|
-
|
|
379
|
-
return typeof output === "object" && output !== null ? JSON.stringify(output) : String(output);
|
|
380
|
-
}
|
|
381
|
-
const parsed = tryParseJson(output);
|
|
382
|
-
if (parsed === undefined) {
|
|
383
|
-
return output;
|
|
384
|
-
}
|
|
385
|
-
const text = extractContentArrayText(parsed);
|
|
386
|
-
return text ?? output;
|
|
387
|
-
}
|
|
388
|
-
function tryParseJson(value) {
|
|
378
|
+
let processed = output;
|
|
389
379
|
try {
|
|
390
|
-
|
|
380
|
+
processed = JSON.parse(output);
|
|
381
|
+
if (Array.isArray(processed)) {
|
|
382
|
+
return processed.map((item) => {
|
|
383
|
+
if (item?.type === "text") {
|
|
384
|
+
return item.text;
|
|
385
|
+
} else {
|
|
386
|
+
return JSON.stringify(item);
|
|
387
|
+
}
|
|
388
|
+
}).join(`
|
|
389
|
+
`);
|
|
390
|
+
}
|
|
391
|
+
return String(output);
|
|
391
392
|
} catch {
|
|
392
|
-
return;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
function extractContentArrayText(value) {
|
|
396
|
-
if (value === null || typeof value !== "object") {
|
|
397
|
-
return null;
|
|
398
|
-
}
|
|
399
|
-
if (!("content" in value)) {
|
|
400
|
-
return null;
|
|
393
|
+
return String(output);
|
|
401
394
|
}
|
|
402
|
-
const content = value.content;
|
|
403
|
-
if (!Array.isArray(content)) {
|
|
404
|
-
return null;
|
|
405
|
-
}
|
|
406
|
-
return content.filter((item) => {
|
|
407
|
-
return typeof item === "object" && item !== null && "type" in item && "text" in item && item.type === "text";
|
|
408
|
-
}).map((item) => {
|
|
409
|
-
return item.text;
|
|
410
|
-
}).join("");
|
|
411
395
|
}
|
|
412
396
|
function getLatestAssistantText(messages) {
|
|
413
397
|
const latestAssistantMessage = [...messages].reverse().find((message) => {
|