@@ -54,7 +54,7 @@ export class Tasks extends APIResource {
54
54
*
55
55
* Returns:
56
56
*
57
- * - The created task with its initial details
57
+ * - The created task ID together with the task's session ID
58
58
*
59
59
* Raises:
60
60
*
@@ -65,34 +65,71 @@ export class Tasks extends APIResource {
65
65
create < T extends ZodType > (
66
66
body : TaskCreateParamsWithSchema < T > ,
67
67
options ?: RequestOptions ,
68
- ) : APIPromise < TaskViewWithSchema < T > > ;
69
- create ( body : TaskCreateParams , options ?: RequestOptions ) : APIPromise < TaskView > ;
68
+ ) : APIPromise < TaskCreateResponse > ;
69
+ create ( body : TaskCreateParams , options ?: RequestOptions ) : APIPromise < TaskCreateResponse > ;
70
70
create (
71
71
body : TaskCreateParams | TaskCreateParamsWithSchema < ZodType > ,
72
72
options ?: RequestOptions ,
73
- ) : APIPromise < unknown > {
74
- if ( body . structuredOutputJson == null || typeof body . structuredOutputJson === 'string' ) {
75
- return this . _client . post ( '/tasks' , { body, ...options } ) ;
76
- }
77
-
78
- if ( typeof body . structuredOutputJson === 'object' ) {
73
+ ) : APIPromise < TaskCreateResponse > {
74
+ if ( body . structuredOutputJson != null && typeof body . structuredOutputJson === 'object' ) {
79
75
const schema = body . structuredOutputJson ;
80
76
81
77
const _body : TaskCreateParams = {
82
78
...body ,
83
79
structuredOutputJson : stringifyStructuredOutput ( schema ) ,
84
80
} ;
85
81
86
- return this . _client
87
- . post ( '/tasks' , { body : _body , ...options } )
88
- . _thenUnwrap ( ( rsp ) => parseStructuredTaskOutput ( rsp as TaskView , schema ) ) ;
82
+ return this . _client . post ( '/tasks' , { body : _body , ...options } ) ;
89
83
}
90
84
91
85
return this . _client . post ( '/tasks' , { body, ...options } ) ;
92
86
}
93
87
88
+ /**
89
+ * Get detailed information about a specific AI agent task.
90
+ *
91
+ * Retrieves comprehensive information about a task, including its current status,
92
+ * progress, and detailed execution data. You can choose to get just the status
93
+ * (for quick polling) or full details including steps and file information.
94
+ *
95
+ * Use this endpoint to:
96
+ *
97
+ * - Monitor task progress in real-time
98
+ * - Review completed task results
99
+ * - Debug failed tasks by examining steps
100
+ * - Download output files and logs
101
+ *
102
+ * Args:
103
+ *
104
+ * - task_id: The unique identifier of the agent task
105
+ *
106
+ * Returns:
107
+ *
108
+ * - Complete task information
109
+ *
110
+ * Raises:
111
+ *
112
+ * - 404: If the user agent task doesn't exist
113
+ */
114
+ retrieve < T extends ZodType > (
115
+ req : { taskId : string ; schema : T } ,
116
+ options ?: RequestOptions ,
117
+ ) : APIPromise < TaskViewWithSchema < T > > ;
118
+ retrieve ( taskID : string , options ?: RequestOptions ) : APIPromise < TaskView > ;
119
+ retrieve ( req : string | { taskId : string ; schema : ZodType } , options ?: RequestOptions ) : APIPromise < unknown > {
120
+ if ( typeof req === 'string' ) {
121
+ return this . _client . get ( path `/tasks/${ req } ` , options ) ;
122
+ }
123
+
124
+ const { taskId, schema } = req ;
125
+
126
+ return this . _client
127
+ . get ( path `/tasks/${ taskId } ` , options )
128
+ . _thenUnwrap ( ( rsp ) => parseStructuredTaskOutput ( rsp as TaskView , schema ) ) ;
129
+ }
130
+
94
131
private async * watch (
95
- data : TaskCreateParams ,
132
+ taskId : string ,
96
133
config : { interval : number } ,
97
134
options ?: RequestOptions ,
98
135
) : AsyncGenerator < { event : 'status' ; data : TaskView } > {
@@ -106,14 +143,7 @@ export class Tasks extends APIResource {
106
143
107
144
tick . current ++ ;
108
145
109
- let status : TaskView ;
110
-
111
- // NOTE: We take action on each tick.
112
- if ( state . current == null ) {
113
- status = await this . create ( data , options ) ;
114
- } else {
115
- status = await this . retrieve ( state . current . taskId ) ;
116
- }
146
+ const status = await this . retrieve ( taskId ) ;
117
147
118
148
const [ newState , event ] = reducer ( state . current , { kind : 'status' , status } ) ;
119
149
@@ -132,89 +162,35 @@ export class Tasks extends APIResource {
132
162
}
133
163
134
164
stream < T extends ZodType > (
135
- body : TaskCreateParamsWithSchema < T > ,
165
+ body : {
166
+ taskId : string ;
167
+ schema : T ;
168
+ } ,
136
169
options ?: RequestOptions ,
137
170
) : AsyncGenerator < { event : 'status' ; data : TaskViewWithSchema < T > } > ;
138
- stream (
139
- body : TaskCreateParams ,
140
- options ?: RequestOptions ,
141
- ) : AsyncGenerator < { event : 'status' ; data : TaskView } > ;
171
+ stream ( taskId : string , options ?: RequestOptions ) : AsyncGenerator < { event : 'status' ; data : TaskView } > ;
142
172
async * stream (
143
- body : TaskCreateParams | TaskCreateParamsWithSchema < ZodType > ,
173
+ body : string | { taskId : string ; schema : ZodType } ,
144
174
options ?: RequestOptions ,
145
175
) : AsyncGenerator < unknown > {
146
176
let req : TaskCreateParams ;
147
177
148
- if (
149
- 'structuredOutputJson' in body &&
150
- body . structuredOutputJson != null &&
151
- typeof body . structuredOutputJson === 'object'
152
- ) {
153
- req = {
154
- ...body ,
155
- structuredOutputJson : stringifyStructuredOutput ( body . structuredOutputJson ) ,
156
- } ;
157
- } else {
158
- req = body as TaskCreateParams ;
159
- }
178
+ const taskId = typeof body === 'object' ? body . taskId : body ;
160
179
161
- for await ( const msg of this . watch ( req , { interval : 500 } , options ) ) {
180
+ for await ( const msg of this . watch ( taskId , { interval : 500 } , options ) ) {
162
181
if ( options ?. signal ?. aborted ) {
163
182
break ;
164
183
}
165
184
166
- if ( body . structuredOutputJson != null && typeof body . structuredOutputJson === 'object' ) {
167
- const parsed = parseStructuredTaskOutput < ZodType > ( msg . data , body . structuredOutputJson ) ;
185
+ if ( typeof body === 'object' ) {
186
+ const parsed = parseStructuredTaskOutput < ZodType > ( msg . data , body . schema ) ;
168
187
yield { event : 'status' , data : parsed } ;
169
188
} else {
170
189
yield { event : 'status' , data : msg . data } ;
171
190
}
172
191
}
173
192
}
174
193
175
- /**
176
- * Get detailed information about a specific AI agent task.
177
- *
178
- * Retrieves comprehensive information about a task, including its current status,
179
- * progress, and detailed execution data. You can choose to get just the status
180
- * (for quick polling) or full details including steps and file information.
181
- *
182
- * Use this endpoint to:
183
- *
184
- * - Monitor task progress in real-time
185
- * - Review completed task results
186
- * - Debug failed tasks by examining steps
187
- * - Download output files and logs
188
- *
189
- * Args:
190
- *
191
- * - task_id: The unique identifier of the agent task
192
- *
193
- * Returns:
194
- *
195
- * - Complete task information
196
- *
197
- * Raises:
198
- *
199
- * - 404: If the user agent task doesn't exist
200
- */
201
- retrieve < T extends ZodType > (
202
- req : { taskId : string ; schema : T } ,
203
- options ?: RequestOptions ,
204
- ) : APIPromise < TaskViewWithSchema < T > > ;
205
- retrieve ( taskID : string , options ?: RequestOptions ) : APIPromise < TaskView > ;
206
- retrieve ( req : string | { taskId : string ; schema : ZodType } , options ?: RequestOptions ) : APIPromise < unknown > {
207
- if ( typeof req === 'string' ) {
208
- return this . _client . get ( path `/tasks/${ req } ` , options ) ;
209
- }
210
-
211
- const { taskId, schema } = req ;
212
-
213
- return this . _client
214
- . get ( path `/tasks/${ taskId } ` , options )
215
- . _thenUnwrap ( ( rsp ) => parseStructuredTaskOutput ( rsp as TaskView , schema ) ) ;
216
- }
217
-
218
194
/**
219
195
* Control the execution of an AI agent task.
220
196
*
@@ -561,6 +537,18 @@ export interface TaskView {
561
537
sessionLiveUrl ?: string | null ;
562
538
}
563
539
540
+ /**
541
+ * Response model for creating a task
542
+ *
543
+ * Attributes: task_id: An unique identifier for the created task session_id: The
544
+ * ID of the session this task belongs to
545
+ */
546
+ export interface TaskCreateResponse {
547
+ id : string ;
548
+
549
+ sessionId : string ;
550
+ }
551
+
564
552
/**
565
553
* Response model for paginated task list requests
566
554
*
@@ -711,6 +699,7 @@ export declare namespace Tasks {
711
699
type TaskStatus as TaskStatus ,
712
700
type TaskStepView as TaskStepView ,
713
701
type TaskView as TaskView ,
702
+ type TaskCreateResponse as TaskCreateResponse ,
714
703
type TaskListResponse as TaskListResponse ,
715
704
type TaskGetLogsResponse as TaskGetLogsResponse ,
716
705
type TaskGetOutputFileResponse as TaskGetOutputFileResponse ,
0 commit comments