@boundaryml/baml-core-node 0.11.2-nightly.20260604.d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,62 @@
1
+ /**
2
+ * THIS FILE IS AUTO-GENERATED — DO NOT EDIT BY HAND.
3
+ *
4
+ * Source: baml_language/crates/bridge_nodejs/typescript_src/
5
+ * Proto: baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/*.proto
6
+ * Build: cd baml_language/crates/bridge_nodejs && pnpm build:debug
7
+ */
8
+ import { BamlRuntime, AbortController, HostSpanManager, Collector as NativeCollector, FunctionLog as NativeFunctionLog, Timing, Usage, LLMCall } from './native.js';
9
+ export { BamlRuntime, AbortController, BamlHandle, HostSpanManager, getRuntime, getVersion, flushEvents } from './native.js';
10
+ export { Timing, Usage, LLMCall } from './native.js';
11
+ export { takeHandleFromTable, putHandleIntoTable, _seedFunctionRefHandle, _seedGenericMediaHandle, } from './native.js';
12
+ export { BamlImage, BamlAudio, BamlVideo, BamlPdf } from './native.js';
13
+ export { BamlStream } from './stream.js';
14
+ export { encodeCallArgs, decodeCallResult } from './proto.js';
15
+ export { CtxManager } from './ctx_manager.js';
16
+ export { BamlTypeMap, setTypeMap, getTypeMap } from './typemap.js';
17
+ export { defineFunction, defineInstanceFunction, UNSET } from './define_function.js';
18
+ /**
19
+ * Free-function runtime initializer used by generated `baml_sdk/index.ts`:
20
+ * `initializeRuntime("baml_src", _inlinedbaml.FILES)`. Thin wrapper over the
21
+ * `BamlRuntime.initializeRuntime` factory (which sets the process-global
22
+ * singleton reachable via `getRuntime()`).
23
+ */
24
+ export declare function initializeRuntime(srcDir: string, files: Record<string, string>): void;
25
+ /**
26
+ * Free-function runtime initializer used by generated `baml_sdk/index.ts` when
27
+ * codegen embeds precompiled BAML bytecode.
28
+ */
29
+ export declare function initializeRuntimeFromBytecode(bytecode: Buffer | Uint8Array): void;
30
+ export { BamlError, BamlInvalidArgumentError, BamlClientError, BamlCancelledError, BamlPanic, wrapNativeError, } from './errors.js';
31
+ export declare class FunctionResult {
32
+ private _value;
33
+ constructor(value: unknown);
34
+ result(): unknown;
35
+ toString(): string;
36
+ }
37
+ export declare class FunctionLog {
38
+ private _inner;
39
+ constructor(inner: NativeFunctionLog);
40
+ get id(): string;
41
+ get functionName(): string;
42
+ get timing(): Timing;
43
+ get usage(): Usage;
44
+ get calls(): LLMCall[];
45
+ get tags(): Record<string, string>;
46
+ get result(): unknown;
47
+ }
48
+ export declare class Collector {
49
+ private _inner;
50
+ constructor(name?: string);
51
+ get name(): string;
52
+ get logs(): FunctionLog[];
53
+ get last(): FunctionLog | null;
54
+ get usage(): Usage;
55
+ clear(): number;
56
+ id(functionLogId: string): FunctionLog | null;
57
+ /** Internal: get native collector for passing to Rust */
58
+ _native(): NativeCollector;
59
+ }
60
+ export declare function callFunctionSync(rt: BamlRuntime, functionName: string, kwargs: Record<string, unknown>, ctx?: HostSpanManager, collectors?: Collector[], abortController?: AbortController): FunctionResult;
61
+ export declare function callFunction(rt: BamlRuntime, functionName: string, kwargs: Record<string, unknown>, ctx?: HostSpanManager, collectors?: Collector[], abortController?: AbortController): Promise<FunctionResult>;
62
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../typescript_src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,WAAW,EACX,eAAe,EAEf,eAAe,EACf,SAAS,IAAI,eAAe,EAC5B,WAAW,IAAI,iBAAiB,EAChC,MAAM,EACN,KAAK,EACL,OAAO,EACV,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC7H,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EACH,mBAAmB,EACnB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M,CAAC,MAAM,EAAE,MAAM,CAAC,CAA6B;IAK/D,IAAI,MAAM,IAAI,OAAO,CAIpB;CACJ;AAED,qBAAa,SAAS;IAClB,OAAO,CAAC,MAAM,CAAkB;gBACpB,IAAI,CAAC,EAAE,MAAM;IACzB,IAAI,IAAI,IAAI,MAAM,CAA6B;IAC/C,IAAI,IAAI,IAAI,WAAW,EAAE,CAExB;IACD,IAAI,IAAI,IAAI,WAAW,GAAG,IAAI,CAG7B;IACD,IAAI,KAAK,IAAI,KAAK,CAA8B;IAChD,KAAK,IAAI,MAAM;IACf,EAAE,CAAC,aAAa,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;IAI7C,yDAAyD;IACzD,OAAO,IAAI,eAAe;CAC7B;AAED,wBAAgB,gBAAgB,CAC5B,EAAE,EAAE,WAAW,EACf,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,GAAG,CAAC,EAAE,eAAe,EACrB,UAAU,CAAC,EAAE,SAAS,EAAE,EACxB,eAAe,CAAC,EAAE,eAAe,GAClC,cAAc,CAahB;AAED,wBAAsB,YAAY,CAC9B,EAAE,EAAE,WAAW,EACf,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,GAAG,CAAC,EAAE,eAAe,EACrB,UAAU,CAAC,EAAE,SAAS,EAAE,EACxB,eAAe,CAAC,EAAE,eAAe,GAClC,OAAO,CAAC,cAAc,CAAC,CASzB"}
package/dist/index.js ADDED
@@ -0,0 +1,125 @@
1
+ /**
2
+ * THIS FILE IS AUTO-GENERATED — DO NOT EDIT BY HAND.
3
+ *
4
+ * Source: baml_language/crates/bridge_nodejs/typescript_src/
5
+ * Proto: baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/*.proto
6
+ * Build: cd baml_language/crates/bridge_nodejs && pnpm build:debug
7
+ */
8
+ // index.ts — mirrors bridge_python/python_src/baml_py/__init__.py
9
+ import { BamlRuntime, Collector as NativeCollector, } from './native.js';
10
+ import { encodeCallArgs, decodeCallResult } from './proto.js';
11
+ import { installFlushOnExit } from './exit_hook.js';
12
+ export { BamlRuntime, AbortController, BamlHandle, HostSpanManager, getRuntime, getVersion, flushEvents } from './native.js';
13
+ export { Timing, Usage } from './native.js';
14
+ // Handle-table helpers (decode validate-on-take / encode clone-on-put + test seeds).
15
+ export { takeHandleFromTable, putHandleIntoTable, _seedFunctionRefHandle, _seedGenericMediaHandle, } from './native.js';
16
+ // Runtime-owned stdlib value classes. Exported under their `Baml*` names only;
17
+ // codegen aliases them as Image/Audio/Video/Pdf on re-export.
18
+ export { BamlImage, BamlAudio, BamlVideo, BamlPdf } from './native.js';
19
+ // Stream wrapper. Exported as `BamlStream`; codegen aliases it as `Stream`.
20
+ export { BamlStream } from './stream.js';
21
+ export { encodeCallArgs, decodeCallResult } from './proto.js';
22
+ export { CtxManager } from './ctx_manager.js';
23
+ // Codegen support: typemap + placeholder sentinel + free runtime initializer.
24
+ export { BamlTypeMap, setTypeMap, getTypeMap } from './typemap.js';
25
+ // Callable factories the generated SDK emits for every BAML function/method.
26
+ export { defineFunction, defineInstanceFunction, UNSET } from './define_function.js';
27
+ /**
28
+ * Free-function runtime initializer used by generated `baml_sdk/index.ts`:
29
+ * `initializeRuntime("baml_src", _inlinedbaml.FILES)`. Thin wrapper over the
30
+ * `BamlRuntime.initializeRuntime` factory (which sets the process-global
31
+ * singleton reachable via `getRuntime()`).
32
+ */
33
+ export function initializeRuntime(srcDir, files) {
34
+ BamlRuntime.initializeRuntime(srcDir, files);
35
+ }
36
+ /**
37
+ * Free-function runtime initializer used by generated `baml_sdk/index.ts` when
38
+ * codegen embeds precompiled BAML bytecode.
39
+ */
40
+ export function initializeRuntimeFromBytecode(bytecode) {
41
+ BamlRuntime.initializeRuntimeFromBytecode(Buffer.from(bytecode));
42
+ }
43
+ import { wrapNativeError } from './errors.js';
44
+ export { BamlError, BamlInvalidArgumentError, BamlClientError, BamlCancelledError, BamlPanic, wrapNativeError, } from './errors.js';
45
+ export class FunctionResult {
46
+ _value;
47
+ constructor(value) {
48
+ this._value = value;
49
+ }
50
+ result() {
51
+ return this._value;
52
+ }
53
+ toString() {
54
+ return `FunctionResult(${JSON.stringify(this._value)})`;
55
+ }
56
+ }
57
+ export class FunctionLog {
58
+ _inner;
59
+ constructor(inner) { this._inner = inner; }
60
+ get id() { return this._inner.id; }
61
+ get functionName() { return this._inner.functionName; }
62
+ get timing() { return this._inner.timing; }
63
+ get usage() { return this._inner.usage; }
64
+ get calls() { return this._inner.calls; }
65
+ get tags() { return this._inner.tags; }
66
+ // FIXME: Returns null for both "no serialized result" (bytes == null) and a legitimate
67
+ // BAML null result (decodeCallResult returns null). Legacy engine/ had no result getter
68
+ // on FunctionLog at all. bridge_python has the same ambiguity (None for both cases).
69
+ // Leaving as-is for parity with bridge_python; narrow edge case in practice.
70
+ get result() {
71
+ const bytes = this._inner.result;
72
+ if (bytes == null)
73
+ return null;
74
+ return decodeCallResult(bytes);
75
+ }
76
+ }
77
+ export class Collector {
78
+ _inner;
79
+ constructor(name) { this._inner = new NativeCollector(name ?? null); }
80
+ get name() { return this._inner.name; }
81
+ get logs() {
82
+ return this._inner.logs.map((l) => new FunctionLog(l));
83
+ }
84
+ get last() {
85
+ const l = this._inner.last;
86
+ return l ? new FunctionLog(l) : null;
87
+ }
88
+ get usage() { return this._inner.usage; }
89
+ clear() { return this._inner.clear(); }
90
+ id(functionLogId) {
91
+ const l = this._inner.id(functionLogId);
92
+ return l ? new FunctionLog(l) : null;
93
+ }
94
+ /** Internal: get native collector for passing to Rust */
95
+ _native() { return this._inner; }
96
+ }
97
+ export function callFunctionSync(rt, functionName, kwargs, ctx, collectors, abortController) {
98
+ // Encode in sync mode so a host callable in the kwargs fast-fails
99
+ // with a clear error instead of registering a tsfn and then hanging —
100
+ // the sync path blocks the Node main thread on a tokio `block_on`,
101
+ // starving libuv so the dispatch could never run.
102
+ const argsProto = encodeCallArgs(kwargs, /* syncMode */ true);
103
+ const nativeCollectors = collectors?.map(c => c._native()) ?? null;
104
+ try {
105
+ const resultBytes = rt.callFunctionSync(functionName, argsProto, ctx ?? null, nativeCollectors, abortController ?? null);
106
+ return new FunctionResult(decodeCallResult(resultBytes));
107
+ }
108
+ catch (err) {
109
+ throw wrapNativeError(err);
110
+ }
111
+ }
112
+ export async function callFunction(rt, functionName, kwargs, ctx, collectors, abortController) {
113
+ const argsProto = encodeCallArgs(kwargs);
114
+ const nativeCollectors = collectors?.map(c => c._native()) ?? null;
115
+ try {
116
+ const resultBytes = await rt.callFunction(functionName, argsProto, ctx ?? null, nativeCollectors, abortController ?? null);
117
+ return new FunctionResult(decodeCallResult(resultBytes));
118
+ }
119
+ catch (err) {
120
+ throw wrapNativeError(err);
121
+ }
122
+ }
123
+ // Register flush on process exit (single registration; see exit_hook.ts).
124
+ installFlushOnExit();
125
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../typescript_src/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAElE,OAAO,EACH,WAAW,EAIX,SAAS,IAAI,eAAe,GAK/B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC7H,OAAO,EAAE,MAAM,EAAE,KAAK,EAAW,MAAM,aAAa,CAAC;AACrD,qFAAqF;AACrF,OAAO,EACH,mBAAmB,EACnB,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,GAC1B,MAAM,aAAa,CAAC;AACrB,+EAA+E;AAC/E,8DAA8D;AAC9D,OAAO,EAAE,SAAS,EAAE,SA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C/B,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAC9B,EAAe,EACf,YAAoB,EACpB,MAA+B,EAC/B,GAAqB,EACrB,UAAwB,EACxB,eAAiC;IAEjC,MAAM,SAAS,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IACzC,MAAM,gBAAgB,GAAG,UAAU,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,IAAI,CAAC;IACnE,IAAI,CAAC;QACD,MAAM,WAAW,GAAG,MAAM,EAAE,CAAC,YAAY,CAAC,YAAY,EAAE,SAAS,EAAE,GAAG,IAAI,IAAI,EAAE,gBAAgB,EAAE,eAAe,IAAI,IAAI,CAAC,CAAC;QAC3H,OAAO,IAAI,cAAc,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC;IAC7D,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,MAAM,eAAe,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;AACL,CAAC;AAED,0EAA0E;AAC1E,kBAAkB,EAAE,CAAC"}
@@ -0,0 +1,280 @@
1
+ /**
2
+ * THIS FILE IS AUTO-GENERATED — DO NOT EDIT BY HAND.
3
+ *
4
+ * Source: baml_language/crates/bridge_nodejs/typescript_src/
5
+ * Proto: baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/*.proto
6
+ * Build: cd baml_language/crates/bridge_nodejs && pnpm build:debug
7
+ */
8
+ /* auto-generated by NAPI-RS */
9
+ /* eslint-disable */
10
+ /** An abort controller for cancelling BAML function calls. */
11
+ export declare class AbortController {
12
+ constructor()
13
+ abort(): void
14
+ get aborted(): boolean
15
+ }
16
+
17
+ export declare class BamlAudio {
18
+ static fromUrl(url: string, mimeType?: string | undefined | null): BamlAudio
19
+ static fromFile(file: string, mimeType?: string | undefined | null): BamlAudio
20
+ static fromBase64(base64: string, mimeType?: string | undefined | null): BamlAudio
21
+ url(): string | null
22
+ file(): string | null
23
+ base64(): string
24
+ mimeType(): string | null
25
+ /**
26
+ * Internal: build from an existing `BamlHandle`. Used by proto
27
+ * decode. Validates the handle's `handle_type` tag matches the
28
+ * expected media kind, then clones the table row so the input
29
+ * handle stays usable.
30
+ */
31
+ static _fromHandle(handle: BamlHandle): BamlAudio
32
+ /**
33
+ * Internal: produce a fresh `BamlHandle` pointing at the same
34
+ * table row (cloned). Used by inbound encode.
35
+ */
36
+ _toHandle(): BamlHandle
37
+ }
38
+
39
+ /**
40
+ * Base class for all opaque BAML handles.
41
+ *
42
+ * When the Node.js garbage collector finalizes an instance, `finalize`
43
+ * releases the corresponding entry from the global handle table.
44
+ */
45
+ export declare class BamlHandle {
46
+ constructor(key: HandleKey, handleType: number)
47
+ get key(): HandleKey
48
+ get handleType(): number
49
+ clone(): BamlHandle
50
+ }
51
+
52
+ export declare class BamlImage {
53
+ static fromUrl(url: string, mimeType?: string | undefined | null): BamlImage
54
+ static fromFile(file: string, mimeType?: string | undefined | null): BamlImage
55
+ static fromBase64(base64: string, mimeType?: string | undefined | null): BamlImage
56
+ url(): string | null
57
+ file(): string | null
58
+ base64(): string
59
+ mimeType(): string | null
60
+ /**
61
+ * Internal: build from an existing `BamlHandle`. Used by proto
62
+ * decode. Validates the handle's `handle_type` tag matches the
63
+ * expected media kind, then clones the table row so the input
64
+ * handle stays usable.
65
+ */
66
+ static _fromHandle(handle: BamlHandle): BamlImage
67
+ /**
68
+ * Internal: produce a fresh `BamlHandle` pointing at the same
69
+ * table row (cloned). Used by inbound encode.
70
+ */
71
+ _toHandle(): BamlHandle
72
+ }
73
+
74
+ export declare class BamlPdf {
75
+ static fromUrl(url: string, mimeType?: string | undefined | null): BamlPdf
76
+ static fromFile(file: string, mimeType?: string | undefined | null): BamlPdf
77
+ static fromBase64(base64: string, mimeType?: string | undefined | null): BamlPdf
78
+ url(): string | null
79
+ file(): string | null
80
+ base64(): string
81
+ mimeType(): string | null
82
+ /**
83
+ * Internal: build from an existing `BamlHandle`. Used by proto
84
+ * decode. Validates the handle's `handle_type` tag matches the
85
+ * expected media kind, then clones the table row so the input
86
+ * handle stays usable.
87
+ */
88
+ static _fromHandle(handle: BamlHandle): BamlPdf
89
+ /**
90
+ * Internal: produce a fresh `BamlHandle` pointing at the same
91
+ * table row (cloned). Used by inbound encode.
92
+ */
93
+ _toHandle(): BamlHandle
94
+ }
95
+
96
+ /** The main BAML runtime. A zero-sized handle (see module docs). */
97
+ export declare class BamlRuntime {
98
+ /**
99
+ * Initialize the process-global runtime from in-memory BAML source
100
+ * files. `bridge_cffi::initialize_runtime` is a single-slot singleton, so
101
+ * a second call replaces the prior runtime; the result is also reachable
102
+ * via the module-level `getRuntime()`. Renamed from `fromFiles` for
103
+ * parity with `bridge_python`'s sole `initialize_runtime` constructor and
104
+ * the `initializeRuntime(...)` import the spec docs use.
105
+ */
106
+ static initializeRuntime(rootPath: string, files: Record<string, string>): BamlRuntime
107
+ /** Initialize the process-global runtime from precompiled BAML bytecode. */
108
+ static initializeRuntimeFromBytecode(bytecode: Buffer): BamlRuntime
109
+ /** Call a BAML function synchronously (blocking). */
110
+ callFunctionSync(functionName: string, argsProto: Buffer, ctx?: HostSpanManager | undefined | null, collectors?: Array<Collector> | undefined | null, abortController?: AbortController | undefined | null): Buffer
111
+ /** Call a BAML function asynchronously. */
112
+ callFunction(functionName: string, argsProto: Buffer, ctx?: HostSpanManager | undefined | null, collectors?: Array<Collector> | undefined | null, abortController?: AbortController | undefined | null): Promise<Buffer>
113
+ }
114
+
115
+ export declare class BamlVideo {
116
+ static fromUrl(url: string, mimeType?: string | undefined | null): BamlVideo
117
+ static fromFile(file: string, mimeType?: string | undefined | null): BamlVideo
118
+ static fromBase64(base64: string, mimeType?: string | undefined | null): BamlVideo
119
+ url(): string | null
120
+ file(): string | null
121
+ base64(): string
122
+ mimeType(): string | null
123
+ /**
124
+ * Internal: build from an existing `BamlHandle`. Used by proto
125
+ * decode. Validates the handle's `handle_type` tag matches the
126
+ * expected media kind, then clones the table row so the input
127
+ * handle stays usable.
128
+ */
129
+ static _fromHandle(handle: BamlHandle): BamlVideo
130
+ /**
131
+ * Internal: produce a fresh `BamlHandle` pointing at the same
132
+ * table row (cloned). Used by inbound encode.
133
+ */
134
+ _toHandle(): BamlHandle
135
+ }
136
+
137
+ export declare class Collector {
138
+ constructor(name?: string | undefined | null)
139
+ get name(): string
140
+ get logs(): Array<FunctionLog>
141
+ get last(): FunctionLog | null
142
+ get usage(): Usage
143
+ clear(): number
144
+ id(functionLogId: string): FunctionLog | null
145
+ }
146
+
147
+ export declare class FunctionLog {
148
+ get id(): string
149
+ get functionName(): string
150
+ get timing(): Timing
151
+ get usage(): Usage
152
+ get calls(): Array<LLMCall>
153
+ get tags(): Record<string, string>
154
+ get result(): Buffer | null
155
+ }
156
+
157
+ export declare class HostSpanManager {
158
+ constructor()
159
+ enter(name: string, args: any): void
160
+ exitOk(): void
161
+ exitError(errorMessage: string): void
162
+ upsertTags(tags: Record<string, string>): void
163
+ deepClone(): HostSpanManager
164
+ contextDepth(): number
165
+ }
166
+
167
+ export declare class LlmCall {
168
+ get functionName(): string
169
+ get provider(): string | null
170
+ get timing(): Timing
171
+ get usage(): Usage
172
+ }
173
+ export type LLMCall = LlmCall
174
+
175
+ export declare class Timing {
176
+ get startTimeUtcMs(): number
177
+ get durationMs(): number | null
178
+ }
179
+
180
+ export declare class Usage {
181
+ get inputTokens(): number | null
182
+ get outputTokens(): number | null
183
+ get cachedInputTokens(): number | null
184
+ }
185
+
186
+ /**
187
+ * Test-only: seed a `FunctionRef` entry into `HANDLE_TABLE`, returning
188
+ * `[key, handleType]` so test code can construct a `BamlHandle`.
189
+ */
190
+ export declare function _seedFunctionRefHandle(globalIndex: number): [HandleKey, number]
191
+
192
+ /** Test-only: seed an `Adt(Media(generic))` entry into `HANDLE_TABLE`. */
193
+ export declare function _seedGenericMediaHandle(): [HandleKey, number]
194
+
195
+ /**
196
+ * Complete an in-flight host call from the JS dispatch wrapper.
197
+ *
198
+ * Exposed to JS as `completeHostCall(callId, isError, content)`. The JS
199
+ * dispatch wrapper invokes this after it has decoded `argsBytes`, called
200
+ * the user function, and encoded the result (success) or constructed a
201
+ * `HostCallableError` (failure).
202
+ *
203
+ * Forwards directly to the `bridge_cffi::complete_host_call` C entry point
204
+ * the engine uses for cross-language completion.
205
+ */
206
+ export declare function completeHostCall(callId: number, isError: number, content: Buffer): void
207
+
208
+ /** Flush all buffered trace events to the JSONL file (if BAML_TRACE_FILE is set). */
209
+ export declare function flushEvents(): void
210
+
211
+ /**
212
+ * Return the process-global `BamlRuntime`, or a `BamlError`-shaped
213
+ * `napi::Error` if `initializeRuntime` has not run yet. The handle is
214
+ * zero-sized; the `Arc<dyn Bex>` lives in `bridge_cffi`. Mirrors
215
+ * `bridge_python`'s module-level `get_runtime()`.
216
+ */
217
+ export declare function getRuntime(): BamlRuntime
218
+
219
+ export declare function getVersion(): string
220
+
221
+ /**
222
+ * A u64 handle key split into two i32 halves, mirroring the shape of
223
+ * protobufjs's `Long` type (`{ low: number, high: number }`).
224
+ *
225
+ * JavaScript has no convenient native representation for u64 — `number` is
226
+ * f64 and silently loses precision above 2^53. Rather than forcing BigInt
227
+ * (which many JS libraries don't handle well), we pass the key as two 32-bit
228
+ * halves that are layout-compatible with `Long`. This means a protobufjs
229
+ * `Long` decoded from a uint64 proto field can be handed directly to the
230
+ * `BamlHandle` constructor, and the `HandleKey` returned by the getter can
231
+ * be passed straight back into a proto uint64 field — no conversions needed.
232
+ */
233
+ export interface HandleKey {
234
+ low: number
235
+ high: number
236
+ }
237
+
238
+ /**
239
+ * Allocate a fresh `HANDLE_TABLE` row sharing the same `Arc` as `handle`,
240
+ * returning the new key so the caller can stage a wire `BamlHandle`. The
241
+ * original `handle` keeps its key and stays usable. Mirrors
242
+ * `bridge_python::py_handle::put_pyhandle_into_table`.
243
+ */
244
+ export declare function putHandleIntoTable(handle: BamlHandle): HandleKey
245
+
246
+ /**
247
+ * Register a JS dispatch wrapper in the host-value table and return its key.
248
+ *
249
+ * Exposed to JS as `registerHostCallable(fn) -> HandleKey`. Called from
250
+ * the inbound encoder in `typescript_src/proto.ts` whenever a JS callable
251
+ * appears as a kwarg — the encoder constructs the dispatch wrapper around
252
+ * the user's function before calling this.
253
+ *
254
+ * The `Function` is converted into a `ThreadsafeFunction` so it can outlive
255
+ * the napi call scope and be invoked from any thread (the engine's tokio
256
+ * runtime calls into this entry point from a worker thread).
257
+ */
258
+ export declare function registerHostCallable(callable: (callId: number, argsBytes: Buffer) => void): HandleKey
259
+
260
+ /**
261
+ * Release a host callable the inbound encoder registered but never handed to
262
+ * the engine — the encode-error rollback path.
263
+ *
264
+ * Exposed to JS as `releaseHostCallable(key)`. When `encodeCallArgs`
265
+ * registers a callable for an early kwarg and then fails to encode a later
266
+ * kwarg, the `CallFunctionArgs` is never sent, so the engine never decodes
267
+ * (and so never releases) that key. Without this, the registry entry — and
268
+ * its strong `weak::<false>` tsfn ref, which keeps the libuv loop alive —
269
+ * would leak for the life of the process. The encoder calls this for every
270
+ * key it registered during a failed encode.
271
+ */
272
+ export declare function releaseHostCallable(key: HandleKey): void
273
+
274
+ /**
275
+ * Validate that `key` exists in `HANDLE_TABLE`, then wrap as a `BamlHandle`.
276
+ * Used by the proto decoder's handle path. Does **not** drain — the entry
277
+ * stays in the table and is owned by the returned `BamlHandle`. Mirrors
278
+ * `bridge_python::py_handle::take_pyhandle_from_table`.
279
+ */
280
+ export declare function takeHandleFromTable(key: HandleKey, handleType: number): BamlHandle