bitfab 0.54.10 → 0.54.11

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
@@ -3602,7 +3602,7 @@ interface CommitRef {
3602
3602
  /**
3603
3603
  * SDK version from package.json (injected at build time)
3604
3604
  */
3605
- declare const __version__ = "0.54.10";
3605
+ declare const __version__ = "0.54.11";
3606
3606
 
3607
3607
  /**
3608
3608
  * Constants for the Bitfab SDK.
package/dist/index.d.ts CHANGED
@@ -3602,7 +3602,7 @@ interface CommitRef {
3602
3602
  /**
3603
3603
  * SDK version from package.json (injected at build time)
3604
3604
  */
3605
- declare const __version__ = "0.54.10";
3605
+ declare const __version__ = "0.54.11";
3606
3606
 
3607
3607
  /**
3608
3608
  * Constants for the Bitfab SDK.
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ import {
30
30
  getCurrentTrace,
31
31
  reseedFromRegistry,
32
32
  seedFromRegistry
33
- } from "./chunk-A3OBQOLV.js";
33
+ } from "./chunk-MEJOPEKV.js";
34
34
  import "./chunk-EGWJYCNT.js";
35
35
  import {
36
36
  BITFAB_PROGRESS_PREFIX,
@@ -39,7 +39,7 @@ import {
39
39
  ReplayError,
40
40
  reportReplayProgress,
41
41
  serializeReplayResult
42
- } from "./chunk-PRXW4B5X.js";
42
+ } from "./chunk-G4LWALQ7.js";
43
43
  import {
44
44
  BitfabError,
45
45
  DEFAULT_SERVICE_URL,
@@ -47,7 +47,7 @@ import {
47
47
  MixedTracingError,
48
48
  __version__,
49
49
  flushTraces
50
- } from "./chunk-B2O33DBH.js";
50
+ } from "./chunk-FMUJONTQ.js";
51
51
  import "./chunk-VCRFFCLY.js";
52
52
  export {
53
53
  AssertionCategoriesClient,
package/dist/node.cjs CHANGED
@@ -97,7 +97,7 @@ var __version__, __packageName__;
97
97
  var init_version_generated = __esm({
98
98
  "src/version.generated.ts"() {
99
99
  "use strict";
100
- __version__ = "0.54.10";
100
+ __version__ = "0.54.11";
101
101
  __packageName__ = "bitfab";
102
102
  }
103
103
  });
@@ -123,20 +123,20 @@ var init_traceCompletion = __esm({
123
123
  this.closed = /* @__PURE__ */ new Map();
124
124
  }
