@bitfab/sdk 0.54.9 → 0.54.10
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-I5Z3CTO6.js → chunk-3F7SICKD.js} +609 -8
- package/dist/chunk-3F7SICKD.js.map +1 -0
- package/dist/{chunk-UL4D3J5B.js → chunk-6KVKJQNH.js} +4 -3
- package/dist/chunk-6KVKJQNH.js.map +1 -0
- package/dist/{chunk-RNIFPMQM.js → chunk-NDWA6QLU.js} +3 -3
- package/dist/chunk-NDWA6QLU.js.map +1 -0
- package/dist/{chunk-4PMIFWUB.js → chunk-VJOLQ7UY.js} +85 -40
- package/dist/chunk-VJOLQ7UY.js.map +1 -0
- package/dist/{chunk-B7CO654C.js → chunk-XREH4NJT.js} +6 -4
- package/dist/chunk-XREH4NJT.js.map +1 -0
- package/dist/{http-FQNKAPY2.js → http-NPOFVS25.js} +2 -2
- package/dist/{http-ARMDS4NC.js → http-NVPWO4TN.js} +2 -2
- package/dist/index.cjs +669 -8
- 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 +669 -8
- 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-OMXCRECR.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-NPOFVS25.js.map} +0 -0
- /package/dist/{http-FQNKAPY2.js.map → http-NVPWO4TN.js.map} +0 -0
- /package/dist/{replay-TTZS5HU2.js.map → replay-OMXCRECR.js.map} +0 -0
package/dist/node.cjs
CHANGED
|
@@ -88,7 +88,7 @@ var __version__, __packageName__;
|
|
|
88
88
|
var init_version_generated = __esm({
|
|
89
89
|
"src/version.generated.ts"() {
|
|
90
90
|
"use strict";
|
|
91
|
-
__version__ = "0.54.
|
|
91
|
+
__version__ = "0.54.10";
|
|
92
92
|
__packageName__ = "@bitfab/sdk";
|
|
93
93
|
}
|
|
94
94
|
});
|
|
@@ -834,8 +834,8 @@ function encodePayloadBody(payload) {
|
|
|
834
834
|
const marker = { error: `payload_serialize_failed: ${message}` };
|
|
835
835
|
return { body: JSON.stringify(marker), dropped, value: marker };
|
|
836
836
|
}
|
|
837
|
-
const
|
|
838
|
-
if (dropped.length > 0 &&
|
|
837
|
+
const isRecord6 = typeof sanitized === "object" && sanitized !== null && !Array.isArray(sanitized);
|
|
838
|
+
if (dropped.length > 0 && isRecord6) {
|
|
839
839
|
const obj = sanitized;
|
|
840
840
|
const existing = Array.isArray(obj.errors) ? obj.errors : [];
|
|
841
841
|
obj.errors = [
|
|
@@ -852,7 +852,7 @@ function encodePayloadBody(payload) {
|
|
|
852
852
|
return {
|
|
853
853
|
body: JSON.stringify(sanitized),
|
|
854
854
|
dropped,
|
|
855
|
-
value:
|
|
855
|
+
value: isRecord6 ? sanitized : void 0
|
|
856
856
|
};
|
|
857
857
|
}
|
|
858
858
|
}
|
|
@@ -954,13 +954,15 @@ var init_spanOrigin = __esm({
|
|
|
954
954
|
"openai-agents",
|
|
955
955
|
"langgraph",
|
|
956
956
|
"claude-agent-sdk",
|
|
957
|
-
"vercel-ai"
|
|
957
|
+
"vercel-ai",
|
|
958
|
+
"rivet"
|
|
958
959
|
];
|
|
959
960
|
FRAMEWORK_INSTRUMENTATIONS = [
|
|
960
961
|
"openai-agents",
|
|
961
962
|
"langgraph",
|
|
962
963
|
"claude-agent-sdk",
|
|
963
|
-
"vercel-ai"
|
|
964
|
+
"vercel-ai",
|
|
965
|
+
"rivet"
|
|
964
966
|
];
|
|
965
967
|
FRAMEWORK_INSTRUMENTATION_SET = new Set(
|
|
966
968
|
FRAMEWORK_INSTRUMENTATIONS
|
|
@@ -3464,6 +3466,55 @@ var init_codeChange = __esm({
|
|
|
3464
3466
|
}
|
|
3465
3467
|
});
|
|
3466
3468
|
|
|
3469
|
+
// src/integrationFixture.ts
|
|
3470
|
+
function isRecord4(value) {
|
|
3471
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3472
|
+
}
|
|
3473
|
+
function createIntegrationFixtureContext(name, value) {
|
|
3474
|
+
const serialized = serializeValue(value);
|
|
3475
|
+
return {
|
|
3476
|
+
[INTEGRATION_FIXTURE_CONTEXT_KEY]: {
|
|
3477
|
+
version: INTEGRATION_FIXTURE_VERSION,
|
|
3478
|
+
name,
|
|
3479
|
+
value: serialized.json,
|
|
3480
|
+
...serialized.meta !== void 0 && { valueMeta: serialized.meta }
|
|
3481
|
+
}
|
|
3482
|
+
};
|
|
3483
|
+
}
|
|
3484
|
+
function extractIntegrationFixtures(spanData) {
|
|
3485
|
+
const contexts = spanData.contexts;
|
|
3486
|
+
if (!Array.isArray(contexts)) {
|
|
3487
|
+
return void 0;
|
|
3488
|
+
}
|
|
3489
|
+
const fixtures = /* @__PURE__ */ new Map();
|
|
3490
|
+
for (const context of contexts) {
|
|
3491
|
+
if (!isRecord4(context)) {
|
|
3492
|
+
continue;
|
|
3493
|
+
}
|
|
3494
|
+
const fixture = context[INTEGRATION_FIXTURE_CONTEXT_KEY];
|
|
3495
|
+
if (!isRecord4(fixture) || fixture.version !== INTEGRATION_FIXTURE_VERSION || typeof fixture.name !== "string") {
|
|
3496
|
+
continue;
|
|
3497
|
+
}
|
|
3498
|
+
fixtures.set(
|
|
3499
|
+
fixture.name,
|
|
3500
|
+
deserializeValue({
|
|
3501
|
+
json: fixture.value,
|
|
3502
|
+
...fixture.valueMeta !== void 0 && { meta: fixture.valueMeta }
|
|
3503
|
+
})
|
|
3504
|
+
);
|
|
3505
|
+
}
|
|
3506
|
+
return fixtures.size > 0 ? fixtures : void 0;
|
|
3507
|
+
}
|
|
3508
|
+
var INTEGRATION_FIXTURE_CONTEXT_KEY, INTEGRATION_FIXTURE_VERSION;
|
|
3509
|
+
var init_integrationFixture = __esm({
|
|
3510
|
+
"src/integrationFixture.ts"() {
|
|
3511
|
+
"use strict";
|
|
3512
|
+
init_serialize();
|
|
3513
|
+
INTEGRATION_FIXTURE_CONTEXT_KEY = "__bitfabIntegrationFixture";
|
|
3514
|
+
INTEGRATION_FIXTURE_VERSION = 1;
|
|
3515
|
+
}
|
|
3516
|
+
});
|
|
3517
|
+
|
|
3467
3518
|
// src/replay.ts
|
|
3468
3519
|
var replay_exports = {};
|
|
3469
3520
|
__export(replay_exports, {
|
|
@@ -3688,6 +3739,7 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
|
|
|
3688
3739
|
const spanData = span.rawData?.span_data ?? {};
|
|
3689
3740
|
inputs = deserializeInputs(spanData);
|
|
3690
3741
|
originalOutput = deserializeOutput(spanData);
|
|
3742
|
+
const integrationFixtures = extractIntegrationFixtures(spanData);
|
|
3691
3743
|
if (adaptInputs) {
|
|
3692
3744
|
const originalMetadata = serverItem.originalMetadata;
|
|
3693
3745
|
inputs = adaptInputs(inputs, {
|
|
@@ -3779,6 +3831,7 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
|
|
|
3779
3831
|
mockStrategy,
|
|
3780
3832
|
mockOverrides: hasOverrides ? resolvedOverrides : void 0,
|
|
3781
3833
|
fetchSpanOutput,
|
|
3834
|
+
integrationFixtures,
|
|
3782
3835
|
dbBranchLease: lease,
|
|
3783
3836
|
dbBranchTimings
|
|
3784
3837
|
},
|
|
@@ -4259,6 +4312,7 @@ var init_replay = __esm({
|
|
|
4259
4312
|
init_codeChange();
|
|
4260
4313
|
init_errors();
|
|
4261
4314
|
init_http();
|
|
4315
|
+
init_integrationFixture();
|
|
4262
4316
|
init_mockOverride();
|
|
4263
4317
|
init_randomUuid();
|
|
4264
4318
|
init_replayContext();
|
|
@@ -4302,6 +4356,7 @@ __export(node_exports, {
|
|
|
4302
4356
|
BitfabLangGraphIntegration: () => BitfabLangGraphIntegration,
|
|
4303
4357
|
BitfabOpenAIAgentHandler: () => BitfabOpenAIAgentHandler,
|
|
4304
4358
|
BitfabOpenAITracingProcessor: () => BitfabOpenAITracingProcessor,
|
|
4359
|
+
BitfabRivetIntegration: () => BitfabRivetIntegration,
|
|
4305
4360
|
BitfabVercelAiHandler: () => BitfabVercelAiHandler,
|
|
4306
4361
|
DEFAULT_SERVICE_URL: () => DEFAULT_SERVICE_URL,
|
|
4307
4362
|
DatasetsClient: () => DatasetsClient,
|
|
@@ -6983,6 +7038,533 @@ _context = new WeakMap();
|
|
|
6983
7038
|
// src/client.ts
|
|
6984
7039
|
init_replayContext();
|
|
6985
7040
|
|
|
7041
|
+
// src/rivetIntegration.ts
|
|
7042
|
+
init_errors();
|
|
7043
|
+
init_integrationFixture();
|
|
7044
|
+
init_replayContext();
|
|
7045
|
+
|
|
7046
|
+
// src/rivetContext.ts
|
|
7047
|
+
init_asyncStorage();
|
|
7048
|
+
var storage = null;
|
|
7049
|
+
var browserBinding = null;
|
|
7050
|
+
var STORAGE_SYMBOL = /* @__PURE__ */ Symbol.for("bitfab.rivetContextStorage");
|
|
7051
|
+
function initializeStorage() {
|
|
7052
|
+
if (storage) {
|
|
7053
|
+
return;
|
|
7054
|
+
}
|
|
7055
|
+
const shared = globalThis;
|
|
7056
|
+
const existing = shared[STORAGE_SYMBOL];
|
|
7057
|
+
if (existing) {
|
|
7058
|
+
storage = existing;
|
|
7059
|
+
return;
|
|
7060
|
+
}
|
|
7061
|
+
const created = createAsyncLocalStorage();
|
|
7062
|
+
if (created) {
|
|
7063
|
+
shared[STORAGE_SYMBOL] = created;
|
|
7064
|
+
storage = created;
|
|
7065
|
+
}
|
|
7066
|
+
}
|
|
7067
|
+
var rivetContextReady = asyncStorageReady.then(() => {
|
|
7068
|
+
initializeStorage();
|
|
7069
|
+
});
|
|
7070
|
+
function getRivetContextBinding() {
|
|
7071
|
+
initializeStorage();
|
|
7072
|
+
return storage?.getStore() ?? browserBinding ?? void 0;
|
|
7073
|
+
}
|
|
7074
|
+
function runWithBrowserBinding(binding, fn) {
|
|
7075
|
+
const previous = browserBinding;
|
|
7076
|
+
browserBinding = binding;
|
|
7077
|
+
try {
|
|
7078
|
+
const result = fn();
|
|
7079
|
+
if (result instanceof Promise) {
|
|
7080
|
+
return result.finally(() => {
|
|
7081
|
+
browserBinding = previous;
|
|
7082
|
+
});
|
|
7083
|
+
}
|
|
7084
|
+
browserBinding = previous;
|
|
7085
|
+
return result;
|
|
7086
|
+
} catch (error) {
|
|
7087
|
+
browserBinding = previous;
|
|
7088
|
+
throw error;
|
|
7089
|
+
}
|
|
7090
|
+
}
|
|
7091
|
+
function runWithRivetContext(binding, fn) {
|
|
7092
|
+
initializeStorage();
|
|
7093
|
+
if (!storage && !isAsyncStorageInitDone()) {
|
|
7094
|
+
return rivetContextReady.then(() => runWithRivetContext(binding, fn));
|
|
7095
|
+
}
|
|
7096
|
+
if (storage) {
|
|
7097
|
+
return storage.run(binding, fn);
|
|
7098
|
+
}
|
|
7099
|
+
return runWithBrowserBinding(binding, fn);
|
|
7100
|
+
}
|
|
7101
|
+
|
|
7102
|
+
// src/rivetIntegration.ts
|
|
7103
|
+
var RIVET_DOCS_URL = "https://docs.bitfab.ai/frameworks/rivet";
|
|
7104
|
+
var RIVET_GROUP_EFFECT_METHODS = {
|
|
7105
|
+
db: ["execute", "nativeMetrics", "close"],
|
|
7106
|
+
kv: [
|
|
7107
|
+
"get",
|
|
7108
|
+
"put",
|
|
7109
|
+
"delete",
|
|
7110
|
+
"batchPut",
|
|
7111
|
+
"batchGet",
|
|
7112
|
+
"batchDelete",
|
|
7113
|
+
"deleteRange",
|
|
7114
|
+
"listPrefix",
|
|
7115
|
+
"listRange",
|
|
7116
|
+
"list"
|
|
7117
|
+
],
|
|
7118
|
+
schedule: ["after", "at", "cancel", "get", "list"],
|
|
7119
|
+
cron: ["set", "every", "get", "list", "delete", "history"],
|
|
7120
|
+
queue: [
|
|
7121
|
+
"send",
|
|
7122
|
+
"next",
|
|
7123
|
+
"nextBatch",
|
|
7124
|
+
"waitForNames",
|
|
7125
|
+
"waitForAvailable",
|
|
7126
|
+
"complete",
|
|
7127
|
+
"enqueueAndWait",
|
|
7128
|
+
"tryNext",
|
|
7129
|
+
"tryNextBatch"
|
|
7130
|
+
],
|
|
7131
|
+
run: ["setWakeAt"]
|
|
7132
|
+
};
|
|
7133
|
+
var RIVET_TOP_LEVEL_EFFECTS = [
|
|
7134
|
+
"broadcast",
|
|
7135
|
+
"saveState",
|
|
7136
|
+
"sleep",
|
|
7137
|
+
"destroy"
|
|
7138
|
+
];
|
|
7139
|
+
var TOP_LEVEL_UNAVAILABLE_CAPABILITIES = /* @__PURE__ */ new Set([
|
|
7140
|
+
"conn",
|
|
7141
|
+
"conns",
|
|
7142
|
+
"log",
|
|
7143
|
+
"request",
|
|
7144
|
+
"actorRuntimeSocket",
|
|
7145
|
+
"keepAwake",
|
|
7146
|
+
"waitUntil",
|
|
7147
|
+
"client"
|
|
7148
|
+
]);
|
|
7149
|
+
var SYNC_VOID_EFFECTS = /* @__PURE__ */ new Set([
|
|
7150
|
+
"broadcast",
|
|
7151
|
+
"sleep",
|
|
7152
|
+
"destroy"
|
|
7153
|
+
]);
|
|
7154
|
+
var QUEUE_MESSAGE_EFFECTS = /* @__PURE__ */ new Set([
|
|
7155
|
+
"queue.next",
|
|
7156
|
+
"queue.nextBatch",
|
|
7157
|
+
"queue.waitForNames",
|
|
7158
|
+
"queue.tryNext",
|
|
7159
|
+
"queue.tryNextBatch"
|
|
7160
|
+
]);
|
|
7161
|
+
function isRecord5(value) {
|
|
7162
|
+
return typeof value === "object" && value !== null;
|
|
7163
|
+
}
|
|
7164
|
+
function readProperty(value, property) {
|
|
7165
|
+
try {
|
|
7166
|
+
return Reflect.get(value, property, value);
|
|
7167
|
+
} catch {
|
|
7168
|
+
return void 0;
|
|
7169
|
+
}
|
|
7170
|
+
}
|
|
7171
|
+
function snapshotContext(context) {
|
|
7172
|
+
const source = context;
|
|
7173
|
+
const snapshot = {};
|
|
7174
|
+
for (const property of [
|
|
7175
|
+
"state",
|
|
7176
|
+
"vars",
|
|
7177
|
+
"actorId",
|
|
7178
|
+
"name",
|
|
7179
|
+
"key",
|
|
7180
|
+
"region",
|
|
7181
|
+
"aborted"
|
|
7182
|
+
]) {
|
|
7183
|
+
const value = readProperty(source, property);
|
|
7184
|
+
if (value !== void 0) {
|
|
7185
|
+
snapshot[property] = value;
|
|
7186
|
+
}
|
|
7187
|
+
}
|
|
7188
|
+
return snapshot;
|
|
7189
|
+
}
|
|
7190
|
+
function unavailableCapability(path) {
|
|
7191
|
+
return new BitfabError(
|
|
7192
|
+
`Rivet context capability "${path}" is unavailable during replay. Add first-class support for that public context path before replaying code that uses it.`,
|
|
7193
|
+
RIVET_DOCS_URL
|
|
7194
|
+
);
|
|
7195
|
+
}
|
|
7196
|
+
function effectNode(traceFunctionKey, effect, mockSpanId) {
|
|
7197
|
+
return {
|
|
7198
|
+
traceFunctionKey,
|
|
7199
|
+
spanName: effect,
|
|
7200
|
+
type: "function",
|
|
7201
|
+
originalSpanId: mockSpanId
|
|
7202
|
+
};
|
|
7203
|
+
}
|
|
7204
|
+
function replayEffectStatus(replay2, traceFunctionKey, effect, marked) {
|
|
7205
|
+
const counterKey = `${traceFunctionKey}:${effect}`;
|
|
7206
|
+
const callIndex = replay2.callCounters?.get(counterKey) ?? 0;
|
|
7207
|
+
const mockSpan = replay2.mockTree?.spans.get(`${counterKey}:${callIndex}`);
|
|
7208
|
+
const hasOverride = replay2.mockOverrides?.some(
|
|
7209
|
+
(override) => override.match(
|
|
7210
|
+
effectNode(traceFunctionKey, effect, mockSpan?.sourceSpanId)
|
|
7211
|
+
)
|
|
7212
|
+
) ?? false;
|
|
7213
|
+
return {
|
|
7214
|
+
willMock: hasOverride || replay2.mockStrategy === "all" || replay2.mockStrategy === "marked" && marked,
|
|
7215
|
+
hasRecordedSpan: mockSpan !== void 0,
|
|
7216
|
+
hasOverride,
|
|
7217
|
+
callIndex
|
|
7218
|
+
};
|
|
7219
|
+
}
|
|
7220
|
+
function assertReplayEffectAvailable(replay2, traceFunctionKey, effect, marked) {
|
|
7221
|
+
if (!replay2) {
|
|
7222
|
+
return;
|
|
7223
|
+
}
|
|
7224
|
+
const status = replayEffectStatus(replay2, traceFunctionKey, effect, marked);
|
|
7225
|
+
if (!status.willMock) {
|
|
7226
|
+
throw new BitfabError(
|
|
7227
|
+
`Rivet effect "${effect}" has no live actor context during replay. Add "${effect}" to mockOnReplay or provide a replay override.`,
|
|
7228
|
+
RIVET_DOCS_URL
|
|
7229
|
+
);
|
|
7230
|
+
}
|
|
7231
|
+
if (!status.hasRecordedSpan && !status.hasOverride) {
|
|
7232
|
+
throw new BitfabError(
|
|
7233
|
+
`No recorded Rivet effect "${effect}" exists at call ${status.callIndex + 1}; the live effect was not executed.`,
|
|
7234
|
+
RIVET_DOCS_URL
|
|
7235
|
+
);
|
|
7236
|
+
}
|
|
7237
|
+
}
|
|
7238
|
+
function fixtureName(traceFunctionKey) {
|
|
7239
|
+
return `rivet:${traceFunctionKey}`;
|
|
7240
|
+
}
|
|
7241
|
+
function snapshotFromReplay(traceFunctionKey, replay2) {
|
|
7242
|
+
const fixture = replay2.integrationFixtures?.get(fixtureName(traceFunctionKey));
|
|
7243
|
+
if (!isRecord5(fixture)) {
|
|
7244
|
+
throw new BitfabError(
|
|
7245
|
+
`Trace "${traceFunctionKey}" has no Rivet context fixture. Capture a fresh trace with the Rivet integration before replaying it.`,
|
|
7246
|
+
RIVET_DOCS_URL
|
|
7247
|
+
);
|
|
7248
|
+
}
|
|
7249
|
+
return fixture;
|
|
7250
|
+
}
|
|
7251
|
+
var BitfabRivetIntegration = class {
|
|
7252
|
+
/** @internal Constructed by `Bitfab.getRivetIntegration()`. */
|
|
7253
|
+
constructor(traceFunctionKey, runtime, options = {}) {
|
|
7254
|
+
this.traceFunctionKey = traceFunctionKey;
|
|
7255
|
+
this.runtime = runtime;
|
|
7256
|
+
this.replayProxies = /* @__PURE__ */ new WeakMap();
|
|
7257
|
+
this.markedEffects = new Set(options.mockOnReplay ?? []);
|
|
7258
|
+
}
|
|
7259
|
+
/**
|
|
7260
|
+
* Run a callback with a live Rivet context bound to the current async chain.
|
|
7261
|
+
* This binds context only; it creates no trace or span.
|
|
7262
|
+
*/
|
|
7263
|
+
withContext(context, fn) {
|
|
7264
|
+
if (!isRecord5(context)) {
|
|
7265
|
+
throw new BitfabError("Rivet withContext requires a context object");
|
|
7266
|
+
}
|
|
7267
|
+
const binding = {
|
|
7268
|
+
context,
|
|
7269
|
+
fixtureContext: createIntegrationFixtureContext(
|
|
7270
|
+
fixtureName(this.traceFunctionKey),
|
|
7271
|
+
snapshotContext(context)
|
|
7272
|
+
),
|
|
7273
|
+
recordedRoots: /* @__PURE__ */ new Set()
|
|
7274
|
+
};
|
|
7275
|
+
return runWithRivetContext(binding, fn);
|
|
7276
|
+
}
|
|
7277
|
+
/**
|
|
7278
|
+
* Adapt a traced function into a Rivet handler whose first argument is the
|
|
7279
|
+
* live actor context. The context is not added to the traced root's inputs.
|
|
7280
|
+
*/
|
|
7281
|
+
bind(fn) {
|
|
7282
|
+
const integration = this;
|
|
7283
|
+
return function(context, ...args) {
|
|
7284
|
+
return integration.withContext(context, () => fn.apply(this, args));
|
|
7285
|
+
};
|
|
7286
|
+
}
|
|
7287
|
+
/**
|
|
7288
|
+
* Return the current Rivet context proxy. In production it delegates to the
|
|
7289
|
+
* bound live context. During replay it hydrates recorded actor state and
|
|
7290
|
+
* intercepts supported effects without requiring a live Rivet actor.
|
|
7291
|
+
*/
|
|
7292
|
+
getContext() {
|
|
7293
|
+
const replay2 = getReplayContext();
|
|
7294
|
+
if (replay2) {
|
|
7295
|
+
const existing = this.replayProxies.get(replay2);
|
|
7296
|
+
if (existing) {
|
|
7297
|
+
return existing;
|
|
7298
|
+
}
|
|
7299
|
+
const proxy = this.createContextProxy(
|
|
7300
|
+
snapshotFromReplay(this.traceFunctionKey, replay2),
|
|
7301
|
+
void 0
|
|
7302
|
+
);
|
|
7303
|
+
this.replayProxies.set(replay2, proxy);
|
|
7304
|
+
return proxy;
|
|
7305
|
+
}
|
|
7306
|
+
const binding = getRivetContextBinding();
|
|
7307
|
+
if (!binding) {
|
|
7308
|
+
throw new BitfabError(
|
|
7309
|
+
"No Rivet context is bound. Call rivet.bind(handler) or rivet.withContext(context, callback) at the Rivet boundary.",
|
|
7310
|
+
RIVET_DOCS_URL
|
|
7311
|
+
);
|
|
7312
|
+
}
|
|
7313
|
+
this.runtime.recordRootFixture(
|
|
7314
|
+
binding.fixtureContext,
|
|
7315
|
+
binding.recordedRoots
|
|
7316
|
+
);
|
|
7317
|
+
if (!binding.proxy) {
|
|
7318
|
+
binding.proxy = this.createContextProxy(
|
|
7319
|
+
binding.context,
|
|
7320
|
+
binding
|
|
7321
|
+
);
|
|
7322
|
+
}
|
|
7323
|
+
return binding.proxy;
|
|
7324
|
+
}
|
|
7325
|
+
createContextProxy(target, binding) {
|
|
7326
|
+
const replay2 = getReplayContext();
|
|
7327
|
+
const dbProxy = this.createDbProxy(binding, replay2);
|
|
7328
|
+
const groupProxies = /* @__PURE__ */ new Map();
|
|
7329
|
+
for (const group of Object.keys(
|
|
7330
|
+
RIVET_GROUP_EFFECT_METHODS
|
|
7331
|
+
)) {
|
|
7332
|
+
if (group !== "db") {
|
|
7333
|
+
groupProxies.set(group, this.createGroupProxy(group, binding, replay2));
|
|
7334
|
+
}
|
|
7335
|
+
}
|
|
7336
|
+
const topLevelEffects = /* @__PURE__ */ new Map();
|
|
7337
|
+
for (const effect of RIVET_TOP_LEVEL_EFFECTS) {
|
|
7338
|
+
topLevelEffects.set(
|
|
7339
|
+
effect,
|
|
7340
|
+
this.createEffect(
|
|
7341
|
+
effect,
|
|
7342
|
+
() => binding?.context,
|
|
7343
|
+
effect,
|
|
7344
|
+
replay2
|
|
7345
|
+
)
|
|
7346
|
+
);
|
|
7347
|
+
}
|
|
7348
|
+
const replayTarget = replay2 ? { ...target } : target;
|
|
7349
|
+
if (replay2) {
|
|
7350
|
+
const controller = new AbortController();
|
|
7351
|
+
if (target.aborted === true) {
|
|
7352
|
+
controller.abort();
|
|
7353
|
+
}
|
|
7354
|
+
replayTarget.abortSignal = controller.signal;
|
|
7355
|
+
}
|
|
7356
|
+
return new Proxy(replayTarget, {
|
|
7357
|
+
get: (source, property) => {
|
|
7358
|
+
if (property === "db") {
|
|
7359
|
+
return dbProxy;
|
|
7360
|
+
}
|
|
7361
|
+
if (typeof property === "string") {
|
|
7362
|
+
const group = groupProxies.get(property);
|
|
7363
|
+
if (group) {
|
|
7364
|
+
return group;
|
|
7365
|
+
}
|
|
7366
|
+
const effect = topLevelEffects.get(property);
|
|
7367
|
+
if (effect) {
|
|
7368
|
+
return effect;
|
|
7369
|
+
}
|
|
7370
|
+
}
|
|
7371
|
+
if (property === "setPreventSleep" && replay2) {
|
|
7372
|
+
return (_preventSleep) => void 0;
|
|
7373
|
+
}
|
|
7374
|
+
if (replay2 && typeof property === "string" && TOP_LEVEL_UNAVAILABLE_CAPABILITIES.has(property)) {
|
|
7375
|
+
throw unavailableCapability(property);
|
|
7376
|
+
}
|
|
7377
|
+
const value = Reflect.get(source, property, source);
|
|
7378
|
+
return typeof value === "function" ? value.bind(source) : value;
|
|
7379
|
+
}
|
|
7380
|
+
});
|
|
7381
|
+
}
|
|
7382
|
+
createDbProxy(binding, replay2) {
|
|
7383
|
+
const proxy = this.createGroupProxy("db", binding, replay2);
|
|
7384
|
+
return new Proxy(proxy, {
|
|
7385
|
+
get: (source, property) => property === "transaction" ? this.createTransaction(binding, replay2) : Reflect.get(source, property, source)
|
|
7386
|
+
});
|
|
7387
|
+
}
|
|
7388
|
+
createGroupProxy(group, binding, replay2) {
|
|
7389
|
+
const targetProvider = () => {
|
|
7390
|
+
if (!binding) {
|
|
7391
|
+
return void 0;
|
|
7392
|
+
}
|
|
7393
|
+
const context = binding.context;
|
|
7394
|
+
const target = readProperty(context, group);
|
|
7395
|
+
return isRecord5(target) ? target : void 0;
|
|
7396
|
+
};
|
|
7397
|
+
const proxy = this.createMethodProxy(
|
|
7398
|
+
targetProvider,
|
|
7399
|
+
group,
|
|
7400
|
+
RIVET_GROUP_EFFECT_METHODS[group],
|
|
7401
|
+
replay2
|
|
7402
|
+
);
|
|
7403
|
+
if (group !== "queue") {
|
|
7404
|
+
return proxy;
|
|
7405
|
+
}
|
|
7406
|
+
return new Proxy(proxy, {
|
|
7407
|
+
get: (source, property) => property === "iter" ? (options) => this.createQueueIterator(source, options) : Reflect.get(source, property, source)
|
|
7408
|
+
});
|
|
7409
|
+
}
|
|
7410
|
+
createMethodProxy(targetProvider, prefix, methods, replay2) {
|
|
7411
|
+
const effects = /* @__PURE__ */ new Map();
|
|
7412
|
+
for (const method of methods) {
|
|
7413
|
+
const effect = `${prefix}.${method}`;
|
|
7414
|
+
effects.set(
|
|
7415
|
+
method,
|
|
7416
|
+
this.createEffect(effect, targetProvider, method, replay2)
|
|
7417
|
+
);
|
|
7418
|
+
}
|
|
7419
|
+
return new Proxy(
|
|
7420
|
+
{},
|
|
7421
|
+
{
|
|
7422
|
+
get: (_source, property) => {
|
|
7423
|
+
if (typeof property === "string") {
|
|
7424
|
+
const effect = effects.get(property);
|
|
7425
|
+
if (effect) {
|
|
7426
|
+
return effect;
|
|
7427
|
+
}
|
|
7428
|
+
if (replay2) {
|
|
7429
|
+
throw unavailableCapability(`${prefix}.${property}`);
|
|
7430
|
+
}
|
|
7431
|
+
}
|
|
7432
|
+
const target = targetProvider();
|
|
7433
|
+
if (!target) {
|
|
7434
|
+
return void 0;
|
|
7435
|
+
}
|
|
7436
|
+
const value = Reflect.get(target, property, target);
|
|
7437
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
7438
|
+
}
|
|
7439
|
+
}
|
|
7440
|
+
);
|
|
7441
|
+
}
|
|
7442
|
+
createEffect(effect, targetProvider, methodName, replay2) {
|
|
7443
|
+
const marked = this.markedEffects.has(effect);
|
|
7444
|
+
const invoke = (...args) => {
|
|
7445
|
+
assertReplayEffectAvailable(
|
|
7446
|
+
getReplayContext(),
|
|
7447
|
+
this.traceFunctionKey,
|
|
7448
|
+
effect,
|
|
7449
|
+
marked
|
|
7450
|
+
);
|
|
7451
|
+
const target = targetProvider();
|
|
7452
|
+
const method = target ? readProperty(target, methodName) : void 0;
|
|
7453
|
+
if (typeof method !== "function") {
|
|
7454
|
+
throw unavailableCapability(effect);
|
|
7455
|
+
}
|
|
7456
|
+
return method.apply(target, args);
|
|
7457
|
+
};
|
|
7458
|
+
const wrapped = SYNC_VOID_EFFECTS.has(effect) ? this.runtime.wrapEffect(
|
|
7459
|
+
effect,
|
|
7460
|
+
marked,
|
|
7461
|
+
invoke,
|
|
7462
|
+
replay2 ? () => void 0 : void 0
|
|
7463
|
+
) : this.runtime.wrapEffect(effect, marked, async (...args) => {
|
|
7464
|
+
return await invoke(...args);
|
|
7465
|
+
});
|
|
7466
|
+
return (...args) => {
|
|
7467
|
+
if (replay2) {
|
|
7468
|
+
assertReplayEffectAvailable(
|
|
7469
|
+
replay2,
|
|
7470
|
+
this.traceFunctionKey,
|
|
7471
|
+
effect,
|
|
7472
|
+
marked
|
|
7473
|
+
);
|
|
7474
|
+
}
|
|
7475
|
+
const result = wrapped(...args);
|
|
7476
|
+
if (!QUEUE_MESSAGE_EFFECTS.has(effect) || !(result instanceof Promise)) {
|
|
7477
|
+
return result;
|
|
7478
|
+
}
|
|
7479
|
+
return result.then(
|
|
7480
|
+
(value) => this.decorateQueueMessages(value, effect, args, replay2)
|
|
7481
|
+
);
|
|
7482
|
+
};
|
|
7483
|
+
}
|
|
7484
|
+
createTransaction(binding, replay2) {
|
|
7485
|
+
return async (callback, options) => {
|
|
7486
|
+
if (typeof callback !== "function") {
|
|
7487
|
+
throw new BitfabError("Rivet db.transaction requires a callback");
|
|
7488
|
+
}
|
|
7489
|
+
if (replay2) {
|
|
7490
|
+
return await callback(
|
|
7491
|
+
this.createMethodProxy(
|
|
7492
|
+
() => void 0,
|
|
7493
|
+
"db.transaction",
|
|
7494
|
+
["execute"],
|
|
7495
|
+
replay2
|
|
7496
|
+
)
|
|
7497
|
+
);
|
|
7498
|
+
}
|
|
7499
|
+
const context = binding?.context;
|
|
7500
|
+
const db = context ? readProperty(context, "db") : void 0;
|
|
7501
|
+
const transaction = isRecord5(db) ? readProperty(db, "transaction") : void 0;
|
|
7502
|
+
if (!isRecord5(db) || typeof transaction !== "function") {
|
|
7503
|
+
throw unavailableCapability("db.transaction");
|
|
7504
|
+
}
|
|
7505
|
+
return await transaction.call(
|
|
7506
|
+
db,
|
|
7507
|
+
async (transactionDb) => {
|
|
7508
|
+
if (!isRecord5(transactionDb)) {
|
|
7509
|
+
throw unavailableCapability("db.transaction.execute");
|
|
7510
|
+
}
|
|
7511
|
+
return await callback(
|
|
7512
|
+
this.createMethodProxy(
|
|
7513
|
+
() => transactionDb,
|
|
7514
|
+
"db.transaction",
|
|
7515
|
+
["execute"],
|
|
7516
|
+
replay2
|
|
7517
|
+
)
|
|
7518
|
+
);
|
|
7519
|
+
},
|
|
7520
|
+
options
|
|
7521
|
+
);
|
|
7522
|
+
};
|
|
7523
|
+
}
|
|
7524
|
+
decorateQueueMessages(value, effect, args, replay2) {
|
|
7525
|
+
if (!this.queueCallIsCompletable(effect, args)) {
|
|
7526
|
+
return value;
|
|
7527
|
+
}
|
|
7528
|
+
if (Array.isArray(value)) {
|
|
7529
|
+
return value.map((message) => this.decorateQueueMessage(message, replay2));
|
|
7530
|
+
}
|
|
7531
|
+
return this.decorateQueueMessage(value, replay2);
|
|
7532
|
+
}
|
|
7533
|
+
decorateQueueMessage(value, replay2) {
|
|
7534
|
+
if (!isRecord5(value)) {
|
|
7535
|
+
return value;
|
|
7536
|
+
}
|
|
7537
|
+
const originalComplete = readProperty(value, "complete");
|
|
7538
|
+
const complete = this.createEffect(
|
|
7539
|
+
"queue.message.complete",
|
|
7540
|
+
() => typeof originalComplete === "function" ? { complete: originalComplete.bind(value) } : void 0,
|
|
7541
|
+
"complete",
|
|
7542
|
+
replay2
|
|
7543
|
+
);
|
|
7544
|
+
return { ...value, complete };
|
|
7545
|
+
}
|
|
7546
|
+
queueCallIsCompletable(effect, args) {
|
|
7547
|
+
const options = effect === "queue.waitForNames" ? args[1] : args[0];
|
|
7548
|
+
return isRecord5(options) && options.completable === true;
|
|
7549
|
+
}
|
|
7550
|
+
createQueueIterator(queue, options) {
|
|
7551
|
+
return {
|
|
7552
|
+
async *[Symbol.asyncIterator]() {
|
|
7553
|
+
for (; ; ) {
|
|
7554
|
+
const next = Reflect.get(queue, "next", queue);
|
|
7555
|
+
if (typeof next !== "function") {
|
|
7556
|
+
throw unavailableCapability("queue.next");
|
|
7557
|
+
}
|
|
7558
|
+
const message = await next.call(queue, options);
|
|
7559
|
+
if (message !== void 0 && message !== null) {
|
|
7560
|
+
yield message;
|
|
7561
|
+
}
|
|
7562
|
+
}
|
|
7563
|
+
}
|
|
7564
|
+
};
|
|
7565
|
+
}
|
|
7566
|
+
};
|
|
7567
|
+
|
|
6986
7568
|
// src/seedContext.ts
|
|
6987
7569
|
init_asyncStorage();
|
|
6988
7570
|
var seedContextStorage = null;
|
|
@@ -8692,6 +9274,47 @@ var Bitfab = class {
|
|
|
8692
9274
|
options
|
|
8693
9275
|
});
|
|
8694
9276
|
}
|
|
9277
|
+
/**
|
|
9278
|
+
* Get the first-class Rivet actor-context integration for an existing trace
|
|
9279
|
+
* root. The integration binds context and records effect spans; it never
|
|
9280
|
+
* creates another root.
|
|
9281
|
+
*
|
|
9282
|
+
* @param traceFunctionKey - Key used by the enclosing `withTrace()` root
|
|
9283
|
+
* @param options - Explicit per-context-path replay mocking policy
|
|
9284
|
+
* @experimental This API may change before it is stable.
|
|
9285
|
+
*/
|
|
9286
|
+
getRivetIntegration(traceFunctionKey, options) {
|
|
9287
|
+
return new BitfabRivetIntegration(
|
|
9288
|
+
traceFunctionKey,
|
|
9289
|
+
{
|
|
9290
|
+
wrapEffect: (effect, mockOnReplay, fn, replayOutput) => {
|
|
9291
|
+
const spanOptions = {
|
|
9292
|
+
name: effect,
|
|
9293
|
+
type: "function",
|
|
9294
|
+
captureWhen: "nested",
|
|
9295
|
+
mockOnReplay,
|
|
9296
|
+
surface: "inherit",
|
|
9297
|
+
instrumentation: "rivet",
|
|
9298
|
+
...replayOutput !== void 0 && { replayOutput }
|
|
9299
|
+
};
|
|
9300
|
+
return this.withSpan(traceFunctionKey, spanOptions, fn);
|
|
9301
|
+
},
|
|
9302
|
+
recordRootFixture: (context, recordedRoots) => {
|
|
9303
|
+
const root = getSpanStack()[0];
|
|
9304
|
+
if (!root) {
|
|
9305
|
+
return;
|
|
9306
|
+
}
|
|
9307
|
+
const rootId = `${root.traceId}:${root.spanId}`;
|
|
9308
|
+
if (recordedRoots.has(rootId)) {
|
|
9309
|
+
return;
|
|
9310
|
+
}
|
|
9311
|
+
root.contexts.push(context);
|
|
9312
|
+
recordedRoots.add(rootId);
|
|
9313
|
+
}
|
|
9314
|
+
},
|
|
9315
|
+
options
|
|
9316
|
+
);
|
|
9317
|
+
}
|
|
8695
9318
|
/**
|
|
8696
9319
|
* Get a Claude Agent SDK handler for tracing.
|
|
8697
9320
|
*
|
|
@@ -9190,6 +9813,7 @@ var Bitfab = class {
|
|
|
9190
9813
|
}
|
|
9191
9814
|
return output;
|
|
9192
9815
|
};
|
|
9816
|
+
const resolveBaseOutput = () => options.replayOutput !== void 0 ? options.replayOutput() : resolveRecordedOutput();
|
|
9193
9817
|
const shouldMockWithBaseStrategy = replayCtxForMock.mockStrategy === "all" || replayCtxForMock.mockStrategy === "marked" && options.mockOnReplay === true;
|
|
9194
9818
|
if (replayCtxForMock.mockOverrides?.length) {
|
|
9195
9819
|
const nodeMeta = {
|
|
@@ -9246,7 +9870,7 @@ var Bitfab = class {
|
|
|
9246
9870
|
}
|
|
9247
9871
|
if (shouldMockWithBaseStrategy) {
|
|
9248
9872
|
const output = await resolveMockOrAbort(
|
|
9249
|
-
() =>
|
|
9873
|
+
() => resolveBaseOutput()
|
|
9250
9874
|
);
|
|
9251
9875
|
void sendSpan({
|
|
9252
9876
|
result: output,
|
|
@@ -9269,7 +9893,7 @@ var Bitfab = class {
|
|
|
9269
9893
|
);
|
|
9270
9894
|
}
|
|
9271
9895
|
if (shouldMockWithBaseStrategy) {
|
|
9272
|
-
const recorded =
|
|
9896
|
+
const recorded = resolveBaseOutput();
|
|
9273
9897
|
if (recorded instanceof Promise) {
|
|
9274
9898
|
return emitMockAsync(recorded, "recorded");
|
|
9275
9899
|
}
|
|
@@ -9871,6 +10495,28 @@ var BitfabFunction = class {
|
|
|
9871
10495
|
span(options = {}) {
|
|
9872
10496
|
return this.client.span(this.traceFunctionKey, options);
|
|
9873
10497
|
}
|
|
10498
|
+
withTrace(optionsOrFn, maybeFn) {
|
|
10499
|
+
if (typeof optionsOrFn === "function") {
|
|
10500
|
+
return this.client.withTrace(this.traceFunctionKey, optionsOrFn);
|
|
10501
|
+
}
|
|
10502
|
+
if (!maybeFn) {
|
|
10503
|
+
throw new BitfabError("BitfabFunction.withTrace requires a function");
|
|
10504
|
+
}
|
|
10505
|
+
return this.client.withTrace(this.traceFunctionKey, optionsOrFn, maybeFn);
|
|
10506
|
+
}
|
|
10507
|
+
/**
|
|
10508
|
+
* Create a trace method decorator bound to this function's key.
|
|
10509
|
+
*
|
|
10510
|
+
* Equivalent to `client.trace(key, options)` but reuses the key bound on
|
|
10511
|
+
* this handle.
|
|
10512
|
+
*
|
|
10513
|
+
* @param options - Trace configuration applied to the decorated method
|
|
10514
|
+
* @returns A method decorator configured for this key
|
|
10515
|
+
* @experimental Automatic child-call instrumentation is experimental.
|
|
10516
|
+
*/
|
|
10517
|
+
trace(options = {}) {
|
|
10518
|
+
return this.client.trace(this.traceFunctionKey, options);
|
|
10519
|
+
}
|
|
9874
10520
|
/**
|
|
9875
10521
|
* Get a Vercel AI SDK language-model middleware bound to this function's key.
|
|
9876
10522
|
*
|
|
@@ -9968,6 +10614,20 @@ var BitfabFunction = class {
|
|
|
9968
10614
|
getLangGraphIntegration(options) {
|
|
9969
10615
|
return this.client.getLangGraphIntegration(this.traceFunctionKey, options);
|
|
9970
10616
|
}
|
|
10617
|
+
/**
|
|
10618
|
+
* Get the first-class Rivet actor-context integration bound to this key.
|
|
10619
|
+
* Use its `bind()` or `withContext()` outside this handle's `withTrace()`
|
|
10620
|
+
* root, then call `getContext()` inside the root.
|
|
10621
|
+
*
|
|
10622
|
+
* @param options - Explicit per-context-path replay mocking policy
|
|
10623
|
+
* @experimental This API may change before it is stable.
|
|
10624
|
+
*/
|
|
10625
|
+
getRivetIntegration(options) {
|
|
10626
|
+
return this.client.getRivetIntegration(
|
|
10627
|
+
this.traceFunctionKey,
|
|
10628
|
+
options
|
|
10629
|
+
);
|
|
10630
|
+
}
|
|
9971
10631
|
/**
|
|
9972
10632
|
* Wrap a BAML client method to automatically capture prompt and LLM metadata.
|
|
9973
10633
|
* Delegates to the parent client's wrapBAML method.
|
|
@@ -10133,6 +10793,7 @@ assertAsyncStorageRegistered();
|
|
|
10133
10793
|
BitfabLangGraphIntegration,
|
|
10134
10794
|
BitfabOpenAIAgentHandler,
|
|
10135
10795
|
BitfabOpenAITracingProcessor,
|
|
10796
|
+
BitfabRivetIntegration,
|
|
10136
10797
|
BitfabVercelAiHandler,
|
|
10137
10798
|
DEFAULT_SERVICE_URL,
|
|
10138
10799
|
DatasetsClient,
|