unfazed 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +323 -1
  2. package/dist/client.d.ts +1 -1
  3. package/dist/client.js +1 -1
  4. package/dist/client.js.map +1 -1
  5. package/dist/errors.d.ts +25 -0
  6. package/dist/errors.js +25 -0
  7. package/dist/errors.js.map +1 -1
  8. package/dist/generated/gql.d.ts +5 -1
  9. package/dist/generated/gql.js +2 -1
  10. package/dist/generated/gql.js.map +1 -1
  11. package/dist/generated/graphql.d.ts +107 -0
  12. package/dist/generated/graphql.js +101 -0
  13. package/dist/generated/graphql.js.map +1 -1
  14. package/dist/index.d.ts +21 -0
  15. package/dist/index.js +22 -0
  16. package/dist/index.js.map +1 -1
  17. package/dist/operations.d.ts +3 -0
  18. package/dist/operations.js +23 -0
  19. package/dist/operations.js.map +1 -1
  20. package/dist/remote/app.d.ts +18 -0
  21. package/dist/remote/app.js +76 -0
  22. package/dist/remote/app.js.map +1 -0
  23. package/dist/remote/documents.d.ts +175 -0
  24. package/dist/remote/documents.js +122 -0
  25. package/dist/remote/documents.js.map +1 -0
  26. package/dist/remote/values.d.ts +67 -0
  27. package/dist/remote/values.js +156 -0
  28. package/dist/remote/values.js.map +1 -0
  29. package/dist/remote/world.d.ts +50 -0
  30. package/dist/remote/world.js +612 -0
  31. package/dist/remote/world.js.map +1 -0
  32. package/dist/unfazed.d.ts +37 -1
  33. package/dist/unfazed.js +13 -1
  34. package/dist/unfazed.js.map +1 -1
  35. package/dist/workflow/config.d.ts +23 -0
  36. package/dist/workflow/config.js +48 -0
  37. package/dist/workflow/config.js.map +1 -0
  38. package/dist/workflow/errors.d.ts +33 -0
  39. package/dist/workflow/errors.js +16 -0
  40. package/dist/workflow/errors.js.map +1 -0
  41. package/dist/workflow/index.d.ts +30 -0
  42. package/dist/workflow/index.js +23 -0
  43. package/dist/workflow/index.js.map +1 -0
  44. package/dist/workflow/inspect-render.d.ts +93 -0
  45. package/dist/workflow/inspect-render.js +302 -0
  46. package/dist/workflow/inspect-render.js.map +1 -0
  47. package/dist/workflow/inspect.d.ts +52 -0
  48. package/dist/workflow/inspect.js +879 -0
  49. package/dist/workflow/inspect.js.map +1 -0
  50. package/dist/workflow/migration-files.d.ts +13 -0
  51. package/dist/workflow/migration-files.js +52 -0
  52. package/dist/workflow/migration-files.js.map +1 -0
  53. package/dist/workflow/migration-types.d.ts +19 -0
  54. package/dist/workflow/migration-types.js +8 -0
  55. package/dist/workflow/migration-types.js.map +1 -0
  56. package/dist/workflow/migrations.d.ts +12 -0
  57. package/dist/workflow/migrations.generated.d.ts +2 -0
  58. package/dist/workflow/migrations.generated.js +34 -0
  59. package/dist/workflow/migrations.generated.js.map +1 -0
  60. package/dist/workflow/migrations.js +94 -0
  61. package/dist/workflow/migrations.js.map +1 -0
  62. package/dist/workflow/nitro-flow-guard.d.ts +4 -0
  63. package/dist/workflow/nitro-flow-guard.js +19 -0
  64. package/dist/workflow/nitro-flow-guard.js.map +1 -0
  65. package/dist/workflow/nitro-inspect.d.ts +3 -0
  66. package/dist/workflow/nitro-inspect.js +19 -0
  67. package/dist/workflow/nitro-inspect.js.map +1 -0
  68. package/dist/workflow/nitro-plugin.d.ts +1 -0
  69. package/dist/workflow/nitro-plugin.js +13 -0
  70. package/dist/workflow/nitro-plugin.js.map +1 -0
  71. package/dist/workflow/nitro.d.ts +70 -0
  72. package/dist/workflow/nitro.js +213 -0
  73. package/dist/workflow/nitro.js.map +1 -0
  74. package/dist/workflow/public-url.d.ts +27 -0
  75. package/dist/workflow/public-url.js +45 -0
  76. package/dist/workflow/public-url.js.map +1 -0
  77. package/dist/workflow/queue.d.ts +128 -0
  78. package/dist/workflow/queue.js +375 -0
  79. package/dist/workflow/queue.js.map +1 -0
  80. package/dist/workflow/state.d.ts +25 -0
  81. package/dist/workflow/state.js +15 -0
  82. package/dist/workflow/state.js.map +1 -0
  83. package/dist/workflow/transport.d.ts +12 -0
  84. package/dist/workflow/transport.js +29 -0
  85. package/dist/workflow/transport.js.map +1 -0
  86. package/dist/workflow/world.d.ts +123 -0
  87. package/dist/workflow/world.js +375 -0
  88. package/dist/workflow/world.js.map +1 -0
  89. package/package.json +66 -5
  90. package/schema/SOURCE.json +4 -4
  91. package/schema/schema.graphqls +36 -0
