@posthog/agent 1.24.0 → 1.24.2

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 (116) hide show
  1. package/LICENSE +33 -0
  2. package/dist/index.d.ts +11 -11
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +3 -3
  5. package/dist/src/adapters/claude/claude-adapter.d.ts +3 -3
  6. package/dist/src/adapters/claude/claude-adapter.d.ts.map +1 -1
  7. package/dist/src/adapters/claude/claude-adapter.js +111 -156
  8. package/dist/src/adapters/claude/claude-adapter.js.map +1 -1
  9. package/dist/src/adapters/claude/tool-mapper.d.ts +1 -1
  10. package/dist/src/adapters/claude/tool-mapper.d.ts.map +1 -1
  11. package/dist/src/adapters/claude/tool-mapper.js.map +1 -1
  12. package/dist/src/adapters/types.d.ts +1 -1
  13. package/dist/src/adapters/types.d.ts.map +1 -1
  14. package/dist/src/agent.d.ts +7 -7
  15. package/dist/src/agent.d.ts.map +1 -1
  16. package/dist/src/agent.js +85 -143
  17. package/dist/src/agent.js.map +1 -1
  18. package/dist/src/agents/execution.js.map +1 -1
  19. package/dist/src/agents/planning.js.map +1 -1
  20. package/dist/src/agents/research.js.map +1 -1
  21. package/dist/src/file-manager.d.ts +4 -4
  22. package/dist/src/file-manager.d.ts.map +1 -1
  23. package/dist/src/file-manager.js +58 -59
  24. package/dist/src/file-manager.js.map +1 -1
  25. package/dist/src/git-manager.d.ts +1 -1
  26. package/dist/src/git-manager.d.ts.map +1 -1
  27. package/dist/src/git-manager.js +70 -87
  28. package/dist/src/git-manager.js.map +1 -1
  29. package/dist/src/posthog-api.d.ts +3 -2
  30. package/dist/src/posthog-api.d.ts.map +1 -1
  31. package/dist/src/posthog-api.js +22 -22
  32. package/dist/src/posthog-api.js.map +1 -1
  33. package/dist/src/prompt-builder.d.ts +3 -3
  34. package/dist/src/prompt-builder.d.ts.map +1 -1
  35. package/dist/src/prompt-builder.js +93 -123
  36. package/dist/src/prompt-builder.js.map +1 -1
  37. package/dist/src/task-manager.d.ts +4 -4
  38. package/dist/src/task-manager.d.ts.map +1 -1
  39. package/dist/src/task-manager.js +18 -19
  40. package/dist/src/task-manager.js.map +1 -1
  41. package/dist/src/task-progress-reporter.d.ts +4 -3
  42. package/dist/src/task-progress-reporter.d.ts.map +1 -1
  43. package/dist/src/task-progress-reporter.js +54 -59
  44. package/dist/src/task-progress-reporter.js.map +1 -1
  45. package/dist/src/template-manager.d.ts +1 -1
  46. package/dist/src/template-manager.d.ts.map +1 -1
  47. package/dist/src/template-manager.js +28 -30
  48. package/dist/src/template-manager.js.map +1 -1
  49. package/dist/src/todo-manager.d.ts +3 -3
  50. package/dist/src/todo-manager.d.ts.map +1 -1
  51. package/dist/src/todo-manager.js +24 -29
  52. package/dist/src/todo-manager.js.map +1 -1
  53. package/dist/src/tools/registry.d.ts +1 -1
  54. package/dist/src/tools/registry.js +60 -60
  55. package/dist/src/tools/registry.js.map +1 -1
  56. package/dist/src/tools/types.d.ts +31 -31
  57. package/dist/src/types.d.ts +33 -33
  58. package/dist/src/types.d.ts.map +1 -1
  59. package/dist/src/types.js.map +1 -1
  60. package/dist/src/utils/logger.d.ts +4 -4
  61. package/dist/src/utils/logger.d.ts.map +1 -1
  62. package/dist/src/utils/logger.js +8 -8
  63. package/dist/src/utils/logger.js.map +1 -1
  64. package/dist/src/workflow/config.d.ts +1 -1
  65. package/dist/src/workflow/config.d.ts.map +1 -1
  66. package/dist/src/workflow/config.js +18 -18
  67. package/dist/src/workflow/config.js.map +1 -1
  68. package/dist/src/workflow/steps/build.d.ts +1 -1
  69. package/dist/src/workflow/steps/build.d.ts.map +1 -1
  70. package/dist/src/workflow/steps/build.js +38 -46
  71. package/dist/src/workflow/steps/build.js.map +1 -1
  72. package/dist/src/workflow/steps/finalize.d.ts +1 -1
  73. package/dist/src/workflow/steps/finalize.d.ts.map +1 -1
  74. package/dist/src/workflow/steps/finalize.js +48 -54
  75. package/dist/src/workflow/steps/finalize.js.map +1 -1
  76. package/dist/src/workflow/steps/plan.d.ts +1 -1
  77. package/dist/src/workflow/steps/plan.d.ts.map +1 -1
  78. package/dist/src/workflow/steps/plan.js +46 -58
  79. package/dist/src/workflow/steps/plan.js.map +1 -1
  80. package/dist/src/workflow/steps/research.d.ts +1 -1
  81. package/dist/src/workflow/steps/research.d.ts.map +1 -1
  82. package/dist/src/workflow/steps/research.js +56 -68
  83. package/dist/src/workflow/steps/research.js.map +1 -1
  84. package/dist/src/workflow/types.d.ts +12 -12
  85. package/dist/src/workflow/types.d.ts.map +1 -1
  86. package/dist/src/workflow/utils.d.ts +1 -1
  87. package/dist/src/workflow/utils.d.ts.map +1 -1
  88. package/dist/src/workflow/utils.js +4 -7
  89. package/dist/src/workflow/utils.js.map +1 -1
  90. package/package.json +6 -6
  91. package/src/adapters/claude/claude-adapter.ts +168 -220
  92. package/src/adapters/claude/tool-mapper.ts +2 -2
  93. package/src/adapters/types.ts +1 -1
  94. package/src/agent.ts +444 -579
  95. package/src/agents/execution.ts +1 -1
  96. package/src/agents/planning.ts +1 -1
  97. package/src/agents/research.ts +1 -0
  98. package/src/file-manager.ts +63 -64
  99. package/src/git-manager.ts +88 -144
  100. package/src/posthog-api.ts +82 -122
  101. package/src/prompt-builder.ts +135 -180
  102. package/src/task-manager.ts +30 -38
  103. package/src/task-progress-reporter.ts +59 -70
  104. package/src/template-manager.ts +45 -98
  105. package/src/todo-manager.ts +30 -35
  106. package/src/tools/registry.ts +62 -62
  107. package/src/tools/types.ts +36 -36
  108. package/src/types.ts +71 -93
  109. package/src/utils/logger.ts +56 -62
  110. package/src/workflow/config.ts +48 -48
  111. package/src/workflow/steps/build.ts +113 -122
  112. package/src/workflow/steps/finalize.ts +182 -214
  113. package/src/workflow/steps/plan.ts +131 -151
  114. package/src/workflow/steps/research.ts +186 -205
  115. package/src/workflow/types.ts +36 -38
  116. package/src/workflow/utils.ts +34 -37
