@friendlyrobot/discord-pi-agent 0.19.5 → 0.19.7

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.
Files changed (2) hide show
  1. package/dist/index.js +22 -31
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -375,17 +375,15 @@ function truncateForLog(value, maxLength = 400) {
375
375
  return `${value.slice(0, maxLength)}...`;
376
376
  }
377
377
  function extractToolOutput(output) {
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
- }
383
- return output;
378
+ if (typeof output !== "string") {
379
+ return typeof output === "object" && output !== null ? JSON.stringify(output) : String(output);
384
380
  }
385
- if (typeof output === "object" && output !== null) {
386
- return extractTextFromObject(output) ?? JSON.stringify(output);
381
+ const parsed = tryParseJson(output);
382
+ if (parsed === undefined) {
383
+ return output;
387
384
  }
388
- return String(output);
385
+ const text = extractContentArrayText(parsed);
386
+ return text ?? output;
389
387
  }
390
388
  function tryParseJson(value) {
391
389
  try {
@@ -394,29 +392,22 @@ function tryParseJson(value) {
394
392
  return;
395
393
  }
396
394
  }
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
- }
395
+ function extractContentArrayText(value) {
396
+ if (value === null || typeof value !== "object") {
397
+ return null;
418
398
  }
419
- return null;
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("");
420
411
  }
421
412
  function getLatestAssistantText(messages) {
422
413
  const latestAssistantMessage = [...messages].reverse().find((message) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@friendlyrobot/discord-pi-agent",
3
- "version": "0.19.5",
3
+ "version": "0.19.7",
4
4
  "description": "Reusable Discord gateway for persistent pi agent sessions",
5
5
  "license": "MIT",
6
6
  "type": "module",