bitfab 0.67.0 → 0.68.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.
Files changed (54) hide show
  1. package/dist/{autoTrace-CQw0qMBt.cjs → autoTrace-D3-OZcmR.cjs} +265 -4
  2. package/dist/autoTrace-D3-OZcmR.cjs.map +1 -0
  3. package/dist/{autoTrace-O40k8f5M.js → autoTrace-ghnojSj9.js} +230 -5
  4. package/dist/autoTrace-ghnojSj9.js.map +1 -0
  5. package/dist/autoTrace.cjs +4 -1
  6. package/dist/autoTrace.d.cts +36 -0
  7. package/dist/autoTrace.d.ts +36 -0
  8. package/dist/autoTrace.js +1 -1
  9. package/dist/{babelPlugin-ZR9ilYct.cjs → babelPlugin-0uOq-j1Q.cjs} +86 -2
  10. package/dist/babelPlugin-0uOq-j1Q.cjs.map +1 -0
  11. package/dist/{babelPlugin-CBjx6aJe.js → babelPlugin-Muq0uuuu.js} +86 -2
  12. package/dist/babelPlugin-Muq0uuuu.js.map +1 -0
  13. package/dist/{http-CcYPHER5.js → http-f8Rl8oRa.js} +3 -3
  14. package/dist/{http-CcYPHER5.js.map → http-f8Rl8oRa.js.map} +1 -1
  15. package/dist/{http-CxT_WDAh.cjs → http-r1r6injY.cjs} +3 -3
  16. package/dist/{http-CxT_WDAh.cjs.map → http-r1r6injY.cjs.map} +1 -1
  17. package/dist/{index-BFgtvRni.d.cts → index-BQV7zzJx.d.cts} +98 -2
  18. package/dist/{index-BFgtvRni.d.ts → index-BQV7zzJx.d.ts} +98 -2
  19. package/dist/index.cjs +2 -2
  20. package/dist/index.d.cts +2 -2
  21. package/dist/index.d.ts +2 -2
  22. package/dist/index.js +2 -2
  23. package/dist/node.cjs +3 -3
  24. package/dist/node.d.cts +2 -2
  25. package/dist/node.d.ts +2 -2
  26. package/dist/node.js +3 -3
  27. package/dist/registryCommand-Dk4Y1ZgW.js.map +1 -1
  28. package/dist/{src-DXmdXbOL.cjs → src-BYXxPnpE.cjs} +138 -8
  29. package/dist/src-BYXxPnpE.cjs.map +1 -0
  30. package/dist/{src-CFDoTgXw.js → src-Cps3Xs_J.js} +138 -8
  31. package/dist/src-Cps3Xs_J.js.map +1 -0
  32. package/dist/transform/babel.cjs +1 -1
  33. package/dist/transform/babel.d.cts +9 -0
  34. package/dist/transform/babel.d.ts +9 -0
  35. package/dist/transform/babel.js +1 -1
  36. package/dist/transform/loaderRuntime.cjs +2 -2
  37. package/dist/transform/loaderRuntime.js +2 -2
  38. package/dist/transform/nodeLoader.js +85 -1
  39. package/dist/transform/nodeLoader.js.map +1 -1
  40. package/dist/transform/swc.cjs +1 -1
  41. package/dist/transform/swc.js +1 -1
  42. package/dist/transform/unplugin.cjs +2 -2
  43. package/dist/transform/unplugin.js +2 -2
  44. package/dist/{transform-DP1qnD8u.js → transform-CAJyLLe2.js} +2 -2
  45. package/dist/{transform-DP1qnD8u.js.map → transform-CAJyLLe2.js.map} +1 -1
  46. package/dist/{transform-D_pSvPJc.cjs → transform-ClCOpCZ2.cjs} +2 -2
  47. package/dist/{transform-D_pSvPJc.cjs.map → transform-ClCOpCZ2.cjs.map} +1 -1
  48. package/package.json +3 -1
  49. package/dist/autoTrace-CQw0qMBt.cjs.map +0 -1
  50. package/dist/autoTrace-O40k8f5M.js.map +0 -1
  51. package/dist/babelPlugin-CBjx6aJe.js.map +0 -1
  52. package/dist/babelPlugin-ZR9ilYct.cjs.map +0 -1
  53. package/dist/src-CFDoTgXw.js.map +0 -1
  54. package/dist/src-DXmdXbOL.cjs.map +0 -1
