import { type IsolatePoolOptions } from "./pool"; import { type SourceFileOptions } from "./typescript"; import type { CreateContextOptions, IsolateOptions, RunReceiptOptions, RunWithMetricsResult, RunWithReceiptResult } from "./types"; export type RunIsolatedOptions = IsolateOptions & { /** * Options for the fresh context used by this one-shot run. */ context?: CreateContextOptions; /** * Host values to install on the context before the script runs. Values use * the same boundary rules as {@link Context.setGlobal}: primitives, * structured-cloneable data, {@link Reference}, and {@link ExternalCopy}. */ globals?: Record; /** * Per-run options. If omitted, policy/defaultRunOptions still apply. */ run?: RunReceiptOptions; /** * Return `{ result, metrics }` instead of the bare result. */ withMetrics?: boolean; /** * Return `{ result, receipt }` instead of the bare result. */ withReceipt?: boolean; }; export type RunIsolatedWithMetricsOptions = RunIsolatedOptions & { withMetrics: true; }; export type RunIsolatedWithReceiptOptions = RunIsolatedOptions & { withReceipt: true; }; export type RunIsolatedFileOptions = RunIsolatedOptions & { /** * Source-file loader/target options. The loader is inferred from the file * extension unless supplied. */ source?: SourceFileOptions; }; export type RunIsolatedFileWithMetricsOptions = RunIsolatedFileOptions & { withMetrics: true; }; export type RunIsolatedFileWithReceiptOptions = RunIsolatedFileOptions & { withReceipt: true; }; export type CreateIsolatedRunnerOptions = IsolateOptions & { /** * Pool controls for the reusable runner. `isolate` is derived from the * top-level options so policy/backend/memory defaults stay in one place. */ pool?: Omit; /** * Context defaults applied to every run unless a call overrides them. */ context?: CreateContextOptions; /** * Globals installed for every run. Per-call globals override by name. */ globals?: Record; /** * Run defaults applied when the call omits `run`. */ run?: RunReceiptOptions; }; export type IsolatedRunnerRunOptions = { /** * Pool key. Use tenant/session/conversation ids to reuse the same isolate * across related executions. Defaults to `"default"`. */ key?: string; context?: CreateContextOptions; globals?: Record; run?: RunReceiptOptions; withMetrics?: boolean; withReceipt?: boolean; }; export type IsolatedRunnerRunFileOptions = IsolatedRunnerRunOptions & { source?: SourceFileOptions; }; export type IsolatedRunnerRunWithMetricsOptions = IsolatedRunnerRunOptions & { withMetrics: true; }; export type IsolatedRunnerRunWithReceiptOptions = IsolatedRunnerRunOptions & { withReceipt: true; }; export type IsolatedRunnerCallOptions = { /** * Pool key. Use tenant/session/conversation ids to reuse the same isolate * and compiled callable across related executions. Defaults to `"default"`. */ key?: string; /** * Context options used when the callable is first compiled for this key/name. */ context?: CreateContextOptions; /** * Globals installed when the callable is first compiled for this key/name. * Dynamic inputs should usually be passed via `args`. */ globals?: Record; run?: RunReceiptOptions; withMetrics?: boolean; withReceipt?: boolean; }; export type IsolatedRunnerCallFileOptions = IsolatedRunnerCallOptions & { source?: SourceFileOptions; }; export type IsolatedRunnerCallWithMetricsOptions = IsolatedRunnerCallOptions & { withMetrics: true; }; export type IsolatedRunnerCallWithReceiptOptions = IsolatedRunnerCallOptions & { withReceipt: true; }; export type IsolatedRunnerPrecompileOptions = { /** * Pool key to warm. Defaults to `"default"`. */ key?: string; /** * Context options used when compiling the callable for this key/name. */ context?: CreateContextOptions; /** * Globals installed when compiling the callable for this key/name. */ globals?: Record; }; export type IsolatedRunnerPrecompileFileOptions = IsolatedRunnerPrecompileOptions & { source?: SourceFileOptions; }; export type IsolatedRunnerStats = { /** * Number of pooled isolate keys currently retained. */ poolSize: number; /** * Number of cached compiled callables across all keys. */ callableCacheSize: number; /** * Cached callable count by pool key. */ callablesByKey: Record; }; export type IsolatedRunner = { run: { (source: string, options: IsolatedRunnerRunWithReceiptOptions): Promise>; (source: string, options: IsolatedRunnerRunWithMetricsOptions): Promise>; (source: string, options?: IsolatedRunnerRunOptions): Promise; }; runFile: { (filePath: string | URL, options: IsolatedRunnerRunFileOptions & { withReceipt: true; }): Promise>; (filePath: string | URL, options: IsolatedRunnerRunFileOptions & { withMetrics: true; }): Promise>; (filePath: string | URL, options?: IsolatedRunnerRunFileOptions): Promise; }; call: { (name: string, source: string, args: unknown[], options: IsolatedRunnerCallWithReceiptOptions): Promise>; (name: string, source: string, args: unknown[], options: IsolatedRunnerCallWithMetricsOptions): Promise>; (name: string, source: string, args?: unknown[], options?: IsolatedRunnerCallOptions): Promise; }; callFile: { (name: string, filePath: string | URL, args: unknown[], options: IsolatedRunnerCallFileOptions & { withReceipt: true; }): Promise>; (name: string, filePath: string | URL, args: unknown[], options: IsolatedRunnerCallFileOptions & { withMetrics: true; }): Promise>; (name: string, filePath: string | URL, args?: unknown[], options?: IsolatedRunnerCallFileOptions): Promise; }; precompile: (name: string, source: string, options?: IsolatedRunnerPrecompileOptions) => Promise; precompileFile: (name: string, filePath: string | URL, options?: IsolatedRunnerPrecompileFileOptions) => Promise; stats: () => IsolatedRunnerStats; size: () => number; dispose: () => Promise; }; export declare function runIsolated(source: string, options: RunIsolatedWithMetricsOptions): Promise>; export declare function runIsolated(source: string, options: RunIsolatedWithReceiptOptions): Promise>; export declare function runIsolated(source: string, options?: RunIsolatedOptions): Promise; export declare function runIsolatedFile(filePath: string | URL, options: RunIsolatedFileWithMetricsOptions): Promise>; export declare function runIsolatedFile(filePath: string | URL, options: RunIsolatedFileWithReceiptOptions): Promise>; export declare function runIsolatedFile(filePath: string | URL, options?: RunIsolatedFileOptions): Promise; export declare const createIsolatedRunner: (options?: CreateIsolatedRunnerOptions) => IsolatedRunner;