@@ -9,18 +9,18 @@ async function finalizeStepGitActions(context, step, options) {
9
9
  const { gitManager, logger } = context;
10
10
  const hasStagedChanges = await gitManager.hasStagedChanges();
11
11
  if (!hasStagedChanges && !options.allowEmptyCommit) {
12
- logger.debug("No staged changes to commit for step", { stepId: step.id });
12
+ logger.debug('No staged changes to commit for step', { stepId: step.id });
13
13
  return false;
14
14
  }
15
15
  try {
16
16
  await gitManager.commitChanges(options.commitMessage);
17
- logger.info("Committed changes for step", {
17
+ logger.info('Committed changes for step', {
18
18
  stepId: step.id,
19
19
  message: options.commitMessage,
20
20
  });
21
21
  }
22
22
  catch (error) {
23
- logger.error("Failed to commit changes for step", {
23
+ logger.error('Failed to commit changes for step', {
24
24
  stepId: step.id,
25
25
  error: error instanceof Error ? error.message : String(error),
26
26
  });
@@ -29,10 +29,7 @@ async function finalizeStepGitActions(context, step, options) {
29
29
  if (step.push) {
30
30
  const branchName = await gitManager.getCurrentBranch();
31
31
  await gitManager.pushBranch(branchName);
32
- logger.info("Pushed branch after step", {
33
- stepId: step.id,
34
- branch: branchName,
35
- });
32
+ logger.info('Pushed branch after step', { stepId: step.id, branch: branchName });
36
33
  }
37
34
  return true;
38
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../../src/workflow/utils.ts"],"sourcesContent":["import type { WorkflowRuntime, WorkflowStepDefinition } from \"./types.js\";\n\ninterface FinalizeGitOptions {\n commitMessage: string;\n allowEmptyCommit?: boolean;\n}\n\n/**\n * Commits (and optionally pushes) any staged changes according to the step configuration.\n * Returns true if a commit was created.\n */\nexport async function finalizeStepGitActions(\n context: WorkflowRuntime,\n step: WorkflowStepDefinition,\n options: FinalizeGitOptions,\n): Promise<boolean> {\n if (!step.commit) {\n return false;\n }\n\n const { gitManager, logger } = context;\n const hasStagedChanges = await gitManager.hasStagedChanges();\n\n if (!hasStagedChanges && !options.allowEmptyCommit) {\n logger.debug(\"No staged changes to commit for step\", { stepId: step.id });\n return false;\n }\n\n try {\n await gitManager.commitChanges(options.commitMessage);\n logger.info(\"Committed changes for step\", {\n stepId: step.id,\n message: options.commitMessage,\n });\n } catch (error) {\n logger.error(\"Failed to commit changes for step\", {\n stepId: step.id,\n error: error instanceof Error ? error.message : String(error),\n });\n throw error;\n }\n\n if (step.push) {\n const branchName = await gitManager.getCurrentBranch();\n await gitManager.pushBranch(branchName);\n logger.info(\"Pushed branch after step\", {\n stepId: step.id,\n branch: branchName,\n });\n }\n\n return true;\n}\n"],"names":[],"mappings":"AAOA;;;AAGG;AACI,eAAe,sBAAsB,CAC1C,OAAwB,EACxB,IAA4B,EAC5B,OAA2B,EAAA;AAE3B,IAAA,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;AAChB,QAAA,OAAO,KAAK;IACd;AAEA,IAAA,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO;AACtC,IAAA,MAAM,gBAAgB,GAAG,MAAM,UAAU,CAAC,gBAAgB,EAAE;IAE5D,IAAI,CAAC,gBAAgB,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE;AAClD,QAAA,MAAM,CAAC,KAAK,CAAC,sCAAsC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;AACzE,QAAA,OAAO,KAAK;IACd;AAEA,IAAA,IAAI;QACF,MAAM,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,aAAa,CAAC;AACrD,QAAA,MAAM,CAAC,IAAI,CAAC,4BAA4B,EAAE;YACxC,MAAM,EAAE,IAAI,CAAC,EAAE;YACf,OAAO,EAAE,OAAO,CAAC,aAAa;AAC/B,SAAA,CAAC;IACJ;IAAE,OAAO,KAAK,EAAE;AACd,QAAA,MAAM,CAAC,KAAK,CAAC,mCAAmC,EAAE;YAChD,MAAM,EAAE,IAAI,CAAC,EAAE;AACf,YAAA,KAAK,EAAE,KAAK,YAAY,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC;AAC9D,SAAA,CAAC;AACF,QAAA,MAAM,KAAK;IACb;AAEA,IAAA,IAAI,IAAI,CAAC,IAAI,EAAE;AACb,QAAA,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC,gBAAgB,EAAE;AACtD,QAAA,MAAM,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC;AACvC,QAAA,MAAM,CAAC,IAAI,CAAC,0BAA0B,EAAE;YACtC,MAAM,EAAE,IAAI,CAAC,EAAE;AACf,YAAA,MAAM,EAAE,UAAU;AACnB,SAAA,CAAC;IACJ;AAEA,IAAA,OAAO,IAAI;AACb;;;;"}
1
+ {"version":3,"file":"utils.js","sources":["../../../src/workflow/utils.ts"],"sourcesContent":["import type { WorkflowRuntime, WorkflowStepDefinition } from './types.js';\n\ninterface FinalizeGitOptions {\n commitMessage: string;\n allowEmptyCommit?: boolean;\n}\n\n/**\n * Commits (and optionally pushes) any staged changes according to the step configuration.\n * Returns true if a commit was created.\n */\nexport async function finalizeStepGitActions(\n context: WorkflowRuntime,\n step: WorkflowStepDefinition,\n options: FinalizeGitOptions\n): Promise<boolean> {\n if (!step.commit) {\n return false;\n }\n\n const { gitManager, logger } = context;\n const hasStagedChanges = await gitManager.hasStagedChanges();\n\n if (!hasStagedChanges && !options.allowEmptyCommit) {\n logger.debug('No staged changes to commit for step', { stepId: step.id });\n return false;\n }\n\n try {\n await gitManager.commitChanges(options.commitMessage);\n logger.info('Committed changes for step', {\n stepId: step.id,\n message: options.commitMessage,\n });\n } catch (error) {\n logger.error('Failed to commit changes for step', {\n stepId: step.id,\n error: error instanceof Error ? error.message : String(error),\n });\n throw error;\n }\n\n if (step.push) {\n const branchName = await gitManager.getCurrentBranch();\n await gitManager.pushBranch(branchName);\n logger.info('Pushed branch after step', { stepId: step.id, branch: branchName });\n }\n\n return true;\n}\n"],"names":[],"mappings":"AAOA;;;AAGG;AACI,eAAe,sBAAsB,CACxC,OAAwB,EACxB,IAA4B,EAC5B,OAA2B,EAAA;AAE3B,IAAA,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;AACd,QAAA,OAAO,KAAK;IAChB;AAEA,IAAA,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO;AACtC,IAAA,MAAM,gBAAgB,GAAG,MAAM,UAAU,CAAC,gBAAgB,EAAE;IAE5D,IAAI,CAAC,gBAAgB,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE;AAChD,QAAA,MAAM,CAAC,KAAK,CAAC,sCAAsC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;AACzE,QAAA,OAAO,KAAK;IAChB;AAEA,IAAA,IAAI;QACA,MAAM,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,aAAa,CAAC;AACrD,QAAA,MAAM,CAAC,IAAI,CAAC,4BAA4B,EAAE;YACtC,MAAM,EAAE,IAAI,CAAC,EAAE;YACf,OAAO,EAAE,OAAO,CAAC,aAAa;AACjC,SAAA,CAAC;IACN;IAAE,OAAO,KAAK,EAAE;AACZ,QAAA,MAAM,CAAC,KAAK,CAAC,mCAAmC,EAAE;YAC9C,MAAM,EAAE,IAAI,CAAC,EAAE;AACf,YAAA,KAAK,EAAE,KAAK,YAAY,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC;AAChE,SAAA,CAAC;AACF,QAAA,MAAM,KAAK;IACf;AAEA,IAAA,IAAI,IAAI,CAAC,IAAI,EAAE;AACX,QAAA,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC,gBAAgB,EAAE;AACtD,QAAA,MAAM,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC;AACvC,QAAA,MAAM,CAAC,IAAI,CAAC,0BAA0B,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;IACpF;AAEA,IAAA,OAAO,IAAI;AACf;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/agent",
3
- "version": "1.24.0",
3
+ "version": "1.24.2",
4
4
  "description": "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -22,16 +22,15 @@
22
22
  "typescript"
23
23
  ],
24
24
  "author": "PostHog",
25
- "license": "SEE LICENSE IN LICENSE",
25
+ "license": "MIT",
26
26
  "repository": {
27
27
  "type": "git",
28
28
  "url": "https://github.com/PostHog/posthog-agent"
29
29
  },
30
30
  "scripts": {
31
- "build": "pnpm exec rimraf dist && pnpm exec rollup -c && pnpm exec tsc --project tsconfig.build.json --emitDeclarationOnly",
32
- "dev": "pnpm exec rollup -c --watch",
33
- "typecheck": "pnpm exec tsc --noEmit",
31
+ "build": "rimraf dist && rollup -c && tsc --project tsconfig.build.json --emitDeclarationOnly",
34
32
  "example": "pnpm run example-usage.ts",
33
+ "dev": "pnpm run example-usage.ts",
35
34
  "prepublishOnly": "pnpm run build"
36
35
  },
37
36
  "engines": {
@@ -62,5 +61,6 @@
62
61
  ],
63
62
  "publishConfig": {
64
63
  "access": "public"
65
- }
64
+ },
65
+ "packageManager": "pnpm@10.14.0+sha512.ad27a79641b49c3e481a16a805baa71817a04bbe06a38d17e60e2eaee83f6a146c6a688125f5792e48dd5ba30e7da52a5cda4c3992b9ccf333f9ce223af84748"
66
66
  }
@@ -1,151 +1,120 @@
1
- import type { SDKMessage } from "@anthropic-ai/claude-agent-sdk";
2
- import type { AgentEvent, ArtifactEvent, StatusEvent } from "../../types.js";
3
- import type { ProviderAdapter } from "../types.js";
4
- import { ClaudeToolMapper } from "./tool-mapper.js";
1
+ import type { AgentEvent, ArtifactEvent, StatusEvent } from '../../types.js';
2
+ import type { SDKMessage } from '@anthropic-ai/claude-agent-sdk';
3
+ import type { ProviderAdapter } from '../types.js';
4
+ import { ClaudeToolMapper } from './tool-mapper.js';
5
5
 
6
6
  /**
7
7
  * Claude provider adapter.
8
8
  * Transforms Claude SDK messages into our standardized AgentEvent format.
9
9
  */
10
10
  export class ClaudeAdapter implements ProviderAdapter {
11
- readonly name = "claude";
11
+ readonly name = 'claude';
12
12
  private toolMapper = new ClaudeToolMapper();
13
13
  createRawSDKEvent(sdkMessage: any): AgentEvent {
14
14
  return {
15
- type: "raw_sdk_event",
15
+ type: 'raw_sdk_event',
16
16
  ts: Date.now(),
17
- sdkMessage,
17
+ sdkMessage
18
18
  };
19
19
  }
20
20
 
21
21
  transform(sdkMessage: SDKMessage): AgentEvent[] {
22
22
  const baseEvent = { ts: Date.now() };
23
23
 
24
- if (sdkMessage.type === "stream_event") {
24
+ if (sdkMessage.type === 'stream_event') {
25
25
  const event = sdkMessage.event;
26
26
 
27
27
  switch (event.type) {
28
- case "message_start":
29
- return [
30
- {
31
- ...baseEvent,
32
- type: "message_start",
33
- messageId: event.message?.id,
34
- model: event.message?.model,
35
- },
36
- ];
28
+ case 'message_start':
29
+ return [{
30
+ ...baseEvent,
31
+ type: 'message_start',
32
+ messageId: event.message?.id,
33
+ model: event.message?.model
34
+ }];
37
35
 
38
- case "content_block_start": {
36
+ case 'content_block_start':
39
37
  const contentBlock = event.content_block;
40
38
  if (!contentBlock) return [];
41
39
 
42
- return [
43
- {
44
- ...baseEvent,
45
- type: "content_block_start",
46
- index: event.index,
47
- contentType: contentBlock.type as
48
- | "text"
49
- | "tool_use"
50
- | "thinking",
51
- toolName:
52
- contentBlock.type === "tool_use"
53
- ? contentBlock.name
54
- : undefined,
55
- toolId:
56
- contentBlock.type === "tool_use" ? contentBlock.id : undefined,
57
- },
58
- ];
59
- }
60
-
61
- case "content_block_delta": {
40
+ return [{
41
+ ...baseEvent,
42
+ type: 'content_block_start',
43
+ index: event.index,
44
+ contentType: contentBlock.type as 'text' | 'tool_use' | 'thinking',
45
+ toolName: contentBlock.type === 'tool_use' ? contentBlock.name : undefined,
46
+ toolId: contentBlock.type === 'tool_use' ? contentBlock.id : undefined
47
+ }];
48
+
49
+ case 'content_block_delta':
62
50
  const delta = event.delta;
63
51
  if (!delta) return [];
64
52
 
65
- if (delta.type === "text_delta") {
66
- return [
67
- {
68
- ...baseEvent,
69
- type: "token",
70
- content: delta.text,
71
- contentType: "text",
72
- },
73
- ];
74
- } else if (delta.type === "input_json_delta") {
75
- return [
76
- {
77
- ...baseEvent,
78
- type: "token",
79
- content: delta.partial_json,
80
- contentType: "tool_input",
81
- },
82
- ];
83
- } else if (delta.type === "thinking_delta") {
84
- return [
85
- {
86
- ...baseEvent,
87
- type: "token",
88
- content: delta.thinking,
89
- contentType: "thinking",
90
- },
91
- ];
92
- }
93
- return [];
94
- }
95
-
96
- case "content_block_stop":
97
- return [
98
- {
53
+ if (delta.type === 'text_delta') {
54
+ return [{
99
55
  ...baseEvent,
100
- type: "content_block_stop",
101
- index: event.index,
102
- },
103
- ];
104
-
105
- case "message_delta":
106
- return [
107
- {
56
+ type: 'token',
57
+ content: delta.text,
58
+ contentType: 'text'
59
+ }];
60
+ } else if (delta.type === 'input_json_delta') {
61
+ return [{
108
62
  ...baseEvent,
109
- type: "message_delta",
110
- stopReason: event.delta?.stop_reason,
111
- stopSequence: event.delta?.stop_sequence,
112
- usage: event.usage
113
- ? {
114
- outputTokens: event.usage.output_tokens,
115
- }
116
- : undefined,
117
- },
118
- ];
119
-
120
- case "message_stop":
121
- return [
122
- {
63
+ type: 'token',
64
+ content: delta.partial_json,
65
+ contentType: 'tool_input'
66
+ }];
67
+ } else if (delta.type === 'thinking_delta') {
68
+ return [{
123
69
  ...baseEvent,
124
- type: "message_stop",
125
- },
126
- ];
70
+ type: 'token',
71
+ content: delta.thinking,
72
+ contentType: 'thinking'
73
+ }];
74
+ }
75
+ return [];
76
+
77
+ case 'content_block_stop':
78
+ return [{
79
+ ...baseEvent,
80
+ type: 'content_block_stop',
81
+ index: event.index
82
+ }];
83
+
84
+ case 'message_delta':
85
+ return [{
86
+ ...baseEvent,
87
+ type: 'message_delta',
88
+ stopReason: event.delta?.stop_reason,
89
+ stopSequence: event.delta?.stop_sequence,
90
+ usage: event.usage ? {
91
+ outputTokens: event.usage.output_tokens
92
+ } : undefined
93
+ }];
94
+
95
+ case 'message_stop':
96
+ return [{
97
+ ...baseEvent,
98
+ type: 'message_stop'
99
+ }];
127
100
 
128
- case "ping":
101
+ case 'ping':
129
102
  // Ignore ping events
130
103
  return [];
131
104
 
132
- case "error":
133
- return [
134
- {
135
- ...baseEvent,
136
- type: "error",
137
- message: event.error?.message || "Unknown error",
138
- error: event.error,
139
- errorType: event.error?.type || "stream_error",
140
- context: event.error
141
- ? {
142
- type: event.error.type,
143
- code: event.error.code,
144
- }
145
- : undefined,
146
- sdkError: event.error,
147
- },
148
- ];
105
+ case 'error':
106
+ return [{
107
+ ...baseEvent,
108
+ type: 'error',
109
+ message: event.error?.message || 'Unknown error',
110
+ error: event.error,
111
+ errorType: event.error?.type || 'stream_error',
112
+ context: event.error ? {
113
+ type: event.error.type,
114
+ code: event.error.code,
115
+ } : undefined,
116
+ sdkError: event.error
117
+ }];
149
118
 
150
119
  default:
151
120
  return [];
@@ -153,7 +122,7 @@ export class ClaudeAdapter implements ProviderAdapter {
153
122
  }
154
123
 
155
124
  // Handle assistant messages (full message, not streaming)
156
- if (sdkMessage.type === "assistant") {
125
+ if (sdkMessage.type === 'assistant') {
157
126
  const message = sdkMessage.message;
158
127
  const events: AgentEvent[] = [];
159
128
 
@@ -161,15 +130,15 @@ export class ClaudeAdapter implements ProviderAdapter {
161
130
  // A single assistant message can contain multiple tool_use blocks
162
131
  if (message.content && Array.isArray(message.content)) {
163
132
  for (const block of message.content) {
164
- if (block.type === "tool_use") {
133
+ if (block.type === 'tool_use') {
165
134
  // Create tool_call event and enrich with metadata
166
135
  const toolCallEvent = {
167
136
  ...baseEvent,
168
- type: "tool_call" as const,
137
+ type: 'tool_call' as const,
169
138
  toolName: block.name,
170
139
  callId: block.id,
171
140
  args: block.input || {},
172
- parentToolUseId: sdkMessage.parent_tool_use_id,
141
+ parentToolUseId: sdkMessage.parent_tool_use_id
173
142
  };
174
143
  // Enrich with tool metadata and add to events array
175
144
  events.push(this.toolMapper.enrichToolCall(toolCallEvent));
@@ -183,34 +152,32 @@ export class ClaudeAdapter implements ProviderAdapter {
183
152
  }
184
153
 
185
154
  // If no tool calls, emit status event
186
- return [
187
- {
188
- ...baseEvent,
189
- type: "status",
190
- phase: "assistant_message",
191
- messageId: message.id,
192
- model: message.model,
193
- },
194
- ];
155
+ return [{
156
+ ...baseEvent,
157
+ type: 'status',
158
+ phase: 'assistant_message',
159
+ messageId: message.id,
160
+ model: message.model
161
+ }];
195
162
  }
196
163
 
197
164
  // Handle user messages
198
- if (sdkMessage.type === "user") {
165
+ if (sdkMessage.type === 'user') {
199
166
  const message = sdkMessage.message;
200
167
  const events: AgentEvent[] = [];
201
168
 
202
169
  // Check for tool results in content blocks, A single user message can contain multiple tool_result blocks
203
- if (message?.content && Array.isArray(message.content)) {
170
+ if (message?.content && Array.isArray(message.content)) {
204
171
  for (const block of message.content) {
205
- if (block.type === "tool_result") {
172
+ if (block.type === 'tool_result') {
206
173
  const toolResultEvent = {
207
174
  ...baseEvent,
208
- type: "tool_result" as const,
209
- toolName: block.tool_name || "unknown",
210
- callId: block.tool_use_id || "",
175
+ type: 'tool_result' as const,
176
+ toolName: block.tool_name || 'unknown',
177
+ callId: block.tool_use_id || '',
211
178
  result: block.content,
212
179
  isError: block.is_error,
213
- parentToolUseId: sdkMessage.parent_tool_use_id,
180
+ parentToolUseId: sdkMessage.parent_tool_use_id
214
181
  };
215
182
  events.push(this.toolMapper.enrichToolResult(toolResultEvent));
216
183
  }
@@ -227,100 +194,90 @@ export class ClaudeAdapter implements ProviderAdapter {
227
194
  if (!textContent) {
228
195
  return [];
229
196
  }
230
- return [
231
- {
232
- ...baseEvent,
233
- type: "user_message",
234
- content: textContent,
235
- isSynthetic: sdkMessage.isSynthetic,
236
- },
237
- ];
197
+ return [{
198
+ ...baseEvent,
199
+ type: 'user_message',
200
+ content: textContent,
201
+ isSynthetic: sdkMessage.isSynthetic
202
+ }];
238
203
  }
239
204
 
240
205
  // Handle result messages
241
- if (sdkMessage.type === "result") {
242
- if (sdkMessage.subtype === "success") {
243
- return [
244
- {
245
- ...baseEvent,
246
- type: "done",
247
- result: sdkMessage.result,
248
- durationMs: sdkMessage.duration_ms,
249
- durationApiMs: sdkMessage.duration_api_ms,
250
- numTurns: sdkMessage.num_turns,
251
- totalCostUsd: sdkMessage.total_cost_usd,
252
- usage: sdkMessage.usage,
253
- modelUsage: sdkMessage.modelUsage,
254
- permissionDenials: sdkMessage.permission_denials,
255
- },
256
- ];
206
+ if (sdkMessage.type === 'result') {
207
+ if (sdkMessage.subtype === 'success') {
208
+ return [{
209
+ ...baseEvent,
210
+ type: 'done',
211
+ result: sdkMessage.result,
212
+ durationMs: sdkMessage.duration_ms,
213
+ durationApiMs: sdkMessage.duration_api_ms,
214
+ numTurns: sdkMessage.num_turns,
215
+ totalCostUsd: sdkMessage.total_cost_usd,
216
+ usage: sdkMessage.usage,
217
+ modelUsage: sdkMessage.modelUsage,
218
+ permissionDenials: sdkMessage.permission_denials
219
+ }];
257
220
  } else {
258
- return [
259
- {
260
- ...baseEvent,
261
- type: "error",
262
- message: `Execution failed: ${sdkMessage.subtype}`,
263
- error: { subtype: sdkMessage.subtype },
264
- errorType: sdkMessage.subtype || "result_error",
265
- context: {
266
- subtype: sdkMessage.subtype,
267
- duration_ms: sdkMessage.duration_ms,
268
- num_turns: sdkMessage.num_turns,
269
- },
270
- sdkError: sdkMessage,
221
+ return [{
222
+ ...baseEvent,
223
+ type: 'error',
224
+ message: `Execution failed: ${sdkMessage.subtype}`,
225
+ error: { subtype: sdkMessage.subtype },
226
+ errorType: sdkMessage.subtype || 'result_error',
227
+ context: {
228
+ subtype: sdkMessage.subtype,
229
+ duration_ms: sdkMessage.duration_ms,
230
+ num_turns: sdkMessage.num_turns
271
231
  },
272
- ];
232
+ sdkError: sdkMessage
233
+ }];
273
234
  }
274
235
  }
275
236
 
276
237
  // Handle system messages
277
- if (sdkMessage.type === "system") {
278
- if (sdkMessage.subtype === "init") {
279
- return [
280
- {
281
- ...baseEvent,
282
- type: "init",
283
- model: sdkMessage.model,
284
- tools: sdkMessage.tools,
285
- permissionMode: sdkMessage.permissionMode,
286
- cwd: sdkMessage.cwd,
287
- apiKeySource: sdkMessage.apiKeySource,
288
- agents: sdkMessage.agents,
289
- slashCommands: sdkMessage.slash_commands,
290
- outputStyle: sdkMessage.output_style,
291
- mcpServers: sdkMessage.mcp_servers,
292
- },
293
- ];
294
- } else if (sdkMessage.subtype === "compact_boundary") {
295
- return [
296
- {
297
- ...baseEvent,
298
- type: "compact_boundary",
299
- trigger: sdkMessage.compact_metadata.trigger,
300
- preTokens: sdkMessage.compact_metadata.pre_tokens,
301
- },
302
- ];
238
+ if (sdkMessage.type === 'system') {
239
+ if (sdkMessage.subtype === 'init') {
240
+ return [{
241
+ ...baseEvent,
242
+ type: 'init',
243
+ model: sdkMessage.model,
244
+ tools: sdkMessage.tools,
245
+ permissionMode: sdkMessage.permissionMode,
246
+ cwd: sdkMessage.cwd,
247
+ apiKeySource: sdkMessage.apiKeySource,
248
+ agents: sdkMessage.agents,
249
+ slashCommands: sdkMessage.slash_commands,
250
+ outputStyle: sdkMessage.output_style,
251
+ mcpServers: sdkMessage.mcp_servers
252
+ }];
253
+ } else if (sdkMessage.subtype === 'compact_boundary') {
254
+ return [{
255
+ ...baseEvent,
256
+ type: 'compact_boundary',
257
+ trigger: sdkMessage.compact_metadata.trigger,
258
+ preTokens: sdkMessage.compact_metadata.pre_tokens
259
+ }];
303
260
  }
304
261
  }
305
262
 
306
263
  return [];
307
264
  }
308
-
265
+
309
266
  createStatusEvent(phase: string, additionalData?: any): StatusEvent {
310
267
  return {
311
- type: "status",
268
+ type: 'status',
312
269
  ts: Date.now(),
313
270
  phase,
314
- ...additionalData,
271
+ ...additionalData
315
272
  };
316
273
  }
317
274
 
318
275
  createArtifactEvent(kind: string, content: any): ArtifactEvent {
319
276
  return {
320
- type: "artifact",
277
+ type: 'artifact',
321
278
  ts: Date.now(),
322
279
  kind,
323
- content,
280
+ content
324
281
  };
325
282
  }
326
283
 
@@ -329,7 +286,7 @@ export class ClaudeAdapter implements ProviderAdapter {
329
286
  return null;
330
287
  }
331
288
 
332
- if (typeof content === "string") {
289
+ if (typeof content === 'string') {
333
290
  const trimmed = content.trim();
334
291
  return trimmed.length > 0 ? trimmed : null;
335
292
  }
@@ -340,20 +297,18 @@ export class ClaudeAdapter implements ProviderAdapter {
340
297
  const extracted = this.extractUserContent(block);
341
298
  if (extracted) {
342
299
  parts.push(extracted);
343
- } else if (block && typeof block === "object") {
344
- const candidate = this.extractFromObject(
345
- block as Record<string, unknown>,
346
- );
300
+ } else if (block && typeof block === 'object') {
301
+ const candidate = this.extractFromObject(block as Record<string, unknown>);
347
302
  if (candidate) {
348
303
  parts.push(candidate);
349
304
  }
350
305
  }
351
306
  }
352
- const text = parts.join("\n").trim();
307
+ const text = parts.join('\n').trim();
353
308
  return text.length > 0 ? text : null;
354
309
  }
355
310
 
356
- if (typeof content === "object") {
311
+ if (typeof content === 'object') {
357
312
  return this.extractFromObject(content as Record<string, unknown>);
358
313
  }
359
314
 
@@ -361,16 +316,9 @@ export class ClaudeAdapter implements ProviderAdapter {
361
316
  }
362
317
 
363
318
  private extractFromObject(value: Record<string, unknown>): string | null {
364
- const preferredKeys = [
365
- "text",
366
- "input_text",
367
- "input",
368
- "markdown",
369
- "content",
370
- "message",
371
- ];
319
+ const preferredKeys = ['text', 'input_text', 'input', 'markdown', 'content', 'message'];
372
320
  for (const key of preferredKeys) {
373
- if (typeof value[key] === "string") {
321
+ if (typeof value[key] === 'string') {
374
322
  const trimmed = (value[key] as string).trim();
375
323
  if (trimmed.length > 0) {
376
324
  return trimmed;
@@ -1,5 +1,5 @@
1
- import { ToolRegistry } from "../../tools/registry.js";
2
- import type { ToolCallEvent, ToolResultEvent } from "../../types.js";
1
+ import type { ToolCallEvent, ToolResultEvent } from '../../types.js';
2
+ import { ToolRegistry } from '../../tools/registry.js';
3
3
 
4
4
  /**
5
5
  * Maps Claude tool names to our tool type system.
@@ -1,4 +1,4 @@
1
- import type { AgentEvent, ArtifactEvent, StatusEvent } from "../types.js";
1
+ import type { AgentEvent, StatusEvent, ArtifactEvent } from '../types.js';
2
2
 
3
3
  /**
4
4
  * Provider adapter interface for transforming provider-specific messages