@bitfab/sdk 0.18.2 → 0.19.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/index.d.cts CHANGED
@@ -1063,7 +1063,7 @@ declare class BitfabFunction {
1063
1063
  /**
1064
1064
  * SDK version from package.json (injected at build time)
1065
1065
  */
1066
- declare const __version__ = "0.18.2";
1066
+ declare const __version__ = "0.19.0";
1067
1067
 
1068
1068
  /**
1069
1069
  * Constants for the Bitfab SDK.
package/dist/index.d.ts CHANGED
@@ -1063,7 +1063,7 @@ declare class BitfabFunction {
1063
1063
  /**
1064
1064
  * SDK version from package.json (injected at build time)
1065
1065
  */
1066
- declare const __version__ = "0.18.2";
1066
+ declare const __version__ = "0.19.0";
1067
1067
 
1068
1068
  /**
1069
1069
  * Constants for the Bitfab SDK.
package/dist/index.js CHANGED
@@ -11,10 +11,10 @@ import {
11
11
  flushTraces,
12
12
  getCurrentSpan,
13
13
  getCurrentTrace
14
- } from "./chunk-UTVFKV2Z.js";
14
+ } from "./chunk-FA6DBCAT.js";
15
15
  import {
16
16
  BitfabError
17
- } from "./chunk-PY6V4FE3.js";
17
+ } from "./chunk-EQI6ZJC3.js";
18
18
  export {
19
19
  Bitfab,
20
20
  BitfabClaudeAgentHandler,
package/dist/node.cjs CHANGED
@@ -91,28 +91,6 @@ var init_errors = __esm({
91
91
  }
92
92
  });
93
93
 
94
- // src/replayContext.ts
95
- function getReplayContext() {
96
- return replayContextStorage?.getStore() ?? null;
97
- }
98
- function runWithReplayContext(ctx, fn) {
99
- if (replayContextStorage) {
100
- return replayContextStorage.run(ctx, fn);
101
- }
102
- return fn();
103
- }
104
- var replayContextStorage, replayContextReady;
105
- var init_replayContext = __esm({
106
- "src/replayContext.ts"() {
107
- "use strict";
108
- init_asyncStorage();
109
- replayContextStorage = null;
110
- replayContextReady = asyncStorageReady.then(() => {
111
- replayContextStorage = createAsyncLocalStorage();
112
- });
113
- }
114
- });
115
-
116
94
  // src/serialize.ts
117
95
  function describeValue(value) {
118
96
  try {
@@ -163,12 +141,89 @@ function deserializeValue(serialized) {
163
141
  meta: serialized.meta
164
142
  });
165
143
  }
166
- var import_superjson, MAX_SERIALIZED_BYTES;
144
+ function toJsonSafe(value) {
145
+ return toJsonSafeInner(value, 0, /* @__PURE__ */ new WeakSet());
146
+ }
147
+ function toJsonSafeInner(value, depth, seen) {
148
+ if (value === null || value === void 0) {
149
+ return value;
150
+ }
151
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
152
+ return value;
153
+ }
154
+ const className = value?.constructor?.name ?? typeof value;
155
+ if (depth > MAX_SAFE_DEPTH) {
156
+ return `<${className}>`;
157
+ }
158
+ if (typeof value !== "object") {
159
+ try {
160
+ return String(value);
161
+ } catch {
162
+ return `<${className}>`;
163
+ }
164
+ }
165
+ if (seen.has(value)) {
166
+ return `<cycle ${className}>`;
167
+ }
168
+ seen.add(value);
169
+ let result;
170
+ if (Array.isArray(value)) {
171
+ result = value.map((item) => toJsonSafeInner(item, depth + 1, seen));
172
+ } else if (typeof value.toJSON === "function") {
173
+ try {
174
+ result = toJsonSafeInner(
175
+ value.toJSON(),
176
+ depth + 1,
177
+ seen
178
+ );
179
+ } catch {
180
+ result = `<${className}>`;
181
+ }
182
+ } else {
183
+ try {
184
+ const obj = {};
185
+ for (const [k, v] of Object.entries(value)) {
186
+ if (!k.startsWith("_")) {
187
+ obj[k] = toJsonSafeInner(v, depth + 1, seen);
188
+ }
189
+ }
190
+ result = obj;
191
+ } catch {
192
+ result = `<${className}>`;
193
+ }
194
+ }
195
+ seen.delete(value);
196
+ return result;
197
+ }
198
+ var import_superjson, MAX_SERIALIZED_BYTES, MAX_SAFE_DEPTH;
167
199
  var init_serialize = __esm({
168
200
  "src/serialize.ts"() {
169
201
  "use strict";
170
202
  import_superjson = __toESM(require("superjson"), 1);
171
203
  MAX_SERIALIZED_BYTES = 512e3;
204
+ MAX_SAFE_DEPTH = 6;
205
+ }
206
+ });
207
+
208
+ // src/replayContext.ts
209
+ function getReplayContext() {
210
+ return replayContextStorage?.getStore() ?? null;
211
+ }
212
+ function runWithReplayContext(ctx, fn) {
213
+ if (replayContextStorage) {
214
+ return replayContextStorage.run(ctx, fn);
215
+ }
216
+ return fn();
217
+ }
218
+ var replayContextStorage, replayContextReady;
219
+ var init_replayContext = __esm({
220
+ "src/replayContext.ts"() {
221
+ "use strict";
222
+ init_asyncStorage();
223
+ replayContextStorage = null;
224
+ replayContextReady = asyncStorageReady.then(() => {
225
+ replayContextStorage = createAsyncLocalStorage();
226
+ });
172
227
  }
173
228
  });
