bitfab 0.54.10 → 0.54.12

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.
@@ -6,7 +6,7 @@ import {
6
6
  replayContextReady,
7
7
  runWithReplayContext,
8
8
  warnOnce
9
- } from "./chunk-B2O33DBH.js";
9
+ } from "./chunk-WKXLCFLT.js";
10
10
  import {
11
11
  runWithCaptureSuppressed
12
12
  } from "./chunk-VCRFFCLY.js";
@@ -1257,4 +1257,4 @@ export {
1257
1257
  sleepForReplayPersistence,
1258
1258
  replay
1259
1259
  };
1260
- //# sourceMappingURL=chunk-PRXW4B5X.js.map
1260
+ //# sourceMappingURL=chunk-ZR4HGK6G.js.map
@@ -6,7 +6,7 @@ import {
6
6
  flushTraces,
7
7
  parseRetryAfterMs,
8
8
  serializePayloadBody
9
- } from "./chunk-B2O33DBH.js";
9
+ } from "./chunk-WKXLCFLT.js";
10
10
  import "./chunk-VCRFFCLY.js";
11
11
  export {
12
12
  BitfabError,
@@ -17,4 +17,4 @@ export {
17
17
  parseRetryAfterMs,
18
18
  serializePayloadBody
19
19
  };
20
- //# sourceMappingURL=http-AVWWAMFV.js.map
20
+ //# sourceMappingURL=http-NWSSB5FA.js.map
@@ -6,7 +6,7 @@ import {
6
6
  flushTraces,
7
7
  parseRetryAfterMs,
8
8
  serializePayloadBody
9
- } from "./chunk-XLWQOUOP.js";
9
+ } from "./chunk-VTFBDA3O.js";
10
10
  export {
11
11
  BitfabError,
12
12
  HttpClient,
@@ -16,4 +16,4 @@ export {
16
16
  parseRetryAfterMs,
17
17
  serializePayloadBody
18
18
  };
19
- //# sourceMappingURL=http-DH3O3L5X.js.map
19
+ //# sourceMappingURL=http-RJH6VYAM.js.map
package/dist/index.cjs CHANGED
@@ -51,7 +51,7 @@ var __version__, __packageName__;
51
51
  var init_version_generated = __esm({
52
52
  "src/version.generated.ts"() {
53
53
  "use strict";
54
- __version__ = "0.54.10";
54
+ __version__ = "0.54.12";
55
55
  __packageName__ = "bitfab";
56
56
  }
57
57
  });
@@ -77,20 +77,20 @@ var init_traceCompletion = __esm({
77
77
  this.closed = /* @__PURE__ */ new Map();
78
78
  }
79
79
  state(traceId) {
80
- let state = this.traces.get(traceId);
81
- if (state === void 0) {
82
- state = { spanIds: /* @__PURE__ */ new Set(), active: /* @__PURE__ */ new Set() };
83
- this.traces.set(traceId, state);
80
+ let state2 = this.traces.get(traceId);
81
+ if (state2 === void 0) {
82
+ state2 = { spanIds: /* @__PURE__ */ new Set(), active: /* @__PURE__ */ new Set() };
83
+ this.traces.set(traceId, state2);
84
84
  }
85
- return state;
85
+ return state2;
86
86
  }
87
87
  start(traceId, spanId) {
88
88
  if (this.closed.has(traceId)) {
89
89
  return;
90
90
  }
91
- const state = this.state(traceId);
92
- state.spanIds.add(spanId);
93
- state.active.add(spanId);
91
+ const state2 = this.state(traceId);
92
+ state2.spanIds.add(spanId);
93
+ state2.active.add(spanId);
94
94
  }
95
95
  open(traceId) {
96
96
  if (!this.closed.has(traceId)) {
@@ -106,24 +106,24 @@ var init_traceCompletion = __esm({
106
106
  }
107
107
  }
108
108
  end(traceId, spanId) {
109
- const state = this.traces.get(traceId);
110
- if (state !== void 0) {
111
- state.active.delete(spanId);
112
- this.drain(traceId, state);
109
+ const state2 = this.traces.get(traceId);
110
+ if (state2 !== void 0) {
111
+ state2.active.delete(spanId);
112
+ this.drain(traceId, state2);
113
113
  }
114
114
  }
115
115
  abort(traceId, spanId) {
116
- const state = this.traces.get(traceId);
117
- if (state === void 0) {
116
+ const state2 = this.traces.get(traceId);
117
+ if (state2 === void 0) {
118
118
  return;
119
119
  }
120
- state.active.delete(spanId);
121
- state.spanIds.delete(spanId);
122
- if (state.active.size === 0 && state.spanIds.size === 0 && state.complete === void 0) {
120
+ state2.active.delete(spanId);
121
+ state2.spanIds.delete(spanId);
122
+ if (state2.active.size === 0 && state2.spanIds.size === 0 && state2.complete === void 0) {
123
123
  this.traces.delete(traceId);
124
124
  return;
125
125
  }
126
- this.drain(traceId, state);
126
+ this.drain(traceId, state2);
127
127
  }
128
128
  close(traceId, complete, dropped = false) {
129
129
  const count = this.closed.get(traceId);
@@ -131,29 +131,29 @@ var init_traceCompletion = __esm({
131
131
  complete(count);
132
132
  return;
133
133
  }
134
- const state = this.traces.get(traceId);
135
- if (state === void 0) {
134
+ const state2 = this.traces.get(traceId);
135
+ if (state2 === void 0) {
136
136
  return;
137
137
  }
138
- state.complete = complete;
138
+ state2.complete = complete;
139
139
  if (dropped) {
140
- state.active.clear();
140
+ state2.active.clear();
141
141
  }
142
- this.drain(traceId, state);
142
+ this.drain(traceId, state2);
143
143
  }
144
- drain(traceId, state) {
145
- if (state.active.size !== 0 || state.complete === void 0) {
144
+ drain(traceId, state2) {
145
+ if (state2.active.size !== 0 || state2.complete === void 0) {
146
146
  return;
147
147
  }
148
148
  this.traces.delete(traceId);
149
- this.closed.set(traceId, state.spanIds.size);
149
+ this.closed.set(traceId, state2.spanIds.size);
150
150
  if (this.closed.size > 1024) {
151
151
  const oldest = this.closed.keys().next().value;
152
152
  if (oldest !== void 0) {
153
153
  this.closed.delete(oldest);
154
154
  }
155
155
  }
156
- state.complete(state.spanIds.size);
156
+ state2.complete(state2.spanIds.size);
157
157
  }
158
158
  };
159
159
  }
@@ -404,8 +404,8 @@ function text(value) {
404
404
  const trimmed = value?.trim();
405
405
  return trimmed ? trimmed : null;
406
406
  }
407
- function isEmptyGitState(state) {
408
- return Object.values(state).every((value) => value === null);
407
+ function isEmptyGitState(state2) {
408
+ return Object.values(state2).every((value) => value === null);
409
409
  }
410
410
  async function resolveGitState(cwd) {
411
411
  const git = await gitRunner({
@@ -426,14 +426,14 @@ async function resolveGitState(cwd) {
426
426
  if (!root) {
427
427
  return null;
428
428
  }
429
- const state = {
429
+ const state2 = {
430
430
  githubEmail: text(email),
431
431
  branch: text(branch),
432
432
  commitSha: sha(commitSha),
433
433
  baseSha: sha(baseSha),
434
434
  experimentSha: await resolveWorkingTreeSha(run, root.trim())
435
435
  };
436
- return isEmptyGitState(state) ? null : state;
436
+ return isEmptyGitState(state2) ? null : state2;
437
437
  }
438
438
  async function resolveWorkingTreeSha(run, root) {
439
439
  let indexPath;
@@ -6980,6 +6980,83 @@ var BitfabOpenAIAgentHandler = class {
6980
6980
  }
6981
6981
  };
6982
6982
 
6983
+ // src/openaiAgentsSpanContext.ts
6984
+ var OPENAI_AGENTS_CONTEXT_STORAGE = /* @__PURE__ */ Symbol.for(
6985
+ "openai.agents.core.asyncLocalStorage"
6986
+ );
6987
+ var MAX_OPENAI_AGENTS_SPAN_CHAIN = 64;
6988
+ var spanGlobal = globalThis;
6989
+ var state = spanGlobal.__bitfabOpenAiAgentsSpansV1 ?? {
6990
+ bitfabTraceIds: /* @__PURE__ */ new Map(),
6991
+ endedSpanIds: /* @__PURE__ */ new Map()
6992
+ };
6993
+ spanGlobal.__bitfabOpenAiAgentsSpansV1 = state;
6994
+ function mapOpenAiAgentsTrace(agentsTraceId, bitfabTraceId) {
6995
+ state.bitfabTraceIds.set(agentsTraceId, bitfabTraceId);
6996
+ }
6997
+ function unmapOpenAiAgentsTrace(agentsTraceId) {
6998
+ state.bitfabTraceIds.delete(agentsTraceId);
6999
+ state.endedSpanIds.delete(agentsTraceId);
7000
+ }
7001
+ function endOpenAiAgentsSpan(agentsTraceId, spanId) {
7002
+ if (!state.bitfabTraceIds.has(agentsTraceId)) {
7003
+ return;
7004
+ }
7005
+ const ended = state.endedSpanIds.get(agentsTraceId) ?? /* @__PURE__ */ new Set();
7006
+ ended.add(spanId);
7007
+ state.endedSpanIds.set(agentsTraceId, ended);
7008
+ }
7009
+ function isOpenAiAgentsContextStorage(value) {
7010
+ return value !== null && typeof value === "object" && typeof value.getStore === "function";
7011
+ }
7012
+ function currentOpenAiAgentsSpan() {
7013
+ const storage2 = spanGlobal[OPENAI_AGENTS_CONTEXT_STORAGE];
7014
+ if (!isOpenAiAgentsContextStorage(storage2)) {
7015
+ return void 0;
7016
+ }
7017
+ try {
7018
+ const store = storage2.getStore();
7019
+ return store?.active === true ? store.span ?? void 0 : void 0;
7020
+ } catch {
7021
+ return void 0;
7022
+ }
7023
+ }
7024
+ function currentOpenAiAgentsSpans() {
7025
+ const spans = [];
7026
+ let span = currentOpenAiAgentsSpan();
7027
+ while (span !== void 0 && spans.length < MAX_OPENAI_AGENTS_SPAN_CHAIN) {
7028
+ spans.push(span);
7029
+ span = span.previousSpan ?? void 0;
7030
+ }
7031
+ return spans;
7032
+ }
7033
+ function openAiAgentsSpanChain() {
7034
+ if (state.bitfabTraceIds.size === 0) {
7035
+ return [];
7036
+ }
7037
+ return currentOpenAiAgentsSpans().map((span) => span.spanId).filter((spanId) => typeof spanId === "string");
7038
+ }
7039
+ function openAiAgentsParentSpanId(bitfabTraceId, enclosingSpanIds) {
7040
+ if (state.bitfabTraceIds.size === 0) {
7041
+ return void 0;
7042
+ }
7043
+ for (const span of currentOpenAiAgentsSpans()) {
7044
+ if (typeof span.spanId !== "string" || typeof span.traceId !== "string") {
7045
+ return void 0;
7046
+ }
7047
+ if (state.bitfabTraceIds.get(span.traceId) !== bitfabTraceId) {
7048
+ return void 0;
7049
+ }
7050
+ if (enclosingSpanIds?.includes(span.spanId)) {
7051
+ return void 0;
7052
+ }
7053
+ if (!state.endedSpanIds.get(span.traceId)?.has(span.spanId)) {
7054
+ return span.spanId;
7055
+ }
7056
+ }
7057
+ return void 0;
7058
+ }
7059
+
6983
7060
  // src/client.ts
6984
7061
  init_policyRefresh();
6985
7062
  init_randomUuid();
@@ -7129,18 +7206,42 @@ var RIVET_TOP_LEVEL_EFFECTS = [
7129
7206
  "broadcast",
7130
7207
  "saveState",
7131
7208
  "sleep",
7132
- "destroy"
7209
+ "destroy",
7210
+ "step",
7211
+ "tryStep",
7212
+ "try",
7213
+ "loop",
7214
+ "sleepUntil",
7215
+ "rollbackCheckpoint",
7216
+ "join",
7217
+ "race",
7218
+ "removed",
7219
+ "getVersion"
7133
7220
  ];
7134
7221
  var TOP_LEVEL_UNAVAILABLE_CAPABILITIES = /* @__PURE__ */ new Set([
7135
7222
  "conn",
7136
7223
  "conns",
7137
- "log",
7138
7224
  "request",
7139
7225
  "actorRuntimeSocket",
7140
7226
  "keepAwake",
7141
7227
  "waitUntil",
7142
7228
  "client"
7143
7229
  ]);
7230
+ var replayLog = () => void 0;
7231
+ var replayLogger = {
7232
+ level: "silent",
7233
+ msgPrefix: void 0,
7234
+ fatal: replayLog,
7235
+ trace: replayLog,
7236
+ silent: replayLog,
7237
+ debug: replayLog,
7238
+ info: replayLog,
7239
+ warn: replayLog,
7240
+ error: replayLog,
7241
+ child: () => replayLogger,
7242
+ bindings: () => ({}),
7243
+ isLevelEnabled: () => false
7244
+ };
7144
7245
  var SYNC_VOID_EFFECTS = /* @__PURE__ */ new Set([
7145
7246
  "broadcast",
7146
7247
  "sleep",
@@ -7170,16 +7271,28 @@ function snapshotContext(context) {
7170
7271
  "state",
7171
7272
  "vars",
7172
7273
  "actorId",
7274
+ "workflowId",
7173
7275
  "name",
7174
7276
  "key",
7175
- "region",
7176
- "aborted"
7277
+ "region"
7177
7278
  ]) {
7178
7279
  const value = readProperty(source, property);
7179
7280
  if (value !== void 0) {
7180
7281
  snapshot[property] = value;
7181
7282
  }
7182
7283
  }
7284
+ const aborted = readProperty(source, "aborted");
7285
+ if (typeof aborted === "boolean") {
7286
+ snapshot.aborted = aborted;
7287
+ } else {
7288
+ const abortSignal = readProperty(source, "abortSignal");
7289
+ if (isRecord5(abortSignal)) {
7290
+ const signalAborted = readProperty(abortSignal, "aborted");
7291
+ if (typeof signalAborted === "boolean") {
7292
+ snapshot.aborted = signalAborted;
7293
+ }
7294
+ }
7295
+ }
7183
7296
  return snapshot;
7184
7297
  }
7185
7298
  function unavailableCapability(path) {
@@ -7271,7 +7384,8 @@ var BitfabRivetIntegration = class {
7271
7384
  }
7272
7385
  /**
7273
7386
  * Adapt a traced function into a Rivet handler whose first argument is the
7274
- * live actor context. The context is not added to the traced root's inputs.
7387
+ * live actor or workflow context. The context is not added to the traced
7388
+ * root's inputs.
7275
7389
  */
7276
7390
  bind(fn) {
7277
7391
  const integration = this;
@@ -7282,7 +7396,8 @@ var BitfabRivetIntegration = class {
7282
7396
  /**
7283
7397
  * Return the current Rivet context proxy. In production it delegates to the
7284
7398
  * bound live context. During replay it hydrates recorded actor state and
7285
- * intercepts supported effects without requiring a live Rivet actor.
7399
+ * intercepts supported effects without requiring a live Rivet actor or
7400
+ * workflow.
7286
7401
  */
7287
7402
  getContext() {
7288
7403
  const replay2 = getReplayContext();
@@ -7366,6 +7481,12 @@ var BitfabRivetIntegration = class {
7366
7481
  if (property === "setPreventSleep" && replay2) {
7367
7482
  return (_preventSleep) => void 0;
7368
7483
  }
7484
+ if (property === "isEvicted" && replay2) {
7485
+ return () => replayTarget.abortSignal?.aborted === true;
7486
+ }
7487
+ if (property === "log" && replay2) {
7488
+ return replayLogger;
7489
+ }
7369
7490
  if (replay2 && typeof property === "string" && TOP_LEVEL_UNAVAILABLE_CAPABILITIES.has(property)) {
7370
7491
  throw unavailableCapability(property);
7371
7492
  }
@@ -7539,7 +7660,7 @@ var BitfabRivetIntegration = class {
7539
7660
  return { ...value, complete };
7540
7661
  }
7541
7662
  queueCallIsCompletable(effect, args) {
7542
- const options = effect === "queue.waitForNames" ? args[1] : args[0];
7663
+ const options = effect === "queue.waitForNames" || (effect === "queue.next" || effect === "queue.nextBatch") && typeof args[0] === "string" ? args[1] : args[0];
7543
7664
  return isRecord5(options) && options.completable === true;
7544
7665
  }
7545
7666
  createQueueIterator(queue, options) {
@@ -7703,6 +7824,9 @@ var BitfabOpenAITracingProcessor = class {
7703
7824
  const activeContext = this.getActiveSpanContext?.();
7704
7825
  if (activeContext) {
7705
7826
  this.activeSpanMappings[trace.traceId] = activeContext;
7827
+ if (this.shouldRecord()) {
7828
+ mapOpenAiAgentsTrace(trace.traceId, activeContext.traceId);
7829
+ }
7706
7830
  }
7707
7831
  const canonicalTraceId = activeContext?.traceId ?? this.getCanonicalTraceId(trace.traceId);
7708
7832
  this.canonicalTraceIds[trace.traceId] = canonicalTraceId;
@@ -7740,6 +7864,7 @@ var BitfabOpenAITracingProcessor = class {
7740
7864
  }
7741
7865
  this.endedTraces.delete(traceId);
7742
7866
  delete this.activeSpanMappings[traceId];
7867
+ unmapOpenAiAgentsTrace(traceId);
7743
7868
  delete this.canonicalTraceIds[traceId];
7744
7869
  delete this.activeTraces[traceId];
7745
7870
  }
@@ -7764,6 +7889,9 @@ var BitfabOpenAITracingProcessor = class {
7764
7889
  async onSpanEnd(span) {
7765
7890
  const originalTraceId = span.traceId ?? "";
7766
7891
  const traceId = this.activeSpanMappings[originalTraceId]?.traceId ?? originalTraceId;
7892
+ if (span.spanId !== void 0) {
7893
+ endOpenAiAgentsSpan(originalTraceId, span.spanId);
7894
+ }
7767
7895
  try {
7768
7896
  this.sendSpan(span);
7769
7897
  } finally {
@@ -7784,6 +7912,9 @@ var BitfabOpenAITracingProcessor = class {
7784
7912
  * Called when the trace processor is shutting down.
7785
7913
  */
7786
7914
  async shutdown(timeout) {
7915
+ for (const traceId of Object.keys(this.activeSpanMappings)) {
7916
+ unmapOpenAiAgentsTrace(traceId);
7917
+ }
7787
7918
  this.activeTraces = {};
7788
7919
  this.activeSpanMappings = {};
7789
7920
  this.canonicalTraceIds = {};
@@ -8941,16 +9072,16 @@ var Bitfab = class {
8941
9072
  this.simulationPlan.send(payload, rootTraceFunctionKeyOf(payload), submit);
8942
9073
  }
8943
9074
  refreshAutoTraceCapturePolicy(traceFunctionKey) {
8944
- const state = this.autoTracePolicyRefreshes.get(traceFunctionKey) ?? new PolicyRefresh();
8945
- this.autoTracePolicyRefreshes.set(traceFunctionKey, state);
8946
- state.run(
9075
+ const state2 = this.autoTracePolicyRefreshes.get(traceFunctionKey) ?? new PolicyRefresh();
9076
+ this.autoTracePolicyRefreshes.set(traceFunctionKey, state2);
9077
+ state2.run(
8947
9078
  () => this.httpClient.getAutoTracePolicy(
8948
9079
  traceFunctionKey,
8949
9080
  AUTO_TRACE_PROTOCOL
8950
9081
  ),
8951
9082
  (policy) => {
8952
9083
  if (policy.protocol !== AUTO_TRACE_PROTOCOL) {
8953
- state.hold(AUTO_TRACE_POLICY_RETRY_MS);
9084
+ state2.hold(AUTO_TRACE_POLICY_RETRY_MS);
8954
9085
  return;
8955
9086
  }
8956
9087
  const functionIds = Array.isArray(policy.functionIds) ? policy.functionIds.filter(
@@ -8961,10 +9092,10 @@ var Bitfab = class {
8961
9092
  traceFunctionKey,
8962
9093
  policy.revision === null ? void 0 : functionIds
8963
9094
  );
8964
- state.hold(AUTO_TRACE_POLICY_REFRESH_MS);
9095
+ state2.hold(AUTO_TRACE_POLICY_REFRESH_MS);
8965
9096
  },
8966
9097
  () => {
8967
- state.hold(AUTO_TRACE_POLICY_RETRY_MS);
9098
+ state2.hold(AUTO_TRACE_POLICY_RETRY_MS);
8968
9099
  }
8969
9100
  );
8970
9101
  }
@@ -9270,9 +9401,9 @@ var Bitfab = class {
9270
9401
  });
9271
9402
  }
9272
9403
  /**
9273
- * Get the first-class Rivet actor-context integration for an existing trace
9274
- * root. The integration binds context and records effect spans; it never
9275
- * creates another root.
9404
+ * Get the first-class Rivet actor/workflow-context integration for an
9405
+ * existing trace root. The integration binds context and records effect
9406
+ * spans; it never creates another root.
9276
9407
  *
9277
9408
  * @param traceFunctionKey - Key used by the enclosing `withTrace()` root
9278
9409
  * @param options - Explicit per-context-path replay mocking policy
@@ -9575,7 +9706,11 @@ var Bitfab = class {
9575
9706
  const seedCtxForTraceId = parentContext ? null : getSeedContext();
9576
9707
  const traceId = parentContext?.traceId ?? replayCtxForTraceId?.traceId ?? seedCtxForTraceId?.traceId ?? randomUuid();
9577
9708
  const spanId = randomUuid();
9578
- const parentSpanId = parentContext?.spanId ?? null;
9709
+ const openAiAgentsParent = parentContext !== void 0 && options.instrumentation === "trace" ? openAiAgentsParentSpanId(
9710
+ parentContext.traceId,
9711
+ parentContext.openAiAgentsSpanIds
9712
+ ) : void 0;
9713
+ const parentSpanId = openAiAgentsParent ?? parentContext?.spanId ?? null;
9579
9714
  const isRootSpan = parentSpanId === null;
9580
9715
  if (options.enclosingTrace !== void 0) {
9581
9716
  options.enclosingTrace.link.traceId = traceId;
@@ -9589,11 +9724,13 @@ var Bitfab = class {
9589
9724
  parentContext?.surface,
9590
9725
  traceFunctionKey
9591
9726
  );
9727
+ const openAiAgentsSpanIds = openAiAgentsSpanChain();
9592
9728
  const newContext = {
9593
9729
  traceId,
9594
9730
  spanId,
9595
9731
  contexts: [],
9596
- ...surface !== void 0 && { surface }
9732
+ ...surface !== void 0 && { surface },
9733
+ ...openAiAgentsSpanIds.length > 0 && { openAiAgentsSpanIds }
9597
9734
  };
9598
9735
  newStack = [...currentStack, newContext];
9599
9736
  const inputs = args;