withruntime 0.37.0 → 0.45.0

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.
package/dist/index.d.ts CHANGED
@@ -29,7 +29,7 @@ export type { CreateJob, Job, JobAlert, JobAlertDelivery, JobCompute, JobDefinit
29
29
  export type { CheckedDomain, DnsRecord, Domain, EgressAddress, TcpPort, Tunnel as PrivateTunnel, TunnelPeer, TunnelPeerCreated, SetUpstreamProxy, UpstreamProxy, } from "./products/network-products.js";
30
30
  export type { PrivateNetwork } from "./products/private-network.js";
31
31
  export type { SignedRequests } from "./products/signed-requests.js";
32
- export { verifyWebhook, WebhookVerificationError, type MetricPoint, type MetricRange, type OtelExport, type RuntimeEvent, type SandboxMetrics, type Webhook, type WebhookDelivery, type WebhookEventType, } from "./products/observability.js";
32
+ export { verifyWebhook, WebhookVerificationError, type MetricPoint, type MetricRange, type OtelExport, type OtelSignal, type RuntimeEvent, type SandboxMetrics, type Webhook, type WebhookDelivery, type WebhookEventType, } from "./products/observability.js";
33
33
  export { Snapshots, type Snapshot, type SnapshotOptions } from "./snapshots.js";
34
34
  export { Transport, VERSION, apiOrigin, type RequestOptions, type Call } from "./transport.js";
35
35
  export * from "./errors.js";
@@ -78,10 +78,10 @@ export { openWalletAccount, claimWalletAccount, rekeyWalletAccount, type OpenedW
78
78
  export type { Topup } from "./products/billing.js";
79
79
  export type { NewKey, LimitedKey, LimitedKeyAction, MadeKey, ListedKey, KeyUsage, } from "./products/api-keys.js";
80
80
  export type { SsoConnection, SsoStatus } from "./products/sso.js";
81
- export type { Agent, AgentAsk, AgentAskState, AgentDefinition, AgentEvent, AgentHeldCall, AgentMemoryEntry, AgentMemoryFile, AgentMemoryHit, AgentMemoryPage, AgentMemoryUsage, AgentMemoryWritten, AgentPermissionPolicy, AgentPermissions, AgentSession, AgentSessionHandle, AgentSessionState, AgentTemplate, AgentTemplateKey, AgentAskToolCall, AgentTokens, AgentToolCall, AgentTrace, AgentTraceOtlp, AgentTracePage, AgentTrigger, AgentTriggerCall, AgentTriggerCallOutcome, AgentTriggerKind, AgentTriggerRules, AgentTurn, AgentUse, AnswerAgentAsk, CreateAgent, CreateAgentTrigger, ListAgentAsks, StartAgentSession, } from "./products/agents.js";
81
+ export type { Agent, AgentAdvisor, AgentAsk, AgentAskState, AgentDefinition, AgentEvent, AgentHeldCall, AgentMemoryEntry, AgentMemoryFile, AgentMemoryHit, AgentMemoryPage, AgentMemoryUsage, AgentMemoryWritten, AgentPermissionPolicy, AgentPermissions, AgentSession, AgentSessionHandle, AgentSessionOverrideLimits, AgentSessionOverrides, AgentSessionState, AgentTemplate, AgentTemplateKey, AgentAskToolCall, AgentTokens, AgentToolCall, AgentTrace, AgentTraceOtlp, AgentTracePage, AgentTrigger, AgentTriggerCall, AgentTriggerCallOutcome, AgentTriggerKind, AgentTriggerRules, AgentTurn, AgentUse, AgentWorkflow, AgentWorkflowHandle, AgentWorkflowPhase, AgentWorkflowState, AgentWorkflowStep, AnswerAgentAsk, CreateAgent, CreateAgentTrigger, ListAgentAsks, RunAgentWorkflow, SlackInstallLink, SlackTeam, StartAgentSession, } from "./products/agents.js";
82
82
  export { AGENT_TEMPLATES, AGENT_USES } from "./products/agents.js";
83
83
  export type { AgentsDeployChange, AgentsDeployOptions, AgentsDeployResult, AgentsFile, AgentsFileAgent, AgentsFileTrigger, AgentsSource, } from "./agents-deploy.js";
84
84
  export type { Container, ContainerState, CreateContainer, UpdateContainer, } from "./products/containers.js";
85
- export type { Browser, BrowserConnectOptions, BrowserInfo, BrowserScreenshot, BrowserScreenshotResult, CreateBrowser, UpdateBrowser, } from "./products/browsers.js";
85
+ export type { Browser, BrowserConnectOptions, BrowserInfo, BrowserScreenshot, BrowserScreenshotResult, BrowserRun, BrowserRunInput, BrowserRunState, BrowserRunStep, BrowserRunSteps, CreateBrowser, UpdateBrowser, } from "./products/browsers.js";
86
86
  export type { CreateDesktop, Desktop, DesktopAct, DesktopState, UpdateDesktop, } from "./products/desktops.js";
87
87
  export type { CiAnnotation, CiFlake, CiFlakeDetail, CiReleaseStep, CiRepository, CiTestResult, ConnectCiRepository, ListCiFlakes, ListCiReleaseSteps, ListCiRepositories, UpdateCiFlake, } from "./products/ci.js";
@@ -92,6 +92,20 @@ export type AgentDefinition = {
92
92
  memory?: {
93
93
  scope: "key" | "agent";
94
94
  };
95
+ /** The model the harness runs (claude-opus-5-5, gpt-5.1-codex,
96
+ * gemini-3-pro); absent, the harness's default. The harness reads it as
97
+ * RUNTIME_AGENT_MODEL, and Claude Code, the Claude Agent SDK, Codex,
98
+ * Gemini CLI and the OpenAI Agents SDK each by their own setting. */
99
+ model?: string;
100
+ /** What a session's start may override (`StartAgentSession.overrides`). */
101
+ sessionOverrides?: AgentSessionOverrideLimits;
102
+ /** Child sessions its tree may hold open at once, a workflow's steps
103
+ * from inside it included: 1 to 1000, default 100. */
104
+ maxChildren?: number;
105
+ /** A second model a session asks for advice mid-task (`advise` in the
106
+ * sandbox). Each question and answer is kept in the session's log as a
107
+ * `note` whose body holds `advice`. */
108
+ advisor?: AgentAdvisor;
95
109
  /** Which tool calls of the harness run, wait for a person, or are
96
110
  * refused. Each call is a `tool_call` event in the session's log; one that
97
111
  * waits is an ask of the inbox with the options Allow and Deny
@@ -99,6 +113,46 @@ export type AgentDefinition = {
99
113
  * Absent: every call runs. */
100
114
  permissions?: AgentPermissions;
101
115
  };
116
+ /** The limits an agent's owner sets on its sessions' overrides. A session
117
+ * may always narrow its MCP servers and disallow tools. */
118
+ export type AgentSessionOverrideLimits = {
119
+ /** The models a session may name; absent, any. */
120
+ models?: string[];
121
+ /** Whether a session may add to the agent's instructions (`append`, the
122
+ * default), also replace them (`replace`), or neither (`none`). */
123
+ instructions?: "append" | "replace" | "none";
124
+ /** The most vCPU a session may ask for; absent, the agent's `vcpu`. */
125
+ maxVcpu?: number;
126
+ /** The most memory a session may ask for; absent, the agent's `memoryMiB`. */
127
+ maxMemoryMiB?: number;
128
+ /** The most budget a session may ask for; absent, the agent's `maxSessionDollars`. */
129
+ maxSessionDollars?: number;
130
+ };
131
+ /** One session's own model, instructions, MCP servers, disallowed tools,
132
+ * size and budget, within its agent's `sessionOverrides`. Recorded on the
133
+ * session (`overrides`) and noted in its log. */
134
+ export type AgentSessionOverrides = {
135
+ /** The model the harness runs for this session. */
136
+ model?: string;
137
+ /** Added after the agent's instructions, or in their place with
138
+ * `instructionsMode: "replace"`; at most 64 KiB with the agent's. */
139
+ instructions?: string;
140
+ /** `append` (the default) or `replace`. */
141
+ instructionsMode?: "append" | "replace";
142
+ /** Names of the agent's MCP servers this session keeps; `[]` keeps none. */
143
+ mcp?: string[];
144
+ /** Tools the harness may not use: Runtime's own (`spawn`, `pr`, `ask`,
145
+ * `remember`, ...; never `wait`, `reply` or `done`) and the harness's
146
+ * (Claude Code's `Bash` or `mcp__github`, Gemini CLI's `run_shell_command`). */
147
+ disallowedTools?: string[];
148
+ /** At most the agent's `sessionOverrides.maxVcpu`, else its own `vcpu`. */
149
+ vcpu?: number;
150
+ /** At most the agent's `sessionOverrides.maxMemoryMiB`, else its own. */
151
+ memoryMiB?: number;
152
+ /** This session's budget, its subagents included; at most the agent's
153
+ * `sessionOverrides.maxSessionDollars`, else its own. */
154
+ maxSessionDollars?: number;
155
+ };
102
156
  /** always_allow: the call runs. always_ask: it waits for a person's Allow or
103
157
  * Deny. auto: Runtime reads the call and runs it, refuses it (high_risk) or
104
158
  * holds it for a person (indeterminate). */
@@ -111,6 +165,21 @@ export type AgentPermissions = {
111
165
  * an MCP server (mcp:github), or a family (shell, edit, read, web, mcp). */
112
166
  tools?: Record<string, AgentPermissionPolicy>;
113
167
  };
168
+ export type AgentAdvisor = {
169
+ /** claude-opus-5-5, gpt-5.5, gemini-3-pro, or an OpenRouter name. */
170
+ model: string;
171
+ /** Read from the model's name when left out. */
172
+ provider?: "anthropic" | "openai" | "google" | "openrouter" | "openai-compatible";
173
+ /** The egress secret its key is, which must be in `secrets` or `pool`;
174
+ * the provider's usual one when left out (ANTHROPIC_API_KEY, ...). */
175
+ secret?: string;
176
+ /** An OpenAI-compatible endpoint, or another host for the provider's API. */
177
+ baseUrl?: string;
178
+ /** Advice a session may ask for: 1 to 200, default 20. */
179
+ maxCalls?: number;
180
+ /** The advisor's standing words, at most 16 KiB. */
181
+ instructions?: string;
182
+ };
114
183
  export type Agent = {
115
184
  id: string;
116
185
  name: string;
@@ -144,6 +213,11 @@ export type AgentSession = {
144
213
  sandboxId: string | null;
145
214
  lastSeq: number;
146
215
  labels: Record<string, string>;
216
+ /** What its start overrode of its agent's definition, as given; null,
217
+ * nothing. */
218
+ overrides: AgentSessionOverrides | null;
219
+ /** The workflow it is a step of, or null. */
220
+ workflowId: string | null;
147
221
  createdAt: string;
148
222
  startedAt: string | null;
149
223
  endedAt: string | null;
@@ -326,6 +400,18 @@ export type AnswerAgentAsk = {
326
400
  text?: string;
327
401
  };
328
402
  export type AgentTriggerKind = "slack" | "github" | "schedule" | "webhook";
403
+ /** The link that adds Runtime's Slack app to a workspace. */
404
+ export type SlackInstallLink = {
405
+ url: string;
406
+ expiresAt: string;
407
+ };
408
+ /** A Slack workspace added to the account: its id is a slack trigger's `team`. */
409
+ export type SlackTeam = {
410
+ team: string;
411
+ name: string | null;
412
+ botUser: string;
413
+ installedAt: string;
414
+ };
329
415
  /** A trigger's rules, each optional. */
330
416
  export type AgentTriggerRules = {
331
417
  /** Queue order of its sessions when the agent's maxConcurrent is full:
@@ -371,6 +457,12 @@ export type StartAgentSession = {
371
457
  * request, one of your customers (`customer:42`). */
372
458
  key?: string;
373
459
  labels?: Record<string, string>;
460
+ /** This session's own model, instructions, MCP servers, disallowed tools,
461
+ * size and budget, within the agent's `sessionOverrides`: one it does not
462
+ * allow is refused (`permission_denied`, naming what it allows). Words
463
+ * that join an open session carry its own overrides or none (else
464
+ * `conflict`). */
465
+ overrides?: AgentSessionOverrides;
374
466
  };
375
467
  export type CreateAgentTrigger = ({
376
468
  kind: "slack";
@@ -436,7 +528,7 @@ export type AgentHeldCall = {
436
528
  resolvedAt: string | null;
437
529
  };
438
530
  /** The harnesses' names, so `templates["claude-code"]` is known to be there. */
439
- export type AgentTemplateKey = "claude-code" | "codex" | "gemini-cli" | "claude-agent-sdk" | "openai-agents-sdk" | "review" | "judge";
531
+ export type AgentTemplateKey = "claude-code" | "codex" | "gemini-cli" | "claude-agent-sdk" | "openai-agents-sdk" | "review" | "judge" | "browser";
440
532
  /** A file of an agent's memory (`memory.list`). `scope` is whose: empty for
441
533
  * the shared memory, which every session reads (one keeping memory per key
442
534
  * reads what you wrote there, and never changes it), or a session key
@@ -516,6 +608,120 @@ export declare const AGENT_TEMPLATES: Readonly<Record<AgentTemplateKey, AgentTem
516
608
  /** A harness by a key read from a file or a flag, or undefined. */
517
609
  export declare function agentTemplate(key: string): AgentTemplate | undefined;
518
610
  export declare const AGENT_USES: Readonly<Record<"support" | "team", AgentUse>>;
611
+ /** One phase of a workflow. */
612
+ export type AgentWorkflowPhase = {
613
+ /** A letter, then letters, digits, _ or -; {{<name>}} reads its results. */
614
+ name: string;
615
+ /** Its sessions' agent, by id or name; the workflow's when left out. */
616
+ agent?: string;
617
+ /** Each session's first words: {{input}}, {{item}}, {{index}} (1-based)
618
+ * and {{<earlier phase>}} (its results, numbered) are filled in. */
619
+ input: string;
620
+ /** A list to fan out over (1 to 1000 items, one session each), or an
621
+ * earlier phase's results split: `json`, the JSON array in each result;
622
+ * `lines`, its non-empty lines. Absent: one session. */
623
+ each?: unknown[] | {
624
+ from: string;
625
+ split?: "json" | "lines";
626
+ };
627
+ /** With `each.from`: start each item the moment its source session ends. */
628
+ pipeline?: boolean;
629
+ };
630
+ /** Many sessions in phases, as one piece of work. */
631
+ export type RunAgentWorkflow = {
632
+ name?: string;
633
+ /** The agent of every phase that names none. */
634
+ agent?: string;
635
+ /** What {{input}} is. */
636
+ input?: string;
637
+ labels?: Record<string, string>;
638
+ /** Sessions it may start in all: 1 to 1000, default 100. */
639
+ maxSessions?: number;
640
+ /** Its sessions open at once: 1 to 200, default 20. */
641
+ maxConcurrent?: number;
642
+ /** What it may cost in all, in dollars: default 10. */
643
+ maxDollars?: number;
644
+ phases: AgentWorkflowPhase[];
645
+ };
646
+ export type AgentWorkflowState = "running" | "done" | "failed" | "stopped";
647
+ export type AgentWorkflow = {
648
+ id: string;
649
+ name: string | null;
650
+ state: AgentWorkflowState;
651
+ /** Why it ended: done, steps_failed, max_sessions, budget, stopped,
652
+ * parent_ended, quota, subagent_quota, agent_gone, permission_denied. */
653
+ reason: string | null;
654
+ /** Its last phase's result: one session's as it is, several as a JSON
655
+ * array of their results. */
656
+ result: string | null;
657
+ /** The session that ran it from inside its sandbox, or null. */
658
+ parentSessionId: string | null;
659
+ spec: RunAgentWorkflow;
660
+ maxSessions: number;
661
+ maxConcurrent: number;
662
+ maxDollars: number;
663
+ /** Sessions it has started. */
664
+ started: number;
665
+ /** Raised at every change. */
666
+ version: number;
667
+ labels: Record<string, string>;
668
+ phases: {
669
+ name: string;
670
+ agentId: string;
671
+ /** Items known so far; final once `ready`. */
672
+ total: number;
673
+ ready: boolean;
674
+ pending: number;
675
+ running: number;
676
+ done: number;
677
+ /** Failed, stopped or skipped. */
678
+ failed: number;
679
+ }[];
680
+ cost: {
681
+ dollars: number;
682
+ vcpuSeconds: number;
683
+ gibSeconds: number;
684
+ };
685
+ createdAt: string;
686
+ updatedAt: string;
687
+ endedAt: string | null;
688
+ };
689
+ export type AgentWorkflowStep = {
690
+ phase: string;
691
+ item: number;
692
+ /** What {{item}} was. */
693
+ itemText: string | null;
694
+ state: "pending" | "running" | "done" | "failed" | "stopped" | "skipped";
695
+ reason: string | null;
696
+ /** What its session ended with. */
697
+ result: string | null;
698
+ sessionId: string | null;
699
+ createdAt: string;
700
+ startedAt: string | null;
701
+ endedAt: string | null;
702
+ };
703
+ /** One workflow, to follow and stop. */
704
+ export type AgentWorkflowHandle = {
705
+ readonly id: string;
706
+ /** The workflow as it was when run or read. */
707
+ readonly workflow: AgentWorkflow;
708
+ /** The workflow at each change, as it happens, until it has ended. */
709
+ follow(options?: {
710
+ after?: number;
711
+ signal?: AbortSignal;
712
+ }): AsyncGenerator<AgentWorkflow>;
713
+ /** Until it has ended; answers it then, with its result. */
714
+ wait(options?: {
715
+ signal?: AbortSignal;
716
+ }): Promise<AgentWorkflow>;
717
+ /** Its steps in phase and item order. */
718
+ steps(query?: {
719
+ state?: AgentWorkflowStep["state"][];
720
+ limit?: number;
721
+ }, options?: RequestOptions): Promise<Page<AgentWorkflowStep>>;
722
+ stop(options?: RequestOptions): Promise<AgentWorkflow>;
723
+ get(options?: RequestOptions): Promise<AgentWorkflow>;
724
+ };
519
725
  /** One session, to talk to and follow. */
520
726
  export type AgentSessionHandle = {
521
727
  readonly id: string;
@@ -597,6 +803,37 @@ export declare function agents(t: Transport): {
597
803
  * (`session_open`): stop it first. */
598
804
  delete: (id: string, options?: RequestOptions) => Promise<void>;
599
805
  };
806
+ /** Many sessions in phases as one piece of work: fanned out over lists
807
+ * or earlier results, in parallel and in pipelines, under maxSessions,
808
+ * maxConcurrent and maxDollars, ending with one result. The database
809
+ * starts each step the moment what it waits on ends; nothing else runs
810
+ * between steps, so a workflow costs only its sessions. */
811
+ workflows: {
812
+ /** Runs it now; answers a handle to follow, wait for and stop. */
813
+ run(input: RunAgentWorkflow, options?: RequestOptions): Promise<AgentWorkflowHandle>;
814
+ /** One you already have, by its id. */
815
+ workflow(id: string, options?: RequestOptions): Promise<AgentWorkflowHandle>;
816
+ get: (id: string, options?: RequestOptions) => Promise<AgentWorkflow>;
817
+ /** The workflow at each change past `after`, as it happens, until it
818
+ * has ended: each read waits up to 30 seconds for the next change. */
819
+ follow: (id: string, options?: {
820
+ after?: number;
821
+ signal?: AbortSignal;
822
+ }) => AsyncGenerator<AgentWorkflow>;
823
+ /** Newest first, each with its phases' progress and cost. */
824
+ list: (query?: {
825
+ state?: AgentWorkflowState[];
826
+ cursor?: string;
827
+ limit?: number;
828
+ }, options?: RequestOptions) => Promise<Page<AgentWorkflow>>;
829
+ steps: (id: string, query?: {
830
+ state?: AgentWorkflowStep["state"][];
831
+ cursor?: string;
832
+ limit?: number;
833
+ }, options?: RequestOptions) => Promise<Page<AgentWorkflowStep>>;
834
+ /** Nothing more of it starts, and its open sessions stop. */
835
+ stop: (id: string, options?: RequestOptions) => Promise<AgentWorkflow>;
836
+ };
600
837
  /** The account's inbox: the questions its agents' sessions need answered
601
838
  * to go on, one row per step however many sessions ask it. */
602
839
  asks: {
@@ -612,6 +849,20 @@ export declare function agents(t: Transport): {
612
849
  * told to the agent as the reason. */
613
850
  deny: (id: string, message?: string, options?: RequestOptions) => Promise<AgentAsk>;
614
851
  };
852
+ /** Runtime's Slack app in your workspaces, for `slack` triggers. */
853
+ slack: {
854
+ /** A link that adds Runtime's Slack app to a workspace, good for 15
855
+ * minutes. Open it in a browser signed in to this account, then
856
+ * approve the app in Slack; Slack sends the browser back to the
857
+ * console once it is added. Opened by anyone outside the account, it
858
+ * adds nothing. */
859
+ install: (options?: RequestOptions) => Promise<SlackInstallLink>;
860
+ /** The workspaces added to this account. */
861
+ teams: (options?: RequestOptions) => Promise<SlackTeam[]>;
862
+ /** Removes a workspace: its token is revoked, and its triggers refuse
863
+ * events until it is added again. */
864
+ remove: (team: string, options?: RequestOptions) => Promise<void>;
865
+ };
615
866
  triggers: {
616
867
  create: (agent: string, input: CreateAgentTrigger, options?: RequestOptions) => Promise<AgentTrigger>;
617
868
  list: (agent: string, options?: RequestOptions) => Promise<AgentTrigger[]>;
@@ -24,6 +24,9 @@ const CODEX = 'npx -y @openai/codex exec --dangerously-bypass-approvals-and-sand
24
24
  const GEMINI = 'npx -y @google/gemini-cli --yolo -p "$(cat ~/.runtime-agent/start.md)"';
25
25
  const REVIEW = "python3 ~/.runtime-agent/runtime-agent review";
26
26
  const JUDGE = "python3 ~/.runtime-agent/runtime-agent judge";
27
+ /** A browser run's harness (browser-use on the sandbox's Chromium); its
28
+ * sessions are started by POST /v1/browsers/runs. */
29
+ const BROWSE = "python3 ~/.runtime-agent/runtime-agent browse";
27
30
  /** The harnesses (agents-contract.md); tests/agents.test.ts holds them
28
31
  * to packages/cloud-guide/agent-templates.json. */
29
32
  export const AGENT_TEMPLATES = {
@@ -102,6 +105,21 @@ export const AGENT_TEMPLATES = {
102
105
  maxSessionSeconds: 1800,
103
106
  },
104
107
  },
108
+ browser: {
109
+ key: "browser",
110
+ title: "Browser task",
111
+ command: BROWSE,
112
+ apiKeySecret: "ANTHROPIC_API_KEY",
113
+ apiKeyHost: "api.anthropic.com",
114
+ subscription: null,
115
+ definition: {
116
+ command: BROWSE,
117
+ secrets: ["ANTHROPIC_API_KEY"],
118
+ vcpu: 2,
119
+ memoryMiB: 4096,
120
+ maxSessionSeconds: 1800,
121
+ },
122
+ },
105
123
  };
106
124
  /** A harness by a key read from a file or a flag, or undefined. */
107
125
  export function agentTemplate(key) {
@@ -212,6 +230,66 @@ export function agents(t) {
212
230
  });
213
231
  return new Page(page.data, page.nextCursor, (cursor) => listSessions({ ...query, cursor }, options));
214
232
  };
233
+ const getWorkflow = (id, options) => t.json({ method: "GET", path: `/v1/agents/workflows/${enc(id)}`, ...options });
234
+ async function* followWorkflow(id, options = {}) {
235
+ let after = options.after ?? 0;
236
+ for (;;) {
237
+ options.signal?.throwIfAborted();
238
+ const now = await t.json({
239
+ method: "GET",
240
+ path: `/v1/agents/workflows/${enc(id)}`,
241
+ query: { after, wait: 30 },
242
+ ...(options.signal ? { signal: options.signal } : {}),
243
+ timeoutMs: 0,
244
+ });
245
+ if (now.version > after) {
246
+ after = now.version;
247
+ yield now;
248
+ }
249
+ if (now.state !== "running")
250
+ return;
251
+ }
252
+ }
253
+ const listWorkflows = async (query = {}, options) => {
254
+ const page = await t.json({
255
+ method: "GET",
256
+ path: "/v1/agents/workflows",
257
+ query,
258
+ ...options,
259
+ });
260
+ return new Page(page.data, page.nextCursor, (cursor) => listWorkflows({ ...query, cursor }, options));
261
+ };
262
+ const listSteps = async (id, query = {}, options) => {
263
+ const page = await t.json({
264
+ method: "GET",
265
+ path: `/v1/agents/workflows/${enc(id)}/steps`,
266
+ query,
267
+ ...options,
268
+ });
269
+ return new Page(page.data, page.nextCursor, (cursor) => listSteps(id, { ...query, cursor }, options));
270
+ };
271
+ const stopWorkflow = (id, options) => t.json({
272
+ method: "POST",
273
+ path: `/v1/agents/workflows/${enc(id)}/stop`,
274
+ body: {},
275
+ ...options,
276
+ });
277
+ const workflowHandle = (workflow) => ({
278
+ id: workflow.id,
279
+ workflow,
280
+ follow: (options) => followWorkflow(workflow.id, options),
281
+ async wait(options = {}) {
282
+ let last = await getWorkflow(workflow.id, options);
283
+ if (last.state !== "running")
284
+ return last;
285
+ for await (const now of followWorkflow(workflow.id, { after: last.version, ...options }))
286
+ last = now;
287
+ return last;
288
+ },
289
+ steps: (query, options) => listSteps(workflow.id, query, options),
290
+ stop: (options) => stopWorkflow(workflow.id, options),
291
+ get: (options) => getWorkflow(workflow.id, options),
292
+ });
215
293
  const listAsks = async (query = {}, options) => {
216
294
  const { labels, ...rest } = query;
217
295
  const page = await t.json({
@@ -306,6 +384,35 @@ export function agents(t) {
306
384
  });
307
385
  },
308
386
  },
387
+ /** Many sessions in phases as one piece of work: fanned out over lists
388
+ * or earlier results, in parallel and in pipelines, under maxSessions,
389
+ * maxConcurrent and maxDollars, ending with one result. The database
390
+ * starts each step the moment what it waits on ends; nothing else runs
391
+ * between steps, so a workflow costs only its sessions. */
392
+ workflows: {
393
+ /** Runs it now; answers a handle to follow, wait for and stop. */
394
+ async run(input, options) {
395
+ return workflowHandle(await t.json({
396
+ method: "POST",
397
+ path: "/v1/agents/workflows",
398
+ body: input,
399
+ ...options,
400
+ }));
401
+ },
402
+ /** One you already have, by its id. */
403
+ async workflow(id, options) {
404
+ return workflowHandle(await getWorkflow(id, options));
405
+ },
406
+ get: getWorkflow,
407
+ /** The workflow at each change past `after`, as it happens, until it
408
+ * has ended: each read waits up to 30 seconds for the next change. */
409
+ follow: followWorkflow,
410
+ /** Newest first, each with its phases' progress and cost. */
411
+ list: listWorkflows,
412
+ steps: listSteps,
413
+ /** Nothing more of it starts, and its open sessions stop. */
414
+ stop: stopWorkflow,
415
+ },
309
416
  /** The account's inbox: the questions its agents' sessions need answered
310
417
  * to go on, one row per step however many sessions ask it. */
311
418
  asks: {
@@ -336,6 +443,35 @@ export function agents(t) {
336
443
  ...options,
337
444
  }),
338
445
  },
446
+ /** Runtime's Slack app in your workspaces, for `slack` triggers. */
447
+ slack: {
448
+ /** A link that adds Runtime's Slack app to a workspace, good for 15
449
+ * minutes. Open it in a browser signed in to this account, then
450
+ * approve the app in Slack; Slack sends the browser back to the
451
+ * console once it is added. Opened by anyone outside the account, it
452
+ * adds nothing. */
453
+ install: (options) => t.json({
454
+ method: "POST",
455
+ path: "/v1/agents/slack/installs",
456
+ body: {},
457
+ ...options,
458
+ }),
459
+ /** The workspaces added to this account. */
460
+ teams: async (options) => (await t.json({
461
+ method: "GET",
462
+ path: "/v1/agents/slack/teams",
463
+ ...options,
464
+ })).data,
465
+ /** Removes a workspace: its token is revoked, and its triggers refuse
466
+ * events until it is added again. */
467
+ remove: async (team, options) => {
468
+ await t.json({
469
+ method: "DELETE",
470
+ path: `/v1/agents/slack/teams/${enc(team)}`,
471
+ ...options,
472
+ });
473
+ },
474
+ },
339
475
  triggers: {
340
476
  create: (agent, input, options) => t.json({
341
477
  method: "POST",
@@ -116,7 +116,8 @@ export type CreateFunction = {
116
116
  name?: string;
117
117
  /** At most 32 entries, each value at most 256 characters. */
118
118
  labels?: Record<string, string>;
119
- /** Required, 1 to 1000. Bounds the number of awake copies. */
119
+ /** Required, 1 to the account's App copies at once (its plan's sandboxes at
120
+ * once, GET /v1/limits `instance.count`). Bounds the number of awake copies. */
120
121
  maxCopies: number;
121
122
  /** Required, 1 to 16. */
122
123
  vcpu: number;
@@ -62,6 +62,61 @@ export type BrowserScreenshotResult = {
62
62
  /** The image. */
63
63
  base64: string;
64
64
  };
65
+ /** A task in plain words, done by an agent that browses (POST /v1/browsers/runs). */
66
+ export type BrowserRunInput = {
67
+ /** What to do, in plain words; at most 16 KiB. */
68
+ task: string;
69
+ /** Opened before the agent's first step. */
70
+ startUrl?: string;
71
+ /** A claude-, gpt-, o1, o3, o4 or gemini- model; the server defaults to
72
+ * claude-sonnet-5-5. Its key is your egress secret ANTHROPIC_API_KEY,
73
+ * OPENAI_API_KEY or GEMINI_API_KEY. */
74
+ model?: string;
75
+ /** 1 to 200; the server defaults to 30. */
76
+ maxSteps?: number;
77
+ /** Only these domains are opened (example.com, *.example.com). */
78
+ allowedDomains?: string[];
79
+ labels?: Record<string, string>;
80
+ };
81
+ export type BrowserRunState = "queued" | "running" | "done" | "failed" | "stopped";
82
+ export type BrowserRun = {
83
+ id: string;
84
+ state: BrowserRunState;
85
+ task: string | null;
86
+ model: string | null;
87
+ startUrl: string | null;
88
+ /** The agent's answer, once done. */
89
+ output: string | null;
90
+ /** Why it failed, and what to do. */
91
+ error: string | null;
92
+ steps: number;
93
+ /** The page the browser ended on. */
94
+ url: string | null;
95
+ sandboxId: string | null;
96
+ labels: Record<string, string>;
97
+ createdAt: string;
98
+ startedAt: string | null;
99
+ endedAt: string | null;
100
+ };
101
+ /** One step of a run: the page the agent saw and what it did. */
102
+ export type BrowserRunStep = {
103
+ /** 0 is the page before the first step; the last is the page at the end. */
104
+ n: number;
105
+ url: string | null;
106
+ title: string | null;
107
+ goal: string | null;
108
+ actions: unknown[];
109
+ /** The page as a JPEG, base64; null when asked without frames. */
110
+ frame: string | null;
111
+ at: string;
112
+ /** Its place in the run's log: pass as `after`. */
113
+ seq: number;
114
+ };
115
+ export type BrowserRunSteps = {
116
+ data: BrowserRunStep[];
117
+ after: number;
118
+ ended: boolean;
119
+ };
65
120
  export type BrowserConnectOptions = {
66
121
  playwright: [endpointURL: string, options: {
67
122
  headers: Record<string, string>;
@@ -94,4 +149,36 @@ export declare function browsers(t: Transport): {
94
149
  screenshot(id: string, input?: BrowserScreenshot, options?: RequestOptions): Promise<BrowserScreenshotResult>;
95
150
  /** End a browser by id; pass RequestOptions to bound or deduplicate the request. */
96
151
  delete: (id: string, options?: RequestOptions) => Promise<void>;
152
+ /** Do a task in a browser, described in plain words, and wait for its
153
+ * end: `output` once done, `error` once failed. A string is the task.
154
+ * Its steps, each with the page it saw, are `runs.steps(run.id)`. */
155
+ run(input: string | BrowserRunInput, options?: RequestOptions): Promise<BrowserRun>;
156
+ runs: {
157
+ /** Start a run and return it at once (state queued). */
158
+ create: (input: BrowserRunInput, options?: RequestOptions) => Promise<BrowserRun>;
159
+ get: (id: string, options?: RequestOptions) => Promise<BrowserRun>;
160
+ list: (query?: {
161
+ cursor?: string;
162
+ limit?: number;
163
+ }, options?: RequestOptions) => Promise<Page<BrowserRun>>;
164
+ /** One page of a run's steps; `wait` (seconds, up to 30) waits for one. */
165
+ steps: (id: string, query?: {
166
+ after?: number;
167
+ limit?: number;
168
+ frames?: boolean;
169
+ wait?: number;
170
+ }, options?: RequestOptions) => Promise<BrowserRunSteps>;
171
+ /** Every step, as it comes, until the run ends: its recording. */
172
+ follow: (id: string, options?: {
173
+ after?: number;
174
+ frames?: boolean;
175
+ signal?: AbortSignal;
176
+ }) => AsyncGenerator<BrowserRunStep>;
177
+ /** Stop a run; its sandbox is deleted and its steps are kept. */
178
+ stop: (id: string, options?: RequestOptions) => Promise<BrowserRun>;
179
+ /** Until the run has ended; answers it then. */
180
+ wait(id: string, options?: {
181
+ signal?: AbortSignal;
182
+ }): Promise<BrowserRun>;
183
+ };
97
184
  };