@bitfab/sdk 0.42.0 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-BC5OYWAM.js → chunk-5BBJ5BQD.js} +173 -67
- package/dist/chunk-5BBJ5BQD.js.map +1 -0
- package/dist/{chunk-UGFTBSGS.js → chunk-6EM2S5H5.js} +6 -3
- package/dist/{chunk-UGFTBSGS.js.map → chunk-6EM2S5H5.js.map} +1 -1
- package/dist/{chunk-QJ6IFPGU.js → chunk-BBJSKBVJ.js} +6 -3
- package/dist/{chunk-QJ6IFPGU.js.map → chunk-BBJSKBVJ.js.map} +1 -1
- package/dist/{chunk-BG3A5HNC.js → chunk-BXBRVWWW.js} +10 -4
- package/dist/chunk-BXBRVWWW.js.map +1 -0
- package/dist/{http-F5L466DI.js → http-IO3Y7ROJ.js} +2 -2
- package/dist/{http-NZHGC5YF.js → http-R553H2H2.js} +2 -2
- package/dist/index.cjs +184 -66
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +37 -53
- package/dist/index.d.ts +37 -53
- package/dist/index.js +3 -3
- package/dist/node.cjs +184 -66
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +3 -3
- package/dist/{replay-PLACY77M.js → replay-LM4GIDVD.js} +3 -3
- package/dist/replayCli.js +31 -10
- package/dist/replayCli.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-BC5OYWAM.js.map +0 -1
- package/dist/chunk-BG3A5HNC.js.map +0 -1
- /package/dist/{http-F5L466DI.js.map → http-IO3Y7ROJ.js.map} +0 -0
- /package/dist/{http-NZHGC5YF.js.map → http-R553H2H2.js.map} +0 -0
- /package/dist/{replay-PLACY77M.js.map → replay-LM4GIDVD.js.map} +0 -0
|
@@ -14,14 +14,14 @@ import {
|
|
|
14
14
|
serializeValue,
|
|
15
15
|
toJsonSafe,
|
|
16
16
|
toJsonSafeReport
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-BXBRVWWW.js";
|
|
18
18
|
import {
|
|
19
19
|
BitfabError,
|
|
20
20
|
DEFAULT_SERVICE_URL,
|
|
21
21
|
HttpClient,
|
|
22
22
|
getReplayContext,
|
|
23
23
|
warnOnce
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-6EM2S5H5.js";
|
|
25
25
|
import {
|
|
26
26
|
__privateAdd,
|
|
27
27
|
__privateGet,
|
|
@@ -1902,7 +1902,8 @@ var BitfabLangGraphIntegration = class {
|
|
|
1902
1902
|
type: "function",
|
|
1903
1903
|
captureWhen: "nested",
|
|
1904
1904
|
mockOnReplay: shouldMock,
|
|
1905
|
-
finalize: finalizeToolResult
|
|
1905
|
+
finalize: finalizeToolResult,
|
|
1906
|
+
surface: "inherit"
|
|
1906
1907
|
},
|
|
1907
1908
|
async (_args) => await originalInvoke(input, ...rest)
|
|
1908
1909
|
);
|
|
@@ -1945,7 +1946,7 @@ var BitfabLangGraphIntegration = class {
|
|
|
1945
1946
|
wrapInvoke(fn) {
|
|
1946
1947
|
return this.client.withSpan(
|
|
1947
1948
|
this.traceFunctionKey,
|
|
1948
|
-
{ name: this.traceFunctionKey, type: "agent" },
|
|
1949
|
+
{ name: this.traceFunctionKey, type: "agent", surface: "inherit" },
|
|
1949
1950
|
fn
|
|
1950
1951
|
);
|
|
1951
1952
|
}
|
|
@@ -1995,7 +1996,11 @@ var BitfabOpenAIAgentHandler = class {
|
|
|
1995
1996
|
}
|
|
1996
1997
|
return res?.finalOutput;
|
|
1997
1998
|
};
|
|
1998
|
-
const options_ = {
|
|
1999
|
+
const options_ = {
|
|
2000
|
+
type: "agent",
|
|
2001
|
+
finalize,
|
|
2002
|
+
surface: "inherit"
|
|
2003
|
+
};
|
|
1999
2004
|
const traced = this.withSpanFn(
|
|
2000
2005
|
this.traceFunctionKey,
|
|
2001
2006
|
options_,
|
|
@@ -2054,6 +2059,35 @@ var ReplayBranch = class {
|
|
|
2054
2059
|
_url = new WeakMap();
|
|
2055
2060
|
_context = new WeakMap();
|
|
2056
2061
|
|
|
2062
|
+
// src/seedContext.ts
|
|
2063
|
+
var seedContextStorage = null;
|
|
2064
|
+
var SEED_CONTEXT_STORAGE_SYMBOL = /* @__PURE__ */ Symbol.for("bitfab.seedContextStorage");
|
|
2065
|
+
var seedContextReady = asyncStorageReady.then(() => {
|
|
2066
|
+
const shared = globalThis;
|
|
2067
|
+
const existing = shared[SEED_CONTEXT_STORAGE_SYMBOL];
|
|
2068
|
+
if (existing) {
|
|
2069
|
+
seedContextStorage = existing;
|
|
2070
|
+
return;
|
|
2071
|
+
}
|
|
2072
|
+
const created = createAsyncLocalStorage();
|
|
2073
|
+
if (created) {
|
|
2074
|
+
shared[SEED_CONTEXT_STORAGE_SYMBOL] = created;
|
|
2075
|
+
seedContextStorage = created;
|
|
2076
|
+
}
|
|
2077
|
+
});
|
|
2078
|
+
function getSeedContext() {
|
|
2079
|
+
return seedContextStorage?.getStore() ?? null;
|
|
2080
|
+
}
|
|
2081
|
+
function inSeedScope() {
|
|
2082
|
+
return getSeedContext() !== null;
|
|
2083
|
+
}
|
|
2084
|
+
function runWithSeedContext(ctx, fn) {
|
|
2085
|
+
if (seedContextStorage) {
|
|
2086
|
+
return seedContextStorage.run(ctx, fn);
|
|
2087
|
+
}
|
|
2088
|
+
return fn();
|
|
2089
|
+
}
|
|
2090
|
+
|
|
2057
2091
|
// src/tracing.ts
|
|
2058
2092
|
var BitfabOpenAITracingProcessor = class {
|
|
2059
2093
|
/**
|
|
@@ -2384,7 +2418,8 @@ var BitfabVercelAiHandler = class {
|
|
|
2384
2418
|
key,
|
|
2385
2419
|
{
|
|
2386
2420
|
type: "llm",
|
|
2387
|
-
finalize: (result) => summarizeGenerate(result ?? {}, label)
|
|
2421
|
+
finalize: (result) => summarizeGenerate(result ?? {}, label),
|
|
2422
|
+
surface: "inherit"
|
|
2388
2423
|
},
|
|
2389
2424
|
() => doGenerate()
|
|
2390
2425
|
);
|
|
@@ -2402,7 +2437,7 @@ var BitfabVercelAiHandler = class {
|
|
|
2402
2437
|
// The wrapped fn returns immediately with the live stream, so the span
|
|
2403
2438
|
// output cannot be read from the return value. `finalize` instead
|
|
2404
2439
|
// awaits the summary the accumulator resolves once the stream drains.
|
|
2405
|
-
{ type: "llm", finalize: () => summary },
|
|
2440
|
+
{ type: "llm", finalize: () => summary, surface: "inherit" },
|
|
2406
2441
|
async () => {
|
|
2407
2442
|
const result = await doStream();
|
|
2408
2443
|
const stream = result.stream.pipeThrough(
|
|
@@ -2418,6 +2453,18 @@ var BitfabVercelAiHandler = class {
|
|
|
2418
2453
|
};
|
|
2419
2454
|
|
|
2420
2455
|
// src/client.ts
|
|
2456
|
+
var MIXED_SURFACE_REMEDY = {
|
|
2457
|
+
"opt-in": "Inside a withTrace/trace subtree, configure a discovered call with node()/withNode() instead, or trace this workflow with withSpan() only.",
|
|
2458
|
+
"opt-out": "Wrap the caller with withTrace()/trace() as well, or wrap this function with withSpan()."
|
|
2459
|
+
};
|
|
2460
|
+
function warnMixedTracingSurfaces(traceFunctionKey, entered, enclosing) {
|
|
2461
|
+
const enteredApi = entered === "opt-in" ? "withSpan()" : "withTrace()";
|
|
2462
|
+
const enclosingApi = enclosing === "opt-in" ? "withSpan()" : "withTrace()";
|
|
2463
|
+
warnOnce(
|
|
2464
|
+
`mixed-tracing-surface:${traceFunctionKey}:${entered}`,
|
|
2465
|
+
`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]}`
|
|
2466
|
+
);
|
|
2467
|
+
}
|
|
2421
2468
|
var activeTraceStates = /* @__PURE__ */ new Map();
|
|
2422
2469
|
var asyncLocalStorage = null;
|
|
2423
2470
|
var SPAN_CONTEXT_STORAGE_SYMBOL = /* @__PURE__ */ Symbol.for("bitfab.spanContextStorage");
|
|
@@ -2781,7 +2828,13 @@ var Bitfab = class {
|
|
|
2781
2828
|
this.serviceUrl = config.serviceUrl ?? DEFAULT_SERVICE_URL;
|
|
2782
2829
|
this.timeout = config.timeout ?? 12e4;
|
|
2783
2830
|
this.envVars = config.envVars ?? {};
|
|
2784
|
-
|
|
2831
|
+
if (config.enabled !== void 0) {
|
|
2832
|
+
warnOnce(
|
|
2833
|
+
"deprecated-enabled-option",
|
|
2834
|
+
"Bitfab({ enabled }) is deprecated; pass captureEnabled instead."
|
|
2835
|
+
);
|
|
2836
|
+
}
|
|
2837
|
+
this.captureConfigured = (config.captureEnabled ?? true) && (config.enabled ?? true);
|
|
2785
2838
|
this.strict = config.strict ?? false;
|
|
2786
2839
|
this.bamlClient = config.bamlClient ?? null;
|
|
2787
2840
|
if (config.dbSnapshot) {
|
|
@@ -2817,9 +2870,6 @@ var Bitfab = class {
|
|
|
2817
2870
|
if (!descriptor || typeof descriptor.value !== "function") {
|
|
2818
2871
|
throw new BitfabError("@bitfab.trace can only decorate methods");
|
|
2819
2872
|
}
|
|
2820
|
-
if (!this.explicitlyEnabled) {
|
|
2821
|
-
return;
|
|
2822
|
-
}
|
|
2823
2873
|
descriptor.value = this.createAutoTraceRoot(
|
|
2824
2874
|
traceFunctionKey,
|
|
2825
2875
|
String(propertyKey),
|
|
@@ -2833,9 +2883,6 @@ var Bitfab = class {
|
|
|
2833
2883
|
if (typeof method !== "function" || context?.kind !== "method" || context.name === void 0) {
|
|
2834
2884
|
throw new BitfabError("@bitfab.trace can only decorate methods");
|
|
2835
2885
|
}
|
|
2836
|
-
if (!this.explicitlyEnabled) {
|
|
2837
|
-
return method;
|
|
2838
|
-
}
|
|
2839
2886
|
return this.createAutoTraceRoot(
|
|
2840
2887
|
traceFunctionKey,
|
|
2841
2888
|
String(context.name),
|
|
@@ -2851,9 +2898,6 @@ var Bitfab = class {
|
|
|
2851
2898
|
if (!fn) {
|
|
2852
2899
|
throw new BitfabError("bitfab.withTrace requires a function");
|
|
2853
2900
|
}
|
|
2854
|
-
if (!this.explicitlyEnabled) {
|
|
2855
|
-
return fn;
|
|
2856
|
-
}
|
|
2857
2901
|
const name = fn.name !== "" ? fn.name : traceFunctionKey;
|
|
2858
2902
|
return this.createAutoTraceRoot(traceFunctionKey, name, options, fn);
|
|
2859
2903
|
}
|
|
@@ -2877,9 +2921,6 @@ var Bitfab = class {
|
|
|
2877
2921
|
if (!descriptor || typeof descriptor.value !== "function") {
|
|
2878
2922
|
throw new BitfabError("@bitfab.node can only decorate methods");
|
|
2879
2923
|
}
|
|
2880
|
-
if (!this.explicitlyEnabled) {
|
|
2881
|
-
return;
|
|
2882
|
-
}
|
|
2883
2924
|
descriptor.value = this.createAutoTraceNode(
|
|
2884
2925
|
configuration,
|
|
2885
2926
|
descriptor.value,
|
|
@@ -2892,9 +2933,6 @@ var Bitfab = class {
|
|
|
2892
2933
|
if (typeof method !== "function" || context?.kind !== "method") {
|
|
2893
2934
|
throw new BitfabError("@bitfab.node can only decorate methods");
|
|
2894
2935
|
}
|
|
2895
|
-
if (!this.explicitlyEnabled) {
|
|
2896
|
-
return method;
|
|
2897
|
-
}
|
|
2898
2936
|
return this.createAutoTraceNode(
|
|
2899
2937
|
configuration,
|
|
2900
2938
|
method,
|
|
@@ -2910,9 +2948,6 @@ var Bitfab = class {
|
|
|
2910
2948
|
throw new BitfabError("bitfab.withNode requires a function");
|
|
2911
2949
|
}
|
|
2912
2950
|
const configuration = this.resolveNodeConfiguration(options);
|
|
2913
|
-
if (!this.explicitlyEnabled) {
|
|
2914
|
-
return fn;
|
|
2915
|
-
}
|
|
2916
2951
|
const functionName = internalFunctionName ?? fn.name;
|
|
2917
2952
|
if (functionName === "") {
|
|
2918
2953
|
throw new BitfabError(
|
|
@@ -2965,9 +3000,14 @@ var Bitfab = class {
|
|
|
2965
3000
|
);
|
|
2966
3001
|
const excluded = new Set(options.exclude ?? []);
|
|
2967
3002
|
const includeWrappers = options.includeWrappers ?? false;
|
|
3003
|
+
const rootOptions = {
|
|
3004
|
+
name: options.name ?? name,
|
|
3005
|
+
type: options.type ?? "custom",
|
|
3006
|
+
surface: "opt-out"
|
|
3007
|
+
};
|
|
2968
3008
|
const tracedRoot = this.withSpan(
|
|
2969
3009
|
traceFunctionKey,
|
|
2970
|
-
|
|
3010
|
+
rootOptions,
|
|
2971
3011
|
function(...args) {
|
|
2972
3012
|
const capturePolicy = getAutoTraceCapturePolicy(self, traceFunctionKey);
|
|
2973
3013
|
self.refreshAutoTraceCapturePolicy(traceFunctionKey);
|
|
@@ -3011,6 +3051,7 @@ var Bitfab = class {
|
|
|
3011
3051
|
name: nodeConfiguration?.name ?? definition.name,
|
|
3012
3052
|
type: nodeConfiguration?.type ?? "function",
|
|
3013
3053
|
captureWhen: "nested",
|
|
3054
|
+
surface: "opt-out",
|
|
3014
3055
|
functionId: definition.id,
|
|
3015
3056
|
captureContent: nodeConfiguration !== void 0 || capturePolicy === void 0 || capturePolicy.has(definition.id),
|
|
3016
3057
|
autoTraceDefinition: definition,
|
|
@@ -3048,7 +3089,7 @@ var Bitfab = class {
|
|
|
3048
3089
|
}
|
|
3049
3090
|
);
|
|
3050
3091
|
const autoTraceRoot = function(...args) {
|
|
3051
|
-
if (!self.
|
|
3092
|
+
if (!self.shouldRecord()) {
|
|
3052
3093
|
return fn.apply(this, args);
|
|
3053
3094
|
}
|
|
3054
3095
|
return tracedRoot.apply(this, args);
|
|
@@ -3056,6 +3097,7 @@ var Bitfab = class {
|
|
|
3056
3097
|
Object.defineProperty(autoTraceRoot, "_bitfabTraceFunctionKey", {
|
|
3057
3098
|
value: traceFunctionKey
|
|
3058
3099
|
});
|
|
3100
|
+
Object.defineProperty(autoTraceRoot, "_bitfabWrappedFn", { value: fn });
|
|
3059
3101
|
return autoTraceRoot;
|
|
3060
3102
|
}
|
|
3061
3103
|
refreshAutoTraceCapturePolicy(traceFunctionKey) {
|
|
@@ -3139,7 +3181,7 @@ var Bitfab = class {
|
|
|
3139
3181
|
"Bitfab: no API key resolved. Set BITFAB_API_KEY or pass apiKey to new Bitfab(). If a script loads env with dotenv, load it before the module that constructs the client is imported (e.g. `node --env-file=.env script.ts`), or pass `apiKey: () => process.env.BITFAB_API_KEY`."
|
|
3140
3182
|
);
|
|
3141
3183
|
}
|
|
3142
|
-
if (this.
|
|
3184
|
+
if (this.captureConfigured && !this.apiKeyWarned) {
|
|
3143
3185
|
this.apiKeyWarned = true;
|
|
3144
3186
|
console.warn(
|
|
3145
3187
|
"Bitfab: apiKey is empty - tracing is disabled. Provide a valid API key to enable tracing."
|
|
@@ -3147,17 +3189,21 @@ var Bitfab = class {
|
|
|
3147
3189
|
}
|
|
3148
3190
|
return void 0;
|
|
3149
3191
|
}
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3192
|
+
isCaptureEnabled() {
|
|
3193
|
+
if (!this.captureConfigured) {
|
|
3194
|
+
return false;
|
|
3195
|
+
}
|
|
3196
|
+
return this.resolveApiKey() !== void 0;
|
|
3197
|
+
}
|
|
3198
|
+
shouldRecord() {
|
|
3199
|
+
if (!this.captureConfigured && !getReplayContext() && !inSeedScope()) {
|
|
3157
3200
|
return false;
|
|
3158
3201
|
}
|
|
3159
3202
|
return this.resolveApiKey() !== void 0;
|
|
3160
3203
|
}
|
|
3204
|
+
get captureEnabled() {
|
|
3205
|
+
return this.isCaptureEnabled();
|
|
3206
|
+
}
|
|
3161
3207
|
/**
|
|
3162
3208
|
* Fetch the function with its current version and BAML prompt from the server.
|
|
3163
3209
|
*
|
|
@@ -3569,9 +3615,6 @@ var Bitfab = class {
|
|
|
3569
3615
|
* @returns A wrapped function with the same signature that creates spans for inputs and outputs
|
|
3570
3616
|
*/
|
|
3571
3617
|
withSpan(traceFunctionKey, optionsOrFn, maybeFn) {
|
|
3572
|
-
if (!this.explicitlyEnabled) {
|
|
3573
|
-
return typeof optionsOrFn === "function" ? optionsOrFn : maybeFn;
|
|
3574
|
-
}
|
|
3575
3618
|
const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
|
|
3576
3619
|
const fn = typeof optionsOrFn === "function" ? optionsOrFn : maybeFn;
|
|
3577
3620
|
const self = this;
|
|
@@ -3585,7 +3628,7 @@ var Bitfab = class {
|
|
|
3585
3628
|
}
|
|
3586
3629
|
})();
|
|
3587
3630
|
const wrappedFn = function(...args) {
|
|
3588
|
-
if (!self.
|
|
3631
|
+
if (!self.shouldRecord()) {
|
|
3589
3632
|
return fn.apply(this, args);
|
|
3590
3633
|
}
|
|
3591
3634
|
initializeAsyncContext();
|
|
@@ -3633,11 +3676,26 @@ var Bitfab = class {
|
|
|
3633
3676
|
const currentStack = getSpanStack();
|
|
3634
3677
|
const parentContext = currentStack[currentStack.length - 1];
|
|
3635
3678
|
const replayCtxForTraceId = parentContext ? null : getReplayContext();
|
|
3636
|
-
const
|
|
3679
|
+
const seedCtxForTraceId = parentContext ? null : getSeedContext();
|
|
3680
|
+
const traceId = parentContext?.traceId ?? replayCtxForTraceId?.traceId ?? seedCtxForTraceId?.traceId ?? randomUuid();
|
|
3637
3681
|
const spanId = randomUuid();
|
|
3638
3682
|
const parentSpanId = parentContext?.spanId ?? null;
|
|
3639
3683
|
const isRootSpan = parentSpanId === null;
|
|
3640
|
-
const
|
|
3684
|
+
const requestedSurface = options.surface ?? "opt-in";
|
|
3685
|
+
const surface = requestedSurface === "inherit" ? parentContext?.surface ?? "opt-in" : requestedSurface;
|
|
3686
|
+
if (requestedSurface !== "inherit" && parentContext?.surface !== void 0 && parentContext.surface !== surface) {
|
|
3687
|
+
warnMixedTracingSurfaces(
|
|
3688
|
+
traceFunctionKey,
|
|
3689
|
+
surface,
|
|
3690
|
+
parentContext.surface
|
|
3691
|
+
);
|
|
3692
|
+
}
|
|
3693
|
+
const newContext = {
|
|
3694
|
+
traceId,
|
|
3695
|
+
spanId,
|
|
3696
|
+
contexts: [],
|
|
3697
|
+
surface
|
|
3698
|
+
};
|
|
3641
3699
|
newStack = [...currentStack, newContext];
|
|
3642
3700
|
const inputs = args;
|
|
3643
3701
|
const startedAt = nowIsoTimestamp();
|
|
@@ -3919,7 +3977,7 @@ var Bitfab = class {
|
|
|
3919
3977
|
if (registeredTraceId) {
|
|
3920
3978
|
activeTraceStates.delete(registeredTraceId);
|
|
3921
3979
|
}
|
|
3922
|
-
if (getReplayContext()) {
|
|
3980
|
+
if (getReplayContext() || inSeedScope()) {
|
|
3923
3981
|
throw setupError;
|
|
3924
3982
|
}
|
|
3925
3983
|
warnOnce(
|
|
@@ -3994,7 +4052,7 @@ var Bitfab = class {
|
|
|
3994
4052
|
return {
|
|
3995
4053
|
traceId,
|
|
3996
4054
|
addContext: (context) => {
|
|
3997
|
-
if (!this.
|
|
4055
|
+
if (!this.shouldRecord()) {
|
|
3998
4056
|
return Promise.resolve();
|
|
3999
4057
|
}
|
|
4000
4058
|
if (typeof context !== "object" || context === null) {
|
|
@@ -4005,7 +4063,7 @@ var Bitfab = class {
|
|
|
4005
4063
|
});
|
|
4006
4064
|
},
|
|
4007
4065
|
setMetadata: (metadata) => {
|
|
4008
|
-
if (!this.
|
|
4066
|
+
if (!this.shouldRecord()) {
|
|
4009
4067
|
return Promise.resolve();
|
|
4010
4068
|
}
|
|
4011
4069
|
if (typeof metadata !== "object" || metadata === null) {
|
|
@@ -4014,7 +4072,7 @@ var Bitfab = class {
|
|
|
4014
4072
|
return this.httpClient.patchTrace(traceId, { mergeMetadata: metadata });
|
|
4015
4073
|
},
|
|
4016
4074
|
setSessionId: (sessionId) => {
|
|
4017
|
-
if (!this.
|
|
4075
|
+
if (!this.shouldRecord()) {
|
|
4018
4076
|
return Promise.resolve();
|
|
4019
4077
|
}
|
|
4020
4078
|
if (typeof sessionId !== "string" || sessionId.length === 0) {
|
|
@@ -4023,7 +4081,7 @@ var Bitfab = class {
|
|
|
4023
4081
|
return this.httpClient.patchTrace(traceId, { setSessionId: sessionId });
|
|
4024
4082
|
},
|
|
4025
4083
|
setName: (name) => {
|
|
4026
|
-
if (!this.
|
|
4084
|
+
if (!this.shouldRecord()) {
|
|
4027
4085
|
return Promise.resolve();
|
|
4028
4086
|
}
|
|
4029
4087
|
if (typeof name !== "string" || name.length === 0) {
|
|
@@ -4259,22 +4317,13 @@ var Bitfab = class {
|
|
|
4259
4317
|
clearMockOverrides() {
|
|
4260
4318
|
this.mockOverrides.length = 0;
|
|
4261
4319
|
}
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
* rather than against a previous run.
|
|
4270
|
-
*
|
|
4271
|
-
* A seeded trace has no child spans and no database pin, so replay mocking
|
|
4272
|
-
* has nothing recorded to substitute and `dbBranch` refuses it. Pass
|
|
4273
|
-
* `mockOverride` at replay time for calls that must not run.
|
|
4274
|
-
*
|
|
4275
|
-
* @returns The trace ID, usable with `replay({ traceIds: [...] })`.
|
|
4276
|
-
*/
|
|
4277
|
-
seedTrace(traceFunctionKey, options) {
|
|
4320
|
+
seedTrace(traceFunctionKey, optionsOrFn, runOptions) {
|
|
4321
|
+
if (typeof optionsOrFn === "function") {
|
|
4322
|
+
return this.seedTraceByRunning(traceFunctionKey, optionsOrFn, runOptions);
|
|
4323
|
+
}
|
|
4324
|
+
return this.seedTraceFromCase(traceFunctionKey, optionsOrFn);
|
|
4325
|
+
}
|
|
4326
|
+
seedTraceFromCase(traceFunctionKey, options) {
|
|
4278
4327
|
const { input } = options;
|
|
4279
4328
|
const fn = options.fn?._bitfabWrappedFn ?? options.fn;
|
|
4280
4329
|
if (fn && input.length < fn.length) {
|
|
@@ -4323,6 +4372,50 @@ var Bitfab = class {
|
|
|
4323
4372
|
}
|
|
4324
4373
|
return traceId;
|
|
4325
4374
|
}
|
|
4375
|
+
async seedTraceByRunning(traceFunctionKey, fn, options) {
|
|
4376
|
+
const wrappedKey = fn._bitfabTraceFunctionKey;
|
|
4377
|
+
let target = fn;
|
|
4378
|
+
if (wrappedKey === void 0) {
|
|
4379
|
+
target = this.withSpan(
|
|
4380
|
+
traceFunctionKey,
|
|
4381
|
+
{ name: traceFunctionKey, type: "agent" },
|
|
4382
|
+
fn
|
|
4383
|
+
);
|
|
4384
|
+
} else if (wrappedKey !== traceFunctionKey) {
|
|
4385
|
+
throw new BitfabError(
|
|
4386
|
+
`Function is wrapped with trace function key '${wrappedKey}' but seedTrace was called with '${traceFunctionKey}'. Pass matching keys, or pass the unwrapped function to seed it under the explicit key.`
|
|
4387
|
+
);
|
|
4388
|
+
}
|
|
4389
|
+
await seedContextReady;
|
|
4390
|
+
const traceId = randomUuid();
|
|
4391
|
+
activeTraceStates.set(traceId, {
|
|
4392
|
+
traceId,
|
|
4393
|
+
startedAt: nowIsoTimestamp(),
|
|
4394
|
+
contexts: [],
|
|
4395
|
+
ingestionType: "seeded",
|
|
4396
|
+
...options?.sessionId !== void 0 && { sessionId: options.sessionId },
|
|
4397
|
+
...options?.name !== void 0 && { name: options.name },
|
|
4398
|
+
...options?.metadata !== void 0 && { metadata: options.metadata }
|
|
4399
|
+
});
|
|
4400
|
+
const args = options?.args ?? [];
|
|
4401
|
+
let unrecorded = true;
|
|
4402
|
+
try {
|
|
4403
|
+
await runWithSeedContext({ traceId }, async () => target(...args));
|
|
4404
|
+
} finally {
|
|
4405
|
+
try {
|
|
4406
|
+
const { flushTraces: flushTraces2 } = await import("./http-IO3Y7ROJ.js");
|
|
4407
|
+
await flushTraces2(3e4);
|
|
4408
|
+
} finally {
|
|
4409
|
+
unrecorded = activeTraceStates.delete(traceId);
|
|
4410
|
+
}
|
|
4411
|
+
}
|
|
4412
|
+
if (unrecorded) {
|
|
4413
|
+
throw new BitfabError(
|
|
4414
|
+
`seedTrace recorded nothing for '${traceFunctionKey}': the call finished without a root span. Check that an API key resolves (BITFAB_API_KEY or apiKey), and that fn is a regular or async function rather than a generator.`
|
|
4415
|
+
);
|
|
4416
|
+
}
|
|
4417
|
+
return traceId;
|
|
4418
|
+
}
|
|
4326
4419
|
async replay(traceFunctionKey, fn, options) {
|
|
4327
4420
|
const wrappedKey = fn._bitfabTraceFunctionKey;
|
|
4328
4421
|
let replayFn = fn;
|
|
@@ -4337,7 +4430,7 @@ var Bitfab = class {
|
|
|
4337
4430
|
`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.`
|
|
4338
4431
|
);
|
|
4339
4432
|
}
|
|
4340
|
-
const { replay: doReplay } = await import("./replay-
|
|
4433
|
+
const { replay: doReplay } = await import("./replay-LM4GIDVD.js");
|
|
4341
4434
|
return doReplay(
|
|
4342
4435
|
this.httpClient,
|
|
4343
4436
|
this.serviceUrl,
|
|
@@ -4573,7 +4666,7 @@ var finalizers = {
|
|
|
4573
4666
|
function defineReplayRegistry(registry) {
|
|
4574
4667
|
return registry;
|
|
4575
4668
|
}
|
|
4576
|
-
async function seedFromRegistry(registry, pipeline, cases) {
|
|
4669
|
+
async function seedFromRegistry(registry, pipeline, cases, options = {}) {
|
|
4577
4670
|
const registration = registry[pipeline];
|
|
4578
4671
|
if (registration === void 0) {
|
|
4579
4672
|
throw new BitfabError(
|
|
@@ -4581,6 +4674,19 @@ async function seedFromRegistry(registry, pipeline, cases) {
|
|
|
4581
4674
|
);
|
|
4582
4675
|
}
|
|
4583
4676
|
const traceFunctionKey = resolveTraceFunctionKey(registration);
|
|
4677
|
+
if (options.run === true) {
|
|
4678
|
+
const traceIds2 = [];
|
|
4679
|
+
for (const seedCase of cases) {
|
|
4680
|
+
traceIds2.push(
|
|
4681
|
+
await registration.client.seedTrace(traceFunctionKey, registration.fn, {
|
|
4682
|
+
args: seedCase.input,
|
|
4683
|
+
metadata: seedCase.metadata,
|
|
4684
|
+
sessionId: seedCase.sessionId
|
|
4685
|
+
})
|
|
4686
|
+
);
|
|
4687
|
+
}
|
|
4688
|
+
return { pipeline, traceFunctionKey, traceIds: traceIds2 };
|
|
4689
|
+
}
|
|
4584
4690
|
const traceIds = cases.map(
|
|
4585
4691
|
(seedCase) => registration.client.seedTrace(traceFunctionKey, {
|
|
4586
4692
|
input: seedCase.input,
|
|
@@ -4590,7 +4696,7 @@ async function seedFromRegistry(registry, pipeline, cases) {
|
|
|
4590
4696
|
sessionId: seedCase.sessionId
|
|
4591
4697
|
})
|
|
4592
4698
|
);
|
|
4593
|
-
const { flushTraces: flushTraces2 } = await import("./http-
|
|
4699
|
+
const { flushTraces: flushTraces2 } = await import("./http-IO3Y7ROJ.js");
|
|
4594
4700
|
await flushTraces2(3e4);
|
|
4595
4701
|
return { pipeline, traceFunctionKey, traceIds };
|
|
4596
4702
|
}
|
|
@@ -4623,4 +4729,4 @@ export {
|
|
|
4623
4729
|
defineReplayRegistry,
|
|
4624
4730
|
seedFromRegistry
|
|
4625
4731
|
};
|
|
4626
|
-
//# sourceMappingURL=chunk-
|
|
4732
|
+
//# sourceMappingURL=chunk-5BBJ5BQD.js.map
|