unfazed 0.8.1 → 0.10.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/eve-sandbox/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EACL,qBAAqB,EACrB,uBAAuB,GAMxB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EACL,UAAU,EACV,aAAa,EACb,kBAAkB,GAInB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAgClE,uFAAuF;AACvF,MAAM,kBAAkB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAC3C,kEAAkE;AAClE,MAAM,eAAe,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AACzC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAElC,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAEjC;IACA;IAFX,YACW,MAAc,EACd,IAAY,EACrB,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAJN,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAQ;QAIrB,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED,SAAS,MAAM,CAAC,OAA8B;IAC5C,IAAI,OAAO,CAAC,GAAG;QAAE,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACxD,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,sCAAsC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,2CAA2C,OAAO,CAAC,GAAG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box` — eve sandboxes backed by an unfazed box.\n *\n * ```ts title=\"agent/sandbox.ts\"\n * import { defineSandbox } from \"eve/sandbox\";\n * import { UnfazedSandbox } from \"unfazed/eve-sandbox\";\n *\n * export const environment = UnfazedSandbox.environment({ box: \"my-sandbox-box\" });\n * export default defineSandbox(() => environment.open());\n * ```\n *\n * The box runs the sandbox daemon (`unfazed eve-sandbox setup` inside it).\n * Each eve session gets its own Unix user, home and workspace on the box; the\n * box keeps them across restarts and redeploys until the session ends. The\n * app authenticates with its workload identity token (audience: the box's\n * URL), so it needs no stored secret; the box's allow list names the apps it\n * serves.\n *\n * Requires the optional peer `eve` (0.90 or newer).\n */\n\nimport type { SandboxSession } from \"eve/sandbox\";\nimport {\n defineSandboxProvider,\n SandboxSessionGoneError,\n type SandboxConnection,\n type SandboxPrepareContext,\n type SandboxProvider,\n type SandboxProviderDefinition,\n type WithPrepareOption,\n} from \"eve/sandbox/provider\";\nimport { oidcToken } from \"../oidc.js\";\nimport {\n API_PREFIX,\n TEMPLATE_HOME,\n TEMPLATE_WORKSPACE,\n type ProcessEvent,\n type SessionInfo,\n type WireFile,\n} from \"./protocol.js\";\n\nexport { TEMPLATE_HOME, TEMPLATE_WORKSPACE } from \"./protocol.js\";\n\n/** Options of `UnfazedSandbox.environment()`. */\nexport interface UnfazedSandboxOptions {\n /** The box's alias; its URL is `https://<box>.unfz.to`. */\n readonly box?: string;\n /** The box's URL, instead of `box`. */\n readonly url?: string;\n /** Token audience; the box's URL by default. */\n readonly audience?: string;\n /** Supplies the bearer token; the app's workload identity token by default. */\n readonly token?: (audience: string) => Promise<string>;\n /** `fetch` used for every call (tests). */\n readonly fetch?: FetchLike;\n}\n\n/** The subset of `fetch` the client uses. */\nexport type FetchLike = (input: string, init: RequestInit) => Promise<Response>;\n\n/** The artifact `prepare()` ships with the deployment: the template files. */\nexport type UnfazedSandboxArtifact = {\n readonly v: 1;\n readonly files: readonly WireFile[];\n};\n\n/** What eve checkpoints for a session. */\nexport type UnfazedSandboxState = {\n readonly v: 1;\n readonly sessionId: string;\n readonly workspace: string;\n};\n\n/** Template files larger than this in total belong on the box, not in the artifact. */\nconst MAX_TEMPLATE_BYTES = 8 * 1024 * 1024;\n/** One `writeFiles` request carries at most this much content. */\nconst MAX_WRITE_BATCH = 16 * 1024 * 1024;\nconst CONTROL_TIMEOUT_MS = 60_000;\n\nexport class UnfazedSandboxError extends Error {\n constructor(\n readonly status: number,\n readonly code: string,\n message: string,\n ) {\n super(message);\n this.name = \"UnfazedSandboxError\";\n }\n}\n\nfunction boxUrl(options: UnfazedSandboxOptions): string {\n if (options.url) return options.url.replace(/\\/+$/, \"\");\n if (options.box) {\n if (!/^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/.test(options.box)) throw new Error(`unfazed eve sandbox: invalid box alias \"${options.box}\"`);\n return `https://${options.box}.unfz.to`;\n }\n throw new Error(\"unfazed eve sandbox: pass { box } or { url }\");\n}\n\nconst toB64 = (bytes: Uint8Array) => Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString(\"base64\");\n\n/** The daemon's HTTP API, one per environment. */\nexport class SandboxClient {\n private readonly doFetch: FetchLike;\n\n constructor(\n readonly base: string,\n private readonly bearer: () => Promise<string>,\n doFetch?: FetchLike,\n ) {\n this.doFetch = doFetch ?? ((input, init) => fetch(input, init));\n }\n\n async request(method: string, path: string, init: { body?: BodyInit; json?: unknown; signal?: AbortSignal; timeoutMs?: number } = {}): Promise<Response> {\n const headers: Record<string, string> = { authorization: `Bearer ${await this.bearer()}` };\n let body = init.body;\n if (init.json !== undefined) {\n headers[\"content-type\"] = \"application/json\";\n body = JSON.stringify(init.json);\n }\n const signals = [AbortSignal.timeout(init.timeoutMs ?? CONTROL_TIMEOUT_MS), ...(init.signal ? [init.signal] : [])];\n return await this.doFetch(`${this.base}${API_PREFIX}${path}`, { method, headers, body, signal: AbortSignal.any(signals) });\n }\n\n async ok(response: Response, what: string): Promise<Response> {\n if (response.ok) return response;\n let code = \"http_\" + response.status;\n let message = \"\";\n try {\n const body = (await response.json()) as { error?: string; message?: string };\n code = body.error ?? code;\n message = body.message ?? \"\";\n } catch {\n // not JSON\n }\n throw new UnfazedSandboxError(response.status, code, `unfazed eve sandbox: ${what}: ${response.status} ${code}${message ? `: ${message}` : \"\"}`);\n }\n\n async ensure(sessionId: string, template: readonly WireFile[]): Promise<SessionInfo> {\n const res = await this.request(\"PUT\", `/sessions/${encodeURIComponent(sessionId)}`, { json: { template } });\n return (await (await this.ok(res, \"start the sandbox\")).json()) as SessionInfo;\n }\n\n /** The session, or `null` when the box no longer has it. */\n async get(sessionId: string): Promise<SessionInfo | null> {\n const res = await this.request(\"GET\", `/sessions/${encodeURIComponent(sessionId)}`);\n if (res.status === 410) return null;\n return (await (await this.ok(res, \"resume the sandbox\")).json()) as SessionInfo;\n }\n\n async delete(sessionId: string, signal?: AbortSignal): Promise<void> {\n const res = await this.request(\"DELETE\", `/sessions/${encodeURIComponent(sessionId)}`, { signal });\n await this.ok(res, \"delete the sandbox\");\n }\n}\n\n/** A sandbox session that is gone answers 410: eve then starts a fresh one. */\nfunction gone(error: unknown, sessionId: string): never {\n if (error instanceof UnfazedSandboxError && error.status === 410) {\n throw new SandboxSessionGoneError(`unfazed sandbox for session ${sessionId} is gone`);\n }\n throw error;\n}\n\n/** Reads a process's event stream, reconnecting after a dropped connection. */\nasync function followProcess(\n client: SandboxClient,\n id: string,\n onEvent: (event: ProcessEvent) => void,\n signal: AbortSignal,\n): Promise<number> {\n let after = 0;\n let failures = 0;\n for (;;) {\n try {\n const res = await client.ok(\n await client.request(\"GET\", `/processes/${id}/events?after=${after}`, { signal, timeoutMs: 24 * 60 * 60 * 1000 }),\n \"read process output\",\n );\n const reader = res.body!.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n for (;;) {\n const { value, done } = await reader.read();\n if (done) break;\n buffer += decoder.decode(value, { stream: true });\n let cut: number;\n while ((cut = buffer.indexOf(\"\\n\\n\")) >= 0) {\n const frame = buffer.slice(0, cut);\n buffer = buffer.slice(cut + 2);\n for (const line of frame.split(\"\\n\")) {\n if (!line.startsWith(\"data: \")) continue;\n const event = JSON.parse(line.slice(6)) as ProcessEvent;\n after = event.s;\n failures = 0;\n onEvent(event);\n if (\"x\" in event) return event.x;\n }\n }\n }\n } catch (error) {\n if (signal.aborted) throw error;\n if (error instanceof UnfazedSandboxError && error.status < 500) throw error;\n if (++failures > 8) throw error;\n }\n await new Promise((resolve) => setTimeout(resolve, Math.min(250 * 2 ** failures, 5000)));\n }\n}\n\nfunction connect(client: SandboxClient, sessionId: string, session: SessionInfo): SandboxConnection {\n const sid = encodeURIComponent(sessionId);\n return {\n workspaceRoot: session.workspace,\n\n async spawn({ command, env, workingDirectory, stdin, signal }) {\n const res = await client\n .request(\"POST\", `/sessions/${sid}/processes`, { json: { command, cwd: workingDirectory, env, stdin: stdin === true }, signal })\n .then((r) => client.ok(r, \"start a command\"))\n .catch((error) => gone(error, sessionId));\n const { id, pid } = (await res.json()) as { id: string; pid?: number };\n const kill = async () => {\n await client.request(\"POST\", `/processes/${id}/kill`).catch(() => undefined);\n };\n const follow = new AbortController();\n let out!: ReadableStreamDefaultController<Uint8Array>;\n let err!: ReadableStreamDefaultController<Uint8Array>;\n const stdout = new ReadableStream<Uint8Array>({ start: (c) => void (out = c) });\n const stderr = new ReadableStream<Uint8Array>({ start: (c) => void (err = c) });\n const closeStreams = (error?: unknown) => {\n for (const c of [out, err]) {\n try {\n error === undefined ? c.close() : c.error(error);\n } catch {\n // already closed\n }\n }\n };\n const exited = followProcess(\n client,\n id,\n (event) => {\n if (\"d\" in event) (event.f === 1 ? out : err).enqueue(new Uint8Array(Buffer.from(event.d, \"base64\")));\n },\n follow.signal,\n ).then(\n (exitCode) => {\n closeStreams();\n return { exitCode };\n },\n (error) => {\n closeStreams(error);\n throw error;\n },\n );\n if (signal) {\n const onAbort = () => void kill();\n if (signal.aborted) onAbort();\n else signal.addEventListener(\"abort\", onAbort, { once: true });\n void exited.finally(() => signal.removeEventListener(\"abort\", onAbort)).catch(() => undefined);\n }\n let pending = Promise.resolve();\n const input = stdin\n ? new WritableStream<Uint8Array>({\n write: (chunk) =>\n (pending = pending.then(async () => {\n await client.ok(await client.request(\"POST\", `/processes/${id}/stdin`, { body: new Uint8Array(chunk) }), \"write stdin\");\n })),\n close: () =>\n (pending = pending.then(async () => {\n await client.ok(await client.request(\"POST\", `/processes/${id}/stdin?eof=1`, { body: new Uint8Array() }), \"close stdin\");\n })),\n })\n : undefined;\n return {\n pid,\n stdin: input,\n stdout,\n stderr,\n wait: () => exited,\n kill,\n };\n },\n\n async readFile({ path, signal }) {\n const res = await client.request(\"GET\", `/sessions/${sid}/file?path=${encodeURIComponent(path)}`, { signal }).catch((e) => gone(e, sessionId));\n if (res.status === 404) return null;\n await client.ok(res, `read ${path}`).catch((e) => gone(e, sessionId));\n return new Uint8Array(await res.arrayBuffer());\n },\n\n async writeFiles({ files, signal }) {\n let batch: WireFile[] = [];\n let size = 0;\n const send = async () => {\n if (batch.length === 0) return;\n await client\n .ok(await client.request(\"POST\", `/sessions/${sid}/files`, { json: { files: batch }, signal }), \"write files\")\n .catch((e) => gone(e, sessionId));\n batch = [];\n size = 0;\n };\n for (const file of files) {\n if (size + file.content.byteLength > MAX_WRITE_BATCH) await send();\n batch.push({ path: file.path, b64: toB64(file.content) });\n size += file.content.byteLength;\n }\n await send();\n },\n\n async removePath({ path, force, recursive, signal }) {\n await client\n .ok(await client.request(\"POST\", `/sessions/${sid}/remove`, { json: { path, force: force === true, recursive: recursive === true }, signal }), `remove ${path}`)\n .catch((e) => gone(e, sessionId));\n },\n\n async stop() {\n const res = await client.request(\"POST\", `/sessions/${sid}/stop`);\n if (res.status === 410) return;\n await client.ok(res, \"stop the sandbox\");\n },\n\n // The box keeps the session's processes (an open browser) between steps;\n // its daemon stops a session's processes after it has been idle.\n async close() {},\n };\n}\n\n/**\n * Captures the workspace and skill files `ctx.populate()` writes at build\n * time, so every new session starts from them. A build-time command other\n * than eve's `$HOME` probe is refused: install tools on the box instead.\n */\nasync function captureTemplate(ctx: SandboxPrepareContext): Promise<WireFile[]> {\n const files = new Map<string, Uint8Array>();\n const empty = () => new ReadableStream<Uint8Array>({ start: (c) => c.close() });\n const capture: SandboxConnection = {\n workspaceRoot: TEMPLATE_WORKSPACE,\n async spawn({ command }) {\n if (command.trim() !== `printf '%s\\\\n' \"$HOME\"`) {\n throw new Error(\n \"unfazed eve sandbox: commands in prepare() do not run at build time; install tools on the box itself (see `unfazed eve-sandbox setup`)\",\n );\n }\n return {\n stdout: new ReadableStream<Uint8Array>({\n start(c) {\n c.enqueue(new TextEncoder().encode(`${TEMPLATE_HOME}\\n`));\n c.close();\n },\n }),\n stderr: empty(),\n wait: async () => ({ exitCode: 0 }),\n kill: async () => {},\n };\n },\n async readFile({ path }) {\n return files.get(path) ?? null;\n },\n async writeFiles({ files: written }) {\n for (const file of written) files.set(file.path, file.content);\n },\n async removePath({ path, recursive }) {\n files.delete(path);\n if (recursive) for (const key of [...files.keys()]) if (key.startsWith(`${path}/`)) files.delete(key);\n },\n async stop() {},\n };\n await ctx.populate(capture);\n let total = 0;\n const out: WireFile[] = [];\n for (const [path, content] of files) {\n total += content.byteLength;\n out.push({ path, b64: toB64(content) });\n }\n if (total > MAX_TEMPLATE_BYTES) {\n throw new Error(`unfazed eve sandbox: the workspace and skill files are ${total} bytes; at most ${MAX_TEMPLATE_BYTES} fit in a template`);\n }\n return out.sort((a, b) => a.path.localeCompare(b.path));\n}\n\n/** The provider's implementation (for tests); eve apps use {@link UnfazedSandbox}. */\nexport const unfazedSandboxDefinition: SandboxProviderDefinition<\n UnfazedSandboxOptions,\n undefined,\n UnfazedSandboxArtifact,\n UnfazedSandboxState,\n {}\n> = {\n name: \"unfazed\",\n stateProtocolVersion: 1,\n environment(options: UnfazedSandboxOptions) {\n const base = boxUrl(options);\n const audience = options.audience ?? base;\n const token = options.token ?? ((aud: string) => oidcToken(aud));\n const client = new SandboxClient(base, () => token(audience), options.fetch);\n return {\n async prepare(ctx): Promise<UnfazedSandboxArtifact> {\n return { v: 1, files: ctx.isEmpty ? [] : await captureTemplate(ctx) };\n },\n async start(ctx, _open: undefined, artifact: Readonly<UnfazedSandboxArtifact>) {\n const session = await client.ensure(ctx.session.id, artifact?.files ?? []);\n const state: UnfazedSandboxState = { v: 1, sessionId: ctx.session.id, workspace: session.workspace };\n return { connection: connect(client, ctx.session.id, session), state };\n },\n async resume(ctx, _artifact: Readonly<UnfazedSandboxArtifact>, state: Readonly<UnfazedSandboxState>) {\n const sessionId = typeof state?.sessionId === \"string\" ? state.sessionId : ctx.session.id;\n const session = await client.get(sessionId);\n if (session === null) throw new SandboxSessionGoneError(`unfazed sandbox for session ${sessionId} is gone`);\n return connect(client, sessionId, session);\n },\n async onSessionEnd(ctx, state: Readonly<UnfazedSandboxState> | null, { signal }) {\n const sessionId = typeof state?.sessionId === \"string\" ? state.sessionId : ctx.session.id;\n await client.delete(sessionId, signal);\n },\n // Keyed MCP tool sessions keep their sandbox between calls; the box\n // deletes a sandbox nobody used for its retention period.\n toolSessions: true as const,\n };\n },\n};\n\n/** The eve sandbox provider backed by an unfazed box. */\nexport const UnfazedSandbox: SandboxProvider<WithPrepareOption<UnfazedSandboxOptions, SandboxSession>, undefined, SandboxSession> =\n defineSandboxProvider(unfazedSandboxDefinition);\n"]}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Wire contract between the eve sandbox provider (`unfazed/eve-sandbox`) and
3
+ * the sandbox daemon that runs inside an unfazed box (`daemon.ts`).
4
+ *
5
+ * Every route but `GET /v1/health` takes `Authorization: Bearer <OIDC JWT>`:
6
+ * a workload identity token of the calling app (issuer
7
+ * `https://unfazed.dev/oidc`) whose audience is the box's URL. The daemon
8
+ * namespaces every sandbox by the token's `app_id`, so two apps sharing a box
9
+ * never see each other's sessions.
10
+ */
11
+ /** Version segment of every route. */
12
+ export declare const API_PREFIX = "/v1";
13
+ /** The daemon's own version, reported by `GET /v1/health`. */
14
+ export declare const DAEMON_VERSION = "1";
15
+ /**
16
+ * Template files captured at build time name these placeholder roots; the
17
+ * daemon maps them onto the session's workspace and home when it creates the
18
+ * session.
19
+ */
20
+ export declare const TEMPLATE_WORKSPACE = "/__unfazed_eve_workspace__";
21
+ export declare const TEMPLATE_HOME = "/__unfazed_eve_home__";
22
+ /** A file as it travels in JSON: an absolute path and base64 content. */
23
+ export type WireFile = {
24
+ readonly path: string;
25
+ readonly b64: string;
26
+ };
27
+ /** `PUT /v1/sessions/:id` body. */
28
+ export interface EnsureSessionRequest {
29
+ readonly template?: readonly WireFile[];
30
+ }
31
+ /** A session as the daemon reports it. */
32
+ export interface SessionInfo {
33
+ readonly name: string;
34
+ readonly home: string;
35
+ readonly workspace: string;
36
+ readonly created?: boolean;
37
+ }
38
+ /** `POST /v1/sessions/:id/processes` body. */
39
+ export interface SpawnRequest {
40
+ readonly command: string;
41
+ readonly cwd: string;
42
+ readonly env: Readonly<Record<string, string>>;
43
+ readonly stdin: boolean;
44
+ }
45
+ /**
46
+ * One server-sent event of `GET /v1/processes/:id/events`: output of stream
47
+ * `f` (1 stdout, 2 stderr) as base64 `d`, or the exit code `x`, numbered `s`
48
+ * from 1 so a client can resume with `?after=<s>`.
49
+ */
50
+ export type ProcessEvent = {
51
+ readonly s: number;
52
+ readonly f: 1 | 2;
53
+ readonly d: string;
54
+ } | {
55
+ readonly s: number;
56
+ readonly x: number;
57
+ };
58
+ /** `POST /v1/sessions/:id/remove` body. */
59
+ export interface RemoveRequest {
60
+ readonly path: string;
61
+ readonly force?: boolean;
62
+ readonly recursive?: boolean;
63
+ }
64
+ /** Error body of every non-2xx answer. */
65
+ export interface ErrorBody {
66
+ readonly error: string;
67
+ readonly message?: string;
68
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Wire contract between the eve sandbox provider (`unfazed/eve-sandbox`) and
3
+ * the sandbox daemon that runs inside an unfazed box (`daemon.ts`).
4
+ *
5
+ * Every route but `GET /v1/health` takes `Authorization: Bearer <OIDC JWT>`:
6
+ * a workload identity token of the calling app (issuer
7
+ * `https://unfazed.dev/oidc`) whose audience is the box's URL. The daemon
8
+ * namespaces every sandbox by the token's `app_id`, so two apps sharing a box
9
+ * never see each other's sessions.
10
+ */
11
+ /** Version segment of every route. */
12
+ export const API_PREFIX = "/v1";
13
+ /** The daemon's own version, reported by `GET /v1/health`. */
14
+ export const DAEMON_VERSION = "1";
15
+ /**
16
+ * Template files captured at build time name these placeholder roots; the
17
+ * daemon maps them onto the session's workspace and home when it creates the
18
+ * session.
19
+ */
20
+ export const TEMPLATE_WORKSPACE = "/__unfazed_eve_workspace__";
21
+ export const TEMPLATE_HOME = "/__unfazed_eve_home__";
22
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/eve-sandbox/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,sCAAsC;AACtC,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,CAAC;AAEhC,8DAA8D;AAC9D,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAC;AAElC;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,4BAA4B,CAAC;AAC/D,MAAM,CAAC,MAAM,aAAa,GAAG,uBAAuB,CAAC","sourcesContent":["/**\n * Wire contract between the eve sandbox provider (`unfazed/eve-sandbox`) and\n * the sandbox daemon that runs inside an unfazed box (`daemon.ts`).\n *\n * Every route but `GET /v1/health` takes `Authorization: Bearer <OIDC JWT>`:\n * a workload identity token of the calling app (issuer\n * `https://unfazed.dev/oidc`) whose audience is the box's URL. The daemon\n * namespaces every sandbox by the token's `app_id`, so two apps sharing a box\n * never see each other's sessions.\n */\n\n/** Version segment of every route. */\nexport const API_PREFIX = \"/v1\";\n\n/** The daemon's own version, reported by `GET /v1/health`. */\nexport const DAEMON_VERSION = \"1\";\n\n/**\n * Template files captured at build time name these placeholder roots; the\n * daemon maps them onto the session's workspace and home when it creates the\n * session.\n */\nexport const TEMPLATE_WORKSPACE = \"/__unfazed_eve_workspace__\";\nexport const TEMPLATE_HOME = \"/__unfazed_eve_home__\";\n\n/** A file as it travels in JSON: an absolute path and base64 content. */\nexport type WireFile = {\n readonly path: string;\n readonly b64: string;\n};\n\n/** `PUT /v1/sessions/:id` body. */\nexport interface EnsureSessionRequest {\n readonly template?: readonly WireFile[];\n}\n\n/** A session as the daemon reports it. */\nexport interface SessionInfo {\n readonly name: string;\n readonly home: string;\n readonly workspace: string;\n readonly created?: boolean;\n}\n\n/** `POST /v1/sessions/:id/processes` body. */\nexport interface SpawnRequest {\n readonly command: string;\n readonly cwd: string;\n readonly env: Readonly<Record<string, string>>;\n readonly stdin: boolean;\n}\n\n/**\n * One server-sent event of `GET /v1/processes/:id/events`: output of stream\n * `f` (1 stdout, 2 stderr) as base64 `d`, or the exit code `x`, numbered `s`\n * from 1 so a client can resume with `?after=<s>`.\n */\nexport type ProcessEvent =\n | { readonly s: number; readonly f: 1 | 2; readonly d: string }\n | { readonly s: number; readonly x: number };\n\n/** `POST /v1/sessions/:id/remove` body. */\nexport interface RemoveRequest {\n readonly path: string;\n readonly force?: boolean;\n readonly recursive?: boolean;\n}\n\n/** Error body of every non-2xx answer. */\nexport interface ErrorBody {\n readonly error: string;\n readonly message?: string;\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -35,8 +35,22 @@ export type { AppRef, ClientTimings, CommitDeploymentTarget, CommitDetail, Commi
35
35
  export { help, REFERENCE } from "./reference.js";
36
36
  export { UnfazedClient, DEFAULT_BASE_URL, DEFAULT_ENDPOINT, ENDPOINT_ENV_VAR, GRAPHQL_PATH, TOKEN_ENV_VAR, VERSION, } from "./client.js";
37
37
  export type { ClientOptions, FetchLike, GraphQLDocument, RequestOptions, ResultOf, VariablesOf, } from "./client.js";
38
- export { DEPLOYMENT_NOT_FOUND, UnfazedAuthError, UnfazedConfigError, UnfazedConflictError, UnfazedDeployError, UnfazedError, UnfazedGraphQLError, UnfazedHTTPError, UnfazedNotFoundError, UnfazedRunError, UnfazedTimeoutError, UnfazedUnconfirmedAppsError, UnfazedWriteError, WORKSPACE_NOT_FOUND, isDuplicateWorkspaceName, isNotFoundSentinel, isTooManyWaits, } from "./errors.js";
39
- export type { GraphQLResponseError } from "./errors.js";
38
+ /**
39
+ * Workload identity: OIDC tokens the platform issues to the app this code
40
+ * runs in, with only its `UNFZ_STATE_TOKEN`. `oidc` is the process's own
41
+ * {@link UnfazedOIDC}; `new Unfazed().oidc` is the same with the instance's
42
+ * endpoint and fetch.
43
+ *
44
+ * ```ts
45
+ * import { oidc, oidcToken } from "unfazed";
46
+ * const jwt = await oidcToken("https://api.example.com");
47
+ * const fetch = oidc.fetchWithToken(process.env.PRIVATEINFERENCE_AUDIENCE);
48
+ * ```
49
+ */
50
+ export { OIDC_TOKEN_PATH, STATE_TOKEN_ENV_VAR, UnfazedOIDC, oidc, oidcToken } from "./oidc.js";
51
+ export type { FetchWithTokenOptions, OIDCOptions, OIDCToken, OIDCTokenOptions, OIDCTransport, TokenFetch, } from "./oidc.js";
52
+ export { DEPLOYMENT_NOT_FOUND, UnfazedAuthError, UnfazedConfigError, UnfazedConflictError, UnfazedDeployError, UnfazedError, UnfazedGraphQLError, UnfazedHTTPError, UnfazedNotFoundError, UnfazedOIDCError, UnfazedRunError, UnfazedTimeoutError, UnfazedUnconfirmedAppsError, UnfazedWriteError, WORKSPACE_NOT_FOUND, isDuplicateWorkspaceName, isNotFoundSentinel, isTooManyWaits, } from "./errors.js";
53
+ export type { GraphQLResponseError, OIDCErrorCode } from "./errors.js";
40
54
  export type { WaitOptions } from "./wait.js";
41
55
  /**
42
56
  * The stored login of `npx unfazed login`, which {@link UnfazedClient} uses when
package/dist/index.js CHANGED
@@ -32,7 +32,20 @@ export { Unfazed, parseDeploymentTimings } from "./unfazed.js";
32
32
  */
33
33
  export { help, REFERENCE } from "./reference.js";
34
34
  export { UnfazedClient, DEFAULT_BASE_URL, DEFAULT_ENDPOINT, ENDPOINT_ENV_VAR, GRAPHQL_PATH, TOKEN_ENV_VAR, VERSION, } from "./client.js";
35
- export { DEPLOYMENT_NOT_FOUND, UnfazedAuthError, UnfazedConfigError, UnfazedConflictError, UnfazedDeployError, UnfazedError, UnfazedGraphQLError, UnfazedHTTPError, UnfazedNotFoundError, UnfazedRunError, UnfazedTimeoutError, UnfazedUnconfirmedAppsError, UnfazedWriteError, WORKSPACE_NOT_FOUND, isDuplicateWorkspaceName, isNotFoundSentinel, isTooManyWaits, } from "./errors.js";
35
+ /**
36
+ * Workload identity: OIDC tokens the platform issues to the app this code
37
+ * runs in, with only its `UNFZ_STATE_TOKEN`. `oidc` is the process's own
38
+ * {@link UnfazedOIDC}; `new Unfazed().oidc` is the same with the instance's
39
+ * endpoint and fetch.
40
+ *
41
+ * ```ts
42
+ * import { oidc, oidcToken } from "unfazed";
43
+ * const jwt = await oidcToken("https://api.example.com");
44
+ * const fetch = oidc.fetchWithToken(process.env.PRIVATEINFERENCE_AUDIENCE);
45
+ * ```
46
+ */
47
+ export { OIDC_TOKEN_PATH, STATE_TOKEN_ENV_VAR, UnfazedOIDC, oidc, oidcToken } from "./oidc.js";
48
+ export { DEPLOYMENT_NOT_FOUND, UnfazedAuthError, UnfazedConfigError, UnfazedConflictError, UnfazedDeployError, UnfazedError, UnfazedGraphQLError, UnfazedHTTPError, UnfazedNotFoundError, UnfazedOIDCError, UnfazedRunError, UnfazedTimeoutError, UnfazedUnconfirmedAppsError, UnfazedWriteError, WORKSPACE_NOT_FOUND, isDuplicateWorkspaceName, isNotFoundSentinel, isTooManyWaits, } from "./errors.js";
36
49
  /**
37
50
  * The stored login of `npx unfazed login`, which {@link UnfazedClient} uses when
38
51
  * no token is passed and `UNFZ_API_TOKEN` is unset. The helpers that read,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAIH,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAoD/D;;;;GAIG;AACH,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,OAAO,GACR,MAAM,aAAa,CAAC;AAUrB,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,2BAA2B,EAC3B,iBAAiB,EACjB,mBAAmB,EACnB,wBAAwB,EACxB,kBAAkB,EAClB,cAAc,GACf,MAAM,aAAa,CAAC;AAKrB;;;;GAIG;AACH,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGpF,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAA4B;IAC5D,MAAM,EAAE,iBAAiB,EAAE,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC;IAChE,OAAO,iBAAiB,CAAC,OAAO,CAAC,CAAC;AACpC,CAAC;AAED;;;GAGG;AACH,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC","sourcesContent":["/**\n * unfazed — official TypeScript SDK.\n *\n * The code-mode companion to the unfazed MCP server: write one script that\n * deploys, waits, reads logs and filters them locally, instead of chaining a\n * dozen tool calls through a model's context.\n *\n * ```ts\n * import { Unfazed } from \"unfazed\";\n *\n * const unfazed = new Unfazed(); // UNFZ_API_TOKEN, else your `npx unfazed login`\n * const ws = await unfazed.createWorkspace(\"hello\");\n * await unfazed.writeFiles(ws.id, {\n * \"server.ts\": `export default { fetch: () => new Response(\"hi\") }`,\n * });\n * const app = await unfazed.deployService({ workspaceId: ws.id, alias: \"hello\", wait: true });\n * console.log(app.url);\n * ```\n *\n * `help()` returns the reference: every method with its signature.\n *\n * Two layers, both public:\n * - {@link Unfazed} — the workflow layer (deploy + wait, one-commit batch\n * writes, history and restore, errors, events, one-call rollback).\n * - {@link UnfazedClient} — the typed GraphQL transport, for anything not wrapped.\n */\n\nimport type { RemoteWorld, RemoteWorldOptions } from \"./remote/world.js\";\n\nexport { Unfazed, parseDeploymentTimings } from \"./unfazed.js\";\nexport type {\n AppRef,\n ClientTimings,\n CommitDeploymentTarget,\n CommitDetail,\n CommitPage,\n CommitsLanded,\n CreateRunOptions,\n FollowUpRunOptions,\n DeleteAppOptions,\n DeleteAppResult,\n DeleteDeploymentOptions,\n DeleteWorkspaceOptions,\n Deployment,\n DeploymentEvent,\n DeployBoxOptions,\n DeployOptions,\n DeployResult,\n DeployServiceOptions,\n DeployStaticOptions,\n DeployTimings,\n EnvVar,\n ErrorGroup,\n ErrorGroupDetail,\n ErrorGroupPage,\n ErrorGroupRef,\n EventPage,\n EventsInput,\n EventType,\n FileCommit,\n FileContent,\n FilesMap,\n FileWriteOutcome,\n ListErrorsOptions,\n ListRunsFilter,\n LiveApp,\n PlatformEvent,\n PlatformTimings,\n RestoreVersionOptions,\n RestoreVersionResult,\n RollbackOptions,\n Run,\n TimingEvent,\n UnfazedOptions,\n Workspace,\n WorkspaceFile,\n WriteFilesOptions,\n WriteFilesResult,\n WrittenFile,\n} from \"./unfazed.js\";\n\n/**\n * The SDK's reference — every method with its signature — as a string:\n * `help()` for the page, `help(\"writeFiles\")` for one entry. The same page\n * ships as REFERENCE.md and is served at https://unfazed.dev/sdk.md.\n */\nexport { help, REFERENCE } from \"./reference.js\";\n\nexport {\n UnfazedClient,\n DEFAULT_BASE_URL,\n DEFAULT_ENDPOINT,\n ENDPOINT_ENV_VAR,\n GRAPHQL_PATH,\n TOKEN_ENV_VAR,\n VERSION,\n} from \"./client.js\";\nexport type {\n ClientOptions,\n FetchLike,\n GraphQLDocument,\n RequestOptions,\n ResultOf,\n VariablesOf,\n} from \"./client.js\";\n\nexport {\n DEPLOYMENT_NOT_FOUND,\n UnfazedAuthError,\n UnfazedConfigError,\n UnfazedConflictError,\n UnfazedDeployError,\n UnfazedError,\n UnfazedGraphQLError,\n UnfazedHTTPError,\n UnfazedNotFoundError,\n UnfazedRunError,\n UnfazedTimeoutError,\n UnfazedUnconfirmedAppsError,\n UnfazedWriteError,\n WORKSPACE_NOT_FOUND,\n isDuplicateWorkspaceName,\n isNotFoundSentinel,\n isTooManyWaits,\n} from \"./errors.js\";\nexport type { GraphQLResponseError } from \"./errors.js\";\n\nexport type { WaitOptions } from \"./wait.js\";\n\n/**\n * The stored login of `npx unfazed login`, which {@link UnfazedClient} uses when\n * no token is passed and `UNFZ_API_TOKEN` is unset. The helpers that read,\n * write and refresh it are in `unfazed/credentials`.\n */\nexport { CREDENTIALS_FILE, LOGIN_COMMAND, credentialsPath } from \"./credentials.js\";\nexport type { StoredCredentials } from \"./credentials.js\";\n\nexport { UnfazedInspectError } from \"./errors.js\";\nexport { APP_ENV_VAR } from \"./remote/app.js\";\nexport type { RemoteWorld, RemoteWorldOptions } from \"./remote/world.js\";\n\n/**\n * The `unfazed` backend of Workflow SDK's CLI: a read-mostly World over the\n * platform's workflow inspection API, for one app.\n *\n * ```sh\n * npx unfazed login # once: signs you in, in the browser\n * UNFZ_APP=birthday-card npx workflow inspect runs --backend unfazed\n * ```\n *\n * The token is `UNFZ_API_TOKEN` when set, else the stored login of\n * `npx unfazed login`, refreshed as it expires.\n *\n * The CLI (and its `--web` UI) resolve `unfazed` from the project and call\n * this with no arguments. The app is `UNFZ_APP`, else the `alias` (or the\n * single `apps[]` entry) of `unfazed.json` in the current directory. Reads\n * and `workflow cancel` work; every other write throws, since an app's own\n * World is `unfazed/workflow`. The module behind it loads on first call, so\n * `import \"unfazed\"` stays as light as before.\n */\nexport async function createWorld(options?: RemoteWorldOptions): Promise<RemoteWorld> {\n const { createRemoteWorld } = await import(\"./remote/world.js\");\n return createRemoteWorld(options);\n}\n\n/**\n * Every operation document the workflow layer uses, for callers that want the\n * typed documents but not the wrapper methods.\n */\nexport * as operations from \"./operations.js\";\n\n/**\n * Schema types generated from the platform's `graph/schema.graphqls`: enums\n * (`DeploymentStatus`, `ServiceMode`, ...), input objects\n * (`CreateDeploymentInput`, ...) and every operation's result type.\n */\nexport type * from \"./generated/graphql.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAIH,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAoD/D;;;;GAIG;AACH,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,OAAO,GACR,MAAM,aAAa,CAAC;AAUrB;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAU/F,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,2BAA2B,EAC3B,iBAAiB,EACjB,mBAAmB,EACnB,wBAAwB,EACxB,kBAAkB,EAClB,cAAc,GACf,MAAM,aAAa,CAAC;AAKrB;;;;GAIG;AACH,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGpF,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAA4B;IAC5D,MAAM,EAAE,iBAAiB,EAAE,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC;IAChE,OAAO,iBAAiB,CAAC,OAAO,CAAC,CAAC;AACpC,CAAC;AAED;;;GAGG;AACH,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC","sourcesContent":["/**\n * unfazed — official TypeScript SDK.\n *\n * The code-mode companion to the unfazed MCP server: write one script that\n * deploys, waits, reads logs and filters them locally, instead of chaining a\n * dozen tool calls through a model's context.\n *\n * ```ts\n * import { Unfazed } from \"unfazed\";\n *\n * const unfazed = new Unfazed(); // UNFZ_API_TOKEN, else your `npx unfazed login`\n * const ws = await unfazed.createWorkspace(\"hello\");\n * await unfazed.writeFiles(ws.id, {\n * \"server.ts\": `export default { fetch: () => new Response(\"hi\") }`,\n * });\n * const app = await unfazed.deployService({ workspaceId: ws.id, alias: \"hello\", wait: true });\n * console.log(app.url);\n * ```\n *\n * `help()` returns the reference: every method with its signature.\n *\n * Two layers, both public:\n * - {@link Unfazed} — the workflow layer (deploy + wait, one-commit batch\n * writes, history and restore, errors, events, one-call rollback).\n * - {@link UnfazedClient} — the typed GraphQL transport, for anything not wrapped.\n */\n\nimport type { RemoteWorld, RemoteWorldOptions } from \"./remote/world.js\";\n\nexport { Unfazed, parseDeploymentTimings } from \"./unfazed.js\";\nexport type {\n AppRef,\n ClientTimings,\n CommitDeploymentTarget,\n CommitDetail,\n CommitPage,\n CommitsLanded,\n CreateRunOptions,\n FollowUpRunOptions,\n DeleteAppOptions,\n DeleteAppResult,\n DeleteDeploymentOptions,\n DeleteWorkspaceOptions,\n Deployment,\n DeploymentEvent,\n DeployBoxOptions,\n DeployOptions,\n DeployResult,\n DeployServiceOptions,\n DeployStaticOptions,\n DeployTimings,\n EnvVar,\n ErrorGroup,\n ErrorGroupDetail,\n ErrorGroupPage,\n ErrorGroupRef,\n EventPage,\n EventsInput,\n EventType,\n FileCommit,\n FileContent,\n FilesMap,\n FileWriteOutcome,\n ListErrorsOptions,\n ListRunsFilter,\n LiveApp,\n PlatformEvent,\n PlatformTimings,\n RestoreVersionOptions,\n RestoreVersionResult,\n RollbackOptions,\n Run,\n TimingEvent,\n UnfazedOptions,\n Workspace,\n WorkspaceFile,\n WriteFilesOptions,\n WriteFilesResult,\n WrittenFile,\n} from \"./unfazed.js\";\n\n/**\n * The SDK's reference — every method with its signature — as a string:\n * `help()` for the page, `help(\"writeFiles\")` for one entry. The same page\n * ships as REFERENCE.md and is served at https://unfazed.dev/sdk.md.\n */\nexport { help, REFERENCE } from \"./reference.js\";\n\nexport {\n UnfazedClient,\n DEFAULT_BASE_URL,\n DEFAULT_ENDPOINT,\n ENDPOINT_ENV_VAR,\n GRAPHQL_PATH,\n TOKEN_ENV_VAR,\n VERSION,\n} from \"./client.js\";\nexport type {\n ClientOptions,\n FetchLike,\n GraphQLDocument,\n RequestOptions,\n ResultOf,\n VariablesOf,\n} from \"./client.js\";\n\n/**\n * Workload identity: OIDC tokens the platform issues to the app this code\n * runs in, with only its `UNFZ_STATE_TOKEN`. `oidc` is the process's own\n * {@link UnfazedOIDC}; `new Unfazed().oidc` is the same with the instance's\n * endpoint and fetch.\n *\n * ```ts\n * import { oidc, oidcToken } from \"unfazed\";\n * const jwt = await oidcToken(\"https://api.example.com\");\n * const fetch = oidc.fetchWithToken(process.env.PRIVATEINFERENCE_AUDIENCE);\n * ```\n */\nexport { OIDC_TOKEN_PATH, STATE_TOKEN_ENV_VAR, UnfazedOIDC, oidc, oidcToken } from \"./oidc.js\";\nexport type {\n FetchWithTokenOptions,\n OIDCOptions,\n OIDCToken,\n OIDCTokenOptions,\n OIDCTransport,\n TokenFetch,\n} from \"./oidc.js\";\n\nexport {\n DEPLOYMENT_NOT_FOUND,\n UnfazedAuthError,\n UnfazedConfigError,\n UnfazedConflictError,\n UnfazedDeployError,\n UnfazedError,\n UnfazedGraphQLError,\n UnfazedHTTPError,\n UnfazedNotFoundError,\n UnfazedOIDCError,\n UnfazedRunError,\n UnfazedTimeoutError,\n UnfazedUnconfirmedAppsError,\n UnfazedWriteError,\n WORKSPACE_NOT_FOUND,\n isDuplicateWorkspaceName,\n isNotFoundSentinel,\n isTooManyWaits,\n} from \"./errors.js\";\nexport type { GraphQLResponseError, OIDCErrorCode } from \"./errors.js\";\n\nexport type { WaitOptions } from \"./wait.js\";\n\n/**\n * The stored login of `npx unfazed login`, which {@link UnfazedClient} uses when\n * no token is passed and `UNFZ_API_TOKEN` is unset. The helpers that read,\n * write and refresh it are in `unfazed/credentials`.\n */\nexport { CREDENTIALS_FILE, LOGIN_COMMAND, credentialsPath } from \"./credentials.js\";\nexport type { StoredCredentials } from \"./credentials.js\";\n\nexport { UnfazedInspectError } from \"./errors.js\";\nexport { APP_ENV_VAR } from \"./remote/app.js\";\nexport type { RemoteWorld, RemoteWorldOptions } from \"./remote/world.js\";\n\n/**\n * The `unfazed` backend of Workflow SDK's CLI: a read-mostly World over the\n * platform's workflow inspection API, for one app.\n *\n * ```sh\n * npx unfazed login # once: signs you in, in the browser\n * UNFZ_APP=birthday-card npx workflow inspect runs --backend unfazed\n * ```\n *\n * The token is `UNFZ_API_TOKEN` when set, else the stored login of\n * `npx unfazed login`, refreshed as it expires.\n *\n * The CLI (and its `--web` UI) resolve `unfazed` from the project and call\n * this with no arguments. The app is `UNFZ_APP`, else the `alias` (or the\n * single `apps[]` entry) of `unfazed.json` in the current directory. Reads\n * and `workflow cancel` work; every other write throws, since an app's own\n * World is `unfazed/workflow`. The module behind it loads on first call, so\n * `import \"unfazed\"` stays as light as before.\n */\nexport async function createWorld(options?: RemoteWorldOptions): Promise<RemoteWorld> {\n const { createRemoteWorld } = await import(\"./remote/world.js\");\n return createRemoteWorld(options);\n}\n\n/**\n * Every operation document the workflow layer uses, for callers that want the\n * typed documents but not the wrapper methods.\n */\nexport * as operations from \"./operations.js\";\n\n/**\n * Schema types generated from the platform's `graph/schema.graphqls`: enums\n * (`DeploymentStatus`, `ServiceMode`, ...), input objects\n * (`CreateDeploymentInput`, ...) and every operation's result type.\n */\nexport type * from \"./generated/graphql.js\";\n"]}
