bitfab 0.43.1 → 0.44.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -98,6 +98,9 @@ declare class BitfabError extends Error {
98
98
  */
99
99
  retryAfterMs?: number | undefined);
100
100
  }
101
+ declare class MixedTracingError extends Error {
102
+ constructor(message: string);
103
+ }
101
104
 
102
105
  /**
103
106
  * Selective mock overrides for replay.
@@ -644,6 +647,32 @@ interface TokenUsage {
644
647
  cached: number | null;
645
648
  total: number | null;
646
649
  }
650
+ interface TraceOutlineSpanError {
651
+ source: string;
652
+ error: string;
653
+ step?: string;
654
+ }
655
+ interface TraceOutlineSpan {
656
+ spanId: string;
657
+ name: string | null;
658
+ type: string;
659
+ traceFunctionKey: string | null;
660
+ durationMs: number | null;
661
+ tokens: TokenUsage | null;
662
+ model: string | null;
663
+ errors: TraceOutlineSpanError[] | null;
664
+ mocked: boolean;
665
+ children: TraceOutlineSpan[];
666
+ }
667
+ interface TraceOutline {
668
+ traceId: string;
669
+ name: string | null;
670
+ status: string;
671
+ traceFunctionKey: string | null;
672
+ durationMs: number | null;
673
+ spanCount: number;
674
+ spans: TraceOutlineSpan[];
675
+ }
647
676
  /**
648
677
  * Describes a single file edited as part of a code change.
649
678
  *
@@ -743,6 +772,8 @@ interface CompleteReplayResponse {
743
772
  * `ReplayItem.tokens`. Absent on servers that predate this field.
744
773
  */
745
774
  tokens?: Record<string, TokenUsage | null>;
775
+ traceOutlines?: Record<string, TraceOutline>;
776
+ originalTraceOutlines?: Record<string, TraceOutline>;
746
777
  /**
747
778
  * Number of traces the server has persisted for this test run at
748
779
  * completion time. Lets the SDK distinguish "uploads failed" from
@@ -1690,6 +1721,8 @@ interface ReplayProgressItem {
1690
1721
  model?: string | null;
1691
1722
  dbSnapshotRef?: DbSnapshotRef | null;
1692
1723
  dbBranchTimings?: DbBranchTimings | null;
1724
+ traceOutline?: TraceOutline | null;
1725
+ originalTraceOutline?: TraceOutline | null;
1693
1726
  }
1694
1727
  /**
1695
1728
  * @deprecated Use {@link ReplayItemFinishProgress}. This legacy shape also
@@ -1841,6 +1874,8 @@ interface ReplayItem<T> {
1841
1874
  * no snapshot ref, or against a server that predates timings.
1842
1875
  */
1843
1876
  dbBranchTimings: DbBranchTimings | null;
1877
+ traceOutline: TraceOutline | null;
1878
+ originalTraceOutline: TraceOutline | null;
1844
1879
  }
1845
1880
 
