bitfab 0.67.0 → 0.68.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.
Files changed (54) hide show
  1. package/dist/{autoTrace-CQw0qMBt.cjs → autoTrace-BikML0lX.cjs} +86 -4
  2. package/dist/autoTrace-BikML0lX.cjs.map +1 -0
  3. package/dist/{autoTrace-O40k8f5M.js → autoTrace-CVt9EDyo.js} +75 -5
  4. package/dist/autoTrace-CVt9EDyo.js.map +1 -0
  5. package/dist/autoTrace.cjs +3 -1
  6. package/dist/autoTrace.d.cts +21 -0
  7. package/dist/autoTrace.d.ts +21 -0
  8. package/dist/autoTrace.js +1 -1
  9. package/dist/{babelPlugin-CBjx6aJe.js → babelPlugin-a7ofCoOd.js} +56 -2
  10. package/dist/babelPlugin-a7ofCoOd.js.map +1 -0
  11. package/dist/{babelPlugin-ZR9ilYct.cjs → babelPlugin-s8EFjT6e.cjs} +56 -2
  12. package/dist/babelPlugin-s8EFjT6e.cjs.map +1 -0
  13. package/dist/{http-CcYPHER5.js → http-_cgR_DM2.js} +3 -3
  14. package/dist/{http-CcYPHER5.js.map → http-_cgR_DM2.js.map} +1 -1
  15. package/dist/{http-CxT_WDAh.cjs → http-psFF1ptn.cjs} +3 -3
  16. package/dist/{http-CxT_WDAh.cjs.map → http-psFF1ptn.cjs.map} +1 -1
  17. package/dist/{index-BFgtvRni.d.cts → index-j7SrvOqe.d.cts} +44 -2
  18. package/dist/{index-BFgtvRni.d.ts → index-j7SrvOqe.d.ts} +44 -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-CFDoTgXw.js → src-DyEKM7yn.js} +115 -8
  29. package/dist/src-DyEKM7yn.js.map +1 -0
  30. package/dist/{src-DXmdXbOL.cjs → src-Dze8o7iU.cjs} +115 -8
  31. package/dist/src-Dze8o7iU.cjs.map +1 -0
  32. package/dist/transform/babel.cjs +1 -1
  33. package/dist/transform/babel.d.cts +2 -0
  34. package/dist/transform/babel.d.ts +2 -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 +55 -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-D_pSvPJc.cjs → transform-BBzrqpVH.cjs} +2 -2
  45. package/dist/{transform-D_pSvPJc.cjs.map → transform-BBzrqpVH.cjs.map} +1 -1
  46. package/dist/{transform-DP1qnD8u.js → transform-DkcFn_tg.js} +2 -2
  47. package/dist/{transform-DP1qnD8u.js.map → transform-DkcFn_tg.js.map} +1 -1
  48. package/package.json +2 -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-psFF1ptn.cjs");
3
+ const require_autoTrace = require("./autoTrace-BikML0lX.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;
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()) : 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,26 @@ 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
+ }
5402
5506
  withSpan(traceFunctionKey, optionsOrFn, maybeFn) {
5403
5507
  this.simulationPlan.refresh();
5404
5508
  const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
@@ -6035,7 +6139,7 @@ var Bitfab = class {
6035
6139
  await runWithSeedContext({ traceId }, async () => target(...args));
6036
6140
  } finally {
6037
6141
  try {
6038
- const { flushTraces } = await Promise.resolve().then(() => require("./http-CxT_WDAh.cjs")).then((n) => n.http_exports);
6142
+ const { flushTraces } = await Promise.resolve().then(() => require("./http-psFF1ptn.cjs")).then((n) => n.http_exports);
6039
6143
  await flushTraces(3e4);
6040
6144
  } finally {
6041
6145
  unrecorded = activeTraceStates.delete(traceId);
@@ -6121,6 +6225,9 @@ var BitfabFunction = class {
6121
6225
  wrapBAML(methodOrClient, maybeMethodOrOptions, maybeOptions) {
6122
6226
  return this.client.wrapBAML(methodOrClient, maybeMethodOrOptions, maybeOptions);
6123
6227
  }
6228
+ wrapJev(method, options) {
6229
+ return this.client.wrapJev(method, options);
6230
+ }
6124
6231
  };
6125
6232
  //#endregion
6126
6233
  //#region src/finalizers.ts
@@ -6223,7 +6330,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
6223
6330
  metadata: seedCase.metadata,
6224
6331
  sessionId: seedCase.sessionId
6225
6332
  }));
6226
- const { flushTraces } = await Promise.resolve().then(() => require("./http-CxT_WDAh.cjs")).then((n) => n.http_exports);
6333
+ const { flushTraces } = await Promise.resolve().then(() => require("./http-psFF1ptn.cjs")).then((n) => n.http_exports);
6227
6334
  await flushTraces(3e4);
6228
6335
  return {
6229
6336
  pipeline,
@@ -6467,4 +6574,4 @@ Object.defineProperty(exports, "serializeReplayResult", {
6467
6574
  }
6468
6575
  });
6469
6576
 
6470
- //# sourceMappingURL=src-DXmdXbOL.cjs.map
6577
+ //# sourceMappingURL=src-Dze8o7iU.cjs.map