@bitfab/sdk 0.26.0 → 0.26.2
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-GCAJN5I7.js → chunk-DW7VTEO2.js} +88 -14
- package/dist/chunk-DW7VTEO2.js.map +1 -0
- package/dist/{chunk-26MUT4IP.js → chunk-IDGR2OIX.js} +54 -33
- package/dist/chunk-IDGR2OIX.js.map +1 -0
- package/dist/index.cjs +140 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/node.cjs +140 -47
- package/dist/node.cjs.map +1 -1
- package/dist/node.js +2 -2
- package/dist/{replay-KYGI6LJY.js → replay-CORDD7TR.js} +2 -2
- package/package.json +2 -2
- package/dist/chunk-26MUT4IP.js.map +0 -1
- package/dist/chunk-GCAJN5I7.js.map +0 -1
- /package/dist/{replay-KYGI6LJY.js.map → replay-CORDD7TR.js.map} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -1491,7 +1491,7 @@ declare class BitfabFunction {
|
|
|
1491
1491
|
/**
|
|
1492
1492
|
* SDK version from package.json (injected at build time)
|
|
1493
1493
|
*/
|
|
1494
|
-
declare const __version__ = "0.26.
|
|
1494
|
+
declare const __version__ = "0.26.2";
|
|
1495
1495
|
|
|
1496
1496
|
/**
|
|
1497
1497
|
* Constants for the Bitfab SDK.
|
package/dist/index.d.ts
CHANGED
|
@@ -1491,7 +1491,7 @@ declare class BitfabFunction {
|
|
|
1491
1491
|
/**
|
|
1492
1492
|
* SDK version from package.json (injected at build time)
|
|
1493
1493
|
*/
|
|
1494
|
-
declare const __version__ = "0.26.
|
|
1494
|
+
declare const __version__ = "0.26.2";
|
|
1495
1495
|
|
|
1496
1496
|
/**
|
|
1497
1497
|
* Constants for the Bitfab SDK.
|
package/dist/index.js
CHANGED
|
@@ -14,10 +14,10 @@ import {
|
|
|
14
14
|
flushTraces,
|
|
15
15
|
getCurrentSpan,
|
|
16
16
|
getCurrentTrace
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-DW7VTEO2.js";
|
|
18
18
|
import {
|
|
19
19
|
BitfabError
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-IDGR2OIX.js";
|
|
21
21
|
export {
|
|
22
22
|
Bitfab,
|
|
23
23
|
BitfabClaudeAgentHandler,
|
package/dist/node.cjs
CHANGED
|
@@ -110,35 +110,6 @@ var init_warnOnce = __esm({
|
|
|
110
110
|
}
|
|
111
111
|
});
|
|
112
112
|
|
|
113
|
-
// src/randomUuid.ts
|
|
114
|
-
function randomUuid() {
|
|
115
|
-
const globalCrypto = globalThis.crypto;
|
|
116
|
-
if (typeof globalCrypto?.randomUUID === "function") {
|
|
117
|
-
try {
|
|
118
|
-
return globalCrypto.randomUUID();
|
|
119
|
-
} catch {
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
warnOnce(
|
|
123
|
-
"crypto-unavailable",
|
|
124
|
-
"global crypto.randomUUID is unavailable; using a non-cryptographic fallback for trace/span ids. Tracing works normally (ids are correlation-only, not security-sensitive)."
|
|
125
|
-
);
|
|
126
|
-
return fallbackUuidV4();
|
|
127
|
-
}
|
|
128
|
-
function fallbackUuidV4() {
|
|
129
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (char) => {
|
|
130
|
-
const rand = Math.random() * 16 | 0;
|
|
131
|
-
const value = char === "x" ? rand : rand & 3 | 8;
|
|
132
|
-
return value.toString(16);
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
var init_randomUuid = __esm({
|
|
136
|
-
"src/randomUuid.ts"() {
|
|
137
|
-
"use strict";
|
|
138
|
-
init_warnOnce();
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
|
|
142
113
|
// src/serialize.ts
|
|
143
114
|
function describeValue(value) {
|
|
144
115
|
try {
|
|
@@ -194,7 +165,11 @@ function deserializeValue(serialized) {
|
|
|
194
165
|
});
|
|
195
166
|
}
|
|
196
167
|
function toJsonSafe(value) {
|
|
197
|
-
|
|
168
|
+
return toJsonSafeReport(value).safe;
|
|
169
|
+
}
|
|
170
|
+
function toJsonSafeReport(value) {
|
|
171
|
+
const dropped = [];
|
|
172
|
+
const safe = toJsonSafeInner(value, 0, /* @__PURE__ */ new WeakSet(), dropped);
|
|
198
173
|
try {
|
|
199
174
|
const size = JSON.stringify(safe)?.length ?? 0;
|
|
200
175
|
if (size > MAX_FRAMEWORK_SERIALIZED_BYTES) {
|
|
@@ -202,13 +177,16 @@ function toJsonSafe(value) {
|
|
|
202
177
|
"toJsonSafe:too_large",
|
|
203
178
|
`a framework payload exceeded ${MAX_FRAMEWORK_SERIALIZED_BYTES} bytes and was replaced with a placeholder so the span still ships. The captured state for this span is incomplete.`
|
|
204
179
|
);
|
|
205
|
-
return
|
|
180
|
+
return {
|
|
181
|
+
safe: `<unserializable: too_large_${size}_bytes>`,
|
|
182
|
+
dropped: [...dropped, `too_large_${size}_bytes`]
|
|
183
|
+
};
|
|
206
184
|
}
|
|
207
185
|
} catch {
|
|
208
186
|
}
|
|
209
|
-
return safe;
|
|
187
|
+
return { safe, dropped };
|
|
210
188
|
}
|
|
211
|
-
function toJsonSafeInner(value, depth, seen) {
|
|
189
|
+
function toJsonSafeInner(value, depth, seen, dropped) {
|
|
212
190
|
if (value === null || value === void 0) {
|
|
213
191
|
return value;
|
|
214
192
|
}
|
|
@@ -217,30 +195,40 @@ function toJsonSafeInner(value, depth, seen) {
|
|
|
217
195
|
}
|
|
218
196
|
const className = value?.constructor?.name ?? typeof value;
|
|
219
197
|
if (depth > MAX_SAFE_DEPTH) {
|
|
198
|
+
dropped.push(className);
|
|
220
199
|
return `<${className}>`;
|
|
221
200
|
}
|
|
222
201
|
if (typeof value !== "object") {
|
|
202
|
+
if (typeof value === "function" || typeof value === "symbol") {
|
|
203
|
+
dropped.push(className);
|
|
204
|
+
}
|
|
223
205
|
try {
|
|
224
206
|
return String(value);
|
|
225
207
|
} catch {
|
|
208
|
+
dropped.push(className);
|
|
226
209
|
return `<${className}>`;
|
|
227
210
|
}
|
|
228
211
|
}
|
|
229
212
|
if (seen.has(value)) {
|
|
213
|
+
dropped.push(className);
|
|
230
214
|
return `<cycle ${className}>`;
|
|
231
215
|
}
|
|
232
216
|
seen.add(value);
|
|
233
217
|
let result;
|
|
234
218
|
if (Array.isArray(value)) {
|
|
235
|
-
result = value.map(
|
|
219
|
+
result = value.map(
|
|
220
|
+
(item) => toJsonSafeInner(item, depth + 1, seen, dropped)
|
|
221
|
+
);
|
|
236
222
|
} else if (typeof value.toJSON === "function") {
|
|
237
223
|
try {
|
|
238
224
|
result = toJsonSafeInner(
|
|
239
225
|
value.toJSON(),
|
|
240
226
|
depth + 1,
|
|
241
|
-
seen
|
|
227
|
+
seen,
|
|
228
|
+
dropped
|
|
242
229
|
);
|
|
243
230
|
} catch {
|
|
231
|
+
dropped.push(className);
|
|
244
232
|
result = `<${className}>`;
|
|
245
233
|
}
|
|
246
234
|
} else {
|
|
@@ -248,11 +236,12 @@ function toJsonSafeInner(value, depth, seen) {
|
|
|
248
236
|
const obj = {};
|
|
249
237
|
for (const [k, v] of Object.entries(value)) {
|
|
250
238
|
if (!k.startsWith("_")) {
|
|
251
|
-
obj[k] = toJsonSafeInner(v, depth + 1, seen);
|
|
239
|
+
obj[k] = toJsonSafeInner(v, depth + 1, seen, dropped);
|
|
252
240
|
}
|
|
253
241
|
}
|
|
254
242
|
result = obj;
|
|
255
243
|
} catch {
|
|
244
|
+
dropped.push(className);
|
|
256
245
|
result = `<${className}>`;
|
|
257
246
|
}
|
|
258
247
|
}
|
|
@@ -271,6 +260,35 @@ var init_serialize = __esm({
|
|
|
271
260
|
}
|
|
272
261
|
});
|
|
273
262
|
|
|
263
|
+
// src/randomUuid.ts
|
|
264
|
+
function randomUuid() {
|
|
265
|
+
const globalCrypto = globalThis.crypto;
|
|
266
|
+
if (typeof globalCrypto?.randomUUID === "function") {
|
|
267
|
+
try {
|
|
268
|
+
return globalCrypto.randomUUID();
|
|
269
|
+
} catch {
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
warnOnce(
|
|
273
|
+
"crypto-unavailable",
|
|
274
|
+
"global crypto.randomUUID is unavailable; using a non-cryptographic fallback for trace/span ids. Tracing works normally (ids are correlation-only, not security-sensitive)."
|
|
275
|
+
);
|
|
276
|
+
return fallbackUuidV4();
|
|
277
|
+
}
|
|
278
|
+
function fallbackUuidV4() {
|
|
279
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (char) => {
|
|
280
|
+
const rand = Math.random() * 16 | 0;
|
|
281
|
+
const value = char === "x" ? rand : rand & 3 | 8;
|
|
282
|
+
return value.toString(16);
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
var init_randomUuid = __esm({
|
|
286
|
+
"src/randomUuid.ts"() {
|
|
287
|
+
"use strict";
|
|
288
|
+
init_warnOnce();
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
|
|
274
292
|
// src/replayContext.ts
|
|
275
293
|
function getReplayContext() {
|
|
276
294
|
return replayContextStorage?.getStore() ?? null;
|
|
@@ -601,7 +619,7 @@ registerAsyncLocalStorageClass(
|
|
|
601
619
|
);
|
|
602
620
|
|
|
603
621
|
// src/version.generated.ts
|
|
604
|
-
var __version__ = "0.26.
|
|
622
|
+
var __version__ = "0.26.2";
|
|
605
623
|
|
|
606
624
|
// src/constants.ts
|
|
607
625
|
var DEFAULT_SERVICE_URL = "https://bitfab.ai";
|
|
@@ -1043,6 +1061,62 @@ var HttpClient = class {
|
|
|
1043
1061
|
}
|
|
1044
1062
|
};
|
|
1045
1063
|
|
|
1064
|
+
// src/processorPayload.ts
|
|
1065
|
+
init_serialize();
|
|
1066
|
+
init_warnOnce();
|
|
1067
|
+
var SERIALIZATION_DEGRADED_STEP = "serialization_degraded";
|
|
1068
|
+
function degradedError(dropped) {
|
|
1069
|
+
const names = [...new Set(dropped)].sort().join(", ");
|
|
1070
|
+
return {
|
|
1071
|
+
source: "sdk",
|
|
1072
|
+
step: SERIALIZATION_DEGRADED_STEP,
|
|
1073
|
+
error: `non-replayable: could not faithfully capture ${names}`
|
|
1074
|
+
};
|
|
1075
|
+
}
|
|
1076
|
+
var ENVELOPE_FIELDS = [
|
|
1077
|
+
"type",
|
|
1078
|
+
"source",
|
|
1079
|
+
"traceFunctionKey",
|
|
1080
|
+
"sourceTraceId",
|
|
1081
|
+
"completed"
|
|
1082
|
+
];
|
|
1083
|
+
function rebuildEnvelope(payload, bodyKey, placeholder) {
|
|
1084
|
+
const rebuilt = {};
|
|
1085
|
+
for (const k of ENVELOPE_FIELDS) {
|
|
1086
|
+
if (k in payload) {
|
|
1087
|
+
rebuilt[k] = payload[k];
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
rebuilt[bodyKey] = { serialized: placeholder };
|
|
1091
|
+
return rebuilt;
|
|
1092
|
+
}
|
|
1093
|
+
function finalizeSpanPayload(payload, extraDropped) {
|
|
1094
|
+
const { safe, dropped } = toJsonSafeReport(payload);
|
|
1095
|
+
const allDropped = [...extraDropped ?? [], ...dropped];
|
|
1096
|
+
const collapsed = safe === null || typeof safe !== "object" || Array.isArray(safe);
|
|
1097
|
+
const result = collapsed ? rebuildEnvelope(payload, "rawSpan", safe) : safe;
|
|
1098
|
+
if (allDropped.length > 0) {
|
|
1099
|
+
const existing = result.errors;
|
|
1100
|
+
const errors = Array.isArray(existing) ? existing : [];
|
|
1101
|
+
errors.push(degradedError(allDropped));
|
|
1102
|
+
result.errors = errors;
|
|
1103
|
+
}
|
|
1104
|
+
return result;
|
|
1105
|
+
}
|
|
1106
|
+
function finalizeTracePayload(payload) {
|
|
1107
|
+
const { safe, dropped } = toJsonSafeReport(payload);
|
|
1108
|
+
const collapsed = safe === null || typeof safe !== "object" || Array.isArray(safe);
|
|
1109
|
+
const result = collapsed ? rebuildEnvelope(payload, "externalTrace", safe) : safe;
|
|
1110
|
+
if (dropped.length > 0 || collapsed) {
|
|
1111
|
+
const names = dropped.length > 0 ? [...new Set(dropped)].sort().join(", ") : "trace";
|
|
1112
|
+
warnOnce(
|
|
1113
|
+
`finalizeTrace:${names.replace(/\d+/g, "N")}`,
|
|
1114
|
+
`a trace held non-serializable value(s) (${names}); they were captured as placeholders, so the trace may not be replayable.`
|
|
1115
|
+
);
|
|
1116
|
+
}
|
|
1117
|
+
return result;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1046
1120
|
// src/claudeAgentSdk.ts
|
|
1047
1121
|
init_randomUuid();
|
|
1048
1122
|
init_serialize();
|
|
@@ -1172,6 +1246,7 @@ var BitfabClaudeAgentHandler = class {
|
|
|
1172
1246
|
// ── span helpers ─────────────────────────────────────────────
|
|
1173
1247
|
startSpan(spanId, name, spanType, inputData, parentId) {
|
|
1174
1248
|
const traceId = this.ensureTrace();
|
|
1249
|
+
const { safe: safeInput, dropped: inputDropped } = toJsonSafeReport(inputData);
|
|
1175
1250
|
const spanInfo = {
|
|
1176
1251
|
spanId,
|
|
1177
1252
|
traceId,
|
|
@@ -1179,9 +1254,12 @@ var BitfabClaudeAgentHandler = class {
|
|
|
1179
1254
|
startedAt: nowIso(),
|
|
1180
1255
|
name,
|
|
1181
1256
|
type: spanType,
|
|
1182
|
-
input:
|
|
1257
|
+
input: safeInput,
|
|
1183
1258
|
contexts: []
|
|
1184
1259
|
};
|
|
1260
|
+
if (inputDropped.length > 0) {
|
|
1261
|
+
spanInfo.dropped = [...inputDropped];
|
|
1262
|
+
}
|
|
1185
1263
|
this.runToSpan.set(spanId, spanInfo);
|
|
1186
1264
|
return spanInfo;
|
|
1187
1265
|
}
|
|
@@ -1192,7 +1270,11 @@ var BitfabClaudeAgentHandler = class {
|
|
|
1192
1270
|
}
|
|
1193
1271
|
this.runToSpan.delete(spanId);
|
|
1194
1272
|
spanInfo.endedAt = nowIso();
|
|
1195
|
-
|
|
1273
|
+
const { safe: safeOutput, dropped: outputDropped } = toJsonSafeReport(output);
|
|
1274
|
+
spanInfo.output = safeOutput;
|
|
1275
|
+
if (outputDropped.length > 0) {
|
|
1276
|
+
spanInfo.dropped = [...spanInfo.dropped ?? [], ...outputDropped];
|
|
1277
|
+
}
|
|
1196
1278
|
if (error !== void 0) {
|
|
1197
1279
|
spanInfo.error = error;
|
|
1198
1280
|
}
|
|
@@ -1235,8 +1317,9 @@ var BitfabClaudeAgentHandler = class {
|
|
|
1235
1317
|
sourceTraceId: spanInfo.traceId,
|
|
1236
1318
|
rawSpan
|
|
1237
1319
|
};
|
|
1320
|
+
const finalized = finalizeSpanPayload(payload, spanInfo.dropped);
|
|
1238
1321
|
try {
|
|
1239
|
-
this.httpClient.sendExternalSpan(
|
|
1322
|
+
this.httpClient.sendExternalSpan(finalized);
|
|
1240
1323
|
} catch {
|
|
1241
1324
|
}
|
|
1242
1325
|
}
|
|
@@ -1263,8 +1346,9 @@ var BitfabClaudeAgentHandler = class {
|
|
|
1263
1346
|
externalTrace,
|
|
1264
1347
|
completed
|
|
1265
1348
|
};
|
|
1349
|
+
const finalized = finalizeTracePayload(traceData);
|
|
1266
1350
|
try {
|
|
1267
|
-
this.httpClient.sendExternalTrace(
|
|
1351
|
+
this.httpClient.sendExternalTrace(finalized);
|
|
1268
1352
|
} catch {
|
|
1269
1353
|
}
|
|
1270
1354
|
}
|
|
@@ -1902,7 +1986,6 @@ var LANGGRAPH_METADATA_KEYS = [
|
|
|
1902
1986
|
function nowIso2() {
|
|
1903
1987
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
1904
1988
|
}
|
|
1905
|
-
var safeSerialize2 = toJsonSafe;
|
|
1906
1989
|
function convertMessage(message) {
|
|
1907
1990
|
if (typeof message !== "object" || message === null) {
|
|
1908
1991
|
return { role: "unknown", content: String(message) };
|
|
@@ -2147,6 +2230,7 @@ var BitfabLangGraphCallbackHandler = class {
|
|
|
2147
2230
|
}
|
|
2148
2231
|
const lgMetadata = extractLangGraphMetadata(metadata);
|
|
2149
2232
|
const contexts = Object.keys(lgMetadata).length > 0 ? [lgMetadata] : [];
|
|
2233
|
+
const { safe: safeInput, dropped: inputDropped } = toJsonSafeReport(inputData);
|
|
2150
2234
|
const spanInfo = {
|
|
2151
2235
|
spanId: runId,
|
|
2152
2236
|
traceId: invocation.traceId,
|
|
@@ -2155,9 +2239,12 @@ var BitfabLangGraphCallbackHandler = class {
|
|
|
2155
2239
|
startedAt: nowIso2(),
|
|
2156
2240
|
name,
|
|
2157
2241
|
type: spanType,
|
|
2158
|
-
input:
|
|
2242
|
+
input: safeInput,
|
|
2159
2243
|
contexts
|
|
2160
2244
|
};
|
|
2245
|
+
if (inputDropped.length > 0) {
|
|
2246
|
+
spanInfo.dropped = [...inputDropped];
|
|
2247
|
+
}
|
|
2161
2248
|
if (willHide) {
|
|
2162
2249
|
spanInfo.hidden = true;
|
|
2163
2250
|
}
|
|
@@ -2171,7 +2258,11 @@ var BitfabLangGraphCallbackHandler = class {
|
|
|
2171
2258
|
}
|
|
2172
2259
|
this.runToSpan.delete(runId);
|
|
2173
2260
|
spanInfo.endedAt = nowIso2();
|
|
2174
|
-
|
|
2261
|
+
const { safe: safeOutput, dropped: outputDropped } = toJsonSafeReport(output);
|
|
2262
|
+
spanInfo.output = safeOutput;
|
|
2263
|
+
if (outputDropped.length > 0) {
|
|
2264
|
+
spanInfo.dropped = [...spanInfo.dropped ?? [], ...outputDropped];
|
|
2265
|
+
}
|
|
2175
2266
|
if (error !== void 0) {
|
|
2176
2267
|
spanInfo.error = error;
|
|
2177
2268
|
}
|
|
@@ -2222,8 +2313,9 @@ var BitfabLangGraphCallbackHandler = class {
|
|
|
2222
2313
|
sourceTraceId: spanInfo.traceId,
|
|
2223
2314
|
rawSpan
|
|
2224
2315
|
};
|
|
2316
|
+
const finalized = finalizeSpanPayload(payload, spanInfo.dropped);
|
|
2225
2317
|
try {
|
|
2226
|
-
this.httpClient.sendExternalSpan(
|
|
2318
|
+
this.httpClient.sendExternalSpan(finalized);
|
|
2227
2319
|
} catch {
|
|
2228
2320
|
}
|
|
2229
2321
|
}
|
|
@@ -2241,8 +2333,9 @@ var BitfabLangGraphCallbackHandler = class {
|
|
|
2241
2333
|
},
|
|
2242
2334
|
completed
|
|
2243
2335
|
};
|
|
2336
|
+
const finalized = finalizeTracePayload(traceData);
|
|
2244
2337
|
try {
|
|
2245
|
-
this.httpClient.sendExternalTrace(
|
|
2338
|
+
this.httpClient.sendExternalTrace(finalized);
|
|
2246
2339
|
} catch {
|
|
2247
2340
|
}
|
|
2248
2341
|
}
|
|
@@ -2757,7 +2850,7 @@ var BitfabOpenAITracingProcessor = class {
|
|
|
2757
2850
|
if (errors.length > 0) {
|
|
2758
2851
|
payload.errors = errors;
|
|
2759
2852
|
}
|
|
2760
|
-
return payload;
|
|
2853
|
+
return finalizeSpanPayload(payload);
|
|
2761
2854
|
}
|
|
2762
2855
|
/**
|
|
2763
2856
|
* Send span to Bitfab API (fire-and-forget).
|