@boundaryml/baml-core-node 0.11.2-nightly.20260604.d → 0.11.3-nightly.20260606.b

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.
@@ -13,7 +13,7 @@ export declare const UNSET: unique symbol;
13
13
  * that maps positional args to kwargs, encodes, calls the runtime, and decodes.
14
14
  * `sync` returns the decoded value; `async` returns a `Promise` of it.
15
15
  */
16
- export declare function defineFunction(bamlFqn: string, mode: Mode, paramNames: readonly string[], requiredPositionalCount?: number): (...args: unknown[]) => unknown;
16
+ export declare function defineFunction(bamlFqn: string, mode: Mode, requiredParamNames: readonly string[], optionalParamNames?: readonly string[] | undefined): (...args: unknown[]) => unknown;
17
17
  /**
18
18
  * Receiver-binding factory for instance methods. `paramNames[0]` is always
19
19
  * `"self"`. Codegen emits the binding as a class-field initializer
@@ -21,7 +21,7 @@ export declare function defineFunction(bamlFqn: string, mode: Mode, paramNames:
21
21
  * captures the instance at construction time; the synthetic `self` param never
22
22
  * appears in the surface type.
23
23
  */
24
- export declare function defineInstanceFunction(bamlFqn: string, mode: Mode, paramNames: readonly string[]): {
24
+ export declare function defineInstanceFunction(bamlFqn: string, mode: Mode, requiredParamNames: readonly string[], optionalParamNames?: readonly string[] | undefined): {
25
25
  bind(self: unknown): (...args: unknown[]) => unknown;
26
26
  };
27
27
  //# sourceMappingURL=define_function.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"define_function.d.ts","sourceRoot":"","sources":["../typescript_src/define_function.ts"],"names":[],"mappings":"AAgBA,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,OAAO,CAAC;AAEpC,8EAA8E;AAC9E,eAAO,MAAM,KAAK,EAAE,OAAO,MAA6B,CAAC;AAsBzD;;;;GAIG;AACH,wBAAgB,cAAc,CAC1B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,uBAAuB,CAAC,EAAE,MAAM,GACjC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAqBjC;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAClC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,SAAS,MAAM,EAAE,GAC9B;IAAE,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAA;CAAE,CAkC1D"}
1
+ {"version":3,"file":"define_function.d.ts","sourceRoot":"","sources":["../typescript_src/define_function.ts"],"names":[],"mappings":"AAgBA,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,OAAO,CAAC;AAEpC,8EAA8E;AAC9E,eAAO,MAAM,KAAK,EAAE,OAAO,MAA6B,CAAC;AAwCzD;;;;GAIG;AACH,wBAAgB,cAAc,CAC1B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,IAAI,EACV,kBAAkB,EAAE,SAAS,MAAM,EAAE,EACrC,kBAAkB,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GACnD,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAsBjC;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAClC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,IAAI,EACV,kBAAkB,EAAE,SAAS,MAAM,EAAE,EACrC,kBAAkB,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GACnD;IAAE,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAA;CAAE,CAmC1D"}
@@ -14,24 +14,43 @@
14
14
  // and per instance method (inside the class body):
15
15
  // m = defineInstanceFunction("user.ns.C.m", "sync", ["self"]).bind(this) as () => R;
16
16
  //
17
- // The factory captures (fqn, mode, paramNames) by closure; the returned
18
- // callable zips positional args against paramNames into a kwargs object,
17
+ // The factory captures (fqn, mode, requiredNames, optionalNames) by closure;
18
+ // the returned callable zips positional args against requiredNames into kwargs,
19
19
  // encodes it, calls the runtime, and decodes the result.
20
20
  import { getRuntime } from './native.js';
21
21
  import { encodeCallArgs, decodeCallResult } from './proto.js';
22
22
  /** Sentinel for "argument not supplied" so optional kwargs can be skipped. */
23
23
  export const UNSET = Symbol('baml.UNSET');
24
- function buildKwargs(args, paramNames, requiredPositionalCount) {
25
- const positionalLimit = requiredPositionalCount ?? paramNames.length;
26
- if (args.length > positionalLimit) {
24
+ function buildKwargs(args, requiredParamNames, optionalParamNames) {
25
+ const positionalLimit = requiredParamNames.length;
26
+ const hasOpts = optionalParamNames.length > 0;
27
+ if (args.length > positionalLimit + (hasOpts ? 1 : 0)) {
27
28
  throw new TypeError(`got ${args.length} positional arguments but only ${positionalLimit} positional ` +
28
- `parameter names (${JSON.stringify(paramNames.slice(0, positionalLimit))})`);
29
+ `parameter names (${JSON.stringify(requiredParamNames)})`);
29
30
  }
30
31
  const built = {};
31
- for (let i = 0; i < args.length && i < paramNames.length; i++) {
32
+ for (let i = 0; i < args.length && i < positionalLimit; i++) {
32
33
  if (args[i] === UNSET)
33
34
  continue;
34
- built[paramNames[i]] = args[i];
35
+ built[requiredParamNames[i]] = args[i];
36
+ }
37
+ if (hasOpts && args.length > positionalLimit) {
38
+ const opts = args[positionalLimit];
39
+ if (opts === undefined || opts === UNSET) {
40
+ return built;
41
+ }
42
+ if (opts === null || Array.isArray(opts) || typeof opts !== 'object') {
43
+ throw new TypeError('optional arguments must be passed as an object');
44
+ }
45
+ const optionNames = new Set(optionalParamNames);
46
+ for (const [key, value] of Object.entries(opts)) {
47
+ if (!optionNames.has(key)) {
48
+ throw new TypeError(`unknown optional argument ${JSON.stringify(key)}`);
49
+ }
50
+ if (value === undefined || value === UNSET)
51
+ continue;
52
+ built[key] = value;
53
+ }
35
54
  }
36
55
  return built;
37
56
  }
@@ -40,11 +59,12 @@ function buildKwargs(args, paramNames, requiredPositionalCount) {
40
59
  * that maps positional args to kwargs, encodes, calls the runtime, and decodes.
41
60
  * `sync` returns the decoded value; `async` returns a `Promise` of it.
42
61
  */
43
- export function defineFunction(bamlFqn, mode, paramNames, requiredPositionalCount) {
44
- const names = [...paramNames];
62
+ export function defineFunction(bamlFqn, mode, requiredParamNames, optionalParamNames) {
63
+ const requiredNames = [...requiredParamNames];
64
+ const optionNames = [...(optionalParamNames ?? [])];
45
65
  if (mode === 'sync') {
46
66
  return (...args) => {
47
- const merged = buildKwargs(args, names, requiredPositionalCount);
67
+ const merged = buildKwargs(args, requiredNames, optionNames);
48
68
  const rt = getRuntime();
49
69
  const argsProto = encodeCallArgs(merged, /* syncMode */ true);
50
70
  const resultBytes = rt.callFunctionSync(bamlFqn, argsProto, null, null, null);
@@ -53,7 +73,7 @@ export function defineFunction(bamlFqn, mode, paramNames, requiredPositionalCoun
53
73
  }
54
74
  if (mode === 'async') {
55
75
  return async (...args) => {
56
- const merged = buildKwargs(args, names, requiredPositionalCount);
76
+ const merged = buildKwargs(args, requiredNames, optionNames);
57
77
  const rt = getRuntime();
58
78
  const argsProto = encodeCallArgs(merged);
59
79
  const resultBytes = await rt.callFunction(bamlFqn, argsProto, null, null, null);
@@ -69,12 +89,13 @@ export function defineFunction(bamlFqn, mode, paramNames, requiredPositionalCoun
69
89
  * captures the instance at construction time; the synthetic `self` param never
70
90
  * appears in the surface type.
71
91
  */
72
- export function defineInstanceFunction(bamlFqn, mode, paramNames) {
73
- const names = [...paramNames];
74
- const selfName = names[0] ?? 'self';
75
- const rest = names.slice(1);
92
+ export function defineInstanceFunction(bamlFqn, mode, requiredParamNames, optionalParamNames) {
93
+ const requiredNames = [...requiredParamNames];
94
+ const optionNames = [...(optionalParamNames ?? [])];
95
+ const selfName = requiredNames[0] ?? 'self';
96
+ const rest = requiredNames.slice(1);
76
97
  const makeKwargs = (self, args) => {
77
- const merged = buildKwargs(args, rest);
98
+ const merged = buildKwargs(args, rest, optionNames);
78
99
  merged[selfName] = self;
79
100
  return merged;
80
101
  };
@@ -1 +1 @@
1
- {"version":3,"file":"define_function.js","sourceRoot":"","sources":["../typescript_src/define_function.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,iEAAiE;AACjE,EAAE;AACF,+CAA+C;AAC/C,gFAAgF;AAChF,gGAAgG;AAChG,mDAAmD;AACnD,uFAAuF;AACvF,EAAE;AACF,wEAAwE;AACxE,yEAAyE;AACzE,yDAAyD;AAEzD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAI9D,8EAA8E;AAC9E,MAAM,CAAC,MAAM,KAAK,GAAkB,MAAM,CAAC,YAAY,CAAC,CAAC;AAEzD,SAAS,WAAW,CAChB,IAAe,EACf,UAA6B,EAC7B,uBAAgC;IAEhC,MAAM,eAAe,GAAG,uBAAuB,IAAI,UAAU,CAAC,MAAM,CAAC;IACrE,IAAI,IAAI,CAAC,MAAM,GAAG,eAAe,EAAE,CAAC;QAChC,MAAM,IAAI,SAAS,CACf,OAAO,IAAI,CAAC,MAAM,kCAAkC,eAAe,cAAc;YACjF,oBAAoB,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,GAAG,CAC9E,CAAC;IACN,CAAC;IACD,MAAM,KAAK,GAA4B,EAAE,CAAC;IAC1C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5D,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,KAAK;YAAE,SAAS;QAChC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,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oBACtC,MAAM,EAAE,GAAG,UAAU,EAAE,CAAC;oBACxB,MAAM,SAAS,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;oBACzC,MAAM,WAAW,GAAG,MAAM,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;oBAChF,OAAO,gBAAgB,CAAC,WAAW,CAAC,CAAC;gBACzC,CAAC,CAAC;YACN,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,uCAAuC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACnF,CAAC;KACJ,CAAC;AACN,CAAC"}
@@ -0,0 +1,57 @@
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 { type HandleKey } from './native.js';
9
+ /**
10
+ * Register a JS error object and return its native `HandleKey` for the
11
+ * `_handle: Handle(HOST_VALUE_ERROR, key)` slot of a
12
+ * `baml.errors.HostCallable` Instance. Mints a fresh key via the Rust
13
+ * side's shared counter (guaranteed non-zero — Rust `next_key` skips
14
+ * `0`); stores the error keyed by the same key (recomposed as a
15
+ * `bigint` for `Map`-key equality).
16
+ *
17
+ * Returns the native `HandleKey` directly so it can flow into the
18
+ * protobufjs encoder without an intermediate `bigint→Long` conversion
19
+ * (protobufjs reads `uint64` fields from a `{low, high}` shape, which
20
+ * the native `HandleKey` already provides; a bare `bigint` does not
21
+ * encode correctly through the `IInboundValue.handle.key` field).
22
+ */
23
+ export declare function registerHostError(err: unknown): HandleKey;
24
+ /**
25
+ * Look up a host-registered JS error by key. Returns `undefined` when:
26
+ * - the key is the reserved sentinel `0n` (no real error was registered);
27
+ * - the engine has already released the entry (last `HostValueArc` clone
28
+ * dropped → Rust `host_release_callback` fired → `_releaseHostError`
29
+ * removed the entry);
30
+ * - the key was minted by a different Node process (cross-runtime handle).
31
+ *
32
+ * Callers should fall back to a metadata-built exception in those cases.
33
+ *
34
+ * GC/decode race: a release notification and a rehydrating decode can be
35
+ * scheduled on the libuv loop concurrently in principle, but in practice
36
+ * the same `HostValueArc` cannot drop *while* the engine is actively
37
+ * emitting an outbound proto referencing its key — the outbound encode
38
+ * holds a strong handle through proto serialization, and the release tsfn
39
+ * isn't fired until that strong handle drops. By the time the TS decoder
40
+ * runs `tryRehydrateFromHandle`, the only way the map entry is gone is if
41
+ * a *prior* outbound completed and the engine has since dropped its last
42
+ * Arc; in that case the user has already observed the original throw at
43
+ * least once, so a second lookup-miss → metadata-fallback is acceptable.
44
+ */
45
+ export declare function lookupHostError(key: bigint): unknown;
46
+ /**
47
+ * Convenience for the outbound decoder: if `handle` is a `BamlHandle`
48
+ * tagged `HOST_VALUE_ERROR`, look up the originating JS error object in
49
+ * the registry and return it. Returns `undefined` for any other handle
50
+ * type, a non-`BamlHandle` argument, or a key that doesn't resolve.
51
+ *
52
+ * Used by `decodeCallResult`'s `error` arm to rehydrate the original JS
53
+ * exception when a BAML-thrown `baml.errors.HostCallable` propagates back
54
+ * to the same Node process that originated it.
55
+ */
56
+ export declare function tryRehydrateFromHandle(handle: unknown): unknown;
57
+ //# sourceMappingURL=host_error_registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host_error_registry.d.ts","sourceRoot":"","sources":["../typescript_src/host_error_registry.ts"],"names":[],"mappings":"AAmCA,OAAO,EAA8D,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AA4BzG;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,CAIzD;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAI/D"}
@@ -0,0 +1,139 @@
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
+ // host_error_registry.ts — mirrors bridge_python's `register_host_error`
9
+ // + `lookup_host_value` pair.
10
+ //
11
+ // A native JS exception raised inside a user callable round-trips back to
12
+ // the *same* Node process as the *same* `Error` object (`raised === caught`
13
+ // identity), not flattened into a metadata-only `BamlError(HostCallable(...))`
14
+ // wrapper. The plumbing:
15
+ //
16
+ // 1. The TS bridge catches the JS error inside `sendHostCallableError`
17
+ // (proto.ts) and calls `registerHostError(err)` here.
18
+ // 2. `registerHostError` mints a globally-unique key via
19
+ // `native.mintHostErrorKey` (drawing from the shared callable+error
20
+ // counter on the Rust side so the engine sees one keyspace), stores
21
+ // the JS error in the local `Map<bigint, unknown>`, returns the key.
22
+ // 3. The bridge emits an `InboundValue.Class(name="baml.errors.HostCallable",
23
+ // fields=[..., _handle: Handle(HOST_VALUE_ERROR, key)])`. The engine
24
+ // interns an `Arc<HostValueArc>` per the same key.
25
+ // 4. When BAML propagates the throw back out to the host, the outbound
26
+ // encoder re-emits the `_handle: Handle(HOST_VALUE_ERROR, key)`. The
27
+ // TS decoder (proto.ts) inspects a decoded `HostCallable` instance,
28
+ // reads `_handle.key`, calls `lookupHostError(key)` here, and re-throws
29
+ // the original JS error.
30
+ // 5. When the engine drops its last `Arc<HostValueArc>(key)`, the Rust
31
+ // `host_release_callback` fires the TS-installed release callback
32
+ // (`native.registerErrorReleaseCallback`), which calls `_releaseHostError`
33
+ // here to remove the map entry.
34
+ //
35
+ // Foreign runtimes (a different Node process, the Python bridge, etc.) see
36
+ // a `_handle` whose key doesn't resolve in their local registry; the
37
+ // decoder falls back to the metadata-bearing `BamlError(HostCallable(...))`
38
+ // wrapper. The reserved `0` is used as a sentinel by code paths that
39
+ // cannot register a real JS error (engine-internal synthetic faults like
40
+ // "no JS callable for this key"); `_releaseHostError(0n)` is a benign
41
+ // no-op since `mintHostErrorKey` never returns `0`.
42
+ import { mintHostErrorKey, registerErrorReleaseCallback, BamlHandle } from './native.js';
43
+ import { baml_core } from './proto/baml_cffi.js';
44
+ const BamlHandleType = baml_core.cffi.v1.BamlHandleType;
45
+ const errorMap = new Map();
46
+ /**
47
+ * Convert a `HandleKey` (`{ low, high }`) to a `bigint` for use as a `Map` key.
48
+ * Native `HandleKey` instances split a `u64` across two `i32` low/high halves
49
+ * (signed, two's-complement). Recompose by treating each half as a 32-bit
50
+ * unsigned value via `>>> 0`, then shift+or as `bigint`.
51
+ *
52
+ * The `>>> 0` coercion matters whenever either half's MSB is set: without it,
53
+ * a negative `i32` would widen to a negative `bigint` and corrupt the
54
+ * recomposed `u64`. Examples:
55
+ *
56
+ * - `{ low: 1, high: 0 }` → `0x1n` (small key, no MSB set)
57
+ * - `{ low: -1, high: -1 }` → `0xFFFFFFFFFFFFFFFFn` (u64::MAX; both halves'
58
+ * MSB set — `>>> 0` reinterprets `-1` as `0xFFFFFFFF` before widening)
59
+ * - `{ low: 0, high: 1 }` → `0x1_00000000n` (2^32)
60
+ */
61
+ function handleKeyToBigint(key) {
62
+ const low = BigInt(key.low >>> 0);
63
+ const high = BigInt(key.high >>> 0);
64
+ return (high << 32n) | low;
65
+ }
66
+ /**
67
+ * Register a JS error object and return its native `HandleKey` for the
68
+ * `_handle: Handle(HOST_VALUE_ERROR, key)` slot of a
69
+ * `baml.errors.HostCallable` Instance. Mints a fresh key via the Rust
70
+ * side's shared counter (guaranteed non-zero — Rust `next_key` skips
71
+ * `0`); stores the error keyed by the same key (recomposed as a
72
+ * `bigint` for `Map`-key equality).
73
+ *
74
+ * Returns the native `HandleKey` directly so it can flow into the
75
+ * protobufjs encoder without an intermediate `bigint→Long` conversion
76
+ * (protobufjs reads `uint64` fields from a `{low, high}` shape, which
77
+ * the native `HandleKey` already provides; a bare `bigint` does not
78
+ * encode correctly through the `IInboundValue.handle.key` field).
79
+ */
80
+ export function registerHostError(err) {
81
+ const key = mintHostErrorKey();
82
+ errorMap.set(handleKeyToBigint(key), err);
83
+ return key;
84
+ }
85
+ /**
86
+ * Look up a host-registered JS error by key. Returns `undefined` when:
87
+ * - the key is the reserved sentinel `0n` (no real error was registered);
88
+ * - the engine has already released the entry (last `HostValueArc` clone
89
+ * dropped → Rust `host_release_callback` fired → `_releaseHostError`
90
+ * removed the entry);
91
+ * - the key was minted by a different Node process (cross-runtime handle).
92
+ *
93
+ * Callers should fall back to a metadata-built exception in those cases.
94
+ *
95
+ * GC/decode race: a release notification and a rehydrating decode can be
96
+ * scheduled on the libuv loop concurrently in principle, but in practice
97
+ * the same `HostValueArc` cannot drop *while* the engine is actively
98
+ * emitting an outbound proto referencing its key — the outbound encode
99
+ * holds a strong handle through proto serialization, and the release tsfn
100
+ * isn't fired until that strong handle drops. By the time the TS decoder
101
+ * runs `tryRehydrateFromHandle`, the only way the map entry is gone is if
102
+ * a *prior* outbound completed and the engine has since dropped its last
103
+ * Arc; in that case the user has already observed the original throw at
104
+ * least once, so a second lookup-miss → metadata-fallback is acceptable.
105
+ */
106
+ export function lookupHostError(key) {
107
+ return errorMap.get(key);
108
+ }
109
+ /**
110
+ * Convenience for the outbound decoder: if `handle` is a `BamlHandle`
111
+ * tagged `HOST_VALUE_ERROR`, look up the originating JS error object in
112
+ * the registry and return it. Returns `undefined` for any other handle
113
+ * type, a non-`BamlHandle` argument, or a key that doesn't resolve.
114
+ *
115
+ * Used by `decodeCallResult`'s `error` arm to rehydrate the original JS
116
+ * exception when a BAML-thrown `baml.errors.HostCallable` propagates back
117
+ * to the same Node process that originated it.
118
+ */
119
+ export function tryRehydrateFromHandle(handle) {
120
+ if (!(handle instanceof BamlHandle))
121
+ return undefined;
122
+ if (handle.handleType !== BamlHandleType.HOST_VALUE_ERROR)
123
+ return undefined;
124
+ return lookupHostError(handleKeyToBigint(handle.key));
125
+ }
126
+ /**
127
+ * Internal: remove the map entry for `key`. Wired at module init as the
128
+ * Rust-side release callback. Idempotent and absent-key-safe so the same
129
+ * callback can be invoked for *every* `HostValueArc` release (including
130
+ * callable keys, which never have a TS-side error entry).
131
+ */
132
+ function _releaseHostError(key) {
133
+ errorMap.delete(handleKeyToBigint(key));
134
+ }
135
+ // Install the Rust-side release callback exactly once at module load. The
136
+ // napi function is itself first-call-wins on the Rust side, so reloads
137
+ // (e.g. test harnesses) are harmless.
138
+ registerErrorReleaseCallback(_releaseHostError);
139
+ //# sourceMappingURL=host_error_registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host_error_registry.js","sourceRoot":"","sources":["../typescript_src/host_error_registry.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,8BAA8B;AAC9B,EAAE;AACF,0EAA0E;AAC1E,4EAA4E;AAC5E,+EAA+E;AAC/E,yBAAyB;AACzB,EAAE;AACF,yEAAyE;AACzE,2DAA2D;AAC3D,2DAA2D;AAC3D,yEAAyE;AACzE,yEAAyE;AACzE,0EAA0E;AAC1E,gFAAgF;AAChF,0EAA0E;AAC1E,wDAAwD;AACxD,yEAAyE;AACzE,0EAA0E;AAC1E,yEAAyE;AACzE,6EAA6E;AAC7E,8BAA8B;AAC9B,yEAAyE;AACzE,uEAAuE;AACvE,gFAAgF;AAChF,qCAAqC;AACrC,EAAE;AACF,2EAA2E;AAC3E,qEAAqE;AACrE,4EAA4E;AAC5E,qEAAqE;AACrE,yEAAyE;AACzE,sEAAsE;AACtE,oDAAoD;AAEpD,OAAO,EAAE,gBAAgB,EAAE,4BAA4B,EAAE,UAAU,EAAkB,MAAM,aAAa,CAAC;AACzG,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,MAAM,cAAc,GAAG,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4BAA4B,CAAC,iBAAiB,CAAC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  import { BamlRuntime, AbortController, HostSpanManager, Collector as NativeCollector, FunctionLog as NativeFunctionLog, Timing, Usage, LLMCall } from './native.js';
9
9
  export { BamlRuntime, AbortController, BamlHandle, HostSpanManager, getRuntime, getVersion, flushEvents } from './native.js';
10
10
  export { Timing, Usage, LLMCall } from './native.js';
11
- export { takeHandleFromTable, putHandleIntoTable, _seedFunctionRefHandle, _seedGenericMediaHandle, } from './native.js';
11
+ export { _seedFunctionRefHandle, _seedGenericMediaHandle } from './native.js';
12
12
  export { BamlImage, BamlAudio, BamlVideo, BamlPdf } from './native.js';
13
13
  export { BamlStream } from './stream.js';
14
14
  export { encodeCallArgs, decodeCallResult } from './proto.js';
@@ -1 +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,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,GAC1B,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9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AM,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,CAmBhB;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,CAezB"}
package/dist/index.js CHANGED
@@ -11,8 +11,7 @@ import { encodeCallArgs, decodeCallResult } from './proto.js';
11
11
  import { installFlushOnExit } from './exit_hook.js';
12
12
  export { BamlRuntime, AbortController, BamlHandle, HostSpanManager, getRuntime, getVersion, flushEvents } from './native.js';
13
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';
14
+ export { _seedFunctionRefHandle, _seedGenericMediaHandle } from './native.js';
16
15
  // Runtime-owned stdlib value classes. Exported under their `Baml*` names only;
17
16
  // codegen aliases them as Image/Audio/Video/Pdf on re-export.
18
17
  export { BamlImage, BamlAudio, BamlVideo, BamlPdf } from './native.js';
@@ -101,24 +100,36 @@ export function callFunctionSync(rt, functionName, kwargs, ctx, collectors, abor
101
100
  // starving libuv so the dispatch could never run.
102
101
  const argsProto = encodeCallArgs(kwargs, /* syncMode */ true);
103
102
  const nativeCollectors = collectors?.map(c => c._native()) ?? null;
103
+ // Only the napi call gets `wrapNativeError`'d — its `napi::Error`
104
+ // messages need parsing into typed `Baml*Error` subclasses. The
105
+ // decoder's throws (`BamlError`/`BamlPanic`, *or* a re-raised
106
+ // original JS exception from the host-callable rehydration path)
107
+ // already carry the right type and must propagate by identity.
108
+ let resultBytes;
104
109
  try {
105
- const resultBytes = rt.callFunctionSync(functionName, argsProto, ctx ?? null, nativeCollectors, abortController ?? null);
106
- return new FunctionResult(decodeCallResult(resultBytes));
110
+ resultBytes = rt.callFunctionSync(functionName, argsProto, ctx ?? null, nativeCollectors, abortController ?? null);
107
111
  }
108
112
  catch (err) {
109
113
  throw wrapNativeError(err);
110
114
  }
115
+ return new FunctionResult(decodeCallResult(resultBytes));
111
116
  }
112
117
  export async function callFunction(rt, functionName, kwargs, ctx, collectors, abortController) {
113
118
  const argsProto = encodeCallArgs(kwargs);
114
119
  const nativeCollectors = collectors?.map(c => c._native()) ?? null;
120
+ // Only the napi call gets `wrapNativeError`'d — its `napi::Error`
121
+ // messages need parsing into typed `Baml*Error` subclasses. The
122
+ // decoder's throws (`BamlError`/`BamlPanic`, *or* a re-raised
123
+ // original JS exception from the host-callable rehydration path)
124
+ // already carry the right type and must propagate by identity.
125
+ let resultBytes;
115
126
  try {
116
- const resultBytes = await rt.callFunction(functionName, argsProto, ctx ?? null, nativeCollectors, abortController ?? null);
117
- return new FunctionResult(decodeCallResult(resultBytes));
127
+ resultBytes = await rt.callFunction(functionName, argsProto, ctx ?? null, nativeCollectors, abortController ?? null);
118
128
  }
119
129
  catch (err) {
120
130
  throw wrapNativeError(err);
121
131
  }
132
+ return new FunctionResult(decodeCallResult(resultBytes));
122
133
  }
123
134
  // Register flush on process exit (single registration; see exit_hook.ts).
124
135
  installFlushOnExit();
package/dist/index.js.map CHANGED
@@ -1 +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,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACvE,4EAA4E;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,8EAA8E;AAC9E,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACnE,6EAA6E;AAC7E,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAErF;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CA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;IACnE,kEAAkE;IAClE,gEAAgE;IAChE,8DAA8D;IAC9D,iEAAiE;IACjE,+DAA+D;IAC/D,IAAI,WAAmB,CAAC;IACxB,IAAI,CAAC;QACD,WAAW,GAAG,MAAM,EAAE,CAAC,YAAY,CAAC,YAAY,EAAE,SAAS,EAAE,GAAG,IAAI,IAAI,EAAE,gBAAgB,EAAE,eAAe,IAAI,IAAI,CAAC,CAAC;IACzH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,MAAM,eAAe,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,IAAI,cAAc,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED,0EAA0E;AAC1E,kBAAkB,EAAE,CAAC"}
package/dist/native.d.ts CHANGED
@@ -47,6 +47,7 @@ export declare class BamlHandle {
47
47
  get key(): HandleKey
48
48
  get handleType(): number
49
49
  clone(): BamlHandle
50
+ _cloneKeyForWire(): HandleKey
50
51
  }
51
52
 
52
53
  export declare class BamlImage {
@@ -197,8 +198,9 @@ export declare function _seedGenericMediaHandle(): [HandleKey, number]
197
198
  *
198
199
  * Exposed to JS as `completeHostCall(callId, isError, content)`. The JS
199
200
  * 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).
201
+ * the user function, and encoded the result as an `InboundValue` (success
202
+ * is the value itself; an error is an `Instance` of
203
+ * `baml.errors.HostCallable` carrying the four metadata fields).
202
204
  *
203
205
  * Forwards directly to the `bridge_cffi::complete_host_call` C entry point
204
206
  * the engine uses for cross-language completion.
@@ -236,12 +238,44 @@ export interface HandleKey {
236
238
  }
237
239
 
238
240
  /**
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`.
241
+ * Mint a fresh host-value key, drawing from the shared callable+error
242
+ * counter so the engine sees one globally-unique keyspace. Returned to
243
+ * TS by `registerHostError` (the TS-side function in
244
+ * `host_error_registry.ts`).
245
+ *
246
+ * Exposed to JS as `mintHostErrorKey() -> HandleKey`. The TS-side error
247
+ * registry calls this once per `registerHostError(err)` before inserting
248
+ * the error into its `Map<bigint, unknown>`.
249
+ */
250
+ export declare function mintHostErrorKey(): HandleKey
251
+
252
+ /**
253
+ * Install the TS-side release callback. First-call-wins; subsequent
254
+ * calls are a no-op (matching the bridge_cffi dispatch-registration
255
+ * semantics). The callback fires for *every* `HostValueArc` release —
256
+ * for callable keys it's a TS-side no-op (`Map.delete(key)` on an absent
257
+ * key), so Rust doesn't need to distinguish kinds here.
258
+ *
259
+ * The tsfn is built with `weak::<true>()` (i.e. `napi_unref_threadsafe_
260
+ * function`). Holding it strong would pin the libuv loop for the
261
+ * lifetime of the process (the tsfn is parked in a `OnceLock` and never
262
+ * dropped), preventing the Node process from exiting even after all
263
+ * host work is done. Weak is correct here: the callback is a *release*
264
+ * notification — purely informational from the engine's side. Pending
265
+ * notifications that never deliver because the loop has already exited
266
+ * are harmless; the engine has already dropped its `Arc<HostValueArc>`,
267
+ * and the TS-side map entry would be torn down with the process
268
+ * anyway.
269
+ *
270
+ * Note this is the inverse of `register_host_callable`'s dispatch tsfn,
271
+ * which is `weak::<false>()` — that one pins the loop because a hung
272
+ * host callback awaiting completion *must* keep the loop alive so the
273
+ * JS callback can actually run.
274
+ *
275
+ * Exposed to JS as `registerErrorReleaseCallback(cb)`. Must be called
276
+ * exactly once at SDK module init, before any host call is dispatched.
243
277
  */
244
- export declare function putHandleIntoTable(handle: BamlHandle): HandleKey
278
+ export declare function registerErrorReleaseCallback(callback: (key: HandleKey) => void): void
245
279
 
246
280
  /**
247
281
  * Register a JS dispatch wrapper in the host-value table and return its key.
@@ -270,11 +304,3 @@ export declare function registerHostCallable(callable: (callId: number, argsByte
270
304
  * key it registered during a failed encode.
271
305
  */
272
306
  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