import { baml_bridge } from './proto/baml_cffi.js'; import { BamlHandle, HandleKey } from '../native.js'; import type { InvocationOptions, InvokeOptions } from './invocation.js'; import { BamlType } from './wire_ty.js'; export interface EncodeCallArgsOptions { callId: bigint; baml?: InvocationOptions | null; syncMode?: boolean; functionName?: string; functionHandle?: HandleKey; /** * Call-level TypeVar bindings for a generic function/method, as * `[typeVarName, wireTy]` pairs in De Bruijn order (enclosing class params * first, then the callee's own `<...>` params). Encoded into * `CallFunctionArgs.type_args`. Mirrors Python's `encode_call_args` * `type_args` argument. Omitted/empty for non-generic calls. */ typeArgs?: Array<[string, baml_bridge.cffi.v1.IBamlTy | BamlType]>; } export interface BamlPromptCallOptions { $baml?: InvocationOptions | null; } /** Structural view returned by `BamlPrompt.messages()`. */ export interface BamlPromptMessage { role: string; content: string; parts: unknown[]; metadata: Record; } /** * Portable representation of `ai.Prompt` at the bridge boundary. * * The protobuf payload is copied both in and out so this wrapper never owns an * engine handle and can safely be passed to another runtime. Its helpers * re-enter the canonical `ai.Prompt` methods with a fresh inline copy, so the * same prompt remains reusable across repeated calls and runtimes. */ export declare class BamlPrompt { private readonly wire; private constructor(); static _fromWire(wire: baml_bridge.cffi.v1.IBamlValuePromptAst): BamlPrompt; _wireCopy(): baml_bridge.cffi.v1.IBamlValuePromptAst; /** A detached JSON-compatible view of the canonical prompt tree. */ toJSON(): unknown; text(options?: BamlPromptCallOptions): Promise; textSync(options?: BamlPromptCallOptions): string; /** Compatibility with the generated SDK's blocking-method spelling. */ text_sync(options?: BamlPromptCallOptions): string; messages(options?: BamlPromptCallOptions): Promise; messagesSync(options?: BamlPromptCallOptions): BamlPromptMessage[]; /** Compatibility with the generated SDK's blocking-method spelling. */ messages_sync(options?: BamlPromptCallOptions): BamlPromptMessage[]; private _callSync; private _callAsync; private static cloneWire; } /** Only the decoder mints a {@link BamlReference}. */ declare const REFERENCE_TOKEN: unique symbol; /** * An instance of a standard-library class the engine keeps for itself * (`reflect.Package`, `reflect.Session`, …). A host holds it and passes it * back, as receiver or argument, but never reads into it or builds one: the * generated class extends this one with the class's methods alone, and the * decoder makes it from the reference the instance crosses as. * * One engine instance is one wrapper for as long as the wrapper lives (the * decoder reuses it), so two are the same instance exactly when they are the * same object. */ export declare class BamlReference { private readonly _handle; /** * The class's type arguments, by parameter name, for an instance of a * generic class: what the engine says the instance is, which an instance * method binds the class's parameters from. */ readonly $types: Readonly> | undefined; constructor(token: typeof REFERENCE_TOKEN, handle: BamlHandle, types?: Readonly>); /** Internal: wrap a decoded `ADT_RUNTIME_VALUE` handle. Used by proto decode. */ static _fromHandle(handle: BamlHandle, types?: Readonly>): BamlReference; /** Internal: expose the inner handle for inbound encoding. */ _toHandle(): BamlHandle; } /** * The control part of a call as `CallFunctionArgs` bytes, with the values the * bridge encodes against the target's declared types alongside: `kwargs` by * declared parameter name and the `$baml.cancel` token, both still JavaScript * values. `BamlRuntime.callFunction(bytes, kwargs, cancel)` takes all three. */ export interface EncodedCall { bytes: Uint8Array; kwargs: Record; cancel: unknown; } /** * Build the control part of a `CallFunctionArgs` for a call. * * The argument values are not encoded here; they ride the returned * {@link EncodedCall} as JavaScript values, and the bridge walks them against * the types the program declares for the target's parameters. `syncMode` is * passed to the bridge by the entry point: a host callable in the arguments of * a *synchronous* call is rejected there before any work, because the sync * path blocks the event loop the callback would need. */ export declare function encodeCallArgs(kwargs: Record, options: EncodeCallArgsOptions): EncodedCall; /** * A leaf's payload as the bridge takes it from {@link hostAdapter.leafOf}: an * `InboundValue`, and what its wire occurrence took, so the bridge can give it * back if the call never goes out. */ type HostLeaf = { bytes: Uint8Array; } /** The engine handle key cloned for the wire, as a decimal string. */ | { bytes: Uint8Array; cloned: string; } /** The host-value key sent again, which took one of its references, as a decimal string. */ | { bytes: Uint8Array; sentAgain: string; }; export declare const hostAdapter: { /** * Is `value` a plain object: one whose prototype is `Object.prototype` or * null? Answered here, in JavaScript, because the question is about realms: * an object from another realm (a `vm` context, an iframe) has that realm's * `Object.prototype`, which only JavaScript can recognise as one. */ /** * Is `value` a `Uint8Array`, whichever realm created it? `instanceof` * against this realm's constructor misses a `vm` context's or an iframe's * typed array. `%TypedArray%.prototype[Symbol.toStringTag]` reads the * value's own kind from its internal slot: `'Uint8Array'` for a typed * array of that kind from any realm, `undefined` for anything else, and * no own `Symbol.toStringTag` property can spoof it. */ isUint8Array(value: unknown): boolean; isPlainObject(value: unknown): boolean; /** The BAML class a generated-class instance is an instance of, or undefined. */ classOf(value: unknown): string | undefined; /** A generic instance's `$types`, lowered to wire `BamlTy` bytes, when every parameter is present. */ typeArgsOf(value: unknown): Uint8Array[] | undefined; /** * The carried tuple type of an array decoded from a BAML tuple, as wire * `BamlTy` bytes, or undefined for any other value. A received tuple sent * back where no tuple type is declared restates it with this type. */ tupleTypeOf(value: unknown): Uint8Array | undefined; /** * The kind of leaf a runtime-owned value is, or undefined for any other * value. A question only: nothing is cloned or serialized until the bridge * asks for the payload with `leafOf`. */ leafKindOf(value: unknown): number | undefined; /** The wire payload of a value `leafKindOf` classified as a leaf, cloning a handle's key for the wire. */ leafOf(value: unknown): HostLeaf; /** Bind a user function as a host callable; what comes back is the platform's (see `registerCallableDispatch`). */ dispatchFor(fn: (...args: unknown[]) => unknown): unknown; /** A short rendering for error messages, bounded in work as in length: a container by its size, never stringified whole. */ describe(value: unknown): string; }; interface InvocationSnapshot { wire: baml_bridge.cffi.v1.IInvocationOptions; cancel: unknown; signal?: AbortSignal | null; retained: unknown[]; } export declare function encodedInvocation(bytes: Uint8Array): InvocationSnapshot | undefined; export declare function invokeTarget(target: string | ((...args: any[]) => unknown), args: Record, options: InvokeOptions | undefined, asynchronous: boolean): unknown; /** * The carried type of an array decoded from a BAML tuple, while the array * still has the tuple's arity; `undefined` for any other value. */ export declare function carriedTupleType(value: unknown): baml_bridge.cffi.v1.IBamlTy | undefined; /** * Decode a bare `BamlOutboundValue` to a JS value. Used for the host-callable * args path, where the engine sends a list-shaped `BamlOutboundValue` rather * than the call-result `BamlOutboundResult` envelope. */ export declare function decodeOutboundValue(data: Uint8Array): unknown; /** * Decode the engine→host `BamlToHostCall`. The engine has already resolved the * call against the callee's declared params and dropped omitted optionals, so * `args` is a flat, declared-order list of the supplied args. Partition it back * into the required positional run and the supplied optionals (keyed by * `argName`) using each arg's `isOptionalArg` flag. */ export declare function decodeHostCall(data: Uint8Array): { positional: unknown[]; optional: Record; }; /** * Decode a `BamlOutboundResult` envelope (the engine's call-result wire shape * after 31c/31e). The `ok` arm returns the decoded value; the `error`/`panic` * arms **throw** a `BamlError`/`BamlPanic` carrying the fully decoded thrown * value (`.value`), the BAML trace (`.bamlTrace`), and the class FQN * (`.className`), with a readable formatted `.message`. An `is_exit_panic` * (clean `baml.sys.exit`) terminates the runtime via `runtime.exit(code)` * rather than throwing. */ export declare function decodeCallResult(data: Uint8Array): unknown; export declare function makeHostCallableDispatch(userFn: (...args: unknown[]) => unknown): (callId: number, argsBytes: Uint8Array, execution?: object) => void; export {}; //# sourceMappingURL=proto.d.ts.map