type ReadFileSync = (path: string) => Uint8Array; type HostCallableDispatchFactory = (callable: (...args: unknown[]) => unknown) => (callId: number, payload: Uint8Array) => void; export declare function installReadFileSync(impl: ReadFileSync): void; export declare function installHostCallableDispatchFactory(factory: HostCallableDispatchFactory): void; export interface HandleKey { low: number; high: number; } /** Release one owned wire reference that never reached a host wrapper. */ export declare function _releaseWireHandle(key: HandleKey): void; export declare class BamlHandle { readonly handleType: number; private readonly rawKey; private readonly finalizerToken; private released; constructor(key: HandleKey, handleType: number); get key(): HandleKey; private assertLive; _keyForBridge(): bigint; clone(): BamlHandle; /** * The key one more wire occurrence of this handle carries: a fresh engine * reference for an engine object. A host value's key goes as it is, taking * one more of the host's references to it; refused once the key is no * longer registered. */ _cloneKeyForWire(): HandleKey; _releaseForTest(): boolean; } declare abstract class BamlMedia { private readonly rawKey; private readonly handleType; private readonly finalizerToken; private released; protected constructor(rawKey: bigint, handleType: number); protected static cloneKeyFromHandle(handle: BamlHandle, expectedHandleType: number, className: string): bigint; private assertLive; _toHandle(): BamlHandle; url(): string | null; /** The base name of the file the content was read from, if any. */ name(): string | null; base64(): string; mimeType(): string | null; _releaseForTest(): boolean; } export declare class BamlImage extends BamlMedia { private constructor(); static fromUrl(url: string, mimeType?: string | null): BamlImage; static fromFile(file: string, mimeType?: string | null): BamlImage; static fromFileContent(file: string, base64: string, mimeType?: string | null): BamlImage; static fromBase64(base64: string, mimeType?: string | null): BamlImage; static _fromHandle(handle: BamlHandle): BamlImage; } export declare class BamlAudio extends BamlMedia { private constructor(); static fromUrl(url: string, mimeType?: string | null): BamlAudio; static fromFile(file: string, mimeType?: string | null): BamlAudio; static fromFileContent(file: string, base64: string, mimeType?: string | null): BamlAudio; static fromBase64(base64: string, mimeType?: string | null): BamlAudio; static _fromHandle(handle: BamlHandle): BamlAudio; } export declare class BamlVideo extends BamlMedia { private constructor(); static fromUrl(url: string, mimeType?: string | null): BamlVideo; static fromFile(file: string, mimeType?: string | null): BamlVideo; static fromFileContent(file: string, base64: string, mimeType?: string | null): BamlVideo; static fromBase64(base64: string, mimeType?: string | null): BamlVideo; static _fromHandle(handle: BamlHandle): BamlVideo; } export declare class BamlPdf extends BamlMedia { private constructor(); static fromUrl(url: string, mimeType?: string | null): BamlPdf; static fromFile(file: string, mimeType?: string | null): BamlPdf; static fromFileContent(file: string, base64: string, mimeType?: string | null): BamlPdf; static fromBase64(base64: string, mimeType?: string | null): BamlPdf; static _fromHandle(handle: BamlHandle): BamlPdf; } export declare function _setCallCancellationObserverForTest(observer: ((callId: bigint) => void) | undefined): void; export declare class BamlRuntime { static initializeRuntimeFromBlob(bytecode: string | Uint8Array, embeddedBamlToml?: string): BamlRuntime; static initializeRuntime(rootPath: string, files: Record): BamlRuntime; /** * `encodedArgs` is the call's control part; `kwargs` (by declared parameter * name) and the `$baml.cancel` token are JavaScript values the bridge * encodes against the target's declared types before the call goes out. */ callFunctionSync(encodedArgs: Uint8Array, kwargs?: Record | null, cancel?: unknown): Uint8Array; callFunction(encodedArgs: Uint8Array, kwargs?: Record | null, cancel?: unknown): Promise; } /** Install the declared types a generated SDK's typemap carries, or clear them with `null`. */ export declare function registerProgramDescriptor(descriptor: string | null): void; /** Install the runtime's answers to the bridge's walker (see `hostAdapter`). */ export declare function registerHostAdapter(adapter: object): void; export declare function getRuntime(): BamlRuntime; /** * Finalize the SDK lifetime: drain in-flight calls and spawned work, then * release the runtime. Repeated calls are harmless; BAML calls made * afterwards fail. */ export declare function shutdownRuntime(): Promise; export declare function newFunctionCall(): bigint; export declare function releaseFunctionCall(callId: string): boolean; export declare function invocationClockNs(callId: string): string; export interface WebHostExecution { state: BamlHandle; cancel: Uint8Array; cancelled: boolean; } export declare function _hostInvocationFrame(execution: object): [BamlHandle, Uint8Array]; export declare function _traceSelection(handle: BamlHandle, callId: string): [Uint8Array, BamlHandle | undefined]; export declare function _invocationContext(handle?: BamlHandle): Uint8Array; export declare function _watchInvocationCancellation(handle: BamlHandle, callback: () => void): object; export declare function _isInvocationCancelled(handle: BamlHandle): boolean; export declare function _startHostCallExecution(execution: object): string | null; export declare function _finishHostCallExecution(_execution: object): void; export declare function _discardHostCallArgs(bytes: Uint8Array): void; export declare function cancelFunctionCall(callId: bigint | string): boolean; export declare function getVersion(): string; export declare function getToolchainVersion(): string; export declare function getBridgeRuntimeVersion(): string; export declare function mintHostValueKey(): HandleKey; /** Give back one reference to a host value whose send never reached the engine. */ export declare function releaseHostValueKey(key: HandleKey): void; /** Test-only: how many host-value keys (callable and opaque) are registered. */ export declare function _hostValueCount(): number; /** Test-only: whether `key` is registered. */ export declare function _hostValueRegistered(key: HandleKey): boolean; export declare function registerHostValueReleaseCallback(callback: (key: HandleKey) => void): void; /** A host function's instrumentation marker: the Web has no host instrumentation, so none exists. */ export type _HostMarker = never; export declare function registerHostCallable(callback: (callId: number, args: Uint8Array, execution?: object) => void, marker?: object): HandleKey; /** Complete a host call as the host's own exception; the engine builds the `baml.errors.HostCallable`. */ export declare function completeHostCallRaised(callId: number, className: string, message: string, stack: string | undefined, handle: HandleKey): void; /** Complete a host call as a failure of the bridge's own (`baml.panics.SdkPanic`). */ export declare function completeHostCallBridgeFailure(callId: number, message: string): void; /** * Complete a host call with its result, encoded by the bridge against the * return type the callable was bound to. A result that does not fit completes * the call as a `HostContractViolation` panic; an error raised while the value * was read throws and leaves the call open for the caller to complete as an * error. Returns the outcome the engine sees, `'ok'` or `'error'`. */ export declare function completeHostCallValue(callId: number, value: unknown): string; /** * Complete a host call with a thrown BAML value, encoded by the bridge against * the callable's declared throws type; a panic value (`isPanic`) against * `unknown`, since a panic is a panic whatever the callable declares. */ export declare function completeHostCallThrow(callId: number, value: unknown, isPanic: boolean): void; export declare function _seedMediaHandle(): [HandleKey, number]; export {}; //# sourceMappingURL=native.d.ts.map