174
229
 
@@ -447,13 +502,93 @@ registerAsyncLocalStorageClass(
447
502
  );
448
503
 
449
504
  // src/version.generated.ts
450
- var __version__ = "0.18.2";
505
+ var __version__ = "0.19.0";
451
506
 
452
507
  // src/constants.ts
453
508
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
454
509
 
455
510
  // src/http.ts
456
511
  init_errors();
512
+ function serializePayloadBody(payload) {
513
+ try {
514
+ return { body: JSON.stringify(payload), dropped: [] };
515
+ } catch {
516
+ const dropped = [];
517
+ const sanitize = (value, seen) => {
518
+ const t = typeof value;
519
+ if (value === null || t === "string" || t === "number" || t === "boolean") {
520
+ return value;
521
+ }
522
+ if (t === "bigint") {
523
+ dropped.push("BigInt");
524
+ return "<unserializable: BigInt>";
525
+ }
526
+ if (t === "function") {
527
+ const name = value.name || "Function";
528
+ dropped.push(name);
529
+ return `<unserializable: ${name}>`;
530
+ }
531
+ if (t === "symbol") {
532
+ dropped.push("Symbol");
533
+ return "<unserializable: Symbol>";
534
+ }
535
+ if (t !== "object") {
536
+ return void 0;
537
+ }
538
+ const obj = value;
539
+ const className = obj.constructor?.name || "object";
540
+ if (seen.has(obj)) {
541
+ dropped.push(className);
542
+ return `<cycle: ${className}>`;
543
+ }
544
+ seen.add(obj);
545
+ let result;
546
+ if (Array.isArray(obj)) {
547
+ result = obj.map((item) => sanitize(item, seen));
548
+ } else if (typeof obj.toJSON === "function") {
549
+ try {
550
+ result = sanitize(obj.toJSON(), seen);
551
+ } catch {
552
+ dropped.push(className);
553
+ result = `<unserializable: ${className}>`;
554
+ }
555
+ } else {
556
+ const out = {};
557
+ for (const [k, v] of Object.entries(obj)) {
558
+ out[k] = sanitize(v, seen);
559
+ }
560
+ result = out;
561
+ }
562
+ seen.delete(obj);
563
+ return result;
564
+ };
565
+ let sanitized;
566
+ try {
567
+ sanitized = sanitize(payload, /* @__PURE__ */ new WeakSet());
568
+ } catch (error) {
569
+ const message = error instanceof Error ? error.message : String(error);
570
+ return {
571
+ body: JSON.stringify({ error: `payload_serialize_failed: ${message}` }),
572
+ dropped
573
+ };
574
+ }
575
+ if (dropped.length > 0 && typeof sanitized === "object" && sanitized !== null && !Array.isArray(sanitized)) {
576
+ const obj = sanitized;
577
+ const existing = Array.isArray(obj.errors) ? obj.errors : [];
578
+ obj.errors = [
579
+ ...existing,
580
+ {
581
+ source: "sdk",
582
+ step: "json_serialize",
583
+ error: `stubbed non-serializable value(s): ${[
584
+ ...new Set(dropped)
585
+ ].join(", ")}`
586
+ }
587
+ ];
588
+ }
589
+ return { body: JSON.stringify(sanitized), dropped };
590
+ }
591
+ }
457
592
  var pendingTracePromises = /* @__PURE__ */ new Set();
