@posthog/agent 1.7.0 → 1.9.0

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 (48) hide show
  1. package/dist/index.d.ts +5 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +2 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/src/adapters/claude/claude-adapter.d.ts +17 -0
  6. package/dist/src/adapters/claude/claude-adapter.d.ts.map +1 -0
  7. package/dist/src/{event-transformer.js → adapters/claude/claude-adapter.js} +34 -10
  8. package/dist/src/adapters/claude/claude-adapter.js.map +1 -0
  9. package/dist/src/adapters/claude/tool-mapper.d.ts +19 -0
  10. package/dist/src/adapters/claude/tool-mapper.d.ts.map +1 -0
  11. package/dist/src/adapters/claude/tool-mapper.js +44 -0
  12. package/dist/src/adapters/claude/tool-mapper.js.map +1 -0
  13. package/dist/src/adapters/types.d.ts +28 -0
  14. package/dist/src/adapters/types.d.ts.map +1 -0
  15. package/dist/src/agent.d.ts +1 -1
  16. package/dist/src/agent.d.ts.map +1 -1
  17. package/dist/src/agent.js +18 -17
  18. package/dist/src/agent.js.map +1 -1
  19. package/dist/src/stage-executor.d.ts +1 -1
  20. package/dist/src/stage-executor.d.ts.map +1 -1
  21. package/dist/src/stage-executor.js +7 -7
  22. package/dist/src/stage-executor.js.map +1 -1
  23. package/dist/src/task-progress-reporter.d.ts +0 -2
  24. package/dist/src/task-progress-reporter.d.ts.map +1 -1
  25. package/dist/src/task-progress-reporter.js +0 -16
  26. package/dist/src/task-progress-reporter.js.map +1 -1
  27. package/dist/src/tools/registry.d.ts +25 -0
  28. package/dist/src/tools/registry.d.ts.map +1 -0
  29. package/dist/src/tools/registry.js +120 -0
  30. package/dist/src/tools/registry.js.map +1 -0
  31. package/dist/src/tools/types.d.ts +80 -0
  32. package/dist/src/tools/types.d.ts.map +1 -0
  33. package/dist/src/types.d.ts +41 -12
  34. package/dist/src/types.d.ts.map +1 -1
  35. package/dist/src/types.js.map +1 -1
  36. package/package.json +1 -1
  37. package/src/{event-transformer.ts → adapters/claude/claude-adapter.ts} +40 -16
  38. package/src/adapters/claude/tool-mapper.ts +46 -0
  39. package/src/adapters/types.ts +31 -0
  40. package/src/agent.ts +19 -17
  41. package/src/stage-executor.ts +11 -11
  42. package/src/task-progress-reporter.ts +0 -19
  43. package/src/tools/registry.ts +129 -0
  44. package/src/tools/types.ts +127 -0
  45. package/src/types.ts +42 -17
  46. package/dist/src/event-transformer.d.ts +0 -10
  47. package/dist/src/event-transformer.d.ts.map +0 -1
  48. package/dist/src/event-transformer.js.map +0 -1
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Registry of all known tools with their metadata.
3
+ * Maps tool names to their definitions.
4
+ */
5
+ const TOOL_DEFINITIONS = {
6
+ // Filesystem tools
7
+ 'Read': {
8
+ name: 'Read',
9
+ category: 'filesystem',
10
+ description: 'Read file contents from the filesystem',
11
+ },
12
+ 'Write': {
13
+ name: 'Write',
14
+ category: 'filesystem',
15
+ description: 'Write content to a file',
16
+ },
17
+ 'Edit': {
18
+ name: 'Edit',
19
+ category: 'filesystem',
20
+ description: 'Edit file with find and replace operations',
21
+ },
22
+ 'Glob': {
23
+ name: 'Glob',
24
+ category: 'filesystem',
25
+ description: 'Find files matching a pattern',
26
+ },
27
+ 'NotebookEdit': {
28
+ name: 'NotebookEdit',
29
+ category: 'filesystem',
30
+ description: 'Edit Jupyter notebook cells',
31
+ },
32
+ // Shell tools
33
+ 'Bash': {
34
+ name: 'Bash',
35
+ category: 'shell',
36
+ description: 'Execute bash commands',
37
+ },
38
+ 'BashOutput': {
39
+ name: 'BashOutput',
40
+ category: 'shell',
41
+ description: 'Read output from a background bash process',
42
+ },
43
+ 'KillShell': {
44
+ name: 'KillShell',
45
+ category: 'shell',
46
+ description: 'Terminate a background bash process',
47
+ },
48
+ // Web tools
49
+ 'WebFetch': {
50
+ name: 'WebFetch',
51
+ category: 'web',
52
+ description: 'Fetch content from a URL',
53
+ },
54
+ 'WebSearch': {
55
+ name: 'WebSearch',
56
+ category: 'web',
57
+ description: 'Search the web',
58
+ },
59
+ // Search tools
60
+ 'Grep': {
61
+ name: 'Grep',
62
+ category: 'search',
63
+ description: 'Search file contents using patterns',
64
+ },
65
+ // Assistant tools
66
+ 'Task': {
67
+ name: 'Task',
68
+ category: 'assistant',
69
+ description: 'Launch a specialized agent for a sub-task',
70
+ },
71
+ 'TodoWrite': {
72
+ name: 'TodoWrite',
73
+ category: 'assistant',
74
+ description: 'Manage task list and track progress',
75
+ },
76
+ 'ExitPlanMode': {
77
+ name: 'ExitPlanMode',
78
+ category: 'assistant',
79
+ description: 'Exit plan mode and present plan to user',
80
+ },
81
+ 'SlashCommand': {
82
+ name: 'SlashCommand',
83
+ category: 'assistant',
84
+ description: 'Execute a slash command',
85
+ },
86
+ };
87
+ /**
88
+ * Tool registry for looking up tool definitions by name.
89
+ * Provides metadata about tools for UI consumption.
90
+ */
91
+ class ToolRegistry {
92
+ /**
93
+ * Get tool definition by name.
94
+ * Returns undefined if tool is not recognized.
95
+ */
96
+ get(name) {
97
+ return TOOL_DEFINITIONS[name];
98
+ }
99
+ /**
100
+ * Get all registered tools.
101
+ */
102
+ getAll() {
103
+ return Object.values(TOOL_DEFINITIONS);
104
+ }
105
+ /**
106
+ * Check if a tool name is registered.
107
+ */
108
+ has(name) {
109
+ return name in TOOL_DEFINITIONS;
110
+ }
111
+ /**
112
+ * Get all tools in a specific category.
113
+ */
114
+ getByCategory(category) {
115
+ return Object.values(TOOL_DEFINITIONS).filter((tool) => tool.category === category);
116
+ }
117
+ }
118
+
119
+ export { ToolRegistry };
120
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sources":["../../../src/tools/registry.ts"],"sourcesContent":["import type { Tool } from './types.js';\n\n/**\n * Registry of all known tools with their metadata.\n * Maps tool names to their definitions.\n */\nconst TOOL_DEFINITIONS: Record<string, Tool> = {\n // Filesystem tools\n 'Read': {\n name: 'Read',\n category: 'filesystem',\n description: 'Read file contents from the filesystem',\n },\n 'Write': {\n name: 'Write',\n category: 'filesystem',\n description: 'Write content to a file',\n },\n 'Edit': {\n name: 'Edit',\n category: 'filesystem',\n description: 'Edit file with find and replace operations',\n },\n 'Glob': {\n name: 'Glob',\n category: 'filesystem',\n description: 'Find files matching a pattern',\n },\n 'NotebookEdit': {\n name: 'NotebookEdit',\n category: 'filesystem',\n description: 'Edit Jupyter notebook cells',\n },\n\n // Shell tools\n 'Bash': {\n name: 'Bash',\n category: 'shell',\n description: 'Execute bash commands',\n },\n 'BashOutput': {\n name: 'BashOutput',\n category: 'shell',\n description: 'Read output from a background bash process',\n },\n 'KillShell': {\n name: 'KillShell',\n category: 'shell',\n description: 'Terminate a background bash process',\n },\n\n // Web tools\n 'WebFetch': {\n name: 'WebFetch',\n category: 'web',\n description: 'Fetch content from a URL',\n },\n 'WebSearch': {\n name: 'WebSearch',\n category: 'web',\n description: 'Search the web',\n },\n\n // Search tools\n 'Grep': {\n name: 'Grep',\n category: 'search',\n description: 'Search file contents using patterns',\n },\n\n // Assistant tools\n 'Task': {\n name: 'Task',\n category: 'assistant',\n description: 'Launch a specialized agent for a sub-task',\n },\n 'TodoWrite': {\n name: 'TodoWrite',\n category: 'assistant',\n description: 'Manage task list and track progress',\n },\n 'ExitPlanMode': {\n name: 'ExitPlanMode',\n category: 'assistant',\n description: 'Exit plan mode and present plan to user',\n },\n 'SlashCommand': {\n name: 'SlashCommand',\n category: 'assistant',\n description: 'Execute a slash command',\n },\n};\n\n/**\n * Tool registry for looking up tool definitions by name.\n * Provides metadata about tools for UI consumption.\n */\nexport class ToolRegistry {\n /**\n * Get tool definition by name.\n * Returns undefined if tool is not recognized.\n */\n get(name: string): Tool | undefined {\n return TOOL_DEFINITIONS[name];\n }\n\n /**\n * Get all registered tools.\n */\n getAll(): Tool[] {\n return Object.values(TOOL_DEFINITIONS);\n }\n\n /**\n * Check if a tool name is registered.\n */\n has(name: string): boolean {\n return name in TOOL_DEFINITIONS;\n }\n\n /**\n * Get all tools in a specific category.\n */\n getByCategory(category: string): Tool[] {\n return Object.values(TOOL_DEFINITIONS).filter(\n (tool) => tool.category === category\n );\n }\n}\n"],"names":[],"mappings":"AAEA;;;AAGG;AACH,MAAM,gBAAgB,GAAyB;;AAE7C,IAAA,MAAM,EAAE;AACN,QAAA,IAAI,EAAE,MAAM;AACZ,QAAA,QAAQ,EAAE,YAAY;AACtB,QAAA,WAAW,EAAE,wCAAwC;AACtD,KAAA;AACD,IAAA,OAAO,EAAE;AACP,QAAA,IAAI,EAAE,OAAO;AACb,QAAA,QAAQ,EAAE,YAAY;AACtB,QAAA,WAAW,EAAE,yBAAyB;AACvC,KAAA;AACD,IAAA,MAAM,EAAE;AACN,QAAA,IAAI,EAAE,MAAM;AACZ,QAAA,QAAQ,EAAE,YAAY;AACtB,QAAA,WAAW,EAAE,4CAA4C;AAC1D,KAAA;AACD,IAAA,MAAM,EAAE;AACN,QAAA,IAAI,EAAE,MAAM;AACZ,QAAA,QAAQ,EAAE,YAAY;AACtB,QAAA,WAAW,EAAE,+BAA+B;AAC7C,KAAA;AACD,IAAA,cAAc,EAAE;AACd,QAAA,IAAI,EAAE,cAAc;AACpB,QAAA,QAAQ,EAAE,YAAY;AACtB,QAAA,WAAW,EAAE,6BAA6B;AAC3C,KAAA;;AAGD,IAAA,MAAM,EAAE;AACN,QAAA,IAAI,EAAE,MAAM;AACZ,QAAA,QAAQ,EAAE,OAAO;AACjB,QAAA,WAAW,EAAE,uBAAuB;AACrC,KAAA;AACD,IAAA,YAAY,EAAE;AACZ,QAAA,IAAI,EAAE,YAAY;AAClB,QAAA,QAAQ,EAAE,OAAO;AACjB,QAAA,WAAW,EAAE,4CAA4C;AAC1D,KAAA;AACD,IAAA,WAAW,EAAE;AACX,QAAA,IAAI,EAAE,WAAW;AACjB,QAAA,QAAQ,EAAE,OAAO;AACjB,QAAA,WAAW,EAAE,qCAAqC;AACnD,KAAA;;AAGD,IAAA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AAC,QAAgB,EAAA;QAC5B,OAAO,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAC3C,CAAC,IAAI,KAAK,IAAI,CAAC,QAAQ,KAAK,QAAQ,CACrC;IACH;AACD;;;;"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Tool category classification for grouping related tools.
3
+ * Makes it easier for UIs to filter and display tools by function.
4
+ */
5
+ export type ToolCategory = 'filesystem' | 'shell' | 'web' | 'assistant' | 'search' | 'unknown';
6
+ /**
7
+ * Base tool interface representing a tool that can be called by the agent.
8
+ * Each tool has a name, category, and human-readable description.
9
+ */
10
+ export interface Tool {
11
+ name: string;
12
+ category: ToolCategory;
13
+ description: string;
14
+ }
15
+ export interface ReadTool extends Tool {
16
+ name: 'Read';
17
+ category: 'filesystem';
18
+ }
19
+ export interface WriteTool extends Tool {
20
+ name: 'Write';
21
+ category: 'filesystem';
22
+ }
23
+ export interface EditTool extends Tool {
24
+ name: 'Edit';
25
+ category: 'filesystem';
26
+ }
27
+ export interface GlobTool extends Tool {
28
+ name: 'Glob';
29
+ category: 'filesystem';
30
+ }
31
+ export interface NotebookEditTool extends Tool {
32
+ name: 'NotebookEdit';
33
+ category: 'filesystem';
34
+ }
35
+ export interface BashTool extends Tool {
36
+ name: 'Bash';
37
+ category: 'shell';
38
+ }
39
+ export interface BashOutputTool extends Tool {
40
+ name: 'BashOutput';
41
+ category: 'shell';
42
+ }
43
+ export interface KillShellTool extends Tool {
44
+ name: 'KillShell';
45
+ category: 'shell';
46
+ }
47
+ export interface WebFetchTool extends Tool {
48
+ name: 'WebFetch';
49
+ category: 'web';
50
+ }
51
+ export interface WebSearchTool extends Tool {
52
+ name: 'WebSearch';
53
+ category: 'web';
54
+ }
55
+ export interface GrepTool extends Tool {
56
+ name: 'Grep';
57
+ category: 'search';
58
+ }
59
+ export interface TaskTool extends Tool {
60
+ name: 'Task';
61
+ category: 'assistant';
62
+ }
63
+ export interface TodoWriteTool extends Tool {
64
+ name: 'TodoWrite';
65
+ category: 'assistant';
66
+ }
67
+ export interface ExitPlanModeTool extends Tool {
68
+ name: 'ExitPlanMode';
69
+ category: 'assistant';
70
+ }
71
+ export interface SlashCommandTool extends Tool {
72
+ name: 'SlashCommand';
73
+ category: 'assistant';
74
+ }
75
+ /**
76
+ * Union type of all known tool types.
77
+ * Useful for discriminated unions and type narrowing.
78
+ */
79
+ export type KnownTool = ReadTool | WriteTool | EditTool | GlobTool | NotebookEditTool | BashTool | BashOutputTool | KillShellTool | WebFetchTool | WebSearchTool | GrepTool | TaskTool | TodoWriteTool | ExitPlanModeTool | SlashCommandTool;
80
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/tools/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,YAAY,GACpB,YAAY,GACZ,OAAO,GACP,KAAK,GACL,WAAW,GACX,QAAQ,GACR,SAAS,CAAC;AAEd;;;GAGG;AACH,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,YAAY,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;CACrB;AAID,MAAM,WAAW,QAAS,SAAQ,IAAI;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,YAAY,CAAC;CACxB;AAED,MAAM,WAAW,SAAU,SAAQ,IAAI;IACrC,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,YAAY,CAAC;CACxB;AAED,MAAM,WAAW,QAAS,SAAQ,IAAI;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,YAAY,CAAC;CACxB;AAED,MAAM,WAAW,QAAS,SAAQ,IAAI;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,YAAY,CAAC;CACxB;AAED,MAAM,WAAW,gBAAiB,SAAQ,IAAI;IAC5C,IAAI,EAAE,cAAc,CAAC;IACr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b,QAAQ,GACR,QAAQ,GACR,aAAa,GACb,gBAAgB,GAChB,gBAAgB,CAAC"}
@@ -55,12 +55,19 @@ export interface ToolCallEvent extends BaseEvent {
55
55
  toolName: string;
56
56
  callId: string;
57
57
  args: Record<string, any>;
58
+ parentToolUseId?: string | null;
59
+ tool?: import('./tools/types.js').Tool;
60
+ category?: import('./tools/types.js').ToolCategory;
58
61
  }
59
62
  export interface ToolResultEvent extends BaseEvent {
60
63
  type: 'tool_result';
61
64
  toolName: string;
62
65
  callId: string;
63
66
  result: any;
67
+ isError?: boolean;
68
+ parentToolUseId?: string | null;
69
+ tool?: import('./tools/types.js').Tool;
70
+ category?: import('./tools/types.js').ToolCategory;
64
71
  }
65
72
  export interface MessageStartEvent extends BaseEvent {
66
73
  type: 'message_start';
@@ -86,6 +93,14 @@ export interface UserMessageEvent extends BaseEvent {
86
93
  export interface StatusEvent extends BaseEvent {
87
94
  type: 'status';
88
95
  phase: string;
96
+ stage?: string;
97
+ kind?: string;
98
+ branch?: string;
99
+ prUrl?: string;
100
+ workflowId?: string;
101
+ taskId?: string;
102
+ messageId?: string;
103
+ model?: string;
89
104
  [key: string]: any;
90
105
  }
91
106
  export interface InitEvent extends BaseEvent {
@@ -95,6 +110,13 @@ export interface InitEvent extends BaseEvent {
95
110
  permissionMode: string;
96
111
  cwd: string;
97
112
  apiKeySource: string;
113
+ agents?: string[];
114
+ slashCommands?: string[];
115
+ outputStyle?: string;
116
+ mcpServers?: Array<{
117
+ name: string;
118
+ status: string;
119
+ }>;
98
120
  }
99
121
  export interface CompactBoundaryEvent extends BaseEvent {
100
122
  type: 'compact_boundary';
@@ -103,10 +125,28 @@ export interface CompactBoundaryEvent extends BaseEvent {
103
125
  }
104
126
  export interface DoneEvent extends BaseEvent {
105
127
  type: 'done';
128
+ result?: string;
106
129
  durationMs?: number;
130
+ durationApiMs?: number;
107
131
  numTurns?: number;
108
132
  totalCostUsd?: number;
109
133
  usage?: any;
134
+ modelUsage?: {
135
+ [modelName: string]: {
136
+ inputTokens: number;
137
+ outputTokens: number;
138
+ cacheReadInputTokens: number;
139
+ cacheCreationInputTokens: number;
140
+ webSearchRequests: number;
141
+ costUSD: number;
142
+ contextWindow: number;
143
+ };
144
+ };
145
+ permissionDenials?: Array<{
146
+ tool_name: string;
147
+ tool_use_id: string;
148
+ tool_input: Record<string, unknown>;
149
+ }>;
110
150
  }
111
151
  export interface ErrorEvent extends BaseEvent {
112
152
  type: 'error';
@@ -116,17 +156,6 @@ export interface ErrorEvent extends BaseEvent {
116
156
  context?: Record<string, any>;
117
157
  sdkError?: any;
118
158
  }
119
- export interface DiffEvent extends BaseEvent {
120
- type: 'diff';
121
- file: string;
122
- patch: string;
123
- summary?: string;
124
- }
125
- export interface FileWriteEvent extends BaseEvent {
126
- type: 'file_write';
127
- path: string;
128
- bytes: number;
129
- }
130
159
  export interface MetricEvent extends BaseEvent {
131
160
  type: 'metric';
132
161
  key: string;
@@ -142,7 +171,7 @@ export interface RawSDKEvent extends BaseEvent {
142
171
  type: 'raw_sdk_event';
143
172
  sdkMessage: any;
144
173
  }
145
- export type AgentEvent = TokenEvent | ContentBlockStartEvent | ContentBlockStopEvent | ToolCallEvent | ToolResultEvent | MessageStartEvent | MessageDeltaEvent | MessageStopEvent | UserMessageEvent | StatusEvent | InitEvent | CompactBoundaryEvent | DoneEvent | ErrorEvent | DiffEvent | FileWriteEvent | MetricEvent | ArtifactEvent | RawSDKEvent;
174
+ export type AgentEvent = TokenEvent | ContentBlockStartEvent | ContentBlockStopEvent | ToolCallEvent | ToolResultEvent | MessageStartEvent | MessageDeltaEvent | MessageStopEvent | UserMessageEvent | StatusEvent | InitEvent | CompactBoundaryEvent | DoneEvent | ErrorEvent | MetricEvent | ArtifactEvent | RawSDKEvent;
146
175
  export interface ExecutionResult {
147
176
  results: any[];
148
177
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,IAA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EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,YAAY,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sources":["../../src/types.ts"],"sourcesContent":["// PostHog Task model (matches Array's OpenAPI schema)\nexport interface Task {\n id: string;\n title: string;\n description: string;\n origin_product: 'error_tracking' | 'eval_clusters' | 'user_created' | 'support_queue' | 'session_summaries';\n position?: number;\n workflow?: string | null;\n current_stage?: string | null;\n github_integration?: number | null;\n repository_config?: unknown; // JSONField\n repository_list: string;\n primary_repository: string;\n github_branch: string | null;\n github_pr_url: string | null;\n created_at: string;\n updated_at: string;\n}\n\nexport interface SupportingFile {\n name: string;\n content: string;\n type: 'plan' | 'context' | 'reference' | 'output';\n created_at: string;\n}\n\n// Removed legacy ExecutionMode in favor of configurable workflows\n\nexport enum PermissionMode {\n PLAN = \"plan\",\n DEFAULT = \"default\",\n ACCEPT_EDITS = \"acceptEdits\",\n BYPASS = \"bypassPermissions\"\n}\n\nexport interface ExecutionOptions {\n repositoryPath?: string;\n permissionMode?: PermissionMode;\n}\n\n// Base event with timestamp\ninterface BaseEvent {\n ts: number;\n}\n\n// Streaming content events\nexport interface TokenEvent extends BaseEvent {\n type: 'token';\n content: string;\n contentType?: 'text' | 'thinking' | 'tool_input';\n}\n\nexport interface ContentBlockStartEvent extends BaseEvent {\n type: 'content_block_start';\n index: number;\n contentType: 'text' | 'tool_use' | 'thinking';\n toolName?: string;\n toolId?: string;\n}\n\nexport interface ContentBlockStopEvent extends BaseEvent {\n type: 'content_block_stop';\n index: number;\n}\n\n// Tool events\nexport interface ToolCallEvent extends BaseEvent {\n type: 'tool_call';\n toolName: string;\n callId: string;\n args: Record<string, any>;\n}\n\nexport interface ToolResultEvent extends BaseEvent {\n type: 'tool_result';\n toolName: string;\n callId: string;\n result: any;\n}\n\n// Message lifecycle events\nexport interface MessageStartEvent extends BaseEvent {\n type: 'message_start';\n messageId?: string;\n model?: string;\n}\n\nexport interface MessageDeltaEvent extends BaseEvent {\n type: 'message_delta';\n stopReason?: string;\n stopSequence?: string;\n usage?: {\n outputTokens: number;\n };\n}\n\nexport interface MessageStopEvent extends BaseEvent {\n type: 'message_stop';\n}\n\n// User message events\nexport interface UserMessageEvent extends BaseEvent {\n type: 'user_message';\n content: string;\n isSynthetic?: boolean;\n}\n\n// System events\nexport interface StatusEvent extends BaseEvent {\n type: 'status';\n phase: string;\n [key: string]: any;\n}\n\nexport interface InitEvent extends BaseEvent {\n type: 'init';\n model: string;\n tools: string[];\n permissionMode: string;\n cwd: string;\n apiKeySource: string;\n}\n\nexport interface CompactBoundaryEvent extends BaseEvent {\n type: 'compact_boundary';\n trigger: 'manual' | 'auto';\n preTokens: number;\n}\n\n// Result events\nexport interface DoneEvent extends BaseEvent {\n type: 'done';\n durationMs?: number;\n numTurns?: number;\n totalCostUsd?: number;\n usage?: any;\n}\n\nexport interface ErrorEvent extends BaseEvent {\n type: 'error';\n message: string;\n error?: any;\n errorType?: string;\n context?: Record<string, any>; // Partial error context for debugging\n sdkError?: any; // Original SDK error object\n}\n\n// Legacy events (keeping for backwards compatibility)\nexport interface DiffEvent extends BaseEvent {\n type: 'diff';\n file: string;\n patch: string;\n summary?: string;\n}\n\nexport interface FileWriteEvent extends BaseEvent {\n type: 'file_write';\n path: string;\n bytes: number;\n}\n\nexport interface MetricEvent extends BaseEvent {\n type: 'metric';\n key: string;\n value: number;\n unit?: string;\n}\n\nexport interface ArtifactEvent extends BaseEvent {\n type: 'artifact';\n kind: string;\n content: any;\n}\n\nexport interface RawSDKEvent extends BaseEvent {\n type: 'raw_sdk_event';\n sdkMessage: any; // Full SDK message for debugging\n}\n\nexport type AgentEvent =\n | TokenEvent\n | ContentBlockStartEvent\n | ContentBlockStopEvent\n | ToolCallEvent\n | ToolResultEvent\n | MessageStartEvent\n | MessageDeltaEvent\n | MessageStopEvent\n | UserMessageEvent\n | StatusEvent\n | InitEvent\n | CompactBoundaryEvent\n | DoneEvent\n | ErrorEvent\n | DiffEvent\n | FileWriteEvent\n | MetricEvent\n | ArtifactEvent\n | RawSDKEvent;\n\nexport interface ExecutionResult {\n results: any[];\n}\n\nexport interface PlanResult {\n plan: string;\n}\n\nexport interface TaskExecutionResult {\n task: Task;\n plan?: string;\n executionResult?: ExecutionResult;\n // Deprecated: mode removed in workflow-based execution\n}\n\n// MCP Server configuration types (re-exported from Claude SDK for convenience)\nexport type McpServerConfig = {\n type?: 'stdio';\n command: string;\n args?: string[];\n env?: Record<string, string>;\n} | {\n type: 'sse';\n url: string;\n headers?: Record<string, string>;\n} | {\n type: 'http';\n url: string;\n headers?: Record<string, string>;\n} | {\n type: 'sdk';\n name: string;\n instance?: any; // McpServer instance\n};\n\nexport interface AgentConfig {\n workingDirectory?: string;\n onEvent?: (event: AgentEvent) => void;\n\n // PostHog API configuration\n posthogApiUrl?: string;\n posthogApiKey?: string;\n\n // PostHog MCP configuration\n posthogMcpUrl?: string;\n\n // MCP Server configuration\n // Additional MCP servers (PostHog MCP is always included by default)\n // You can override the PostHog MCP config by providing mcpServers.posthog\n mcpServers?: Record<string, McpServerConfig>;\n\n // Logging configuration\n debug?: boolean;\n}\n\nexport interface PostHogAPIConfig {\n apiUrl: string;\n apiKey: string;\n}\n\n// URL mention types\nexport type ResourceType = 'error' | 'experiment' | 'insight' | 'feature_flag' | 'generic';\n\nexport interface PostHogResource {\n type: ResourceType;\n id: string;\n url: string;\n title?: string;\n content: string;\n metadata?: Record<string, any>;\n}\n\nexport interface UrlMention {\n url: string;\n type: ResourceType;\n id?: string;\n label?: string;\n}"],"names":[],"mappings":"AA0BA;IAEY;AAAZ,CAAA,UAAY,cAAc,EAAA;AACxB,IAAA,cAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACb,IAAA,cAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACnB,IAAA,cAAA,CAAA,cAAA,CAAA,GAAA,aAA4B;AAC5B,IAAA,cAAA,CAAA,QAAA,CAAA,GAAA,mBAA4B;AAC9B,CAAC,EALW,cAAc,KAAd,cAAc,GAAA,EAAA,CAAA,CAAA;;;;"}
1
+ {"version":3,"file":"types.js","sources":["../../src/types.ts"],"sourcesContent":["// PostHog Task model (matches Array's OpenAPI schema)\nexport interface Task {\n id: string;\n title: string;\n description: string;\n origin_product: 'error_tracking' | 'eval_clusters' | 'user_created' | 'support_queue' | 'session_summaries';\n position?: number;\n workflow?: string | null;\n current_stage?: string | null;\n github_integration?: number | null;\n repository_config?: unknown; // JSONField\n repository_list: string;\n primary_repository: string;\n github_branch: string | null;\n github_pr_url: string | null;\n created_at: string;\n updated_at: string;\n}\n\nexport interface SupportingFile {\n name: string;\n content: string;\n type: 'plan' | 'context' | 'reference' | 'output';\n created_at: string;\n}\n\n// Removed legacy ExecutionMode in favor of configurable workflows\n\nexport enum PermissionMode {\n PLAN = \"plan\",\n DEFAULT = \"default\",\n ACCEPT_EDITS = \"acceptEdits\",\n BYPASS = \"bypassPermissions\"\n}\n\nexport interface ExecutionOptions {\n repositoryPath?: string;\n permissionMode?: PermissionMode;\n}\n\n// Base event with timestamp\ninterface BaseEvent {\n ts: number;\n}\n\n// Streaming content events\nexport interface TokenEvent extends BaseEvent {\n type: 'token';\n content: string;\n contentType?: 'text' | 'thinking' | 'tool_input';\n}\n\nexport interface ContentBlockStartEvent extends BaseEvent {\n type: 'content_block_start';\n index: number;\n contentType: 'text' | 'tool_use' | 'thinking';\n toolName?: string;\n toolId?: string;\n}\n\nexport interface ContentBlockStopEvent extends BaseEvent {\n type: 'content_block_stop';\n index: number;\n}\n\n// Tool events\nexport interface ToolCallEvent extends BaseEvent {\n type: 'tool_call';\n toolName: string;\n callId: string;\n args: Record<string, any>;\n parentToolUseId?: string | null; // For nested tool calls (subagents)\n // Tool metadata (enriched by adapter for UI consumption)\n tool?: import('./tools/types.js').Tool;\n category?: import('./tools/types.js').ToolCategory;\n}\n\nexport interface ToolResultEvent extends BaseEvent {\n type: 'tool_result';\n toolName: string;\n callId: string;\n result: any;\n isError?: boolean; // Whether the tool execution failed\n parentToolUseId?: string | null; // For nested tool calls (subagents)\n // Tool metadata (enriched by adapter for UI consumption)\n tool?: import('./tools/types.js').Tool;\n category?: import('./tools/types.js').ToolCategory;\n}\n\n// Message lifecycle events\nexport interface MessageStartEvent extends BaseEvent {\n type: 'message_start';\n messageId?: string;\n model?: string;\n}\n\nexport interface MessageDeltaEvent extends BaseEvent {\n type: 'message_delta';\n stopReason?: string;\n stopSequence?: string;\n usage?: {\n outputTokens: number;\n };\n}\n\nexport interface MessageStopEvent extends BaseEvent {\n type: 'message_stop';\n}\n\n// User message events\nexport interface UserMessageEvent extends BaseEvent {\n type: 'user_message';\n content: string;\n isSynthetic?: boolean;\n}\n\n// System events\nexport interface StatusEvent extends BaseEvent {\n type: 'status';\n phase: string;\n // Common optional fields (varies by phase):\n stage?: string; // Workflow stage (plan, code, complete)\n kind?: string; // Kind of status (plan, implementation)\n branch?: string; // Git branch name\n prUrl?: string; // Pull request URL\n workflowId?: string; // Workflow identifier\n taskId?: string; // Task identifier\n messageId?: string; // Claude message ID\n model?: string; // Model name\n [key: string]: any; // Allow additional fields\n}\n\nexport interface InitEvent extends BaseEvent {\n type: 'init';\n model: string;\n tools: string[];\n permissionMode: string;\n cwd: string;\n apiKeySource: string;\n agents?: string[];\n slashCommands?: string[];\n outputStyle?: string;\n mcpServers?: Array<{ name: string; status: string }>;\n}\n\nexport interface CompactBoundaryEvent extends BaseEvent {\n type: 'compact_boundary';\n trigger: 'manual' | 'auto';\n preTokens: number;\n}\n\n// Result events\nexport interface DoneEvent extends BaseEvent {\n type: 'done';\n result?: string; // Final summary text from Claude\n durationMs?: number;\n durationApiMs?: number; // API-only duration (excluding local processing)\n numTurns?: number;\n totalCostUsd?: number;\n usage?: any;\n modelUsage?: { // Per-model usage breakdown\n [modelName: string]: {\n inputTokens: number;\n outputTokens: number;\n cacheReadInputTokens: number;\n cacheCreationInputTokens: number;\n webSearchRequests: number;\n costUSD: number;\n contextWindow: number;\n };\n };\n permissionDenials?: Array<{ // Tools that were denied by permissions\n tool_name: string;\n tool_use_id: string;\n tool_input: Record<string, unknown>;\n }>;\n}\n\nexport interface ErrorEvent extends BaseEvent {\n type: 'error';\n message: string;\n error?: any;\n errorType?: string;\n context?: Record<string, any>; // Partial error context for debugging\n sdkError?: any; // Original SDK error object\n}\n\n// Metric and artifact events (general purpose, not tool-specific)\nexport interface MetricEvent extends BaseEvent {\n type: 'metric';\n key: string;\n value: number;\n unit?: string;\n}\n\nexport interface ArtifactEvent extends BaseEvent {\n type: 'artifact';\n kind: string;\n content: any;\n}\n\nexport interface RawSDKEvent extends BaseEvent {\n type: 'raw_sdk_event';\n sdkMessage: any; // Full SDK message for debugging\n}\n\nexport type AgentEvent =\n | TokenEvent\n | ContentBlockStartEvent\n | ContentBlockStopEvent\n | ToolCallEvent\n | ToolResultEvent\n | MessageStartEvent\n | MessageDeltaEvent\n | MessageStopEvent\n | UserMessageEvent\n | StatusEvent\n | InitEvent\n | CompactBoundaryEvent\n | DoneEvent\n | ErrorEvent\n | MetricEvent\n | ArtifactEvent\n | RawSDKEvent;\n\nexport interface ExecutionResult {\n results: any[];\n}\n\nexport interface PlanResult {\n plan: string;\n}\n\nexport interface TaskExecutionResult {\n task: Task;\n plan?: string;\n executionResult?: ExecutionResult;\n // Deprecated: mode removed in workflow-based execution\n}\n\n// MCP Server configuration types (re-exported from Claude SDK for convenience)\nexport type McpServerConfig = {\n type?: 'stdio';\n command: string;\n args?: string[];\n env?: Record<string, string>;\n} | {\n type: 'sse';\n url: string;\n headers?: Record<string, string>;\n} | {\n type: 'http';\n url: string;\n headers?: Record<string, string>;\n} | {\n type: 'sdk';\n name: string;\n instance?: any; // McpServer instance\n};\n\nexport interface AgentConfig {\n workingDirectory?: string;\n onEvent?: (event: AgentEvent) => void;\n\n // PostHog API configuration\n posthogApiUrl?: string;\n posthogApiKey?: string;\n\n // PostHog MCP configuration\n posthogMcpUrl?: string;\n\n // MCP Server configuration\n // Additional MCP servers (PostHog MCP is always included by default)\n // You can override the PostHog MCP config by providing mcpServers.posthog\n mcpServers?: Record<string, McpServerConfig>;\n\n // Logging configuration\n debug?: boolean;\n}\n\nexport interface PostHogAPIConfig {\n apiUrl: string;\n apiKey: string;\n}\n\n// URL mention types\nexport type ResourceType = 'error' | 'experiment' | 'insight' | 'feature_flag' | 'generic';\n\nexport interface PostHogResource {\n type: ResourceType;\n id: string;\n url: string;\n title?: string;\n content: string;\n metadata?: Record<string, any>;\n}\n\nexport interface UrlMention {\n url: string;\n type: ResourceType;\n id?: string;\n label?: string;\n}"],"names":[],"mappings":"AA0BA;IAEY;AAAZ,CAAA,UAAY,cAAc,EAAA;AACxB,IAAA,cAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACb,IAAA,cAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACnB,IAAA,cAAA,CAAA,cAAA,CAAA,GAAA,aAA4B;AAC5B,IAAA,cAAA,CAAA,QAAA,CAAA,GAAA,mBAA4B;AAC9B,CAAC,EALW,cAAc,KAAd,cAAc,GAAA,EAAA,CAAA,CAAA;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/agent",
3
- "version": "1.7.0",
3
+ "version": "1.9.0",
4
4
  "description": "TypeScript agent framework wrapping Claude Agent SDK with Git-based workflow for PostHog tasks",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -1,7 +1,15 @@
1
- import type { AgentEvent } from './types.js';
1
+ import type { AgentEvent } from '../../types.js';
2
2
  import type { SDKMessage } from '@anthropic-ai/claude-agent-sdk';
3
+ import type { ProviderAdapter } from '../types.js';
4
+ import { ClaudeToolMapper } from './tool-mapper.js';
3
5
 
4
- export class EventTransformer {
6
+ /**
7
+ * Claude provider adapter.
8
+ * Transforms Claude SDK messages into our standardized AgentEvent format.
9
+ */
10
+ export class ClaudeAdapter implements ProviderAdapter {
11
+ readonly name = 'claude';
12
+ private toolMapper = new ClaudeToolMapper();
5
13
  createRawSDKEvent(sdkMessage: any): AgentEvent {
6
14
  return {
7
15
  type: 'raw_sdk_event',
@@ -117,23 +125,26 @@ export class EventTransformer {
117
125
  // Handle assistant messages (full message, not streaming)
118
126
  if (sdkMessage.type === 'assistant') {
119
127
  const message = sdkMessage.message;
120
-
128
+
121
129
  // Extract tool calls from content blocks
122
130
  if (message.content && Array.isArray(message.content)) {
123
131
  for (const block of message.content) {
124
132
  if (block.type === 'tool_use') {
125
- // Return first tool_call event found
126
- return {
133
+ // Create tool_call event and enrich with metadata
134
+ const toolCallEvent = {
127
135
  ...baseEvent,
128
- type: 'tool_call',
136
+ type: 'tool_call' as const,
129
137
  toolName: block.name,
130
138
  callId: block.id,
131
- args: block.input || {}
139
+ args: block.input || {},
140
+ parentToolUseId: sdkMessage.parent_tool_use_id
132
141
  };
142
+ // Enrich with tool metadata
143
+ return this.toolMapper.enrichToolCall(toolCallEvent);
133
144
  }
134
145
  }
135
146
  }
136
-
147
+
137
148
  // If no tool calls, emit status event
138
149
  return {
139
150
  ...baseEvent,
@@ -147,22 +158,27 @@ export class EventTransformer {
147
158
  // Handle user messages
148
159
  if (sdkMessage.type === 'user') {
149
160
  const message = sdkMessage.message;
150
-
161
+
151
162
  // Check for tool results in content blocks
152
163
  if (message?.content && Array.isArray(message.content)) {
153
164
  for (const block of message.content) {
154
165
  if (block.type === 'tool_result') {
155
- return {
166
+ // Create tool_result event and enrich with metadata
167
+ const toolResultEvent = {
156
168
  ...baseEvent,
157
- type: 'tool_result',
169
+ type: 'tool_result' as const,
158
170
  toolName: block.tool_name || 'unknown',
159
171
  callId: block.tool_use_id || '',
160
- result: block.content
172
+ result: block.content,
173
+ isError: block.is_error,
174
+ parentToolUseId: sdkMessage.parent_tool_use_id
161
175
  };
176
+ // Enrich with tool metadata
177
+ return this.toolMapper.enrichToolResult(toolResultEvent);
162
178
  }
163
179
  }
164
180
  }
165
-
181
+
166
182
  // Otherwise extract text content
167
183
  const textContent = this.extractUserContent(message?.content);
168
184
  if (!textContent) {
@@ -182,10 +198,14 @@ export class EventTransformer {
182
198
  return {
183
199
  ...baseEvent,
184
200
  type: 'done',
201
+ result: sdkMessage.result,
185
202
  durationMs: sdkMessage.duration_ms,
203
+ durationApiMs: sdkMessage.duration_api_ms,
186
204
  numTurns: sdkMessage.num_turns,
187
205
  totalCostUsd: sdkMessage.total_cost_usd,
188
- usage: sdkMessage.usage
206
+ usage: sdkMessage.usage,
207
+ modelUsage: sdkMessage.modelUsage,
208
+ permissionDenials: sdkMessage.permission_denials
189
209
  };
190
210
  } else {
191
211
  return {
@@ -214,7 +234,11 @@ export class EventTransformer {
214
234
  tools: sdkMessage.tools,
215
235
  permissionMode: sdkMessage.permissionMode,
216
236
  cwd: sdkMessage.cwd,
217
- apiKeySource: sdkMessage.apiKeySource
237
+ apiKeySource: sdkMessage.apiKeySource,
238
+ agents: sdkMessage.agents,
239
+ slashCommands: sdkMessage.slash_commands,
240
+ outputStyle: sdkMessage.output_style,
241
+ mcpServers: sdkMessage.mcp_servers
218
242
  };
219
243
  } else if (sdkMessage.subtype === 'compact_boundary') {
220
244
  return {
@@ -229,7 +253,7 @@ export class EventTransformer {
229
253
  return null;
230
254
  }
231
255
 
232
- createStatusEvent(phase: string, additionalData?: any): AgentEvent {
256
+ createStatusEvent(phase: string, additionalData?: any): import('../../types.js').StatusEvent {
233
257
  return {
234
258
  type: 'status',
235
259
  ts: Date.now(),
@@ -0,0 +1,46 @@
1
+ import type { ToolCallEvent, ToolResultEvent } from '../../types.js';
2
+ import { ToolRegistry } from '../../tools/registry.js';
3
+
4
+ /**
5
+ * Maps Claude tool names to our tool type system.
6
+ * Enriches tool events with metadata for better UI consumption.
7
+ */
8
+ export class ClaudeToolMapper {
9
+ private registry = new ToolRegistry();
10
+
11
+ /**
12
+ * Enrich a tool call event with tool metadata.
13
+ * Looks up the tool definition and adds it to the event.
14
+ */
15
+ enrichToolCall(event: ToolCallEvent): ToolCallEvent {
16
+ const tool = this.registry.get(event.toolName);
17
+ if (!tool) {
18
+ // Tool not recognized, return as-is
19
+ return event;
20
+ }
21
+
22
+ return {
23
+ ...event,
24
+ tool,
25
+ category: tool.category,
26
+ };
27
+ }
28
+
29
+ /**
30
+ * Enrich a tool result event with tool metadata.
31
+ * Looks up the tool definition and adds it to the event.
32
+ */
33
+ enrichToolResult(event: ToolResultEvent): ToolResultEvent {
34
+ const tool = this.registry.get(event.toolName);
35
+ if (!tool) {
36
+ // Tool not recognized, return as-is
37
+ return event;
38
+ }
39
+
40
+ return {
41
+ ...event,
42
+ tool,
43
+ category: tool.category,
44
+ };
45
+ }
46
+ }
@@ -0,0 +1,31 @@
1
+ import type { AgentEvent, StatusEvent } from '../types.js';
2
+
3
+ /**
4
+ * Provider adapter interface for transforming provider-specific messages
5
+ * into our standardized AgentEvent format.
6
+ *
7
+ * This allows us to support multiple AI providers (Claude, Gemini, OpenAI, etc.)
8
+ * while maintaining a consistent event interface for consumers.
9
+ */
10
+ export interface ProviderAdapter {
11
+ /** Provider name (e.g., 'claude', 'gemini') */
12
+ name: string;
13
+
14
+ /**
15
+ * Transform a provider-specific SDK message into an AgentEvent.
16
+ * Returns null if the message should be ignored.
17
+ */
18
+ transform(sdkMessage: unknown): AgentEvent | null;
19
+
20
+ /**
21
+ * Create a standardized status event.
22
+ * Used for workflow stage transitions and other status updates.
23
+ */
24
+ createStatusEvent(phase: string, additionalData?: any): StatusEvent;
25
+
26
+ /**
27
+ * Create a raw SDK event for debugging purposes.
28
+ * Wraps the original SDK message in a raw_sdk_event.
29
+ */
30
+ createRawSDKEvent(sdkMessage: any): AgentEvent;
31
+ }