UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

153 lines • 8.24 kB
import type { util } from 'zod'; interface Exports { readonly memory: WebAssembly.Memory; mirage_rs_args(len: number): number; mirage_rs_open(kindLen: number, configLen: number): number; mirage_rs_input_capacity(): number; mirage_rs_input(handle: number): number; mirage_rs_feed(handle: number, len: number): number; mirage_rs_finish(handle: number): number; mirage_rs_wants(handle: number): number; mirage_rs_busy(handle: number): number; mirage_rs_cancel(handle: number): number; mirage_rs_drain(handle: number): number; mirage_rs_feed_input(handle: number, index: number, len: number): number; mirage_rs_end_input(handle: number, index: number): number; mirage_rs_begin(handle: number, len: number): number; mirage_rs_test(handle: number, len: number): number; mirage_rs_done(handle: number): number; mirage_rs_status(handle: number): number; mirage_rs_metadata(handle: number): number; mirage_rs_take_stderr(handle: number): number; mirage_rs_request(handle: number): number; mirage_rs_stage(handle: number, len: number): number; mirage_rs_respond(handle: number, replyLen: number): number; mirage_rs_output(handle: number): number; mirage_rs_output_len(handle: number): number; mirage_rs_error(handle: number): number; mirage_rs_error_len(handle: number): number; mirage_rs_error_status(handle: number): number; mirage_rs_close(handle: number): void; mirage_rs_open_count(): number; } /** The compiled module, for the page to hand the workers it starts without a copy. */ export declare function compiledModule(): Promise<WebAssembly.Module>; /** The compiled module, compiled now if no one has yet, for a caller that cannot wait. */ export declare function moduleSync(): WebAssembly.Module; /** Run on the module the page compiled: a browser worker's bundle leaves the bytes out. */ export declare function adoptModule(module: WebAssembly.Module): void; /** One mirage-rs stream: chunks go in, the bytes they produce come out. Mirrors Python's OpenStream. */ export declare class OpenStream { readonly movable: boolean; private readonly exports; private handle; private readonly capacity; constructor(exports: Exports, handle: number, movable?: boolean); /** Whether the stream is still open; a movable one closes when its instance retires. */ get live(): boolean; /** Push one chunk and return what it produced. */ feed(chunk: Uint8Array): Uint8Array; /** End the input and return what the stream held back. */ finish(): Uint8Array; /** Whether `drain` has work or output left. */ busy(): boolean; /** Stop processing and report whether bounded retirement is available. */ cancel(): boolean; /** Bounded steps of the work `busy` reports, up to a piece of output, and that output. */ drain(): Uint8Array; /** The input a multi-input stream needs next, null for none. */ wants(): number | null; /** Push one chunk of input `index` to a multi-input stream. */ feedInput(index: number, chunk: Uint8Array): Uint8Array; /** End input `index` of a multi-input stream. */ endInput(index: number): Uint8Array; /** Start the next input of a stream that reads one after another. */ begin(config: Readonly<Record<string, util.JSONType>>): void; /** Whether the input fed since the last answer, then `chunk`, passes the stream's test, in one call. */ test(chunk: Uint8Array): boolean; /** Whether the stream wants no more of the current input. */ done(): boolean; /** The command's exit status for the input so far. */ status(): number; /** The stream's current progress as its typed JSON record. */ metadata(): Uint8Array; /** What the stream wrote to stderr since the last call. */ takeStderr(): Uint8Array; /** The host operation the stream waits on and the bytes it carries, null while it waits on none. */ request(): [Record<string, util.JSONType>, Uint8Array] | null; /** Answer the request taken last with the host's reply and the bytes it carries. */ respond(reply: Readonly<Record<string, util.JSONType>>, data: Uint8Array | readonly Uint8Array[]): Uint8Array; close(): void; /** Close the handle, on the instance itself unless it trapped. */ drop(release: boolean): void; private guard; private push; private collect; } /** What a host made of one request: the reply, the bytes it carries, and output it wrote doing it. Mirrors Python's Served. */ export interface Served { readonly reply: Record<string, util.JSONType>; /** The bytes, or the parts they come in. */ readonly data?: Uint8Array | readonly Uint8Array[]; readonly output?: Uint8Array | AsyncIterable<Uint8Array> | null; } /** Serves the requests of a stream that reaches files and commands; `errors` gathers its stderr and theirs, in order. Mirrors Python's RequestHost. */ export interface RequestHost { readonly errors: { append(data: Uint8Array): Promise<void>; }; serve(request: Readonly<Record<string, util.JSONType>>, data: Uint8Array): Promise<Served>; } /** * Run a stream until it waits on neither work nor its host, a bounded call * at a time, serving each request it makes. Mirrors Python's serve_requests. */ export declare function serveRequests(stream: OpenStream, host: RequestHost, signal?: AbortSignal): AsyncGenerator<Uint8Array>; /** Open the mirage-rs stream `kind`. Mirrors Python's open_stream. */ export declare function openStream(kind: string, config: Readonly<Record<string, util.JSONType>>): Promise<OpenStream>; /** * Open a stream for synchronous pure utilities, initializing Wasm on first use. * A `movable` stream does not keep a grown instance alive: it closes when the * instance retires, and its owner opens it again. */ export declare function openStreamSync(kind: string, config: Readonly<Record<string, util.JSONType>>, movable?: boolean): OpenStream; /** * A movable synchronous stream for an object a cache keeps, such as a compiled * matcher: it opens again on the live instance once the one it was on retired, * and closes when its owner is collected. A retired stream is unregistered, so * it never holds its instance's memory. */ export declare class MovableStream { private readonly kind; private readonly config; private stream; constructor(kind: string, config: Readonly<Record<string, util.JSONType>>); /** Close the stream now rather than when its owner is collected. */ close(): void; /** The stream, opened again first when its instance retired. */ get live(): OpenStream; private open; } /** * Stream `source` through `kind`, one bounded chunk at a time. A refusal * throws StreamRefusal holding the output written before it, so the caller * records the failure before it passes that output on: a reader that stops * at the output would otherwise never see it. Mirrors Python's run_stream. */ export declare function runStream(kind: string, config: Readonly<Record<string, util.JSONType>>, source: Uint8Array | AsyncIterable<Uint8Array>, signal?: AbortSignal): AsyncIterable<Uint8Array>; /** * Feed a multi-input stream the input its `wants` names until it wants none, * handing on its output a bounded call at a time. Mirrors Python's * merge_output. */ export declare function mergeOutput(stream: OpenStream, read: (index: number) => Promise<Uint8Array | null>, signal?: AbortSignal): AsyncGenerator<Uint8Array>; /** * Feed a stream that reads its inputs one after another each source in turn, * through mergeOutput, and close the sources. Mirrors Python's chain_output. */ export declare function chainOutput(stream: OpenStream, sources: readonly (Uint8Array | AsyncIterable<Uint8Array>)[], signal?: AbortSignal): AsyncGenerator<Uint8Array>; export declare function streamOutputChunks(stream: OpenStream, source: Uint8Array | AsyncIterable<Uint8Array>, signal?: AbortSignal, ownsStream?: boolean): AsyncGenerator<Uint8Array>; /** Retire cancelled records through bounded calls before releasing the handle. */ export declare function closeStream(stream: OpenStream): Promise<void>; export {}; //# sourceMappingURL=stream.d.ts.map