@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
59 lines • 2.7 kB
TypeScript
/**
* What a worker guest's blocking call carries besides its own fields:
* the shared memory it waits on for the answer, or the id the page's
* service worker holds it under where no memory is shared.
*/
export interface BridgeCall {
kind: 'vfs';
buffer?: SharedArrayBuffer;
id?: string;
}
/** The query parameter that marks a request for the service worker bridge. */
export declare const PARAM = "mirage-pyodide";
/** The header that carries an answer's format across the bridge. */
export declare const FORMAT = "x-mirage-pyodide-format";
/**
* A thrown value, told the way a command can print it. Most guest
* failures are Errors, but Emscripten and a crashed worker can surface a
* plain object, whose String() is `[object Object]`: its name and message
* say more, and failing those its keys.
*/
export declare function failureText(value: unknown): string;
/** Worker-only blocking half; the host always answers asynchronously. */
export declare function requestSync<T extends object>(post: (message: T & BridgeCall) => void, request: T, interrupt?: Int32Array): unknown;
/** Stream arbitrary-size responses through a bounded shared buffer. */
export declare function respond(buffer: SharedArrayBuffer, operation: () => Promise<unknown>): Promise<void>;
/**
* Worker-only blocking half where no memory is shared: the request goes
* to the host as a message, and the worker waits on a synchronous request
* that the page's service worker holds until the host's answer arrives.
*
* Args:
* post: sends the request to the host.
* request: the call to make.
* bridge: the page URL the service worker answers bridge requests at.
*/
export declare function requestOverBridge<T extends object>(post: (message: T & BridgeCall) => void, request: T, bridge: string): unknown;
/**
* Answer one bridged request: the service worker hands the answer to the
* worker's request waiting under `id`.
*
* Args:
* bridge: the page URL the service worker answers bridge requests at.
* id: the request being answered.
* operation: computes the answer.
*/
export declare function answerOverBridge(bridge: string, id: string, operation: () => Promise<unknown>): Promise<void>;
/**
* Whether the service worker controlling the page answers bridge requests.
*
* Args:
* bridge: the page URL the service worker answers bridge requests at.
*/
export declare function bridged(bridge: string): Promise<boolean>;
/**
* The page URL its service worker bridges file calls at, or null when no
* service worker controlling the page answers the bridge.
*/
export declare function serviceWorkerBridge(): Promise<string | null>;
//# sourceMappingURL=transport.d.ts.map