@friendlyrobot/discord-pi-agent 0.19.6 → 0.19.8
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 +3 -28
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -375,39 +375,14 @@ function truncateForLog(value, maxLength = 400) {
|
|
|
375
375
|
return `${value.slice(0, maxLength)}...`;
|
|
376
376
|
}
|
|
377
377
|
function extractToolOutput(output) {
|
|
378
|
-
if (typeof output
|
|
379
|
-
return typeof output === "object" && output !== null ? JSON.stringify(output) : String(output);
|
|
380
|
-
}
|
|
381
|
-
const parsed = tryParseJson(output);
|
|
382
|
-
if (parsed === undefined) {
|
|
378
|
+
if (typeof output === "string") {
|
|
383
379
|
return output;
|
|
384
380
|
}
|
|
385
|
-
const text = extractContentArrayText(parsed);
|
|
386
|
-
return text ?? output;
|
|
387
|
-
}
|
|
388
|
-
function tryParseJson(value) {
|
|
389
381
|
try {
|
|
390
|
-
return JSON.
|
|
382
|
+
return JSON.stringify(output);
|
|
391
383
|
} catch {
|
|
392
|
-
return;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
function extractContentArrayText(value) {
|
|
396
|
-
if (value === null || typeof value !== "object") {
|
|
397
|
-
return null;
|
|
384
|
+
return String(output);
|
|
398
385
|
}
|
|
399
|
-
if (!("content" in value)) {
|
|
400
|
-
return null;
|
|
401
|
-
}
|
|
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
386
|
}
|
|
412
387
|
function getLatestAssistantText(messages) {
|
|
413
388
|
const latestAssistantMessage = [...messages].reverse().find((message) => {
|