withruntime 0.35.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/BLAXEL.md +207 -204
- package/COMPATIBILITY.md +367 -337
- package/DAYTONA.md +180 -173
- package/E2B.md +246 -230
- package/README.md +182 -142
- package/README.src.md +182 -142
- package/VERCEL.md +173 -168
- package/agent-platforms-inventory.json +387 -0
- package/dist/agents-cli.d.ts +7 -1
- package/dist/agents-cli.js +470 -6
- package/dist/agents-deploy.d.ts +1 -1
- package/dist/agents-deploy.js +62 -1
- package/dist/apps-cli.d.ts +3 -3
- package/dist/apps-cli.js +10 -5
- package/dist/browsers-cli.d.ts +1 -1
- package/dist/browsers-cli.js +122 -3
- package/dist/ci-cli.d.ts +11 -1
- package/dist/ci-cli.js +69 -6
- package/dist/cli-update.d.ts +11 -0
- package/dist/cli-update.js +46 -0
- package/dist/cli-words.js +1 -0
- package/dist/cli.d.ts +4 -6
- package/dist/cli.js +249 -58
- package/dist/daytona/daytona.js +1 -1
- package/dist/e2b/sandbox.d.ts +6 -5
- package/dist/e2b/sandbox.js +6 -5
- package/dist/errors.d.ts +4 -3
- package/dist/errors.js +7 -3
- package/dist/index.d.ts +5 -5
- package/dist/inngest/index.d.ts +96 -0
- package/dist/inngest/index.js +183 -0
- package/dist/jobs-code/cron.d.ts +12 -0
- package/dist/jobs-code/cron.js +93 -0
- package/dist/jobs-code/registry.d.ts +31 -0
- package/dist/jobs-code/registry.js +30 -0
- package/dist/jobs-code/runner.d.ts +1 -0
- package/dist/jobs-code/runner.js +74 -0
- package/dist/jobs-deploy.d.ts +22 -0
- package/dist/jobs-deploy.js +247 -0
- package/dist/jobs-import.d.ts +15 -0
- package/dist/jobs-import.js +231 -0
- package/dist/products/agents.d.ts +413 -2
- package/dist/products/agents.js +176 -0
- package/dist/products/apps.d.ts +2 -1
- package/dist/products/browsers.d.ts +87 -0
- package/dist/products/browsers.js +67 -0
- package/dist/products/builds.d.ts +11 -2
- package/dist/products/ci.d.ts +21 -1
- package/dist/products/jobs.d.ts +77 -0
- package/dist/products/jobs.js +5 -0
- package/dist/products/observability.d.ts +31 -3
- package/dist/products/plans.d.ts +5 -3
- package/dist/products/secrets.d.ts +67 -14
- package/dist/products/secrets.js +41 -12
- package/dist/transport.d.ts +6 -1
- package/dist/transport.js +38 -1
- package/dist/trigger/index.d.ts +202 -0
- package/dist/trigger/index.js +244 -0
- package/dist/types.d.ts +14 -0
- package/package.json +14 -3
|
@@ -20,6 +20,21 @@ export type MetricPoint = {
|
|
|
20
20
|
memoryPeakBytes: number;
|
|
21
21
|
/** Host readings in the bucket. */
|
|
22
22
|
samples: number;
|
|
23
|
+
/** Average bytes used on the root file system, as `df /` in the sandbox
|
|
24
|
+
* reports; null where no reading carries it. Older servers omit it. */
|
|
25
|
+
diskUsedBytes?: number | null;
|
|
26
|
+
/** Bytes read from and written to the sandbox's disks per second, as its
|
|
27
|
+
* kernel counts them; null where unmeasured. */
|
|
28
|
+
diskReadBytesPerSecond?: number | null;
|
|
29
|
+
diskWriteBytesPerSecond?: number | null;
|
|
30
|
+
/** Read and write operations completed per second. */
|
|
31
|
+
diskReadOpsPerSecond?: number | null;
|
|
32
|
+
diskWriteOpsPerSecond?: number | null;
|
|
33
|
+
/** Bytes received and sent per second over the network: what came back on
|
|
34
|
+
* the sandbox's connections, and what it sent on them and served through
|
|
35
|
+
* preview links, custom domains and TCP ports. */
|
|
36
|
+
networkReceivedBytesPerSecond?: number | null;
|
|
37
|
+
networkSentBytesPerSecond?: number | null;
|
|
23
38
|
};
|
|
24
39
|
export type SandboxMetrics = {
|
|
25
40
|
sandboxId: string;
|
|
@@ -86,7 +101,7 @@ export type OtelExport = {
|
|
|
86
101
|
endpoint: string;
|
|
87
102
|
/** Header names only; values are never shown back. */
|
|
88
103
|
headerNames: string[];
|
|
89
|
-
signals:
|
|
104
|
+
signals: OtelSignal[];
|
|
90
105
|
enabled: boolean;
|
|
91
106
|
createdAt: string;
|
|
92
107
|
updatedAt: string;
|
|
@@ -96,7 +111,20 @@ export type OtelExport = {
|
|
|
96
111
|
failures: number;
|
|
97
112
|
exportedEvents: number;
|
|
98
113
|
exportedPoints: number;
|
|
114
|
+
/** Spans that arrived at the endpoint ("traces"). */
|
|
115
|
+
exportedSpans?: number;
|
|
116
|
+
/** The span pushes' own health. `lastAttemptAt`, `lastSuccessAt`,
|
|
117
|
+
* `lastError` and `failures` describe logs and metrics only. */
|
|
118
|
+
tracesLastAttemptAt?: string | null;
|
|
119
|
+
tracesLastSuccessAt?: string | null;
|
|
120
|
+
tracesLastError?: string | null;
|
|
121
|
+
tracesFailures?: number;
|
|
99
122
|
};
|
|
123
|
+
/** "logs": events as log records. "metrics": CPU, memory, disk and network.
|
|
124
|
+
* "traces": a span for every API call, a child of the caller's span when the
|
|
125
|
+
* call carried a W3C traceparent (the SDK sends the active OpenTelemetry
|
|
126
|
+
* context's). */
|
|
127
|
+
export type OtelSignal = "logs" | "metrics" | "traces";
|
|
100
128
|
type List<T> = {
|
|
101
129
|
data: T[];
|
|
102
130
|
nextCursor: string | null;
|
|
@@ -199,14 +227,14 @@ export declare function otel(t: Transport): {
|
|
|
199
227
|
endpoint: string;
|
|
200
228
|
/** For the endpoint's authentication; never shown back. */
|
|
201
229
|
headers?: Record<string, string>;
|
|
202
|
-
signals?:
|
|
230
|
+
signals?: OtelSignal[];
|
|
203
231
|
}, options?: RequestOptions) => Promise<OtelExport>;
|
|
204
232
|
list: (options?: RequestOptions) => Promise<List<OtelExport>>;
|
|
205
233
|
get: (id: string, options?: RequestOptions) => Promise<OtelExport>;
|
|
206
234
|
update: (id: string, patch: {
|
|
207
235
|
endpoint?: string;
|
|
208
236
|
headers?: Record<string, string>;
|
|
209
|
-
signals?:
|
|
237
|
+
signals?: OtelSignal[];
|
|
210
238
|
enabled?: boolean;
|
|
211
239
|
}, options?: RequestOptions) => Promise<OtelExport>;
|
|
212
240
|
/** Push now instead of at the next interval. */
|
package/dist/products/plans.d.ts
CHANGED
|
@@ -45,7 +45,8 @@ export type Plan = {
|
|
|
45
45
|
yearlyFeeMicros: string | null;
|
|
46
46
|
/** Usage given on top of the fee each month. */
|
|
47
47
|
bonusMicros: string;
|
|
48
|
-
/** Days of trial
|
|
48
|
+
/** Days of trial; 0 for none. A trial saves a card and charges the
|
|
49
|
+
* first period when it ends, unless cancelled before. */
|
|
49
50
|
trialDays: number;
|
|
50
51
|
/** The first month on the plan, and the first after an upgrade to it,
|
|
51
52
|
* holds twice its usage. */
|
|
@@ -70,13 +71,14 @@ export type PlanNow = {
|
|
|
70
71
|
planId: string;
|
|
71
72
|
name: string;
|
|
72
73
|
/** incomplete: the first payment is not through yet. trialing: a trial,
|
|
73
|
-
* until trialEndsAt
|
|
74
|
+
* until trialEndsAt, when the saved card is charged the first period
|
|
75
|
+
* unless cancelAtPeriodEnd. past_due: a payment failed and is retried. */
|
|
74
76
|
status: "incomplete" | "trialing" | "active" | "past_due" | "canceled";
|
|
75
77
|
interval: "month" | "year";
|
|
76
78
|
periodStart: string | null;
|
|
77
79
|
/** The next fee, or the end of a cancelled plan. */
|
|
78
80
|
periodEnd: string | null;
|
|
79
|
-
/** When a trial ends; null outside one. */
|
|
81
|
+
/** When a trial ends and its first period is charged; null outside one. */
|
|
80
82
|
trialEndsAt: string | null;
|
|
81
83
|
/** True once a cancel takes effect at periodEnd. */
|
|
82
84
|
cancelAtPeriodEnd: boolean;
|
|
@@ -83,17 +83,28 @@ export type SecretApiPolicy = {
|
|
|
83
83
|
mutations: string[];
|
|
84
84
|
};
|
|
85
85
|
};
|
|
86
|
-
/** A secret
|
|
86
|
+
/** A secret, of one of two kinds. The placeholder kind (`exposed: false`):
|
|
87
|
+
* your sandboxes use it without seeing it. Every sandbox of your
|
|
87
88
|
* organization has an environment variable of the secret's name (or `env`)
|
|
88
89
|
* holding `placeholder`; the egress proxy sets `header` on every HTTPS request to
|
|
89
90
|
* `hosts`, or, without `header`, replaces the placeholder in a credential
|
|
90
91
|
* header (Authorization, x-api-key, x-goog-api-key, api-key, xi-api-key,
|
|
91
92
|
* x-subscription-token, private-token). Never in the URL or another header.
|
|
92
|
-
* The value
|
|
93
|
+
* The real-value kind (`exposed: true`): the sandboxes and Apps its `only`
|
|
94
|
+
* names by id get the value itself in the variable, for a database password
|
|
95
|
+
* or an SSH key; it has no hosts. Either way, the value is never returned. */
|
|
93
96
|
export type Secret = {
|
|
94
97
|
name: string;
|
|
95
|
-
/** The environment variable the placeholder is in, when not `name`. */
|
|
98
|
+
/** The environment variable the placeholder or value is in, when not `name`. */
|
|
96
99
|
env?: string;
|
|
100
|
+
/** true: the machines it reaches get the value itself in the variable.
|
|
101
|
+
* false: they see `placeholder`, which the proxy swaps on HTTPS to `hosts`. */
|
|
102
|
+
exposed: boolean;
|
|
103
|
+
/** 1 when stored, one more each time the secret changes: its value, who
|
|
104
|
+
* gets it, its hosts, rules or variable. Pass it as `expectedVersion` to
|
|
105
|
+
* write only if no one else has changed it since. */
|
|
106
|
+
version: number;
|
|
107
|
+
/** Empty for a real-value secret. */
|
|
97
108
|
hosts: string[];
|
|
98
109
|
header?: string;
|
|
99
110
|
format?: string;
|
|
@@ -103,18 +114,25 @@ export type Secret = {
|
|
|
103
114
|
githubApp?: SecretGithubApp;
|
|
104
115
|
git?: SecretGit;
|
|
105
116
|
api?: SecretApiPolicy;
|
|
117
|
+
/** What the variable holds. For a real-value secret, the server running a
|
|
118
|
+
* machine replaces it with the value wherever it stands in an environment
|
|
119
|
+
* variable given to that machine (a command's env, a deploy's), so
|
|
120
|
+
* `DATABASE_URL=postgres://app:<placeholder>@db/app` works. */
|
|
106
121
|
placeholder: string;
|
|
107
122
|
valueBytes: number;
|
|
108
123
|
createdAt: string;
|
|
109
124
|
updatedAt: string;
|
|
110
125
|
};
|
|
111
126
|
export type SetSecret = {
|
|
112
|
-
/** Visible ASCII and spaces, at most 8 KiB for sandboxes
|
|
113
|
-
*
|
|
127
|
+
/** Visible ASCII and spaces, one line, at most 8 KiB for sandboxes. With
|
|
128
|
+
* `exposed`: any UTF-8 text without NUL of at most 64 KiB, several lines
|
|
129
|
+
* included (a PEM key, a service account's JSON), sent as it is. 64 KiB of
|
|
130
|
+
* UTF-8 for a jobs-only secret. Stored sealed; the sandboxes' copy is never
|
|
114
131
|
* returned. */
|
|
115
132
|
value: string;
|
|
116
133
|
/** Where the value may go: `api.openai.com`, `*.github.com`. 1 to 16.
|
|
117
|
-
* Required unless `jobs` is true
|
|
134
|
+
* Required unless `exposed` or `jobs` is true; a real-value secret takes
|
|
135
|
+
* none. */
|
|
118
136
|
hosts?: string[];
|
|
119
137
|
/** Set this header on every request to the hosts, replacing the sandbox's
|
|
120
138
|
* own; the value then goes nowhere else. Needed when the API reads its key
|
|
@@ -146,6 +164,30 @@ export type SetSecret = {
|
|
|
146
164
|
* secret's own name gives the name back. Absent when replacing a secret:
|
|
147
165
|
* the variable it has stays. */
|
|
148
166
|
env?: string;
|
|
167
|
+
/** Give the machines the value itself in the variable (`env`, or the
|
|
168
|
+
* secret's name) instead of a placeholder: for a database password, an SSH
|
|
169
|
+
* or signing key, anything that is not an HTTPS header. It then takes no
|
|
170
|
+
* `hosts`, `header`, `format`, `rules`, `githubApp`, `git` or `api`. It
|
|
171
|
+
* needs `only` naming the sandboxes or Apps that get it by id
|
|
172
|
+
* (`only.sandboxes`, `only.apps`), never labels or every sandbox, since code
|
|
173
|
+
* in them can read it; a replacement may leave `only` out to keep the scope
|
|
174
|
+
* it has. Which machines get it changes only with the value: `scope` is
|
|
175
|
+
* refused for it, so store it again. `env` works as for any secret. An
|
|
176
|
+
* organization's real-value secrets
|
|
177
|
+
* hold at most 64 KiB together. The value is still sealed and opened only on
|
|
178
|
+
* the server running the machine, but code in the machine can read it and
|
|
179
|
+
* send it anywhere, and it is in the machine's memory, so in its snapshots,
|
|
180
|
+
* forks and an App's saved server image. Prefer the placeholder kind for
|
|
181
|
+
* HTTPS APIs. Not kept: give it on every write of such a secret. A command
|
|
182
|
+
* in a machine it reaches may fail with 503 `secret_withheld` while the
|
|
183
|
+
* server cannot give the value right now; nothing ran, and the same call
|
|
184
|
+
* a few seconds later may work (`error.retryable`). */
|
|
185
|
+
exposed?: boolean;
|
|
186
|
+
/** Write only if the sandboxes' copy is at this version (0: it must not
|
|
187
|
+
* exist yet). At another, nothing is written and the call fails with 409
|
|
188
|
+
* `version_conflict`, `details.version` the current one. Read it with
|
|
189
|
+
* `get(name)`. */
|
|
190
|
+
expectedVersion?: number;
|
|
149
191
|
/** Also keep a copy for scheduled jobs, which a job puts into its run's
|
|
150
192
|
* environment (`jobs.create({ secrets: [...] })`). Unlike the sandboxes'
|
|
151
193
|
* copy, the jobs copy is yours rather than the account's, versioned, and can
|
|
@@ -190,14 +232,20 @@ export declare class SecretPartlyStoredError extends RuntimeError {
|
|
|
190
232
|
export declare function secrets(t: Transport): {
|
|
191
233
|
/** Store or replace a secret. With `hosts`, sandboxes see a placeholder
|
|
192
234
|
* and the egress proxy puts the value into HTTPS requests to them
|
|
193
|
-
* (replacing keeps the placeholder). With `
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
235
|
+
* (replacing keeps the placeholder). With `exposed: true`, no hosts and
|
|
236
|
+
* `only` naming sandboxes or Apps by id, those machines get the value
|
|
237
|
+
* itself. Each new value raises the
|
|
238
|
+
* sandboxes' copy's version; `expectedVersion` writes only over that
|
|
239
|
+
* one. With `jobs: true`, a copy scheduled jobs can put into their
|
|
240
|
+
* environment; setting it again rotates it. Both at once store both; if
|
|
241
|
+
* only the first lands, `SecretPartlyStoredError` says so and the same
|
|
242
|
+
* call again finishes it. */
|
|
197
243
|
set: {
|
|
198
|
-
(name: string, input: SetSecret & {
|
|
244
|
+
(name: string, input: SetSecret & ({
|
|
199
245
|
hosts: string[];
|
|
200
|
-
}
|
|
246
|
+
} | {
|
|
247
|
+
exposed: true;
|
|
248
|
+
}), options?: RequestOptions): Promise<Secret & {
|
|
201
249
|
enforced: boolean;
|
|
202
250
|
jobs?: JobSecret;
|
|
203
251
|
}>;
|
|
@@ -211,7 +259,9 @@ export declare function secrets(t: Transport): {
|
|
|
211
259
|
}>>;
|
|
212
260
|
};
|
|
213
261
|
/** Changes which sandboxes get a secret, without its value: `{}` is every
|
|
214
|
-
* sandbox of the organization again.
|
|
262
|
+
* sandbox of the organization again. Refused (400) for a real-value secret
|
|
263
|
+
* (`exposed`), whose machines change only with its value: `set` it again
|
|
264
|
+
* with `value`, `exposed` and `only`. */
|
|
215
265
|
scope: (name: string, only: SecretScope, options?: RequestOptions) => Promise<Secret & {
|
|
216
266
|
enforced: boolean;
|
|
217
267
|
}>;
|
|
@@ -231,7 +281,10 @@ export declare function secrets(t: Transport): {
|
|
|
231
281
|
list: (query?: ListSecrets & RequestOptions) => Promise<Secret[]>;
|
|
232
282
|
/** Every secret by name, with where its value may go. */
|
|
233
283
|
all: (options?: RequestOptions) => Promise<SecretUse[]>;
|
|
234
|
-
/** One secret by name, with where its value may go
|
|
284
|
+
/** One secret by name, with where its value may go: `sandboxes` (its
|
|
285
|
+
* kind, `version`, variable, hosts and placeholder, from
|
|
286
|
+
* `GET /v1/egress-secrets/{name}`) and `jobs`, each null when it has no
|
|
287
|
+
* such copy. Never the value. */
|
|
235
288
|
get: (name: string, options?: RequestOptions) => Promise<SecretUse>;
|
|
236
289
|
/** Replace the jobs copy's value with a new version. Runs already bound to
|
|
237
290
|
* the old version are refused it. Only the jobs copy has versions; to
|
package/dist/products/secrets.js
CHANGED
|
@@ -134,15 +134,24 @@ export function secrets(t) {
|
|
|
134
134
|
}
|
|
135
135
|
async function set(name, input, options) {
|
|
136
136
|
const { jobs, value, ...egress } = input;
|
|
137
|
-
|
|
137
|
+
// The sandboxes' copy: through the proxy to hosts, or the value itself.
|
|
138
|
+
const forSandboxes = !!egress.hosts?.length || egress.exposed === true;
|
|
139
|
+
if (!forSandboxes && !jobs)
|
|
138
140
|
throw new RuntimeError({
|
|
139
|
-
message: "Say where the value may go: hosts for sandboxes, jobs: true for scheduled jobs
|
|
141
|
+
message: "Say where the value may go: hosts for sandboxes through the proxy, exposed: true to give the machines the value itself, jobs: true for scheduled jobs.",
|
|
140
142
|
code: "invalid_request",
|
|
141
143
|
status: 0,
|
|
142
144
|
details: { field: "hosts" },
|
|
143
145
|
});
|
|
146
|
+
if (!forSandboxes && egress.expectedVersion !== undefined)
|
|
147
|
+
throw new RuntimeError({
|
|
148
|
+
message: "expectedVersion is the version of the sandboxes' copy, and this call stores only the jobs copy.",
|
|
149
|
+
code: "invalid_request",
|
|
150
|
+
status: 0,
|
|
151
|
+
details: { field: "expectedVersion" },
|
|
152
|
+
});
|
|
144
153
|
let sandboxes;
|
|
145
|
-
if (
|
|
154
|
+
if (forSandboxes)
|
|
146
155
|
sandboxes = await t.json({
|
|
147
156
|
method: "PUT",
|
|
148
157
|
path: path(name),
|
|
@@ -173,13 +182,19 @@ export function secrets(t) {
|
|
|
173
182
|
return {
|
|
174
183
|
/** Store or replace a secret. With `hosts`, sandboxes see a placeholder
|
|
175
184
|
* and the egress proxy puts the value into HTTPS requests to them
|
|
176
|
-
* (replacing keeps the placeholder). With `
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
185
|
+
* (replacing keeps the placeholder). With `exposed: true`, no hosts and
|
|
186
|
+
* `only` naming sandboxes or Apps by id, those machines get the value
|
|
187
|
+
* itself. Each new value raises the
|
|
188
|
+
* sandboxes' copy's version; `expectedVersion` writes only over that
|
|
189
|
+
* one. With `jobs: true`, a copy scheduled jobs can put into their
|
|
190
|
+
* environment; setting it again rotates it. Both at once store both; if
|
|
191
|
+
* only the first lands, `SecretPartlyStoredError` says so and the same
|
|
192
|
+
* call again finishes it. */
|
|
180
193
|
set,
|
|
181
194
|
/** Changes which sandboxes get a secret, without its value: `{}` is every
|
|
182
|
-
* sandbox of the organization again.
|
|
195
|
+
* sandbox of the organization again. Refused (400) for a real-value secret
|
|
196
|
+
* (`exposed`), whose machines change only with its value: `set` it again
|
|
197
|
+
* with `value`, `exposed` and `only`. */
|
|
183
198
|
scope: (name, only, options) => t.json({
|
|
184
199
|
method: "PUT",
|
|
185
200
|
path: `${path(name)}/sandboxes`,
|
|
@@ -202,17 +217,31 @@ export function secrets(t) {
|
|
|
202
217
|
list,
|
|
203
218
|
/** Every secret by name, with where its value may go. */
|
|
204
219
|
all,
|
|
205
|
-
/** One secret by name, with where its value may go
|
|
220
|
+
/** One secret by name, with where its value may go: `sandboxes` (its
|
|
221
|
+
* kind, `version`, variable, hosts and placeholder, from
|
|
222
|
+
* `GET /v1/egress-secrets/{name}`) and `jobs`, each null when it has no
|
|
223
|
+
* such copy. Never the value. */
|
|
206
224
|
get: async (name, options) => {
|
|
207
|
-
const
|
|
208
|
-
|
|
225
|
+
const [sandboxes, jobs] = await Promise.all([
|
|
226
|
+
t.json({ method: "GET", path: path(name), ...options }).catch((error) => {
|
|
227
|
+
if (error instanceof NotFoundError)
|
|
228
|
+
return null;
|
|
229
|
+
throw error;
|
|
230
|
+
}),
|
|
231
|
+
liveCopy(name, options).catch((error) => {
|
|
232
|
+
if (unavailable(error))
|
|
233
|
+
return undefined;
|
|
234
|
+
throw error;
|
|
235
|
+
}),
|
|
236
|
+
]);
|
|
237
|
+
if (!sandboxes && !jobs)
|
|
209
238
|
throw new NotFoundError({
|
|
210
239
|
message: `No secret named ${name}.`,
|
|
211
240
|
code: "not_found",
|
|
212
241
|
status: 404,
|
|
213
242
|
hint: "List them with runtime.secrets.all().",
|
|
214
243
|
});
|
|
215
|
-
return
|
|
244
|
+
return { name, sandboxes, jobs: jobs ?? null };
|
|
216
245
|
},
|
|
217
246
|
/** Replace the jobs copy's value with a new version. Runs already bound to
|
|
218
247
|
* the old version are refused it. Only the jobs copy has versions; to
|
package/dist/transport.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RuntimeError } from "./errors.js";
|
|
2
|
-
export declare const VERSION = "0.
|
|
2
|
+
export declare const VERSION = "0.45.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
|
|
@@ -69,6 +69,7 @@ export type Call = RequestOptions & {
|
|
|
69
69
|
* for capacity never spends the caller's own `timeoutMs`. */
|
|
70
70
|
extendDeadline?: (ms: number) => void;
|
|
71
71
|
};
|
|
72
|
+
export declare function traceHeaders(): Record<string, string>;
|
|
72
73
|
/** How long one attempt waits for its answer to start. The API starts every
|
|
73
74
|
* answer within 120 s: Caddy answers 503 itself past that, and a longer call
|
|
74
75
|
* gets its 200 at 90 s and then its JSON (runtime-late-answer). An attempt
|
|
@@ -141,6 +142,10 @@ export declare class Transport {
|
|
|
141
142
|
fileStream(call: Call): Promise<ReadableStream<Uint8Array>>;
|
|
142
143
|
/** Newline-delimited JSON events, as they arrive. */
|
|
143
144
|
events<T>(call: Call): AsyncGenerator<T>;
|
|
145
|
+
/** The key calls are made with: the one given, RUNTIME_API_KEY, or the
|
|
146
|
+
* connection `runtime login` saved. For another platform's SDK pointed at
|
|
147
|
+
* Runtime (`runtime.agents.anthropic()`). */
|
|
148
|
+
apiKey(): Promise<string>;
|
|
144
149
|
/** A WebSocket to an API path, authenticated with the same key. */
|
|
145
150
|
websocket(path: string, query?: Query): Promise<WebSocket>;
|
|
146
151
|
}
|
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.
|
|
4
|
+
export const VERSION = "0.45.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
|
|
@@ -39,6 +39,36 @@ export function reachable(origin, inSandbox = inRuntimeSandbox) {
|
|
|
39
39
|
function processEnv() {
|
|
40
40
|
return (globalThis.process?.env ?? {});
|
|
41
41
|
}
|
|
42
|
+
/** The W3C trace context of the caller's active OpenTelemetry span, when the
|
|
43
|
+
* program uses OpenTelemetry for JavaScript: version 1 of @opentelemetry/api
|
|
44
|
+
* keeps its registered context manager and propagator on globalThis under
|
|
45
|
+
* this symbol, so the SDK reads them without depending on the package. With
|
|
46
|
+
* it, Runtime's span of the call (an export with "traces") is a child of the
|
|
47
|
+
* caller's, in the caller's own trace. Nothing without OpenTelemetry, and
|
|
48
|
+
* never a reason for a call to fail. */
|
|
49
|
+
const OTEL_API = Symbol.for("opentelemetry.js.api.1");
|
|
50
|
+
export function traceHeaders() {
|
|
51
|
+
try {
|
|
52
|
+
const otel = globalThis[OTEL_API];
|
|
53
|
+
const active = otel?.context?.active?.();
|
|
54
|
+
if (!active || !otel?.propagation?.inject)
|
|
55
|
+
return {};
|
|
56
|
+
const carrier = {};
|
|
57
|
+
otel.propagation.inject(active, carrier, {
|
|
58
|
+
set: (into, key, value) => {
|
|
59
|
+
into[key.toLowerCase()] = String(value);
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
const headers = {};
|
|
63
|
+
for (const name of ["traceparent", "tracestate"])
|
|
64
|
+
if (typeof carrier[name] === "string" && carrier[name].length <= 512)
|
|
65
|
+
headers[name] = carrier[name];
|
|
66
|
+
return headers;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return {};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
42
72
|
/** How long an answer that ran nothing (NOTHING_RAN) is retried for a call
|
|
43
73
|
* that has no deadline of its own. */
|
|
44
74
|
const NOTHING_RAN_MS = 300_000;
|
|
@@ -278,6 +308,7 @@ export class Transport {
|
|
|
278
308
|
: { "content-type": "application/json" }),
|
|
279
309
|
...(key ? { "idempotency-key": key } : {}),
|
|
280
310
|
...(call.wait ? { prefer: `wait=${Math.min(120, Math.ceil(call.wait))}` } : {}),
|
|
311
|
+
...traceHeaders(),
|
|
281
312
|
};
|
|
282
313
|
}
|
|
283
314
|
/** Sends a call and returns the raw Response once it succeeded. Retries
|
|
@@ -723,6 +754,12 @@ export class Transport {
|
|
|
723
754
|
release();
|
|
724
755
|
}
|
|
725
756
|
}
|
|
757
|
+
/** The key calls are made with: the one given, RUNTIME_API_KEY, or the
|
|
758
|
+
* connection `runtime login` saved. For another platform's SDK pointed at
|
|
759
|
+
* Runtime (`runtime.agents.anthropic()`). */
|
|
760
|
+
async apiKey() {
|
|
761
|
+
return this.#key();
|
|
762
|
+
}
|
|
726
763
|
/** A WebSocket to an API path, authenticated with the same key. */
|
|
727
764
|
async websocket(path, query) {
|
|
728
765
|
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 {};
|