@bitfab/sdk 0.76.6 → 0.76.8
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-B0HsiBQB.cjs → autoTrace-BtiEpHTN.cjs} +40 -3
- package/dist/autoTrace-BtiEpHTN.cjs.map +1 -0
- package/dist/{autoTrace-g3y0sLPq.js → autoTrace-RWUOk1WF.js} +17 -4
- package/dist/autoTrace-RWUOk1WF.js.map +1 -0
- package/dist/autoTrace.cjs +1 -1
- package/dist/autoTrace.js +1 -1
- package/dist/{http-DZlsxUgc.js → http-DHXjaX-W.js} +3 -3
- package/dist/{http-DZlsxUgc.js.map → http-DHXjaX-W.js.map} +1 -1
- package/dist/{http-C6oeysq-.cjs → http-E8Qa7I4v.cjs} +3 -3
- package/dist/{http-C6oeysq-.cjs.map → http-E8Qa7I4v.cjs.map} +1 -1
- package/dist/{index-DjGNdF9p.d.cts → index-B8gVPP6Y.d.cts} +14 -1
- package/dist/{index-DjGNdF9p.d.ts → index-B8gVPP6Y.d.ts} +14 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/node.cjs +3 -3
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +3 -3
- package/dist/{registryCommand-UEUDL6JV.js → registryCommand-D9EkYtKh.js} +6 -3
- package/dist/registryCommand-D9EkYtKh.js.map +1 -0
- package/dist/replayCli.js +1 -1
- package/dist/seedCli.js +1 -1
- package/dist/{src-DIJP4CNn.js → src-BnELQNAx.js} +113 -62
- package/dist/src-BnELQNAx.js.map +1 -0
- package/dist/{src-CI_xliRE.cjs → src-D3bpLZ98.cjs} +113 -62
- package/dist/src-D3bpLZ98.cjs.map +1 -0
- package/package.json +1 -1
- package/dist/autoTrace-B0HsiBQB.cjs.map +0 -1
- package/dist/autoTrace-g3y0sLPq.js.map +0 -1
- package/dist/registryCommand-UEUDL6JV.js.map +0 -1
- package/dist/src-CI_xliRE.cjs.map +0 -1
- package/dist/src-DIJP4CNn.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_bamlPeer = require("./bamlPeer-BxJO7-pm.cjs");
|
|
2
|
-
const require_http = require("./http-
|
|
3
|
-
const require_autoTrace = require("./autoTrace-
|
|
2
|
+
const require_http = require("./http-E8Qa7I4v.cjs");
|
|
3
|
+
const require_autoTrace = require("./autoTrace-BtiEpHTN.cjs");
|
|
4
4
|
const require_optionalPeer = require("./optionalPeer-CUH756lt.cjs");
|
|
5
5
|
let superjson = require("superjson");
|
|
6
6
|
superjson = require_bamlPeer.__toESM(superjson, 1);
|
|
@@ -1545,11 +1545,11 @@ var GradersClient = class {
|
|
|
1545
1545
|
const JEV_PROVIDER = "typesafe";
|
|
1546
1546
|
const JEV_WATCH_STORAGE_SYMBOL = Symbol.for("bitfab.jevWatchStorage");
|
|
1547
1547
|
const repliesRecordedByAutoTrace = /* @__PURE__ */ new WeakSet();
|
|
1548
|
-
function isRecord$
|
|
1548
|
+
function isRecord$6(value) {
|
|
1549
1549
|
return typeof value === "object" && value !== null;
|
|
1550
1550
|
}
|
|
1551
1551
|
function isJevReply(value) {
|
|
1552
|
-
return isRecord$
|
|
1552
|
+
return isRecord$6(value) && typeof value.model === "string" && isRecord$6(value.usage);
|
|
1553
1553
|
}
|
|
1554
1554
|
function tokenCount(usage, key) {
|
|
1555
1555
|
const count = usage[key];
|
|
@@ -1608,7 +1608,7 @@ function recordWatchedJevReply(span, watch, reply, durationMs) {
|
|
|
1608
1608
|
markEnclosingWatches(watch);
|
|
1609
1609
|
}
|
|
1610
1610
|
function isRecordedByAutoTrace(reply) {
|
|
1611
|
-
return isRecord$
|
|
1611
|
+
return isRecord$6(reply) && repliesRecordedByAutoTrace.has(reply);
|
|
1612
1612
|
}
|
|
1613
1613
|
function recordAutoTracedJev(invokeFn, span) {
|
|
1614
1614
|
const startedAt = Date.now();
|
|
@@ -2121,7 +2121,7 @@ var BitfabLangGraphCallbackHandler = class {
|
|
|
2121
2121
|
//#region src/integrationFixture.ts
|
|
2122
2122
|
const INTEGRATION_FIXTURE_CONTEXT_KEY = "__bitfabIntegrationFixture";
|
|
2123
2123
|
const INTEGRATION_FIXTURE_VERSION = 1;
|
|
2124
|
-
function isRecord$
|
|
2124
|
+
function isRecord$5(value) {
|
|
2125
2125
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2126
2126
|
}
|
|
2127
2127
|
function createIntegrationFixtureContext(name, value) {
|
|
@@ -2135,8 +2135,8 @@ function createIntegrationFixtureContext(name, value) {
|
|
|
2135
2135
|
}
|
|
2136
2136
|
function hasIntegrationFixture(contexts, name) {
|
|
2137
2137
|
return contexts.some((context) => {
|
|
2138
|
-
const fixture = isRecord$
|
|
2139
|
-
return isRecord$
|
|
2138
|
+
const fixture = isRecord$5(context) ? context[INTEGRATION_FIXTURE_CONTEXT_KEY] : void 0;
|
|
2139
|
+
return isRecord$5(fixture) && fixture.version === INTEGRATION_FIXTURE_VERSION && fixture.name === name;
|
|
2140
2140
|
});
|
|
2141
2141
|
}
|
|
2142
2142
|
function extractIntegrationFixtures(spanData) {
|
|
@@ -2144,9 +2144,9 @@ function extractIntegrationFixtures(spanData) {
|
|
|
2144
2144
|
if (!Array.isArray(contexts)) return;
|
|
2145
2145
|
const fixtures = /* @__PURE__ */ new Map();
|
|
2146
2146
|
for (const context of contexts) {
|
|
2147
|
-
if (!isRecord$
|
|
2147
|
+
if (!isRecord$5(context)) continue;
|
|
2148
2148
|
const fixture = context[INTEGRATION_FIXTURE_CONTEXT_KEY];
|
|
2149
|
-
if (!isRecord$
|
|
2149
|
+
if (!isRecord$5(fixture) || fixture.version !== INTEGRATION_FIXTURE_VERSION || typeof fixture.name !== "string" || fixtures.has(fixture.name)) continue;
|
|
2150
2150
|
fixtures.set(fixture.name, deserializeValue({
|
|
2151
2151
|
json: fixture.value,
|
|
2152
2152
|
...fixture.valueMeta !== void 0 && { meta: fixture.valueMeta }
|
|
@@ -2165,7 +2165,7 @@ const THREAD_CONFIG_KEYS = [
|
|
|
2165
2165
|
"checkpoint_ns",
|
|
2166
2166
|
"checkpoint_id"
|
|
2167
2167
|
];
|
|
2168
|
-
function isRecord$
|
|
2168
|
+
function isRecord$4(value) {
|
|
2169
2169
|
return typeof value === "object" && value !== null;
|
|
2170
2170
|
}
|
|
2171
2171
|
function toBase64(bytes) {
|
|
@@ -2192,12 +2192,12 @@ async function newMemorySaver() {
|
|
|
2192
2192
|
return new MemorySaver();
|
|
2193
2193
|
}
|
|
2194
2194
|
async function unstoredDeltaChannels(graph, tuple) {
|
|
2195
|
-
const channels = isRecord$
|
|
2196
|
-
if (!isRecord$
|
|
2195
|
+
const channels = isRecord$4(graph) ? graph.channels : void 0;
|
|
2196
|
+
if (!isRecord$4(channels)) return [];
|
|
2197
2197
|
const { DeltaChannel } = await loadLangGraphPeer();
|
|
2198
2198
|
if (DeltaChannel === void 0) return [];
|
|
2199
|
-
const versions = isRecord$
|
|
2200
|
-
const values = isRecord$
|
|
2199
|
+
const versions = isRecord$4(tuple.checkpoint.channel_versions) ? tuple.checkpoint.channel_versions : {};
|
|
2200
|
+
const values = isRecord$4(tuple.checkpoint.channel_values) ? tuple.checkpoint.channel_values : {};
|
|
2201
2201
|
return Object.entries(channels).filter(([name, spec]) => spec instanceof DeltaChannel && name in versions && !(name in values)).map(([name]) => name);
|
|
2202
2202
|
}
|
|
2203
2203
|
async function selfContained(graph, checkpointer, tuple) {
|
|
@@ -2210,27 +2210,27 @@ async function selfContained(graph, checkpointer, tuple) {
|
|
|
2210
2210
|
checkpoint: {
|
|
2211
2211
|
...tuple.checkpoint,
|
|
2212
2212
|
channel_values: {
|
|
2213
|
-
...isRecord$
|
|
2213
|
+
...isRecord$4(tuple.checkpoint.channel_values) ? tuple.checkpoint.channel_values : {},
|
|
2214
2214
|
...Object.fromEntries(names.filter((name) => name in values).map((name) => [name, values[name]]))
|
|
2215
2215
|
}
|
|
2216
2216
|
}
|
|
2217
2217
|
};
|
|
2218
2218
|
}
|
|
2219
2219
|
function savingCheckpointer(graph) {
|
|
2220
|
-
const own = isRecord$
|
|
2221
|
-
const inner = isRecord$
|
|
2220
|
+
const own = isRecord$4(graph) ? graph.checkpointer : void 0;
|
|
2221
|
+
const inner = isRecord$4(graph) && isRecord$4(graph.graph) ? graph.graph.checkpointer : void 0;
|
|
2222
2222
|
const checkpointer = own ?? inner;
|
|
2223
|
-
return isRecord$
|
|
2223
|
+
return isRecord$4(checkpointer) && typeof checkpointer.getTuple === "function" ? checkpointer : null;
|
|
2224
2224
|
}
|
|
2225
2225
|
function threadConfig(config) {
|
|
2226
|
-
const configurable = isRecord$
|
|
2226
|
+
const configurable = isRecord$4(config?.configurable) ? config.configurable : {};
|
|
2227
2227
|
return Object.fromEntries(THREAD_CONFIG_KEYS.filter((key) => key in configurable).map((key) => [key, configurable[key]]));
|
|
2228
2228
|
}
|
|
2229
2229
|
function withConfigurable(config, values) {
|
|
2230
2230
|
return {
|
|
2231
2231
|
...config ?? {},
|
|
2232
2232
|
configurable: {
|
|
2233
|
-
...isRecord$
|
|
2233
|
+
...isRecord$4(config?.configurable) ? config.configurable : {},
|
|
2234
2234
|
...values
|
|
2235
2235
|
}
|
|
2236
2236
|
};
|
|
@@ -2367,7 +2367,7 @@ var GraphRun = class {
|
|
|
2367
2367
|
}
|
|
2368
2368
|
async restoreThread(replay) {
|
|
2369
2369
|
const { saver, thread } = await restoredCheckpointer(replay.integrationFixtures?.get(this.fixtureName) ?? null);
|
|
2370
|
-
const configurable = isRecord$
|
|
2370
|
+
const configurable = isRecord$4(this.config?.configurable) ? this.config.configurable : {};
|
|
2371
2371
|
return {
|
|
2372
2372
|
saver,
|
|
2373
2373
|
thread: {
|
|
@@ -2381,19 +2381,19 @@ var GraphRun = class {
|
|
|
2381
2381
|
//#region src/langgraphIntegration.ts
|
|
2382
2382
|
const TOOL_RESULT_TAG = "__bitfabLangGraphToolResult";
|
|
2383
2383
|
const AGENT_MIDDLEWARE_BRAND = Symbol.for("AgentMiddleware");
|
|
2384
|
-
function isRecord$
|
|
2384
|
+
function isRecord$3(value) {
|
|
2385
2385
|
return typeof value === "object" && value !== null;
|
|
2386
2386
|
}
|
|
2387
2387
|
function isToolMessage(value) {
|
|
2388
|
-
return isRecord$
|
|
2388
|
+
return isRecord$3(value) && value.lc_direct_tool_output === true && value.type === "tool" && (typeof value.content === "string" || Array.isArray(value.content));
|
|
2389
2389
|
}
|
|
2390
2390
|
function isCommand(value) {
|
|
2391
|
-
return isRecord$
|
|
2391
|
+
return isRecord$3(value) && value.lg_name === "Command";
|
|
2392
2392
|
}
|
|
2393
2393
|
function encodeNested(value) {
|
|
2394
2394
|
if (isToolMessage(value) || isCommand(value)) return encodeNativeToolResult(value);
|
|
2395
2395
|
if (Array.isArray(value)) return value.map(encodeNested);
|
|
2396
|
-
if (isRecord$
|
|
2396
|
+
if (isRecord$3(value)) return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, encodeNested(entry)]));
|
|
2397
2397
|
return value;
|
|
2398
2398
|
}
|
|
2399
2399
|
function encodeNativeToolResult(value) {
|
|
@@ -2410,17 +2410,17 @@ function encodeNativeToolResult(value) {
|
|
|
2410
2410
|
};
|
|
2411
2411
|
return {
|
|
2412
2412
|
[TOOL_RESULT_TAG]: "command",
|
|
2413
|
-
graph: isRecord$
|
|
2414
|
-
update: isRecord$
|
|
2415
|
-
resume: isRecord$
|
|
2416
|
-
goto: isRecord$
|
|
2413
|
+
graph: isRecord$3(value) && typeof value.graph === "string" ? value.graph : void 0,
|
|
2414
|
+
update: isRecord$3(value) ? encodeNested(value.update) : void 0,
|
|
2415
|
+
resume: isRecord$3(value) ? encodeNested(value.resume) : void 0,
|
|
2416
|
+
goto: isRecord$3(value) ? encodeNested(value.goto) : void 0
|
|
2417
2417
|
};
|
|
2418
2418
|
}
|
|
2419
2419
|
function finalizeToolResult(value) {
|
|
2420
2420
|
return isToolMessage(value) || isCommand(value) ? encodeNativeToolResult(value) : value;
|
|
2421
2421
|
}
|
|
2422
2422
|
function isEncodedToolResult(value) {
|
|
2423
|
-
return isRecord$
|
|
2423
|
+
return isRecord$3(value) && typeof value[TOOL_RESULT_TAG] === "string";
|
|
2424
2424
|
}
|
|
2425
2425
|
async function loadPeer(specifierParts, packageName, docsPath) {
|
|
2426
2426
|
try {
|
|
@@ -2450,7 +2450,7 @@ async function loadLangGraph() {
|
|
|
2450
2450
|
async function reviveNested(value, toolCallId) {
|
|
2451
2451
|
if (isEncodedToolResult(value)) return reviveToolResult(value, toolCallId);
|
|
2452
2452
|
if (Array.isArray(value)) return Promise.all(value.map((entry) => reviveNested(entry, toolCallId)));
|
|
2453
|
-
if (isRecord$
|
|
2453
|
+
if (isRecord$3(value)) {
|
|
2454
2454
|
const entries = await Promise.all(Object.entries(value).map(async ([key, entry]) => [key, await reviveNested(entry, toolCallId)]));
|
|
2455
2455
|
return Object.fromEntries(entries);
|
|
2456
2456
|
}
|
|
@@ -2466,9 +2466,9 @@ async function reviveToolResult(value, toolCallId) {
|
|
|
2466
2466
|
...typeof value.id === "string" && { id: value.id },
|
|
2467
2467
|
...(value.status === "success" || value.status === "error") && { status: value.status },
|
|
2468
2468
|
...value.artifact !== void 0 && { artifact: await reviveNested(value.artifact, toolCallId) },
|
|
2469
|
-
...isRecord$
|
|
2470
|
-
...isRecord$
|
|
2471
|
-
...isRecord$
|
|
2469
|
+
...isRecord$3(value.metadata) && { metadata: await reviveNested(value.metadata, toolCallId) },
|
|
2470
|
+
...isRecord$3(value.additionalKwargs) && { additional_kwargs: await reviveNested(value.additionalKwargs, toolCallId) },
|
|
2471
|
+
...isRecord$3(value.responseMetadata) && { response_metadata: await reviveNested(value.responseMetadata, toolCallId) }
|
|
2472
2472
|
});
|
|
2473
2473
|
}
|
|
2474
2474
|
const { Command } = await loadLangGraph();
|
|
@@ -2545,7 +2545,7 @@ var BitfabLangGraphIntegration = class {
|
|
|
2545
2545
|
return middleware.includes(this.middleware) ? [...middleware] : [...middleware, this.middleware];
|
|
2546
2546
|
}
|
|
2547
2547
|
withSubagentMiddleware(spec) {
|
|
2548
|
-
if (!isRecord$
|
|
2548
|
+
if (!isRecord$3(spec) || "runnable" in spec || "graphId" in spec) return spec;
|
|
2549
2549
|
return {
|
|
2550
2550
|
...spec,
|
|
2551
2551
|
middleware: this.withMiddleware(Array.isArray(spec.middleware) ? spec.middleware : [])
|
|
@@ -2562,7 +2562,7 @@ var BitfabLangGraphIntegration = class {
|
|
|
2562
2562
|
return await this.runClaimedToolCall(traceId, toolCallId, toolName, shouldMock, request.toolCall.args, async () => await handler(request), stepSpanId);
|
|
2563
2563
|
}
|
|
2564
2564
|
stepSpanIdFor(config, traceId) {
|
|
2565
|
-
const namespace = isRecord$
|
|
2565
|
+
const namespace = isRecord$3(config) && isRecord$3(config.configurable) ? config.configurable.checkpoint_ns : void 0;
|
|
2566
2566
|
return typeof namespace === "string" ? this.callbackHandler.visibleStepSpanId(namespace, traceId) : null;
|
|
2567
2567
|
}
|
|
2568
2568
|
recordingTraceId(toolName) {
|
|
@@ -2609,8 +2609,8 @@ var BitfabLangGraphIntegration = class {
|
|
|
2609
2609
|
const originalInvoke = tool.invoke.bind(tool);
|
|
2610
2610
|
return new Proxy(tool, { get: (target, property) => {
|
|
2611
2611
|
if (property === "invoke") return async (input, ...rest) => {
|
|
2612
|
-
const toolCallId = isRecord$
|
|
2613
|
-
const args = isRecord$
|
|
2612
|
+
const toolCallId = isRecord$3(input) && typeof input.id === "string" ? input.id : "";
|
|
2613
|
+
const args = isRecord$3(input) && "args" in input ? input.args : input;
|
|
2614
2614
|
this.assertReplayToolResultExists(toolName, shouldMock);
|
|
2615
2615
|
const traceId = this.getActiveSpan()?.traceId ?? null;
|
|
2616
2616
|
const run = async () => await originalInvoke(input, ...rest);
|
|
@@ -2728,7 +2728,7 @@ function transcriptFixtureName(traceFunctionKey) {
|
|
|
2728
2728
|
return `pi-transcript:${traceFunctionKey}`;
|
|
2729
2729
|
}
|
|
2730
2730
|
function isTranscriptFixture(value) {
|
|
2731
|
-
return isRecord$
|
|
2731
|
+
return isRecord$2(value) && (value.method === "prompt" || value.method === "continue") && Array.isArray(value.messages);
|
|
2732
2732
|
}
|
|
2733
2733
|
function conversationMessages(messages) {
|
|
2734
2734
|
return messages.filter((message) => message?.role !== "system");
|
|
@@ -2788,17 +2788,17 @@ async function rethrowingKept(work) {
|
|
|
2788
2788
|
throw error;
|
|
2789
2789
|
}
|
|
2790
2790
|
}
|
|
2791
|
-
function isRecord$
|
|
2791
|
+
function isRecord$2(value) {
|
|
2792
2792
|
return typeof value === "object" && value !== null;
|
|
2793
2793
|
}
|
|
2794
2794
|
function isAgentLike(value) {
|
|
2795
|
-
return isRecord$
|
|
2795
|
+
return isRecord$2(value) && typeof value.prompt === "function" && typeof value.continue === "function" && isRecord$2(value.state) && Array.isArray(value.state.messages);
|
|
2796
2796
|
}
|
|
2797
2797
|
function isSessionLike(value) {
|
|
2798
|
-
return isRecord$
|
|
2798
|
+
return isRecord$2(value) && typeof value.prompt === "function" && isAgentLike(value.agent);
|
|
2799
2799
|
}
|
|
2800
2800
|
function isEventStream(value) {
|
|
2801
|
-
return isRecord$
|
|
2801
|
+
return isRecord$2(value) && typeof value.result === "function" && typeof value[Symbol.asyncIterator] === "function";
|
|
2802
2802
|
}
|
|
2803
2803
|
function failed(message) {
|
|
2804
2804
|
return typeof message?.stopReason === "string" && FAILED_STOP_REASONS.has(message.stopReason);
|
|
@@ -2827,7 +2827,7 @@ function usageContext(message, model) {
|
|
|
2827
2827
|
const modelName = message.model ?? model.id;
|
|
2828
2828
|
if (typeof modelName === "string") context.model = modelName;
|
|
2829
2829
|
const usage = message.usage;
|
|
2830
|
-
if (!isRecord$
|
|
2830
|
+
if (!isRecord$2(usage)) return context;
|
|
2831
2831
|
const entries = {
|
|
2832
2832
|
inputTokens: wholePromptTokens(usage),
|
|
2833
2833
|
outputTokens: asCount(usage.output),
|
|
@@ -2838,7 +2838,7 @@ function usageContext(message, model) {
|
|
|
2838
2838
|
return context;
|
|
2839
2839
|
}
|
|
2840
2840
|
function toolDeclarations(tools) {
|
|
2841
|
-
return tools.filter(isRecord$
|
|
2841
|
+
return tools.filter(isRecord$2).map((tool) => ({
|
|
2842
2842
|
name: tool.name,
|
|
2843
2843
|
description: tool.description,
|
|
2844
2844
|
parameters: tool.parameters
|
|
@@ -2919,7 +2919,7 @@ var BitfabPiIntegration = class {
|
|
|
2919
2919
|
});
|
|
2920
2920
|
const value = Reflect.get(target, property, proxy);
|
|
2921
2921
|
if (STREAM_FN_PROPERTY_NAMES_BY_RELEASE.has(property) && typeof value === "function") return this.wrapStreamFn(value);
|
|
2922
|
-
if (STATE_PROPERTIES.has(property) && isRecord$
|
|
2922
|
+
if (STATE_PROPERTIES.has(property) && isRecord$2(value)) return this.toolWrappingState(value);
|
|
2923
2923
|
if (HOOKS_RETURNING_CONTEXT.has(property) && typeof value === "function") return this.toolWrappingHook(value);
|
|
2924
2924
|
return value;
|
|
2925
2925
|
} });
|
|
@@ -2943,7 +2943,7 @@ var BitfabPiIntegration = class {
|
|
|
2943
2943
|
if (existing !== void 0) return existing;
|
|
2944
2944
|
const wrapped = async (...args) => {
|
|
2945
2945
|
const update = await hook(...args);
|
|
2946
|
-
if (!isRecord$
|
|
2946
|
+
if (!isRecord$2(update) || !isRecord$2(update.context)) return update;
|
|
2947
2947
|
const tools = update.context.tools;
|
|
2948
2948
|
if (!Array.isArray(tools)) return update;
|
|
2949
2949
|
return {
|
|
@@ -3101,7 +3101,7 @@ var BitfabPiIntegration = class {
|
|
|
3101
3101
|
return this.originalTools.get(tool) ?? tool;
|
|
3102
3102
|
}
|
|
3103
3103
|
wrapTool(tool) {
|
|
3104
|
-
if (!isRecord$
|
|
3104
|
+
if (!isRecord$2(tool) || typeof tool.execute !== "function" || wrappersByAnyIntegration.has(tool)) return tool;
|
|
3105
3105
|
const existing = this.wrappedTools.get(tool);
|
|
3106
3106
|
if (existing !== void 0) return existing;
|
|
3107
3107
|
const execute = tool.execute;
|
|
@@ -4785,7 +4785,7 @@ const QUEUE_MESSAGE_EFFECTS = /* @__PURE__ */ new Set([
|
|
|
4785
4785
|
"queue.tryNext",
|
|
4786
4786
|
"queue.tryNextBatch"
|
|
4787
4787
|
]);
|
|
4788
|
-
function isRecord(value) {
|
|
4788
|
+
function isRecord$1(value) {
|
|
4789
4789
|
return typeof value === "object" && value !== null;
|
|
4790
4790
|
}
|
|
4791
4791
|
function readProperty(value, property) {
|
|
@@ -4814,7 +4814,7 @@ function snapshotContext(context) {
|
|
|
4814
4814
|
if (typeof aborted === "boolean") snapshot.aborted = aborted;
|
|
4815
4815
|
else {
|
|
4816
4816
|
const abortSignal = readProperty(source, "abortSignal");
|
|
4817
|
-
if (isRecord(abortSignal)) {
|
|
4817
|
+
if (isRecord$1(abortSignal)) {
|
|
4818
4818
|
const signalAborted = readProperty(abortSignal, "aborted");
|
|
4819
4819
|
if (typeof signalAborted === "boolean") snapshot.aborted = signalAborted;
|
|
4820
4820
|
}
|
|
@@ -4855,7 +4855,7 @@ function fixtureName(traceFunctionKey) {
|
|
|
4855
4855
|
}
|
|
4856
4856
|
function snapshotFromReplay(traceFunctionKey, replay) {
|
|
4857
4857
|
const fixture = replay.integrationFixtures?.get(fixtureName(traceFunctionKey));
|
|
4858
|
-
if (!isRecord(fixture)) throw new require_http.BitfabError(`Trace "${traceFunctionKey}" has no Rivet context fixture. Capture a fresh trace with the Rivet integration before replaying it.`, RIVET_DOCS_URL);
|
|
4858
|
+
if (!isRecord$1(fixture)) throw new require_http.BitfabError(`Trace "${traceFunctionKey}" has no Rivet context fixture. Capture a fresh trace with the Rivet integration before replaying it.`, RIVET_DOCS_URL);
|
|
4859
4859
|
return fixture;
|
|
4860
4860
|
}
|
|
4861
4861
|
var BitfabRivetIntegration = class {
|
|
@@ -4866,7 +4866,7 @@ var BitfabRivetIntegration = class {
|
|
|
4866
4866
|
this.markedEffects = new Set(options.mockOnReplay ?? []);
|
|
4867
4867
|
}
|
|
4868
4868
|
withContext(context, fn) {
|
|
4869
|
-
if (!isRecord(context)) throw new require_http.BitfabError("Rivet withContext requires a context object");
|
|
4869
|
+
if (!isRecord$1(context)) throw new require_http.BitfabError("Rivet withContext requires a context object");
|
|
4870
4870
|
return runWithRivetContext({
|
|
4871
4871
|
context,
|
|
4872
4872
|
fixtureContext: createIntegrationFixtureContext(fixtureName(this.traceFunctionKey), snapshotContext(context)),
|
|
@@ -4932,7 +4932,7 @@ var BitfabRivetIntegration = class {
|
|
|
4932
4932
|
if (!binding) return;
|
|
4933
4933
|
const context = binding.context;
|
|
4934
4934
|
const target = readProperty(context, group);
|
|
4935
|
-
return isRecord(target) ? target : void 0;
|
|
4935
|
+
return isRecord$1(target) ? target : void 0;
|
|
4936
4936
|
};
|
|
4937
4937
|
const proxy = this.createMethodProxy(targetProvider, group, RIVET_GROUP_EFFECT_METHODS[group], replay);
|
|
4938
4938
|
if (group !== "queue") return proxy;
|
|
@@ -4981,10 +4981,10 @@ var BitfabRivetIntegration = class {
|
|
|
4981
4981
|
if (replay) return await callback(this.createMethodProxy(() => void 0, "db.transaction", ["execute"], replay));
|
|
4982
4982
|
const context = binding?.context;
|
|
4983
4983
|
const db = context ? readProperty(context, "db") : void 0;
|
|
4984
|
-
const transaction = isRecord(db) ? readProperty(db, "transaction") : void 0;
|
|
4985
|
-
if (!isRecord(db) || typeof transaction !== "function") throw unavailableCapability("db.transaction");
|
|
4984
|
+
const transaction = isRecord$1(db) ? readProperty(db, "transaction") : void 0;
|
|
4985
|
+
if (!isRecord$1(db) || typeof transaction !== "function") throw unavailableCapability("db.transaction");
|
|
4986
4986
|
return await transaction.call(db, async (transactionDb) => {
|
|
4987
|
-
if (!isRecord(transactionDb)) throw unavailableCapability("db.transaction.execute");
|
|
4987
|
+
if (!isRecord$1(transactionDb)) throw unavailableCapability("db.transaction.execute");
|
|
4988
4988
|
return await callback(this.createMethodProxy(() => transactionDb, "db.transaction", ["execute"], replay));
|
|
4989
4989
|
}, options);
|
|
4990
4990
|
};
|
|
@@ -4995,7 +4995,7 @@ var BitfabRivetIntegration = class {
|
|
|
4995
4995
|
return this.decorateQueueMessage(value, replay);
|
|
4996
4996
|
}
|
|
4997
4997
|
decorateQueueMessage(value, replay) {
|
|
4998
|
-
if (!isRecord(value)) return value;
|
|
4998
|
+
if (!isRecord$1(value)) return value;
|
|
4999
4999
|
const originalComplete = readProperty(value, "complete");
|
|
5000
5000
|
const complete = this.createEffect("queue.message.complete", () => typeof originalComplete === "function" ? { complete: originalComplete.bind(value) } : void 0, "complete", replay);
|
|
5001
5001
|
return {
|
|
@@ -5005,7 +5005,7 @@ var BitfabRivetIntegration = class {
|
|
|
5005
5005
|
}
|
|
5006
5006
|
queueCallIsCompletable(effect, args) {
|
|
5007
5007
|
const options = effect === "queue.waitForNames" || (effect === "queue.next" || effect === "queue.nextBatch") && typeof args[0] === "string" ? args[1] : args[0];
|
|
5008
|
-
return isRecord(options) && options.completable === true;
|
|
5008
|
+
return isRecord$1(options) && options.completable === true;
|
|
5009
5009
|
}
|
|
5010
5010
|
createQueueIterator(queue, options) {
|
|
5011
5011
|
return { async *[Symbol.asyncIterator]() {
|
|
@@ -5197,6 +5197,56 @@ function withoutDataRecords(edit) {
|
|
|
5197
5197
|
};
|
|
5198
5198
|
}
|
|
5199
5199
|
//#endregion
|
|
5200
|
+
//#region src/openaiAgentsUsage.ts
|
|
5201
|
+
const TOKEN_CONTEXT_KEYS = [
|
|
5202
|
+
"inputTokens",
|
|
5203
|
+
"outputTokens",
|
|
5204
|
+
"cachedInputTokens",
|
|
5205
|
+
"cacheReadTokens",
|
|
5206
|
+
"costUsd"
|
|
5207
|
+
];
|
|
5208
|
+
function isRecord(value) {
|
|
5209
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5210
|
+
}
|
|
5211
|
+
function modelResponses(spanData) {
|
|
5212
|
+
const firstOutput = Array.isArray(spanData.output) ? spanData.output[0] : void 0;
|
|
5213
|
+
return [
|
|
5214
|
+
spanData,
|
|
5215
|
+
spanData.response,
|
|
5216
|
+
firstOutput
|
|
5217
|
+
].filter(isRecord);
|
|
5218
|
+
}
|
|
5219
|
+
function modelCallModel(spanData) {
|
|
5220
|
+
return modelResponses(spanData).map((candidate) => candidate.model).find((model) => typeof model === "string" && model !== "");
|
|
5221
|
+
}
|
|
5222
|
+
function modelCallProvider(spanData, call) {
|
|
5223
|
+
const baseUrl = isRecord(spanData.model_config) ? spanData.model_config.base_url : void 0;
|
|
5224
|
+
if (require_autoTrace.isOpenRouterBaseUrl(baseUrl)) return "openrouter";
|
|
5225
|
+
return require_autoTrace.isAnthropicBaseUrl(baseUrl) ? "anthropic" : call.provider;
|
|
5226
|
+
}
|
|
5227
|
+
function hasTokenUsage(context) {
|
|
5228
|
+
return isRecord(context) && TOKEN_CONTEXT_KEYS.some((key) => typeof context[key] === "number" && Number.isFinite(context[key]));
|
|
5229
|
+
}
|
|
5230
|
+
function openAiAgentsUsageContext(spanData) {
|
|
5231
|
+
if (!isRecord(spanData) || !require_autoTrace.MODEL_CALL_SPAN_TYPES.has(String(spanData.type))) return null;
|
|
5232
|
+
const response = modelResponses(spanData).find((candidate) => isRecord(candidate.usage));
|
|
5233
|
+
if (response === void 0 || !isRecord(response.usage)) return null;
|
|
5234
|
+
const call = require_autoTrace.clientCallProviderForUsage(response.usage);
|
|
5235
|
+
const usage = Object.fromEntries(Object.entries(call.usage({ model: modelCallModel(spanData) }, response)).filter(([, value]) => value !== void 0));
|
|
5236
|
+
if (usage.inputTokens === void 0 && usage.outputTokens === void 0) return null;
|
|
5237
|
+
return {
|
|
5238
|
+
provider: modelCallProvider(spanData, call),
|
|
5239
|
+
...usage
|
|
5240
|
+
};
|
|
5241
|
+
}
|
|
5242
|
+
function addOpenAiAgentsUsageContext(spanData) {
|
|
5243
|
+
const existing = Array.isArray(spanData.contexts) ? spanData.contexts : [];
|
|
5244
|
+
if (existing.some(hasTokenUsage)) return;
|
|
5245
|
+
const context = openAiAgentsUsageContext(spanData);
|
|
5246
|
+
if (context === null) return;
|
|
5247
|
+
spanData.contexts = [...existing, context];
|
|
5248
|
+
}
|
|
5249
|
+
//#endregion
|
|
5200
5250
|
//#region src/tracing.ts
|
|
5201
5251
|
var BitfabOpenAITracingProcessor = class {
|
|
5202
5252
|
getCanonicalTraceId(sourceTraceId) {
|
|
@@ -5376,6 +5426,7 @@ var BitfabOpenAITracingProcessor = class {
|
|
|
5376
5426
|
const [serializedSpan, exportErrors] = this.exportSpan(span);
|
|
5377
5427
|
errors.push(...exportErrors);
|
|
5378
5428
|
this.extractSpanInputResponse(span, serializedSpan, errors);
|
|
5429
|
+
addOpenAiAgentsUsageContext(serializedSpan.span_data);
|
|
5379
5430
|
this.applySpanOverrides(serializedSpan, span.traceId ?? "");
|
|
5380
5431
|
const payload = this.buildSpanPayload(serializedSpan, errors);
|
|
5381
5432
|
const canonicalTraceId = span.traceId ? this.getCanonicalTraceId(span.traceId) : void 0;
|
|
@@ -7240,7 +7291,7 @@ var Bitfab = class {
|
|
|
7240
7291
|
await runWithSeedContext({ traceId }, async () => target(...args));
|
|
7241
7292
|
} finally {
|
|
7242
7293
|
try {
|
|
7243
|
-
const { flushTraces } = await Promise.resolve().then(() => require("./http-
|
|
7294
|
+
const { flushTraces } = await Promise.resolve().then(() => require("./http-E8Qa7I4v.cjs")).then((n) => n.http_exports);
|
|
7244
7295
|
await flushTraces(3e4);
|
|
7245
7296
|
} finally {
|
|
7246
7297
|
unrecorded = activeTraceStates.delete(traceId);
|
|
@@ -7461,7 +7512,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
|
|
|
7461
7512
|
metadata: seedCase.metadata,
|
|
7462
7513
|
sessionId: seedCase.sessionId
|
|
7463
7514
|
}));
|
|
7464
|
-
const { flushTraces } = await Promise.resolve().then(() => require("./http-
|
|
7515
|
+
const { flushTraces } = await Promise.resolve().then(() => require("./http-E8Qa7I4v.cjs")).then((n) => n.http_exports);
|
|
7465
7516
|
await flushTraces(3e4);
|
|
7466
7517
|
return {
|
|
7467
7518
|
pipeline,
|
|
@@ -7711,4 +7762,4 @@ Object.defineProperty(exports, "serializeReplayResult", {
|
|
|
7711
7762
|
}
|
|
7712
7763
|
});
|
|
7713
7764
|
|
|
7714
|
-
//# sourceMappingURL=src-
|
|
7765
|
+
//# sourceMappingURL=src-D3bpLZ98.cjs.map
|