125
125
  state(traceId) {
126
- let state = this.traces.get(traceId);
127
- if (state === void 0) {
128
- state = { spanIds: /* @__PURE__ */ new Set(), active: /* @__PURE__ */ new Set() };
129
- this.traces.set(traceId, state);
126
+ let state2 = this.traces.get(traceId);
127
+ if (state2 === void 0) {
128
+ state2 = { spanIds: /* @__PURE__ */ new Set(), active: /* @__PURE__ */ new Set() };
129
+ this.traces.set(traceId, state2);
130
130
  }
131
- return state;
131
+ return state2;
132
132
  }
133
133
  start(traceId, spanId) {
134
134
  if (this.closed.has(traceId)) {
135
135
  return;
136
136
  }
137
- const state = this.state(traceId);
138
- state.spanIds.add(spanId);
139
- state.active.add(spanId);
137
+ const state2 = this.state(traceId);
138
+ state2.spanIds.add(spanId);
139
+ state2.active.add(spanId);
140
140
  }
141
141
  open(traceId) {
142
142
  if (!this.closed.has(traceId)) {
@@ -152,24 +152,24 @@ var init_traceCompletion = __esm({
152
152
  }
153
153
  }
154
154
  end(traceId, spanId) {
155
- const state = this.traces.get(traceId);
156
- if (state !== void 0) {
157
- state.active.delete(spanId);
158
- this.drain(traceId, state);
155
+ const state2 = this.traces.get(traceId);
156
+ if (state2 !== void 0) {
157
+ state2.active.delete(spanId);
158
+ this.drain(traceId, state2);
159
159
  }
160
160
  }
161
161
  abort(traceId, spanId) {
162
- const state = this.traces.get(traceId);
163
- if (state === void 0) {
162
+ const state2 = this.traces.get(traceId);
163
+ if (state2 === void 0) {
164
164
  return;
165
165
  }
166
- state.active.delete(spanId);
167
- state.spanIds.delete(spanId);
168
- if (state.active.size === 0 && state.spanIds.size === 0 && state.complete === void 0) {
166
+ state2.active.delete(spanId);
167
+ state2.spanIds.delete(spanId);
168
+ if (state2.active.size === 0 && state2.spanIds.size === 0 && state2.complete === void 0) {
169
169
  this.traces.delete(traceId);
170
170
  return;
171
171
  }
172
- this.drain(traceId, state);
172
+ this.drain(traceId, state2);
173
173
  }
174
174
  close(traceId, complete, dropped = false) {
175
175
  const count = this.closed.get(traceId);
@@ -177,29 +177,29 @@ var init_traceCompletion = __esm({
177
177
  complete(count);
178
178
  return;
179
179
  }
180
- const state = this.traces.get(traceId);
181
- if (state === void 0) {
180
+ const state2 = this.traces.get(traceId);
181
+ if (state2 === void 0) {
182
182
  return;
183
183
  }
184
- state.complete = complete;
184
+ state2.complete = complete;
185
185
  if (dropped) {
186
- state.active.clear();
186
+ state2.active.clear();
187
187
  }
188
- this.drain(traceId, state);
188
+ this.drain(traceId, state2);
189
189
  }
190
- drain(traceId, state) {
191
- if (state.active.size !== 0 || state.complete === void 0) {
190
+ drain(traceId, state2) {
191
+ if (state2.active.size !== 0 || state2.complete === void 0) {
192
192
  return;
193
193
  }
194
194
  this.traces.delete(traceId);
195
- this.closed.set(traceId, state.spanIds.size);
195
+ this.closed.set(traceId, state2.spanIds.size);
196
196
  if (this.closed.size > 1024) {
197
197
  const oldest = this.closed.keys().next().value;
198
198
  if (oldest !== void 0) {
199
199
  this.closed.delete(oldest);
200
200
  }
201
201
  }
202
- state.complete(state.spanIds.size);
202
+ state2.complete(state2.spanIds.size);
203
203
  }
204
204
  };
205
205
  }
@@ -450,8 +450,8 @@ function text(value) {
450
450
  const trimmed = value?.trim();
451
451
  return trimmed ? trimmed : null;
452
452
  }
453
- function isEmptyGitState(state) {
454
- return Object.values(state).every((value) => value === null);
453
+ function isEmptyGitState(state2) {
454
+ return Object.values(state2).every((value) => value === null);
455
455
  }
456
456
  async function resolveGitState(cwd) {
457
457
  const git = await gitRunner({
@@ -472,14 +472,14 @@ async function resolveGitState(cwd) {
472
472
  if (!root) {
473
473
  return null;
474
474
  }
475
- const state = {
475
+ const state2 = {
476
476
  githubEmail: text(email),
477
477
  branch: text(branch),
478
478
  commitSha: sha(commitSha),
479
479
  baseSha: sha(baseSha),
480
480
  experimentSha: await resolveWorkingTreeSha(run, root.trim())
481
481
  };
482
- return isEmptyGitState(state) ? null : state;
482
+ return isEmptyGitState(state2) ? null : state2;
483
483
  }
484
484
  async function resolveWorkingTreeSha(run, root) {
485
485
  let indexPath;
@@ -6994,6 +6994,83 @@ var BitfabOpenAIAgentHandler = class {
6994
6994
  }
6995
6995
  };
6996
6996
 
6997
+ // src/openaiAgentsSpanContext.ts
6998
+ var OPENAI_AGENTS_CONTEXT_STORAGE = /* @__PURE__ */ Symbol.for(
6999
+ "openai.agents.core.asyncLocalStorage"
7000
+ );
7001
+ var MAX_OPENAI_AGENTS_SPAN_CHAIN = 64;
7002
+ var spanGlobal = globalThis;
7003
+ var state = spanGlobal.__bitfabOpenAiAgentsSpansV1 ?? {
7004
+ bitfabTraceIds: /* @__PURE__ */ new Map(),
7005
+ endedSpanIds: /* @__PURE__ */ new Map()
7006
+ };
7007
+ spanGlobal.__bitfabOpenAiAgentsSpansV1 = state;
7008
+ function mapOpenAiAgentsTrace(agentsTraceId, bitfabTraceId) {
7009
+ state.bitfabTraceIds.set(agentsTraceId, bitfabTraceId);
7010
+ }
7011
+ function unmapOpenAiAgentsTrace(agentsTraceId) {
7012
+ state.bitfabTraceIds.delete(agentsTraceId);
7013
+ state.endedSpanIds.delete(agentsTraceId);
7014
+ }
7015
+ function endOpenAiAgentsSpan(agentsTraceId, spanId) {
7016
+ if (!state.bitfabTraceIds.has(agentsTraceId)) {
7017
+ return;
7018
+ }
7019
+ const ended = state.endedSpanIds.get(agentsTraceId) ?? /* @__PURE__ */ new Set();
7020
+ ended.add(spanId);
7021
+ state.endedSpanIds.set(agentsTraceId, ended);
7022
+ }
7023
+ function isOpenAiAgentsContextStorage(value) {
7024
+ return value !== null && typeof value === "object" && typeof value.getStore === "function";
7025
+ }
7026
+ function currentOpenAiAgentsSpan() {
7027
+ const storage2 = spanGlobal[OPENAI_AGENTS_CONTEXT_STORAGE];
7028
+ if (!isOpenAiAgentsContextStorage(storage2)) {
7029
+ return void 0;
7030
+ }
7031
+ try {
7032
+ const store = storage2.getStore();
7033
+ return store?.active === true ? store.span ?? void 0 : void 0;
7034
+ } catch {
7035
+ return void 0;
7036
+ }
7037
+ }
7038
+ function currentOpenAiAgentsSpans() {
7039
+ const spans = [];
7040
+ let span = currentOpenAiAgentsSpan();
7041
+ while (span !== void 0 && spans.length < MAX_OPENAI_AGENTS_SPAN_CHAIN) {
7042
+ spans.push(span);
7043
+ span = span.previousSpan ?? void 0;
7044
+ }
7045
+ return spans;
7046
+ }
7047
+ function openAiAgentsSpanChain() {
7048
+ if (state.bitfabTraceIds.size === 0) {
7049
+ return [];
7050
+ }
7051
+ return currentOpenAiAgentsSpans().map((span) => span.spanId).filter((spanId) => typeof spanId === "string");
7052
+ }
7053
+ function openAiAgentsParentSpanId(bitfabTraceId, enclosingSpanIds) {
7054
+ if (state.bitfabTraceIds.size === 0) {
7055
+ return void 0;
7056
+ }
7057
+ for (const span of currentOpenAiAgentsSpans()) {
7058
+ if (typeof span.spanId !== "string" || typeof span.traceId !== "string") {
7059
+ return void 0;
7060
+ }
7061
+ if (state.bitfabTraceIds.get(span.traceId) !== bitfabTraceId) {
7062
+ return void 0;
7063
+ }
7064
+ if (enclosingSpanIds?.includes(span.spanId)) {
7065
+ return void 0;
7066
+ }
7067
+ if (!state.endedSpanIds.get(span.traceId)?.has(span.spanId)) {
7068
+ return span.spanId;
7069
+ }
7070
+ }
7071
+ return void 0;
7072
+ }
7073
+
6997
7074
  // src/client.ts
6998
7075
  init_policyRefresh();
6999
7076
  init_randomUuid();
@@ -7717,6 +7794,9 @@ var BitfabOpenAITracingProcessor = class {
7717
7794
  const activeContext = this.getActiveSpanContext?.();
7718
7795
  if (activeContext) {
7719
7796
  this.activeSpanMappings[trace.traceId] = activeContext;
7797
+ if (this.shouldRecord()) {
7798
+ mapOpenAiAgentsTrace(trace.traceId, activeContext.traceId);
7799
+ }
7720
7800
  }
7721
7801
  const canonicalTraceId = activeContext?.traceId ?? this.getCanonicalTraceId(trace.traceId);
7722
7802
  this.canonicalTraceIds[trace.traceId] = canonicalTraceId;
@@ -7754,6 +7834,7 @@ var BitfabOpenAITracingProcessor = class {
7754
7834
  }
7755
7835
  this.endedTraces.delete(traceId);
7756
7836
  delete this.activeSpanMappings[traceId];
7837
+ unmapOpenAiAgentsTrace(traceId);
7757
7838
  delete this.canonicalTraceIds[traceId];
7758
7839
  delete this.activeTraces[traceId];
7759
7840
  }
@@ -7778,6 +7859,9 @@ var BitfabOpenAITracingProcessor = class {
7778
7859
  async onSpanEnd(span) {
7779
7860
  const originalTraceId = span.traceId ?? "";
7780
7861
  const traceId = this.activeSpanMappings[originalTraceId]?.traceId ?? originalTraceId;
7862
+ if (span.spanId !== void 0) {
7863
+ endOpenAiAgentsSpan(originalTraceId, span.spanId);
7864
+ }
7781
7865
  try {
7782
7866
  this.sendSpan(span);
7783
7867
  } finally {
@@ -7798,6 +7882,9 @@ var BitfabOpenAITracingProcessor = class {
7798
7882
  * Called when the trace processor is shutting down.
7799
7883
  */
7800
7884
  async shutdown(timeout) {
7885
+ for (const traceId of Object.keys(this.activeSpanMappings)) {
7886
+ unmapOpenAiAgentsTrace(traceId);
7887
+ }
7801
7888
  this.activeTraces = {};
7802
7889
  this.activeSpanMappings = {};
7803
7890
  this.canonicalTraceIds = {};
@@ -8955,16 +9042,16 @@ var Bitfab = class {
8955
9042
  this.simulationPlan.send(payload, rootTraceFunctionKeyOf(payload), submit);
8956
9043
  }
8957
9044
  refreshAutoTraceCapturePolicy(traceFunctionKey) {
8958
- const state = this.autoTracePolicyRefreshes.get(traceFunctionKey) ?? new PolicyRefresh();
8959
- this.autoTracePolicyRefreshes.set(traceFunctionKey, state);
8960
- state.run(
9045
+ const state2 = this.autoTracePolicyRefreshes.get(traceFunctionKey) ?? new PolicyRefresh();
9046
+ this.autoTracePolicyRefreshes.set(traceFunctionKey, state2);
9047
+ state2.run(
8961
9048
  () => this.httpClient.getAutoTracePolicy(
8962
9049
  traceFunctionKey,
8963
9050
  AUTO_TRACE_PROTOCOL
8964
9051
  ),
8965
9052
  (policy) => {
8966
9053
  if (policy.protocol !== AUTO_TRACE_PROTOCOL) {
8967
- state.hold(AUTO_TRACE_POLICY_RETRY_MS);
9054
+ state2.hold(AUTO_TRACE_POLICY_RETRY_MS);
8968
9055
  return;
8969
9056
  }
8970
9057
  const functionIds = Array.isArray(policy.functionIds) ? policy.functionIds.filter(
@@ -8975,10 +9062,10 @@ var Bitfab = class {
8975
9062
  traceFunctionKey,
8976
9063
  policy.revision === null ? void 0 : functionIds
8977
9064
  );
8978
- state.hold(AUTO_TRACE_POLICY_REFRESH_MS);
9065
+ state2.hold(AUTO_TRACE_POLICY_REFRESH_MS);
8979
9066
  },
8980
9067
  () => {
8981
- state.hold(AUTO_TRACE_POLICY_RETRY_MS);
9068
+ state2.hold(AUTO_TRACE_POLICY_RETRY_MS);
8982
9069
  }
8983
9070
  );
8984
9071
  }
@@ -9589,7 +9676,11 @@ var Bitfab = class {
9589
9676
  const seedCtxForTraceId = parentContext ? null : getSeedContext();
9590
9677
  const traceId = parentContext?.traceId ?? replayCtxForTraceId?.traceId ?? seedCtxForTraceId?.traceId ?? randomUuid();
9591
9678
  const spanId = randomUuid();
9592
- const parentSpanId = parentContext?.spanId ?? null;
9679
+ const openAiAgentsParent = parentContext !== void 0 && options.instrumentation === "trace" ? openAiAgentsParentSpanId(
9680
+ parentContext.traceId,
9681
+ parentContext.openAiAgentsSpanIds
9682
+ ) : void 0;
9683
+ const parentSpanId = openAiAgentsParent ?? parentContext?.spanId ?? null;
9593
9684
  const isRootSpan = parentSpanId === null;
9594
9685
  if (options.enclosingTrace !== void 0) {
9595
9686
  options.enclosingTrace.link.traceId = traceId;
@@ -9603,11 +9694,13 @@ var Bitfab = class {
9603
9694
  parentContext?.surface,
9604
9695
  traceFunctionKey
9605
9696
  );
9697
+ const openAiAgentsSpanIds = openAiAgentsSpanChain();
9606
9698
  const newContext = {
9607
9699
  traceId,
9608
9700
  spanId,
9609
9701
  contexts: [],
9610
- ...surface !== void 0 && { surface }
9702
+ ...surface !== void 0 && { surface },
9703
+ ...openAiAgentsSpanIds.length > 0 && { openAiAgentsSpanIds }
9611
9704
  };
9612
9705
  newStack = [...currentStack, newContext];
9613
9706
  const inputs = args;