@simular-ai/sai-sdk 0.0.0-stage → 0.1.0-alpha.2

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenants.js","sourceRoot":"","sources":["../src/tenants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtD,OAAO,EACL,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,gBAAgB,GAMjB,MAAM,YAAY,CAAA;AAKnB,iFAAiF;AACjF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAA;AAEpD,iFAAiF;AACjF,MAAM,wBAAwB,GAAG,KAAK,CAAA;AAEtC,MAAM,CAAC,GAAG,kBAAkB,CAAA;AAC5B,MAAM,UAAU,GAAG,CAAC,MAAiB,EAAU,EAAE,CAC/C,eAAe,CAAC,CAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAA;AAErE,4FAA4F;AAC5F,MAAM,OAAO,OAAO;IAEC;IACA;IACA;IAHnB,YACmB,IAAU,EACV,KAAyB,EACzB,cAA+C;QAF/C,SAAI,GAAJ,IAAI,CAAM;QACV,UAAK,GAAL,KAAK,CAAoB;QACzB,mBAAc,GAAd,cAAc,CAAiC;IAC/D,CAAC;IAEJ,qGAAqG;IACrG,KAAK,CAAC,MAAM,CACV,IAAY,EACZ,OAAmE,EAAE;QAErE,OAAO,WAAW,CAChB,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,aAAa,EAAE;YAC1C,IAAI,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE;SACrE,CAAC,CACH,CAAA;IACH,CAA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C;CACF;AAED,MAAM,KAAK,GAAG,CAAC,EAAU,EAAiB,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Turns: what a message to Sai started or joined. Every message gets a turn id
3
+ * (`turn.id`); this reads the turn's record: status, output, evidence, usage,
4
+ * and its trajectory when the message set `recordTrajectory`.
5
+ *
6
+ * Maps to `/v1/agents/turns/*`.
7
+ */
8
+ import type { Http } from './http.js';
9
+ import { type TrajectoryStep, type TurnRecord } from './types.js';
10
+ /** A turn id, a `Turn`, or a `TurnRecord`. */
11
+ export type TurnRef = string | {
12
+ id: string | null;
13
+ };
14
+ export declare class Turns {
15
+ private readonly http;
16
+ constructor(http: Http);
17
+ /** The turn's record now. Never waits: `finalizing` while the result is worked out. */
18
+ get(turn: TurnRef): Promise<TurnRecord>;
19
+ /**
20
+ * Read the turn until it is `succeeded`, `failed` or `needs_input`. On
21
+ * `needs_input`, answer the approval on the turn's session
22
+ * (`sai.sessions.resume(record.sessionId)`) and wait again. `timeoutMs`
23
+ * throws a `TimeoutError` (DOMException) with the turn unfinished.
24
+ */
25
+ wait(turn: TurnRef, opts?: {
26
+ timeoutMs?: number;
27
+ }): Promise<TurnRecord>;
28
+ /** The steps the agent took, in order. Recorded only when the message set `recordTrajectory`. */
29
+ trajectory(turn: TurnRef): Promise<TrajectoryStep[]>;
30
+ /** The screen before step `index` (the last one is after the turn), as JPEG bytes. */
31
+ screenshot(turn: TurnRef, index: number): Promise<Uint8Array>;
32
+ }
package/dist/turns.js ADDED
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Turns: what a message to Sai started or joined. Every message gets a turn id
3
+ * (`turn.id`); this reads the turn's record: status, output, evidence, usage,
4
+ * and its trajectory when the message set `recordTrajectory`.
5
+ *
6
+ * Maps to `/v1/agents/turns/*`.
7
+ */
8
+ import { waitTurnRecord } from './sessions.js';
9
+ import { parseTrajectoryStep, parseTurnRecord, } from './types.js';
10
+ const idOf = (turn) => {
11
+ const id = typeof turn === 'string' ? turn : turn.id;
12
+ if (!id)
13
+ throw new Error('This turn has no id: the message was answered without starting one.');
14
+ return encodeURIComponent(id);
15
+ };
16
+ export class Turns {
17
+ http;
18
+ constructor(http) {
19
+ this.http = http;
20
+ }
21
+ /** The turn's record now. Never waits: `finalizing` while the result is worked out. */
22
+ async get(turn) {
23
+ return parseTurnRecord(await this.http.json('GET', `/v1/agents/turns/${idOf(turn)}`));
24
+ }
25
+ /**
26
+ * Read the turn until it is `succeeded`, `failed` or `needs_input`. On
27
+ * `needs_input`, answer the approval on the turn's session
28
+ * (`sai.sessions.resume(record.sessionId)`) and wait again. `timeoutMs`
29
+ * throws a `TimeoutError` (DOMException) with the turn unfinished.
30
+ */
31
+ async wait(turn, opts = {}) {
32
+ const deadline = opts.timeoutMs === undefined ? null : Date.now() + opts.timeoutMs;
33
+ return waitTurnRecord(this.http, decodeURIComponent(idOf(turn)), deadline, [
34
+ 'succeeded',
35
+ 'failed',
36
+ 'needs_input',
37
+ ]);
38
+ }
39
+ /** The steps the agent took, in order. Recorded only when the message set `recordTrajectory`. */
40
+ async trajectory(turn) {
41
+ const d = await this.http.json('GET', `/v1/agents/turns/${idOf(turn)}/trajectory`);
42
+ return (d.steps ?? []).map(parseTrajectoryStep);
43
+ }
44
+ /** The screen before step `index` (the last one is after the turn), as JPEG bytes. */
45
+ async screenshot(turn, index) {
46
+ const res = await this.http.request('GET', `/v1/agents/turns/${idOf(turn)}/trajectory/screenshots/${index}`);
47
+ return new Uint8Array(await res.arrayBuffer());
48
+ }
49
+ }
50
+ //# sourceMappingURL=turns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"turns.js","sourceRoot":"","sources":["../src/turns.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EACL,mB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CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;IACjD,CAAC;IAED,sFAAsF;IACtF,KAAK,CAAC,UAAU,CAAC,IAAa,EAAE,KAAa;QAC3C,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CACjC,KAAK,EACL,oBAAoB,IAAI,CAAC,IAAI,CAAC,2BAA2B,KAAK,EAAE,CACjE,CAAA;QACD,OAAO,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,WAAW,EAAE,CAAC,CAAA;IAChD,CAAC;CACF"}
@@ -0,0 +1,456 @@
1
+ /**
2
+ * Response objects. Each keeps the server's JSON in `raw`, so a field the SDK
3
+ * does not model yet is still reachable.
4
+ */
5
+ type Json = Record<string, unknown>;
6
+ export interface Account {
7
+ userId: string;
8
+ planId: string | null;
9
+ planTitle: string;
10
+ free: boolean;
11
+ unlimited: boolean;
12
+ /** Spendable credit in USD; null on the unlimited plan or when billing could not be reached. */
13
+ creditsUsd: number | null;
14
+ raw: Json;
15
+ }
16
+ export declare function parseAccount(d: Json): Account;
17
+ export interface Model {
18
+ id: string;
19
+ name: string;
20
+ provider: string;
21
+ tier: string;
22
+ costTier: string;
23
+ allowed: boolean;
24
+ raw: Json;
25
+ }
26
+ export declare function parseModel(d: Json): Model;
27
+ export interface Machine {
28
+ id: string;
29
+ name: string | null;
30
+ /** `cloud` (hosted by Simular) or `own` (a desktop with the Sai app). */
31
+ kind: string;
32
+ /** True when a message can reach it now (a hibernated cloud computer wakes on the first message). */
33
+ online: boolean;
34
+ /**
35
+ * `running`, `starting`, `asleep`, `creating` or `unknown`; `null` on servers that do not
36
+ * send it yet. Prefer it over `status`.
37
+ */
38
+ state: string | null;
39
+ /** @deprecated The server's internal lifecycle value; it may gain values at any time. Use `state`. */
40
+ status: string | null;
41
+ canWake: boolean;
42
+ raw: Json;
43
+ }
44
+ export declare function parseMachine(d: Json): Machine;
45
+ /** One of your customers under an Organisation. */
46
+ export interface Tenant {
47
+ id: string;
48
+ name: string;
49
+ /** Your id for the customer. Unique in the Organisation; set on create only. */
50
+ externalId: string | null;
51
+ metadata: Record<string, string>;
52
+ /** `active` or `disabled`. */
53
+ status: string;
54
+ /** Unix time in milliseconds. */
55
+ createdAt: number;
56
+ disabledAt: number | null;
57
+ /** Enrolled machines. */
58
+ machineCount: number;
59
+ /** Most cloud machines the Tenant may have at once. null: no limit. */
60
+ cloudMachineLimit: number | null;
61
+ /**
62
+ * The Tenant's residential proxy switch. It has no effect yet: traffic goes direct. Set by `get` and
63
+ * `update`; null from `list` and from servers before cloud machines.
64
+ */
65
+ residentialProxy: boolean | null;
66
+ /** Set by `get` and `update`; null from `list` and from servers before cloud machines. */
67
+ cloudMachineCount: number | null;
68
+ raw: Json;
69
+ }
70
+ export declare function parseTenant(d: Json): Tenant;
71
+ export interface TenantPage {
72
+ tenants: Tenant[];
73
+ /** Pass as `cursor` for the next page; null on the last page. */
74
+ nextCursor: string | null;
75
+ }
76
+ /** A Tenant's computer: its own, enrolled, or a cloud machine Sai hosts for it. */
77
+ export interface TenantMachine {
78
+ id: string;
79
+ name: string | null;
80
+ platform: string | null;
81
+ /** Older servers only; empty on servers with cloud machines. Read `state`. */
82
+ status: string;
83
+ /** True when an enrolled machine reported in the last 3 minutes, or a cloud machine is `ready`. */
84
+ online: boolean;
85
+ lastSeen: number | null;
86
+ runtimeVersion: string | null;
87
+ kind: 'enrolled' | 'cloud';
88
+ /**
89
+ * Enrolled: `online` or `offline`. Cloud: `provisioning`, `ready`, `starting`, `hibernated`,
90
+ * `deleting` or `failed`. A run starts without waiting only on `ready`; a hibernated machine
91
+ * wakes when a run is sent to it.
92
+ */
93
+ state: string;
94
+ /** Cloud only: the billing class, e.g. `win32-4c8g`. */
95
+ machineClass: string | null;
96
+ /** Unix time in milliseconds. null from servers before cloud machines. */
97
+ createdAt: number | null;
98
+ raw: Json;
99
+ }
100
+ export declare function parseTenantMachine(d: Json): TenantMachine;
101
+ export interface Enrollment {
102
+ /** Single use. Treat it as a secret until the Sai runtime redeems it. */
103
+ token: string;
104
+ /** Unix time in milliseconds, 15 minutes after it was created. */
105
+ expiresAt: number;
106
+ raw: Json;
107
+ }
108
+ export declare function parseEnrollment(d: Json): Enrollment;
109
+ export interface TenantToken {
110
+ /** Pass as `new Sai({ apiKey })` to act as the Tenant on sessions, machines and turns. */
111
+ token: string;
112
+ /** Unix time in milliseconds, an hour after the exchange. There is no refresh: exchange again. */
113
+ expiresAt: number;
114
+ tenantId: string;
115
+ raw: Json;
116
+ }
117
+ export declare function parseTenantToken(d: Json): TenantToken;
118
+ /** A file uploaded with `sai.files.upload()`. Pass it in `attachments`. */
119
+ export interface Attachment {
120
+ fileId: string;
121
+ name: string;
122
+ mime: string;
123
+ size: number;
124
+ raw: Json;
125
+ }
126
+ export declare function parseAttachment(d: Json): Attachment;
127
+ /** A view-only Guacamole stream of a computer's screen. The URL carries a token: keep it private. */
128
+ export interface LiveView {
129
+ machineId: string;
130
+ websocketUrl: string;
131
+ width: number;
132
+ height: number;
133
+ }
134
+ /** Sai is waiting for permission (or for an answer to a choice question). */
135
+ export interface Approval {
136
+ id: string;
137
+ title: string;
138
+ description: string;
139
+ /** `exec`, `choice`, ...; a `choice` needs `selections` when approved. */
140
+ type: string;
141
+ /** True: a human must answer in a browser at `url`; the API cannot. */
142
+ isLinkOnly: boolean;
143
+ url: string | null;
144
+ command: string | null;
145
+ questions: Json[];
146
+ raw: Json;
147
+ }
148
+ export declare function parseApproval(d: Json): Approval;
149
+ export interface Usage {
150
+ inputTokens: number;
151
+ outputTokens: number;
152
+ cacheReadTokens: number;
153
+ cacheWriteTokens: number;
154
+ costUsd: number;
155
+ modelCalls: number;
156
+ byModel: Json;
157
+ }
158
+ export declare function parseUsage(d: unknown): Usage | null;
159
+ /** The SDK's event kinds. `other` only appears with `events({ raw: true })`. */
160
+ export declare const EVENT_KINDS: readonly ["step", "message", "approval", "tool_error", "error", "finished", "other"];
161
+ export type EventKind = (typeof EVENT_KINDS)[number];
162
+ /**
163
+ * One thing that happened in a turn. `kind` is the SDK's name; `type` is the
164
+ * wire type.
165
+ */
166
+ export interface Event {
167
+ kind: EventKind;
168
+ type: string;
169
+ text: string | null;
170
+ approval: Approval | null;
171
+ /** `insufficient_credits` / `free_computer_time_exhausted` on errors: stop retrying today. */
172
+ code: string | null;
173
+ raw: Json;
174
+ }
175
+ export declare function parseEvent(d: Json): Event;
176
+ /** Turn statuses: `running` while polling, then one of the three below. */
177
+ export declare const TURN_STATUSES: readonly ["running", "idle", "needs_approval", "error"];
178
+ export type TurnStatus = (typeof TURN_STATUSES)[number];
179
+ /**
180
+ * Where a turn stopped. `status` is `idle` (done: `text` is the answer),
181
+ * `error`, or `needs_approval` (waiting on `approval`; answer it and call
182
+ * `wait()` again). `record` is the turn's record for a structured message (one
183
+ * with `inputs`, `outputSchema` or `successCriteria`).
184
+ */
185
+ export interface TurnResult {
186
+ status: TurnStatus;
187
+ text: string;
188
+ sessionId: string;
189
+ approval: Approval | null;
190
+ error: string | null;
191
+ errorCode: string | null;
192
+ usage: Usage | null;
193
+ sessionUsage: Usage | null;
194
+ record: TurnRecord | null;
195
+ /** Idle, and for a structured message, the turn succeeded. */
196
+ ok: boolean;
197
+ }
198
+ /** One yes/no constraint a structured message's turn is checked against after it ends. */
199
+ export interface Check {
200
+ /** Letters, digits, `_` or `-`; at most 64 characters. */
201
+ id: string;
202
+ check: string;
203
+ /** Also return one sentence of evidence for this check (an extra model call). */
204
+ returnEvidence?: boolean;
205
+ }
206
+ /** The verdict on one success criterion. */
207
+ export interface Evidence {
208
+ /** The check's id; null for a natural-language `successCriteria`. */
209
+ id: string | null;
210
+ passed: boolean;
211
+ /** The probability that the check holds (`Check` criteria only). */
212
+ score: number | null;
213
+ /** Always for a natural-language criteria; for a `Check`, only with `returnEvidence`. */
214
+ evidence: string | null;
215
+ }
216
+ /** Turn record statuses, from `GET /v1/agents/turns/{id}`. */
217
+ export declare const TURN_RECORD_STATUSES: readonly ["running", "needs_input", "finalizing", "succeeded", "failed"];
218
+ export type TurnRecordStatus = (typeof TURN_RECORD_STATUSES)[number];
219
+ /**
220
+ * A turn's record. `status` is `running`, `needs_input` (an approval or
221
+ * question is pending), `finalizing` (the agent is done; output and checks are
222
+ * being worked out), `succeeded` or `failed`. On `failed`, `reasonCode` says
223
+ * why: `agent_error` (with `errorCode` when known), `machine_unavailable`,
224
+ * `not_started`, and for a structured message `output_invalid` (see `rawAnswer`
225
+ * and `outputErrors`), `criteria_not_met` or `criteria_unchecked`.
226
+ */
227
+ export interface TurnRecord {
228
+ id: string;
229
+ sessionId: string | null;
230
+ machineId: string;
231
+ status: TurnRecordStatus;
232
+ /** The agent's final text; with `outputSchema`, an object matching it. */
233
+ output: unknown;
234
+ reasonCode: string | null;
235
+ rawAnswer: string | null;
236
+ /** `insufficient_credits` or `free_computer_time_exhausted`, for a known `agent_error`. */
237
+ errorCode: string | null;
238
+ outputErrors: string[];
239
+ /** Empty for a plain message. */
240
+ evidence: Evidence[];
241
+ /** Tokens of every model call the agent made in the turn. */
242
+ usage: Usage | null;
243
+ recordTrajectory: boolean;
244
+ /** At least one step was stored (`sai.turns.trajectory()`). */
245
+ trajectoryRecorded: boolean;
246
+ template: string | null;
247
+ inputs: Json | null;
248
+ /** True when `idempotencyKey` matched an earlier turn: this is that turn, and nothing was sent. */
249
+ replayed: boolean;
250
+ done: boolean;
251
+ ok: boolean;
252
+ raw: Json;
253
+ }
254
+ export declare function parseTurnRecord(d: Json): TurnRecord;
255
+ /** One step the agent took: what it did, and why. Fetch its screen with `sai.turns.screenshot()`. */
256
+ export interface TrajectoryStep {
257
+ index: number;
258
+ /** The screenshot taken when the turn ended, after the last step. */
259
+ final: boolean;
260
+ timestamp: string;
261
+ title: string | null;
262
+ code: string | null;
263
+ /** The agent's text before the action. */
264
+ rationale: string | null;
265
+ error: string | null;
266
+ hasScreenshot: boolean;
267
+ raw: Json;
268
+ }
269
+ export declare function parseTrajectoryStep(d: Json): TrajectoryStep;
270
+ export interface ExecError {
271
+ /** `exception`, `timeout` or `interrupted`. */
272
+ kind: string;
273
+ message: string;
274
+ stack: string | null;
275
+ }
276
+ /** What one Simulang block returned. A block that threw is still a result: check `error`. */
277
+ export interface ExecResult {
278
+ result: unknown;
279
+ logs: string[];
280
+ error: ExecError | null;
281
+ /** The screenshot the block captured (page/app snapshot, pageContent), decoded. */
282
+ screenshot: Uint8Array | null;
283
+ /** `image/jpeg` or `image/png`. */
284
+ screenshotMimeType: string | null;
285
+ /** @deprecated Use `screenshot`. Not always PNG; see `screenshotMimeType`. */
286
+ screenshotPng?: Uint8Array | null;
287
+ screenshotOmitted: boolean;
288
+ variables: Json[];
289
+ durationMs: number;
290
+ ok: boolean;
291
+ raw: Json;
292
+ }
293
+ export declare function parseExecResult(d: Json): ExecResult;
294
+ /** One input of learned code: a `{{name}}` in the template and a key of `main`'s `params`. */
295
+ export interface LearnParameter {
296
+ name: string;
297
+ defaultValue: string;
298
+ description: string | null;
299
+ }
300
+ /** How learned code did on one run, for `sai.learn.create(..., { initialCode, evaluations })`. */
301
+ export interface Evaluation {
302
+ inputs: Record<string, string | number | boolean>;
303
+ /** The run's result from `lease.exec()` / `lease.run()`; its screenshot is not sent. */
304
+ result?: ExecResult;
305
+ /** A judgement of the run, or its id. */
306
+ judgement?: Judgement | string;
307
+ passed?: boolean;
308
+ note?: string;
309
+ }
310
+ /** What a `reset` did before a run or before the agent run. */
311
+ export interface LearnReset {
312
+ kind: 'code' | 'task';
313
+ ok: boolean;
314
+ durationMs: number | null;
315
+ /** A reset task's turn. */
316
+ turnId: string | null;
317
+ error: string | null;
318
+ }
319
+ /** One run of a version of the code in a learn job. */
320
+ export interface LearnRollout {
321
+ index: number;
322
+ /**
323
+ * `stopped`: the job stopped during this run (see the job's `stopReason`); `error`: the run could
324
+ * not be judged; `null` while the run is going.
325
+ */
326
+ verdict: 'passed' | 'failed' | 'error' | 'stopped' | null;
327
+ reset: LearnReset | null;
328
+ error: string | null;
329
+ result: Json | null;
330
+ durationMs: number | null;
331
+ judgementId: string | null;
332
+ /** The judge's summary. */
333
+ summary: string | null;
334
+ /** With `continueWithAgent`, the agent's turn after this failed run. */
335
+ continuationTurnId: string | null;
336
+ continuationTimedOut: boolean;
337
+ }
338
+ /** One version of the code in a learn job and its runs. */
339
+ export interface LearnIteration {
340
+ /** 1-based. */
341
+ index: number;
342
+ /** The convert or heal record that wrote this version (`sai.learn.get()` reads it). */
343
+ learnId: string | null;
344
+ /** What the repair changed and why. */
345
+ changes: string | null;
346
+ passed: number;
347
+ runs: number;
348
+ rollouts: LearnRollout[];
349
+ }
350
+ /** How the returned code did when it was run, on `inputs` only. */
351
+ export interface LearnTestResult {
352
+ /** `not_judged`: the code was not run all its runs; `passed`: it passed every run; `failed`: a run failed. */
353
+ status: 'not_judged' | 'passed' | 'failed';
354
+ passedRuns: number;
355
+ requiredRuns: number;
356
+ inputs: Record<string, string | number | boolean> | null;
357
+ }
358
+ /**
359
+ * The result of `sai.learn.create()`: Simulang code made from recorded turns or from an agent
360
+ * run, a repair of code you sent, or a learn job that runs, judges and repairs the code. Run the
361
+ * code with `lease.run(learned, inputs)`. Research preview.
362
+ */
363
+ export interface LearnResult {
364
+ id: string;
365
+ /** `convert` (code from turns), `heal` (a repair of `initialCode`), or `policyIteration` (a job that runs the code). */
366
+ mode: 'convert' | 'heal' | 'policyIteration';
367
+ /**
368
+ * Whether the call did its work: `running` while a job runs; `failed` when it wrote no code
369
+ * (e.g. `validation.errors`); `stopped` when a job ended early (see `stopReason`).
370
+ * How the code did is `testResult`.
371
+ */
372
+ status: 'succeeded' | 'failed' | 'running' | 'stopped';
373
+ /** Why a job ended early, e.g. `cancelled`, `time_limit`, `agent_failed`, `interrupted`. */
374
+ stopReason: string | null;
375
+ /** One sentence on why a job stopped. */
376
+ message: string | null;
377
+ /** How the returned code did when it was run. */
378
+ testResult: LearnTestResult | null;
379
+ /** While a job runs: the step it is on. */
380
+ progress: {
381
+ step: string;
382
+ iteration: number | null;
383
+ rollout: number | null;
384
+ } | null;
385
+ /** A job's agent run; pass it as `turns` to start again from that run. */
386
+ agentTurnId: string | null;
387
+ agentRunReset: LearnReset | null;
388
+ /** With `judgeInitialAgentRun`: the judgement of the agent run. */
389
+ agentJudgement: {
390
+ judgementId: string;
391
+ verdict: string;
392
+ summary: string | null;
393
+ } | null;
394
+ /** Which iteration `code` is from. */
395
+ version: number | null;
396
+ iterations: LearnIteration[];
397
+ title: string | null;
398
+ /** The task with `{{name}}` placeholders: send it to `session.send()` with `inputs` to run it with the agent. */
399
+ template: string | null;
400
+ parameters: LearnParameter[];
401
+ /** `async function main(params = { ... })`. */
402
+ code: string;
403
+ outputSchema: Json | null;
404
+ validation: {
405
+ errors: string[];
406
+ warnings: string[];
407
+ };
408
+ /** For `heal`: what changed and why. */
409
+ changes: string | null;
410
+ sourceTurns: string[];
411
+ usage: Usage | null;
412
+ /** The error code when the request failed, e.g. `trajectory_not_recorded`. */
413
+ error: string | null;
414
+ /** True when `idempotencyKey` matched an earlier call: this is that call's result. */
415
+ replayed: boolean;
416
+ ok: boolean;
417
+ raw: Json;
418
+ }
419
+ export declare function parseLearnResult(d: Json): LearnResult;
420
+ /** One run of a learn job's code, from `sai.learn.rollout()`. */
421
+ export interface LearnRun {
422
+ learnId: string;
423
+ iteration: number;
424
+ rollout: number;
425
+ /** What the run returned and logged: `{ result, logs, error, durationMs }`. */
426
+ run: Json;
427
+ /** The judge's record of the run, when it was judged. */
428
+ judgement: Json | null;
429
+ raw: Json;
430
+ }
431
+ export declare function parseLearnRun(d: Json): LearnRun;
432
+ /** The verdict on one criterion of a judgement. */
433
+ export interface CriterionResult {
434
+ /** The check's id; null for a natural-language criteria. */
435
+ id: string | null;
436
+ check: string;
437
+ /** `unverifiable` when the record cannot show it. */
438
+ verdict: 'passed' | 'failed' | 'unverifiable';
439
+ score: number | null;
440
+ evidence: string | null;
441
+ }
442
+ /** The result of `sai.judge.create()`. It never changes the turns it judged. Research preview. */
443
+ export interface Judgement {
444
+ id: string;
445
+ verdict: 'passed' | 'failed' | 'unverifiable' | null;
446
+ summary: string | null;
447
+ task: string | null;
448
+ criteria: CriterionResult[];
449
+ turns: string[];
450
+ usage: Usage | null;
451
+ replayed: boolean;
452
+ ok: boolean;
453
+ raw: Json;
454
+ }
455
+ export declare function parseJudgement(d: Json): Judgement;
456
+ export {};