withruntime 0.35.0 → 0.37.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.
@@ -65,6 +65,13 @@ export type AgentDefinition = {
65
65
  volume: string;
66
66
  path: string;
67
67
  }[];
68
+ /** Where each session's sandbox may connect, enforced by its network
69
+ * rules from its first packet: with allow, only those hosts. Absent:
70
+ * anywhere. */
71
+ network?: {
72
+ internet: boolean;
73
+ allow?: string[];
74
+ };
68
75
  /** How long a session's sandbox runs with nothing happening before it
69
76
  * pauses; default 60. */
70
77
  idlePauseSeconds?: number;
@@ -85,6 +92,24 @@ export type AgentDefinition = {
85
92
  memory?: {
86
93
  scope: "key" | "agent";
87
94
  };
95
+ /** Which tool calls of the harness run, wait for a person, or are
96
+ * refused. Each call is a `tool_call` event in the session's log; one that
97
+ * waits is an ask of the inbox with the options Allow and Deny
98
+ * (`agents.asks.approve`, `agents.asks.deny`), and only that call waits.
99
+ * Absent: every call runs. */
100
+ permissions?: AgentPermissions;
101
+ };
102
+ /** always_allow: the call runs. always_ask: it waits for a person's Allow or
103
+ * Deny. auto: Runtime reads the call and runs it, refuses it (high_risk) or
104
+ * holds it for a person (indeterminate). */
105
+ export type AgentPermissionPolicy = "always_allow" | "always_ask" | "auto";
106
+ export type AgentPermissions = {
107
+ /** Default always_allow. */
108
+ default?: AgentPermissionPolicy;
109
+ /** By the most particular name that matches: the harness's own tool name
110
+ * (Bash, Edit, apply_patch, run_shell_command, mcp__github__create_issue),
111
+ * an MCP server (mcp:github), or a family (shell, edit, read, web, mcp). */
112
+ tools?: Record<string, AgentPermissionPolicy>;
88
113
  };
