@bitfab/sdk 0.32.0 → 0.33.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-NMNVPON4.js → chunk-ADUWXWWI.js} +21 -10
- package/dist/chunk-ADUWXWWI.js.map +1 -0
- package/dist/{chunk-YZZO475T.js → chunk-HPLLGCTO.js} +54 -105
- package/dist/chunk-HPLLGCTO.js.map +1 -0
- package/dist/index.cjs +66 -114
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +214 -105
- package/dist/index.d.ts +214 -105
- package/dist/index.js +4 -4
- package/dist/node.cjs +66 -114
- 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 +4 -4
- package/dist/{replay-DJWVOJUR.js → replay-EQPISJKC.js} +2 -2
- package/package.json +1 -1
- package/dist/chunk-NMNVPON4.js.map +0 -1
- package/dist/chunk-YZZO475T.js.map +0 -1
- /package/dist/{replay-DJWVOJUR.js.map → replay-EQPISJKC.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __typeError = (msg) => {
|
|
9
|
+
throw TypeError(msg);
|
|
10
|
+
};
|
|
8
11
|
var __esm = (fn, res) => function __init() {
|
|
9
12
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
13
|
};
|
|
@@ -29,6 +32,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
32
|
mod
|
|
30
33
|
));
|
|
31
34
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
36
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
37
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
38
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
32
39
|
|
|
33
40
|
// src/errors.ts
|
|
34
41
|
var BitfabError;
|
|
@@ -524,11 +531,11 @@ __export(replay_exports, {
|
|
|
524
531
|
replay: () => replay,
|
|
525
532
|
reportReplayProgress: () => reportReplayProgress
|
|
526
533
|
});
|
|
527
|
-
function resolveDbBranchSettings(
|
|
528
|
-
if (!
|
|
534
|
+
function resolveDbBranchSettings(dbBranch) {
|
|
535
|
+
if (!dbBranch) {
|
|
529
536
|
return void 0;
|
|
530
537
|
}
|
|
531
|
-
const { minCu, maxCu, warmupSql } =
|
|
538
|
+
const { minCu, maxCu, warmupSql } = dbBranch;
|
|
532
539
|
const settings = {
|
|
533
540
|
...minCu === void 0 ? {} : { minCu },
|
|
534
541
|
...maxCu === void 0 ? {} : { maxCu },
|
|
@@ -596,9 +603,9 @@ function buildMockTree(rootNode) {
|
|
|
596
603
|
}
|
|
597
604
|
return { spans };
|
|
598
605
|
}
|
|
599
|
-
async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy, resolvedOverrides, replayedTraceId,
|
|
600
|
-
const lease =
|
|
601
|
-
const leaseError =
|
|
606
|
+
async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy, resolvedOverrides, replayedTraceId, includeDbBranchLease, adaptInputs) {
|
|
607
|
+
const lease = includeDbBranchLease ? serverItem.dbBranchLease : void 0;
|
|
608
|
+
const leaseError = includeDbBranchLease ? serverItem.dbBranchLeaseError : void 0;
|
|
602
609
|
let inputs = [];
|
|
603
610
|
let originalOutput;
|
|
604
611
|
let result;
|
|
@@ -781,12 +788,12 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
|
|
|
781
788
|
options?.name,
|
|
782
789
|
codeChangeDescription,
|
|
783
790
|
codeChangeFiles,
|
|
784
|
-
options?.
|
|
791
|
+
options?.dbBranch !== void 0,
|
|
785
792
|
// includeDbBranchLease
|
|
786
793
|
options?.experimentGroupId,
|
|
787
794
|
options?.datasetId,
|
|
788
795
|
options?.graderIds,
|
|
789
|
-
resolveDbBranchSettings(options?.
|
|
796
|
+
resolveDbBranchSettings(options?.dbBranch)
|
|
790
797
|
);
|
|
791
798
|
const mockStrategy = options?.mock ?? "marked";
|
|
792
799
|
const maxConcurrency = options?.maxConcurrency ?? 10;
|
|
@@ -804,7 +811,7 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
|
|
|
804
811
|
mockStrategy,
|
|
805
812
|
resolvedOverrides,
|
|
806
813
|
replayedTraceIds[index],
|
|
807
|
-
options?.
|
|
814
|
+
options?.dbBranch !== void 0,
|
|
808
815
|
options?.adaptInputs
|
|
809
816
|
)
|
|
810
817
|
);
|
|
@@ -961,11 +968,11 @@ __export(index_exports, {
|
|
|
961
968
|
BitfabOpenAITracingProcessor: () => BitfabOpenAITracingProcessor,
|
|
962
969
|
BitfabVercelAiHandler: () => BitfabVercelAiHandler,
|
|
963
970
|
DEFAULT_SERVICE_URL: () => DEFAULT_SERVICE_URL,
|
|
964
|
-
ReplayEnvironment: () => ReplayEnvironment,
|
|
965
971
|
SUPPORTED_PROVIDERS: () => SUPPORTED_PROVIDERS,
|
|
966
972
|
__version__: () => __version__,
|
|
967
973
|
finalizers: () => finalizers,
|
|
968
974
|
flushTraces: () => flushTraces,
|
|
975
|
+
getCurrentReplayBranch: () => getCurrentReplayBranch,
|
|
969
976
|
getCurrentSpan: () => getCurrentSpan,
|
|
970
977
|
getCurrentTrace: () => getCurrentTrace,
|
|
971
978
|
reportReplayProgress: () => reportReplayProgress
|
|
@@ -973,7 +980,7 @@ __export(index_exports, {
|
|
|
973
980
|
module.exports = __toCommonJS(index_exports);
|
|
974
981
|
|
|
975
982
|
// src/version.generated.ts
|
|
976
|
-
var __version__ = "0.
|
|
983
|
+
var __version__ = "0.33.0";
|
|
977
984
|
|
|
978
985
|
// src/constants.ts
|
|
979
986
|
var DEFAULT_SERVICE_URL = "https://bitfab.ai";
|
|
@@ -1776,7 +1783,7 @@ var BitfabClaudeAgentHandler = class {
|
|
|
1776
1783
|
}
|
|
1777
1784
|
}
|
|
1778
1785
|
// ── hook callbacks ───────────────────────────────────────────
|
|
1779
|
-
async preToolUseHook(inputData, toolUseId,
|
|
1786
|
+
async preToolUseHook(inputData, toolUseId, _context2) {
|
|
1780
1787
|
try {
|
|
1781
1788
|
const sid = inputData.tool_use_id ?? toolUseId ?? randomUuid();
|
|
1782
1789
|
const toolName = inputData.tool_name ?? "tool";
|
|
@@ -1788,7 +1795,7 @@ var BitfabClaudeAgentHandler = class {
|
|
|
1788
1795
|
}
|
|
1789
1796
|
return {};
|
|
1790
1797
|
}
|
|
1791
|
-
async postToolUseHook(inputData, toolUseId,
|
|
1798
|
+
async postToolUseHook(inputData, toolUseId, _context2) {
|
|
1792
1799
|
try {
|
|
1793
1800
|
const sid = inputData.tool_use_id ?? toolUseId ?? "";
|
|
1794
1801
|
const toolResponse = inputData.tool_response;
|
|
@@ -1797,7 +1804,7 @@ var BitfabClaudeAgentHandler = class {
|
|
|
1797
1804
|
}
|
|
1798
1805
|
return {};
|
|
1799
1806
|
}
|
|
1800
|
-
async postToolUseFailureHook(inputData, toolUseId,
|
|
1807
|
+
async postToolUseFailureHook(inputData, toolUseId, _context2) {
|
|
1801
1808
|
try {
|
|
1802
1809
|
const sid = inputData.tool_use_id ?? toolUseId ?? "";
|
|
1803
1810
|
const error = String(inputData.error ?? "Unknown error");
|
|
@@ -1806,7 +1813,7 @@ var BitfabClaudeAgentHandler = class {
|
|
|
1806
1813
|
}
|
|
1807
1814
|
return {};
|
|
1808
1815
|
}
|
|
1809
|
-
async subagentStartHook(inputData, _toolUseId,
|
|
1816
|
+
async subagentStartHook(inputData, _toolUseId, _context2) {
|
|
1810
1817
|
try {
|
|
1811
1818
|
const agentId = inputData.agent_id ?? randomUuid();
|
|
1812
1819
|
const agentType = inputData.agent_type ?? "subagent";
|
|
@@ -1824,7 +1831,7 @@ var BitfabClaudeAgentHandler = class {
|
|
|
1824
1831
|
}
|
|
1825
1832
|
return {};
|
|
1826
1833
|
}
|
|
1827
|
-
async subagentStopHook(inputData, _toolUseId,
|
|
1834
|
+
async subagentStopHook(inputData, _toolUseId, _context2) {
|
|
1828
1835
|
try {
|
|
1829
1836
|
const agentId = inputData.agent_id ?? "";
|
|
1830
1837
|
const spanId = this.activeSubagentSpans.get(agentId);
|
|
@@ -3064,106 +3071,46 @@ var BitfabOpenAIAgentHandler = class {
|
|
|
3064
3071
|
|
|
3065
3072
|
// src/client.ts
|
|
3066
3073
|
init_randomUuid();
|
|
3067
|
-
init_replayContext();
|
|
3068
3074
|
|
|
3069
|
-
// src/
|
|
3070
|
-
|
|
3071
|
-
var
|
|
3072
|
-
|
|
3073
|
-
|
|
3075
|
+
// src/replayBranch.ts
|
|
3076
|
+
var _url, _context;
|
|
3077
|
+
var ReplayBranch = class {
|
|
3078
|
+
/** @internal Built by `getCurrentReplayBranch()`; never constructed by callers. */
|
|
3079
|
+
constructor(lease, traceId, context) {
|
|
3080
|
+
// Genuine JS private fields, not TypeScript `private`: these must be
|
|
3081
|
+
// non-enumerable so neither the connection string nor the whole replay
|
|
3082
|
+
// context can ride along into a log line or a serialized payload.
|
|
3083
|
+
__privateAdd(this, _url);
|
|
3084
|
+
__privateAdd(this, _context);
|
|
3085
|
+
this.expiresAt = lease.expiresAt;
|
|
3086
|
+
this.providerConsoleUrl = lease.providerConsoleUrl;
|
|
3087
|
+
this.readOnly = lease.readOnly;
|
|
3088
|
+
this.region = lease.region;
|
|
3089
|
+
this.traceId = traceId;
|
|
3090
|
+
__privateSet(this, _url, lease.databaseUrl);
|
|
3091
|
+
__privateSet(this, _context, context);
|
|
3074
3092
|
}
|
|
3075
3093
|
/**
|
|
3076
|
-
*
|
|
3077
|
-
*
|
|
3094
|
+
* Connection string for this item's branch. Point your database client at it
|
|
3095
|
+
* instead of the live database for the duration of the replayed call.
|
|
3096
|
+
*
|
|
3097
|
+
* Reading it records on the trace that the replayed code obtained the branch
|
|
3098
|
+
* URL, which is what separates "a branch was provisioned" from "the branch
|
|
3099
|
+
* was actually used". The other fields inspect the lease without exposing the
|
|
3100
|
+
* connection string, so they deliberately do not record anything. That is
|
|
3101
|
+
* also why this is a getter and not a plain field: the URL is absent from
|
|
3102
|
+
* `JSON.stringify(branch)` and from logging the object.
|
|
3078
3103
|
*/
|
|
3079
3104
|
get databaseUrl() {
|
|
3080
|
-
|
|
3081
|
-
this
|
|
3082
|
-
return snapshot.databaseUrl;
|
|
3083
|
-
}
|
|
3084
|
-
/** When the per-trace branch URL stops being valid. ISO-8601. */
|
|
3085
|
-
get expiresAt() {
|
|
3086
|
-
return this.require().expiresAt;
|
|
3087
|
-
}
|
|
3088
|
-
/** Deep link to the branch in the provider console, if available. */
|
|
3089
|
-
get providerConsoleUrl() {
|
|
3090
|
-
return this.require().providerConsoleUrl;
|
|
3091
|
-
}
|
|
3092
|
-
/**
|
|
3093
|
-
* True if the branch is read-only. Customer code can use this to skip
|
|
3094
|
-
* write operations during replay when the provider returned a read-only
|
|
3095
|
-
* lease.
|
|
3096
|
-
*/
|
|
3097
|
-
get readOnly() {
|
|
3098
|
-
return this.require().readOnly;
|
|
3099
|
-
}
|
|
3100
|
-
/**
|
|
3101
|
-
* The branch's region, e.g. `aws-us-east-1`. A compute runs in its project's
|
|
3102
|
-
* region, so a replay runner elsewhere pays that round trip on every query.
|
|
3103
|
-
*/
|
|
3104
|
-
get region() {
|
|
3105
|
-
return this.require().region;
|
|
3106
|
-
}
|
|
3107
|
-
/** The historical trace ID that produced the input for this replay item. */
|
|
3108
|
-
get traceId() {
|
|
3109
|
-
return this.require().traceId;
|
|
3110
|
-
}
|
|
3111
|
-
/** True when read inside a replay item that has a resolved branch. */
|
|
3112
|
-
get active() {
|
|
3113
|
-
return this.read() !== null;
|
|
3114
|
-
}
|
|
3115
|
-
/** Non-throwing variant for callers that handle the inactive case. */
|
|
3116
|
-
snapshot() {
|
|
3117
|
-
const snapshot = this.read();
|
|
3118
|
-
if (snapshot) {
|
|
3119
|
-
this.markAccessed();
|
|
3120
|
-
}
|
|
3121
|
-
return snapshot;
|
|
3122
|
-
}
|
|
3123
|
-
/**
|
|
3124
|
-
* Record on the replay context that customer code obtained the branch
|
|
3125
|
-
* URL. Only `databaseUrl` and `snapshot()` count - `active`, `readOnly`
|
|
3126
|
-
* and friends inspect the lease without exposing the connection string,
|
|
3127
|
-
* so they don't prove the replayed code could have connected to the
|
|
3128
|
-
* branch.
|
|
3129
|
-
*/
|
|
3130
|
-
markAccessed() {
|
|
3131
|
-
const ctx = getReplayContext();
|
|
3132
|
-
if (ctx?.dbBranchLease) {
|
|
3133
|
-
ctx.dbSnapshotAccessed = true;
|
|
3134
|
-
}
|
|
3135
|
-
}
|
|
3136
|
-
read() {
|
|
3137
|
-
const ctx = getReplayContext();
|
|
3138
|
-
if (!ctx?.dbBranchLease) {
|
|
3139
|
-
return null;
|
|
3140
|
-
}
|
|
3141
|
-
const traceId = ctx.sourceBitfabTraceId ?? ctx.inputSourceTraceId;
|
|
3142
|
-
if (!traceId) {
|
|
3143
|
-
return null;
|
|
3144
|
-
}
|
|
3145
|
-
const lease = ctx.dbBranchLease;
|
|
3146
|
-
return {
|
|
3147
|
-
databaseUrl: lease.databaseUrl,
|
|
3148
|
-
expiresAt: lease.expiresAt,
|
|
3149
|
-
providerConsoleUrl: lease.providerConsoleUrl,
|
|
3150
|
-
readOnly: lease.readOnly,
|
|
3151
|
-
region: lease.region,
|
|
3152
|
-
traceId
|
|
3153
|
-
};
|
|
3154
|
-
}
|
|
3155
|
-
require() {
|
|
3156
|
-
const snapshot = this.read();
|
|
3157
|
-
if (!snapshot) {
|
|
3158
|
-
throw new Error(
|
|
3159
|
-
"ReplayEnvironment accessed outside of a replay item. Pass it to bitfab.replay({ environment }) and only read it inside the replayed function."
|
|
3160
|
-
);
|
|
3161
|
-
}
|
|
3162
|
-
return snapshot;
|
|
3105
|
+
__privateGet(this, _context).dbSnapshotAccessed = true;
|
|
3106
|
+
return __privateGet(this, _url);
|
|
3163
3107
|
}
|
|
3164
3108
|
};
|
|
3109
|
+
_url = new WeakMap();
|
|
3110
|
+
_context = new WeakMap();
|
|
3165
3111
|
|
|
3166
3112
|
// src/client.ts
|
|
3113
|
+
init_replayContext();
|
|
3167
3114
|
init_serialize();
|
|
3168
3115
|
|
|
3169
3116
|
// src/tracing.ts
|
|
@@ -3760,6 +3707,17 @@ function getCurrentSpan() {
|
|
|
3760
3707
|
}
|
|
3761
3708
|
};
|
|
3762
3709
|
}
|
|
3710
|
+
function getCurrentReplayBranch() {
|
|
3711
|
+
const ctx = getReplayContext();
|
|
3712
|
+
if (!ctx?.dbBranchLease) {
|
|
3713
|
+
return null;
|
|
3714
|
+
}
|
|
3715
|
+
const traceId = ctx.sourceBitfabTraceId ?? ctx.inputSourceTraceId;
|
|
3716
|
+
if (!traceId) {
|
|
3717
|
+
return null;
|
|
3718
|
+
}
|
|
3719
|
+
return new ReplayBranch(ctx.dbBranchLease, traceId, ctx);
|
|
3720
|
+
}
|
|
3763
3721
|
function getCurrentTrace() {
|
|
3764
3722
|
const stack = getSpanStack();
|
|
3765
3723
|
const current = stack[stack.length - 1];
|
|
@@ -4834,12 +4792,6 @@ var Bitfab = class {
|
|
|
4834
4792
|
);
|
|
4835
4793
|
}
|
|
4836
4794
|
};
|
|
4837
|
-
/**
|
|
4838
|
-
* Per-trace environment for `replay({ environment })`. Construct one,
|
|
4839
|
-
* pass it to replay, and read `env.databaseUrl` inside the replayed
|
|
4840
|
-
* function to pick up the per-trace branch URL.
|
|
4841
|
-
*/
|
|
4842
|
-
Bitfab.ReplayEnvironment = ReplayEnvironment;
|
|
4843
4795
|
var BitfabFunction = class {
|
|
4844
4796
|
constructor(client, traceFunctionKey) {
|
|
4845
4797
|
this.client = client;
|
|
@@ -5047,11 +4999,11 @@ init_replay();
|
|
|
5047
4999
|
BitfabOpenAITracingProcessor,
|
|
5048
5000
|
BitfabVercelAiHandler,
|
|
5049
5001
|
DEFAULT_SERVICE_URL,
|
|
5050
|
-
ReplayEnvironment,
|
|
5051
5002
|
SUPPORTED_PROVIDERS,
|
|
5052
5003
|
__version__,
|
|
5053
5004
|
finalizers,
|
|
5054
5005
|
flushTraces,
|
|
5006
|
+
getCurrentReplayBranch,
|
|
5055
5007
|
getCurrentSpan,
|
|
5056
5008
|
getCurrentTrace,
|
|
5057
5009
|
reportReplayProgress
|