Skip to content

Commit e28930a

Browse files
committed
get latest run instead
1 parent 2ed6a51 commit e28930a

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/main/services/agent.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { randomUUID } from "node:crypto";
22
import { Agent, PermissionMode } from "@posthog/agent";
33
import { type BrowserWindow, type IpcMainInvokeEvent, ipcMain } from "electron";
4-
import type { TaskRun } from "@/shared/types";
54

65
interface AgentStartParams {
76
taskId: string;
@@ -124,12 +123,8 @@ export function registerAgentIpc(
124123
const pollTaskProgress = async () => {
125124
if (abortController.signal.aborted) return;
126125
try {
127-
const runs = await posthogClient.listTaskRuns(posthogTaskId);
128-
const latestRun = runs?.sort(
129-
(a: TaskRun, b: TaskRun) =>
130-
new Date(b.created_at).getTime() -
131-
new Date(a.created_at).getTime(),
132-
)[0];
126+
const task = await posthogClient.fetchTask(posthogTaskId);
127+
const latestRun = task?.latest_run;
133128

134129
// Only emit progress for runs created after this workflow started
135130
if (
@@ -146,7 +141,7 @@ export function registerAgentIpc(
146141
});
147142
}
148143
} catch (err) {
149-
console.warn("[agent] failed to fetch task runs", err);
144+
console.warn("[agent] failed to fetch task progress", err);
150145
}
151146
};
152147

0 commit comments

Comments
 (0)