89
114
  export type Agent = {
90
115
  id: string;
@@ -125,7 +150,11 @@ export type AgentSession = {
125
150
  };
126
151
  export type AgentEvent = {
127
152
  seq: number;
128
- kind: "input" | "answer" | "reply" | "ask" | "status" | "result" | "error" | "note";
153
+ /** turn and tool: a model turn and a tool call of the session's trace,
154
+ * the span in body (`AgentTurn`, `AgentToolCall`). tool_call: one call
155
+ * the harness made under the agent's permissions, body {text, tool,
156
+ * input, toolUseId, evaluatedPermission, evaluation, askId}. */
157
+ kind: "input" | "answer" | "reply" | "ask" | "status" | "result" | "error" | "note" | "child" | "turn" | "tool" | "tool_call";
129
158
  /** A key's principal id, slack:<user>, github:<login>, agent (the
130
159
  * harness) or runtime. */
131
160
  actor: string;
@@ -135,6 +164,95 @@ export type AgentEvent = {
135
164
  } & Record<string, unknown>;
136
165
  createdAt: string;
137
166
  };
167
+ /** Token counts and their cost at the provider's list price, in USD. */
168
+ export type AgentTokens = {
169
+ /** Input tokens not read from or written to the prompt cache. */
170
+ inputTokens: number;
171
+ outputTokens: number;
172
+ cacheReadTokens: number;
173
+ cacheWriteTokens: number;
174
+ costUsd: number;
175
+ };
176
+ /** One model request the session's harness made. */
177
+ export type AgentTurn = Omit<AgentTokens, "costUsd"> & {
178
+ seq: number;
179
+ kind: "turn";
180
+ /** 16 hex digits; a tool call's `turn` names it. */
181
+ id: string;
182
+ provider: "anthropic" | "openai" | "google" | "other";
183
+ model: string;
184
+ startedAt: string;
185
+ durationMs: number;
186
+ /** Until the first bytes of the answer. */
187
+ firstTokenMs: number | null;
188
+ /** null for a model with no list price known. */
189
+ costUsd: number | null;
190
+ stopReason: string | null;
191
+ /** The model API's HTTP status. */
192
+ status: number;
193
+ error: string | null;
194
+ toolCalls: {
195
+ id: string;
196
+ name: string;
197
+ }[];
198
+ };
199
+ /** One tool call: from the turn that asked for it to the request that
200
+ * carried its result back. */
201
+ export type AgentToolCall = {
202
+ seq: number;
203
+ kind: "tool";
204
+ id: string;
205
+ name: string;
206
+ turn: string | null;
207
+ startedAt: string;
208
+ durationMs: number;
209
+ /** The call's input and output, each at most 2,000 characters. */
210
+ input: string;
211
+ output: string;
212
+ error: boolean;
213
+ };
214
+ /** A page of a session's trace: the whole session's totals, by model and
215
+ * by tool, and up to `limit` spans after `after`. Read the next page with
216
+ * `after: nextAfter` until it is null. */
217
+ export type AgentTrace = {
218
+ sessionId: string;
219
+ totals: AgentTokens & {
220
+ turns: number;
221
+ toolCalls: number;
222
+ unpricedTurns: number;
223
+ failedTurns: number;
224
+ failedToolCalls: number;
225
+ modelMs: number;
226
+ toolMs: number;
227
+ };
228
+ models: (AgentTokens & {
229
+ model: string;
230
+ provider: string;
231
+ turns: number;
232
+ unpricedTurns: number;
233
+ })[];
234
+ tools: {
235
+ name: string;
236
+ calls: number;
237
+ failed: number;
238
+ durationMs: number;
239
+ }[];
240
+ spans: (AgentTurn | AgentToolCall)[];
241
+ /** The seq to read the next page after; null when the log held no more. */
242
+ nextAfter: number | null;
243
+ };
244
+ /** OTLP/JSON: an ExportTraceServiceRequest of one page, to POST to a
245
+ * collector's /v1/traces; the first page holds the session's root span. */
246
+ export type AgentTraceOtlp = {
247
+ resourceSpans: Record<string, unknown>[];
248
+ nextAfter: number | null;
249
+ };
250
+ /** Which page of a trace: spans after `after` (0 by default), at most
251
+ * `limit` (200 by default, 500 at most). */
252
+ export type AgentTracePage = {
253
+ after?: number;
254
+ limit?: number;
255
+ };
138
256
  export type AgentAskState = "open" | "answered" | "expired" | "withdrawn" | "closed";
139
257
  /** One row of the account's inbox: a question a session's harness needs
140
258
  * answered to go on. Asks of one agent's sessions sharing a memory, with the same `step` are
@@ -178,6 +296,20 @@ export type AgentAsk = {
178
296
  createdAt: string;
179
297
  updatedAt: string;
180
298
  closedAt: string | null;
299
+ /** The tool call it holds, answered Allow or Deny; null for any other ask. */
300
+ toolCall: AgentAskToolCall | null;
301
+ };
302
+ /** A tool call the agent's permissions hold for a person. */
303
+ export type AgentAskToolCall = {
304
+ /** The harness's name for it: Bash, apply_patch, mcp__github__create_issue. */
305
+ tool: string;
306
+ input: Record<string, unknown>;
307
+ toolUseId?: string;
308
+ /** Its tool_call event in the session's log. */
309
+ seq?: number;
310
+ policy: "always_ask" | "auto";
311
+ /** Why auto held it: indeterminate. */
312
+ reasonCode?: string;
181
313
  };
182
314
  export type ListAgentAsks = {
183
315
  /** Open by default. */
@@ -404,6 +536,13 @@ export type AgentSessionHandle = {
404
536
  signal?: AbortSignal;
405
537
  }): AsyncGenerator<AgentEvent>;
406
538
  stop(options?: RequestOptions): Promise<AgentSession>;