@@ -1,6 +1,6 @@
1
1
  const require_bamlPeer = require("./bamlPeer-BUoZgNxZ.cjs");
2
- const require_http = require("./http-CxT_WDAh.cjs");
3
- const require_autoTrace = require("./autoTrace-CQw0qMBt.cjs");
2
+ const require_http = require("./http-r1r6injY.cjs");
3
+ const require_autoTrace = require("./autoTrace-D3-OZcmR.cjs");
4
4
  let superjson = require("superjson");
5
5
  superjson = require_bamlPeer.__toESM(superjson, 1);
6
6
  //#region src/categories.ts
@@ -1407,6 +1407,89 @@ var GradersClient = class {
1407
1407
  }
1408
1408
  };
1409
1409
  //#endregion
1410
+ //#region src/jev.ts
1411
+ const JEV_PROVIDER = "typesafe";
1412
+ const JEV_WATCH_STORAGE_SYMBOL = Symbol.for("bitfab.jevWatchStorage");
1413
+ const repliesRecordedByAutoTrace = /* @__PURE__ */ new WeakSet();
1414
+ function isRecord$3(value) {
1415
+ return typeof value === "object" && value !== null;
1416
+ }
1417
+ function isJevReply(value) {
1418
+ return isRecord$3(value) && typeof value.model === "string" && isRecord$3(value.usage);
1419
+ }
1420
+ function tokenCount(usage, key) {
1421
+ const count = usage[key];
1422
+ return typeof count === "number" ? count : null;
1423
+ }
1424
+ function jevContext(reply, durationMs) {
1425
+ if (!isJevReply(reply)) return null;
1426
+ const context = {
1427
+ provider: JEV_PROVIDER,
1428
+ model: reply.model
1429
+ };
1430
+ const inputTokens = tokenCount(reply.usage, "input_tokens");
1431
+ const outputTokens = tokenCount(reply.usage, "output_tokens");
1432
+ if (inputTokens !== null) context.inputTokens = inputTokens;
1433
+ if (outputTokens !== null) context.outputTokens = outputTokens;
1434
+ context.durationMs = durationMs;
1435
+ return context;
1436
+ }
1437
+ function recordJevReply(span, reply, durationMs) {
1438
+ try {
1439
+ const context = jevContext(reply, durationMs);
1440
+ if (context) span.addContext(context);
1441
+ } catch {}
1442
+ }
1443
+ let jevWatchStorage = null;
1444
+ function watchStorage() {
1445
+ if (jevWatchStorage) return jevWatchStorage;
1446
+ const shared = globalThis;
1447
+ const existing = shared[JEV_WATCH_STORAGE_SYMBOL];
1448
+ jevWatchStorage = existing ?? require_autoTrace.createAsyncLocalStorage();
1449
+ if (jevWatchStorage && !existing) shared[JEV_WATCH_STORAGE_SYMBOL] = jevWatchStorage;
1450
+ return jevWatchStorage;
1451
+ }
1452
+ function watchJevUsage(fn) {
1453
+ const storage = watchStorage();
1454
+ const watch = {
1455
+ recorded: false,
1456
+ parent: storage?.getStore() ?? null
1457
+ };
1458
+ return {
1459
+ watch,
1460
+ result: storage ? storage.run(watch, fn) : fn()
1461
+ };
1462
+ }
1463
+ function markEnclosingWatches(watch) {
1464
+ for (let current = watch.parent; current; current = current.parent) current.recorded = true;
1465
+ }
1466
+ function recordWatchedJevReply(span, watch, reply, durationMs) {
1467
+ if (watch.recorded || isRecordedByAutoTrace(reply)) {
1468
+ markEnclosingWatches(watch);
1469
+ return;
1470
+ }
1471
+ if (!isJevReply(reply)) return;
1472
+ recordJevReply(span, reply, durationMs);
1473
+ repliesRecordedByAutoTrace.add(reply);
1474
+ markEnclosingWatches(watch);
1475
+ }
1476
+ function isRecordedByAutoTrace(reply) {
1477
+ return isRecord$3(reply) && repliesRecordedByAutoTrace.has(reply);
1478
+ }
1479
+ function recordAutoTracedJev(invokeFn, span) {
1480
+ const startedAt = Date.now();
1481
+ const { watch, result } = watchJevUsage(invokeFn);
1482
+ const settle = (reply) => {
1483
+ recordWatchedJevReply(span, watch, reply, Date.now() - startedAt);
1484
+ };
1485
+ if (result instanceof Promise) return result.then((reply) => {
1486
+ settle(reply);
1487
+ return reply;
1488
+ });
1489
+ settle(result);
1490
+ return result;
1491
+ }
1492
+ //#endregion
1410
1493
  //#region src/langgraph.ts
