@fabrika/provider-zerops 0.9.0-dev.1 → 0.9.0-dev.10
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/package.json +17 -14
- package/sandbox/Dockerfile +16 -0
- package/sandbox/bin/postgres-auth.sh +38 -0
- package/sandbox/bin/reset.sh +12 -0
- package/sandbox/bin/run-build.sh +35 -0
- package/sandbox/bin/run-launcher.sh +18 -0
- package/sandbox/bin/start-launcher.sh +25 -0
- package/sandbox/bin/stop.sh +47 -0
- package/sandbox/init.sh +61 -0
- package/src/api/client.ts +15 -1
- package/src/api/errors.ts +7 -3
- package/src/api/readers.ts +29 -0
- package/src/api/types.ts +52 -0
- package/src/api.ts +2 -0
- package/src/cli.ts +11 -0
- package/src/collaborators.ts +0 -14
- package/src/compile.ts +1 -1
- package/src/control.ts +159 -92
- package/src/execution.ts +45 -195
- package/src/index.ts +2 -0
- package/src/installation/admin.ts +1 -1
- package/src/installation/deploy-options.ts +1 -2
- package/src/installation/deploy.ts +225 -80
- package/src/installation/generated/platform-console-schema.ts +3 -0
- package/src/installation/generated/platform-proxy-manifest.ts +1 -1
- package/src/installation/guide.md +48 -18
- package/src/installation/hosts.ts +1 -7
- package/src/installation/index.ts +13 -16
- package/src/installation/init-options.ts +2 -1
- package/src/installation/install-environment.ts +47 -108
- package/src/installation/install-options.ts +3 -1
- package/src/installation/install-secrets.ts +24 -68
- package/src/installation/install.ts +9 -4
- package/src/installation/sidecar.ts +5 -26
- package/src/installation/topology/setups.ts +17 -4
- package/src/installation/topology/topology.ts +32 -22
- package/src/installation/upgrade-options.ts +2 -2
- package/src/managed-env.ts +1 -174
- package/src/manifest.ts +4 -16
- package/src/namespace/claims.ts +60 -1
- package/src/namespace/codec.ts +17 -0
- package/src/namespace/errors.ts +22 -1
- package/src/namespace/manifest.ts +36 -23
- package/src/namespace/provisioning.ts +88 -114
- package/src/namespace/proxy-attempt.ts +14 -2
- package/src/namespace/proxy-reads.ts +28 -23
- package/src/namespace/proxy-secrets.ts +18 -5
- package/src/namespace/sandbox-host.ts +212 -0
- package/src/namespace/subdomain.ts +113 -0
- package/src/namespace/topology.ts +1 -1
- package/src/namespace/types.ts +13 -0
- package/src/namespace/update.ts +1 -0
- package/src/namespace-cli.ts +152 -0
- package/src/plan.ts +1 -6
- package/src/provider.ts +88 -166
- package/src/proxy-manifest-carrier.ts +39 -0
- package/src/sandbox/base-image.ts +100 -0
- package/src/sandbox/constants.ts +44 -0
- package/src/sandbox/deploy.ts +471 -0
- package/src/sandbox/dev-artifact.ts +206 -0
- package/src/sandbox/lifecycle.ts +204 -0
- package/src/sandbox/scripts.ts +26 -0
- package/src/sandbox-host.ts +28 -0
- package/src/source/port.ts +5 -0
- package/src/types.ts +0 -2
- package/src/zbox/client.ts +259 -0
- package/src/zbox/errors.ts +45 -0
- package/src/zbox/index.ts +22 -0
- package/src/zbox/types.ts +165 -0
- package/types/src/api/client.d.ts +5 -0
- package/types/src/api/errors.d.ts +26 -0
- package/types/src/api/polling.d.ts +41 -0
- package/types/src/api/readers.d.ts +1115 -0
- package/types/src/api/service-env-limit.d.ts +17 -0
- package/types/src/api/service-env-response.d.ts +23 -0
- package/types/src/api/types.d.ts +687 -0
- package/types/src/api.d.ts +6 -0
- package/types/src/authoring.d.ts +9 -0
- package/types/src/cli-args.d.ts +19 -0
- package/types/src/cli.d.ts +13 -0
- package/types/src/collaborators.d.ts +16 -0
- package/types/src/compile.d.ts +91 -0
- package/types/src/control.d.ts +51 -0
- package/types/src/database-budget.d.ts +38 -0
- package/types/src/descriptor.d.ts +28 -0
- package/types/src/execution.d.ts +114 -0
- package/types/src/exposure.d.ts +47 -0
- package/types/src/index.d.ts +31 -0
- package/types/src/installation/admin-options.d.ts +24 -0
- package/types/src/installation/admin.d.ts +35 -0
- package/types/src/installation/checker-release.d.ts +12 -0
- package/types/src/installation/deploy-options.d.ts +37 -0
- package/types/src/installation/deploy.d.ts +136 -0
- package/types/src/installation/generated/platform-console-schema.d.ts +2 -0
- package/types/src/installation/generated/platform-proxy-manifest.d.ts +2 -0
- package/types/src/installation/hosts.d.ts +34 -0
- package/types/src/installation/index.d.ts +7 -0
- package/types/src/installation/init-options.d.ts +38 -0
- package/types/src/installation/init.d.ts +60 -0
- package/types/src/installation/install-collaborators.d.ts +24 -0
- package/types/src/installation/install-environment.d.ts +63 -0
- package/types/src/installation/install-options.d.ts +49 -0
- package/types/src/installation/install-project.d.ts +13 -0
- package/types/src/installation/install-provisioning.d.ts +58 -0
- package/types/src/installation/install-secrets.d.ts +17 -0
- package/types/src/installation/install-token.d.ts +10 -0
- package/types/src/installation/install.d.ts +23 -0
- package/types/src/installation/installation-source.d.ts +8 -0
- package/types/src/installation/log.d.ts +44 -0
- package/types/src/installation/machine-key.d.ts +19 -0
- package/types/src/installation/placement-options.d.ts +11 -0
- package/types/src/installation/platform-archive.d.ts +7 -0
- package/types/src/installation/platform-source.d.ts +8 -0
- package/types/src/installation/platform-upload.d.ts +3 -0
- package/types/src/installation/sidecar.d.ts +49 -0
- package/types/src/installation/source-options.d.ts +1 -0
- package/types/src/installation/topology/artifacts.d.ts +8 -0
- package/types/src/installation/topology/index.d.ts +5 -0
- package/types/src/installation/topology/installation-schemas.d.ts +2242 -0
- package/types/src/installation/topology/invariants.d.ts +23 -0
- package/types/src/installation/topology/setups.d.ts +59 -0
- package/types/src/installation/topology/topology.d.ts +153 -0
- package/types/src/installation/topology/validate.d.ts +11 -0
- package/types/src/installation/upgrade-options.d.ts +26 -0
- package/types/src/installation/upgrade-output.d.ts +6 -0
- package/types/src/installation/upgrade.d.ts +88 -0
- package/types/src/managed-env.d.ts +24 -0
- package/types/src/manifest.d.ts +199 -0
- package/types/src/namespace/claims.d.ts +16 -0
- package/types/src/namespace/codec.d.ts +352 -0
- package/types/src/namespace/constants.d.ts +25 -0
- package/types/src/namespace/errors.d.ts +25 -0
- package/types/src/namespace/manifest.d.ts +4 -0
- package/types/src/namespace/operator.d.ts +12 -0
- package/types/src/namespace/provisioning.d.ts +4 -0
- package/types/src/namespace/proxy-attempt.d.ts +39 -0
- package/types/src/namespace/proxy-reads.d.ts +27 -0
- package/types/src/namespace/proxy-secrets.d.ts +8 -0
- package/types/src/namespace/proxy-source.d.ts +74 -0
- package/types/src/namespace/sandbox-host.d.ts +23 -0
- package/types/src/namespace/subdomain.d.ts +43 -0
- package/types/src/namespace/topology.d.ts +9 -0
- package/types/src/namespace/types.d.ts +111 -0
- package/types/src/namespace/update.d.ts +6 -0
- package/types/src/namespace/validation.d.ts +12 -0
- package/types/src/namespace-cli.d.ts +2 -0
- package/types/src/namespace.d.ts +9 -0
- package/types/src/plan.d.ts +11 -0
- package/types/src/provider.d.ts +60 -0
- package/types/src/proxy-manifest-carrier.d.ts +37 -0
- package/types/src/sandbox/base-image.d.ts +28 -0
- package/types/src/sandbox/constants.d.ts +30 -0
- package/types/src/sandbox/deploy.d.ts +75 -0
- package/types/src/sandbox/dev-artifact.d.ts +51 -0
- package/types/src/sandbox/lifecycle.d.ts +27 -0
- package/types/src/sandbox/scripts.d.ts +11 -0
- package/types/src/sandbox-host.d.ts +16 -0
- package/types/src/schema.generated.d.ts +376 -0
- package/types/src/service-names.d.ts +4 -0
- package/types/src/service-references.d.ts +13 -0
- package/types/src/source/constants.d.ts +6 -0
- package/types/src/source/port.d.ts +65 -0
- package/types/src/source/types.d.ts +4 -0
- package/types/src/source/validation.d.ts +19 -0
- package/types/src/source.d.ts +2 -0
- package/types/src/types.d.ts +119 -0
- package/types/src/version-attempt.d.ts +8 -0
- package/types/src/zbox/client.d.ts +2 -0
- package/types/src/zbox/errors.d.ts +25 -0
- package/types/src/zbox/index.d.ts +3 -0
- package/types/src/zbox/types.d.ts +433 -0
- package/src/installation/mcp.ts +0 -102
- package/src/installation/proxy-manifest.ts +0 -214
- package/src/installation/secrets.ts +0 -78
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
// The per-workspace sandboxes of a `dev` environment outside a run (`ProviderDevSandboxes`): one Box sandbox per MCP
|
|
2
|
+
// workspace on the namespace's sandbox host, found again by its name, so every call converges instead of duplicating.
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
PROVIDER_DEV_CAPACITY,
|
|
6
|
+
PROVIDER_DEV_HOST_PENDING,
|
|
7
|
+
type ProviderDevSandbox,
|
|
8
|
+
type ProviderDevSandboxes,
|
|
9
|
+
type ProviderEnvironment,
|
|
10
|
+
ProviderNamespaceError,
|
|
11
|
+
} from '@fabrika/provider-contract'
|
|
12
|
+
import type { Sleeper } from '../collaborators'
|
|
13
|
+
import { ZEROPS_APPLICATION_PORT } from '../execution'
|
|
14
|
+
import { sandboxUpstreamHost } from '../sandbox-host'
|
|
15
|
+
import { isZboxNotFound, isZboxWorkspaceFull, type ZboxClient, ZboxOperationFailed, type ZboxSandbox } from '../zbox'
|
|
16
|
+
import { ensureSandboxBase, readSandboxBaseContext, type SandboxBaseContext } from './base-image'
|
|
17
|
+
import { SANDBOX_CPUS, SANDBOX_DISK_BYTES, SANDBOX_INIT_COMMAND, SANDBOX_MEMORY_BYTES } from './constants'
|
|
18
|
+
|
|
19
|
+
/** A workspace id is a UUIDv7, so the sandbox name it makes is a fixed shape. */
|
|
20
|
+
const WORKSPACE_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
|
|
21
|
+
|
|
22
|
+
/** How long a sandbox in a transition (creating, parking, waking) is waited for. Measured: each takes under 2 s. */
|
|
23
|
+
const TRANSITION_DEADLINE_MS = 120_000
|
|
24
|
+
const TRANSITION_POLL_MS = 1_000
|
|
25
|
+
|
|
26
|
+
const TRANSITIONS: ReadonlySet<ZboxSandbox['status']> = new Set(['CREATING', 'PARKING', 'WAKING', 'FORKING', 'RESTORING'])
|
|
27
|
+
|
|
28
|
+
/** A sandbox that will not run again. Box archives one past its absolute TTL. */
|
|
29
|
+
const ENDED: ReadonlySet<ZboxSandbox['status']> = new Set(['FAILED', 'TERMINATED', 'ARCHIVED'])
|
|
30
|
+
|
|
31
|
+
/** The sandbox name of a workspace: what `ensure` finds it again by. */
|
|
32
|
+
export function sandboxName(workspaceId: string): string {
|
|
33
|
+
if (!WORKSPACE_ID.test(workspaceId)) throw new Error('zerops: a workspace id is a lower-case UUID')
|
|
34
|
+
return `fabrika-${workspaceId}`
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** A deterministic `Idempotency-Key` in UUID form: the same delete after a lost answer gets Box's first answer. */
|
|
38
|
+
export function sandboxIdempotencyKey(...parts: readonly string[]): string {
|
|
39
|
+
const hex = new Bun.CryptoHasher('sha256').update(['fabrika-dev-sandbox', ...parts].join('\u0000')).digest('hex')
|
|
40
|
+
const variant = ((Number.parseInt(hex.slice(16, 17), 16) & 0x3) | 0x8).toString(16)
|
|
41
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-8${hex.slice(13, 16)}-${variant}${hex.slice(17, 20)}-${hex.slice(20, 32)}`
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** A full sandbox host is the operator's to relieve, so it surfaces as the contract's capacity code. */
|
|
45
|
+
export async function withSandboxCapacity<T>(run: () => Promise<T>): Promise<T> {
|
|
46
|
+
try {
|
|
47
|
+
return await run()
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (isZboxWorkspaceFull(error) || (error instanceof ZboxOperationFailed && error.code === 'workspaceFull')) {
|
|
50
|
+
throw new ProviderNamespaceError(
|
|
51
|
+
"zerops: the namespace's sandbox host has no room for another running sandbox; park or remove another workspace's sandbox and retry",
|
|
52
|
+
PROVIDER_DEV_CAPACITY,
|
|
53
|
+
true,
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
throw error
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface ZeropsDevSandboxesOptions {
|
|
61
|
+
/** The Box client of the environment's namespace sandbox host, authenticated with `sandboxKey`. */
|
|
62
|
+
/** Null while the namespace has no sandbox host yet. */
|
|
63
|
+
readonly client: (environment: ProviderEnvironment, sandboxKey: string) => ZboxClient | null
|
|
64
|
+
/** Refuses an environment whose placement cannot serve a workspace sandbox; see `ProviderDevSandboxes.admit`. */
|
|
65
|
+
readonly admit: (environment: ProviderEnvironment) => void
|
|
66
|
+
readonly sleep: Sleeper
|
|
67
|
+
/** Where `ensure` says it replaced a dead sandbox: the seam has no run log outside a run. */
|
|
68
|
+
readonly log: (line: string) => void
|
|
69
|
+
/** The base image's build context; the one this package ships unless a test passes another. */
|
|
70
|
+
readonly baseContext?: () => Promise<SandboxBaseContext>
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const assertDevEnvironment = (environment: ProviderEnvironment): void => {
|
|
74
|
+
if (environment.kind !== 'dev') throw new Error('zerops: only a dev environment has workspace sandboxes')
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Wait out a transition; answers the sandbox in a settled state. */
|
|
78
|
+
export async function settledSandbox(client: ZboxClient, sandbox: ZboxSandbox, sleep: Sleeper, signal: AbortSignal): Promise<ZboxSandbox> {
|
|
79
|
+
const deadline = Date.now() + TRANSITION_DEADLINE_MS
|
|
80
|
+
let current = sandbox
|
|
81
|
+
while (TRANSITIONS.has(current.status)) {
|
|
82
|
+
signal.throwIfAborted()
|
|
83
|
+
if (Date.now() > deadline) throw new Error(`zerops: sandbox ${current.id} stayed ${current.status}`)
|
|
84
|
+
await sleep(TRANSITION_POLL_MS, signal)
|
|
85
|
+
current = await client.getSandbox(current.id, signal)
|
|
86
|
+
}
|
|
87
|
+
return current
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The sandbox running: a parked one is woken, a transition waited out. */
|
|
91
|
+
export async function runningSandbox(client: ZboxClient, sandboxId: string, sleep: Sleeper, signal: AbortSignal): Promise<ZboxSandbox> {
|
|
92
|
+
let sandbox = await settledSandbox(client, await existingSandbox(client, sandboxId, signal), sleep, signal)
|
|
93
|
+
if (sandbox.status === 'PARKED') {
|
|
94
|
+
await withSandboxCapacity(() => client.wake(sandbox.id, signal))
|
|
95
|
+
sandbox = await settledSandbox(client, await client.getSandbox(sandbox.id, signal), sleep, signal)
|
|
96
|
+
}
|
|
97
|
+
if (sandbox.status !== 'RUNNING') throw new Error(`zerops: sandbox ${sandbox.id} is ${sandbox.status} and cannot run`)
|
|
98
|
+
return sandbox
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const existingSandbox = async (client: ZboxClient, sandboxId: string, signal: AbortSignal): Promise<ZboxSandbox> => {
|
|
102
|
+
try {
|
|
103
|
+
return await client.getSandbox(sandboxId, signal)
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (isZboxNotFound(error)) throw new Error(`zerops: the workspace's sandbox ${sandboxId} no longer exists; bind the workspace again`)
|
|
106
|
+
throw error
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const sandboxOf = (sandbox: ZboxSandbox): ProviderDevSandbox => ({
|
|
111
|
+
sandboxId: sandbox.id,
|
|
112
|
+
baseDigest: sandbox.baseDigest,
|
|
113
|
+
upstreamHost: sandboxUpstreamHost(sandbox.id),
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
export function createZeropsDevSandboxes(options: ZeropsDevSandboxesOptions): ProviderDevSandboxes {
|
|
117
|
+
const baseContext = options.baseContext ?? readSandboxBaseContext
|
|
118
|
+
|
|
119
|
+
const create = async (client: ZboxClient, workspaceId: string, signal: AbortSignal): Promise<ZboxSandbox> => {
|
|
120
|
+
const baseDigest = await ensureSandboxBase(client, await baseContext(), { signal, sleep: options.sleep })
|
|
121
|
+
const { sandbox } = await withSandboxCapacity(() =>
|
|
122
|
+
client.createSandbox({
|
|
123
|
+
name: sandboxName(workspaceId),
|
|
124
|
+
baseDigest,
|
|
125
|
+
cpus: SANDBOX_CPUS,
|
|
126
|
+
memoryBytes: SANDBOX_MEMORY_BYTES,
|
|
127
|
+
diskBytes: SANDBOX_DISK_BYTES,
|
|
128
|
+
networkMode: 'INTERNET',
|
|
129
|
+
launch: { entrypoint: SANDBOX_INIT_COMMAND.slice(0, 1), cmd: SANDBOX_INIT_COMMAND.slice(1) },
|
|
130
|
+
ports: [{ port: ZEROPS_APPLICATION_PORT, access: 'PROJECT', wakeOnRequest: true }],
|
|
131
|
+
// Fresh per call: a key that repeats after a removal could replay Box's answer naming the removed sandbox. A lost
|
|
132
|
+
// answer is found again by name, which a live sandbox holds alone.
|
|
133
|
+
idempotencyKey: crypto.randomUUID(),
|
|
134
|
+
}, signal)
|
|
135
|
+
)
|
|
136
|
+
return sandbox
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const hostClient = (environment: ProviderEnvironment, sandboxKey: string): ZboxClient => {
|
|
140
|
+
const client = options.client(environment, sandboxKey)
|
|
141
|
+
if (client === null) {
|
|
142
|
+
throw new ProviderNamespaceError(
|
|
143
|
+
"zerops: the namespace's sandbox host is not created yet; a namespace republish creates it",
|
|
144
|
+
PROVIDER_DEV_HOST_PENDING,
|
|
145
|
+
true,
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
return client
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
admit: (input) => {
|
|
153
|
+
assertDevEnvironment(input.environment)
|
|
154
|
+
options.admit(input.environment)
|
|
155
|
+
},
|
|
156
|
+
ensure: async (input) => {
|
|
157
|
+
assertDevEnvironment(input.environment)
|
|
158
|
+
options.admit(input.environment)
|
|
159
|
+
const client = hostClient(input.environment, input.sandboxKey)
|
|
160
|
+
const found = await client.findSandboxByName(sandboxName(input.workspaceId), input.signal)
|
|
161
|
+
let replaced: string | null = null
|
|
162
|
+
if (found !== null) {
|
|
163
|
+
const sandbox = await settledSandbox(client, found, options.sleep, input.signal)
|
|
164
|
+
if (!ENDED.has(sandbox.status)) {
|
|
165
|
+
// A sandbox on an older base is kept: a new one would change its id, which the published proxy entry names.
|
|
166
|
+
return sandboxOf(await runningSandbox(client, sandbox.id, options.sleep, input.signal))
|
|
167
|
+
}
|
|
168
|
+
await client.deleteSandbox(sandbox.id, sandboxIdempotencyKey('delete', sandbox.id), input.signal)
|
|
169
|
+
replaced = sandbox.id
|
|
170
|
+
}
|
|
171
|
+
const created = await create(client, input.workspaceId, input.signal)
|
|
172
|
+
if (replaced !== null) {
|
|
173
|
+
options.log(
|
|
174
|
+
`zerops: workspace ${input.workspaceId}'s sandbox ${replaced} had ended; it is replaced by sandbox ${created.id}, with an empty database`,
|
|
175
|
+
)
|
|
176
|
+
}
|
|
177
|
+
return sandboxOf(await runningSandbox(client, created.id, options.sleep, input.signal))
|
|
178
|
+
},
|
|
179
|
+
park: async (input) => {
|
|
180
|
+
assertDevEnvironment(input.environment)
|
|
181
|
+
const client = hostClient(input.environment, input.sandboxKey)
|
|
182
|
+
const sandbox = await settledSandbox(client, await existingSandbox(client, input.sandbox.sandboxId, input.signal), options.sleep, input.signal)
|
|
183
|
+
if (sandbox.status === 'PARKED') return
|
|
184
|
+
if (sandbox.status !== 'RUNNING') throw new Error(`zerops: sandbox ${sandbox.id} is ${sandbox.status} and cannot be parked`)
|
|
185
|
+
await client.park(sandbox.id, { memory: true }, input.signal)
|
|
186
|
+
},
|
|
187
|
+
wake: async (input) => {
|
|
188
|
+
assertDevEnvironment(input.environment)
|
|
189
|
+
const client = hostClient(input.environment, input.sandboxKey)
|
|
190
|
+
await runningSandbox(client, input.sandbox.sandboxId, options.sleep, input.signal)
|
|
191
|
+
},
|
|
192
|
+
remove: async (input) => {
|
|
193
|
+
assertDevEnvironment(input.environment)
|
|
194
|
+
const client = options.client(input.environment, input.sandboxKey)
|
|
195
|
+
// No sandbox host, so no sandbox of the workspace can exist.
|
|
196
|
+
if (client === null) return
|
|
197
|
+
const recorded = input.sandbox?.sandboxId
|
|
198
|
+
if (recorded !== undefined) await client.deleteSandbox(recorded, sandboxIdempotencyKey('delete', recorded), input.signal)
|
|
199
|
+
// An `ensure` that raced the removal may have created another sandbox under the workspace's name.
|
|
200
|
+
const named = (await client.findSandboxByName(sandboxName(input.workspaceId), input.signal))?.id
|
|
201
|
+
if (named !== undefined && named !== recorded) await client.deleteSandbox(named, sandboxIdempotencyKey('delete', named), input.signal)
|
|
202
|
+
},
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// The helper scripts every deploy uploads into a sandbox (`packages/provider-zerops/sandbox/bin/`), under a directory
|
|
2
|
+
// named by their hash: a fix reaches every existing sandbox with its next deploy, without a new base image.
|
|
3
|
+
|
|
4
|
+
import { contentVersion, readSandboxFiles } from './base-image'
|
|
5
|
+
import { SANDBOX_BIN_DIR } from './constants'
|
|
6
|
+
|
|
7
|
+
export const SANDBOX_SCRIPT_FILES = ['postgres-auth.sh', 'reset.sh', 'run-build.sh', 'run-launcher.sh', 'start-launcher.sh', 'stop.sh'] as const
|
|
8
|
+
|
|
9
|
+
export type SandboxScript = (typeof SANDBOX_SCRIPT_FILES)[number]
|
|
10
|
+
|
|
11
|
+
export interface SandboxScripts {
|
|
12
|
+
readonly version: string
|
|
13
|
+
readonly files: Readonly<Record<string, Uint8Array>>
|
|
14
|
+
/** The absolute path of a script of this version inside a sandbox. */
|
|
15
|
+
path(script: SandboxScript): string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function sandboxScripts(files: Readonly<Record<string, Uint8Array>>): SandboxScripts {
|
|
19
|
+
const version = contentVersion(files)
|
|
20
|
+
return { version, files, path: (script) => `${SANDBOX_BIN_DIR}/${version}/${script}` }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The scripts this package ships. */
|
|
24
|
+
export async function readSandboxScripts(): Promise<SandboxScripts> {
|
|
25
|
+
return sandboxScripts(await readSandboxFiles('./bin/', SANDBOX_SCRIPT_FILES))
|
|
26
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ZEROPS_APPLICATION_PORT } from './execution'
|
|
2
|
+
|
|
3
|
+
/** The hostname of a namespace's dev sandbox host: a Zerops Box Workspace, which runs one sandbox per MCP workspace. */
|
|
4
|
+
export const SANDBOX_HOST_HOSTNAME = 'zbox'
|
|
5
|
+
|
|
6
|
+
/** The type an import declares. */
|
|
7
|
+
export const SANDBOX_HOST_TYPE = 'zbox@1'
|
|
8
|
+
|
|
9
|
+
/** The type the platform reads back for it (measured live): the OS-qualified form of `SANDBOX_HOST_TYPE`. */
|
|
10
|
+
export const SANDBOX_HOST_SERVICE_TYPE = 'ubuntu/zbox@1'
|
|
11
|
+
|
|
12
|
+
/** The Box API port. Control reaches it over the service's public subdomain, with the key Fabrika generated for it. */
|
|
13
|
+
export const SANDBOX_HOST_API_PORT = 8080
|
|
14
|
+
|
|
15
|
+
/** The Box router port: the namespace proxy reaches a sandbox's project-only application port here, by Host. */
|
|
16
|
+
export const SANDBOX_HOST_ROUTER_PORT = 8081
|
|
17
|
+
|
|
18
|
+
/** The service variable Box reads its API key from; Fabrika writes it sensitive and never reads it back. */
|
|
19
|
+
export const SANDBOX_HOST_KEY_VARIABLE = 'ZBOX_WORKSPACE_API_KEY'
|
|
20
|
+
|
|
21
|
+
/** The dial address of the Box router from the namespace proxy. */
|
|
22
|
+
export const SANDBOX_UPSTREAM = `${SANDBOX_HOST_HOSTNAME}:${SANDBOX_HOST_ROUTER_PORT}`
|
|
23
|
+
|
|
24
|
+
/** The Host the namespace proxy sends the Box router to reach a sandbox's application port: the bare form, no domain. */
|
|
25
|
+
export function sandboxUpstreamHost(sandboxId: string): string {
|
|
26
|
+
if (!/^[a-z0-9]{1,32}$/.test(sandboxId)) throw new Error('zerops: a sandbox id is lower-case letters and digits')
|
|
27
|
+
return `${ZEROPS_APPLICATION_PORT}-${sandboxId}`
|
|
28
|
+
}
|
package/src/source/port.ts
CHANGED
|
@@ -38,6 +38,11 @@ export interface ZeropsSourceUploadInput {
|
|
|
38
38
|
readonly archive: ZeropsSourceArchive
|
|
39
39
|
/** A credential in transit: never logged, persisted, or returned in an error. */
|
|
40
40
|
readonly uploadUrl: string
|
|
41
|
+
/**
|
|
42
|
+
* Present for a dev sandbox: `uploadUrl` is the sandbox host's file endpoint for one sandbox, and the PUT carries this
|
|
43
|
+
* bearer. A credential in transit, like `uploadUrl`.
|
|
44
|
+
*/
|
|
45
|
+
readonly uploadBearer?: string
|
|
41
46
|
readonly signal: AbortSignal
|
|
42
47
|
}
|
|
43
48
|
|
package/src/types.ts
CHANGED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import type { z } from 'zod'
|
|
2
|
+
import { isZboxNotFound, ZboxApiError, zboxErrorCode, zboxOperationErrorCode, ZboxOperationFailed } from './errors'
|
|
3
|
+
import {
|
|
4
|
+
type ZboxAwaitOptions,
|
|
5
|
+
zboxBaseListSchema,
|
|
6
|
+
type ZboxBody,
|
|
7
|
+
type ZboxClient,
|
|
8
|
+
type ZboxClientOptions,
|
|
9
|
+
zboxExecResultSchema,
|
|
10
|
+
type ZboxOperation,
|
|
11
|
+
zboxOperationSchema,
|
|
12
|
+
type ZboxSandbox,
|
|
13
|
+
zboxSandboxListSchema,
|
|
14
|
+
zboxSandboxSchema,
|
|
15
|
+
zboxSessionSchema,
|
|
16
|
+
zboxSpawnSchema,
|
|
17
|
+
zboxSuccessSchema,
|
|
18
|
+
zboxWorkspaceSchema,
|
|
19
|
+
} from './types'
|
|
20
|
+
|
|
21
|
+
/** Box cuts a request off at 60 s; giving up first leaves the error ours to name. */
|
|
22
|
+
const REQUEST_TIMEOUT_MS = 55_000
|
|
23
|
+
|
|
24
|
+
/** The longest `waitSeconds` Box honours. */
|
|
25
|
+
const MAX_WAIT_SECONDS = 30
|
|
26
|
+
|
|
27
|
+
/** How long a create, park, wake or delete may take before the client stops waiting. Measured: all under 2 s. */
|
|
28
|
+
const OPERATION_DEADLINE_MS = 120_000
|
|
29
|
+
|
|
30
|
+
interface CallInit {
|
|
31
|
+
json?: unknown
|
|
32
|
+
body?: ZboxBody
|
|
33
|
+
idempotencyKey?: string
|
|
34
|
+
signal: AbortSignal | undefined
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const createZboxClient = (options: ZboxClientOptions): ZboxClient => {
|
|
38
|
+
const base = `${options.baseUrl.replace(/\/+$/, '')}/api/rest`
|
|
39
|
+
const doFetch = options.fetch ?? fetch
|
|
40
|
+
const nextIdempotencyKey = options.idempotencyKey ?? (() => crypto.randomUUID())
|
|
41
|
+
|
|
42
|
+
const errorBody = async (response: Response): Promise<unknown> => {
|
|
43
|
+
try {
|
|
44
|
+
return JSON.parse(await response.text())
|
|
45
|
+
} catch {
|
|
46
|
+
return null
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const call = async <Result>(
|
|
51
|
+
operation: string,
|
|
52
|
+
method: string,
|
|
53
|
+
path: string,
|
|
54
|
+
init: CallInit,
|
|
55
|
+
read: (response: Response) => Promise<Result>,
|
|
56
|
+
): Promise<Result> => {
|
|
57
|
+
init.signal?.throwIfAborted()
|
|
58
|
+
const timeout = AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
59
|
+
const signal = init.signal === undefined ? timeout : AbortSignal.any([init.signal, timeout])
|
|
60
|
+
const headers: Record<string, string> = { authorization: `Bearer ${options.apiKey}`, accept: 'application/json' }
|
|
61
|
+
if (init.idempotencyKey !== undefined) {
|
|
62
|
+
headers['idempotency-key'] = init.idempotencyKey
|
|
63
|
+
}
|
|
64
|
+
let body: string | ZboxBody | undefined
|
|
65
|
+
if (init.json !== undefined) {
|
|
66
|
+
headers['content-type'] = 'application/json'
|
|
67
|
+
body = JSON.stringify(init.json)
|
|
68
|
+
} else if (init.body !== undefined) {
|
|
69
|
+
headers['content-type'] = 'application/octet-stream'
|
|
70
|
+
body = init.body
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const response = await doFetch(`${base}${path}`, { method, headers, body, signal })
|
|
74
|
+
if (!response.ok) {
|
|
75
|
+
throw new ZboxApiError(operation, response.status, zboxErrorCode(response.status, await errorBody(response)))
|
|
76
|
+
}
|
|
77
|
+
return await read(response)
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (error instanceof ZboxApiError) throw error
|
|
80
|
+
init.signal?.throwIfAborted()
|
|
81
|
+
// The fetch error is dropped: its text is the runtime's, and nothing here may echo a request.
|
|
82
|
+
throw new ZboxApiError(operation, 0, timeout.aborted ? 'timeout' : 'unreachable')
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const json = <Output>(operation: string, schema: z.ZodType<Output, z.ZodTypeDef, unknown>) => async (response: Response): Promise<Output> => {
|
|
87
|
+
let value: unknown
|
|
88
|
+
try {
|
|
89
|
+
value = JSON.parse(await response.text())
|
|
90
|
+
} catch {
|
|
91
|
+
throw new ZboxApiError(operation, response.status, 'unreadable')
|
|
92
|
+
}
|
|
93
|
+
const parsed = schema.safeParse(value)
|
|
94
|
+
if (!parsed.success) {
|
|
95
|
+
throw new ZboxApiError(operation, response.status, 'unreadable')
|
|
96
|
+
}
|
|
97
|
+
return parsed.data
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const bytes = async (response: Response): Promise<Uint8Array> => new Uint8Array(await response.arrayBuffer())
|
|
101
|
+
|
|
102
|
+
const sandboxPath = (id: string, suffix = ''): string => `/sandbox/${encodeURIComponent(id)}${suffix}`
|
|
103
|
+
|
|
104
|
+
const getOperation = (id: string, waitSeconds: number, signal?: AbortSignal): Promise<ZboxOperation> => {
|
|
105
|
+
const wait = Math.max(0, Math.min(MAX_WAIT_SECONDS, Math.floor(waitSeconds)))
|
|
106
|
+
return call(
|
|
107
|
+
'get operation',
|
|
108
|
+
'GET',
|
|
109
|
+
`/operation/${encodeURIComponent(id)}?waitSeconds=${wait}`,
|
|
110
|
+
{ signal },
|
|
111
|
+
json('get operation', zboxOperationSchema),
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const awaitOperation = async (operation: ZboxOperation, awaitOptions: ZboxAwaitOptions): Promise<ZboxOperation> => {
|
|
116
|
+
const startedAt = Date.now()
|
|
117
|
+
let current = operation
|
|
118
|
+
while (true) {
|
|
119
|
+
if (current.status === 'FINISHED') return current
|
|
120
|
+
if (current.status === 'FAILED') {
|
|
121
|
+
throw new ZboxOperationFailed(current.kind, current.id, zboxOperationErrorCode(current.error))
|
|
122
|
+
}
|
|
123
|
+
awaitOptions.signal?.throwIfAborted()
|
|
124
|
+
const remainingMs = awaitOptions.deadlineMs - (Date.now() - startedAt)
|
|
125
|
+
if (remainingMs <= 0) {
|
|
126
|
+
throw new ZboxApiError(`await ${current.kind} operation`, 0, 'timeout')
|
|
127
|
+
}
|
|
128
|
+
current = await getOperation(current.id, Math.max(1, Math.min(MAX_WAIT_SECONDS, Math.floor(remainingMs / 1000))), awaitOptions.signal)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const getSandbox = (id: string, signal?: AbortSignal): Promise<ZboxSandbox> =>
|
|
133
|
+
call('get sandbox', 'GET', sandboxPath(id), { signal }, json('get sandbox', zboxSandboxSchema))
|
|
134
|
+
|
|
135
|
+
const sandboxOperation = async (operation: string, id: string, suffix: string, payload: unknown, signal?: AbortSignal): Promise<ZboxOperation> => {
|
|
136
|
+
const started = await call(
|
|
137
|
+
operation,
|
|
138
|
+
'POST',
|
|
139
|
+
sandboxPath(id, suffix),
|
|
140
|
+
{ json: payload, idempotencyKey: nextIdempotencyKey(), signal },
|
|
141
|
+
json(operation, zboxOperationSchema),
|
|
142
|
+
)
|
|
143
|
+
return awaitOperation(started, { signal, deadlineMs: OPERATION_DEADLINE_MS })
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
getWorkspace: (signal) => call('get workspace', 'GET', '/workspace', { signal }, json('get workspace', zboxWorkspaceSchema)),
|
|
148
|
+
|
|
149
|
+
pullBase: ({ imageRef, name }, signal) =>
|
|
150
|
+
call(
|
|
151
|
+
'pull base',
|
|
152
|
+
'POST',
|
|
153
|
+
'/base',
|
|
154
|
+
{ json: { imageRef, name }, idempotencyKey: nextIdempotencyKey(), signal },
|
|
155
|
+
json('pull base', zboxOperationSchema),
|
|
156
|
+
),
|
|
157
|
+
|
|
158
|
+
buildBase: ({ context, name }, signal) =>
|
|
159
|
+
call('build base', 'POST', `/base-build?name=${encodeURIComponent(name)}`, { body: context, signal }, json('build base', zboxOperationSchema)),
|
|
160
|
+
|
|
161
|
+
listBases: async (signal) => (await call('list bases', 'GET', '/base-list', { signal }, json('list bases', zboxBaseListSchema))).items,
|
|
162
|
+
|
|
163
|
+
getOperation,
|
|
164
|
+
|
|
165
|
+
awaitOperation,
|
|
166
|
+
|
|
167
|
+
createSandbox: async (input, signal) => {
|
|
168
|
+
const spawn = await call(
|
|
169
|
+
'create sandbox',
|
|
170
|
+
'POST',
|
|
171
|
+
'/sandbox',
|
|
172
|
+
{
|
|
173
|
+
json: {
|
|
174
|
+
name: input.name,
|
|
175
|
+
baseDigest: input.baseDigest,
|
|
176
|
+
cpus: input.cpus,
|
|
177
|
+
memoryBytes: input.memoryBytes,
|
|
178
|
+
diskBytes: input.diskBytes,
|
|
179
|
+
networkMode: input.networkMode,
|
|
180
|
+
integrations: [],
|
|
181
|
+
launch: { entrypoint: input.launch.entrypoint, cmd: input.launch.cmd, workingDir: input.launch.workingDir },
|
|
182
|
+
policy: {
|
|
183
|
+
ingress: {
|
|
184
|
+
ports: input.ports.map(({ port, access, wakeOnRequest }) => ({ port, access, protocol: 'HTTP', wakeOnRequest })),
|
|
185
|
+
},
|
|
186
|
+
secrets: { mode: 'NONE' },
|
|
187
|
+
},
|
|
188
|
+
waitSeconds: MAX_WAIT_SECONDS,
|
|
189
|
+
},
|
|
190
|
+
idempotencyKey: input.idempotencyKey,
|
|
191
|
+
signal,
|
|
192
|
+
},
|
|
193
|
+
json('create sandbox', zboxSpawnSchema),
|
|
194
|
+
)
|
|
195
|
+
const [created, ...others] = spawn.sandboxes
|
|
196
|
+
if (created === undefined || others.length > 0) {
|
|
197
|
+
throw new ZboxApiError('create sandbox', 200, 'unreadable')
|
|
198
|
+
}
|
|
199
|
+
const operation = await awaitOperation(spawn.operation, { signal, deadlineMs: OPERATION_DEADLINE_MS })
|
|
200
|
+
// A create answered before it finished carries the CREATING row; read the final one.
|
|
201
|
+
const sandbox = spawn.operation.status === 'FINISHED' ? created : await getSandbox(created.id, signal)
|
|
202
|
+
return { operation, sandbox }
|
|
203
|
+
},
|
|
204
|
+
|
|
205
|
+
getSandbox,
|
|
206
|
+
|
|
207
|
+
findSandboxByName: async (name, signal) => {
|
|
208
|
+
const list = await call('list sandboxes', 'GET', '/sandbox-list', { signal }, json('list sandboxes', zboxSandboxListSchema))
|
|
209
|
+
// Box refuses a create whose name a live sandbox holds, so at most one live sandbox matches.
|
|
210
|
+
return list.items.find((sandbox) => sandbox.name === name) ?? null
|
|
211
|
+
},
|
|
212
|
+
|
|
213
|
+
deleteSandbox: async (id, idempotencyKey, signal) => {
|
|
214
|
+
let started: ZboxOperation
|
|
215
|
+
try {
|
|
216
|
+
started = await call('delete sandbox', 'DELETE', sandboxPath(id), { idempotencyKey, signal }, json('delete sandbox', zboxOperationSchema))
|
|
217
|
+
} catch (error) {
|
|
218
|
+
if (isZboxNotFound(error) && error.code === 'sandboxNotFound') return
|
|
219
|
+
throw error
|
|
220
|
+
}
|
|
221
|
+
await awaitOperation(started, { signal, deadlineMs: OPERATION_DEADLINE_MS })
|
|
222
|
+
},
|
|
223
|
+
|
|
224
|
+
park: (id, { memory }, signal) => sandboxOperation('park sandbox', id, '/park', { memory }, signal),
|
|
225
|
+
|
|
226
|
+
wake: (id, signal) => sandboxOperation('wake sandbox', id, '/wake', {}, signal),
|
|
227
|
+
|
|
228
|
+
exec: (id, { command, workingDir, timeoutSeconds }, signal) =>
|
|
229
|
+
call('exec', 'POST', sandboxPath(id, '/exec'), { json: { command, workingDir, timeoutSeconds }, signal }, json('exec', zboxExecResultSchema)),
|
|
230
|
+
|
|
231
|
+
startProcess: (id, { command, workingDir }, signal) =>
|
|
232
|
+
call('start process', 'POST', sandboxPath(id, '/process'), { json: { command, workingDir }, signal }, json('start process', zboxSessionSchema)),
|
|
233
|
+
|
|
234
|
+
getSession: (id, signal) => call('get session', 'GET', `/session/${encodeURIComponent(id)}`, { signal }, json('get session', zboxSessionSchema)),
|
|
235
|
+
|
|
236
|
+
sessionOutput: (id, signal) => call('get session output', 'GET', `/session/${encodeURIComponent(id)}/output`, { signal }, bytes),
|
|
237
|
+
|
|
238
|
+
putFile: async (id, path, body, putOptions) => {
|
|
239
|
+
const mode = putOptions?.mode === undefined ? '' : `&mode=${encodeURIComponent(putOptions.mode)}`
|
|
240
|
+
await call(
|
|
241
|
+
'put file',
|
|
242
|
+
'PUT',
|
|
243
|
+
sandboxPath(id, `/file?path=${encodeURIComponent(path)}${mode}`),
|
|
244
|
+
{ body, signal: putOptions?.signal },
|
|
245
|
+
json('put file', zboxSuccessSchema),
|
|
246
|
+
)
|
|
247
|
+
},
|
|
248
|
+
|
|
249
|
+
getFile: async (id, path, signal) => {
|
|
250
|
+
try {
|
|
251
|
+
return await call('get file', 'GET', sandboxPath(id, `/file?path=${encodeURIComponent(path)}`), { signal }, bytes)
|
|
252
|
+
} catch (error) {
|
|
253
|
+
// Only a missing PATH is an absent file; a missing sandbox stays an error.
|
|
254
|
+
if (isZboxNotFound(error) && error.code === 'pathNotFound') return null
|
|
255
|
+
throw error
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
}
|
|
259
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
/** A Box error code is a fixed identifier; anything else in that slot is body text and must not reach a message. */
|
|
4
|
+
const BOX_CODE = /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/
|
|
5
|
+
|
|
6
|
+
const codeSchema = z.string().regex(BOX_CODE).optional().catch(undefined)
|
|
7
|
+
// Live answers wrap the error (`{ error: { code } }`); the OpenAPI `Error` schema is the bare `{ code }`.
|
|
8
|
+
const errorBodySchema = z
|
|
9
|
+
.object({ code: codeSchema, error: z.object({ code: codeSchema }).optional().catch(undefined) })
|
|
10
|
+
.catch({ code: undefined, error: undefined })
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A failed Box Workspace API call. `code` is Box's `error.code` when the body was Box's error JSON, `http_<status>`
|
|
14
|
+
* when it was not, or one of the client's own: `unreadable` (a success body that does not parse), `timeout`,
|
|
15
|
+
* `unreachable` (status 0 for the last two). The message names the operation and nothing the server sent beyond
|
|
16
|
+
* the code: a body is the server's text, and a message may reach a log.
|
|
17
|
+
*/
|
|
18
|
+
export class ZboxApiError extends Error {
|
|
19
|
+
constructor(readonly operation: string, readonly status: number, readonly code: string) {
|
|
20
|
+
super(`zbox: ${operation} failed (${status === 0 ? code : `${status} ${code}`})`)
|
|
21
|
+
this.name = 'ZboxApiError'
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** An asynchronous Box operation that ended FAILED. `code` is Box's error only when it is an identifier. */
|
|
26
|
+
export class ZboxOperationFailed extends Error {
|
|
27
|
+
constructor(readonly kind: string, readonly operationId: string, readonly code: string | null) {
|
|
28
|
+
super(`zbox: ${kind} operation ${operationId} failed${code === null ? '' : ` (${code})`}`)
|
|
29
|
+
this.name = 'ZboxOperationFailed'
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const zboxErrorCode = (status: number, body: unknown): string => {
|
|
34
|
+
const parsed = errorBodySchema.parse(body)
|
|
35
|
+
return parsed.error?.code ?? parsed.code ?? `http_${status}`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const zboxOperationErrorCode = (error: string | null): string | null => error !== null && BOX_CODE.test(error) ? error : null
|
|
39
|
+
|
|
40
|
+
export const isZboxNotFound = (error: unknown): error is ZboxApiError => error instanceof ZboxApiError && error.status === 404
|
|
41
|
+
|
|
42
|
+
export const isZboxWorkspaceFull = (error: unknown): error is ZboxApiError => error instanceof ZboxApiError && error.code === 'workspaceFull'
|
|
43
|
+
|
|
44
|
+
/** An upload over the workspace's body limit; nginx answers it with an HTML page, so only the status identifies it. */
|
|
45
|
+
export const isZboxTooLarge = (error: unknown): error is ZboxApiError => error instanceof ZboxApiError && error.status === 413
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { createZboxClient } from './client'
|
|
2
|
+
export { isZboxNotFound, isZboxTooLarge, isZboxWorkspaceFull, ZboxApiError, ZboxOperationFailed } from './errors'
|
|
3
|
+
export type {
|
|
4
|
+
ZboxAwaitOptions,
|
|
5
|
+
ZboxBase,
|
|
6
|
+
ZboxBody,
|
|
7
|
+
ZboxClient,
|
|
8
|
+
ZboxClientOptions,
|
|
9
|
+
ZboxCreateSandboxInput,
|
|
10
|
+
ZboxExecInput,
|
|
11
|
+
ZboxExecResult,
|
|
12
|
+
ZboxFetch,
|
|
13
|
+
ZboxIngressPort,
|
|
14
|
+
ZboxLaunch,
|
|
15
|
+
ZboxNetworkMode,
|
|
16
|
+
ZboxOperation,
|
|
17
|
+
ZboxPortAccess,
|
|
18
|
+
ZboxProcessInput,
|
|
19
|
+
ZboxSandbox,
|
|
20
|
+
ZboxSession,
|
|
21
|
+
ZboxWorkspace,
|
|
22
|
+
} from './types'
|