@boundaryml/baml-bridge 0.0.0 → 0.13.1-nightly.20260707.e

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.
Files changed (46) hide show
  1. package/dist/ctx_manager.d.ts +22 -0
  2. package/dist/ctx_manager.d.ts.map +1 -0
  3. package/dist/ctx_manager.js +91 -0
  4. package/dist/ctx_manager.js.map +1 -0
  5. package/dist/define_function.d.ts +38 -0
  6. package/dist/define_function.d.ts.map +1 -0
  7. package/dist/define_function.js +281 -0
  8. package/dist/define_function.js.map +1 -0
  9. package/dist/errors.d.ts +51 -0
  10. package/dist/errors.d.ts.map +1 -0
  11. package/dist/errors.js +67 -0
  12. package/dist/errors.js.map +1 -0
  13. package/dist/exit_hook.d.ts +9 -0
  14. package/dist/exit_hook.d.ts.map +1 -0
  15. package/dist/exit_hook.js +27 -0
  16. package/dist/exit_hook.js.map +1 -0
  17. package/dist/host_value_registry.d.ts +57 -0
  18. package/dist/host_value_registry.d.ts.map +1 -0
  19. package/dist/host_value_registry.js +141 -0
  20. package/dist/host_value_registry.js.map +1 -0
  21. package/dist/index.d.ts +67 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +162 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/native.d.ts +312 -0
  26. package/dist/native.js +625 -0
  27. package/dist/proto/baml_cffi.d.ts +6385 -0
  28. package/dist/proto/baml_cffi.js +17738 -0
  29. package/dist/proto.d.ts +62 -0
  30. package/dist/proto.d.ts.map +1 -0
  31. package/dist/proto.js +963 -0
  32. package/dist/proto.js.map +1 -0
  33. package/dist/stream.d.ts +23 -0
  34. package/dist/stream.d.ts.map +1 -0
  35. package/dist/stream.js +68 -0
  36. package/dist/stream.js.map +1 -0
  37. package/dist/typemap.d.ts +37 -0
  38. package/dist/typemap.d.ts.map +1 -0
  39. package/dist/typemap.js +110 -0
  40. package/dist/typemap.js.map +1 -0
  41. package/dist/wire_ty.d.ts +58 -0
  42. package/dist/wire_ty.d.ts.map +1 -0
  43. package/dist/wire_ty.js +147 -0
  44. package/dist/wire_ty.js.map +1 -0
  45. package/package.json +64 -5
  46. package/README.md +0 -3
