@friendlyrobot/discord-pi-agent 0.19.4 → 0.19.6

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 +31 -14
  2. 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}] ${String(input)}`);
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({
@@ -378,15 +375,40 @@ function truncateForLog(value, maxLength = 400) {
378
375
  return `${value.slice(0, maxLength)}...`;
379
376
  }
380
377
  function extractToolOutput(output) {
381
- if (typeof output === "string") {
378
+ if (typeof output !== "string") {
379
+ return typeof output === "object" && output !== null ? JSON.stringify(output) : String(output);
380
+ }
381
+ const parsed = tryParseJson(output);
382
+ if (parsed === undefined) {
382
383
  return output;
383
384
  }
385
+ const text = extractContentArrayText(parsed);
386
+ return text ?? output;
387
+ }
388
+ function tryParseJson(value) {
384
389
  try {
385
- return JSON.stringify(output);
390
+ return JSON.parse(value);
386
391
  } catch {
387
- return String(output);
392
+ return;
388
393
  }
389
394
  }
395
+ function extractContentArrayText(value) {
396
+ if (value === null || typeof value !== "object") {
397
+ return null;
398
+ }
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
+ }
390
412
  function getLatestAssistantText(messages) {
391
413
  const latestAssistantMessage = [...messages].reverse().find((message) => {
392
414
  return message.role === "assistant";
@@ -663,12 +685,7 @@ function parseStringArrayFromEnv(key) {
663
685
  }
664
686
 
665
687
  // src/discord-gateway-client.ts
666
- import {
667
- Client,
668
- Events,
669
- GatewayIntentBits,
670
- Partials
671
- } from "discord.js";
688
+ import { Client, Events, GatewayIntentBits, Partials } from "discord.js";
672
689
 
673
690
  // src/session-commands.ts
674
691
  function getSessionStatusText(session, promptQueue, extras) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@friendlyrobot/discord-pi-agent",
3
- "version": "0.19.4",
3
+ "version": "0.19.6",
4
4
  "description": "Reusable Discord gateway for persistent pi agent sessions",
5
5
  "license": "MIT",
6
6
  "type": "module",