@bitfab/sdk 0.25.0 → 0.26.0

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.
package/dist/index.d.cts CHANGED
@@ -1384,10 +1384,97 @@ declare class BitfabFunction {
1384
1384
  * @returns A wrapped function with the same signature that creates spans
1385
1385
  */
1386
1386
  withSpan<TArgs extends unknown[], TReturn>(optionsOrFn: SpanOptions | ((...args: TArgs) => TReturn), maybeFn?: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
1387
+ /**
1388
+ * Get a Vercel AI SDK language-model middleware bound to this function's key.
1389
+ *
1390
+ * Equivalent to `client.getVercelAiMiddleware(key)` but reuses the key bound
1391
+ * on this handle, so an outer `withSpan` root and the middleware-traced model
1392
+ * calls share one key without repeating the string. With a matching key, the
1393
+ * outer span is the replayable root and the model-call spans nest beneath it.
1394
+ *
1395
+ * Nesting is captured when the model is called, so keep the
1396
+ * `generateText` / `streamText` call inside this handle's `withSpan`; the
1397
+ * middleware object itself can be created anywhere.
1398
+ *
1399
+ * ```typescript
1400
+ * const chatTurn = client.getFunction("chat-turn");
1401
+ * const runChatTurn = chatTurn.withSpan(
1402
+ * { type: "agent", finalize: finalizers.aiSdk },
1403
+ * (messages) => streamText({ model, messages }),
1404
+ * );
1405
+ * const model = wrapLanguageModel({
1406
+ * model: openai("gpt-4o"),
1407
+ * middleware: chatTurn.getVercelAiMiddleware(),
1408
+ * });
1409
+ * ```
1410
+ *
1411
+ * @returns A Vercel AI SDK middleware configured for this client and key
1412
+ */
1413
+ getVercelAiMiddleware(): BitfabLanguageModelMiddleware;
1414
+ /**
1415
+ * Get a Claude Agent SDK handler bound to this function's key.
1416
+ *
1417
+ * Equivalent to `client.getClaudeAgentHandler(key)` but reuses the key bound
1418
+ * on this handle, so an outer `withSpan` root and the handler share one key
1419
+ * without repeating the string. With a matching key, the outer span is the
1420
+ * replayable root and every handler span nests beneath it.
1421
+ *
1422
+ * Use the handler inside this handle's `withSpan` body so its spans capture
1423
+ * the enclosing root; framework calls made with no active span record their
1424
+ * own root instead.
1425
+ *
1426
+ * ```typescript
1427
+ * const pipeline = client.getFunction("my-agent");
1428
+ * const tracedRun = pipeline.withSpan({ type: "agent" }, async (prompt) => {
1429
+ * const handler = pipeline.getClaudeAgentHandler();
1430
+ * const options = handler.instrumentOptions({ model: "claude-sonnet-4-6" });
1431
+ * for await (const msg of handler.wrapQuery(query({ prompt, options }))) { ... }
1432
+ * });
1433
+ * ```
1434
+ *
1435
+ * @returns A Claude Agent SDK handler configured for this client and key
1436
+ */
1437
+ getClaudeAgentHandler(): BitfabClaudeAgentHandler;
1438
+ /**
1439
+ * Get a LangGraph/LangChain callback handler bound to this function's key.
1440
+ *
1441
+ * Equivalent to `client.getLangGraphCallbackHandler(key)` but reuses the key
1442
+ * bound on this handle, so an outer `withSpan` root and the handler share one
1443
+ * key without repeating the string. With a matching key, the outer span is
1444
+ * the replayable root and the LangGraph spans nest beneath it.
1445
+ *
1446
+ * Use the handler inside this handle's `withSpan` body so its spans capture
1447
+ * the enclosing root; framework calls made with no active span record their
1448
+ * own root instead.
1449
+ *
1450
+ * ```typescript
1451
+ * const pipeline = client.getFunction("my-pipeline");
1452
+ * const tracedRun = pipeline.withSpan({ type: "agent" }, async (query) => {
1453
+ * const handler = pipeline.getLangGraphCallbackHandler();
1454
+ * return agent.invoke({ messages: [...] }, { callbacks: [handler] });
1455
+ * });
1456
+ * ```
1457
+ *
1458
+ * @returns A LangGraph/LangChain callback handler for this client and key
1459
+ */
1460
+ getLangGraphCallbackHandler(): BitfabLangGraphCallbackHandler;
1461
+ /**
1462
+ * Alias of {@link getLangGraphCallbackHandler} — LangChain and LangGraph
1463
+ * share one callback system, so the same bound handler serves both.
1464
+ *
1465
+ * @returns A LangChain callback handler for this client and key
1466
+ */
1467
+ getLangChainCallbackHandler(): BitfabLangGraphCallbackHandler;
1387
1468
  /**
1388
1469
  * Wrap a BAML client method to automatically capture prompt and LLM metadata.
1389
1470
  * Delegates to the parent client's wrapBAML method.
1390
1471
  *
1472
+ * Unlike the other methods on this handle, `wrapBAML` does NOT use the bound
1473
+ * key: it opens no span of its own. It enriches the *current* span (via
1474
+ * `getCurrentSpan().setPrompt()` / `addContext()`), so call it inside a
1475
+ * function wrapped by this handle's `withSpan` — the bound key keys that
1476
+ * wrapper, and the BAML prompt/metadata attach to it.
1477
+ *
1391
1478
  * @param methodOrClient - Either a BAML method (uses constructor bamlClient) or the BAML client instance
1392
1479
  * @param maybeMethodOrOptions - The BAML method when the first argument is a client, or WrapBAMLOptions when the first argument is the method
1393
1480
  * @param maybeOptions - WrapBAMLOptions when using the two-argument (client, method) form
@@ -1404,7 +1491,7 @@ declare class BitfabFunction {
1404
1491
  /**
1405
1492
  * SDK version from package.json (injected at build time)
1406
1493
  */
1407
- declare const __version__ = "0.25.0";
1494
+ declare const __version__ = "0.26.0";
1408
1495
 
1409
1496
  /**
1410
1497
  * Constants for the Bitfab SDK.
package/dist/index.d.ts CHANGED
@@ -1384,10 +1384,97 @@ declare class BitfabFunction {
1384
1384
  * @returns A wrapped function with the same signature that creates spans
1385
1385
  */
1386
1386
  withSpan<TArgs extends unknown[], TReturn>(optionsOrFn: SpanOptions | ((...args: TArgs) => TReturn), maybeFn?: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
1387
+ /**
1388
+ * Get a Vercel AI SDK language-model middleware bound to this function's key.
1389
+ *
1390
+ * Equivalent to `client.getVercelAiMiddleware(key)` but reuses the key bound
1391
+ * on this handle, so an outer `withSpan` root and the middleware-traced model
1392
+ * calls share one key without repeating the string. With a matching key, the
1393
+ * outer span is the replayable root and the model-call spans nest beneath it.
1394
+ *
1395
+ * Nesting is captured when the model is called, so keep the
1396
+ * `generateText` / `streamText` call inside this handle's `withSpan`; the
1397
+ * middleware object itself can be created anywhere.
1398
+ *
1399
+ * ```typescript
1400
+ * const chatTurn = client.getFunction("chat-turn");
1401
+ * const runChatTurn = chatTurn.withSpan(
1402
+ * { type: "agent", finalize: finalizers.aiSdk },
1403
+ * (messages) => streamText({ model, messages }),
1404
+ * );
1405
+ * const model = wrapLanguageModel({
1406
+ * model: openai("gpt-4o"),
1407
+ * middleware: chatTurn.getVercelAiMiddleware(),
1408
+ * });
1409
+ * ```
1410
+ *
1411
+ * @returns A Vercel AI SDK middleware configured for this client and key
1412
+ */
1413
+ getVercelAiMiddleware(): BitfabLanguageModelMiddleware;
1414
+ /**
1415
+ * Get a Claude Agent SDK handler bound to this function's key.
1416
+ *
1417
+ * Equivalent to `client.getClaudeAgentHandler(key)` but reuses the key bound
1418
+ * on this handle, so an outer `withSpan` root and the handler share one key
1419
+ * without repeating the string. With a matching key, the outer span is the
1420
+ * replayable root and every handler span nests beneath it.
1421
+ *
1422
+ * Use the handler inside this handle's `withSpan` body so its spans capture
1423
+ * the enclosing root; framework calls made with no active span record their
1424
+ * own root instead.
1425
+ *
1426
+ * ```typescript
1427
+ * const pipeline = client.getFunction("my-agent");
1428
+ * const tracedRun = pipeline.withSpan({ type: "agent" }, async (prompt) => {
1429
+ * const handler = pipeline.getClaudeAgentHandler();
1430
+ * const options = handler.instrumentOptions({ model: "claude-sonnet-4-6" });
1431
+ * for await (const msg of handler.wrapQuery(query({ prompt, options }))) { ... }
1432
+ * });
1433
+ * ```
1434
+ *
1435
+ * @returns A Claude Agent SDK handler configured for this client and key
1436
+ */
1437
+ getClaudeAgentHandler(): BitfabClaudeAgentHandler;
1438
+ /**
1439
+ * Get a LangGraph/LangChain callback handler bound to this function's key.
1440
+ *
1441
+ * Equivalent to `client.getLangGraphCallbackHandler(key)` but reuses the key
1442
+ * bound on this handle, so an outer `withSpan` root and the handler share one
1443
+ * key without repeating the string. With a matching key, the outer span is
1444
+ * the replayable root and the LangGraph spans nest beneath it.
1445
+ *
1446
+ * Use the handler inside this handle's `withSpan` body so its spans capture
1447
+ * the enclosing root; framework calls made with no active span record their
1448
+ * own root instead.
1449
+ *
1450
+ * ```typescript
1451
+ * const pipeline = client.getFunction("my-pipeline");
1452
+ * const tracedRun = pipeline.withSpan({ type: "agent" }, async (query) => {
1453
+ * const handler = pipeline.getLangGraphCallbackHandler();
1454
+ * return agent.invoke({ messages: [...] }, { callbacks: [handler] });
1455
+ * });
1456
+ * ```
1457
+ *
1458
+ * @returns A LangGraph/LangChain callback handler for this client and key
1459
+ */
1460
+ getLangGraphCallbackHandler(): BitfabLangGraphCallbackHandler;
1461
+ /**
1462
+ * Alias of {@link getLangGraphCallbackHandler} — LangChain and LangGraph
1463
+ * share one callback system, so the same bound handler serves both.
1464
+ *
1465
+ * @returns A LangChain callback handler for this client and key
1466
+ */
1467
+ getLangChainCallbackHandler(): BitfabLangGraphCallbackHandler;
1387
1468
  /**
1388
1469
  * Wrap a BAML client method to automatically capture prompt and LLM metadata.
1389
1470
  * Delegates to the parent client's wrapBAML method.
1390
1471
  *
1472
+ * Unlike the other methods on this handle, `wrapBAML` does NOT use the bound
1473
+ * key: it opens no span of its own. It enriches the *current* span (via
1474
+ * `getCurrentSpan().setPrompt()` / `addContext()`), so call it inside a
1475
+ * function wrapped by this handle's `withSpan` — the bound key keys that
1476
+ * wrapper, and the BAML prompt/metadata attach to it.
1477
+ *
1391
1478
  * @param methodOrClient - Either a BAML method (uses constructor bamlClient) or the BAML client instance
1392
1479
  * @param maybeMethodOrOptions - The BAML method when the first argument is a client, or WrapBAMLOptions when the first argument is the method
1393
1480
  * @param maybeOptions - WrapBAMLOptions when using the two-argument (client, method) form
@@ -1404,7 +1491,7 @@ declare class BitfabFunction {
1404
1491
  /**
1405
1492
  * SDK version from package.json (injected at build time)
1406
1493
  */
1407
- declare const __version__ = "0.25.0";
1494
+ declare const __version__ = "0.26.0";
1408
1495
 
1409
1496
  /**
1410
1497
  * Constants for the Bitfab SDK.
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  flushTraces,
15
15
  getCurrentSpan,
16
16
  getCurrentTrace
17
- } from "./chunk-GQLNEYSU.js";
17
+ } from "./chunk-GCAJN5I7.js";
18
18
  import {
19
19
  BitfabError
20
20
  } from "./chunk-26MUT4IP.js";
package/dist/node.cjs CHANGED
@@ -601,7 +601,7 @@ registerAsyncLocalStorageClass(
601
601
  );
602
602
 
603
603
  // src/version.generated.ts
604
- var __version__ = "0.25.0";
604
+ var __version__ = "0.26.0";
605
605
 
606
606
  // src/constants.ts
607
607
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -4107,10 +4107,105 @@ var BitfabFunction = class {
4107
4107
  const fn = typeof optionsOrFn === "function" ? optionsOrFn : maybeFn;
4108
4108
  return this.client.withSpan(this.traceFunctionKey, options, fn);
4109
4109
  }
4110
+ /**
4111
+ * Get a Vercel AI SDK language-model middleware bound to this function's key.
4112
+ *
4113
+ * Equivalent to `client.getVercelAiMiddleware(key)` but reuses the key bound
4114
+ * on this handle, so an outer `withSpan` root and the middleware-traced model
4115
+ * calls share one key without repeating the string. With a matching key, the
4116
+ * outer span is the replayable root and the model-call spans nest beneath it.
4117
+ *
4118
+ * Nesting is captured when the model is called, so keep the
4119
+ * `generateText` / `streamText` call inside this handle's `withSpan`; the
4120
+ * middleware object itself can be created anywhere.
4121
+ *
4122
+ * ```typescript
4123
+ * const chatTurn = client.getFunction("chat-turn");
4124
+ * const runChatTurn = chatTurn.withSpan(
4125
+ * { type: "agent", finalize: finalizers.aiSdk },
4126
+ * (messages) => streamText({ model, messages }),
4127
+ * );
4128
+ * const model = wrapLanguageModel({
4129
+ * model: openai("gpt-4o"),
4130
+ * middleware: chatTurn.getVercelAiMiddleware(),
4131
+ * });
4132
+ * ```
4133
+ *
4134
+ * @returns A Vercel AI SDK middleware configured for this client and key
4135
+ */
4136
+ getVercelAiMiddleware() {
4137
+ return this.client.getVercelAiMiddleware(this.traceFunctionKey);
4138
+ }
4139
+ /**
4140
+ * Get a Claude Agent SDK handler bound to this function's key.
4141
+ *
4142
+ * Equivalent to `client.getClaudeAgentHandler(key)` but reuses the key bound
4143
+ * on this handle, so an outer `withSpan` root and the handler share one key
4144
+ * without repeating the string. With a matching key, the outer span is the
4145
+ * replayable root and every handler span nests beneath it.
4146
+ *
4147
+ * Use the handler inside this handle's `withSpan` body so its spans capture
4148
+ * the enclosing root; framework calls made with no active span record their
4149
+ * own root instead.
4150
+ *
4151
+ * ```typescript
4152
+ * const pipeline = client.getFunction("my-agent");
4153
+ * const tracedRun = pipeline.withSpan({ type: "agent" }, async (prompt) => {
4154
+ * const handler = pipeline.getClaudeAgentHandler();
4155
+ * const options = handler.instrumentOptions({ model: "claude-sonnet-4-6" });
4156
+ * for await (const msg of handler.wrapQuery(query({ prompt, options }))) { ... }
4157
+ * });
4158
+ * ```
4159
+ *
4160
+ * @returns A Claude Agent SDK handler configured for this client and key
4161
+ */
4162
+ getClaudeAgentHandler() {
4163
+ return this.client.getClaudeAgentHandler(this.traceFunctionKey);
4164
+ }
4165
+ /**
4166
+ * Get a LangGraph/LangChain callback handler bound to this function's key.
4167
+ *
4168
+ * Equivalent to `client.getLangGraphCallbackHandler(key)` but reuses the key
4169
+ * bound on this handle, so an outer `withSpan` root and the handler share one
4170
+ * key without repeating the string. With a matching key, the outer span is
4171
+ * the replayable root and the LangGraph spans nest beneath it.
4172
+ *
4173
+ * Use the handler inside this handle's `withSpan` body so its spans capture
4174
+ * the enclosing root; framework calls made with no active span record their
4175
+ * own root instead.
4176
+ *
4177
+ * ```typescript
4178
+ * const pipeline = client.getFunction("my-pipeline");
4179
+ * const tracedRun = pipeline.withSpan({ type: "agent" }, async (query) => {
4180
+ * const handler = pipeline.getLangGraphCallbackHandler();
4181
+ * return agent.invoke({ messages: [...] }, { callbacks: [handler] });
4182
+ * });
4183
+ * ```
4184
+ *
4185
+ * @returns A LangGraph/LangChain callback handler for this client and key
4186
+ */
4187
+ getLangGraphCallbackHandler() {
4188
+ return this.client.getLangGraphCallbackHandler(this.traceFunctionKey);
4189
+ }
4190
+ /**
4191
+ * Alias of {@link getLangGraphCallbackHandler} — LangChain and LangGraph
4192
+ * share one callback system, so the same bound handler serves both.
4193
+ *
4194
+ * @returns A LangChain callback handler for this client and key
4195
+ */
4196
+ getLangChainCallbackHandler() {
4197
+ return this.client.getLangChainCallbackHandler(this.traceFunctionKey);
4198
+ }
4110
4199
  /**
4111
4200
  * Wrap a BAML client method to automatically capture prompt and LLM metadata.
4112
4201
  * Delegates to the parent client's wrapBAML method.
4113
4202
  *
4203
+ * Unlike the other methods on this handle, `wrapBAML` does NOT use the bound
4204
+ * key: it opens no span of its own. It enriches the *current* span (via
4205
+ * `getCurrentSpan().setPrompt()` / `addContext()`), so call it inside a
4206
+ * function wrapped by this handle's `withSpan` — the bound key keys that
4207
+ * wrapper, and the BAML prompt/metadata attach to it.
4208
+ *
4114
4209
  * @param methodOrClient - Either a BAML method (uses constructor bamlClient) or the BAML client instance
4115
4210
  * @param maybeMethodOrOptions - The BAML method when the first argument is a client, or WrapBAMLOptions when the first argument is the method
4116
4211
  * @param maybeOptions - WrapBAMLOptions when using the two-argument (client, method) form