import type { Context } from "@earendil-works/chord/context"; import type { ConversationId, Extension, JsonObject, ToolExecutionApi } from "@earendil-works/pi-durable"; import type { FabricKernelRuntime } from "./runtime/kernel.js"; /** One granted action of a host provider. Arguments are the program's object, copied to plain JSON. */ export type FabricDurableAction = (args: JsonObject, call: { readonly api: ToolExecutionApi; readonly context: Context; }) => unknown | Promise; /** * A granted action with its replay rule. `repeatable: true` says running it twice does no harm (a read), so after a * restart an interrupted call simply runs again. Otherwise it counts as an effect: an intent is recorded before it runs, * and if a restart interrupts it, the program stops and the model is told it may have run. */ export interface FabricDurableActionEntry { readonly run: FabricDurableAction; readonly repeatable?: boolean; } /** A provider the host grants to programs, reachable as `.(args)` or `fabric.tools.call({ ref: ".", args })`. */ export interface FabricDurableProvider { readonly description?: string; /** A bare function is an effect (not repeatable). */ readonly actions: Readonly>; } /** Where an internal failure happened, for `onError`. Holds no program source or arguments. */ export interface FabricDurableErrorInfo { readonly conversationId: ConversationId; readonly callId: string; } export interface FabricExtensionOptions { /** Registry extension name; pi-durable reports section errors under it. Default `pi-fabric`. */ readonly name?: string; /** Tool name. Default `fabric_exec`. */ readonly toolName?: string; /** * Host tools programs may call, by name, out of the conversation's callable tools (`Agent.callable`). * Omitted: every callable tool. An empty list grants none. Never widens what the conversation allows. */ readonly tools?: readonly string[]; /** Fabric providers granted to programs. Omitted: none; every provider ref is refused. */ readonly providers?: Readonly>; /** Whole-program deadline in milliseconds, nested calls included. Default 30 000. */ readonly timeoutMs?: number; /** QuickJS heap limit in bytes. Default 64 MiB (67 108 864). */ readonly memoryLimitBytes?: number; /** Characters of `print()`/`console.*` output kept per program; more is cut with a notice. Default 20 000. */ readonly maxLogChars?: number; /** Characters of the whole result the model sees; more is cut with a notice. Default 40 000. */ readonly maxResultChars?: number; /** Largest JSON argument object, in UTF-8 bytes, a program may pass to one nested tool call or provider action. Default 262 144. */ readonly maxArgumentBytes?: number; /** Token budget (4 characters a token) for the tool declarations in the prompt section. Default 3 000. */ readonly sectionTokenBudget?: number; /** * A precompiled QuickJS wasm module for the default kernel, for hosts that cannot compile wasm from bytes * (Cloudflare Workers). It must be the `@jitl/quickjs-singlefile-mjs-release-sync` build this package depends on. * Ignored when `runtime` is set. Default: the module compiles the wasm it bundles. */ readonly quickJsWasmModule?: WebAssembly.Module; /** Kernel override, for example a sandbox in another isolate. Default: the in-process QuickJS kernel. */ readonly runtime?: FabricKernelRuntime; /** * Receives internal failures: the kernel failing to load, a bug in this extension, a granted provider action * throwing anything but `FabricDurableRefusal`. The model sees only a fixed error either way. Its own throw is * dropped. Default: none (pi-durable gives a tool no report channel). */ readonly onError?: (error: unknown, info: FabricDurableErrorInfo) => void; } /** The defaults `createFabricExtension` applies, for hosts that want to show or derive from them. */ export declare const FABRIC_DURABLE_DEFAULTS: Readonly<{ name: "pi-fabric"; toolName: "fabric_exec"; timeoutMs: 30000; memoryLimitBytes: number; maxLogChars: 20000; maxResultChars: 40000; maxArgumentBytes: number; sectionTokenBudget: 3000; }>; /** * Names what replays a recorded run: the journal format, this package's version and the guest engine. A resume * recorded under another value is refused. tests/durable-extension-replay.test.ts checks it against package.json. * The manifest is bundled as data, keeping Worker imports host-free and release versions in sync. */ export declare const FABRIC_DURABLE_ENGINE: string; /** * Refusal raised to the program; its message reaches the program as an Error. A granted provider action may throw * it to show the program a message; any other error becomes the fixed `Fabric action failed`. */ export declare class FabricDurableRefusal extends Error { readonly name = "FabricDurableRefusal"; } /** The fabric_exec tool and its prompt section, as one pi-durable extension. */ export declare function createFabricExtension(options?: FabricExtensionOptions): Extension; //# sourceMappingURL=durable-extension.d.ts.map