bitfab 0.9.2 → 0.11.4

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/node.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- export { ActiveSpanContext, AllowedEnvVars, BamlExecutionResult, Bitfab, BitfabConfig, BitfabError, BitfabFunction, BitfabOpenAITracingProcessor, CurrentSpan, CurrentTrace, DEFAULT_SERVICE_URL, ProviderDefinition, ReplayItem, ReplayOptions, ReplayResult, SpanOptions, SpanType, TraceResponse, TracingProcessor, WrapBAMLOptions, WrappedBamlFn, __version__, flushTraces, getCurrentSpan, getCurrentTrace } from './index.cjs';
1
+ export { ActiveSpanContext, AllowedEnvVars, BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler, BitfabOpenAITracingProcessor, CurrentSpan, CurrentTrace, DEFAULT_SERVICE_URL, ProviderDefinition, ReplayItem, ReplayOptions, ReplayResult, SpanOptions, SpanType, TokenUsage, TraceResponse, TracingProcessor, WrapBAMLOptions, WrappedBamlFn, __version__, flushTraces, getCurrentSpan, getCurrentTrace } from './index.cjs';
2
2
  import '@openai/agents';
package/dist/node.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { ActiveSpanContext, AllowedEnvVars, BamlExecutionResult, Bitfab, BitfabConfig, BitfabError, BitfabFunction, BitfabOpenAITracingProcessor, CurrentSpan, CurrentTrace, DEFAULT_SERVICE_URL, ProviderDefinition, ReplayItem, ReplayOptions, ReplayResult, SpanOptions, SpanType, TraceResponse, TracingProcessor, WrapBAMLOptions, WrappedBamlFn, __version__, flushTraces, getCurrentSpan, getCurrentTrace } from './index.js';
1
+ export { ActiveSpanContext, AllowedEnvVars, BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler, BitfabOpenAITracingProcessor, CurrentSpan, CurrentTrace, DEFAULT_SERVICE_URL, ProviderDefinition, ReplayItem, ReplayOptions, ReplayResult, SpanOptions, SpanType, TokenUsage, TraceResponse, TracingProcessor, WrapBAMLOptions, WrappedBamlFn, __version__, flushTraces, getCurrentSpan, getCurrentTrace } from './index.js';
2
2
  import '@openai/agents';
package/dist/node.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import {
2
2
  Bitfab,
3
+ BitfabClaudeAgentHandler,
3
4
  BitfabFunction,
5
+ BitfabLangGraphCallbackHandler,
4
6
  BitfabOpenAITracingProcessor,
5
7
  getCurrentSpan,
6
8
  getCurrentTrace
7
- } from "./chunk-WUJR72QY.js";
9
+ } from "./chunk-I3OKZ2TF.js";
8
10
  import {
9
11
  BitfabError,
10
12
  DEFAULT_SERVICE_URL,
@@ -12,7 +14,7 @@ import {
12
14
  assertAsyncStorageRegistered,
13
15
  flushTraces,
14
16
  registerAsyncLocalStorageClass
15
- } from "./chunk-VGALEXKQ.js";
17
+ } from "./chunk-KAX2QQPS.js";
16
18
 
17
19
  // src/asyncStorageNode.ts
18
20
  import { AsyncLocalStorage } from "async_hooks";
