@crouter/sdk 0.3.377

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +170 -0
  2. package/dist/client.d.ts +153 -0
  3. package/dist/client.js +491 -0
  4. package/dist/error-codes.d.ts +7 -0
  5. package/dist/error-codes.js +35 -0
  6. package/dist/errors.d.ts +43 -0
  7. package/dist/errors.js +76 -0
  8. package/dist/index.d.ts +33 -0
  9. package/dist/index.js +13 -0
  10. package/dist/keygen-cli.d.ts +2 -0
  11. package/dist/keygen-cli.js +6 -0
  12. package/dist/keygen-command.d.ts +6 -0
  13. package/dist/keygen-command.js +157 -0
  14. package/dist/oauth/index.d.ts +147 -0
  15. package/dist/oauth/index.js +377 -0
  16. package/dist/oauth/keygen.d.ts +18 -0
  17. package/dist/oauth/keygen.js +46 -0
  18. package/dist/resources/activity.d.ts +22 -0
  19. package/dist/resources/activity.js +43 -0
  20. package/dist/resources/attachments.d.ts +15 -0
  21. package/dist/resources/attachments.js +13 -0
  22. package/dist/resources/bash.d.ts +9 -0
  23. package/dist/resources/bash.js +15 -0
  24. package/dist/resources/canvas/history.d.ts +11 -0
  25. package/dist/resources/canvas/history.js +20 -0
  26. package/dist/resources/canvas.d.ts +19 -0
  27. package/dist/resources/canvas.js +42 -0
  28. package/dist/resources/crons.d.ts +15 -0
  29. package/dist/resources/crons.js +33 -0
  30. package/dist/resources/custom-objects.d.ts +20 -0
  31. package/dist/resources/custom-objects.js +84 -0
  32. package/dist/resources/files.d.ts +34 -0
  33. package/dist/resources/files.js +34 -0
  34. package/dist/resources/forward.d.ts +7 -0
  35. package/dist/resources/forward.js +64 -0
  36. package/dist/resources/human/inbox.d.ts +14 -0
  37. package/dist/resources/human/inbox.js +30 -0
  38. package/dist/resources/human/requests.d.ts +13 -0
  39. package/dist/resources/human/requests.js +26 -0
  40. package/dist/resources/human.d.ts +8 -0
  41. package/dist/resources/human.js +10 -0
  42. package/dist/resources/identifiers.d.ts +8 -0
  43. package/dist/resources/identifiers.js +33 -0
  44. package/dist/resources/memory.d.ts +69 -0
  45. package/dist/resources/memory.js +30 -0
  46. package/dist/resources/models/config.d.ts +8 -0
  47. package/dist/resources/models/config.js +9 -0
  48. package/dist/resources/models/credentials.d.ts +10 -0
  49. package/dist/resources/models/credentials.js +17 -0
  50. package/dist/resources/models.d.ts +8 -0
  51. package/dist/resources/models.js +10 -0
  52. package/dist/resources/node-stream.d.ts +34 -0
  53. package/dist/resources/node-stream.js +176 -0
  54. package/dist/resources/nodes/jobs.d.ts +9 -0
  55. package/dist/resources/nodes/jobs.js +14 -0
  56. package/dist/resources/nodes/result.d.ts +8 -0
  57. package/dist/resources/nodes/result.js +11 -0
  58. package/dist/resources/nodes/worktree.d.ts +9 -0
  59. package/dist/resources/nodes/worktree.js +14 -0
  60. package/dist/resources/nodes.d.ts +23 -0
  61. package/dist/resources/nodes.js +47 -0
  62. package/dist/resources/providers.d.ts +51 -0
  63. package/dist/resources/providers.js +15 -0
  64. package/dist/resources/questions.d.ts +49 -0
  65. package/dist/resources/questions.js +21 -0
  66. package/dist/resources/request.d.ts +3 -0
  67. package/dist/resources/request.js +11 -0
  68. package/dist/resources/run-reply.d.ts +79 -0
  69. package/dist/resources/run-reply.js +84 -0
  70. package/dist/resources/run-stream.d.ts +40 -0
  71. package/dist/resources/run-stream.js +206 -0
  72. package/dist/resources/runs.d.ts +184 -0
  73. package/dist/resources/runs.js +197 -0
  74. package/dist/resources/shares.d.ts +40 -0
  75. package/dist/resources/shares.js +19 -0
  76. package/dist/resources/uploads.d.ts +27 -0
  77. package/dist/resources/uploads.js +11 -0
  78. package/dist/schema.d.ts +7 -0
  79. package/dist/schema.js +10 -0
  80. package/dist/stores/postgres.d.ts +29 -0
  81. package/dist/stores/postgres.js +86 -0
  82. package/dist/types.d.ts +80 -0
  83. package/dist/types.js +1 -0
  84. package/package.json +55 -0