1846
1881
  interface ReplayResult<T> {
@@ -2096,6 +2131,7 @@ declare class BitfabOpenAITracingProcessor implements TracingProcessor {
2096
2131
  }
2097
2132
 
2098
2133
  type CaptureSurface = "opt-in" | "opt-out";
2134
+
2099
2135
  /**
2100
2136
  * Options for wrapBAML.
2101
2137
  */
@@ -3078,7 +3114,7 @@ declare class BitfabFunction {
3078
3114
  /**
3079
3115
  * SDK version from package.json (injected at build time)
3080
3116
  */
3081
- declare const __version__ = "0.43.1";
3117
+ declare const __version__ = "0.44.1";
3082
3118
 
3083
3119
  /**
3084
3120
  * Constants for the Bitfab SDK.
@@ -3208,4 +3244,4 @@ declare function seedFromRegistry(registry: ReplayRegistry, pipeline: string, ca
3208
3244
  run?: boolean;
3209
3245
  }): Promise<SeedResult>;
3210
3246
 
3211
- export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AddDatasetGradersResult, type AddDatasetTracesResult, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, BitfabLangGraphIntegration, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CaptureSurface, type CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type Dataset, type DatasetGraderRef, type DatasetTraceIds, DatasetsClient, type DbBranchOptions, DbBranchReplayError, type DbBranchTimings, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type GraderRerun, type GraderRerunProgress, type GraderRerunResult, type GraderRerunStatus, HttpClient, type LangGraphIntegrationOptions, type ListDatasetsParams, type MockOverride, type MockOverrideCtx, type MockOverrideInput, type MockOverrideResolver, type MockStrategy, type MockValue, NO_MOCK_OVERRIDE, type NodeMatcher, type NodeMethodDecorator, type NodeOptions, type ProviderDefinition, type RemoveDatasetGradersResult, type RemoveDatasetTracesResult, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayOptionsFactory, type ReplayProgress, type ReplayProgressItem, type ReplayRegistration, type ReplayRegistry, type ReplayRegistryContext, type ReplayRegistryOptions, type ReplayResult, type RerunGradersOptions, type RerunGradersResult, SUPPORTED_PROVIDERS, type SaveDatasetParams, type SaveDatasetResult, type SeedCase, type SeedCaseOptions, type SeedResult, type SeedRunOptions, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceIngestionType, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, defineReplayRegistry, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, seedFromRegistry, serializeReplayResult };
3247
+ export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AddDatasetGradersResult, type AddDatasetTracesResult, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, BitfabLangGraphIntegration, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CaptureSurface, type CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type Dataset, type DatasetGraderRef, type DatasetTraceIds, DatasetsClient, type DbBranchOptions, DbBranchReplayError, type DbBranchTimings, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type GraderRerun, type GraderRerunProgress, type GraderRerunResult, type GraderRerunStatus, HttpClient, type LangGraphIntegrationOptions, type ListDatasetsParams, MixedTracingError, type MockOverride, type MockOverrideCtx, type MockOverrideInput, type MockOverrideResolver, type MockStrategy, type MockValue, NO_MOCK_OVERRIDE, type NodeMatcher, type NodeMethodDecorator, type NodeOptions, type ProviderDefinition, type RemoveDatasetGradersResult, type RemoveDatasetTracesResult, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayOptionsFactory, type ReplayProgress, type ReplayProgressItem, type ReplayRegistration, type ReplayRegistry, type ReplayRegistryContext, type ReplayRegistryOptions, type ReplayResult, type RerunGradersOptions, type RerunGradersResult, SUPPORTED_PROVIDERS, type SaveDatasetParams, type SaveDatasetResult, type SeedCase, type SeedCaseOptions, type SeedResult, type SeedRunOptions, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceIngestionType, type TraceOutline, type TraceOutlineSpan, type TraceOutlineSpanError, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, defineReplayRegistry, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, seedFromRegistry, serializeReplayResult };
package/dist/index.d.ts CHANGED
@@ -98,6 +98,9 @@ declare class BitfabError extends Error {
98
98
  */
99
99
  retryAfterMs?: number | undefined);
100
100
  }
101
+ declare class MixedTracingError extends Error {
102
+ constructor(message: string);
103
+ }
101
104
 
102
105
  /**
103
106
  * Selective mock overrides for replay.
@@ -644,6 +647,32 @@ interface TokenUsage {
644
647
  cached: number | null;
645
648
  total: number | null;
646
649
  }
650
+ interface TraceOutlineSpanError {
651
+ source: string;
652
+ error: string;
653
+ step?: string;
654
+ }
655
+ interface TraceOutlineSpan {
656
+ spanId: string;
657
+ name: string | null;
658
+ type: string;
659
+ traceFunctionKey: string | null;
660
+ durationMs: number | null;
661
+ tokens: TokenUsage | null;
662
+ model: string | null;
663
+ errors: TraceOutlineSpanError[] | null;
664
+ mocked: boolean;
665
+ children: TraceOutlineSpan[];
666
+ }
667
+ interface TraceOutline {
668
+ traceId: string;
669
+ name: string | null;
670
+ status: string;
671
+ traceFunctionKey: string | null;
672
+ durationMs: number | null;
673
+ spanCount: number;
674
+ spans: TraceOutlineSpan[];
675
+ }
647
676
  /**
648
677
  * Describes a single file edited as part of a code change.
649
678
  *
@@ -743,6 +772,8 @@ interface CompleteReplayResponse {
743
772
  * `ReplayItem.tokens`. Absent on servers that predate this field.
744
773
  */