@@ -0,0 +1,312 @@
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_bridge/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
+ export declare class BamlAudio {
11
+ static fromUrl(url: string, mimeType?: string | undefined | null): BamlAudio
12
+ static fromFile(file: string, mimeType?: string | undefined | null): BamlAudio
13
+ static fromBase64(base64: string, mimeType?: string | undefined | null): BamlAudio
14
+ url(): string | null
15
+ file(): string | null
16
+ base64(): string
17
+ mimeType(): string | null
18
+ /**
19
+ * Internal: build from an existing `BamlHandle`. Used by proto
20
+ * decode. Validates the handle's `handle_type` tag matches the
21
+ * expected media kind, then clones the table row so the input
22
+ * handle stays usable.
23
+ */
24
+ static _fromHandle(handle: BamlHandle): BamlAudio
25
+ /**
26
+ * Internal: produce a fresh `BamlHandle` pointing at the same
27
+ * table row (cloned). Used by inbound encode.
28
+ */
29
+ _toHandle(): BamlHandle
30
+ }
31
+
32
+ /** A call context for cancelling BAML function calls. */
33
+ export declare class BamlCallContext {
34
+ constructor()
35
+ abort(): void
36
+ get aborted(): boolean
37
+ _attachCallId(callId: string): void
38
+ _detachCallId(callId: string): void
39
+ }
40
+
41
+ /**
42
+ * Base class for all opaque BAML handles.
43
+ *
44
+ * When the Node.js garbage collector finalizes an instance, `finalize`
45
+ * releases the corresponding entry from the global handle table.
46
+ */
47
+ export declare class BamlHandle {
48
+ constructor(key: HandleKey, handleType: number)
49
+ get key(): HandleKey
50
+ get handleType(): number
51
+ clone(): BamlHandle
52
+ _cloneKeyForWire(): HandleKey
53
+ }
54
+
55
+ export declare class BamlImage {
56
+ static fromUrl(url: string, mimeType?: string | undefined | null): BamlImage
57
+ static fromFile(file: string, mimeType?: string | undefined | null): BamlImage
58
+ static fromBase64(base64: string, mimeType?: string | undefined | null): BamlImage
59
+ url(): string | null
60
+ file(): string | null
61
+ base64(): string
62
+ mimeType(): string | null
63
+ /**
64
+ * Internal: build from an existing `BamlHandle`. Used by proto
65
+ * decode. Validates the handle's `handle_type` tag matches the
66
+ * expected media kind, then clones the table row so the input
67
+ * handle stays usable.
68
+ */
69
+ static _fromHandle(handle: BamlHandle): BamlImage
70
+ /**
71
+ * Internal: produce a fresh `BamlHandle` pointing at the same
72
+ * table row (cloned). Used by inbound encode.
73
+ */
74
+ _toHandle(): BamlHandle
75
+ }
76
+
77
+ export declare class BamlPdf {
78
+ static fromUrl(url: string, mimeType?: string | undefined | null): BamlPdf
79
+ static fromFile(file: string, mimeType?: string | undefined | null): BamlPdf
80
+ static fromBase64(base64: string, mimeType?: string | undefined | null): BamlPdf
81
+ url(): string | null
82
+ file(): string | null
83
+ base64(): string
84
+ mimeType(): string | null
85
+ /**
86
+ * Internal: build from an existing `BamlHandle`. Used by proto
87
+ * decode. Validates the handle's `handle_type` tag matches the
88
+ * expected media kind, then clones the table row so the input
89
+ * handle stays usable.
90
+ */
91
+ static _fromHandle(handle: BamlHandle): BamlPdf
92
+ /**
93
+ * Internal: produce a fresh `BamlHandle` pointing at the same
94
+ * table row (cloned). Used by inbound encode.
95
+ */
96
+ _toHandle(): BamlHandle
97
+ }
98
+
99
+ /** The main BAML runtime. A zero-sized handle (see module docs). */
100
+ export declare class BamlRuntime {
101
+ /**
102
+ * Initialize the process-global runtime from in-memory BAML source
103
+ * files. `bridge_cffi::initialize_runtime` is a single-slot singleton, so
104
+ * a second call replaces the prior runtime; the result is also reachable
105
+ * via the module-level `getRuntime()`. Renamed from `fromFiles` for
106
+ * parity with `bridge_python`'s sole `initialize_runtime` constructor and
107
+ * the `initializeRuntime(...)` import the spec docs use.
108
+ */
109
+ static initializeRuntime(rootPath: string, files: Record<string, string>): BamlRuntime
110
+ /** Initialize the process-global runtime from precompiled BAML bytecode. */
111
+ static initializeRuntimeFromBytecode(bytecode: Buffer): BamlRuntime
112
+ /** Call a BAML function synchronously (blocking). */
113
+ callFunctionSync(functionName: string, argsProto: Buffer, ctx?: HostSpanManager | undefined | null, collectors?: Array<Collector> | undefined | null): Buffer
114
+ /** Call a BAML function asynchronously. */
115
+ callFunction(functionName: string, argsProto: Buffer, ctx?: HostSpanManager | undefined | null, collectors?: Array<Collector> | undefined | null): Promise<Buffer>
116
+ }
117
+
118
+ export declare class BamlVideo {
119
+ static fromUrl(url: string, mimeType?: string | undefined | null): BamlVideo
120
+ static fromFile(file: string, mimeType?: string | undefined | null): BamlVideo
121
+ static fromBase64(base64: string, mimeType?: string | undefined | null): BamlVideo
122
+ url(): string | null
123
+ file(): string | null
124
+ base64(): string
125
+ mimeType(): string | null
126
+ /**
127
+ * Internal: build from an existing `BamlHandle`. Used by proto
128
+ * decode. Validates the handle's `handle_type` tag matches the
129
+ * expected media kind, then clones the table row so the input
130
+ * handle stays usable.
131
+ */
132
+ static _fromHandle(handle: BamlHandle): BamlVideo
133
+ /**
134
+ * Internal: produce a fresh `BamlHandle` pointing at the same
135
+ * table row (cloned). Used by inbound encode.
136
+ */
137
+ _toHandle(): BamlHandle
138
+ }
139
+
140
+ export declare class Collector {
141
+ constructor(name?: string | undefined | null)
142
+ get name(): string
143
+ get logs(): Array<FunctionLog>
144
+ get last(): FunctionLog | null
145
+ get usage(): Usage
146
+ clear(): number
147
+ id(functionLogId: string): FunctionLog | null
148
+ }
149
+
150
+ export declare class FunctionLog {
151
+ get id(): string
152
+ get functionName(): string
153
+ get timing(): Timing
154
+ get usage(): Usage
155
+ get calls(): Array<LLMCall>
156
+ get tags(): Record<string, string>
157
+ get result(): Buffer | null
158
+ }
159
+
160
+ export declare class HostSpanManager {
161
+ constructor()
162
+ enter(name: string, args: any): void
163
+ exitOk(): void
164
+ exitError(errorMessage: string): void
165
+ upsertTags(tags: Record<string, string>): void
166
+ deepClone(): HostSpanManager
167
+ contextDepth(): number
168
+ }
169
+
170
+ export declare class LlmCall {
171
+ get functionName(): string
172
+ get provider(): string | null
173
+ get timing(): Timing
174
+ get usage(): Usage
175
+ }
176
+ export type LLMCall = LlmCall
177
+
178
+ export declare class Timing {
179
+ get startTimeUtcMs(): number
180
+ get durationMs(): number | null
181
+ }
182
+
183
+ export declare class Usage {
184
+ get inputTokens(): number | null
185
+ get outputTokens(): number | null
186
+ get cachedInputTokens(): number | null
187
+ }
188
+
189
+ /**
190
+ * Test-only: seed a `FunctionRef` entry into `HANDLE_TABLE`, returning
191
+ * `[key, handleType]` so test code can construct a `BamlHandle`.
192
+ */
193
+ export declare function _seedFunctionRefHandle(globalIndex: number): [HandleKey, number]
194
+
195
+ /** Test-only: seed an `Adt(Media(generic))` entry into `HANDLE_TABLE`. */
196
+ export declare function _seedGenericMediaHandle(): [HandleKey, number]
197
+
198
+ export declare function cancelFunctionCall(callId: string): boolean
199
+
200
+ /**
201
+ * Complete an in-flight host call from the JS dispatch wrapper.
202
+ *
203
+ * Exposed to JS as `completeHostCall(callId, isError, content)`. The JS
204
+ * dispatch wrapper invokes this after it has decoded `argsBytes`, called
205
+ * the user function, and encoded the result as an `InboundValue` (success
206
+ * is the value itself; an error is an `Instance` of
207
+ * `baml.errors.HostCallable` carrying the four metadata fields).
208
+ *
209
+ * Forwards directly to the `bridge_cffi::complete_host_call` C entry point
210
+ * the engine uses for cross-language completion.
211
+ */
212
+ export declare function completeHostCall(callId: number, isError: number, content: Buffer): void
213
+
214
+ /** No-op: tracing has been removed. Kept as a live symbol for ABI stability. */
215
+ export declare function flushEvents(): void
216
+
217
+ /**
218
+ * Return the process-global `BamlRuntime`, or a `BamlError`-shaped
219
+ * `napi::Error` if `initializeRuntime` has not run yet. The handle is
220
+ * zero-sized; the `Arc<dyn Bex>` lives in `bridge_cffi`. Mirrors
221
+ * `bridge_python`'s module-level `get_runtime()`.
222
+ */
223
+ export declare function getRuntime(): BamlRuntime
224
+
225
+ export declare function getVersion(): string
226
+
227
+ /**
228
+ * A u64 handle key split into two i32 halves, mirroring the shape of
229
+ * protobufjs's `Long` type (`{ low: number, high: number }`).
230
+ *
231
+ * JavaScript has no convenient native representation for u64 — `number` is
232
+ * f64 and silently loses precision above 2^53. Rather than forcing BigInt
233
+ * (which many JS libraries don't handle well), we pass the key as two 32-bit
234
+ * halves that are layout-compatible with `Long`. This means a protobufjs
235
+ * `Long` decoded from a uint64 proto field can be handed directly to the
236
+ * `BamlHandle` constructor, and the `HandleKey` returned by the getter can
237
+ * be passed straight back into a proto uint64 field — no conversions needed.
238
+ */
239
+ export interface HandleKey {
240
+ low: number
241
+ high: number
242
+ }
243
+
244
+ /**
245
+ * Mint a fresh host-value key, drawing from the shared callable+opaque
246
+ * counter so the engine sees one globally-unique keyspace. Returned to
247
+ * TS by `registerHostOpaque` (the TS-side function in
248
+ * `host_value_registry.ts`).
249
+ *
250
+ * Exposed to JS as `mintHostValueKey() -> HandleKey`. The TS-side host-value
251
+ * registry calls this once per `registerHostOpaque(value)` before inserting
252
+ * the value into its `Map<bigint, unknown>`.
253
+ */
254
+ export declare function mintHostValueKey(): HandleKey
255
+
256
+ export declare function newFunctionCall(): string
257
+
258
+ /**
259
+ * Register a JS dispatch wrapper in the host-value table and return its key.
260
+ *
261
+ * Exposed to JS as `registerHostCallable(fn) -> HandleKey`. Called from
262
+ * the inbound encoder in `typescript_src/proto.ts` whenever a JS callable
263
+ * appears as a kwarg — the encoder constructs the dispatch wrapper around
264
+ * the user's function before calling this.
265
+ *
266
+ * The `Function` is converted into a `ThreadsafeFunction` so it can outlive
267
+ * the napi call scope and be invoked from any thread (the engine's tokio
268
+ * runtime calls into this entry point from a worker thread).
269
+ */
270
+ export declare function registerHostCallable(callable: (callId: number, argsBytes: Buffer) => void): HandleKey
271
+
272
+ /**
273
+ * Install the TS-side release callback. First-call-wins; subsequent
274
+ * calls are a no-op (matching the bridge_cffi dispatch-registration
275
+ * semantics). The callback fires for *every* `HostValueArc` release —
276
+ * for callable keys it's a TS-side no-op (`Map.delete(key)` on an absent
277
+ * key), so Rust doesn't need to distinguish kinds here.
278
+ *
279
+ * The tsfn is built with `weak::<true>()` (i.e. `napi_unref_threadsafe_
280
+ * function`). Holding it strong would pin the libuv loop for the
281
+ * lifetime of the process (the tsfn is parked in a `OnceLock` and never
282
+ * dropped), preventing the Node process from exiting even after all
283
+ * host work is done. Weak is correct here: the callback is a *release*
284
+ * notification — purely informational from the engine's side. Pending
285
+ * notifications that never deliver because the loop has already exited
286
+ * are harmless; the engine has already dropped its `Arc<HostValueArc>`,
287
+ * and the TS-side map entry would be torn down with the process
288
+ * anyway.
289
+ *
290
+ * Note this is the inverse of `register_host_callable`'s dispatch tsfn,
291
+ * which is `weak::<false>()` — that one pins the loop because a hung
292
+ * host callback awaiting completion *must* keep the loop alive so the
293
+ * JS callback can actually run.
294
+ *
295
+ * Exposed to JS as `registerHostValueReleaseCallback(cb)`. Must be called
296
+ * exactly once at SDK module init, before any host call is dispatched.
297
+ */
298
+ export declare function registerHostValueReleaseCallback(callback: (key: HandleKey) => void): void
299
+
300
+ /**
301
+ * Release a host callable the inbound encoder registered but never handed to
302
+ * the engine — the encode-error rollback path.
303
+ *
304
+ * Exposed to JS as `releaseHostCallable(key)`. When `encodeCallArgs`
305
+ * registers a callable for an early kwarg and then fails to encode a later
306
+ * kwarg, the `CallFunctionArgs` is never sent, so the engine never decodes
307
+ * (and so never releases) that key. Without this, the registry entry — and
308
+ * its strong `weak::<false>` tsfn ref, which keeps the libuv loop alive —
309
+ * would leak for the life of the process. The encoder calls this for every
310
+ * key it registered during a failed encode.
311
+ */
312
+ export declare function releaseHostCallable(key: HandleKey): void