@@ -0,0 +1,84 @@
1
+ import { APIError } from '../errors.js';
2
+ /**
3
+ * The reply to one message: the root's turn that delivers it. Consume it once:
4
+ * iterate it, or call `collect()` (text plus how it ended, with an optional
5
+ * `onDelta` while it streams) or `text()`. It ends after `turn.completed` (or `run.settled`) and
6
+ * closes its event stream; aborting the `signal` rejects with `APIUserAbortError`.
7
+ */
8
+ export class RunReply {
9
+ open;
10
+ sent;
11
+ consumed = false;
12
+ constructor(open, sent) {
13
+ this.open = open;
14
+ this.sent = sent;
15
+ }
16
+ async *[Symbol.asyncIterator]() {
17
+ if (this.consumed)
18
+ throw new Error('a RunReply can be consumed only once');
19
+ this.consumed = true;
20
+ const stream = this.open();
21
+ let inTurn = false;
22
+ try {
23
+ for await (const event of stream) {
24
+ if (event.node_id !== this.sent.run_id)
25
+ continue;
26
+ if (event.type === 'node.settled') {
27
+ yield { type: 'run.settled', outcome: event.outcome, sequence_number: event.sequence_number };
28
+ return;
29
+ }
30
+ if (!inTurn) {
31
+ inTurn = event.type === 'node.turn.started' && event.input.message_ids.includes(this.sent.message_id);
32
+ continue;
33
+ }
34
+ if (event.type === 'node.output_text.delta')
35
+ yield { type: 'text.delta', delta: event.delta, sequence_number: event.sequence_number };
36
+ else if (event.type === 'node.output_text.done')
37
+ yield { type: 'message.done', text: event.text, stop_reason: event.stop_reason, sequence_number: event.sequence_number };
38
+ else if (event.type === 'node.turn.completed') {
39
+ yield {
40
+ type: 'turn.completed', run_status: event.run_status, stop_reason: event.stop_reason,
41
+ ...(event.error ? { error: event.error } : {}), message_ids: event.message_ids, sequence_number: event.sequence_number,
42
+ };
43
+ return;
44
+ }
45
+ }
46
+ }
47
+ finally {
48
+ stream.abort();
49
+ }
50
+ }
51
+ /** Consume the reply: stream its text to `onDelta` and resolve to the whole text and how the turn ended.
52
+ * A stream that closes before the turn ends throws, as iterating does. */
53
+ async collect(options = {}) {
54
+ const texts = [];
55
+ let partial = false;
56
+ for await (const event of this) {
57
+ if (event.type === 'text.delta') {
58
+ if (!event.delta)
59
+ continue;
60
+ options.onDelta?.(!partial && texts.length ? `\n\n${event.delta}` : event.delta);
61
+ partial = true;
62
+ }
63
+ else if (event.type === 'message.done') {
64
+ if (event.text.trim())
65
+ texts.push(event.text.trim());
66
+ partial = false;
67
+ }
68
+ else {
69
+ const text = texts.join('\n\n');
70
+ if (event.type === 'run.settled')
71
+ return { text, ended: 'settled', outcome: event.outcome };
72
+ if (event.error)
73
+ return { text, ended: 'error', error: event.error };
74
+ return { text, ended: event.run_status === 'waiting_on_user' ? 'waiting_on_user' : 'completed' };
75
+ }
76
+ }
77
+ throw new APIError(0, 'stream_error', 'the run event stream ended before the reply did', undefined, undefined, { retryable: false, run_id: this.sent.run_id });
78
+ }
79
+ /** The reply's text: every assistant message's trimmed text in the turn, joined with a blank line. Empty when the turn wrote none.
80
+ * `onDelta` receives the text as it streams, as in `collect`. */
81
+ async text(options = {}) {
82
+ return (await this.collect(options)).text;
83
+ }
84
+ }
@@ -0,0 +1,40 @@
1
+ import type { RunEvent, RunEventBaseDTO, RunEventOf, RunEventType } from '@crouter/api';
2
+ /** Every run event, discriminated on `type`: the daemon declares the union once and the SDK re-exports it. */
3
+ export type { RunEvent, RunEventOf, RunEventType };
4
+ export type RunEventListener<T extends RunEventType = RunEventType> = (event: RunEventOf<T>) => void;
5
+ /** An event under a type this SDK version does not declare (a newer daemon's), or read by field name. */
6
+ export type UnknownRunEvent = RunEventBaseDTO & {
7
+ type: string;
8
+ [field: string]: unknown;
9
+ };
10
+ /** A resumable run event stream. Closing it does not stop the run. */
11
+ export declare class RunStream implements AsyncIterable<RunEvent> {
12
+ private readonly open;
13
+ private readonly onReconnect?;
14
+ private readonly controller;
15
+ private readonly listeners;
16
+ private cursor;
17
+ private readonly outcome;
18
+ private resolveOutcome;
19
+ private rejectOutcome;
20
+ private finished;
21
+ private readonly events;
22
+ private wake?;
23
+ private failure;
24
+ constructor(open: (after: number, signal: AbortSignal) => Promise<Response>, after?: number, signal?: AbortSignal, onReconnect?: ((state: "reconnecting" | "reconnected", error?: unknown) => void) | undefined);
25
+ on<T extends RunEventType>(type: T, listener: RunEventListener<T>): this;
26
+ on(type: string, listener: (event: RunEvent | UnknownRunEvent) => void): this;
27
+ off<T extends RunEventType>(type: T, listener: RunEventListener<T>): this;
28
+ off(type: string, listener: (event: RunEvent | UnknownRunEvent) => void): this;
29
+ abort(): void;
30
+ /** Resolves to the run's `node.settled` event. */
31
+ finalOutcome(): Promise<RunEventOf<'node.settled'>>;
32
+ /** The run's `waiting_on_user` events: each carries a question (`question_id, initiating_app, title, subtitle?, steps, slots`). */
33
+ waitingOnUser(): AsyncIterable<RunEventOf<'waiting_on_user'>>;
34
+ [Symbol.asyncIterator](): AsyncIterator<RunEvent>;
35
+ private finish;
36
+ private deliver;
37
+ private consume;
38
+ private record;
39
+ private deliverPayload;
40
+ }
@@ -0,0 +1,206 @@
1
+ import { APIError, APIUserAbortError } from '../errors.js';
2
+ /** A resumable run event stream. Closing it does not stop the run. */
3
+ export class RunStream {
4
+ open;
5
+ onReconnect;
6
+ controller = new AbortController();
7
+ listeners = new Map();
8
+ cursor;
9
+ outcome;
10
+ resolveOutcome;
11
+ rejectOutcome;
12
+ finished = false;
13
+ events = [];
14
+ wake;
15
+ failure;
16
+ constructor(open, after = 0, signal, onReconnect) {
17
+ this.open = open;
18
+ this.onReconnect = onReconnect;
19
+ if (!Number.isSafeInteger(after) || after < 0)
20
+ throw new RangeError('after must be a non-negative safe integer');
21
+ this.cursor = after;
22
+ this.outcome = new Promise((resolve, reject) => { this.resolveOutcome = resolve; this.rejectOutcome = reject; });
23
+ void this.outcome.catch(() => undefined);
24
+ if (signal?.aborted)
25
+ this.controller.abort(signal.reason);
26
+ else
27
+ signal?.addEventListener('abort', () => this.controller.abort(signal.reason), { once: true });
28
+ void this.consume();
29
+ }
30
+ on(type, listener) {
31
+ const set = this.listeners.get(type) ?? new Set();
32
+ set.add(listener);
33
+ this.listeners.set(type, set);
34
+ return this;
35
+ }
36
+ off(type, listener) { this.listeners.get(type)?.delete(listener); return this; }
37
+ abort() { this.controller.abort(); }
38
+ /** Resolves to the run's `node.settled` event. */
39
+ finalOutcome() { return this.outcome; }
40
+ /** The run's `waiting_on_user` events: each carries a question (`question_id, initiating_app, title, subtitle?, steps, slots`). */
41
+ async *waitingOnUser() {
42
+ for await (const event of this)
43
+ if (event.type === 'waiting_on_user')
44
+ yield event;
45
+ }
46
+ async *[Symbol.asyncIterator]() {
47
+ for (;;) {
48
+ if (this.events.length) {
49
+ yield this.events.shift();
50
+ continue;
51
+ }
52
+ if (this.finished) {
53
+ if (this.failure)
54
+ throw this.failure;
55
+ return;
56
+ }
57
+ await new Promise((resolve) => { this.wake = resolve; });
58
+ }
59
+ }
60
+ finish(error) {
61
+ if (this.finished)
62
+ return;
63
+ this.finished = true;
64
+ this.failure = error;
65
+ if (error)
66
+ this.rejectOutcome(error);
67
+ this.wake?.();
68
+ this.wake = undefined;
69
+ }
70
+ deliver(event) {
71
+ if (!Number.isSafeInteger(event.sequence_number) || event.sequence_number <= this.cursor)
72
+ return;
73
+ this.cursor = event.sequence_number;
74
+ this.events.push(event);
75
+ for (const listener of this.listeners.get(event.type) ?? [])
76
+ listener(event);
77
+ this.wake?.();
78
+ this.wake = undefined;
79
+ if (event.type === 'node.settled') {
80
+ this.resolveOutcome(event);
81
+ this.finish();
82
+ }
83
+ }
84
+ async consume() {
85
+ let attempt = 0;
86
+ let failedReconnect = false;
87
+ while (!this.controller.signal.aborted && !this.finished) {
88
+ const connection = new AbortController();
89
+ const stop = () => connection.abort();
90
+ this.controller.signal.addEventListener('abort', stop, { once: true });
91
+ let idle;
92
+ let opened = false;
93
+ const resetIdle = () => { if (idle)
94
+ clearTimeout(idle); idle = setTimeout(() => connection.abort(), 45_000); };
95
+ try {
96
+ const response = await this.open(this.cursor, connection.signal);
97
+ opened = true;
98
+ if (!response.ok)
99
+ throw await streamResponseError(response);
100
+ if (!response.body)
101
+ throw new Error('Run event stream has no body');
102
+ if (failedReconnect) {
103
+ this.onReconnect?.('reconnected');
104
+ failedReconnect = false;
105
+ }
106
+ const reader = response.body.getReader();
107
+ const decoder = new TextDecoder();
108
+ const ndjson = response.headers.get('content-type')?.includes('application/x-ndjson') ?? false;
109
+ let buffer = '';
110
+ if (!ndjson)
111
+ resetIdle();
112
+ for (;;) {
113
+ const { done, value } = await reader.read();
114
+ if (done)
115
+ break;
116
+ if (!ndjson)
117
+ resetIdle();
118
+ buffer += decoder.decode(value, { stream: true });
119
+ const records = ndjson ? buffer.split(/\r?\n/) : buffer.split(/\r\n\r\n|\n\n|\r\r/);
120
+ buffer = records.pop() ?? '';
121
+ for (const record of records) {
122
+ if (ndjson)
123
+ this.deliverPayload(JSON.parse(record));
124
+ else
125
+ this.record(record);
126
+ if (this.finished) {
127
+ await reader.cancel();
128
+ return;
129
+ }
130
+ }
131
+ }
132
+ if (buffer) {
133
+ if (ndjson)
134
+ this.deliverPayload(JSON.parse(buffer));
135
+ else
136
+ this.record(buffer);
137
+ }
138
+ attempt = 0;
139
+ }
140
+ catch (error) {
141
+ if (this.controller.signal.aborted)
142
+ break;
143
+ if ((!opened && !(error instanceof APIError)) ||
144
+ (error instanceof APIError && (error.code === 'stream_dropped' || error.code === 'stream_error' || !error.retryable))) {
145
+ this.finish(error);
146
+ return;
147
+ }
148
+ if (attempt > 0) {
149
+ failedReconnect = true;
150
+ this.onReconnect?.('reconnecting', error);
151
+ }
152
+ }
153
+ finally {
154
+ if (idle)
155
+ clearTimeout(idle);
156
+ this.controller.signal.removeEventListener('abort', stop);
157
+ }
158
+ if (this.finished || this.controller.signal.aborted)
159
+ break;
160
+ const delay = Math.min(30_000, 500 * 2 ** Math.min(attempt++, 6));
161
+ try {
162
+ await new Promise((resolve, reject) => {
163
+ const timer = setTimeout(resolve, delay);
164
+ this.controller.signal.addEventListener('abort', () => { clearTimeout(timer); reject(new Error('aborted')); }, { once: true });
165
+ });
166
+ }
167
+ catch {
168
+ break;
169
+ }
170
+ }
171
+ if (this.controller.signal.aborted)
172
+ this.finish(new APIUserAbortError(0, 'request_aborted', 'run stream aborted by caller'));
173
+ }
174
+ record(record) {
175
+ let type;
176
+ const data = [];
177
+ for (const line of record.split(/\r\n|\n|\r/)) {
178
+ if (line.startsWith(':'))
179
+ continue;
180
+ const separator = line.indexOf(':');
181
+ const field = separator === -1 ? line : line.slice(0, separator);
182
+ const value = separator === -1 ? '' : line.slice(separator + 1).replace(/^ /, '');
183
+ if (field === 'event')
184
+ type = value;
185
+ if (field === 'data')
186
+ data.push(value);
187
+ }
188
+ if (!type || !data.length)
189
+ return;
190
+ const payload = JSON.parse(data.join('\n'));
191
+ this.deliverPayload({ ...payload, type });
192
+ }
193
+ deliverPayload(payload) {
194
+ if (payload.type === 'error') {
195
+ const envelope = (payload.error ?? payload);
196
+ throw new APIError(0, envelope.code ?? 'stream_error', envelope.message ?? 'Run stream error', envelope.details, undefined, envelope);
197
+ }
198
+ // A newer daemon may send an event type this SDK does not declare; it is delivered as-is.
199
+ this.deliver(payload);
200
+ }
201
+ }
202
+ async function streamResponseError(response) {
203
+ const payload = await response.json();
204
+ const error = payload.error;
205
+ return new APIError(response.status, error?.code ?? 'invalid_response', error?.message ?? `HTTP ${response.status}`, error?.details, response.headers, error);
206
+ }
@@ -0,0 +1,184 @@
1
+ import { RunStream } from './run-stream.js';
2
+ import { RunReply, type SentRunMessage } from './run-reply.js';
3
+ import type { Questions, Question, QuestionResponses } from './questions.js';
4
+ import type { JsonSchema, OutputSchema, RequestOptions, SchemaOutput } from '../types.js';
5
+ import type { RunActivityDTO, RunOutcomeDTO, RunTraceDTO, TurnErrorDTO } from '@crouter/api';
6
+ export interface RunStartParams {
7
+ prompt: string;
8
+ scopes?: string[];
9
+ metadata?: Record<string, unknown>;
10
+ /** Launch every node without network or the app's files mount. Descendants cannot disable it. */
11
+ isolated?: boolean;
12
+ /** Profile id (`profile_id` from `profiles.list()`) the run's agent uses; absent uses the app's default profile. */
13
+ profile?: string;
14
+ /** A JSON Schema, or an object with `toJSONSchema()` (a Zod v4 object), the run's result must satisfy.
15
+ * Sent as a JSON object; the daemon refuses one that is not an object or is over 256 KB serialized
16
+ * (`invalid_request`, `param: output_schema`), which is raised without a resend. The SDK does not
17
+ * validate results against it. */
18
+ output_schema?: JsonSchema | {
19
+ toJSONSchema(): JsonSchema;
20
+ };
21
+ /** A first message, stored with the run as a `start_turn: false` message: it always joins the first turn
22
+ * as context ahead of `prompt`. The result's `message` is what `runs.reply` takes to follow that turn. */
23
+ message?: string;
24
+ }
25
+ export interface RunStartResult {
26
+ run_id: string;
27
+ node_id: string;
28
+ grantee: string;
29
+ grant: string;
30
+ rev: number;
31
+ scopes: string[] | null;
32
+ payer: 'user';
33
+ status: 'running';
34
+ created_at: string;
35
+ metadata: Record<string, unknown>;
36
+ sequence_number: number;
37
+ /** Present when `RunStartParams.message` was sent: pass it to `runs.reply(run.run_id, run.message)`. */
38
+ message?: SentRunMessage;
39
+ }
40
+ export type RunStatus = 'running' | 'waiting_on_user' | 'idle' | 'settled';
41
+ export interface RunObject {
42
+ run_id: string;
43
+ name: string;
44
+ status: RunStatus;
45
+ /** Present once the run settled: `finalized`; `declined` with `details: {reason, code, retryable}`;
46
+ * `canceled`; `deadline_exceeded`; `runtime_error` with `details.crouter_reason`. */
47
+ outcome?: RunOutcomeDTO;
48
+ /** The validated `output_schema` result, exactly as the daemon sent it; present when `outcome.kind` is `result` and one was submitted. */
49
+ result?: unknown;
50
+ last_report?: string;
51
+ /** Present when the root's latest completed turn ended in error; the next turn that completes without one clears it. */
52
+ last_turn_error?: TurnErrorDTO;
53
+ pending_question_ids: string[];
54
+ usage: {
55
+ input_tokens: number;
56
+ output_tokens: number;
57
+ cache_read_tokens: number;
58
+ cache_write_tokens: number;
59
+ cost_usd: number;
60
+ };
61
+ payer: 'user';
62
+ scopes: string[] | null;
63
+ metadata: Record<string, unknown>;
64
+ created_at: string;
65
+ settled_at?: string;
66
+ latest_sequence: number;
67
+ last_activity_at: string;
68
+ /** What the root is doing while the run is `running`, else null: `starting`, `thinking`, `tool` (with `tool.name`
69
+ * and a one-line `tool.summary`), `writing`, or `between_turns`. Poll `runs.get` for a progress badge instead of
70
+ * reading `runs.trace`. */
71
+ activity: RunActivity | null;
72
+ }
73
+ /** `RunObject.activity` while the run is `running`. */
74
+ export type RunActivity = RunActivityDTO;
75
+ /** A profile an app may start runs with (`profiles.list()`). Pass `profile_id` as `RunStartParams.profile`. */
76
+ export interface AppProfile {
77
+ profile_id: string;
78
+ name: string;
79
+ grantee: string;
80
+ default_kind: string;
81
+ default: boolean;
82
+ }
83
+ export interface RunDeleteResult {
84
+ run_id: string;
85
+ uploads_pending: number;
86
+ }
87
+ /** `runs.trace` in its rendered form; message `content` narrows on `type` and role fields on `role`. */
88
+ export type RunTrace = RunTraceDTO;
89
+ /** A settled `runs.parse` run: the run outcome plus `output_parsed`, typed to the schema and non-null exactly when `kind` is `result`. */
90
+ export type RunParsedOutcome<T> = (Extract<RunOutcomeDTO, {
91
+ kind: 'result';
92
+ }> & {
93
+ output_parsed: T;
94
+ }) | (Exclude<RunOutcomeDTO, {
95
+ kind: 'result';
96
+ }> & {
97
+ output_parsed: null;
98
+ });
99
+ /** `runs.parse` params: `runs.start`'s, with `output_schema` required. */
100
+ export type RunParseParams<TSchema> = Omit<RunStartParams, 'output_schema'> & {
101
+ output_schema: TSchema;
102
+ };
103
+ export interface RunParseOptions extends RequestOptions {
104
+ /** Answers each open question once, by id, with one response per slot. Without it `parse` rejects `waiting_on_user`. */
105
+ onQuestion?: (question: Question) => QuestionResponses | Promise<QuestionResponses>;
106
+ idempotencyKey?: string;
107
+ }
108
+ export type RunRequest = <T>(method: string, path: string, body?: unknown, options?: RequestOptions) => Promise<T>;
109
+ export declare class Runs {
110
+ private readonly request;
111
+ private readonly openEvents;
112
+ private readonly questions?;
113
+ constructor(request: RunRequest, openEvents: (runId: string, after: number, signal: AbortSignal) => Promise<Response>, questions?: Questions | undefined);
114
+ start(params: RunStartParams, options?: RequestOptions & {
115
+ idempotencyKey?: string;
116
+ }): Promise<RunStartResult>;
117
+ get(runId: string, options?: RequestOptions & {
118
+ wait?: number;
119
+ }): Promise<RunObject>;
120
+ list(filters?: {
121
+ status?: RunStatus;
122
+ after?: string;
123
+ limit?: number;
124
+ }, options?: RequestOptions): Promise<{
125
+ runs: RunObject[];
126
+ next: string | null;
127
+ }>;
128
+ /** Every run across pages, most recently active first: `for await (const run of runs.listAll())`. Fetches
129
+ * the next page (`limit` per page) only as you iterate; `break` stops fetching. */
130
+ listAll(filters?: {
131
+ status?: RunStatus;
132
+ limit?: number;
133
+ }, options?: RequestOptions): AsyncGenerator<RunObject, void, undefined>;
134
+ /** Send a message to a run. `start_turn: true` (the default) answers it in its
135
+ * own turn: a running run receives it when its current turn ends, and a
136
+ * message sent before the first turn has started queues behind that turn,
137
+ * because a run's `runs.start` prompt is always its first turn's input.
138
+ * `start_turn: false` stores it without starting a turn; it is delivered as
139
+ * context at the start of the next turn, ahead of that turn's input. For a
140
+ * new run that is the first turn only if it is stored before the run claims
141
+ * its first turn's messages; to guarantee it, pass `message` to `runs.start`. */
142
+ message(runId: string, message: string, options?: RequestOptions & {
143
+ start_turn?: boolean;
144
+ }): Promise<SentRunMessage>;
145
+ interrupt(runId: string, options?: RequestOptions & {
146
+ children?: 'stop' | 'continue';
147
+ }): Promise<RunObject>;
148
+ cancel(runId: string, options?: RequestOptions & {
149
+ keepSchedules?: boolean;
150
+ }): Promise<RunObject>;
151
+ /** Delete the run, running or not: the runtime stops its turns and sandboxes itself, so there is no need to
152
+ * `cancel` first. Deleting a run that is already gone throws `NotFoundError` (404).
153
+ * `uploads_pending` counts the run's released uploads storage has not yet confirmed deleted; the runtime retries those. */
154
+ delete(runId: string, options?: RequestOptions): Promise<RunDeleteResult>;
155
+ /** Rename the caller's own run. The name is trimmed, must not be empty, and is at most 200 characters. */
156
+ rename(runId: string, name: string, options?: RequestOptions): Promise<RunObject>;
157
+ trace(runId: string, options?: RequestOptions & {
158
+ format?: 'entries';
159
+ }): Promise<RunTrace>;
160
+ events(runId: string, options?: {
161
+ after?: number;
162
+ signal?: AbortSignal;
163
+ onReconnect?: (state: 'reconnecting' | 'reconnected', error?: unknown) => void;
164
+ }): RunStream;
165
+ /** Follow the reply to one message: `sent` is what `runs.message` returned, or `runs.start`'s `message`. Reads the run's events after
166
+ * `sent.sequence_number`, keeps the root's, starts at the turn that delivers the message and ends after that
167
+ * turn's `turn.completed` (or the run's settlement). Several messages delivered in one turn share that turn's reply.
168
+ * An expired cursor throws `stream_gap`. */
169
+ reply(runId: string, sent: SentRunMessage, options?: {
170
+ signal?: AbortSignal;
171
+ }): RunReply;
172
+ stream(params: RunStartParams, options?: RequestOptions & {
173
+ idempotencyKey?: string;
174
+ }): RunStream;
175
+ /** Long-polls `runs.get` until the run is `settled`, `waiting_on_user`, or `idle`, and returns that response
176
+ * unchanged (`result` is not parsed). Aborting `signal` rejects with its reason and leaves the run as it is. */
177
+ wait(runId: string, options?: RequestOptions): Promise<RunObject>;
178
+ /** Start a run with `output_schema` and wait for it to settle; resolves with the outcome and `output_parsed`
179
+ * typed to the schema. `onQuestion` answers each open question once; without it, a question rejects with
180
+ * `APIError` code `waiting_on_user`. A run that stops without settling rejects `run_idle` (untouched:
181
+ * send `runs.message` or `runs.cancel`). Aborting `signal` rejects with its reason; the run is never canceled. */
182
+ parse<TSchema extends OutputSchema>(params: RunParseParams<TSchema>, options?: RunParseOptions): Promise<RunParsedOutcome<SchemaOutput<TSchema>>>;
183
+ private parseRun;
184
+ }