458
593
  function awaitOnExit(promise) {
459
594
  pendingTracePromises.add(promise);
@@ -512,23 +647,14 @@ var HttpClient = class {
512
647
  const method = options?.method ?? "POST";
513
648
  const controller = new AbortController();
514
649
  const timeoutId = setTimeout(() => controller.abort(), timeout);
515
- let body;
516
- let serializationError;
517
- try {
518
- body = JSON.stringify(payload);
519
- } catch (error) {
520
- serializationError = error instanceof Error ? error.message : String(error);
521
- body = JSON.stringify({
522
- ...Object.fromEntries(
523
- Object.entries(payload).filter(
524
- ([, v]) => typeof v === "string" || typeof v === "number"
525
- )
526
- ),
527
- rawSpan: {},
528
- errors: [
529
- { source: "sdk", step: "json_serialize", error: serializationError }
530
- ]
531
- });
650
+ const { body, dropped } = serializePayloadBody(payload);
651
+ if (dropped.length > 0) {
652
+ try {
653
+ console.warn(
654
+ `Bitfab: request body to ${endpoint} held ${dropped.length} non-serializable value(s) (${[...new Set(dropped)].join(", ")}); they were stubbed so the span still sends, but the trace may be incomplete or not replayable. Capture a JSON-safe projection of this input to make it replayable.`
655
+ );
656
+ } catch {
657
+ }
532
658
  }
533
659
  try {
534
660
  const response = await fetch(url, {
@@ -786,33 +912,11 @@ var HttpClient = class {
786
912
  };
787
913
 
788
914
  // src/claudeAgentSdk.ts
915
+ init_serialize();
789
916
  function nowIso() {
790
917
  return (/* @__PURE__ */ new Date()).toISOString();
791
918
  }
792
- function safeSerialize(value) {
793
- if (value === null || value === void 0) {
794
- return value;
795
- }
796
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
797
- return value;
798
- }
799
- if (Array.isArray(value)) {
800
- return value.map(safeSerialize);
801
- }
802
- if (typeof value === "object") {
803
- if (typeof value.toJSON === "function") {
804
- return value.toJSON();
805
- }
806
- const result = {};
807
- for (const [k, v] of Object.entries(value)) {
808
- if (!k.startsWith("_")) {
809
- result[k] = safeSerialize(v);
810
- }
811
- }
812
- return result;
813
- }
814
- return String(value);
815
- }
919
+ var safeSerialize = toJsonSafe;
816
920
  function extractContentBlocks(content) {
817
921
  if (!Array.isArray(content)) {
818
922
  return [];
@@ -1568,6 +1672,7 @@ function buildSnapshotRef(config, sdkWallClockBeforeFn) {
1568
1672
  }
1569
1673
 
1570
1674
  // src/langgraph.ts
1675
+ init_serialize();
1571
1676
  var LANGSMITH_HIDDEN_TAG = "langsmith:hidden";
1572
1677
  var LANGGRAPH_METADATA_KEYS = [
1573
1678
  "langgraph_step",
@@ -1579,56 +1684,7 @@ var LANGGRAPH_METADATA_KEYS = [
1579
1684
  function nowIso2() {
1580
1685
  return (/* @__PURE__ */ new Date()).toISOString();
1581
1686
  }
1582
- var MAX_SERIALIZE_DEPTH = 6;
1583
- function safeSerialize2(value) {
1584
- return safeSerializeInner(value, 0, /* @__PURE__ */ new WeakSet());
1585
- }
1586
- function safeSerializeInner(value, depth, seen) {
1587
- if (value === null || value === void 0) {
1588
- return value;
1589
- }
1590
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1591
- return value;
1592
- }
1593
- const className = value?.constructor?.name ?? typeof value;
1594
- if (depth > MAX_SERIALIZE_DEPTH) {
1595
- return `<${className}>`;
1596
- }
1597
- if (typeof value === "object") {
1598
- if (seen.has(value)) {
1599
- return `<cycle ${className}>`;
1600
- }
1601
- seen.add(value);
1602
- }
1603
- if (Array.isArray(value)) {
1604
- return value.map((item) => safeSerializeInner(item, depth + 1, seen));
1605
- }
1606
- if (typeof value === "object") {
1607
- if (typeof value.toJSON === "function") {
1608
- try {
1609
- return value.toJSON();
1610
- } catch {
1611
- return `<${className}>`;
1612
- }
1613
- }
1614
- try {
1615
- const result = {};
1616
- for (const [k, v] of Object.entries(value)) {
1617
- if (!k.startsWith("_")) {
1618
- result[k] = safeSerializeInner(v, depth + 1, seen);
1619
- }
1620
- }
1621
- return result;
1622
- } catch {
1623
- return `<${className}>`;
1624
- }
1625
- }
1626
- try {
1627
- return String(value);
1628
- } catch {
1629
- return `<${className}>`;
1630
- }
1631
- }
1687
+ var safeSerialize2 = toJsonSafe;
1632
1688
  function convertMessage(message) {
1633
1689
  if (typeof message !== "object" || message === null) {
1634
1690
  return { role: "unknown", content: String(message) };