1
1
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
3
+ import type { ZodType } from 'zod' ;
4
+
3
5
import { APIResource } from '../core/resource' ;
4
6
import * as TasksAPI from './tasks' ;
5
7
import { APIPromise } from '../core/api-promise' ;
6
8
import { RequestOptions } from '../internal/request-options' ;
7
9
import { path } from '../internal/utils/path' ;
10
+ import {
11
+ parseStructuredTaskOutput ,
12
+ stringifyStructuredOutput ,
13
+ type TaskViewWithStructuredOutput ,
14
+ type GetTaskStatusParamsWithStructuredOutput ,
15
+ type RunTaskCreateParamsWithStructuredOutput ,
16
+ } from '../lib/parse' ;
8
17
9
18
export class Tasks extends APIResource {
10
19
/**
@@ -14,6 +23,15 @@ export class Tasks extends APIResource {
14
23
return this . _client . post ( '/tasks' , { body, ...options } ) ;
15
24
}
16
25
26
+ createWithStructuredOutput < T extends ZodType > (
27
+ body : RunTaskCreateParamsWithStructuredOutput < T > ,
28
+ options ?: RequestOptions ,
29
+ ) : APIPromise < TaskViewWithStructuredOutput < T > > {
30
+ return this . create ( stringifyStructuredOutput ( body ) , options ) . _thenUnwrap ( ( rsp ) =>
31
+ parseStructuredTaskOutput ( rsp as TaskView , body ) ,
32
+ ) ;
33
+ }
34
+
17
35
/**
18
36
* Get Task
19
37
*/
@@ -25,6 +43,20 @@ export class Tasks extends APIResource {
25
43
return this . _client . get ( path `/tasks/${ taskID } ` , { query, ...options } ) ;
26
44
}
27
45
46
+ retrieveWithStructuredOutput < T extends ZodType > (
47
+ taskID : string ,
48
+ query : GetTaskStatusParamsWithStructuredOutput < T > ,
49
+ options ?: RequestOptions ,
50
+ ) : APIPromise < TaskViewWithStructuredOutput < T > > {
51
+ // NOTE: We manually remove structuredOutputJson from the query object because
52
+ // it's not a valid Browser Use Cloud parameter.
53
+ const { structuredOutputJson, ...rest } = query ;
54
+
55
+ return this . retrieve ( taskID , rest , options ) . _thenUnwrap ( ( rsp ) =>
56
+ parseStructuredTaskOutput ( rsp as TaskView , query ) ,
57
+ ) ;
58
+ }
59
+
28
60
/**
29
61
* Update Task
30
62
*/
0 commit comments