sandcovery 0.1.0 → 0.3.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/LICENSE +21 -0
- package/README.md +96 -0
- package/dist/Schema-DiSfJzMf.mjs +11549 -0
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.mjs +1710 -0
- package/dist/handlers-rkx0CsMY.mjs +2459 -0
- package/dist/index.d.mts +84 -1
- package/dist/index.mjs +1 -5
- package/dist/origin-CIA-1Jia.mjs +413 -0
- package/dist/posthog-project-BpOd2VxW.mjs +1 -0
- package/dist/posthog-project-CdWw_ofg.mjs +22 -0
- package/dist/spec-DfgmzDj-.mjs +2057 -0
- package/dist/src-YrynO3hz.mjs +799 -0
- package/dist/telemetry-BYnuVdoZ.mjs +43 -0
- package/dist/telemetry-delivery-zinKRHRc.mjs +8712 -0
- package/dist/types-DMB8KnA3.d.mts +545 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +67 -0
- package/package.json +46 -4
|
@@ -0,0 +1,799 @@
|
|
|
1
|
+
import { A as optionalKey, C as isBetween, O as makeFilter, V as getOrElse, _ 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, j as tag, 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-DiSfJzMf.mjs";
|
|
2
|
+
import { A as KeyId, E as CreditCheckout, F as SandboxId, I as Timestamp, M as MicroUsd, N as Provider, O as ApiKeyId, P as Region, S as Billing, a as Key, f as Port, g as SandboxSpec, h as SandboxList, i as CreatedKey, k as GpuType, 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-CIA-1Jia.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/providers.ts
|
|
71
|
+
const Ratio = Finite.check(isBetween({
|
|
72
|
+
maximum: 1,
|
|
73
|
+
minimum: 0
|
|
74
|
+
})).annotate({ description: "A share from 0 to 1." });
|
|
75
|
+
const EgressMode = NonEmptyString.annotate({
|
|
76
|
+
description: "An egress policy mode the provider can enforce, such as `allow_all`, `allowlist`, or `deny_all`. The API adds modes over time.",
|
|
77
|
+
examples: [
|
|
78
|
+
"allow_all",
|
|
79
|
+
"allowlist",
|
|
80
|
+
"deny_all"
|
|
81
|
+
],
|
|
82
|
+
identifier: "EgressMode"
|
|
83
|
+
});
|
|
84
|
+
const ProviderFeatures = Struct({
|
|
85
|
+
custom_image: Boolean,
|
|
86
|
+
egress_modes: ArraySchema(EgressMode),
|
|
87
|
+
gpu_types: ArraySchema(GpuType).annotate({ description: "The GPU types a sandbox on this provider can get, up to 8 GPUs of one type. Empty when the provider runs no GPU sandbox." }),
|
|
88
|
+
idle_timeout: Boolean,
|
|
89
|
+
max_disk_mib: NullOr(Natural).annotate({ description: "The largest disk size in MiB the provider takes, or null when it takes no disk size." }),
|
|
90
|
+
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." }),
|
|
91
|
+
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." }),
|
|
92
|
+
max_vcpu: Natural,
|
|
93
|
+
pause: Boolean,
|
|
94
|
+
ports: Boolean,
|
|
95
|
+
regions: ArraySchema(Region),
|
|
96
|
+
snapshot: Boolean,
|
|
97
|
+
streamed_exec: Boolean
|
|
98
|
+
}).annotate({
|
|
99
|
+
description: "What the provider can enforce. A spec asking for more answers `unsupported` on that provider.",
|
|
100
|
+
identifier: "ProviderFeatures"
|
|
101
|
+
});
|
|
102
|
+
const CredentialField = Struct({
|
|
103
|
+
label: NonEmptyString.annotate({ description: "The field name to show a person, such as \"Team ID\"." }),
|
|
104
|
+
name: NonEmptyString.annotate({ description: "The key of the field in `PUT /api/v1/credentials/{provider}`, such as `team_id`." }),
|
|
105
|
+
secret: Boolean.annotate({ description: "Whether to mask the value while it is typed." })
|
|
106
|
+
}).annotate({
|
|
107
|
+
description: "One field of a provider credential.",
|
|
108
|
+
identifier: "CredentialField"
|
|
109
|
+
});
|
|
110
|
+
const ProviderStatus = Literals([
|
|
111
|
+
"degraded",
|
|
112
|
+
"down",
|
|
113
|
+
"operational",
|
|
114
|
+
"unknown"
|
|
115
|
+
]).annotate({ identifier: "ProviderStatus" });
|
|
116
|
+
const securityFact = (value) => Struct({
|
|
117
|
+
detail: NullOr(String$1).annotate({ description: "A sentence that qualifies the value, or null." }),
|
|
118
|
+
read_at: Timestamp.annotate({ description: "The UTC day Sandcovery read the provider's page." }),
|
|
119
|
+
source_changed_at: NullOr(Timestamp).annotate({ description: "When Sandcovery's daily check first found the visible text of `source_url` changed since its first check after `read_at`, or null while it reads the same, so a non-null value means the fact may be out of date." }),
|
|
120
|
+
source_url: String$1.annotate({ description: "The provider's public page that states the value." }),
|
|
121
|
+
value
|
|
122
|
+
});
|
|
123
|
+
const SecurityText = securityFact(String$1).annotate({
|
|
124
|
+
description: "A security fact a provider states, with the page and the day it was read.",
|
|
125
|
+
identifier: "SecurityText"
|
|
126
|
+
});
|
|
127
|
+
const SecurityList = securityFact(ArraySchema(String$1)).annotate({
|
|
128
|
+
description: "A list of names a provider states, with the page and the day it was read.",
|
|
129
|
+
identifier: "SecurityList"
|
|
130
|
+
});
|
|
131
|
+
const ProviderSecurity = Struct({
|
|
132
|
+
compliance: NullOr(SecurityList).annotate({ description: "The audits and certifications the provider states, or null when its pages state none." }),
|
|
133
|
+
data_location: NullOr(SecurityText).annotate({ description: "Where the provider says customer data sits, or null when its pages do not say." }),
|
|
134
|
+
isolation: NullOr(SecurityText).annotate({ description: "How the provider isolates one sandbox from another, or null when its pages do not say." })
|
|
135
|
+
}).annotate({
|
|
136
|
+
description: "What the provider's own pages state about its security.",
|
|
137
|
+
identifier: "ProviderSecurity"
|
|
138
|
+
});
|
|
139
|
+
const VendorIncident = Struct({
|
|
140
|
+
id: NonEmptyString.annotate({ description: "The incident's ID on the provider's status page." }),
|
|
141
|
+
impact: Literals([
|
|
142
|
+
"none",
|
|
143
|
+
"minor",
|
|
144
|
+
"major",
|
|
145
|
+
"critical",
|
|
146
|
+
"maintenance"
|
|
147
|
+
]).annotate({
|
|
148
|
+
description: "The impact the provider states, on the Atlassian Statuspage scale: `none`, `minor`, `major`, or `critical`, or `maintenance` for planned work.",
|
|
149
|
+
identifier: "IncidentImpact"
|
|
150
|
+
}),
|
|
151
|
+
resolved_at: NullOr(Timestamp).annotate({ description: "When the provider marked the incident resolved, or null while it is active." }),
|
|
152
|
+
started_at: Timestamp,
|
|
153
|
+
title: NonEmptyString,
|
|
154
|
+
url: NonEmptyString.annotate({ description: "The incident's page on the provider's status page." })
|
|
155
|
+
}).annotate({
|
|
156
|
+
description: "One incident from the provider's own status page.",
|
|
157
|
+
identifier: "VendorIncident"
|
|
158
|
+
});
|
|
159
|
+
const VendorIncidentRead = Struct({
|
|
160
|
+
data: ArraySchema(VendorIncident).annotate({ description: "Active incidents first, then those resolved in the last 7 days, each group newest first." }),
|
|
161
|
+
read_at: Timestamp.annotate({ description: "When Sandcovery last read the feed." }),
|
|
162
|
+
source_url: NonEmptyString.annotate({ description: "The provider's public status feed Sandcovery reads." })
|
|
163
|
+
}).annotate({
|
|
164
|
+
description: "The last read of a provider status feed.",
|
|
165
|
+
identifier: "VendorIncidentRead"
|
|
166
|
+
});
|
|
167
|
+
const VendorIncidents = NullOr(VendorIncidentRead).annotate({ description: "Incidents the provider's own status page reports, read every 5 minutes, or null when Sandcovery reads no status feed of the provider. A provider whose `status_url` is null publishes no status page." });
|
|
168
|
+
const ProviderBoardEntry = Struct({
|
|
169
|
+
create_latency_ms: Struct({
|
|
170
|
+
p50: NullOr(Natural),
|
|
171
|
+
p95: NullOr(Natural)
|
|
172
|
+
}).annotate({ description: "Create latency of the probe sandboxes over the last 24 hours, or null before the first probe or when `health_published` is false." }),
|
|
173
|
+
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." }),
|
|
174
|
+
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." }),
|
|
175
|
+
features: ProviderFeatures,
|
|
176
|
+
gpu_prices: ArraySchema(Struct({
|
|
177
|
+
hourly_micro_usd: MicroUsd,
|
|
178
|
+
type: GpuType
|
|
179
|
+
})).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." }),
|
|
180
|
+
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." }),
|
|
181
|
+
home_url: String$1.annotate({ description: "The provider's own home page." }),
|
|
182
|
+
incidents: VendorIncidents,
|
|
183
|
+
name: String$1,
|
|
184
|
+
prices: ArraySchema(Struct({
|
|
185
|
+
hourly_micro_usd: MicroUsd,
|
|
186
|
+
size: StandardSize
|
|
187
|
+
})).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`." }),
|
|
188
|
+
provider: Provider,
|
|
189
|
+
rate_card_source_url: String$1.annotate({ description: "The provider's public pricing page the rate card copies." }),
|
|
190
|
+
rate_card_version: String$1,
|
|
191
|
+
security: ProviderSecurity,
|
|
192
|
+
status: ProviderStatus,
|
|
193
|
+
status_url: NullOr(String$1).annotate({ description: "The provider's own status page, or null when it publishes none." }),
|
|
194
|
+
updated_at: Timestamp,
|
|
195
|
+
uptime: Struct({
|
|
196
|
+
last_15_minutes: NullOr(Ratio),
|
|
197
|
+
last_24_hours: NullOr(Ratio),
|
|
198
|
+
last_7_days: NullOr(Ratio)
|
|
199
|
+
}).annotate({ description: "Share of probe creates that succeeded in each window, or null before the first probe or when `health_published` is false. 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." })
|
|
200
|
+
}).annotate({
|
|
201
|
+
description: "One provider on the public provider board.",
|
|
202
|
+
identifier: "ProviderBoardEntry"
|
|
203
|
+
});
|
|
204
|
+
const ProviderBoard = Struct({ data: ArraySchema(ProviderBoardEntry) }).annotate({ identifier: "ProviderBoard" });
|
|
205
|
+
// ../sandcovery-contract/src/catalog.ts
|
|
206
|
+
const fact = (value) => Struct({
|
|
207
|
+
detail: NullOr(String$1).annotate({ description: "A sentence that qualifies the value, or null." }),
|
|
208
|
+
source_url: NullOr(String$1).annotate({ description: "The provider's public page that states the value, or null when the value comes from Sandcovery's own adapter for the provider, whose pages are `adapter_source_urls`." }),
|
|
209
|
+
value
|
|
210
|
+
});
|
|
211
|
+
const CatalogFlag = fact(Boolean).annotate({
|
|
212
|
+
description: "A yes or no fact about a provider and where it was read.",
|
|
213
|
+
identifier: "CatalogFlag"
|
|
214
|
+
});
|
|
215
|
+
const CatalogText = fact(String$1).annotate({
|
|
216
|
+
description: "A short fact about a provider and where it was read.",
|
|
217
|
+
identifier: "CatalogText"
|
|
218
|
+
});
|
|
219
|
+
const CatalogList = fact(ArraySchema(String$1)).annotate({
|
|
220
|
+
description: "A list of names about a provider and where it was read.",
|
|
221
|
+
identifier: "CatalogList"
|
|
222
|
+
});
|
|
223
|
+
const CatalogLimit = fact(NullOr(Natural)).annotate({
|
|
224
|
+
description: "A ceiling and where it was read. A null `value` means the provider states that it sets no such ceiling.",
|
|
225
|
+
identifier: "CatalogLimit"
|
|
226
|
+
});
|
|
227
|
+
const CatalogGpus = fact(ArraySchema(Struct({
|
|
228
|
+
hourly_micro_usd: NullOr(MicroUsd).annotate({ description: "List price per hour of one GPU, or null when the provider publishes none." }),
|
|
229
|
+
name: String$1.annotate({ description: "The GPU's name: a `GpuType` for a provider Sandcovery routes to, and the name on the provider's page otherwise." })
|
|
230
|
+
}))).annotate({
|
|
231
|
+
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.",
|
|
232
|
+
identifier: "CatalogGpus"
|
|
233
|
+
});
|
|
234
|
+
const ProviderCatalogEntry = Struct({
|
|
235
|
+
adapter_source_urls: ArraySchema(String$1).annotate({ description: "The provider's public pages that Sandcovery's adapter for it was written from, which every fact with a null `source_url` traces to. Empty for a provider with no adapter." }),
|
|
236
|
+
billing: NullOr(CatalogText).annotate({ description: "The unit the provider bills a sandbox in, such as per second or per session-hour." }),
|
|
237
|
+
capabilities: Struct({
|
|
238
|
+
custom_image: NullOr(CatalogFlag),
|
|
239
|
+
environment: NullOr(CatalogFlag),
|
|
240
|
+
files: NullOr(CatalogFlag),
|
|
241
|
+
idle_timeout: NullOr(CatalogFlag),
|
|
242
|
+
pause: NullOr(CatalogFlag),
|
|
243
|
+
ports: NullOr(CatalogFlag),
|
|
244
|
+
snapshot: NullOr(CatalogFlag),
|
|
245
|
+
streamed_exec: NullOr(CatalogFlag)
|
|
246
|
+
}).annotate({ description: "What a sandbox can do. For a provider Sandcovery routes to, each is what Sandcovery's adapter does there, and otherwise what the provider's pages state." }),
|
|
247
|
+
create_latency_ms: Struct({
|
|
248
|
+
p50: NullOr(Natural),
|
|
249
|
+
p95: NullOr(Natural)
|
|
250
|
+
}).annotate({ description: "Create latency of the probe sandboxes over the last 24 hours, or null unless `measurement` is `measured` and a probe has run." }),
|
|
251
|
+
credential_fields: ArraySchema(CredentialField).annotate({ description: "The fields a credential for this provider takes. Empty for a provider that is coming soon." }),
|
|
252
|
+
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 `measurement` is `not_measured`." }),
|
|
253
|
+
egress_modes: NullOr(CatalogList).annotate({ description: "The egress policy modes the provider can enforce, such as `allow_all`, `allowlist`, or `deny_all`." }),
|
|
254
|
+
gpus: NullOr(CatalogGpus),
|
|
255
|
+
incidents: VendorIncidents,
|
|
256
|
+
limits: Struct({
|
|
257
|
+
max_disk_mib: NullOr(CatalogLimit),
|
|
258
|
+
max_memory_mib: NullOr(CatalogLimit),
|
|
259
|
+
max_ttl_seconds: NullOr(CatalogLimit),
|
|
260
|
+
max_vcpu: NullOr(CatalogLimit)
|
|
261
|
+
}).annotate({ description: "The most one sandbox can get. For a provider Sandcovery routes to, each is the most Sandcovery starts there, and `max_disk_mib` is null when its adapter takes no disk size." }),
|
|
262
|
+
links: Struct({
|
|
263
|
+
docs_url: String$1,
|
|
264
|
+
home_url: String$1,
|
|
265
|
+
pricing_url: String$1,
|
|
266
|
+
security_url: NullOr(String$1),
|
|
267
|
+
status_url: NullOr(String$1),
|
|
268
|
+
terms_url: String$1
|
|
269
|
+
}).annotate({ description: "The provider's own public pages." }),
|
|
270
|
+
measured_at: NullOr(Timestamp).annotate({ description: "When the published uptime and create latency were last rolled up, or null when none is published." }),
|
|
271
|
+
measurement: Literals([
|
|
272
|
+
"measured",
|
|
273
|
+
"not_measured",
|
|
274
|
+
"not_published"
|
|
275
|
+
]).annotate({
|
|
276
|
+
description: "Whether the figures are measured: `measured` when Sandcovery probes the provider and publishes the result, `not_published` when it probes the provider and the provider's terms do not allow publishing the result, and `not_measured` when it runs no probe there.",
|
|
277
|
+
identifier: "CatalogMeasurement"
|
|
278
|
+
}),
|
|
279
|
+
name: String$1,
|
|
280
|
+
policy: Struct({
|
|
281
|
+
benchmark_terms: fact(Literals([
|
|
282
|
+
"barred",
|
|
283
|
+
"conditional",
|
|
284
|
+
"no_bar_found"
|
|
285
|
+
])).annotate({
|
|
286
|
+
description: "What the provider's terms say about publishing benchmarks of its service: `barred` when they forbid it, `conditional` when they allow it under a condition that `detail` states, and `no_bar_found` when a reading of the terms found no such clause.",
|
|
287
|
+
identifier: "CatalogBenchmarkTerms"
|
|
288
|
+
}),
|
|
289
|
+
compliance: ProviderSecurity.fields.compliance,
|
|
290
|
+
data_location: ProviderSecurity.fields.data_location,
|
|
291
|
+
free_allowance: NullOr(CatalogText).annotate({ description: "The free usage or credit the provider states." }),
|
|
292
|
+
isolation: ProviderSecurity.fields.isolation,
|
|
293
|
+
payment_required: NullOr(CatalogFlag).annotate({ description: "Whether an account needs a payment method before it starts a sandbox." }),
|
|
294
|
+
plan_required: NullOr(CatalogFlag).annotate({ description: "Whether an account needs a paid plan before it starts a sandbox." }),
|
|
295
|
+
read_at: Timestamp.annotate({ description: "The UTC day the provider's pages were read. Each security fact carries its own `read_at`, which is later for a fact read again since." }),
|
|
296
|
+
sla: NullOr(CatalogText).annotate({ description: "The uptime commitment the provider states." })
|
|
297
|
+
}).annotate({ description: "What the provider's terms and public pages state. A null fact means those pages do not state it." }),
|
|
298
|
+
prices: ArraySchema(Struct({
|
|
299
|
+
hourly_micro_usd: NullOr(MicroUsd),
|
|
300
|
+
offered: NullOr(Boolean).annotate({ description: "Whether the provider runs the size, or null when its pages do not say which sizes a sandbox takes." }),
|
|
301
|
+
size: StandardSize
|
|
302
|
+
})).annotate({ description: "List price per hour of each standard size, then of each other size the provider runs, such as `2x0.5`, from the provider's vCPU and memory rates or its listed plan price. `hourly_micro_usd` is null when the provider does not run the size or its pages give no rate that prices it." }),
|
|
303
|
+
provider: Provider,
|
|
304
|
+
rates: NullOr(Struct({
|
|
305
|
+
as_of: Timestamp.annotate({ description: "When the rates took effect on a provider Sandcovery routes to, and when the pricing page was read otherwise." }),
|
|
306
|
+
detail: NullOr(String$1),
|
|
307
|
+
memory_gib_hour_micro_usd: MicroUsd,
|
|
308
|
+
source_url: String$1,
|
|
309
|
+
vcpu_hour_micro_usd: MicroUsd
|
|
310
|
+
})).annotate({ description: "List price of one vCPU and of one GiB of memory for an hour, or null when the provider prices no such unit." }),
|
|
311
|
+
regions: NullOr(CatalogList).annotate({ description: "Where a sandbox can run: coarse `Region` names for a provider Sandcovery routes to, and the region names on the provider's page otherwise." }),
|
|
312
|
+
routed: Boolean.annotate({ description: "Whether Sandcovery routes sandboxes to the provider. `false` means the provider is coming soon: Sandcovery does not route to it yet." }),
|
|
313
|
+
sizes: NullOr(CatalogText).annotate({ description: "The sizes a sandbox comes in, each named `<vCPU>x<memory GiB>`, or a note that any size within the limits runs." }),
|
|
314
|
+
status: ProviderStatus,
|
|
315
|
+
uptime: Struct({
|
|
316
|
+
last_15_minutes: NullOr(Ratio),
|
|
317
|
+
last_24_hours: NullOr(Ratio),
|
|
318
|
+
last_7_days: NullOr(Ratio)
|
|
319
|
+
}).annotate({ description: "Share of probe creates that succeeded in each window, or null unless `measurement` is `measured` and a probe has run. 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." })
|
|
320
|
+
}).annotate({
|
|
321
|
+
description: "One sandbox provider in the catalog: what Sandcovery measured, and what the provider's public pages state. A null fact means those pages do not state it.",
|
|
322
|
+
identifier: "ProviderCatalogEntry"
|
|
323
|
+
});
|
|
324
|
+
const ProviderCatalog = Struct({ data: ArraySchema(ProviderCatalogEntry) }).annotate({ identifier: "ProviderCatalog" });
|
|
325
|
+
// ../sandcovery-contract/src/credentials.ts
|
|
326
|
+
const CredentialFields = Record(String$1, NonEmptyString).annotate({
|
|
327
|
+
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 `api_key` and `workspace_id` for `render`. A missing or unknown field answers 400 `invalid_request`.",
|
|
328
|
+
identifier: "CredentialFields"
|
|
329
|
+
});
|
|
330
|
+
const ProviderCredential = Struct({
|
|
331
|
+
created_at: Timestamp,
|
|
332
|
+
hint: String$1.annotate({ description: "The last four characters of the first secret field, for display." }),
|
|
333
|
+
provider: Provider,
|
|
334
|
+
updated_at: Timestamp
|
|
335
|
+
}).annotate({
|
|
336
|
+
description: "A stored provider credential. Sandcovery encrypts it at rest and never returns its fields.",
|
|
337
|
+
identifier: "ProviderCredential"
|
|
338
|
+
});
|
|
339
|
+
const ProviderCredentialList = Struct({ data: ArraySchema(ProviderCredential) }).annotate({ identifier: "ProviderCredentialList" });
|
|
340
|
+
// ../sandcovery-contract/src/errors/concurrency-limit-reached.ts
|
|
341
|
+
var ConcurrencyLimitReached = class extends Error$1("ConcurrencyLimitReached")({
|
|
342
|
+
concurrency_cap: Natural,
|
|
343
|
+
error: tag("concurrency_limit_reached"),
|
|
344
|
+
message: String$1
|
|
345
|
+
}, {
|
|
346
|
+
description: "The API key already has `concurrency_cap` live sandboxes, its `max_concurrent_sandboxes`. Destroy one or wait for one to end.",
|
|
347
|
+
httpApiStatus: 429,
|
|
348
|
+
identifier: "ConcurrencyLimitReached"
|
|
349
|
+
}) {
|
|
350
|
+
[ignore] = true;
|
|
351
|
+
};
|
|
352
|
+
// ../sandcovery-contract/src/errors/conflict.ts
|
|
353
|
+
var Conflict = class extends Error$1("Conflict")({
|
|
354
|
+
error: tag("conflict"),
|
|
355
|
+
message: String$1
|
|
356
|
+
}, {
|
|
357
|
+
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.",
|
|
358
|
+
httpApiStatus: 409,
|
|
359
|
+
identifier: "Conflict"
|
|
360
|
+
}) {
|
|
361
|
+
[ignore] = true;
|
|
362
|
+
};
|
|
363
|
+
// ../sandcovery-contract/src/errors/forbidden.ts
|
|
364
|
+
var Forbidden = class extends Error$1("Forbidden")({
|
|
365
|
+
error: tag("forbidden"),
|
|
366
|
+
message: String$1
|
|
367
|
+
}, {
|
|
368
|
+
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 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.",
|
|
369
|
+
httpApiStatus: 403,
|
|
370
|
+
identifier: "Forbidden"
|
|
371
|
+
}) {
|
|
372
|
+
[ignore] = true;
|
|
373
|
+
};
|
|
374
|
+
// ../sandcovery-contract/src/errors/invalid-request.ts
|
|
375
|
+
var InvalidRequest = class extends Error$1("InvalidRequest")({
|
|
376
|
+
error: tag("invalid_request"),
|
|
377
|
+
message: String$1
|
|
378
|
+
}, {
|
|
379
|
+
description: "The path, query, headers, or body do not decode against the operation, or contradict each other, and `message` names the failure.",
|
|
380
|
+
httpApiStatus: 400,
|
|
381
|
+
identifier: "InvalidRequest"
|
|
382
|
+
}) {
|
|
383
|
+
[ignore] = true;
|
|
384
|
+
};
|
|
385
|
+
// ../sandcovery-contract/src/errors/no-provider-available.ts
|
|
386
|
+
var NoProviderAvailable = class extends Error$1("NoProviderAvailable")({
|
|
387
|
+
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." }),
|
|
388
|
+
error: tag("no_provider_available"),
|
|
389
|
+
message: String$1
|
|
390
|
+
}, {
|
|
391
|
+
description: "Every candidate provider failed to create the sandbox, or none was left after filtering.",
|
|
392
|
+
httpApiStatus: 503,
|
|
393
|
+
identifier: "NoProviderAvailable"
|
|
394
|
+
}) {};
|
|
395
|
+
// ../sandcovery-contract/src/errors/not-found.ts
|
|
396
|
+
var NotFound = class extends Error$1("NotFound")({
|
|
397
|
+
error: tag("not_found"),
|
|
398
|
+
message: String$1
|
|
399
|
+
}, {
|
|
400
|
+
description: "The resource the path names does not exist or belongs to another organization or key.",
|
|
401
|
+
httpApiStatus: 404,
|
|
402
|
+
identifier: "NotFound"
|
|
403
|
+
}) {
|
|
404
|
+
[ignore] = true;
|
|
405
|
+
};
|
|
406
|
+
// ../sandcovery-contract/src/errors/provider-error.ts
|
|
407
|
+
var ProviderError = class extends Error$1("ProviderError")({
|
|
408
|
+
error: tag("provider_error"),
|
|
409
|
+
message: String$1,
|
|
410
|
+
provider: Provider
|
|
411
|
+
}, {
|
|
412
|
+
description: "The sandbox's provider failed the call. `message` carries the provider's reason.",
|
|
413
|
+
httpApiStatus: 502,
|
|
414
|
+
identifier: "ProviderError"
|
|
415
|
+
}) {};
|
|
416
|
+
// ../sandcovery-contract/src/errors/spend-limit-reached.ts
|
|
417
|
+
var SpendLimitReached = class extends Error$1("SpendLimitReached")({
|
|
418
|
+
error: tag("spend_limit_reached"),
|
|
419
|
+
limit_micro_usd: MicroUsd,
|
|
420
|
+
message: String$1,
|
|
421
|
+
resets_at: NullOr(Timestamp),
|
|
422
|
+
spent_micro_usd: MicroUsd
|
|
423
|
+
}, {
|
|
424
|
+
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.",
|
|
425
|
+
httpApiStatus: 402,
|
|
426
|
+
identifier: "SpendLimitReached"
|
|
427
|
+
}) {
|
|
428
|
+
[ignore] = true;
|
|
429
|
+
};
|
|
430
|
+
// ../sandcovery-contract/src/errors/unauthorized.ts
|
|
431
|
+
var Unauthorized = class extends Error$1("Unauthorized")({
|
|
432
|
+
error: tag("unauthorized"),
|
|
433
|
+
message: String$1
|
|
434
|
+
}, {
|
|
435
|
+
description: "The request carries no live key and no signed-in session, or a key that is unknown, revoked, or expired.",
|
|
436
|
+
httpApiStatus: 401,
|
|
437
|
+
identifier: "Unauthorized"
|
|
438
|
+
}) {
|
|
439
|
+
[ignore] = true;
|
|
440
|
+
};
|
|
441
|
+
// ../sandcovery-contract/src/errors/unsupported.ts
|
|
442
|
+
var Unsupported = class extends Error$1("Unsupported")({
|
|
443
|
+
error: tag("unsupported"),
|
|
444
|
+
message: String$1,
|
|
445
|
+
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." }),
|
|
446
|
+
provider: NullOr(Provider).annotate({ description: "The sandbox's provider for an operation on an existing sandbox, or null for a create." })
|
|
447
|
+
}, {
|
|
448
|
+
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.",
|
|
449
|
+
httpApiStatus: 422,
|
|
450
|
+
identifier: "Unsupported"
|
|
451
|
+
}) {
|
|
452
|
+
[ignore] = true;
|
|
453
|
+
};
|
|
454
|
+
// ../sandcovery-contract/src/errors/api-error.ts
|
|
455
|
+
const ApiError = Union([
|
|
456
|
+
ConcurrencyLimitReached,
|
|
457
|
+
Conflict,
|
|
458
|
+
Forbidden,
|
|
459
|
+
InvalidRequest,
|
|
460
|
+
NoProviderAvailable,
|
|
461
|
+
NotFound,
|
|
462
|
+
ProviderError,
|
|
463
|
+
SpendLimitReached,
|
|
464
|
+
Unauthorized,
|
|
465
|
+
Unsupported
|
|
466
|
+
]);
|
|
467
|
+
// ../sandcovery-contract/src/exec.ts
|
|
468
|
+
const MAX_EXEC_TIMEOUT_SECONDS = 3600;
|
|
469
|
+
const commandFields = {
|
|
470
|
+
command: NonEmptyString.annotate({ description: "A shell command line, run with `sh -c`." }),
|
|
471
|
+
cwd: optionalKey(NonEmptyString.annotate({ description: "Working directory. Defaults to the provider's default directory." })),
|
|
472
|
+
env: optionalKey(Record(NonEmptyString, String$1).annotate({ description: "Environment variables for this command only." }))
|
|
473
|
+
};
|
|
474
|
+
Struct(commandFields).annotate({
|
|
475
|
+
description: "A command to start and leave running. It runs until it exits or the sandbox ends, with no timeout, and its output is not kept.",
|
|
476
|
+
identifier: "DetachedExecRequest"
|
|
477
|
+
});
|
|
478
|
+
const DetachedExec = Struct({ started_at: Timestamp.annotate({ description: "When the provider reported the command started." }) }).annotate({
|
|
479
|
+
description: "A command the provider started and left running.",
|
|
480
|
+
identifier: "DetachedExec"
|
|
481
|
+
});
|
|
482
|
+
Struct({
|
|
483
|
+
...commandFields,
|
|
484
|
+
timeout_seconds: optionalKey(Int.check(isBetween({
|
|
485
|
+
maximum: MAX_EXEC_TIMEOUT_SECONDS,
|
|
486
|
+
minimum: 1
|
|
487
|
+
})).annotate({ description: "Seconds after which the command is killed. Defaults to 300." }))
|
|
488
|
+
}).annotate({ identifier: "ExecRequest" });
|
|
489
|
+
const ExecResult = Struct({
|
|
490
|
+
duration_ms: Natural,
|
|
491
|
+
exit_code: Int,
|
|
492
|
+
stderr: String$1,
|
|
493
|
+
stdout: String$1
|
|
494
|
+
}).annotate({
|
|
495
|
+
description: "The result of a command that ran to its end.",
|
|
496
|
+
identifier: "ExecResult"
|
|
497
|
+
});
|
|
498
|
+
const ExecEvent = Union([
|
|
499
|
+
Struct({
|
|
500
|
+
data: String$1,
|
|
501
|
+
type: Literal("stdout")
|
|
502
|
+
}),
|
|
503
|
+
Struct({
|
|
504
|
+
data: String$1,
|
|
505
|
+
type: Literal("stderr")
|
|
506
|
+
}),
|
|
507
|
+
Struct({
|
|
508
|
+
duration_ms: Natural,
|
|
509
|
+
exit_code: Int,
|
|
510
|
+
type: Literal("exit")
|
|
511
|
+
}),
|
|
512
|
+
Struct({
|
|
513
|
+
message: String$1,
|
|
514
|
+
provider: Provider,
|
|
515
|
+
type: Literal("error")
|
|
516
|
+
})
|
|
517
|
+
]).annotate({
|
|
518
|
+
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.",
|
|
519
|
+
identifier: "ExecEvent"
|
|
520
|
+
});
|
|
521
|
+
Struct({ path: NonEmptyString.annotate({ description: "An absolute path inside the sandbox." }) });
|
|
522
|
+
const FileEntry = Struct({
|
|
523
|
+
modified_at: NullOr(Timestamp),
|
|
524
|
+
name: String$1,
|
|
525
|
+
path: String$1,
|
|
526
|
+
size_bytes: NullOr(Natural),
|
|
527
|
+
type: Literals([
|
|
528
|
+
"directory",
|
|
529
|
+
"file",
|
|
530
|
+
"other",
|
|
531
|
+
"symlink"
|
|
532
|
+
]).annotate({
|
|
533
|
+
description: "`other` is an entry that is neither a file, a directory, nor a symlink, such as a socket or a device.",
|
|
534
|
+
identifier: "FileEntryType"
|
|
535
|
+
})
|
|
536
|
+
}).annotate({ identifier: "FileEntry" });
|
|
537
|
+
const FileList = Struct({
|
|
538
|
+
entries: ArraySchema(FileEntry),
|
|
539
|
+
path: String$1
|
|
540
|
+
}).annotate({ identifier: "FileList" });
|
|
541
|
+
// ../sandcovery-contract/src/offer.ts
|
|
542
|
+
const VcpuSeconds = Natural;
|
|
543
|
+
const Offer = Struct({
|
|
544
|
+
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." }),
|
|
545
|
+
keys_counted: Natural.annotate({ description: "Providers the account has earned free vCPU-seconds for, counted once each for good: each is a provider that 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." }),
|
|
546
|
+
keys_needed: Natural.annotate({ description: "Counted keys the account needs before its sandboxes may run on free vCPU-seconds." }),
|
|
547
|
+
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`." }),
|
|
548
|
+
provider: Provider.annotate({ description: "The provider whose sandboxes run on free vCPU-seconds, on its account that Sandcovery pays for." }),
|
|
549
|
+
remaining_vcpu_seconds: VcpuSeconds.annotate({ description: "`cap_vcpu_seconds` less `used_vcpu_seconds`, never below zero." }),
|
|
550
|
+
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." }),
|
|
551
|
+
vcpu_seconds_per_key: VcpuSeconds.annotate({ description: "The free vCPU-seconds each counted key earns." })
|
|
552
|
+
}).annotate({
|
|
553
|
+
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.",
|
|
554
|
+
identifier: "Offer"
|
|
555
|
+
});
|
|
556
|
+
// ../sandcovery-contract/src/usage.ts
|
|
557
|
+
const EstimateRequest = Struct({
|
|
558
|
+
...SandboxSpec.fields,
|
|
559
|
+
provider: optionalKey(ProviderPreferences)
|
|
560
|
+
}).annotate({
|
|
561
|
+
description: "A sandbox spec and routing preferences to price without creating anything.",
|
|
562
|
+
identifier: "EstimateRequest"
|
|
563
|
+
});
|
|
564
|
+
const Estimate = Struct({
|
|
565
|
+
hourly_micro_usd: MicroUsd,
|
|
566
|
+
provider: Provider,
|
|
567
|
+
rate_card_version: String$1,
|
|
568
|
+
ttl_micro_usd: MicroUsd.annotate({ description: "List-price cost if the sandbox runs for its whole TTL." })
|
|
569
|
+
}).annotate({ identifier: "Estimate" });
|
|
570
|
+
const EstimateList = Struct({ data: ArraySchema(Estimate).annotate({ description: "One estimate per provider that can run the spec, in routing order." }) }).annotate({ identifier: "EstimateList" });
|
|
571
|
+
const isCalendarDay = makeFilter((value) => {
|
|
572
|
+
const at = Date.parse(`${value}T00:00:00.000Z`);
|
|
573
|
+
return Number.isFinite(at) && new Date(at).toISOString().slice(0, 10) === value;
|
|
574
|
+
}, {
|
|
575
|
+
expected: "a UTC calendar day such as 2026-11-08",
|
|
576
|
+
toJsonSchema: () => ({ format: "date" })
|
|
577
|
+
});
|
|
578
|
+
const CalendarDay = String$1.check(isCalendarDay);
|
|
579
|
+
Struct({
|
|
580
|
+
api_key_id: optionalKey(ApiKeyId),
|
|
581
|
+
from: CalendarDay.annotate({ description: "First UTC day, inclusive." }),
|
|
582
|
+
to: CalendarDay.annotate({ description: "Last UTC day, inclusive. At most 92 days after `from`." })
|
|
583
|
+
});
|
|
584
|
+
const UsageDay = Struct({
|
|
585
|
+
api_key_id: ApiKeyId.annotate({ description: "The key that created the sandboxes." }),
|
|
586
|
+
date: CalendarDay,
|
|
587
|
+
estimated_micro_usd: MicroUsd,
|
|
588
|
+
provider: Provider,
|
|
589
|
+
sandbox_count: Natural,
|
|
590
|
+
sandbox_seconds: Natural
|
|
591
|
+
}).annotate({
|
|
592
|
+
description: "Estimated list-price usage of one key on one provider on one UTC day.",
|
|
593
|
+
identifier: "UsageDay"
|
|
594
|
+
});
|
|
595
|
+
const Usage = Struct({ data: ArraySchema(UsageDay) }).annotate({ identifier: "Usage" });
|
|
596
|
+
// src/sse.ts
|
|
597
|
+
const fieldOf = (line) => {
|
|
598
|
+
const colon = line.indexOf(":");
|
|
599
|
+
if (colon === -1) return {
|
|
600
|
+
name: line,
|
|
601
|
+
value: ""
|
|
602
|
+
};
|
|
603
|
+
const value = line.slice(colon + 1);
|
|
604
|
+
return {
|
|
605
|
+
name: line.slice(0, colon),
|
|
606
|
+
value: value.startsWith(" ") ? value.slice(1) : value
|
|
607
|
+
};
|
|
608
|
+
};
|
|
609
|
+
const eventOf = (block) => {
|
|
610
|
+
const fields = block.split("\n").flatMap((line) => {
|
|
611
|
+
if (line.startsWith(":")) return [];
|
|
612
|
+
return [fieldOf(line)];
|
|
613
|
+
});
|
|
614
|
+
const data = fields.flatMap(({ name, value }) => name === "data" ? [value] : []);
|
|
615
|
+
const event = fields.findLast(({ name }) => name === "event")?.value ?? "message";
|
|
616
|
+
return data.length > 0 ? {
|
|
617
|
+
data: data.join("\n"),
|
|
618
|
+
event
|
|
619
|
+
} : void 0;
|
|
620
|
+
};
|
|
621
|
+
const normalized = (text) => text.replaceAll("\r\n", "\n").replaceAll("\r", "\n");
|
|
622
|
+
const serverSentEvents = async function* (body) {
|
|
623
|
+
const decoder = new TextDecoder();
|
|
624
|
+
let pending = "";
|
|
625
|
+
for await (const bytes of body) {
|
|
626
|
+
const text = `${pending}${decoder.decode(bytes, { stream: true })}`;
|
|
627
|
+
const cut = text.endsWith("\r") ? text.length - 1 : text.length;
|
|
628
|
+
const blocks = normalized(text.slice(0, cut)).split("\n\n");
|
|
629
|
+
pending = `${blocks.pop() ?? ""}${text.slice(cut)}`;
|
|
630
|
+
for (const block of blocks) {
|
|
631
|
+
const event = eventOf(block);
|
|
632
|
+
if (event !== void 0) yield event;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
// src/index.ts
|
|
637
|
+
const STREAM_FAILURE_EVENT = "effect/http-api/stream/failure";
|
|
638
|
+
const decodeApiError = decodeUnknownOption(fromJsonString(ApiError));
|
|
639
|
+
const failureOf = async (response) => {
|
|
640
|
+
const text = await response.text();
|
|
641
|
+
return getOrElse(decodeApiError(text), () => new Error(`Sandcovery answered ${response.status}`, { cause: {
|
|
642
|
+
body: text,
|
|
643
|
+
status: response.status
|
|
644
|
+
} }));
|
|
645
|
+
};
|
|
646
|
+
const segment = (schema, value) => encodeURIComponent(decodeUnknownSync(schema)(value));
|
|
647
|
+
const sandboxPath = (sandboxId) => `/sandboxes/${segment(SandboxId, sandboxId)}`;
|
|
648
|
+
const keyPath = (keyId) => `/keys/${segment(KeyId, keyId)}`;
|
|
649
|
+
const portSegment = (port) => String(decodeUnknownSync(Port)(port));
|
|
650
|
+
const credentialPath = (provider) => `/credentials/${segment(Provider, provider)}`;
|
|
651
|
+
const filePath = (sandboxId) => `${sandboxPath(sandboxId)}/files/content`;
|
|
652
|
+
const decodeExecEvent = decodeUnknownSync(fromJsonString(ExecEvent));
|
|
653
|
+
var Sandcovery = class {
|
|
654
|
+
activity;
|
|
655
|
+
billing;
|
|
656
|
+
credentials;
|
|
657
|
+
keys;
|
|
658
|
+
providers;
|
|
659
|
+
sandboxes;
|
|
660
|
+
usage;
|
|
661
|
+
constructor(options = {}) {
|
|
662
|
+
const configuredKey = options.apiKey ?? globalThis.process?.env.SANDCOVERY_API_KEY;
|
|
663
|
+
const apiKey = configuredKey === "" ? void 0 : configuredKey;
|
|
664
|
+
const baseUrl = options.baseUrl ?? "https://www.sandcovery.com";
|
|
665
|
+
const send = options.fetch ?? globalThis.fetch;
|
|
666
|
+
const call = async (method, path, { body, headers = {}, json, query = {}, signal } = {}) => {
|
|
667
|
+
const url = new URL(`${API_PREFIX}${path}`, baseUrl);
|
|
668
|
+
for (const [key, value] of Object.entries(query)) if (value !== void 0) url.searchParams.set(key, String(value));
|
|
669
|
+
const sent = new Headers(headers);
|
|
670
|
+
if (apiKey !== void 0) sent.set("authorization", `Bearer ${apiKey}`);
|
|
671
|
+
if (json !== void 0) sent.set("content-type", "application/json");
|
|
672
|
+
const response = await send(url, {
|
|
673
|
+
body: json === void 0 ? body : JSON.stringify(json),
|
|
674
|
+
headers: sent,
|
|
675
|
+
method,
|
|
676
|
+
signal
|
|
677
|
+
});
|
|
678
|
+
if (!response.ok) throw await failureOf(response);
|
|
679
|
+
return response;
|
|
680
|
+
};
|
|
681
|
+
const read = async (schema, method, path, request) => {
|
|
682
|
+
const text = await (await call(method, path, request)).text();
|
|
683
|
+
return decodeUnknownSync(fromJsonString(schema))(text);
|
|
684
|
+
};
|
|
685
|
+
this.sandboxes = {
|
|
686
|
+
create: async (request = {}, { idempotencyKey, signal } = {}) => await read(Sandbox, "POST", "/sandboxes", {
|
|
687
|
+
headers: idempotencyKey === void 0 ? {} : { "idempotency-key": idempotencyKey },
|
|
688
|
+
json: request,
|
|
689
|
+
signal
|
|
690
|
+
}),
|
|
691
|
+
destroy: async (sandboxId, { signal } = {}) => await read(Sandbox, "DELETE", sandboxPath(sandboxId), { signal }),
|
|
692
|
+
downloadFile: async (sandboxId, path, { signal } = {}) => {
|
|
693
|
+
const response = await call("GET", filePath(sandboxId), {
|
|
694
|
+
query: { path },
|
|
695
|
+
signal
|
|
696
|
+
});
|
|
697
|
+
if (response.body === null) throw new Error("Sandcovery answered no file body", { cause: { status: response.status } });
|
|
698
|
+
return response.body;
|
|
699
|
+
},
|
|
700
|
+
exec: async (sandboxId, request, { signal } = {}) => await read(ExecResult, "POST", `${sandboxPath(sandboxId)}/exec`, {
|
|
701
|
+
json: request,
|
|
702
|
+
signal
|
|
703
|
+
}),
|
|
704
|
+
execDetached: async (sandboxId, request, { signal } = {}) => await read(DetachedExec, "POST", `${sandboxPath(sandboxId)}/exec/detached`, {
|
|
705
|
+
json: request,
|
|
706
|
+
signal
|
|
707
|
+
}),
|
|
708
|
+
async *execStream(sandboxId, request, { signal } = {}) {
|
|
709
|
+
const response = await call("POST", `${sandboxPath(sandboxId)}/exec/stream`, {
|
|
710
|
+
headers: { accept: "text/event-stream" },
|
|
711
|
+
json: request,
|
|
712
|
+
signal
|
|
713
|
+
});
|
|
714
|
+
if (response.body === null) return;
|
|
715
|
+
for await (const { data, event } of serverSentEvents(response.body)) {
|
|
716
|
+
if (event === STREAM_FAILURE_EVENT) throw new Error("Sandcovery failed the stream", { cause: { body: data } });
|
|
717
|
+
yield decodeExecEvent(data);
|
|
718
|
+
}
|
|
719
|
+
},
|
|
720
|
+
get: async (sandboxId, { signal } = {}) => await read(Sandbox, "GET", sandboxPath(sandboxId), { signal }),
|
|
721
|
+
list: async (query = {}, { signal } = {}) => await read(SandboxList, "GET", "/sandboxes", {
|
|
722
|
+
query: { ...query },
|
|
723
|
+
signal
|
|
724
|
+
}),
|
|
725
|
+
listFiles: async (sandboxId, path, { signal } = {}) => await read(FileList, "GET", `${sandboxPath(sandboxId)}/files`, {
|
|
726
|
+
query: { path },
|
|
727
|
+
signal
|
|
728
|
+
}),
|
|
729
|
+
pause: async (sandboxId, { signal } = {}) => await read(Sandbox, "POST", `${sandboxPath(sandboxId)}/pause`, { signal }),
|
|
730
|
+
portPreview: async (sandboxId, port, { signal } = {}) => await read(PortPreview, "GET", `${sandboxPath(sandboxId)}/ports/${portSegment(port)}`, { signal }),
|
|
731
|
+
readFile: async (sandboxId, path, { signal } = {}) => {
|
|
732
|
+
const response = await call("GET", filePath(sandboxId), {
|
|
733
|
+
query: { path },
|
|
734
|
+
signal
|
|
735
|
+
});
|
|
736
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
737
|
+
},
|
|
738
|
+
resume: async (sandboxId, { signal } = {}) => await read(Sandbox, "POST", `${sandboxPath(sandboxId)}/resume`, { signal }),
|
|
739
|
+
snapshot: async (sandboxId, { signal } = {}) => await read(Snapshot, "POST", `${sandboxPath(sandboxId)}/snapshot`, { signal }),
|
|
740
|
+
writeFile: async (sandboxId, path, content, { signal } = {}) => await read(FileEntry, "PUT", filePath(sandboxId), {
|
|
741
|
+
body: content instanceof Uint8Array ? new Uint8Array(content) : content,
|
|
742
|
+
headers: { "content-type": "application/octet-stream" },
|
|
743
|
+
query: { path },
|
|
744
|
+
signal
|
|
745
|
+
})
|
|
746
|
+
};
|
|
747
|
+
this.keys = {
|
|
748
|
+
create: async (request, { signal } = {}) => await read(CreatedKey, "POST", "/keys", {
|
|
749
|
+
json: request,
|
|
750
|
+
signal
|
|
751
|
+
}),
|
|
752
|
+
get: async (keyId, { signal } = {}) => await read(Key, "GET", keyPath(keyId), { signal }),
|
|
753
|
+
list: async ({ signal } = {}) => await read(KeyList, "GET", "/keys", { signal }),
|
|
754
|
+
revoke: async (keyId, { signal } = {}) => await read(Key, "DELETE", keyPath(keyId), { signal }),
|
|
755
|
+
update: async (keyId, request, { signal } = {}) => await read(Key, "PATCH", keyPath(keyId), {
|
|
756
|
+
json: request,
|
|
757
|
+
signal
|
|
758
|
+
})
|
|
759
|
+
};
|
|
760
|
+
this.credentials = {
|
|
761
|
+
delete: async (provider, { signal } = {}) => {
|
|
762
|
+
await call("DELETE", credentialPath(provider), { signal });
|
|
763
|
+
},
|
|
764
|
+
list: async ({ signal } = {}) => await read(ProviderCredentialList, "GET", "/credentials", { signal }),
|
|
765
|
+
offer: async ({ signal } = {}) => await read(Offer, "GET", "/offer", { signal }),
|
|
766
|
+
set: async (provider, fields, { signal } = {}) => await read(ProviderCredential, "PUT", credentialPath(provider), {
|
|
767
|
+
json: fields,
|
|
768
|
+
signal
|
|
769
|
+
})
|
|
770
|
+
};
|
|
771
|
+
this.activity = { list: async (query = {}, { signal } = {}) => await read(ActivityList, "GET", "/activity", {
|
|
772
|
+
query: { ...query },
|
|
773
|
+
signal
|
|
774
|
+
}) };
|
|
775
|
+
this.billing = {
|
|
776
|
+
buyCredits: async (request, { signal } = {}) => await read(CreditCheckout, "POST", "/billing/credits", {
|
|
777
|
+
json: request,
|
|
778
|
+
signal
|
|
779
|
+
}),
|
|
780
|
+
get: async ({ signal } = {}) => await read(Billing, "GET", "/billing", { signal })
|
|
781
|
+
};
|
|
782
|
+
this.providers = {
|
|
783
|
+
catalog: async ({ signal } = {}) => await read(ProviderCatalog, "GET", "/catalog", { signal }),
|
|
784
|
+
get: async (provider, { signal } = {}) => await read(ProviderBoardEntry, "GET", `/providers/${segment(Provider, provider)}`, { signal }),
|
|
785
|
+
list: async ({ signal } = {}) => await read(ProviderBoard, "GET", "/providers", { signal })
|
|
786
|
+
};
|
|
787
|
+
this.usage = {
|
|
788
|
+
estimate: async (request, { signal } = {}) => await read(EstimateList, "POST", "/estimates", {
|
|
789
|
+
json: request,
|
|
790
|
+
signal
|
|
791
|
+
}),
|
|
792
|
+
get: async (query, { signal } = {}) => await read(Usage, "GET", "/usage", {
|
|
793
|
+
query: { ...query },
|
|
794
|
+
signal
|
|
795
|
+
})
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
};
|
|
799
|
+
export { CredentialFields as a, ApiError as i, CalendarDay as n, EstimateRequest as r, Sandcovery as t };
|