@bitfab/sdk 0.54.9 → 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/{chunk-RNIFPMQM.js → chunk-EG2BK73V.js} +3 -3
- package/dist/chunk-EG2BK73V.js.map +1 -0
- package/dist/{chunk-UL4D3J5B.js → chunk-GQNLAY72.js} +4 -3
- package/dist/chunk-GQNLAY72.js.map +1 -0
- package/dist/{chunk-B7CO654C.js → chunk-MC2NKYDY.js} +6 -4
- package/dist/chunk-MC2NKYDY.js.map +1 -0
- package/dist/{chunk-I5Z3CTO6.js → chunk-NLJLEF7Q.js} +710 -16
- package/dist/chunk-NLJLEF7Q.js.map +1 -0
- package/dist/{chunk-4PMIFWUB.js → chunk-WEUG3N7A.js} +85 -40
- package/dist/chunk-WEUG3N7A.js.map +1 -0
- package/dist/{http-ARMDS4NC.js → http-3NVEDIBT.js} +2 -2
- package/dist/{http-FQNKAPY2.js → http-L357FQLN.js} +2 -2
- package/dist/index.cjs +801 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +130 -2
- package/dist/index.d.ts +130 -2
- package/dist/index.js +5 -3
- package/dist/node.cjs +801 -47
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +5 -3
- package/dist/node.js.map +1 -1
- package/dist/{replay-TTZS5HU2.js → replay-ZXA5AA2M.js} +3 -3
- package/dist/replayCli.js +2 -2
- package/dist/seedCli.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-4PMIFWUB.js.map +0 -1
- package/dist/chunk-B7CO654C.js.map +0 -1
- package/dist/chunk-I5Z3CTO6.js.map +0 -1
- package/dist/chunk-RNIFPMQM.js.map +0 -1
- package/dist/chunk-UL4D3J5B.js.map +0 -1
- /package/dist/{http-ARMDS4NC.js.map → http-3NVEDIBT.js.map} +0 -0
- /package/dist/{http-FQNKAPY2.js.map → http-L357FQLN.js.map} +0 -0
- /package/dist/{replay-TTZS5HU2.js.map → replay-ZXA5AA2M.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -42,7 +42,7 @@ var __version__, __packageName__;
|
|
|
42
42
|
var init_version_generated = __esm({
|
|
43
43
|
"src/version.generated.ts"() {
|
|
44
44
|
"use strict";
|
|
45
|
-
__version__ = "0.54.
|
|
45
|
+
__version__ = "0.54.11";
|
|
46
46
|
__packageName__ = "@bitfab/sdk";
|
|
47
47
|
}
|
|
48
48
|
});
|
|
@@ -68,20 +68,20 @@ var init_traceCompletion = __esm({
|
|
|
68
68
|
this.closed = /* @__PURE__ */ new Map();
|
|
69
69
|
}
|
|
70
70
|
state(traceId) {
|
|
71
|
-
let
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
this.traces.set(traceId,
|
|
71
|
+
let state2 = this.traces.get(traceId);
|
|
72
|
+
if (state2 === void 0) {
|
|
73
|
+
state2 = { spanIds: /* @__PURE__ */ new Set(), active: /* @__PURE__ */ new Set() };
|
|
74
|
+
this.traces.set(traceId, state2);
|
|
75
75
|
}
|
|
76
|
-
return
|
|
76
|
+
return state2;
|
|
77
77
|
}
|
|
78
78
|
start(traceId, spanId) {
|
|
79
79
|
if (this.closed.has(traceId)) {
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
const state2 = this.state(traceId);
|
|
83
|
+
state2.spanIds.add(spanId);
|
|
84
|
+
state2.active.add(spanId);
|
|
85
85
|
}
|
|
86
86
|
open(traceId) {
|
|
87
87
|
if (!this.closed.has(traceId)) {
|
|
@@ -97,24 +97,24 @@ var init_traceCompletion = __esm({
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
end(traceId, spanId) {
|
|
100
|
-
const
|
|
101
|
-
if (
|
|
102
|
-
|
|
103
|
-
this.drain(traceId,
|
|
100
|
+
const state2 = this.traces.get(traceId);
|
|
101
|
+
if (state2 !== void 0) {
|
|
102
|
+
state2.active.delete(spanId);
|
|
103
|
+
this.drain(traceId, state2);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
abort(traceId, spanId) {
|
|
107
|
-
const
|
|
108
|
-
if (
|
|
107
|
+
const state2 = this.traces.get(traceId);
|
|
108
|
+
if (state2 === void 0) {
|
|
109
109
|
return;
|
|
110
110
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (
|
|
111
|
+
state2.active.delete(spanId);
|
|
112
|
+
state2.spanIds.delete(spanId);
|
|
113
|
+
if (state2.active.size === 0 && state2.spanIds.size === 0 && state2.complete === void 0) {
|
|
114
114
|
this.traces.delete(traceId);
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
117
|
-
this.drain(traceId,
|
|
117
|
+
this.drain(traceId, state2);
|
|
118
118
|
}
|
|
119
119
|
close(traceId, complete, dropped = false) {
|
|
120
120
|
const count = this.closed.get(traceId);
|
|
@@ -122,29 +122,29 @@ var init_traceCompletion = __esm({
|
|
|
122
122
|
complete(count);
|
|
123
123
|
return;
|
|
124
124
|
}
|
|
125
|
-
const
|
|
126
|
-
if (
|
|
125
|
+
const state2 = this.traces.get(traceId);
|
|
126
|
+
if (state2 === void 0) {
|
|
127
127
|
return;
|
|
128
128
|
}
|
|
129
|
-
|
|
129
|
+
state2.complete = complete;
|
|
130
130
|
if (dropped) {
|
|
131
|
-
|
|
131
|
+
state2.active.clear();
|
|
132
132
|
}
|
|
133
|
-
this.drain(traceId,
|
|
133
|
+
this.drain(traceId, state2);
|
|
134
134
|
}
|
|
135
|
-
drain(traceId,
|
|
136
|
-
if (
|
|
135
|
+
drain(traceId, state2) {
|
|
136
|
+
if (state2.active.size !== 0 || state2.complete === void 0) {
|
|
137
137
|
return;
|
|
138
138
|
}
|
|
139
139
|
this.traces.delete(traceId);
|
|
140
|
-
this.closed.set(traceId,
|
|
140
|
+
this.closed.set(traceId, state2.spanIds.size);
|
|
141
141
|
if (this.closed.size > 1024) {
|
|
142
142
|
const oldest = this.closed.keys().next().value;
|
|
143
143
|
if (oldest !== void 0) {
|
|
144
144
|
this.closed.delete(oldest);
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
|
-
|
|
147
|
+
state2.complete(state2.spanIds.size);
|
|
148
148
|
}
|
|
149
149
|
};
|
|
150
150
|
}
|
|
@@ -395,8 +395,8 @@ function text(value) {
|
|
|
395
395
|
const trimmed = value?.trim();
|
|
396
396
|
return trimmed ? trimmed : null;
|
|
397
397
|
}
|
|
398
|
-
function isEmptyGitState(
|
|
399
|
-
return Object.values(
|
|
398
|
+
function isEmptyGitState(state2) {
|
|
399
|
+
return Object.values(state2).every((value) => value === null);
|
|
400
400
|
}
|
|
401
401
|
async function resolveGitState(cwd) {
|
|
402
402
|
const git = await gitRunner({
|
|
@@ -417,14 +417,14 @@ async function resolveGitState(cwd) {
|
|
|
417
417
|
if (!root) {
|
|
418
418
|
return null;
|
|
419
419
|
}
|
|
420
|
-
const
|
|
420
|
+
const state2 = {
|
|
421
421
|
githubEmail: text(email),
|
|
422
422
|
branch: text(branch),
|
|
423
423
|
commitSha: sha(commitSha),
|
|
424
424
|
baseSha: sha(baseSha),
|
|
425
425
|
experimentSha: await resolveWorkingTreeSha(run, root.trim())
|
|
426
426
|
};
|
|
427
|
-
return isEmptyGitState(
|
|
427
|
+
return isEmptyGitState(state2) ? null : state2;
|
|
428
428
|
}
|
|
429
429
|
async function resolveWorkingTreeSha(run, root) {
|
|
430
430
|
let indexPath;
|
|
@@ -827,8 +827,8 @@ function encodePayloadBody(payload) {
|
|
|
827
827
|
const marker = { error: `payload_serialize_failed: ${message}` };
|
|
828
828
|
return { body: JSON.stringify(marker), dropped, value: marker };
|
|
829
829
|
}
|
|
830
|
-
const
|
|
831
|
-
if (dropped.length > 0 &&
|
|
830
|
+
const isRecord6 = typeof sanitized === "object" && sanitized !== null && !Array.isArray(sanitized);
|
|
831
|
+
if (dropped.length > 0 && isRecord6) {
|
|
832
832
|
const obj = sanitized;
|
|
833
833
|
const existing = Array.isArray(obj.errors) ? obj.errors : [];
|
|
834
834
|
obj.errors = [
|
|
@@ -845,7 +845,7 @@ function encodePayloadBody(payload) {
|
|
|
845
845
|
return {
|
|
846
846
|
body: JSON.stringify(sanitized),
|
|
847
847
|
dropped,
|
|
848
|
-
value:
|
|
848
|
+
value: isRecord6 ? sanitized : void 0
|
|
849
849
|
};
|
|
850
850
|
}
|
|
851
851
|
}
|
|
@@ -947,13 +947,15 @@ var init_spanOrigin = __esm({
|
|
|
947
947
|
"openai-agents",
|
|
948
948
|
"langgraph",
|
|
949
949
|
"claude-agent-sdk",
|
|
950
|
-
"vercel-ai"
|
|
950
|
+
"vercel-ai",
|
|
951
|
+
"rivet"
|
|
951
952
|
];
|
|
952
953
|
FRAMEWORK_INSTRUMENTATIONS = [
|
|
953
954
|
"openai-agents",
|
|
954
955
|
"langgraph",
|
|
955
956
|
"claude-agent-sdk",
|
|
956
|
-
"vercel-ai"
|
|
957
|
+
"vercel-ai",
|
|
958
|
+
"rivet"
|
|
957
959
|
];
|
|
958
960
|
FRAMEWORK_INSTRUMENTATION_SET = new Set(
|
|
959
961
|
FRAMEWORK_INSTRUMENTATIONS
|
|
@@ -3457,6 +3459,55 @@ var init_codeChange = __esm({
|
|
|
3457
3459
|
}
|
|
3458
3460
|
});
|
|
3459
3461
|
|
|
3462
|
+
// src/integrationFixture.ts
|
|
3463
|
+
function isRecord4(value) {
|
|
3464
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3465
|
+
}
|
|
3466
|
+
function createIntegrationFixtureContext(name, value) {
|
|
3467
|
+
const serialized = serializeValue(value);
|
|
3468
|
+
return {
|
|
3469
|
+
[INTEGRATION_FIXTURE_CONTEXT_KEY]: {
|
|
3470
|
+
version: INTEGRATION_FIXTURE_VERSION,
|
|
3471
|
+
name,
|
|
3472
|
+
value: serialized.json,
|
|
3473
|
+
...serialized.meta !== void 0 && { valueMeta: serialized.meta }
|
|
3474
|
+
}
|
|
3475
|
+
};
|
|
3476
|
+
}
|
|
3477
|
+
function extractIntegrationFixtures(spanData) {
|
|
3478
|
+
const contexts = spanData.contexts;
|
|
3479
|
+
if (!Array.isArray(contexts)) {
|
|
3480
|
+
return void 0;
|
|
3481
|
+
}
|
|
3482
|
+
const fixtures = /* @__PURE__ */ new Map();
|
|
3483
|
+
for (const context of contexts) {
|
|
3484
|
+
if (!isRecord4(context)) {
|
|
3485
|
+
continue;
|
|
3486
|
+
}
|
|
3487
|
+
const fixture = context[INTEGRATION_FIXTURE_CONTEXT_KEY];
|
|
3488
|
+
if (!isRecord4(fixture) || fixture.version !== INTEGRATION_FIXTURE_VERSION || typeof fixture.name !== "string") {
|
|
3489
|
+
continue;
|
|
3490
|
+
}
|
|
3491
|
+
fixtures.set(
|
|
3492
|
+
fixture.name,
|
|
3493
|
+
deserializeValue({
|
|
3494
|
+
json: fixture.value,
|
|
3495
|
+
...fixture.valueMeta !== void 0 && { meta: fixture.valueMeta }
|
|
3496
|
+
})
|
|
3497
|
+
);
|
|
3498
|
+
}
|
|
3499
|
+
return fixtures.size > 0 ? fixtures : void 0;
|
|
3500
|
+
}
|
|
3501
|
+
var INTEGRATION_FIXTURE_CONTEXT_KEY, INTEGRATION_FIXTURE_VERSION;
|
|
3502
|
+
var init_integrationFixture = __esm({
|
|
3503
|
+
"src/integrationFixture.ts"() {
|
|
3504
|
+
"use strict";
|
|
3505
|
+
init_serialize();
|
|
3506
|
+
INTEGRATION_FIXTURE_CONTEXT_KEY = "__bitfabIntegrationFixture";
|
|
3507
|
+
INTEGRATION_FIXTURE_VERSION = 1;
|
|
3508
|
+
}
|
|
3509
|
+
});
|
|
3510
|
+
|
|
3460
3511
|
// src/replay.ts
|
|
3461
3512
|
var replay_exports = {};
|
|
3462
3513
|
__export(replay_exports, {
|
|
@@ -3681,6 +3732,7 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
|
|
|
3681
3732
|
const spanData = span.rawData?.span_data ?? {};
|
|
3682
3733
|
inputs = deserializeInputs(spanData);
|
|
3683
3734
|
originalOutput = deserializeOutput(spanData);
|
|
3735
|
+
const integrationFixtures = extractIntegrationFixtures(spanData);
|
|
3684
3736
|
if (adaptInputs) {
|
|
3685
3737
|
const originalMetadata = serverItem.originalMetadata;
|
|
3686
3738
|
inputs = adaptInputs(inputs, {
|
|
@@ -3772,6 +3824,7 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
|
|
|
3772
3824
|
mockStrategy,
|
|
3773
3825
|
mockOverrides: hasOverrides ? resolvedOverrides : void 0,
|
|
3774
3826
|
fetchSpanOutput,
|
|
3827
|
+
integrationFixtures,
|
|
3775
3828
|
dbBranchLease: lease,
|
|
3776
3829
|
dbBranchTimings
|
|
3777
3830
|
},
|
|
@@ -4252,6 +4305,7 @@ var init_replay = __esm({
|
|
|
4252
4305
|
init_codeChange();
|
|
4253
4306
|
init_errors();
|
|
4254
4307
|
init_http();
|
|
4308
|
+
init_integrationFixture();
|
|
4255
4309
|
init_mockOverride();
|
|
4256
4310
|
init_randomUuid();
|
|
4257
4311
|
init_replayContext();
|
|
@@ -4295,6 +4349,7 @@ __export(index_exports, {
|
|
|
4295
4349
|
BitfabLangGraphIntegration: () => BitfabLangGraphIntegration,
|
|
4296
4350
|
BitfabOpenAIAgentHandler: () => BitfabOpenAIAgentHandler,
|
|
4297
4351
|
BitfabOpenAITracingProcessor: () => BitfabOpenAITracingProcessor,
|
|
4352
|
+
BitfabRivetIntegration: () => BitfabRivetIntegration,
|
|
4298
4353
|
BitfabVercelAiHandler: () => BitfabVercelAiHandler,
|
|
4299
4354
|
DEFAULT_SERVICE_URL: () => DEFAULT_SERVICE_URL,
|
|
4300
4355
|
DatasetsClient: () => DatasetsClient,
|
|
@@ -6916,6 +6971,83 @@ var BitfabOpenAIAgentHandler = class {
|
|
|
6916
6971
|
}
|
|
6917
6972
|
};
|
|
6918
6973
|
|
|
6974
|
+
// src/openaiAgentsSpanContext.ts
|
|
6975
|
+
var OPENAI_AGENTS_CONTEXT_STORAGE = /* @__PURE__ */ Symbol.for(
|
|
6976
|
+
"openai.agents.core.asyncLocalStorage"
|
|
6977
|
+
);
|
|
6978
|
+
var MAX_OPENAI_AGENTS_SPAN_CHAIN = 64;
|
|
6979
|
+
var spanGlobal = globalThis;
|
|
6980
|
+
var state = spanGlobal.__bitfabOpenAiAgentsSpansV1 ?? {
|
|
6981
|
+
bitfabTraceIds: /* @__PURE__ */ new Map(),
|
|
6982
|
+
endedSpanIds: /* @__PURE__ */ new Map()
|
|
6983
|
+
};
|
|
6984
|
+
spanGlobal.__bitfabOpenAiAgentsSpansV1 = state;
|
|
6985
|
+
function mapOpenAiAgentsTrace(agentsTraceId, bitfabTraceId) {
|
|
6986
|
+
state.bitfabTraceIds.set(agentsTraceId, bitfabTraceId);
|
|
6987
|
+
}
|
|
6988
|
+
function unmapOpenAiAgentsTrace(agentsTraceId) {
|
|
6989
|
+
state.bitfabTraceIds.delete(agentsTraceId);
|
|
6990
|
+
state.endedSpanIds.delete(agentsTraceId);
|
|
6991
|
+
}
|
|
6992
|
+
function endOpenAiAgentsSpan(agentsTraceId, spanId) {
|
|
6993
|
+
if (!state.bitfabTraceIds.has(agentsTraceId)) {
|
|
6994
|
+
return;
|
|
6995
|
+
}
|
|
6996
|
+
const ended = state.endedSpanIds.get(agentsTraceId) ?? /* @__PURE__ */ new Set();
|
|
6997
|
+
ended.add(spanId);
|
|
6998
|
+
state.endedSpanIds.set(agentsTraceId, ended);
|
|
6999
|
+
}
|
|
7000
|
+
function isOpenAiAgentsContextStorage(value) {
|
|
7001
|
+
return value !== null && typeof value === "object" && typeof value.getStore === "function";
|
|
7002
|
+
}
|
|
7003
|
+
function currentOpenAiAgentsSpan() {
|
|
7004
|
+
const storage2 = spanGlobal[OPENAI_AGENTS_CONTEXT_STORAGE];
|
|
7005
|
+
if (!isOpenAiAgentsContextStorage(storage2)) {
|
|
7006
|
+
return void 0;
|
|
7007
|
+
}
|
|
7008
|
+
try {
|
|
7009
|
+
const store = storage2.getStore();
|
|
7010
|
+
return store?.active === true ? store.span ?? void 0 : void 0;
|
|
7011
|
+
} catch {
|
|
7012
|
+
return void 0;
|
|
7013
|
+
}
|
|
7014
|
+
}
|
|
7015
|
+
function currentOpenAiAgentsSpans() {
|
|
7016
|
+
const spans = [];
|
|
7017
|
+
let span = currentOpenAiAgentsSpan();
|
|
7018
|
+
while (span !== void 0 && spans.length < MAX_OPENAI_AGENTS_SPAN_CHAIN) {
|
|
7019
|
+
spans.push(span);
|
|
7020
|
+
span = span.previousSpan ?? void 0;
|
|
7021
|
+
}
|
|
7022
|
+
return spans;
|
|
7023
|
+
}
|
|
7024
|
+
function openAiAgentsSpanChain() {
|
|
7025
|
+
if (state.bitfabTraceIds.size === 0) {
|
|
7026
|
+
return [];
|
|
7027
|
+
}
|
|
7028
|
+
return currentOpenAiAgentsSpans().map((span) => span.spanId).filter((spanId) => typeof spanId === "string");
|
|
7029
|
+
}
|
|
7030
|
+
function openAiAgentsParentSpanId(bitfabTraceId, enclosingSpanIds) {
|
|
7031
|
+
if (state.bitfabTraceIds.size === 0) {
|
|
7032
|
+
return void 0;
|
|
7033
|
+
}
|
|
7034
|
+
for (const span of currentOpenAiAgentsSpans()) {
|
|
7035
|
+
if (typeof span.spanId !== "string" || typeof span.traceId !== "string") {
|
|
7036
|
+
return void 0;
|
|
7037
|
+
}
|
|
7038
|
+
if (state.bitfabTraceIds.get(span.traceId) !== bitfabTraceId) {
|
|
7039
|
+
return void 0;
|
|
7040
|
+
}
|
|
7041
|
+
if (enclosingSpanIds?.includes(span.spanId)) {
|
|
7042
|
+
return void 0;
|
|
7043
|
+
}
|
|
7044
|
+
if (!state.endedSpanIds.get(span.traceId)?.has(span.spanId)) {
|
|
7045
|
+
return span.spanId;
|
|
7046
|
+
}
|
|
7047
|
+
}
|
|
7048
|
+
return void 0;
|
|
7049
|
+
}
|
|
7050
|
+
|
|
6919
7051
|
// src/client.ts
|
|
6920
7052
|
init_policyRefresh();
|
|
6921
7053
|
init_randomUuid();
|
|
@@ -6969,6 +7101,533 @@ _context = new WeakMap();
|
|
|
6969
7101
|
// src/client.ts
|
|
6970
7102
|
init_replayContext();
|
|
6971
7103
|
|
|
7104
|
+
// src/rivetIntegration.ts
|
|
7105
|
+
init_errors();
|
|
7106
|
+
init_integrationFixture();
|
|
7107
|
+
init_replayContext();
|
|
7108
|
+
|
|
7109
|
+
// src/rivetContext.ts
|
|
7110
|
+
init_asyncStorage();
|
|
7111
|
+
var storage = null;
|
|
7112
|
+
var browserBinding = null;
|
|
7113
|
+
var STORAGE_SYMBOL = /* @__PURE__ */ Symbol.for("bitfab.rivetContextStorage");
|
|
7114
|
+
function initializeStorage() {
|
|
7115
|
+
if (storage) {
|
|
7116
|
+
return;
|
|
7117
|
+
}
|
|
7118
|
+
const shared = globalThis;
|
|
7119
|
+
const existing = shared[STORAGE_SYMBOL];
|
|
7120
|
+
if (existing) {
|
|
7121
|
+
storage = existing;
|
|
7122
|
+
return;
|
|
7123
|
+
}
|
|
7124
|
+
const created = createAsyncLocalStorage();
|
|
7125
|
+
if (created) {
|
|
7126
|
+
shared[STORAGE_SYMBOL] = created;
|
|
7127
|
+
storage = created;
|
|
7128
|
+
}
|
|
7129
|
+
}
|
|
7130
|
+
var rivetContextReady = asyncStorageReady.then(() => {
|
|
7131
|
+
initializeStorage();
|
|
7132
|
+
});
|
|
7133
|
+
function getRivetContextBinding() {
|
|
7134
|
+
initializeStorage();
|
|
7135
|
+
return storage?.getStore() ?? browserBinding ?? void 0;
|
|
7136
|
+
}
|
|
7137
|
+
function runWithBrowserBinding(binding, fn) {
|
|
7138
|
+
const previous = browserBinding;
|
|
7139
|
+
browserBinding = binding;
|
|
7140
|
+
try {
|
|
7141
|
+
const result = fn();
|
|
7142
|
+
if (result instanceof Promise) {
|
|
7143
|
+
return result.finally(() => {
|
|
7144
|
+
browserBinding = previous;
|
|
7145
|
+
});
|
|
7146
|
+
}
|
|
7147
|
+
browserBinding = previous;
|
|
7148
|
+
return result;
|
|
7149
|
+
} catch (error) {
|
|
7150
|
+
browserBinding = previous;
|
|
7151
|
+
throw error;
|
|
7152
|
+
}
|
|
7153
|
+
}
|
|
7154
|
+
function runWithRivetContext(binding, fn) {
|
|
7155
|
+
initializeStorage();
|
|
7156
|
+
if (!storage && !isAsyncStorageInitDone()) {
|
|
7157
|
+
return rivetContextReady.then(() => runWithRivetContext(binding, fn));
|
|
7158
|
+
}
|
|
7159
|
+
if (storage) {
|
|
7160
|
+
return storage.run(binding, fn);
|
|
7161
|
+
}
|
|
7162
|
+
return runWithBrowserBinding(binding, fn);
|
|
7163
|
+
}
|
|
7164
|
+
|
|
7165
|
+
// src/rivetIntegration.ts
|
|
7166
|
+
var RIVET_DOCS_URL = "https://docs.bitfab.ai/frameworks/rivet";
|
|
7167
|
+
var RIVET_GROUP_EFFECT_METHODS = {
|
|
7168
|
+
db: ["execute", "nativeMetrics", "close"],
|
|
7169
|
+
kv: [
|
|
7170
|
+
"get",
|
|
7171
|
+
"put",
|
|
7172
|
+
"delete",
|
|
7173
|
+
"batchPut",
|
|
7174
|
+
"batchGet",
|
|
7175
|
+
"batchDelete",
|
|
7176
|
+
"deleteRange",
|
|
7177
|
+
"listPrefix",
|
|
7178
|
+
"listRange",
|
|
7179
|
+
"list"
|
|
7180
|
+
],
|
|
7181
|
+
schedule: ["after", "at", "cancel", "get", "list"],
|
|
7182
|
+
cron: ["set", "every", "get", "list", "delete", "history"],
|
|
7183
|
+
queue: [
|
|
7184
|
+
"send",
|
|
7185
|
+
"next",
|
|
7186
|
+
"nextBatch",
|
|
7187
|
+
"waitForNames",
|
|
7188
|
+
"waitForAvailable",
|
|
7189
|
+
"complete",
|
|
7190
|
+
"enqueueAndWait",
|
|
7191
|
+
"tryNext",
|
|
7192
|
+
"tryNextBatch"
|
|
7193
|
+
],
|
|
7194
|
+
run: ["setWakeAt"]
|
|
7195
|
+
};
|
|
7196
|
+
var RIVET_TOP_LEVEL_EFFECTS = [
|
|
7197
|
+
"broadcast",
|
|
7198
|
+
"saveState",
|
|
7199
|
+
"sleep",
|
|
7200
|
+
"destroy"
|
|
7201
|
+
];
|
|
7202
|
+
var TOP_LEVEL_UNAVAILABLE_CAPABILITIES = /* @__PURE__ */ new Set([
|
|
7203
|
+
"conn",
|
|
7204
|
+
"conns",
|
|
7205
|
+
"log",
|
|
7206
|
+
"request",
|
|
7207
|
+
"actorRuntimeSocket",
|
|
7208
|
+
"keepAwake",
|
|
7209
|
+
"waitUntil",
|
|
7210
|
+
"client"
|
|
7211
|
+
]);
|
|
7212
|
+
var SYNC_VOID_EFFECTS = /* @__PURE__ */ new Set([
|
|
7213
|
+
"broadcast",
|
|
7214
|
+
"sleep",
|
|
7215
|
+
"destroy"
|
|
7216
|
+
]);
|
|
7217
|
+
var QUEUE_MESSAGE_EFFECTS = /* @__PURE__ */ new Set([
|
|
7218
|
+
"queue.next",
|
|
7219
|
+
"queue.nextBatch",
|
|
7220
|
+
"queue.waitForNames",
|
|
7221
|
+
"queue.tryNext",
|
|
7222
|
+
"queue.tryNextBatch"
|
|
7223
|
+
]);
|
|
7224
|
+
function isRecord5(value) {
|
|
7225
|
+
return typeof value === "object" && value !== null;
|
|
7226
|
+
}
|
|
7227
|
+
function readProperty(value, property) {
|
|
7228
|
+
try {
|
|
7229
|
+
return Reflect.get(value, property, value);
|
|
7230
|
+
} catch {
|
|
7231
|
+
return void 0;
|
|
7232
|
+
}
|
|
7233
|
+
}
|
|
7234
|
+
function snapshotContext(context) {
|
|
7235
|
+
const source = context;
|
|
7236
|
+
const snapshot = {};
|
|
7237
|
+
for (const property of [
|
|
7238
|
+
"state",
|
|
7239
|
+
"vars",
|
|
7240
|
+
"actorId",
|
|
7241
|
+
"name",
|
|
7242
|
+
"key",
|
|
7243
|
+
"region",
|
|
7244
|
+
"aborted"
|
|
7245
|
+
]) {
|
|
7246
|
+
const value = readProperty(source, property);
|
|
7247
|
+
if (value !== void 0) {
|
|
7248
|
+
snapshot[property] = value;
|
|
7249
|
+
}
|
|
7250
|
+
}
|
|
7251
|
+
return snapshot;
|
|
7252
|
+
}
|
|
7253
|
+
function unavailableCapability(path) {
|
|
7254
|
+
return new BitfabError(
|
|
7255
|
+
`Rivet context capability "${path}" is unavailable during replay. Add first-class support for that public context path before replaying code that uses it.`,
|
|
7256
|
+
RIVET_DOCS_URL
|
|
7257
|
+
);
|
|
7258
|
+
}
|
|
7259
|
+
function effectNode(traceFunctionKey, effect, mockSpanId) {
|
|
7260
|
+
return {
|
|
7261
|
+
traceFunctionKey,
|
|
7262
|
+
spanName: effect,
|
|
7263
|
+
type: "function",
|
|
7264
|
+
originalSpanId: mockSpanId
|
|
7265
|
+
};
|
|
7266
|
+
}
|
|
7267
|
+
function replayEffectStatus(replay2, traceFunctionKey, effect, marked) {
|
|
7268
|
+
const counterKey = `${traceFunctionKey}:${effect}`;
|
|
7269
|
+
const callIndex = replay2.callCounters?.get(counterKey) ?? 0;
|
|
7270
|
+
const mockSpan = replay2.mockTree?.spans.get(`${counterKey}:${callIndex}`);
|
|
7271
|
+
const hasOverride = replay2.mockOverrides?.some(
|
|
7272
|
+
(override) => override.match(
|
|
7273
|
+
effectNode(traceFunctionKey, effect, mockSpan?.sourceSpanId)
|
|
7274
|
+
)
|
|
7275
|
+
) ?? false;
|
|
7276
|
+
return {
|
|
7277
|
+
willMock: hasOverride || replay2.mockStrategy === "all" || replay2.mockStrategy === "marked" && marked,
|
|
7278
|
+
hasRecordedSpan: mockSpan !== void 0,
|
|
7279
|
+
hasOverride,
|
|
7280
|
+
callIndex
|
|
7281
|
+
};
|
|
7282
|
+
}
|
|
7283
|
+
function assertReplayEffectAvailable(replay2, traceFunctionKey, effect, marked) {
|
|
7284
|
+
if (!replay2) {
|
|
7285
|
+
return;
|
|
7286
|
+
}
|
|
7287
|
+
const status = replayEffectStatus(replay2, traceFunctionKey, effect, marked);
|
|
7288
|
+
if (!status.willMock) {
|
|
7289
|
+
throw new BitfabError(
|
|
7290
|
+
`Rivet effect "${effect}" has no live actor context during replay. Add "${effect}" to mockOnReplay or provide a replay override.`,
|
|
7291
|
+
RIVET_DOCS_URL
|
|
7292
|
+
);
|
|
7293
|
+
}
|
|
7294
|
+
if (!status.hasRecordedSpan && !status.hasOverride) {
|
|
7295
|
+
throw new BitfabError(
|
|
7296
|
+
`No recorded Rivet effect "${effect}" exists at call ${status.callIndex + 1}; the live effect was not executed.`,
|
|
7297
|
+
RIVET_DOCS_URL
|
|
7298
|
+
);
|
|
7299
|
+
}
|
|
7300
|
+
}
|
|
7301
|
+
function fixtureName(traceFunctionKey) {
|
|
7302
|
+
return `rivet:${traceFunctionKey}`;
|
|
7303
|
+
}
|
|
7304
|
+
function snapshotFromReplay(traceFunctionKey, replay2) {
|
|
7305
|
+
const fixture = replay2.integrationFixtures?.get(fixtureName(traceFunctionKey));
|
|
7306
|
+
if (!isRecord5(fixture)) {
|
|
7307
|
+
throw new BitfabError(
|
|
7308
|
+
`Trace "${traceFunctionKey}" has no Rivet context fixture. Capture a fresh trace with the Rivet integration before replaying it.`,
|
|
7309
|
+
RIVET_DOCS_URL
|
|
7310
|
+
);
|
|
7311
|
+
}
|
|
7312
|
+
return fixture;
|
|
7313
|
+
}
|
|
7314
|
+
var BitfabRivetIntegration = class {
|
|
7315
|
+
/** @internal Constructed by `Bitfab.getRivetIntegration()`. */
|
|
7316
|
+
constructor(traceFunctionKey, runtime, options = {}) {
|
|
7317
|
+
this.traceFunctionKey = traceFunctionKey;
|
|
7318
|
+
this.runtime = runtime;
|
|
7319
|
+
this.replayProxies = /* @__PURE__ */ new WeakMap();
|
|
7320
|
+
this.markedEffects = new Set(options.mockOnReplay ?? []);
|
|
7321
|
+
}
|
|
7322
|
+
/**
|
|
7323
|
+
* Run a callback with a live Rivet context bound to the current async chain.
|
|
7324
|
+
* This binds context only; it creates no trace or span.
|
|
7325
|
+
*/
|
|
7326
|
+
withContext(context, fn) {
|
|
7327
|
+
if (!isRecord5(context)) {
|
|
7328
|
+
throw new BitfabError("Rivet withContext requires a context object");
|
|
7329
|
+
}
|
|
7330
|
+
const binding = {
|
|
7331
|
+
context,
|
|
7332
|
+
fixtureContext: createIntegrationFixtureContext(
|
|
7333
|
+
fixtureName(this.traceFunctionKey),
|
|
7334
|
+
snapshotContext(context)
|
|
7335
|
+
),
|
|
7336
|
+
recordedRoots: /* @__PURE__ */ new Set()
|
|
7337
|
+
};
|
|
7338
|
+
return runWithRivetContext(binding, fn);
|
|
7339
|
+
}
|
|
7340
|
+
/**
|
|
7341
|
+
* Adapt a traced function into a Rivet handler whose first argument is the
|
|
7342
|
+
* live actor context. The context is not added to the traced root's inputs.
|
|
7343
|
+
*/
|
|
7344
|
+
bind(fn) {
|
|
7345
|
+
const integration = this;
|
|
7346
|
+
return function(context, ...args) {
|
|
7347
|
+
return integration.withContext(context, () => fn.apply(this, args));
|
|
7348
|
+
};
|
|
7349
|
+
}
|
|
7350
|
+
/**
|
|
7351
|
+
* Return the current Rivet context proxy. In production it delegates to the
|
|
7352
|
+
* bound live context. During replay it hydrates recorded actor state and
|
|
7353
|
+
* intercepts supported effects without requiring a live Rivet actor.
|
|
7354
|
+
*/
|
|
7355
|
+
getContext() {
|
|
7356
|
+
const replay2 = getReplayContext();
|
|
7357
|
+
if (replay2) {
|
|
7358
|
+
const existing = this.replayProxies.get(replay2);
|
|
7359
|
+
if (existing) {
|
|
7360
|
+
return existing;
|
|
7361
|
+
}
|
|
7362
|
+
const proxy = this.createContextProxy(
|
|
7363
|
+
snapshotFromReplay(this.traceFunctionKey, replay2),
|
|
7364
|
+
void 0
|
|
7365
|
+
);
|
|
7366
|
+
this.replayProxies.set(replay2, proxy);
|
|
7367
|
+
return proxy;
|
|
7368
|
+
}
|
|
7369
|
+
const binding = getRivetContextBinding();
|
|
7370
|
+
if (!binding) {
|
|
7371
|
+
throw new BitfabError(
|
|
7372
|
+
"No Rivet context is bound. Call rivet.bind(handler) or rivet.withContext(context, callback) at the Rivet boundary.",
|
|
7373
|
+
RIVET_DOCS_URL
|
|
7374
|
+
);
|
|
7375
|
+
}
|
|
7376
|
+
this.runtime.recordRootFixture(
|
|
7377
|
+
binding.fixtureContext,
|
|
7378
|
+
binding.recordedRoots
|
|
7379
|
+
);
|
|
7380
|
+
if (!binding.proxy) {
|
|
7381
|
+
binding.proxy = this.createContextProxy(
|
|
7382
|
+
binding.context,
|
|
7383
|
+
binding
|
|
7384
|
+
);
|
|
7385
|
+
}
|
|
7386
|
+
return binding.proxy;
|
|
7387
|
+
}
|
|
7388
|
+
createContextProxy(target, binding) {
|
|
7389
|
+
const replay2 = getReplayContext();
|
|
7390
|
+
const dbProxy = this.createDbProxy(binding, replay2);
|
|
7391
|
+
const groupProxies = /* @__PURE__ */ new Map();
|
|
7392
|
+
for (const group of Object.keys(
|
|
7393
|
+
RIVET_GROUP_EFFECT_METHODS
|
|
7394
|
+
)) {
|
|
7395
|
+
if (group !== "db") {
|
|
7396
|
+
groupProxies.set(group, this.createGroupProxy(group, binding, replay2));
|
|
7397
|
+
}
|
|
7398
|
+
}
|
|
7399
|
+
const topLevelEffects = /* @__PURE__ */ new Map();
|
|
7400
|
+
for (const effect of RIVET_TOP_LEVEL_EFFECTS) {
|
|
7401
|
+
topLevelEffects.set(
|
|
7402
|
+
effect,
|
|
7403
|
+
this.createEffect(
|
|
7404
|
+
effect,
|
|
7405
|
+
() => binding?.context,
|
|
7406
|
+
effect,
|
|
7407
|
+
replay2
|
|
7408
|
+
)
|
|
7409
|
+
);
|
|
7410
|
+
}
|
|
7411
|
+
const replayTarget = replay2 ? { ...target } : target;
|
|
7412
|
+
if (replay2) {
|
|
7413
|
+
const controller = new AbortController();
|
|
7414
|
+
if (target.aborted === true) {
|
|
7415
|
+
controller.abort();
|
|
7416
|
+
}
|
|
7417
|
+
replayTarget.abortSignal = controller.signal;
|
|
7418
|
+
}
|
|
7419
|
+
return new Proxy(replayTarget, {
|
|
7420
|
+
get: (source, property) => {
|
|
7421
|
+
if (property === "db") {
|
|
7422
|
+
return dbProxy;
|
|
7423
|
+
}
|
|
7424
|
+
if (typeof property === "string") {
|
|
7425
|
+
const group = groupProxies.get(property);
|
|
7426
|
+
if (group) {
|
|
7427
|
+
return group;
|
|
7428
|
+
}
|
|
7429
|
+
const effect = topLevelEffects.get(property);
|
|
7430
|
+
if (effect) {
|
|
7431
|
+
return effect;
|
|
7432
|
+
}
|
|
7433
|
+
}
|
|
7434
|
+
if (property === "setPreventSleep" && replay2) {
|
|
7435
|
+
return (_preventSleep) => void 0;
|
|
7436
|
+
}
|
|
7437
|
+
if (replay2 && typeof property === "string" && TOP_LEVEL_UNAVAILABLE_CAPABILITIES.has(property)) {
|
|
7438
|
+
throw unavailableCapability(property);
|
|
7439
|
+
}
|
|
7440
|
+
const value = Reflect.get(source, property, source);
|
|
7441
|
+
return typeof value === "function" ? value.bind(source) : value;
|
|
7442
|
+
}
|
|
7443
|
+
});
|
|
7444
|
+
}
|
|
7445
|
+
createDbProxy(binding, replay2) {
|
|
7446
|
+
const proxy = this.createGroupProxy("db", binding, replay2);
|
|
7447
|
+
return new Proxy(proxy, {
|
|
7448
|
+
get: (source, property) => property === "transaction" ? this.createTransaction(binding, replay2) : Reflect.get(source, property, source)
|
|
7449
|
+
});
|
|
7450
|
+
}
|
|
7451
|
+
createGroupProxy(group, binding, replay2) {
|
|
7452
|
+
const targetProvider = () => {
|
|
7453
|
+
if (!binding) {
|
|
7454
|
+
return void 0;
|
|
7455
|
+
}
|
|
7456
|
+
const context = binding.context;
|
|
7457
|
+
const target = readProperty(context, group);
|
|
7458
|
+
return isRecord5(target) ? target : void 0;
|
|
7459
|
+
};
|
|
7460
|
+
const proxy = this.createMethodProxy(
|
|
7461
|
+
targetProvider,
|
|
7462
|
+
group,
|
|
7463
|
+
RIVET_GROUP_EFFECT_METHODS[group],
|
|
7464
|
+
replay2
|
|
7465
|
+
);
|
|
7466
|
+
if (group !== "queue") {
|
|
7467
|
+
return proxy;
|
|
7468
|
+
}
|
|
7469
|
+
return new Proxy(proxy, {
|
|
7470
|
+
get: (source, property) => property === "iter" ? (options) => this.createQueueIterator(source, options) : Reflect.get(source, property, source)
|
|
7471
|
+
});
|
|
7472
|
+
}
|
|
7473
|
+
createMethodProxy(targetProvider, prefix, methods, replay2) {
|
|
7474
|
+
const effects = /* @__PURE__ */ new Map();
|
|
7475
|
+
for (const method of methods) {
|
|
7476
|
+
const effect = `${prefix}.${method}`;
|
|
7477
|
+
effects.set(
|
|
7478
|
+
method,
|
|
7479
|
+
this.createEffect(effect, targetProvider, method, replay2)
|
|
7480
|
+
);
|
|
7481
|
+
}
|
|
7482
|
+
return new Proxy(
|
|
7483
|
+
{},
|
|
7484
|
+
{
|
|
7485
|
+
get: (_source, property) => {
|
|
7486
|
+
if (typeof property === "string") {
|
|
7487
|
+
const effect = effects.get(property);
|
|
7488
|
+
if (effect) {
|
|
7489
|
+
return effect;
|
|
7490
|
+
}
|
|
7491
|
+
if (replay2) {
|
|
7492
|
+
throw unavailableCapability(`${prefix}.${property}`);
|
|
7493
|
+
}
|
|
7494
|
+
}
|
|
7495
|
+
const target = targetProvider();
|
|
7496
|
+
if (!target) {
|
|
7497
|
+
return void 0;
|
|
7498
|
+
}
|
|
7499
|
+
const value = Reflect.get(target, property, target);
|
|
7500
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
7501
|
+
}
|
|
7502
|
+
}
|
|
7503
|
+
);
|
|
7504
|
+
}
|
|
7505
|
+
createEffect(effect, targetProvider, methodName, replay2) {
|
|
7506
|
+
const marked = this.markedEffects.has(effect);
|
|
7507
|
+
const invoke = (...args) => {
|
|
7508
|
+
assertReplayEffectAvailable(
|
|
7509
|
+
getReplayContext(),
|
|
7510
|
+
this.traceFunctionKey,
|
|
7511
|
+
effect,
|
|
7512
|
+
marked
|
|
7513
|
+
);
|
|
7514
|
+
const target = targetProvider();
|
|
7515
|
+
const method = target ? readProperty(target, methodName) : void 0;
|
|
7516
|
+
if (typeof method !== "function") {
|
|
7517
|
+
throw unavailableCapability(effect);
|
|
7518
|
+
}
|
|
7519
|
+
return method.apply(target, args);
|
|
7520
|
+
};
|
|
7521
|
+
const wrapped = SYNC_VOID_EFFECTS.has(effect) ? this.runtime.wrapEffect(
|
|
7522
|
+
effect,
|
|
7523
|
+
marked,
|
|
7524
|
+
invoke,
|
|
7525
|
+
replay2 ? () => void 0 : void 0
|
|
7526
|
+
) : this.runtime.wrapEffect(effect, marked, async (...args) => {
|
|
7527
|
+
return await invoke(...args);
|
|
7528
|
+
});
|
|
7529
|
+
return (...args) => {
|
|
7530
|
+
if (replay2) {
|
|
7531
|
+
assertReplayEffectAvailable(
|
|
7532
|
+
replay2,
|
|
7533
|
+
this.traceFunctionKey,
|
|
7534
|
+
effect,
|
|
7535
|
+
marked
|
|
7536
|
+
);
|
|
7537
|
+
}
|
|
7538
|
+
const result = wrapped(...args);
|
|
7539
|
+
if (!QUEUE_MESSAGE_EFFECTS.has(effect) || !(result instanceof Promise)) {
|
|
7540
|
+
return result;
|
|
7541
|
+
}
|
|
7542
|
+
return result.then(
|
|
7543
|
+
(value) => this.decorateQueueMessages(value, effect, args, replay2)
|
|
7544
|
+
);
|
|
7545
|
+
};
|
|
7546
|
+
}
|
|
7547
|
+
createTransaction(binding, replay2) {
|
|
7548
|
+
return async (callback, options) => {
|
|
7549
|
+
if (typeof callback !== "function") {
|
|
7550
|
+
throw new BitfabError("Rivet db.transaction requires a callback");
|
|
7551
|
+
}
|
|
7552
|
+
if (replay2) {
|
|
7553
|
+
return await callback(
|
|
7554
|
+
this.createMethodProxy(
|
|
7555
|
+
() => void 0,
|
|
7556
|
+
"db.transaction",
|
|
7557
|
+
["execute"],
|
|
7558
|
+
replay2
|
|
7559
|
+
)
|
|
7560
|
+
);
|
|
7561
|
+
}
|
|
7562
|
+
const context = binding?.context;
|
|
7563
|
+
const db = context ? readProperty(context, "db") : void 0;
|
|
7564
|
+
const transaction = isRecord5(db) ? readProperty(db, "transaction") : void 0;
|
|
7565
|
+
if (!isRecord5(db) || typeof transaction !== "function") {
|
|
7566
|
+
throw unavailableCapability("db.transaction");
|
|
7567
|
+
}
|
|
7568
|
+
return await transaction.call(
|
|
7569
|
+
db,
|
|
7570
|
+
async (transactionDb) => {
|
|
7571
|
+
if (!isRecord5(transactionDb)) {
|
|
7572
|
+
throw unavailableCapability("db.transaction.execute");
|
|
7573
|
+
}
|
|
7574
|
+
return await callback(
|
|
7575
|
+
this.createMethodProxy(
|
|
7576
|
+
() => transactionDb,
|
|
7577
|
+
"db.transaction",
|
|
7578
|
+
["execute"],
|
|
7579
|
+
replay2
|
|
7580
|
+
)
|
|
7581
|
+
);
|
|
7582
|
+
},
|
|
7583
|
+
options
|
|
7584
|
+
);
|
|
7585
|
+
};
|
|
7586
|
+
}
|
|
7587
|
+
decorateQueueMessages(value, effect, args, replay2) {
|
|
7588
|
+
if (!this.queueCallIsCompletable(effect, args)) {
|
|
7589
|
+
return value;
|
|
7590
|
+
}
|
|
7591
|
+
if (Array.isArray(value)) {
|
|
7592
|
+
return value.map((message) => this.decorateQueueMessage(message, replay2));
|
|
7593
|
+
}
|
|
7594
|
+
return this.decorateQueueMessage(value, replay2);
|
|
7595
|
+
}
|
|
7596
|
+
decorateQueueMessage(value, replay2) {
|
|
7597
|
+
if (!isRecord5(value)) {
|
|
7598
|
+
return value;
|
|
7599
|
+
}
|
|
7600
|
+
const originalComplete = readProperty(value, "complete");
|
|
7601
|
+
const complete = this.createEffect(
|
|
7602
|
+
"queue.message.complete",
|
|
7603
|
+
() => typeof originalComplete === "function" ? { complete: originalComplete.bind(value) } : void 0,
|
|
7604
|
+
"complete",
|
|
7605
|
+
replay2
|
|
7606
|
+
);
|
|
7607
|
+
return { ...value, complete };
|
|
7608
|
+
}
|
|
7609
|
+
queueCallIsCompletable(effect, args) {
|
|
7610
|
+
const options = effect === "queue.waitForNames" ? args[1] : args[0];
|
|
7611
|
+
return isRecord5(options) && options.completable === true;
|
|
7612
|
+
}
|
|
7613
|
+
createQueueIterator(queue, options) {
|
|
7614
|
+
return {
|
|
7615
|
+
async *[Symbol.asyncIterator]() {
|
|
7616
|
+
for (; ; ) {
|
|
7617
|
+
const next = Reflect.get(queue, "next", queue);
|
|
7618
|
+
if (typeof next !== "function") {
|
|
7619
|
+
throw unavailableCapability("queue.next");
|
|
7620
|
+
}
|
|
7621
|
+
const message = await next.call(queue, options);
|
|
7622
|
+
if (message !== void 0 && message !== null) {
|
|
7623
|
+
yield message;
|
|
7624
|
+
}
|
|
7625
|
+
}
|
|
7626
|
+
}
|
|
7627
|
+
};
|
|
7628
|
+
}
|
|
7629
|
+
};
|
|
7630
|
+
|
|
6972
7631
|
// src/seedContext.ts
|
|
6973
7632
|
init_asyncStorage();
|
|
6974
7633
|
var seedContextStorage = null;
|
|
@@ -7112,6 +7771,9 @@ var BitfabOpenAITracingProcessor = class {
|
|
|
7112
7771
|
const activeContext = this.getActiveSpanContext?.();
|
|
7113
7772
|
if (activeContext) {
|
|
7114
7773
|
this.activeSpanMappings[trace.traceId] = activeContext;
|
|
7774
|
+
if (this.shouldRecord()) {
|
|
7775
|
+
mapOpenAiAgentsTrace(trace.traceId, activeContext.traceId);
|
|
7776
|
+
}
|
|
7115
7777
|
}
|
|
7116
7778
|
const canonicalTraceId = activeContext?.traceId ?? this.getCanonicalTraceId(trace.traceId);
|
|
7117
7779
|
this.canonicalTraceIds[trace.traceId] = canonicalTraceId;
|
|
@@ -7149,6 +7811,7 @@ var BitfabOpenAITracingProcessor = class {
|
|
|
7149
7811
|
}
|
|
7150
7812
|
this.endedTraces.delete(traceId);
|
|
7151
7813
|
delete this.activeSpanMappings[traceId];
|
|
7814
|
+
unmapOpenAiAgentsTrace(traceId);
|
|
7152
7815
|
delete this.canonicalTraceIds[traceId];
|
|
7153
7816
|
delete this.activeTraces[traceId];
|
|
7154
7817
|
}
|
|
@@ -7173,6 +7836,9 @@ var BitfabOpenAITracingProcessor = class {
|
|
|
7173
7836
|
async onSpanEnd(span) {
|
|
7174
7837
|
const originalTraceId = span.traceId ?? "";
|
|
7175
7838
|
const traceId = this.activeSpanMappings[originalTraceId]?.traceId ?? originalTraceId;
|
|
7839
|
+
if (span.spanId !== void 0) {
|
|
7840
|
+
endOpenAiAgentsSpan(originalTraceId, span.spanId);
|
|
7841
|
+
}
|
|
7176
7842
|
try {
|
|
7177
7843
|
this.sendSpan(span);
|
|
7178
7844
|
} finally {
|
|
@@ -7193,6 +7859,9 @@ var BitfabOpenAITracingProcessor = class {
|
|
|
7193
7859
|
* Called when the trace processor is shutting down.
|
|
7194
7860
|
*/
|
|
7195
7861
|
async shutdown(timeout) {
|
|
7862
|
+
for (const traceId of Object.keys(this.activeSpanMappings)) {
|
|
7863
|
+
unmapOpenAiAgentsTrace(traceId);
|
|
7864
|
+
}
|
|
7196
7865
|
this.activeTraces = {};
|
|
7197
7866
|
this.activeSpanMappings = {};
|
|
7198
7867
|
this.canonicalTraceIds = {};
|
|
@@ -8350,16 +9019,16 @@ var Bitfab = class {
|
|
|
8350
9019
|
this.simulationPlan.send(payload, rootTraceFunctionKeyOf(payload), submit);
|
|
8351
9020
|
}
|
|
8352
9021
|
refreshAutoTraceCapturePolicy(traceFunctionKey) {
|
|
8353
|
-
const
|
|
8354
|
-
this.autoTracePolicyRefreshes.set(traceFunctionKey,
|
|
8355
|
-
|
|
9022
|
+
const state2 = this.autoTracePolicyRefreshes.get(traceFunctionKey) ?? new PolicyRefresh();
|
|
9023
|
+
this.autoTracePolicyRefreshes.set(traceFunctionKey, state2);
|
|
9024
|
+
state2.run(
|
|
8356
9025
|
() => this.httpClient.getAutoTracePolicy(
|
|
8357
9026
|
traceFunctionKey,
|
|
8358
9027
|
AUTO_TRACE_PROTOCOL
|
|
8359
9028
|
),
|
|
8360
9029
|
(policy) => {
|
|
8361
9030
|
if (policy.protocol !== AUTO_TRACE_PROTOCOL) {
|
|
8362
|
-
|
|
9031
|
+
state2.hold(AUTO_TRACE_POLICY_RETRY_MS);
|
|
8363
9032
|
return;
|
|
8364
9033
|
}
|
|
8365
9034
|
const functionIds = Array.isArray(policy.functionIds) ? policy.functionIds.filter(
|
|
@@ -8370,10 +9039,10 @@ var Bitfab = class {
|
|
|
8370
9039
|
traceFunctionKey,
|
|
8371
9040
|
policy.revision === null ? void 0 : functionIds
|
|
8372
9041
|
);
|
|
8373
|
-
|
|
9042
|
+
state2.hold(AUTO_TRACE_POLICY_REFRESH_MS);
|
|
8374
9043
|
},
|
|
8375
9044
|
() => {
|
|
8376
|
-
|
|
9045
|
+
state2.hold(AUTO_TRACE_POLICY_RETRY_MS);
|
|
8377
9046
|
}
|
|
8378
9047
|
);
|
|
8379
9048
|
}
|
|
@@ -8678,6 +9347,47 @@ var Bitfab = class {
|
|
|
8678
9347
|
options
|
|
8679
9348
|
});
|
|
8680
9349
|
}
|
|
9350
|
+
/**
|
|
9351
|
+
* Get the first-class Rivet actor-context integration for an existing trace
|
|
9352
|
+
* root. The integration binds context and records effect spans; it never
|
|
9353
|
+
* creates another root.
|
|
9354
|
+
*
|
|
9355
|
+
* @param traceFunctionKey - Key used by the enclosing `withTrace()` root
|
|
9356
|
+
* @param options - Explicit per-context-path replay mocking policy
|
|
9357
|
+
* @experimental This API may change before it is stable.
|
|
9358
|
+
*/
|
|
9359
|
+
getRivetIntegration(traceFunctionKey, options) {
|
|
9360
|
+
return new BitfabRivetIntegration(
|
|
9361
|
+
traceFunctionKey,
|
|
9362
|
+
{
|
|
9363
|
+
wrapEffect: (effect, mockOnReplay, fn, replayOutput) => {
|
|
9364
|
+
const spanOptions = {
|
|
9365
|
+
name: effect,
|
|
9366
|
+
type: "function",
|
|
9367
|
+
captureWhen: "nested",
|
|
9368
|
+
mockOnReplay,
|
|
9369
|
+
surface: "inherit",
|
|
9370
|
+
instrumentation: "rivet",
|
|
9371
|
+
...replayOutput !== void 0 && { replayOutput }
|
|
9372
|
+
};
|
|
9373
|
+
return this.withSpan(traceFunctionKey, spanOptions, fn);
|
|
9374
|
+
},
|
|
9375
|
+
recordRootFixture: (context, recordedRoots) => {
|
|
9376
|
+
const root = getSpanStack()[0];
|
|
9377
|
+
if (!root) {
|
|
9378
|
+
return;
|
|
9379
|
+
}
|
|
9380
|
+
const rootId = `${root.traceId}:${root.spanId}`;
|
|
9381
|
+
if (recordedRoots.has(rootId)) {
|
|
9382
|
+
return;
|
|
9383
|
+
}
|
|
9384
|
+
root.contexts.push(context);
|
|
9385
|
+
recordedRoots.add(rootId);
|
|
9386
|
+
}
|
|
9387
|
+
},
|
|
9388
|
+
options
|
|
9389
|
+
);
|
|
9390
|
+
}
|
|
8681
9391
|
/**
|
|
8682
9392
|
* Get a Claude Agent SDK handler for tracing.
|
|
8683
9393
|
*
|
|
@@ -8943,7 +9653,11 @@ var Bitfab = class {
|
|
|
8943
9653
|
const seedCtxForTraceId = parentContext ? null : getSeedContext();
|
|
8944
9654
|
const traceId = parentContext?.traceId ?? replayCtxForTraceId?.traceId ?? seedCtxForTraceId?.traceId ?? randomUuid();
|
|
8945
9655
|
const spanId = randomUuid();
|
|
8946
|
-
const
|
|
9656
|
+
const openAiAgentsParent = parentContext !== void 0 && options.instrumentation === "trace" ? openAiAgentsParentSpanId(
|
|
9657
|
+
parentContext.traceId,
|
|
9658
|
+
parentContext.openAiAgentsSpanIds
|
|
9659
|
+
) : void 0;
|
|
9660
|
+
const parentSpanId = openAiAgentsParent ?? parentContext?.spanId ?? null;
|
|
8947
9661
|
const isRootSpan = parentSpanId === null;
|
|
8948
9662
|
if (options.enclosingTrace !== void 0) {
|
|
8949
9663
|
options.enclosingTrace.link.traceId = traceId;
|
|
@@ -8957,11 +9671,13 @@ var Bitfab = class {
|
|
|
8957
9671
|
parentContext?.surface,
|
|
8958
9672
|
traceFunctionKey
|
|
8959
9673
|
);
|
|
9674
|
+
const openAiAgentsSpanIds = openAiAgentsSpanChain();
|
|
8960
9675
|
const newContext = {
|
|
8961
9676
|
traceId,
|
|
8962
9677
|
spanId,
|
|
8963
9678
|
contexts: [],
|
|
8964
|
-
...surface !== void 0 && { surface }
|
|
9679
|
+
...surface !== void 0 && { surface },
|
|
9680
|
+
...openAiAgentsSpanIds.length > 0 && { openAiAgentsSpanIds }
|
|
8965
9681
|
};
|
|
8966
9682
|
newStack = [...currentStack, newContext];
|
|
8967
9683
|
const inputs = args;
|
|
@@ -9176,6 +9892,7 @@ var Bitfab = class {
|
|
|
9176
9892
|
}
|
|
9177
9893
|
return output;
|
|
9178
9894
|
};
|
|
9895
|
+
const resolveBaseOutput = () => options.replayOutput !== void 0 ? options.replayOutput() : resolveRecordedOutput();
|
|
9179
9896
|
const shouldMockWithBaseStrategy = replayCtxForMock.mockStrategy === "all" || replayCtxForMock.mockStrategy === "marked" && options.mockOnReplay === true;
|
|
9180
9897
|
if (replayCtxForMock.mockOverrides?.length) {
|
|
9181
9898
|
const nodeMeta = {
|
|
@@ -9232,7 +9949,7 @@ var Bitfab = class {
|
|
|
9232
9949
|
}
|
|
9233
9950
|
if (shouldMockWithBaseStrategy) {
|
|
9234
9951
|
const output = await resolveMockOrAbort(
|
|
9235
|
-
() =>
|
|
9952
|
+
() => resolveBaseOutput()
|
|
9236
9953
|
);
|
|
9237
9954
|
void sendSpan({
|
|
9238
9955
|
result: output,
|
|
@@ -9255,7 +9972,7 @@ var Bitfab = class {
|
|
|
9255
9972
|
);
|
|
9256
9973
|
}
|
|
9257
9974
|
if (shouldMockWithBaseStrategy) {
|
|
9258
|
-
const recorded =
|
|
9975
|
+
const recorded = resolveBaseOutput();
|
|
9259
9976
|
if (recorded instanceof Promise) {
|
|
9260
9977
|
return emitMockAsync(recorded, "recorded");
|
|
9261
9978
|
}
|
|
@@ -9857,6 +10574,28 @@ var BitfabFunction = class {
|
|
|
9857
10574
|
span(options = {}) {
|
|
9858
10575
|
return this.client.span(this.traceFunctionKey, options);
|
|
9859
10576
|
}
|
|
10577
|
+
withTrace(optionsOrFn, maybeFn) {
|
|
10578
|
+
if (typeof optionsOrFn === "function") {
|
|
10579
|
+
return this.client.withTrace(this.traceFunctionKey, optionsOrFn);
|
|
10580
|
+
}
|
|
10581
|
+
if (!maybeFn) {
|
|
10582
|
+
throw new BitfabError("BitfabFunction.withTrace requires a function");
|
|
10583
|
+
}
|
|
10584
|
+
return this.client.withTrace(this.traceFunctionKey, optionsOrFn, maybeFn);
|
|
10585
|
+
}
|
|
10586
|
+
/**
|
|
10587
|
+
* Create a trace method decorator bound to this function's key.
|
|
10588
|
+
*
|
|
10589
|
+
* Equivalent to `client.trace(key, options)` but reuses the key bound on
|
|
10590
|
+
* this handle.
|
|
10591
|
+
*
|
|
10592
|
+
* @param options - Trace configuration applied to the decorated method
|
|
10593
|
+
* @returns A method decorator configured for this key
|
|
10594
|
+
* @experimental Automatic child-call instrumentation is experimental.
|
|
10595
|
+
*/
|
|
10596
|
+
trace(options = {}) {
|
|
10597
|
+
return this.client.trace(this.traceFunctionKey, options);
|
|
10598
|
+
}
|
|
9860
10599
|
/**
|
|
9861
10600
|
* Get a Vercel AI SDK language-model middleware bound to this function's key.
|
|
9862
10601
|
*
|
|
@@ -9954,6 +10693,20 @@ var BitfabFunction = class {
|
|
|
9954
10693
|
getLangGraphIntegration(options) {
|
|
9955
10694
|
return this.client.getLangGraphIntegration(this.traceFunctionKey, options);
|
|
9956
10695
|
}
|
|
10696
|
+
/**
|
|
10697
|
+
* Get the first-class Rivet actor-context integration bound to this key.
|
|
10698
|
+
* Use its `bind()` or `withContext()` outside this handle's `withTrace()`
|
|
10699
|
+
* root, then call `getContext()` inside the root.
|
|
10700
|
+
*
|
|
10701
|
+
* @param options - Explicit per-context-path replay mocking policy
|
|
10702
|
+
* @experimental This API may change before it is stable.
|
|
10703
|
+
*/
|
|
10704
|
+
getRivetIntegration(options) {
|
|
10705
|
+
return this.client.getRivetIntegration(
|
|
10706
|
+
this.traceFunctionKey,
|
|
10707
|
+
options
|
|
10708
|
+
);
|
|
10709
|
+
}
|
|
9957
10710
|
/**
|
|
9958
10711
|
* Wrap a BAML client method to automatically capture prompt and LLM metadata.
|
|
9959
10712
|
* Delegates to the parent client's wrapBAML method.
|
|
@@ -10115,6 +10868,7 @@ function resolveTraceFunctionKey(registration) {
|
|
|
10115
10868
|
BitfabLangGraphIntegration,
|
|
10116
10869
|
BitfabOpenAIAgentHandler,
|
|
10117
10870
|
BitfabOpenAITracingProcessor,
|
|
10871
|
+
BitfabRivetIntegration,
|
|
10118
10872
|
BitfabVercelAiHandler,
|
|
10119
10873
|
DEFAULT_SERVICE_URL,
|
|
10120
10874
|
DatasetsClient,
|