sandcovery 0.5.0 → 0.6.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/README.md +13 -5
- package/dist/{Schema-fLas6rbA.mjs → Schema-CoX0a2_o.mjs} +133 -9
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/sandcovery-docker.mjs +1 -1
- package/dist/cli/sandcovery-kubectl.d.mts +1 -0
- package/dist/cli/sandcovery-kubectl.mjs +8 -0
- package/dist/{handlers-qYjkPftS.mjs → handlers-U3pqRNro.mjs} +13013 -11632
- package/dist/index.d.mts +42 -1
- package/dist/index.mjs +1 -1
- package/dist/{spec-cGDeWJ3v.mjs → port-forwarder-Du1VlKxg.mjs} +2301 -95
- package/dist/{src-zWk1RjrB.mjs → src-lrpT0LG_.mjs} +1178 -153
- package/dist/{start-B8ruSPVb.mjs → start-Dg7sRQ28.mjs} +35 -423
- package/dist/{telemetry-delivery-8t5RXWli.mjs → telemetry-delivery-BSGibWPJ.mjs} +3 -3
- package/dist/{types-ZqbGCXKy.d.mts → types-C7lGEXT5.d.mts} +110 -5
- package/dist/types.d.mts +2 -2
- package/package.json +7 -4
- package/dist/origin-5maEGWRg.mjs +0 -444
- package/dist/{telemetry-BYnuVdoZ.mjs → telemetry-DBPKT8Ap.mjs} +1 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { B as
|
|
2
|
-
import { A as CreditCheckout, B as MicroUsd, C as RoutingFields, E as Billing, F as CiJobId, H as Region, I as CredentialId, L as GpuType, N as Pricing, P as ApiKeyId, R as KeyId, S as ROUTING_FIELDS_TEXT, T as StandardSize, U as SandboxId, V as Provider, W as Timestamp, a as Key, b as ProviderPreferences, f as Port, g as SandboxSpec, h as SandboxList, i as CreatedKey, m as Sandbox, p as PortPreview, s as KeyList, t as API_PREFIX, u as CreateAttempt, v as Snapshot, w as Slug } from "./origin-5maEGWRg.mjs";
|
|
1
|
+
import { A as isBase64Url$1, B as makeFilter, E as decodeUnknownSync, F as isMaxLength, H as optionalKey, I as isMinLength, L as isMultipleOf, M as isGreaterThan, N as isGreaterThanOrEqualTo, O as fromJsonString, U as tag, _ as String$1, a as Finite, cr as isSome, d as Natural, f as NonEmptyArray, g as Record, h as Number$1, i as Error$1, j as isBetween, k as is, l as Literal, m as NullOr, n as Boolean, o as FiniteFromString, p as NonEmptyString, rr as getOrElse, s as Int, t as ArraySchema, u as Literals, v as Struct, w as decodeUnknownOption, x as annotateEncoded, y as Union, z as isUUID } from "./Schema-CoX0a2_o.mjs";
|
|
3
2
|
// ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/ErrorReporter.js
|
|
4
3
|
/**
|
|
5
4
|
* Defines the runtime property key used to mark an object error as ignored by error
|
|
@@ -37,6 +36,84 @@ import { A as CreditCheckout, B as MicroUsd, C as RoutingFields, E as Billing, F
|
|
|
37
36
|
* @since 4.0.0
|
|
38
37
|
*/
|
|
39
38
|
const ignore = "~effect/ErrorReporter/ignore";
|
|
39
|
+
// ../sandcovery-contract/src/primitives.ts
|
|
40
|
+
const PROVIDERS = [
|
|
41
|
+
"daytona",
|
|
42
|
+
"depot",
|
|
43
|
+
"e2b",
|
|
44
|
+
"upstash"
|
|
45
|
+
];
|
|
46
|
+
const PROVIDER_EXAMPLES = new Intl.ListFormat("en", { type: "disjunction" }).format(PROVIDERS.map((provider) => `\`${provider}\``));
|
|
47
|
+
const SLUG_CHARACTERS = /* @__PURE__ */ new Set("abcdefghijklmnopqrstuvwxyz0123456789-");
|
|
48
|
+
const isProviderName = (value) => value !== "" && value.split("").every((character) => SLUG_CHARACTERS.has(character));
|
|
49
|
+
const Provider = String$1.check(makeFilter(isProviderName, {
|
|
50
|
+
expected: "a provider name of lowercase letters, digits, and hyphens",
|
|
51
|
+
toJsonSchema: () => ({ minLength: 1 })
|
|
52
|
+
})).annotate({
|
|
53
|
+
description: `A provider name of lowercase letters, digits, and hyphens, such as ${PROVIDER_EXAMPLES}. The API adds providers over time, so a client accepts any such name and the API refuses one it does not serve.`,
|
|
54
|
+
examples: PROVIDERS,
|
|
55
|
+
identifier: "Provider"
|
|
56
|
+
});
|
|
57
|
+
const Region = NonEmptyString.annotate({
|
|
58
|
+
description: "A coarse region, such as `asia`, `eu`, or `us`. A sandbox runs in a data center of the routed provider inside that region. The API adds regions over time.",
|
|
59
|
+
examples: [
|
|
60
|
+
"asia",
|
|
61
|
+
"eu",
|
|
62
|
+
"us"
|
|
63
|
+
],
|
|
64
|
+
identifier: "Region"
|
|
65
|
+
});
|
|
66
|
+
const GpuType = NonEmptyString.annotate({
|
|
67
|
+
description: "A GPU model, such as `h100`, `b200`, `rtx-pro-6000`, or `mi355x`. The API adds types over time.",
|
|
68
|
+
examples: [
|
|
69
|
+
"b200",
|
|
70
|
+
"b300",
|
|
71
|
+
"h100",
|
|
72
|
+
"h200",
|
|
73
|
+
"mi355x",
|
|
74
|
+
"rtx-4090",
|
|
75
|
+
"rtx-5090",
|
|
76
|
+
"rtx-pro-6000"
|
|
77
|
+
],
|
|
78
|
+
identifier: "GpuType"
|
|
79
|
+
});
|
|
80
|
+
const isUtcTimestamp = makeFilter((value) => {
|
|
81
|
+
const at = Date.parse(value);
|
|
82
|
+
return Number.isFinite(at) && new Date(at).toISOString() === value;
|
|
83
|
+
}, {
|
|
84
|
+
expected: "a UTC timestamp such as 2026-11-08T11:20:00.000Z",
|
|
85
|
+
toJsonSchema: () => ({ format: "date-time" })
|
|
86
|
+
});
|
|
87
|
+
const Timestamp = String$1.check(isUtcTimestamp).annotate({ description: "A UTC instant with milliseconds and a `Z` suffix, such as `2026-11-08T11:20:00.000Z`." });
|
|
88
|
+
const MicroUsd = Natural.annotate({ description: "An amount in integer micro-dollars: 1,000,000 is 1 USD." });
|
|
89
|
+
const isUuidV7 = is(String$1.check(isUUID(7)));
|
|
90
|
+
const hasPrefixedUuid = (value, prefix) => value.startsWith(prefix) && isUuidV7(value.slice(prefix.length));
|
|
91
|
+
const prefixedId = (prefix, noun) => String$1.check(makeFilter((value) => hasPrefixedUuid(value, prefix), {
|
|
92
|
+
expected: `${prefix} followed by a UUID v7`,
|
|
93
|
+
toJsonSchema: () => ({})
|
|
94
|
+
})).annotate({ description: `${noun} ID: \`${prefix}\` followed by a UUID v7.` });
|
|
95
|
+
const SandboxId = prefixedId("sbx_", "Sandbox");
|
|
96
|
+
const SnapshotId = prefixedId("snap_", "Snapshot");
|
|
97
|
+
const CiJobId = prefixedId("cij_", "CI job");
|
|
98
|
+
const CredentialId = prefixedId("cred_", "Provider credential");
|
|
99
|
+
const ProcessId = prefixedId("proc_", "Process");
|
|
100
|
+
const UsageShareId = prefixedId("ush_", "Usage share");
|
|
101
|
+
const API_KEY_ID_PREFIX = "key_";
|
|
102
|
+
const MANAGEMENT_KEY_ID_PREFIX = "mkey_";
|
|
103
|
+
const ApiKeyId = prefixedId(API_KEY_ID_PREFIX, "API key");
|
|
104
|
+
const KeyId = String$1.check(makeFilter((value) => hasPrefixedUuid(value, API_KEY_ID_PREFIX) || hasPrefixedUuid(value, MANAGEMENT_KEY_ID_PREFIX), {
|
|
105
|
+
expected: `${API_KEY_ID_PREFIX} or ${MANAGEMENT_KEY_ID_PREFIX} followed by a UUID v7`,
|
|
106
|
+
toJsonSchema: () => ({})
|
|
107
|
+
})).annotate({ description: `Key ID: \`${API_KEY_ID_PREFIX}\` for an API key or \`${MANAGEMENT_KEY_ID_PREFIX}\` for a management key, followed by a UUID v7.` });
|
|
108
|
+
const SECRET_TEXT_LENGTH = 43;
|
|
109
|
+
const isBase64Url = is(String$1.check(isBase64Url$1()));
|
|
110
|
+
const API_KEY_SECRET_PREFIX = "sand_";
|
|
111
|
+
const MANAGEMENT_KEY_SECRET_PREFIX = "sandm_";
|
|
112
|
+
const hasPrefixedSecret = (value, prefix) => value.startsWith(prefix) && value.length === prefix.length + SECRET_TEXT_LENGTH && isBase64Url(value.slice(prefix.length));
|
|
113
|
+
const KeySecret = String$1.check(makeFilter((value) => hasPrefixedSecret(value, API_KEY_SECRET_PREFIX) || hasPrefixedSecret(value, MANAGEMENT_KEY_SECRET_PREFIX), {
|
|
114
|
+
expected: `${API_KEY_SECRET_PREFIX} or ${MANAGEMENT_KEY_SECRET_PREFIX} followed by 43 base64url characters`,
|
|
115
|
+
toJsonSchema: () => ({})
|
|
116
|
+
})).annotate({ description: `The key secret, returned once at creation: \`${API_KEY_SECRET_PREFIX}\` for an API key or \`${MANAGEMENT_KEY_SECRET_PREFIX}\` for a management key, followed by 32 random bytes as 43 unpadded base64url characters.` });
|
|
40
117
|
const ActivityAction = NonEmptyString.annotate({
|
|
41
118
|
description: "What happened, such as `sandbox.create`, `sandbox.create_attempt` for each provider tried, `sandbox.destroy`, or `sandbox.expire` at the TTL. The API adds actions over time.",
|
|
42
119
|
examples: [
|
|
@@ -67,6 +144,801 @@ const ActivityList = Struct({
|
|
|
67
144
|
data: ArraySchema(ActivityEvent),
|
|
68
145
|
next_cursor: NullOr(String$1)
|
|
69
146
|
}).annotate({ identifier: "ActivityList" });
|
|
147
|
+
// ../sandcovery-contract/src/errors/concurrency-limit-reached.ts
|
|
148
|
+
var ConcurrencyLimitReached = class extends Error$1("ConcurrencyLimitReached")({
|
|
149
|
+
concurrency_cap: Natural,
|
|
150
|
+
error: tag("concurrency_limit_reached"),
|
|
151
|
+
message: String$1
|
|
152
|
+
}, {
|
|
153
|
+
description: "The API key already has `concurrency_cap` live sandboxes, its `max_concurrent_sandboxes`. Destroy one or wait for one to end.",
|
|
154
|
+
httpApiStatus: 429,
|
|
155
|
+
identifier: "ConcurrencyLimitReached"
|
|
156
|
+
}) {
|
|
157
|
+
[ignore] = true;
|
|
158
|
+
};
|
|
159
|
+
// ../sandcovery-contract/src/errors/conflict.ts
|
|
160
|
+
var Conflict = class extends Error$1("Conflict")({
|
|
161
|
+
error: tag("conflict"),
|
|
162
|
+
message: String$1
|
|
163
|
+
}, {
|
|
164
|
+
description: "The request clashes with the current state, such as an `Idempotency-Key` reused with a different body, a call on a sandbox that is not running, or deleting a provider credential that live sandboxes still use.",
|
|
165
|
+
httpApiStatus: 409,
|
|
166
|
+
identifier: "Conflict"
|
|
167
|
+
}) {
|
|
168
|
+
[ignore] = true;
|
|
169
|
+
};
|
|
170
|
+
// ../sandcovery-contract/src/errors/forbidden.ts
|
|
171
|
+
var Forbidden = class extends Error$1("Forbidden")({
|
|
172
|
+
error: tag("forbidden"),
|
|
173
|
+
message: String$1
|
|
174
|
+
}, {
|
|
175
|
+
description: "The credential is valid but may not make this call, such as a management key on a sandbox, an API key on keys, usage, or provider credentials, a member who is not an owner on keys, a member who is not an owner or admin on usage or provider credentials, a signed-in member who is not an owner or admin, or their agent, on sandbox create, a management key whose minting owner is no longer an owner on keys, or a TTL over the API key's `max_ttl_seconds`. `message` names the rule.",
|
|
176
|
+
httpApiStatus: 403,
|
|
177
|
+
identifier: "Forbidden"
|
|
178
|
+
}) {
|
|
179
|
+
[ignore] = true;
|
|
180
|
+
};
|
|
181
|
+
// ../sandcovery-contract/src/errors/invalid-request.ts
|
|
182
|
+
var InvalidRequest = class extends Error$1("InvalidRequest")({
|
|
183
|
+
error: tag("invalid_request"),
|
|
184
|
+
message: String$1
|
|
185
|
+
}, {
|
|
186
|
+
description: "The path, query, headers, or body do not decode against the operation, or contradict each other, and `message` names the failure.",
|
|
187
|
+
httpApiStatus: 400,
|
|
188
|
+
identifier: "InvalidRequest"
|
|
189
|
+
}) {
|
|
190
|
+
[ignore] = true;
|
|
191
|
+
};
|
|
192
|
+
const StandardSize = NonEmptyString.annotate({
|
|
193
|
+
description: "A standard size named `<vCPU>x<memory GiB>`, such as `1x2`, `2x4`, `4x8`, or `8x16`. The API adds sizes over time.",
|
|
194
|
+
examples: [
|
|
195
|
+
{
|
|
196
|
+
memory_mib: 2048,
|
|
197
|
+
name: "1x2",
|
|
198
|
+
vcpu: 1
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
memory_mib: 4096,
|
|
202
|
+
name: "2x4",
|
|
203
|
+
vcpu: 2
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
memory_mib: 8192,
|
|
207
|
+
name: "4x8",
|
|
208
|
+
vcpu: 4
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
memory_mib: 16384,
|
|
212
|
+
name: "8x16",
|
|
213
|
+
vcpu: 8
|
|
214
|
+
}
|
|
215
|
+
].map(({ name }) => name),
|
|
216
|
+
identifier: "StandardSize"
|
|
217
|
+
});
|
|
218
|
+
const ProviderSort = Literals([
|
|
219
|
+
"latency",
|
|
220
|
+
"price",
|
|
221
|
+
"uptime"
|
|
222
|
+
]).annotate({
|
|
223
|
+
description: "Candidate order: `price` by list price, `latency` by measured create latency, and `uptime` by uptime over the last 15 minutes, or over a provider's own probe interval where it is probed less often.",
|
|
224
|
+
identifier: "ProviderSort"
|
|
225
|
+
});
|
|
226
|
+
const ROUTER = "sandcovery";
|
|
227
|
+
const DEFAULT_SLUG = `${ROUTER}/2x4`;
|
|
228
|
+
const MIB_PER_GIB = 1024;
|
|
229
|
+
const ANY = "n";
|
|
230
|
+
const vcpusOf = (text) => {
|
|
231
|
+
if (text === ANY) return null;
|
|
232
|
+
const value = Number(text);
|
|
233
|
+
return Number.isSafeInteger(value) && value > 0 && String(value) === text ? value : void 0;
|
|
234
|
+
};
|
|
235
|
+
const memoryGibOf = (text) => {
|
|
236
|
+
if (text === ANY) return null;
|
|
237
|
+
const value = Number(text);
|
|
238
|
+
return String(value) === text && value > 0 && Number.isSafeInteger(value * MIB_PER_GIB) ? value : void 0;
|
|
239
|
+
};
|
|
240
|
+
const parseSlug = (text) => {
|
|
241
|
+
const [provider = "", size = "", ...extraPaths] = text.split("/");
|
|
242
|
+
const [dimensions = "", suffix, ...extraSuffixes] = size.split(":");
|
|
243
|
+
const [vcpuText = "", memoryText = "", ...extraParts] = dimensions.split("x");
|
|
244
|
+
if (extraPaths.length + extraSuffixes.length + extraParts.length > 0 || suffix === "" || !isProviderName(provider)) return;
|
|
245
|
+
const vcpus = vcpusOf(vcpuText);
|
|
246
|
+
const memoryGib = memoryGibOf(memoryText);
|
|
247
|
+
return vcpus === void 0 || memoryGib === void 0 ? void 0 : {
|
|
248
|
+
memoryGib,
|
|
249
|
+
provider,
|
|
250
|
+
suffix: suffix ?? null,
|
|
251
|
+
vcpus
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
const isSizeName = (text) => {
|
|
255
|
+
const parsed = parseSlug(`${ROUTER}/${text}`);
|
|
256
|
+
return parsed !== void 0 && parsed.suffix === null && parsed.vcpus !== null && parsed.memoryGib !== null;
|
|
257
|
+
};
|
|
258
|
+
const SizeName = String$1.check(makeFilter(isSizeName, {
|
|
259
|
+
expected: "<vcpu>x<memory_gib>, such as 2x4 or 2x0.5",
|
|
260
|
+
toJsonSchema: () => ({ minLength: 1 })
|
|
261
|
+
}));
|
|
262
|
+
const SLUG_EXAMPLES = [
|
|
263
|
+
`${ROUTER}/2x4`,
|
|
264
|
+
`${ROUTER}/2x4:cheapest`,
|
|
265
|
+
`${ROUTER}/nx16:cheapest`,
|
|
266
|
+
`${ROUTER}/2xn:fastest`,
|
|
267
|
+
`${ROUTER}/nxn:most-reliable`,
|
|
268
|
+
"boat/2x4",
|
|
269
|
+
"e2b/2x0.5"
|
|
270
|
+
];
|
|
271
|
+
const Slug = String$1.check(makeFilter((text) => parseSlug(text) !== void 0, {
|
|
272
|
+
expected: "<provider>/<vcpu>x<memory_gib>, optionally followed by a routing suffix",
|
|
273
|
+
toJsonSchema: () => ({ minLength: 1 })
|
|
274
|
+
})).annotate({
|
|
275
|
+
description: `A provider and size, written \`<provider>/<vcpu>x<memory_gib>\` and optionally followed by a routing suffix, in the shape of OpenRouter model slugs. A provider name such as \`boat\` or \`e2b\` pins that provider, and \`${ROUTER}\` routes across every candidate provider. \`2x4\` is 2 vCPU and 4 GiB, and memory may be any whole number of MiB written in GiB, such as \`2x0.5\` or \`2x1.5\`. Either number may be \`n\`, meaning any value: \`nx16\` is any vCPU count with 16 GiB, \`2xn\` is 2 vCPU with any memory, and \`nxn\` is any size, and each provider then runs its cheapest size that matches. \`:cheapest\` sorts candidates by list price, \`:fastest\` by measured create latency, and \`:most-reliable\` by uptime over the last 15 minutes, or over a provider's own probe interval where it is probed less often. A slug with no suffix routes as \`:cheapest\`. A malformed slug or an unknown suffix answers 400 \`invalid_request\`, and a slug that no candidate provider can run answers 422 \`unsupported\`, listing slugs that would run as \`options\`.`,
|
|
276
|
+
examples: SLUG_EXAMPLES,
|
|
277
|
+
identifier: "Slug"
|
|
278
|
+
});
|
|
279
|
+
const ROUTING_FIELDS_TEXT = `\`slug\` is the provider and size to run, as OpenRouter takes \`model\`, and \`slugs\` lists slugs to try in order, as OpenRouter takes \`models\`. With both, \`slug\` is tried first. With neither, the slug is \`${DEFAULT_SLUG}\`.`;
|
|
280
|
+
const RoutingFields = {
|
|
281
|
+
slug: optionalKey(Slug),
|
|
282
|
+
slugs: optionalKey(ArraySchema(Slug).check(isMinLength(1), isMaxLength(8)).annotate({ description: `Slugs to try in order, from 1 to ${String(8)}, as OpenRouter takes \`models\`. Within a \`${ROUTER}/\` slug, a failed create (capacity, quota, a provider 5xx, or a timeout) first falls back across that slug's candidates, then the create moves to the next slug. A provider is tried at most once a create, at the size of the first slug that reaches it.` }))
|
|
283
|
+
};
|
|
284
|
+
const ProviderPreferences = Struct({
|
|
285
|
+
allow_fallbacks: optionalKey(Boolean.annotate({ description: "Whether a failed create (capacity, quota, a provider 5xx, or a timeout) moves to the next candidate of the same slug. Defaults to true. With false, each slug tries only its first candidate, and the create still moves on to the next slug." })),
|
|
286
|
+
ignore: optionalKey(ArraySchema(Provider).annotate({ description: "Providers never to route to." })),
|
|
287
|
+
only: optionalKey(ArraySchema(Provider).annotate({ description: "The only providers to route to." })),
|
|
288
|
+
order: optionalKey(ArraySchema(Provider).annotate({ description: `Providers a \`${ROUTER}/\` slug tries first, in this order, before its remaining candidates in sorted order.` })),
|
|
289
|
+
sort: optionalKey(ProviderSort)
|
|
290
|
+
}).annotate({
|
|
291
|
+
description: `Routing preferences in the shape of OpenRouter provider preferences, applied to every slug: \`only\`, \`ignore\`, and the API key's provider allowlist filter each slug's candidates. A slug's suffix sets \`sort\` for that slug, and a slug whose suffix disagrees with \`sort\` answers 400 \`invalid_request\`.`,
|
|
292
|
+
identifier: "ProviderPreferences"
|
|
293
|
+
});
|
|
294
|
+
// ../sandcovery-contract/src/sandbox.ts
|
|
295
|
+
const MAX_TTL_SECONDS = 86400;
|
|
296
|
+
const MAX_PORT = 65535;
|
|
297
|
+
const MAX_PORTS = 8;
|
|
298
|
+
const MAX_GPUS = 8;
|
|
299
|
+
const between = (minimum, maximum) => Int.check(isBetween({
|
|
300
|
+
maximum,
|
|
301
|
+
minimum
|
|
302
|
+
}));
|
|
303
|
+
const Port = between(1, MAX_PORT);
|
|
304
|
+
const Gpu = Struct({
|
|
305
|
+
count: between(1, MAX_GPUS).annotate({ description: "How many GPUs of `type` the sandbox gets, from 1 to 8." }),
|
|
306
|
+
type: GpuType
|
|
307
|
+
}).annotate({
|
|
308
|
+
description: "GPUs for the sandbox. It runs only on a provider that runs `count` GPUs of `type`, which picks the sandbox's region itself, so a GPU sandbox takes no `region`. Its list price adds each GPU's hourly price to the price of its size.",
|
|
309
|
+
identifier: "Gpu"
|
|
310
|
+
});
|
|
311
|
+
const EnvironmentVariables = Record(NonEmptyString, String$1).annotate({ description: "Environment variables by name. Sandcovery passes them to the provider and never returns them." });
|
|
312
|
+
const EgressPolicy = Union([
|
|
313
|
+
Struct({ mode: Literal("allow_all") }),
|
|
314
|
+
Struct({ mode: Literal("deny_all") }),
|
|
315
|
+
Struct({
|
|
316
|
+
destinations: NonEmptyArray(NonEmptyString).annotate({ description: "Host names or CIDR blocks the sandbox may reach." }),
|
|
317
|
+
mode: Literal("allowlist")
|
|
318
|
+
})
|
|
319
|
+
]).annotate({
|
|
320
|
+
description: "Outbound network access: `allow_all`, `deny_all`, or `allowlist` with the destinations the sandbox may reach.",
|
|
321
|
+
identifier: "EgressPolicy"
|
|
322
|
+
});
|
|
323
|
+
const SandboxSpec = Struct({
|
|
324
|
+
disk_mib: optionalKey(Int.check(isGreaterThanOrEqualTo(1024)).annotate({ description: "Disk size in MiB. Defaults to the provider default." })),
|
|
325
|
+
egress: optionalKey(EgressPolicy),
|
|
326
|
+
env: optionalKey(EnvironmentVariables),
|
|
327
|
+
gpu: optionalKey(Gpu),
|
|
328
|
+
idle_timeout_seconds: optionalKey(Int.check(isGreaterThanOrEqualTo(60)).annotate({ description: "Seconds without a running command after which the provider pauses the sandbox. Unset means no idle timeout." })),
|
|
329
|
+
image: optionalKey(NonEmptyString.annotate({ description: "An OCI image reference. Unset means the provider's default Linux image." })),
|
|
330
|
+
ports: optionalKey(ArraySchema(Port).check(isMaxLength(MAX_PORTS)).annotate({ description: "Ports to expose for preview URLs. Some providers expose only ports declared at create." })),
|
|
331
|
+
region: optionalKey(Region),
|
|
332
|
+
ttl_seconds: optionalKey(between(60, MAX_TTL_SECONDS).annotate({ description: "Seconds from creation after which Sandcovery destroys the sandbox, even when the client is gone. Defaults to 3600, and the API key may cap it lower." }))
|
|
333
|
+
});
|
|
334
|
+
const CreateSandboxRequest = Struct({
|
|
335
|
+
...SandboxSpec.fields,
|
|
336
|
+
...RoutingFields,
|
|
337
|
+
provider: optionalKey(ProviderPreferences),
|
|
338
|
+
snapshot_id: optionalKey(SnapshotId.annotate({ description: "A snapshot to start from. The sandbox runs on the snapshot's provider." }))
|
|
339
|
+
}).annotate({
|
|
340
|
+
description: `A sandbox spec, the slug or slugs to run it on, and routing preferences. ${ROUTING_FIELDS_TEXT} A spec option that no candidate provider can enforce answers 422 \`unsupported\` and is never ignored.`,
|
|
341
|
+
identifier: "CreateSandboxRequest"
|
|
342
|
+
});
|
|
343
|
+
const CreateAttempt = Struct({
|
|
344
|
+
duration_ms: Natural,
|
|
345
|
+
failure: NullOr(Struct({
|
|
346
|
+
message: String$1,
|
|
347
|
+
reason: Literals([
|
|
348
|
+
"capacity",
|
|
349
|
+
"quota",
|
|
350
|
+
"rejected",
|
|
351
|
+
"server_error",
|
|
352
|
+
"timeout"
|
|
353
|
+
]).annotate({ identifier: "CreateFailureReason" })
|
|
354
|
+
}).annotate({ description: "Why the attempt failed: `capacity`, `quota`, `server_error` (a provider 5xx), and `timeout` fall back to the next candidate when `allow_fallbacks` is not false, while `rejected` (any other provider refusal, such as an invalid credential) stops the create, which answers 502 `provider_error` naming that provider." })),
|
|
355
|
+
provider: Provider,
|
|
356
|
+
started_at: Timestamp
|
|
357
|
+
}).annotate({
|
|
358
|
+
description: "One provider create call made while routing a sandbox. `failure` is null on the attempt that created it.",
|
|
359
|
+
identifier: "CreateAttempt"
|
|
360
|
+
});
|
|
361
|
+
const SandboxStatus = Literals([
|
|
362
|
+
"creating",
|
|
363
|
+
"destroyed",
|
|
364
|
+
"destroying",
|
|
365
|
+
"failed",
|
|
366
|
+
"paused",
|
|
367
|
+
"running"
|
|
368
|
+
]).annotate({ identifier: "SandboxStatus" });
|
|
369
|
+
const SandboxEndReason = Literals([
|
|
370
|
+
"create_failed",
|
|
371
|
+
"destroyed",
|
|
372
|
+
"expired",
|
|
373
|
+
"gone"
|
|
374
|
+
]).annotate({
|
|
375
|
+
description: "Why the sandbox ended: `create_failed` when no create attempt succeeded, `destroyed` by a destroy call, `expired` at its TTL, or `gone` when the provider no longer had it.",
|
|
376
|
+
identifier: "SandboxEndReason"
|
|
377
|
+
});
|
|
378
|
+
const SandboxCost = Struct({
|
|
379
|
+
estimated_micro_usd: MicroUsd.annotate({ description: "Estimated list-price cost so far, from the rate card, until the sandbox is destroyed." }),
|
|
380
|
+
hourly_micro_usd: MicroUsd,
|
|
381
|
+
rate_card_version: String$1
|
|
382
|
+
}).annotate({
|
|
383
|
+
description: "Estimated cost at the provider's list price from a versioned rate card. The provider bills your own account.",
|
|
384
|
+
identifier: "SandboxCost"
|
|
385
|
+
});
|
|
386
|
+
const Sandbox = Struct({
|
|
387
|
+
api_key_id: NullOr(ApiKeyId).annotate({ description: "The API key that created the sandbox, or null when an organization owner or admin created it while signed in, or their agent did on their session." }),
|
|
388
|
+
attempts: ArraySchema(CreateAttempt),
|
|
389
|
+
cost: SandboxCost,
|
|
390
|
+
created_at: Timestamp,
|
|
391
|
+
disk_mib: NullOr(Natural),
|
|
392
|
+
egress: EgressPolicy,
|
|
393
|
+
end_reason: NullOr(SandboxEndReason),
|
|
394
|
+
ended_at: NullOr(Timestamp),
|
|
395
|
+
expires_at: Timestamp,
|
|
396
|
+
gpu: NullOr(Gpu),
|
|
397
|
+
id: SandboxId,
|
|
398
|
+
idle_timeout_seconds: NullOr(Natural),
|
|
399
|
+
image: NullOr(String$1),
|
|
400
|
+
memory_mib: Natural.annotate({ description: "Memory of the bound size, or of the first candidate's size while the sandbox is creating or after every create attempt failed." }),
|
|
401
|
+
ports: ArraySchema(Port),
|
|
402
|
+
provider: NullOr(Provider).annotate({ description: "The provider the sandbox is bound to, or null while it is creating or when every create attempt failed." }),
|
|
403
|
+
provider_sandbox_id: NullOr(String$1),
|
|
404
|
+
region: NullOr(Region),
|
|
405
|
+
slug: NullOr(Slug).annotate({ description: "The provider and size the sandbox runs on, such as `boat/2x4`, as OpenRouter answers the `model` it used, or null while it is creating or when every create attempt failed." }),
|
|
406
|
+
started_at: NullOr(Timestamp).annotate({ description: "When the provider reported the sandbox running." }),
|
|
407
|
+
status: SandboxStatus,
|
|
408
|
+
ttl_seconds: Natural,
|
|
409
|
+
vcpu: Natural.annotate({ description: "vCPU count of the bound size, or of the first candidate's size while the sandbox is creating or after every create attempt failed." })
|
|
410
|
+
}).annotate({
|
|
411
|
+
description: "A sandbox, bound to the provider that created it. `expires_at` is when Sandcovery destroys it, and pausing does not move it. `ended_at` and `end_reason` are set once it ends.",
|
|
412
|
+
identifier: "Sandbox"
|
|
413
|
+
});
|
|
414
|
+
const SandboxList = Struct({
|
|
415
|
+
data: ArraySchema(Sandbox),
|
|
416
|
+
next_cursor: NullOr(String$1)
|
|
417
|
+
}).annotate({ identifier: "SandboxList" });
|
|
418
|
+
const Snapshot = Struct({
|
|
419
|
+
created_at: Timestamp,
|
|
420
|
+
id: SnapshotId,
|
|
421
|
+
provider: Provider,
|
|
422
|
+
sandbox_id: SandboxId
|
|
423
|
+
}).annotate({
|
|
424
|
+
description: "A snapshot of a sandbox filesystem. A sandbox created from it runs on the same provider.",
|
|
425
|
+
identifier: "Snapshot"
|
|
426
|
+
});
|
|
427
|
+
const PortPreview = Struct({
|
|
428
|
+
expires_at: NullOr(Timestamp),
|
|
429
|
+
headers: Record(String$1, String$1).annotate({ description: "Headers a request to `url` must carry, such as a provider preview token. Often empty." }),
|
|
430
|
+
port: Port,
|
|
431
|
+
url: String$1
|
|
432
|
+
}).annotate({
|
|
433
|
+
description: "A provider URL that reaches a port inside the sandbox.",
|
|
434
|
+
identifier: "PortPreview"
|
|
435
|
+
});
|
|
436
|
+
// ../sandcovery-contract/src/errors/no-provider-available.ts
|
|
437
|
+
var NoProviderAvailable = class extends Error$1("NoProviderAvailable")({
|
|
438
|
+
attempts: ArraySchema(CreateAttempt).annotate({ description: "Every create attempt, in order. Empty when no provider was a candidate, such as when none has a stored credential." }),
|
|
439
|
+
error: tag("no_provider_available"),
|
|
440
|
+
message: String$1
|
|
441
|
+
}, {
|
|
442
|
+
description: "Every candidate provider failed to create the sandbox, or none was left after filtering.",
|
|
443
|
+
httpApiStatus: 503,
|
|
444
|
+
identifier: "NoProviderAvailable"
|
|
445
|
+
}) {};
|
|
446
|
+
// ../sandcovery-contract/src/errors/not-found.ts
|
|
447
|
+
var NotFound = class extends Error$1("NotFound")({
|
|
448
|
+
error: tag("not_found"),
|
|
449
|
+
message: String$1
|
|
450
|
+
}, {
|
|
451
|
+
description: "The resource the path names does not exist or belongs to another organization or key.",
|
|
452
|
+
httpApiStatus: 404,
|
|
453
|
+
identifier: "NotFound"
|
|
454
|
+
}) {
|
|
455
|
+
[ignore] = true;
|
|
456
|
+
};
|
|
457
|
+
// ../sandcovery-contract/src/errors/provider-error.ts
|
|
458
|
+
var ProviderError = class extends Error$1("ProviderError")({
|
|
459
|
+
error: tag("provider_error"),
|
|
460
|
+
message: String$1,
|
|
461
|
+
provider: Provider
|
|
462
|
+
}, {
|
|
463
|
+
description: "The sandbox's provider failed the call. `message` carries the provider's reason.",
|
|
464
|
+
httpApiStatus: 502,
|
|
465
|
+
identifier: "ProviderError"
|
|
466
|
+
}) {};
|
|
467
|
+
// ../sandcovery-contract/src/errors/rate-limited.ts
|
|
468
|
+
var RateLimited = class extends Error$1("RateLimited")({
|
|
469
|
+
error: tag("rate_limited"),
|
|
470
|
+
message: String$1
|
|
471
|
+
}, {
|
|
472
|
+
description: "The caller sent this operation more requests than its limit allows, such as more than 3 problem reports a minute. Wait a minute and try again.",
|
|
473
|
+
httpApiStatus: 429,
|
|
474
|
+
identifier: "RateLimited"
|
|
475
|
+
}) {
|
|
476
|
+
[ignore] = true;
|
|
477
|
+
};
|
|
478
|
+
// ../sandcovery-contract/src/errors/spend-limit-reached.ts
|
|
479
|
+
var SpendLimitReached = class extends Error$1("SpendLimitReached")({
|
|
480
|
+
error: tag("spend_limit_reached"),
|
|
481
|
+
limit_micro_usd: MicroUsd,
|
|
482
|
+
message: String$1,
|
|
483
|
+
resets_at: NullOr(Timestamp),
|
|
484
|
+
spent_micro_usd: MicroUsd
|
|
485
|
+
}, {
|
|
486
|
+
description: "The API key's spend limit leaves too little for the sandbox's full TTL at list price. `resets_at` is when the window resets, or null for a `total` limit.",
|
|
487
|
+
httpApiStatus: 402,
|
|
488
|
+
identifier: "SpendLimitReached"
|
|
489
|
+
}) {
|
|
490
|
+
[ignore] = true;
|
|
491
|
+
};
|
|
492
|
+
// ../sandcovery-contract/src/errors/unauthorized.ts
|
|
493
|
+
var Unauthorized = class extends Error$1("Unauthorized")({
|
|
494
|
+
error: tag("unauthorized"),
|
|
495
|
+
message: String$1
|
|
496
|
+
}, {
|
|
497
|
+
description: "The request carries no live key and no signed-in session, or a key that is unknown, revoked, or expired.",
|
|
498
|
+
httpApiStatus: 401,
|
|
499
|
+
identifier: "Unauthorized"
|
|
500
|
+
}) {
|
|
501
|
+
[ignore] = true;
|
|
502
|
+
};
|
|
503
|
+
// ../sandcovery-contract/src/errors/unsupported.ts
|
|
504
|
+
var Unsupported = class extends Error$1("Unsupported")({
|
|
505
|
+
error: tag("unsupported"),
|
|
506
|
+
message: String$1,
|
|
507
|
+
options: ArraySchema(String$1).annotate({ description: "Slugs that would run for this request: each refused slug at the sizes its candidates run, then, for a slug that pins a provider, the `sandcovery/` slug at the size it asked for. Empty when nothing near the refused slugs would run, such as a spec field no candidate provider can enforce or an operation the bound provider lacks, and then `message` names that field or operation." }),
|
|
508
|
+
provider: NullOr(Provider).annotate({ description: "The sandbox's provider for an operation on an existing sandbox, or null for a create." })
|
|
509
|
+
}, {
|
|
510
|
+
description: "A slug, spec option, or operation that no candidate provider can serve. Sandcovery never ignores an option. For a slug, `options` lists slugs that would run; otherwise `options` is empty and `message` names the field or operation.",
|
|
511
|
+
httpApiStatus: 422,
|
|
512
|
+
identifier: "Unsupported"
|
|
513
|
+
}) {
|
|
514
|
+
[ignore] = true;
|
|
515
|
+
};
|
|
516
|
+
// ../sandcovery-contract/src/errors/api-error.ts
|
|
517
|
+
const ApiError = Union([
|
|
518
|
+
ConcurrencyLimitReached,
|
|
519
|
+
Conflict,
|
|
520
|
+
Forbidden,
|
|
521
|
+
InvalidRequest,
|
|
522
|
+
NoProviderAvailable,
|
|
523
|
+
NotFound,
|
|
524
|
+
ProviderError,
|
|
525
|
+
RateLimited,
|
|
526
|
+
SpendLimitReached,
|
|
527
|
+
Unauthorized,
|
|
528
|
+
Unsupported
|
|
529
|
+
]);
|
|
530
|
+
// ../sandcovery-contract/src/attach.ts
|
|
531
|
+
const ATTACH_PROTOCOL = "sandcovery-attach-v1";
|
|
532
|
+
const STDIN = 0;
|
|
533
|
+
const STDOUT = 1;
|
|
534
|
+
const STDERR = 2;
|
|
535
|
+
const HEADER_BYTES = 9;
|
|
536
|
+
const CHUNK_BYTES = 65536;
|
|
537
|
+
const UNACKNOWLEDGED_LIMIT_BYTES = 8388608;
|
|
538
|
+
const NORMAL_CLOSURE = 1e3;
|
|
539
|
+
const REPLACED = 4e3;
|
|
540
|
+
const RETRY_MS = [
|
|
541
|
+
250,
|
|
542
|
+
1e3,
|
|
543
|
+
2e3,
|
|
544
|
+
5e3
|
|
545
|
+
];
|
|
546
|
+
const CHECK_MS = 15e3;
|
|
547
|
+
const LOST = "The sandbox ended before the process reported an exit, so its exit is unknown.";
|
|
548
|
+
const REPLACED_MESSAGE = "Another client attached to the process, which detached this one.";
|
|
549
|
+
const ABORTED = "The attach was aborted.";
|
|
550
|
+
const OUTPUT_NAMES = /* @__PURE__ */ new Map([[STDOUT, "stdout"], [STDERR, "stderr"]]);
|
|
551
|
+
const RelayMessageSchema = Union([
|
|
552
|
+
Struct({ type: Literals(["ready", "waiting"]) }),
|
|
553
|
+
Struct({
|
|
554
|
+
offset: Number$1,
|
|
555
|
+
stream: Literal("stdin"),
|
|
556
|
+
type: Literal("ack")
|
|
557
|
+
}),
|
|
558
|
+
Struct({
|
|
559
|
+
code: Int,
|
|
560
|
+
signal: NullOr(String$1),
|
|
561
|
+
type: Literal("exit")
|
|
562
|
+
})
|
|
563
|
+
]);
|
|
564
|
+
const decodeRelayMessage = decodeUnknownOption(fromJsonString(RelayMessageSchema));
|
|
565
|
+
const isApiError = is(ApiError);
|
|
566
|
+
const frame = (stream, offset, data) => {
|
|
567
|
+
const bytes = new Uint8Array(HEADER_BYTES + data.length);
|
|
568
|
+
bytes[0] = stream;
|
|
569
|
+
new DataView(bytes.buffer).setBigUint64(1, BigInt(offset));
|
|
570
|
+
bytes.set(data, HEADER_BYTES);
|
|
571
|
+
return bytes;
|
|
572
|
+
};
|
|
573
|
+
const control = (message) => JSON.stringify(message);
|
|
574
|
+
const abortError = (signal) => {
|
|
575
|
+
const reason = signal?.reason;
|
|
576
|
+
return reason instanceof Error ? reason : new Error(ABORTED, { cause: reason });
|
|
577
|
+
};
|
|
578
|
+
var Attachment = class {
|
|
579
|
+
#done = Promise.withResolvers();
|
|
580
|
+
#received = /* @__PURE__ */ new Map();
|
|
581
|
+
#sinks;
|
|
582
|
+
#target;
|
|
583
|
+
#drained = [];
|
|
584
|
+
#ended = false;
|
|
585
|
+
#finished = false;
|
|
586
|
+
#ready = false;
|
|
587
|
+
#retries = 0;
|
|
588
|
+
#signals = [];
|
|
589
|
+
#size;
|
|
590
|
+
#socket = null;
|
|
591
|
+
#stdinAcked = 0;
|
|
592
|
+
#stdinEnd = 0;
|
|
593
|
+
#synced = false;
|
|
594
|
+
#timer;
|
|
595
|
+
#unacknowledged = [];
|
|
596
|
+
#aborted = () => {
|
|
597
|
+
this.#fail(abortError(this.#target.options.signal));
|
|
598
|
+
};
|
|
599
|
+
constructor(target) {
|
|
600
|
+
this.#target = target;
|
|
601
|
+
this.#sinks = /* @__PURE__ */ new Map([[STDOUT, target.options.stdout], [STDERR, target.options.stderr]]);
|
|
602
|
+
const { signal } = target.options;
|
|
603
|
+
if (signal?.aborted === true) this.#fail(abortError(signal));
|
|
604
|
+
else {
|
|
605
|
+
signal?.addEventListener("abort", this.#aborted, { once: true });
|
|
606
|
+
this.#connect();
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
get exit() {
|
|
610
|
+
return this.#done.promise;
|
|
611
|
+
}
|
|
612
|
+
async write(data) {
|
|
613
|
+
if (this.#ended || this.#finished) return;
|
|
614
|
+
for (let start = 0; start < data.length; start += CHUNK_BYTES) {
|
|
615
|
+
const chunk = data.slice(start, start + CHUNK_BYTES);
|
|
616
|
+
const offset = this.#stdinEnd;
|
|
617
|
+
this.#unacknowledged.push({
|
|
618
|
+
data: chunk,
|
|
619
|
+
offset
|
|
620
|
+
});
|
|
621
|
+
this.#stdinEnd += chunk.length;
|
|
622
|
+
if (this.#live()) this.#socket?.send(frame(STDIN, offset, chunk));
|
|
623
|
+
}
|
|
624
|
+
if (this.#stdinEnd - this.#stdinAcked > UNACKNOWLEDGED_LIMIT_BYTES) {
|
|
625
|
+
const drained = Promise.withResolvers();
|
|
626
|
+
this.#drained.push(drained);
|
|
627
|
+
await drained.promise;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
endStdin() {
|
|
631
|
+
if (this.#ended || this.#finished) return;
|
|
632
|
+
this.#ended = true;
|
|
633
|
+
if (this.#live()) this.#socket?.send(this.#eof());
|
|
634
|
+
}
|
|
635
|
+
resize(cols, rows) {
|
|
636
|
+
this.#size = {
|
|
637
|
+
cols,
|
|
638
|
+
rows
|
|
639
|
+
};
|
|
640
|
+
if (this.#live()) this.#socket?.send(control({
|
|
641
|
+
cols,
|
|
642
|
+
rows,
|
|
643
|
+
type: "resize"
|
|
644
|
+
}));
|
|
645
|
+
}
|
|
646
|
+
sendSignal(name) {
|
|
647
|
+
if (this.#finished) return;
|
|
648
|
+
if (this.#live()) this.#socket?.send(control({
|
|
649
|
+
name,
|
|
650
|
+
type: "signal"
|
|
651
|
+
}));
|
|
652
|
+
else this.#signals.push(name);
|
|
653
|
+
}
|
|
654
|
+
#live() {
|
|
655
|
+
return this.#ready && this.#synced;
|
|
656
|
+
}
|
|
657
|
+
#eof() {
|
|
658
|
+
return control({
|
|
659
|
+
offset: this.#stdinEnd,
|
|
660
|
+
stream: "stdin",
|
|
661
|
+
type: "eof"
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
#connect() {
|
|
665
|
+
const { credential, url } = this.#target;
|
|
666
|
+
const socket = new WebSocket(url, credential === null ? [ATTACH_PROTOCOL] : [ATTACH_PROTOCOL, credential]);
|
|
667
|
+
socket.binaryType = "arraybuffer";
|
|
668
|
+
socket.addEventListener("message", (event) => {
|
|
669
|
+
this.#message(event);
|
|
670
|
+
});
|
|
671
|
+
socket.addEventListener("close", (event) => {
|
|
672
|
+
this.#closed(socket, event.code);
|
|
673
|
+
});
|
|
674
|
+
this.#socket = socket;
|
|
675
|
+
this.#watch();
|
|
676
|
+
}
|
|
677
|
+
#closed(socket, code) {
|
|
678
|
+
if (socket !== this.#socket || this.#finished) return;
|
|
679
|
+
this.#socket = null;
|
|
680
|
+
this.#ready = false;
|
|
681
|
+
if (code === REPLACED) {
|
|
682
|
+
this.#fail(/* @__PURE__ */ new Error(REPLACED_MESSAGE));
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
const delay = RETRY_MS[Math.min(this.#retries, RETRY_MS.length - 1)];
|
|
686
|
+
this.#retries += 1;
|
|
687
|
+
clearTimeout(this.#timer);
|
|
688
|
+
this.#timer = setTimeout(() => {
|
|
689
|
+
this.#reconnect();
|
|
690
|
+
}, delay);
|
|
691
|
+
}
|
|
692
|
+
async #reconnect() {
|
|
693
|
+
if (await this.#alive() && this.#socket === null) this.#connect();
|
|
694
|
+
}
|
|
695
|
+
#watch() {
|
|
696
|
+
clearTimeout(this.#timer);
|
|
697
|
+
this.#timer = setTimeout(() => {
|
|
698
|
+
this.#keepWatching();
|
|
699
|
+
}, CHECK_MS);
|
|
700
|
+
}
|
|
701
|
+
async #keepWatching() {
|
|
702
|
+
if (await this.#alive() && !this.#ready && this.#socket !== null) this.#watch();
|
|
703
|
+
}
|
|
704
|
+
async #alive() {
|
|
705
|
+
const [checked] = await Promise.allSettled([this.#target.check()]);
|
|
706
|
+
if (checked.status === "fulfilled" && checked.value.status === "lost") this.#fail(/* @__PURE__ */ new Error(LOST));
|
|
707
|
+
if (checked.status === "rejected") {
|
|
708
|
+
const reason = checked.reason;
|
|
709
|
+
if (isApiError(reason)) this.#fail(reason);
|
|
710
|
+
}
|
|
711
|
+
return !this.#finished;
|
|
712
|
+
}
|
|
713
|
+
#message(event) {
|
|
714
|
+
const data = event.data;
|
|
715
|
+
if (data instanceof ArrayBuffer) {
|
|
716
|
+
this.#output(new Uint8Array(data));
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
const decoded = decodeRelayMessage(data);
|
|
720
|
+
if (isSome(decoded)) this.#control(decoded.value);
|
|
721
|
+
}
|
|
722
|
+
#control(message) {
|
|
723
|
+
switch (message.type) {
|
|
724
|
+
case "ready":
|
|
725
|
+
this.#ready = true;
|
|
726
|
+
this.#retries = 0;
|
|
727
|
+
clearTimeout(this.#timer);
|
|
728
|
+
if (this.#synced) this.#resend();
|
|
729
|
+
break;
|
|
730
|
+
case "waiting":
|
|
731
|
+
this.#ready = false;
|
|
732
|
+
this.#watch();
|
|
733
|
+
break;
|
|
734
|
+
case "ack":
|
|
735
|
+
this.#acknowledgeStdin(message.offset);
|
|
736
|
+
break;
|
|
737
|
+
case "exit": this.#finish({
|
|
738
|
+
code: message.code,
|
|
739
|
+
signal: message.signal
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
#resend() {
|
|
744
|
+
for (const { data, offset } of this.#unacknowledged) this.#socket?.send(frame(STDIN, offset, data));
|
|
745
|
+
if (this.#ended) this.#socket?.send(this.#eof());
|
|
746
|
+
if (this.#size !== void 0) this.#socket?.send(control({
|
|
747
|
+
...this.#size,
|
|
748
|
+
type: "resize"
|
|
749
|
+
}));
|
|
750
|
+
for (const name of this.#signals) this.#socket?.send(control({
|
|
751
|
+
name,
|
|
752
|
+
type: "signal"
|
|
753
|
+
}));
|
|
754
|
+
this.#signals = [];
|
|
755
|
+
}
|
|
756
|
+
#rebase(base) {
|
|
757
|
+
this.#synced = true;
|
|
758
|
+
this.#stdinAcked = base;
|
|
759
|
+
this.#stdinEnd += base;
|
|
760
|
+
this.#unacknowledged = this.#unacknowledged.map(({ data, offset }) => ({
|
|
761
|
+
data,
|
|
762
|
+
offset: offset + base
|
|
763
|
+
}));
|
|
764
|
+
if (this.#ready) this.#resend();
|
|
765
|
+
}
|
|
766
|
+
#acknowledgeStdin(offset) {
|
|
767
|
+
if (!this.#synced) {
|
|
768
|
+
this.#rebase(offset);
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
this.#stdinAcked = Math.max(this.#stdinAcked, offset);
|
|
772
|
+
this.#unacknowledged = this.#unacknowledged.filter((chunk) => chunk.offset + chunk.data.length > this.#stdinAcked);
|
|
773
|
+
if (this.#stdinEnd - this.#stdinAcked <= UNACKNOWLEDGED_LIMIT_BYTES) this.#release();
|
|
774
|
+
}
|
|
775
|
+
#output(bytes) {
|
|
776
|
+
const stream = bytes[0] ?? STDIN;
|
|
777
|
+
const name = OUTPUT_NAMES.get(stream);
|
|
778
|
+
if (bytes.length < HEADER_BYTES || name === void 0) return;
|
|
779
|
+
const offset = Number(new DataView(bytes.buffer, bytes.byteOffset).getBigUint64(1));
|
|
780
|
+
const known = this.#received.get(stream) ?? offset;
|
|
781
|
+
const data = bytes.subarray(HEADER_BYTES);
|
|
782
|
+
if (offset > known) return;
|
|
783
|
+
const fresh = data.subarray(known - offset);
|
|
784
|
+
const received = known + fresh.length;
|
|
785
|
+
if (fresh.length > 0) {
|
|
786
|
+
this.#received.set(stream, received);
|
|
787
|
+
this.#sinks.get(stream)?.(fresh);
|
|
788
|
+
}
|
|
789
|
+
this.#socket?.send(control({
|
|
790
|
+
offset: received,
|
|
791
|
+
stream: name,
|
|
792
|
+
type: "ack"
|
|
793
|
+
}));
|
|
794
|
+
}
|
|
795
|
+
#release() {
|
|
796
|
+
const waiting = this.#drained;
|
|
797
|
+
this.#drained = [];
|
|
798
|
+
for (const drained of waiting) drained.resolve(void 0);
|
|
799
|
+
}
|
|
800
|
+
#stop() {
|
|
801
|
+
this.#finished = true;
|
|
802
|
+
this.#ready = false;
|
|
803
|
+
clearTimeout(this.#timer);
|
|
804
|
+
this.#target.options.signal?.removeEventListener("abort", this.#aborted);
|
|
805
|
+
this.#socket?.close(NORMAL_CLOSURE);
|
|
806
|
+
this.#socket = null;
|
|
807
|
+
this.#release();
|
|
808
|
+
}
|
|
809
|
+
#finish(exit) {
|
|
810
|
+
if (!this.#finished) {
|
|
811
|
+
this.#stop();
|
|
812
|
+
this.#done.resolve(exit);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
#fail(error) {
|
|
816
|
+
if (!this.#finished) {
|
|
817
|
+
this.#stop();
|
|
818
|
+
this.#done.reject(error);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
};
|
|
822
|
+
const attach = (target) => {
|
|
823
|
+
const attachment = new Attachment(target);
|
|
824
|
+
return {
|
|
825
|
+
endStdin: () => {
|
|
826
|
+
attachment.endStdin();
|
|
827
|
+
},
|
|
828
|
+
exit: attachment.exit,
|
|
829
|
+
resize: (cols, rows) => {
|
|
830
|
+
attachment.resize(cols, rows);
|
|
831
|
+
},
|
|
832
|
+
sendSignal: (name) => {
|
|
833
|
+
attachment.sendSignal(name);
|
|
834
|
+
},
|
|
835
|
+
write: async (data) => {
|
|
836
|
+
await attachment.write(data);
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
};
|
|
840
|
+
// ../sandcovery-contract/src/billing.ts
|
|
841
|
+
const FREE_PLAN = "free";
|
|
842
|
+
const ENTERPRISE_PLAN = "enterprise";
|
|
843
|
+
const MICRO_USD_PER_CENT = 1e4;
|
|
844
|
+
const MICRO_USD_PER_DOLLAR = 1e6;
|
|
845
|
+
const CREDIT_PURCHASE_MIN_MICRO_USD = 25 * MICRO_USD_PER_DOLLAR;
|
|
846
|
+
const CREDIT_PURCHASE_MAX_MICRO_USD = 1e3 * MICRO_USD_PER_DOLLAR;
|
|
847
|
+
const CARD_FEE_TERMS = "2.9% plus 30 cents";
|
|
848
|
+
const NO_MARKUP_TERMS = [
|
|
849
|
+
"Sandbox usage carries no markup.",
|
|
850
|
+
"On your own provider keys, each provider bills you at its own prices, and Sandcovery charges nothing for that usage.",
|
|
851
|
+
`Credits pay each provider's list price for a sandbox's size, from its start until it ends, and a card processing fee of ${CARD_FEE_TERMS} comes out of each credit purchase.`,
|
|
852
|
+
"Beyond list prices and that fee, Sandcovery charges only for its Pro and Enterprise plans, each a fixed fee for each organization."
|
|
853
|
+
].join(" ");
|
|
854
|
+
const BASIS_POINTS = 1e4;
|
|
855
|
+
const CARD_FEE_BASIS_POINTS = 290;
|
|
856
|
+
const CARD_FEE_FIXED_MICRO_USD = 30 * MICRO_USD_PER_CENT;
|
|
857
|
+
const creditsAfterFeeMicroUsd = (paidMicroUsd) => {
|
|
858
|
+
const paidCents = paidMicroUsd / MICRO_USD_PER_CENT;
|
|
859
|
+
return paidMicroUsd - Math.round(paidCents * CARD_FEE_BASIS_POINTS / BASIS_POINTS) * MICRO_USD_PER_CENT - CARD_FEE_FIXED_MICRO_USD;
|
|
860
|
+
};
|
|
861
|
+
const AUTO_TOP_UP_THRESHOLD_MIN_MICRO_USD = MICRO_USD_PER_DOLLAR;
|
|
862
|
+
const AUTO_TOP_UP_THRESHOLD_MAX_MICRO_USD = Math.floor((creditsAfterFeeMicroUsd(CREDIT_PURCHASE_MAX_MICRO_USD) - 1) / MICRO_USD_PER_DOLLAR) * MICRO_USD_PER_DOLLAR;
|
|
863
|
+
const thresholdBelowTopUp = ({ amountMicroUsd, thresholdMicroUsd }) => thresholdMicroUsd < creditsAfterFeeMicroUsd(amountMicroUsd);
|
|
864
|
+
const Plan = Literals([
|
|
865
|
+
FREE_PLAN,
|
|
866
|
+
"pro",
|
|
867
|
+
ENTERPRISE_PLAN
|
|
868
|
+
]).annotate({
|
|
869
|
+
description: "The organization plan: `pro` or `enterprise` while that subscription is active, trialing, or past due, otherwise `free`. `enterprise` is Pro for an organization that connects a GitHub account a GitHub Enterprise owns.",
|
|
870
|
+
identifier: "Plan"
|
|
871
|
+
});
|
|
872
|
+
const ProInterval = Literals([
|
|
873
|
+
"day",
|
|
874
|
+
"month",
|
|
875
|
+
"week",
|
|
876
|
+
"year"
|
|
877
|
+
]).annotate({
|
|
878
|
+
description: "How often the plan fee is charged.",
|
|
879
|
+
identifier: "ProInterval"
|
|
880
|
+
});
|
|
881
|
+
const ProPrice = Struct({
|
|
882
|
+
interval: ProInterval,
|
|
883
|
+
micro_usd: MicroUsd
|
|
884
|
+
}).annotate({
|
|
885
|
+
description: "The fixed fee of a plan for each billing interval.",
|
|
886
|
+
identifier: "ProPrice"
|
|
887
|
+
});
|
|
888
|
+
const EnterprisePrice = NullOr(ProPrice).annotate({ description: "The Enterprise price, or null while the Enterprise plan is not on sale." });
|
|
889
|
+
const AutoTopUp = Struct({
|
|
890
|
+
amount_micro_usd: NullOr(MicroUsd).annotate({ description: "Whole US dollars each top-up charges to the saved card, or null before auto top-up was first turned on." }),
|
|
891
|
+
enabled: Boolean.annotate({ description: "Whether a saved card is charged once the credit balance falls below the threshold, or a create is refused for credits that one top-up covers." }),
|
|
892
|
+
failed_at: NullOr(Timestamp).annotate({ description: "When a failed top-up turned auto top-up off, or null. Turning it on again clears it." }),
|
|
893
|
+
failure: NullOr(String$1).annotate({ description: "Why a failed top-up turned auto top-up off, such as a declined card, a card that asks its holder to authenticate, or a disputed payment, or null. Turning it on again clears it." }),
|
|
894
|
+
threshold_micro_usd: NullOr(MicroUsd).annotate({ description: "The credit balance below which a top-up is charged, or null before auto top-up was first turned on." })
|
|
895
|
+
}).annotate({
|
|
896
|
+
description: `Auto top-up: while it is on, each time the credit balance falls below the threshold, the saved card is charged the amount once, off session, and the credit, the amount less the processing fee of ${CARD_FEE_TERMS}, arrives once Stripe confirms the charge. It charges only while credits are on sale, and a failed charge turns it off.`,
|
|
897
|
+
identifier: "AutoTopUp"
|
|
898
|
+
});
|
|
899
|
+
const Billing = Struct({
|
|
900
|
+
auto_top_up: AutoTopUp,
|
|
901
|
+
credit_balance_micro_usd: Int.annotate({ description: "Credits bought, less refunds and held disputes up to each purchase's credit, the list-price cost of each ended sandbox paid with credits, and the full-TTL hold of each live one. A refund or dispute after use can take it below zero." }),
|
|
902
|
+
credits_on_sale: Boolean.annotate({ description: "Whether a credit purchase is open." }),
|
|
903
|
+
enterprise_price: EnterprisePrice,
|
|
904
|
+
github_enterprise: Boolean.annotate({ description: "Whether a GitHub Enterprise owns a GitHub account this organization connected to Sandcovery CI, so that its jobs run only on the Enterprise plan." }),
|
|
905
|
+
plan: Plan,
|
|
906
|
+
pro_price: NullOr(ProPrice).annotate({ description: "The Pro price, or null while Pro is not on sale." })
|
|
907
|
+
}).annotate({ identifier: "Billing" });
|
|
908
|
+
const CreditTerms = Struct({
|
|
909
|
+
fee_fixed_micro_usd: MicroUsd.annotate({ description: "The fixed part of the processing fee that comes out of each credit purchase." }),
|
|
910
|
+
fee_rate_basis_points: Natural.annotate({ description: "The part of the processing fee that grows with the payment, in basis points of it, rounded to the cent: 290 is 2.9%." }),
|
|
911
|
+
max_micro_usd: MicroUsd.annotate({ description: "The largest credit purchase, in whole US dollars." }),
|
|
912
|
+
min_micro_usd: MicroUsd.annotate({ description: "The smallest credit purchase, in whole US dollars." })
|
|
913
|
+
}).annotate({
|
|
914
|
+
description: "How credits are bought: a payment in whole US dollars between the two bounds adds credit equal to the payment less the processing fee, spent at each provider list price.",
|
|
915
|
+
identifier: "CreditTerms"
|
|
916
|
+
});
|
|
917
|
+
const Pricing = Struct({
|
|
918
|
+
credits: CreditTerms,
|
|
919
|
+
enterprise_price: EnterprisePrice,
|
|
920
|
+
pro_price: NullOr(ProPrice).annotate({ description: "The Pro price, or null while Pro is not on sale." })
|
|
921
|
+
}).annotate({
|
|
922
|
+
description: "The public prices: the Pro and Enterprise prices for one organization and the terms of a credit purchase.",
|
|
923
|
+
identifier: "Pricing"
|
|
924
|
+
});
|
|
925
|
+
const CreditAmount = MicroUsd.check(isMultipleOf(MICRO_USD_PER_DOLLAR), isBetween({
|
|
926
|
+
maximum: CREDIT_PURCHASE_MAX_MICRO_USD,
|
|
927
|
+
minimum: CREDIT_PURCHASE_MIN_MICRO_USD
|
|
928
|
+
})).annotate({ description: `Whole US dollars charged to the card, from 25 to 1,000 USD. The credits granted are this amount less the processing fee of ${CARD_FEE_TERMS}, rounded to the cent.` });
|
|
929
|
+
Struct({ amount_micro_usd: CreditAmount }).annotate({ identifier: "CreditPurchaseRequest" });
|
|
930
|
+
Struct({
|
|
931
|
+
amount_micro_usd: CreditAmount,
|
|
932
|
+
threshold_micro_usd: MicroUsd.check(isMultipleOf(MICRO_USD_PER_DOLLAR), isBetween({
|
|
933
|
+
maximum: AUTO_TOP_UP_THRESHOLD_MAX_MICRO_USD,
|
|
934
|
+
minimum: AUTO_TOP_UP_THRESHOLD_MIN_MICRO_USD
|
|
935
|
+
})).annotate({ description: "Whole US dollars, from 1 to 970 USD, and below the credit one top-up adds, so that one top-up lifts the balance back above it: a 25 USD top-up adds 23.97 USD, so its threshold is at most 23 USD." })
|
|
936
|
+
}).annotate({ identifier: "AutoTopUpRequest" });
|
|
937
|
+
const AutoTopUpChange = Struct({
|
|
938
|
+
auto_top_up: AutoTopUp,
|
|
939
|
+
url: NullOr(String$1).annotate({ description: "The Stripe Checkout page that saves a card and then turns auto top-up on with these settings, or null when auto top-up was on and the settings apply at once." })
|
|
940
|
+
}).annotate({ identifier: "AutoTopUpChange" });
|
|
941
|
+
const CreditCheckout = Struct({ url: String$1.annotate({ description: "The Stripe Checkout page that takes the payment. The credits arrive once Stripe confirms it." }) }).annotate({ identifier: "CreditCheckout" });
|
|
70
942
|
// ../sandcovery-contract/src/providers.ts
|
|
71
943
|
const Ratio = Finite.check(isBetween({
|
|
72
944
|
maximum: 1,
|
|
@@ -181,7 +1053,7 @@ const ProviderBoardEntry = Struct({
|
|
|
181
1053
|
create_latency_ms: Struct({
|
|
182
1054
|
p50: NullOr(Natural),
|
|
183
1055
|
p95: NullOr(Natural)
|
|
184
|
-
}).annotate({ description: "Create latency of the probe sandboxes over the last 24 hours, or null before the first probe or when `
|
|
1056
|
+
}).annotate({ description: "Create latency of the probe sandboxes over the last 24 hours, or null before the first probe or when `docs_only_adapter` is true." }),
|
|
185
1057
|
credential_fields: ArraySchema(CredentialField).annotate({ description: "The fields a credential for this provider takes, in form order, so a client can ask for a provider it does not know." }),
|
|
186
1058
|
docs_only_adapter: Boolean.annotate({ description: "True when Sandcovery routes to the provider through an adapter written from the provider's public docs alone. Sandcovery has not run that adapter against the provider's service and runs no probe there, so `status` stays `unknown` and the `uptime` and `create_latency_ms` values stay null." }),
|
|
187
1059
|
favicon: NullOr(ThemedBrandImage).annotate({ description: "The provider's favicon for a light and a dark background, or null when Sandcovery shows no mark for the provider." }),
|
|
@@ -190,7 +1062,6 @@ const ProviderBoardEntry = Struct({
|
|
|
190
1062
|
hourly_micro_usd: MicroUsd,
|
|
191
1063
|
type: GpuType
|
|
192
1064
|
})).annotate({ description: "List price per hour of one GPU of each type the provider runs, which a GPU sandbox adds to the price of its size. Empty when the provider runs no GPU sandbox." }),
|
|
193
|
-
health_published: Boolean.annotate({ description: "Whether the board publishes the provider's status, uptime, and create latency. False for a provider whose terms do not allow publishing them, whose `status` is then `unknown` and whose `uptime` and `create_latency_ms` values are null." }),
|
|
194
1065
|
home_url: String$1.annotate({ description: "The provider's own home page." }),
|
|
195
1066
|
incidents: VendorIncidents,
|
|
196
1067
|
name: String$1,
|
|
@@ -209,7 +1080,7 @@ const ProviderBoardEntry = Struct({
|
|
|
209
1080
|
last_15_minutes: NullOr(Ratio),
|
|
210
1081
|
last_24_hours: NullOr(Ratio),
|
|
211
1082
|
last_7_days: NullOr(Ratio)
|
|
212
|
-
}).annotate({ description: "Share of probe creates that succeeded in each window, or null before the first probe or when `
|
|
1083
|
+
}).annotate({ description: "Share of probe creates that succeeded in each window, or null before the first probe or when `docs_only_adapter` is true. For a provider probed less often than every 5 minutes, `last_15_minutes` covers its own probe interval instead, so it holds the result of its last probe." })
|
|
213
1084
|
}).annotate({
|
|
214
1085
|
description: "One provider on the public provider board.",
|
|
215
1086
|
identifier: "ProviderBoardEntry"
|
|
@@ -244,11 +1115,7 @@ const CatalogGpus = fact(ArraySchema(Struct({
|
|
|
244
1115
|
description: "The GPUs a sandbox can get and where the list was read. Empty when Sandcovery starts no GPU sandbox on a provider it routes to.",
|
|
245
1116
|
identifier: "CatalogGpus"
|
|
246
1117
|
});
|
|
247
|
-
const CATALOG_MEASUREMENTS = [
|
|
248
|
-
"measured",
|
|
249
|
-
"not_measured",
|
|
250
|
-
"not_published"
|
|
251
|
-
];
|
|
1118
|
+
const CATALOG_MEASUREMENTS = ["measured", "not_measured"];
|
|
252
1119
|
const BENCHMARK_TERMS = [
|
|
253
1120
|
"barred",
|
|
254
1121
|
"conditional",
|
|
@@ -295,9 +1162,9 @@ const ProviderCatalogEntry = Struct({
|
|
|
295
1162
|
status_url: NullOr(String$1),
|
|
296
1163
|
terms_url: String$1
|
|
297
1164
|
}).annotate({ description: "The provider's own public pages." }),
|
|
298
|
-
measured_at: NullOr(Timestamp).annotate({ description: "When the
|
|
1165
|
+
measured_at: NullOr(Timestamp).annotate({ description: "When the uptime and create latency were last rolled up, or null when Sandcovery has measured none." }),
|
|
299
1166
|
measurement: Literals(CATALOG_MEASUREMENTS).annotate({
|
|
300
|
-
description: "Whether the figures are measured: `measured` when Sandcovery probes the provider and publishes the result,
|
|
1167
|
+
description: "Whether the figures are measured: `measured` when Sandcovery probes the provider and publishes the result, and `not_measured` when it runs no probe there.",
|
|
301
1168
|
identifier: "CatalogMeasurement"
|
|
302
1169
|
}),
|
|
303
1170
|
name: String$1,
|
|
@@ -424,133 +1291,6 @@ const ProviderCredential = Struct({
|
|
|
424
1291
|
identifier: "ProviderCredential"
|
|
425
1292
|
});
|
|
426
1293
|
const ProviderCredentialList = Struct({ data: ArraySchema(ProviderCredential).annotate({ description: "Every stored credential, by provider and then in the order a create tries them: the order they were added. A Free organization routes only its oldest credential, and `paused` marks each other one." }) }).annotate({ identifier: "ProviderCredentialList" });
|
|
427
|
-
// ../sandcovery-contract/src/errors/concurrency-limit-reached.ts
|
|
428
|
-
var ConcurrencyLimitReached = class extends Error$1("ConcurrencyLimitReached")({
|
|
429
|
-
concurrency_cap: Natural,
|
|
430
|
-
error: tag("concurrency_limit_reached"),
|
|
431
|
-
message: String$1
|
|
432
|
-
}, {
|
|
433
|
-
description: "The API key already has `concurrency_cap` live sandboxes, its `max_concurrent_sandboxes`. Destroy one or wait for one to end.",
|
|
434
|
-
httpApiStatus: 429,
|
|
435
|
-
identifier: "ConcurrencyLimitReached"
|
|
436
|
-
}) {
|
|
437
|
-
[ignore] = true;
|
|
438
|
-
};
|
|
439
|
-
// ../sandcovery-contract/src/errors/conflict.ts
|
|
440
|
-
var Conflict = class extends Error$1("Conflict")({
|
|
441
|
-
error: tag("conflict"),
|
|
442
|
-
message: String$1
|
|
443
|
-
}, {
|
|
444
|
-
description: "The request clashes with the current state, such as an `Idempotency-Key` reused with a different body, a call on a sandbox that is not running, or deleting a provider credential that live sandboxes still use.",
|
|
445
|
-
httpApiStatus: 409,
|
|
446
|
-
identifier: "Conflict"
|
|
447
|
-
}) {
|
|
448
|
-
[ignore] = true;
|
|
449
|
-
};
|
|
450
|
-
// ../sandcovery-contract/src/errors/forbidden.ts
|
|
451
|
-
var Forbidden = class extends Error$1("Forbidden")({
|
|
452
|
-
error: tag("forbidden"),
|
|
453
|
-
message: String$1
|
|
454
|
-
}, {
|
|
455
|
-
description: "The credential is valid but may not make this call, such as a management key on a sandbox, an API key on keys, usage, or provider credentials, a member who is not an owner on keys, a member who is not an owner or admin on usage or provider credentials, a signed-in member who is not an owner or admin, or their agent, on sandbox create, a management key whose minting owner is no longer an owner on keys, or a TTL over the API key's `max_ttl_seconds`. `message` names the rule.",
|
|
456
|
-
httpApiStatus: 403,
|
|
457
|
-
identifier: "Forbidden"
|
|
458
|
-
}) {
|
|
459
|
-
[ignore] = true;
|
|
460
|
-
};
|
|
461
|
-
// ../sandcovery-contract/src/errors/invalid-request.ts
|
|
462
|
-
var InvalidRequest = class extends Error$1("InvalidRequest")({
|
|
463
|
-
error: tag("invalid_request"),
|
|
464
|
-
message: String$1
|
|
465
|
-
}, {
|
|
466
|
-
description: "The path, query, headers, or body do not decode against the operation, or contradict each other, and `message` names the failure.",
|
|
467
|
-
httpApiStatus: 400,
|
|
468
|
-
identifier: "InvalidRequest"
|
|
469
|
-
}) {
|
|
470
|
-
[ignore] = true;
|
|
471
|
-
};
|
|
472
|
-
// ../sandcovery-contract/src/errors/no-provider-available.ts
|
|
473
|
-
var NoProviderAvailable = class extends Error$1("NoProviderAvailable")({
|
|
474
|
-
attempts: ArraySchema(CreateAttempt).annotate({ description: "Every create attempt, in order. Empty when no provider was a candidate, such as when none has a stored credential." }),
|
|
475
|
-
error: tag("no_provider_available"),
|
|
476
|
-
message: String$1
|
|
477
|
-
}, {
|
|
478
|
-
description: "Every candidate provider failed to create the sandbox, or none was left after filtering.",
|
|
479
|
-
httpApiStatus: 503,
|
|
480
|
-
identifier: "NoProviderAvailable"
|
|
481
|
-
}) {};
|
|
482
|
-
// ../sandcovery-contract/src/errors/not-found.ts
|
|
483
|
-
var NotFound = class extends Error$1("NotFound")({
|
|
484
|
-
error: tag("not_found"),
|
|
485
|
-
message: String$1
|
|
486
|
-
}, {
|
|
487
|
-
description: "The resource the path names does not exist or belongs to another organization or key.",
|
|
488
|
-
httpApiStatus: 404,
|
|
489
|
-
identifier: "NotFound"
|
|
490
|
-
}) {
|
|
491
|
-
[ignore] = true;
|
|
492
|
-
};
|
|
493
|
-
// ../sandcovery-contract/src/errors/provider-error.ts
|
|
494
|
-
var ProviderError = class extends Error$1("ProviderError")({
|
|
495
|
-
error: tag("provider_error"),
|
|
496
|
-
message: String$1,
|
|
497
|
-
provider: Provider
|
|
498
|
-
}, {
|
|
499
|
-
description: "The sandbox's provider failed the call. `message` carries the provider's reason.",
|
|
500
|
-
httpApiStatus: 502,
|
|
501
|
-
identifier: "ProviderError"
|
|
502
|
-
}) {};
|
|
503
|
-
// ../sandcovery-contract/src/errors/spend-limit-reached.ts
|
|
504
|
-
var SpendLimitReached = class extends Error$1("SpendLimitReached")({
|
|
505
|
-
error: tag("spend_limit_reached"),
|
|
506
|
-
limit_micro_usd: MicroUsd,
|
|
507
|
-
message: String$1,
|
|
508
|
-
resets_at: NullOr(Timestamp),
|
|
509
|
-
spent_micro_usd: MicroUsd
|
|
510
|
-
}, {
|
|
511
|
-
description: "The API key's spend limit leaves too little for the sandbox's full TTL at list price. `resets_at` is when the window resets, or null for a `total` limit.",
|
|
512
|
-
httpApiStatus: 402,
|
|
513
|
-
identifier: "SpendLimitReached"
|
|
514
|
-
}) {
|
|
515
|
-
[ignore] = true;
|
|
516
|
-
};
|
|
517
|
-
// ../sandcovery-contract/src/errors/unauthorized.ts
|
|
518
|
-
var Unauthorized = class extends Error$1("Unauthorized")({
|
|
519
|
-
error: tag("unauthorized"),
|
|
520
|
-
message: String$1
|
|
521
|
-
}, {
|
|
522
|
-
description: "The request carries no live key and no signed-in session, or a key that is unknown, revoked, or expired.",
|
|
523
|
-
httpApiStatus: 401,
|
|
524
|
-
identifier: "Unauthorized"
|
|
525
|
-
}) {
|
|
526
|
-
[ignore] = true;
|
|
527
|
-
};
|
|
528
|
-
// ../sandcovery-contract/src/errors/unsupported.ts
|
|
529
|
-
var Unsupported = class extends Error$1("Unsupported")({
|
|
530
|
-
error: tag("unsupported"),
|
|
531
|
-
message: String$1,
|
|
532
|
-
options: ArraySchema(String$1).annotate({ description: "Slugs that would run for this request: each refused slug at the sizes its candidates run, then, for a slug that pins a provider, the `sandcovery/` slug at the size it asked for. Empty when nothing near the refused slugs would run, such as a spec field no candidate provider can enforce or an operation the bound provider lacks, and then `message` names that field or operation." }),
|
|
533
|
-
provider: NullOr(Provider).annotate({ description: "The sandbox's provider for an operation on an existing sandbox, or null for a create." })
|
|
534
|
-
}, {
|
|
535
|
-
description: "A slug, spec option, or operation that no candidate provider can serve. Sandcovery never ignores an option. For a slug, `options` lists slugs that would run; otherwise `options` is empty and `message` names the field or operation.",
|
|
536
|
-
httpApiStatus: 422,
|
|
537
|
-
identifier: "Unsupported"
|
|
538
|
-
}) {
|
|
539
|
-
[ignore] = true;
|
|
540
|
-
};
|
|
541
|
-
// ../sandcovery-contract/src/errors/api-error.ts
|
|
542
|
-
const ApiError = Union([
|
|
543
|
-
ConcurrencyLimitReached,
|
|
544
|
-
Conflict,
|
|
545
|
-
Forbidden,
|
|
546
|
-
InvalidRequest,
|
|
547
|
-
NoProviderAvailable,
|
|
548
|
-
NotFound,
|
|
549
|
-
ProviderError,
|
|
550
|
-
SpendLimitReached,
|
|
551
|
-
Unauthorized,
|
|
552
|
-
Unsupported
|
|
553
|
-
]);
|
|
554
1294
|
// ../sandcovery-contract/src/exec.ts
|
|
555
1295
|
const MAX_EXEC_TIMEOUT_SECONDS = 3600;
|
|
556
1296
|
const commandFields = {
|
|
@@ -625,21 +1365,147 @@ const FileList = Struct({
|
|
|
625
1365
|
entries: ArraySchema(FileEntry),
|
|
626
1366
|
path: String$1
|
|
627
1367
|
}).annotate({ identifier: "FileList" });
|
|
1368
|
+
const KeyName = NonEmptyString.check(isMaxLength(64));
|
|
1369
|
+
const PositiveInt = Int.check(isGreaterThanOrEqualTo(1));
|
|
1370
|
+
const KeyKind = Literals(["api", "management"]).annotate({
|
|
1371
|
+
description: "An `api` key creates and drives sandboxes. A `management` key mints, changes, and revokes keys, sets provider credentials, and reads usage, and reaches no sandbox.",
|
|
1372
|
+
identifier: "KeyKind"
|
|
1373
|
+
});
|
|
1374
|
+
const SpendLimit = Struct({
|
|
1375
|
+
limit_micro_usd: MicroUsd,
|
|
1376
|
+
period: Literals([
|
|
1377
|
+
"day",
|
|
1378
|
+
"month",
|
|
1379
|
+
"total",
|
|
1380
|
+
"week"
|
|
1381
|
+
]).annotate({
|
|
1382
|
+
description: "The window the limit counts: a UTC `day`, an ISO `week` from Monday 00:00 UTC, a UTC calendar `month`, or the key `total`.",
|
|
1383
|
+
identifier: "SpendLimitPeriod"
|
|
1384
|
+
})
|
|
1385
|
+
}).annotate({
|
|
1386
|
+
description: "A cap on the list-price cost of sandboxes the key creates, counting usage billed to your own provider accounts.",
|
|
1387
|
+
identifier: "SpendLimit"
|
|
1388
|
+
});
|
|
1389
|
+
const keyPolicyFields = {
|
|
1390
|
+
allowed_providers: NullOr(ArraySchema(Provider)).annotate({ description: "The only providers the key may route to. Null allows all." }),
|
|
1391
|
+
max_concurrent_sandboxes: NullOr(PositiveInt),
|
|
1392
|
+
max_ttl_seconds: NullOr(PositiveInt),
|
|
1393
|
+
spend_limit: NullOr(SpendLimit)
|
|
1394
|
+
};
|
|
1395
|
+
const Key = Struct({
|
|
1396
|
+
...keyPolicyFields,
|
|
1397
|
+
created_at: Timestamp,
|
|
1398
|
+
expires_at: NullOr(Timestamp),
|
|
1399
|
+
id: KeyId,
|
|
1400
|
+
kind: KeyKind,
|
|
1401
|
+
last_used_at: NullOr(Timestamp),
|
|
1402
|
+
name: String$1,
|
|
1403
|
+
revoked_at: NullOr(Timestamp),
|
|
1404
|
+
spend: Struct({
|
|
1405
|
+
resets_at: NullOr(Timestamp),
|
|
1406
|
+
spent_micro_usd: MicroUsd
|
|
1407
|
+
}).annotate({ description: "List-price cost counted against `spend_limit` in its current window, or in total when the key has no limit. Always 0 for a management key." }),
|
|
1408
|
+
start: String$1.annotate({ description: "The first 12 characters of the secret, for display." })
|
|
1409
|
+
}).annotate({
|
|
1410
|
+
description: "An API key or a management key. Its secret is never returned after creation, and the limits are null on a management key.",
|
|
1411
|
+
identifier: "Key"
|
|
1412
|
+
});
|
|
1413
|
+
const KeyList = Struct({ data: ArraySchema(Key) }).annotate({ identifier: "KeyList" });
|
|
1414
|
+
const CreateKeyRequest = Struct({
|
|
1415
|
+
allowed_providers: optionalKey(keyPolicyFields.allowed_providers),
|
|
1416
|
+
expires_at: optionalKey(NullOr(Timestamp)),
|
|
1417
|
+
kind: optionalKey(KeyKind).annotate({ description: "Defaults to `api`. Only a signed-in owner mints a `management` key, and a management key takes no limits." }),
|
|
1418
|
+
max_concurrent_sandboxes: optionalKey(keyPolicyFields.max_concurrent_sandboxes),
|
|
1419
|
+
max_ttl_seconds: optionalKey(keyPolicyFields.max_ttl_seconds),
|
|
1420
|
+
name: KeyName,
|
|
1421
|
+
spend_limit: optionalKey(keyPolicyFields.spend_limit)
|
|
1422
|
+
}).annotate({ identifier: "CreateKeyRequest" });
|
|
1423
|
+
const UpdateKeyRequest = Struct({
|
|
1424
|
+
allowed_providers: optionalKey(keyPolicyFields.allowed_providers),
|
|
1425
|
+
expires_at: optionalKey(NullOr(Timestamp)),
|
|
1426
|
+
max_concurrent_sandboxes: optionalKey(keyPolicyFields.max_concurrent_sandboxes),
|
|
1427
|
+
max_ttl_seconds: optionalKey(keyPolicyFields.max_ttl_seconds),
|
|
1428
|
+
name: optionalKey(KeyName),
|
|
1429
|
+
spend_limit: optionalKey(keyPolicyFields.spend_limit)
|
|
1430
|
+
}).annotate({
|
|
1431
|
+
description: "Fields to change. An absent field keeps its value, and null clears a limit. A limit on a management key answers 400 `invalid_request`.",
|
|
1432
|
+
identifier: "UpdateKeyRequest"
|
|
1433
|
+
});
|
|
1434
|
+
const CreatedKey = Struct({
|
|
1435
|
+
key: Key,
|
|
1436
|
+
secret: KeySecret
|
|
1437
|
+
}).annotate({ identifier: "CreatedKey" });
|
|
628
1438
|
// ../sandcovery-contract/src/offer.ts
|
|
629
1439
|
const VcpuSeconds = Natural;
|
|
1440
|
+
const POST_URL_MAX = 2048;
|
|
1441
|
+
const SANDCOVERY_X_HANDLE = "Sandcovery";
|
|
630
1442
|
const Offer = Struct({
|
|
631
1443
|
cap_vcpu_seconds: VcpuSeconds.annotate({ description: "The free vCPU-seconds the account has earned in total, with no reset: `vcpu_seconds_per_key` for each counted key once `keys_counted` reaches `keys_needed`, and 0 before." }),
|
|
632
|
-
keys_counted: Natural.annotate({ description: "Providers the account has earned free vCPU-seconds for, counted once each for good
|
|
1444
|
+
keys_counted: Natural.annotate({ description: "Providers the account has earned free vCPU-seconds for, counted once each for good, plus one for a counted post on X: each provider accepted a credential an organization the account owns stored, when it was stored for a provider that names the account a key belongs to and otherwise when a sandbox first ran on it. A key, or a provider account a provider names, that already earned for any account counts nothing, and removing a credential and storing it again counts nothing more." }),
|
|
633
1445
|
keys_needed: Natural.annotate({ description: "Counted keys the account needs before its sandboxes may run on free vCPU-seconds." }),
|
|
634
1446
|
month_used_up: Boolean.annotate({ description: "Whether the free vCPU-seconds on `provider` that all accounts share this month are used up, so no free sandbox fits until use more than 31 days old stops counting. The account's own `remaining_vcpu_seconds` stays as it is, and a create that would go past the month's share routes to a provider whose credential the organization stored, or fails with `no_provider_available`." }),
|
|
635
1447
|
provider: Provider.annotate({ description: "The provider whose sandboxes run on free vCPU-seconds, on its account that Sandcovery pays for." }),
|
|
636
1448
|
remaining_vcpu_seconds: VcpuSeconds.annotate({ description: "`cap_vcpu_seconds` less `used_vcpu_seconds`, never below zero." }),
|
|
637
1449
|
used_vcpu_seconds: VcpuSeconds.annotate({ description: "vCPU-seconds of the account's ended free sandboxes as they ran, plus each live one's vCPUs over its full TTL." }),
|
|
638
|
-
vcpu_seconds_per_key: VcpuSeconds.annotate({ description: "The free vCPU-seconds each counted key earns." })
|
|
1450
|
+
vcpu_seconds_per_key: VcpuSeconds.annotate({ description: "The free vCPU-seconds each counted key earns." }),
|
|
1451
|
+
x_post_counted: Boolean.annotate({ description: `Whether a post on X that tags @${SANDCOVERY_X_HANDLE} counted as one of the account's keys. One post counts per account, for good.` })
|
|
639
1452
|
}).annotate({
|
|
640
1453
|
description: "Free vCPU-seconds on `provider`, which an organization with no credential of its own for `provider` may route to. They belong to the account that owns the organization, the organization's earliest owner, and every organization that account owns draws on them.",
|
|
641
1454
|
identifier: "Offer"
|
|
642
1455
|
});
|
|
1456
|
+
Struct({ url: NonEmptyString.check(isMaxLength(POST_URL_MAX)).annotate({ description: "The post's address on x.com or twitter.com, such as `https://x.com/<handle>/status/<id>`." }) }).annotate({
|
|
1457
|
+
description: `A post on X that tags @${SANDCOVERY_X_HANDLE}, to count as one key of the free vCPU-seconds.`,
|
|
1458
|
+
identifier: "XPostRequest"
|
|
1459
|
+
});
|
|
1460
|
+
// ../sandcovery-contract/src/origin.ts
|
|
1461
|
+
const SANDCOVERY_ORIGIN = "https://www.sandcovery.com";
|
|
1462
|
+
const isLocalPath = (path) => path.startsWith("/") && !path.startsWith("//") && !path.startsWith("/\\");
|
|
1463
|
+
const LocalPath = String$1.check(makeFilter(isLocalPath, { expected: "a path on this site" }));
|
|
1464
|
+
const API_PREFIX = "/api/v1";
|
|
1465
|
+
// ../sandcovery-contract/src/process.ts
|
|
1466
|
+
const TerminalCells = Int.check(isBetween({
|
|
1467
|
+
maximum: 65535,
|
|
1468
|
+
minimum: 1
|
|
1469
|
+
}));
|
|
1470
|
+
const ProcessTerminal = Struct({
|
|
1471
|
+
cols: TerminalCells.annotate({ description: "Columns of the terminal." }),
|
|
1472
|
+
rows: TerminalCells.annotate({ description: "Rows of the terminal." }),
|
|
1473
|
+
stderr: Boolean.annotate({ description: "Whether stderr is the terminal." }),
|
|
1474
|
+
stdin: Boolean.annotate({ description: "Whether stdin is the terminal." }),
|
|
1475
|
+
stdout: Boolean.annotate({ description: "Whether stdout is the terminal." })
|
|
1476
|
+
}).annotate({
|
|
1477
|
+
description: "A pseudo-terminal of the given size, and which of stdin, stdout, and stderr sit on it. At least one does; the rest are pipes.",
|
|
1478
|
+
identifier: "ProcessTerminal"
|
|
1479
|
+
});
|
|
1480
|
+
Struct({
|
|
1481
|
+
...commandFields,
|
|
1482
|
+
terminal: optionalKey(ProcessTerminal)
|
|
1483
|
+
}).annotate({
|
|
1484
|
+
description: "A command to run as a process, with no timeout, on a terminal or on pipes.",
|
|
1485
|
+
identifier: "ProcessRequest"
|
|
1486
|
+
});
|
|
1487
|
+
const ProcessStatus = Literals([
|
|
1488
|
+
"exited",
|
|
1489
|
+
"lost",
|
|
1490
|
+
"running"
|
|
1491
|
+
]).annotate({
|
|
1492
|
+
description: "`running` until the command exits, then `exited`, or `lost` when the sandbox ended before the process reported an exit.",
|
|
1493
|
+
identifier: "ProcessStatus"
|
|
1494
|
+
});
|
|
1495
|
+
const Process = Struct({
|
|
1496
|
+
command: String$1,
|
|
1497
|
+
created_at: Timestamp,
|
|
1498
|
+
exit_code: NullOr(Int).annotate({ description: "The exit code, 128 plus the signal number after a signal, or null until the command exits." }),
|
|
1499
|
+
exited_at: NullOr(Timestamp),
|
|
1500
|
+
id: ProcessId,
|
|
1501
|
+
sandbox_id: SandboxId,
|
|
1502
|
+
signal: NullOr(String$1).annotate({ description: "The signal that ended the command, such as `SIGKILL`." }),
|
|
1503
|
+
status: ProcessStatus,
|
|
1504
|
+
terminal: NullOr(ProcessTerminal)
|
|
1505
|
+
}).annotate({
|
|
1506
|
+
description: "A command a sandbox runs on a terminal or pipes. A client attaches to its stdin, stdout, stderr, resizes, and signals over a WebSocket at `/api/v1/sandboxes/{sandbox_id}/processes/{process_id}/attach`.",
|
|
1507
|
+
identifier: "Process"
|
|
1508
|
+
});
|
|
643
1509
|
// ../sandcovery-contract/src/usage.ts
|
|
644
1510
|
const EstimateRequest = Struct({
|
|
645
1511
|
...SandboxSpec.fields,
|
|
@@ -660,6 +1526,32 @@ const Estimate = Struct({
|
|
|
660
1526
|
identifier: "Estimate"
|
|
661
1527
|
});
|
|
662
1528
|
const EstimateList = Struct({ data: ArraySchema(Estimate).annotate({ description: "One estimate per candidate provider that can run the spec, in routing order, each at the size of the first slug that reaches it." }) }).annotate({ identifier: "EstimateList" });
|
|
1529
|
+
const MONTH_TEXT = "an average month of 365/12 days";
|
|
1530
|
+
const MonthlyCostQuery = Struct({
|
|
1531
|
+
hours_per_day: FiniteFromString.check(isGreaterThan(0), isBetween({
|
|
1532
|
+
maximum: 24,
|
|
1533
|
+
minimum: 0
|
|
1534
|
+
})).pipe(annotateEncoded({ description: `Hours a day the sandbox runs, above 0 and at most ${String(24)}, such as 8 or 0.5.` })),
|
|
1535
|
+
size: SizeName.annotate({ description: "The size to price, `<vcpu>x<memory_gib>` as in a slug, such as `2x4` or `2x0.5`." })
|
|
1536
|
+
});
|
|
1537
|
+
const MonthlyCost = Struct({
|
|
1538
|
+
hourly_micro_usd: MicroUsd,
|
|
1539
|
+
monthly_micro_usd: MicroUsd.annotate({ description: `List-price cost of the size running \`hours_per_day\` hours on every day of ${MONTH_TEXT}.` }),
|
|
1540
|
+
provider: Provider,
|
|
1541
|
+
rate_card_source_url: String$1.annotate({ description: "The provider's public pricing page the rate card copies." }),
|
|
1542
|
+
rate_card_version: String$1,
|
|
1543
|
+
slug: Slug
|
|
1544
|
+
}).annotate({
|
|
1545
|
+
description: "The list price of one size on one provider, by the hour and for a month, with the slug that pins it there, such as `e2b/2x4`.",
|
|
1546
|
+
identifier: "MonthlyCost"
|
|
1547
|
+
});
|
|
1548
|
+
const MonthlyCostList = Struct({
|
|
1549
|
+
data: ArraySchema(MonthlyCost).annotate({ description: "Each provider Sandcovery routes to that runs the size, cheapest first, and none when no provider runs it." }),
|
|
1550
|
+
slug: Slug
|
|
1551
|
+
}).annotate({
|
|
1552
|
+
description: "The monthly list price of one size on every provider Sandcovery routes to, and `slug`, such as `sandcovery/2x4:cheapest`, which routes a create of that size to the cheapest of them that holds your credential.",
|
|
1553
|
+
identifier: "MonthlyCostList"
|
|
1554
|
+
});
|
|
663
1555
|
const isCalendarDay = makeFilter((value) => {
|
|
664
1556
|
const at = Date.parse(`${value}T00:00:00.000Z`);
|
|
665
1557
|
return Number.isFinite(at) && new Date(at).toISOString().slice(0, 10) === value;
|
|
@@ -712,19 +1604,20 @@ const LiveUsage = Struct({
|
|
|
712
1604
|
at: Timestamp.annotate({ description: "When the API read these figures." }),
|
|
713
1605
|
data: ArraySchema(LiveSandboxes)
|
|
714
1606
|
}).annotate({ identifier: "LiveUsage" });
|
|
1607
|
+
const UsagePeriod = Literals([
|
|
1608
|
+
"day",
|
|
1609
|
+
"month",
|
|
1610
|
+
"total",
|
|
1611
|
+
"week"
|
|
1612
|
+
]).annotate({
|
|
1613
|
+
description: "The window: the current UTC `day`, the ISO `week` from Monday 00:00 UTC, the UTC calendar `month`, or the `total` of every sandbox run.",
|
|
1614
|
+
identifier: "UsagePeriod"
|
|
1615
|
+
});
|
|
715
1616
|
const UsageTotal = Struct({
|
|
716
1617
|
estimated_micro_usd: MicroUsd,
|
|
717
1618
|
gpu_seconds: Natural,
|
|
718
1619
|
memory_gib_seconds: Natural,
|
|
719
|
-
period:
|
|
720
|
-
"day",
|
|
721
|
-
"month",
|
|
722
|
-
"total",
|
|
723
|
-
"week"
|
|
724
|
-
]).annotate({
|
|
725
|
-
description: "The window: the current UTC `day`, the ISO `week` from Monday 00:00 UTC, the UTC calendar `month`, or the `total` of every sandbox run.",
|
|
726
|
-
identifier: "UsagePeriod"
|
|
727
|
-
}),
|
|
1620
|
+
period: UsagePeriod,
|
|
728
1621
|
sandbox_count: Natural.annotate({ description: "Sandboxes that ran at any time in the window." }),
|
|
729
1622
|
sandbox_seconds: Natural,
|
|
730
1623
|
since: NullOr(Timestamp).annotate({ description: "The start of the window, or null for `total`." }),
|
|
@@ -778,6 +1671,79 @@ const Stats = Struct({
|
|
|
778
1671
|
description: "The organization's level, streak, records, and badges, each read from the sandboxes, create attempts, and snapshots it stores.",
|
|
779
1672
|
identifier: "Stats"
|
|
780
1673
|
});
|
|
1674
|
+
// ../sandcovery-contract/src/usage-shares.ts
|
|
1675
|
+
const USAGE_SHARE_FIGURES = [
|
|
1676
|
+
"sandbox_count",
|
|
1677
|
+
"sandbox_seconds",
|
|
1678
|
+
"vcpu_seconds",
|
|
1679
|
+
"memory_gib_seconds",
|
|
1680
|
+
"gpu_seconds",
|
|
1681
|
+
"estimated_micro_usd"
|
|
1682
|
+
];
|
|
1683
|
+
const UsageShareFigure = Literals(USAGE_SHARE_FIGURES).annotate({
|
|
1684
|
+
description: "A figure of a usage total, named as its `UsageTotal` field.",
|
|
1685
|
+
identifier: "UsageShareFigure"
|
|
1686
|
+
});
|
|
1687
|
+
const DEFAULT_SHARED_FIGURES = USAGE_SHARE_FIGURES.filter((figure) => figure !== "estimated_micro_usd");
|
|
1688
|
+
const SHARE_TOKEN_LENGTH = 43;
|
|
1689
|
+
const BASE64URL = /* @__PURE__ */ new Set("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");
|
|
1690
|
+
const isShareToken = (value) => value.length === SHARE_TOKEN_LENGTH && value.split("").every((character) => BASE64URL.has(character));
|
|
1691
|
+
const ShareToken = String$1.check(makeFilter(isShareToken, {
|
|
1692
|
+
expected: "a share token of 43 base64url characters",
|
|
1693
|
+
toJsonSchema: () => ({})
|
|
1694
|
+
})).annotate({ description: "A share token: 32 random bytes as 43 unpadded base64url characters. Anyone holding it can read the figures it shares." });
|
|
1695
|
+
const CreateUsageShareRequest = Struct({
|
|
1696
|
+
figures: ArraySchema(UsageShareFigure).check(isMinLength(1), isMaxLength(USAGE_SHARE_FIGURES.length)).annotate({ description: "The figures of the window to share, at least one. The share shows each once, in the order `UsageShareFigure` lists them." }),
|
|
1697
|
+
period: UsagePeriod
|
|
1698
|
+
}).annotate({
|
|
1699
|
+
description: "The window whose usage total to share and the figures of it to show. Nothing else of the organization becomes public.",
|
|
1700
|
+
identifier: "CreateUsageShareRequest"
|
|
1701
|
+
});
|
|
1702
|
+
const SharedUsageFigure = Struct({
|
|
1703
|
+
figure: UsageShareFigure,
|
|
1704
|
+
value: Natural.annotate({ description: "The value, in the unit of its `UsageTotal` field." })
|
|
1705
|
+
}).annotate({ identifier: "SharedUsageFigure" });
|
|
1706
|
+
const SharedUsage = Struct({
|
|
1707
|
+
at: Timestamp.annotate({ description: "When the API read the figures. They never change after." }),
|
|
1708
|
+
figures: ArraySchema(SharedUsageFigure).annotate({ description: "The shared figures, in the order `UsageShareFigure` lists them." }),
|
|
1709
|
+
period: UsagePeriod,
|
|
1710
|
+
shared_by: String$1.annotate({ description: "The Sandcovery username of the person who shared, as it reads now, so a rename shows on every link they shared." }),
|
|
1711
|
+
since: NullOr(Timestamp).annotate({ description: "The start of the window, or null for `total`." })
|
|
1712
|
+
}).annotate({
|
|
1713
|
+
description: "A usage total an organization shared by link: only the window and the figures it chose, read once when it shared them, and the username of the person who shared, with no organization, email, name, key, or billing detail.",
|
|
1714
|
+
identifier: "SharedUsage"
|
|
1715
|
+
});
|
|
1716
|
+
const UsageShare = Struct({
|
|
1717
|
+
id: UsageShareId,
|
|
1718
|
+
image_url: String$1.annotate({ description: "The PNG card of the share, which its page names as its social image and anyone can download without signing in." }),
|
|
1719
|
+
token: ShareToken,
|
|
1720
|
+
url: String$1.annotate({ description: "The public page of the share, which anyone can open without signing in." }),
|
|
1721
|
+
usage: SharedUsage
|
|
1722
|
+
}).annotate({
|
|
1723
|
+
description: "A public link to one usage total of the organization. It lives until revoked.",
|
|
1724
|
+
identifier: "UsageShare"
|
|
1725
|
+
});
|
|
1726
|
+
const UsageShareList = Struct({ data: ArraySchema(UsageShare).annotate({ description: "Every live usage share of the organization, newest first." }) }).annotate({ identifier: "UsageShareList" });
|
|
1727
|
+
// ../sandcovery-contract/src/x-account.ts
|
|
1728
|
+
const XAccount = Struct({
|
|
1729
|
+
id: String$1.annotate({ description: "X's ID of the account." }),
|
|
1730
|
+
linked_at: Timestamp,
|
|
1731
|
+
username: String$1.annotate({ description: "The X handle, without the leading @." })
|
|
1732
|
+
}).annotate({
|
|
1733
|
+
description: "The X account linked to you.",
|
|
1734
|
+
identifier: "XAccount"
|
|
1735
|
+
});
|
|
1736
|
+
const XAccountStatus = Struct({
|
|
1737
|
+
linked: NullOr(XAccount).annotate({ description: "The X account linked to you, or null while none is." }),
|
|
1738
|
+
linking_open: Boolean.annotate({ description: "Whether Sandcovery links X accounts now." })
|
|
1739
|
+
}).annotate({
|
|
1740
|
+
description: "The X account linked to you, and whether linking is open.",
|
|
1741
|
+
identifier: "XAccountStatus"
|
|
1742
|
+
});
|
|
1743
|
+
const XAccountLink = Struct({ url: String$1.annotate({ description: "The dashboard page where you confirm the link on X, signed in to www.sandcovery.com as yourself." }) }).annotate({
|
|
1744
|
+
description: "Where to finish linking an X account, since X confirms it in the browser.",
|
|
1745
|
+
identifier: "XAccountLink"
|
|
1746
|
+
});
|
|
781
1747
|
// src/sse.ts
|
|
782
1748
|
const fieldOf = (line) => {
|
|
783
1749
|
const colon = line.indexOf(":");
|
|
@@ -820,6 +1786,8 @@ const serverSentEvents = async function* (body) {
|
|
|
820
1786
|
};
|
|
821
1787
|
// src/index.ts
|
|
822
1788
|
const STREAM_FAILURE_EVENT = "effect/http-api/stream/failure";
|
|
1789
|
+
const X_ACCOUNT_PATH = "/x-account";
|
|
1790
|
+
const AUTO_TOP_UP_PATH = "/billing/auto-top-up";
|
|
823
1791
|
const decodeApiError = decodeUnknownOption(fromJsonString(ApiError));
|
|
824
1792
|
const failureOf = async (response) => {
|
|
825
1793
|
const text = await response.text();
|
|
@@ -830,12 +1798,14 @@ const failureOf = async (response) => {
|
|
|
830
1798
|
};
|
|
831
1799
|
const segment = (schema, value) => encodeURIComponent(decodeUnknownSync(schema)(value));
|
|
832
1800
|
const sandboxPath = (sandboxId) => `/sandboxes/${segment(SandboxId, sandboxId)}`;
|
|
1801
|
+
const processPath = (sandboxId, processId) => `${sandboxPath(sandboxId)}/processes/${segment(ProcessId, processId)}`;
|
|
833
1802
|
const keyPath = (keyId) => `/keys/${segment(KeyId, keyId)}`;
|
|
834
1803
|
const portSegment = (port) => String(decodeUnknownSync(Port)(port));
|
|
835
1804
|
const credentialPath = (provider) => `/credentials/${segment(Provider, provider)}`;
|
|
836
1805
|
const ciJobPath = (jobId) => `/ci/jobs/${segment(CiJobId, jobId)}`;
|
|
837
1806
|
const ciInstallationPath = (installationId) => `/ci/installations/${String(decodeUnknownSync(GitHubId)(installationId))}`;
|
|
838
1807
|
const filePath = (sandboxId) => `${sandboxPath(sandboxId)}/files/content`;
|
|
1808
|
+
const USAGE_SHARES_PATH = "/usage/shares";
|
|
839
1809
|
const decodeExecEvent = decodeUnknownSync(fromJsonString(ExecEvent));
|
|
840
1810
|
var Sandcovery = class {
|
|
841
1811
|
activity;
|
|
@@ -844,10 +1814,12 @@ var Sandcovery = class {
|
|
|
844
1814
|
credentials;
|
|
845
1815
|
keys;
|
|
846
1816
|
pricing;
|
|
1817
|
+
problems;
|
|
847
1818
|
providers;
|
|
848
1819
|
sandboxes;
|
|
849
1820
|
stats;
|
|
850
1821
|
usage;
|
|
1822
|
+
xAccount;
|
|
851
1823
|
constructor(options = {}) {
|
|
852
1824
|
const configuredKey = options.apiKey ?? globalThis.process?.env.SANDCOVERY_API_KEY;
|
|
853
1825
|
const apiKey = configuredKey === "" ? void 0 : configuredKey;
|
|
@@ -873,6 +1845,17 @@ var Sandcovery = class {
|
|
|
873
1845
|
return decodeUnknownSync(fromJsonString(schema))(text);
|
|
874
1846
|
};
|
|
875
1847
|
this.sandboxes = {
|
|
1848
|
+
attachProcess: (sandboxId, processId, attachOptions = {}) => {
|
|
1849
|
+
const path = processPath(sandboxId, processId);
|
|
1850
|
+
const url = new URL(`${API_PREFIX}${path}/attach`, baseUrl);
|
|
1851
|
+
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
1852
|
+
return attach({
|
|
1853
|
+
check: async () => await read(Process, "GET", path, { signal: attachOptions.signal }),
|
|
1854
|
+
credential: apiKey ?? null,
|
|
1855
|
+
options: attachOptions,
|
|
1856
|
+
url
|
|
1857
|
+
});
|
|
1858
|
+
},
|
|
876
1859
|
create: async (request = {}, { idempotencyKey, signal } = {}) => await read(Sandbox, "POST", "/sandboxes", {
|
|
877
1860
|
headers: idempotencyKey === void 0 ? {} : { "idempotency-key": idempotencyKey },
|
|
878
1861
|
json: request,
|
|
@@ -908,6 +1891,7 @@ var Sandcovery = class {
|
|
|
908
1891
|
}
|
|
909
1892
|
},
|
|
910
1893
|
get: async (sandboxId, { signal } = {}) => await read(Sandbox, "GET", sandboxPath(sandboxId), { signal }),
|
|
1894
|
+
getProcess: async (sandboxId, processId, { signal } = {}) => await read(Process, "GET", processPath(sandboxId, processId), { signal }),
|
|
911
1895
|
list: async (query = {}, { signal } = {}) => await read(SandboxList, "GET", "/sandboxes", {
|
|
912
1896
|
query: { ...query },
|
|
913
1897
|
signal
|
|
@@ -927,6 +1911,10 @@ var Sandcovery = class {
|
|
|
927
1911
|
},
|
|
928
1912
|
resume: async (sandboxId, { signal } = {}) => await read(Sandbox, "POST", `${sandboxPath(sandboxId)}/resume`, { signal }),
|
|
929
1913
|
snapshot: async (sandboxId, { signal } = {}) => await read(Snapshot, "POST", `${sandboxPath(sandboxId)}/snapshot`, { signal }),
|
|
1914
|
+
startProcess: async (sandboxId, request, { signal } = {}) => await read(Process, "POST", `${sandboxPath(sandboxId)}/processes`, {
|
|
1915
|
+
json: request,
|
|
1916
|
+
signal
|
|
1917
|
+
}),
|
|
930
1918
|
writeFile: async (sandboxId, path, content, { signal } = {}) => await read(FileEntry, "PUT", filePath(sandboxId), {
|
|
931
1919
|
body: content instanceof Uint8Array ? new Uint8Array(content) : content,
|
|
932
1920
|
headers: { "content-type": "application/octet-stream" },
|
|
@@ -952,6 +1940,10 @@ var Sandcovery = class {
|
|
|
952
1940
|
json: fields,
|
|
953
1941
|
signal
|
|
954
1942
|
}),
|
|
1943
|
+
countXPost: async (request, { signal } = {}) => await read(Offer, "POST", "/offer/x-post", {
|
|
1944
|
+
json: request,
|
|
1945
|
+
signal
|
|
1946
|
+
}),
|
|
955
1947
|
delete: async (provider, { signal } = {}) => {
|
|
956
1948
|
await call("DELETE", credentialPath(provider), { signal });
|
|
957
1949
|
},
|
|
@@ -974,7 +1966,12 @@ var Sandcovery = class {
|
|
|
974
1966
|
json: request,
|
|
975
1967
|
signal
|
|
976
1968
|
}),
|
|
977
|
-
get: async ({ signal } = {}) => await read(Billing, "GET", "/billing", { signal })
|
|
1969
|
+
get: async ({ signal } = {}) => await read(Billing, "GET", "/billing", { signal }),
|
|
1970
|
+
setAutoTopUp: async (request, { signal } = {}) => await read(AutoTopUpChange, "PUT", AUTO_TOP_UP_PATH, {
|
|
1971
|
+
json: request,
|
|
1972
|
+
signal
|
|
1973
|
+
}),
|
|
1974
|
+
stopAutoTopUp: async ({ signal } = {}) => await read(AutoTopUp, "DELETE", AUTO_TOP_UP_PATH, { signal })
|
|
978
1975
|
};
|
|
979
1976
|
this.ci = {
|
|
980
1977
|
getJob: async (jobId, { signal } = {}) => await read(CiJob, "GET", ciJobPath(jobId), { signal }),
|
|
@@ -987,7 +1984,19 @@ var Sandcovery = class {
|
|
|
987
1984
|
await call("DELETE", ciInstallationPath(installationId), { signal });
|
|
988
1985
|
}
|
|
989
1986
|
};
|
|
990
|
-
this.pricing = {
|
|
1987
|
+
this.pricing = {
|
|
1988
|
+
get: async ({ signal } = {}) => await read(Pricing, "GET", "/pricing", { signal }),
|
|
1989
|
+
monthly: async (query, { signal } = {}) => await read(MonthlyCostList, "GET", "/pricing/monthly", {
|
|
1990
|
+
query: { ...query },
|
|
1991
|
+
signal
|
|
1992
|
+
})
|
|
1993
|
+
};
|
|
1994
|
+
this.problems = { report: async (request, { signal } = {}) => {
|
|
1995
|
+
await call("POST", "/problem-reports", {
|
|
1996
|
+
json: request,
|
|
1997
|
+
signal
|
|
1998
|
+
});
|
|
1999
|
+
} };
|
|
991
2000
|
this.providers = {
|
|
992
2001
|
catalog: async ({ signal } = {}) => await read(ProviderCatalog, "GET", "/catalog", { signal }),
|
|
993
2002
|
get: async (provider, { signal } = {}) => await read(ProviderBoardEntry, "GET", `/providers/${segment(Provider, provider)}`, { signal }),
|
|
@@ -1003,15 +2012,31 @@ var Sandcovery = class {
|
|
|
1003
2012
|
query: { ...query },
|
|
1004
2013
|
signal
|
|
1005
2014
|
}),
|
|
2015
|
+
getShared: async (token, { signal } = {}) => await read(SharedUsage, "GET", `/shared-usage/${segment(ShareToken, token)}`, { signal }),
|
|
2016
|
+
listShares: async ({ signal } = {}) => await read(UsageShareList, "GET", USAGE_SHARES_PATH, { signal }),
|
|
1006
2017
|
live: async (query = {}, { signal } = {}) => await read(LiveUsage, "GET", "/usage/live", {
|
|
1007
2018
|
query: { ...query },
|
|
1008
2019
|
signal
|
|
1009
2020
|
}),
|
|
2021
|
+
revokeShare: async (shareId, { signal } = {}) => {
|
|
2022
|
+
await call("DELETE", `${USAGE_SHARES_PATH}/${segment(UsageShareId, shareId)}`, { signal });
|
|
2023
|
+
},
|
|
2024
|
+
share: async (request, { signal } = {}) => await read(UsageShare, "POST", USAGE_SHARES_PATH, {
|
|
2025
|
+
json: request,
|
|
2026
|
+
signal
|
|
2027
|
+
}),
|
|
1010
2028
|
totals: async (query = {}, { signal } = {}) => await read(UsageTotals, "GET", "/usage/totals", {
|
|
1011
2029
|
query: { ...query },
|
|
1012
2030
|
signal
|
|
1013
2031
|
})
|
|
1014
2032
|
};
|
|
2033
|
+
this.xAccount = {
|
|
2034
|
+
get: async ({ signal } = {}) => await read(XAccountStatus, "GET", X_ACCOUNT_PATH, { signal }),
|
|
2035
|
+
link: async ({ signal } = {}) => await read(XAccountLink, "POST", X_ACCOUNT_PATH, { signal }),
|
|
2036
|
+
unlink: async ({ signal } = {}) => {
|
|
2037
|
+
await call("DELETE", X_ACCOUNT_PATH, { signal });
|
|
2038
|
+
}
|
|
2039
|
+
};
|
|
1015
2040
|
}
|
|
1016
2041
|
};
|
|
1017
|
-
export {
|
|
2042
|
+
export { NO_MARKUP_TERMS as A, DEFAULT_SLUG as B, AUTO_TOP_UP_THRESHOLD_MIN_MICRO_USD as C, ENTERPRISE_PLAN as D, CREDIT_PURCHASE_MIN_MICRO_USD as E, Unauthorized as F, CiJobId as G, Forbidden as H, NotFound as I, KeySecret as J, CredentialId as K, CreateSandboxRequest as L, thresholdBelowTopUp as M, ApiError as N, FREE_PLAN as O, Unsupported as P, UsageShareId as Q, Port as R, AUTO_TOP_UP_THRESHOLD_MAX_MICRO_USD as S, CREDIT_PURCHASE_MAX_MICRO_USD as T, Conflict as U, ProviderSort as V, ApiKeyId as W, Provider as X, ProcessId as Y, SandboxId as Z, KeyKind as _, USAGE_SHARE_FIGURES as a, CredentialFields as b, EstimateRequest as c, UsagePeriod as d, API_PREFIX as f, CreateKeyRequest as g, SANDCOVERY_X_HANDLE as h, ShareToken as i, creditsAfterFeeMicroUsd as j, MICRO_USD_PER_DOLLAR as k, MONTH_TEXT as l, SANDCOVERY_ORIGIN as m, CreateUsageShareRequest as n, UsageShareFigure as o, LocalPath as p, KeyId as q, DEFAULT_SHARED_FIGURES as r, CalendarDay as s, Sandcovery as t, MonthlyCostQuery as u, SpendLimit as v, CARD_FEE_TERMS as w, GitHubId as x, UpdateKeyRequest as y, SandboxStatus as z };
|