bitfab 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.
Files changed (35) hide show
  1. package/dist/{chunk-UKKR2PF4.js → chunk-A3OBQOLV.js} +609 -8
  2. package/dist/chunk-A3OBQOLV.js.map +1 -0
  3. package/dist/{chunk-7HXFT6JR.js → chunk-B2O33DBH.js} +6 -4
  4. package/dist/chunk-B2O33DBH.js.map +1 -0
  5. package/dist/{chunk-5EW5MV2Z.js → chunk-OGZLJINL.js} +3 -3
  6. package/dist/chunk-OGZLJINL.js.map +1 -0
  7. package/dist/{chunk-VT5IUVBY.js → chunk-PRXW4B5X.js} +85 -40
  8. package/dist/chunk-PRXW4B5X.js.map +1 -0
  9. package/dist/{chunk-TOCJX6OP.js → chunk-XLWQOUOP.js} +4 -3
  10. package/dist/chunk-XLWQOUOP.js.map +1 -0
  11. package/dist/{http-WQ6YWRTW.js → http-AVWWAMFV.js} +2 -2
  12. package/dist/{http-HYJYQTX2.js → http-DH3O3L5X.js} +2 -2
  13. package/dist/index.cjs +669 -8
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +130 -2
  16. package/dist/index.d.ts +130 -2
  17. package/dist/index.js +5 -3
  18. package/dist/node.cjs +669 -8
  19. package/dist/node.cjs.map +1 -1
  20. package/dist/node.d.cts +1 -1
  21. package/dist/node.d.ts +1 -1
  22. package/dist/node.js +5 -3
  23. package/dist/node.js.map +1 -1
  24. package/dist/{replay-MISWCCCG.js → replay-BCWIDCKH.js} +3 -3
  25. package/dist/replayCli.js +2 -2
  26. package/dist/seedCli.js +2 -2
  27. package/package.json +1 -1
  28. package/dist/chunk-5EW5MV2Z.js.map +0 -1
  29. package/dist/chunk-7HXFT6JR.js.map +0 -1
  30. package/dist/chunk-TOCJX6OP.js.map +0 -1
  31. package/dist/chunk-UKKR2PF4.js.map +0 -1
  32. package/dist/chunk-VT5IUVBY.js.map +0 -1
  33. /package/dist/{http-HYJYQTX2.js.map → http-AVWWAMFV.js.map} +0 -0
  34. /package/dist/{http-WQ6YWRTW.js.map → http-DH3O3L5X.js.map} +0 -0
  35. /package/dist/{replay-MISWCCCG.js.map → replay-BCWIDCKH.js.map} +0 -0
package/dist/node.cjs CHANGED
@@ -97,7 +97,7 @@ var __version__, __packageName__;
97
97
  var init_version_generated = __esm({
98
98
  "src/version.generated.ts"() {
99
99
  "use strict";
100
- __version__ = "0.54.9";
100
+ __version__ = "0.54.10";
101
101
  __packageName__ = "bitfab";
102
102
  }
103
103
  });
@@ -843,8 +843,8 @@ function encodePayloadBody(payload) {
843
843
  const marker = { error: `payload_serialize_failed: ${message}` };
844
844
  return { body: JSON.stringify(marker), dropped, value: marker };
845
845
  }
