Skip to content

Commit 405b75c

Browse files
committed
fixed complete task sdk
1 parent 1b4434a commit 405b75c

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

examples/retrieve.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ async function basic() {
2828

2929
poll: do {
3030
// Wait for Task to Finish
31-
const status = await browseruse.tasks.getTask(rsp.id);
31+
const status = await browseruse.tasks.getTask({ task_id: rsp.id });
3232

3333
switch (status.status) {
3434
case "started":
35-
case "paused":
35+
case "created":
3636
case "stopped":
3737
log = `agent ${status.status} ${status.sessionId} ${status.steps.length} steps`;
3838

@@ -73,13 +73,13 @@ async function structured() {
7373
poll: do {
7474
// Wait for Task to Finish
7575
const status = await browseruse.tasks.getTask({
76-
taskId: rsp.id,
76+
task_id: rsp.id,
7777
schema: TaskOutput,
7878
});
7979

8080
switch (status.status) {
8181
case "started":
82-
case "paused":
82+
case "created":
8383
case "stopped": {
8484
log = `agent ${status.status} ${status.sessionId} | ${status.steps.length} steps`;
8585

examples/run.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ async function basic() {
2222
task: "What's the weather in SF and what's the temperature?",
2323
});
2424

25+
26+
for await (const msg of rsp.watch()) {
27+
console.log(msg);
28+
}
29+
2530
const result = await rsp.complete();
2631

2732
console.log(`Basic: ${result.output}`);

src/wrapper/lib/parse.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ export function wrapCreateTaskResponse(
157157
switch (res.status) {
158158
case "finished":
159159
case "stopped":
160+
break poll;
160161

162+
case "created":
161163
case "started":
162164
await new Promise((resolve) => setTimeout(resolve, intervalMs));
163165
break;
@@ -236,14 +238,15 @@ export function wrapCreateTaskResponse(
236238
options?: RequestOptions,
237239
): Promise<TaskViewWithSchema<ZodType> | TaskView> {
238240
for await (const msg of _watch(response.id, config, options)) {
239-
switch (msg.data.status) {
240-
case "finished":
241-
case "stopped":
242-
case "started":
243-
break;
244-
// default:
245-
// throw new ExhaustiveSwitchCheck(msg.data.status as never);
241+
// Return on terminal statuses
242+
if (msg.data.status === "finished" || msg.data.status === "stopped") {
243+
if (schema != null) {
244+
return parseStructuredTaskOutput<ZodType>(msg.data, schema);
245+
} else {
246+
return msg.data;
247+
}
246248
}
249+
// Continue polling for any other status (created, started, or future statuses)
247250
}
248251

249252
throw new Error("Stream ended before the task finished!");

0 commit comments

Comments
 (0)