1411
1494
  const LANGSMITH_HIDDEN_TAG = "langsmith:hidden";
1412
1495
  const CHAIN_RUN_TYPES = /* @__PURE__ */ new Set([
@@ -4715,9 +4798,10 @@ function extractContextFromCollector(collector) {
4715
4798
  }
4716
4799
  const BOUND_FUNCTION_NAME_PREFIX = /^bound /;
4717
4800
  function discoveredSpanType(definition, nodeConfiguration) {
4718
- const ownType = definition.baml === true ? "llm" : "function";
4801
+ const recordsModelCall = definition.baml === true || definition.jev === true || definition.openrouter === true;
4802
+ const ownType = recordsModelCall ? "llm" : "function";
4719
4803
  if (nodeConfiguration === void 0) return ownType;
4720
- if (definition.baml === true && nodeConfiguration.defaultType === true) return ownType;
4804
+ if (recordsModelCall && nodeConfiguration.defaultType === true) return ownType;
4721
4805
  return nodeConfiguration.type ?? ownType;
4722
4806
  }
4723
4807
  const collectorsRecordedByAutoTrace = /* @__PURE__ */ new WeakSet();
@@ -5115,7 +5199,7 @@ var Bitfab = class {
5115
5199
  ...nodeConfiguration?.finalize !== void 0 && { finalize: nodeConfiguration.finalize }
5116
5200
  };
5117
5201
  const isAsync = definition.async === true;
5118
- return openChild(entry, childOptions, inputs, isAsync, definition.baml === true ? () => invokeAutoTracedBaml(invokeFn, isAsync) : invokeFn);
5202
+ return openChild(entry, childOptions, inputs, isAsync, definition.baml === true ? () => invokeAutoTracedBaml(invokeFn, isAsync) : definition.jev === true ? () => recordAutoTracedJev(invokeFn, getCurrentSpan()) : definition.openrouter === true ? () => require_autoTrace.recordAutoTracedOpenRouter(invokeFn, inputs[0], getCurrentSpan()) : invokeFn);
5119
5203
  },
5120
5204
  invokeNestedRoot(nestedName, nestedFunctionName, inputs, invokeFn, entry, link, spanDetails) {
5121
5205
  if (excluded.has(nestedName) || excluded.has(nestedFunctionName) || !recordsSpan(entry, nestedName, true)) return invokeFn();
@@ -5399,6 +5483,46 @@ var Bitfab = class {
5399
5483
  });
5400
5484
  return wrappedFn;
5401
5485
  }
