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