846
- const isRecord4 = typeof sanitized === "object" && sanitized !== null && !Array.isArray(sanitized);
847
- if (dropped.length > 0 && isRecord4) {
846
+ const isRecord6 = typeof sanitized === "object" && sanitized !== null && !Array.isArray(sanitized);
847
+ if (dropped.length > 0 && isRecord6) {
848
848
  const obj = sanitized;
849
849
  const existing = Array.isArray(obj.errors) ? obj.errors : [];
850
850
  obj.errors = [
@@ -861,7 +861,7 @@ function encodePayloadBody(payload) {
861
861
  return {
862
862
  body: JSON.stringify(sanitized),
863
863
  dropped,
864
- value: isRecord4 ? sanitized : void 0
864
+ value: isRecord6 ? sanitized : void 0
865
865
  };
866
866
  }
867
867
  }
@@ -963,13 +963,15 @@ var init_spanOrigin = __esm({
963
963
  "openai-agents",
964
964
  "langgraph",
965
965
  "claude-agent-sdk",
966
- "vercel-ai"
966
+ "vercel-ai",
967
+ "rivet"
967
968
  ];
968
969
  FRAMEWORK_INSTRUMENTATIONS = [
969
970
  "openai-agents",
970
971
  "langgraph",
971
972
  "claude-agent-sdk",
972
- "vercel-ai"
973
+ "vercel-ai",
974
+ "rivet"
973
975
  ];
974
976
  FRAMEWORK_INSTRUMENTATION_SET = new Set(
975
977
  FRAMEWORK_INSTRUMENTATIONS
@@ -3473,6 +3475,55 @@ var init_codeChange = __esm({
3473
3475
  }
3474
3476
  });
3475
3477
 
3478
+ // src/integrationFixture.ts
3479
+ function isRecord4(value) {
3480
+ return typeof value === "object" && value !== null && !Array.isArray(value);
3481
+ }
3482
+ function createIntegrationFixtureContext(name, value) {
3483
+ const serialized = serializeValue(value);
3484
+ return {
3485
+ [INTEGRATION_FIXTURE_CONTEXT_KEY]: {
3486
+ version: INTEGRATION_FIXTURE_VERSION,
3487
+ name,
3488
+ value: serialized.json,
3489
+ ...serialized.meta !== void 0 && { valueMeta: serialized.meta }
3490
+ }
3491
+ };
3492
+ }
3493
+ function extractIntegrationFixtures(spanData) {
3494
+ const contexts = spanData.contexts;
3495
+ if (!Array.isArray(contexts)) {
3496
+ return void 0;
3497
+ }
3498
+ const fixtures = /* @__PURE__ */ new Map();
3499
+ for (const context of contexts) {
3500
+ if (!isRecord4(context)) {
3501
+ continue;
3502
+ }
3503
+ const fixture = context[INTEGRATION_FIXTURE_CONTEXT_KEY];
3504
+ if (!isRecord4(fixture) || fixture.version !== INTEGRATION_FIXTURE_VERSION || typeof fixture.name !== "string") {
3505
+ continue;
3506
+ }
3507
+ fixtures.set(
3508
+ fixture.name,
3509
+ deserializeValue({
3510
+ json: fixture.value,
3511
+ ...fixture.valueMeta !== void 0 && { meta: fixture.valueMeta }
3512
+ })
3513
+ );
3514
+ }
3515
+ return fixtures.size > 0 ? fixtures : void 0;
3516
+ }
3517
+ var INTEGRATION_FIXTURE_CONTEXT_KEY, INTEGRATION_FIXTURE_VERSION;
3518
+ var init_integrationFixture = __esm({
3519
+ "src/integrationFixture.ts"() {
3520
+ "use strict";
3521
+ init_serialize();
3522
+ INTEGRATION_FIXTURE_CONTEXT_KEY = "__bitfabIntegrationFixture";
3523
+ INTEGRATION_FIXTURE_VERSION = 1;
3524
+ }
3525
+ });
3526
+
3476
3527
  // src/replay.ts
3477
3528
  var replay_exports = {};
3478
3529
  __export(replay_exports, {
@@ -3697,6 +3748,7 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
3697
3748
  const spanData = span.rawData?.span_data ?? {};
3698
3749
  inputs = deserializeInputs(spanData);
3699
3750
  originalOutput = deserializeOutput(spanData);
3751
+ const integrationFixtures = extractIntegrationFixtures(spanData);
3700
3752
  if (adaptInputs) {
3701
3753
  const originalMetadata = serverItem.originalMetadata;
3702
3754
  inputs = adaptInputs(inputs, {
@@ -3788,6 +3840,7 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
3788
3840
  mockStrategy,
3789
3841
  mockOverrides: hasOverrides ? resolvedOverrides : void 0,
3790
3842
  fetchSpanOutput,
3843
+ integrationFixtures,
3791
3844
  dbBranchLease: lease,
3792
3845
  dbBranchTimings
3793
3846
  },
@@ -4268,6 +4321,7 @@ var init_replay = __esm({
4268
4321
  init_codeChange();
4269
4322
  init_errors();
4270
4323
  init_http();
4324
+ init_integrationFixture();
4271
4325
  init_mockOverride();
4272
4326
  init_randomUuid();
4273
4327
  init_replayContext();
@@ -4311,6 +4365,7 @@ __export(node_exports, {
4311
4365
  BitfabLangGraphIntegration: () => BitfabLangGraphIntegration,
4312
4366
  BitfabOpenAIAgentHandler: () => BitfabOpenAIAgentHandler,
4313
4367
  BitfabOpenAITracingProcessor: () => BitfabOpenAITracingProcessor,
4368
+ BitfabRivetIntegration: () => BitfabRivetIntegration,
4314
4369
  BitfabVercelAiHandler: () => BitfabVercelAiHandler,
4315
4370
  DEFAULT_SERVICE_URL: () => DEFAULT_SERVICE_URL,
4316
4371
  DatasetsClient: () => DatasetsClient,
@@ -6992,6 +7047,533 @@ _context = new WeakMap();
6992
7047
  // src/client.ts
6993
7048
  init_replayContext();
6994
7049
 
7050
+ // src/rivetIntegration.ts
7051
+ init_errors();
7052
+ init_integrationFixture();
7053
+ init_replayContext();
7054
+
7055
+ // src/rivetContext.ts
7056
+ init_asyncStorage();
7057
+ var storage = null;
7058
+ var browserBinding = null;
7059
+ var STORAGE_SYMBOL = /* @__PURE__ */ Symbol.for("bitfab.rivetContextStorage");
7060
+ function initializeStorage() {
7061
+ if (storage) {
7062
+ return;
7063
+ }
7064
+ const shared = globalThis;
7065
+ const existing = shared[STORAGE_SYMBOL];
7066
+ if (existing) {
7067
+ storage = existing;
7068
+ return;
7069
+ }
7070
+ const created = createAsyncLocalStorage();
7071
+ if (created) {
7072
+ shared[STORAGE_SYMBOL] = created;
7073
+ storage = created;
7074
+ }
7075
+ }
7076
+ var rivetContextReady = asyncStorageReady.then(() => {
7077
+ initializeStorage();
7078
+ });
7079
+ function getRivetContextBinding() {
7080
+ initializeStorage();
7081
+ return storage?.getStore() ?? browserBinding ?? void 0;
7082
+ }
7083
+ function runWithBrowserBinding(binding, fn) {
7084
+ const previous = browserBinding;
7085
+ browserBinding = binding;
7086
+ try {
7087
+ const result = fn();
7088
+ if (result instanceof Promise) {
7089
+ return result.finally(() => {
7090
+ browserBinding = previous;
7091
+ });
7092
+ }
7093
+ browserBinding = previous;
7094
+ return result;
7095
+ } catch (error) {
7096
+ browserBinding = previous;
7097
+ throw error;
7098
+ }
7099
+ }
7100
+ function runWithRivetContext(binding, fn) {
7101
+ initializeStorage();
7102
+ if (!storage && !isAsyncStorageInitDone()) {
7103
+ return rivetContextReady.then(() => runWithRivetContext(binding, fn));
7104
+ }
7105
+ if (storage) {
7106
+ return storage.run(binding, fn);
7107
+ }
7108
+ return runWithBrowserBinding(binding, fn);
7109
+ }
7110
+
7111
+ // src/rivetIntegration.ts
7112
+ var RIVET_DOCS_URL = "https://docs.bitfab.ai/frameworks/rivet";
7113
+ var RIVET_GROUP_EFFECT_METHODS = {
7114
+ db: ["execute", "nativeMetrics", "close"],
7115
+ kv: [
7116
+ "get",
7117
+ "put",
7118
+ "delete",
7119
+ "batchPut",
7120
+ "batchGet",
7121
+ "batchDelete",
7122
+ "deleteRange",
7123
+ "listPrefix",
7124
+ "listRange",
7125
+ "list"
7126
+ ],
7127
+ schedule: ["after", "at", "cancel", "get", "list"],
7128
+ cron: ["set", "every", "get", "list", "delete", "history"],
7129
+ queue: [
7130
+ "send",
7131
+ "next",
7132
+ "nextBatch",
7133
+ "waitForNames",
7134
+ "waitForAvailable",
7135
+ "complete",
7136
+ "enqueueAndWait",
7137
+ "tryNext",
7138
+ "tryNextBatch"
7139
+ ],
7140
+ run: ["setWakeAt"]
7141
+ };
7142
+ var RIVET_TOP_LEVEL_EFFECTS = [
7143
+ "broadcast",
7144
+ "saveState",
7145
+ "sleep",
7146
+ "destroy"
7147
+ ];
7148
+ var TOP_LEVEL_UNAVAILABLE_CAPABILITIES = /* @__PURE__ */ new Set([
7149
+ "conn",
7150
+ "conns",
7151
+ "log",
7152
+ "request",
7153
+ "actorRuntimeSocket",
7154
+ "keepAwake",
7155
+ "waitUntil",
7156
+ "client"
7157
+ ]);
7158
+ var SYNC_VOID_EFFECTS = /* @__PURE__ */ new Set([
7159
+ "broadcast",
7160
+ "sleep",
7161
+ "destroy"
7162
+ ]);
7163
+ var QUEUE_MESSAGE_EFFECTS = /* @__PURE__ */ new Set([
7164
+ "queue.next",
7165
+ "queue.nextBatch",
7166
+ "queue.waitForNames",
7167
+ "queue.tryNext",
7168
+ "queue.tryNextBatch"
7169
+ ]);
7170
+ function isRecord5(value) {
7171
+ return typeof value === "object" && value !== null;
7172
+ }
7173
+ function readProperty(value, property) {
7174
+ try {
7175
+ return Reflect.get(value, property, value);
7176
+ } catch {
7177
+ return void 0;
7178
+ }
7179
+ }
7180
+ function snapshotContext(context) {
7181
+ const source = context;
7182
+ const snapshot = {};
7183
+ for (const property of [
7184
+ "state",
7185
+ "vars",
7186
+ "actorId",
7187
+ "name",
7188
+ "key",
7189
+ "region",
7190
+ "aborted"
7191
+ ]) {
7192
+ const value = readProperty(source, property);
7193
+ if (value !== void 0) {
7194
+ snapshot[property] = value;
7195
+ }
7196
+ }
7197
+ return snapshot;
7198
+ }
7199
+ function unavailableCapability(path) {
7200
+ return new BitfabError(
7201
+ `Rivet context capability "${path}" is unavailable during replay. Add first-class support for that public context path before replaying code that uses it.`,
7202
+ RIVET_DOCS_URL
7203
+ );
7204
+ }
7205
+ function effectNode(traceFunctionKey, effect, mockSpanId) {
7206
+ return {
7207
+ traceFunctionKey,
7208
+ spanName: effect,
7209
+ type: "function",
7210
+ originalSpanId: mockSpanId
7211
+ };
7212
+ }
7213
+ function replayEffectStatus(replay2, traceFunctionKey, effect, marked) {
7214
+ const counterKey = `${traceFunctionKey}:${effect}`;
7215
+ const callIndex = replay2.callCounters?.get(counterKey) ?? 0;
7216
+ const mockSpan = replay2.mockTree?.spans.get(`${counterKey}:${callIndex}`);
7217
+ const hasOverride = replay2.mockOverrides?.some(
7218
+ (override) => override.match(
7219
+ effectNode(traceFunctionKey, effect, mockSpan?.sourceSpanId)
7220
+ )
7221
+ ) ?? false;
7222
+ return {
7223
+ willMock: hasOverride || replay2.mockStrategy === "all" || replay2.mockStrategy === "marked" && marked,
7224
+ hasRecordedSpan: mockSpan !== void 0,
7225
+ hasOverride,
7226
+ callIndex
7227
+ };
7228
+ }
7229
+ function assertReplayEffectAvailable(replay2, traceFunctionKey, effect, marked) {
7230
+ if (!replay2) {
7231
+ return;
7232
+ }
7233
+ const status = replayEffectStatus(replay2, traceFunctionKey, effect, marked);
7234
+ if (!status.willMock) {
7235
+ throw new BitfabError(
7236
+ `Rivet effect "${effect}" has no live actor context during replay. Add "${effect}" to mockOnReplay or provide a replay override.`,
7237
+ RIVET_DOCS_URL
7238
+ );
7239
+ }
7240
+ if (!status.hasRecordedSpan && !status.hasOverride) {
7241
+ throw new BitfabError(
7242
+ `No recorded Rivet effect "${effect}" exists at call ${status.callIndex + 1}; the live effect was not executed.`,
7243
+ RIVET_DOCS_URL
7244
+ );
7245
+ }
7246
+ }
7247
+ function fixtureName(traceFunctionKey) {
7248
+ return `rivet:${traceFunctionKey}`;
7249
+ }
7250
+ function snapshotFromReplay(traceFunctionKey, replay2) {
7251
+ const fixture = replay2.integrationFixtures?.get(fixtureName(traceFunctionKey));
7252
+ if (!isRecord5(fixture)) {
7253
+ throw new BitfabError(
7254
+ `Trace "${traceFunctionKey}" has no Rivet context fixture. Capture a fresh trace with the Rivet integration before replaying it.`,
7255
+ RIVET_DOCS_URL
7256
+ );
7257
+ }
7258
+ return fixture;
7259
+ }
7260
+ var BitfabRivetIntegration = class {
7261
+ /** @internal Constructed by `Bitfab.getRivetIntegration()`. */
7262
+ constructor(traceFunctionKey, runtime, options = {}) {
7263
+ this.traceFunctionKey = traceFunctionKey;
7264
+ this.runtime = runtime;
7265
+ this.replayProxies = /* @__PURE__ */ new WeakMap();
7266
+ this.markedEffects = new Set(options.mockOnReplay ?? []);
7267
+ }
7268
+ /**
7269
+ * Run a callback with a live Rivet context bound to the current async chain.
7270
+ * This binds context only; it creates no trace or span.
7271
+ */
7272
+ withContext(context, fn) {
7273
+ if (!isRecord5(context)) {
7274
+ throw new BitfabError("Rivet withContext requires a context object");
7275
+ }
7276
+ const binding = {
7277
+ context,
7278
+ fixtureContext: createIntegrationFixtureContext(
7279
+ fixtureName(this.traceFunctionKey),
7280
+ snapshotContext(context)
7281
+ ),
7282
+ recordedRoots: /* @__PURE__ */ new Set()
7283
+ };
7284
+ return runWithRivetContext(binding, fn);
7285
+ }
7286
+ /**
7287
+ * Adapt a traced function into a Rivet handler whose first argument is the
7288
+ * live actor context. The context is not added to the traced root's inputs.
7289
+ */
7290
+ bind(fn) {
7291
+ const integration = this;
7292
+ return function(context, ...args) {
7293
+ return integration.withContext(context, () => fn.apply(this, args));
7294
+ };
7295
+ }
7296
+ /**
7297
+ * Return the current Rivet context proxy. In production it delegates to the
7298
+ * bound live context. During replay it hydrates recorded actor state and
7299
+ * intercepts supported effects without requiring a live Rivet actor.
7300
+ */
7301
+ getContext() {
7302
+ const replay2 = getReplayContext();
7303
+ if (replay2) {
7304
+ const existing = this.replayProxies.get(replay2);
7305
+ if (existing) {
7306
+ return existing;
7307
+ }
7308
+ const proxy = this.createContextProxy(
7309
+ snapshotFromReplay(this.traceFunctionKey, replay2),
7310
+ void 0
7311
+ );
7312
+ this.replayProxies.set(replay2, proxy);
7313
+ return proxy;
7314
+ }
7315
+ const binding = getRivetContextBinding();
7316
+ if (!binding) {
7317
+ throw new BitfabError(
7318
+ "No Rivet context is bound. Call rivet.bind(handler) or rivet.withContext(context, callback) at the Rivet boundary.",
7319
+ RIVET_DOCS_URL
7320
+ );
7321
+ }
7322
+ this.runtime.recordRootFixture(
7323
+ binding.fixtureContext,
7324
+ binding.recordedRoots
7325
+ );
7326
+ if (!binding.proxy) {
7327
+ binding.proxy = this.createContextProxy(
7328
+ binding.context,
7329
+ binding
7330
+ );
7331
+ }
7332
+ return binding.proxy;
7333
+ }
7334
+ createContextProxy(target, binding) {
7335
+ const replay2 = getReplayContext();
7336
+ const dbProxy = this.createDbProxy(binding, replay2);
7337
+ const groupProxies = /* @__PURE__ */ new Map();
7338
+ for (const group of Object.keys(
7339
+ RIVET_GROUP_EFFECT_METHODS
7340
+ )) {
7341
+ if (group !== "db") {
7342
+ groupProxies.set(group, this.createGroupProxy(group, binding, replay2));
7343
+ }
7344
+ }
7345
+ const topLevelEffects = /* @__PURE__ */ new Map();
7346
+ for (const effect of RIVET_TOP_LEVEL_EFFECTS) {
7347
+ topLevelEffects.set(
7348
+ effect,
7349
+ this.createEffect(
7350
+ effect,
7351
+ () => binding?.context,
7352
+ effect,
7353
+ replay2
7354
+ )
7355
+ );
7356
+ }
7357
+ const replayTarget = replay2 ? { ...target } : target;
7358
+ if (replay2) {
7359
+ const controller = new AbortController();
7360
+ if (target.aborted === true) {
7361
+ controller.abort();
7362
+ }
7363
+ replayTarget.abortSignal = controller.signal;
7364
+ }
7365
+ return new Proxy(replayTarget, {
7366
+ get: (source, property) => {
7367
+ if (property === "db") {
7368
+ return dbProxy;
7369
+ }
7370
+ if (typeof property === "string") {
7371
+ const group = groupProxies.get(property);
7372
+ if (group) {
7373
+ return group;
7374
+ }
7375
+ const effect = topLevelEffects.get(property);
7376
+ if (effect) {
7377
+ return effect;
7378
+ }
7379
+ }
7380
+ if (property === "setPreventSleep" && replay2) {
7381
+ return (_preventSleep) => void 0;
7382
+ }
7383
+ if (replay2 && typeof property === "string" && TOP_LEVEL_UNAVAILABLE_CAPABILITIES.has(property)) {
7384
+ throw unavailableCapability(property);
7385
+ }
7386
+ const value = Reflect.get(source, property, source);
7387
+ return typeof value === "function" ? value.bind(source) : value;
7388
+ }
7389
+ });
7390
+ }
7391
+ createDbProxy(binding, replay2) {
7392
+ const proxy = this.createGroupProxy("db", binding, replay2);
7393
+ return new Proxy(proxy, {
7394
+ get: (source, property) => property === "transaction" ? this.createTransaction(binding, replay2) : Reflect.get(source, property, source)
7395
+ });
7396
+ }
7397
+ createGroupProxy(group, binding, replay2) {
7398
+ const targetProvider = () => {
7399
+ if (!binding) {
7400
+ return void 0;
7401
+ }
7402
+ const context = binding.context;
7403
+ const target = readProperty(context, group);
7404
+ return isRecord5(target) ? target : void 0;
7405
+ };
7406
+ const proxy = this.createMethodProxy(
7407
+ targetProvider,
7408
+ group,
7409
+ RIVET_GROUP_EFFECT_METHODS[group],
7410
+ replay2
7411
+ );
7412
+ if (group !== "queue") {
7413
+ return proxy;
7414
+ }
7415
+ return new Proxy(proxy, {
7416
+ get: (source, property) => property === "iter" ? (options) => this.createQueueIterator(source, options) : Reflect.get(source, property, source)
7417
+ });
7418
+ }
7419
+ createMethodProxy(targetProvider, prefix, methods, replay2) {
7420
+ const effects = /* @__PURE__ */ new Map();
7421
+ for (const method of methods) {
7422
+ const effect = `${prefix}.${method}`;
7423
+ effects.set(
7424
+ method,
7425
+ this.createEffect(effect, targetProvider, method, replay2)
7426
+ );
7427
+ }
7428
+ return new Proxy(
7429
+ {},
7430
+ {
7431
+ get: (_source, property) => {
7432
+ if (typeof property === "string") {
7433
+ const effect = effects.get(property);
7434
+ if (effect) {
7435
+ return effect;
7436
+ }
7437
+ if (replay2) {
7438
+ throw unavailableCapability(`${prefix}.${property}`);
7439
+ }
7440
+ }
7441
+ const target = targetProvider();
7442
+ if (!target) {
7443
+ return void 0;
7444
+ }
7445
+ const value = Reflect.get(target, property, target);
7446
+ return typeof value === "function" ? value.bind(target) : value;
7447
+ }
7448
+ }
7449
+ );
7450
+ }
7451
+ createEffect(effect, targetProvider, methodName, replay2) {
7452
+ const marked = this.markedEffects.has(effect);
7453
+ const invoke = (...args) => {
7454
+ assertReplayEffectAvailable(
7455
+ getReplayContext(),
7456
+ this.traceFunctionKey,
7457
+ effect,
7458
+ marked
7459
+ );
7460
+ const target = targetProvider();
7461
+ const method = target ? readProperty(target, methodName) : void 0;
7462
+ if (typeof method !== "function") {
7463
+ throw unavailableCapability(effect);
7464
+ }
7465
+ return method.apply(target, args);
7466
+ };
7467
+ const wrapped = SYNC_VOID_EFFECTS.has(effect) ? this.runtime.wrapEffect(
7468
+ effect,
7469
+ marked,
7470
+ invoke,
7471
+ replay2 ? () => void 0 : void 0
7472
+ ) : this.runtime.wrapEffect(effect, marked, async (...args) => {
7473
+ return await invoke(...args);
7474
+ });
7475
+ return (...args) => {
7476
+ if (replay2) {
7477
+ assertReplayEffectAvailable(
7478
+ replay2,
7479
+ this.traceFunctionKey,
7480
+ effect,
7481
+ marked
7482
+ );
7483
+ }
7484
+ const result = wrapped(...args);
7485
+ if (!QUEUE_MESSAGE_EFFECTS.has(effect) || !(result instanceof Promise)) {
7486
+ return result;
7487
+ }
7488
+ return result.then(
7489
+ (value) => this.decorateQueueMessages(value, effect, args, replay2)
7490
+ );
7491
+ };
7492
+ }
7493
+ createTransaction(binding, replay2) {
7494
+ return async (callback, options) => {
7495
+ if (typeof callback !== "function") {
7496
+ throw new BitfabError("Rivet db.transaction requires a callback");
7497
+ }
7498
+ if (replay2) {
7499
+ return await callback(
7500
+ this.createMethodProxy(
7501
+ () => void 0,
7502
+ "db.transaction",
7503
+ ["execute"],
7504
+ replay2
7505
+ )
7506
+ );
7507
+ }
7508
+ const context = binding?.context;
7509
+ const db = context ? readProperty(context, "db") : void 0;
7510
+ const transaction = isRecord5(db) ? readProperty(db, "transaction") : void 0;
7511
+ if (!isRecord5(db) || typeof transaction !== "function") {
7512
+ throw unavailableCapability("db.transaction");
7513
+ }
7514
+ return await transaction.call(
7515
+ db,
7516
+ async (transactionDb) => {
7517
+ if (!isRecord5(transactionDb)) {
7518
+ throw unavailableCapability("db.transaction.execute");
7519
+ }
7520
+ return await callback(
7521
+ this.createMethodProxy(
7522
+ () => transactionDb,
7523
+ "db.transaction",
7524
+ ["execute"],
7525
+ replay2
7526
+ )
7527
+ );
7528
+ },
7529
+ options
7530
+ );
7531
+ };
7532
+ }
7533
+ decorateQueueMessages(value, effect, args, replay2) {
7534
+ if (!this.queueCallIsCompletable(effect, args)) {
7535
+ return value;
7536
+ }
7537
+ if (Array.isArray(value)) {
7538
+ return value.map((message) => this.decorateQueueMessage(message, replay2));
7539
+ }
7540
+ return this.decorateQueueMessage(value, replay2);
7541
+ }
7542
+ decorateQueueMessage(value, replay2) {
7543
+ if (!isRecord5(value)) {
7544
+ return value;
7545
+ }
7546
+ const originalComplete = readProperty(value, "complete");
7547
+ const complete = this.createEffect(
7548
+ "queue.message.complete",
7549
+ () => typeof originalComplete === "function" ? { complete: originalComplete.bind(value) } : void 0,
7550
+ "complete",
7551
+ replay2
7552
+ );
7553
+ return { ...value, complete };
7554
+ }
7555
+ queueCallIsCompletable(effect, args) {
7556
+ const options = effect === "queue.waitForNames" ? args[1] : args[0];
7557
+ return isRecord5(options) && options.completable === true;
7558
+ }
7559
+ createQueueIterator(queue, options) {
7560
+ return {
7561
+ async *[Symbol.asyncIterator]() {
7562
+ for (; ; ) {
7563
+ const next = Reflect.get(queue, "next", queue);
7564
+ if (typeof next !== "function") {
7565
+ throw unavailableCapability("queue.next");
7566
+ }
7567
+ const message = await next.call(queue, options);
7568
+ if (message !== void 0 && message !== null) {
7569
+ yield message;
7570
+ }
7571
+ }
7572
+ }
7573
+ };
7574
+ }
7575
+ };
7576
+
6995
7577
  // src/seedContext.ts
6996
7578
  init_asyncStorage();
6997
7579
  var seedContextStorage = null;
@@ -8701,6 +9283,47 @@ var Bitfab = class {
8701
9283
  options
8702
9284
  });
8703
9285
  }
9286
+ /**
9287
+ * Get the first-class Rivet actor-context integration for an existing trace
9288
+ * root. The integration binds context and records effect spans; it never
9289
+ * creates another root.
9290
+ *
9291
+ * @param traceFunctionKey - Key used by the enclosing `withTrace()` root
9292
+ * @param options - Explicit per-context-path replay mocking policy
9293
+ * @experimental This API may change before it is stable.
9294
+ */
9295
+ getRivetIntegration(traceFunctionKey, options) {
9296
+ return new BitfabRivetIntegration(
9297
+ traceFunctionKey,
9298
+ {
9299
+ wrapEffect: (effect, mockOnReplay, fn, replayOutput) => {
9300
+ const spanOptions = {
9301
+ name: effect,
9302
+ type: "function",
9303
+ captureWhen: "nested",
9304
+ mockOnReplay,
9305
+ surface: "inherit",
9306
+ instrumentation: "rivet",
9307
+ ...replayOutput !== void 0 && { replayOutput }
9308
+ };
9309
+ return this.withSpan(traceFunctionKey, spanOptions, fn);
9310
+ },
9311
+ recordRootFixture: (context, recordedRoots) => {
9312
+ const root = getSpanStack()[0];
9313
+ if (!root) {
9314
+ return;
9315
+ }
9316
+ const rootId = `${root.traceId}:${root.spanId}`;
9317
+ if (recordedRoots.has(rootId)) {
9318
+ return;
9319
+ }
9320
+ root.contexts.push(context);
9321
+ recordedRoots.add(rootId);
9322
+ }
9323
+ },
9324
+ options
9325
+ );
9326
+ }
8704
9327
  /**
8705
9328
  * Get a Claude Agent SDK handler for tracing.
8706
9329
  *
@@ -9199,6 +9822,7 @@ var Bitfab = class {
9199
9822
  }
9200
9823
  return output;
9201
9824
  };
9825
+ const resolveBaseOutput = () => options.replayOutput !== void 0 ? options.replayOutput() : resolveRecordedOutput();
9202
9826
  const shouldMockWithBaseStrategy = replayCtxForMock.mockStrategy === "all" || replayCtxForMock.mockStrategy === "marked" && options.mockOnReplay === true;
9203
9827
  if (replayCtxForMock.mockOverrides?.length) {
9204
9828
  const nodeMeta = {
@@ -9255,7 +9879,7 @@ var Bitfab = class {
9255
9879
  }
9256
9880
  if (shouldMockWithBaseStrategy) {
9257
9881
  const output = await resolveMockOrAbort(
9258
- () => resolveRecordedOutput()
9882
+ () => resolveBaseOutput()
9259
9883
  );
9260
9884
  void sendSpan({
9261
9885
  result: output,
@@ -9278,7 +9902,7 @@ var Bitfab = class {
9278
9902
  );
9279
9903
  }
9280
9904
  if (shouldMockWithBaseStrategy) {
9281
- const recorded = resolveRecordedOutput();
9905
+ const recorded = resolveBaseOutput();
9282
9906
  if (recorded instanceof Promise) {
9283
9907
  return emitMockAsync(recorded, "recorded");
9284
9908
  }
@@ -9880,6 +10504,28 @@ var BitfabFunction = class {
9880
10504
  span(options = {}) {
9881
10505
  return this.client.span(this.traceFunctionKey, options);
9882
10506
  }
10507
+ withTrace(optionsOrFn, maybeFn) {
10508
+ if (typeof optionsOrFn === "function") {
10509
+ return this.client.withTrace(this.traceFunctionKey, optionsOrFn);
10510
+ }
10511
+ if (!maybeFn) {
10512
+ throw new BitfabError("BitfabFunction.withTrace requires a function");
10513
+ }
10514
+ return this.client.withTrace(this.traceFunctionKey, optionsOrFn, maybeFn);
10515
+ }
10516
+ /**
10517
+ * Create a trace method decorator bound to this function's key.
10518
+ *
10519
+ * Equivalent to `client.trace(key, options)` but reuses the key bound on
10520
+ * this handle.
10521
+ *
10522
+ * @param options - Trace configuration applied to the decorated method
10523
+ * @returns A method decorator configured for this key
10524
+ * @experimental Automatic child-call instrumentation is experimental.
10525
+ */
10526
+ trace(options = {}) {
10527
+ return this.client.trace(this.traceFunctionKey, options);
10528
+ }
9883
10529
  /**
9884
10530
  * Get a Vercel AI SDK language-model middleware bound to this function's key.
9885
10531
  *
@@ -9977,6 +10623,20 @@ var BitfabFunction = class {
9977
10623
  getLangGraphIntegration(options) {
9978
10624
  return this.client.getLangGraphIntegration(this.traceFunctionKey, options);
9979
10625
  }
10626
+ /**
10627
+ * Get the first-class Rivet actor-context integration bound to this key.
10628
+ * Use its `bind()` or `withContext()` outside this handle's `withTrace()`
10629
+ * root, then call `getContext()` inside the root.
10630
+ *
10631
+ * @param options - Explicit per-context-path replay mocking policy
10632
+ * @experimental This API may change before it is stable.
10633
+ */
10634
+ getRivetIntegration(options) {
10635
+ return this.client.getRivetIntegration(
10636
+ this.traceFunctionKey,
10637
+ options
10638
+ );
10639
+ }
9980
10640
  /**
9981
10641
  * Wrap a BAML client method to automatically capture prompt and LLM metadata.
9982
10642
  * Delegates to the parent client's wrapBAML method.
@@ -10142,6 +10802,7 @@ assertAsyncStorageRegistered();
10142
10802
  BitfabLangGraphIntegration,
10143
10803
  BitfabOpenAIAgentHandler,
10144
10804
  BitfabOpenAITracingProcessor,
10805
+ BitfabRivetIntegration,
10145
10806
  BitfabVercelAiHandler,
10146
10807
  DEFAULT_SERVICE_URL,
10147
10808
  DatasetsClient,