bitfab 0.38.2 → 0.38.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/autoTrace.cjs +48 -1
- package/dist/autoTrace.cjs.map +1 -1
- package/dist/autoTrace.d.cts +13 -2
- package/dist/autoTrace.d.ts +13 -2
- package/dist/autoTrace.js +3 -1
- package/dist/{chunk-GFBQ2AMO.js → chunk-J47KPS77.js} +48 -2
- package/dist/chunk-J47KPS77.js.map +1 -0
- package/dist/{chunk-QWV7JDLQ.js → chunk-LHFNHB2J.js} +7 -2
- package/dist/{chunk-QWV7JDLQ.js.map → chunk-LHFNHB2J.js.map} +1 -1
- package/dist/{chunk-JSU2Z2Z7.js → chunk-PXAL7PPD.js} +146 -23
- package/dist/chunk-PXAL7PPD.js.map +1 -0
- package/dist/index.cjs +194 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +81 -4
- package/dist/index.d.ts +81 -4
- package/dist/index.js +5 -3
- package/dist/node.cjs +194 -19
- 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 +5 -3
- package/dist/node.js.map +1 -1
- package/dist/{replay-DDAYVRET.js → replay-BYW5MCLO.js} +2 -2
- package/dist/replayCli.js +620 -0
- package/dist/replayCli.js.map +1 -0
- package/package.json +6 -2
- package/dist/chunk-GFBQ2AMO.js.map +0 -1
- package/dist/chunk-JSU2Z2Z7.js.map +0 -1
- /package/dist/{replay-DDAYVRET.js.map → replay-BYW5MCLO.js.map} +0 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
+
__bitfabAutoTraceActive,
|
|
2
3
|
__setBitfabAutoTraceCapturePolicy,
|
|
3
4
|
getAutoTraceCapturePolicy,
|
|
4
5
|
runWithAutoTraceContext,
|
|
6
|
+
runWithAutoTraceNodeConfiguration,
|
|
5
7
|
runWithAutoTraceRootContext
|
|
6
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-J47KPS77.js";
|
|
7
9
|
import {
|
|
8
10
|
BitfabError,
|
|
9
11
|
DEFAULT_SERVICE_URL,
|
|
@@ -16,7 +18,7 @@ import {
|
|
|
16
18
|
toJsonSafe,
|
|
17
19
|
toJsonSafeReport,
|
|
18
20
|
warnOnce
|
|
19
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-LHFNHB2J.js";
|
|
20
22
|
import {
|
|
21
23
|
__privateAdd,
|
|
22
24
|
__privateGet,
|
|
@@ -2447,6 +2449,102 @@ var Bitfab = class {
|
|
|
2447
2449
|
const name = fn.name !== "" ? fn.name : traceFunctionKey;
|
|
2448
2450
|
return this.createAutoTraceRoot(traceFunctionKey, name, options, fn);
|
|
2449
2451
|
}
|
|
2452
|
+
/**
|
|
2453
|
+
* Configure a transformed class method when it is discovered beneath a
|
|
2454
|
+
* {@link Bitfab.trace} root.
|
|
2455
|
+
*
|
|
2456
|
+
* The decorator creates no span or trace by itself. Beneath an active trace,
|
|
2457
|
+
* it can rename or retype the discovered call, capture its contents, mark it
|
|
2458
|
+
* for recorded-output replay, finalize its output, or omit it while leaving
|
|
2459
|
+
* captured descendants attached to the nearest captured parent.
|
|
2460
|
+
*
|
|
2461
|
+
* @param options - Trace-owned call configuration.
|
|
2462
|
+
* @experimental Automatic child-call instrumentation is experimental.
|
|
2463
|
+
*/
|
|
2464
|
+
node(options = {}) {
|
|
2465
|
+
const configuration = this.resolveNodeConfiguration(options);
|
|
2466
|
+
const decorator = (...args) => {
|
|
2467
|
+
if (args.length === 3) {
|
|
2468
|
+
const descriptor = args[2];
|
|
2469
|
+
if (!descriptor || typeof descriptor.value !== "function") {
|
|
2470
|
+
throw new BitfabError("@bitfab.node can only decorate methods");
|
|
2471
|
+
}
|
|
2472
|
+
if (!this.explicitlyEnabled) {
|
|
2473
|
+
return;
|
|
2474
|
+
}
|
|
2475
|
+
descriptor.value = this.createAutoTraceNode(
|
|
2476
|
+
configuration,
|
|
2477
|
+
descriptor.value,
|
|
2478
|
+
String(args[1])
|
|
2479
|
+
);
|
|
2480
|
+
return;
|
|
2481
|
+
}
|
|
2482
|
+
const method = args[0];
|
|
2483
|
+
const context = args[1];
|
|
2484
|
+
if (typeof method !== "function" || context?.kind !== "method") {
|
|
2485
|
+
throw new BitfabError("@bitfab.node can only decorate methods");
|
|
2486
|
+
}
|
|
2487
|
+
if (!this.explicitlyEnabled) {
|
|
2488
|
+
return method;
|
|
2489
|
+
}
|
|
2490
|
+
return this.createAutoTraceNode(
|
|
2491
|
+
configuration,
|
|
2492
|
+
method,
|
|
2493
|
+
String(context.name)
|
|
2494
|
+
);
|
|
2495
|
+
};
|
|
2496
|
+
return decorator;
|
|
2497
|
+
}
|
|
2498
|
+
withNode(optionsOrFn, maybeFn, internalFunctionName) {
|
|
2499
|
+
const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
|
|
2500
|
+
const fn = typeof optionsOrFn === "function" ? optionsOrFn : maybeFn;
|
|
2501
|
+
if (!fn) {
|
|
2502
|
+
throw new BitfabError("bitfab.withNode requires a function");
|
|
2503
|
+
}
|
|
2504
|
+
const configuration = this.resolveNodeConfiguration(options);
|
|
2505
|
+
if (!this.explicitlyEnabled) {
|
|
2506
|
+
return fn;
|
|
2507
|
+
}
|
|
2508
|
+
const functionName = internalFunctionName ?? fn.name;
|
|
2509
|
+
if (functionName === "") {
|
|
2510
|
+
throw new BitfabError(
|
|
2511
|
+
"bitfab.withNode requires a named function so the subtree transform can bind its configuration to the correct call."
|
|
2512
|
+
);
|
|
2513
|
+
}
|
|
2514
|
+
return this.createAutoTraceNode(configuration, fn, functionName);
|
|
2515
|
+
}
|
|
2516
|
+
resolveNodeConfiguration(options) {
|
|
2517
|
+
const capture = options.capture ?? true;
|
|
2518
|
+
if (!capture && options.mockOnReplay === true) {
|
|
2519
|
+
throw new BitfabError(
|
|
2520
|
+
"bitfab.node({ capture: false }) cannot use mockOnReplay: true because an uncaptured node has no recorded output."
|
|
2521
|
+
);
|
|
2522
|
+
}
|
|
2523
|
+
return {
|
|
2524
|
+
capture,
|
|
2525
|
+
type: options.type ?? "custom",
|
|
2526
|
+
...options.name !== void 0 && { name: options.name },
|
|
2527
|
+
...options.testRunId !== void 0 && {
|
|
2528
|
+
testRunId: options.testRunId
|
|
2529
|
+
},
|
|
2530
|
+
...options.mockOnReplay !== void 0 && {
|
|
2531
|
+
mockOnReplay: options.mockOnReplay
|
|
2532
|
+
},
|
|
2533
|
+
...options.finalize !== void 0 && { finalize: options.finalize }
|
|
2534
|
+
};
|
|
2535
|
+
}
|
|
2536
|
+
createAutoTraceNode(configuration, fn, functionName) {
|
|
2537
|
+
const nodeConfiguration = { ...configuration, functionName };
|
|
2538
|
+
return function(...args) {
|
|
2539
|
+
if (!__bitfabAutoTraceActive()) {
|
|
2540
|
+
return fn.apply(this, args);
|
|
2541
|
+
}
|
|
2542
|
+
return runWithAutoTraceNodeConfiguration(
|
|
2543
|
+
nodeConfiguration,
|
|
2544
|
+
() => fn.apply(this, args)
|
|
2545
|
+
);
|
|
2546
|
+
};
|
|
2547
|
+
}
|
|
2450
2548
|
createAutoTraceRoot(traceFunctionKey, name, options, fn) {
|
|
2451
2549
|
const self = this;
|
|
2452
2550
|
const maxDepth = autoTraceLimit(
|
|
@@ -2485,29 +2583,51 @@ var Bitfab = class {
|
|
|
2485
2583
|
);
|
|
2486
2584
|
};
|
|
2487
2585
|
const autoTraceContext = {
|
|
2488
|
-
invoke(definition, inputs, invokeFn, depth) {
|
|
2586
|
+
invoke(definition, inputs, invokeFn, depth, nodeConfiguration) {
|
|
2489
2587
|
const nameParts = definition.name.split(".");
|
|
2490
2588
|
const simpleName = nameParts[nameParts.length - 1];
|
|
2491
|
-
|
|
2492
|
-
|
|
2589
|
+
const invokeWithoutNode = () => nodeConfiguration === void 0 ? invokeFn() : runWithAutoTraceContext(autoTraceContext, invokeFn, depth);
|
|
2590
|
+
if (excluded.has(definition.name) || simpleName !== void 0 && excluded.has(simpleName) || nodeConfiguration === void 0 && definition.wrapper === true && !includeWrappers) {
|
|
2591
|
+
return invokeWithoutNode();
|
|
2592
|
+
}
|
|
2593
|
+
if (nodeConfiguration?.capture === false) {
|
|
2594
|
+
return runWithAutoTraceContext(autoTraceContext, invokeFn, depth);
|
|
2493
2595
|
}
|
|
2494
2596
|
if (depth >= maxDepth || spansUsed >= maxSpans) {
|
|
2495
2597
|
warnTruncated();
|
|
2496
|
-
return
|
|
2598
|
+
return invokeWithoutNode();
|
|
2497
2599
|
}
|
|
2498
2600
|
spansUsed += 1;
|
|
2499
2601
|
const childOptions = {
|
|
2500
|
-
name: definition.name,
|
|
2501
|
-
type: "function",
|
|
2602
|
+
name: nodeConfiguration?.name ?? definition.name,
|
|
2603
|
+
type: nodeConfiguration?.type ?? "function",
|
|
2502
2604
|
captureWhen: "nested",
|
|
2503
2605
|
functionId: definition.id,
|
|
2504
|
-
captureContent: capturePolicy.has(definition.id),
|
|
2505
|
-
autoTraceDefinition: definition
|
|
2606
|
+
captureContent: nodeConfiguration !== void 0 || capturePolicy.has(definition.id),
|
|
2607
|
+
autoTraceDefinition: definition,
|
|
2608
|
+
...nodeConfiguration?.testRunId !== void 0 && {
|
|
2609
|
+
testRunId: nodeConfiguration.testRunId
|
|
2610
|
+
},
|
|
2611
|
+
...nodeConfiguration?.mockOnReplay !== void 0 && {
|
|
2612
|
+
mockOnReplay: nodeConfiguration.mockOnReplay
|
|
2613
|
+
},
|
|
2614
|
+
...nodeConfiguration?.finalize !== void 0 && {
|
|
2615
|
+
finalize: nodeConfiguration.finalize
|
|
2616
|
+
}
|
|
2506
2617
|
};
|
|
2618
|
+
const invokeWithAutoTraceContext = () => runWithAutoTraceContext(autoTraceContext, invokeFn, depth + 1);
|
|
2619
|
+
if (definition.async === true) {
|
|
2620
|
+
const tracedAsyncChild = self.withSpan(
|
|
2621
|
+
traceFunctionKey,
|
|
2622
|
+
childOptions,
|
|
2623
|
+
async (..._inputs) => await invokeWithAutoTraceContext()
|
|
2624
|
+
);
|
|
2625
|
+
return tracedAsyncChild(...inputs);
|
|
2626
|
+
}
|
|
2507
2627
|
const tracedChild = self.withSpan(
|
|
2508
2628
|
traceFunctionKey,
|
|
2509
2629
|
childOptions,
|
|
2510
|
-
(..._inputs) =>
|
|
2630
|
+
(..._inputs) => invokeWithAutoTraceContext()
|
|
2511
2631
|
);
|
|
2512
2632
|
return tracedChild(...inputs);
|
|
2513
2633
|
}
|
|
@@ -3077,18 +3197,17 @@ var Bitfab = class {
|
|
|
3077
3197
|
newStack = [...currentStack, newContext];
|
|
3078
3198
|
const inputs = args;
|
|
3079
3199
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3200
|
+
const replayCtxAtStart = getReplayContext();
|
|
3201
|
+
const testRunId = replayCtxAtStart?.testRunId ?? options.testRunId;
|
|
3080
3202
|
if (isRootSpan && !activeTraceStates.has(traceId)) {
|
|
3081
|
-
const replayCtxAtRoot = getReplayContext();
|
|
3082
3203
|
const dbSnapshotRef = buildSnapshotRef(self.dbSnapshot, startedAt);
|
|
3083
3204
|
activeTraceStates.set(traceId, {
|
|
3084
3205
|
traceId,
|
|
3085
3206
|
startedAt,
|
|
3086
3207
|
contexts: [],
|
|
3087
|
-
...
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
...replayCtxAtRoot?.inputSourceTraceId && {
|
|
3091
|
-
inputSourceTraceId: replayCtxAtRoot.inputSourceTraceId
|
|
3208
|
+
...testRunId !== void 0 && { testRunId },
|
|
3209
|
+
...replayCtxAtStart?.inputSourceTraceId && {
|
|
3210
|
+
inputSourceTraceId: replayCtxAtStart.inputSourceTraceId
|
|
3092
3211
|
},
|
|
3093
3212
|
dbSnapshotRef
|
|
3094
3213
|
});
|
|
@@ -3121,9 +3240,7 @@ var Bitfab = class {
|
|
|
3121
3240
|
contexts: newContext.contexts,
|
|
3122
3241
|
prompt: newContext.prompt,
|
|
3123
3242
|
endedAt,
|
|
3124
|
-
...
|
|
3125
|
-
testRunId: replayCtx.testRunId
|
|
3126
|
-
},
|
|
3243
|
+
...testRunId !== void 0 && { testRunId },
|
|
3127
3244
|
...replayCtx?.inputSourceSpanId && {
|
|
3128
3245
|
inputSourceSpanId: replayCtx.inputSourceSpanId
|
|
3129
3246
|
}
|
|
@@ -3608,7 +3725,7 @@ var Bitfab = class {
|
|
|
3608
3725
|
`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.`
|
|
3609
3726
|
);
|
|
3610
3727
|
}
|
|
3611
|
-
const { replay: doReplay } = await import("./replay-
|
|
3728
|
+
const { replay: doReplay } = await import("./replay-BYW5MCLO.js");
|
|
3612
3729
|
return doReplay(
|
|
3613
3730
|
this.httpClient,
|
|
3614
3731
|
this.serviceUrl,
|
|
@@ -3832,6 +3949,11 @@ var finalizers = {
|
|
|
3832
3949
|
readableStream
|
|
3833
3950
|
};
|
|
3834
3951
|
|
|
3952
|
+
// src/replayRegistry.ts
|
|
3953
|
+
function defineReplayRegistry(registry) {
|
|
3954
|
+
return registry;
|
|
3955
|
+
}
|
|
3956
|
+
|
|
3835
3957
|
export {
|
|
3836
3958
|
BitfabClaudeAgentHandler,
|
|
3837
3959
|
SUPPORTED_PROVIDERS,
|
|
@@ -3844,6 +3966,7 @@ export {
|
|
|
3844
3966
|
getCurrentTrace,
|
|
3845
3967
|
Bitfab,
|
|
3846
3968
|
BitfabFunction,
|
|
3847
|
-
finalizers
|
|
3969
|
+
finalizers,
|
|
3970
|
+
defineReplayRegistry
|
|
3848
3971
|
};
|
|
3849
|
-
//# sourceMappingURL=chunk-
|
|
3972
|
+
//# sourceMappingURL=chunk-PXAL7PPD.js.map
|