5486
+ wrapJev(method, options) {
5487
+ const methodName = method.name.replace(BOUND_FUNCTION_NAME_PREFIX, "");
5488
+ if (!methodName) throw new require_http.BitfabError("wrapJev requires a named function (e.g., jev.systemOne.bind(jev)).");
5489
+ const wrappedFn = async (...args) => {
5490
+ const span = getCurrentSpan();
5491
+ const startedAt = Date.now();
5492
+ const { watch, result } = watchJevUsage(() => method(...args));
5493
+ const reply = await result;
5494
+ recordWatchedJevReply(span, watch, reply, Date.now() - startedAt);
5495
+ try {
5496
+ options?.onReply?.(reply);
5497
+ } catch {}
5498
+ return reply;
5499
+ };
5500
+ Object.defineProperty(wrappedFn, "name", {
5501
+ configurable: true,
5502
+ value: methodName
5503
+ });
5504
+ return wrappedFn;
5505
+ }
5506
+ wrapOpenRouter(method, options) {
5507
+ const methodName = method.name.replace(BOUND_FUNCTION_NAME_PREFIX, "");
5508
+ if (!methodName) throw new require_http.BitfabError("wrapOpenRouter requires a named function (e.g., openai.chat.completions.create.bind(openai.chat.completions)).");
5509
+ const wrappedFn = async (...args) => {
5510
+ const span = getCurrentSpan();
5511
+ const startedAt = Date.now();
5512
+ const { watch, result } = require_autoTrace.watchOpenRouterUsage(() => method(...args));
5513
+ const response = await result;
5514
+ require_autoTrace.recordWatchedOpenRouterCompletion(span, watch, args[0], response, Date.now() - startedAt);
5515
+ try {
5516
+ options?.onResponse?.(response);
5517
+ } catch {}
5518
+ return response;
5519
+ };
5520
+ Object.defineProperty(wrappedFn, "name", {
5521
+ configurable: true,
5522
+ value: methodName
5523
+ });
5524
+ return wrappedFn;
5525
+ }
5402
5526
  withSpan(traceFunctionKey, optionsOrFn, maybeFn) {
5403
5527
  this.simulationPlan.refresh();
5404
5528
  const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
@@ -6035,7 +6159,7 @@ var Bitfab = class {
6035
6159
  await runWithSeedContext({ traceId }, async () => target(...args));
6036
6160
  } finally {
6037
6161
  try {
6038
- const { flushTraces } = await Promise.resolve().then(() => require("./http-CxT_WDAh.cjs")).then((n) => n.http_exports);
6162
+ const { flushTraces } = await Promise.resolve().then(() => require("./http-r1r6injY.cjs")).then((n) => n.http_exports);
6039
6163
  await flushTraces(3e4);
6040
6164
  } finally {
6041
6165
  unrecorded = activeTraceStates.delete(traceId);
@@ -6121,6 +6245,12 @@ var BitfabFunction = class {
6121
6245
  wrapBAML(methodOrClient, maybeMethodOrOptions, maybeOptions) {
6122
6246
  return this.client.wrapBAML(methodOrClient, maybeMethodOrOptions, maybeOptions);
6123
6247
  }
6248
+ wrapJev(method, options) {
6249
+ return this.client.wrapJev(method, options);
6250
+ }
6251
+ wrapOpenRouter(method, options) {
6252
+ return this.client.wrapOpenRouter(method, options);
6253
+ }
6124
6254
  };
6125
6255
  //#endregion
6126
6256
  //#region src/finalizers.ts
@@ -6223,7 +6353,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
6223
6353
  metadata: seedCase.metadata,
6224
6354
  sessionId: seedCase.sessionId
6225
6355
  }));
6226
- const { flushTraces } = await Promise.resolve().then(() => require("./http-CxT_WDAh.cjs")).then((n) => n.http_exports);
6356
+ const { flushTraces } = await Promise.resolve().then(() => require("./http-r1r6injY.cjs")).then((n) => n.http_exports);
6227
6357
  await flushTraces(3e4);
6228
6358
  return {
6229
6359
  pipeline,
@@ -6467,4 +6597,4 @@ Object.defineProperty(exports, "serializeReplayResult", {
6467
6597
  }
6468
6598
  });
6469
6599
 
6470
- //# sourceMappingURL=src-DXmdXbOL.cjs.map
6600
+ //# sourceMappingURL=src-BYXxPnpE.cjs.map