import { l as ArtifactClient } from "./shared-C9CTqSgh.js"; import { t as AssetsClient } from "./shared-DwuIaYac.js"; import { n as GitClient } from "./shared-BTtKnEVB.js"; import { i as ChangeCursor, n as WorkspaceBackend, r as WorkspaceBackendHost } from "./shared-C-sNJ-xg.js"; //#region ../dofs/dist/sync/apply.d.ts interface SkippedEntry { path: string; mountRoot: string; op: "write" | "delete"; reason: "read-only"; } interface ApplyResult { applied: number; skipped: SkippedEntry[]; minted?: number; } //#endregion //#region src/runtime/output-tail.d.ts /** How much output to keep: at most `maxLines` lines and `maxBytes` bytes from the end. */ interface OutputLimits { /** The most lines kept. A positive integer. */ readonly maxLines: number; /** The most bytes kept. A positive integer. */ readonly maxBytes: number; } //#endregion //#region src/runtime/output-spool.d.ts /** Why a command's full output could not be saved to a file. */ declare class CommandOutputSaveFailed extends Error { readonly path: string; readonly cause: unknown; readonly _tag: "CommandOutputSaveFailed"; /** * @param path - The file the output was being written to. * @param cause - What the write failed with. */ constructor(path: string, cause: unknown); } /** The outcome of closing an output file. */ type CommandOutputSaveResult = { readonly _tag: "ok"; } | { readonly _tag: "err"; readonly error: CommandOutputSaveFailed; }; /** One file a command's output streams into. */ interface CommandOutputFile { /** Where the file is in the Workspace. */ readonly path: string; /** * Append a chunk. Resolves once the file can take more, so a command * that prints faster than storage writes waits instead of queueing * its output in memory. */ write(chunk: Uint8Array): Promise; /** Finish the file once the output ends. */ close(): Promise; } /** Where full output goes once it is too long to keep in a result. */ interface CommandOutputFiles { /** * Start a file for one stream of one execution. * * @param name - A file name unique to the execution and stream. * @returns The open file. */ open(name: string): CommandOutputFile; } /** * What a result says about output it cut. The kept part is the end of * the output; the full output is in `path` when it could be saved. */ type TruncatedOutput = { /** The full output is in `path`. */readonly status: "saved"; /** The Workspace file holding the full output, byte for byte. */ readonly path: string; /** Size of the full output in bytes. */ readonly totalBytes: number; /** Lines in the full output. */ readonly totalLines: number; /** One-based number of the first line kept. */ readonly firstLine: number; /** Whether the kept part starts partway through its first line. */ readonly partialLine: boolean; } | { /** The full output could not be saved; only the kept part is left. */readonly status: "not-saved"; /** Why saving failed. */ readonly reason: string; /** Size of the full output in bytes. */ readonly totalBytes: number; /** Lines in the full output. */ readonly totalLines: number; /** One-based number of the first line kept. */ readonly firstLine: number; /** Whether the kept part starts partway through its first line. */ readonly partialLine: boolean; }; //#endregion //#region src/runtime/runtime.d.ts interface WorkspaceRuntimeRouterOptions { backends: ReadonlyMap; backendHandle: (id: string) => Promise; resolveBackendId: (id: string | undefined) => string; output?: { readonly files: CommandOutputFiles; readonly limits: OutputLimits; }; } /** What a registered backend says about itself. */ interface WorkspaceBackendInfo { /** The id the backend is registered under. */ readonly id: string; /** * What `exec` source means on this backend: a shell command * (`"command"`) or module source (`"module"`). */ readonly protocol: "command" | "module"; /** Whether the backend takes structured `input` and returns a `result`. */ readonly callable: boolean; /** What the backend tells a model about itself. */ readonly description?: string; } declare class WorkspaceRuntime { #private; constructor(options: WorkspaceRuntimeRouterOptions); isCallable(id: string): boolean; backends(): WorkspaceBackendInfo[]; exec(source: string): Promise>; exec(source: string, options: WorkspaceRuntimeExecOptions<"utf8">): Promise>; exec(source: string, options: WorkspaceRuntimeExecOptions): Promise>; getExec(id: string): Promise>; getExec(id: string, options: WorkspaceRuntimeGetOptions<"utf8">): Promise>; getExec(id: string, options: WorkspaceRuntimeGetOptions): Promise>; /** * Resume or settle the runs a Durable Object restart interrupted. * Backends do this when they first connect, which the next runtime * call or `ready({ all: true })` triggers. Call this from an alarm to * resume runs without waiting for one. */ recover(): Promise; /** * Host module calls waiting for an answer, from `ctx.interrupt()`, * across every backend that supports it, oldest wait first. * Experimental: it may change in any release. */ pending(): Promise; /** * Answer a call waiting in `ctx.interrupt()`. The run resumes once * none of its calls are still waiting, and the call gets `answer` as * what `interrupt()` returns. Throws `ENOTWAITING` if the call isn't * waiting, for example because it was already answered or the run * was killed. Experimental: it may change in any release. */ respond(id: string, callId: string, answer: WorkspaceRuntimeValue, options?: { backend?: string; }): Promise; killExec(id: string, options?: WorkspaceRuntimeKillOptions): Promise; disposeExec(id: string, options?: WorkspaceRuntimeDisposeOptions): Promise; } //#endregion //#region src/shell.d.ts type ExecEncoding = "utf8" | undefined; type Chunk = E extends "utf8" ? string : Uint8Array; type WorkspaceExecEvent = { id: string; seq: number; name: "stdout"; value: Chunk; } | { id: string; seq: number; name: "stderr"; value: Chunk; } | { id: string; seq: number; name: "exit"; value: number; }; type ExecSyncResult = { status: "complete"; applied: number; skipped: SkippedEntry[]; } | { status: "pending"; applied: number; skipped: SkippedEntry[]; error?: string; backend?: string; runtimeId?: string; targetCursor?: ChangeCursor; }; type KillSignal = "SIGTERM" | "SIGKILL" | "SIGINT" | "SIGHUP"; //#endregion //#region src/runtime/types.d.ts type WorkspaceRuntimeAccess = "read" | "read-write"; /** Per-call context the backend passes to every host module function. */ interface WorkspaceModuleCallContext { /** Aborts when the call passes its deadline or the execution is cancelled. */ readonly signal: AbortSignal; /** Epoch milliseconds after which the caller stops waiting for this call. */ readonly deadline: number; /** Access level of the backend running the call. */ readonly access: WorkspaceRuntimeAccess; /** * Resolve a path the isolate passed against the backend's root. * Rejects paths that escape the root or pass through a symlink. * * @param path - An absolute path, or one relative to the backend root. * @param options - Set `allowMissing` when the path may not exist yet. * @returns The confined absolute path. */ resolvePath(path: string, options?: { readonly allowMissing?: boolean; }): Promise; /** * Identifies this call. When a replayable run is interrupted while the * call is in flight and runs it again on resume, the second call gets * the same id, so a function can use it as an idempotency key. */ readonly callId: string; /** * Pause the run until a person or another system answers, and return * the answer. The run is released while it waits, survives a deploy, * and resumes once `workspace.runtime.respond()` answers this call: * it replays to this call, and this function runs again with the same * `callId`, this time getting the answer straight away. Anything the * function does before `interrupt()` therefore runs twice, so keep it * safe to repeat. Only a run with `onInterrupt: "replay"` can wait; * anywhere else this throws. A call can interrupt once, and a second * `interrupt()` throws. Experimental: it may change in any release. * * ```ts * postComment: async ([issue, body], ctx) => { * const { approved } = await ctx.interrupt({ kind: "approval", issue, body }); * if (!approved) throw new Error("The comment was rejected."); * return github.comment(issue, body, { idempotencyKey: ctx.callId }); * } * ``` * * @param payload What the answer is for, as `pending()` lists it. */ interrupt(payload: WorkspaceRuntimeValue): Promise; } /** * One host function exported by a host module. * * `args` holds the arguments the isolate passed, decoded from the wire. * They come from untrusted code, so parse them before use. The function * may return a value or a promise of one. Arguments and results cross * the isolate boundary as real values through Workers RPC, not as * encoded text. The result must be JSON-compatible plain data: the * bridge checks it at runtime and treats `undefined` as `null`. */ type WorkspaceModuleFunction = (args: readonly WorkspaceRuntimeValue[], context: WorkspaceModuleCallContext) => unknown; /** Named functions a host module exports into the isolate. */ type WorkspaceModuleFunctions = Readonly>; /** Workspace services a host module factory can build its functions from. */ interface WorkspaceModuleHost { /** The Workspace's Git client. Throws on use when Git is not configured. */ readonly git: GitClient; /** The Workspace's Artifacts client. Throws on use when Artifacts is not configured. */ readonly artifacts: ArtifactClient; /** The Workspace runtime, for running commands on other backends. */ readonly runtime: WorkspaceRuntime; readonly assets?: AssetsClient; } /** * Builds a host module's functions from the Workspace's services. The * backend calls it once when it connects to its Workspace. The * prebuilt modules in `@cloudflare/computer/modules/*` are factories. */ interface WorkspaceModuleFactory { (host: WorkspaceModuleHost): WorkspaceModuleFunctions; /** * What the module does and how to call it, for a model. The * JavaScript backend adds it to its own description, which the exec * tool shows. Objects of functions are listed by their export names. */ readonly description?: string; } /** * A module caller source can import. * * - A string is JavaScript source bundled into the isolate, with no host access. * - An object of functions is a host module. Its functions run in the * Durable Object and each becomes a named export: * `{ "ws:weather": { forecast } }` lets code write * `import { forecast } from "ws:weather"`. * - A factory is a host module that needs the Workspace's Git client, * Artifacts client, or runtime, such as `createGitModule()`. * * Host modules must use a `ws:*` specifier. */ type WorkspaceModule = string | WorkspaceModuleFunctions | WorkspaceModuleFactory; type WorkspaceRuntimeValue = null | boolean | number | string | WorkspaceRuntimeValue[] | { [key: string]: WorkspaceRuntimeValue; }; interface WorkspaceRuntimeLoader { load(code: { compatibilityDate: string; compatibilityFlags?: string[]; limits?: { cpuMs?: number; }; mainModule: string; modules: Record; globalOutbound?: Fetcher | null; }): { getEntrypoint(name?: string, options?: { limits?: { cpuMs?: number; }; }): unknown; }; } type WorkspaceRuntimeStatus = "completed" | "failed" | "cancelled"; type RuntimeChunk = E extends "utf8" ? string : Uint8Array; type WorkspaceRuntimeEvent = { id: string; seq: number; name: "stdout"; value: RuntimeChunk; } | { id: string; seq: number; name: "stderr"; value: RuntimeChunk; } | { id: string; seq: number; name: "exit"; code: number; result?: WorkspaceRuntimeValue; /** Output that passed the limits, and where it was saved in full. */ truncated?: WorkspaceRuntimeTruncation; }; /** * Which streams of a run were cut to their last lines, and where each * was saved in full. A stream that fit its limits is absent. */ interface WorkspaceRuntimeTruncation { /** Present when stdout was cut. */ stdout?: TruncatedOutput; /** Present when stderr was cut. */ stderr?: TruncatedOutput; } interface WorkspaceRuntimeResult { status: WorkspaceRuntimeStatus; exitCode: number; stdout: E extends "utf8" ? string : Uint8Array; stderr: E extends "utf8" ? string : Uint8Array; value?: WorkspaceRuntimeValue; /** * Present when output passed the limits. `stdout` and `stderr` then * hold only the end of the output; the full output is in the file * each entry names. */ truncated?: WorkspaceRuntimeTruncation; pushed: number; pulled: number; skipped: SkippedEntry[]; sync: ExecSyncResult; } interface WorkspaceRuntimeExecOptions { id?: string; backend?: string; cwd?: string; encoding?: E; input?: WorkspaceRuntimeValue; env?: Record; stdin?: Uint8Array | string; timeoutMs?: number; sync?: "wait" | "defer"; /** * What happens to this run if the Durable Object restarts while it * runs, as on a deploy or crash. Overrides the backend's * `onInterrupt`. Backends that can't resume a run ignore it. */ onInterrupt?: WorkspaceRuntimeInterruptPolicy; /** * How much output `result()` keeps per stream. Output past it is cut * to its last lines and saved in full to a Workspace file. Overrides * the Workspace's `output` limits for this run; `false` keeps all * output and saves nothing. */ output?: WorkspaceRuntimeOutputOptions | false; } /** Per-run output limits. Fields left out use the Workspace's limits. */ interface WorkspaceRuntimeOutputOptions { /** The most lines kept per stream. Defaults to 2000. */ maxLines?: number; /** The most bytes kept per stream. Defaults to 64 KiB. */ maxBytes?: number; } interface WorkspaceRuntimeGetOptions { backend?: string; encoding?: E; resume?: "tail" | "full" | number; /** Output limits for this replay, as for `exec`. */ output?: WorkspaceRuntimeOutputOptions | false; } interface WorkspaceRuntimeKillOptions { backend?: string; signal?: KillSignal; } interface WorkspaceRuntimeDisposeOptions { backend?: string; } interface WorkspaceRuntimeExecHandle extends ReadableStream> { readonly id: string; readonly backend: string; result(): Promise>; kill(signal?: KillSignal): Promise; [Symbol.dispose](): void; } interface ModuleExecutionInput { id?: string; source: string; cwd?: string; input?: WorkspaceRuntimeValue; env?: Record; stdin?: Uint8Array | string; timeoutMs?: number; sync?: "wait" | "defer"; onInterrupt?: WorkspaceRuntimeInterruptPolicy; } /** * What a backend does with a run its Durable Object restarted under. * `fail` settles it as failed. `restart` runs it again from the start. * `replay` runs it again and answers the calls it already made from a * journal, so their effects aren't repeated. `restart` and `replay` are * experimental and may change in any release. */ type WorkspaceRuntimeInterruptPolicy = "fail" | "restart" | "replay"; /** * A host module call waiting for an answer, from `ctx.interrupt()`. * Experimental: it may change in any release. */ interface WorkspaceRuntimePendingCall { /** The execution the call belongs to. */ readonly id: string; readonly backend: string; /** Pass this to `respond()` to answer the call. */ readonly callId: string; /** What the call passed to `ctx.interrupt()`. */ readonly payload: WorkspaceRuntimeValue; /** When the call started waiting, in milliseconds since the epoch. */ readonly since: number; } interface ModuleExecutionEnvelope { id: string; runtimeId?: string; events: ReadableStream; sync?: { pushed: number; outcome: Promise<{ applied: number; skipped: SkippedEntry[]; sync: ExecSyncResult; }>; }; } interface WorkspaceModuleBackendHandle { exec(input: ModuleExecutionInput): Promise; getExec(input: { id: string; after?: number | "tail"; runtimeId?: string; }): Promise; killExec(input: { id: string; signal?: KillSignal; runtimeId?: string; }): Promise; disposeExec(input: { id: string; runtimeId?: string; }): Promise; recover?(): Promise; pending?(): Promise[]>; respond?(input: { id: string; callId: string; answer: WorkspaceRuntimeValue; }): Promise; close?(): Promise; } /** What a module backend receives when it connects to its Workspace. */ type WorkspaceModuleBackendHost = WorkspaceBackendHost & { /** The Workspace runtime, handed to host modules. */readonly runtime: WorkspaceRuntime; readonly assets?: AssetsClient; }; interface WorkspaceModuleBackend { readonly protocol: "module"; readonly id: string; readonly type: string; readonly callable?: boolean; /** What the backend tells a model about itself. Shown by the exec tool. */ readonly description?: string; connect(host: WorkspaceModuleBackendHost): Promise; } type WorkspaceRegisteredBackend = WorkspaceBackend | WorkspaceModuleBackend; //#endregion export { KillSignal as A, WorkspaceRuntimePendingCall as C, WorkspaceRuntimeValue as D, WorkspaceRuntimeTruncation as E, ApplyResult as F, SkippedEntry as I, WorkspaceBackendInfo as M, WorkspaceRuntime as N, ExecEncoding as O, TruncatedOutput as P, WorkspaceRuntimeOutputOptions as S, WorkspaceRuntimeStatus as T, WorkspaceRuntimeExecOptions as _, WorkspaceModuleBackendHandle as a, WorkspaceRuntimeKillOptions as b, WorkspaceModuleFactory as c, WorkspaceModuleHost as d, WorkspaceRegisteredBackend as f, WorkspaceRuntimeExecHandle as g, WorkspaceRuntimeEvent as h, WorkspaceModuleBackend as i, WorkspaceExecEvent as j, ExecSyncResult as k, WorkspaceModuleFunction as l, WorkspaceRuntimeDisposeOptions as m, ModuleExecutionInput as n, WorkspaceModuleBackendHost as o, WorkspaceRuntimeAccess as p, WorkspaceModule as r, WorkspaceModuleCallContext as s, ModuleExecutionEnvelope as t, WorkspaceModuleFunctions as u, WorkspaceRuntimeGetOptions as v, WorkspaceRuntimeResult as w, WorkspaceRuntimeLoader as x, WorkspaceRuntimeInterruptPolicy as y }; //# sourceMappingURL=shared-BP8PrtyI.d.ts.map