bitfab 0.68.3 → 0.68.5
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/{autoTrace-D3-OZcmR.cjs → autoTrace-DUmR1KJ8.cjs} +417 -62
- package/dist/autoTrace-DUmR1KJ8.cjs.map +1 -0
- package/dist/{autoTrace-ghnojSj9.js → autoTrace-DVnpnuMb.js} +322 -57
- package/dist/autoTrace-DVnpnuMb.js.map +1 -0
- package/dist/autoTrace.cjs +3 -1
- package/dist/autoTrace.d.cts +29 -1
- package/dist/autoTrace.d.ts +29 -1
- package/dist/autoTrace.js +1 -1
- package/dist/{babelPlugin-0uOq-j1Q.cjs → babelPlugin-C0Im6AZ2.cjs} +37 -14
- package/dist/babelPlugin-C0Im6AZ2.cjs.map +1 -0
- package/dist/{babelPlugin-Muq0uuuu.js → babelPlugin-hS2Hb2vt.js} +37 -14
- package/dist/babelPlugin-hS2Hb2vt.js.map +1 -0
- package/dist/baml.cjs +1 -1
- package/dist/baml.js +1 -1
- package/dist/{bamlPeer-BUoZgNxZ.cjs → bamlPeer-5Ohpq8q9.cjs} +3 -17
- package/dist/bamlPeer-5Ohpq8q9.cjs.map +1 -0
- package/dist/{bamlPeer-CIVwS68E.js → bamlPeer-Dyeb3e5o.js} +3 -11
- package/dist/bamlPeer-Dyeb3e5o.js.map +1 -0
- package/dist/{http-WVZO9E-Q.js → http-CDqaLdge.js} +3 -3
- package/dist/{http-WVZO9E-Q.js.map → http-CDqaLdge.js.map} +1 -1
- package/dist/{http-bBRhl6b9.cjs → http-DFqFW_hG.cjs} +4 -4
- package/dist/{http-bBRhl6b9.cjs.map → http-DFqFW_hG.cjs.map} +1 -1
- package/dist/{index-D1heoBkv.d.cts → index-DMJ6qrtL.d.cts} +113 -6
- package/dist/{index-D1heoBkv.d.ts → index-DMJ6qrtL.d.ts} +113 -6
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/node.cjs +3 -3
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.js +3 -3
- package/dist/optionalPeer-CUH756lt.cjs +17 -0
- package/dist/optionalPeer-CUH756lt.cjs.map +1 -0
- package/dist/optionalPeer-CczrzrXx.js +12 -0
- package/dist/optionalPeer-CczrzrXx.js.map +1 -0
- package/dist/{registryCommand-Dk4Y1ZgW.js → registryCommand-D7bfo0Au.js} +179 -8
- package/dist/registryCommand-D7bfo0Au.js.map +1 -0
- package/dist/replayCli.js +1 -1
- package/dist/seedCli.js +1 -1
- package/dist/{src-BRR42NiJ.cjs → src-CxELko3f.cjs} +52 -80
- package/dist/src-CxELko3f.cjs.map +1 -0
- package/dist/{src--sgdobPE.js → src-DvVk1aLi.js} +41 -69
- package/dist/src-DvVk1aLi.js.map +1 -0
- package/dist/transform/babel.cjs +1 -1
- package/dist/transform/babel.js +1 -1
- package/dist/transform/loaderRuntime.cjs +2 -2
- package/dist/transform/loaderRuntime.js +2 -2
- package/dist/transform/nodeLoader.js +36 -13
- package/dist/transform/nodeLoader.js.map +1 -1
- package/dist/transform/swc.cjs +1 -1
- package/dist/transform/swc.js +1 -1
- package/dist/transform/unplugin.cjs +2 -2
- package/dist/transform/unplugin.js +2 -2
- package/dist/{transform-CAJyLLe2.js → transform-BL1fJW-C.js} +2 -2
- package/dist/{transform-CAJyLLe2.js.map → transform-BL1fJW-C.js.map} +1 -1
- package/dist/{transform-ClCOpCZ2.cjs → transform-C4H7TKW-.cjs} +2 -2
- package/dist/{transform-ClCOpCZ2.cjs.map → transform-C4H7TKW-.cjs.map} +1 -1
- package/package.json +1 -1
- package/dist/autoTrace-D3-OZcmR.cjs.map +0 -1
- package/dist/autoTrace-ghnojSj9.js.map +0 -1
- package/dist/babelPlugin-0uOq-j1Q.cjs.map +0 -1
- package/dist/babelPlugin-Muq0uuuu.js.map +0 -1
- package/dist/bamlPeer-BUoZgNxZ.cjs.map +0 -1
- package/dist/bamlPeer-CIVwS68E.js.map +0 -1
- package/dist/registryCommand-Dk4Y1ZgW.js.map +0 -1
- package/dist/src--sgdobPE.js.map +0 -1
- package/dist/src-BRR42NiJ.cjs.map +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_optionalPeer = require("./optionalPeer-CUH756lt.cjs");
|
|
1
2
|
//#region src/asyncStorage.ts
|
|
2
3
|
let AsyncLocalStorageClass = null;
|
|
3
4
|
let initDone = false;
|
|
@@ -61,11 +62,150 @@ function writeOnce(key, line, write = console.warn) {
|
|
|
61
62
|
} catch {}
|
|
62
63
|
}
|
|
63
64
|
//#endregion
|
|
64
|
-
//#region src/
|
|
65
|
-
const
|
|
65
|
+
//#region src/langchainRunScope.ts
|
|
66
|
+
const RUN_SCOPE_STORAGE_SYMBOL = Symbol.for("bitfab.langchainRunScopeStorage");
|
|
67
|
+
const SCOPED_GENERATE_SYMBOL = Symbol.for("bitfab.langchainScopedGenerate");
|
|
68
|
+
const UNSCOPED_RUNS_SYMBOL = Symbol.for("bitfab.langchainUnscopedRuns");
|
|
69
|
+
const MODEL_CLASSES = [{
|
|
70
|
+
specifierParts: [
|
|
71
|
+
"@langchain",
|
|
72
|
+
"core",
|
|
73
|
+
"language_models",
|
|
74
|
+
"chat_models"
|
|
75
|
+
],
|
|
76
|
+
name: "BaseChatModel"
|
|
77
|
+
}, {
|
|
78
|
+
specifierParts: [
|
|
79
|
+
"@langchain",
|
|
80
|
+
"core",
|
|
81
|
+
"language_models",
|
|
82
|
+
"llms"
|
|
83
|
+
],
|
|
84
|
+
name: "BaseLLM"
|
|
85
|
+
}];
|
|
86
|
+
let runScopeStorage = null;
|
|
87
|
+
let installation = null;
|
|
88
|
+
function storage() {
|
|
89
|
+
if (runScopeStorage) return runScopeStorage;
|
|
90
|
+
const shared = globalThis;
|
|
91
|
+
const existing = shared[RUN_SCOPE_STORAGE_SYMBOL];
|
|
92
|
+
runScopeStorage = existing ?? createAsyncLocalStorage();
|
|
93
|
+
if (runScopeStorage && !existing) shared[RUN_SCOPE_STORAGE_SYMBOL] = runScopeStorage;
|
|
94
|
+
return runScopeStorage;
|
|
95
|
+
}
|
|
96
|
+
function unscopedRuns() {
|
|
97
|
+
const shared = globalThis;
|
|
98
|
+
const existing = shared[UNSCOPED_RUNS_SYMBOL];
|
|
99
|
+
if (existing) return existing;
|
|
100
|
+
const created = /* @__PURE__ */ new Set();
|
|
101
|
+
shared[UNSCOPED_RUNS_SYMBOL] = created;
|
|
102
|
+
return created;
|
|
103
|
+
}
|
|
104
|
+
function scopeGenerate(prototype) {
|
|
105
|
+
const original = prototype.generate;
|
|
106
|
+
if (typeof original !== "function" || original[SCOPED_GENERATE_SYMBOL]) return;
|
|
107
|
+
const scoped = function(...args) {
|
|
108
|
+
const runStorage = storage();
|
|
109
|
+
if (!runStorage) return original.apply(this, args);
|
|
110
|
+
return runStorage.run({ recordedByHandler: false }, () => original.apply(this, args));
|
|
111
|
+
};
|
|
112
|
+
scoped[SCOPED_GENERATE_SYMBOL] = true;
|
|
113
|
+
prototype.generate = scoped;
|
|
114
|
+
}
|
|
115
|
+
async function scopeModelClass(specifierParts, name) {
|
|
116
|
+
try {
|
|
117
|
+
const modelClass = (await require_optionalPeer.importOptionalPeer(specifierParts))[name];
|
|
118
|
+
if (modelClass?.prototype) scopeGenerate(modelClass.prototype);
|
|
119
|
+
} catch {}
|
|
120
|
+
}
|
|
121
|
+
function installLangChainRunScopes() {
|
|
122
|
+
installation ?? (installation = Promise.all(MODEL_CLASSES.map(({ specifierParts, name }) => scopeModelClass(specifierParts, name))).then(() => void 0));
|
|
123
|
+
return installation;
|
|
124
|
+
}
|
|
125
|
+
function markLangChainRunRecorded(runId) {
|
|
126
|
+
const scope = storage()?.getStore();
|
|
127
|
+
if (scope) {
|
|
128
|
+
scope.recordedByHandler = true;
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
unscopedRuns().add(runId);
|
|
132
|
+
}
|
|
133
|
+
function forgetLangChainRun(runId) {
|
|
134
|
+
unscopedRuns().delete(runId);
|
|
135
|
+
}
|
|
136
|
+
function langChainHandlerRecordsCall() {
|
|
137
|
+
const scope = storage()?.getStore();
|
|
138
|
+
if (scope) return scope.recordedByHandler;
|
|
139
|
+
return unscopedRuns().size > 0;
|
|
140
|
+
}
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/openaiAgentsSpanContext.ts
|
|
143
|
+
const OPENAI_AGENTS_CONTEXT_STORAGE = Symbol.for("openai.agents.core.asyncLocalStorage");
|
|
144
|
+
const MAX_OPENAI_AGENTS_SPAN_CHAIN = 64;
|
|
145
|
+
const MODEL_CALL_SPAN_TYPES = /* @__PURE__ */ new Set(["generation", "response"]);
|
|
146
|
+
const spanGlobal = globalThis;
|
|
147
|
+
const state = spanGlobal.__bitfabOpenAiAgentsSpansV1 ?? {
|
|
148
|
+
bitfabTraceIds: /* @__PURE__ */ new Map(),
|
|
149
|
+
endedSpanIds: /* @__PURE__ */ new Map()
|
|
150
|
+
};
|
|
151
|
+
spanGlobal.__bitfabOpenAiAgentsSpansV1 = state;
|
|
152
|
+
function mapOpenAiAgentsTrace(agentsTraceId, bitfabTraceId) {
|
|
153
|
+
state.bitfabTraceIds.set(agentsTraceId, bitfabTraceId);
|
|
154
|
+
}
|
|
155
|
+
function unmapOpenAiAgentsTrace(agentsTraceId) {
|
|
156
|
+
state.bitfabTraceIds.delete(agentsTraceId);
|
|
157
|
+
state.endedSpanIds.delete(agentsTraceId);
|
|
158
|
+
}
|
|
159
|
+
function endOpenAiAgentsSpan(agentsTraceId, spanId) {
|
|
160
|
+
if (!state.bitfabTraceIds.has(agentsTraceId)) return;
|
|
161
|
+
const ended = state.endedSpanIds.get(agentsTraceId) ?? /* @__PURE__ */ new Set();
|
|
162
|
+
ended.add(spanId);
|
|
163
|
+
state.endedSpanIds.set(agentsTraceId, ended);
|
|
164
|
+
}
|
|
165
|
+
function isOpenAiAgentsContextStorage(value) {
|
|
166
|
+
return value !== null && typeof value === "object" && typeof value.getStore === "function";
|
|
167
|
+
}
|
|
168
|
+
function currentOpenAiAgentsSpan() {
|
|
169
|
+
const storage = spanGlobal[OPENAI_AGENTS_CONTEXT_STORAGE];
|
|
170
|
+
if (!isOpenAiAgentsContextStorage(storage)) return;
|
|
171
|
+
try {
|
|
172
|
+
const store = storage.getStore();
|
|
173
|
+
return store?.active === true ? store.span ?? void 0 : void 0;
|
|
174
|
+
} catch {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function currentOpenAiAgentsSpans() {
|
|
179
|
+
const spans = [];
|
|
180
|
+
let span = currentOpenAiAgentsSpan();
|
|
181
|
+
while (span !== void 0 && spans.length < MAX_OPENAI_AGENTS_SPAN_CHAIN) {
|
|
182
|
+
spans.push(span);
|
|
183
|
+
span = span.previousSpan ?? void 0;
|
|
184
|
+
}
|
|
185
|
+
return spans;
|
|
186
|
+
}
|
|
187
|
+
function openAiAgentsSpanChain() {
|
|
188
|
+
if (state.bitfabTraceIds.size === 0) return [];
|
|
189
|
+
return currentOpenAiAgentsSpans().map((span) => span.spanId).filter((spanId) => typeof spanId === "string");
|
|
190
|
+
}
|
|
191
|
+
function openAiAgentsParentSpanId(bitfabTraceId, enclosingSpanIds) {
|
|
192
|
+
if (state.bitfabTraceIds.size === 0) return;
|
|
193
|
+
for (const span of currentOpenAiAgentsSpans()) {
|
|
194
|
+
if (typeof span.spanId !== "string" || typeof span.traceId !== "string") return;
|
|
195
|
+
if (state.bitfabTraceIds.get(span.traceId) !== bitfabTraceId) return;
|
|
196
|
+
if (enclosingSpanIds?.includes(span.spanId)) return;
|
|
197
|
+
if (!state.endedSpanIds.get(span.traceId)?.has(span.spanId)) return span.spanId;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function openAiAgentsModelCallOpen() {
|
|
201
|
+
if (state.bitfabTraceIds.size === 0) return false;
|
|
202
|
+
return currentOpenAiAgentsSpans().some((span) => typeof span.traceId === "string" && typeof span.spanId === "string" && state.bitfabTraceIds.has(span.traceId) && MODEL_CALL_SPAN_TYPES.has(String(span.spanData?.type)) && !state.endedSpanIds.get(span.traceId)?.has(span.spanId));
|
|
203
|
+
}
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/clientCalls.ts
|
|
66
206
|
const OPENROUTER_HOSTNAME = "openrouter.ai";
|
|
67
|
-
const
|
|
68
|
-
const
|
|
207
|
+
const CLIENT_CALL_WATCH_STORAGE_SYMBOL = Symbol.for("bitfab.clientCallWatchStorage");
|
|
208
|
+
const responsesRecordedByAutoTrace = /* @__PURE__ */ new WeakSet();
|
|
69
209
|
function isRecord(value) {
|
|
70
210
|
return typeof value === "object" && value !== null;
|
|
71
211
|
}
|
|
@@ -79,6 +219,49 @@ function numberField(value, name) {
|
|
|
79
219
|
function nonEmptyString(value) {
|
|
80
220
|
return typeof value === "string" && value !== "" ? value : void 0;
|
|
81
221
|
}
|
|
222
|
+
function presentFields(base, values, durationMs) {
|
|
223
|
+
const context = { ...base };
|
|
224
|
+
for (const [key, value] of Object.entries(values)) if (value !== void 0) context[key] = value;
|
|
225
|
+
context.durationMs = durationMs;
|
|
226
|
+
return context;
|
|
227
|
+
}
|
|
228
|
+
function sumOfPresent(values) {
|
|
229
|
+
const present = values.filter((value) => value !== void 0);
|
|
230
|
+
return present.length > 0 ? present.reduce((total, value) => total + value, 0) : void 0;
|
|
231
|
+
}
|
|
232
|
+
function textOf(content) {
|
|
233
|
+
return typeof content === "string" ? content : JSON.stringify(content);
|
|
234
|
+
}
|
|
235
|
+
function roleEntries(items) {
|
|
236
|
+
return items.flatMap((item) => {
|
|
237
|
+
const role = field(item, "role");
|
|
238
|
+
if (typeof role !== "string") return [];
|
|
239
|
+
return [{
|
|
240
|
+
role,
|
|
241
|
+
content: textOf(field(item, "content"))
|
|
242
|
+
}];
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
function renderedPrompt(entries) {
|
|
246
|
+
return entries.length > 0 ? JSON.stringify(entries) : void 0;
|
|
247
|
+
}
|
|
248
|
+
function clientOf(receiver) {
|
|
249
|
+
try {
|
|
250
|
+
return field(receiver, "_client");
|
|
251
|
+
} catch {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function clientClassStatic(receiver, name) {
|
|
256
|
+
const client = clientOf(receiver);
|
|
257
|
+
if (!isRecord(client)) return;
|
|
258
|
+
try {
|
|
259
|
+
const clientClass = client.constructor;
|
|
260
|
+
return typeof clientClass === "function" ? clientClass[name] : void 0;
|
|
261
|
+
} catch {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
82
265
|
function isOpenRouterBaseUrl(baseUrl) {
|
|
83
266
|
if (typeof baseUrl !== "string") return false;
|
|
84
267
|
try {
|
|
@@ -90,35 +273,27 @@ function isOpenRouterBaseUrl(baseUrl) {
|
|
|
90
273
|
}
|
|
91
274
|
function isOpenRouterCompletions(receiver) {
|
|
92
275
|
try {
|
|
93
|
-
return isOpenRouterBaseUrl(field(
|
|
276
|
+
return isOpenRouterBaseUrl(field(clientOf(receiver), "baseURL"));
|
|
94
277
|
} catch {
|
|
95
278
|
return false;
|
|
96
279
|
}
|
|
97
280
|
}
|
|
281
|
+
function isAnthropicMessages(receiver) {
|
|
282
|
+
return typeof clientClassStatic(receiver, "HUMAN_PROMPT") === "string";
|
|
283
|
+
}
|
|
284
|
+
function isOpenAIResponses(receiver) {
|
|
285
|
+
return typeof clientClassStatic(receiver, "OpenAI") === "function";
|
|
286
|
+
}
|
|
98
287
|
function isStreamingRequest(body) {
|
|
99
288
|
return field(body, "stream") === true;
|
|
100
289
|
}
|
|
101
|
-
function isChatCompletion(value) {
|
|
102
|
-
return isRecord(value) && Array.isArray(value.choices);
|
|
103
|
-
}
|
|
104
290
|
function openRouterPrompt(body) {
|
|
105
291
|
const messages = field(body, "messages");
|
|
106
|
-
|
|
107
|
-
const rendered = messages.flatMap((message) => {
|
|
108
|
-
const role = field(message, "role");
|
|
109
|
-
if (typeof role !== "string") return [];
|
|
110
|
-
const content = field(message, "content");
|
|
111
|
-
return [{
|
|
112
|
-
role,
|
|
113
|
-
content: typeof content === "string" ? content : JSON.stringify(content)
|
|
114
|
-
}];
|
|
115
|
-
});
|
|
116
|
-
return rendered.length > 0 ? JSON.stringify(rendered) : void 0;
|
|
292
|
+
return Array.isArray(messages) ? renderedPrompt(roleEntries(messages)) : void 0;
|
|
117
293
|
}
|
|
118
294
|
function openRouterContext(body, response, durationMs) {
|
|
119
295
|
const usage = field(response, "usage");
|
|
120
|
-
|
|
121
|
-
const values = {
|
|
296
|
+
return presentFields({ provider: "openrouter" }, {
|
|
122
297
|
model: nonEmptyString(field(response, "model")) ?? nonEmptyString(field(body, "model")),
|
|
123
298
|
upstreamProvider: nonEmptyString(field(response, "provider")),
|
|
124
299
|
inputTokens: numberField(usage, "prompt_tokens"),
|
|
@@ -126,28 +301,105 @@ function openRouterContext(body, response, durationMs) {
|
|
|
126
301
|
cachedInputTokens: numberField(field(usage, "prompt_tokens_details"), "cached_tokens"),
|
|
127
302
|
reasoningTokens: numberField(field(usage, "completion_tokens_details"), "reasoning_tokens"),
|
|
128
303
|
costUsd: numberField(usage, "cost")
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
304
|
+
}, durationMs);
|
|
305
|
+
}
|
|
306
|
+
function anthropicPrompt(body) {
|
|
307
|
+
const system = field(body, "system");
|
|
308
|
+
const messages = field(body, "messages");
|
|
309
|
+
return renderedPrompt([...system === void 0 || system === null ? [] : [{
|
|
310
|
+
role: "system",
|
|
311
|
+
content: textOf(system)
|
|
312
|
+
}], ...Array.isArray(messages) ? roleEntries(messages) : []]);
|
|
133
313
|
}
|
|
134
|
-
function
|
|
314
|
+
function anthropicContext(body, response, durationMs) {
|
|
315
|
+
const usage = field(response, "usage");
|
|
316
|
+
const cacheRead = numberField(usage, "cache_read_input_tokens");
|
|
317
|
+
return presentFields({ provider: "anthropic" }, {
|
|
318
|
+
model: nonEmptyString(field(response, "model")) ?? nonEmptyString(field(body, "model")),
|
|
319
|
+
inputTokens: sumOfPresent([
|
|
320
|
+
numberField(usage, "input_tokens"),
|
|
321
|
+
cacheRead,
|
|
322
|
+
numberField(usage, "cache_creation_input_tokens")
|
|
323
|
+
]),
|
|
324
|
+
outputTokens: numberField(usage, "output_tokens"),
|
|
325
|
+
cachedInputTokens: cacheRead
|
|
326
|
+
}, durationMs);
|
|
327
|
+
}
|
|
328
|
+
function openAIResponsesPrompt(body) {
|
|
329
|
+
const instructions = field(body, "instructions");
|
|
330
|
+
const input = field(body, "input");
|
|
331
|
+
return renderedPrompt([
|
|
332
|
+
...typeof instructions === "string" ? [{
|
|
333
|
+
role: "system",
|
|
334
|
+
content: instructions
|
|
335
|
+
}] : [],
|
|
336
|
+
...typeof input === "string" ? [{
|
|
337
|
+
role: "user",
|
|
338
|
+
content: input
|
|
339
|
+
}] : [],
|
|
340
|
+
...Array.isArray(input) ? roleEntries(input) : []
|
|
341
|
+
]);
|
|
342
|
+
}
|
|
343
|
+
function openAIResponsesContext(body, response, durationMs) {
|
|
344
|
+
const usage = field(response, "usage");
|
|
345
|
+
return presentFields({ provider: "openai" }, {
|
|
346
|
+
model: nonEmptyString(field(response, "model")) ?? nonEmptyString(field(body, "model")),
|
|
347
|
+
inputTokens: numberField(usage, "input_tokens"),
|
|
348
|
+
outputTokens: numberField(usage, "output_tokens"),
|
|
349
|
+
cachedInputTokens: numberField(field(usage, "input_tokens_details"), "cached_tokens"),
|
|
350
|
+
reasoningTokens: numberField(field(usage, "output_tokens_details"), "reasoning_tokens"),
|
|
351
|
+
costUsd: numberField(usage, "cost")
|
|
352
|
+
}, durationMs);
|
|
353
|
+
}
|
|
354
|
+
const OPENROUTER = {
|
|
355
|
+
key: "openrouter",
|
|
356
|
+
library: "openai",
|
|
357
|
+
matchesReceiver: isOpenRouterCompletions,
|
|
358
|
+
isResponse: (response) => isRecord(response) && Array.isArray(response.choices),
|
|
359
|
+
prompt: openRouterPrompt,
|
|
360
|
+
context: openRouterContext
|
|
361
|
+
};
|
|
362
|
+
const ANTHROPIC = {
|
|
363
|
+
key: "anthropic",
|
|
364
|
+
library: "@anthropic-ai/sdk",
|
|
365
|
+
matchesReceiver: isAnthropicMessages,
|
|
366
|
+
isResponse: (response) => field(response, "type") === "message" && Array.isArray(field(response, "content")),
|
|
367
|
+
prompt: anthropicPrompt,
|
|
368
|
+
context: anthropicContext
|
|
369
|
+
};
|
|
370
|
+
const OPENAI_RESPONSES = {
|
|
371
|
+
key: "openai-responses",
|
|
372
|
+
library: "openai",
|
|
373
|
+
matchesReceiver: isOpenAIResponses,
|
|
374
|
+
isResponse: (response) => field(response, "object") === "response",
|
|
375
|
+
prompt: openAIResponsesPrompt,
|
|
376
|
+
context: openAIResponsesContext
|
|
377
|
+
};
|
|
378
|
+
const CLIENT_CALL_PROVIDERS = new Map([
|
|
379
|
+
OPENROUTER,
|
|
380
|
+
ANTHROPIC,
|
|
381
|
+
OPENAI_RESPONSES
|
|
382
|
+
].map((provider) => [provider.key, provider]));
|
|
383
|
+
function clientCallProvider(key) {
|
|
384
|
+
return key === void 0 ? void 0 : CLIENT_CALL_PROVIDERS.get(key);
|
|
385
|
+
}
|
|
386
|
+
function recordClientCall(provider, span, body, response, durationMs) {
|
|
135
387
|
try {
|
|
136
|
-
const prompt =
|
|
388
|
+
const prompt = provider.prompt(body);
|
|
137
389
|
if (prompt !== void 0) span.setPrompt(prompt);
|
|
138
|
-
span.addContext(
|
|
390
|
+
span.addContext(provider.context(body, response, durationMs));
|
|
139
391
|
} catch {}
|
|
140
392
|
}
|
|
141
|
-
let
|
|
393
|
+
let clientCallWatchStorage = null;
|
|
142
394
|
function watchStorage() {
|
|
143
|
-
if (
|
|
395
|
+
if (clientCallWatchStorage) return clientCallWatchStorage;
|
|
144
396
|
const shared = globalThis;
|
|
145
|
-
const existing = shared[
|
|
146
|
-
|
|
147
|
-
if (
|
|
148
|
-
return
|
|
397
|
+
const existing = shared[CLIENT_CALL_WATCH_STORAGE_SYMBOL];
|
|
398
|
+
clientCallWatchStorage = existing ?? createAsyncLocalStorage();
|
|
399
|
+
if (clientCallWatchStorage && !existing) shared[CLIENT_CALL_WATCH_STORAGE_SYMBOL] = clientCallWatchStorage;
|
|
400
|
+
return clientCallWatchStorage;
|
|
149
401
|
}
|
|
150
|
-
function
|
|
402
|
+
function watchClientCall(fn) {
|
|
151
403
|
const storage = watchStorage();
|
|
152
404
|
const watch = {
|
|
153
405
|
recorded: false,
|
|
@@ -161,24 +413,27 @@ function watchOpenRouterUsage(fn) {
|
|
|
161
413
|
function markEnclosingWatches(watch) {
|
|
162
414
|
for (let current = watch.parent; current; current = current.parent) current.recorded = true;
|
|
163
415
|
}
|
|
416
|
+
function frameworkRecordsClientCall() {
|
|
417
|
+
return langChainHandlerRecordsCall() || openAiAgentsModelCallOpen();
|
|
418
|
+
}
|
|
164
419
|
function isRecordedByAutoTrace(response) {
|
|
165
|
-
return isRecord(response) &&
|
|
420
|
+
return isRecord(response) && responsesRecordedByAutoTrace.has(response);
|
|
166
421
|
}
|
|
167
|
-
function
|
|
422
|
+
function recordWatchedClientCall(provider, span, watch, body, response, durationMs) {
|
|
168
423
|
if (watch.recorded || isRecordedByAutoTrace(response)) {
|
|
169
424
|
markEnclosingWatches(watch);
|
|
170
425
|
return;
|
|
171
426
|
}
|
|
172
|
-
if (!
|
|
173
|
-
|
|
174
|
-
|
|
427
|
+
if (!provider.isResponse(response)) return;
|
|
428
|
+
recordClientCall(provider, span, body, response, durationMs);
|
|
429
|
+
responsesRecordedByAutoTrace.add(response);
|
|
175
430
|
markEnclosingWatches(watch);
|
|
176
431
|
}
|
|
177
|
-
function
|
|
432
|
+
function recordAutoTracedClientCall(provider, invokeFn, body, span) {
|
|
178
433
|
const startedAt = Date.now();
|
|
179
|
-
const { watch, result } =
|
|
434
|
+
const { watch, result } = watchClientCall(invokeFn);
|
|
180
435
|
const settle = (response) => {
|
|
181
|
-
|
|
436
|
+
recordWatchedClientCall(provider, span, watch, body, response, Date.now() - startedAt);
|
|
182
437
|
};
|
|
183
438
|
if (result instanceof Promise) return result.then((response) => {
|
|
184
439
|
settle(response);
|
|
@@ -439,30 +694,40 @@ function __bitfabAutoJev(receiver, ...args) {
|
|
|
439
694
|
if (!__bitfabAutoTraceActive()) return target.systemOne(...args);
|
|
440
695
|
return invokeRecordedClientCall(jevDefinition(receiver), args, () => target.systemOne(...args));
|
|
441
696
|
}
|
|
442
|
-
const
|
|
443
|
-
const
|
|
444
|
-
function
|
|
697
|
+
const CLIENT_CALL_METHOD = "create";
|
|
698
|
+
const clientCallDefinitions = /* @__PURE__ */ new Map();
|
|
699
|
+
function clientCallDefinition(provider, receiver) {
|
|
445
700
|
const className = receiverClassName(receiver);
|
|
446
|
-
const name = className === void 0 ?
|
|
447
|
-
|
|
701
|
+
const name = className === void 0 ? CLIENT_CALL_METHOD : `${className}.${CLIENT_CALL_METHOD}`;
|
|
702
|
+
const id = `ts-auto-v1:${provider.key}#${name}`;
|
|
703
|
+
let definition = clientCallDefinitions.get(id);
|
|
448
704
|
if (definition === void 0) {
|
|
449
705
|
definition = {
|
|
450
|
-
id
|
|
706
|
+
id,
|
|
451
707
|
name,
|
|
452
|
-
file:
|
|
708
|
+
file: provider.library,
|
|
453
709
|
line: 0,
|
|
454
710
|
column: 0,
|
|
455
711
|
async: true,
|
|
456
|
-
|
|
712
|
+
clientCall: provider.key
|
|
457
713
|
};
|
|
458
|
-
|
|
714
|
+
clientCallDefinitions.set(id, definition);
|
|
459
715
|
}
|
|
460
716
|
return definition;
|
|
461
717
|
}
|
|
462
|
-
function
|
|
718
|
+
function invokeClientCall(provider, receiver, args) {
|
|
463
719
|
const target = receiver;
|
|
464
|
-
if (!__bitfabAutoTraceActive() || isStreamingRequest(args[0]) || !
|
|
465
|
-
return invokeRecordedClientCall(
|
|
720
|
+
if (!__bitfabAutoTraceActive() || isStreamingRequest(args[0]) || !provider.matchesReceiver(receiver) || frameworkRecordsClientCall()) return target.create(...args);
|
|
721
|
+
return invokeRecordedClientCall(clientCallDefinition(provider, receiver), args, () => target.create(...args));
|
|
722
|
+
}
|
|
723
|
+
function __bitfabAutoOpenRouter(receiver, ...args) {
|
|
724
|
+
return invokeClientCall(OPENROUTER, receiver, args);
|
|
725
|
+
}
|
|
726
|
+
function __bitfabAutoAnthropic(receiver, ...args) {
|
|
727
|
+
return invokeClientCall(ANTHROPIC, receiver, args);
|
|
728
|
+
}
|
|
729
|
+
function __bitfabAutoOpenAIResponses(receiver, ...args) {
|
|
730
|
+
return invokeClientCall(OPENAI_RESPONSES, receiver, args);
|
|
466
731
|
}
|
|
467
732
|
function __bitfabAutoWrap(definition, fn) {
|
|
468
733
|
noteTransformedModule();
|
|
@@ -491,12 +756,42 @@ function _resetAutoTraceTransformDetection() {
|
|
|
491
756
|
autoTraceGlobal.__bitfab_auto_trace_transformed_v1__ = void 0;
|
|
492
757
|
}
|
|
493
758
|
//#endregion
|
|
759
|
+
Object.defineProperty(exports, "ANTHROPIC", {
|
|
760
|
+
enumerable: true,
|
|
761
|
+
get: function() {
|
|
762
|
+
return ANTHROPIC;
|
|
763
|
+
}
|
|
764
|
+
});
|
|
765
|
+
Object.defineProperty(exports, "OPENAI_RESPONSES", {
|
|
766
|
+
enumerable: true,
|
|
767
|
+
get: function() {
|
|
768
|
+
return OPENAI_RESPONSES;
|
|
769
|
+
}
|
|
770
|
+
});
|
|
771
|
+
Object.defineProperty(exports, "OPENROUTER", {
|
|
772
|
+
enumerable: true,
|
|
773
|
+
get: function() {
|
|
774
|
+
return OPENROUTER;
|
|
775
|
+
}
|
|
776
|
+
});
|
|
777
|
+
Object.defineProperty(exports, "__bitfabAutoAnthropic", {
|
|
778
|
+
enumerable: true,
|
|
779
|
+
get: function() {
|
|
780
|
+
return __bitfabAutoAnthropic;
|
|
781
|
+
}
|
|
782
|
+
});
|
|
494
783
|
Object.defineProperty(exports, "__bitfabAutoJev", {
|
|
495
784
|
enumerable: true,
|
|
496
785
|
get: function() {
|
|
497
786
|
return __bitfabAutoJev;
|
|
498
787
|
}
|
|
499
788
|
});
|
|
789
|
+
Object.defineProperty(exports, "__bitfabAutoOpenAIResponses", {
|
|
790
|
+
enumerable: true,
|
|
791
|
+
get: function() {
|
|
792
|
+
return __bitfabAutoOpenAIResponses;
|
|
793
|
+
}
|
|
794
|
+
});
|
|
500
795
|
Object.defineProperty(exports, "__bitfabAutoOpenRouter", {
|
|
501
796
|
enumerable: true,
|
|
502
797
|
get: function() {
|
|
@@ -545,6 +840,12 @@ Object.defineProperty(exports, "clearAutoTraceNodeConfiguration", {
|
|
|
545
840
|
return clearAutoTraceNodeConfiguration;
|
|
546
841
|
}
|
|
547
842
|
});
|
|
843
|
+
Object.defineProperty(exports, "clientCallProvider", {
|
|
844
|
+
enumerable: true,
|
|
845
|
+
get: function() {
|
|
846
|
+
return clientCallProvider;
|
|
847
|
+
}
|
|
848
|
+
});
|
|
548
849
|
Object.defineProperty(exports, "createAsyncLocalStorage", {
|
|
549
850
|
enumerable: true,
|
|
550
851
|
get: function() {
|
|
@@ -557,6 +858,30 @@ Object.defineProperty(exports, "currentAutoTraceEntries", {
|
|
|
557
858
|
return currentAutoTraceEntries;
|
|
558
859
|
}
|
|
559
860
|
});
|
|
861
|
+
Object.defineProperty(exports, "endOpenAiAgentsSpan", {
|
|
862
|
+
enumerable: true,
|
|
863
|
+
get: function() {
|
|
864
|
+
return endOpenAiAgentsSpan;
|
|
865
|
+
}
|
|
866
|
+
});
|
|
867
|
+
Object.defineProperty(exports, "forgetLangChainRun", {
|
|
868
|
+
enumerable: true,
|
|
869
|
+
get: function() {
|
|
870
|
+
return forgetLangChainRun;
|
|
871
|
+
}
|
|
872
|
+
});
|
|
873
|
+
Object.defineProperty(exports, "frameworkRecordsClientCall", {
|
|
874
|
+
enumerable: true,
|
|
875
|
+
get: function() {
|
|
876
|
+
return frameworkRecordsClientCall;
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
Object.defineProperty(exports, "installLangChainRunScopes", {
|
|
880
|
+
enumerable: true,
|
|
881
|
+
get: function() {
|
|
882
|
+
return installLangChainRunScopes;
|
|
883
|
+
}
|
|
884
|
+
});
|
|
560
885
|
Object.defineProperty(exports, "invokeAsDiscoveredCall", {
|
|
561
886
|
enumerable: true,
|
|
562
887
|
get: function() {
|
|
@@ -581,16 +906,40 @@ Object.defineProperty(exports, "isCaptureSuppressed", {
|
|
|
581
906
|
return isCaptureSuppressed;
|
|
582
907
|
}
|
|
583
908
|
});
|
|
584
|
-
Object.defineProperty(exports, "
|
|
909
|
+
Object.defineProperty(exports, "mapOpenAiAgentsTrace", {
|
|
910
|
+
enumerable: true,
|
|
911
|
+
get: function() {
|
|
912
|
+
return mapOpenAiAgentsTrace;
|
|
913
|
+
}
|
|
914
|
+
});
|
|
915
|
+
Object.defineProperty(exports, "markLangChainRunRecorded", {
|
|
916
|
+
enumerable: true,
|
|
917
|
+
get: function() {
|
|
918
|
+
return markLangChainRunRecorded;
|
|
919
|
+
}
|
|
920
|
+
});
|
|
921
|
+
Object.defineProperty(exports, "openAiAgentsParentSpanId", {
|
|
922
|
+
enumerable: true,
|
|
923
|
+
get: function() {
|
|
924
|
+
return openAiAgentsParentSpanId;
|
|
925
|
+
}
|
|
926
|
+
});
|
|
927
|
+
Object.defineProperty(exports, "openAiAgentsSpanChain", {
|
|
585
928
|
enumerable: true,
|
|
586
929
|
get: function() {
|
|
587
|
-
return
|
|
930
|
+
return openAiAgentsSpanChain;
|
|
588
931
|
}
|
|
589
932
|
});
|
|
590
|
-
Object.defineProperty(exports, "
|
|
933
|
+
Object.defineProperty(exports, "recordAutoTracedClientCall", {
|
|
591
934
|
enumerable: true,
|
|
592
935
|
get: function() {
|
|
593
|
-
return
|
|
936
|
+
return recordAutoTracedClientCall;
|
|
937
|
+
}
|
|
938
|
+
});
|
|
939
|
+
Object.defineProperty(exports, "recordWatchedClientCall", {
|
|
940
|
+
enumerable: true,
|
|
941
|
+
get: function() {
|
|
942
|
+
return recordWatchedClientCall;
|
|
594
943
|
}
|
|
595
944
|
});
|
|
596
945
|
Object.defineProperty(exports, "registerAsyncLocalStorageClass", {
|
|
@@ -629,6 +978,12 @@ Object.defineProperty(exports, "runWithCaptureSuppressed", {
|
|
|
629
978
|
return runWithCaptureSuppressed;
|
|
630
979
|
}
|
|
631
980
|
});
|
|
981
|
+
Object.defineProperty(exports, "unmapOpenAiAgentsTrace", {
|
|
982
|
+
enumerable: true,
|
|
983
|
+
get: function() {
|
|
984
|
+
return unmapOpenAiAgentsTrace;
|
|
985
|
+
}
|
|
986
|
+
});
|
|
632
987
|
Object.defineProperty(exports, "warn", {
|
|
633
988
|
enumerable: true,
|
|
634
989
|
get: function() {
|
|
@@ -641,10 +996,10 @@ Object.defineProperty(exports, "warnOnce", {
|
|
|
641
996
|
return warnOnce;
|
|
642
997
|
}
|
|
643
998
|
});
|
|
644
|
-
Object.defineProperty(exports, "
|
|
999
|
+
Object.defineProperty(exports, "watchClientCall", {
|
|
645
1000
|
enumerable: true,
|
|
646
1001
|
get: function() {
|
|
647
|
-
return
|
|
1002
|
+
return watchClientCall;
|
|
648
1003
|
}
|
|
649
1004
|
});
|
|
650
1005
|
Object.defineProperty(exports, "writeOnce", {
|
|
@@ -654,4 +1009,4 @@ Object.defineProperty(exports, "writeOnce", {
|
|
|
654
1009
|
}
|
|
655
1010
|
});
|
|
656
1011
|
|
|
657
|
-
//# sourceMappingURL=autoTrace-
|
|
1012
|
+
//# sourceMappingURL=autoTrace-DUmR1KJ8.cjs.map
|