@@ -24,8 +26,10 @@ registerAsyncLocalStorageClass(
24
26
  assertAsyncStorageRegistered();
25
27
  export {
26
28
  Bitfab,
29
+ BitfabClaudeAgentHandler,
27
30
  BitfabError,
28
31
  BitfabFunction,
32
+ BitfabLangGraphCallbackHandler,
29
33
  BitfabOpenAITracingProcessor,
30
34
  DEFAULT_SERVICE_URL,
31
35
  __version__,
package/dist/node.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/asyncStorageNode.ts","../src/node.ts"],"sourcesContent":["/**\n * Synchronous AsyncLocalStorage registration for Node.js.\n *\n * This module is a side-effect-only import: it registers the Node.js\n * AsyncLocalStorage class into the shared registry so span nesting\n * works immediately — no async gap, no microtask delay.\n *\n * It is imported by `node.ts` (the Node.js-specific entry point) as\n * the FIRST import, before `index.ts` or `client.ts` are evaluated.\n *\n * This file must ONLY be imported in Node.js environments (not browsers).\n * It uses a static `import` of `node:async_hooks`, which will fail in\n * browser bundlers. The `node.ts` entry point is conditionally selected\n * via package.json `exports` conditions, so browsers never see this file.\n */\n\nimport { AsyncLocalStorage } from \"node:async_hooks\"\nimport type { AsyncLocalStorageLike } from \"./asyncStorage.js\"\nimport { registerAsyncLocalStorageClass } from \"./asyncStorage.js\"\n\nregisterAsyncLocalStorageClass(\n AsyncLocalStorage as unknown as new () => AsyncLocalStorageLike<unknown>,\n)\n","/**\n * Node.js-specific entry point for the Bitfab SDK.\n *\n * Selected automatically via package.json `exports` conditions when the\n * consumer's runtime or bundler supports the \"node\" condition (Node.js,\n * most server-side bundlers).\n *\n * This entry point differs from the default (`index.ts`) in one way:\n * it synchronously registers Node.js's `AsyncLocalStorage` before any\n * other SDK code evaluates. This eliminates the async initialization\n * gap that the default entry point has (where the first span might\n * execute before the dynamic import of `node:async_hooks` resolves).\n *\n * The default entry point (`index.ts`) is used for browsers and other\n * environments where `node:async_hooks` is unavailable. There, span\n * nesting degrades gracefully to a shared stack (correct for sequential\n * async, but not for concurrent Promise.all patterns).\n */\n\n// ⚠️ IMPORT ORDER MATTERS\n// asyncStorageNode MUST be imported before index.js.\n// It registers the AsyncLocalStorage class synchronously during module\n// evaluation. index.js (via client.ts) reads from that registration at\n// span creation time. If this import is moved after index.js or removed,\n// span nesting silently degrades to the browser fallback (flat spans).\nimport \"./asyncStorageNode.js\"\n\nexport * from \"./index.js\"\n\n// Verify registration succeeded. This turns a silent degradation into a\n// loud error if someone reorders the imports above or if asyncStorageNode.ts\n// fails to register for any reason. Only runs in the Node.js entry point\n// where we know node:async_hooks must be available.\nimport { assertAsyncStorageRegistered } from \"./asyncStorage.js\"\n\nassertAsyncStorageRegistered()\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,SAAS,yBAAyB;AAIlC;AAAA,EACE;AACF;;;ACaA,6BAA6B;","names":[]}
1
+ {"version":3,"sources":["../src/asyncStorageNode.ts","../src/node.ts"],"sourcesContent":["/**\n * Synchronous AsyncLocalStorage registration for Node.js.\n *\n * This module is a side-effect-only import: it registers the Node.js\n * AsyncLocalStorage class into the shared registry so span nesting\n * works immediately — no async gap, no microtask delay.\n *\n * It is imported by `node.ts` (the Node.js-specific entry point) as\n * the FIRST import, before `index.ts` or `client.ts` are evaluated.\n *\n * This file must ONLY be imported in Node.js environments (not browsers).\n * It uses a static `import` of `node:async_hooks`, which will fail in\n * browser bundlers. The `node.ts` entry point is conditionally selected\n * via package.json `exports` conditions, so browsers never see this file.\n */\n\nimport { AsyncLocalStorage } from \"node:async_hooks\"\nimport type { AsyncLocalStorageLike } from \"./asyncStorage.js\"\nimport { registerAsyncLocalStorageClass } from \"./asyncStorage.js\"\n\nregisterAsyncLocalStorageClass(\n AsyncLocalStorage as unknown as new () => AsyncLocalStorageLike<unknown>,\n)\n","/**\n * Node.js-specific entry point for the Bitfab SDK.\n *\n * Selected automatically via package.json `exports` conditions when the\n * consumer's runtime or bundler supports the \"node\" condition (Node.js,\n * most server-side bundlers).\n *\n * This entry point differs from the default (`index.ts`) in one way:\n * it synchronously registers Node.js's `AsyncLocalStorage` before any\n * other SDK code evaluates. This eliminates the async initialization\n * gap that the default entry point has (where the first span might\n * execute before the dynamic import of `node:async_hooks` resolves).\n *\n * The default entry point (`index.ts`) is used for browsers and other\n * environments where `node:async_hooks` is unavailable. There, span\n * nesting degrades gracefully to a shared stack (correct for sequential\n * async, but not for concurrent Promise.all patterns).\n */\n\n// ⚠️ IMPORT ORDER MATTERS\n// asyncStorageNode MUST be imported before index.js.\n// It registers the AsyncLocalStorage class synchronously during module\n// evaluation. index.js (via client.ts) reads from that registration at\n// span creation time. If this import is moved after index.js or removed,\n// span nesting silently degrades to the browser fallback (flat spans).\nimport \"./asyncStorageNode.js\"\n\nexport * from \"./index.js\"\n\n// Verify registration succeeded. This turns a silent degradation into a\n// loud error if someone reorders the imports above or if asyncStorageNode.ts\n// fails to register for any reason. Only runs in the Node.js entry point\n// where we know node:async_hooks must be available.\nimport { assertAsyncStorageRegistered } from \"./asyncStorage.js\"\n\nassertAsyncStorageRegistered()\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgBA,SAAS,yBAAyB;AAIlC;AAAA,EACE;AACF;;;ACaA,6BAA6B;","names":[]}
@@ -3,7 +3,7 @@ import {
3
3
  flushTraces,
4
4
  replayContextReady,
5
5
  runWithReplayContext
6
- } from "./chunk-VGALEXKQ.js";
6
+ } from "./chunk-KAX2QQPS.js";
7
7
 
8
8
  // src/replay.ts
9
9
  function deserializeInputs(spanData) {
@@ -45,7 +45,15 @@ async function processItem(httpClient, serverItem, fn, testRunId) {
45
45
  } catch (e) {
46
46
  error = e instanceof Error ? e.message : String(e);
47
47
  }
48
- return { input: inputs, result, originalOutput, error };
48
+ return {
49
+ input: inputs,
50
+ result,
51
+ originalOutput,
52
+ error,
53
+ durationMs: serverItem.durationMs ?? null,
54
+ tokens: serverItem.tokens ?? null,
55
+ model: serverItem.model ?? null
56
+ };
49
57
  }
50
58
  async function mapWithConcurrency(tasks, maxConcurrency) {
51
59
  const results = new Array(tasks.length);
@@ -97,4 +105,4 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options) {
97
105
  export {
98
106
  replay
99
107
  };
100
- //# sourceMappingURL=replay-DJ2HXTHQ.js.map
108
+ //# sourceMappingURL=replay-IIBLVODH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/replay.ts"],"sourcesContent":["/**\n * Replay historical traces through a function and create a test run.\n *\n * The replay flow has three phases:\n * 1. Start — fetches historical traces from the server and creates a test run\n * 2. Execute — re-runs each trace's inputs through the provided function locally\n * 3. Complete — marks the test run as completed on the server\n */\n\nimport type { HttpClient, TokenUsage } from \"./http.js\"\nimport { flushTraces } from \"./http.js\"\nimport { replayContextReady, runWithReplayContext } from \"./replayContext.js\"\nimport { deserializeValue } from \"./serialize.js\"\n\nexport interface ReplayOptions {\n /** Maximum number of traces to replay (1–100, default 5). */\n limit?: number\n /** Optional list of specific trace IDs to replay. */\n traceIds?: string[]\n /** Maximum number of items to process in parallel. Set to 1 for sequential. Default 10. */\n maxConcurrency?: number\n}\n\nexport interface ReplayItem<T> {\n /** Deserialized inputs from the original trace. */\n input: unknown[]\n /** The result returned by the function during replay, or undefined on error. */\n result: T | undefined\n /** The original output from the historical trace. */\n originalOutput: unknown\n /** Error message if the function threw, or null on success. */\n error: string | null\n /** Original trace duration in milliseconds, or null if timestamps are missing. */\n durationMs: number | null\n /** Token usage from the original trace, or null if not captured. */\n tokens: TokenUsage | null\n /** Model name from the original trace, or null if not captured. */\n model: string | null\n}\n\nexport type { TokenUsage }\n\nexport interface ReplayResult<T> {\n /** Individual replay items with inputs, results, and comparison data. */\n items: ReplayItem<T>[]\n /** The test run ID created on the server. */\n testRunId: string\n /** Full URL to view the test run in the dashboard. */\n testRunUrl: string\n}\n\n/**\n * Deserialize inputs from a historical span's rawData.\n *\n * Prefers superjson-serialized `input_meta` for type preservation,\n * falls back to the raw `input` field.\n */\nfunction deserializeInputs(spanData: Record<string, unknown>): unknown[] {\n const inputMeta = spanData.input_meta as unknown\n const rawInput = spanData.input\n\n // If superjson meta is available, deserialize with type reconstruction\n if (inputMeta !== undefined && inputMeta !== null) {\n const deserialized = deserializeValue({ json: rawInput, meta: inputMeta })\n if (Array.isArray(deserialized)) {\n return deserialized\n }\n return deserialized !== undefined && deserialized !== null\n ? [deserialized]\n : []\n }\n\n // Fall back to raw input\n if (Array.isArray(rawInput)) {\n return rawInput\n }\n return rawInput !== undefined && rawInput !== null ? [rawInput] : []\n}\n\n/**\n * Deserialize the original output from a historical span's rawData.\n */\nfunction deserializeOutput(spanData: Record<string, unknown>): unknown {\n const outputMeta = spanData.output_meta as unknown\n const rawOutput = spanData.output\n\n if (outputMeta !== undefined && outputMeta !== null) {\n return deserializeValue({ json: rawOutput, meta: outputMeta })\n }\n\n return rawOutput\n}\n\n/**\n * Execute a single replay item: fetch span data, deserialize inputs, call\n * the function within a replay context that injects testRunId into new spans.\n */\nasync function processItem<TReturn>(\n httpClient: HttpClient,\n serverItem: {\n externalSpanId: string\n durationMs: number | null\n tokens: TokenUsage | null\n model: string | null\n },\n // biome-ignore lint/suspicious/noExplicitAny: replay deserializes inputs from historical data\n fn: (...args: any[]) => TReturn | Promise<TReturn>,\n testRunId: string,\n): Promise<ReplayItem<TReturn>> {\n const span = await httpClient.getExternalSpan(serverItem.externalSpanId)\n const spanData = (span.rawData?.span_data ?? {}) as Record<string, unknown>\n\n const inputs = deserializeInputs(spanData)\n const originalOutput = deserializeOutput(spanData)\n\n let result: TReturn | undefined\n let error: string | null = null\n\n try {\n const maybePromise = runWithReplayContext(\n { testRunId, inputSourceSpanId: span.id },\n () => fn(...inputs),\n )\n result = maybePromise instanceof Promise ? await maybePromise : maybePromise\n } catch (e) {\n error = e instanceof Error ? e.message : String(e)\n }\n\n return {\n input: inputs,\n result,\n originalOutput,\n error,\n durationMs: serverItem.durationMs ?? null,\n tokens: serverItem.tokens ?? null,\n model: serverItem.model ?? null,\n }\n}\n\n/**\n * Run async tasks with a concurrency limit.\n * Each task factory is called when a slot opens; results preserve input order.\n */\nasync function mapWithConcurrency<T>(\n tasks: Array<() => Promise<T>>,\n maxConcurrency: number,\n): Promise<T[]> {\n const results: T[] = new Array(tasks.length)\n let nextIndex = 0\n\n async function worker(): Promise<void> {\n while (nextIndex < tasks.length) {\n const index = nextIndex++\n results[index] = await tasks[index]()\n }\n }\n\n const workers = Array.from(\n { length: Math.min(maxConcurrency, tasks.length) },\n () => worker(),\n )\n await Promise.all(workers)\n return results\n}\n\n/**\n * Replay historical traces through a function and create a test run.\n *\n * @internal Called by Bitfab.replay — not part of the public API.\n */\nexport async function replay<TReturn>(\n httpClient: HttpClient,\n serviceUrl: string,\n traceFunctionKey: string,\n // biome-ignore lint/suspicious/noExplicitAny: replay deserializes inputs from historical data\n fn: (...args: any[]) => TReturn | Promise<TReturn>,\n options?: ReplayOptions,\n): Promise<ReplayResult<TReturn>> {\n await replayContextReady\n\n const {\n testRunId,\n testRunUrl,\n items: serverItems,\n } = await httpClient.startReplay(\n traceFunctionKey,\n options?.limit ?? 5,\n options?.traceIds,\n )\n\n const maxConcurrency = options?.maxConcurrency ?? 10\n\n const tasks = serverItems.map(\n (serverItem) => () => processItem(httpClient, serverItem, fn, testRunId),\n )\n const resultItems = await mapWithConcurrency(tasks, maxConcurrency)\n\n await flushTraces()\n\n try {\n await httpClient.completeReplay(testRunId)\n } catch (e) {\n try {\n console.error(\"Bitfab: Failed to complete replay:\", e)\n } catch {\n // Never crash the host app\n }\n }\n\n return {\n items: resultItems,\n testRunId,\n testRunUrl: `${serviceUrl}${testRunUrl}`,\n }\n}\n"],"mappings":";;;;;;;;AAyDA,SAAS,kBAAkB,UAA8C;AACvE,QAAM,YAAY,SAAS;AAC3B,QAAM,WAAW,SAAS;AAG1B,MAAI,cAAc,UAAa,cAAc,MAAM;AACjD,UAAM,eAAe,iBAAiB,EAAE,MAAM,UAAU,MAAM,UAAU,CAAC;AACzE,QAAI,MAAM,QAAQ,YAAY,GAAG;AAC/B,aAAO;AAAA,IACT;AACA,WAAO,iBAAiB,UAAa,iBAAiB,OAClD,CAAC,YAAY,IACb,CAAC;AAAA,EACP;AAGA,MAAI,MAAM,QAAQ,QAAQ,GAAG;AAC3B,WAAO;AAAA,EACT;AACA,SAAO,aAAa,UAAa,aAAa,OAAO,CAAC,QAAQ,IAAI,CAAC;AACrE;AAKA,SAAS,kBAAkB,UAA4C;AACrE,QAAM,aAAa,SAAS;AAC5B,QAAM,YAAY,SAAS;AAE3B,MAAI,eAAe,UAAa,eAAe,MAAM;AACnD,WAAO,iBAAiB,EAAE,MAAM,WAAW,MAAM,WAAW,CAAC;AAAA,EAC/D;AAEA,SAAO;AACT;AAMA,eAAe,YACb,YACA,YAOA,IACA,WAC8B;AAC9B,QAAM,OAAO,MAAM,WAAW,gBAAgB,WAAW,cAAc;AACvE,QAAM,WAAY,KAAK,SAAS,aAAa,CAAC;AAE9C,QAAM,SAAS,kBAAkB,QAAQ;AACzC,QAA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AAM,mBAAmB,OAAO,cAAc;AAElE,QAAM,YAAY;AAElB,MAAI;AACF,UAAM,WAAW,eAAe,SAAS;AAAA,EAC3C,SAAS,GAAG;AACV,QAAI;AACF,cAAQ,MAAM,sCAAsC,CAAC;AAAA,IACvD,QAAQ;AAAA,IAER;AAAA,EACF;AAEA,SAAO;AAAA,IACL,OAAO;AAAA,IACP;AAAA,IACA,YAAY,GAAG,UAAU,GAAG,UAAU;AAAA,EACxC;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bitfab",
3
- "version": "0.9.2",
3
+ "version": "0.11.4",
4
4
  "description": "Bitfab client for provider-based API calls with local BAML execution",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -42,10 +42,10 @@
42
42
  "tsc": "tsc --noEmit",
43
43
  "knip": "knip",
44
44
  "madge": "madge --warning --ts-config ./tsconfig.json --extensions ts --circular ./src",
45
+ "prevalidate": "tsx scripts/generate-version.ts",
45
46
  "validate": "pnpm lint && pnpm tsc && pnpm knip && pnpm madge",
46
47
  "test": "vitest run",
47
- "test:watch": "vitest",
48
- "release": "tsx scripts/release.ts"
48
+ "test:watch": "vitest"
49
49
  },
50
50
  "keywords": [
51
51
  "bitfab",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/asyncStorage.ts","../src/version.generated.ts","../src/constants.ts","../src/http.ts","../src/replayContext.ts","../src/serialize.ts"],"sourcesContent":["/**\n * Shared AsyncLocalStorage loader.\n *\n * Provides two ways to initialize AsyncLocalStorage:\n *\n * 1. **Synchronous registration** (preferred for Node.js):\n * `asyncStorageNode.ts` calls `registerAsyncLocalStorageClass()` at module\n * evaluation time, so the class is available immediately — no async gap.\n * The `node.ts` entry point imports it before anything else.\n *\n * 2. **Async dynamic import** (fallback for the default entry point):\n * Loads `node:async_hooks` via a bundler-safe dynamic import. This is used\n * by the default `index.ts` entry point so the SDK works in browsers\n * (where the import silently fails) and in Node.js when imported via the\n * default entry point.\n *\n * ## Why the dynamic import looks like this\n *\n * We need to handle three environments:\n *\n * 1. **Pure Node.js** — `import(\"node:async_hooks\")` works natively.\n * 2. **Webpack/Turbopack (Next.js server)** — The bundler processes\n * `import()` calls at build time. The `webpackIgnore` magic comment tells\n * webpack (and turbopack) to emit a native `import()` call instead of\n * trying to resolve it, so Node.js handles it at runtime.\n * 3. **Browsers / Edge** — The `process.versions?.node` guard prevents\n * execution entirely. If it somehow runs, `.catch(() => {})` swallows\n * the failure.\n */\n\nexport interface AsyncLocalStorageLike<T> {\n getStore(): T | undefined\n run<R>(store: T, fn: () => R): R\n}\n\nlet AsyncLocalStorageClass: (new () => AsyncLocalStorageLike<unknown>) | null =\n null\nlet initDone = false\n\n/**\n * Register the AsyncLocalStorage class synchronously.\n *\n * Called by `asyncStorageNode.ts` at module evaluation time so the class\n * is available before any span is created — no async gap, no race condition.\n *\n * Safe to call multiple times; subsequent calls are no-ops.\n */\nexport function registerAsyncLocalStorageClass(\n cls: new () => AsyncLocalStorageLike<unknown>,\n): void {\n if (!AsyncLocalStorageClass) {\n AsyncLocalStorageClass = cls\n }\n initDone = true\n}\n\n/**\n * Assert that AsyncLocalStorage was registered successfully.\n *\n * Called by `node.ts` after importing `asyncStorageNode.ts` to catch\n * import-order bugs at startup rather than silently degrading to the\n * browser fallback (flat spans with no nesting).\n *\n * This should ONLY be called from the Node.js entry point where we\n * know `node:async_hooks` must be available.\n */\nexport function assertAsyncStorageRegistered(): void {\n if (!AsyncLocalStorageClass) {\n console.warn(\n \"Bitfab: AsyncLocalStorage not available — nested span context will not propagate.\",\n )\n }\n}\n\nexport const asyncStorageReady: Promise<void> = (\n typeof process !== \"undefined\" && process.versions?.node\n ? // The join trick hides \"node:async_hooks\" from static analysis so\n // bundlers that ban Node.js built-ins don't fail at build time.\n // webpackIgnore tells webpack/turbopack to emit a native import()\n // so Node.js can resolve the module at runtime.\n import(\n /* webpackIgnore: true */\n [\"node\", \"async_hooks\"].join(\":\")\n )\n .then(\n (mod: {\n AsyncLocalStorage: new () => AsyncLocalStorageLike<unknown>\n }) => {\n registerAsyncLocalStorageClass(mod.AsyncLocalStorage)\n },\n )\n .catch(() => {})\n : Promise.resolve()\n).then(() => {\n initDone = true\n})\n\nexport function isAsyncStorageInitDone(): boolean {\n return initDone\n}\n\nexport function createAsyncLocalStorage<T>(): AsyncLocalStorageLike<T> | null {\n return AsyncLocalStorageClass\n ? (new AsyncLocalStorageClass() as AsyncLocalStorageLike<T>)\n : null\n}\n","/**\n * Auto-generated version file.\n * This file is generated by scripts/generate-version.ts during build.\n * DO NOT EDIT MANUALLY.\n */\n\n/**\n * SDK version from package.json (injected at build time)\n */\nexport const __version__ = \"0.9.2\"\n","/**\n * Constants for the Bitfab SDK.\n */\n\n/**\n * Default service URL for Bitfab API.\n */\nexport const DEFAULT_SERVICE_URL = \"https://bitfab.ai\"\n\n/**\n * SDK version from package.json (injected at build time)\n *\n * The version is generated at build time by scripts/generate-version.ts\n * to ensure compatibility with both Node.js and browser environments.\n */\nexport { __version__ } from \"./version.generated.js\"\n","/**\n * HTTP client utilities for Bitfab API requests.\n *\n * This module provides:\n * - HttpClient class for making API requests\n * - awaitOnExit helper for fire-and-forget operations that must complete before process exit\n */\n\nimport { __version__ } from \"./constants.js\"\n\n/**\n * Error class for Bitfab API errors.\n */\nexport class BitfabError extends Error {\n constructor(\n message: string,\n public readonly url?: string,\n ) {\n super(message)\n this.name = \"BitfabError\"\n }\n}\n\n// Global set to track pending trace creation promises\n// This prevents promises from being garbage collected before they complete\nconst pendingTracePromises = new Set<Promise<unknown>>()\n\n/**\n * Track a promise to prevent it from being garbage collected.\n * The promise will be removed from tracking when it completes (success or failure).\n * Useful for fire-and-forget operations that need to complete before process exit.\n *\n * @param promise - The promise to track\n * @returns The same promise (for chaining)\n */\nexport function awaitOnExit<T>(promise: Promise<T>): Promise<T> {\n pendingTracePromises.add(promise)\n // Use void to prevent unhandled rejection warnings from the .finally() chain\n // The actual error handling is done by the caller's .catch() on the returned promise\n void promise\n .finally(() => {\n pendingTracePromises.delete(promise)\n })\n .catch(() => {\n // Swallow rejection in this chain - the caller handles errors via their own .catch()\n })\n return promise\n}\n\n/**\n * Wait for all pending fire-and-forget operations (spans, traces) to complete.\n * Useful in tests and scripts to ensure all data has been sent before asserting or exiting.\n *\n * @param timeoutMs - Maximum time to wait in milliseconds (default: 5000)\n */\nexport async function flushTraces(timeoutMs: number = 5000): Promise<void> {\n if (pendingTracePromises.size === 0) {\n return\n }\n await Promise.race([\n Promise.allSettled(Array.from(pendingTracePromises)),\n new Promise<void>((resolve) => setTimeout(resolve, timeoutMs)),\n ])\n}\n\n// Register beforeExit handler to wait for pending traces (Node.js only)\n// This ensures traces are sent before the process exits (for scripts)\nif (\n typeof process !== \"undefined\" &&\n process.versions != null &&\n process.versions.node != null\n) {\n let isFlushing = false\n process.on(\"beforeExit\", () => {\n if (pendingTracePromises.size > 0 && !isFlushing) {\n isFlushing = true\n // Wait for all pending traces to complete\n // This keeps the event loop alive until promises resolve\n Promise.allSettled(\n Array.from(pendingTracePromises).map((p) =>\n p.catch(() => {\n // Silently ignore individual trace failures\n }),\n ),\n )\n .then(() => {\n isFlushing = false\n })\n .catch(() => {\n isFlushing = false\n })\n }\n })\n}\n\nexport interface HttpClientConfig {\n apiKey?: string\n serviceUrl: string\n timeout?: number\n}\n\n/**\n * HTTP client for Bitfab API requests.\n *\n * Provides methods for different API endpoints with proper error handling,\n * timeouts, and authentication.\n */\nexport class HttpClient {\n private readonly apiKey: string | undefined\n private readonly serviceUrl: string\n private readonly timeout: number\n\n constructor(config: HttpClientConfig) {\n this.apiKey = config.apiKey\n this.serviceUrl = config.serviceUrl\n this.timeout = config.timeout ?? 120000\n }\n\n /**\n * Make an HTTP POST request to the Bitfab API.\n *\n * @param endpoint - The API endpoint (without base URL)\n * @param payload - The request body\n * @param options - Optional request options\n * @returns The parsed JSON response\n * @throws {BitfabError} If the request fails\n */\n async request<T>(\n endpoint: string,\n payload: Record<string, unknown>,\n options?: { timeout?: number },\n ): Promise<T> {\n const url = `${this.serviceUrl}${endpoint}`\n const timeout = options?.timeout ?? this.timeout\n\n const controller = new AbortController()\n const timeoutId = setTimeout(() => controller.abort(), timeout)\n\n // Serialize payload, handling circular references\n let body: string\n let serializationError: string | undefined\n try {\n body = JSON.stringify(payload)\n } catch (error) {\n serializationError =\n error instanceof Error ? error.message : String(error)\n // Create fallback payload with error info\n body = JSON.stringify({\n ...Object.fromEntries(\n Object.entries(payload).filter(\n ([, v]) => typeof v === \"string\" || typeof v === \"number\",\n ),\n ),\n rawSpan: {},\n errors: [{ step: \"json_serialize\", error: serializationError }],\n })\n }\n\n try {\n const response = await fetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n },\n body,\n signal: controller.signal,\n })\n\n if (!response.ok) {\n const errorText = await response.text()\n throw new BitfabError(\n `HTTP ${response.status}: ${errorText.slice(0, 500)}`,\n )\n }\n\n const result = await response.json()\n\n // Check for errors in the response\n if (result.error) {\n if (result.url) {\n throw new BitfabError(\n `${result.error} Configure it at: ${this.serviceUrl}${result.url}`,\n result.url,\n )\n }\n throw new BitfabError(result.error)\n }\n\n return result as T\n } catch (error) {\n if (error instanceof BitfabError) {\n throw error\n }\n if (error instanceof Error) {\n if (error.name === \"AbortError\") {\n throw new BitfabError(`Request timed out after ${timeout}ms`)\n }\n throw new BitfabError(error.message)\n }\n throw new BitfabError(\"Unknown error occurred\")\n } finally {\n clearTimeout(timeoutId)\n }\n }\n\n /**\n * Look up a function by name.\n * Blocks until complete - needed for function execution.\n */\n async lookupFunction<T>(name: string): Promise<T> {\n return this.request<T>(\"/api/sdk/functions/lookup\", { name })\n }\n\n /**\n * Send an internal trace (from BAML execution).\n * Fire-and-forget with awaitOnExit - doesn't block the caller.\n */\n sendInternalTrace(\n functionId: string,\n payload: Record<string, unknown>,\n ): void {\n void awaitOnExit(\n this.request(`/api/sdk/functions/${functionId}/traces`, {\n ...payload,\n sdkVersion: __version__,\n }),\n ).catch((error) => {\n try {\n console.error(\"Bitfab: Failed to create trace:\", error)\n } catch {}\n })\n }\n\n /**\n * Send an external span (from withSpan wrapper or OpenAI tracing).\n * Fire-and-forget with awaitOnExit - doesn't block the caller.\n * Returns the tracked promise so callers can optionally await it.\n */\n sendExternalSpan(payload: Record<string, unknown>): Promise<unknown> {\n return awaitOnExit(\n this.request(\"/api/sdk/externalSpans\", {\n ...payload,\n sdkVersion: __version__,\n }),\n ).catch((error) => {\n try {\n console.error(\"Bitfab: Failed to create external span:\", error)\n } catch {}\n })\n }\n\n /**\n * Send an external trace (from OpenAI tracing).\n * Fire-and-forget with awaitOnExit - doesn't block the caller.\n */\n sendExternalTrace(payload: Record<string, unknown>): void {\n void awaitOnExit(\n this.request(\"/api/sdk/externalTraces\", {\n ...payload,\n sdkVersion: __version__,\n }),\n ).catch((error) => {\n try {\n console.error(\"Bitfab: Failed to create external trace:\", error)\n } catch {}\n })\n }\n\n /**\n * Start a replay session by fetching historical traces.\n * Blocking call — creates a test run and returns lightweight item references.\n */\n async startReplay(\n traceFunctionKey: string,\n limit: number,\n traceIds?: string[],\n ): Promise<StartReplayResponse> {\n const payload: Record<string, unknown> = { traceFunctionKey, limit }\n if (traceIds) {\n payload.traceIds = traceIds\n }\n return this.request<StartReplayResponse>(\"/api/sdk/replay/start\", payload, {\n timeout: 30_000,\n })\n }\n\n /**\n * Fetch an external span by ID.\n * Blocking GET request.\n */\n async getExternalSpan(spanId: string): Promise<ExternalSpanResponse> {\n const url = `${this.serviceUrl}/api/sdk/externalSpans/${spanId}`\n const controller = new AbortController()\n const timeoutId = setTimeout(() => controller.abort(), 30_000)\n\n try {\n const response = await fetch(url, {\n method: \"GET\",\n headers: { Authorization: `Bearer ${this.apiKey}` },\n signal: controller.signal,\n })\n\n if (!response.ok) {\n const errorText = await response.text()\n throw new BitfabError(\n `HTTP ${response.status}: ${errorText.slice(0, 500)}`,\n )\n }\n\n return (await response.json()) as ExternalSpanResponse\n } catch (error) {\n if (error instanceof BitfabError) {\n throw error\n }\n if (error instanceof Error) {\n if (error.name === \"AbortError\") {\n throw new BitfabError(\"Request timed out after 30000ms\")\n }\n throw new BitfabError(error.message)\n }\n throw new BitfabError(\"Unknown error occurred\")\n } finally {\n clearTimeout(timeoutId)\n }\n }\n\n /**\n * Mark a replay test run as completed.\n * Blocking call.\n */\n async completeReplay(testRunId: string): Promise<CompleteReplayResponse> {\n return this.request<CompleteReplayResponse>(\n \"/api/sdk/replay/complete\",\n { testRunId },\n { timeout: 30_000 },\n )\n }\n}\n\nexport interface StartReplayResponse {\n testRunId: string\n testRunUrl: string\n items: Array<{\n traceId: string\n externalSpanId: string\n }>\n}\n\nexport interface ExternalSpanResponse {\n id: string\n externalTraceId: string\n rawData: {\n span_data: {\n input: unknown\n output: unknown\n input_meta?: unknown\n output_meta?: unknown\n input_serialized?: { json: unknown; meta: unknown }\n output_serialized?: { json: unknown; meta: unknown }\n }\n }\n}\n\nexport interface CompleteReplayResponse {\n id: string\n status: string\n}\n","/**\n * Replay context propagation via AsyncLocalStorage.\n *\n * When set, the withSpan wrapper injects testRunId into the span payload\n * so that new spans created during replay are linked to the test run.\n */\n\nimport {\n type AsyncLocalStorageLike,\n asyncStorageReady,\n createAsyncLocalStorage,\n} from \"./asyncStorage.js\"\n\nexport interface ReplayContext {\n testRunId: string\n inputSourceSpanId?: string\n}\n\nlet replayContextStorage: AsyncLocalStorageLike<ReplayContext | null> | null =\n null\n\nexport const replayContextReady: Promise<void> = asyncStorageReady.then(() => {\n replayContextStorage = createAsyncLocalStorage<ReplayContext | null>()\n})\n\n/** Get the current replay context, if any. */\nexport function getReplayContext(): ReplayContext | null {\n return replayContextStorage?.getStore() ?? null\n}\n\n/** Run a function within a replay context. */\nexport function runWithReplayContext<T>(ctx: ReplayContext, fn: () => T): T {\n if (replayContextStorage) {\n return replayContextStorage.run(ctx, fn)\n }\n return fn()\n}\n","/**\n * Serialization utilities for Bitfab SDK.\n *\n * This module provides serialization with type metadata preservation,\n * using superjson for handling special JavaScript types like Date, Map,\n * Set, BigInt, undefined, etc.\n */\n\nimport superjson from \"superjson\"\n\n/**\n * Serialized value with JSON data and optional superjson meta for type preservation.\n *\n * The json field contains the JSON-serializable data.\n * The meta field (if present) contains superjson type information for deserializing\n * special types like Date, Map, Set, BigInt, etc.\n */\nexport interface SerializedValue {\n json: unknown\n meta?: unknown\n}\n\n/**\n * Serialize a value using superjson for trace storage.\n *\n * Handles arbitrary JavaScript values including:\n * - Date, RegExp, Error\n * - Map, Set\n * - BigInt\n * - undefined (in objects/arrays)\n * - Circular references\n *\n * @param value - Any JavaScript value to serialize\n * @returns SerializedValue with 'json' field containing the data.\n * If type metadata is needed for reconstruction, includes 'meta' field.\n *\n * @example\n * ```typescript\n * const result = serializeValue(new Date('2024-01-15T10:30:00Z'))\n * // result.json contains the ISO string\n * // result.meta contains type info for Date reconstruction\n * ```\n */\nexport function serializeValue(value: unknown): SerializedValue {\n try {\n const { json, meta } = superjson.serialize(value)\n return meta ? { json, meta } : { json }\n } catch {\n // Fallback to basic JSON serialization\n try {\n return { json: JSON.parse(JSON.stringify(value)) }\n } catch {\n return { json: String(value) }\n }\n }\n}\n\n/**\n * Deserialize a value that was serialized with serializeValue.\n *\n * @param serialized - A SerializedValue object with 'json' and optional 'meta'\n * @returns The reconstructed JavaScript value\n *\n * @example\n * ```typescript\n * const serialized = serializeValue(new Date('2024-01-15'))\n * const date = deserializeValue(serialized)\n * // date is a Date object\n * ```\n */\nexport function deserializeValue(serialized: SerializedValue): unknown {\n if (serialized.meta === undefined) {\n // No metadata, return as-is\n return serialized.json\n }\n\n // Use superjson to deserialize with type reconstruction\n // Cast json to the expected superjson type\n type SuperJSONResult = Parameters<typeof superjson.deserialize>[0]\n return superjson.deserialize({\n json: serialized.json as SuperJSONResult[\"json\"],\n meta: serialized.meta as SuperJSONResult[\"meta\"],\n })\n}\n"],"mappings":";AAmCA,IAAI,yBACF;AACF,IAAI,WAAW;AAUR,SA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,UAAU,UAAU,KAAK;AAChD,WAAO,OAAO,EAAE,MAAM,KAAK,IAAI,EAAE,KAAK;AAAA,EACxC,QAAQ;AAEN,QAAI;AACF,aAAO,EAAE,MAAM,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC,EAAE;AAAA,IACnD,QAAQ;AACN,aAAO,EAAE,MAAM,OAAO,KAAK,EAAE;AAAA,IAC/B;AAAA,EACF;AACF;AAeO,SAAS,iBAAiB,YAAsC;AACrE,MAAI,WAAW,SAAS,QAAW;AAEjC,WAAO,WAAW;AAAA,EACpB;AAKA,SAAO,UAAU,YAAY;AAAA,IAC3B,MAAM,WAAW;AAAA,IACjB,MAAM,WAAW;AAAA,EACnB,CAAC;AACH;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/baml.ts","../src/tracing.ts","../src/client.ts"],"sourcesContent":["/**\n * BAML execution utilities for the Bitfab TypeScript SDK.\n * This module provides functions to execute BAML prompts dynamically on the client side.\n */\n\ntype BamlModule = typeof import(\"@boundaryml/baml\")\n\nlet cachedBaml: BamlModule | null = null\n\nasync function loadBaml(): Promise<BamlModule> {\n if (cachedBaml) {\n return cachedBaml\n }\n try {\n cachedBaml = await import(\"@boundaryml/baml\")\n return cachedBaml\n } catch {\n throw new Error(\n \"@boundaryml/baml is required for Bitfab.call(). Install it with: npm install @boundaryml/baml\",\n )\n }\n}\n\n/**\n * Provider definition from the server.\n */\nexport interface ProviderDefinition {\n provider: string\n apiKeyEnv: string\n models: Array<{\n model: string\n description: string\n }>\n}\n\n/**\n * Result of a BAML function execution with raw collector data.\n */\nexport interface BamlExecutionResult {\n /** The parsed result of the function */\n result: unknown\n /** Raw collector data for the server to parse */\n rawCollector: Record<string, unknown> | null\n}\n\n/**\n * Capitalize first letter of a string.\n */\nfunction capitalize(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1)\n}\n\n/**\n * Convert provider name to PascalCase.\n * e.g., \"openai\" -> \"OpenAI\", \"anthropic\" -> \"Anthropic\"\n */\nfunction formatProvider(provider: string): string {\n const providerMap: Record<string, string> = {\n openai: \"OpenAI\",\n anthropic: \"Anthropic\",\n google: \"Google\",\n }\n return providerMap[provider] ?? capitalize(provider)\n}\n\n/**\n * Convert a model name to a valid BAML identifier part.\n * e.g., \"gpt-5-mini\" -> \"GPT5_mini\", \"gpt-4.1\" -> \"GPT4_1\"\n */\nfunction formatModel(model: string): string {\n return model\n .replace(/^gpt-/, \"GPT\") // gpt- prefix -> GPT\n .replace(/\\./g, \"_\") // dots -> underscore\n .replace(/-/g, \"_\") // hyphens -> underscore\n}\n\n/**\n * Generate the BAML client name from provider and model.\n * e.g., \"openai\" + \"gpt-4.1-mini\" -> \"OpenAI_GPT4_1_mini\"\n */\nexport function getClientName(provider: string, model: string): string {\n return `${formatProvider(provider)}_${formatModel(model)}`\n}\n\n/**\n * Generates BAML client definition strings.\n * BamlRuntime.fromFiles requires clients to be defined in source for parsing.\n */\nfunction generateClientDefinitions(providers: ProviderDefinition[]): string {\n const definitions: string[] = []\n\n for (const providerDef of providers) {\n for (const model of providerDef.models) {\n const clientName = getClientName(providerDef.provider, model.model)\n definitions.push(`client<llm> ${clientName} {\n provider ${providerDef.provider}\n options {\n model \"${model.model}\"\n api_key env.${providerDef.apiKeyEnv}\n }\n}`)\n }\n }\n\n return definitions.join(\"\\n\\n\")\n}\n\n/**\n * Prepends the default client definitions to a BAML source if it doesn't already define them.\n */\nfunction withDefaultClients(\n bamlSource: string,\n providers: ProviderDefinition[],\n): string {\n const hasDefaultClient = bamlSource.includes(\"client<llm> OpenAI_\")\n if (hasDefaultClient) {\n return bamlSource\n }\n const defaultClients = generateClientDefinitions(providers)\n return `${defaultClients}\\n\\n${bamlSource}`\n}\n\n/**\n * Extracts the first function name from BAML source code.\n */\nfunction extractFunctionName(bamlSource: string): string | null {\n const match = bamlSource.match(/function\\s+(\\w+)\\s*\\(/)\n return match?.[1] ?? null\n}\n\n/**\n * Parameter type information extracted from BAML function signature.\n */\nexport interface BamlParameterType {\n name: string\n type: string\n isOptional: boolean\n}\n\n/**\n * Extracts function parameter names and types from BAML source code.\n * Used to properly coerce inputs based on expected types.\n */\nexport function extractFunctionParameters(\n bamlSource: string,\n): BamlParameterType[] {\n const functionMatch = bamlSource.match(/function\\s+\\w+\\s*\\(([^)]*)\\)\\s*->/)\n if (!functionMatch) {\n return []\n }\n\n const paramsString = functionMatch[1].trim()\n if (!paramsString) {\n return []\n }\n\n const params: BamlParameterType[] = []\n const paramParts = splitParameters(paramsString)\n\n for (const part of paramParts) {\n const trimmed = part.trim()\n if (!trimmed) {\n continue\n }\n\n const paramMatch = trimmed.match(/^(\\w+)\\s*:\\s*(.+)$/)\n if (paramMatch) {\n const name = paramMatch[1]\n let type = paramMatch[2].trim()\n const isOptional = type.endsWith(\"?\")\n if (isOptional) {\n type = type.slice(0, -1)\n }\n params.push({ name, type, isOptional })\n }\n }\n\n return params\n}\n\n/**\n * Split parameter string by commas, respecting nested angle brackets.\n */\nfunction splitParameters(paramsString: string): string[] {\n const parts: string[] = []\n let current = \"\"\n let depth = 0\n\n for (const char of paramsString) {\n if (char === \"<\") {\n depth++\n current += char\n } else if (char === \">\") {\n depth--\n current += char\n } else if (char === \",\" && depth === 0) {\n parts.push(current)\n current = \"\"\n } else {\n current += char\n }\n }\n\n if (current.trim()) {\n parts.push(current)\n }\n\n return parts\n}\n\n/**\n * Coerce a single string value to the expected BAML type.\n * Returns the coerced value, or the original string if coercion fails.\n */\nfunction coerceToType(value: string, expectedType: string): unknown {\n // String type - keep as is\n if (expectedType === \"string\") {\n return value\n }\n\n // Integer type\n if (expectedType === \"int\") {\n const parsed = Number.parseInt(value, 10)\n if (!Number.isNaN(parsed)) {\n return parsed\n }\n return value\n }\n\n // Float type\n if (expectedType === \"float\") {\n const parsed = Number.parseFloat(value)\n if (!Number.isNaN(parsed)) {\n return parsed\n }\n return value\n }\n\n // Boolean type\n if (expectedType === \"bool\") {\n const lower = value.toLowerCase()\n if (lower === \"true\") {\n return true\n }\n if (lower === \"false\") {\n return false\n }\n return value\n }\n\n // Array types (e.g., string[], int[])\n if (expectedType.endsWith(\"[]\")) {\n try {\n const parsed = JSON.parse(value)\n if (Array.isArray(parsed)) {\n return parsed\n }\n } catch {\n // Not valid JSON array\n }\n return value\n }\n\n // Complex types (objects, classes, maps) - try JSON parse\n try {\n return JSON.parse(value)\n } catch {\n return value\n }\n}\n\n/**\n * Coerces input values from strings to their appropriate types based on expected BAML types.\n * Actively coerces to the expected type (int, float, bool, etc.) rather than just avoiding\n * unintended conversions.\n */\nfunction coerceInputs(\n inputs: Record<string, unknown>,\n expectedTypes: Map<string, string>,\n): Record<string, unknown> {\n const coerced: Record<string, unknown> = {}\n\n for (const [key, value] of Object.entries(inputs)) {\n if (typeof value === \"string\") {\n const expectedType = expectedTypes.get(key)\n\n if (expectedType) {\n coerced[key] = coerceToType(value, expectedType)\n } else {\n // No expected type info - keep as string\n coerced[key] = value\n }\n } else {\n coerced[key] = value\n }\n }\n\n return coerced\n}\n\n/**\n * Recursively convert an object to a JSON-serializable structure.\n * Similar to Python's _obj_to_dict function.\n */\nfunction objToDict(obj: unknown, depth = 0, maxDepth = 5): unknown {\n if (depth > maxDepth) {\n return `<max depth reached: ${typeof obj}>`\n }\n\n // Handle primitives\n if (\n obj === null ||\n obj === undefined ||\n typeof obj === \"string\" ||\n typeof obj === \"number\" ||\n typeof obj === \"boolean\"\n ) {\n return obj\n }\n\n // Handle arrays\n if (Array.isArray(obj)) {\n return obj.map((item) => objToDict(item, depth + 1, maxDepth))\n }\n\n // Handle plain objects and class instances\n if (typeof obj === \"object\") {\n const result: Record<string, unknown> = {}\n\n // Add type information for non-plain objects\n if (obj.constructor && obj.constructor.name !== \"Object\") {\n result.__type__ = obj.constructor.name\n }\n\n // Extract all enumerable properties\n for (const key of Object.keys(obj)) {\n if (key.startsWith(\"_\")) {\n continue // Skip private properties\n }\n\n try {\n const value = (obj as Record<string, unknown>)[key]\n\n // Skip functions\n if (typeof value === \"function\") {\n continue\n }\n\n result[key] = objToDict(value, depth + 1, maxDepth)\n } catch (error) {\n result[key] =\n `<error: ${error instanceof Error ? error.message : String(error)}>`\n }\n }\n\n // Also try to get non-enumerable properties from the prototype\n // This helps capture getters and computed properties\n try {\n const proto = Object.getPrototypeOf(obj)\n if (proto && proto !== Object.prototype) {\n const descriptors = Object.getOwnPropertyDescriptors(proto)\n for (const [key, descriptor] of Object.entries(descriptors)) {\n if (key.startsWith(\"_\") || key === \"constructor\" || key in result) {\n continue\n }\n\n // Try to get the value if it has a getter\n if (descriptor.get) {\n try {\n const value = (obj as Record<string, unknown>)[key]\n if (typeof value !== \"function\") {\n result[key] = objToDict(value, depth + 1, maxDepth)\n }\n } catch {\n // Getter might throw or be inaccessible\n }\n }\n }\n }\n } catch {\n // Prototype inspection might fail\n }\n\n return result\n }\n\n // Fallback for other types\n return String(obj)\n}\n\n/**\n * Serialize the BAML Collector to a JSON-serializable structure.\n * Recursively extracts all properties from the Collector for server-side parsing.\n */\nfunction serializeCollector(\n collector: unknown,\n): Record<string, unknown> | null {\n try {\n return objToDict(collector, 0, 5) as Record<string, unknown>\n } catch (_error) {\n // Silently ignore serialization failures\n return null\n }\n}\n\n/**\n * Allowed environment variable keys for LLM providers.\n * Only these keys will be passed to the BAML runtime.\n */\nconst ALLOWED_ENV_KEYS = [\"OPENAI_API_KEY\"] as const\n\n/**\n * Type for allowed environment variables.\n * Only OPENAI_API_KEY is currently supported.\n */\nexport type AllowedEnvVars = {\n OPENAI_API_KEY?: string\n}\n\n/**\n * Filters environment variables to only include allowed keys.\n * This prevents accidentally passing sensitive environment variables to the BAML runtime.\n */\nfunction filterEnvVars(envVars: AllowedEnvVars): Record<string, string> {\n const filtered: Record<string, string> = {}\n for (const key of ALLOWED_ENV_KEYS) {\n const value = envVars[key]\n if (value) {\n filtered[key] = value\n }\n }\n return filtered\n}\n\n/**\n * Runs the BAML function with the given inputs using the BAML runtime directly.\n * No file generation or subprocess spawning needed.\n *\n * @param bamlSource - The BAML source code containing the function\n * @param inputs - Named arguments to pass to the function\n * @param providers - Available provider definitions\n * @param envVars - Environment variables for API keys (only OPENAI_API_KEY is allowed)\n * @returns The result and execution metadata of the BAML function call\n */\nexport async function runFunctionWithBaml(\n bamlSource: string,\n inputs: Record<string, unknown>,\n providers: ProviderDefinition[],\n envVars: AllowedEnvVars,\n): Promise<BamlExecutionResult> {\n const { BamlRuntime, Collector } = await loadBaml()\n\n // Extract function name from the BAML source\n const functionName = extractFunctionName(bamlSource)\n if (!functionName) {\n throw new Error(\"No function found in BAML source\")\n }\n\n // Add default client definitions (runtime needs them for parsing)\n const fullSource = withDefaultClients(bamlSource, providers)\n\n // Filter env vars to only allowed keys\n const filteredEnvVars = filterEnvVars(envVars)\n\n // Create runtime from source with env vars\n const runtime = BamlRuntime.fromFiles(\n \"/tmp/baml_runtime\",\n { \"source.baml\": fullSource },\n filteredEnvVars,\n )\n\n // Create context manager\n const ctx = runtime.createContextManager()\n\n // Create collector to capture execution metadata\n const collector = new Collector(\"bitfab-collector\")\n\n // Extract expected parameter types from BAML source\n const params = extractFunctionParameters(bamlSource)\n const expectedTypes = new Map(params.map((p) => [p.name, p.type]))\n\n // Coerce inputs from strings to proper types based on BAML signature\n const args = coerceInputs(inputs, expectedTypes)\n\n // Call the function with collector\n const functionResult = await runtime.callFunction(\n functionName,\n args,\n ctx,\n null, // TypeBuilder\n null, // ClientRegistry\n [collector], // Collectors - capture execution data\n {}, // Tags\n filteredEnvVars,\n )\n\n if (!functionResult.isOk()) {\n throw new Error(\"BAML function execution failed\")\n }\n\n // Serialize the collector to a dict for the server to parse\n const rawCollector = serializeCollector(collector)\n\n return {\n result: functionResult.parsed(false),\n rawCollector,\n }\n}\n","/**\n * Tracing utilities for external trace submission to Bitfab.\n *\n * This module provides utilities for sending external traces (e.g., from OpenAI API calls)\n * to Bitfab for monitoring and analysis.\n */\n\nimport type { Span, Trace } from \"@openai/agents\"\nimport { DEFAULT_SERVICE_URL } from \"./constants.js\"\nimport { HttpClient } from \"./http.js\"\n\nexport interface TraceResponse {\n traceId: string\n status: \"success\"\n}\n\nexport interface ActiveSpanContext {\n traceId: string\n spanId: string\n}\n\n/**\n * TracingProcessor interface from OpenAI Agents SDK v0.3.7\n */\nexport interface TracingProcessor {\n onTraceStart(trace: Trace): Promise<void>\n onTraceEnd(trace: Trace): Promise<void>\n // biome-ignore lint/suspicious/noExplicitAny: OpenAI Agents SDK uses any for span data\n onSpanStart(span: Span<any>): Promise<void>\n // biome-ignore lint/suspicious/noExplicitAny: OpenAI Agents SDK uses any for span data\n onSpanEnd(span: Span<any>): Promise<void>\n forceFlush(): Promise<void>\n shutdown(timeout?: number): Promise<void>\n}\n\n/**\n * Tracing processor for OpenAI Agents SDK integration.\n *\n * Implements the TracingProcessor interface from the OpenAI Agents SDK to\n * automatically capture traces and spans and send them to Bitfab for\n * monitoring and analysis.\n *\n * Example usage:\n * ```typescript\n * import { Bitfab } from '@goharvest/bitfab';\n * import { addTraceProcessor } from '@openai/agents';\n *\n * const client = new Bitfab({ apiKey: 'your-api-key' });\n * const processor = client.getOpenAiTracingProcessor();\n * addTraceProcessor(processor);\n * ```\n */\nexport class BitfabOpenAITracingProcessor implements TracingProcessor {\n private readonly httpClient: HttpClient\n private activeTraces: Record<string, Trace> = {}\n private readonly getActiveSpanContext: (() => ActiveSpanContext | null) | null\n private activeSpanMappings: Record<string, ActiveSpanContext> = {}\n\n /**\n * Initialize the tracing processor.\n *\n * @param config - Configuration options\n */\n constructor(config: {\n apiKey?: string\n serviceUrl?: string\n timeout?: number\n getActiveSpanContext?: () => ActiveSpanContext | null\n }) {\n this.httpClient = new HttpClient({\n apiKey: config.apiKey,\n serviceUrl: config.serviceUrl ?? DEFAULT_SERVICE_URL,\n timeout: config.timeout ?? 10000,\n })\n this.getActiveSpanContext = config.getActiveSpanContext ?? null\n }\n\n /**\n * Called when a trace is started.\n * If there's an active withSpan context, the trace ID is remapped to the\n * outer trace and sent to pre-create the external_traces row on the server.\n */\n async onTraceStart(trace: Trace): Promise<void> {\n this.activeTraces[trace.traceId] = trace\n\n const activeContext = this.getActiveSpanContext?.()\n if (activeContext) {\n this.activeSpanMappings[trace.traceId] = activeContext\n }\n\n this.sendTrace(trace, activeContext ? { id: activeContext.traceId } : {})\n }\n\n /**\n * Called when a trace is ended.\n * If mapped to a withSpan trace, sends with remapped ID and completed=false\n * since the parent withSpan handles completion.\n */\n async onTraceEnd(trace: Trace): Promise<void> {\n const mapping = this.activeSpanMappings[trace.traceId]\n\n this.sendTrace(\n trace,\n mapping ? { id: mapping.traceId } : { completed: true },\n )\n\n delete this.activeSpanMappings[trace.traceId]\n delete this.activeTraces[trace.traceId]\n }\n\n /**\n * Called when a span is started.\n */\n // biome-ignore lint/suspicious/noExplicitAny: OpenAI Agents SDK uses any for span data\n async onSpanStart(span: Span<any>): Promise<void> {\n // Send the span to Bitfab (fire-and-forget)\n this.sendSpan(span)\n }\n\n /**\n * Called when a span is ended.\n *\n * Send all spans to Bitfab for complete trace capture.\n */\n // biome-ignore lint/suspicious/noExplicitAny: OpenAI Agents SDK uses any for span data\n async onSpanEnd(span: Span<any>): Promise<void> {\n // Send the span to Bitfab again to capture updates (fire-and-forget)\n this.sendSpan(span)\n }\n\n /**\n * Called when a trace is being flushed.\n */\n async forceFlush(): Promise<void> {\n // No buffering, so nothing to flush\n }\n\n /**\n * Called when the trace processor is shutting down.\n */\n async shutdown(_timeout?: number): Promise<void> {\n this.activeTraces = {}\n this.activeSpanMappings = {}\n }\n\n /**\n * Send trace to Bitfab API (fire-and-forget).\n * When traceIdOverride is provided, the trace ID is remapped to link\n * the OpenAI trace into an outer withSpan trace.\n */\n private sendTrace(\n trace: Trace,\n overrides: { completed?: boolean; id?: string } = {},\n ): void {\n try {\n const { completed, ...traceOverrides } = overrides\n const traceData = trace.toJSON() as Record<string, unknown>\n Object.assign(traceData, traceOverrides)\n\n this.httpClient.sendExternalTrace({\n type: \"openai\",\n source: \"typescript-sdk-openai-tracing\",\n externalTrace: traceData,\n completed: completed ?? false,\n })\n } catch {\n // Silently ignore — never crash the host app\n }\n }\n\n /**\n * Export span to JSON object, collecting any errors.\n */\n private exportSpan(\n // biome-ignore lint/suspicious/noExplicitAny: OpenAI Agents SDK uses any for span data\n span: Span<any>,\n ): [Record<string, unknown>, Array<{ step: string; error: string }>] {\n const errors: Array<{ step: string; error: string }> = []\n let serializedSpan: Record<string, unknown>\n\n try {\n const jsonResult = span.toJSON()\n if (typeof jsonResult !== \"object\" || jsonResult === null) {\n errors.push({\n step: \"span.toJSON()\",\n error: `Returned unexpected type: ${typeof jsonResult}`,\n })\n serializedSpan = {}\n } else {\n serializedSpan = jsonResult as Record<string, unknown>\n }\n } catch (error) {\n errors.push({\n step: \"span.toJSON()\",\n error: error instanceof Error ? error.message : String(error),\n })\n serializedSpan = {}\n }\n\n if (!serializedSpan.span_data) {\n serializedSpan.span_data = {} as Record<string, unknown>\n }\n\n return [serializedSpan, errors]\n }\n\n /**\n * Extract and add input/response to serialized span, updating errors list.\n */\n private extractSpanInputResponse(\n // biome-ignore lint/suspicious/noExplicitAny: OpenAI Agents SDK uses any for span data\n span: Span<any>,\n serializedSpan: Record<string, unknown>,\n errors: Array<{ step: string; error: string }>,\n ): void {\n const spanData = serializedSpan.span_data as Record<string, unknown>\n\n try {\n spanData.input = span.spanData?._input || []\n } catch (error) {\n errors.push({\n step: \"access_input\",\n error: error instanceof Error ? error.message : String(error),\n })\n }\n\n try {\n spanData.response = span.spanData?._response || null\n } catch (error) {\n errors.push({\n step: \"access_response\",\n error: error instanceof Error ? error.message : String(error),\n })\n }\n }\n\n /**\n * If the span's trace is mapped to a withSpan trace, rewrite trace_id and parent_id.\n */\n private applySpanOverrides(\n serializedSpan: Record<string, unknown>,\n traceId: string,\n ): void {\n const mapping = this.activeSpanMappings[traceId]\n if (mapping) {\n serializedSpan.trace_id = mapping.traceId\n if (!serializedSpan.parent_id) {\n serializedSpan.parent_id = mapping.spanId\n }\n }\n }\n\n /**\n * Build span payload for the external spans API.\n */\n private buildSpanPayload(\n serializedSpan: Record<string, unknown>,\n errors: Array<{ step: string; error: string }>,\n ): Record<string, unknown> {\n const payload: Record<string, unknown> = {\n type: \"openai\",\n source: \"typescript-sdk-openai-tracing\",\n sourceTraceId: serializedSpan.trace_id ?? \"unknown\",\n rawSpan: serializedSpan,\n }\n\n if (errors.length > 0) {\n payload.errors = errors\n }\n\n return payload\n }\n\n /**\n * Send span to Bitfab API (fire-and-forget).\n * If the span belongs to a trace mapped to a withSpan trace, the trace_id\n * and parent_id are rewritten to link the span into the withSpan tree.\n */\n private sendSpan(\n // biome-ignore lint/suspicious/noExplicitAny: OpenAI Agents SDK uses any for span data\n span: Span<any>,\n ): void {\n const errors: Array<{ step: string; error: string }> = []\n const [serializedSpan, exportErrors] = this.exportSpan(span)\n errors.push(...exportErrors)\n\n this.extractSpanInputResponse(span, serializedSpan, errors)\n\n this.applySpanOverrides(serializedSpan, span.traceId ?? \"\")\n\n const payload = this.buildSpanPayload(serializedSpan, errors)\n\n this.httpClient.sendExternalSpan(payload)\n }\n}\n","/**\n * Bitfab client for provider-based API calls.\n */\n\nimport {\n type AsyncLocalStorageLike,\n asyncStorageReady,\n createAsyncLocalStorage,\n isAsyncStorageInitDone,\n} from \"./asyncStorage.js\"\nimport {\n type AllowedEnvVars,\n type ProviderDefinition,\n runFunctionWithBaml,\n} from \"./baml.js\"\nimport { DEFAULT_SERVICE_URL } from \"./constants.js\"\nimport { BitfabError, HttpClient } from \"./http.js\"\nimport { getReplayContext } from \"./replayContext.js\"\nimport { serializeValue } from \"./serialize.js\"\nimport { BitfabOpenAITracingProcessor } from \"./tracing.js\"\n\n// Context entry for addContext calls - each entry is an object with multiple key-value pairs\ntype ContextEntry = Record<string, unknown>\n\n// Trace state for tracking trace-level data\ninterface TraceState {\n traceId: string\n sessionId?: string\n metadata?: Record<string, unknown>\n contexts: ContextEntry[]\n startedAt: string\n}\n\n// Span context for tracking nested spans\ninterface SpanContext {\n traceId: string\n spanId: string\n contexts: ContextEntry[]\n prompt?: string\n}\n\n// Global map to track active trace states\nconst activeTraceStates = new Map<string, TraceState>()\nconst pendingSpanPromises = new Map<string, Promise<unknown>[]>()\n\nlet asyncLocalStorage: AsyncLocalStorageLike<SpanContext[]> | null = null\n\nconst asyncLocalStorageReady: Promise<void> = asyncStorageReady.then(() => {\n asyncLocalStorage = createAsyncLocalStorage<SpanContext[]>()\n})\n\n// Browser fallback: a single module-level stack shared across all async\n// execution chains. Works correctly for synchronous nesting and sequential\n// async nesting (the common browser cases), but breaks when multiple\n// independent spans are in-flight concurrently (e.g. Promise.all with\n// separate withSpan calls). In that scenario, whichever span resumes last\n// overwrites the shared stack, so inner spans may see the wrong parent.\n//\n// Node.js avoids this via AsyncLocalStorage, which gives each async chain\n// its own isolated copy of the stack.\n//\n// Potential future fixes:\n// - TC39 AsyncContext proposal (stage 2) would provide AsyncLocalStorage\n// semantics natively in all JS environments, including browsers.\n// https://github.com/tc39/proposal-async-context\n// - Zone.js could work today but is ~50KB, monkey-patches Promise/setTimeout/\n// fetch/etc., and can conflict with frameworks like React. Too invasive for\n// an SDK dependency.\nlet browserSpanStack: SpanContext[] = []\n\nfunction getSpanStack(): SpanContext[] {\n if (asyncLocalStorage) {\n return asyncLocalStorage.getStore() ?? []\n }\n return browserSpanStack\n}\n\nfunction runWithSpanStack<T>(stack: SpanContext[], fn: () => T): T {\n if (asyncLocalStorage) {\n return asyncLocalStorage.run(stack, fn)\n }\n // Browser fallback: save/restore the stack around the function call.\n // This is correct for sequential async but not for concurrent async —\n // see the browserSpanStack comment above for details.\n const previousStack = browserSpanStack\n browserSpanStack = stack\n try {\n const result = fn()\n if (result instanceof Promise) {\n return result.finally(() => {\n browserSpanStack = previousStack\n }) as T\n }\n browserSpanStack = previousStack\n return result\n } catch (error) {\n browserSpanStack = previousStack\n throw error\n }\n}\n\n// --- BAML Collector support for wrapBAML ---\n\ntype CollectorConstructor = new (name: string) => unknown\n\nlet cachedCollectorClass: CollectorConstructor | null | undefined\n\n/** @internal Reset the cached Collector class — for testing only. */\nexport function _resetCollectorCache(): void {\n cachedCollectorClass = undefined\n}\n\n/** @internal Inject a mock Collector class — for testing only. */\nexport function _setCollectorCache(cls: CollectorConstructor | null): void {\n cachedCollectorClass = cls\n}\n\nasync function loadCollectorClass(): Promise<CollectorConstructor | null> {\n if (cachedCollectorClass !== undefined) {\n return cachedCollectorClass\n }\n try {\n const baml = await import(\"@boundaryml/baml\")\n cachedCollectorClass = baml.Collector as CollectorConstructor\n return cachedCollectorClass\n } catch {\n cachedCollectorClass = null\n return null\n }\n}\n\n// Typed accessors for the BAML Collector's internal structure.\n// Uses defensive access since these are untyped objects from the BAML runtime.\n\ninterface CollectorCall {\n selected?: boolean\n clientName?: string\n provider?: string\n usage?: {\n inputTokens?: number\n outputTokens?: number\n cachedInputTokens?: number\n }\n httpRequest?: {\n url?: string\n body?: { json: () => Record<string, unknown> | null }\n }\n}\n\ninterface CollectorLog {\n calls?: CollectorCall[]\n timing?: { durationMs?: number }\n}\n\ninterface CollectorLike {\n last?: CollectorLog | null\n usage?: {\n inputTokens?: number\n outputTokens?: number\n cachedInputTokens?: number\n }\n}\n\nfunction extractPromptFromCollector(collector: unknown): string | null {\n try {\n const c = collector as CollectorLike\n const calls = c?.last?.calls ?? []\n const selectedCall = calls.find((call) => call.selected) ?? calls[0]\n if (!selectedCall?.httpRequest?.body) {\n return null\n }\n const body = selectedCall.httpRequest.body.json()\n if (!body || typeof body !== \"object\") {\n return null\n }\n const messages = body.messages\n if (!Array.isArray(messages) || messages.length === 0) {\n return null\n }\n const rendered = (messages as Record<string, unknown>[])\n .filter(\n (msg): msg is { role: string; content: unknown } =>\n typeof msg === \"object\" &&\n msg !== null &&\n \"role\" in msg &&\n typeof (msg as { role: unknown }).role === \"string\",\n )\n .map((msg) => ({\n role: msg.role,\n content:\n typeof msg.content === \"string\"\n ? msg.content\n : JSON.stringify(msg.content),\n }))\n if (rendered.length > 0) {\n return JSON.stringify(rendered)\n }\n return null\n } catch {\n return null\n }\n}\n\nfunction extractContextFromCollector(\n collector: unknown,\n): Record<string, unknown> | null {\n try {\n const c = collector as CollectorLike\n const calls = c?.last?.calls ?? []\n const selectedCall = calls.find((call) => call.selected) ?? calls[0]\n const usage = c?.usage\n\n const context: Record<string, unknown> = {}\n if (selectedCall?.provider) {\n context.provider = selectedCall.provider\n }\n\n // Extract model from HTTP request body (OpenAI/Anthropic) or URL (Vertex AI)\n const body = selectedCall?.httpRequest?.body?.json()\n if (body && typeof body === \"object\" && typeof body.model === \"string\") {\n context.model = body.model\n } else {\n const url = selectedCall?.httpRequest?.url\n if (url) {\n const match = url.match(/\\/models\\/([^/:]+)/)\n if (match?.[1]) {\n context.model = match[1]\n }\n }\n }\n\n const inputTokens =\n usage?.inputTokens ?? selectedCall?.usage?.inputTokens ?? null\n const outputTokens =\n usage?.outputTokens ?? selectedCall?.usage?.outputTokens ?? null\n if (inputTokens !== null) {\n context.inputTokens = inputTokens\n }\n if (outputTokens !== null) {\n context.outputTokens = outputTokens\n }\n\n const durationMs = c?.last?.timing?.durationMs ?? null\n if (durationMs !== null) {\n context.durationMs = durationMs\n }\n\n return Object.keys(context).length > 0 ? context : null\n } catch {\n return null\n }\n}\n\n/**\n * Options for wrapBAML.\n */\nexport interface WrapBAMLOptions {\n /** Called after each BAML invocation with the Collector instance. */\n onCollector?: (collector: unknown) => void\n}\n\n/**\n * A function returned by wrapBAML that exposes the BAML collector from the last call.\n */\nexport interface WrappedBamlFn<TArgs extends unknown[], TReturn> {\n (...args: TArgs): Promise<TReturn>\n /** The BAML Collector instance from the most recent call. `null` before the first call or if @boundaryml/baml is unavailable. */\n collector: unknown | null\n}\n\n/**\n * A handle to the current active span, allowing context to be added.\n */\nexport interface CurrentSpan {\n /** The trace ID for the current span. */\n readonly traceId: string\n /**\n * Add a context entry to this span. Each call appends to the contexts array.\n * Context entries are stored in span_data.contexts as [{key, value}, ...].\n */\n addContext(context: Record<string, unknown>): void\n /**\n * Set the prompt for this span. Stored in span_data.prompt.\n * Calling multiple times overwrites the previous value.\n */\n setPrompt(prompt: string): void\n}\n\n/**\n * A handle to the current active trace, allowing trace-level context to be set.\n */\nexport interface CurrentTrace {\n /**\n * Set the session ID for this trace. Stored in the database session_id column.\n */\n setSessionId(sessionId: string): void\n /**\n * Set metadata for this trace. Stored in rawData.metadata.\n * Subsequent calls merge with existing metadata, with later values taking precedence.\n */\n setMetadata(metadata: Record<string, unknown>): void\n /**\n * Add a context entry to this trace. Each call appends to the contexts array.\n * Context entries are stored in rawData.contexts as [{key, value}, ...].\n */\n addContext(context: Record<string, unknown>): void\n}\n\n// No-op implementations for when called outside a span context\nconst noOpSpan: CurrentSpan = {\n traceId: \"\",\n addContext(): void {\n // No-op\n },\n setPrompt(): void {\n // No-op\n },\n}\n\nconst noOpTrace: CurrentTrace = {\n setSessionId(): void {\n // No-op\n },\n setMetadata(): void {\n // No-op\n },\n addContext(): void {\n // No-op\n },\n}\n\n/**\n * Get a handle to the current active span.\n *\n * Call this from inside a traced function (wrapped with `withSpan`) to get\n * a span handle that allows adding context at runtime.\n *\n * Returns a no-op object if called outside of a span context (methods do nothing).\n */\nexport function getCurrentSpan(): CurrentSpan {\n const stack = getSpanStack()\n const current = stack[stack.length - 1]\n if (!current) {\n return noOpSpan\n }\n return {\n traceId: current.traceId,\n addContext(context: Record<string, unknown>): void {\n try {\n if (typeof context !== \"object\" || context === null) {\n return\n }\n // Push the entire context object as one entry\n current.contexts.push(context)\n } catch {\n // Silently ignore - never crash the host app\n }\n },\n setPrompt(prompt: string): void {\n try {\n if (typeof prompt !== \"string\") {\n return\n }\n current.prompt = prompt\n } catch {\n // Silently ignore - never crash the host app\n }\n },\n }\n}\n\n/**\n * Get a handle to the current active trace.\n *\n * Call this from inside a traced function (wrapped with `withSpan`) to get\n * a trace handle that allows setting trace-level context at runtime.\n *\n * Returns a no-op object if called outside of a span context (methods do nothing).\n */\nexport function getCurrentTrace(): CurrentTrace {\n const stack = getSpanStack()\n const current = stack[stack.length - 1]\n if (!current) {\n return noOpTrace\n }\n\n const traceId = current.traceId\n\n const getOrCreateTraceState = (): TraceState => {\n let traceState = activeTraceStates.get(traceId)\n if (!traceState) {\n traceState = {\n traceId,\n startedAt: new Date().toISOString(),\n contexts: [],\n }\n activeTraceStates.set(traceId, traceState)\n }\n return traceState\n }\n\n return {\n setSessionId(sessionId: string): void {\n try {\n const traceState = getOrCreateTraceState()\n traceState.sessionId = sessionId\n } catch {\n // Silently ignore - never crash the host app\n }\n },\n setMetadata(metadata: Record<string, unknown>): void {\n try {\n if (typeof metadata !== \"object\" || metadata === null) {\n return\n }\n const traceState = getOrCreateTraceState()\n traceState.metadata = { ...traceState.metadata, ...metadata }\n } catch {\n // Silently ignore - never crash the host app\n }\n },\n addContext(context: Record<string, unknown>): void {\n try {\n if (typeof context !== \"object\" || context === null) {\n return\n }\n const traceState = getOrCreateTraceState()\n // Push the entire context object as one entry\n traceState.contexts.push(context)\n } catch {\n // Silently ignore - never crash the host app\n }\n },\n }\n}\n\nexport interface BitfabConfig {\n /** The API key for Bitfab API authentication. When undefined or empty, tracing is disabled. */\n apiKey?: string\n /** The base URL for the Bitfab API (default: https://bitfab.ai) */\n serviceUrl?: string\n /** Request timeout in milliseconds (default: 120000) */\n timeout?: number\n /** Environment variables for LLM provider API keys (only OPENAI_API_KEY is supported) */\n envVars?: AllowedEnvVars\n /** Whether the client is enabled. Defaults to true. When false, withSpan returns the original function unwrapped. */\n enabled?: boolean\n /** The generated BAML client instance (e.g., `b` from your baml_client). Used by wrapBAML() when no explicit client is passed. */\n bamlClient?: unknown\n}\n\n/**\n * Span types matching the backend enum.\n * - llm: LLM API calls\n * - agent: Autonomous orchestrators\n * - function: Tool implementations\n * - guardrail: Safety/validation checks\n * - handoff: Agent-to-agent transfers\n * - custom: Application-specific tracing (default)\n */\nexport type SpanType =\n | \"llm\"\n | \"agent\"\n | \"function\"\n | \"guardrail\"\n | \"handoff\"\n | \"custom\"\n\n/**\n * Options for configuring span behavior.\n */\nexport interface SpanOptions {\n /**\n * The name of the span. Defaults to the function name if available,\n * otherwise falls back to the trace function key.\n */\n name?: string\n /**\n * The type of span. Defaults to \"custom\" if not specified.\n */\n type?: SpanType\n}\n\ninterface FunctionVersionResponse {\n id: string\n name: string\n versionId: string\n versionNumber: number | null\n prompt: string\n providers: ProviderDefinition[]\n}\n\n// Re-export BitfabError for backwards compatibility\nexport { BitfabError }\n\n/**\n * Client for making provider-based API calls via BAML.\n */\nexport class Bitfab {\n private readonly apiKey: string | undefined\n private readonly serviceUrl: string\n private readonly timeout: number\n private readonly envVars: AllowedEnvVars\n private readonly enabled: boolean\n private readonly httpClient: HttpClient\n private readonly bamlClient: unknown\n\n /**\n * Initialize the Bitfab client.\n *\n * @param config - Configuration options for the client\n */\n constructor(config: BitfabConfig) {\n this.apiKey = config.apiKey\n this.serviceUrl = config.serviceUrl ?? DEFAULT_SERVICE_URL\n this.timeout = config.timeout ?? 120000\n this.envVars = config.envVars ?? {}\n const enabled = config.enabled ?? true\n if (enabled && (!config.apiKey || config.apiKey.trim() === \"\")) {\n console.warn(\n \"Bitfab: apiKey is empty — tracing is disabled. Provide a valid API key to enable tracing.\",\n )\n this.enabled = false\n } else {\n this.enabled = enabled\n }\n this.bamlClient = config.bamlClient ?? null\n this.httpClient = new HttpClient({\n apiKey: this.apiKey,\n serviceUrl: this.serviceUrl,\n timeout: this.timeout,\n })\n }\n\n /**\n * Fetch the function with its current version and BAML prompt from the server.\n *\n * @param methodName - The name of the method to fetch\n * @returns The function with current version, BAML prompt, and provider definitions\n * @throws {BitfabError} If the function is not found or an error occurs\n */\n private async fetchFunctionVersion(\n methodName: string,\n ): Promise<FunctionVersionResponse> {\n const result =\n await this.httpClient.lookupFunction<FunctionVersionResponse>(methodName)\n\n // Check if function was not found\n if (result.id === null) {\n throw new BitfabError(\n `Function \"${methodName}\" not found. Create it at: ${this.serviceUrl}/functions`,\n \"/functions\",\n )\n }\n\n // Check if function has no prompt\n if (!result.prompt) {\n throw new BitfabError(\n `Function \"${methodName}\" has no prompt configured. Add one at: ${this.serviceUrl}/functions/${result.id}`,\n `/functions/${result.id}`,\n )\n }\n\n return result\n }\n\n /**\n * Call a method with the given named arguments via BAML execution.\n *\n * @param methodName - The name of the method to call\n * @param inputs - Named arguments to pass to the method\n * @returns The result of the BAML function execution\n * @throws {BitfabError} If service_url is not set, or if an error occurs\n */\n async call<T = unknown>(\n methodName: string,\n inputs: Record<string, unknown> = {},\n ): Promise<T> {\n try {\n const functionVersion = await this.fetchFunctionVersion(methodName)\n const executionResult = await runFunctionWithBaml(\n functionVersion.prompt,\n inputs,\n functionVersion.providers,\n this.envVars,\n )\n\n // Create trace for the local execution\n const resultStr =\n typeof executionResult.result === \"string\"\n ? executionResult.result\n : JSON.stringify(executionResult.result)\n\n // Create trace in background so user doesn't have to wait\n this.httpClient.sendInternalTrace(functionVersion.id, {\n result: resultStr,\n source: \"typescript-sdk\",\n ...(Object.keys(inputs).length > 0 && { inputs }),\n ...(executionResult.rawCollector != null && {\n rawCollector: executionResult.rawCollector,\n }),\n })\n\n return executionResult.result as T\n } catch (error) {\n if (error instanceof BitfabError) {\n throw error\n }\n if (error instanceof Error) {\n throw new BitfabError(error.message)\n }\n throw new BitfabError(\"Unknown error occurred during local execution\")\n }\n }\n\n /**\n * Get a tracing processor for OpenAI Agents SDK integration.\n *\n * This processor automatically captures traces and spans from the OpenAI Agents SDK\n * and sends them to Bitfab for monitoring and analysis.\n *\n * Example usage:\n * ```typescript\n * import { addTraceProcessor } from '@openai/agents';\n *\n * const client = new Bitfab({ apiKey: 'your-api-key' });\n * const processor = client.getOpenAiTracingProcessor();\n * addTraceProcessor(processor);\n * ```\n *\n * @returns A BitfabOpenAITracingProcessor instance configured for this client\n */\n getOpenAiTracingProcessor() {\n return new BitfabOpenAITracingProcessor({\n apiKey: this.apiKey,\n serviceUrl: this.serviceUrl,\n getActiveSpanContext: () => {\n const stack = getSpanStack()\n return stack[stack.length - 1] ?? null\n },\n })\n }\n\n /**\n * Wrap a BAML client method to automatically capture prompt and LLM metadata.\n *\n * Creates a BAML Collector, calls the method through a tracked client,\n * then extracts rendered messages and token usage — calling setPrompt()\n * and addContext() on the current span automatically.\n *\n * The BAML client can be provided in the constructor or passed explicitly:\n *\n * ```typescript\n * // Option 1: bamlClient in constructor (use wrapBAML with just the method)\n * const client = new Bitfab({ apiKey: 'your-api-key', bamlClient: b });\n * const traced = client.withSpan('classify', { type: 'llm' },\n * client.wrapBAML(b.ClassifyText)\n * );\n *\n * // Option 2: pass bamlClient at call site\n * const client = new Bitfab({ apiKey: 'your-api-key' });\n * const traced = client.withSpan('classify', { type: 'llm' },\n * client.wrapBAML(b, b.ClassifyText)\n * );\n * ```\n *\n * @param methodOrClient - Either a BAML method (uses constructor bamlClient) or the BAML client instance\n * @param maybeMethodOrOptions - The BAML method when the first argument is a client, or WrapBAMLOptions when the first argument is the method\n * @param maybeOptions - WrapBAMLOptions when using the two-argument (client, method) form\n * @returns An async function with the same signature that instruments the BAML call\n */\n wrapBAML<TArgs extends unknown[], TReturn>(\n methodOrClient: unknown,\n maybeMethodOrOptions?:\n | ((...args: TArgs) => Promise<TReturn>)\n | WrapBAMLOptions,\n maybeOptions?: WrapBAMLOptions,\n ): WrappedBamlFn<TArgs, TReturn> {\n let bamlClient: unknown\n let method: (...args: TArgs) => Promise<TReturn>\n let options: WrapBAMLOptions | undefined\n\n if (typeof maybeMethodOrOptions === \"function\") {\n bamlClient = methodOrClient\n method = maybeMethodOrOptions\n options = maybeOptions\n } else {\n bamlClient = this.bamlClient\n method = methodOrClient as (...args: TArgs) => Promise<TReturn>\n options = maybeMethodOrOptions as WrapBAMLOptions | undefined\n if (!bamlClient) {\n throw new BitfabError(\n \"bamlClient is required for wrapBAML. Pass it in the constructor or as the first argument.\",\n )\n }\n }\n\n const methodName = method.name\n if (!methodName) {\n throw new BitfabError(\n \"wrapBAML requires a named function (e.g., b.ClassifyText).\",\n )\n }\n\n // Warm the Collector class cache so it's ready by the time the wrapper is called\n loadCollectorClass()\n\n const wrappedFn = async (...args: TArgs): Promise<TReturn> => {\n const CollectorClass = await loadCollectorClass()\n if (!CollectorClass) {\n // @boundaryml/baml not available — call method directly as fallback\n wrappedFn.collector = null\n return await (\n bamlClient as Record<string, (...a: TArgs) => Promise<TReturn>>\n )[methodName](...args)\n }\n\n const collector = new CollectorClass(\"bitfab-baml-tracing\")\n const trackedClient = (\n bamlClient as { withOptions: (opts: unknown) => unknown }\n ).withOptions({ collector })\n const trackedMethod = (\n trackedClient as Record<string, (...a: TArgs) => Promise<TReturn>>\n )[methodName]\n const result = await trackedMethod.bind(\n trackedClient as Record<string, unknown>,\n )(...args)\n\n wrappedFn.collector = collector\n\n try {\n const prompt = extractPromptFromCollector(collector)\n if (prompt) {\n getCurrentSpan().setPrompt(prompt)\n }\n const metadata = extractContextFromCollector(collector)\n if (metadata) {\n getCurrentSpan().addContext(metadata)\n }\n } catch {\n // Never crash the host app\n }\n\n try {\n options?.onCollector?.(collector)\n } catch {\n // Never crash the host app\n }\n\n return result\n }\n\n wrappedFn.collector = null as unknown | null\n\n return wrappedFn\n }\n\n /**\n * Wrap a function to automatically create a span for its inputs and outputs.\n *\n * The wrapped function behaves identically to the original, but sends\n * span data to Bitfab in the background after each call.\n *\n * Example usage:\n * ```typescript\n * const client = new Bitfab({ apiKey: 'your-api-key' });\n *\n * async function processOrder(orderId: string, items: string[]): Promise<{ total: number }> {\n * // ... process order\n * return { total: 100 };\n * }\n *\n * // Basic usage (defaults to \"custom\" span type)\n * const tracedProcessOrder = client.withSpan('order-processing', processOrder);\n *\n * // With explicit span type\n * const tracedProcessOrder = client.withSpan('order-processing', { type: 'function' }, processOrder);\n *\n * // Call the wrapped function normally\n * const result = await tracedProcessOrder('order-123', ['item-1', 'item-2']);\n * // Span is automatically sent to Bitfab\n * ```\n *\n * @param traceFunctionKey - A string identifier for grouping spans (e.g., 'order-processing', 'user-auth')\n * @param optionsOrFn - Either SpanOptions or the function to wrap\n * @param maybeFn - The function to wrap if options were provided\n * @returns A wrapped function with the same signature that creates spans for inputs and outputs\n */\n withSpan<TArgs extends unknown[], TReturn>(\n traceFunctionKey: string,\n optionsOrFn: SpanOptions | ((...args: TArgs) => TReturn),\n maybeFn?: (...args: TArgs) => TReturn,\n ): (...args: TArgs) => TReturn {\n if (!this.enabled) {\n const fn = typeof optionsOrFn === \"function\" ? optionsOrFn : maybeFn!\n return fn\n }\n\n // Handle overloaded signature\n const options: SpanOptions =\n typeof optionsOrFn === \"function\" ? {} : optionsOrFn\n const fn: (...args: TArgs) => TReturn =\n typeof optionsOrFn === \"function\" ? optionsOrFn : maybeFn!\n const self = this\n\n const wrappedFn = function (this: unknown, ...args: TArgs): TReturn {\n // Defer until AsyncLocalStorage init completes. In Node.js, the\n // dynamic import resolves in one microtask; in browsers, the init\n // resolves immediately to a no-op. The `asyncLocalStorageInitDone`\n // flag prevents an infinite loop when AsyncLocalStorage is\n // unavailable (browsers).\n if (!asyncLocalStorage && !isAsyncStorageInitDone()) {\n return asyncLocalStorageReady.then(() =>\n wrappedFn.apply(this, args),\n ) as unknown as TReturn\n }\n\n // Get current span stack to determine trace context\n const currentStack = getSpanStack()\n const parentContext = currentStack[currentStack.length - 1]\n\n // Generate trace ID (new if root, inherit if nested)\n const traceId = parentContext?.traceId ?? crypto.randomUUID()\n const spanId = crypto.randomUUID()\n const parentSpanId = parentContext?.spanId ?? null\n const isRootSpan = parentSpanId === null\n\n // Create new context for this span with empty contexts array\n const newContext: SpanContext = { traceId, spanId, contexts: [] }\n const newStack = [...currentStack, newContext]\n\n // Capture inputs and start time\n const inputs = args\n const startedAt = new Date().toISOString()\n\n // Register trace state for root spans\n if (isRootSpan && !activeTraceStates.has(traceId)) {\n activeTraceStates.set(traceId, {\n traceId,\n startedAt,\n contexts: [],\n })\n pendingSpanPromises.set(traceId, [])\n }\n\n // Shared span parameters\n const functionName = fn.name !== \"\" ? fn.name : undefined\n const baseSpanParams = {\n traceFunctionKey,\n functionName,\n spanName: options.name ?? functionName ?? traceFunctionKey,\n traceId,\n spanId,\n parentSpanId,\n inputs,\n startedAt,\n spanType: options.type ?? \"custom\",\n }\n\n // Helper to send span and (for root spans) await all pending spans\n // before sending the trace completion signal.\n // Wrapped in try/catch so span errors never crash the host app.\n const sendSpan = async (params: { result: unknown; error?: string }) => {\n try {\n const endedAt = new Date().toISOString()\n const replayCtx = getReplayContext()\n const spanPromise = self.sendWrapperSpan({\n ...baseSpanParams,\n ...params,\n contexts: newContext.contexts,\n prompt: newContext.prompt,\n endedAt,\n ...(replayCtx?.testRunId && { testRunId: replayCtx.testRunId }),\n ...(replayCtx?.inputSourceSpanId && {\n inputSourceSpanId: replayCtx.inputSourceSpanId,\n }),\n })\n\n // For root spans, await all pending span requests then send trace completion\n if (isRootSpan) {\n const pending = pendingSpanPromises.get(traceId) ?? []\n pending.push(spanPromise)\n await Promise.race([\n Promise.allSettled(pending),\n new Promise((resolve) => setTimeout(resolve, 5000)),\n ])\n pendingSpanPromises.delete(traceId)\n\n const traceState = activeTraceStates.get(traceId)\n self.sendTraceCompletion({\n traceFunctionKey,\n traceId,\n startedAt: traceState?.startedAt ?? startedAt,\n endedAt,\n sessionId: traceState?.sessionId,\n metadata: traceState?.metadata,\n contexts: traceState?.contexts ?? [],\n })\n activeTraceStates.delete(traceId)\n } else {\n // Non-root spans: track the promise for the root to await later\n const pending = pendingSpanPromises.get(traceId)\n if (pending) {\n pending.push(spanPromise)\n } else {\n pendingSpanPromises.set(traceId, [spanPromise])\n }\n }\n } catch {\n // Silently ignore — user's result/exception takes priority\n }\n }\n\n // Execute function within new span context\n const executeWithContext = (): TReturn => {\n const result = fn(...args)\n\n // Check if result is a Promise (async function)\n if (result instanceof Promise) {\n return result\n .then((resolvedResult) => {\n void sendSpan({ result: resolvedResult })\n return resolvedResult\n })\n .catch((error: unknown) => {\n void sendSpan({\n result: undefined,\n error: error instanceof Error ? error.message : String(error),\n })\n throw error\n }) as TReturn\n }\n\n // Sync function - create span in background\n void sendSpan({ result })\n return result\n }\n\n return runWithSpanStack(newStack, executeWithContext)\n }\n return wrappedFn\n }\n\n /**\n * Get a function wrapper for a specific trace function key.\n *\n * This provides a fluent API alternative to calling withSpan directly,\n * allowing you to bind the traceFunctionKey once and wrap multiple functions.\n *\n * Example usage:\n * ```typescript\n * const client = new Bitfab({ apiKey: 'your-api-key' });\n *\n * const orderFunc = client.getFunction('order-processing');\n * const tracedProcessOrder = orderFunc.withSpan(processOrder);\n * const tracedValidateOrder = orderFunc.withSpan(validateOrder);\n * ```\n *\n * @param traceFunctionKey - A string identifier for grouping spans\n * @returns A BitfabFunction instance for wrapping functions\n */\n getFunction(traceFunctionKey: string): BitfabFunction {\n return new BitfabFunction(this, traceFunctionKey)\n }\n\n /**\n * Send trace completion when a root span ends.\n * Internal method to record trace completion with end time.\n * Fire-and-forget - sends to externalTraces endpoint via httpClient.\n */\n private sendTraceCompletion(params: {\n traceFunctionKey: string\n traceId: string\n startedAt: string\n endedAt: string\n sessionId?: string\n metadata?: Record<string, unknown>\n contexts?: ContextEntry[]\n }): void {\n // Build the raw trace object for the externalTraces endpoint\n const rawTrace: Record<string, unknown> = {\n id: params.traceId,\n started_at: params.startedAt,\n ended_at: params.endedAt,\n workflow_name: params.traceFunctionKey,\n }\n\n // Add optional fields to rawData\n if (params.metadata && Object.keys(params.metadata).length > 0) {\n rawTrace.metadata = params.metadata\n }\n if (params.contexts && params.contexts.length > 0) {\n rawTrace.contexts = params.contexts\n }\n\n this.httpClient.sendExternalTrace({\n type: \"sdk-function\",\n source: \"typescript-sdk-function\",\n traceFunctionKey: params.traceFunctionKey,\n externalTrace: rawTrace,\n completed: true,\n ...(params.sessionId && { sessionId: params.sessionId }),\n })\n }\n\n /**\n * Send a wrapper span from function execution.\n * Internal method to record spans when using withSpan.\n * Fire-and-forget - sends to externalSpans endpoint via httpClient.\n */\n private sendWrapperSpan(params: {\n traceFunctionKey: string\n functionName?: string\n spanName: string\n traceId: string\n spanId: string\n parentSpanId: string | null\n inputs?: unknown[]\n result: unknown\n error?: string\n startedAt: string\n endedAt: string\n spanType: SpanType\n contexts?: ContextEntry[]\n prompt?: string\n testRunId?: string\n inputSourceSpanId?: string\n }): Promise<unknown> {\n // Serialize inputs and result with superjson for type preservation\n const serializedInputs = serializeValue(params.inputs)\n const serializedResult = serializeValue(params.result)\n\n // Format as an external span with the wrapper format\n const externalSpan: Record<string, unknown> = {\n id: params.spanId,\n trace_id: params.traceId,\n started_at: params.startedAt,\n ended_at: params.endedAt,\n span_data: {\n name: params.spanName,\n type: params.spanType,\n input: serializedInputs.json,\n output: serializedResult.json,\n // Include superjson meta for type preservation\n ...(serializedInputs.meta !== undefined && {\n input_meta: serializedInputs.meta,\n }),\n ...(serializedResult.meta !== undefined && {\n output_meta: serializedResult.meta,\n }),\n ...(params.functionName !== undefined && {\n function_name: params.functionName,\n }),\n ...(params.error !== undefined && { error: params.error }),\n ...(params.contexts &&\n params.contexts.length > 0 && {\n contexts: params.contexts,\n }),\n ...(params.prompt !== undefined && { prompt: params.prompt }),\n },\n }\n\n // Add parent_id for nested spans\n if (params.parentSpanId) {\n externalSpan.parent_id = params.parentSpanId\n }\n if (params.inputSourceSpanId) {\n externalSpan.input_source_span_id = params.inputSourceSpanId\n }\n\n return this.httpClient.sendExternalSpan({\n type: \"sdk-function\",\n source: \"typescript-sdk-function\",\n sourceTraceId: params.traceId,\n traceFunctionKey: params.traceFunctionKey,\n rawSpan: externalSpan,\n ...(params.testRunId && { testRunId: params.testRunId }),\n })\n }\n\n /**\n * Replay historical traces through a function and create a test run.\n *\n * Fetches the last N traces for the given trace function key, re-runs each\n * through the provided function, and returns comparison data.\n *\n * The function must have been wrapped with `withSpan` — replay injects\n * `testRunId` via async context so new spans are linked to the test run.\n *\n * @param traceFunctionKey - The trace function key to replay\n * @param fn - The function to replay (must be the return value of `withSpan`)\n * @param options - Optional replay options (limit, traceIds)\n * @returns ReplayResult with items, testRunId, and testRunUrl\n */\n async replay<TReturn>(\n traceFunctionKey: string,\n // biome-ignore lint/suspicious/noExplicitAny: replay deserializes inputs from historical data — typed args would be incorrect\n fn: (...args: any[]) => TReturn | Promise<TReturn>,\n options?: { limit?: number; traceIds?: string[]; maxConcurrency?: number },\n ): Promise<{\n items: Array<{\n input: unknown[]\n result: TReturn | undefined\n originalOutput: unknown\n error: string | null\n }>\n testRunId: string\n testRunUrl: string\n }> {\n const { replay: doReplay } = await import(\"./replay.js\")\n return doReplay(\n this.httpClient,\n this.serviceUrl,\n traceFunctionKey,\n fn,\n options,\n )\n }\n}\n\n/**\n * Represents a Bitfab function that can wrap user functions for tracing.\n *\n * This provides a fluent API for binding a traceFunctionKey once and\n * then wrapping multiple functions with that key.\n *\n * Example usage:\n * ```typescript\n * const client = new Bitfab({ apiKey: 'your-api-key' });\n *\n * const orderFunc = client.getFunction('order-processing');\n * const tracedProcessOrder = orderFunc.withSpan(processOrder);\n * const tracedValidateOrder = orderFunc.withSpan(validateOrder);\n * ```\n */\nexport class BitfabFunction {\n constructor(\n private readonly client: Bitfab,\n private readonly traceFunctionKey: string,\n ) {}\n\n /**\n * Wrap a function to automatically create a span for its inputs and outputs.\n *\n * The wrapped function behaves identically to the original, but sends\n * span data to Bitfab in the background after each call.\n *\n * Example usage:\n * ```typescript\n * const orderFunc = client.getFunction('order-processing');\n *\n * // Basic usage (defaults to \"custom\" span type)\n * const tracedProcessOrder = orderFunc.withSpan(processOrder);\n *\n * // With explicit span type\n * const tracedProcessOrder = orderFunc.withSpan({ type: 'function' }, processOrder);\n * ```\n *\n * @param optionsOrFn - Either SpanOptions or the function to wrap\n * @param maybeFn - The function to wrap if options were provided\n * @returns A wrapped function with the same signature that creates spans\n */\n withSpan<TArgs extends unknown[], TReturn>(\n optionsOrFn: SpanOptions | ((...args: TArgs) => TReturn),\n maybeFn?: (...args: TArgs) => TReturn,\n ): (...args: TArgs) => TReturn {\n // Handle overloaded signature\n const options: SpanOptions =\n typeof optionsOrFn === \"function\" ? {} : optionsOrFn\n const fn: (...args: TArgs) => TReturn =\n typeof optionsOrFn === \"function\" ? optionsOrFn : maybeFn!\n\n return this.client.withSpan(this.traceFunctionKey, options, fn)\n }\n\n /**\n * Wrap a BAML client method to automatically capture prompt and LLM metadata.\n * Delegates to the parent client's wrapBAML method.\n *\n * @param methodOrClient - Either a BAML method (uses constructor bamlClient) or the BAML client instance\n * @param maybeMethodOrOptions - The BAML method when the first argument is a client, or WrapBAMLOptions when the first argument is the method\n * @param maybeOptions - WrapBAMLOptions when using the two-argument (client, method) form\n * @returns An async function with the same signature that instruments the BAML call\n */\n wrapBAML<TArgs extends unknown[], TReturn>(\n methodOrClient: unknown,\n maybeMethodOrOptions?:\n | ((...args: TArgs) => Promise<TReturn>)\n | WrapBAMLOptions,\n maybeOptions?: WrapBAMLOptions,\n ): WrappedBamlFn<TArgs, TReturn> {\n return this.client.wrapBAML(\n methodOrClient,\n maybeMethodOrOptions,\n maybeOptions,\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;AAOA,IAAI,aAAgC;AAEpC,eAAe,WAAgC;AAC7C,MAAI,YAAY;AACd,WAAO;AAAA,EACT;AACA,MAAI;AACF,iBAAa,MAAM,OAAO,kBAAkB;AAC5C,WAAO;AAAA,EACT,QAAQ;AACN,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;AA2BA,SAAS,WAAW,KAAqB;AACvC,SAAO,IAAI,OAAO,CAAC,EAAE,YAAY,IAAI,IAAI,MAAM,CAAC;AAClD;AAMA,SAAS,eAAe,UAA0B;AAChD,QAAM,cAAsC;AAAA,IAC1C,QAAQ;AAAA,IACR,WAAW;AAAA,IACX,QAAQ;AAAA,EACV;AACA,SAAO,YAAY,QAAQ,KAAK,WAAW,QAAQ;AACrD;AAMA,SAAS,YAAY,OAAuB;AAC1C,SAAO,MACJ,QAAQ,SAAS,KAAK,EACtB,QAAQ,OAAO,GAAG,EAClB,QAAQ,MAAM,GAAG;AACtB;AAMO,SAAS,cAAc,UAAkB,OAAuB;AACrE,SAAO,GAAG,eAAe,QAAQ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AAI,OAAO,aAAa,EAAE,WAAW,OAAO,UAAU;AAAA,IACxD,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBA,MAAM,OACJ,kBAEA,IACA,SAUC;AACD,UAAM,EAAE,QAAQ,SAAS,IAAI,MAAM,OAAO,sBAAa;AACvD,WAAO;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAiBO,IAAM,iBAAN,MAAqB;AAAA,EAC1B,YACmB,QACA,kBACjB;AAFiB;AACA;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuBH,SACE,aACA,SAC6B;AAE7B,UAAM,UACJ,OAAO,gBAAgB,aAAa,CAAC,IAAI;AAC3C,UAAM,KACJ,OAAO,gBAAgB,aAAa,cAAc;AAEpD,WAAO,KAAK,OAAO,SAAS,KAAK,kBAAkB,SAAS,EAAE;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,SACE,gBACA,sBAGA,cAC+B;AAC/B,WAAO,KAAK,OAAO;AAAA,MACjB;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;","names":["fn"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/replay.ts"],"sourcesContent":["/**\n * Replay historical traces through a function and create a test run.\n *\n * The replay flow has three phases:\n * 1. Start — fetches historical traces from the server and creates a test run\n * 2. Execute — re-runs each trace's inputs through the provided function locally\n * 3. Complete — marks the test run as completed on the server\n */\n\nimport type { HttpClient } from \"./http.js\"\nimport { flushTraces } from \"./http.js\"\nimport { replayContextReady, runWithReplayContext } from \"./replayContext.js\"\nimport { deserializeValue } from \"./serialize.js\"\n\nexport interface ReplayOptions {\n /** Maximum number of traces to replay (1–100, default 5). */\n limit?: number\n /** Optional list of specific trace IDs to replay. */\n traceIds?: string[]\n /** Maximum number of items to process in parallel. Set to 1 for sequential. Default 10. */\n maxConcurrency?: number\n}\n\nexport interface ReplayItem<T> {\n /** Deserialized inputs from the original trace. */\n input: unknown[]\n /** The result returned by the function during replay, or undefined on error. */\n result: T | undefined\n /** The original output from the historical trace. */\n originalOutput: unknown\n /** Error message if the function threw, or null on success. */\n error: string | null\n}\n\nexport interface ReplayResult<T> {\n /** Individual replay items with inputs, results, and comparison data. */\n items: ReplayItem<T>[]\n /** The test run ID created on the server. */\n testRunId: string\n /** Full URL to view the test run in the dashboard. */\n testRunUrl: string\n}\n\n/**\n * Deserialize inputs from a historical span's rawData.\n *\n * Prefers superjson-serialized `input_meta` for type preservation,\n * falls back to the raw `input` field.\n */\nfunction deserializeInputs(spanData: Record<string, unknown>): unknown[] {\n const inputMeta = spanData.input_meta as unknown\n const rawInput = spanData.input\n\n // If superjson meta is available, deserialize with type reconstruction\n if (inputMeta !== undefined && inputMeta !== null) {\n const deserialized = deserializeValue({ json: rawInput, meta: inputMeta })\n if (Array.isArray(deserialized)) {\n return deserialized\n }\n return deserialized !== undefined && deserialized !== null\n ? [deserialized]\n : []\n }\n\n // Fall back to raw input\n if (Array.isArray(rawInput)) {\n return rawInput\n }\n return rawInput !== undefined && rawInput !== null ? [rawInput] : []\n}\n\n/**\n * Deserialize the original output from a historical span's rawData.\n */\nfunction deserializeOutput(spanData: Record<string, unknown>): unknown {\n const outputMeta = spanData.output_meta as unknown\n const rawOutput = spanData.output\n\n if (outputMeta !== undefined && outputMeta !== null) {\n return deserializeValue({ json: rawOutput, meta: outputMeta })\n }\n\n return rawOutput\n}\n\n/**\n * Execute a single replay item: fetch span data, deserialize inputs, call\n * the function within a replay context that injects testRunId into new spans.\n */\nasync function processItem<TReturn>(\n httpClient: HttpClient,\n serverItem: { externalSpanId: string },\n // biome-ignore lint/suspicious/noExplicitAny: replay deserializes inputs from historical data\n fn: (...args: any[]) => TReturn | Promise<TReturn>,\n testRunId: string,\n): Promise<ReplayItem<TReturn>> {\n const span = await httpClient.getExternalSpan(serverItem.externalSpanId)\n const spanData = (span.rawData?.span_data ?? {}) as Record<string, unknown>\n\n const inputs = deserializeInputs(spanData)\n const originalOutput = deserializeOutput(spanData)\n\n let result: TReturn | undefined\n let error: string | null = null\n\n try {\n const maybePromise = runWithReplayContext(\n { testRunId, inputSourceSpanId: span.id },\n () => fn(...inputs),\n )\n result = maybePromise instanceof Promise ? await maybePromise : maybePromise\n } catch (e) {\n error = e instanceof Error ? e.message : String(e)\n }\n\n return { input: inputs, result, originalOutput, error }\n}\n\n/**\n * Run async tasks with a concurrency limit.\n * Each task factory is called when a slot opens; results preserve input order.\n */\nasync function mapWithConcurrency<T>(\n tasks: Array<() => Promise<T>>,\n maxConcurrency: number,\n): Promise<T[]> {\n const results: T[] = new Array(tasks.length)\n let nextIndex = 0\n\n async function worker(): Promise<void> {\n while (nextIndex < tasks.length) {\n const index = nextIndex++\n results[index] = await tasks[index]()\n }\n }\n\n const workers = Array.from(\n { length: Math.min(maxConcurrency, tasks.length) },\n () => worker(),\n )\n await Promise.all(workers)\n return results\n}\n\n/**\n * Replay historical traces through a function and create a test run.\n *\n * @internal Called by Bitfab.replay — not part of the public API.\n */\nexport async function replay<TReturn>(\n httpClient: HttpClient,\n serviceUrl: string,\n traceFunctionKey: string,\n // biome-ignore lint/suspicious/noExplicitAny: replay deserializes inputs from historical data\n fn: (...args: any[]) => TReturn | Promise<TReturn>,\n options?: ReplayOptions,\n): Promise<ReplayResult<TReturn>> {\n await replayContextReady\n\n const {\n testRunId,\n testRunUrl,\n items: serverItems,\n } = await httpClient.startReplay(\n traceFunctionKey,\n options?.limit ?? 5,\n options?.traceIds,\n )\n\n const maxConcurrency = options?.maxConcurrency ?? 10\n\n const tasks = serverItems.map(\n (serverItem) => () => processItem(httpClient, serverItem, fn, testRunId),\n )\n const resultItems = await mapWithConcurrency(tasks, maxConcurrency)\n\n await flushTraces()\n\n try {\n await httpClient.completeReplay(testRunId)\n } catch (e) {\n try {\n console.error(\"Bitfab: Failed to complete replay:\", e)\n } catch {\n // Never crash the host app\n }\n }\n\n return {\n items: resultItems,\n testRunId,\n testRunUrl: `${serviceUrl}${testRunUrl}`,\n }\n}\n"],"mappings":";;;;;;;;AAiDA,SAAS,kBAAkB,UAA8C;AACvE,QAAM,YAAY,SAAS;AAC3B,QAAM,WAAW,SAAS;AAG1B,MAAI,cAAc,UAAa,cAAc,MAAM;AACjD,UAAM,eAAe,iBAAiB,EAAE,MAAM,UAAU,MAAM,UAAU,CAAC;AACzE,QAAI,MAAM,QAAQ,YAAY,GAAG;AAC/B,aAAO;AAAA,IACT;AACA,WAAO,iBAAiB,UAAa,iBAAiB,OAClD,CAAC,YAAY,IACb,CAAC;AAAA,EACP;AAGA,MAAI,MAAM,QAAQ,QAAQ,GAAG;AAC3B,WAAO;AAAA,EACT;AACA,SAAO,aAAa,UAAa,aAAa,OAAO,CAAC,QAAQ,IAAI,CAAC;AACrE;AAKA,SAAS,kBAAkB,UAA4C;AACrE,QAAM,aAAa,SAAS;AAC5B,QAAM,YAAY,SAAS;AAE3B,MAAI,eAAe,UAAa,eAAe,MAAM;AACnD,WAAO,iBAAiB,EAAE,MAAM,WAAW,MAAM,WAAW,CAAC;AAAA,EAC/D;AAEA,SAAO;AACT;AAMA,eAAe,YACb,YACA,YAEA,IACA,WAC8B;AAC9B,QAAM,OAAO,MAAM,WAAW,gBAAgB,WAAW,cAAc;AACvE,QAAM,WAAY,KAAK,SAAS,aAAa,CAAC;AAE9C,QAAM,SAAS,kBAAkB,QAAQ;AACzC,QAAM,iBAAiB,kBAAkB,QAAQ;AAEjD,MAAI;AACJ,MAAI,QAAuB;AAE3B,MAAI;AACF,UAAM,eAAe;AAAA,MACnB,EAAE,WAAW,mBAAmB,KAAK,GAAG;AAAA,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