-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathruns.ts
More file actions
755 lines (651 loc) · 18.3 KB
/
runs.ts
File metadata and controls
755 lines (651 loc) · 18.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../../core/resource';
import * as AgentAPI from './agent';
import { APIPromise } from '../../core/api-promise';
import { PagePromise, RunsCursorPage, type RunsCursorPageParams } from '../../core/pagination';
import { RequestOptions } from '../../internal/request-options';
import { path } from '../../internal/utils/path';
/**
* Operations for running and managing cloud agents
*/
export class Runs extends APIResource {
/**
* Retrieve detailed information about a specific agent run, including the full
* prompt, session link, and resolved configuration.
*
* @example
* ```ts
* const runItem = await client.agent.runs.retrieve('runId');
* ```
*/
retrieve(runID: string, options?: RequestOptions): APIPromise<RunItem> {
return this._client.get(path`/agent/runs/${runID}`, options);
}
/**
* Retrieve a paginated list of agent runs with optional filtering. Results default
* to `sort_by=updated_at` and `sort_order=desc`.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const runItem of client.agent.runs.list()) {
* // ...
* }
* ```
*/
list(
query: RunListParams | null | undefined = {},
options?: RequestOptions,
): PagePromise<RunItemsRunsCursorPage, RunItem> {
return this._client.getAPIList('/agent/runs', RunsCursorPage<RunItem>, { query, ...options });
}
/**
* Cancel an agent run that is currently queued or in progress. Once cancelled, the
* run will transition to a cancelled state.
*
* Not all runs can be cancelled. Runs that are in a terminal state (SUCCEEDED,
* FAILED, ERROR, BLOCKED, CANCELLED) return 400. Runs in PENDING state return 409
* (retry after a moment). Self-hosted, local, and GitHub Action runs return 422.
*
* @example
* ```ts
* const response = await client.agent.runs.cancel('runId');
* ```
*/
cancel(runID: string, options?: RequestOptions): APIPromise<string> {
return this._client.post(path`/agent/runs/${runID}/cancel`, options);
}
/**
* Return fresh presigned download URLs for handoff snapshot files uploaded by the
* latest ended execution of this run. An empty list is returned when no ended
* execution exists or no snapshot files were uploaded.
*
* This endpoint is useful for third-party harnesses that want to download the
* snapshot files produced by a previous execution before starting a handoff
* execution themselves.
*
* @example
* ```ts
* const response =
* await client.agent.runs.listHandoffAttachments('runId');
* ```
*/
listHandoffAttachments(
runID: string,
options?: RequestOptions,
): APIPromise<RunListHandoffAttachmentsResponse> {
return this._client.get(path`/agent/runs/${runID}/handoff/attachments`, options);
}
/**
* Send a follow-up message to an existing run. The server transparently routes the
* message based on the current state of the run (still queued, actively running,
* or ended). A 200 response means the follow-up was accepted; updated run state
* can be observed via `GET /agent/runs/{runId}`.
*
* @example
* ```ts
* const response = await client.agent.runs.submitFollowup(
* 'runId',
* { message: 'message' },
* );
* ```
*/
submitFollowup(
runID: string,
body: RunSubmitFollowupParams,
options?: RequestOptions,
): APIPromise<unknown> {
return this._client.post(path`/agent/runs/${runID}/followups`, { body, ...options });
}
}
export type RunItemsRunsCursorPage = RunsCursorPage<RunItem>;
export type ArtifactItem =
| ArtifactItem.PlanArtifact
| ArtifactItem.PullRequestArtifact
| ArtifactItem.ScreenshotArtifact
| ArtifactItem.FileArtifact;
export namespace ArtifactItem {
export interface PlanArtifact {
/**
* Type of the artifact
*/
artifact_type: 'PLAN';
/**
* Timestamp when the artifact was created (RFC3339)
*/
created_at: string;
data: PlanArtifact.Data;
}
export namespace PlanArtifact {
export interface Data {
/**
* Unique identifier for the plan document
*/
document_uid: string;
/**
* Unique identifier for the plan artifact, usable with the artifact retrieval
* endpoint
*/
artifact_uid?: string;
/**
* Unique identifier for the associated notebook
*/
notebook_uid?: string;
/**
* Title of the plan
*/
title?: string;
/**
* URL to open the plan in Warp Drive
*/
url?: string;
}
}
export interface PullRequestArtifact {
/**
* Type of the artifact
*/
artifact_type: 'PULL_REQUEST';
/**
* Timestamp when the artifact was created (RFC3339)
*/
created_at: string;
data: PullRequestArtifact.Data;
}
export namespace PullRequestArtifact {
export interface Data {
/**
* Branch name for the pull request
*/
branch: string;
/**
* URL of the pull request
*/
url: string;
}
}
export interface ScreenshotArtifact {
/**
* Type of the artifact
*/
artifact_type: 'SCREENSHOT';
/**
* Timestamp when the artifact was created (RFC3339)
*/
created_at: string;
data: ScreenshotArtifact.Data;
}
export namespace ScreenshotArtifact {
export interface Data {
/**
* Unique identifier for the screenshot artifact
*/
artifact_uid: string;
/**
* MIME type of the screenshot image
*/
mime_type: string;
/**
* Optional description of the screenshot
*/
description?: string;
}
}
export interface FileArtifact {
/**
* Type of the artifact
*/
artifact_type: 'FILE';
/**
* Timestamp when the artifact was created (RFC3339)
*/
created_at: string;
data: FileArtifact.Data;
}
export namespace FileArtifact {
export interface Data {
/**
* Unique identifier for the file artifact
*/
artifact_uid: string;
/**
* Last path component of filepath
*/
filename: string;
/**
* Conversation-relative filepath for the uploaded file
*/
filepath: string;
/**
* MIME type of the uploaded file
*/
mime_type: string;
/**
* Optional description of the file
*/
description?: string;
/**
* Size of the uploaded file in bytes
*/
size_bytes?: number;
}
}
}
export interface RunItem {
/**
* Timestamp when the run was created (RFC3339)
*/
created_at: string;
/**
* The prompt/instruction for the agent
*/
prompt: string;
/**
* Unique identifier for the run
*/
run_id: string;
/**
* Current state of the run:
*
* - QUEUED: Run is waiting to be picked up
* - PENDING: Run is being prepared
* - CLAIMED: Run has been claimed by a worker
* - INPROGRESS: Run is actively being executed
* - SUCCEEDED: Run completed successfully
* - FAILED: Run failed
* - BLOCKED: Run is blocked (e.g., awaiting user input or approval)
* - ERROR: Run encountered an error
* - CANCELLED: Run was cancelled by user
*/
state: RunState;
/**
* @deprecated Use run_id instead.
*/
task_id: string;
/**
* Human-readable title for the run
*/
title: string;
/**
* Timestamp when the run was last updated (RFC3339)
*/
updated_at: string;
/**
* Configuration for a cloud agent run
*/
agent_config?: AgentAPI.AmbientAgentConfig;
/**
* Information about the agent skill used for the run. Either full_path or
* bundled_skill_id will be set, but not both.
*/
agent_skill?: RunItem.AgentSkill;
/**
* Artifacts created during the run (plans, pull requests, etc.)
*/
artifacts?: Array<ArtifactItem>;
/**
* UUID of the conversation associated with the run
*/
conversation_id?: string;
creator?: AgentAPI.UserProfile;
/**
* Where the run executed:
*
* - LOCAL: Executed in the user's local Oz environment
* - REMOTE: Executed by a remote/cloud worker
*/
execution_location?: 'LOCAL' | 'REMOTE';
executor?: AgentAPI.UserProfile;
/**
* Whether the sandbox environment is currently running
*/
is_sandbox_running?: boolean;
/**
* UUID of the parent run that spawned this run
*/
parent_run_id?: string;
/**
* Resource usage information for the run
*/
request_usage?: RunItem.RequestUsage;
/**
* Information about the schedule that triggered this run (only present for
* scheduled runs)
*/
schedule?: RunItem.Schedule;
/**
* Ownership scope for a resource (team or personal)
*/
scope?: AgentAPI.Scope;
/**
* UUID of the shared session (if available)
*/
session_id?: string;
/**
* URL to view the agent session
*/
session_link?: string;
/**
* Source that created the run:
*
* - LINEAR: Created from Linear integration
* - API: Created via the Warp API
* - SLACK: Created from Slack integration
* - LOCAL: Created from local CLI/app
* - SCHEDULED_AGENT: Created by a scheduled agent
* - WEB_APP: Created from the Warp web app
* - GITHUB_ACTION: Created from a GitHub action
* - CLOUD_MODE: Created from a Cloud Mode
* - CLI: Created from the CLI
*/
source?: RunSourceType;
/**
* Timestamp when the agent started working on the run (RFC3339)
*/
started_at?: string | null;
/**
* Status message for a run. For terminal error states, includes structured error
* code and retryability info from the platform error catalog.
*/
status_message?: RunItem.StatusMessage;
/**
* URL to the run trigger (e.g. Slack thread, Linear issue, schedule)
*/
trigger_url?: string;
}
export namespace RunItem {
/**
* Information about the agent skill used for the run. Either full_path or
* bundled_skill_id will be set, but not both.
*/
export interface AgentSkill {
/**
* Unique identifier for bundled skills
*/
bundled_skill_id?: string;
/**
* Description of the skill
*/
description?: string;
/**
* Path to the SKILL.md file (for file-based skills)
*/
full_path?: string;
/**
* Human-readable name of the skill
*/
name?: string;
}
/**
* Resource usage information for the run
*/
export interface RequestUsage {
/**
* Cost of compute resources for the run
*/
compute_cost?: number;
/**
* Cost of LLM inference for the run
*/
inference_cost?: number;
}
/**
* Information about the schedule that triggered this run (only present for
* scheduled runs)
*/
export interface Schedule {
/**
* Cron expression at the time the run was created
*/
cron_schedule: string;
/**
* Unique identifier for the schedule
*/
schedule_id: string;
/**
* Name of the schedule at the time the run was created
*/
schedule_name: string;
}
/**
* Status message for a run. For terminal error states, includes structured error
* code and retryability info from the platform error catalog.
*/
export interface StatusMessage {
/**
* Human-readable status message
*/
message: string;
/**
* Machine-readable error code identifying the problem type. Used in the `type` URI
* of Error responses and in the `error_code` field of RunStatusMessage.
*
* User errors (run transitions to FAILED):
*
* - `insufficient_credits` — Team has no remaining add-on credits
* - `feature_not_available` — Required feature not enabled for user's plan
* - `external_authentication_required` — User hasn't authorized a required
* external service
* - `not_authorized` — Principal lacks permission for the requested operation
* - `invalid_request` — Request is malformed or contains invalid parameters
* - `resource_not_found` — Referenced resource does not exist
* - `budget_exceeded` — Spending budget limit has been reached
* - `integration_disabled` — Integration is disabled and must be enabled
* - `integration_not_configured` — Integration setup is incomplete
* - `operation_not_supported` — Requested operation not supported for this
* resource/state
* - `environment_setup_failed` — Client-side environment setup failed
* - `content_policy_violation` — Prompt or setup commands violated content policy
* - `conflict` — Request conflicts with the current state of the resource
*
* Warp errors (run transitions to ERROR):
*
* - `authentication_required` — Request lacks valid authentication credentials
* - `resource_unavailable` — Transient infrastructure issue (retryable)
* - `internal_error` — Unexpected server-side error (retryable)
*/
error_code?: AgentAPI.ErrorCode;
/**
* Whether the error is transient and the client may retry by submitting a new run.
* Only present on terminal error states. When false, retrying without addressing
* the underlying cause will not succeed.
*/
retryable?: boolean;
}
}
/**
* Source that created the run:
*
* - LINEAR: Created from Linear integration
* - API: Created via the Warp API
* - SLACK: Created from Slack integration
* - LOCAL: Created from local CLI/app
* - SCHEDULED_AGENT: Created by a scheduled agent
* - WEB_APP: Created from the Warp web app
* - GITHUB_ACTION: Created from a GitHub action
* - CLOUD_MODE: Created from a Cloud Mode
* - CLI: Created from the CLI
*/
export type RunSourceType =
| 'LINEAR'
| 'API'
| 'SLACK'
| 'LOCAL'
| 'SCHEDULED_AGENT'
| 'WEB_APP'
| 'GITHUB_ACTION'
| 'CLOUD_MODE'
| 'CLI';
/**
* Current state of the run:
*
* - QUEUED: Run is waiting to be picked up
* - PENDING: Run is being prepared
* - CLAIMED: Run has been claimed by a worker
* - INPROGRESS: Run is actively being executed
* - SUCCEEDED: Run completed successfully
* - FAILED: Run failed
* - BLOCKED: Run is blocked (e.g., awaiting user input or approval)
* - ERROR: Run encountered an error
* - CANCELLED: Run was cancelled by user
*/
export type RunState =
| 'QUEUED'
| 'PENDING'
| 'CLAIMED'
| 'INPROGRESS'
| 'SUCCEEDED'
| 'FAILED'
| 'BLOCKED'
| 'ERROR'
| 'CANCELLED';
/**
* The ID of the cancelled run
*/
export type RunCancelResponse = string;
/**
* Response body for listing handoff snapshot attachments.
*/
export interface RunListHandoffAttachmentsResponse {
/**
* Handoff snapshot attachments exposed by the latest ended execution. Empty when
* no ended execution exists or no files were uploaded.
*/
attachments: Array<RunListHandoffAttachmentsResponse.Attachment>;
}
export namespace RunListHandoffAttachmentsResponse {
/**
* A handoff snapshot attachment exposed for download.
*/
export interface Attachment {
/**
* Identifier for the snapshot attachment within the run.
*/
attachment_id: string;
/**
* Time-limited signed URL to download the snapshot attachment.
*/
download_url: string;
/**
* Original filename of the snapshot attachment.
*/
filename: string;
/**
* MIME type of the snapshot attachment, if known.
*/
mime_type?: string;
}
}
export type RunSubmitFollowupResponse = unknown;
export interface RunListParams extends RunsCursorPageParams {
/**
* Filter runs by ancestor run ID. The referenced run must exist and be accessible
* to the caller.
*/
ancestor_run_id?: string;
/**
* Filter runs by artifact type
*/
artifact_type?: 'PLAN' | 'PULL_REQUEST' | 'SCREENSHOT' | 'FILE';
/**
* Filter runs created after this timestamp (RFC3339 format)
*/
created_after?: string;
/**
* Filter runs created before this timestamp (RFC3339 format)
*/
created_before?: string;
/**
* Filter by creator UID (user or service account)
*/
creator?: string;
/**
* Filter runs by environment ID
*/
environment_id?: string;
/**
* Filter by where the run executed
*/
execution_location?: 'LOCAL' | 'REMOTE';
/**
* Filter by the user or agent that executed the run. This will often be the same
* as the creator, but not always: users may delegate tasks to agents.
*/
executor?: string;
/**
* Filter by model ID
*/
model_id?: string;
/**
* Filter by agent config name
*/
name?: string;
/**
* Fuzzy search query across run title, prompt, and skill_spec
*/
q?: string;
/**
* Filter runs by the scheduled agent ID that created them
*/
schedule_id?: string;
/**
* Filter runs by skill spec (e.g., "owner/repo:path/to/SKILL.md"). Alias for
* skill_spec.
*/
skill?: string;
/**
* Filter runs by skill spec (e.g., "owner/repo:path/to/SKILL.md")
*/
skill_spec?: string;
/**
* Sort field for results.
*
* - `updated_at`: Sort by last update timestamp (default)
* - `created_at`: Sort by creation timestamp
* - `title`: Sort alphabetically by run title
* - `agent`: Sort alphabetically by skill. Runs without a skill are grouped last.
*/
sort_by?: 'updated_at' | 'created_at' | 'title' | 'agent';
/**
* Sort direction
*/
sort_order?: 'asc' | 'desc';
/**
* Filter by run source type
*/
source?: RunSourceType;
/**
* Filter by run state. Can be specified multiple times to match any of the given
* states.
*/
state?: Array<RunState>;
/**
* Filter runs updated after this timestamp (RFC3339 format)
*/
updated_after?: string;
}
export interface RunSubmitFollowupParams {
/**
* The follow-up message to send to the run.
*/
message: string;
/**
* Optional query mode for the follow-up. Defaults to `normal` when omitted. The
* server does not infer mode from prompt prefixes such as `/plan`.
*/
mode?: 'normal' | 'plan' | 'orchestrate';
}
export declare namespace Runs {
export {
type ArtifactItem as ArtifactItem,
type RunItem as RunItem,
type RunSourceType as RunSourceType,
type RunState as RunState,
type RunCancelResponse as RunCancelResponse,
type RunListHandoffAttachmentsResponse as RunListHandoffAttachmentsResponse,
type RunSubmitFollowupResponse as RunSubmitFollowupResponse,
type RunItemsRunsCursorPage as RunItemsRunsCursorPage,
type RunListParams as RunListParams,
type RunSubmitFollowupParams as RunSubmitFollowupParams,
};
}