@finalai/sandbox-router-final 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -6
- package/dist/modules/claims.d.mts +3 -0
- package/dist/modules/claims.mjs +24 -0
- package/dist/modules/claims.mjs.map +7 -0
- package/dist/modules/computer.d.mts +7 -0
- package/dist/modules/computer.mjs +57 -0
- package/dist/modules/computer.mjs.map +7 -0
- package/dist/modules/images.d.mts +23 -3
- package/dist/modules/images.mjs +48 -23
- package/dist/modules/images.mjs.map +3 -3
- package/dist/modules/lifecycle.d.mts +25 -0
- package/dist/modules/lifecycle.mjs +46 -0
- package/dist/modules/lifecycle.mjs.map +7 -0
- package/dist/modules/limits.d.mts +1 -0
- package/dist/modules/limits.mjs +20 -1
- package/dist/modules/limits.mjs.map +2 -2
- package/dist/modules/options.d.mts +8 -5
- package/dist/modules/options.mjs +8 -6
- package/dist/modules/options.mjs.map +2 -2
- package/dist/modules/provider.mjs +1023 -127
- package/dist/modules/provider.mjs.map +2 -2
- package/dist/modules/service.d.mts +12 -0
- package/dist/modules/service.mjs +49 -0
- package/dist/modules/service.mjs.map +7 -0
- package/dist/modules/usage.d.mts +7 -0
- package/dist/modules/usage.mjs +50 -0
- package/dist/modules/usage.mjs.map +7 -0
- package/dist/modules/vm/api.d.mts +2 -1
- package/dist/modules/vm/api.mjs +11 -3
- package/dist/modules/vm/api.mjs.map +2 -2
- package/dist/modules/vm/client.d.mts +85 -4
- package/dist/modules/vm/client.mjs +142 -6
- package/dist/modules/vm/client.mjs.map +2 -2
- package/dist/modules/vm/errors.d.mts +2 -0
- package/dist/modules/vm/errors.mjs +2 -1
- package/dist/modules/vm/errors.mjs.map +2 -2
- package/dist/modules/vm/exec.d.mts +1 -0
- package/dist/modules/vm/exec.mjs +2 -0
- package/dist/modules/vm/exec.mjs.map +2 -2
- package/dist/modules/vm/files.d.mts +8 -0
- package/dist/modules/vm/files.mjs +47 -0
- package/dist/modules/vm/files.mjs.map +2 -2
- package/dist/modules/vm/ids.d.mts +1 -0
- package/dist/modules/vm/ids.mjs +2 -0
- package/dist/modules/vm/ids.mjs.map +2 -2
- package/dist/modules/vm/ingress.d.mts +5 -0
- package/dist/modules/vm/ingress.mjs +21 -0
- package/dist/modules/vm/ingress.mjs.map +2 -2
- package/dist/modules/vm/machines.d.mts +3 -0
- package/dist/modules/vm/machines.mjs +2 -0
- package/dist/modules/vm/machines.mjs.map +2 -2
- package/dist/modules/vm/network.d.mts +3 -1
- package/dist/modules/vm/network.mjs +3 -2
- package/dist/modules/vm/network.mjs.map +2 -2
- package/dist/modules/vm/resources.d.mts +251 -0
- package/dist/modules/vm/resources.mjs +210 -0
- package/dist/modules/vm/resources.mjs.map +7 -0
- package/dist/modules/vm/routes.d.mts +55 -0
- package/dist/modules/vm/routes.mjs +61 -0
- package/dist/modules/vm/routes.mjs.map +7 -0
- package/dist/modules/vm/sandbox.d.mts +92 -3
- package/dist/modules/vm/sandbox.mjs +234 -4
- package/dist/modules/vm/sandbox.mjs.map +2 -2
- package/dist/modules/vm/schemas.d.mts +219 -0
- package/dist/modules/vm/schemas.mjs +34 -3
- package/dist/modules/vm/schemas.mjs.map +2 -2
- package/dist/modules/vm/size.d.mts +10 -0
- package/dist/modules/vm/size.mjs +7 -0
- package/dist/modules/vm/size.mjs.map +7 -0
- package/dist/modules/vm/wire.d.mts +3 -0
- package/dist/modules/vm/wire.mjs +6 -0
- package/dist/modules/vm/wire.mjs.map +2 -2
- package/package.json +2 -2
package/dist/modules/vm/api.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { parseRetryAfterMs, vmError, VmErrorSource } from "./errors.mjs";
|
|
2
2
|
import { apiErrorBodySchema } from "./schemas.mjs";
|
|
3
|
+
import { NO_CAPACITY_HEADER } from "./wire.mjs";
|
|
3
4
|
var HttpMethod = /* @__PURE__ */ ((HttpMethod2) => {
|
|
4
5
|
HttpMethod2["Get"] = "GET";
|
|
5
6
|
HttpMethod2["Post"] = "POST";
|
|
@@ -8,6 +9,10 @@ var HttpMethod = /* @__PURE__ */ ((HttpMethod2) => {
|
|
|
8
9
|
HttpMethod2["Delete"] = "DELETE";
|
|
9
10
|
return HttpMethod2;
|
|
10
11
|
})(HttpMethod || {});
|
|
12
|
+
const labelQuery = (labels) => Object.entries(labels).map(([key, value]) => {
|
|
13
|
+
if (key.includes("=")) throw new RangeError(`cannot filter by a label key holding "=": ${key}`);
|
|
14
|
+
return `${key}=${value}`;
|
|
15
|
+
});
|
|
11
16
|
const RETRYABLE_STATUSES = [429, 503];
|
|
12
17
|
const NETWORK_RETRIES = 2;
|
|
13
18
|
const decode = (text, schema) => {
|
|
@@ -22,7 +27,8 @@ const createApiTransport = (options) => {
|
|
|
22
27
|
return async (request) => {
|
|
23
28
|
const url = new URL(`${base}${request.path}`);
|
|
24
29
|
for (const [name, value] of Object.entries(request.query ?? {})) {
|
|
25
|
-
if (value
|
|
30
|
+
if (Array.isArray(value)) for (const item of value) url.searchParams.append(name, item);
|
|
31
|
+
else if (value != null) url.searchParams.set(name, String(value));
|
|
26
32
|
}
|
|
27
33
|
const headers = new Headers({
|
|
28
34
|
authorization: `Bearer ${options.credential}`,
|
|
@@ -82,13 +88,15 @@ const createApiTransport = (options) => {
|
|
|
82
88
|
status: response.status,
|
|
83
89
|
code: failure?.success === true ? failure.data.error : `http_${response.status}`,
|
|
84
90
|
message: `${request.method} ${request.path}: ${response.status} ${failure?.success === true ? failure.data.message ?? failure.data.error : text.slice(0, 500)}`,
|
|
85
|
-
retryAfterMs
|
|
91
|
+
retryAfterMs,
|
|
92
|
+
noCapacity: response.headers.get(NO_CAPACITY_HEADER) === "1"
|
|
86
93
|
});
|
|
87
94
|
}
|
|
88
95
|
};
|
|
89
96
|
};
|
|
90
97
|
export {
|
|
91
98
|
HttpMethod,
|
|
92
|
-
createApiTransport
|
|
99
|
+
createApiTransport,
|
|
100
|
+
labelQuery
|
|
93
101
|
};
|
|
94
102
|
//# sourceMappingURL=api.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/vm/api.ts"],
|
|
4
|
-
"sourcesContent": ["import type * as z from 'zod';\nimport type { ClockIface } from \"./clock.mjs\";\nimport { parseRetryAfterMs, vmError, VmErrorSource } from \"./errors.mjs\";\nimport { apiErrorBodySchema } from \"./schemas.mjs\";\n\n// The API transport: bearer credential, JSON both ways, bounded requests. A 503 or 429 with\n// `Retry-After` asks for the same request again (`pending`: the outcome is not known yet and a\n// retry continues the same operation; `unavailable`: nothing can take it yet), so requests that\n// are safe to repeat retry it within `maxRetryWaitMs`: GET, PUT, PATCH, DELETE and POSTs marked\n// `idempotent` (state commands, and creates that name their own id). Others surface it: a fork\n// or checkpoint repeated would be a second one. Only GETs retry a request that got no answer at\n// all: a lost POST may have been applied.\n\nexport enum HttpMethod {\n Get = 'GET',\n Post = 'POST',\n Put = 'PUT',\n Patch = 'PATCH',\n Delete = 'DELETE',\n}\n\nexport interface ApiTransportOptionsIface {\n apiUrl: string;\n credential: string;\n fetch: typeof fetch;\n requestTimeoutMs: number;\n maxRetryWaitMs: number;\n clock: ClockIface;\n}\n\nexport interface ApiRequestIface<T> {\n method: HttpMethod;\n path: string;\n query?: Record<string, string | number | undefined>;\n // Serialized with JSON.stringify; undefined fields are left out.\n body?: object;\n schema: z.ZodType<T>;\n signal?: AbortSignal;\n // Repeating it has the effect of sending it once (see the transport's retry rule).\n idempotent?: boolean;\n}\n\nexport type ApiTransport = <T>(request: ApiRequestIface<T>) => Promise<T>;\n\nconst RETRYABLE_STATUSES = [429, 503];\nconst NETWORK_RETRIES = 2;\n\n// The answer's JSON through `schema`; null when it isn't JSON. An empty body reads as `{}`.\nconst decode = <T>(text: string, schema: z.ZodType<T>) => {\n try {\n return schema.safeParse(text.trim() === '' ? {} : JSON.parse(text));\n } catch {\n return null;\n }\n};\n\nexport const createApiTransport = (options: ApiTransportOptionsIface): ApiTransport => {\n const base = `${options.apiUrl.replace(/\\/+$/, '')}/v1`;\n return async <T>(request: ApiRequestIface<T>): Promise<T> => {\n const url = new URL(`${base}${request.path}`);\n for (const [name, value] of Object.entries(request.query ?? {})) {\n if (value != null) url.searchParams.set(name, String(value));\n }\n const headers = new Headers({\n authorization: `Bearer ${options.credential}`,\n accept: 'application/json',\n });\n if (request.body !== undefined) headers.set('content-type', 'application/json');\n const body = request.body === undefined ? undefined : JSON.stringify(request.body);\n const retryUntil = options.clock.now() + options.maxRetryWaitMs;\n let networkFailures = 0;\n for (;;) {\n request.signal?.throwIfAborted();\n const timeout = AbortSignal.timeout(options.requestTimeoutMs);\n let response: Response;\n try {\n response = await options.fetch(url, {\n method: request.method,\n headers,\n body,\n signal: request.signal == null ? timeout : AbortSignal.any([timeout, request.signal]),\n });\n } catch (error) {\n request.signal?.throwIfAborted();\n if (request.method === HttpMethod.Get && networkFailures < NETWORK_RETRIES) {\n networkFailures += 1;\n await options.clock.sleep(200 * networkFailures, request.signal);\n continue;\n }\n throw vmError({\n source: VmErrorSource.Api,\n status: null,\n code: 'request_failed',\n message: `${request.method} ${request.path} failed: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n // Text first: a proxy's or CDN's error page is kept for the message.\n const text = await response.text();\n if (response.ok) {\n const result = decode(text, request.schema);\n if (result?.success === true) return result.data;\n throw vmError({\n source: VmErrorSource.Api,\n status: response.status,\n code: 'invalid_answer',\n message: `${request.method} ${request.path}: unexpected answer: ${result?.error.message ?? 'not JSON'}`,\n });\n }\n const retryAfterMs = parseRetryAfterMs(\n response.headers.get('retry-after'),\n options.clock.now(),\n );\n if (\n (request.idempotent === true || request.method !== HttpMethod.Post) &&\n RETRYABLE_STATUSES.includes(response.status) &&\n retryAfterMs != null &&\n options.clock.now() + retryAfterMs <= retryUntil\n ) {\n await options.clock.sleep(retryAfterMs, request.signal);\n continue;\n }\n const failure = decode(text, apiErrorBodySchema);\n throw vmError({\n source: VmErrorSource.Api,\n status: response.status,\n code: failure?.success === true ? failure.data.error : `http_${response.status}`,\n message: `${request.method} ${request.path}: ${response.status} ${\n failure?.success === true\n ? (failure.data.message ?? failure.data.error)\n : text.slice(0, 500)\n }`,\n retryAfterMs,\n });\n }\n };\n};\n"],
|
|
5
|
-
"mappings": "AAEA,SAAS,mBAAmB,SAAS,qBAAqB;AAC1D,SAAS,0BAA0B;AAU5B,IAAK,aAAL,kBAAKA,gBAAL;AACL,EAAAA,YAAA,SAAM;AACN,EAAAA,YAAA,UAAO;AACP,EAAAA,YAAA,SAAM;AACN,EAAAA,YAAA,WAAQ;AACR,EAAAA,YAAA,YAAS;AALC,SAAAA;AAAA,GAAA;
|
|
4
|
+
"sourcesContent": ["import type * as z from 'zod';\nimport type { ClockIface } from \"./clock.mjs\";\nimport { parseRetryAfterMs, vmError, VmErrorSource } from \"./errors.mjs\";\nimport { apiErrorBodySchema } from \"./schemas.mjs\";\nimport { NO_CAPACITY_HEADER } from \"./wire.mjs\";\n\n// The API transport: bearer credential, JSON both ways, bounded requests. A 503 or 429 with\n// `Retry-After` asks for the same request again (`pending`: the outcome is not known yet and a\n// retry continues the same operation; `unavailable`: nothing can take it yet), so requests that\n// are safe to repeat retry it within `maxRetryWaitMs`: GET, PUT, PATCH, DELETE and POSTs marked\n// `idempotent` (state commands, and creates that name their own id). Others surface it: a fork\n// or checkpoint repeated would be a second one. Only GETs retry a request that got no answer at\n// all: a lost POST may have been applied.\n\nexport enum HttpMethod {\n Get = 'GET',\n Post = 'POST',\n Put = 'PUT',\n Patch = 'PATCH',\n Delete = 'DELETE',\n}\n\nexport interface ApiTransportOptionsIface {\n apiUrl: string;\n credential: string;\n fetch: typeof fetch;\n requestTimeoutMs: number;\n maxRetryWaitMs: number;\n clock: ClockIface;\n}\n\nexport interface ApiRequestIface<T> {\n method: HttpMethod;\n path: string;\n // A list repeats the parameter.\n query?: Record<string, string | number | readonly string[] | undefined>;\n // Serialized with JSON.stringify; undefined fields are left out.\n body?: object;\n schema: z.ZodType<T>;\n signal?: AbortSignal;\n // Repeating it has the effect of sending it once (see the transport's retry rule).\n idempotent?: boolean;\n}\n\n// `label=key=value` filters: a listed resource carries every one. The platform splits each at its\n// first `=`, so a key cannot hold one.\nexport const labelQuery = (labels: Record<string, string>): string[] =>\n Object.entries(labels).map(([key, value]) => {\n if (key.includes('=')) throw new RangeError(`cannot filter by a label key holding \"=\": ${key}`);\n return `${key}=${value}`;\n });\n\nexport type ApiTransport = <T>(request: ApiRequestIface<T>) => Promise<T>;\n\nconst RETRYABLE_STATUSES = [429, 503];\nconst NETWORK_RETRIES = 2;\n\n// The answer's JSON through `schema`; null when it isn't JSON. An empty body reads as `{}`.\nconst decode = <T>(text: string, schema: z.ZodType<T>) => {\n try {\n return schema.safeParse(text.trim() === '' ? {} : JSON.parse(text));\n } catch {\n return null;\n }\n};\n\nexport const createApiTransport = (options: ApiTransportOptionsIface): ApiTransport => {\n const base = `${options.apiUrl.replace(/\\/+$/, '')}/v1`;\n return async <T>(request: ApiRequestIface<T>): Promise<T> => {\n const url = new URL(`${base}${request.path}`);\n for (const [name, value] of Object.entries(request.query ?? {})) {\n if (Array.isArray(value)) for (const item of value) url.searchParams.append(name, item);\n else if (value != null) url.searchParams.set(name, String(value));\n }\n const headers = new Headers({\n authorization: `Bearer ${options.credential}`,\n accept: 'application/json',\n });\n if (request.body !== undefined) headers.set('content-type', 'application/json');\n const body = request.body === undefined ? undefined : JSON.stringify(request.body);\n const retryUntil = options.clock.now() + options.maxRetryWaitMs;\n let networkFailures = 0;\n for (;;) {\n request.signal?.throwIfAborted();\n const timeout = AbortSignal.timeout(options.requestTimeoutMs);\n let response: Response;\n try {\n response = await options.fetch(url, {\n method: request.method,\n headers,\n body,\n signal: request.signal == null ? timeout : AbortSignal.any([timeout, request.signal]),\n });\n } catch (error) {\n request.signal?.throwIfAborted();\n if (request.method === HttpMethod.Get && networkFailures < NETWORK_RETRIES) {\n networkFailures += 1;\n await options.clock.sleep(200 * networkFailures, request.signal);\n continue;\n }\n throw vmError({\n source: VmErrorSource.Api,\n status: null,\n code: 'request_failed',\n message: `${request.method} ${request.path} failed: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n // Text first: a proxy's or CDN's error page is kept for the message.\n const text = await response.text();\n if (response.ok) {\n const result = decode(text, request.schema);\n if (result?.success === true) return result.data;\n throw vmError({\n source: VmErrorSource.Api,\n status: response.status,\n code: 'invalid_answer',\n message: `${request.method} ${request.path}: unexpected answer: ${result?.error.message ?? 'not JSON'}`,\n });\n }\n const retryAfterMs = parseRetryAfterMs(\n response.headers.get('retry-after'),\n options.clock.now(),\n );\n if (\n (request.idempotent === true || request.method !== HttpMethod.Post) &&\n RETRYABLE_STATUSES.includes(response.status) &&\n retryAfterMs != null &&\n options.clock.now() + retryAfterMs <= retryUntil\n ) {\n await options.clock.sleep(retryAfterMs, request.signal);\n continue;\n }\n const failure = decode(text, apiErrorBodySchema);\n throw vmError({\n source: VmErrorSource.Api,\n status: response.status,\n code: failure?.success === true ? failure.data.error : `http_${response.status}`,\n message: `${request.method} ${request.path}: ${response.status} ${\n failure?.success === true\n ? (failure.data.message ?? failure.data.error)\n : text.slice(0, 500)\n }`,\n retryAfterMs,\n noCapacity: response.headers.get(NO_CAPACITY_HEADER) === '1',\n });\n }\n };\n};\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,mBAAmB,SAAS,qBAAqB;AAC1D,SAAS,0BAA0B;AACnC,SAAS,0BAA0B;AAU5B,IAAK,aAAL,kBAAKA,gBAAL;AACL,EAAAA,YAAA,SAAM;AACN,EAAAA,YAAA,UAAO;AACP,EAAAA,YAAA,SAAM;AACN,EAAAA,YAAA,WAAQ;AACR,EAAAA,YAAA,YAAS;AALC,SAAAA;AAAA,GAAA;AAgCL,MAAM,aAAa,CAAC,WACzB,OAAO,QAAQ,MAAM,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAC3C,MAAI,IAAI,SAAS,GAAG,EAAG,OAAM,IAAI,WA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;AAC/C,YAAM,QAAQ;AAAA,QACZ,QAAQ,cAAc;AAAA,QACtB,QAAQ,SAAS;AAAA,QACjB,MAAM,SAAS,YAAY,OAAO,QAAQ,KAAK,QAAQ,QAAQ,SAAS,MAAM;AAAA,QAC9E,SAAS,GAAG,QAAQ,MAAM,IAAI,QAAQ,IAAI,KAAK,SAAS,MAAM,IAC5D,SAAS,YAAY,OAChB,QAAQ,KAAK,WAAW,QAAQ,KAAK,QACtC,KAAK,MAAM,GAAG,GAAG,CACvB;AAAA,QACA;AAAA,QACA,YAAY,SAAS,QAAQ,IAAI,kBAAkB,MAAM;AAAA,MAC3D,CAAC;AAAA,IACH;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["HttpMethod"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { type WorkloadOptionsIface } from "./workload.mjs";
|
|
2
2
|
import { type MachineOptionsIface, type MachineTypesIface } from "./machines.mjs";
|
|
3
|
+
import { type CpuOption, type MemoryOption } from "./size.mjs";
|
|
4
|
+
import { type IngressRoutesIface } from "./routes.mjs";
|
|
3
5
|
import { type ClockIface } from "./clock.mjs";
|
|
4
6
|
import { type SandboxIface } from "./sandbox.mjs";
|
|
7
|
+
import { type CacheObjectIface, type IdlePolicy, type MaxLifetimeBodyIface, type VolumeIface, type WorkloadBodyIface } from "./resources.mjs";
|
|
5
8
|
import { type ImageIface, type SandboxInfoIface, type SnapshotIface, type TemplateBuildIface, type TemplateIface } from "./schemas.mjs";
|
|
6
9
|
export declare const DEFAULT_API_URL = "https://api.vm.finalwebservices.com";
|
|
7
10
|
export declare const DEFAULT_PREVIEW_DOMAIN = "vm.finalwebservices.com";
|
|
@@ -35,8 +38,6 @@ export interface ProjectScopeIface {
|
|
|
35
38
|
export interface ListScopeIface {
|
|
36
39
|
projectId?: string;
|
|
37
40
|
}
|
|
38
|
-
export type CpuOption = number | [request: number, limit: number];
|
|
39
|
-
export type MemoryOption = number | [request: number, limit: number];
|
|
40
41
|
export interface CreateSandboxOptionsIface extends ProjectScopeIface {
|
|
41
42
|
sandboxId?: string;
|
|
42
43
|
workload?: WorkloadOptionsIface;
|
|
@@ -55,8 +56,24 @@ export interface CreateSandboxOptionsIface extends ProjectScopeIface {
|
|
|
55
56
|
allowDomains?: string[];
|
|
56
57
|
labels?: Record<string, string>;
|
|
57
58
|
idleTimeoutS?: number | null;
|
|
58
|
-
|
|
59
|
+
idlePolicy?: IdlePolicy;
|
|
60
|
+
autoResume?: boolean;
|
|
61
|
+
wallClockLimitS?: number | null;
|
|
59
62
|
ttlS?: number;
|
|
63
|
+
maxLifetime?: MaxLifetimeBodyIface;
|
|
64
|
+
pausedRetentionS?: number;
|
|
65
|
+
placementGroup?: string;
|
|
66
|
+
telemetryResource?: Record<string, string>;
|
|
67
|
+
volumes?: {
|
|
68
|
+
volumeId: string;
|
|
69
|
+
path: string;
|
|
70
|
+
allowCommit: boolean;
|
|
71
|
+
}[];
|
|
72
|
+
workloadBody?: WorkloadBodyIface;
|
|
73
|
+
ownerSelf?: boolean;
|
|
74
|
+
retentionExempt?: boolean;
|
|
75
|
+
platformEgress?: boolean;
|
|
76
|
+
cpuPool?: string;
|
|
60
77
|
tools?: string[];
|
|
61
78
|
signal?: AbortSignal;
|
|
62
79
|
}
|
|
@@ -67,6 +84,7 @@ export interface ListSandboxesOptionsIface extends ListScopeIface {
|
|
|
67
84
|
limit?: number;
|
|
68
85
|
}
|
|
69
86
|
export interface VmClientIface {
|
|
87
|
+
ingressRoutes: IngressRoutesIface;
|
|
70
88
|
sandboxes: {
|
|
71
89
|
create: (options: CreateSandboxOptionsIface) => Promise<SandboxIface>;
|
|
72
90
|
get: (id: string) => Promise<SandboxIface>;
|
|
@@ -86,8 +104,10 @@ export interface VmClientIface {
|
|
|
86
104
|
imageId: string;
|
|
87
105
|
startCmd?: string;
|
|
88
106
|
readyCmd?: string;
|
|
107
|
+
warmupCmd?: string;
|
|
89
108
|
cpu?: CpuOption;
|
|
90
109
|
memory?: MemoryOption;
|
|
110
|
+
tools?: string[];
|
|
91
111
|
}) => Promise<TemplateIface>;
|
|
92
112
|
get: (id: string) => Promise<TemplateIface>;
|
|
93
113
|
list: (options?: ListScopeIface) => Promise<TemplateIface[]>;
|
|
@@ -96,9 +116,70 @@ export interface VmClientIface {
|
|
|
96
116
|
};
|
|
97
117
|
snapshots: {
|
|
98
118
|
get: (id: string) => Promise<SnapshotIface>;
|
|
99
|
-
list: (options?: ListScopeIface
|
|
119
|
+
list: (options?: ListScopeIface & {
|
|
120
|
+
labels?: Record<string, string>;
|
|
121
|
+
}) => Promise<SnapshotIface[]>;
|
|
100
122
|
delete: (id: string) => Promise<void>;
|
|
101
123
|
};
|
|
102
124
|
machineTypes: MachineTypesIface;
|
|
125
|
+
volumes: {
|
|
126
|
+
create: (options: ProjectScopeIface & {
|
|
127
|
+
name: string;
|
|
128
|
+
sizeGb: number;
|
|
129
|
+
expiresAfterUnusedS?: number;
|
|
130
|
+
labels?: Record<string, string>;
|
|
131
|
+
}) => Promise<VolumeIface>;
|
|
132
|
+
get: (id: string) => Promise<VolumeIface>;
|
|
133
|
+
list: (options?: ListScopeIface & {
|
|
134
|
+
labels?: Record<string, string>;
|
|
135
|
+
}) => Promise<VolumeIface[]>;
|
|
136
|
+
delete: (id: string) => Promise<void>;
|
|
137
|
+
commit: (id: string, commitId: string) => Promise<{
|
|
138
|
+
id: string;
|
|
139
|
+
state: string;
|
|
140
|
+
version: number | null;
|
|
141
|
+
}>;
|
|
142
|
+
};
|
|
143
|
+
caches: {
|
|
144
|
+
start: (options: {
|
|
145
|
+
namespace: string;
|
|
146
|
+
key: string;
|
|
147
|
+
partCount: number;
|
|
148
|
+
}) => Promise<{
|
|
149
|
+
object: CacheObjectIface;
|
|
150
|
+
parts: {
|
|
151
|
+
partNumber: number;
|
|
152
|
+
url: string;
|
|
153
|
+
}[];
|
|
154
|
+
}>;
|
|
155
|
+
parts: (id: string, partNumbers: number[]) => Promise<{
|
|
156
|
+
partNumber: number;
|
|
157
|
+
url: string;
|
|
158
|
+
}[]>;
|
|
159
|
+
complete: (id: string, parts: {
|
|
160
|
+
partNumber: number;
|
|
161
|
+
etag: string;
|
|
162
|
+
}[]) => Promise<CacheObjectIface>;
|
|
163
|
+
get: (id: string) => Promise<CacheObjectIface>;
|
|
164
|
+
delete: (id: string) => Promise<void>;
|
|
165
|
+
lookup: (candidates: {
|
|
166
|
+
namespace: string;
|
|
167
|
+
key: string;
|
|
168
|
+
prefix: boolean;
|
|
169
|
+
}[]) => Promise<{
|
|
170
|
+
object: CacheObjectIface;
|
|
171
|
+
url: string;
|
|
172
|
+
urlExpiresAt: string | null;
|
|
173
|
+
} | null>;
|
|
174
|
+
list: (options: {
|
|
175
|
+
namespace: string;
|
|
176
|
+
prefix?: string;
|
|
177
|
+
after?: string;
|
|
178
|
+
limit?: number;
|
|
179
|
+
}) => Promise<{
|
|
180
|
+
objects: CacheObjectIface[];
|
|
181
|
+
next: string | null;
|
|
182
|
+
}>;
|
|
183
|
+
};
|
|
103
184
|
}
|
|
104
185
|
export declare const createVmClient: (options: VmClientOptionsIface) => VmClientIface;
|
|
@@ -5,9 +5,19 @@ import {
|
|
|
5
5
|
} from "./machines.mjs";
|
|
6
6
|
import * as z from "zod";
|
|
7
7
|
import { newSandboxId } from "./ids.mjs";
|
|
8
|
-
import {
|
|
8
|
+
import { cpuBody, memoryBody } from "./size.mjs";
|
|
9
|
+
import { createApiTransport, HttpMethod, labelQuery } from "./api.mjs";
|
|
10
|
+
import { createIngressRoutes } from "./routes.mjs";
|
|
9
11
|
import { systemClock } from "./clock.mjs";
|
|
10
12
|
import { createSandboxHandle } from "./sandbox.mjs";
|
|
13
|
+
import {
|
|
14
|
+
cacheObjectSchema,
|
|
15
|
+
cachePartsSchema,
|
|
16
|
+
cacheReadSchema,
|
|
17
|
+
cacheStartSchema,
|
|
18
|
+
commitSchema,
|
|
19
|
+
volumeSchema
|
|
20
|
+
} from "./resources.mjs";
|
|
11
21
|
import {
|
|
12
22
|
deletedSchema,
|
|
13
23
|
imageSchema,
|
|
@@ -26,11 +36,23 @@ var SourceKind = /* @__PURE__ */ ((SourceKind2) => {
|
|
|
26
36
|
SourceKind2["Template"] = "template";
|
|
27
37
|
return SourceKind2;
|
|
28
38
|
})(SourceKind || {});
|
|
29
|
-
const
|
|
30
|
-
const memoryBody = (memory) => Array.isArray(memory) ? { request: memory[0], limit: memory[1] } : memory;
|
|
39
|
+
const partsOf = (parts) => parts.map((part) => ({ partNumber: part.part_number, url: part.url }));
|
|
31
40
|
const item = (resource, id) => `/${resource}/${encodeURIComponent(id)}`;
|
|
32
41
|
const createBody = (options) => ({
|
|
33
|
-
workload: options.workload == null ? void 0 : workloadBody(options.workload),
|
|
42
|
+
workload: options.workloadBody ?? (options.workload == null ? void 0 : workloadBody(options.workload)),
|
|
43
|
+
auto_resume: options.autoResume,
|
|
44
|
+
idle_policy: options.idlePolicy,
|
|
45
|
+
placement_group: options.placementGroup,
|
|
46
|
+
telemetry_resource: options.telemetryResource,
|
|
47
|
+
volumes: options.volumes?.map((volume) => ({
|
|
48
|
+
volume_id: volume.volumeId,
|
|
49
|
+
path: volume.path,
|
|
50
|
+
allow_commit: volume.allowCommit
|
|
51
|
+
})),
|
|
52
|
+
owner: options.ownerSelf === true ? "self" : void 0,
|
|
53
|
+
retention_exempt: options.retentionExempt,
|
|
54
|
+
platform_egress: options.platformEgress,
|
|
55
|
+
cpu_pool: options.cpuPool,
|
|
34
56
|
ephemeral: options.ephemeral,
|
|
35
57
|
project_id: options.projectId,
|
|
36
58
|
source: options.source == null ? void 0 : options.source.kind === "image" /* Image */ ? { kind: "image" /* Image */, image_id: options.source.imageId } : options.source.kind === "snapshot" /* Snapshot */ ? { kind: "snapshot" /* Snapshot */, snapshot_id: options.source.snapshotId } : { kind: "template" /* Template */, template_id: options.source.templateId },
|
|
@@ -53,6 +75,8 @@ const createBody = (options) => ({
|
|
|
53
75
|
wall_clock_limit_s: options.wallClockLimitS
|
|
54
76
|
},
|
|
55
77
|
ttl_s: options.ttlS,
|
|
78
|
+
max_lifetime: options.maxLifetime,
|
|
79
|
+
paused_retention_s: options.pausedRetentionS,
|
|
56
80
|
tools: options.tools
|
|
57
81
|
});
|
|
58
82
|
const remove = async (api, resource, id) => {
|
|
@@ -77,6 +101,7 @@ const createVmClient = (options) => {
|
|
|
77
101
|
};
|
|
78
102
|
const getImage = (id) => api({ method: HttpMethod.Get, path: item("images", id), schema: imageSchema });
|
|
79
103
|
return {
|
|
104
|
+
ingressRoutes: createIngressRoutes(api),
|
|
80
105
|
sandboxes: {
|
|
81
106
|
create: async (createOptions) => {
|
|
82
107
|
const requestedAt = clock.now();
|
|
@@ -144,6 +169,8 @@ const createVmClient = (options) => {
|
|
|
144
169
|
image_id: templateOptions.imageId,
|
|
145
170
|
start_cmd: templateOptions.startCmd,
|
|
146
171
|
ready_cmd: templateOptions.readyCmd,
|
|
172
|
+
warmup_cmd: templateOptions.warmupCmd,
|
|
173
|
+
tools: templateOptions.tools,
|
|
147
174
|
cpu: cpuBody(templateOptions.cpu),
|
|
148
175
|
memory: memoryBody(templateOptions.memory)
|
|
149
176
|
},
|
|
@@ -169,12 +196,121 @@ const createVmClient = (options) => {
|
|
|
169
196
|
list: async (listOptions = {}) => (await api({
|
|
170
197
|
method: HttpMethod.Get,
|
|
171
198
|
path: "/snapshots",
|
|
172
|
-
query: {
|
|
199
|
+
query: {
|
|
200
|
+
project_id: listOptions.projectId,
|
|
201
|
+
label: labelQuery(listOptions.labels ?? {})
|
|
202
|
+
},
|
|
173
203
|
schema: z.object({ snapshots: z.array(snapshotSchema) })
|
|
174
204
|
})).snapshots,
|
|
175
205
|
delete: (id) => remove(api, "snapshots", id)
|
|
176
206
|
},
|
|
177
|
-
machineTypes: createMachineTypesApi(api)
|
|
207
|
+
machineTypes: createMachineTypesApi(api),
|
|
208
|
+
volumes: {
|
|
209
|
+
create: (volumeOptions) => api({
|
|
210
|
+
method: HttpMethod.Post,
|
|
211
|
+
path: "/volumes",
|
|
212
|
+
body: {
|
|
213
|
+
project_id: volumeOptions.projectId,
|
|
214
|
+
name: volumeOptions.name,
|
|
215
|
+
size_gb: volumeOptions.sizeGb,
|
|
216
|
+
expires_after_unused_s: volumeOptions.expiresAfterUnusedS,
|
|
217
|
+
labels: volumeOptions.labels
|
|
218
|
+
},
|
|
219
|
+
schema: volumeSchema
|
|
220
|
+
}),
|
|
221
|
+
get: (id) => api({ method: HttpMethod.Get, path: item("volumes", id), schema: volumeSchema }),
|
|
222
|
+
list: async (listOptions = {}) => (await api({
|
|
223
|
+
method: HttpMethod.Get,
|
|
224
|
+
path: "/volumes",
|
|
225
|
+
query: {
|
|
226
|
+
project_id: listOptions.projectId,
|
|
227
|
+
label: labelQuery(listOptions.labels ?? {})
|
|
228
|
+
},
|
|
229
|
+
schema: z.object({ volumes: z.array(volumeSchema) })
|
|
230
|
+
})).volumes,
|
|
231
|
+
delete: async (id) => {
|
|
232
|
+
await api({ method: HttpMethod.Delete, path: item("volumes", id), schema: z.unknown() });
|
|
233
|
+
},
|
|
234
|
+
commit: async (id, commitId) => {
|
|
235
|
+
const commit = await api({
|
|
236
|
+
method: HttpMethod.Get,
|
|
237
|
+
path: `${item("volumes", id)}/commits/${encodeURIComponent(commitId)}`,
|
|
238
|
+
schema: commitSchema
|
|
239
|
+
});
|
|
240
|
+
return { id: commit.id, state: commit.state, version: commit.version ?? null };
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
caches: {
|
|
244
|
+
start: async (startOptions) => {
|
|
245
|
+
const started = await api({
|
|
246
|
+
method: HttpMethod.Post,
|
|
247
|
+
path: "/cache-objects",
|
|
248
|
+
body: {
|
|
249
|
+
namespace: startOptions.namespace,
|
|
250
|
+
key: startOptions.key,
|
|
251
|
+
if_absent: true,
|
|
252
|
+
part_count: startOptions.partCount
|
|
253
|
+
},
|
|
254
|
+
schema: cacheStartSchema
|
|
255
|
+
});
|
|
256
|
+
return { object: started.object, parts: partsOf(started.parts) };
|
|
257
|
+
},
|
|
258
|
+
parts: async (id, partNumbers) => partsOf(
|
|
259
|
+
(await api({
|
|
260
|
+
method: HttpMethod.Post,
|
|
261
|
+
path: `${item("cache-objects", id)}/parts`,
|
|
262
|
+
body: { part_numbers: partNumbers },
|
|
263
|
+
schema: cachePartsSchema
|
|
264
|
+
})).parts
|
|
265
|
+
),
|
|
266
|
+
complete: async (id, parts) => (await api({
|
|
267
|
+
method: HttpMethod.Post,
|
|
268
|
+
path: `${item("cache-objects", id)}/complete`,
|
|
269
|
+
body: {
|
|
270
|
+
parts: parts.map((part) => ({ part_number: part.partNumber, etag: part.etag }))
|
|
271
|
+
},
|
|
272
|
+
idempotent: true,
|
|
273
|
+
schema: z.object({ object: cacheObjectSchema })
|
|
274
|
+
})).object,
|
|
275
|
+
get: async (id) => (await api({
|
|
276
|
+
method: HttpMethod.Get,
|
|
277
|
+
path: item("cache-objects", id),
|
|
278
|
+
schema: z.object({ object: cacheObjectSchema })
|
|
279
|
+
})).object,
|
|
280
|
+
delete: async (id) => {
|
|
281
|
+
await api({
|
|
282
|
+
method: HttpMethod.Delete,
|
|
283
|
+
path: item("cache-objects", id),
|
|
284
|
+
schema: z.unknown()
|
|
285
|
+
});
|
|
286
|
+
},
|
|
287
|
+
lookup: async (candidates) => {
|
|
288
|
+
const found = await api({
|
|
289
|
+
method: HttpMethod.Post,
|
|
290
|
+
path: "/cache-lookups",
|
|
291
|
+
body: { candidates },
|
|
292
|
+
schema: cacheReadSchema
|
|
293
|
+
});
|
|
294
|
+
return found.object == null || found.url == null ? null : { object: found.object, url: found.url, urlExpiresAt: found.url_expires_at ?? null };
|
|
295
|
+
},
|
|
296
|
+
list: async (listOptions) => {
|
|
297
|
+
const page = await api({
|
|
298
|
+
method: HttpMethod.Get,
|
|
299
|
+
path: "/cache-objects",
|
|
300
|
+
query: {
|
|
301
|
+
namespace: listOptions.namespace,
|
|
302
|
+
prefix: listOptions.prefix,
|
|
303
|
+
after_key: listOptions.after,
|
|
304
|
+
limit: listOptions.limit
|
|
305
|
+
},
|
|
306
|
+
schema: z.object({
|
|
307
|
+
objects: z.array(cacheObjectSchema),
|
|
308
|
+
next: z.string().nullable().optional()
|
|
309
|
+
})
|
|
310
|
+
});
|
|
311
|
+
return { objects: page.objects, next: page.next ?? null };
|
|
312
|
+
}
|
|
313
|
+
}
|
|
178
314
|
};
|
|
179
315
|
};
|
|
180
316
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/vm/client.ts"],
|
|
4
|
-
"sourcesContent": ["import { workloadBody, type WorkloadOptionsIface } from \"./workload.mjs\";\nimport {\n createMachineTypesApi,\n machineBody,\n type MachineOptionsIface,\n type MachineTypesIface,\n} from \"./machines.mjs\";\nimport * as z from 'zod';\nimport { newSandboxId } from \"./ids.mjs\";\nimport { createApiTransport, HttpMethod, type ApiTransport } from \"./api.mjs\";\nimport { systemClock, type ClockIface } from \"./clock.mjs\";\nimport { createSandboxHandle, type SandboxIface } from \"./sandbox.mjs\";\nimport {\n deletedSchema,\n imageSchema,\n sandboxInfoSchema,\n sandboxListSchema,\n sandboxOpSchema,\n snapshotSchema,\n templateBuildSchema,\n templateSchema,\n type ImageIface,\n type SandboxInfoIface,\n type SnapshotIface,\n type TemplateBuildIface,\n type TemplateIface,\n} from \"./schemas.mjs\";\n\nexport const DEFAULT_API_URL = 'https://api.vm.finalwebservices.com';\nexport const DEFAULT_PREVIEW_DOMAIN = 'vm.finalwebservices.com';\n\nexport interface VmClientOptionsIface {\n // A Final API key.\n apiKey: string;\n apiUrl?: string;\n previewDomain?: string;\n requestTimeoutMs?: number;\n // How long API calls keep honouring `503 Retry-After` before failing.\n maxRetryWaitMs?: number;\n fetch?: typeof fetch;\n clock?: ClockIface;\n}\n\nexport enum SourceKind {\n Image = 'image',\n Snapshot = 'snapshot',\n Template = 'template',\n}\n\nexport type CreateSourceIface =\n | { kind: SourceKind.Image; imageId: string }\n | { kind: SourceKind.Snapshot; snapshotId: string }\n | { kind: SourceKind.Template; templateId: string };\n\n// Creates land in `projectId` (`prj_\u2026`), which the caller must be able to edit; without one, in\n// the caller's own project (an API key's parent project).\nexport interface ProjectScopeIface {\n projectId?: string;\n}\n\n// Lists return everything the caller can see; with `projectId`, only that project and the\n// projects below it.\nexport interface ListScopeIface {\n projectId?: string;\n}\n\n// CPU in vCPU: a number is the guaranteed request, bursting to the platform's default limit; `[request, limit]` sets both, and\n// `[n, n]` is a fixed size. The guest sees ceil(limit) CPUs. Unset: the platform defaults.\nexport type CpuOption = number | [request: number, limit: number];\n\nconst cpuBody = (cpu: CpuOption | undefined) =>\n Array.isArray(cpu) ? { request: cpu[0], limit: cpu[1] } : cpu;\n\n// Memory in MiB, the same form: a number is the guaranteed request, growing to the platform's\n// largest guest; `[request, limit]` sets both, and `[n, n]` is a fixed size. Unset: the platform\n// defaults.\nexport type MemoryOption = number | [request: number, limit: number];\n\nconst memoryBody = (memory: MemoryOption | undefined) =>\n Array.isArray(memory) ? { request: memory[0], limit: memory[1] } : memory;\n\nexport interface CreateSandboxOptionsIface extends ProjectScopeIface {\n // The id (`sbx_\u2026`) to create it under, for a caller that reserved one; the SDK mints one\n // otherwise. Either way a retried create names the same sandbox.\n sandboxId?: string;\n workload?: WorkloadOptionsIface;\n ephemeral?: boolean;\n // Without one, the platform's default image (base).\n source?: CreateSourceIface;\n cpu?: CpuOption;\n memory?: MemoryOption;\n diskGb?: number;\n // The machines it may run on, kept for every wake and move; absent: any, cheapest first.\n machine?: MachineOptionsIface;\n // Stored encrypted and handed to the workload at start.\n env?: Record<string, string>;\n ports?: number[];\n publicPorts?: number[];\n allowInternet?: boolean;\n allowCidrs?: string[];\n denyCidrs?: string[];\n allowDomains?: string[];\n labels?: Record<string, string>;\n idleTimeoutS?: number | null;\n wallClockLimitS?: number;\n ttlS?: number;\n // Platform tools to run (`docker`), delivered as it starts; a template source adds its own.\n // A name that is not an available platform tool is refused (`unknown_tool`).\n tools?: string[];\n signal?: AbortSignal;\n}\n\nexport interface ListSandboxesOptionsIface extends ListScopeIface {\n states?: string[];\n // Only sandboxes carrying every one of these labels (filtered by the API).\n labels?: Record<string, string>;\n // The last id of the previous page.\n after?: string;\n limit?: number;\n}\n\nexport interface VmClientIface {\n sandboxes: {\n create: (options: CreateSandboxOptionsIface) => Promise<SandboxIface>;\n get: (id: string) => Promise<SandboxIface>;\n list: (options?: ListSandboxesOptionsIface) => Promise<SandboxInfoIface[]>;\n };\n images: {\n create: (options: ProjectScopeIface & { reference: string }) => Promise<ImageIface>;\n get: (id: string) => Promise<ImageIface>;\n list: (options?: ListScopeIface) => Promise<ImageIface[]>;\n delete: (id: string) => Promise<void>;\n };\n templates: {\n create: (\n options: ProjectScopeIface & {\n name: string;\n imageId: string;\n startCmd?: string;\n readyCmd?: string;\n cpu?: CpuOption;\n memory?: MemoryOption;\n },\n ) => Promise<TemplateIface>;\n get: (id: string) => Promise<TemplateIface>;\n list: (options?: ListScopeIface) => Promise<TemplateIface[]>;\n delete: (id: string) => Promise<void>;\n build: (id: string) => Promise<TemplateBuildIface>;\n };\n snapshots: {\n get: (id: string) => Promise<SnapshotIface>;\n list: (options?: ListScopeIface) => Promise<SnapshotIface[]>;\n delete: (id: string) => Promise<void>;\n };\n machineTypes: MachineTypesIface;\n}\n\nconst item = (resource: string, id: string) => `/${resource}/${encodeURIComponent(id)}`;\n\nconst createBody = (options: CreateSandboxOptionsIface) => ({\n workload: options.workload == null ? undefined : workloadBody(options.workload),\n ephemeral: options.ephemeral,\n project_id: options.projectId,\n source:\n options.source == null\n ? undefined\n : options.source.kind === SourceKind.Image\n ? { kind: SourceKind.Image, image_id: options.source.imageId }\n : options.source.kind === SourceKind.Snapshot\n ? { kind: SourceKind.Snapshot, snapshot_id: options.source.snapshotId }\n : { kind: SourceKind.Template, template_id: options.source.templateId },\n size: {\n cpu: cpuBody(options.cpu),\n memory: memoryBody(options.memory),\n disk_gb: options.diskGb,\n },\n machine: machineBody(options.machine),\n env: options.env,\n ports: options.ports,\n public_ports: options.publicPorts,\n allow_internet: options.allowInternet,\n allow_cidrs: options.allowCidrs,\n deny_cidrs: options.denyCidrs,\n allow_domains: options.allowDomains,\n labels: options.labels,\n timers: {\n idle_timeout_s: options.idleTimeoutS,\n wall_clock_limit_s: options.wallClockLimitS,\n },\n ttl_s: options.ttlS,\n tools: options.tools,\n});\n\nconst remove = async (api: ApiTransport, resource: string, id: string): Promise<void> => {\n await api({ method: HttpMethod.Delete, path: item(resource, id), schema: deletedSchema });\n};\n\nexport const createVmClient = (options: VmClientOptionsIface): VmClientIface => {\n const clock = options.clock ?? systemClock;\n const fetchImpl = options.fetch ?? globalThis.fetch;\n const api = createApiTransport({\n apiUrl: options.apiUrl ?? DEFAULT_API_URL,\n credential: options.apiKey,\n fetch: fetchImpl,\n requestTimeoutMs: options.requestTimeoutMs ?? 30_000,\n maxRetryWaitMs: options.maxRetryWaitMs ?? 30_000,\n clock,\n });\n const ctx = {\n api,\n fetch: fetchImpl,\n clock,\n previewDomain: options.previewDomain ?? DEFAULT_PREVIEW_DOMAIN,\n };\n const getImage = (id: string) =>\n api({ method: HttpMethod.Get, path: item('images', id), schema: imageSchema });\n\n return {\n sandboxes: {\n create: async (createOptions) => {\n const requestedAt = clock.now();\n const result = await api({\n method: HttpMethod.Post,\n path: '/sandboxes',\n // The id is chosen once, so a retry after a lost answer finds this sandbox.\n body: {\n sandbox_id: createOptions.sandboxId ?? newSandboxId(),\n ...createBody(createOptions),\n },\n schema: sandboxOpSchema,\n signal: createOptions.signal,\n idempotent: true,\n });\n return createSandboxHandle(ctx, result.sandbox, { grant: result.connect, requestedAt });\n },\n get: async (id) =>\n createSandboxHandle(\n ctx,\n await api({\n method: HttpMethod.Get,\n path: item('sandboxes', id),\n schema: sandboxInfoSchema,\n }),\n ),\n list: async (listOptions = {}) =>\n (\n await api({\n method: HttpMethod.Get,\n path: '/sandboxes',\n query: {\n state: listOptions.states?.join(','),\n labels:\n listOptions.labels == null || Object.keys(listOptions.labels).length === 0\n ? undefined\n : JSON.stringify(listOptions.labels),\n after: listOptions.after,\n limit: listOptions.limit,\n project_id: listOptions.projectId,\n },\n schema: sandboxListSchema,\n })\n ).sandboxes,\n },\n images: {\n create: (imageOptions) =>\n api({\n method: HttpMethod.Post,\n path: '/images',\n body: {\n project_id: imageOptions.projectId,\n reference: imageOptions.reference,\n },\n schema: imageSchema,\n }),\n get: getImage,\n list: async (listOptions = {}) =>\n (\n await api({\n method: HttpMethod.Get,\n path: '/images',\n query: { project_id: listOptions.projectId },\n schema: z.object({ images: z.array(imageSchema) }),\n })\n ).images,\n delete: (id) => remove(api, 'images', id),\n },\n templates: {\n create: (templateOptions) =>\n api({\n method: HttpMethod.Post,\n path: '/templates',\n body: {\n project_id: templateOptions.projectId,\n name: templateOptions.name,\n image_id: templateOptions.imageId,\n start_cmd: templateOptions.startCmd,\n ready_cmd: templateOptions.readyCmd,\n cpu: cpuBody(templateOptions.cpu),\n memory: memoryBody(templateOptions.memory),\n },\n schema: templateSchema,\n }),\n get: (id) =>\n api({ method: HttpMethod.Get, path: item('templates', id), schema: templateSchema }),\n list: async (listOptions = {}) =>\n (\n await api({\n method: HttpMethod.Get,\n path: '/templates',\n query: { project_id: listOptions.projectId },\n schema: z.object({ templates: z.array(templateSchema) }),\n })\n ).templates,\n delete: (id) => remove(api, 'templates', id),\n build: (id) =>\n api({\n method: HttpMethod.Post,\n path: `${item('templates', id)}/build`,\n body: {},\n schema: templateBuildSchema,\n }),\n },\n snapshots: {\n get: (id) =>\n api({ method: HttpMethod.Get, path: item('snapshots', id), schema: snapshotSchema }),\n list: async (listOptions = {}) =>\n (\n await api({\n method: HttpMethod.Get,\n path: '/snapshots',\n query: { project_id: listOptions.projectId },\n schema: z.object({ snapshots: z.array(snapshotSchema) }),\n })\n ).snapshots,\n delete: (id) => remove(api, 'snapshots', id),\n },\n machineTypes: createMachineTypesApi(api),\n };\n};\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAA+C;AACxD;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,YAAY,OAAO;AACnB,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB,kBAAqC;
|
|
4
|
+
"sourcesContent": ["import { workloadBody, type WorkloadOptionsIface } from \"./workload.mjs\";\nimport {\n createMachineTypesApi,\n machineBody,\n type MachineOptionsIface,\n type MachineTypesIface,\n} from \"./machines.mjs\";\nimport * as z from 'zod';\nimport { newSandboxId } from \"./ids.mjs\";\nimport { cpuBody, memoryBody, type CpuOption, type MemoryOption } from \"./size.mjs\";\nimport { createApiTransport, HttpMethod, labelQuery, type ApiTransport } from \"./api.mjs\";\nimport { createIngressRoutes, type IngressRoutesIface } from \"./routes.mjs\";\nimport { systemClock, type ClockIface } from \"./clock.mjs\";\nimport { createSandboxHandle, type SandboxIface } from \"./sandbox.mjs\";\nimport {\n cacheObjectSchema,\n cachePartsSchema,\n cacheReadSchema,\n cacheStartSchema,\n commitSchema,\n volumeSchema,\n type CacheObjectIface,\n type IdlePolicy,\n type MaxLifetimeBodyIface,\n type VolumeIface,\n type WorkloadBodyIface,\n} from \"./resources.mjs\";\nimport {\n deletedSchema,\n imageSchema,\n sandboxInfoSchema,\n sandboxListSchema,\n sandboxOpSchema,\n snapshotSchema,\n templateBuildSchema,\n templateSchema,\n type ImageIface,\n type SandboxInfoIface,\n type SnapshotIface,\n type TemplateBuildIface,\n type TemplateIface,\n} from \"./schemas.mjs\";\n\nexport const DEFAULT_API_URL = 'https://api.vm.finalwebservices.com';\nexport const DEFAULT_PREVIEW_DOMAIN = 'vm.finalwebservices.com';\n\nexport interface VmClientOptionsIface {\n // A Final API key.\n apiKey: string;\n apiUrl?: string;\n previewDomain?: string;\n requestTimeoutMs?: number;\n // How long API calls keep honouring `503 Retry-After` before failing.\n maxRetryWaitMs?: number;\n fetch?: typeof fetch;\n clock?: ClockIface;\n}\n\nexport enum SourceKind {\n Image = 'image',\n Snapshot = 'snapshot',\n Template = 'template',\n}\n\nexport type CreateSourceIface =\n | { kind: SourceKind.Image; imageId: string }\n | { kind: SourceKind.Snapshot; snapshotId: string }\n | { kind: SourceKind.Template; templateId: string };\n\n// Creates land in `projectId` (`prj_\u2026`), which the caller must be able to edit; without one, in\n// the caller's own project (an API key's parent project).\nexport interface ProjectScopeIface {\n projectId?: string;\n}\n\n// Lists return everything the caller can see; with `projectId`, only that project and the\n// projects below it.\nexport interface ListScopeIface {\n projectId?: string;\n}\n\nexport interface CreateSandboxOptionsIface extends ProjectScopeIface {\n // The id (`sbx_\u2026`) to create it under, for a caller that reserved one; the SDK mints one\n // otherwise. Either way a retried create names the same sandbox.\n sandboxId?: string;\n workload?: WorkloadOptionsIface;\n ephemeral?: boolean;\n // Without one, the platform's default image (base).\n source?: CreateSourceIface;\n cpu?: CpuOption;\n memory?: MemoryOption;\n diskGb?: number;\n // The machines it may run on, kept for every wake and move; absent: any, cheapest first.\n machine?: MachineOptionsIface;\n // Stored encrypted and handed to the workload at start.\n env?: Record<string, string>;\n ports?: number[];\n publicPorts?: number[];\n allowInternet?: boolean;\n allowCidrs?: string[];\n denyCidrs?: string[];\n allowDomains?: string[];\n labels?: Record<string, string>;\n // Null turns the idle timeout off.\n idleTimeoutS?: number | null;\n // What an idle sandbox (and one past its wall-clock limit) does.\n idlePolicy?: IdlePolicy;\n // A paused or stopped sandbox wakes when used.\n autoResume?: boolean;\n // Null turns the wall-clock limit off (organizations entitled to it only).\n wallClockLimitS?: number | null;\n ttlS?: number;\n // Stop or delete it after a time from create or its latest start, in any state; it replaces the\n // wall-clock limit. Not with `ttlS`.\n maxLifetime?: MaxLifetimeBodyIface;\n // How long it stays paused before it stops, at most the organization's setting.\n pausedRetentionS?: number;\n // Sandboxes sharing a placement group are placed near each other.\n placementGroup?: string;\n // Recorded with the sandbox's usage and logs.\n telemetryResource?: Record<string, string>;\n volumes?: { volumeId: string; path: string; allowCommit: boolean }[];\n // A raw workload, for callers that build one themselves.\n workloadBody?: WorkloadBodyIface;\n // Only the creating API key may change, capture or copy it.\n ownerSelf?: boolean;\n // Never deleted by the organization's retention policy (an entitlement).\n retentionExempt?: boolean;\n // Egress through the platform's own network (an entitlement).\n platformEgress?: boolean;\n cpuPool?: string;\n // Platform tools to run (`docker`), delivered as it starts; a template source adds its own.\n // A name that is not an available platform tool is refused (`unknown_tool`).\n tools?: string[];\n signal?: AbortSignal;\n}\n\nexport interface ListSandboxesOptionsIface extends ListScopeIface {\n states?: string[];\n // Only sandboxes carrying every one of these labels (filtered by the API).\n labels?: Record<string, string>;\n // The last id of the previous page.\n after?: string;\n limit?: number;\n}\n\nexport interface VmClientIface {\n ingressRoutes: IngressRoutesIface;\n sandboxes: {\n create: (options: CreateSandboxOptionsIface) => Promise<SandboxIface>;\n get: (id: string) => Promise<SandboxIface>;\n list: (options?: ListSandboxesOptionsIface) => Promise<SandboxInfoIface[]>;\n };\n images: {\n create: (options: ProjectScopeIface & { reference: string }) => Promise<ImageIface>;\n get: (id: string) => Promise<ImageIface>;\n list: (options?: ListScopeIface) => Promise<ImageIface[]>;\n delete: (id: string) => Promise<void>;\n };\n templates: {\n create: (\n options: ProjectScopeIface & {\n name: string;\n imageId: string;\n startCmd?: string;\n readyCmd?: string;\n warmupCmd?: string;\n cpu?: CpuOption;\n memory?: MemoryOption;\n tools?: string[];\n },\n ) => Promise<TemplateIface>;\n get: (id: string) => Promise<TemplateIface>;\n list: (options?: ListScopeIface) => Promise<TemplateIface[]>;\n delete: (id: string) => Promise<void>;\n build: (id: string) => Promise<TemplateBuildIface>;\n };\n snapshots: {\n get: (id: string) => Promise<SnapshotIface>;\n // Named snapshots; with `labels`, those carrying every one.\n list: (\n options?: ListScopeIface & { labels?: Record<string, string> },\n ) => Promise<SnapshotIface[]>;\n delete: (id: string) => Promise<void>;\n };\n machineTypes: MachineTypesIface;\n volumes: {\n create: (\n options: ProjectScopeIface & {\n name: string;\n sizeGb: number;\n expiresAfterUnusedS?: number;\n labels?: Record<string, string>;\n },\n ) => Promise<VolumeIface>;\n get: (id: string) => Promise<VolumeIface>;\n // With `labels`, the volumes carrying every one.\n list: (\n options?: ListScopeIface & { labels?: Record<string, string> },\n ) => Promise<VolumeIface[]>;\n delete: (id: string) => Promise<void>;\n commit: (\n id: string,\n commitId: string,\n ) => Promise<{ id: string; state: string; version: number | null }>;\n };\n caches: {\n // Refused (`cache_object_exists`) when the key holds a ready object, now or at completion.\n start: (options: {\n namespace: string;\n key: string;\n partCount: number;\n }) => Promise<{ object: CacheObjectIface; parts: { partNumber: number; url: string }[] }>;\n parts: (id: string, partNumbers: number[]) => Promise<{ partNumber: number; url: string }[]>;\n complete: (\n id: string,\n parts: { partNumber: number; etag: string }[],\n ) => Promise<CacheObjectIface>;\n get: (id: string) => Promise<CacheObjectIface>;\n delete: (id: string) => Promise<void>;\n lookup: (\n candidates: { namespace: string; key: string; prefix: boolean }[],\n ) => Promise<{ object: CacheObjectIface; url: string; urlExpiresAt: string | null } | null>;\n // Ready objects of a namespace whose keys start with `prefix`, in key order; `next` (the\n // last key) continues as `after`, null at the end.\n list: (options: {\n namespace: string;\n prefix?: string;\n after?: string;\n limit?: number;\n }) => Promise<{ objects: CacheObjectIface[]; next: string | null }>;\n };\n}\n\nconst partsOf = (parts: { part_number: number; url: string }[]) =>\n parts.map((part) => ({ partNumber: part.part_number, url: part.url }));\n\nconst item = (resource: string, id: string) => `/${resource}/${encodeURIComponent(id)}`;\n\nconst createBody = (options: CreateSandboxOptionsIface) => ({\n workload:\n options.workloadBody ?? (options.workload == null ? undefined : workloadBody(options.workload)),\n auto_resume: options.autoResume,\n idle_policy: options.idlePolicy,\n placement_group: options.placementGroup,\n telemetry_resource: options.telemetryResource,\n volumes: options.volumes?.map((volume) => ({\n volume_id: volume.volumeId,\n path: volume.path,\n allow_commit: volume.allowCommit,\n })),\n owner: options.ownerSelf === true ? 'self' : undefined,\n retention_exempt: options.retentionExempt,\n platform_egress: options.platformEgress,\n cpu_pool: options.cpuPool,\n ephemeral: options.ephemeral,\n project_id: options.projectId,\n source:\n options.source == null\n ? undefined\n : options.source.kind === SourceKind.Image\n ? { kind: SourceKind.Image, image_id: options.source.imageId }\n : options.source.kind === SourceKind.Snapshot\n ? { kind: SourceKind.Snapshot, snapshot_id: options.source.snapshotId }\n : { kind: SourceKind.Template, template_id: options.source.templateId },\n size: {\n cpu: cpuBody(options.cpu),\n memory: memoryBody(options.memory),\n disk_gb: options.diskGb,\n },\n machine: machineBody(options.machine),\n env: options.env,\n ports: options.ports,\n public_ports: options.publicPorts,\n allow_internet: options.allowInternet,\n allow_cidrs: options.allowCidrs,\n deny_cidrs: options.denyCidrs,\n allow_domains: options.allowDomains,\n labels: options.labels,\n timers: {\n idle_timeout_s: options.idleTimeoutS,\n wall_clock_limit_s: options.wallClockLimitS,\n },\n ttl_s: options.ttlS,\n max_lifetime: options.maxLifetime,\n paused_retention_s: options.pausedRetentionS,\n tools: options.tools,\n});\n\nconst remove = async (api: ApiTransport, resource: string, id: string): Promise<void> => {\n await api({ method: HttpMethod.Delete, path: item(resource, id), schema: deletedSchema });\n};\n\nexport const createVmClient = (options: VmClientOptionsIface): VmClientIface => {\n const clock = options.clock ?? systemClock;\n const fetchImpl = options.fetch ?? globalThis.fetch;\n const api = createApiTransport({\n apiUrl: options.apiUrl ?? DEFAULT_API_URL,\n credential: options.apiKey,\n fetch: fetchImpl,\n requestTimeoutMs: options.requestTimeoutMs ?? 30_000,\n maxRetryWaitMs: options.maxRetryWaitMs ?? 30_000,\n clock,\n });\n const ctx = {\n api,\n fetch: fetchImpl,\n clock,\n previewDomain: options.previewDomain ?? DEFAULT_PREVIEW_DOMAIN,\n };\n const getImage = (id: string) =>\n api({ method: HttpMethod.Get, path: item('images', id), schema: imageSchema });\n\n return {\n ingressRoutes: createIngressRoutes(api),\n sandboxes: {\n create: async (createOptions) => {\n const requestedAt = clock.now();\n const result = await api({\n method: HttpMethod.Post,\n path: '/sandboxes',\n // The id is chosen once, so a retry after a lost answer finds this sandbox.\n body: {\n sandbox_id: createOptions.sandboxId ?? newSandboxId(),\n ...createBody(createOptions),\n },\n schema: sandboxOpSchema,\n signal: createOptions.signal,\n idempotent: true,\n });\n return createSandboxHandle(ctx, result.sandbox, { grant: result.connect, requestedAt });\n },\n get: async (id) =>\n createSandboxHandle(\n ctx,\n await api({\n method: HttpMethod.Get,\n path: item('sandboxes', id),\n schema: sandboxInfoSchema,\n }),\n ),\n list: async (listOptions = {}) =>\n (\n await api({\n method: HttpMethod.Get,\n path: '/sandboxes',\n query: {\n state: listOptions.states?.join(','),\n labels:\n listOptions.labels == null || Object.keys(listOptions.labels).length === 0\n ? undefined\n : JSON.stringify(listOptions.labels),\n after: listOptions.after,\n limit: listOptions.limit,\n project_id: listOptions.projectId,\n },\n schema: sandboxListSchema,\n })\n ).sandboxes,\n },\n images: {\n create: (imageOptions) =>\n api({\n method: HttpMethod.Post,\n path: '/images',\n body: {\n project_id: imageOptions.projectId,\n reference: imageOptions.reference,\n },\n schema: imageSchema,\n }),\n get: getImage,\n list: async (listOptions = {}) =>\n (\n await api({\n method: HttpMethod.Get,\n path: '/images',\n query: { project_id: listOptions.projectId },\n schema: z.object({ images: z.array(imageSchema) }),\n })\n ).images,\n delete: (id) => remove(api, 'images', id),\n },\n templates: {\n create: (templateOptions) =>\n api({\n method: HttpMethod.Post,\n path: '/templates',\n body: {\n project_id: templateOptions.projectId,\n name: templateOptions.name,\n image_id: templateOptions.imageId,\n start_cmd: templateOptions.startCmd,\n ready_cmd: templateOptions.readyCmd,\n warmup_cmd: templateOptions.warmupCmd,\n tools: templateOptions.tools,\n cpu: cpuBody(templateOptions.cpu),\n memory: memoryBody(templateOptions.memory),\n },\n schema: templateSchema,\n }),\n get: (id) =>\n api({ method: HttpMethod.Get, path: item('templates', id), schema: templateSchema }),\n list: async (listOptions = {}) =>\n (\n await api({\n method: HttpMethod.Get,\n path: '/templates',\n query: { project_id: listOptions.projectId },\n schema: z.object({ templates: z.array(templateSchema) }),\n })\n ).templates,\n delete: (id) => remove(api, 'templates', id),\n build: (id) =>\n api({\n method: HttpMethod.Post,\n path: `${item('templates', id)}/build`,\n body: {},\n schema: templateBuildSchema,\n }),\n },\n snapshots: {\n get: (id) =>\n api({ method: HttpMethod.Get, path: item('snapshots', id), schema: snapshotSchema }),\n list: async (listOptions = {}) =>\n (\n await api({\n method: HttpMethod.Get,\n path: '/snapshots',\n query: {\n project_id: listOptions.projectId,\n label: labelQuery(listOptions.labels ?? {}),\n },\n schema: z.object({ snapshots: z.array(snapshotSchema) }),\n })\n ).snapshots,\n delete: (id) => remove(api, 'snapshots', id),\n },\n machineTypes: createMachineTypesApi(api),\n volumes: {\n create: (volumeOptions) =>\n api({\n method: HttpMethod.Post,\n path: '/volumes',\n body: {\n project_id: volumeOptions.projectId,\n name: volumeOptions.name,\n size_gb: volumeOptions.sizeGb,\n expires_after_unused_s: volumeOptions.expiresAfterUnusedS,\n labels: volumeOptions.labels,\n },\n schema: volumeSchema,\n }),\n get: (id) => api({ method: HttpMethod.Get, path: item('volumes', id), schema: volumeSchema }),\n list: async (listOptions = {}) =>\n (\n await api({\n method: HttpMethod.Get,\n path: '/volumes',\n query: {\n project_id: listOptions.projectId,\n label: labelQuery(listOptions.labels ?? {}),\n },\n schema: z.object({ volumes: z.array(volumeSchema) }),\n })\n ).volumes,\n delete: async (id) => {\n await api({ method: HttpMethod.Delete, path: item('volumes', id), schema: z.unknown() });\n },\n commit: async (id, commitId) => {\n const commit = await api({\n method: HttpMethod.Get,\n path: `${item('volumes', id)}/commits/${encodeURIComponent(commitId)}`,\n schema: commitSchema,\n });\n return { id: commit.id, state: commit.state, version: commit.version ?? null };\n },\n },\n caches: {\n start: async (startOptions) => {\n const started = await api({\n method: HttpMethod.Post,\n path: '/cache-objects',\n body: {\n namespace: startOptions.namespace,\n key: startOptions.key,\n if_absent: true,\n part_count: startOptions.partCount,\n },\n schema: cacheStartSchema,\n });\n return { object: started.object, parts: partsOf(started.parts) };\n },\n parts: async (id, partNumbers) =>\n partsOf(\n (\n await api({\n method: HttpMethod.Post,\n path: `${item('cache-objects', id)}/parts`,\n body: { part_numbers: partNumbers },\n schema: cachePartsSchema,\n })\n ).parts,\n ),\n complete: async (id, parts) =>\n (\n await api({\n method: HttpMethod.Post,\n path: `${item('cache-objects', id)}/complete`,\n body: {\n parts: parts.map((part) => ({ part_number: part.partNumber, etag: part.etag })),\n },\n idempotent: true,\n schema: z.object({ object: cacheObjectSchema }),\n })\n ).object,\n get: async (id) =>\n (\n await api({\n method: HttpMethod.Get,\n path: item('cache-objects', id),\n schema: z.object({ object: cacheObjectSchema }),\n })\n ).object,\n delete: async (id) => {\n await api({\n method: HttpMethod.Delete,\n path: item('cache-objects', id),\n schema: z.unknown(),\n });\n },\n lookup: async (candidates) => {\n const found = await api({\n method: HttpMethod.Post,\n path: '/cache-lookups',\n body: { candidates },\n schema: cacheReadSchema,\n });\n return found.object == null || found.url == null\n ? null\n : { object: found.object, url: found.url, urlExpiresAt: found.url_expires_at ?? null };\n },\n list: async (listOptions) => {\n const page = await api({\n method: HttpMethod.Get,\n path: '/cache-objects',\n query: {\n namespace: listOptions.namespace,\n prefix: listOptions.prefix,\n after_key: listOptions.after,\n limit: listOptions.limit,\n },\n schema: z.object({\n objects: z.array(cacheObjectSchema),\n next: z.string().nullable().optional(),\n }),\n });\n return { objects: page.objects, next: page.next ?? null };\n },\n },\n };\n};\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAA+C;AACxD;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,YAAY,OAAO;AACnB,SAAS,oBAAoB;AAC7B,SAAS,SAAS,kBAAqD;AACvE,SAAS,oBAAoB,YAAY,kBAAqC;AAC9E,SAAS,2BAAoD;AAC7D,SAAS,mBAAoC;AAC7C,SAAS,2BAA8C;AACvD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAMK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;A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AE,SAAS,KAAK,SAAS,MAAM,KAAK,QAAQ,KAAK;AAAA,MAC1D;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["SourceKind"]
|
|
7
7
|
}
|
|
@@ -8,6 +8,7 @@ export interface VmErrorIface extends Error {
|
|
|
8
8
|
status: number | null;
|
|
9
9
|
code: string;
|
|
10
10
|
retryAfterMs: number | null;
|
|
11
|
+
noCapacity: boolean;
|
|
11
12
|
}
|
|
12
13
|
interface VmErrorFieldsIface {
|
|
13
14
|
source: VmErrorSource;
|
|
@@ -15,6 +16,7 @@ interface VmErrorFieldsIface {
|
|
|
15
16
|
code: string;
|
|
16
17
|
message: string;
|
|
17
18
|
retryAfterMs?: number | null;
|
|
19
|
+
noCapacity?: boolean;
|
|
18
20
|
}
|
|
19
21
|
export declare const VM_ERROR_NAME = "VmError";
|
|
20
22
|
export declare const vmError: (fields: VmErrorFieldsIface) => VmErrorIface;
|
|
@@ -10,7 +10,8 @@ const vmError = (fields) => Object.assign(new Error(fields.message), {
|
|
|
10
10
|
source: fields.source,
|
|
11
11
|
status: fields.status,
|
|
12
12
|
code: fields.code,
|
|
13
|
-
retryAfterMs: fields.retryAfterMs ?? null
|
|
13
|
+
retryAfterMs: fields.retryAfterMs ?? null,
|
|
14
|
+
noCapacity: fields.noCapacity ?? false
|
|
14
15
|
});
|
|
15
16
|
const isVmError = (cause) => cause instanceof Error && cause.name === VM_ERROR_NAME && "code" in cause;
|
|
16
17
|
const parseRetryAfterMs = (value, now) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/vm/errors.ts"],
|
|
4
|
-
"sourcesContent": ["// Every failure the client reports: an HTTP answer from the API or the data plane, a protocol\n// violation, or a broken exec stream. `code` is the server's `error` field when it sent one.\n\nexport enum VmErrorSource {\n Api = 'api',\n Ingress = 'ingress',\n Exec = 'exec',\n}\n\nexport interface VmErrorIface extends Error {\n source: VmErrorSource;\n // HTTP status, or null when no answer arrived.\n status: number | null;\n code: string;\n // Milliseconds the server asked to wait before retrying.\n retryAfterMs: number | null;\n}\n\ninterface VmErrorFieldsIface {\n source: VmErrorSource;\n status: number | null;\n code: string;\n message: string;\n retryAfterMs?: number | null;\n}\n\nexport const VM_ERROR_NAME = 'VmError';\n\nexport const vmError = (fields: VmErrorFieldsIface): VmErrorIface =>\n Object.assign(new Error(fields.message), {\n name: VM_ERROR_NAME,\n source: fields.source,\n status: fields.status,\n code: fields.code,\n retryAfterMs: fields.retryAfterMs ?? null,\n });\n\nexport const isVmError = (cause: unknown): cause is VmErrorIface =>\n cause instanceof Error && cause.name === VM_ERROR_NAME && 'code' in cause;\n\n// `Retry-After` in seconds or as an HTTP date.\nexport const parseRetryAfterMs = (value: string | null, now: number): number | null => {\n if (value == null || value.trim() === '') return null;\n const seconds = Number(value);\n if (Number.isFinite(seconds)) return Math.max(0, seconds * 1000);\n const at = Date.parse(value);\n return Number.isFinite(at) ? Math.max(0, at - now) : null;\n};\n"],
|
|
5
|
-
"mappings": "AAGO,IAAK,gBAAL,kBAAKA,mBAAL;AACL,EAAAA,eAAA,SAAM;AACN,EAAAA,eAAA,aAAU;AACV,EAAAA,eAAA,UAAO;AAHG,SAAAA;AAAA,GAAA;
|
|
4
|
+
"sourcesContent": ["// Every failure the client reports: an HTTP answer from the API or the data plane, a protocol\n// violation, or a broken exec stream. `code` is the server's `error` field when it sent one.\n\nexport enum VmErrorSource {\n Api = 'api',\n Ingress = 'ingress',\n Exec = 'exec',\n}\n\nexport interface VmErrorIface extends Error {\n source: VmErrorSource;\n // HTTP status, or null when no answer arrived.\n status: number | null;\n code: string;\n // Milliseconds the server asked to wait before retrying.\n retryAfterMs: number | null;\n // The platform had no capacity for the request.\n noCapacity: boolean;\n}\n\ninterface VmErrorFieldsIface {\n source: VmErrorSource;\n status: number | null;\n code: string;\n message: string;\n retryAfterMs?: number | null;\n noCapacity?: boolean;\n}\n\nexport const VM_ERROR_NAME = 'VmError';\n\nexport const vmError = (fields: VmErrorFieldsIface): VmErrorIface =>\n Object.assign(new Error(fields.message), {\n name: VM_ERROR_NAME,\n source: fields.source,\n status: fields.status,\n code: fields.code,\n retryAfterMs: fields.retryAfterMs ?? null,\n noCapacity: fields.noCapacity ?? false,\n });\n\nexport const isVmError = (cause: unknown): cause is VmErrorIface =>\n cause instanceof Error && cause.name === VM_ERROR_NAME && 'code' in cause;\n\n// `Retry-After` in seconds or as an HTTP date.\nexport const parseRetryAfterMs = (value: string | null, now: number): number | null => {\n if (value == null || value.trim() === '') return null;\n const seconds = Number(value);\n if (Number.isFinite(seconds)) return Math.max(0, seconds * 1000);\n const at = Date.parse(value);\n return Number.isFinite(at) ? Math.max(0, at - now) : null;\n};\n"],
|
|
5
|
+
"mappings": "AAGO,IAAK,gBAAL,kBAAKA,mBAAL;AACL,EAAAA,eAAA,SAAM;AACN,EAAAA,eAAA,aAAU;AACV,EAAAA,eAAA,UAAO;AAHG,SAAAA;AAAA,GAAA;AA0BL,MAAM,gBAAgB;AAEtB,MAAM,UAAU,CAAC,WACtB,OAAO,OAAO,IAAI,MAAM,OAAO,OAAO,GAAG;AAAA,EACvC,MAAM;AAAA,EACN,QAAQ,OAAO;AAAA,EACf,QAAQ,OAAO;AAAA,EACf,MAAM,OAAO;AAAA,EACb,cAAc,OAAO,gBAAgB;AAAA,EACrC,YAAY,OAAO,cAAc;AACnC,CAAC;AAEI,MAAM,YAAY,CAAC,UACxB,iBAAiB,SAAS,MAAM,SAAS,iBAAiB,UAAU;AAG/D,MAAM,oBAAoB,CAAC,OAAsB,QAA+B;AACrF,MAAI,SAAS,QAAQ,MAAM,KAAK,MAAM,GAAI,QAAO;AACjD,QAAM,UAAU,OAAO,KAAK;AAC5B,MAAI,OAAO,SAAS,OAAO,EAAG,QAAO,KAAK,IAAI,GAAG,UAAU,GAAI;AAC/D,QAAM,KAAK,KAAK,MAAM,KAAK;AAC3B,SAAO,OAAO,SAAS,EAAE,IAAI,KAAK,IAAI,GAAG,KAAK,GAAG,IAAI;AACvD;",
|
|
6
6
|
"names": ["VmErrorSource"]
|
|
7
7
|
}
|
package/dist/modules/vm/exec.mjs
CHANGED
|
@@ -158,6 +158,7 @@ const runSession = async (transport, init, handlers) => {
|
|
|
158
158
|
const url = new URL(
|
|
159
159
|
`${current.origin.replace(/^http/, "ws")}/v1/sandboxes/${current.sandboxUuid}/exec`
|
|
160
160
|
);
|
|
161
|
+
if (init.autoResume === false) url.searchParams.set("auto_resume", "false");
|
|
161
162
|
if (processId != null) {
|
|
162
163
|
url.searchParams.set("process_id", processId);
|
|
163
164
|
url.searchParams.set("after_seq", String(lastSeq));
|
|
@@ -274,6 +275,7 @@ const startExec = async (transport, options) => runSession(
|
|
|
274
275
|
pty: options.pty,
|
|
275
276
|
timeout_ms: options.timeoutMs
|
|
276
277
|
},
|
|
278
|
+
autoResume: options.autoResume,
|
|
277
279
|
processId: null,
|
|
278
280
|
afterSeq: 0
|
|
279
281
|
},
|