sandcovery 0.2.0 → 0.4.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 +17 -7
- package/dist/{Schema-C4ay0Aif.mjs → Schema-CFI3ZMu8.mjs} +216 -4
- package/dist/cli/index.mjs +10 -29
- package/dist/handlers-BS1KuMqq.mjs +6546 -0
- package/dist/index.d.mts +31 -1
- package/dist/index.mjs +1 -1
- package/dist/{origin-Dj-n4EQa.mjs → origin-BTx2gX8x.mjs} +162 -81
- package/dist/posthog-project-BpOd2VxW.mjs +1 -0
- package/dist/{posthog-project-Bb0IFKUv.mjs → posthog-project-CdWw_ofg.mjs} +3 -1
- package/dist/{spec-ClAX0dAN.mjs → spec-B4c-Ug3B.mjs} +765 -144
- package/dist/src-DPDVOBkr.mjs +1016 -0
- package/dist/{telemetry-delivery-1a7C-8DK.mjs → telemetry-delivery-Yd6CeynR.mjs} +3 -3
- package/dist/types-DvoIdTvQ.d.mts +684 -0
- package/dist/types.d.mts +2 -2
- package/dist/types.mjs +35 -19
- package/package.json +6 -4
- package/dist/handlers-BxhSLDGk.mjs +0 -2217
- package/dist/posthog-project-B0jmQTwy.mjs +0 -1
- package/dist/src-D3WZodpF.mjs +0 -572
- package/dist/types-Dxh7amZB.d.mts +0 -345
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { t as OTLP_DESTINATIONS, n as POSTHOG_INGEST_HOST, r as POSTHOG_PROJECT_TOKEN, i as WORKER_OBSERVABILITY } from "./posthog-project-Bb0IFKUv.mjs";
|
package/dist/src-D3WZodpF.mjs
DELETED
|
@@ -1,572 +0,0 @@
|
|
|
1
|
-
import { A as tag, B as getOrElse, C as isBetween, D as makeFilter, _ as decodeUnknownOption, a as Int, b as fromJsonString, c as Literals, d as NonEmptyString, f as NullOr, g as Union, h as Struct, i as Finite, k as optionalKey, l as Natural, m as String$1, n as Boolean, p as Record, r as Error$1, s as Literal, t as ArraySchema, y as decodeUnknownSync } from "./Schema-C4ay0Aif.mjs";
|
|
2
|
-
import { C as KeyId, D as Region, E as Provider, O as SandboxId, S as ApiKeyId, T as MicroUsd, a as Key, f as Port, g as SandboxSpec, h as SandboxList, i as CreatedKey, k as Timestamp, m as Sandbox, p as PortPreview, s as KeyList, t as API_PREFIX, u as CreateAttempt, v as Snapshot, x as StandardSize, y as ProviderPreferences } from "./origin-Dj-n4EQa.mjs";
|
|
3
|
-
// ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/ErrorReporter.js
|
|
4
|
-
/**
|
|
5
|
-
* Defines the runtime property key used to mark an object error as ignored by error
|
|
6
|
-
* reporting.
|
|
7
|
-
*
|
|
8
|
-
* **When to use**
|
|
9
|
-
*
|
|
10
|
-
* Use to suppress reporting for expected object errors, such as HTTP 404
|
|
11
|
-
* responses.
|
|
12
|
-
*
|
|
13
|
-
* **Details**
|
|
14
|
-
*
|
|
15
|
-
* Set `error[ErrorReporter.ignore]` to `true` to prevent the error from being
|
|
16
|
-
* forwarded to reporters. This is useful for expected failures such as HTTP 404
|
|
17
|
-
* responses.
|
|
18
|
-
*
|
|
19
|
-
* **Example** (Marking errors as ignored)
|
|
20
|
-
*
|
|
21
|
-
* ```ts import.meta.vitest
|
|
22
|
-
* import { Data, ErrorReporter } from "effect"
|
|
23
|
-
*
|
|
24
|
-
* class NotFoundError extends Data.TaggedError("NotFoundError")<{}> {
|
|
25
|
-
* readonly [ErrorReporter.ignore] = true
|
|
26
|
-
* }
|
|
27
|
-
*
|
|
28
|
-
* ErrorReporter.isIgnored(new NotFoundError()) // => true
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* @see {@link isIgnored} for checking whether a value carries this annotation
|
|
32
|
-
* @see {@link Reportable} for the annotation contract recognized on object
|
|
33
|
-
* errors
|
|
34
|
-
*
|
|
35
|
-
* @stability unstable
|
|
36
|
-
* @category annotations
|
|
37
|
-
* @since 4.0.0
|
|
38
|
-
*/
|
|
39
|
-
const ignore = "~effect/ErrorReporter/ignore";
|
|
40
|
-
const ActivityAction = NonEmptyString.annotate({
|
|
41
|
-
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
|
-
examples: [
|
|
43
|
-
"sandbox.create",
|
|
44
|
-
"sandbox.create_attempt",
|
|
45
|
-
"sandbox.destroy",
|
|
46
|
-
"sandbox.expire",
|
|
47
|
-
"sandbox.pause",
|
|
48
|
-
"sandbox.resume",
|
|
49
|
-
"sandbox.snapshot"
|
|
50
|
-
],
|
|
51
|
-
identifier: "ActivityAction"
|
|
52
|
-
});
|
|
53
|
-
const ActivityEvent = Struct({
|
|
54
|
-
action: ActivityAction,
|
|
55
|
-
api_key_id: NullOr(ApiKeyId),
|
|
56
|
-
at: Timestamp,
|
|
57
|
-
error: NullOr(String$1).annotate({ description: "Why the action failed, or null when it succeeded." }),
|
|
58
|
-
id: NonEmptyString,
|
|
59
|
-
outcome: Literals(["failed", "succeeded"]),
|
|
60
|
-
provider: NullOr(Provider),
|
|
61
|
-
sandbox_id: NullOr(SandboxId)
|
|
62
|
-
}).annotate({
|
|
63
|
-
description: "One entry of the activity log, which records every sandbox lifecycle call and create attempt.",
|
|
64
|
-
identifier: "ActivityEvent"
|
|
65
|
-
});
|
|
66
|
-
const ActivityList = Struct({
|
|
67
|
-
data: ArraySchema(ActivityEvent),
|
|
68
|
-
next_cursor: NullOr(String$1)
|
|
69
|
-
}).annotate({ identifier: "ActivityList" });
|
|
70
|
-
// ../sandcovery-contract/src/credentials.ts
|
|
71
|
-
const CredentialFields = Record(String$1, NonEmptyString).annotate({
|
|
72
|
-
description: "The provider's credential fields by name, as its `credential_fields` on the provider board lists them, such as `api_key` for `e2b` or `token`, `team_id`, and `project_id` for `vercel`. A missing or unknown field answers 400 `invalid_request`.",
|
|
73
|
-
identifier: "CredentialFields"
|
|
74
|
-
});
|
|
75
|
-
const ProviderCredential = Struct({
|
|
76
|
-
created_at: Timestamp,
|
|
77
|
-
hint: String$1.annotate({ description: "The last four characters of the first secret field, for display." }),
|
|
78
|
-
provider: Provider,
|
|
79
|
-
updated_at: Timestamp
|
|
80
|
-
}).annotate({
|
|
81
|
-
description: "A stored provider credential. Sandcovery encrypts it at rest and never returns its fields.",
|
|
82
|
-
identifier: "ProviderCredential"
|
|
83
|
-
});
|
|
84
|
-
const ProviderCredentialList = Struct({ data: ArraySchema(ProviderCredential) }).annotate({ identifier: "ProviderCredentialList" });
|
|
85
|
-
// ../sandcovery-contract/src/errors/concurrency-limit-reached.ts
|
|
86
|
-
var ConcurrencyLimitReached = class extends Error$1("ConcurrencyLimitReached")({
|
|
87
|
-
concurrency_cap: Natural,
|
|
88
|
-
error: tag("concurrency_limit_reached"),
|
|
89
|
-
message: String$1
|
|
90
|
-
}, {
|
|
91
|
-
description: "The API key already has `concurrency_cap` live sandboxes, its `max_concurrent_sandboxes`. Destroy one or wait for one to end.",
|
|
92
|
-
httpApiStatus: 429,
|
|
93
|
-
identifier: "ConcurrencyLimitReached"
|
|
94
|
-
}) {
|
|
95
|
-
[ignore] = true;
|
|
96
|
-
};
|
|
97
|
-
// ../sandcovery-contract/src/errors/conflict.ts
|
|
98
|
-
var Conflict = class extends Error$1("Conflict")({
|
|
99
|
-
error: tag("conflict"),
|
|
100
|
-
message: String$1
|
|
101
|
-
}, {
|
|
102
|
-
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.",
|
|
103
|
-
httpApiStatus: 409,
|
|
104
|
-
identifier: "Conflict"
|
|
105
|
-
}) {
|
|
106
|
-
[ignore] = true;
|
|
107
|
-
};
|
|
108
|
-
// ../sandcovery-contract/src/errors/forbidden.ts
|
|
109
|
-
var Forbidden = class extends Error$1("Forbidden")({
|
|
110
|
-
error: tag("forbidden"),
|
|
111
|
-
message: String$1
|
|
112
|
-
}, {
|
|
113
|
-
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 or admin on keys, usage, or provider credentials, or a TTL over the API key's `max_ttl_seconds`. `message` names the rule.",
|
|
114
|
-
httpApiStatus: 403,
|
|
115
|
-
identifier: "Forbidden"
|
|
116
|
-
}) {
|
|
117
|
-
[ignore] = true;
|
|
118
|
-
};
|
|
119
|
-
// ../sandcovery-contract/src/errors/invalid-request.ts
|
|
120
|
-
var InvalidRequest = class extends Error$1("InvalidRequest")({
|
|
121
|
-
error: tag("invalid_request"),
|
|
122
|
-
message: String$1
|
|
123
|
-
}, {
|
|
124
|
-
description: "The path, query, headers, or body do not decode against the operation, or contradict each other, and `message` names the failure.",
|
|
125
|
-
httpApiStatus: 400,
|
|
126
|
-
identifier: "InvalidRequest"
|
|
127
|
-
}) {
|
|
128
|
-
[ignore] = true;
|
|
129
|
-
};
|
|
130
|
-
// ../sandcovery-contract/src/errors/no-provider-available.ts
|
|
131
|
-
var NoProviderAvailable = class extends Error$1("NoProviderAvailable")({
|
|
132
|
-
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." }),
|
|
133
|
-
error: tag("no_provider_available"),
|
|
134
|
-
message: String$1
|
|
135
|
-
}, {
|
|
136
|
-
description: "Every candidate provider failed to create the sandbox, or none was left after filtering.",
|
|
137
|
-
httpApiStatus: 503,
|
|
138
|
-
identifier: "NoProviderAvailable"
|
|
139
|
-
}) {};
|
|
140
|
-
// ../sandcovery-contract/src/errors/not-found.ts
|
|
141
|
-
var NotFound = class extends Error$1("NotFound")({
|
|
142
|
-
error: tag("not_found"),
|
|
143
|
-
message: String$1
|
|
144
|
-
}, {
|
|
145
|
-
description: "The resource the path names does not exist or belongs to another organization or key.",
|
|
146
|
-
httpApiStatus: 404,
|
|
147
|
-
identifier: "NotFound"
|
|
148
|
-
}) {
|
|
149
|
-
[ignore] = true;
|
|
150
|
-
};
|
|
151
|
-
// ../sandcovery-contract/src/errors/provider-error.ts
|
|
152
|
-
var ProviderError = class extends Error$1("ProviderError")({
|
|
153
|
-
error: tag("provider_error"),
|
|
154
|
-
message: String$1,
|
|
155
|
-
provider: Provider
|
|
156
|
-
}, {
|
|
157
|
-
description: "The sandbox's provider failed the call. `message` carries the provider's reason.",
|
|
158
|
-
httpApiStatus: 502,
|
|
159
|
-
identifier: "ProviderError"
|
|
160
|
-
}) {};
|
|
161
|
-
// ../sandcovery-contract/src/errors/spend-limit-reached.ts
|
|
162
|
-
var SpendLimitReached = class extends Error$1("SpendLimitReached")({
|
|
163
|
-
error: tag("spend_limit_reached"),
|
|
164
|
-
limit_micro_usd: MicroUsd,
|
|
165
|
-
message: String$1,
|
|
166
|
-
resets_at: NullOr(Timestamp),
|
|
167
|
-
spent_micro_usd: MicroUsd
|
|
168
|
-
}, {
|
|
169
|
-
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.",
|
|
170
|
-
httpApiStatus: 402,
|
|
171
|
-
identifier: "SpendLimitReached"
|
|
172
|
-
}) {
|
|
173
|
-
[ignore] = true;
|
|
174
|
-
};
|
|
175
|
-
// ../sandcovery-contract/src/errors/unauthorized.ts
|
|
176
|
-
var Unauthorized = class extends Error$1("Unauthorized")({
|
|
177
|
-
error: tag("unauthorized"),
|
|
178
|
-
message: String$1
|
|
179
|
-
}, {
|
|
180
|
-
description: "The request carries no live key and no signed-in session, or a key that is unknown, revoked, or expired.",
|
|
181
|
-
httpApiStatus: 401,
|
|
182
|
-
identifier: "Unauthorized"
|
|
183
|
-
}) {
|
|
184
|
-
[ignore] = true;
|
|
185
|
-
};
|
|
186
|
-
// ../sandcovery-contract/src/errors/unsupported.ts
|
|
187
|
-
var Unsupported = class extends Error$1("Unsupported")({
|
|
188
|
-
error: tag("unsupported"),
|
|
189
|
-
message: String$1,
|
|
190
|
-
options: ArraySchema(String$1).annotate({ description: "The sizes that would run for this request. Empty when the cause is not the size, 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." }),
|
|
191
|
-
provider: NullOr(Provider).annotate({ description: "The sandbox's provider for an operation on an existing sandbox, or null for a create." })
|
|
192
|
-
}, {
|
|
193
|
-
description: "A size, spec option, or operation that no candidate provider can serve. Sandcovery never ignores an option. For a size, `options` lists the sizes that would run; otherwise `options` is empty and `message` names the field or operation.",
|
|
194
|
-
httpApiStatus: 422,
|
|
195
|
-
identifier: "Unsupported"
|
|
196
|
-
}) {
|
|
197
|
-
[ignore] = true;
|
|
198
|
-
};
|
|
199
|
-
// ../sandcovery-contract/src/errors/api-error.ts
|
|
200
|
-
const ApiError = Union([
|
|
201
|
-
ConcurrencyLimitReached,
|
|
202
|
-
Conflict,
|
|
203
|
-
Forbidden,
|
|
204
|
-
InvalidRequest,
|
|
205
|
-
NoProviderAvailable,
|
|
206
|
-
NotFound,
|
|
207
|
-
ProviderError,
|
|
208
|
-
SpendLimitReached,
|
|
209
|
-
Unauthorized,
|
|
210
|
-
Unsupported
|
|
211
|
-
]);
|
|
212
|
-
Struct({
|
|
213
|
-
command: NonEmptyString.annotate({ description: "A shell command line, run with `sh -c`." }),
|
|
214
|
-
cwd: optionalKey(NonEmptyString.annotate({ description: "Working directory. Defaults to the provider's default directory." })),
|
|
215
|
-
env: optionalKey(Record(NonEmptyString, String$1).annotate({ description: "Environment variables for this command only." })),
|
|
216
|
-
timeout_seconds: optionalKey(Int.check(isBetween({
|
|
217
|
-
maximum: 3600,
|
|
218
|
-
minimum: 1
|
|
219
|
-
})).annotate({ description: "Seconds after which the command is killed. Defaults to 300." }))
|
|
220
|
-
}).annotate({ identifier: "ExecRequest" });
|
|
221
|
-
const ExecResult = Struct({
|
|
222
|
-
duration_ms: Natural,
|
|
223
|
-
exit_code: Int,
|
|
224
|
-
stderr: String$1,
|
|
225
|
-
stdout: String$1
|
|
226
|
-
}).annotate({
|
|
227
|
-
description: "The result of a command that ran to its end.",
|
|
228
|
-
identifier: "ExecResult"
|
|
229
|
-
});
|
|
230
|
-
const ExecEvent = Union([
|
|
231
|
-
Struct({
|
|
232
|
-
data: String$1,
|
|
233
|
-
type: Literal("stdout")
|
|
234
|
-
}),
|
|
235
|
-
Struct({
|
|
236
|
-
data: String$1,
|
|
237
|
-
type: Literal("stderr")
|
|
238
|
-
}),
|
|
239
|
-
Struct({
|
|
240
|
-
duration_ms: Natural,
|
|
241
|
-
exit_code: Int,
|
|
242
|
-
type: Literal("exit")
|
|
243
|
-
}),
|
|
244
|
-
Struct({
|
|
245
|
-
message: String$1,
|
|
246
|
-
provider: Provider,
|
|
247
|
-
type: Literal("error")
|
|
248
|
-
})
|
|
249
|
-
]).annotate({
|
|
250
|
-
description: "One server-sent event of a streamed command: output chunks as they arrive, then one `exit`, or one `error` when the provider fails mid-stream.",
|
|
251
|
-
identifier: "ExecEvent"
|
|
252
|
-
});
|
|
253
|
-
Struct({ path: NonEmptyString.annotate({ description: "An absolute path inside the sandbox." }) });
|
|
254
|
-
const FileEntry = Struct({
|
|
255
|
-
modified_at: NullOr(Timestamp),
|
|
256
|
-
name: String$1,
|
|
257
|
-
path: String$1,
|
|
258
|
-
size_bytes: NullOr(Natural),
|
|
259
|
-
type: Literals([
|
|
260
|
-
"directory",
|
|
261
|
-
"file",
|
|
262
|
-
"other",
|
|
263
|
-
"symlink"
|
|
264
|
-
]).annotate({
|
|
265
|
-
description: "`other` is an entry that is neither a file, a directory, nor a symlink, such as a socket or a device.",
|
|
266
|
-
identifier: "FileEntryType"
|
|
267
|
-
})
|
|
268
|
-
}).annotate({ identifier: "FileEntry" });
|
|
269
|
-
const FileList = Struct({
|
|
270
|
-
entries: ArraySchema(FileEntry),
|
|
271
|
-
path: String$1
|
|
272
|
-
}).annotate({ identifier: "FileList" });
|
|
273
|
-
// ../sandcovery-contract/src/providers.ts
|
|
274
|
-
const Ratio = Finite.check(isBetween({
|
|
275
|
-
maximum: 1,
|
|
276
|
-
minimum: 0
|
|
277
|
-
})).annotate({ description: "A share from 0 to 1." });
|
|
278
|
-
const EgressMode = NonEmptyString.annotate({
|
|
279
|
-
description: "An egress policy mode the provider can enforce, such as `allow_all`, `allowlist`, or `deny_all`. The API adds modes over time.",
|
|
280
|
-
examples: [
|
|
281
|
-
"allow_all",
|
|
282
|
-
"allowlist",
|
|
283
|
-
"deny_all"
|
|
284
|
-
],
|
|
285
|
-
identifier: "EgressMode"
|
|
286
|
-
});
|
|
287
|
-
const ProviderFeatures = Struct({
|
|
288
|
-
custom_image: Boolean,
|
|
289
|
-
egress_modes: ArraySchema(EgressMode),
|
|
290
|
-
idle_timeout: Boolean,
|
|
291
|
-
max_disk_mib: NullOr(Natural).annotate({ description: "The largest disk size in MiB the provider takes, or null when it takes no disk size." }),
|
|
292
|
-
max_memory_mib: Natural.annotate({ description: "The most memory in MiB the provider runs. For a provider that states no memory ceiling, such as Depot, it is the memory of the largest standard size the provider runs." }),
|
|
293
|
-
max_ttl_seconds: Natural.annotate({ description: "The longest TTL in seconds. For a provider that states no TTL limit, such as Sprites, it is Sandcovery's own maximum of 86,400, which Sandcovery enforces by destroying the sandbox." }),
|
|
294
|
-
max_vcpu: Natural,
|
|
295
|
-
pause: Boolean,
|
|
296
|
-
ports: Boolean,
|
|
297
|
-
regions: ArraySchema(Region),
|
|
298
|
-
snapshot: Boolean,
|
|
299
|
-
streamed_exec: Boolean
|
|
300
|
-
}).annotate({
|
|
301
|
-
description: "What the provider can enforce. A spec asking for more answers `unsupported` on that provider.",
|
|
302
|
-
identifier: "ProviderFeatures"
|
|
303
|
-
});
|
|
304
|
-
const CredentialField = Struct({
|
|
305
|
-
label: NonEmptyString.annotate({ description: "The field name to show a person, such as \"Team ID\"." }),
|
|
306
|
-
name: NonEmptyString.annotate({ description: "The key of the field in `PUT /api/v1/credentials/{provider}`, such as `team_id`." }),
|
|
307
|
-
secret: Boolean.annotate({ description: "Whether to mask the value while it is typed." })
|
|
308
|
-
}).annotate({
|
|
309
|
-
description: "One field of a provider credential.",
|
|
310
|
-
identifier: "CredentialField"
|
|
311
|
-
});
|
|
312
|
-
const ProviderBoardEntry = Struct({
|
|
313
|
-
create_latency_ms: Struct({
|
|
314
|
-
p50: NullOr(Natural),
|
|
315
|
-
p95: NullOr(Natural)
|
|
316
|
-
}).annotate({ description: "Create latency of the probe sandboxes over the last 24 hours, or null before the first probe." }),
|
|
317
|
-
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." }),
|
|
318
|
-
features: ProviderFeatures,
|
|
319
|
-
name: String$1,
|
|
320
|
-
prices: ArraySchema(Struct({
|
|
321
|
-
hourly_micro_usd: MicroUsd,
|
|
322
|
-
size: StandardSize
|
|
323
|
-
})).annotate({ description: "List price per hour of each standard size the provider can run. A provider that runs no standard size lists each size it does run instead, named `<vCPU>x<memory GiB>`, such as `2x0.5`, which a create asks for with `vcpu` and `memory_mib`." }),
|
|
324
|
-
provider: Provider,
|
|
325
|
-
rate_card_source_url: String$1.annotate({ description: "The provider's public pricing page the rate card copies." }),
|
|
326
|
-
rate_card_version: String$1,
|
|
327
|
-
status: Literals([
|
|
328
|
-
"degraded",
|
|
329
|
-
"down",
|
|
330
|
-
"operational",
|
|
331
|
-
"unknown"
|
|
332
|
-
]).annotate({ identifier: "ProviderStatus" }),
|
|
333
|
-
updated_at: Timestamp,
|
|
334
|
-
uptime: Struct({
|
|
335
|
-
last_15_minutes: NullOr(Ratio),
|
|
336
|
-
last_24_hours: NullOr(Ratio),
|
|
337
|
-
last_7_days: NullOr(Ratio)
|
|
338
|
-
}).annotate({ description: "Share of probe creates that succeeded in each window, or null before the first probe." })
|
|
339
|
-
}).annotate({
|
|
340
|
-
description: "One provider on the public provider board.",
|
|
341
|
-
identifier: "ProviderBoardEntry"
|
|
342
|
-
});
|
|
343
|
-
const ProviderBoard = Struct({ data: ArraySchema(ProviderBoardEntry) }).annotate({ identifier: "ProviderBoard" });
|
|
344
|
-
// ../sandcovery-contract/src/usage.ts
|
|
345
|
-
const EstimateRequest = Struct({
|
|
346
|
-
...SandboxSpec.fields,
|
|
347
|
-
provider: optionalKey(ProviderPreferences)
|
|
348
|
-
}).annotate({
|
|
349
|
-
description: "A sandbox spec and routing preferences to price without creating anything.",
|
|
350
|
-
identifier: "EstimateRequest"
|
|
351
|
-
});
|
|
352
|
-
const Estimate = Struct({
|
|
353
|
-
hourly_micro_usd: MicroUsd,
|
|
354
|
-
provider: Provider,
|
|
355
|
-
rate_card_version: String$1,
|
|
356
|
-
ttl_micro_usd: MicroUsd.annotate({ description: "List-price cost if the sandbox runs for its whole TTL." })
|
|
357
|
-
}).annotate({ identifier: "Estimate" });
|
|
358
|
-
const EstimateList = Struct({ data: ArraySchema(Estimate).annotate({ description: "One estimate per provider that can run the spec, in routing order." }) }).annotate({ identifier: "EstimateList" });
|
|
359
|
-
const isCalendarDay = makeFilter((value) => {
|
|
360
|
-
const at = Date.parse(`${value}T00:00:00.000Z`);
|
|
361
|
-
return Number.isFinite(at) && new Date(at).toISOString().slice(0, 10) === value;
|
|
362
|
-
}, {
|
|
363
|
-
expected: "a UTC calendar day such as 2026-11-08",
|
|
364
|
-
toJsonSchema: () => ({ format: "date" })
|
|
365
|
-
});
|
|
366
|
-
const CalendarDay = String$1.check(isCalendarDay);
|
|
367
|
-
Struct({
|
|
368
|
-
api_key_id: optionalKey(ApiKeyId),
|
|
369
|
-
from: CalendarDay.annotate({ description: "First UTC day, inclusive." }),
|
|
370
|
-
to: CalendarDay.annotate({ description: "Last UTC day, inclusive. At most 92 days after `from`." })
|
|
371
|
-
});
|
|
372
|
-
const UsageDay = Struct({
|
|
373
|
-
api_key_id: ApiKeyId.annotate({ description: "The key that created the sandboxes." }),
|
|
374
|
-
date: CalendarDay,
|
|
375
|
-
estimated_micro_usd: MicroUsd,
|
|
376
|
-
provider: Provider,
|
|
377
|
-
sandbox_count: Natural,
|
|
378
|
-
sandbox_seconds: Natural
|
|
379
|
-
}).annotate({
|
|
380
|
-
description: "Estimated list-price usage of one key on one provider on one UTC day.",
|
|
381
|
-
identifier: "UsageDay"
|
|
382
|
-
});
|
|
383
|
-
const Usage = Struct({ data: ArraySchema(UsageDay) }).annotate({ identifier: "Usage" });
|
|
384
|
-
// src/sse.ts
|
|
385
|
-
const fieldOf = (line) => {
|
|
386
|
-
const colon = line.indexOf(":");
|
|
387
|
-
if (colon === -1) return {
|
|
388
|
-
name: line,
|
|
389
|
-
value: ""
|
|
390
|
-
};
|
|
391
|
-
const value = line.slice(colon + 1);
|
|
392
|
-
return {
|
|
393
|
-
name: line.slice(0, colon),
|
|
394
|
-
value: value.startsWith(" ") ? value.slice(1) : value
|
|
395
|
-
};
|
|
396
|
-
};
|
|
397
|
-
const eventOf = (block) => {
|
|
398
|
-
const fields = block.split("\n").flatMap((line) => {
|
|
399
|
-
if (line.startsWith(":")) return [];
|
|
400
|
-
return [fieldOf(line)];
|
|
401
|
-
});
|
|
402
|
-
const data = fields.flatMap(({ name, value }) => name === "data" ? [value] : []);
|
|
403
|
-
const event = fields.findLast(({ name }) => name === "event")?.value ?? "message";
|
|
404
|
-
return data.length > 0 ? {
|
|
405
|
-
data: data.join("\n"),
|
|
406
|
-
event
|
|
407
|
-
} : void 0;
|
|
408
|
-
};
|
|
409
|
-
const normalized = (text) => text.replaceAll("\r\n", "\n").replaceAll("\r", "\n");
|
|
410
|
-
const serverSentEvents = async function* (body) {
|
|
411
|
-
const decoder = new TextDecoder();
|
|
412
|
-
let pending = "";
|
|
413
|
-
for await (const bytes of body) {
|
|
414
|
-
const text = `${pending}${decoder.decode(bytes, { stream: true })}`;
|
|
415
|
-
const cut = text.endsWith("\r") ? text.length - 1 : text.length;
|
|
416
|
-
const blocks = normalized(text.slice(0, cut)).split("\n\n");
|
|
417
|
-
pending = `${blocks.pop() ?? ""}${text.slice(cut)}`;
|
|
418
|
-
for (const block of blocks) {
|
|
419
|
-
const event = eventOf(block);
|
|
420
|
-
if (event !== void 0) yield event;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
};
|
|
424
|
-
// src/index.ts
|
|
425
|
-
const STREAM_FAILURE_EVENT = "effect/http-api/stream/failure";
|
|
426
|
-
const decodeApiError = decodeUnknownOption(fromJsonString(ApiError));
|
|
427
|
-
const failureOf = async (response) => {
|
|
428
|
-
const text = await response.text();
|
|
429
|
-
return getOrElse(decodeApiError(text), () => new Error(`Sandcovery answered ${response.status}`, { cause: {
|
|
430
|
-
body: text,
|
|
431
|
-
status: response.status
|
|
432
|
-
} }));
|
|
433
|
-
};
|
|
434
|
-
const segment = (schema, value) => encodeURIComponent(decodeUnknownSync(schema)(value));
|
|
435
|
-
const sandboxPath = (sandboxId) => `/sandboxes/${segment(SandboxId, sandboxId)}`;
|
|
436
|
-
const keyPath = (keyId) => `/keys/${segment(KeyId, keyId)}`;
|
|
437
|
-
const portSegment = (port) => String(decodeUnknownSync(Port)(port));
|
|
438
|
-
const credentialPath = (provider) => `/credentials/${segment(Provider, provider)}`;
|
|
439
|
-
const filePath = (sandboxId) => `${sandboxPath(sandboxId)}/files/content`;
|
|
440
|
-
const decodeExecEvent = decodeUnknownSync(fromJsonString(ExecEvent));
|
|
441
|
-
var Sandcovery = class {
|
|
442
|
-
activity;
|
|
443
|
-
credentials;
|
|
444
|
-
keys;
|
|
445
|
-
providers;
|
|
446
|
-
sandboxes;
|
|
447
|
-
usage;
|
|
448
|
-
constructor(options = {}) {
|
|
449
|
-
const apiKey = options.apiKey ?? globalThis.process?.env.SANDCOVERY_API_KEY;
|
|
450
|
-
const baseUrl = options.baseUrl ?? "https://www.sandcovery.com";
|
|
451
|
-
const send = options.fetch ?? globalThis.fetch;
|
|
452
|
-
const call = async (method, path, { body, headers = {}, json, query = {}, signal } = {}) => {
|
|
453
|
-
const url = new URL(`${API_PREFIX}${path}`, baseUrl);
|
|
454
|
-
for (const [key, value] of Object.entries(query)) if (value !== void 0) url.searchParams.set(key, String(value));
|
|
455
|
-
const sent = new Headers(headers);
|
|
456
|
-
if (apiKey !== void 0) sent.set("authorization", `Bearer ${apiKey}`);
|
|
457
|
-
if (json !== void 0) sent.set("content-type", "application/json");
|
|
458
|
-
const response = await send(url, {
|
|
459
|
-
body: json === void 0 ? body : JSON.stringify(json),
|
|
460
|
-
headers: sent,
|
|
461
|
-
method,
|
|
462
|
-
signal
|
|
463
|
-
});
|
|
464
|
-
if (!response.ok) throw await failureOf(response);
|
|
465
|
-
return response;
|
|
466
|
-
};
|
|
467
|
-
const read = async (schema, method, path, request) => {
|
|
468
|
-
const text = await (await call(method, path, request)).text();
|
|
469
|
-
return decodeUnknownSync(fromJsonString(schema))(text);
|
|
470
|
-
};
|
|
471
|
-
this.sandboxes = {
|
|
472
|
-
create: async (request = {}, { idempotencyKey, signal } = {}) => await read(Sandbox, "POST", "/sandboxes", {
|
|
473
|
-
headers: idempotencyKey === void 0 ? {} : { "idempotency-key": idempotencyKey },
|
|
474
|
-
json: request,
|
|
475
|
-
signal
|
|
476
|
-
}),
|
|
477
|
-
destroy: async (sandboxId, { signal } = {}) => await read(Sandbox, "DELETE", sandboxPath(sandboxId), { signal }),
|
|
478
|
-
downloadFile: async (sandboxId, path, { signal } = {}) => {
|
|
479
|
-
const response = await call("GET", filePath(sandboxId), {
|
|
480
|
-
query: { path },
|
|
481
|
-
signal
|
|
482
|
-
});
|
|
483
|
-
if (response.body === null) throw new Error("Sandcovery answered no file body", { cause: { status: response.status } });
|
|
484
|
-
return response.body;
|
|
485
|
-
},
|
|
486
|
-
exec: async (sandboxId, request, { signal } = {}) => await read(ExecResult, "POST", `${sandboxPath(sandboxId)}/exec`, {
|
|
487
|
-
json: request,
|
|
488
|
-
signal
|
|
489
|
-
}),
|
|
490
|
-
async *execStream(sandboxId, request, { signal } = {}) {
|
|
491
|
-
const response = await call("POST", `${sandboxPath(sandboxId)}/exec/stream`, {
|
|
492
|
-
headers: { accept: "text/event-stream" },
|
|
493
|
-
json: request,
|
|
494
|
-
signal
|
|
495
|
-
});
|
|
496
|
-
if (response.body === null) return;
|
|
497
|
-
for await (const { data, event } of serverSentEvents(response.body)) {
|
|
498
|
-
if (event === STREAM_FAILURE_EVENT) throw new Error("Sandcovery failed the stream", { cause: { body: data } });
|
|
499
|
-
yield decodeExecEvent(data);
|
|
500
|
-
}
|
|
501
|
-
},
|
|
502
|
-
get: async (sandboxId, { signal } = {}) => await read(Sandbox, "GET", sandboxPath(sandboxId), { signal }),
|
|
503
|
-
list: async (query = {}, { signal } = {}) => await read(SandboxList, "GET", "/sandboxes", {
|
|
504
|
-
query: { ...query },
|
|
505
|
-
signal
|
|
506
|
-
}),
|
|
507
|
-
listFiles: async (sandboxId, path, { signal } = {}) => await read(FileList, "GET", `${sandboxPath(sandboxId)}/files`, {
|
|
508
|
-
query: { path },
|
|
509
|
-
signal
|
|
510
|
-
}),
|
|
511
|
-
pause: async (sandboxId, { signal } = {}) => await read(Sandbox, "POST", `${sandboxPath(sandboxId)}/pause`, { signal }),
|
|
512
|
-
portPreview: async (sandboxId, port, { signal } = {}) => await read(PortPreview, "GET", `${sandboxPath(sandboxId)}/ports/${portSegment(port)}`, { signal }),
|
|
513
|
-
readFile: async (sandboxId, path, { signal } = {}) => {
|
|
514
|
-
const response = await call("GET", filePath(sandboxId), {
|
|
515
|
-
query: { path },
|
|
516
|
-
signal
|
|
517
|
-
});
|
|
518
|
-
return new Uint8Array(await response.arrayBuffer());
|
|
519
|
-
},
|
|
520
|
-
resume: async (sandboxId, { signal } = {}) => await read(Sandbox, "POST", `${sandboxPath(sandboxId)}/resume`, { signal }),
|
|
521
|
-
snapshot: async (sandboxId, { signal } = {}) => await read(Snapshot, "POST", `${sandboxPath(sandboxId)}/snapshot`, { signal }),
|
|
522
|
-
writeFile: async (sandboxId, path, content, { signal } = {}) => await read(FileEntry, "PUT", filePath(sandboxId), {
|
|
523
|
-
body: content instanceof Uint8Array ? new Uint8Array(content) : content,
|
|
524
|
-
headers: { "content-type": "application/octet-stream" },
|
|
525
|
-
query: { path },
|
|
526
|
-
signal
|
|
527
|
-
})
|
|
528
|
-
};
|
|
529
|
-
this.keys = {
|
|
530
|
-
create: async (request, { signal } = {}) => await read(CreatedKey, "POST", "/keys", {
|
|
531
|
-
json: request,
|
|
532
|
-
signal
|
|
533
|
-
}),
|
|
534
|
-
get: async (keyId, { signal } = {}) => await read(Key, "GET", keyPath(keyId), { signal }),
|
|
535
|
-
list: async ({ signal } = {}) => await read(KeyList, "GET", "/keys", { signal }),
|
|
536
|
-
revoke: async (keyId, { signal } = {}) => await read(Key, "DELETE", keyPath(keyId), { signal }),
|
|
537
|
-
update: async (keyId, request, { signal } = {}) => await read(Key, "PATCH", keyPath(keyId), {
|
|
538
|
-
json: request,
|
|
539
|
-
signal
|
|
540
|
-
})
|
|
541
|
-
};
|
|
542
|
-
this.credentials = {
|
|
543
|
-
delete: async (provider, { signal } = {}) => {
|
|
544
|
-
await call("DELETE", credentialPath(provider), { signal });
|
|
545
|
-
},
|
|
546
|
-
list: async ({ signal } = {}) => await read(ProviderCredentialList, "GET", "/credentials", { signal }),
|
|
547
|
-
set: async (provider, fields, { signal } = {}) => await read(ProviderCredential, "PUT", credentialPath(provider), {
|
|
548
|
-
json: fields,
|
|
549
|
-
signal
|
|
550
|
-
})
|
|
551
|
-
};
|
|
552
|
-
this.activity = { list: async (query = {}, { signal } = {}) => await read(ActivityList, "GET", "/activity", {
|
|
553
|
-
query: { ...query },
|
|
554
|
-
signal
|
|
555
|
-
}) };
|
|
556
|
-
this.providers = {
|
|
557
|
-
get: async (provider, { signal } = {}) => await read(ProviderBoardEntry, "GET", `/providers/${segment(Provider, provider)}`, { signal }),
|
|
558
|
-
list: async ({ signal } = {}) => await read(ProviderBoard, "GET", "/providers", { signal })
|
|
559
|
-
};
|
|
560
|
-
this.usage = {
|
|
561
|
-
estimate: async (request, { signal } = {}) => await read(EstimateList, "POST", "/estimates", {
|
|
562
|
-
json: request,
|
|
563
|
-
signal
|
|
564
|
-
}),
|
|
565
|
-
get: async (query, { signal } = {}) => await read(Usage, "GET", "/usage", {
|
|
566
|
-
query: { ...query },
|
|
567
|
-
signal
|
|
568
|
-
})
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
|
-
};
|
|
572
|
-
export { CredentialFields as a, ApiError as i, CalendarDay as n, EstimateRequest as r, Sandcovery as t };
|