@bitfab/sdk 0.32.0 → 0.33.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/{chunk-YZZO475T.js → chunk-7UHJ67MH.js} +55 -106
- package/dist/chunk-7UHJ67MH.js.map +1 -0
- package/dist/{chunk-NMNVPON4.js → chunk-ADUWXWWI.js} +21 -10
- package/dist/chunk-ADUWXWWI.js.map +1 -0
- package/dist/index.cjs +67 -115
- 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 +67 -115
- 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
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BitfabError,
|
|
3
|
+
__privateAdd,
|
|
4
|
+
__privateGet,
|
|
5
|
+
__privateSet,
|
|
3
6
|
asyncStorageReady,
|
|
4
7
|
createAsyncLocalStorage,
|
|
5
8
|
deserializeValue,
|
|
@@ -11,10 +14,10 @@ import {
|
|
|
11
14
|
toJsonSafe,
|
|
12
15
|
toJsonSafeReport,
|
|
13
16
|
warnOnce
|
|
14
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-ADUWXWWI.js";
|
|
15
18
|
|
|
16
19
|
// src/version.generated.ts
|
|
17
|
-
var __version__ = "0.
|
|
20
|
+
var __version__ = "0.33.1";
|
|
18
21
|
|
|
19
22
|
// src/constants.ts
|
|
20
23
|
var DEFAULT_SERVICE_URL = "https://bitfab.ai";
|
|
@@ -401,7 +404,7 @@ var HttpClient = class {
|
|
|
401
404
|
if (dbBranchSettings !== void 0) {
|
|
402
405
|
payload.dbBranchSettings = dbBranchSettings;
|
|
403
406
|
}
|
|
404
|
-
const timeout = includeDbBranchLease ?
|
|
407
|
+
const timeout = includeDbBranchLease ? 3e5 : 3e4;
|
|
405
408
|
return this.request("/api/sdk/replay/start", payload, {
|
|
406
409
|
timeout
|
|
407
410
|
});
|
|
@@ -809,7 +812,7 @@ var BitfabClaudeAgentHandler = class {
|
|
|
809
812
|
}
|
|
810
813
|
}
|
|
811
814
|
// ── hook callbacks ───────────────────────────────────────────
|
|
812
|
-
async preToolUseHook(inputData, toolUseId,
|
|
815
|
+
async preToolUseHook(inputData, toolUseId, _context2) {
|
|
813
816
|
try {
|
|
814
817
|
const sid = inputData.tool_use_id ?? toolUseId ?? randomUuid();
|
|
815
818
|
const toolName = inputData.tool_name ?? "tool";
|
|
@@ -821,7 +824,7 @@ var BitfabClaudeAgentHandler = class {
|
|
|
821
824
|
}
|
|
822
825
|
return {};
|
|
823
826
|
}
|
|
824
|
-
async postToolUseHook(inputData, toolUseId,
|
|
827
|
+
async postToolUseHook(inputData, toolUseId, _context2) {
|
|
825
828
|
try {
|
|
826
829
|
const sid = inputData.tool_use_id ?? toolUseId ?? "";
|
|
827
830
|
const toolResponse = inputData.tool_response;
|
|
@@ -830,7 +833,7 @@ var BitfabClaudeAgentHandler = class {
|
|
|
830
833
|
}
|
|
831
834
|
return {};
|
|
832
835
|
}
|
|
833
|
-
async postToolUseFailureHook(inputData, toolUseId,
|
|
836
|
+
async postToolUseFailureHook(inputData, toolUseId, _context2) {
|
|
834
837
|
try {
|
|
835
838
|
const sid = inputData.tool_use_id ?? toolUseId ?? "";
|
|
836
839
|
const error = String(inputData.error ?? "Unknown error");
|
|
@@ -839,7 +842,7 @@ var BitfabClaudeAgentHandler = class {
|
|
|
839
842
|
}
|
|
840
843
|
return {};
|
|
841
844
|
}
|
|
842
|
-
async subagentStartHook(inputData, _toolUseId,
|
|
845
|
+
async subagentStartHook(inputData, _toolUseId, _context2) {
|
|
843
846
|
try {
|
|
844
847
|
const agentId = inputData.agent_id ?? randomUuid();
|
|
845
848
|
const agentType = inputData.agent_type ?? "subagent";
|
|
@@ -857,7 +860,7 @@ var BitfabClaudeAgentHandler = class {
|
|
|
857
860
|
}
|
|
858
861
|
return {};
|
|
859
862
|
}
|
|
860
|
-
async subagentStopHook(inputData, _toolUseId,
|
|
863
|
+
async subagentStopHook(inputData, _toolUseId, _context2) {
|
|
861
864
|
try {
|
|
862
865
|
const agentId = inputData.agent_id ?? "";
|
|
863
866
|
const spanId = this.activeSubagentSpans.get(agentId);
|
|
@@ -2086,101 +2089,42 @@ var BitfabOpenAIAgentHandler = class {
|
|
|
2086
2089
|
}
|
|
2087
2090
|
};
|
|
2088
2091
|
|
|
2089
|
-
// src/
|
|
2090
|
-
var
|
|
2091
|
-
|
|
2092
|
-
|
|
2092
|
+
// src/replayBranch.ts
|
|
2093
|
+
var _url, _context;
|
|
2094
|
+
var ReplayBranch = class {
|
|
2095
|
+
/** @internal Built by `getCurrentReplayBranch()`; never constructed by callers. */
|
|
2096
|
+
constructor(lease, traceId, context) {
|
|
2097
|
+
// Genuine JS private fields, not TypeScript `private`: these must be
|
|
2098
|
+
// non-enumerable so neither the connection string nor the whole replay
|
|
2099
|
+
// context can ride along into a log line or a serialized payload.
|
|
2100
|
+
__privateAdd(this, _url);
|
|
2101
|
+
__privateAdd(this, _context);
|
|
2102
|
+
this.expiresAt = lease.expiresAt;
|
|
2103
|
+
this.providerConsoleUrl = lease.providerConsoleUrl;
|
|
2104
|
+
this.readOnly = lease.readOnly;
|
|
2105
|
+
this.region = lease.region;
|
|
2106
|
+
this.traceId = traceId;
|
|
2107
|
+
__privateSet(this, _url, lease.databaseUrl);
|
|
2108
|
+
__privateSet(this, _context, context);
|
|
2093
2109
|
}
|
|
2094
2110
|
/**
|
|
2095
|
-
*
|
|
2096
|
-
*
|
|
2111
|
+
* Connection string for this item's branch. Point your database client at it
|
|
2112
|
+
* instead of the live database for the duration of the replayed call.
|
|
2113
|
+
*
|
|
2114
|
+
* Reading it records on the trace that the replayed code obtained the branch
|
|
2115
|
+
* URL, which is what separates "a branch was provisioned" from "the branch
|
|
2116
|
+
* was actually used". The other fields inspect the lease without exposing the
|
|
2117
|
+
* connection string, so they deliberately do not record anything. That is
|
|
2118
|
+
* also why this is a getter and not a plain field: the URL is absent from
|
|
2119
|
+
* `JSON.stringify(branch)` and from logging the object.
|
|
2097
2120
|
*/
|
|
2098
2121
|
get databaseUrl() {
|
|
2099
|
-
|
|
2100
|
-
this
|
|
2101
|
-
return snapshot.databaseUrl;
|
|
2102
|
-
}
|
|
2103
|
-
/** When the per-trace branch URL stops being valid. ISO-8601. */
|
|
2104
|
-
get expiresAt() {
|
|
2105
|
-
return this.require().expiresAt;
|
|
2106
|
-
}
|
|
2107
|
-
/** Deep link to the branch in the provider console, if available. */
|
|
2108
|
-
get providerConsoleUrl() {
|
|
2109
|
-
return this.require().providerConsoleUrl;
|
|
2110
|
-
}
|
|
2111
|
-
/**
|
|
2112
|
-
* True if the branch is read-only. Customer code can use this to skip
|
|
2113
|
-
* write operations during replay when the provider returned a read-only
|
|
2114
|
-
* lease.
|
|
2115
|
-
*/
|
|
2116
|
-
get readOnly() {
|
|
2117
|
-
return this.require().readOnly;
|
|
2118
|
-
}
|
|
2119
|
-
/**
|
|
2120
|
-
* The branch's region, e.g. `aws-us-east-1`. A compute runs in its project's
|
|
2121
|
-
* region, so a replay runner elsewhere pays that round trip on every query.
|
|
2122
|
-
*/
|
|
2123
|
-
get region() {
|
|
2124
|
-
return this.require().region;
|
|
2125
|
-
}
|
|
2126
|
-
/** The historical trace ID that produced the input for this replay item. */
|
|
2127
|
-
get traceId() {
|
|
2128
|
-
return this.require().traceId;
|
|
2129
|
-
}
|
|
2130
|
-
/** True when read inside a replay item that has a resolved branch. */
|
|
2131
|
-
get active() {
|
|
2132
|
-
return this.read() !== null;
|
|
2133
|
-
}
|
|
2134
|
-
/** Non-throwing variant for callers that handle the inactive case. */
|
|
2135
|
-
snapshot() {
|
|
2136
|
-
const snapshot = this.read();
|
|
2137
|
-
if (snapshot) {
|
|
2138
|
-
this.markAccessed();
|
|
2139
|
-
}
|
|
2140
|
-
return snapshot;
|
|
2141
|
-
}
|
|
2142
|
-
/**
|
|
2143
|
-
* Record on the replay context that customer code obtained the branch
|
|
2144
|
-
* URL. Only `databaseUrl` and `snapshot()` count - `active`, `readOnly`
|
|
2145
|
-
* and friends inspect the lease without exposing the connection string,
|
|
2146
|
-
* so they don't prove the replayed code could have connected to the
|
|
2147
|
-
* branch.
|
|
2148
|
-
*/
|
|
2149
|
-
markAccessed() {
|
|
2150
|
-
const ctx = getReplayContext();
|
|
2151
|
-
if (ctx?.dbBranchLease) {
|
|
2152
|
-
ctx.dbSnapshotAccessed = true;
|
|
2153
|
-
}
|
|
2154
|
-
}
|
|
2155
|
-
read() {
|
|
2156
|
-
const ctx = getReplayContext();
|
|
2157
|
-
if (!ctx?.dbBranchLease) {
|
|
2158
|
-
return null;
|
|
2159
|
-
}
|
|
2160
|
-
const traceId = ctx.sourceBitfabTraceId ?? ctx.inputSourceTraceId;
|
|
2161
|
-
if (!traceId) {
|
|
2162
|
-
return null;
|
|
2163
|
-
}
|
|
2164
|
-
const lease = ctx.dbBranchLease;
|
|
2165
|
-
return {
|
|
2166
|
-
databaseUrl: lease.databaseUrl,
|
|
2167
|
-
expiresAt: lease.expiresAt,
|
|
2168
|
-
providerConsoleUrl: lease.providerConsoleUrl,
|
|
2169
|
-
readOnly: lease.readOnly,
|
|
2170
|
-
region: lease.region,
|
|
2171
|
-
traceId
|
|
2172
|
-
};
|
|
2173
|
-
}
|
|
2174
|
-
require() {
|
|
2175
|
-
const snapshot = this.read();
|
|
2176
|
-
if (!snapshot) {
|
|
2177
|
-
throw new Error(
|
|
2178
|
-
"ReplayEnvironment accessed outside of a replay item. Pass it to bitfab.replay({ environment }) and only read it inside the replayed function."
|
|
2179
|
-
);
|
|
2180
|
-
}
|
|
2181
|
-
return snapshot;
|
|
2122
|
+
__privateGet(this, _context).dbSnapshotAccessed = true;
|
|
2123
|
+
return __privateGet(this, _url);
|
|
2182
2124
|
}
|
|
2183
2125
|
};
|
|
2126
|
+
_url = new WeakMap();
|
|
2127
|
+
_context = new WeakMap();
|
|
2184
2128
|
|
|
2185
2129
|
// src/tracing.ts
|
|
2186
2130
|
var BitfabOpenAITracingProcessor = class {
|
|
@@ -2774,6 +2718,17 @@ function getCurrentSpan() {
|
|
|
2774
2718
|
}
|
|
2775
2719
|
};
|
|
2776
2720
|
}
|
|
2721
|
+
function getCurrentReplayBranch() {
|
|
2722
|
+
const ctx = getReplayContext();
|
|
2723
|
+
if (!ctx?.dbBranchLease) {
|
|
2724
|
+
return null;
|
|
2725
|
+
}
|
|
2726
|
+
const traceId = ctx.sourceBitfabTraceId ?? ctx.inputSourceTraceId;
|
|
2727
|
+
if (!traceId) {
|
|
2728
|
+
return null;
|
|
2729
|
+
}
|
|
2730
|
+
return new ReplayBranch(ctx.dbBranchLease, traceId, ctx);
|
|
2731
|
+
}
|
|
2777
2732
|
function getCurrentTrace() {
|
|
2778
2733
|
const stack = getSpanStack();
|
|
2779
2734
|
const current = stack[stack.length - 1];
|
|
@@ -3837,7 +3792,7 @@ var Bitfab = class {
|
|
|
3837
3792
|
`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.`
|
|
3838
3793
|
);
|
|
3839
3794
|
}
|
|
3840
|
-
const { replay: doReplay } = await import("./replay-
|
|
3795
|
+
const { replay: doReplay } = await import("./replay-EQPISJKC.js");
|
|
3841
3796
|
return doReplay(
|
|
3842
3797
|
this.httpClient,
|
|
3843
3798
|
this.serviceUrl,
|
|
@@ -3848,12 +3803,6 @@ var Bitfab = class {
|
|
|
3848
3803
|
);
|
|
3849
3804
|
}
|
|
3850
3805
|
};
|
|
3851
|
-
/**
|
|
3852
|
-
* Per-trace environment for `replay({ environment })`. Construct one,
|
|
3853
|
-
* pass it to replay, and read `env.databaseUrl` inside the replayed
|
|
3854
|
-
* function to pick up the per-trace branch URL.
|
|
3855
|
-
*/
|
|
3856
|
-
Bitfab.ReplayEnvironment = ReplayEnvironment;
|
|
3857
3806
|
var BitfabFunction = class {
|
|
3858
3807
|
constructor(client, traceFunctionKey) {
|
|
3859
3808
|
this.client = client;
|
|
@@ -4054,13 +4003,13 @@ export {
|
|
|
4054
4003
|
SUPPORTED_PROVIDERS,
|
|
4055
4004
|
BitfabLangGraphCallbackHandler,
|
|
4056
4005
|
BitfabOpenAIAgentHandler,
|
|
4057
|
-
ReplayEnvironment,
|
|
4058
4006
|
BitfabOpenAITracingProcessor,
|
|
4059
4007
|
BitfabVercelAiHandler,
|
|
4060
4008
|
getCurrentSpan,
|
|
4009
|
+
getCurrentReplayBranch,
|
|
4061
4010
|
getCurrentTrace,
|
|
4062
4011
|
Bitfab,
|
|
4063
4012
|
BitfabFunction,
|
|
4064
4013
|
finalizers
|
|
4065
4014
|
};
|
|
4066
|
-
//# sourceMappingURL=chunk-
|
|
4015
|
+
//# sourceMappingURL=chunk-7UHJ67MH.js.map
|