@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.
- package/LICENSE +33 -0
- package/dist/index.d.ts +11 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/src/adapters/claude/claude-adapter.d.ts +3 -3
- package/dist/src/adapters/claude/claude-adapter.d.ts.map +1 -1
- package/dist/src/adapters/claude/claude-adapter.js +111 -156
- package/dist/src/adapters/claude/claude-adapter.js.map +1 -1
- package/dist/src/adapters/claude/tool-mapper.d.ts +1 -1
- package/dist/src/adapters/claude/tool-mapper.d.ts.map +1 -1
- package/dist/src/adapters/claude/tool-mapper.js.map +1 -1
- package/dist/src/adapters/types.d.ts +1 -1
- package/dist/src/adapters/types.d.ts.map +1 -1
- package/dist/src/agent.d.ts +7 -7
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +85 -143
- package/dist/src/agent.js.map +1 -1
- package/dist/src/agents/execution.js.map +1 -1
- package/dist/src/agents/planning.js.map +1 -1
- package/dist/src/agents/research.js.map +1 -1
- package/dist/src/file-manager.d.ts +4 -4
- package/dist/src/file-manager.d.ts.map +1 -1
- package/dist/src/file-manager.js +58 -59
- package/dist/src/file-manager.js.map +1 -1
- package/dist/src/git-manager.d.ts +1 -1
- package/dist/src/git-manager.d.ts.map +1 -1
- package/dist/src/git-manager.js +70 -87
- package/dist/src/git-manager.js.map +1 -1
- package/dist/src/posthog-api.d.ts +3 -2
- package/dist/src/posthog-api.d.ts.map +1 -1
- package/dist/src/posthog-api.js +22 -22
- package/dist/src/posthog-api.js.map +1 -1
- package/dist/src/prompt-builder.d.ts +3 -3
- package/dist/src/prompt-builder.d.ts.map +1 -1
- package/dist/src/prompt-builder.js +93 -123
- package/dist/src/prompt-builder.js.map +1 -1
- package/dist/src/task-manager.d.ts +4 -4
- package/dist/src/task-manager.d.ts.map +1 -1
- package/dist/src/task-manager.js +18 -19
- package/dist/src/task-manager.js.map +1 -1
- package/dist/src/task-progress-reporter.d.ts +4 -3
- package/dist/src/task-progress-reporter.d.ts.map +1 -1
- package/dist/src/task-progress-reporter.js +54 -59
- package/dist/src/task-progress-reporter.js.map +1 -1
- package/dist/src/template-manager.d.ts +1 -1
- package/dist/src/template-manager.d.ts.map +1 -1
- package/dist/src/template-manager.js +28 -30
- package/dist/src/template-manager.js.map +1 -1
- package/dist/src/todo-manager.d.ts +3 -3
- package/dist/src/todo-manager.d.ts.map +1 -1
- package/dist/src/todo-manager.js +24 -29
- package/dist/src/todo-manager.js.map +1 -1
- package/dist/src/tools/registry.d.ts +1 -1
- package/dist/src/tools/registry.js +60 -60
- package/dist/src/tools/registry.js.map +1 -1
- package/dist/src/tools/types.d.ts +31 -31
- package/dist/src/types.d.ts +33 -33
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/dist/src/utils/logger.d.ts +4 -4
- package/dist/src/utils/logger.d.ts.map +1 -1
- package/dist/src/utils/logger.js +8 -8
- package/dist/src/utils/logger.js.map +1 -1
- package/dist/src/workflow/config.d.ts +1 -1
- package/dist/src/workflow/config.d.ts.map +1 -1
- package/dist/src/workflow/config.js +18 -18
- package/dist/src/workflow/config.js.map +1 -1
- package/dist/src/workflow/steps/build.d.ts +1 -1
- package/dist/src/workflow/steps/build.d.ts.map +1 -1
- package/dist/src/workflow/steps/build.js +38 -46
- package/dist/src/workflow/steps/build.js.map +1 -1
- package/dist/src/workflow/steps/finalize.d.ts +1 -1
- package/dist/src/workflow/steps/finalize.d.ts.map +1 -1
- package/dist/src/workflow/steps/finalize.js +48 -54
- package/dist/src/workflow/steps/finalize.js.map +1 -1
- package/dist/src/workflow/steps/plan.d.ts +1 -1
- package/dist/src/workflow/steps/plan.d.ts.map +1 -1
- package/dist/src/workflow/steps/plan.js +46 -58
- package/dist/src/workflow/steps/plan.js.map +1 -1
- package/dist/src/workflow/steps/research.d.ts +1 -1
- package/dist/src/workflow/steps/research.d.ts.map +1 -1
- package/dist/src/workflow/steps/research.js +56 -68
- package/dist/src/workflow/steps/research.js.map +1 -1
- package/dist/src/workflow/types.d.ts +12 -12
- package/dist/src/workflow/types.d.ts.map +1 -1
- package/dist/src/workflow/utils.d.ts +1 -1
- package/dist/src/workflow/utils.d.ts.map +1 -1
- package/dist/src/workflow/utils.js +4 -7
- package/dist/src/workflow/utils.js.map +1 -1
- package/package.json +6 -6
- package/src/adapters/claude/claude-adapter.ts +168 -220
- package/src/adapters/claude/tool-mapper.ts +2 -2
- package/src/adapters/types.ts +1 -1
- package/src/agent.ts +444 -579
- package/src/agents/execution.ts +1 -1
- package/src/agents/planning.ts +1 -1
- package/src/agents/research.ts +1 -0
- package/src/file-manager.ts +63 -64
- package/src/git-manager.ts +88 -144
- package/src/posthog-api.ts +82 -122
- package/src/prompt-builder.ts +135 -180
- package/src/task-manager.ts +30 -38
- package/src/task-progress-reporter.ts +59 -70
- package/src/template-manager.ts +45 -98
- package/src/todo-manager.ts +30 -35
- package/src/tools/registry.ts +62 -62
- package/src/tools/types.ts +36 -36
- package/src/types.ts +71 -93
- package/src/utils/logger.ts +56 -62
- package/src/workflow/config.ts +48 -48
- package/src/workflow/steps/build.ts +113 -122
- package/src/workflow/steps/finalize.ts +182 -214
- package/src/workflow/steps/plan.ts +131 -151
- package/src/workflow/steps/research.ts +186 -205
- package/src/workflow/types.ts +36 -38
- package/src/workflow/utils.ts +34 -37
package/src/task-manager.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { randomBytes } from
|
|
1
|
+
import { randomBytes } from 'crypto';
|
|
2
2
|
|
|
3
3
|
export interface TaskExecutionState {
|
|
4
4
|
taskId: string;
|
|
5
|
-
status:
|
|
6
|
-
mode:
|
|
5
|
+
status: 'running' | 'completed' | 'failed' | 'canceled' | 'timeout';
|
|
6
|
+
mode: 'plan_only' | 'plan_and_build' | 'build_only';
|
|
7
7
|
result?: any;
|
|
8
8
|
startedAt: number;
|
|
9
9
|
completedAt?: number;
|
|
@@ -11,21 +11,21 @@ export interface TaskExecutionState {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export class TaskManager {
|
|
14
|
-
|
|
14
|
+
private executionStates = new Map<string, TaskExecutionState>();
|
|
15
15
|
private defaultTimeout = 10 * 60 * 1000; // 10 minutes
|
|
16
16
|
|
|
17
17
|
generateExecutionId(): string {
|
|
18
|
-
return randomBytes(16).toString(
|
|
18
|
+
return randomBytes(16).toString('hex');
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
startExecution(
|
|
22
|
-
taskId: string,
|
|
23
|
-
mode:
|
|
24
|
-
executionId: string = this.generateExecutionId()
|
|
22
|
+
taskId: string,
|
|
23
|
+
mode: 'plan_only' | 'plan_and_build' | 'build_only',
|
|
24
|
+
executionId: string = this.generateExecutionId()
|
|
25
25
|
): TaskExecutionState {
|
|
26
26
|
const executionState: TaskExecutionState = {
|
|
27
27
|
taskId,
|
|
28
|
-
status:
|
|
28
|
+
status: 'running',
|
|
29
29
|
mode,
|
|
30
30
|
startedAt: Date.now(),
|
|
31
31
|
abortController: new AbortController(),
|
|
@@ -33,7 +33,7 @@ export class TaskManager {
|
|
|
33
33
|
|
|
34
34
|
this.executionStates.set(executionId, executionState);
|
|
35
35
|
this.scheduleTimeout(executionId);
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
return executionState;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -43,7 +43,7 @@ export class TaskManager {
|
|
|
43
43
|
throw new Error(`Execution ${executionId} not found`);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
if (execution.result && execution.status ===
|
|
46
|
+
if (execution.result && execution.status === 'completed') {
|
|
47
47
|
return execution.result;
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -56,21 +56,16 @@ export class TaskManager {
|
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
if (
|
|
60
|
-
currentExecution.status === "completed" &&
|
|
61
|
-
currentExecution.result
|
|
62
|
-
) {
|
|
59
|
+
if (currentExecution.status === 'completed' && currentExecution.result) {
|
|
63
60
|
clearInterval(checkInterval);
|
|
64
61
|
resolve(currentExecution.result);
|
|
65
62
|
} else if (
|
|
66
|
-
currentExecution.status ===
|
|
67
|
-
currentExecution.status ===
|
|
68
|
-
currentExecution.status ===
|
|
63
|
+
currentExecution.status === 'failed' ||
|
|
64
|
+
currentExecution.status === 'canceled' ||
|
|
65
|
+
currentExecution.status === 'timeout'
|
|
69
66
|
) {
|
|
70
67
|
clearInterval(checkInterval);
|
|
71
|
-
reject(
|
|
72
|
-
new Error(`Execution ${executionId} ${currentExecution.status}`),
|
|
73
|
-
);
|
|
68
|
+
reject(new Error(`Execution ${executionId} ${currentExecution.status}`));
|
|
74
69
|
}
|
|
75
70
|
}, 100);
|
|
76
71
|
});
|
|
@@ -82,7 +77,7 @@ export class TaskManager {
|
|
|
82
77
|
throw new Error(`Execution ${executionId} not found`);
|
|
83
78
|
}
|
|
84
79
|
|
|
85
|
-
execution.status =
|
|
80
|
+
execution.status = 'completed';
|
|
86
81
|
execution.result = result;
|
|
87
82
|
execution.completedAt = Date.now();
|
|
88
83
|
}
|
|
@@ -93,11 +88,11 @@ export class TaskManager {
|
|
|
93
88
|
throw new Error(`Execution ${executionId} not found`);
|
|
94
89
|
}
|
|
95
90
|
|
|
96
|
-
execution.status =
|
|
91
|
+
execution.status = 'failed';
|
|
97
92
|
execution.completedAt = Date.now();
|
|
98
93
|
execution.result = {
|
|
99
94
|
error: error.message,
|
|
100
|
-
status:
|
|
95
|
+
status: 'failed',
|
|
101
96
|
};
|
|
102
97
|
}
|
|
103
98
|
|
|
@@ -107,14 +102,14 @@ export class TaskManager {
|
|
|
107
102
|
throw new Error(`Execution ${executionId} not found`);
|
|
108
103
|
}
|
|
109
104
|
|
|
110
|
-
execution.status =
|
|
105
|
+
execution.status = 'canceled';
|
|
111
106
|
execution.completedAt = Date.now();
|
|
112
107
|
execution.abortController?.abort();
|
|
113
|
-
|
|
108
|
+
|
|
114
109
|
if (!execution.result) {
|
|
115
110
|
execution.result = {
|
|
116
|
-
status:
|
|
117
|
-
message:
|
|
111
|
+
status: 'canceled',
|
|
112
|
+
message: 'Execution was canceled',
|
|
118
113
|
};
|
|
119
114
|
}
|
|
120
115
|
}
|
|
@@ -131,21 +126,18 @@ export class TaskManager {
|
|
|
131
126
|
return this.executionStates.get(executionId)?.abortController;
|
|
132
127
|
}
|
|
133
128
|
|
|
134
|
-
private scheduleTimeout(
|
|
135
|
-
executionId: string,
|
|
136
|
-
timeout: number = this.defaultTimeout,
|
|
137
|
-
): void {
|
|
129
|
+
private scheduleTimeout(executionId: string, timeout: number = this.defaultTimeout): void {
|
|
138
130
|
setTimeout(() => {
|
|
139
131
|
const execution = this.executionStates.get(executionId);
|
|
140
|
-
if (execution && execution.status ===
|
|
141
|
-
execution.status =
|
|
132
|
+
if (execution && execution.status === 'running') {
|
|
133
|
+
execution.status = 'timeout';
|
|
142
134
|
execution.completedAt = Date.now();
|
|
143
135
|
execution.abortController?.abort();
|
|
144
|
-
|
|
136
|
+
|
|
145
137
|
if (!execution.result) {
|
|
146
138
|
execution.result = {
|
|
147
|
-
status:
|
|
148
|
-
message:
|
|
139
|
+
status: 'timeout',
|
|
140
|
+
message: 'Execution timed out',
|
|
149
141
|
};
|
|
150
142
|
}
|
|
151
143
|
}
|
|
@@ -160,4 +152,4 @@ export class TaskManager {
|
|
|
160
152
|
}
|
|
161
153
|
}
|
|
162
154
|
}
|
|
163
|
-
}
|
|
155
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { Logger } from './utils/logger.js';
|
|
2
|
+
import type { PostHogAPIClient, TaskRunUpdate } from './posthog-api.js';
|
|
3
|
+
import type { AgentEvent, TaskRun, LogEntry } from './types.js';
|
|
4
4
|
|
|
5
5
|
interface ProgressMetadata {
|
|
6
6
|
totalSteps?: number;
|
|
@@ -17,9 +17,10 @@ export class TaskProgressReporter {
|
|
|
17
17
|
private logger: Logger;
|
|
18
18
|
private taskRun?: TaskRun;
|
|
19
19
|
private taskId?: string;
|
|
20
|
+
private outputLog: string[] = [];
|
|
20
21
|
private totalSteps?: number;
|
|
21
22
|
private lastLogEntry?: string;
|
|
22
|
-
private tokenBuffer: string =
|
|
23
|
+
private tokenBuffer: string = '';
|
|
23
24
|
private tokenCount: number = 0;
|
|
24
25
|
private tokenFlushTimer?: NodeJS.Timeout;
|
|
25
26
|
private readonly TOKEN_BATCH_SIZE = 100;
|
|
@@ -30,7 +31,7 @@ export class TaskProgressReporter {
|
|
|
30
31
|
|
|
31
32
|
constructor(posthogAPI: PostHogAPIClient | undefined, logger: Logger) {
|
|
32
33
|
this.posthogAPI = posthogAPI;
|
|
33
|
-
this.logger = logger.child(
|
|
34
|
+
this.logger = logger.child('TaskProgressReporter');
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
get runId(): string | undefined {
|
|
@@ -47,15 +48,13 @@ export class TaskProgressReporter {
|
|
|
47
48
|
|
|
48
49
|
try {
|
|
49
50
|
const run = await this.posthogAPI.createTaskRun(taskId, {
|
|
50
|
-
status:
|
|
51
|
+
status: 'started',
|
|
51
52
|
});
|
|
52
53
|
this.taskRun = run;
|
|
53
|
-
this.
|
|
54
|
+
this.outputLog = [];
|
|
55
|
+
this.logger.debug('Created task run', { taskId, runId: run.id });
|
|
54
56
|
} catch (error) {
|
|
55
|
-
this.logger.warn(
|
|
56
|
-
taskId,
|
|
57
|
-
error: (error as Error).message,
|
|
58
|
-
});
|
|
57
|
+
this.logger.warn('Failed to create task run', { taskId, error: (error as Error).message });
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
60
|
|
|
@@ -64,32 +63,25 @@ export class TaskProgressReporter {
|
|
|
64
63
|
try {
|
|
65
64
|
await this.logWriteQueue;
|
|
66
65
|
} catch (error) {
|
|
67
|
-
this.logger.debug(
|
|
68
|
-
error,
|
|
69
|
-
});
|
|
66
|
+
this.logger.debug('Pending logs failed to write during completion', { error });
|
|
70
67
|
}
|
|
71
68
|
|
|
72
69
|
if (this.tokenFlushTimer) {
|
|
73
70
|
clearTimeout(this.tokenFlushTimer);
|
|
74
71
|
this.tokenFlushTimer = undefined;
|
|
75
72
|
}
|
|
76
|
-
await this.update({ status:
|
|
73
|
+
await this.update({ status: 'completed' }, 'Task execution completed');
|
|
77
74
|
}
|
|
78
75
|
|
|
79
76
|
async fail(error: Error | string): Promise<void> {
|
|
80
77
|
try {
|
|
81
78
|
await this.logWriteQueue;
|
|
82
79
|
} catch (logError) {
|
|
83
|
-
this.logger.debug(
|
|
84
|
-
error: logError,
|
|
85
|
-
});
|
|
80
|
+
this.logger.debug('Pending logs failed to write during fail', { error: logError });
|
|
86
81
|
}
|
|
87
82
|
|
|
88
|
-
const message = typeof error ===
|
|
89
|
-
await this.update(
|
|
90
|
-
{ status: "failed", error_message: message },
|
|
91
|
-
`Task execution failed: ${message}`,
|
|
92
|
-
);
|
|
83
|
+
const message = typeof error === 'string' ? error : error.message;
|
|
84
|
+
await this.update({ status: 'failed', error_message: message }, `Task execution failed: ${message}`);
|
|
93
85
|
}
|
|
94
86
|
|
|
95
87
|
async appendLog(line: string): Promise<void> {
|
|
@@ -102,11 +94,11 @@ export class TaskProgressReporter {
|
|
|
102
94
|
}
|
|
103
95
|
|
|
104
96
|
const buffer = this.tokenBuffer;
|
|
105
|
-
this.tokenBuffer =
|
|
97
|
+
this.tokenBuffer = '';
|
|
106
98
|
this.tokenCount = 0;
|
|
107
99
|
|
|
108
100
|
await this.appendLogEntry({
|
|
109
|
-
type:
|
|
101
|
+
type: 'token',
|
|
110
102
|
message: buffer,
|
|
111
103
|
});
|
|
112
104
|
}
|
|
@@ -119,7 +111,7 @@ export class TaskProgressReporter {
|
|
|
119
111
|
this.tokenFlushTimer = setTimeout(() => {
|
|
120
112
|
this.tokenFlushTimer = undefined;
|
|
121
113
|
this.flushTokens().catch((err) => {
|
|
122
|
-
this.logger.warn(
|
|
114
|
+
this.logger.warn('Failed to flush tokens', { error: err });
|
|
123
115
|
});
|
|
124
116
|
}, this.TOKEN_FLUSH_INTERVAL_MS);
|
|
125
117
|
}
|
|
@@ -134,7 +126,7 @@ export class TaskProgressReporter {
|
|
|
134
126
|
|
|
135
127
|
this.logWriteQueue = this.logWriteQueue
|
|
136
128
|
.catch((error) => {
|
|
137
|
-
this.logger.debug(
|
|
129
|
+
this.logger.debug('Previous log append failed', {
|
|
138
130
|
taskId,
|
|
139
131
|
runId,
|
|
140
132
|
error: error instanceof Error ? error.message : String(error),
|
|
@@ -159,7 +151,7 @@ export class TaskProgressReporter {
|
|
|
159
151
|
await this.posthogAPI.appendTaskRunLog(taskId, runId, [entry]);
|
|
160
152
|
return;
|
|
161
153
|
} catch (error) {
|
|
162
|
-
this.logger.warn(
|
|
154
|
+
this.logger.warn('Failed to append log entry', {
|
|
163
155
|
taskId,
|
|
164
156
|
runId,
|
|
165
157
|
attempt,
|
|
@@ -172,7 +164,7 @@ export class TaskProgressReporter {
|
|
|
172
164
|
}
|
|
173
165
|
|
|
174
166
|
const delayMs =
|
|
175
|
-
this.LOG_APPEND_RETRY_BASE_DELAY_MS * 2
|
|
167
|
+
this.LOG_APPEND_RETRY_BASE_DELAY_MS * Math.pow(2, attempt - 1);
|
|
176
168
|
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
177
169
|
}
|
|
178
170
|
}
|
|
@@ -184,7 +176,7 @@ export class TaskProgressReporter {
|
|
|
184
176
|
}
|
|
185
177
|
|
|
186
178
|
switch (event.type) {
|
|
187
|
-
case
|
|
179
|
+
case 'token': {
|
|
188
180
|
// Batch tokens for efficiency
|
|
189
181
|
this.tokenBuffer += event.content;
|
|
190
182
|
this.tokenCount++;
|
|
@@ -201,9 +193,9 @@ export class TaskProgressReporter {
|
|
|
201
193
|
return;
|
|
202
194
|
}
|
|
203
195
|
|
|
204
|
-
case
|
|
196
|
+
case 'content_block_start': {
|
|
205
197
|
await this.appendLogEntry({
|
|
206
|
-
type:
|
|
198
|
+
type: 'content_block_start',
|
|
207
199
|
message: JSON.stringify({
|
|
208
200
|
index: event.index,
|
|
209
201
|
contentType: event.contentType,
|
|
@@ -215,9 +207,9 @@ export class TaskProgressReporter {
|
|
|
215
207
|
return;
|
|
216
208
|
}
|
|
217
209
|
|
|
218
|
-
case
|
|
210
|
+
case 'content_block_stop': {
|
|
219
211
|
await this.appendLogEntry({
|
|
220
|
-
type:
|
|
212
|
+
type: 'content_block_stop',
|
|
221
213
|
message: JSON.stringify({
|
|
222
214
|
index: event.index,
|
|
223
215
|
ts: event.ts,
|
|
@@ -226,9 +218,9 @@ export class TaskProgressReporter {
|
|
|
226
218
|
return;
|
|
227
219
|
}
|
|
228
220
|
|
|
229
|
-
case
|
|
221
|
+
case 'message_start': {
|
|
230
222
|
await this.appendLogEntry({
|
|
231
|
-
type:
|
|
223
|
+
type: 'message_start',
|
|
232
224
|
message: JSON.stringify({
|
|
233
225
|
messageId: event.messageId,
|
|
234
226
|
model: event.model,
|
|
@@ -238,9 +230,9 @@ export class TaskProgressReporter {
|
|
|
238
230
|
return;
|
|
239
231
|
}
|
|
240
232
|
|
|
241
|
-
case
|
|
233
|
+
case 'message_delta': {
|
|
242
234
|
await this.appendLogEntry({
|
|
243
|
-
type:
|
|
235
|
+
type: 'message_delta',
|
|
244
236
|
message: JSON.stringify({
|
|
245
237
|
stopReason: event.stopReason,
|
|
246
238
|
stopSequence: event.stopSequence,
|
|
@@ -251,17 +243,17 @@ export class TaskProgressReporter {
|
|
|
251
243
|
return;
|
|
252
244
|
}
|
|
253
245
|
|
|
254
|
-
case
|
|
246
|
+
case 'message_stop': {
|
|
255
247
|
await this.appendLogEntry({
|
|
256
|
-
type:
|
|
248
|
+
type: 'message_stop',
|
|
257
249
|
message: JSON.stringify({ ts: event.ts }),
|
|
258
250
|
});
|
|
259
251
|
return;
|
|
260
252
|
}
|
|
261
253
|
|
|
262
|
-
case
|
|
254
|
+
case 'status': {
|
|
263
255
|
await this.appendLogEntry({
|
|
264
|
-
type:
|
|
256
|
+
type: 'status',
|
|
265
257
|
message: JSON.stringify({
|
|
266
258
|
phase: event.phase,
|
|
267
259
|
kind: event.kind,
|
|
@@ -276,9 +268,9 @@ export class TaskProgressReporter {
|
|
|
276
268
|
return;
|
|
277
269
|
}
|
|
278
270
|
|
|
279
|
-
case
|
|
271
|
+
case 'artifact': {
|
|
280
272
|
await this.appendLogEntry({
|
|
281
|
-
type:
|
|
273
|
+
type: 'artifact',
|
|
282
274
|
message: JSON.stringify({
|
|
283
275
|
kind: event.kind,
|
|
284
276
|
content: event.content,
|
|
@@ -288,9 +280,9 @@ export class TaskProgressReporter {
|
|
|
288
280
|
return;
|
|
289
281
|
}
|
|
290
282
|
|
|
291
|
-
case
|
|
283
|
+
case 'init': {
|
|
292
284
|
await this.appendLogEntry({
|
|
293
|
-
type:
|
|
285
|
+
type: 'init',
|
|
294
286
|
message: JSON.stringify({
|
|
295
287
|
model: event.model,
|
|
296
288
|
tools: event.tools,
|
|
@@ -303,9 +295,9 @@ export class TaskProgressReporter {
|
|
|
303
295
|
return;
|
|
304
296
|
}
|
|
305
297
|
|
|
306
|
-
case
|
|
298
|
+
case 'metric': {
|
|
307
299
|
await this.appendLogEntry({
|
|
308
|
-
type:
|
|
300
|
+
type: 'metric',
|
|
309
301
|
message: JSON.stringify({
|
|
310
302
|
key: event.key,
|
|
311
303
|
value: event.value,
|
|
@@ -316,9 +308,9 @@ export class TaskProgressReporter {
|
|
|
316
308
|
return;
|
|
317
309
|
}
|
|
318
310
|
|
|
319
|
-
case
|
|
311
|
+
case 'compact_boundary': {
|
|
320
312
|
await this.appendLogEntry({
|
|
321
|
-
type:
|
|
313
|
+
type: 'compact_boundary',
|
|
322
314
|
message: JSON.stringify({
|
|
323
315
|
trigger: event.trigger,
|
|
324
316
|
preTokens: event.preTokens,
|
|
@@ -328,9 +320,9 @@ export class TaskProgressReporter {
|
|
|
328
320
|
return;
|
|
329
321
|
}
|
|
330
322
|
|
|
331
|
-
case
|
|
323
|
+
case 'tool_call': {
|
|
332
324
|
await this.appendLogEntry({
|
|
333
|
-
type:
|
|
325
|
+
type: 'tool_call',
|
|
334
326
|
message: JSON.stringify({
|
|
335
327
|
toolName: event.toolName,
|
|
336
328
|
callId: event.callId,
|
|
@@ -342,9 +334,9 @@ export class TaskProgressReporter {
|
|
|
342
334
|
return;
|
|
343
335
|
}
|
|
344
336
|
|
|
345
|
-
case
|
|
337
|
+
case 'tool_result': {
|
|
346
338
|
await this.appendLogEntry({
|
|
347
|
-
type:
|
|
339
|
+
type: 'tool_result',
|
|
348
340
|
message: JSON.stringify({
|
|
349
341
|
toolName: event.toolName,
|
|
350
342
|
callId: event.callId,
|
|
@@ -357,9 +349,9 @@ export class TaskProgressReporter {
|
|
|
357
349
|
return;
|
|
358
350
|
}
|
|
359
351
|
|
|
360
|
-
case
|
|
352
|
+
case 'error': {
|
|
361
353
|
await this.appendLogEntry({
|
|
362
|
-
type:
|
|
354
|
+
type: 'error',
|
|
363
355
|
message: JSON.stringify({
|
|
364
356
|
message: event.message,
|
|
365
357
|
errorType: event.errorType,
|
|
@@ -370,9 +362,9 @@ export class TaskProgressReporter {
|
|
|
370
362
|
return;
|
|
371
363
|
}
|
|
372
364
|
|
|
373
|
-
case
|
|
365
|
+
case 'done': {
|
|
374
366
|
await this.appendLogEntry({
|
|
375
|
-
type:
|
|
367
|
+
type: 'done',
|
|
376
368
|
message: JSON.stringify({
|
|
377
369
|
result: event.result,
|
|
378
370
|
durationMs: event.durationMs,
|
|
@@ -388,9 +380,9 @@ export class TaskProgressReporter {
|
|
|
388
380
|
return;
|
|
389
381
|
}
|
|
390
382
|
|
|
391
|
-
case
|
|
383
|
+
case 'user_message': {
|
|
392
384
|
await this.appendLogEntry({
|
|
393
|
-
type:
|
|
385
|
+
type: 'user_message',
|
|
394
386
|
message: JSON.stringify({
|
|
395
387
|
content: event.content,
|
|
396
388
|
isSynthetic: event.isSynthetic,
|
|
@@ -400,14 +392,14 @@ export class TaskProgressReporter {
|
|
|
400
392
|
return;
|
|
401
393
|
}
|
|
402
394
|
|
|
403
|
-
case
|
|
395
|
+
case 'raw_sdk_event': {
|
|
404
396
|
// Skip raw SDK events - too verbose for persistence
|
|
405
397
|
return;
|
|
406
398
|
}
|
|
407
399
|
|
|
408
400
|
default:
|
|
409
401
|
// For any unfamiliar event types, log them as-is
|
|
410
|
-
this.logger.debug(
|
|
402
|
+
this.logger.debug('Unknown event type', { type: (event as any).type });
|
|
411
403
|
return;
|
|
412
404
|
}
|
|
413
405
|
}
|
|
@@ -421,11 +413,11 @@ export class TaskProgressReporter {
|
|
|
421
413
|
if (logLine && logLine !== this.lastLogEntry) {
|
|
422
414
|
try {
|
|
423
415
|
await this.posthogAPI.appendTaskRunLog(this.taskId, this.runId, [
|
|
424
|
-
{ type:
|
|
416
|
+
{ type: 'info', message: logLine }
|
|
425
417
|
]);
|
|
426
418
|
this.lastLogEntry = logLine;
|
|
427
419
|
} catch (error) {
|
|
428
|
-
this.logger.warn(
|
|
420
|
+
this.logger.warn('Failed to append log entry', {
|
|
429
421
|
taskId: this.taskId,
|
|
430
422
|
runId: this.runId,
|
|
431
423
|
error: (error as Error).message,
|
|
@@ -436,14 +428,10 @@ export class TaskProgressReporter {
|
|
|
436
428
|
// Update other fields if provided
|
|
437
429
|
if (Object.keys(update).length > 0) {
|
|
438
430
|
try {
|
|
439
|
-
const run = await this.posthogAPI.updateTaskRun(
|
|
440
|
-
this.taskId,
|
|
441
|
-
this.runId,
|
|
442
|
-
update,
|
|
443
|
-
);
|
|
431
|
+
const run = await this.posthogAPI.updateTaskRun(this.taskId, this.runId, update);
|
|
444
432
|
this.taskRun = run;
|
|
445
433
|
} catch (error) {
|
|
446
|
-
this.logger.warn(
|
|
434
|
+
this.logger.warn('Failed to update task run', {
|
|
447
435
|
taskId: this.taskId,
|
|
448
436
|
runId: this.runId,
|
|
449
437
|
error: (error as Error).message,
|
|
@@ -451,4 +439,5 @@ export class TaskProgressReporter {
|
|
|
451
439
|
}
|
|
452
440
|
}
|
|
453
441
|
}
|
|
442
|
+
|
|
454
443
|
}
|