539
+ /** A page of its trace: every model turn and tool call, with timing,
540
+ * tokens and cost, and the session's totals; `{ format: "otlp" }` for
541
+ * OpenTelemetry traces. */
542
+ trace(options?: RequestOptions & AgentTracePage): Promise<AgentTrace>;
543
+ trace(options: RequestOptions & AgentTracePage & {
544
+ format: "otlp";
545
+ }): Promise<AgentTraceOtlp>;
407
546
  /** Until it has ended; answers it then. */
408
547
  wait(options?: {
409
548
  signal?: AbortSignal;
@@ -411,6 +550,13 @@ export type AgentSessionHandle = {
411
550
  get(options?: RequestOptions): Promise<AgentSession>;
412
551
  };
413
552
  export declare function agents(t: Transport): {
553
+ /** Claude Managed Agents' API on Runtime: the options Anthropic's SDK
554
+ * takes, so code written for it runs here unchanged:
555
+ * `new Anthropic(await runtime.agents.anthropic())`. */
556
+ anthropic: () => Promise<{
557
+ baseURL: string;
558
+ apiKey: string;
559
+ }>;
414
560
  /** An agent: a name and a definition its sessions start from. */
415
561
  create: (input: CreateAgent, options?: RequestOptions) => Promise<Agent>;
416
562
  /** By its id or its name. */
@@ -430,6 +576,15 @@ export declare function agents(t: Transport): {
430
576
  session(id: string, options?: RequestOptions): Promise<AgentSessionHandle>;
431
577
  sessions: {
432
578
  get: (id: string, options?: RequestOptions) => Promise<AgentSession>;
579
+ /** A session's trace: every model turn and tool call with its timing,
580
+ * tokens and cost, totals by model and tool; `{ format: "otlp" }` for
581
+ * OpenTelemetry traces in the GenAI semantic conventions. */
582
+ trace: {
583
+ (id: string, options?: RequestOptions & AgentTracePage): Promise<AgentTrace>;
584
+ (id: string, options: RequestOptions & AgentTracePage & {
585
+ format: "otlp";
586
+ }): Promise<AgentTraceOtlp>;
587
+ };
433
588
  /** Newest first; of one agent, or in some states. */
434
589
  list: (query?: {
435
590
  agent?: string;
@@ -451,6 +606,11 @@ export declare function agents(t: Transport): {
451
606
  /** Every session asking it reads the answer next, and wakes. An ask no
452
607
  * longer open is refused with `ask_closed`. */
453
608
  answer: (id: string, answer: AnswerAgentAsk, options?: RequestOptions) => Promise<AgentAsk>;
609
+ /** Lets a tool call the agent's permissions held run (its ask's Allow). */
610
+ approve: (id: string, options?: RequestOptions) => Promise<AgentAsk>;
611
+ /** Keeps a held tool call from running (its ask's Deny); `message` is
612
+ * told to the agent as the reason. */
613
+ deny: (id: string, message?: string, options?: RequestOptions) => Promise<AgentAsk>;
454
614
  };
455
615
  triggers: {
456
616
  create: (agent: string, input: CreateAgentTrigger, options?: RequestOptions) => Promise<AgentTrigger>;
@@ -133,6 +133,19 @@ const enc = encodeURIComponent;
133
133
  const ENDED = ["done", "failed", "stopped"];
134
134
  export function agents(t) {
135
135
  const getSession = (id, options) => t.json({ method: "GET", path: `/v1/agents/sessions/${enc(id)}`, ...options });
136
+ function trace(id, options = {}) {
137
+ const { format = "json", after, limit, ...rest } = options;
138
+ return t.json({
139
+ method: "GET",
140
+ path: `/v1/agents/sessions/${enc(id)}/trace`,
141
+ query: {
142
+ format,
143
+ ...(after !== undefined ? { after } : {}),
144
+ ...(limit !== undefined ? { limit } : {}),
145
+ },
146
+ ...rest,
147
+ });
148
+ }
136
149
  async function* events(id, options = {}) {
137
150
  let after = options.after ?? 0;
138
151
  for (;;) {
@@ -164,6 +177,7 @@ export function agents(t) {
164
177
  ...options,
165
178
  }),
166
179
  events: (options) => events(session.id, options),
180
+ trace: ((options) => trace(session.id, options)),
167
181
  stop: (options) => t.json({
168
182
  method: "POST",
169
183
  path: `/v1/agents/sessions/${enc(session.id)}/stop`,
@@ -235,6 +249,13 @@ export function agents(t) {
235
249
  query: { scope, path },
236
250
  });
237
251
  return {
252
+ /** Claude Managed Agents' API on Runtime: the options Anthropic's SDK
253
+ * takes, so code written for it runs here unchanged:
254
+ * `new Anthropic(await runtime.agents.anthropic())`. */
255
+ anthropic: async () => ({
256
+ baseURL: `${t.baseUrl}/anthropic`,
257
+ apiKey: await t.apiKey(),
258
+ }),
238
259
  /** An agent: a name and a definition its sessions start from. */
239
260
  create: (input, options) => t.json({ method: "POST", path: "/v1/agents", body: input, ...options }),
240
261
  /** By its id or its name. */
@@ -268,6 +289,10 @@ export function agents(t) {
268
289
  },
269
290
  sessions: {
270
291
  get: getSession,
292
+ /** A session's trace: every model turn and tool call with its timing,
293
+ * tokens and cost, totals by model and tool; `{ format: "otlp" }` for
294
+ * OpenTelemetry traces in the GenAI semantic conventions. */
295
+ trace,
271
296
  /** Newest first; of one agent, or in some states. */
272
297
  list: listSessions,
273
298
  /** An ended session and its log go. Its history is storage like any
@@ -295,6 +320,21 @@ export function agents(t) {
295
320
  body: answer,
296
321
  ...options,
297
322
  }),
323
+ /** Lets a tool call the agent's permissions held run (its ask's Allow). */
324
+ approve: (id, options) => t.json({
325
+ method: "POST",
326
+ path: `/v1/agents/asks/${enc(id)}/answer`,
327
+ body: { option: "Allow" },
328
+ ...options,
329
+ }),
330
+ /** Keeps a held tool call from running (its ask's Deny); `message` is
331
+ * told to the agent as the reason. */
332
+ deny: (id, message, options) => t.json({
333
+ method: "POST",
334
+ path: `/v1/agents/asks/${enc(id)}/answer`,
335
+ body: { option: "Deny", ...(message ? { text: message } : {}) },
336
+ ...options,
337
+ }),
298
338
  },
299
339
  triggers: {
300
340
  create: (agent, input, options) => t.json({
@@ -18,7 +18,7 @@ export type CiRepository = {
18
18
  repository: string;
19
19
  /** The branch whose pushes are checked as landed. */
20
20
  productionBranch: string;
21
- /** Where in the repository its checks are written. */
21
+ /** Where in the repository its checks are written: a `runtime.yml`, or a `cloudbuild.yaml` or `buildspec.yml`, run as Cloud Build or CodeBuild runs it. */
22
22
  configPath: string;
23
23
  /** The organization's installation of Runtime's GitHub App it is read through. */
24
24
  installation: number;
@@ -122,7 +122,14 @@ export type CiJob = {
122
122
  /** The sandboxes it ran in. A failure's may be kept paused: wake it, or
123
123
  * exec in it, with runtime.sandboxes. */
124
124
  sandboxIds: string[];
125
+ /** The ID of the job's own GitHub check run (`runtime / <name>`), created
126
+ * completed when the job ends; null while it runs, for a reused pass, or
127
+ * when GitHub did not accept the run. */
125
128
  githubCheckRun: number | null;
129
+ /** Lines of the repository's files that the job's log reports as failing,
130
+ * or as warnings and notices, as its GitHub check run shows them. At most
131
+ * 50, failures first. */
132
+ annotations: CiAnnotation[];
126
133
  /** A review step's verdict on the commit; null for a command's job. */
127
134
  review: CiReview | null;
128
135
  ms: number | null;
@@ -131,6 +138,17 @@ export type CiJob = {
131
138
  startedAt: number | null;
132
139
  endedAt: number | null;
133
140
  };
141
+ /** A line of a file that a job's log reports. */
142
+ export type CiAnnotation = {
143
+ path: string;
144
+ startLine: number;
145
+ endLine: number;
146
+ /** Present only for a single line. */
147
+ startColumn?: number;
148
+ level: "notice" | "warning" | "failure";
149
+ message: string;
150
+ title?: string;
151
+ };
134
152
  /** What one finding of a review is about. */
135
153
  export type CiReviewKind = "bug" | "missed-case" | "data-at-risk" | "money-at-risk" | "auth-bypass" | "privilege-escalation" | "secret-exposed" | "made-public" | "command-injection" | "manipulation" | "other";
136
154
  /** One thing a review found in the change. */
@@ -264,6 +264,78 @@ export declare function jobUpdateBody(input: UpdateJob): Record<string, unknown>
264
264
  * on this deployment."). This names the product, keeps the code, status and
265
265
  * request id, and says no retry will change it. */
266
266
  export declare function switchedOff(product: string): (error: unknown) => never;
267
+ /** Another platform's job files, read into Runtime jobs (`jobs.importPlan`). */
268
+ export type JobImportRequest = {
269
+ /** The files, each with its name: a Cloud Run job's YAML and the Cloud
270
+ * Scheduler job that runs it, or an AWS Batch job definition (API JSON,
271
+ * describe-job-definitions output or a CloudFormation template) and the
272
+ * EventBridge schedule or rule that submits it. At most 1 MiB in all. */
273
+ files: {
274
+ path: string;
275
+ text: string;
276
+ }[];
277
+ /** Read them as this platform's; detected from the files when omitted. */
278
+ from?: "cloud-run" | "aws-batch";
279
+ /** A CloudFormation template's parameters and pseudo parameters, such as
280
+ * `{ "AWS::Region": "us-east-1" }`. */
281
+ parameters?: Record<string, string>;
282
+ };
283
+ export type JobImportSchedule = {
284
+ kind: "cron";
285
+ expression: string;
286
+ timezone: string;
287
+ } | {
288
+ kind: "once";
289
+ at: string;
290
+ timezone: string;
291
+ };
292
+ /** One job of a plan. Its image is built from `dockerfile`, and it runs the
293
+ * built image's start command. */
294
+ export type JobImportJob = {
295
+ name: string;
296
+ file: string;
297
+ /** The container image it ran on the other platform. */
298
+ sourceImage: string;
299
+ dockerfile: string;
300
+ /** The whole command when the file names it; null when part of it is the
301
+ * container image's own ENTRYPOINT or CMD. */
302
+ command: string[] | null;
303
+ env: Record<string, string>;
304
+ /** Values it read from a secret store; each is bound from the jobs secret
305
+ * of that name. */
306
+ secrets: {
307
+ name: string;
308
+ from: string;
309
+ }[];
310
+ compute: {
311
+ vcpu: number;
312
+ memoryMib: number;
313
+ diskMib: number | null;
314
+ };
315
+ timeoutSeconds: number;
316
+ retry: {
317
+ maxAttempts: number;
318
+ backoffSeconds: number;
319
+ };
320
+ /** Null: no schedule ran it there; it runs when triggered. */
321
+ schedule: JobImportSchedule | null;
322
+ /** Why it cannot be created as planned; null when it can. */
323
+ blocked: string | null;
324
+ };
325
+ export type JobImportPlan = {
326
+ from: "cloud-run" | "aws-batch";
327
+ read: string[];
328
+ jobs: JobImportJob[];
329
+ /** unmapped: left out. changed: carried over differently. info: how. */
330
+ notes: {
331
+ level: "unmapped" | "changed" | "info";
332
+ file: string;
333
+ key: string;
334
+ job?: string;
335
+ message: string;
336
+ }[];
337
+ importable: boolean;
338
+ };
267
339
  /** Scheduled jobs: a command run in a fresh sandbox, once or on a cron
268
340
  * schedule. Each run is a sandbox, paid for as one: from the free usage first while the run fits the limits without credit, then from credit
269
341
  * at the sandbox rates, through the same holds and spending limits.
@@ -287,6 +359,11 @@ export declare function jobs(transport: Transport): {
287
359
  limit?: number;
288
360
  cursor?: string;
289
361
  }, options?: RequestOptions) => Promise<Page<Job>>;
362
+ /** Read a Cloud Run job or an AWS Batch job definition, with its
363
+ * schedule, into the jobs that run the same container here, and what
364
+ * could not be carried over. Changes nothing; `runtime jobs import`
365
+ * builds and creates the plan. */
366
+ importPlan: (input: JobImportRequest, options?: RequestOptions) => Promise<JobImportPlan>;
290
367
  get: (id: string, options?: RequestOptions) => Promise<Job>;
291
368
  /** A job's runs, oldest first: each attempt of each occurrence.
292
369
  * `{ order: "newest" }`: newest first, so the last run is one call.
@@ -198,6 +198,11 @@ export function jobs(transport) {
198
198
  create: (input, options) => t.json({ method: "POST", path: "/v1/jobs", body: jobBody(input), ...options }),
199
199
  /** Your jobs, oldest first. Await for a page, or `for await` for all. */
200
200
  list,
201
+ /** Read a Cloud Run job or an AWS Batch job definition, with its
202
+ * schedule, into the jobs that run the same container here, and what
203
+ * could not be carried over. Changes nothing; `runtime jobs import`
204
+ * builds and creates the plan. */
205
+ importPlan: (input, options) => t.json({ method: "POST", path: "/v1/job-imports", body: input, ...options }),
201
206
  get: (id, options) => t.json({ method: "GET", path: `/v1/jobs/${enc(id)}`, ...options }),
202
207
  /** A job's runs, oldest first: each attempt of each occurrence.
203
208
  * `{ order: "newest" }`: newest first, so the last run is one call.
@@ -1,5 +1,5 @@
1
1
  import { RuntimeError } from "./errors.js";
2
- export declare const VERSION = "0.35.0";
2
+ export declare const VERSION = "0.37.0";
3
3
  export declare const DEFAULT_BASE_URL = "https://api.withruntime.com";
4
4
  /** Runtime's API as code inside a Runtime sandbox reaches it: the sandbox's
5
5
  * own host sends each request on to DEFAULT_BASE_URL over HTTPS. The API runs
@@ -141,6 +141,10 @@ export declare class Transport {
141
141
  fileStream(call: Call): Promise<ReadableStream<Uint8Array>>;
142
142
  /** Newline-delimited JSON events, as they arrive. */
143
143
  events<T>(call: Call): AsyncGenerator<T>;
144
+ /** The key calls are made with: the one given, RUNTIME_API_KEY, or the
145
+ * connection `runtime login` saved. For another platform's SDK pointed at
146
+ * Runtime (`runtime.agents.anthropic()`). */
147
+ apiKey(): Promise<string>;
144
148
  /** A WebSocket to an API path, authenticated with the same key. */
145
149
  websocket(path: string, query?: Query): Promise<WebSocket>;
146
150
  }
package/dist/transport.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ConnectionError, DELIBERATE, errorFor, NOTHING_RAN, RuntimeError, WAITS_FOR_ROOM, } from "./errors.js";
2
2
  import { describeRoute, envFetch, openWebSocket, untrustedCertificate } from "./proxy.js";
3
3
  import { warningText } from "./product-renames.js";
4
- export const VERSION = "0.35.0";
4
+ export const VERSION = "0.37.0";
5
5
  export const DEFAULT_BASE_URL = "https://api.withruntime.com";
6
6
  /** Runtime's API as code inside a Runtime sandbox reaches it: the sandbox's
7
7
  * own host sends each request on to DEFAULT_BASE_URL over HTTPS. The API runs
@@ -723,6 +723,12 @@ export class Transport {
723
723
  release();
724
724
  }
725
725
  }
726
+ /** The key calls are made with: the one given, RUNTIME_API_KEY, or the
727
+ * connection `runtime login` saved. For another platform's SDK pointed at
728
+ * Runtime (`runtime.agents.anthropic()`). */
729
+ async apiKey() {
730
+ return this.#key();
731
+ }
726
732
  /** A WebSocket to an API path, authenticated with the same key. */
727
733
  async websocket(path, query) {
728
734
  const apiKey = await this.#key();
@@ -0,0 +1,202 @@
1
+ export declare class AbortTaskRunError extends Error {
2
+ }
3
+ export declare class CompatibilityError extends Error {
4
+ readonly code = "not_supported";
5
+ }
6
+ /** Trigger.dev's machine presets as vCPU and MiB: a job's sandbox is at
7
+ * least 1 vCPU and 128 MiB, so the smaller ones round up to it. */
8
+ export declare const MACHINES: Record<string, {
9
+ vcpu: number;
10
+ memoryMiB: number;
11
+ }>;
12
+ /** Month and day names as the numbers Runtime's cron takes. */
13
+ export declare function numericCron(cron: string): string;
14
+ type Machine = keyof typeof MACHINES | {
15
+ preset?: keyof typeof MACHINES;
16
+ };
17
+ type Retry = {
18
+ maxAttempts?: number;
19
+ [key: string]: unknown;
20
+ };
21
+ export type Context = {
22
+ task: {
23
+ id: string;
24
+ filePath: string;
25
+ };
26
+ run: {
27
+ id: string;
28
+ tags: string[];
29
+ isTest: boolean;
30
+ createdAt: Date;
31
+ startedAt: Date;
32
+ };
33
+ attempt: {
34
+ number: number;
35
+ startedAt: Date;
36
+ };
37
+ environment: {
38
+ type: "PRODUCTION";
39
+ slug: "prod";
40
+ };
41
+ machine: {
42
+ name: string;
43
+ cpu: number;
44
+ memory: number;
45
+ };
46
+ project: {
47
+ ref: string;
48
+ };
49
+ };
50
+ type RunParams = {
51
+ ctx: Context;
52
+ signal: AbortSignal;
53
+ init?: unknown;
54
+ };
55
+ type TaskOptions<P, O> = {
56
+ id: string;
57
+ run: (payload: P, params: RunParams) => Promise<O> | O;
58
+ machine?: Machine;
59
+ maxDuration?: number;
60
+ retry?: Retry;
61
+ queue?: {
62
+ name?: string;
63
+ concurrencyLimit?: number;
64
+ };
65
+ description?: string;
66
+ init?: (payload: P, params: RunParams) => unknown;
67
+ cleanup?: (payload: P, params: RunParams) => unknown;
68
+ onStart?: (payload: P, params: RunParams) => unknown;
69
+ onSuccess?: (payload: P, output: O, params: RunParams) => unknown;
70
+ onFailure?: (payload: P, error: unknown, params: RunParams) => unknown;
71
+ onComplete?: (payload: P, result: unknown, params: RunParams) => unknown;
72
+ [hook: string]: unknown;
73
+ };
74
+ export type ScheduledTaskPayload = {
75
+ timestamp: Date;
76
+ lastTimestamp: Date | undefined;
77
+ timezone: string;
78
+ scheduleId: string;
79
+ externalId: string | undefined;
80
+ upcoming: Date[];
81
+ };
82
+ type Cron = string | {
83
+ pattern: string;
84
+ timezone?: string;
85
+ environments?: string[];
86
+ };
87
+ export type Task<P = unknown, O = unknown> = {
88
+ id: string;
89
+ trigger(payload?: P): Promise<{
90
+ id: string;
91
+ }>;
92
+ triggerAndWait(payload?: P): never;
93
+ batchTrigger(items: unknown[]): never;
94
+ batchTriggerAndWait(items: unknown[]): never;
95
+ /** For tests: the task's run function. */
96
+ run(payload: P, params: RunParams): Promise<O> | O;
97
+ };
98
+ /** A task run on demand: `tasks.trigger(id, payload)` runs it once. */
99
+ export declare function task<P = unknown, O = unknown>(options: TaskOptions<P, O>): Task<P, O>;
100
+ export declare const schemaTask: <P = unknown, O = unknown>(options: TaskOptions<P, O> & {
101
+ schema?: {
102
+ parse?: (v: unknown) => P;
103
+ };
104
+ }) => Task<P, O>;
105
+ export declare const schedules: {
106
+ /** A task on a cron: a Runtime job with that schedule. */
107
+ task<O = unknown>(options: TaskOptions<ScheduledTaskPayload, O> & {
108
+ cron?: Cron;
109
+ }): Task<ScheduledTaskPayload, O>;
110
+ create: () => never;
111
+ update: () => never;
112
+ del: () => never;
113
+ deactivate: () => never;
114
+ activate: () => never;
115
+ list: () => never;
116
+ retrieve: () => never;
117
+ };
118
+ /** The job `runtime jobs deploy` made for task `id`. A backend calling
119
+ * tasks.trigger, or a task triggering another in its run, has usually not
120
+ * loaded trigger.config.ts, so it may not know the project's name: the job
121
+ * is found by what it runs (`run <file> trigger <id>`, the deploy's
122
+ * command), and the project's name only picks between projects that both
123
+ * have a task with this id. */
124
+ export declare function taskJob<J extends {
125
+ name: string;
126
+ state: string;
127
+ definition: {
128
+ command: {
129
+ argv: string[];
130
+ };
131
+ };
132
+ }>(id: string, jobs: J[]): J;
133
+ export declare const tasks: {
134
+ /** Runs the task once now, in a fresh sandbox of its image, with this
135
+ * payload (at most 64 KiB as JSON). Needs RUNTIME_API_KEY where it is
136
+ * called, and the task deployed with `runtime jobs deploy`. */
137
+ trigger(id: string, payload?: unknown): Promise<{
138
+ id: string;
139
+ }>;
140
+ triggerAndWait: () => never;
141
+ batchTrigger: () => never;
142
+ };
143
+ type Attributes = Record<string, unknown>;
144
+ export declare const logger: {
145
+ debug: (message: string, attributes?: Attributes) => void;
146
+ log: (message: string, attributes?: Attributes) => void;
147
+ info: (message: string, attributes?: Attributes) => void;
148
+ warn: (message: string, attributes?: Attributes) => void;
149
+ error: (message: string, attributes?: Attributes) => void;
150
+ trace: <T>(_name: string, fn: (span: unknown) => Promise<T>) => Promise<T>;
151
+ };
152
+ type Duration = {
153
+ seconds?: number;
154
+ minutes?: number;
155
+ hours?: number;
156
+ days?: number;
157
+ };
158
+ /** Waits in the run, which counts toward its maxDuration. */
159
+ export declare const wait: {
160
+ for: (d: Duration) => Promise<void>;
161
+ until: ({ date }: {
162
+ date: Date;
163
+ }) => Promise<void>;
164
+ forToken: () => never;
165
+ createToken: () => never;
166
+ };
167
+ /** trigger.config.ts's defineConfig: its `project` names the jobs. */
168
+ export declare function defineConfig<T extends {
169
+ project?: string;
170
+ dirs?: string[];
171
+ maxDuration?: number;
172
+ machine?: string;
173
+ retries?: {
174
+ default?: {
175
+ maxAttempts?: number;
176
+ };
177
+ };
178
+ }>(config: T): T;
179
+ export declare const configure: () => undefined;
180
+ export declare const auth: {
181
+ configure: () => undefined;
182
+ withAuth: <T>(_a: unknown, fn: () => T) => T;
183
+ };
184
+ export declare const metadata: {
185
+ set: () => /*elided*/ any;
186
+ get: () => undefined;
187
+ current: () => {};
188
+ flush: () => Promise<undefined>;
189
+ };
190
+ export declare const runs: {
191
+ retrieve: () => never;
192
+ list: () => never;
193
+ cancel: () => never;
194
+ };
195
+ export declare const queue: (options: {
196
+ name: string;
197
+ concurrencyLimit?: number;
198
+ }) => {
199
+ name: string;
200
+ concurrencyLimit?: number;
201
+ };
202
+ export {};