745
774
  tokens?: Record<string, TokenUsage | null>;
775
+ traceOutlines?: Record<string, TraceOutline>;
776
+ originalTraceOutlines?: Record<string, TraceOutline>;
746
777
  /**
747
778
  * Number of traces the server has persisted for this test run at
748
779
  * completion time. Lets the SDK distinguish "uploads failed" from
@@ -1690,6 +1721,8 @@ interface ReplayProgressItem {
1690
1721
  model?: string | null;
1691
1722
  dbSnapshotRef?: DbSnapshotRef | null;
1692
1723
  dbBranchTimings?: DbBranchTimings | null;
1724
+ traceOutline?: TraceOutline | null;
1725
+ originalTraceOutline?: TraceOutline | null;
1693
1726
  }
1694
1727
  /**
1695
1728
  * @deprecated Use {@link ReplayItemFinishProgress}. This legacy shape also
@@ -1841,6 +1874,8 @@ interface ReplayItem<T> {
1841
1874
  * no snapshot ref, or against a server that predates timings.
1842
1875
  */
1843
1876
  dbBranchTimings: DbBranchTimings | null;
1877
+ traceOutline: TraceOutline | null;
1878
+ originalTraceOutline: TraceOutline | null;
1844
1879
  }
1845
1880
 
1846
1881
  interface ReplayResult<T> {
@@ -2096,6 +2131,7 @@ declare class BitfabOpenAITracingProcessor implements TracingProcessor {
2096
2131
  }
2097
2132
 
2098
2133
  type CaptureSurface = "opt-in" | "opt-out";
2134
+
2099
2135
  /**
2100
2136
  * Options for wrapBAML.
2101
2137
  */
@@ -3078,7 +3114,7 @@ declare class BitfabFunction {
3078
3114
  /**
3079
3115
  * SDK version from package.json (injected at build time)
3080
3116
  */
3081
- declare const __version__ = "0.43.1";
3117
+ declare const __version__ = "0.44.1";
3082
3118
 
3083
3119
  /**
3084
3120
  * Constants for the Bitfab SDK.
@@ -3208,4 +3244,4 @@ declare function seedFromRegistry(registry: ReplayRegistry, pipeline: string, ca
3208
3244
  run?: boolean;
3209
3245
  }): Promise<SeedResult>;
3210
3246
 
3211
- export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AddDatasetGradersResult, type AddDatasetTracesResult, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, BitfabLangGraphIntegration, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CaptureSurface, type CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type Dataset, type DatasetGraderRef, type DatasetTraceIds, DatasetsClient, type DbBranchOptions, DbBranchReplayError, type DbBranchTimings, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type GraderRerun, type GraderRerunProgress, type GraderRerunResult, type GraderRerunStatus, HttpClient, type LangGraphIntegrationOptions, type ListDatasetsParams, type MockOverride, type MockOverrideCtx, type MockOverrideInput, type MockOverrideResolver, type MockStrategy, type MockValue, NO_MOCK_OVERRIDE, type NodeMatcher, type NodeMethodDecorator, type NodeOptions, type ProviderDefinition, type RemoveDatasetGradersResult, type RemoveDatasetTracesResult, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayOptionsFactory, type ReplayProgress, type ReplayProgressItem, type ReplayRegistration, type ReplayRegistry, type ReplayRegistryContext, type ReplayRegistryOptions, type ReplayResult, type RerunGradersOptions, type RerunGradersResult, SUPPORTED_PROVIDERS, type SaveDatasetParams, type SaveDatasetResult, type SeedCase, type SeedCaseOptions, type SeedResult, type SeedRunOptions, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceIngestionType, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, defineReplayRegistry, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, seedFromRegistry, serializeReplayResult };
3247
+ export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AddDatasetGradersResult, type AddDatasetTracesResult, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, BitfabLangGraphIntegration, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CaptureSurface, type CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type Dataset, type DatasetGraderRef, type DatasetTraceIds, DatasetsClient, type DbBranchOptions, DbBranchReplayError, type DbBranchTimings, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type GraderRerun, type GraderRerunProgress, type GraderRerunResult, type GraderRerunStatus, HttpClient, type LangGraphIntegrationOptions, type ListDatasetsParams, MixedTracingError, type MockOverride, type MockOverrideCtx, type MockOverrideInput, type MockOverrideResolver, type MockStrategy, type MockValue, NO_MOCK_OVERRIDE, type NodeMatcher, type NodeMethodDecorator, type NodeOptions, type ProviderDefinition, type RemoveDatasetGradersResult, type RemoveDatasetTracesResult, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayOptionsFactory, type ReplayProgress, type ReplayProgressItem, type ReplayRegistration, type ReplayRegistry, type ReplayRegistryContext, type ReplayRegistryOptions, type ReplayResult, type RerunGradersOptions, type RerunGradersResult, SUPPORTED_PROVIDERS, type SaveDatasetParams, type SaveDatasetResult, type SeedCase, type SeedCaseOptions, type SeedResult, type SeedRunOptions, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceIngestionType, type TraceOutline, type TraceOutlineSpan, type TraceOutlineSpanError, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, defineReplayRegistry, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, seedFromRegistry, serializeReplayResult };
package/dist/index.js CHANGED
@@ -24,7 +24,7 @@ import {
24
24
  getCurrentSpan,
25
25
  getCurrentTrace,
26
26
  seedFromRegistry
27
- } from "./chunk-NQULKHFJ.js";
27
+ } from "./chunk-BPVYNFCE.js";
28
28
  import "./chunk-ZUD7OFYB.js";
29
29
  import {
30
30
  BITFAB_PROGRESS_PREFIX,
@@ -33,14 +33,15 @@ import {
33
33
  ReplayError,
34
34
  reportReplayProgress,
35
35
  serializeReplayResult
36
- } from "./chunk-M3WVF2H7.js";
36
+ } from "./chunk-PUHN4E2S.js";
37
37
  import {
38
38
  BitfabError,
39
39
  DEFAULT_SERVICE_URL,
40
40
  HttpClient,
41
+ MixedTracingError,
41
42
  __version__,
42
43
  flushTraces
43
- } from "./chunk-QP3ZDSMN.js";
44
+ } from "./chunk-6K7ZEU4B.js";
44
45
  import "./chunk-H6LZRFMN.js";
45
46
  export {
46
47
  BITFAB_PROGRESS_PREFIX,
@@ -58,6 +59,7 @@ export {
58
59
  DatasetsClient,
59
60
  DbBranchReplayError,
60
61
  HttpClient,
62
+ MixedTracingError,
61
63
  NO_MOCK_OVERRIDE,
62
64
  ReplayError,
63
65
  SUPPORTED_PROVIDERS,
package/dist/node.cjs CHANGED
@@ -97,7 +97,7 @@ var __version__, __packageName__;
97
97
  var init_version_generated = __esm({
98
98
  "src/version.generated.ts"() {
99
99
  "use strict";
100
- __version__ = "0.43.1";
100
+ __version__ = "0.44.1";
101
101
  __packageName__ = "bitfab";
102
102
  }
103
103
  });
@@ -219,7 +219,7 @@ var init_compress = __esm({
219
219
  });
220
220
 
221
221
  // src/errors.ts
222
- var BitfabError;
222
+ var BitfabError, MixedTracingError;
223
223
  var init_errors = __esm({
224
224
  "src/errors.ts"() {
225
225
  "use strict";
@@ -232,6 +232,12 @@ var init_errors = __esm({
232
232
  this.name = "BitfabError";
233
233
  }
234
234
  };
235
+ MixedTracingError = class extends Error {
236
+ constructor(message) {
237
+ super(message);
238
+ this.name = "MixedTracingError";
239
+ }
240
+ };
235
241
  }
236
242
  });
237
243
 
@@ -2729,7 +2735,9 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2729
2735
  tokens: null,
2730
2736
  model: serverItem.originalModel ?? serverItem.model ?? null,
2731
2737
  dbSnapshotRef: dbSnapshotRef ?? null,
2732
- dbBranchTimings: dbBranchTimings ?? null
2738
+ dbBranchTimings: dbBranchTimings ?? null,
2739
+ traceOutline: null,
2740
+ originalTraceOutline: null
2733
2741
  };
2734
2742
  }
2735
2743
  try {
@@ -2813,7 +2821,9 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2813
2821
  tokens: null,
2814
2822
  model: originalModel,
2815
2823
  dbSnapshotRef: dbSnapshotRef ?? null,
2816
- dbBranchTimings: dbBranchTimings ?? null
2824
+ dbBranchTimings: dbBranchTimings ?? null,
2825
+ traceOutline: null,
2826
+ originalTraceOutline: null
2817
2827
  };
2818
2828
  }
2819
2829
  async function waitForReplayPersistence(httpClient, testRunId, replayedTraceIds) {
@@ -3068,7 +3078,9 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
3068
3078
  tokens: item.tokens,
3069
3079
  model: item.model,
3070
3080
  dbSnapshotRef: item.dbSnapshotRef,
3071
- dbBranchTimings: item.dbBranchTimings
3081
+ dbBranchTimings: item.dbBranchTimings,
3082
+ traceOutline: item.traceOutline,
3083
+ originalTraceOutline: item.originalTraceOutline
3072
3084
  }
3073
3085
  });
3074
3086
  } catch {
@@ -3148,7 +3160,9 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
3148
3160
  }
3149
3161
  if (mapped !== void 0) {
3150
3162
  item.tokens = replayTokens?.[mapped] ?? null;
3163
+ item.traceOutline = completeResult.traceOutlines?.[mapped] ?? null;
3151
3164
  }
3165
+ item.originalTraceOutline = completeResult.originalTraceOutlines?.[item.originalTraceId] ?? null;
3152
3166
  }
3153
3167
  if (completedCount > 0 && missing.length === completedCount) {
3154
3168
  const serverCount = completeResult.traceCount !== void 0 ? ` The server persisted ${completeResult.traceCount} trace(s) for this run.` : "";
@@ -3271,6 +3285,7 @@ __export(node_exports, {
3271
3285
  DatasetsClient: () => DatasetsClient,
3272
3286
  DbBranchReplayError: () => DbBranchReplayError,
3273
3287
  HttpClient: () => HttpClient,
3288
+ MixedTracingError: () => MixedTracingError,
3274
3289
  NO_MOCK_OVERRIDE: () => NO_MOCK_OVERRIDE,
3275
3290
  ReplayError: () => ReplayError,
3276
3291
  SUPPORTED_PROVIDERS: () => SUPPORTED_PROVIDERS,
@@ -4351,6 +4366,50 @@ async function runFunctionWithBaml(bamlSource, inputs, providers, envVars) {
4351
4366
  };
4352
4367
  }
4353
4368
 
4369
+ // src/captureSurface.ts
4370
+ init_errors();
4371
+ var DEFAULT_SURFACE = "opt-in";
4372
+ var SURFACE_API = {
4373
+ "opt-in": "withSpan()",
4374
+ "opt-out": "withTrace()"
4375
+ };
4376
+ var MIXED_SURFACE_REMEDY = {
4377
+ "opt-in": "Inside a withTrace/trace subtree, configure a discovered call with node()/withNode() instead, or trace this workflow with withSpan() only.",
4378
+ "opt-out": "Wrap the caller with withTrace()/trace() as well, or wrap this function with withSpan()."
4379
+ };
4380
+ function resolveSurface(requested, parentSurface) {
4381
+ if (requested === "neutral") {
4382
+ return void 0;
4383
+ }
4384
+ if (requested === "inherit") {
4385
+ return parentSurface ?? DEFAULT_SURFACE;
4386
+ }
4387
+ return requested;
4388
+ }
4389
+ function mixedTracingError(enteredApi, entered, enclosing, traceFunctionKey) {
4390
+ const subject = traceFunctionKey === void 0 ? "" : ` for "${traceFunctionKey}"`;
4391
+ return new MixedTracingError(
4392
+ `opt-in and opt-out tracing can't be mixed in one call stack: ${enteredApi} (${entered})${subject} was entered inside a ${SURFACE_API[enclosing]} call (${enclosing}). ${MIXED_SURFACE_REMEDY[entered]}`
4393
+ );
4394
+ }
4395
+ function assertSurfacesCompatible(requested, resolved, parentSurface, traceFunctionKey) {
4396
+ if (requested === "inherit" || requested === "neutral") {
4397
+ return;
4398
+ }
4399
+ if (resolved === void 0 || parentSurface === void 0) {
4400
+ return;
4401
+ }
4402
+ if (parentSurface === resolved) {
4403
+ return;
4404
+ }
4405
+ throw mixedTracingError(
4406
+ SURFACE_API[resolved],
4407
+ resolved,
4408
+ parentSurface,
4409
+ traceFunctionKey
4410
+ );
4411
+ }
4412
+
4354
4413
  // src/client.ts
4355
4414
  init_constants();
4356
4415
 
@@ -4497,6 +4556,7 @@ function buildSnapshotRef(config, sdkWallClockBeforeFn) {
4497
4556
  }
4498
4557
 
4499
4558
  // src/client.ts
4559
+ init_errors();
4500
4560
  init_http();
4501
4561
 
4502
4562
  // src/langgraph.ts
@@ -5886,18 +5946,6 @@ var BitfabVercelAiHandler = class {
5886
5946
 
5887
5947
  // src/client.ts
5888
5948
  init_warnOnce();
5889
- var MIXED_SURFACE_REMEDY = {
5890
- "opt-in": "Inside a withTrace/trace subtree, configure a discovered call with node()/withNode() instead, or trace this workflow with withSpan() only.",
5891
- "opt-out": "Wrap the caller with withTrace()/trace() as well, or wrap this function with withSpan()."
5892
- };
5893
- function warnMixedTracingSurfaces(traceFunctionKey, entered, enclosing) {
5894
- const enteredApi = entered === "opt-in" ? "withSpan()" : "withTrace()";
5895
- const enclosingApi = enclosing === "opt-in" ? "withSpan()" : "withTrace()";
5896
- warnOnce(
5897
- `mixed-tracing-surface:${traceFunctionKey}:${entered}`,
5898
- `opt-in and opt-out tracing are mixed in one call stack: ${enteredApi} (${entered}) for "${traceFunctionKey}" was entered inside a ${enclosingApi} call (${enclosing}). Both are recorded, and the spans nest as written. ${MIXED_SURFACE_REMEDY[entered]}`
5899
- );
5900
- }
5901
5949
  var activeTraceStates = /* @__PURE__ */ new Map();
5902
5950
  var asyncLocalStorage = null;
5903
5951
  var SPAN_CONTEXT_STORAGE_SYMBOL = /* @__PURE__ */ Symbol.for("bitfab.spanContextStorage");
@@ -5927,6 +5975,10 @@ function getSpanStack() {
5927
5975
  }
5928
5976
  return browserSpanStack;
5929
5977
  }
5978
+ function enclosingSurface() {
5979
+ const stack = getSpanStack();
5980
+ return stack[stack.length - 1]?.surface;
5981
+ }
5930
5982
  function runWithSpanStack(stack, fn) {
5931
5983
  if (asyncLocalStorage) {
5932
5984
  return asyncLocalStorage.run(stack, fn);
@@ -6413,6 +6465,9 @@ var Bitfab = class {
6413
6465
  const nodeConfiguration = { ...configuration, functionName };
6414
6466
  return function(...args) {
6415
6467
  if (!__bitfabAutoTraceActive()) {
6468
+ if (enclosingSurface() === "opt-in") {
6469
+ throw mixedTracingError("node()", "opt-out", "opt-in");
6470
+ }
6416
6471
  return fn.apply(this, args);
6417
6472
  }
6418
6473
  return runWithAutoTraceNodeConfiguration(
@@ -7114,20 +7169,19 @@ var Bitfab = class {
7114
7169
  const spanId = randomUuid();
7115
7170
  const parentSpanId = parentContext?.spanId ?? null;
7116
7171
  const isRootSpan = parentSpanId === null;
7117
- const requestedSurface = options.surface ?? "opt-in";
7118
- const surface = requestedSurface === "inherit" ? parentContext?.surface ?? "opt-in" : requestedSurface;
7119
- if (requestedSurface !== "inherit" && parentContext?.surface !== void 0 && parentContext.surface !== surface) {
7120
- warnMixedTracingSurfaces(
7121
- traceFunctionKey,
7122
- surface,
7123
- parentContext.surface
7124
- );
7125
- }
7172
+ const requestedSurface = options.surface ?? DEFAULT_SURFACE;
7173
+ const surface = resolveSurface(requestedSurface, parentContext?.surface);
7174
+ assertSurfacesCompatible(
7175
+ requestedSurface,
7176
+ surface,
7177
+ parentContext?.surface,
7178
+ traceFunctionKey
7179
+ );
7126
7180
  const newContext = {
7127
7181
  traceId,
7128
7182
  spanId,
7129
7183
  contexts: [],
7130
- surface
7184
+ ...surface !== void 0 && { surface }
7131
7185
  };
7132
7186
  newStack = [...currentStack, newContext];
7133
7187
  const inputs = args;
@@ -7410,6 +7464,9 @@ var Bitfab = class {
7410
7464
  if (registeredTraceId) {
7411
7465
  activeTraceStates.delete(registeredTraceId);
7412
7466
  }
7467
+ if (setupError instanceof MixedTracingError) {
7468
+ throw setupError;
7469
+ }
7413
7470
  if (getReplayContext() || inSeedScope()) {
7414
7471
  throw setupError;
7415
7472
  }
@@ -7809,9 +7866,14 @@ var Bitfab = class {
7809
7866
  const wrappedKey = fn._bitfabTraceFunctionKey;
7810
7867
  let target = fn;
7811
7868
  if (wrappedKey === void 0) {
7869
+ const seedRootOptions = {
7870
+ name: traceFunctionKey,
7871
+ type: "agent",
7872
+ surface: "neutral"
7873
+ };
7812
7874
  target = this.withSpan(
7813
7875
  traceFunctionKey,
7814
- { name: traceFunctionKey, type: "agent" },
7876
+ seedRootOptions,
7815
7877
  fn
7816
7878
  );
7817
7879
  } else if (wrappedKey !== traceFunctionKey) {
@@ -7853,11 +7915,12 @@ var Bitfab = class {
7853
7915
  const wrappedKey = fn._bitfabTraceFunctionKey;
7854
7916
  let replayFn = fn;
7855
7917
  if (wrappedKey === void 0) {
7856
- replayFn = this.withSpan(
7857
- traceFunctionKey,
7858
- { name: traceFunctionKey, type: "agent" },
7859
- fn
7860
- );
7918
+ const replayRootOptions = {
7919
+ name: traceFunctionKey,
7920
+ type: "agent",
7921
+ surface: "neutral"
7922
+ };
7923
+ replayFn = this.withSpan(traceFunctionKey, replayRootOptions, fn);
7861
7924
  } else if (wrappedKey !== traceFunctionKey) {
7862
7925
  throw new BitfabError(
7863
7926
  `Function is wrapped with trace function key '${wrappedKey}' but replay was called with '${traceFunctionKey}'. Pass matching keys, or pass the unwrapped function to replay it under the explicit key.`
@@ -8174,6 +8237,7 @@ assertAsyncStorageRegistered();
8174
8237
  DatasetsClient,
8175
8238
  DbBranchReplayError,
8176
8239
  HttpClient,
8240
+ MixedTracingError,
8177
8241
  NO_MOCK_OVERRIDE,
8178
8242
  ReplayError,
8179
8243
  SUPPORTED_PROVIDERS,