/* tslint:disable */ /* eslint-disable */ export class CancellationWatch { private constructor(); free(): void; [Symbol.dispose](): void; } /** * Encode one JavaScript value as the bridge would send it where the program * declares no type: the value's own type, stated on the wire where a * container or class needs it. Returns `InboundValue` bytes; raises for a * value the bridge cannot send. For inspection and tests. */ export function _encodeWebInbound(value: any, name?: string | null): Uint8Array; export function _testHandleTableEntryCount(): number; export function _testWebFireHostRelease(key: bigint): void; export function _testWebHostReleaseCallbackInstalled(): boolean; export function _testWebHostValueCount(): number; export function _testWebHostValueRegistered(key: bigint): boolean; export function _testWebInFlightHostCallCount(): number; export function _testWebMissingHostCallableError(key: bigint): Promise; export function _testWebSyncPendingHostCallableError(key: bigint): string; /** * Call a BAML function asynchronously. Arguments as for * [`call_function_sync`]; they are encoded while the caller's frame is still * running, before the promise exists, so a value the caller mutates after * the call is made is never what crosses (an `async fn` export would run * its body in a microtask, after the caller's next statements). A value that * does not fit throws synchronously, as on Node. */ export function callFunction(encoded_args: Uint8Array, kwargs: any, cancel: any): Promise; /** * Call a BAML function synchronously. `encoded_args` carries the call's * control part with no `kwargs`; `kwargs` are the arguments by declared * parameter name as JavaScript values, encoded here against the target's * declared types, and `cancel` the `$baml.cancel` token. A value that does * not fit raises before anything is sent. */ export function callFunctionSync(encoded_args: Uint8Array, kwargs: any, cancel: any): Uint8Array; export function cancelFunctionCall(call_id: bigint): boolean; export function cloneHandle(key: bigint): bigint; export function cloneOutboundValue(wire: Uint8Array): Uint8Array; /** * Complete an in-flight host call from the JS dispatch wrapper with a * protobuf-encoded `HostCallCompletion`: the callable's result or thrown * value encoded against its declared types, an exception of the host's own, * a broken contract, or a bridge failure. The engine holds the values to the * declared types and builds every panic itself. * * Returns `true` when the id named an in-flight call. An unknown id is a * late completion: its transfers are still consumed and released, and it * returns `false` after a bounded warning, making a Promise settlement racing * cancellation an observable benign stale completion. */ export function completeHostCall(call_id: number, content: Uint8Array): boolean; /** * Complete an in-flight host call as a failure of the bridge's own, which * the engine surfaces as `baml.panics.SdkPanic`. */ export function completeWebHostCallBridgeFailure(call_id: number, message: string): boolean; /** * Complete an in-flight host call as the host's own exception: the engine * builds the `baml.errors.HostCallable` whose `_handle` is `handle`, the * JS-side registration of the error object (a decimal host-value key). */ export function completeWebHostCallRaised(call_id: number, class_name: string, message: string, stack: string | null | undefined, handle: string): boolean; /** * Complete an in-flight host call with a thrown BAML value, encoded against * the throws type of the slot the callable was bound to; a `baml.panics.*` * value is a panic whatever the slot declares. */ export function completeWebHostCallThrow(call_id: number, value: any, is_panic: boolean): boolean; /** * Complete an in-flight host call with its JavaScript result, encoded * against the return type of the slot the dispatched callable was bound to * (the runtime's own I/O callables have none, and send their results as the * types they have). A value that does not fit completes the call as a * `baml.panics.HostContractViolation`; a value the bridge could not carry as * a `baml.panics.SdkPanic`; an error the callable's own code raised while * the value was read is raised here, and the runtime completes the call with * it. Returns the outcome the engine sees, `"ok"` or `"error"`, for the * runtime's instrumentation. */ export function completeWebHostCallValue(call_id: number, value: any): string; export function configureWebSysops(fetch_key: bigint, read_file_sync_key: bigint): void; /** * Select workerd startup restrictions before generated bytecode is staged. */ export function configureWorkerdRuntime(): void; export function getBridgeRuntimeVersion(): string; export function getToolchainVersion(): string; export function getVersion(): string; export function init(): void; export function invocationClockNs(call_id: bigint): bigint; export function invocationContext(key: bigint): Uint8Array; export function invocationProtocolVersion(): number; export function isInvocationCancelled(key: bigint): boolean; export function mediaBase64(key: bigint, handle_type: number): string; export function mediaFromBase64(media_kind_value: number, base64: string, mime_type?: string | null): bigint; /** * Media from the bytes of `file`, which the JavaScript host read: this * module has no file system of its own. */ export function mediaFromFileBytes(media_kind_value: number, file: string, content: Uint8Array, mime_type?: string | null): bigint; /** * Media from base64 content that was read from `file`. Reads nothing. */ export function mediaFromFileContent(media_kind_value: number, file: string, base64: string, mime_type?: string | null): bigint; export function mediaFromUrl(media_kind_value: number, url: string, mime_type?: string | null): bigint; export function mediaMimeType(key: bigint, handle_type: number): string | undefined; /** * The base name of the file the content was read from, if any. */ export function mediaName(key: bigint, handle_type: number): string | undefined; export function mediaUrl(key: bigint, handle_type: number): string | undefined; /** * Mint a key for a JS-owned opaque value from the same keyspace used by * callable host values: both are the engine's references to host objects. * The key holds the one reference the send it is minted for takes. */ export function mintHostValueKey(): bigint; export function mintWebHostValueKey(): bigint; export function newFunctionCall(): bigint; /** * Install the runtime's adapter: `classOf(value)`, `typeArgsOf(value)`, * `leafKindOf(value)`, `leafOf(value)`, `dispatchFor(fn)` and * `describe(value)`. */ export function registerHostAdapter(adapter: object): void; /** * Register a JS callable in the WASM host-value table and return its key. * * Exposed to JS as `registerHostCallable(fn) -> bigint`. The key is then * embedded in `InboundValue::Handle { key, handleType: HOST_VALUE_CALLABLE }` * by the JS encoder. The returned value is a `BigInt` because `u64` does not * fit into JS's safe-integer range. */ export function registerHostCallable(callable: Function): bigint; export function registerHostCancelCallback(callback: Function): boolean; /** * Register the JS callback told of every key whose last reference was given * back, so the SDK can drop what it keeps for the key. */ export function registerHostValueReleaseCallback(callback: Function): boolean; /** * Install the program descriptor a generated SDK embeds in its typemap * (`setTypeMap` calls this), or clear it with `null`. */ export function registerProgramDescriptor(descriptor?: string | null): void; export function registerWebHostCallable(callable: Function): bigint; export function registerWebHostCancelCallback(callback: Function): boolean; export function registerWebHostValueReleaseCallback(callback: Function): boolean; export function releaseFunctionCall(call_id: bigint): boolean; export function releaseHandle(key: bigint): boolean; /** * Give back one reference to the host value `key` that was registered or * sent again but never reached the engine. Returns whether it was the last. */ export function releaseWebHostValue(key: bigint): boolean; /** * Test-only: seed an image media entry into the handle table. */ export function seedMediaHandle(): bigint; /** * Take one more reference to the host value `key` for sending it to the * engine again; refused once every reference has been given back. */ export function sendWebHostValueAgain(key: bigint): void; /** * 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 function shutdownRuntime(): Promise; /** * Stage a runtime from precompiled BAML bytecode: a raw artifact * (`Uint8Array`), or the encoded string generated SDKs embed (decoded * natively, never in JavaScript). */ export function stageRuntimeBytecode(bytecode: any, embedded_baml_toml?: string | null): void; export function stageRuntimeSources(root_path: string, files: any): void; export function traceSelection(call_id: bigint, key: bigint): Array; export function watchInvocationCancellation(key: bigint, callback: Function): CancellationWatch; export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module; export interface InitOutput { readonly memory: WebAssembly.Memory; readonly __wbg_cancellationwatch_free: (a: number, b: number) => void; readonly _encodeWebInbound: (a: number, b: number, c: number, d: number) => void; readonly _testHandleTableEntryCount: (a: number) => void; readonly _testWebFireHostRelease: (a: bigint) => void; readonly _testWebHostReleaseCallbackInstalled: () => number; readonly _testWebHostValueCount: () => number; readonly _testWebHostValueRegistered: (a: bigint) => number; readonly _testWebInFlightHostCallCount: () => number; readonly _testWebMissingHostCallableError: (a: bigint) => number; readonly _testWebSyncPendingHostCallableError: (a: number, b: bigint) => void; readonly callFunction: (a: number, b: number, c: number, d: number, e: number) => void; readonly callFunctionSync: (a: number, b: number, c: number, d: number, e: number) => void; readonly cancelFunctionCall: (a: bigint) => number; readonly cloneHandle: (a: number, b: bigint) => void; readonly cloneOutboundValue: (a: number, b: number, c: number) => void; readonly completeWebHostCallBridgeFailure: (a: number, b: number, c: number) => number; readonly completeWebHostCallRaised: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void; readonly completeWebHostCallThrow: (a: number, b: number, c: number, d: number) => void; readonly completeWebHostCallValue: (a: number, b: number, c: number) => void; readonly configureWebSysops: (a: number, b: bigint, c: bigint) => void; readonly configureWorkerdRuntime: () => void; readonly getBridgeRuntimeVersion: (a: number) => void; readonly init: () => void; readonly invocationClockNs: (a: number, b: bigint) => void; readonly invocationContext: (a: number, b: bigint) => void; readonly invocationProtocolVersion: () => number; readonly isInvocationCancelled: (a: number, b: bigint) => void; readonly mediaBase64: (a: number, b: bigint, c: number) => void; readonly mediaFromBase64: (a: number, b: number, c: number, d: number, e: number, f: number) => void; readonly mediaFromFileBytes: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void; readonly mediaFromFileContent: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void; readonly mediaFromUrl: (a: number, b: number, c: number, d: number, e: number, f: number) => void; readonly mediaMimeType: (a: number, b: bigint, c: number) => void; readonly mediaName: (a: number, b: bigint, c: number) => void; readonly mediaUrl: (a: number, b: bigint, c: number) => void; readonly mintWebHostValueKey: () => bigint; readonly newFunctionCall: (a: number) => void; readonly registerHostAdapter: (a: number) => void; readonly registerProgramDescriptor: (a: number, b: number, c: number) => void; readonly registerWebHostCallable: (a: number) => bigint; readonly registerWebHostCancelCallback: (a: number) => number; readonly registerWebHostValueReleaseCallback: (a: number) => number; readonly releaseFunctionCall: (a: bigint) => number; readonly releaseHandle: (a: bigint) => number; readonly releaseWebHostValue: (a: bigint) => number; readonly seedMediaHandle: (a: number) => void; readonly sendWebHostValueAgain: (a: number, b: bigint) => void; readonly shutdownRuntime: () => number; readonly stageRuntimeBytecode: (a: number, b: number, c: number, d: number) => void; readonly stageRuntimeSources: (a: number, b: number, c: number, d: number) => void; readonly traceSelection: (a: number, b: bigint, c: bigint) => void; readonly watchInvocationCancellation: (a: number, b: bigint, c: number) => void; readonly getToolchainVersion: (a: number) => void; readonly getVersion: (a: number) => void; readonly completeHostCall: (a: number, b: number, c: number) => number; readonly registerHostCallable: (a: number) => bigint; readonly registerHostCancelCallback: (a: number) => number; readonly registerHostValueReleaseCallback: (a: number) => number; readonly mintHostValueKey: () => bigint; readonly cancel_function_call: (a: bigint) => number; readonly free_buffer: (a: number) => void; readonly new_function_call: () => bigint; readonly release_function_call: (a: bigint) => number; readonly __wasm_bindgen_func_elem_47849: (a: number, b: number, c: number, d: number) => void; readonly __wasm_bindgen_func_elem_47851: (a: number, b: number, c: number, d: number) => void; readonly __wasm_bindgen_func_elem_773: (a: number, b: number, c: number) => void; readonly __wasm_bindgen_func_elem_34612: (a: number, b: number) => void; readonly __wbindgen_export: (a: number) => void; readonly __wbindgen_export2: (a: number, b: number) => number; readonly __wbindgen_export3: (a: number, b: number, c: number, d: number) => number; readonly __wbindgen_export4: (a: number, b: number) => void; readonly __wbindgen_add_to_stack_pointer: (a: number) => number; readonly __wbindgen_export5: (a: number, b: number, c: number) => void; readonly __wbindgen_start: () => void; } export type SyncInitInput = BufferSource | WebAssembly.Module; /** * Instantiates the given `module`, which can either be bytes or * a precompiled `WebAssembly.Module`. * * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated. * * @returns {InitOutput} */ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput; /** * If `module_or_path` is {RequestInfo} or {URL}, makes a request and * for everything else, calls `WebAssembly.instantiate` directly. * * @param {{ module_or_path: InitInput | Promise }} module_or_path - Passing `InitInput` directly is deprecated. * * @returns {Promise} */ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise } | InitInput | Promise): Promise;