package/dist/oidc.d.ts ADDED
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Workload identity: OIDC tokens the platform issues to an app.
3
+ *
4
+ * An app running on unfazed (a service or a cron job) asks the control plane
5
+ * for a short-lived JWT that names it, for one audience, and presents it to a
6
+ * service that trusts the issuer `https://unfazed.dev/oidc` instead of a
7
+ * static API key. The only credential is the app's own `UNFZ_STATE_TOKEN`,
8
+ * which the platform puts into each of its VMs; no `UNFZ_API_TOKEN` is
9
+ * involved.
10
+ *
11
+ * ```ts
12
+ * import { oidcToken } from "unfazed";
13
+ * const jwt = await oidcToken("https://api.example.com");
14
+ * ```
15
+ *
16
+ * Wire contract: `POST <platform>/oidc/token` with
17
+ * `Authorization: Bearer $UNFZ_STATE_TOKEN` and `{ audience, ttl_seconds? }`;
18
+ * 200 is `{ token, expires_at, token_type: "Bearer" }`, an error
19
+ * `{ error, error_description }`.
20
+ */
21
+ /** Environment variable holding the app's state token, set in every unfazed service and cron VM. */
22
+ export declare const STATE_TOKEN_ENV_VAR = "UNFZ_STATE_TOKEN";
23
+ /** Path of the token endpoint under the platform origin. */
24
+ export declare const OIDC_TOKEN_PATH = "/oidc/token";
25
+ /**
26
+ * The `fetch` the token request goes through: the global `fetch`, or anything
27
+ * shaped like it (the client's `FetchLike` fits). `headers` on the response
28
+ * is read for `Retry-After` when present.
29
+ */
30
+ export type OIDCTransport = (input: string, init: {
31
+ method: string;
32
+ headers: Record<string, string>;
33
+ body: string;
34
+ signal?: AbortSignal;
35
+ }) => Promise<{
36
+ status: number;
37
+ headers?: {
38
+ get(name: string): string | null;
39
+ };
40
+ text(): Promise<string>;
41
+ }>;
42
+ /** A `fetch` as the OpenAI SDK (and most HTTP clients) take one. */
43
+ export type TokenFetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
44
+ export interface OIDCOptions {
45
+ /** The app's state token. Default: `UNFZ_STATE_TOKEN`, read on every call. */
46
+ stateToken?: string;
47
+ /**
48
+ * Full GraphQL endpoint; tokens come from its origin. Wins over `baseUrl`.
49
+ * Falls back to `UNFZ_API_URL`, then `https://unfazed.dev` (as the client).
50
+ */
51
+ endpoint?: string;
52
+ /** Platform origin; `/oidc/token` is appended. */
53
+ baseUrl?: string;
54
+ /** Where `UNFZ_STATE_TOKEN` and `UNFZ_API_URL` are read from. Default: `process.env`. */
55
+ env?: Record<string, string | undefined>;
56
+ /**
57
+ * The transport of the token request. Default: the global `fetch`. An
58
+ * instance with its own `fetch` (or `now`) keeps its own cache; every other
59
+ * one shares the process's.
60
+ */
61
+ fetch?: OIDCTransport;
62
+ /** Overrides the default `unfazed-sdk/<version>` User-Agent. */
63
+ userAgent?: string;
64
+ /** Timeout of one attempt, in ms. Default 10_000; 0 disables it. */
65
+ timeoutMs?: number;
66
+ /** Injected wall clock, ms (tests). */
67
+ now?: () => number;
68
+ /** Injected sleep between retries (tests). */
69
+ sleep?: (ms: number) => Promise<void>;
70
+ }
71
+ export interface OIDCTokenOptions {
72
+ /** Token lifetime, a whole number of seconds from 60 to 3600. Default: the platform's. */
73
+ ttlSeconds?: number;
74
+ /**
75
+ * Stops waiting, with {@link UnfazedTimeoutError}. A request other callers
76
+ * wait on too keeps going (and fills the cache).
77
+ */
78
+ signal?: AbortSignal;
79
+ }
80
+ /** A token with its expiry, from {@link UnfazedOIDC.tokenResponse}. */
81
+ export interface OIDCToken {
82
+ /** The JWT. */
83
+ token: string;
84
+ /** When it expires (the platform's `expires_at`). */
85
+ expiresAt: Date;
86
+ }
87
+ export interface FetchWithTokenOptions {
88
+ /** Token lifetime, a whole number of seconds from 60 to 3600. Default: the platform's. */
89
+ ttlSeconds?: number;
90
+ /** The `fetch` that sends the request. Default: the global `fetch`, at call time. */
91
+ fetch?: TokenFetch;
92
+ }
93
+ /**
94
+ * Workload identity tokens for the app this code runs in: `unfazed.oidc` on an
95
+ * {@link import("./unfazed.js").Unfazed} instance, or the standalone `oidc`.
96
+ *
97
+ * Tokens are cached per (audience, ttl) and reused until 80% of their
98
+ * lifetime has passed; concurrent calls for the same pair share one request.
99
+ * 503 (and a gateway's 502/504), 429 and network failures are retried up to 3
100
+ * times (200, 400, 800 ms; a 429's or 503's `Retry-After` up to 10 s is waited
101
+ * out instead); no other 4xx is retried. When a refresh fails for one of
102
+ * those passing reasons, the token it was replacing is returned while it is
103
+ * still valid.
104
+ */
105
+ export declare class UnfazedOIDC {
106
+ #private;
107
+ constructor(options?: OIDCOptions);
108
+ /**
109
+ * A JWT for `audience`, from the cache while it is fresh.
110
+ *
111
+ * ```ts
112
+ * const jwt = await unfazed.oidc.token("https://api.example.com", { ttlSeconds: 300 });
113
+ * ```
114
+ *
115
+ * Throws {@link UnfazedOIDCError}: `not_in_app` without `UNFZ_STATE_TOKEN`,
116
+ * `invalid_audience`, `invalid_request` (`ttlSeconds`), or the platform's
117
+ * code.
118
+ */
119
+ token(audience: string | undefined, options?: OIDCTokenOptions): Promise<string>;
120
+ /** {@link token}, with the token's expiry: `{ token, expiresAt }`. */
121
+ tokenResponse(audience: string | undefined, options?: OIDCTokenOptions): Promise<OIDCToken>;
122
+ /**
123
+ * A `fetch` that sends every request with `Authorization: Bearer <token>`,
124
+ * a fresh token for `audience` each time (from the cache while it lasts).
125
+ * Every other header, the body and the signal pass through; an
126
+ * `Authorization` already there is replaced.
127
+ *
128
+ * ```ts
129
+ * const openai = new OpenAI({
130
+ * baseURL: process.env.PRIVATEINFERENCE_BASE_URL,
131
+ * apiKey: "unused",
132
+ * fetch: unfazed.oidc.fetchWithToken(process.env.PRIVATEINFERENCE_AUDIENCE),
133
+ * });
134
+ * ```
135
+ *
136
+ * An invalid `audience` (an unset variable among them) throws here, at
137
+ * once; a missing `UNFZ_STATE_TOKEN` on the first request.
138
+ */
139
+ fetchWithToken(audience: string | undefined, options?: FetchWithTokenOptions): TokenFetch;
140
+ }
141
+ /**
142
+ * The process's own {@link UnfazedOIDC}: `UNFZ_STATE_TOKEN` and `UNFZ_API_URL`
143
+ * read on every call, the global `fetch`, one cache.
144
+ *
145
+ * ```ts
146
+ * import { oidc } from "unfazed";
147
+ * const fetchWithToken = oidc.fetchWithToken(process.env.PRIVATEINFERENCE_AUDIENCE);
148
+ * ```
149
+ */
150
+ export declare const oidc: UnfazedOIDC;
151
+ /**
152
+ * A JWT for `audience`, issued to the app this code runs in:
153
+ * {@link UnfazedOIDC.token} on the process's {@link oidc}. Needs only
154
+ * `UNFZ_STATE_TOKEN`.
155
+ *
156
+ * ```ts
157
+ * import { oidcToken } from "unfazed";
158
+ * const res = await fetch(url, { headers: { Authorization: `Bearer ${await oidcToken(url)}` } });
159
+ * ```
160
+ */
161
+ export declare function oidcToken(audience: string | undefined, options?: OIDCTokenOptions): Promise<string>;