@@ -1 +1 @@
1
- {"version":3,"file":"unfazed.js","sourceRoot":"","sources":["../src/unfazed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA2C,MAAM,aAAa,CAAC;AACrF,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,wBAAwB,EACxB,kBAAkB,IAAI,UAAU,EAChC,oBAAoB,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AAWvC,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAoB,MAAM,WAAW,CAAC;AA6PlF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,OAAO;IAClB,6EAA6E;IACpE,MAAM,CAAgB;IAE/B,YAAY,UAA0B,EAAE;QACtC,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC;QAC7C,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,aAAa,CAAC,aAAa,CAAC,CAAC;IAC3D,CAAC;IAED,+EAA+E;IAE/E,uEAAuE;IACvE,KAAK,CAAC,MAAM,CAAC,OAAwB;QACnC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,cAAc,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;QACtE,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,+EAA+E;IAE/E,iFAAiF;IACjF,KAAK,CAAC,eAAe,CAAC,IAAY,EAAE,OAAwB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AM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,0EAA0E;QAC1E,qCAAqC;QACrC,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5D,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,SAAS,IAAI,KAAK,GAAG,IAAI,GAAG,aAAa,CAAC,EAAE,CAAC;YACxF,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACtB,OAAO,GAAG,EAAE,CAAC;YACb,KAAK,GAAG,CAAC,CAAC;QACZ,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnB,KAAK,IAAI,IAAI,CAAC;IAChB,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC9C,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { UnfazedClient, type ClientOptions, type RequestOptions } from \"./client.js\";\nimport {\n DEPLOYMENT_NOT_FOUND,\n UnfazedConflictError,\n UnfazedDeployError,\n UnfazedGraphQLError,\n UnfazedNotFoundError,\n UnfazedRunError,\n WORKSPACE_NOT_FOUND,\n isDuplicateWorkspaceName,\n isNotFoundSentinel as isNotFound,\n looksLikeCASConflict,\n} from \"./errors.js\";\nimport * as ops from \"./operations.js\";\nimport type {\n CreateDeploymentInput,\n DeploymentFieldsFragment,\n ListDeploymentsInput,\n RunFieldsFragment,\n RunStatus,\n ServiceMode,\n ServiceRuntime,\n SdkCreateWorkspaceMutation,\n} from \"./generated/graphql.js\";\nimport { pollWithBackoff, resolveWaitOptions, type WaitOptions } from \"./wait.js\";\n\n/** A deployment as the workflow layer returns it. */\nexport type Deployment = DeploymentFieldsFragment;\n\n/** An agent run as the workflow layer returns it. */\nexport type Run = RunFieldsFragment;\n\n/**\n * A workspace as {@link Unfazed.createWorkspace} and\n * {@link Unfazed.ensureWorkspace} return it.\n *\n * Derived from the generated mutation type rather than hand-written, so the\n * two documents selecting these fields cannot drift apart without a compile\n * error — which is exactly what makes `ensureWorkspace` able to return either\n * a listed or a freshly created workspace under one type.\n */\nexport type Workspace = SdkCreateWorkspaceMutation[\"createWorkspace\"][\"workspace\"];\n\n/** Options for {@link Unfazed.deleteWorkspace}. */\nexport type DeleteWorkspaceOptions = {\n /**\n * Also delete every deployment snapshotted from the workspace, stopping\n * their service VMs. **Defaults to `true`** — see the method docs for why.\n */\n withDeployments?: boolean;\n /** Resolve `false` instead of throwing when the workspace is not visible. */\n ignoreNotFound?: boolean;\n} & RequestOptions;\n\n/** Options for {@link Unfazed.deleteDeployment}. */\nexport type DeleteDeploymentOptions = {\n /** Resolve `false` instead of throwing when the deployment is not visible. */\n ignoreNotFound?: boolean;\n} & RequestOptions;\n\n/** A file record returned by any write/list operation. */\nexport interface WorkspaceFile {\n path: string;\n sizeBytes: number;\n size: string;\n sha256: string;\n updatedAt: string;\n}\n\n/** One env var in a workspace- or app-scoped view. Secret values are never returned. */\nexport interface EnvVar {\n name: string;\n value: string | null;\n secret: boolean;\n alias: string | null;\n inherited: boolean;\n masked: boolean;\n updatedAt: string;\n}\n\n/**\n * A file's contents for {@link Unfazed.writeFiles}.\n *\n * A bare string is text — the overwhelmingly common case, and what makes\n * `{ \"server.ts\": code }` read well. Binary goes through `bytes` or `base64`,\n * which route to `writeWorkspaceBase64File` instead.\n */\nexport type FileContent =\n | string\n | { text: string }\n | { base64: string }\n | { bytes: Uint8Array | ArrayBuffer };\n\n/** Files keyed by workspace-relative path. */\nexport type FilesMap = Record<string, FileContent>;\n\nexport interface WriteFilesOptions {\n /**\n * Max files per GraphQL request. Default 20.\n *\n * The batch is one document with N aliased root fields; too many at once\n * makes a single oversized request whose failure is all-or-nothing to\n * diagnose. Twenty keeps a typical app to one or two round trips.\n */\n batchSize?: number;\n /**\n * Max total payload bytes per request. Default 4 MiB. Whichever limit trips\n * first closes the batch, so one large file cannot blow the request up.\n */\n maxBatchBytes?: number;\n signal?: AbortSignal;\n}\n\n/** Common options for the deploy helpers. */\nexport interface DeployOptions {\n workspaceId: string;\n alias?: string;\n /**\n * Block until the deployment reaches a terminal status.\n *\n * `createDeployment` returns BUILDING immediately; the build, VM boot and\n * health probe run in the background. With `wait: true` the call resolves\n * only on READY and throws {@link UnfazedDeployError} on FAILED — which is\n * what makes a one-script deploy possible.\n */\n wait?: boolean;\n /** Backoff/timeout knobs used when `wait` is true. */\n waitOptions?: WaitOptions;\n signal?: AbortSignal;\n}\n\nexport interface DeployServiceOptions extends DeployOptions {\n /** Omit to auto-detect: a root go.mod+main.go is GO, otherwise BUN. */\n runtime?: ServiceRuntime;\n /** Omit for ON_DEMAND. Only set ALWAYS_ON to keep the VM warm. */\n serviceMode?: ServiceMode;\n healthPath?: string;\n /** Standard 5-field cron spec. Prefer ON_DEMAND + cron over ALWAYS_ON. */\n cronSchedule?: string;\n /** Path the cron tick POSTs to. Defaults to /cron when cronSchedule is set. */\n cronPath?: string;\n}\n\nexport interface DeployStaticOptions extends DeployOptions {\n /** Serve index.html for missing paths (single-page apps). */\n spaMode?: boolean;\n}\n\nexport interface DeployBoxOptions extends DeployOptions {\n /** VM size. Omit for platform defaults (2048 MiB / 2 vCPU / 8 GiB disk). */\n resources?: { memMiB?: number; vcpus?: number; diskGiB?: number };\n}\n\nexport interface RollbackOptions {\n /** The alias to roll back. */\n alias: string;\n /**\n * Release to restore. Omit to pick the most recent READY release that is not\n * the current holder — i.e. \"undo the last deploy\".\n */\n to?: string;\n /**\n * Re-list-and-retry attempts when the compare-and-swap guard is rejected.\n * Default 1. Each retry refreshes the guard from a fresh read; the TARGET\n * release stays pinned, so a retry can never silently roll back to something\n * other than what was chosen.\n *\n * Ignored when {@link expectedCurrentId} is set — see there.\n */\n retries?: number;\n /**\n * The release you believe currently holds the alias. When set, the rollback\n * proceeds only if that is still true.\n *\n * This turns the rollback from \"undo whatever is live now\" into a checked\n * operation: if the live holder is anything else, you get\n * {@link UnfazedConflictError} BEFORE any mutation is sent, so a rollback\n * script can never act on a world that moved since you inspected it.\n *\n * It also disables the CAS retry, necessarily: a rejected guard means the\n * alias moved, and the alias having moved is precisely the precondition you\n * asked to be enforced. Retrying would refresh the guard to the new holder\n * and roll back the very deploy the precondition existed to protect.\n */\n expectedCurrentId?: string;\n signal?: AbortSignal;\n}\n\n/** Options for {@link Unfazed.createRun}. */\nexport interface CreateRunOptions {\n workspaceId: string;\n /** Delivered to the guest as `/work/prompt.md` and `$UNFZ_RUN_PROMPT` (max 64 KiB). */\n prompt?: string;\n /** A named preset from the image's `/etc/unfazed/harnesses.json`. Mutually exclusive in effect with `command` — set one. */\n harness?: string;\n /** Runs anything else with `sh -c`, instead of a named `harness`. */\n command?: string;\n /** Up to 20 single-line shell commands run in `/work` before the harness; the first failure fails the run. */\n setup?: string[];\n /** Up to 10 `owner/repo:path` GitHub references, cloned into `/work/.claude/skills/<name>` first. */\n skills?: string[];\n /**\n * Up to 20 shell commands run in `/work` AFTER the harness exited 0 —\n * tests, a build, `test -f out.txt`. The first failure FAILS the run\n * (`error` \"verification failed\", `verifyExitCode`). Without `verify`,\n * SUCCEEDED only means the harness exited cleanly: an agent that answered\n * \"I could not do this\" still succeeds — read `run.result.text` in that\n * case. Skipped in plan mode.\n */\n verify?: string[];\n /** VM memory. Omit for the platform default. */\n memoryMiB?: number;\n /** Wall-clock cap in seconds. Omit for the platform default; capped at 3600. */\n maxSeconds?: number;\n /** Up to 20 immutable labels for your own correlation (a ticket id, a PR). Echoed back on every read. */\n metadata?: unknown;\n /** Copy the workspace's files into `/work`. Default true. */\n includeFiles?: boolean;\n /**\n * `\"human\"` routes the harness's guarded actions (permission prompts) to\n * the run's owner: the run shows BLOCKED with the question until it is\n * answered ({@link Unfazed.answerRun}, the dashboard). Omit for the\n * harness's own defaults.\n */\n approval?: \"human\";\n /**\n * `\"plan\"` asks the harness to research and write a plan WITHOUT acting\n * (Claude Code runs in `--permission-mode plan`); the plan is the run's\n * transcript. Approve it with {@link Unfazed.followUpRun}. Omit to do the task.\n */\n mode?: \"plan\";\n /** The run this one continues. Usually set for you by {@link Unfazed.followUpRun}. */\n parentRunId?: string;\n /**\n * Block until the run reaches a terminal status.\n *\n * `createRun` itself already returns RUNNING or — on a boot failure —\n * FAILED with `error` set; `wait: true` additionally polls a RUNNING run\n * through to SUCCEEDED/FAILED/CANCELLED. Either way this resolves with the\n * run, never throws for FAILED: see {@link Unfazed.waitForRun}.\n */\n wait?: boolean;\n /** Backoff/timeout knobs used when `wait` is true. */\n waitOptions?: WaitOptions;\n signal?: AbortSignal;\n}\n\n/** Options for {@link Unfazed.followUpRun}. */\nexport interface FollowUpRunOptions {\n /** What to do next. For a plan run: the go-ahead (and any changes to the plan). */\n prompt: string;\n /** `\"plan\"` to plan again instead of executing; omit to execute. */\n mode?: \"plan\";\n /** Override the parent's approval; omit to inherit it. */\n approval?: \"human\" | \"\";\n /** Override the parent's wall clock (seconds). */\n maxSeconds?: number;\n metadata?: unknown;\n /** As for {@link CreateRunOptions.wait}. */\n wait?: boolean;\n waitOptions?: WaitOptions;\n signal?: AbortSignal;\n}\n\n/** Filter/paging for {@link Unfazed.listRuns}. */\nexport interface ListRunsFilter {\n workspaceId?: string;\n status?: RunStatus;\n limit?: number;\n offset?: number;\n}\n\nexport interface UnfazedOptions extends ClientOptions {\n /** Use an existing core client instead of constructing one. */\n client?: UnfazedClient;\n}\n\n/**\n * Layer 2 — the agent workflow layer.\n *\n * Wraps the chains an agent actually performs (create → write → deploy → wait\n * → read logs → roll back) so a code-mode script does in one call what would\n * otherwise be many round trips through a model's context. Everything here is\n * built on {@link UnfazedClient}, exposed as `.client` for anything not\n * wrapped.\n *\n * ```ts\n * const unfazed = new Unfazed(); // reads UNFZ_API_TOKEN\n * const ws = await unfazed.createWorkspace(\"hello\");\n * await unfazed.writeFiles(ws.id, { \"server.ts\": code });\n * const app = await unfazed.deployService({ workspaceId: ws.id, alias: \"hello\", wait: true });\n * console.log(app.url);\n * ```\n */\nexport class Unfazed {\n /** The underlying typed GraphQL client. Use it for un-wrapped operations. */\n readonly client: UnfazedClient;\n\n constructor(options: UnfazedOptions = {}) {\n const { client, ...clientOptions } = options;\n this.client = client ?? new UnfazedClient(clientOptions);\n }\n\n /* ---------------------------------------------------------------- identity */\n\n /** Who this token authenticates as, plus usage and resource limits. */\n async whoami(options?: RequestOptions) {\n const data = await this.client.query(ops.WhoamiDocument, {}, options);\n return data.whoami;\n }\n\n /* -------------------------------------------------------------- workspaces */\n\n /** Creates a source workspace — the container for files, env and deployments. */\n async createWorkspace(name: string, options?: RequestOptions) {\n const data = await this.client.mutate(ops.CreateWorkspaceDocument, { name }, options);\n return data.createWorkspace.workspace;\n }\n\n /** Workspaces visible to this token. */\n async listWorkspaces(options?: RequestOptions) {\n const data = await this.client.query(ops.ListWorkspacesDocument, {}, options);\n return data.workspaces;\n }\n\n /**\n * Deletes a workspace and everything anchored to it — deployments, env, and\n * a BOX's persistent data disk. Not recoverable.\n *\n * **The cascade is opt-out, not opt-in.** The server refuses to delete a\n * workspace that has ANY deployment history — including FAILED records, and\n * including deployments whose alias was long since taken over by something\n * else — unless the mutation carries `withDeployments`. Since almost every\n * workspace an agent creates gets deployed at least once, defaulting to\n * `false` would make this method fail on nearly every real workspace, so it\n * defaults to **`true`**: the behaviour this docstring has always promised.\n *\n * Pass `withDeployments: false` for the strict variant, which refuses rather\n * than cascading and is the safer choice when you are deleting a workspace\n * you did not create:\n *\n * ```ts\n * await unfazed.deleteWorkspace(ws.id); // cascade\n * await unfazed.deleteWorkspace(ws.id, { withDeployments: false }); // refuse if deployed\n * await unfazed.deleteWorkspace(id, { ignoreNotFound: true }); // false, not a throw\n * ```\n *\n * With `ignoreNotFound` a workspace that is absent (or belongs to someone\n * else — the server returns one indistinguishable sentinel for both, on\n * purpose) resolves to `false` instead of throwing, which makes teardown in\n * a `finally` block idempotent.\n */\n async deleteWorkspace(\n workspaceId: string,\n options: DeleteWorkspaceOptions = {},\n ): Promise<boolean> {\n const withDeployments = options.withDeployments ?? true;\n try {\n const data = await this.client.mutate(\n ops.DeleteWorkspaceDocument,\n { workspaceID: workspaceId, withDeployments },\n options,\n );\n return data.deleteWorkspace.ok;\n } catch (e) {\n if (options.ignoreNotFound && isNotFound(e, WORKSPACE_NOT_FOUND)) return false;\n throw e;\n }\n }\n\n /**\n * Returns the workspace named `name`, creating it only if it does not exist.\n *\n * Workspace names are unique per owner, case-insensitively — a second\n * `createWorkspace(\"Hello\")` after a `createWorkspace(\"hello\")` is an error,\n * not a second workspace. That makes the bare create a poor fit for any\n * script that might run twice; this is the re-runnable form.\n *\n * ```ts\n * const ws = await unfazed.ensureWorkspace(\"greeter\"); // safe to re-run\n * ```\n *\n * Costs one list, plus one create only on a miss. The create is still\n * guarded: if a concurrent caller wins the race, the duplicate-name error is\n * caught and the now-existing workspace is returned instead of thrown.\n */\n async ensureWorkspace(name: string, options?: RequestOptions) {\n const existing = await this.#findWorkspaceByName(name, options);\n if (existing) return existing;\n\n try {\n return await this.createWorkspace(name, options);\n } catch (e) {\n // Lost a create/create race, or the server's case folding is stricter\n // than ours. Either way the workspace exists now — re-read rather than\n // failing a script whose intent was \"make sure this exists\".\n if (!isDuplicateWorkspaceName(e)) throw e;\n const raced = await this.#findWorkspaceByName(name, options);\n if (raced) return raced;\n // The name is taken by something we cannot see. Surface the real error.\n throw e;\n }\n }\n\n /* ------------------------------------------------------------------- files */\n\n /**\n * Writes many files in as few requests as possible.\n *\n * The API is one-file-per-mutation, so writing a 12-file app naively costs 12\n * round trips. This batches them into a single GraphQL document with one\n * ALIASED root field per file (`f0: writeWorkspaceTextFile(...)`,\n * `f1: ...`), which the server resolves in one request.\n *\n * ```ts\n * await unfazed.writeFiles(ws.id, {\n * \"server.ts\": serverCode,\n * \"unfazed.json\": JSON.stringify({ entry: \"server.ts\" }),\n * \"public/logo.png\": { bytes: pngBytes },\n * });\n * ```\n *\n * Batches are NOT atomic: GraphQL resolves each aliased field independently,\n * so a partial failure leaves earlier writes committed. The thrown\n * {@link UnfazedGraphQLError} carries `data` with whichever aliases\n * succeeded, and `error.path` identifies the ones that did not.\n */\n async writeFiles(\n workspaceId: string,\n files: FilesMap,\n options: WriteFilesOptions = {},\n ): Promise<WorkspaceFile[]> {\n const entries = Object.entries(files).map(([path, content]) => normalizeFile(path, content));\n if (entries.length === 0) return [];\n\n const batchSize = options.batchSize ?? 20;\n const maxBatchBytes = options.maxBatchBytes ?? 4 * 1024 * 1024;\n\n const written: WorkspaceFile[] = [];\n for (const batch of chunkFiles(entries, batchSize, maxBatchBytes)) {\n written.push(...(await this.#writeBatch(workspaceId, batch, options.signal)));\n }\n return written;\n }\n\n /** Writes one text file. Prefer {@link writeFiles} for more than one. */\n async writeFile(\n workspaceId: string,\n path: string,\n text: string,\n options?: RequestOptions,\n ): Promise<WorkspaceFile> {\n const data = await this.client.mutate(\n ops.WriteTextFileDocument,\n { workspaceID: workspaceId, path, text },\n options,\n );\n return data.writeWorkspaceTextFile.file;\n }\n\n /** Writes one binary file. Accepts raw bytes or a base64 string. */\n async writeBinaryFile(\n workspaceId: string,\n path: string,\n content: Uint8Array | ArrayBuffer | { base64: string },\n options?: RequestOptions,\n ): Promise<WorkspaceFile> {\n const contentBase64 = \"base64\" in content ? content.base64 : toBase64(content);\n const data = await this.client.mutate(\n ops.WriteBase64FileDocument,\n { workspaceID: workspaceId, path, contentBase64 },\n options,\n );\n return data.writeWorkspaceBase64File.file;\n }\n\n /** Lists workspace files (paginated). */\n async listFiles(\n workspaceId: string,\n input: { limit?: number; offset?: number; order?: string } = {},\n options?: RequestOptions,\n ) {\n const data = await this.client.query(\n ops.ListFilesDocument,\n { input: { workspaceID: workspaceId, ...input } },\n options,\n );\n return data.workspaceFilesPage;\n }\n\n /** Reads a text file, optionally a byte range of it. Null when absent. */\n async readFile(\n workspaceId: string,\n path: string,\n input: { offset?: number; limit?: number } = {},\n options?: RequestOptions,\n ) {\n const data = await this.client.query(\n ops.ReadFileDocument,\n { input: { workspaceID: workspaceId, path, ...input } },\n options,\n );\n return data.readWorkspaceFile;\n }\n\n /**\n * Deletes a workspace file.\n *\n * Returns `false` when there was nothing to delete — an absent path is not\n * an error. See the `ok: false` convention on {@link deleteEnv}.\n */\n async deleteFile(\n workspaceId: string,\n path: string,\n options?: RequestOptions,\n ): Promise<boolean> {\n const data = await this.client.mutate(\n ops.DeleteFileDocument,\n { workspaceID: workspaceId, path },\n options,\n );\n return data.deleteWorkspaceFile.ok;\n }\n\n /* ----------------------------------------------------------------- deploys\n *\n * Every deploy method here MINTS A NEW RELEASE on every call. There is no\n * content dedupe: deploying byte-identical files twice produces two distinct\n * releases with two ids, both real, both counting against retention (which\n * keeps only the most recent few per alias and prunes the rest). Deploying\n * in a retry loop is therefore not free — it churns the release history and\n * can push a release you still wanted to roll back to out of retention.\n * Check {@link getDeployment} or {@link listReleases} before redeploying if\n * you only meant to converge.\n */\n\n /**\n * Deploys the workspace as a SERVICE (an HTTP server).\n *\n * With `wait: true` this resolves only once the build, VM boot and health\n * probe have all passed.\n *\n * Passing the same `alias` again redeploys that alias — a new release that\n * takes over the alias when it goes READY. Omitting `alias` lets the server\n * generate one, which means a different app on every call.\n */\n deployService(options: DeployServiceOptions): Promise<Deployment> {\n const { workspaceId, alias, runtime, serviceMode, healthPath, cronSchedule, cronPath } =\n options;\n return this.#deploy(\n {\n workspaceID: workspaceId,\n kind: \"SERVICE\",\n ...(alias === undefined ? {} : { alias }),\n ...(runtime === undefined ? {} : { runtime }),\n ...(serviceMode === undefined ? {} : { serviceMode }),\n ...(healthPath === undefined ? {} : { healthPath }),\n ...(cronSchedule === undefined ? {} : { cronSchedule }),\n ...(cronPath === undefined ? {} : { cronPath }),\n },\n options,\n );\n }\n\n /** Deploys the workspace as a STATIC site. */\n deployStatic(options: DeployStaticOptions): Promise<Deployment> {\n const { workspaceId, alias, spaMode } = options;\n return this.#deploy(\n {\n workspaceID: workspaceId,\n kind: \"STATIC\",\n ...(alias === undefined ? {} : { alias }),\n ...(spaMode === undefined ? {} : { spaMode }),\n },\n options,\n );\n }\n\n /**\n * Deploys a BOX: a persistent always-on Linux VM with a data disk that\n * survives stops and redeploys. A dev machine, not an HTTP service. The\n * result's `sshCommand` is how you get in.\n *\n * ⚠️ **Omitting `alias` creates a NEW BOX every single call.** There is no\n * \"the workspace's box\" to update: with no alias the server generates a\n * fresh random one, so a script run twice leaves you with two box records,\n * not one redeployed box.\n *\n * The data disk, meanwhile, is keyed by WORKSPACE — one disk, shared by\n * every box in the workspace, and it is the box's real identity. Since only\n * one VM can hold that disk read-write, the second box cannot even start\n * while the first is running (`box data disk for workspace ... is attached\n * to VM ...; stop it first`). The result is a pile of dead box records\n * fighting over one disk.\n *\n * **Always pass an explicit `alias` in anything re-runnable.** Redeploying\n * the same alias is the in-place update you actually want.\n *\n * ```ts\n * await unfazed.deployBox({ workspaceId: ws.id, alias: \"dev\" }); // re-runnable\n * ```\n */\n deployBox(options: DeployBoxOptions): Promise<Deployment> {\n const { workspaceId, alias, resources } = options;\n return this.#deploy(\n {\n workspaceID: workspaceId,\n kind: \"BOX\",\n ...(alias === undefined ? {} : { alias }),\n ...(resources === undefined ? {} : { boxResources: resources }),\n },\n options,\n );\n }\n\n /** Escape hatch: deploy with a raw CreateDeploymentInput. */\n deploy(\n input: CreateDeploymentInput,\n options: Omit<DeployOptions, \"workspaceId\"> = {},\n ): Promise<Deployment> {\n return this.#deploy(input, options);\n }\n\n async #deploy(\n input: CreateDeploymentInput,\n options: Omit<DeployOptions, \"workspaceId\">,\n ): Promise<Deployment> {\n const requestOptions: RequestOptions = options.signal ? { signal: options.signal } : {};\n const data = await this.client.mutate(ops.CreateDeploymentDocument, { input }, requestOptions);\n const deployment = data.createDeployment.deployment;\n if (!options.wait) return deployment;\n return this.waitForDeployment(deployment.id, {\n ...options.waitOptions,\n ...(options.signal ? { signal: options.signal } : {}),\n });\n }\n\n /**\n * Polls a deployment until it is READY, throwing on FAILED or timeout.\n *\n * BUILDING is the only non-terminal status; READY and FAILED are terminal.\n * The poll query selects six fields rather than the full deployment, because\n * this runs every few seconds for potentially minutes — then the READY\n * deployment is re-read in full so callers get the same shape `deployService`\n * returns without `wait`.\n */\n async waitForDeployment(deploymentId: string, waitOptions: WaitOptions = {}): Promise<Deployment> {\n const resolved = resolveWaitOptions(waitOptions);\n const requestOptions: RequestOptions = resolved.signal ? { signal: resolved.signal } : {};\n let last: { id: string; status: string; error: string | null } | null = null;\n\n await pollWithBackoff<true>(\n async () => {\n const data = await this.client.query(\n ops.PollDeploymentDocument,\n { id: deploymentId },\n requestOptions,\n );\n const d = data.deployment;\n if (!d) {\n throw new UnfazedNotFoundError(`unfazed: deployment ${deploymentId} not found`);\n }\n last = d;\n if (d.status === \"READY\") return { done: true, value: true };\n if (d.status === \"FAILED\") {\n throw new UnfazedDeployError(\n \"FAILED\",\n deploymentId,\n d,\n `unfazed: deployment ${deploymentId} FAILED${d.error ? `: ${d.error}` : \"\"}`,\n );\n }\n return { done: false };\n },\n resolved,\n () =>\n new UnfazedDeployError(\n \"TIMEOUT\",\n deploymentId,\n last,\n `unfazed: deployment ${deploymentId} still ${\n (last as { status?: string } | null)?.status ?? \"BUILDING\"\n } after ${resolved.timeoutMs}ms`,\n ),\n );\n\n const full = await this.getDeployment(deploymentId, requestOptions);\n if (!full) throw new UnfazedNotFoundError(`unfazed: deployment ${deploymentId} not found`);\n return full;\n }\n\n /** Reads one deployment by id. Null when absent. */\n async getDeployment(\n deploymentId: string,\n options?: RequestOptions,\n ): Promise<Deployment | null> {\n const data = await this.client.query(ops.GetDeploymentDocument, { id: deploymentId }, options);\n return data.deployment;\n }\n\n /** Reads the deployment currently serving an alias. Null when absent. */\n async getDeploymentByAlias(\n alias: string,\n options?: RequestOptions,\n ): Promise<Deployment | null> {\n const data = await this.client.query(ops.GetDeploymentByAliasDocument, { alias }, options);\n return data.deploymentByAlias;\n }\n\n /** Lists deployments (paginated, filterable by kind/alias/workspace). */\n async listDeployments(input: ListDeploymentsInput = {}, options?: RequestOptions) {\n const data = await this.client.query(ops.ListDeploymentsDocument, { input }, options);\n return data.deploymentsPage;\n }\n\n /* ------------------------------------------------------- runtime & logging */\n\n /** Live VM status: health, in-flight requests, restarts, RAM ceiling. */\n async getStatus(deploymentId: string, options?: RequestOptions) {\n const data = await this.client.query(\n ops.ServiceStatusDocument,\n { deploymentID: deploymentId },\n options,\n );\n return data.serviceStatus;\n }\n\n /**\n * Tail of the service's stdout/stderr.\n *\n * The point of doing this from a script rather than through tool calls: you\n * can filter locally. `(await unfazed.getLogs(id)).stderr.split(\"\\n\")\n * .filter(l => l.includes(\"ERROR\"))` costs a model zero context, where the\n * same tail through an MCP tool spends all of it.\n */\n async getLogs(\n deploymentId: string,\n input: { tailBytes?: number } = {},\n options?: RequestOptions,\n ) {\n const data = await this.client.query(\n ops.ServiceLogsDocument,\n { deploymentID: deploymentId, tailBytes: input.tailBytes ?? null },\n options,\n );\n return data.serviceLogs;\n }\n\n /** Deployment lifecycle events — build, boot, probe, cron, restarts. */\n async getEvents(deploymentId: string, limit?: number, options?: RequestOptions) {\n const data = await this.client.query(\n ops.DeploymentEventsDocument,\n { deploymentID: deploymentId, limit: limit ?? null },\n options,\n );\n return data.deploymentEvents;\n }\n\n /** Restarts a service's VM. */\n async restartService(deploymentId: string, options?: RequestOptions) {\n const data = await this.client.mutate(\n ops.RestartServiceDocument,\n { deploymentID: deploymentId },\n options,\n );\n return data.restartService;\n }\n\n /** Stops a service's VM. An on-demand service cold-starts again on request. */\n async stopService(deploymentId: string, options?: RequestOptions) {\n const data = await this.client.mutate(\n ops.StopServiceDocument,\n { deploymentID: deploymentId },\n options,\n );\n return data.stopService;\n }\n\n /**\n * Deletes a deployment: stops its VM, releases its alias, drops its release.\n *\n * With `ignoreNotFound` a deployment that is absent — or belongs to another\n * tenant, which the server reports identically so ids cannot be probed —\n * resolves to `false` instead of throwing, making cleanup loops idempotent.\n */\n async deleteDeployment(\n deploymentId: string,\n options: DeleteDeploymentOptions = {},\n ): Promise<boolean> {\n try {\n const data = await this.client.mutate(\n ops.DeleteDeploymentDocument,\n { deploymentID: deploymentId },\n options,\n );\n return data.deleteDeployment.ok;\n } catch (e) {\n if (options.ignoreNotFound && isNotFound(e, DEPLOYMENT_NOT_FOUND)) return false;\n throw e;\n }\n }\n\n /* ------------------------------------------------------------ env & secrets\n *\n * Workspace values are SERVICE defaults for every app in the source; app\n * values override them for one alias. Both are SNAPSHOTTED into a release at\n * deploy time — changing either does not affect a running app until you\n * redeploy that alias. Old releases are immutable, and STATIC gets no env.\n */\n\n /**\n * Sets a workspace-default env var. Redeploy the alias to apply it.\n *\n * A name is either plain or secret, never both: this DELETES a workspace\n * secret of the same name. {@link setSecret} displaces a plain var the same\n * way. Last write wins, and the kind flips silently — so re-running a setup\n * script that calls `setSecret(\"API_KEY\", ...)` after one that called\n * `setEnv(\"API_KEY\", ...)` quietly converts it, and vice versa.\n */\n async setEnv(\n workspaceId: string,\n name: string,\n value: string,\n options?: RequestOptions,\n ): Promise<EnvVar> {\n const data = await this.client.mutate(\n ops.SetWorkspaceEnvDocument,\n { workspaceID: workspaceId, name, value },\n options,\n );\n return data.setWorkspaceEnv.env;\n }\n\n /**\n * Sets a workspace-default secret. The value is never readable again.\n *\n * Mutually exclusive with {@link setEnv}: this DELETES a plain workspace var\n * of the same name. See {@link setEnv} for the displacement rule.\n */\n async setSecret(\n workspaceId: string,\n name: string,\n value: string,\n options?: RequestOptions,\n ): Promise<EnvVar> {\n const data = await this.client.mutate(\n ops.SetWorkspaceSecretDocument,\n { workspaceID: workspaceId, name, value },\n options,\n );\n return data.setWorkspaceSecret.env;\n }\n\n /**\n * Sets many workspace env vars in one request, via aliased mutations —\n * the same batching trick as {@link writeFiles}.\n *\n * Pass `{ secret: true }` to route them all to `setWorkspaceSecret`.\n *\n * It inherits {@link writeFiles}' failure semantics too: the batch is NOT\n * atomic. GraphQL resolves each aliased field independently, so a rejected\n * name (over the limit, malformed, whatever) leaves the vars before it\n * already committed. The thrown {@link UnfazedGraphQLError} carries `data`\n * with the aliases that succeeded and `errors[].path` naming those that did\n * not — do not assume \"it threw\" means \"nothing was written\".\n *\n * Each name still displaces its opposite kind, exactly as {@link setEnv} and\n * {@link setSecret} do one at a time.\n */\n async setEnvMany(\n workspaceId: string,\n vars: Record<string, string>,\n options: { secret?: boolean; signal?: AbortSignal } = {},\n ): Promise<EnvVar[]> {\n const entries = Object.entries(vars);\n if (entries.length === 0) return [];\n\n const field = options.secret ? \"setWorkspaceSecret\" : \"setWorkspaceEnv\";\n const varDefs = [\"$workspaceID: ID!\"];\n const fields: string[] = [];\n const variables: Record<string, string> = { workspaceID: workspaceId };\n\n entries.forEach(([name, value], i) => {\n varDefs.push(`$n${i}: String!`, `$v${i}: String!`);\n variables[`n${i}`] = name;\n variables[`v${i}`] = value;\n fields.push(\n ` e${i}: ${field}(input: { workspaceID: $workspaceID, name: $n${i}, value: $v${i} }) { env { ${ENV_SELECTION} } }`,\n );\n });\n\n const document = `mutation SdkSetEnvBatch(${varDefs.join(\", \")}) {\\n${fields.join(\"\\n\")}\\n}`;\n const data = await this.client.mutate<Record<string, { env: EnvVar }>, typeof variables>(\n document,\n variables,\n options.signal ? { signal: options.signal } : {},\n );\n return entries.map((_, i) => data[`e${i}`]!.env);\n }\n\n /**\n * Deletes a workspace-default env var (plain or secret).\n *\n * **The `ok: false` convention.** A `false` here does NOT mean failure — it\n * means \"nothing to do, the world is already in the state you asked for\".\n * The var did not exist. Every `ok`-returning mutation in this SDK follows\n * the rule ({@link deleteFile}, {@link inheritAppEnv}, {@link removeAppEnv}),\n * so the idempotent-cleanup pattern is simply to ignore the boolean; a real\n * failure throws.\n */\n async deleteEnv(workspaceId: string, name: string, options?: RequestOptions): Promise<boolean> {\n const data = await this.client.mutate(\n ops.DeleteWorkspaceEnvDocument,\n { workspaceID: workspaceId, name },\n options,\n );\n return data.deleteWorkspaceEnv.ok;\n }\n\n /** Workspace-default env vars. Secret values are redacted. */\n async listEnv(workspaceId: string, options?: RequestOptions): Promise<EnvVar[]> {\n const data = await this.client.query(\n ops.ListWorkspaceEnvDocument,\n { workspaceID: workspaceId },\n options,\n );\n return data.workspaceEnv;\n }\n\n /**\n * Sets an env var for ONE alias, overriding the workspace default.\n *\n * Displaces both of the other states this name could be in for the app: it\n * deletes an app SECRET of the same name, and it CLEARS a REMOVE mask left\n * by {@link removeAppEnv}. So setting a value is also the way to un-block a\n * masked name, and a name is only ever one of plain / secret / masked.\n */\n async setAppEnv(\n workspaceId: string,\n alias: string,\n name: string,\n value: string,\n options?: RequestOptions,\n ): Promise<EnvVar> {\n const data = await this.client.mutate(\n ops.SetAppEnvDocument,\n { workspaceID: workspaceId, alias, name, value },\n options,\n );\n return data.setAppEnv.env;\n }\n\n /**\n * Sets a secret for ONE alias, overriding the workspace default.\n *\n * Like {@link setAppEnv}, this deletes a plain app var of the same name and\n * clears a REMOVE mask for it.\n */\n async setAppSecret(\n workspaceId: string,\n alias: string,\n name: string,\n value: string,\n options?: RequestOptions,\n ): Promise<EnvVar> {\n const data = await this.client.mutate(\n ops.SetAppSecretDocument,\n { workspaceID: workspaceId, alias, name, value },\n options,\n );\n return data.setAppSecret.env;\n }\n\n /**\n * REMOVE: blocks this name for the app entirely — the app override, the\n * workspace default, and integration enrichment. Not the same as deleting an\n * override; use {@link inheritAppEnv} for that.\n *\n * This WRITES A MASK, and the mask is a real, persistent row. Two things\n * follow that surprise people:\n *\n * - It is written even when nothing was inherited. Masking a name that no\n * workspace default and no integration ever provided is not a no-op; it\n * leaves a tombstone that keeps blocking the name if a default appears\n * later. Clear it with {@link inheritAppEnv}.\n * - It COSTS A SLOT. A workspace gets 128 env entries total — that budget\n * is shared across the workspace defaults AND every app scope combined,\n * not 128 per scope — and masks count toward it just like values do.\n * Masking names in a loop can exhaust the workspace's env budget.\n *\n * Returns `false` when the exact mask was already present (a second call for\n * the same name), per the {@link deleteEnv} `ok: false` convention. It\n * returns `true` when it had something to change — including converting an\n * existing override into a mask.\n */\n async removeAppEnv(\n workspaceId: string,\n alias: string,\n name: string,\n options?: RequestOptions,\n ): Promise<boolean> {\n const data = await this.client.mutate(\n ops.RemoveAppEnvDocument,\n { workspaceID: workspaceId, alias, name },\n options,\n );\n return data.removeAppEnv.ok;\n }\n\n /**\n * INHERIT: clears the app override/mask so workspace and integration values\n * apply again. This is the undo for both {@link setAppEnv} and\n * {@link removeAppEnv}.\n *\n * Returns `false` when there was no override and no mask to clear — nothing\n * to do, not a failure. See {@link deleteEnv}.\n */\n async inheritAppEnv(\n workspaceId: string,\n alias: string,\n name: string,\n options?: RequestOptions,\n ): Promise<boolean> {\n const data = await this.client.mutate(\n ops.InheritAppEnvDocument,\n { workspaceID: workspaceId, alias, name },\n options,\n );\n return data.inheritAppEnv.ok;\n }\n\n /** The effective env view for one alias: overrides, inherited and masked. */\n async listAppEnv(\n workspaceId: string,\n alias: string,\n options?: RequestOptions,\n ): Promise<EnvVar[]> {\n const data = await this.client.query(\n ops.ListAppEnvDocument,\n { workspaceID: workspaceId, alias },\n options,\n );\n return data.appEnv;\n }\n\n /* -------------------------------------------------- releases & rollback */\n\n /**\n * An alias's terminal release history, newest first.\n *\n * Exactly one entry has `aliasHeld: true` — the live release. FAILED entries\n * appear on purpose (they are rejected promotions, so a kept-live previous\n * release is never mistaken for a silent fallback) and cannot be rolled back\n * to. Retention keeps only the most recent few per alias, default 5.\n */\n async listReleases(alias: string, options?: RequestOptions): Promise<Deployment[]> {\n const data = await this.client.query(ops.ListReleasesDocument, { alias }, options);\n return data.deploymentReleases;\n }\n\n /**\n * Rolls an alias back to a prior release, handling the whole compare-and-swap\n * protocol in one call.\n *\n * The server requires the caller to prove it observed the current state: you\n * must pass the live release's id AND its opaque `aliasRevision`, and the\n * swap fails if either changed since you listed — including same-id ABA. So\n * this method does the full dance: list releases, find the `aliasHeld` entry,\n * pick the target, and submit both guard values.\n *\n * On a rejected guard it re-lists and retries (default once). The TARGET is\n * pinned across retries while the guard is refreshed, so a concurrent deploy\n * can never redirect the rollback to a different release than the one chosen.\n *\n * ```ts\n * await unfazed.rollback({ alias: \"my-app\" }); // undo last deploy\n * await unfazed.rollback({ alias: \"my-app\", to: relId }); // to a specific release\n * await unfazed.rollback({ alias: \"my-app\", to: relId, expectedCurrentId: liveId });\n * ```\n *\n * ⚠️ **A bare `rollback({ alias })` is a TOGGLE, not an idempotent step.**\n * It means \"restore the most recent READY release that is not the live one\",\n * which is a different release each time the alias moves. Run the same\n * script twice and the second run rolls back the rollback — A → B → A → B,\n * forever, with each hop a real alias swap. Nothing errors, because every\n * individual call did exactly what it was asked.\n *\n * In anything re-runnable — a retry loop, a CI job, an agent that might redo\n * a step — pin the outcome instead:\n *\n * - `to:` names the release you want live, so re-running is a no-op-ish\n * convergence rather than a flip (a second run then reports the target\n * already holds the alias instead of moving it);\n * - `expectedCurrentId:` states what you expect to be live now, so a second\n * run fails loudly instead of silently undoing the first.\n */\n async rollback(options: RollbackOptions): Promise<Deployment> {\n const { alias, signal, expectedCurrentId } = options;\n // A caller-supplied precondition and the CAS retry are mutually exclusive:\n // retrying re-guards against whatever holds the alias NOW, which is the\n // one thing `expectedCurrentId` exists to refuse.\n const retries = expectedCurrentId === undefined ? (options.retries ?? 1) : 0;\n const requestOptions: RequestOptions = signal ? { signal } : {};\n\n let targetId = options.to;\n\n for (let attempt = 0; ; attempt++) {\n const releases = await this.listReleases(alias, requestOptions);\n if (releases.length === 0) {\n throw new UnfazedNotFoundError(`unfazed: alias \"${alias}\" has no release history`);\n }\n\n const current = releases.find((r) => r.aliasHeld);\n if (!current) {\n throw new UnfazedNotFoundError(\n `unfazed: alias \"${alias}\" has no current release holding the alias`,\n );\n }\n\n // The caller's precondition, checked before anything is sent. Failing\n // here rather than at the server keeps a violated expectation from\n // costing an alias swap, and reports the holder we actually observed.\n if (expectedCurrentId !== undefined && current.id !== expectedCurrentId) {\n throw new UnfazedConflictError(\n `unfazed: alias \"${alias}\" is held by ${current.id}, not the expected ` +\n `${expectedCurrentId} — it moved since you read it; re-read and decide again`,\n [],\n );\n }\n\n // Pin the target on the first pass so a retry refreshes only the guard.\n if (targetId === undefined) {\n const previous = releases.find((r) => r.id !== current.id && r.status === \"READY\");\n if (!previous) {\n throw new UnfazedNotFoundError(\n `unfazed: alias \"${alias}\" has no prior READY release to roll back to ` +\n `(history: ${releases.map((r) => `${r.id}:${r.status}`).join(\", \")})`,\n );\n }\n targetId = previous.id;\n }\n\n const target = releases.find((r) => r.id === targetId);\n if (!target) {\n throw new UnfazedNotFoundError(\n `unfazed: release ${targetId} is not in alias \"${alias}\"'s history ` +\n `(it may have been pruned; retention keeps only the most recent few)`,\n );\n }\n if (target.id === current.id) {\n throw new UnfazedConflictError(\n `unfazed: release ${targetId} already holds alias \"${alias}\"`,\n [],\n );\n }\n if (target.status !== \"READY\") {\n throw new UnfazedConflictError(\n `unfazed: release ${targetId} is ${target.status}, only READY releases can be restored`,\n [],\n );\n }\n\n try {\n const data = await this.client.mutate(\n ops.RollbackDocument,\n {\n deploymentID: target.id,\n expectedCurrentDeploymentID: current.id,\n expectedCurrentAliasRevision: current.aliasRevision,\n },\n requestOptions,\n );\n return data.rollbackDeployment;\n } catch (e) {\n const retryable =\n e instanceof UnfazedGraphQLError && looksLikeCASConflict(e.errors) && attempt < retries;\n if (!retryable) {\n if (e instanceof UnfazedGraphQLError && looksLikeCASConflict(e.errors)) {\n throw new UnfazedConflictError(\n `unfazed: rollback of \"${alias}\" lost the compare-and-swap after ${\n attempt + 1\n } attempt(s) — the alias is being deployed concurrently. ${e.message}`,\n e.errors,\n );\n }\n throw e;\n }\n // Loop: re-list, rebuild the guard, keep the same target.\n }\n }\n }\n\n /* --------------------------------------------------------------- agent runs\n *\n * A run is the past-tense counterpart to a deployment: boot a fresh VM off\n * the box image, hand it a prompt, let a harness work for up to an hour,\n * keep the transcript, meter what it cost, reap the VM. Deployments answer\n * \"what is running\"; runs answer \"what happened\". Inside a run, `new\n * Unfazed()` is already authenticated — the platform injects\n * UNFZ_API_TOKEN / UNFZ_API_URL, at most the parent's scopes, revoked when\n * the run settles.\n */\n\n /**\n * Starts an agent run.\n *\n * Resolves once the VM has started (status RUNNING) — or, on a boot\n * failure, once the run has already settled FAILED with `error` set. A\n * boot failure is a normal return value here, not a thrown error, with or\n * without `wait`.\n *\n * ```ts\n * const run = await unfazed.createRun({\n * workspaceId: ws.id,\n * harness: \"claude-code\",\n * prompt: \"Fix the failing test in test/foo.test.ts and open a PR.\",\n * wait: true,\n * });\n * console.log(run.status, run.usage.mibSeconds);\n * ```\n *\n * With `wait: true` this additionally polls a RUNNING run through to a\n * terminal status — see {@link waitForRun} for exactly what \"terminal\"\n * means and how a timeout is reported.\n */\n async createRun(options: CreateRunOptions): Promise<Run> {\n const {\n workspaceId,\n prompt,\n harness,\n command,\n setup,\n skills,\n verify,\n memoryMiB,\n maxSeconds,\n metadata,\n includeFiles,\n approval,\n mode,\n parentRunId,\n wait,\n waitOptions,\n signal,\n } = options;\n const requestOptions: RequestOptions = signal ? { signal } : {};\n const data = await this.client.mutate(\n ops.CreateRunDocument,\n {\n input: {\n workspaceID: workspaceId,\n ...(prompt === undefined ? {} : { prompt }),\n ...(harness === undefined ? {} : { harness }),\n ...(command === undefined ? {} : { command }),\n ...(setup === undefined ? {} : { setup }),\n ...(skills === undefined ? {} : { skills }),\n ...(verify === undefined ? {} : { verify }),\n ...(memoryMiB === undefined ? {} : { memoryMiB }),\n ...(maxSeconds === undefined ? {} : { maxSeconds }),\n ...(metadata === undefined ? {} : { metadata }),\n ...(includeFiles === undefined ? {} : { includeFiles }),\n ...(approval === undefined ? {} : { approval }),\n ...(mode === undefined ? {} : { mode }),\n ...(parentRunId === undefined ? {} : { parentRunID: parentRunId }),\n },\n },\n requestOptions,\n );\n const run = data.createRun;\n // Unlike createDeployment (always BUILDING), createRun can come back\n // already terminal — a boot failure settles FAILED synchronously. Only\n // poll when there is actually something to wait for.\n if (!wait || isTerminalRunStatus(run.status)) return run;\n return this.waitForRun(run.id, {\n ...waitOptions,\n ...(signal ? { signal } : {}),\n });\n }\n\n /**\n * Polls a run until it leaves QUEUED/RUNNING, throwing only on timeout.\n *\n * Terminal is defined negatively — anything that is not QUEUED or RUNNING —\n * matching the platform's own status machine, so an unknown future status\n * still ends the wait instead of looping forever. **SUCCEEDED, FAILED and\n * CANCELLED are all returned normally**: a run that executed and exited\n * non-zero is a completed answer (read `run.error` / `run.exitCode`), not\n * an exception the way a FAILED deployment is. Only running out of time\n * throws, as {@link UnfazedRunError} with `reason: \"TIMEOUT\"`.\n */\n async waitForRun(runId: string, waitOptions: WaitOptions = {}): Promise<Run> {\n const resolved = resolveWaitOptions(waitOptions);\n const requestOptions: RequestOptions = resolved.signal ? { signal: resolved.signal } : {};\n let last: { id: string; status: RunStatus; error: string | null; exitCode: number | null } | null =\n null;\n\n await pollWithBackoff<true>(\n async () => {\n const data = await this.client.query(ops.PollRunDocument, { id: runId }, requestOptions);\n const r = data.run;\n last = r;\n if (isTerminalRunStatus(r.status)) return { done: true, value: true };\n return { done: false };\n },\n resolved,\n () =>\n new UnfazedRunError(\n \"TIMEOUT\",\n runId,\n last,\n `unfazed: run ${runId} still ${(last as { status?: string } | null)?.status ?? \"QUEUED\"} after ${resolved.timeoutMs}ms`,\n ),\n );\n\n return this.getRun(runId, requestOptions);\n }\n\n /** Reads one run by id. Throws if it does not exist or is not visible to you. */\n async getRun(runId: string, options?: RequestOptions): Promise<Run> {\n const data = await this.client.query(ops.GetRunDocument, { id: runId }, options);\n return data.run;\n }\n\n /** Your agent runs, newest first, optionally filtered by workspace/status. */\n async listRuns(filter: ListRunsFilter = {}, options?: RequestOptions) {\n const { workspaceId, status, limit, offset } = filter;\n const data = await this.client.query(\n ops.ListRunsDocument,\n {\n input: {\n ...(workspaceId === undefined ? {} : { workspaceID: workspaceId }),\n ...(status === undefined ? {} : { status }),\n ...(limit === undefined ? {} : { limit }),\n ...(offset === undefined ? {} : { offset }),\n },\n },\n options,\n );\n return data.runs;\n }\n\n /**\n * Stops a run: a QUEUED run is cancelled at once, a RUNNING run's VM is\n * killed and the run settles CANCELLED shortly after (`waitForRun` to\n * observe it). Idempotent on an already-CANCELLED run; a run that has\n * already SUCCEEDED or FAILED cannot be cancelled and the server rejects\n * the call (thrown as {@link UnfazedGraphQLError}) — check `status` first\n * when that is a routine case for you.\n */\n async cancelRun(runId: string, options?: RequestOptions): Promise<Run> {\n const data = await this.client.mutate(ops.CancelRunDocument, { id: runId }, options);\n return data.cancelRun;\n }\n\n /**\n * Continues a FINISHED run with a new instruction: a new run in the same\n * workspace that inherits the parent's harness (or command), setup, skills\n * and approval, with the parent's task, outcome and the end of its\n * transcript prepended to `prompt` as context. This is how a plan is\n * approved — `createRun({ mode: \"plan\" })` writes the plan, `followUpRun`\n * with the go-ahead executes it — and how work continues after a run\n * exited. The new run carries `parentRunID` and `depth`; chains are capped\n * server-side. A live run cannot be followed up (the server refuses):\n * answer it or wait for it.\n *\n * ```ts\n * const plan = await unfazed.createRun({ workspaceId, harness: \"claude-code\", prompt: \"plan the migration\", mode: \"plan\", wait: true });\n * const done = await unfazed.followUpRun(plan.id, { prompt: \"go ahead\", wait: true });\n * ```\n */\n async followUpRun(runId: string, options: FollowUpRunOptions): Promise<Run> {\n const { prompt, mode, approval, maxSeconds, metadata, wait, waitOptions, signal } = options;\n const requestOptions: RequestOptions = signal ? { signal } : {};\n const data = await this.client.mutate(\n ops.FollowUpRunDocument,\n {\n input: {\n runID: runId,\n prompt,\n ...(mode === undefined ? {} : { mode }),\n ...(approval === undefined ? {} : { approval }),\n ...(maxSeconds === undefined ? {} : { maxSeconds }),\n ...(metadata === undefined ? {} : { metadata }),\n },\n },\n requestOptions,\n );\n const run = data.followUpRun;\n if (!wait || isTerminalRunStatus(run.status)) return run;\n return this.waitForRun(run.id, { ...waitOptions, ...(signal ? { signal } : {}) });\n }\n\n /**\n * Answers a BLOCKED run's pending question (`run.question`); the run\n * resumes with the text. For a question with `options`, answer with one\n * of them. Only a BLOCKED run accepts an answer — anything else is\n * refused by the server.\n *\n * A run blocks when the agent inside calls `request_human_input`, or when\n * it was created with `approval: \"human\"` and its harness asks permission\n * for a guarded action. `waitForRun` keeps waiting through BLOCKED (it is\n * not terminal); poll `getRun` and look at `question` to notice one.\n */\n async answerRun(runId: string, answer: string, options?: RequestOptions): Promise<Run> {\n const data = await this.client.mutate(ops.AnswerRunDocument, { id: runId, answer }, options);\n return data.answerRun;\n }\n\n /** A run's own history, oldest first (started, cancel requested, settled). */\n async runEvents(runId: string, input: { limit?: number } = {}, options?: RequestOptions) {\n const data = await this.client.query(\n ops.RunEventsDocument,\n { runID: runId, limit: input.limit ?? null },\n options,\n );\n return data.runEvents;\n }\n\n /**\n * The live tail of a RUNNING run's console. Once the run has settled this\n * comes back empty with `running: false` — read {@link runTranscript}\n * instead, which is the stored, durable copy.\n */\n async runConsole(runId: string, input: { tailBytes?: number } = {}, options?: RequestOptions) {\n const data = await this.client.query(\n ops.RunConsoleDocument,\n { id: runId, tailBytes: input.tailBytes ?? null },\n options,\n );\n return data.runConsole;\n }\n\n /**\n * The bounded end of a finished run's stored transcript (secrets\n * redacted). `available` is false until the run settles and the transcript\n * is copied out of the VM's console file — check `run.transcriptAvailable`\n * or poll this after {@link waitForRun} resolves.\n */\n async runTranscript(runId: string, input: { tailBytes?: number } = {}, options?: RequestOptions) {\n const data = await this.client.query(\n ops.RunTranscriptDocument,\n { id: runId, tailBytes: input.tailBytes ?? null },\n options,\n );\n return data.runTranscript;\n }\n\n /* -------------------------------------------------------------- internals */\n\n /**\n * Finds a visible workspace by name, the way the server compares names.\n *\n * The server rejects duplicates with Go's `strings.EqualFold`, so matching\n * must be case-insensitive here too or `ensureWorkspace` would try to create\n * a \"new\" workspace the server considers a duplicate. An exact-case hit wins\n * over a folded one, which only matters if a name ever slipped past the\n * uniqueness check.\n */\n async #findWorkspaceByName(\n name: string,\n options?: RequestOptions,\n ): Promise<Workspace | undefined> {\n const workspaces = await this.listWorkspaces(options);\n const folded = name.toLowerCase();\n return (\n workspaces.find((w) => w.name === name) ??\n workspaces.find((w) => w.name.toLowerCase() === folded)\n );\n }\n\n async #writeBatch(\n workspaceId: string,\n batch: NormalizedFile[],\n signal?: AbortSignal,\n ): Promise<WorkspaceFile[]> {\n const varDefs = [\"$workspaceID: ID!\"];\n const fields: string[] = [];\n const variables: Record<string, string> = { workspaceID: workspaceId };\n\n batch.forEach((file, i) => {\n variables[`p${i}`] = file.path;\n variables[`c${i}`] = file.content;\n varDefs.push(`$p${i}: String!`, `$c${i}: String!`);\n fields.push(\n file.kind === \"text\"\n ? ` f${i}: writeWorkspaceTextFile(input: { workspaceID: $workspaceID, path: $p${i}, text: $c${i} }) { file { ${FILE_SELECTION} } }`\n : ` f${i}: writeWorkspaceBase64File(input: { workspaceID: $workspaceID, path: $p${i}, contentBase64: $c${i} }) { file { ${FILE_SELECTION} } }`,\n );\n });\n\n // Built at runtime rather than codegen'd: the field COUNT varies per call,\n // so no static document can express it. The field shapes are still fixed\n // and typed below, and each individual mutation is codegen-validated by its\n // single-file twin in operations.ts.\n const document = `mutation SdkWriteFilesBatch(${varDefs.join(\", \")}) {\\n${fields.join(\"\\n\")}\\n}`;\n\n const data = await this.client.mutate<\n Record<string, { file: WorkspaceFile }>,\n typeof variables\n >(document, variables, signal ? { signal } : {});\n\n return batch.map((_, i) => data[`f${i}`]!.file);\n }\n}\n\nconst FILE_SELECTION = \"path sizeBytes size sha256 updatedAt\";\nconst ENV_SELECTION = \"name value secret alias inherited masked updatedAt\";\n\n/**\n * Terminal = anything but QUEUED or RUNNING, defined negatively exactly like\n * the platform's own `IsTerminalRunStatus` — so a future status this SDK does\n * not know about yet still ends a wait instead of polling forever.\n */\nfunction isTerminalRunStatus(status: string): boolean {\n return status !== \"QUEUED\" && status !== \"RUNNING\";\n}\n\ninterface NormalizedFile {\n path: string;\n kind: \"text\" | \"base64\";\n content: string;\n}\n\nfunction normalizeFile(path: string, content: FileContent): NormalizedFile {\n if (typeof content === \"string\") return { path, kind: \"text\", content };\n if (\"text\" in content) return { path, kind: \"text\", content: content.text };\n if (\"base64\" in content) return { path, kind: \"base64\", content: content.base64 };\n return { path, kind: \"base64\", content: toBase64(content.bytes) };\n}\n\nfunction toBase64(input: Uint8Array | ArrayBuffer): string {\n const bytes = input instanceof Uint8Array ? input : new Uint8Array(input);\n // Node/Bun have Buffer; browsers and workers do not.\n const maybeBuffer = (globalThis as { Buffer?: { from(b: Uint8Array): { toString(e: string): string } } })\n .Buffer;\n if (maybeBuffer) return maybeBuffer.from(bytes).toString(\"base64\");\n\n let binary = \"\";\n const CHUNK = 0x8000; // avoid blowing the argument limit on large files\n for (let i = 0; i < bytes.length; i += CHUNK) {\n binary += String.fromCharCode(...bytes.subarray(i, i + CHUNK));\n }\n return btoa(binary);\n}\n\nconst utf8 = new TextEncoder();\n\n/**\n * UTF-8 byte length, which is what the wire actually costs.\n *\n * `String.length` counts UTF-16 code units and undercounts by up to 3x on\n * non-ASCII text — a CJK or emoji-heavy payload would sail past a budget it\n * had already blown.\n */\nfunction utf8Bytes(s: string): number {\n return utf8.encode(s).length;\n}\n\n/**\n * Splits files into request-sized batches.\n *\n * Closes a batch on whichever limit trips first — count or bytes — but always\n * emits at least one file per batch, so a single file larger than\n * `maxBatchBytes` still gets sent (and fails loudly at the server's limit)\n * rather than silently vanishing into an empty batch.\n */\nfunction chunkFiles(\n files: NormalizedFile[],\n batchSize: number,\n maxBatchBytes: number,\n): NormalizedFile[][] {\n const batches: NormalizedFile[][] = [];\n let current: NormalizedFile[] = [];\n let bytes = 0;\n\n for (const file of files) {\n // Measured once per file, so the encode cost is linear in the payload the\n // request was going to carry anyway.\n const size = utf8Bytes(file.content) + utf8Bytes(file.path);\n if (current.length > 0 && (current.length >= batchSize || bytes + size > maxBatchBytes)) {\n batches.push(current);\n current = [];\n bytes = 0;\n }\n current.push(file);\n bytes += size;\n }\n if (current.length > 0) batches.push(current);\n return batches;\n}\n"]}
1
+ {"version":3,"file":"unfazed.js","sourceRo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;;;;;;;GAOG;AACH,SAAS,UAAU,CACjB,KAAuB,EACvB,SAAiB,EACjB,aAAqB;IAErB,MAAM,OAAO,GAAuB,EAAE,CAAC;IACvC,IAAI,OAAO,GAAqB,EAAE,CAAC;IACnC,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,0EAA0E;QAC1E,qCAAqC;QACrC,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5D,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,SAAS,IAAI,KAAK,GAAG,IAAI,GAAG,aAAa,CAAC,EAAE,CAAC;YACxF,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACtB,OAAO,GAAG,EAAE,CAAC;YACb,KAAK,GAAG,CAAC,CAAC;QACZ,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnB,KAAK,IAAI,IAAI,CAAC;IAChB,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC9C,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { UnfazedClient, type ClientOptions, type RequestOptions } from \"./client.js\";\nimport {\n DEPLOYMENT_NOT_FOUND,\n UnfazedConflictError,\n UnfazedDeployError,\n UnfazedGraphQLError,\n UnfazedNotFoundError,\n UnfazedRunError,\n WORKSPACE_NOT_FOUND,\n isDuplicateWorkspaceName,\n isNotFoundSentinel as isNotFound,\n looksLikeCASConflict,\n} from \"./errors.js\";\nimport * as ops from \"./operations.js\";\nimport type {\n CreateDeploymentInput,\n DeploymentFieldsFragment,\n ListDeploymentsInput,\n RunFieldsFragment,\n RunStatus,\n ServiceMode,\n ServiceRuntime,\n SdkCreateWorkspaceMutation,\n SdkRunHarnessesQuery,\n} from \"./generated/graphql.js\";\nimport { pollWithBackoff, resolveWaitOptions, type WaitOptions } from \"./wait.js\";\n\n/** A deployment as the workflow layer returns it. */\nexport type Deployment = DeploymentFieldsFragment;\n\n/** An agent run as the workflow layer returns it. */\nexport type Run = RunFieldsFragment;\n/** One harness preset of the box image, from {@link Unfazed.listRunHarnesses}. */\nexport type RunHarness = SdkRunHarnessesQuery[\"runHarnesses\"][number];\n\n/**\n * A workspace as {@link Unfazed.createWorkspace} and\n * {@link Unfazed.ensureWorkspace} return it.\n *\n * Derived from the generated mutation type rather than hand-written, so the\n * two documents selecting these fields cannot drift apart without a compile\n * error — which is exactly what makes `ensureWorkspace` able to return either\n * a listed or a freshly created workspace under one type.\n */\nexport type Workspace = SdkCreateWorkspaceMutation[\"createWorkspace\"][\"workspace\"];\n\n/** Options for {@link Unfazed.deleteWorkspace}. */\nexport type DeleteWorkspaceOptions = {\n /**\n * Also delete every deployment snapshotted from the workspace, stopping\n * their service VMs. **Defaults to `true`** — see the method docs for why.\n */\n withDeployments?: boolean;\n /** Resolve `false` instead of throwing when the workspace is not visible. */\n ignoreNotFound?: boolean;\n} & RequestOptions;\n\n/** Options for {@link Unfazed.deleteDeployment}. */\nexport type DeleteDeploymentOptions = {\n /** Resolve `false` instead of throwing when the deployment is not visible. */\n ignoreNotFound?: boolean;\n} & RequestOptions;\n\n/** A file record returned by any write/list operation. */\nexport interface WorkspaceFile {\n path: string;\n sizeBytes: number;\n size: string;\n sha256: string;\n updatedAt: string;\n}\n\n/** One env var in a workspace- or app-scoped view. Secret values are never returned. */\nexport interface EnvVar {\n name: string;\n value: string | null;\n secret: boolean;\n alias: string | null;\n inherited: boolean;\n masked: boolean;\n updatedAt: string;\n}\n\n/**\n * A file's contents for {@link Unfazed.writeFiles}.\n *\n * A bare string is text — the overwhelmingly common case, and what makes\n * `{ \"server.ts\": code }` read well. Binary goes through `bytes` or `base64`,\n * which route to `writeWorkspaceBase64File` instead.\n */\nexport type FileContent =\n | string\n | { text: string }\n | { base64: string }\n | { bytes: Uint8Array | ArrayBuffer };\n\n/** Files keyed by workspace-relative path. */\nexport type FilesMap = Record<string, FileContent>;\n\nexport interface WriteFilesOptions {\n /**\n * Max files per GraphQL request. Default 20.\n *\n * The batch is one document with N aliased root fields; too many at once\n * makes a single oversized request whose failure is all-or-nothing to\n * diagnose. Twenty keeps a typical app to one or two round trips.\n */\n batchSize?: number;\n /**\n * Max total payload bytes per request. Default 4 MiB. Whichever limit trips\n * first closes the batch, so one large file cannot blow the request up.\n */\n maxBatchBytes?: number;\n signal?: AbortSignal;\n}\n\n/** Common options for the deploy helpers. */\nexport interface DeployOptions {\n workspaceId: string;\n alias?: string;\n /**\n * Block until the deployment reaches a terminal status.\n *\n * `createDeployment` returns BUILDING immediately; the build, VM boot and\n * health probe run in the background. With `wait: true` the call resolves\n * only on READY and throws {@link UnfazedDeployError} on FAILED — which is\n * what makes a one-script deploy possible.\n */\n wait?: boolean;\n /** Backoff/timeout knobs used when `wait` is true. */\n waitOptions?: WaitOptions;\n signal?: AbortSignal;\n}\n\nexport interface DeployServiceOptions extends DeployOptions {\n /** Omit to auto-detect: a root go.mod+main.go is GO, otherwise BUN. */\n runtime?: ServiceRuntime;\n /** Omit for ON_DEMAND. Only set ALWAYS_ON to keep the VM warm. */\n serviceMode?: ServiceMode;\n healthPath?: string;\n /** Standard 5-field cron spec. Prefer ON_DEMAND + cron over ALWAYS_ON. */\n cronSchedule?: string;\n /** Path the cron tick POSTs to. Defaults to /cron when cronSchedule is set. */\n cronPath?: string;\n}\n\nexport interface DeployStaticOptions extends DeployOptions {\n /** Serve index.html for missing paths (single-page apps). */\n spaMode?: boolean;\n}\n\nexport interface DeployBoxOptions extends DeployOptions {\n /** VM size. Omit for platform defaults (2048 MiB / 2 vCPU / 8 GiB disk). */\n resources?: { memMiB?: number; vcpus?: number; diskGiB?: number };\n}\n\nexport interface RollbackOptions {\n /** The alias to roll back. */\n alias: string;\n /**\n * Release to restore. Omit to pick the most recent READY release that is not\n * the current holder — i.e. \"undo the last deploy\".\n */\n to?: string;\n /**\n * Re-list-and-retry attempts when the compare-and-swap guard is rejected.\n * Default 1. Each retry refreshes the guard from a fresh read; the TARGET\n * release stays pinned, so a retry can never silently roll back to something\n * other than what was chosen.\n *\n * Ignored when {@link expectedCurrentId} is set — see there.\n */\n retries?: number;\n /**\n * The release you believe currently holds the alias. When set, the rollback\n * proceeds only if that is still true.\n *\n * This turns the rollback from \"undo whatever is live now\" into a checked\n * operation: if the live holder is anything else, you get\n * {@link UnfazedConflictError} BEFORE any mutation is sent, so a rollback\n * script can never act on a world that moved since you inspected it.\n *\n * It also disables the CAS retry, necessarily: a rejected guard means the\n * alias moved, and the alias having moved is precisely the precondition you\n * asked to be enforced. Retrying would refresh the guard to the new holder\n * and roll back the very deploy the precondition existed to protect.\n */\n expectedCurrentId?: string;\n signal?: AbortSignal;\n}\n\n/** Options for {@link Unfazed.createRun}. */\nexport interface CreateRunOptions {\n workspaceId: string;\n /** Delivered to the guest as `/work/prompt.md` and `$UNFZ_RUN_PROMPT` (max 64 KiB). */\n prompt?: string;\n /** A named preset from the image's `/etc/unfazed/harnesses.json`. Mutually exclusive in effect with `command` — set one. */\n harness?: string;\n /** Runs anything else with `sh -c`, instead of a named `harness`. */\n command?: string;\n /** Up to 20 single-line shell commands run in `/work` before the harness; the first failure fails the run. */\n setup?: string[];\n /** Up to 10 `owner/repo:path` GitHub references, cloned into `/work/.claude/skills/<name>` first. */\n skills?: string[];\n /**\n * Up to 20 shell commands run in `/work` AFTER the harness exited 0 —\n * tests, a build, `test -f out.txt`. The first failure FAILS the run\n * (`error` \"verification failed\", `verifyExitCode`). Without `verify`,\n * SUCCEEDED only means the harness exited cleanly: an agent that answered\n * \"I could not do this\" still succeeds — read `run.result.text` in that\n * case. Skipped in plan mode.\n */\n verify?: string[];\n /** VM memory. Omit for the platform default. */\n memoryMiB?: number;\n /** Wall-clock cap in seconds. Omit for the platform default; capped at 3600. */\n maxSeconds?: number;\n /** Up to 20 immutable labels for your own correlation (a ticket id, a PR). Echoed back on every read. */\n metadata?: unknown;\n /** Copy the workspace's files into `/work`. Default true. */\n includeFiles?: boolean;\n /**\n * `\"human\"` routes the harness's guarded actions (permission prompts) to\n * the run's owner: the run shows BLOCKED with the question until it is\n * answered ({@link Unfazed.answerRun}, the dashboard). Omit for the\n * harness's own defaults.\n */\n approval?: \"human\";\n /**\n * `\"plan\"` asks the harness to research and write a plan WITHOUT acting\n * (Claude Code runs in `--permission-mode plan`); the plan is the run's\n * transcript. Approve it with {@link Unfazed.followUpRun}. Omit to do the task.\n */\n mode?: \"plan\";\n /**\n * `\"read-only\"` (the default) or `\"read-write\"`. A read-only run gets the\n * app's integrations' read-only credentials (none where the product has no\n * read-only key), only their read MCP tools, and a platform token that\n * cannot deploy or write env; read-write gets the app's own credentials,\n * read+write tools and a deploy-capable token. Ask for read-write only\n * when the run must change things.\n */\n access?: \"read-only\" | \"read-write\";\n /**\n * The app (alias) whose integrations the run gets. Implicit when the\n * workspace has one app; required when it has several.\n */\n alias?: string;\n /** The run this one continues. Usually set for you by {@link Unfazed.followUpRun}. */\n parentRunId?: string;\n /**\n * Block until the run reaches a terminal status.\n *\n * `createRun` itself already returns RUNNING or — on a boot failure —\n * FAILED with `error` set; `wait: true` additionally polls a RUNNING run\n * through to SUCCEEDED/FAILED/CANCELLED. Either way this resolves with the\n * run, never throws for FAILED: see {@link Unfazed.waitForRun}.\n */\n wait?: boolean;\n /** Backoff/timeout knobs used when `wait` is true. */\n waitOptions?: WaitOptions;\n signal?: AbortSignal;\n}\n\n/** Options for {@link Unfazed.followUpRun}. */\nexport interface FollowUpRunOptions {\n /** What to do next. For a plan run: the go-ahead (and any changes to the plan). */\n prompt: string;\n /** `\"plan\"` to plan again instead of executing; omit to execute. */\n mode?: \"plan\";\n /** Override the parent's approval; omit to inherit it. */\n approval?: \"human\" | \"\";\n /** Override the parent's wall clock (seconds). */\n maxSeconds?: number;\n metadata?: unknown;\n /** As for {@link CreateRunOptions.wait}. */\n wait?: boolean;\n waitOptions?: WaitOptions;\n signal?: AbortSignal;\n}\n\n/** Filter/paging for {@link Unfazed.listRuns}. */\nexport interface ListRunsFilter {\n workspaceId?: string;\n status?: RunStatus;\n limit?: number;\n offset?: number;\n}\n\nexport interface UnfazedOptions extends ClientOptions {\n /** Use an existing core client instead of constructing one. */\n client?: UnfazedClient;\n}\n\n/**\n * Layer 2 — the agent workflow layer.\n *\n * Wraps the chains an agent actually performs (create → write → deploy → wait\n * → read logs → roll back) so a code-mode script does in one call what would\n * otherwise be many round trips through a model's context. Everything here is\n * built on {@link UnfazedClient}, exposed as `.client` for anything not\n * wrapped.\n *\n * ```ts\n * const unfazed = new Unfazed(); // reads UNFZ_API_TOKEN\n * const ws = await unfazed.createWorkspace(\"hello\");\n * await unfazed.writeFiles(ws.id, { \"server.ts\": code });\n * const app = await unfazed.deployService({ workspaceId: ws.id, alias: \"hello\", wait: true });\n * console.log(app.url);\n * ```\n */\nexport class Unfazed {\n /** The underlying typed GraphQL client. Use it for un-wrapped operations. */\n readonly client: UnfazedClient;\n\n constructor(options: UnfazedOptions = {}) {\n const { client, ...clientOptions } = options;\n this.client = client ?? new UnfazedClient(clientOptions);\n }\n\n /* ---------------------------------------------------------------- identity */\n\n /** Who this token authenticates as, plus usage and resource limits. */\n async whoami(options?: RequestOptions) {\n const data = await this.client.query(ops.WhoamiDocument, {}, options);\n return data.whoami;\n }\n\n /* -------------------------------------------------------------- workspaces */\n\n /** Creates a source workspace — the container for files, env and deployments. */\n async createWorkspace(name: string, options?: RequestOptions) {\n const data = await this.client.mutate(ops.CreateWorkspaceDocument, { name }, options);\n return data.createWorkspace.workspace;\n }\n\n /** Workspaces visible to this token. */\n async listWorkspaces(options?: RequestOptions) {\n const data = await this.client.query(ops.ListWorkspacesDocument, {}, options);\n return data.workspaces;\n }\n\n /**\n * Deletes a workspace and everything anchored to it — deployments, env, and\n * a BOX's persistent data disk. Not recoverable.\n *\n * **The cascade is opt-out, not opt-in.** The server refuses to delete a\n * workspace that has ANY deployment history — including FAILED records, and\n * including deployments whose alias was long since taken over by something\n * else — unless the mutation carries `withDeployments`. Since almost every\n * workspace an agent creates gets deployed at least once, defaulting to\n * `false` would make this method fail on nearly every real workspace, so it\n * defaults to **`true`**: the behaviour this docstring has always promised.\n *\n * Pass `withDeployments: false` for the strict variant, which refuses rather\n * than cascading and is the safer choice when you are deleting a workspace\n * you did not create:\n *\n * ```ts\n * await unfazed.deleteWorkspace(ws.id); // cascade\n * await unfazed.deleteWorkspace(ws.id, { withDeployments: false }); // refuse if deployed\n * await unfazed.deleteWorkspace(id, { ignoreNotFound: true }); // false, not a throw\n * ```\n *\n * With `ignoreNotFound` a workspace that is absent (or belongs to someone\n * else — the server returns one indistinguishable sentinel for both, on\n * purpose) resolves to `false` instead of throwing, which makes teardown in\n * a `finally` block idempotent.\n */\n async deleteWorkspace(\n workspaceId: string,\n options: DeleteWorkspaceOptions = {},\n ): Promise<boolean> {\n const withDeployments = options.withDeployments ?? true;\n try {\n const data = await this.client.mutate(\n ops.DeleteWorkspaceDocument,\n { workspaceID: workspaceId, withDeployments },\n options,\n );\n return data.deleteWorkspace.ok;\n } catch (e) {\n if (options.ignoreNotFound && isNotFound(e, WORKSPACE_NOT_FOUND)) return false;\n throw e;\n }\n }\n\n /**\n * Returns the workspace named `name`, creating it only if it does not exist.\n *\n * Workspace names are unique per owner, case-insensitively — a second\n * `createWorkspace(\"Hello\")` after a `createWorkspace(\"hello\")` is an error,\n * not a second workspace. That makes the bare create a poor fit for any\n * script that might run twice; this is the re-runnable form.\n *\n * ```ts\n * const ws = await unfazed.ensureWorkspace(\"greeter\"); // safe to re-run\n * ```\n *\n * Costs one list, plus one create only on a miss. The create is still\n * guarded: if a concurrent caller wins the race, the duplicate-name error is\n * caught and the now-existing workspace is returned instead of thrown.\n */\n async ensureWorkspace(name: string, options?: RequestOptions) {\n const existing = await this.#findWorkspaceByName(name, options);\n if (existing) return existing;\n\n try {\n return await this.createWorkspace(name, options);\n } catch (e) {\n // Lost a create/create race, or the server's case folding is stricter\n // than ours. Either way the workspace exists now — re-read rather than\n // failing a script whose intent was \"make sure this exists\".\n if (!isDuplicateWorkspaceName(e)) throw e;\n const raced = await this.#findWorkspaceByName(name, options);\n if (raced) return raced;\n // The name is taken by something we cannot see. Surface the real error.\n throw e;\n }\n }\n\n /* ------------------------------------------------------------------- files */\n\n /**\n * Writes many files in as few requests as possible.\n *\n * The API is one-file-per-mutation, so writing a 12-file app naively costs 12\n * round trips. This batches them into a single GraphQL document with one\n * ALIASED root field per file (`f0: writeWorkspaceTextFile(...)`,\n * `f1: ...`), which the server resolves in one request.\n *\n * ```ts\n * await unfazed.writeFiles(ws.id, {\n * \"server.ts\": serverCode,\n * \"unfazed.json\": JSON.stringify({ entry: \"server.ts\" }),\n * \"public/logo.png\": { bytes: pngBytes },\n * });\n * ```\n *\n * Batches are NOT atomic: GraphQL resolves each aliased field independently,\n * so a partial failure leaves earlier writes committed. The thrown\n * {@link UnfazedGraphQLError} carries `data` with whichever aliases\n * succeeded, and `error.path` identifies the ones that did not.\n */\n async writeFiles(\n workspaceId: string,\n files: FilesMap,\n options: WriteFilesOptions = {},\n ): Promise<WorkspaceFile[]> {\n const entries = Object.entries(files).map(([path, content]) => normalizeFile(path, content));\n if (entries.length === 0) return [];\n\n const batchSize = options.batchSize ?? 20;\n const maxBatchBytes = options.maxBatchBytes ?? 4 * 1024 * 1024;\n\n const written: WorkspaceFile[] = [];\n for (const batch of chunkFiles(entries, batchSize, maxBatchBytes)) {\n written.push(...(await this.#writeBatch(workspaceId, batch, options.signal)));\n }\n return written;\n }\n\n /** Writes one text file. Prefer {@link writeFiles} for more than one. */\n async writeFile(\n workspaceId: string,\n path: string,\n text: string,\n options?: RequestOptions,\n ): Promise<WorkspaceFile> {\n const data = await this.client.mutate(\n ops.WriteTextFileDocument,\n { workspaceID: workspaceId, path, text },\n options,\n );\n return data.writeWorkspaceTextFile.file;\n }\n\n /** Writes one binary file. Accepts raw bytes or a base64 string. */\n async writeBinaryFile(\n workspaceId: string,\n path: string,\n content: Uint8Array | ArrayBuffer | { base64: string },\n options?: RequestOptions,\n ): Promise<WorkspaceFile> {\n const contentBase64 = \"base64\" in content ? content.base64 : toBase64(content);\n const data = await this.client.mutate(\n ops.WriteBase64FileDocument,\n { workspaceID: workspaceId, path, contentBase64 },\n options,\n );\n return data.writeWorkspaceBase64File.file;\n }\n\n /** Lists workspace files (paginated). */\n async listFiles(\n workspaceId: string,\n input: { limit?: number; offset?: number; order?: string } = {},\n options?: RequestOptions,\n ) {\n const data = await this.client.query(\n ops.ListFilesDocument,\n { input: { workspaceID: workspaceId, ...input } },\n options,\n );\n return data.workspaceFilesPage;\n }\n\n /** Reads a text file, optionally a byte range of it. Null when absent. */\n async readFile(\n workspaceId: string,\n path: string,\n input: { offset?: number; limit?: number } = {},\n options?: RequestOptions,\n ) {\n const data = await this.client.query(\n ops.ReadFileDocument,\n { input: { workspaceID: workspaceId, path, ...input } },\n options,\n );\n return data.readWorkspaceFile;\n }\n\n /**\n * Deletes a workspace file.\n *\n * Returns `false` when there was nothing to delete — an absent path is not\n * an error. See the `ok: false` convention on {@link deleteEnv}.\n */\n async deleteFile(\n workspaceId: string,\n path: string,\n options?: RequestOptions,\n ): Promise<boolean> {\n const data = await this.client.mutate(\n ops.DeleteFileDocument,\n { workspaceID: workspaceId, path },\n options,\n );\n return data.deleteWorkspaceFile.ok;\n }\n\n /* ----------------------------------------------------------------- deploys\n *\n * Every deploy method here MINTS A NEW RELEASE on every call. There is no\n * content dedupe: deploying byte-identical files twice produces two distinct\n * releases with two ids, both real, both counting against retention (which\n * keeps only the most recent few per alias and prunes the rest). Deploying\n * in a retry loop is therefore not free — it churns the release history and\n * can push a release you still wanted to roll back to out of retention.\n * Check {@link getDeployment} or {@link listReleases} before redeploying if\n * you only meant to converge.\n */\n\n /**\n * Deploys the workspace as a SERVICE (an HTTP server).\n *\n * With `wait: true` this resolves only once the build, VM boot and health\n * probe have all passed.\n *\n * Passing the same `alias` again redeploys that alias — a new release that\n * takes over the alias when it goes READY. Omitting `alias` lets the server\n * generate one, which means a different app on every call.\n */\n deployService(options: DeployServiceOptions): Promise<Deployment> {\n const { workspaceId, alias, runtime, serviceMode, healthPath, cronSchedule, cronPath } =\n options;\n return this.#deploy(\n {\n workspaceID: workspaceId,\n kind: \"SERVICE\",\n ...(alias === undefined ? {} : { alias }),\n ...(runtime === undefined ? {} : { runtime }),\n ...(serviceMode === undefined ? {} : { serviceMode }),\n ...(healthPath === undefined ? {} : { healthPath }),\n ...(cronSchedule === undefined ? {} : { cronSchedule }),\n ...(cronPath === undefined ? {} : { cronPath }),\n },\n options,\n );\n }\n\n /** Deploys the workspace as a STATIC site. */\n deployStatic(options: DeployStaticOptions): Promise<Deployment> {\n const { workspaceId, alias, spaMode } = options;\n return this.#deploy(\n {\n workspaceID: workspaceId,\n kind: \"STATIC\",\n ...(alias === undefined ? {} : { alias }),\n ...(spaMode === undefined ? {} : { spaMode }),\n },\n options,\n );\n }\n\n /**\n * Deploys a BOX: a persistent always-on Linux VM with a data disk that\n * survives stops and redeploys. A dev machine, not an HTTP service. The\n * result's `sshCommand` is how you get in.\n *\n * ⚠️ **Omitting `alias` creates a NEW BOX every single call.** There is no\n * \"the workspace's box\" to update: with no alias the server generates a\n * fresh random one, so a script run twice leaves you with two box records,\n * not one redeployed box.\n *\n * The data disk, meanwhile, is keyed by WORKSPACE — one disk, shared by\n * every box in the workspace, and it is the box's real identity. Since only\n * one VM can hold that disk read-write, the second box cannot even start\n * while the first is running (`box data disk for workspace ... is attached\n * to VM ...; stop it first`). The result is a pile of dead box records\n * fighting over one disk.\n *\n * **Always pass an explicit `alias` in anything re-runnable.** Redeploying\n * the same alias is the in-place update you actually want.\n *\n * ```ts\n * await unfazed.deployBox({ workspaceId: ws.id, alias: \"dev\" }); // re-runnable\n * ```\n */\n deployBox(options: DeployBoxOptions): Promise<Deployment> {\n const { workspaceId, alias, resources } = options;\n return this.#deploy(\n {\n workspaceID: workspaceId,\n kind: \"BOX\",\n ...(alias === undefined ? {} : { alias }),\n ...(resources === undefined ? {} : { boxResources: resources }),\n },\n options,\n );\n }\n\n /** Escape hatch: deploy with a raw CreateDeploymentInput. */\n deploy(\n input: CreateDeploymentInput,\n options: Omit<DeployOptions, \"workspaceId\"> = {},\n ): Promise<Deployment> {\n return this.#deploy(input, options);\n }\n\n async #deploy(\n input: CreateDeploymentInput,\n options: Omit<DeployOptions, \"workspaceId\">,\n ): Promise<Deployment> {\n const requestOptions: RequestOptions = options.signal ? { signal: options.signal } : {};\n const data = await this.client.mutate(ops.CreateDeploymentDocument, { input }, requestOptions);\n const deployment = data.createDeployment.deployment;\n if (!options.wait) return deployment;\n return this.waitForDeployment(deployment.id, {\n ...options.waitOptions,\n ...(options.signal ? { signal: options.signal } : {}),\n });\n }\n\n /**\n * Polls a deployment until it is READY, throwing on FAILED or timeout.\n *\n * BUILDING is the only non-terminal status; READY and FAILED are terminal.\n * The poll query selects six fields rather than the full deployment, because\n * this runs every few seconds for potentially minutes — then the READY\n * deployment is re-read in full so callers get the same shape `deployService`\n * returns without `wait`.\n */\n async waitForDeployment(deploymentId: string, waitOptions: WaitOptions = {}): Promise<Deployment> {\n const resolved = resolveWaitOptions(waitOptions);\n const requestOptions: RequestOptions = resolved.signal ? { signal: resolved.signal } : {};\n let last: { id: string; status: string; error: string | null } | null = null;\n\n await pollWithBackoff<true>(\n async () => {\n const data = await this.client.query(\n ops.PollDeploymentDocument,\n { id: deploymentId },\n requestOptions,\n );\n const d = data.deployment;\n if (!d) {\n throw new UnfazedNotFoundError(`unfazed: deployment ${deploymentId} not found`);\n }\n last = d;\n if (d.status === \"READY\") return { done: true, value: true };\n if (d.status === \"FAILED\") {\n throw new UnfazedDeployError(\n \"FAILED\",\n deploymentId,\n d,\n `unfazed: deployment ${deploymentId} FAILED${d.error ? `: ${d.error}` : \"\"}`,\n );\n }\n return { done: false };\n },\n resolved,\n () =>\n new UnfazedDeployError(\n \"TIMEOUT\",\n deploymentId,\n last,\n `unfazed: deployment ${deploymentId} still ${\n (last as { status?: string } | null)?.status ?? \"BUILDING\"\n } after ${resolved.timeoutMs}ms`,\n ),\n );\n\n const full = await this.getDeployment(deploymentId, requestOptions);\n if (!full) throw new UnfazedNotFoundError(`unfazed: deployment ${deploymentId} not found`);\n return full;\n }\n\n /** Reads one deployment by id. Null when absent. */\n async getDeployment(\n deploymentId: string,\n options?: RequestOptions,\n ): Promise<Deployment | null> {\n const data = await this.client.query(ops.GetDeploymentDocument, { id: deploymentId }, options);\n return data.deployment;\n }\n\n /** Reads the deployment currently serving an alias. Null when absent. */\n async getDeploymentByAlias(\n alias: string,\n options?: RequestOptions,\n ): Promise<Deployment | null> {\n const data = await this.client.query(ops.GetDeploymentByAliasDocument, { alias }, options);\n return data.deploymentByAlias;\n }\n\n /** Lists deployments (paginated, filterable by kind/alias/workspace). */\n async listDeployments(input: ListDeploymentsInput = {}, options?: RequestOptions) {\n const data = await this.client.query(ops.ListDeploymentsDocument, { input }, options);\n return data.deploymentsPage;\n }\n\n /* ------------------------------------------------------- runtime & logging */\n\n /** Live VM status: health, in-flight requests, restarts, RAM ceiling. */\n async getStatus(deploymentId: string, options?: RequestOptions) {\n const data = await this.client.query(\n ops.ServiceStatusDocument,\n { deploymentID: deploymentId },\n options,\n );\n return data.serviceStatus;\n }\n\n /**\n * Tail of the service's stdout/stderr.\n *\n * The point of doing this from a script rather than through tool calls: you\n * can filter locally. `(await unfazed.getLogs(id)).stderr.split(\"\\n\")\n * .filter(l => l.includes(\"ERROR\"))` costs a model zero context, where the\n * same tail through an MCP tool spends all of it.\n */\n async getLogs(\n deploymentId: string,\n input: { tailBytes?: number } = {},\n options?: RequestOptions,\n ) {\n const data = await this.client.query(\n ops.ServiceLogsDocument,\n { deploymentID: deploymentId, tailBytes: input.tailBytes ?? null },\n options,\n );\n return data.serviceLogs;\n }\n\n /** Deployment lifecycle events — build, boot, probe, cron, restarts. */\n async getEvents(deploymentId: string, limit?: number, options?: RequestOptions) {\n const data = await this.client.query(\n ops.DeploymentEventsDocument,\n { deploymentID: deploymentId, limit: limit ?? null },\n options,\n );\n return data.deploymentEvents;\n }\n\n /** Restarts a service's VM. */\n async restartService(deploymentId: string, options?: RequestOptions) {\n const data = await this.client.mutate(\n ops.RestartServiceDocument,\n { deploymentID: deploymentId },\n options,\n );\n return data.restartService;\n }\n\n /** Stops a service's VM. An on-demand service cold-starts again on request. */\n async stopService(deploymentId: string, options?: RequestOptions) {\n const data = await this.client.mutate(\n ops.StopServiceDocument,\n { deploymentID: deploymentId },\n options,\n );\n return data.stopService;\n }\n\n /**\n * Deletes a deployment: stops its VM, releases its alias, drops its release.\n *\n * With `ignoreNotFound` a deployment that is absent — or belongs to another\n * tenant, which the server reports identically so ids cannot be probed —\n * resolves to `false` instead of throwing, making cleanup loops idempotent.\n */\n async deleteDeployment(\n deploymentId: string,\n options: DeleteDeploymentOptions = {},\n ): Promise<boolean> {\n try {\n const data = await this.client.mutate(\n ops.DeleteDeploymentDocument,\n { deploymentID: deploymentId },\n options,\n );\n return data.deleteDeployment.ok;\n } catch (e) {\n if (options.ignoreNotFound && isNotFound(e, DEPLOYMENT_NOT_FOUND)) return false;\n throw e;\n }\n }\n\n /* ------------------------------------------------------------ env & secrets\n *\n * Workspace values are SERVICE defaults for every app in the source; app\n * values override them for one alias. Both are SNAPSHOTTED into a release at\n * deploy time — changing either does not affect a running app until you\n * redeploy that alias. Old releases are immutable, and STATIC gets no env.\n */\n\n /**\n * Sets a workspace-default env var. Redeploy the alias to apply it.\n *\n * A name is either plain or secret, never both: this DELETES a workspace\n * secret of the same name. {@link setSecret} displaces a plain var the same\n * way. Last write wins, and the kind flips silently — so re-running a setup\n * script that calls `setSecret(\"API_KEY\", ...)` after one that called\n * `setEnv(\"API_KEY\", ...)` quietly converts it, and vice versa.\n */\n async setEnv(\n workspaceId: string,\n name: string,\n value: string,\n options?: RequestOptions,\n ): Promise<EnvVar> {\n const data = await this.client.mutate(\n ops.SetWorkspaceEnvDocument,\n { workspaceID: workspaceId, name, value },\n options,\n );\n return data.setWorkspaceEnv.env;\n }\n\n /**\n * Sets a workspace-default secret. The value is never readable again.\n *\n * Mutually exclusive with {@link setEnv}: this DELETES a plain workspace var\n * of the same name. See {@link setEnv} for the displacement rule.\n */\n async setSecret(\n workspaceId: string,\n name: string,\n value: string,\n options?: RequestOptions,\n ): Promise<EnvVar> {\n const data = await this.client.mutate(\n ops.SetWorkspaceSecretDocument,\n { workspaceID: workspaceId, name, value },\n options,\n );\n return data.setWorkspaceSecret.env;\n }\n\n /**\n * Sets many workspace env vars in one request, via aliased mutations —\n * the same batching trick as {@link writeFiles}.\n *\n * Pass `{ secret: true }` to route them all to `setWorkspaceSecret`.\n *\n * It inherits {@link writeFiles}' failure semantics too: the batch is NOT\n * atomic. GraphQL resolves each aliased field independently, so a rejected\n * name (over the limit, malformed, whatever) leaves the vars before it\n * already committed. The thrown {@link UnfazedGraphQLError} carries `data`\n * with the aliases that succeeded and `errors[].path` naming those that did\n * not — do not assume \"it threw\" means \"nothing was written\".\n *\n * Each name still displaces its opposite kind, exactly as {@link setEnv} and\n * {@link setSecret} do one at a time.\n */\n async setEnvMany(\n workspaceId: string,\n vars: Record<string, string>,\n options: { secret?: boolean; signal?: AbortSignal } = {},\n ): Promise<EnvVar[]> {\n const entries = Object.entries(vars);\n if (entries.length === 0) return [];\n\n const field = options.secret ? \"setWorkspaceSecret\" : \"setWorkspaceEnv\";\n const varDefs = [\"$workspaceID: ID!\"];\n const fields: string[] = [];\n const variables: Record<string, string> = { workspaceID: workspaceId };\n\n entries.forEach(([name, value], i) => {\n varDefs.push(`$n${i}: String!`, `$v${i}: String!`);\n variables[`n${i}`] = name;\n variables[`v${i}`] = value;\n fields.push(\n ` e${i}: ${field}(input: { workspaceID: $workspaceID, name: $n${i}, value: $v${i} }) { env { ${ENV_SELECTION} } }`,\n );\n });\n\n const document = `mutation SdkSetEnvBatch(${varDefs.join(\", \")}) {\\n${fields.join(\"\\n\")}\\n}`;\n const data = await this.client.mutate<Record<string, { env: EnvVar }>, typeof variables>(\n document,\n variables,\n options.signal ? { signal: options.signal } : {},\n );\n return entries.map((_, i) => data[`e${i}`]!.env);\n }\n\n /**\n * Deletes a workspace-default env var (plain or secret).\n *\n * **The `ok: false` convention.** A `false` here does NOT mean failure — it\n * means \"nothing to do, the world is already in the state you asked for\".\n * The var did not exist. Every `ok`-returning mutation in this SDK follows\n * the rule ({@link deleteFile}, {@link inheritAppEnv}, {@link removeAppEnv}),\n * so the idempotent-cleanup pattern is simply to ignore the boolean; a real\n * failure throws.\n */\n async deleteEnv(workspaceId: string, name: string, options?: RequestOptions): Promise<boolean> {\n const data = await this.client.mutate(\n ops.DeleteWorkspaceEnvDocument,\n { workspaceID: workspaceId, name },\n options,\n );\n return data.deleteWorkspaceEnv.ok;\n }\n\n /** Workspace-default env vars. Secret values are redacted. */\n async listEnv(workspaceId: string, options?: RequestOptions): Promise<EnvVar[]> {\n const data = await this.client.query(\n ops.ListWorkspaceEnvDocument,\n { workspaceID: workspaceId },\n options,\n );\n return data.workspaceEnv;\n }\n\n /**\n * Sets an env var for ONE alias, overriding the workspace default.\n *\n * Displaces both of the other states this name could be in for the app: it\n * deletes an app SECRET of the same name, and it CLEARS a REMOVE mask left\n * by {@link removeAppEnv}. So setting a value is also the way to un-block a\n * masked name, and a name is only ever one of plain / secret / masked.\n */\n async setAppEnv(\n workspaceId: string,\n alias: string,\n name: string,\n value: string,\n options?: RequestOptions,\n ): Promise<EnvVar> {\n const data = await this.client.mutate(\n ops.SetAppEnvDocument,\n { workspaceID: workspaceId, alias, name, value },\n options,\n );\n return data.setAppEnv.env;\n }\n\n /**\n * Sets a secret for ONE alias, overriding the workspace default.\n *\n * Like {@link setAppEnv}, this deletes a plain app var of the same name and\n * clears a REMOVE mask for it.\n */\n async setAppSecret(\n workspaceId: string,\n alias: string,\n name: string,\n value: string,\n options?: RequestOptions,\n ): Promise<EnvVar> {\n const data = await this.client.mutate(\n ops.SetAppSecretDocument,\n { workspaceID: workspaceId, alias, name, value },\n options,\n );\n return data.setAppSecret.env;\n }\n\n /**\n * REMOVE: blocks this name for the app entirely — the app override, the\n * workspace default, and integration enrichment. Not the same as deleting an\n * override; use {@link inheritAppEnv} for that.\n *\n * This WRITES A MASK, and the mask is a real, persistent row. Two things\n * follow that surprise people:\n *\n * - It is written even when nothing was inherited. Masking a name that no\n * workspace default and no integration ever provided is not a no-op; it\n * leaves a tombstone that keeps blocking the name if a default appears\n * later. Clear it with {@link inheritAppEnv}.\n * - It COSTS A SLOT. A workspace gets 128 env entries total — that budget\n * is shared across the workspace defaults AND every app scope combined,\n * not 128 per scope — and masks count toward it just like values do.\n * Masking names in a loop can exhaust the workspace's env budget.\n *\n * Returns `false` when the exact mask was already present (a second call for\n * the same name), per the {@link deleteEnv} `ok: false` convention. It\n * returns `true` when it had something to change — including converting an\n * existing override into a mask.\n */\n async removeAppEnv(\n workspaceId: string,\n alias: string,\n name: string,\n options?: RequestOptions,\n ): Promise<boolean> {\n const data = await this.client.mutate(\n ops.RemoveAppEnvDocument,\n { workspaceID: workspaceId, alias, name },\n options,\n );\n return data.removeAppEnv.ok;\n }\n\n /**\n * INHERIT: clears the app override/mask so workspace and integration values\n * apply again. This is the undo for both {@link setAppEnv} and\n * {@link removeAppEnv}.\n *\n * Returns `false` when there was no override and no mask to clear — nothing\n * to do, not a failure. See {@link deleteEnv}.\n */\n async inheritAppEnv(\n workspaceId: string,\n alias: string,\n name: string,\n options?: RequestOptions,\n ): Promise<boolean> {\n const data = await this.client.mutate(\n ops.InheritAppEnvDocument,\n { workspaceID: workspaceId, alias, name },\n options,\n );\n return data.inheritAppEnv.ok;\n }\n\n /** The effective env view for one alias: overrides, inherited and masked. */\n async listAppEnv(\n workspaceId: string,\n alias: string,\n options?: RequestOptions,\n ): Promise<EnvVar[]> {\n const data = await this.client.query(\n ops.ListAppEnvDocument,\n { workspaceID: workspaceId, alias },\n options,\n );\n return data.appEnv;\n }\n\n /* -------------------------------------------------- releases & rollback */\n\n /**\n * An alias's terminal release history, newest first.\n *\n * Exactly one entry has `aliasHeld: true` — the live release. FAILED entries\n * appear on purpose (they are rejected promotions, so a kept-live previous\n * release is never mistaken for a silent fallback) and cannot be rolled back\n * to. Retention keeps only the most recent few per alias, default 5.\n */\n async listReleases(alias: string, options?: RequestOptions): Promise<Deployment[]> {\n const data = await this.client.query(ops.ListReleasesDocument, { alias }, options);\n return data.deploymentReleases;\n }\n\n /**\n * Rolls an alias back to a prior release, handling the whole compare-and-swap\n * protocol in one call.\n *\n * The server requires the caller to prove it observed the current state: you\n * must pass the live release's id AND its opaque `aliasRevision`, and the\n * swap fails if either changed since you listed — including same-id ABA. So\n * this method does the full dance: list releases, find the `aliasHeld` entry,\n * pick the target, and submit both guard values.\n *\n * On a rejected guard it re-lists and retries (default once). The TARGET is\n * pinned across retries while the guard is refreshed, so a concurrent deploy\n * can never redirect the rollback to a different release than the one chosen.\n *\n * ```ts\n * await unfazed.rollback({ alias: \"my-app\" }); // undo last deploy\n * await unfazed.rollback({ alias: \"my-app\", to: relId }); // to a specific release\n * await unfazed.rollback({ alias: \"my-app\", to: relId, expectedCurrentId: liveId });\n * ```\n *\n * ⚠️ **A bare `rollback({ alias })` is a TOGGLE, not an idempotent step.**\n * It means \"restore the most recent READY release that is not the live one\",\n * which is a different release each time the alias moves. Run the same\n * script twice and the second run rolls back the rollback — A → B → A → B,\n * forever, with each hop a real alias swap. Nothing errors, because every\n * individual call did exactly what it was asked.\n *\n * In anything re-runnable — a retry loop, a CI job, an agent that might redo\n * a step — pin the outcome instead:\n *\n * - `to:` names the release you want live, so re-running is a no-op-ish\n * convergence rather than a flip (a second run then reports the target\n * already holds the alias instead of moving it);\n * - `expectedCurrentId:` states what you expect to be live now, so a second\n * run fails loudly instead of silently undoing the first.\n */\n async rollback(options: RollbackOptions): Promise<Deployment> {\n const { alias, signal, expectedCurrentId } = options;\n // A caller-supplied precondition and the CAS retry are mutually exclusive:\n // retrying re-guards against whatever holds the alias NOW, which is the\n // one thing `expectedCurrentId` exists to refuse.\n const retries = expectedCurrentId === undefined ? (options.retries ?? 1) : 0;\n const requestOptions: RequestOptions = signal ? { signal } : {};\n\n let targetId = options.to;\n\n for (let attempt = 0; ; attempt++) {\n const releases = await this.listReleases(alias, requestOptions);\n if (releases.length === 0) {\n throw new UnfazedNotFoundError(`unfazed: alias \"${alias}\" has no release history`);\n }\n\n const current = releases.find((r) => r.aliasHeld);\n if (!current) {\n throw new UnfazedNotFoundError(\n `unfazed: alias \"${alias}\" has no current release holding the alias`,\n );\n }\n\n // The caller's precondition, checked before anything is sent. Failing\n // here rather than at the server keeps a violated expectation from\n // costing an alias swap, and reports the holder we actually observed.\n if (expectedCurrentId !== undefined && current.id !== expectedCurrentId) {\n throw new UnfazedConflictError(\n `unfazed: alias \"${alias}\" is held by ${current.id}, not the expected ` +\n `${expectedCurrentId} — it moved since you read it; re-read and decide again`,\n [],\n );\n }\n\n // Pin the target on the first pass so a retry refreshes only the guard.\n if (targetId === undefined) {\n const previous = releases.find((r) => r.id !== current.id && r.status === \"READY\");\n if (!previous) {\n throw new UnfazedNotFoundError(\n `unfazed: alias \"${alias}\" has no prior READY release to roll back to ` +\n `(history: ${releases.map((r) => `${r.id}:${r.status}`).join(\", \")})`,\n );\n }\n targetId = previous.id;\n }\n\n const target = releases.find((r) => r.id === targetId);\n if (!target) {\n throw new UnfazedNotFoundError(\n `unfazed: release ${targetId} is not in alias \"${alias}\"'s history ` +\n `(it may have been pruned; retention keeps only the most recent few)`,\n );\n }\n if (target.id === current.id) {\n throw new UnfazedConflictError(\n `unfazed: release ${targetId} already holds alias \"${alias}\"`,\n [],\n );\n }\n if (target.status !== \"READY\") {\n throw new UnfazedConflictError(\n `unfazed: release ${targetId} is ${target.status}, only READY releases can be restored`,\n [],\n );\n }\n\n try {\n const data = await this.client.mutate(\n ops.RollbackDocument,\n {\n deploymentID: target.id,\n expectedCurrentDeploymentID: current.id,\n expectedCurrentAliasRevision: current.aliasRevision,\n },\n requestOptions,\n );\n return data.rollbackDeployment;\n } catch (e) {\n const retryable =\n e instanceof UnfazedGraphQLError && looksLikeCASConflict(e.errors) && attempt < retries;\n if (!retryable) {\n if (e instanceof UnfazedGraphQLError && looksLikeCASConflict(e.errors)) {\n throw new UnfazedConflictError(\n `unfazed: rollback of \"${alias}\" lost the compare-and-swap after ${\n attempt + 1\n } attempt(s) — the alias is being deployed concurrently. ${e.message}`,\n e.errors,\n );\n }\n throw e;\n }\n // Loop: re-list, rebuild the guard, keep the same target.\n }\n }\n }\n\n /* --------------------------------------------------------------- agent runs\n *\n * A run is the past-tense counterpart to a deployment: boot a fresh VM off\n * the box image, hand it a prompt, let a harness work for up to an hour,\n * keep the transcript, meter what it cost, reap the VM. Deployments answer\n * \"what is running\"; runs answer \"what happened\". Inside a run, `new\n * Unfazed()` is already authenticated — the platform injects\n * UNFZ_API_TOKEN / UNFZ_API_URL, at most the parent's scopes, revoked when\n * the run settles.\n */\n\n /**\n * Starts an agent run.\n *\n * Resolves once the VM has started (status RUNNING) — or, on a boot\n * failure, once the run has already settled FAILED with `error` set. A\n * boot failure is a normal return value here, not a thrown error, with or\n * without `wait`.\n *\n * ```ts\n * const run = await unfazed.createRun({\n * workspaceId: ws.id,\n * harness: \"claude-code\",\n * prompt: \"Fix the failing test in test/foo.test.ts and open a PR.\",\n * wait: true,\n * });\n * console.log(run.status, run.usage.mibSeconds);\n * ```\n *\n * With `wait: true` this additionally polls a RUNNING run through to a\n * terminal status — see {@link waitForRun} for exactly what \"terminal\"\n * means and how a timeout is reported.\n */\n async createRun(options: CreateRunOptions): Promise<Run> {\n const {\n workspaceId,\n prompt,\n harness,\n command,\n setup,\n skills,\n verify,\n memoryMiB,\n maxSeconds,\n metadata,\n includeFiles,\n approval,\n mode,\n access,\n alias,\n parentRunId,\n wait,\n waitOptions,\n signal,\n } = options;\n const requestOptions: RequestOptions = signal ? { signal } : {};\n const data = await this.client.mutate(\n ops.CreateRunDocument,\n {\n input: {\n workspaceID: workspaceId,\n ...(prompt === undefined ? {} : { prompt }),\n ...(harness === undefined ? {} : { harness }),\n ...(command === undefined ? {} : { command }),\n ...(setup === undefined ? {} : { setup }),\n ...(skills === undefined ? {} : { skills }),\n ...(verify === undefined ? {} : { verify }),\n ...(memoryMiB === undefined ? {} : { memoryMiB }),\n ...(maxSeconds === undefined ? {} : { maxSeconds }),\n ...(metadata === undefined ? {} : { metadata }),\n ...(includeFiles === undefined ? {} : { includeFiles }),\n ...(approval === undefined ? {} : { approval }),\n ...(mode === undefined ? {} : { mode }),\n ...(access === undefined ? {} : { access }),\n ...(alias === undefined ? {} : { alias }),\n ...(parentRunId === undefined ? {} : { parentRunID: parentRunId }),\n },\n },\n requestOptions,\n );\n const run = data.createRun;\n // Unlike createDeployment (always BUILDING), createRun can come back\n // already terminal — a boot failure settles FAILED synchronously. Only\n // poll when there is actually something to wait for.\n if (!wait || isTerminalRunStatus(run.status)) return run;\n return this.waitForRun(run.id, {\n ...waitOptions,\n ...(signal ? { signal } : {}),\n });\n }\n\n /**\n * Polls a run until it leaves QUEUED/RUNNING, throwing only on timeout.\n *\n * Terminal is defined negatively — anything that is not QUEUED or RUNNING —\n * matching the platform's own status machine, so an unknown future status\n * still ends the wait instead of looping forever. **SUCCEEDED, FAILED and\n * CANCELLED are all returned normally**: a run that executed and exited\n * non-zero is a completed answer (read `run.error` / `run.exitCode`), not\n * an exception the way a FAILED deployment is. Only running out of time\n * throws, as {@link UnfazedRunError} with `reason: \"TIMEOUT\"`.\n */\n async waitForRun(runId: string, waitOptions: WaitOptions = {}): Promise<Run> {\n const resolved = resolveWaitOptions(waitOptions);\n const requestOptions: RequestOptions = resolved.signal ? { signal: resolved.signal } : {};\n let last: { id: string; status: RunStatus; error: string | null; exitCode: number | null } | null =\n null;\n\n await pollWithBackoff<true>(\n async () => {\n const data = await this.client.query(ops.PollRunDocument, { id: runId }, requestOptions);\n const r = data.run;\n last = r;\n if (isTerminalRunStatus(r.status)) return { done: true, value: true };\n return { done: false };\n },\n resolved,\n () =>\n new UnfazedRunError(\n \"TIMEOUT\",\n runId,\n last,\n `unfazed: run ${runId} still ${(last as { status?: string } | null)?.status ?? \"QUEUED\"} after ${resolved.timeoutMs}ms`,\n ),\n );\n\n return this.getRun(runId, requestOptions);\n }\n\n /** Reads one run by id. Throws if it does not exist or is not visible to you. */\n async getRun(runId: string, options?: RequestOptions): Promise<Run> {\n const data = await this.client.query(ops.GetRunDocument, { id: runId }, options);\n return data.run;\n }\n\n /**\n * The harness presets a run may name (`createRun({ harness })`): name,\n * title, what it is, and the workspace secrets it requires (set them with\n * {@link Unfazed.setSecret} before the run). Empty when the node's box\n * image carries no catalogue.\n */\n async listRunHarnesses(options?: RequestOptions): Promise<RunHarness[]> {\n const data = await this.client.query(ops.ListRunHarnessesDocument, {}, options);\n return data.runHarnesses;\n }\n\n /** Your agent runs, newest first, optionally filtered by workspace/status. */\n async listRuns(filter: ListRunsFilter = {}, options?: RequestOptions) {\n const { workspaceId, status, limit, offset } = filter;\n const data = await this.client.query(\n ops.ListRunsDocument,\n {\n input: {\n ...(workspaceId === undefined ? {} : { workspaceID: workspaceId }),\n ...(status === undefined ? {} : { status }),\n ...(limit === undefined ? {} : { limit }),\n ...(offset === undefined ? {} : { offset }),\n },\n },\n options,\n );\n return data.runs;\n }\n\n /**\n * Stops a run: a QUEUED run is cancelled at once, a RUNNING run's VM is\n * killed and the run settles CANCELLED shortly after (`waitForRun` to\n * observe it). Idempotent on an already-CANCELLED run; a run that has\n * already SUCCEEDED or FAILED cannot be cancelled and the server rejects\n * the call (thrown as {@link UnfazedGraphQLError}) — check `status` first\n * when that is a routine case for you.\n */\n async cancelRun(runId: string, options?: RequestOptions): Promise<Run> {\n const data = await this.client.mutate(ops.CancelRunDocument, { id: runId }, options);\n return data.cancelRun;\n }\n\n /**\n * Continues a FINISHED run with a new instruction: a new run in the same\n * workspace that inherits the parent's harness (or command), setup, skills\n * and approval, with the parent's task, outcome and the end of its\n * transcript prepended to `prompt` as context. This is how a plan is\n * approved — `createRun({ mode: \"plan\" })` writes the plan, `followUpRun`\n * with the go-ahead executes it — and how work continues after a run\n * exited. The new run carries `parentRunID` and `depth`; chains are capped\n * server-side. A live run cannot be followed up (the server refuses):\n * answer it or wait for it.\n *\n * ```ts\n * const plan = await unfazed.createRun({ workspaceId, harness: \"claude-code\", prompt: \"plan the migration\", mode: \"plan\", wait: true });\n * const done = await unfazed.followUpRun(plan.id, { prompt: \"go ahead\", wait: true });\n * ```\n */\n async followUpRun(runId: string, options: FollowUpRunOptions): Promise<Run> {\n const { prompt, mode, approval, maxSeconds, metadata, wait, waitOptions, signal } = options;\n const requestOptions: RequestOptions = signal ? { signal } : {};\n const data = await this.client.mutate(\n ops.FollowUpRunDocument,\n {\n input: {\n runID: runId,\n prompt,\n ...(mode === undefined ? {} : { mode }),\n ...(approval === undefined ? {} : { approval }),\n ...(maxSeconds === undefined ? {} : { maxSeconds }),\n ...(metadata === undefined ? {} : { metadata }),\n },\n },\n requestOptions,\n );\n const run = data.followUpRun;\n if (!wait || isTerminalRunStatus(run.status)) return run;\n return this.waitForRun(run.id, { ...waitOptions, ...(signal ? { signal } : {}) });\n }\n\n /**\n * Answers a BLOCKED run's pending question (`run.question`); the run\n * resumes with the text. For a question with `options`, answer with one\n * of them. Only a BLOCKED run accepts an answer — anything else is\n * refused by the server.\n *\n * A run blocks when the agent inside calls `request_human_input`, or when\n * it was created with `approval: \"human\"` and its harness asks permission\n * for a guarded action. `waitForRun` keeps waiting through BLOCKED (it is\n * not terminal); poll `getRun` and look at `question` to notice one.\n */\n async answerRun(runId: string, answer: string, options?: RequestOptions): Promise<Run> {\n const data = await this.client.mutate(ops.AnswerRunDocument, { id: runId, answer }, options);\n return data.answerRun;\n }\n\n /** A run's own history, oldest first (started, cancel requested, settled). */\n async runEvents(runId: string, input: { limit?: number } = {}, options?: RequestOptions) {\n const data = await this.client.query(\n ops.RunEventsDocument,\n { runID: runId, limit: input.limit ?? null },\n options,\n );\n return data.runEvents;\n }\n\n /**\n * The live tail of a RUNNING run's console. Once the run has settled this\n * comes back empty with `running: false` — read {@link runTranscript}\n * instead, which is the stored, durable copy.\n */\n async runConsole(runId: string, input: { tailBytes?: number } = {}, options?: RequestOptions) {\n const data = await this.client.query(\n ops.RunConsoleDocument,\n { id: runId, tailBytes: input.tailBytes ?? null },\n options,\n );\n return data.runConsole;\n }\n\n /**\n * The bounded end of a finished run's stored transcript (secrets\n * redacted). `available` is false until the run settles and the transcript\n * is copied out of the VM's console file — check `run.transcriptAvailable`\n * or poll this after {@link waitForRun} resolves.\n */\n async runTranscript(runId: string, input: { tailBytes?: number } = {}, options?: RequestOptions) {\n const data = await this.client.query(\n ops.RunTranscriptDocument,\n { id: runId, tailBytes: input.tailBytes ?? null },\n options,\n );\n return data.runTranscript;\n }\n\n /* -------------------------------------------------------------- internals */\n\n /**\n * Finds a visible workspace by name, the way the server compares names.\n *\n * The server rejects duplicates with Go's `strings.EqualFold`, so matching\n * must be case-insensitive here too or `ensureWorkspace` would try to create\n * a \"new\" workspace the server considers a duplicate. An exact-case hit wins\n * over a folded one, which only matters if a name ever slipped past the\n * uniqueness check.\n */\n async #findWorkspaceByName(\n name: string,\n options?: RequestOptions,\n ): Promise<Workspace | undefined> {\n const workspaces = await this.listWorkspaces(options);\n const folded = name.toLowerCase();\n return (\n workspaces.find((w) => w.name === name) ??\n workspaces.find((w) => w.name.toLowerCase() === folded)\n );\n }\n\n async #writeBatch(\n workspaceId: string,\n batch: NormalizedFile[],\n signal?: AbortSignal,\n ): Promise<WorkspaceFile[]> {\n const varDefs = [\"$workspaceID: ID!\"];\n const fields: string[] = [];\n const variables: Record<string, string> = { workspaceID: workspaceId };\n\n batch.forEach((file, i) => {\n variables[`p${i}`] = file.path;\n variables[`c${i}`] = file.content;\n varDefs.push(`$p${i}: String!`, `$c${i}: String!`);\n fields.push(\n file.kind === \"text\"\n ? ` f${i}: writeWorkspaceTextFile(input: { workspaceID: $workspaceID, path: $p${i}, text: $c${i} }) { file { ${FILE_SELECTION} } }`\n : ` f${i}: writeWorkspaceBase64File(input: { workspaceID: $workspaceID, path: $p${i}, contentBase64: $c${i} }) { file { ${FILE_SELECTION} } }`,\n );\n });\n\n // Built at runtime rather than codegen'd: the field COUNT varies per call,\n // so no static document can express it. The field shapes are still fixed\n // and typed below, and each individual mutation is codegen-validated by its\n // single-file twin in operations.ts.\n const document = `mutation SdkWriteFilesBatch(${varDefs.join(\", \")}) {\\n${fields.join(\"\\n\")}\\n}`;\n\n const data = await this.client.mutate<\n Record<string, { file: WorkspaceFile }>,\n typeof variables\n >(document, variables, signal ? { signal } : {});\n\n return batch.map((_, i) => data[`f${i}`]!.file);\n }\n}\n\nconst FILE_SELECTION = \"path sizeBytes size sha256 updatedAt\";\nconst ENV_SELECTION = \"name value secret alias inherited masked updatedAt\";\n\n/**\n * Terminal = anything but QUEUED or RUNNING, defined negatively exactly like\n * the platform's own `IsTerminalRunStatus` — so a future status this SDK does\n * not know about yet still ends a wait instead of polling forever.\n */\nfunction isTerminalRunStatus(status: string): boolean {\n return status !== \"QUEUED\" && status !== \"RUNNING\";\n}\n\ninterface NormalizedFile {\n path: string;\n kind: \"text\" | \"base64\";\n content: string;\n}\n\nfunction normalizeFile(path: string, content: FileContent): NormalizedFile {\n if (typeof content === \"string\") return { path, kind: \"text\", content };\n if (\"text\" in content) return { path, kind: \"text\", content: content.text };\n if (\"base64\" in content) return { path, kind: \"base64\", content: content.base64 };\n return { path, kind: \"base64\", content: toBase64(content.bytes) };\n}\n\nfunction toBase64(input: Uint8Array | ArrayBuffer): string {\n const bytes = input instanceof Uint8Array ? input : new Uint8Array(input);\n // Node/Bun have Buffer; browsers and workers do not.\n const maybeBuffer = (globalThis as { Buffer?: { from(b: Uint8Array): { toString(e: string): string } } })\n .Buffer;\n if (maybeBuffer) return maybeBuffer.from(bytes).toString(\"base64\");\n\n let binary = \"\";\n const CHUNK = 0x8000; // avoid blowing the argument limit on large files\n for (let i = 0; i < bytes.length; i += CHUNK) {\n binary += String.fromCharCode(...bytes.subarray(i, i + CHUNK));\n }\n return btoa(binary);\n}\n\nconst utf8 = new TextEncoder();\n\n/**\n * UTF-8 byte length, which is what the wire actually costs.\n *\n * `String.length` counts UTF-16 code units and undercounts by up to 3x on\n * non-ASCII text — a CJK or emoji-heavy payload would sail past a budget it\n * had already blown.\n */\nfunction utf8Bytes(s: string): number {\n return utf8.encode(s).length;\n}\n\n/**\n * Splits files into request-sized batches.\n *\n * Closes a batch on whichever limit trips first — count or bytes — but always\n * emits at least one file per batch, so a single file larger than\n * `maxBatchBytes` still gets sent (and fails loudly at the server's limit)\n * rather than silently vanishing into an empty batch.\n */\nfunction chunkFiles(\n files: NormalizedFile[],\n batchSize: number,\n maxBatchBytes: number,\n): NormalizedFile[][] {\n const batches: NormalizedFile[][] = [];\n let current: NormalizedFile[] = [];\n let bytes = 0;\n\n for (const file of files) {\n // Measured once per file, so the encode cost is linear in the payload the\n // request was going to carry anyway.\n const size = utf8Bytes(file.content) + utf8Bytes(file.path);\n if (current.length > 0 && (current.length >= batchSize || bytes + size > maxBatchBytes)) {\n batches.push(current);\n current = [];\n bytes = 0;\n }\n current.push(file);\n bytes += size;\n }\n if (current.length > 0) batches.push(current);\n return batches;\n}\n"]}
@@ -0,0 +1,23 @@
1
+ /** Environment as the World reads it. */
2
+ export type WorkflowEnv = Record<string, string | undefined>;
3
+ /**
4
+ * Connection string precedence. `DATABASE_URL_UNPOOLED` comes before
5
+ * `DATABASE_URL` because a Neon pooled (PgBouncer, transaction mode) URL
6
+ * cannot hold the `LISTEN` the streamer and `waitForTerminalStatus` use.
7
+ */
8
+ export declare const DATABASE_URL_VARS: readonly ["WORKFLOW_POSTGRES_URL", "DATABASE_URL_UNPOOLED", "DATABASE_URL"];
9
+ /** Non-empty value of `name`, or undefined. */
10
+ export declare function envValue(env: WorkflowEnv, name: string): string | undefined;
11
+ /** The first database URL variable that is set, in {@link DATABASE_URL_VARS} order. */
12
+ export declare function resolveDatabaseUrl(env: WorkflowEnv): string | undefined;
13
+ /**
14
+ * Makes a libpq-style URL mean the same thing to node-postgres.
15
+ *
16
+ * libpq reads `sslmode=require` as "encrypt, do not verify the certificate";
17
+ * node-postgres reads it as `verify-full` unless `uselibpqcompat=true` is set,
18
+ * and then refuses the unfazed Postgres integration's self-signed certificate.
19
+ * An explicit `uselibpqcompat` is left alone.
20
+ */
21
+ export declare function withLibpqCompat(connectionString: string): string;
22
+ /** Positive integer value of `name`, or undefined. */
23
+ export declare function envPositiveInt(env: WorkflowEnv, name: string): number | undefined;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Connection string precedence. `DATABASE_URL_UNPOOLED` comes before
3
+ * `DATABASE_URL` because a Neon pooled (PgBouncer, transaction mode) URL
4
+ * cannot hold the `LISTEN` the streamer and `waitForTerminalStatus` use.
5
+ */
6
+ export const DATABASE_URL_VARS = ["WORKFLOW_POSTGRES_URL", "DATABASE_URL_UNPOOLED", "DATABASE_URL"];
7
+ /** Non-empty value of `name`, or undefined. */
8
+ export function envValue(env, name) {
9
+ const value = env[name];
10
+ return value === undefined || value.trim() === "" ? undefined : value;
11
+ }
12
+ /** The first database URL variable that is set, in {@link DATABASE_URL_VARS} order. */
13
+ export function resolveDatabaseUrl(env) {
14
+ for (const name of DATABASE_URL_VARS) {
15
+ const value = envValue(env, name);
16
+ if (value)
17
+ return value;
18
+ }
19
+ return undefined;
20
+ }
21
+ /**
22
+ * Makes a libpq-style URL mean the same thing to node-postgres.
23
+ *
24
+ * libpq reads `sslmode=require` as "encrypt, do not verify the certificate";
25
+ * node-postgres reads it as `verify-full` unless `uselibpqcompat=true` is set,
26
+ * and then refuses the unfazed Postgres integration's self-signed certificate.
27
+ * An explicit `uselibpqcompat` is left alone.
28
+ */
29
+ export function withLibpqCompat(connectionString) {
30
+ let url;
31
+ try {
32
+ url = new URL(connectionString);
33
+ }
34
+ catch {
35
+ return connectionString;
36
+ }
37
+ if (url.searchParams.get("sslmode") !== "require" || url.searchParams.has("uselibpqcompat")) {
38
+ return connectionString;
39
+ }
40
+ url.searchParams.set("uselibpqcompat", "true");
41
+ return url.toString();
42
+ }
43
+ /** Positive integer value of `name`, or undefined. */
44
+ export function envPositiveInt(env, name) {
45
+ const parsed = Number.parseInt(env[name] ?? "", 10);
46
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;
47
+ }
48
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/workflow/config.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,uBAAuB,EAAE,uBAAuB,EAAE,cAAc,CAAU,CAAC;AAE7G,+CAA+C;AAC/C,MAAM,UAAU,QAAQ,CAAC,GAAgB,EAAE,IAAY;IACrD,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;IACxB,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;AACxE,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,kBAAkB,CAAC,GAAgB;IACjD,KAAK,MAAM,IAAI,IAAI,iBAAiB,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAClC,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC;IAC1B,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,gBAAwB;IACtD,IAAI,GAAQ,CAAC;IACb,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAClC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IACD,IAAI,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,SAAS,IAAI,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAC5F,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IACD,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;IAC/C,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;AACxB,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,cAAc,CAAC,GAAgB,EAAE,IAAY;IAC3D,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;IACpD,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACpE,CAAC","sourcesContent":["/** Environment as the World reads it. */\nexport type WorkflowEnv = Record<string, string | undefined>;\n\n/**\n * Connection string precedence. `DATABASE_URL_UNPOOLED` comes before\n * `DATABASE_URL` because a Neon pooled (PgBouncer, transaction mode) URL\n * cannot hold the `LISTEN` the streamer and `waitForTerminalStatus` use.\n */\nexport const DATABASE_URL_VARS = [\"WORKFLOW_POSTGRES_URL\", \"DATABASE_URL_UNPOOLED\", \"DATABASE_URL\"] as const;\n\n/** Non-empty value of `name`, or undefined. */\nexport function envValue(env: WorkflowEnv, name: string): string | undefined {\n const value = env[name];\n return value === undefined || value.trim() === \"\" ? undefined : value;\n}\n\n/** The first database URL variable that is set, in {@link DATABASE_URL_VARS} order. */\nexport function resolveDatabaseUrl(env: WorkflowEnv): string | undefined {\n for (const name of DATABASE_URL_VARS) {\n const value = envValue(env, name);\n if (value) return value;\n }\n return undefined;\n}\n\n/**\n * Makes a libpq-style URL mean the same thing to node-postgres.\n *\n * libpq reads `sslmode=require` as \"encrypt, do not verify the certificate\";\n * node-postgres reads it as `verify-full` unless `uselibpqcompat=true` is set,\n * and then refuses the unfazed Postgres integration's self-signed certificate.\n * An explicit `uselibpqcompat` is left alone.\n */\nexport function withLibpqCompat(connectionString: string): string {\n let url: URL;\n try {\n url = new URL(connectionString);\n } catch {\n return connectionString;\n }\n if (url.searchParams.get(\"sslmode\") !== \"require\" || url.searchParams.has(\"uselibpqcompat\")) {\n return connectionString;\n }\n url.searchParams.set(\"uselibpqcompat\", \"true\");\n return url.toString();\n}\n\n/** Positive integer value of `name`, or undefined. */\nexport function envPositiveInt(env: WorkflowEnv, name: string): number | undefined {\n const parsed = Number.parseInt(env[name] ?? \"\", 10);\n return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;\n}\n"]}
@@ -0,0 +1,33 @@
1
+ import { UnfazedError } from "../errors.js";
2
+ /**
3
+ * Why the unfazed World refused or failed a call.
4
+ *
5
+ * The queue codes are the wire contract's `error` values; the rest are the
6
+ * World's own configuration problems.
7
+ */
8
+ export type UnfazedWorkflowErrorCode =
9
+ /** No Postgres connection string in the environment. */
10
+ "no_database"
11
+ /** `UNFZ_STATE_URL` / `UNFZ_STATE_TOKEN` missing: not running inside an unfazed service. */
12
+ | "no_platform"
13
+ /** The platform answered 404 on `/queue/v1`: it has no queue yet. */
14
+ | "queue_not_supported"
15
+ /** 409: this app's queue cannot live here (replicas, App State elsewhere). */
16
+ | "queue_unavailable" | "invalid_request" | "unauthorized" | "payload_too_large" | "quota_exceeded"
17
+ /** 503 or a network failure that outlasted the retry budget. */
18
+ | "unavailable"
19
+ /** Any other status. */
20
+ | "http_error";
21
+ /** Everything `unfazed/workflow` throws on purpose. */
22
+ export declare class UnfazedWorkflowError extends UnfazedError {
23
+ readonly code: UnfazedWorkflowErrorCode;
24
+ /** HTTP status from the platform, when the error came from one. */
25
+ readonly status: number | undefined;
26
+ /** Repeating the same call (same idempotency keys) may succeed. */
27
+ readonly retryable: boolean;
28
+ constructor(code: UnfazedWorkflowErrorCode, message: string, options?: {
29
+ status?: number;
30
+ retryable?: boolean;
31
+ cause?: unknown;
32
+ });
33
+ }
@@ -0,0 +1,16 @@
1
+ import { UnfazedError } from "../errors.js";
2
+ /** Everything `unfazed/workflow` throws on purpose. */
3
+ export class UnfazedWorkflowError extends UnfazedError {
4
+ code;
5
+ /** HTTP status from the platform, when the error came from one. */
6
+ status;
7
+ /** Repeating the same call (same idempotency keys) may succeed. */
8
+ retryable;
9
+ constructor(code, message, options) {
10
+ super(message, options?.cause === undefined ? undefined : { cause: options.cause });
11
+ this.code = code;
12
+ this.status = options?.status;
13
+ this.retryable = options?.retryable ?? false;
14
+ }
15
+ }
16
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/workflow/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AA0B5C,uDAAuD;AACvD,MAAM,OAAO,oBAAqB,SAAQ,YAAY;IAC3C,IAAI,CAA2B;IACxC,mEAAmE;IAC1D,MAAM,CAAqB;IACpC,mEAAmE;IAC1D,SAAS,CAAU;IAE5B,YACE,IAA8B,EAC9B,OAAe,EACf,OAAmE;QAEnE,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;QACpF,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,CAAC;QAC9B,IAAI,CAAC,SAAS,GAAG,OAAO,EAAE,SAAS,IAAI,KAAK,CAAC;IAC/C,CAAC;CACF","sourcesContent":["import { UnfazedError } from \"../errors.js\";\n\n/**\n * Why the unfazed World refused or failed a call.\n *\n * The queue codes are the wire contract's `error` values; the rest are the\n * World's own configuration problems.\n */\nexport type UnfazedWorkflowErrorCode =\n /** No Postgres connection string in the environment. */\n | \"no_database\"\n /** `UNFZ_STATE_URL` / `UNFZ_STATE_TOKEN` missing: not running inside an unfazed service. */\n | \"no_platform\"\n /** The platform answered 404 on `/queue/v1`: it has no queue yet. */\n | \"queue_not_supported\"\n /** 409: this app's queue cannot live here (replicas, App State elsewhere). */\n | \"queue_unavailable\"\n | \"invalid_request\"\n | \"unauthorized\"\n | \"payload_too_large\"\n | \"quota_exceeded\"\n /** 503 or a network failure that outlasted the retry budget. */\n | \"unavailable\"\n /** Any other status. */\n | \"http_error\";\n\n/** Everything `unfazed/workflow` throws on purpose. */\nexport class UnfazedWorkflowError extends UnfazedError {\n readonly code: UnfazedWorkflowErrorCode;\n /** HTTP status from the platform, when the error came from one. */\n readonly status: number | undefined;\n /** Repeating the same call (same idempotency keys) may succeed. */\n readonly retryable: boolean;\n\n constructor(\n code: UnfazedWorkflowErrorCode,\n message: string,\n options?: { status?: number; retryable?: boolean; cause?: unknown },\n ) {\n super(message, options?.cause === undefined ? undefined : { cause: options.cause });\n this.code = code;\n this.status = options?.status;\n this.retryable = options?.retryable ?? false;\n }\n}\n"]}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * `unfazed/workflow` — the unfazed World for Workflow SDK.
3
+ *
4
+ * ```ts
5
+ * import { setWorld } from "workflow/runtime";
6
+ * import { createWorld } from "unfazed/workflow";
7
+ *
8
+ * setWorld(createWorld()); // before the server serves
9
+ * ```
10
+ *
11
+ * With Nitro, add `"unfazed/workflow/nitro"` to `modules` instead; it does
12
+ * exactly that for you. Requires the optional peers `workflow`,
13
+ * `@workflow/world` and `@workflow/world-postgres`.
14
+ */
15
+ export { createWorld, LOCAL_DEPLOYMENT_ID } from "./world.js";
16
+ export type { UnfazedWorld, UnfazedWorldOptions } from "./world.js";
17
+ export { UnfazedWorkflowError } from "./errors.js";
18
+ export type { UnfazedWorkflowErrorCode } from "./errors.js";
19
+ export { DATABASE_URL_VARS, resolveDatabaseUrl, withLibpqCompat } from "./config.js";
20
+ export { applyPublicUrl } from "./public-url.js";
21
+ export type { PublicUrlResult } from "./public-url.js";
22
+ export type { WorkflowEnv } from "./config.js";
23
+ export { DELIVERY_HEADERS, QUEUE_API_PATH, verifyQueueToken } from "./queue.js";
24
+ export { createInspectHandler, INSPECT_BASE_PATH, INSPECT_CONTRACT_VERSION } from "./inspect.js";
25
+ export type { InspectHandlerOptions, InspectRunHandle } from "./inspect.js";
26
+ export type { InspectError, InspectValue } from "./inspect-render.js";
27
+ export type { QueueStats, WorkflowFetch } from "./queue.js";
28
+ export { MIGRATIONS_SCHEMA, MIGRATIONS_TABLE } from "./migration-types.js";
29
+ export type { WorkflowMigrations } from "./migration-types.js";
30
+ export { embeddedMigrations } from "./migrations.generated.js";