@posthog/agent 1.3.1 → 1.5.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.
@@ -120,15 +120,30 @@ export class TaskProgressReporter {
120
120
  case 'content_block_start':
121
121
  case 'content_block_stop':
122
122
  case 'compact_boundary':
123
- case 'tool_call':
124
- case 'tool_result':
125
123
  case 'message_start':
126
124
  case 'message_stop':
127
125
  case 'metric':
128
126
  case 'artifact':
127
+ case 'raw_sdk_event':
129
128
  // Skip verbose streaming artifacts from persistence
130
129
  return;
131
130
 
131
+ case 'tool_call': {
132
+ const logLine = this.formatToolCallEvent(event);
133
+ if (logLine) {
134
+ await this.appendLog(logLine);
135
+ }
136
+ return;
137
+ }
138
+
139
+ case 'tool_result': {
140
+ const logLine = this.formatToolResultEvent(event);
141
+ if (logLine) {
142
+ await this.appendLog(logLine);
143
+ }
144
+ return;
145
+ }
146
+
132
147
  case 'file_write':
133
148
  await this.appendLog(this.formatFileWriteEvent(event));
134
149
  return;
@@ -284,4 +299,31 @@ export class TaskProgressReporter {
284
299
  const compact = text.replace(/\s+/g, ' ').trim();
285
300
  return compact.length > max ? `${compact.slice(0, max)}…` : compact;
286
301
  }
302
+
303
+ private formatToolCallEvent(event: Extract<AgentEvent, { type: 'tool_call' }>): string | null {
304
+ // File operations to track
305
+ const fileOps = ['read_file', 'write', 'search_replace', 'delete_file', 'glob_file_search', 'file_search', 'list_dir', 'edit_notebook'];
306
+ // Terminal commands to track
307
+ const terminalOps = ['run_terminal_cmd', 'bash', 'shell'];
308
+
309
+ if (fileOps.includes(event.toolName)) {
310
+ // Extract file path from args
311
+ const path = event.args?.target_file || event.args?.file_path || event.args?.target_notebook || event.args?.target_directory || '';
312
+ return `[tool] ${event.toolName}${path ? `: ${path}` : ''}`;
313
+ } else if (terminalOps.includes(event.toolName)) {
314
+ // Extract command from args
315
+ const cmd = event.args?.command || '';
316
+ const truncated = cmd.length > 80 ? `${cmd.slice(0, 80)}…` : cmd;
317
+ return `[cmd] ${truncated}`;
318
+ }
319
+
320
+ // Skip other tools from persistence
321
+ return null;
322
+ }
323
+
324
+ private formatToolResultEvent(event: Extract<AgentEvent, { type: 'tool_result' }>): string | null {
325
+ // We don't need to log tool results separately - tool calls are sufficient
326
+ // This keeps the log concise
327
+ return null;
328
+ }
287
329
  }
package/src/types.ts CHANGED
@@ -141,6 +141,8 @@ export interface ErrorEvent extends BaseEvent {
141
141
  message: string;
142
142
  error?: any;
143
143
  errorType?: string;
144
+ context?: Record<string, any>; // Partial error context for debugging
145
+ sdkError?: any; // Original SDK error object
144
146
  }
145
147
 
146
148
  // Legacy events (keeping for backwards compatibility)
@@ -170,6 +172,11 @@ export interface ArtifactEvent extends BaseEvent {
170
172
  content: any;
171
173
  }
172
174
 
175
+ export interface RawSDKEvent extends BaseEvent {
176
+ type: 'raw_sdk_event';
177
+ sdkMessage: any; // Full SDK message for debugging
178
+ }
179
+
173
180
  export type AgentEvent =
174
181
  | TokenEvent
175
182
  | ContentBlockStartEvent
@@ -188,7 +195,8 @@ export type AgentEvent =
188
195
  | DiffEvent
189
196
  | FileWriteEvent
190
197
  | MetricEvent
191
- | ArtifactEvent;
198
+ | ArtifactEvent
199
+ | RawSDKEvent;
192
200
 
193
201
  export interface ExecutionResult {
194
202
  results: any[];