@posthog/agent 2.1.113 → 2.1.114

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/agent",
3
- "version": "2.1.113",
3
+ "version": "2.1.114",
4
4
  "repository": "https://github.com/PostHog/twig",
5
5
  "description": "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
6
6
  "exports": {
@@ -71,8 +71,8 @@
71
71
  "tsx": "^4.20.6",
72
72
  "typescript": "^5.5.0",
73
73
  "vitest": "^2.1.8",
74
- "@posthog/shared": "1.0.0",
75
- "@twig/git": "1.0.0"
74
+ "@twig/git": "1.0.0",
75
+ "@posthog/shared": "1.0.0"
76
76
  },
77
77
  "dependencies": {
78
78
  "@agentclientprotocol/sdk": "^0.14.0",
@@ -609,32 +609,56 @@ export function toolUpdateFromToolResult(
609
609
  }
610
610
  }
611
611
 
612
+ function itemToText(item: unknown): string | null {
613
+ if (!item || typeof item !== "object") return null;
614
+ const obj = item as Record<string, unknown>;
615
+ // Standard text block
616
+ if (obj.type === "text" && typeof obj.text === "string") {
617
+ return obj.text;
618
+ }
619
+ // Any other structured object — serialize it
620
+ try {
621
+ return JSON.stringify(obj, null, 2);
622
+ } catch {
623
+ return null;
624
+ }
625
+ }
626
+
612
627
  function toAcpContentUpdate(
613
628
  content: unknown,
614
629
  isError: boolean = false,
615
630
  ): Pick<ToolCallUpdate, "content"> {
616
631
  if (Array.isArray(content) && content.length > 0) {
617
- return {
618
- content: content.map((item) => {
619
- const itemObj = item as { type?: string; text?: string };
620
- if (isError && itemObj.type === "text") {
621
- return {
622
- type: "content" as const,
623
- content: text(`\`\`\`\n${itemObj.text ?? ""}\n\`\`\``),
624
- };
625
- }
626
- return {
627
- type: "content" as const,
628
- content: item as { type: "text"; text: string },
629
- };
630
- }),
631
- };
632
+ const texts: string[] = [];
633
+ for (const item of content) {
634
+ const t = itemToText(item);
635
+ if (t) texts.push(t);
636
+ }
637
+ if (texts.length > 0) {
638
+ const combined = texts.join("\n");
639
+ return {
640
+ content: toolContent()
641
+ .text(isError ? `\`\`\`\n${combined}\n\`\`\`` : combined)
642
+ .build(),
643
+ };
644
+ }
632
645
  } else if (typeof content === "string" && content.length > 0) {
633
646
  return {
634
647
  content: toolContent()
635
648
  .text(isError ? `\`\`\`\n${content}\n\`\`\`` : content)
636
649
  .build(),
637
650
  };
651
+ } else if (content && typeof content === "object") {
652
+ try {
653
+ const json = JSON.stringify(content, null, 2);
654
+ if (json && json !== "{}") {
655
+ return {
656
+ content: toolContent().text(json).build(),
657
+ };
658
+ }
659
+ } catch {
660
+ // ignore serialization errors
661
+ }
638
662
  }
639
663
  return {};
640
664
  }