@capxul/sdk 4.0.0 → 4.1.0

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.
@@ -1,5 +1,5 @@
1
1
  import { $ as CapxulError, A as toAuthUserId, C as WEI_RE, D as toAddress, E as toAccountId, G as toPayrollRunId, H as toOrgId, I as toEmail, M as toChainId, N as toCountryCode, P as toCurrencyCode, Q as CAPXUL_ERROR_CODES, S as SUPPORTED_CURRENCY_CODES, U as toPartyId, W as toPayrollGroupId, _ as deriveCapxulSafeAddress, at as boundedResponseHeaders, b as BYTES32_RE, ct as decodeChainCause, dt as isFailureMode, et as EXPECTED_OPERATION_OUTCOMES, ft as revertSummaryText, it as FAILURE_MODES$1, j as toBudgetId, lt as failureFingerprint, mt as redactSecrets, n as InMemoryAuthCacheAdapter, nt as isCapxulError, ot as chainCauseProperties, p as orgRoleKeyForLabel, pt as containsSensitiveMaterial, q as toRoleKey, r as BrowserAuthCacheAdapter, rt as CHAIN_UPSTREAMS, st as chainEvidenceLabel, tt as Errors, ut as isChainUpstream, v as validateHandle, w as ZERO_BYTES32, x as EVM_ADDRESS_RE$1, y as APP_ID_RE } from "./clock-C2AUlq1V.mjs";
2
- import { Context, Data, Deferred, Duration, Effect, Exit, Fiber, Layer, Queue, Ref, Result, Schema, SchemaGetter, SchemaParser, Scope } from "effect";
2
+ import { Cause, Clock, Context, Data, Deferred, Duration, Effect, Exit, Fiber, Layer, Queue, Ref, Result, Schema, SchemaGetter, SchemaParser, Scope } from "effect";
3
3
  import { formatUnits, keccak256, parseUnits, recoverAddress, toBytes } from "viem";
4
4
  import { makeFunctionReference } from "convex/server";
5
5
  //#region src/domain/identity/model.ts
@@ -440,12 +440,14 @@ const CAPXUL_OPERATIONS = {
440
440
  },
441
441
  activity: {
442
442
  annotate: "activity.annotate",
443
+ emitAnnotationSaved: "activity.emitAnnotationSaved",
443
444
  get: "activity.get",
444
445
  list: "activity.list",
445
446
  summary: "activity.summary"
446
447
  },
447
448
  addressBook: {
448
449
  add: "addressBook.add",
450
+ emitRelationshipChanged: "addressBook.emitRelationshipChanged",
449
451
  get: "addressBook.get",
450
452
  hide: "addressBook.hide",
451
453
  label: "addressBook.label",
@@ -508,6 +510,7 @@ const CAPXUL_OPERATIONS = {
508
510
  createOrganization: "identity.CreateOrganization",
509
511
  ensureAccount: "identity.EnsureAccount",
510
512
  leaveOrganization: "identity.LeaveOrganization",
513
+ loadByAuthUserId: "identity.loadByAuthUserId",
511
514
  loadCurrent: "identity.loadCurrent",
512
515
  orgAt: "identity.OrgAt",
513
516
  orgFailed: "identity.OrgFailed",
@@ -658,7 +661,8 @@ const CAPXUL_OPERATIONS = {
658
661
  organizationPayments: {
659
662
  pay: "organizationPayments.pay",
660
663
  payBatch: "organizationPayments.payBatch",
661
- prepareExecution: "organizationPayments.prepareExecution"
664
+ prepareExecution: "organizationPayments.prepareExecution",
665
+ retry: "organizationPayments.retry"
662
666
  },
663
667
  organizationSetup: { getProofReceipt: "organizationSetup.getProofReceipt" },
664
668
  organizations: { detectAndAcceptPendingInvitations: "orgs.detectAndAcceptPendingInvitations" },
@@ -673,6 +677,7 @@ const CAPXUL_OPERATIONS = {
673
677
  prepareExecution: "payments.prepareExecution",
674
678
  prepareLifecycleExecution: "payments.prepareLifecycleExecution",
675
679
  redirect: "payments.redirect",
680
+ retry: "payments.retry",
676
681
  submitCommandExecution: "payments.submitCommandExecution",
677
682
  submitExecution: "payments.submitExecution"
678
683
  },
@@ -754,6 +759,7 @@ const CAPXUL_OPERATIONS = {
754
759
  smartAccount: {
755
760
  claim: "smartAccount.claim",
756
761
  confirmDeployment: "smartAccount.confirmDeployment",
762
+ loadByAuthUserId: "smartAccount.loadByAuthUserId",
757
763
  loadCurrent: "smartAccount.loadCurrent",
758
764
  provision: "smartAccount.provision"
759
765
  },
@@ -1538,6 +1544,148 @@ Schema.Struct({
1538
1544
  name: Schema.Literal("movement_scan_incident"),
1539
1545
  props: MovementScanIncidentProps
1540
1546
  });
1547
+ const ActivityReferenceProps = {
1548
+ reference_kind: Schema.Literals(["payment", "movement"]),
1549
+ reference_id: Schema.String
1550
+ };
1551
+ const ActivityFilterProps = {
1552
+ filter_kind: Schema.optional(Schema.Literals([
1553
+ "all",
1554
+ "payment",
1555
+ "movement"
1556
+ ])),
1557
+ filter_direction: Schema.optional(Schema.Literals([
1558
+ "all",
1559
+ "in",
1560
+ "out",
1561
+ "self"
1562
+ ])),
1563
+ filter_status: Schema.optional(Schema.Array(Schema.Literals([
1564
+ "pending",
1565
+ "settling",
1566
+ "pending_claim",
1567
+ "scheduled",
1568
+ "streaming",
1569
+ "settled",
1570
+ "cancelled",
1571
+ "failed"
1572
+ ])))
1573
+ };
1574
+ const ActivityActionProps = {
1575
+ ...TelemetryEnvelopeProps,
1576
+ scope_kind: Schema.Literals(["account", "organization"]),
1577
+ reason_code: Schema.optional(Schema.Literals(CAPXUL_ERROR_CODES))
1578
+ };
1579
+ Schema.Struct({
1580
+ name: Schema.Literal("contact_relationship_changed"),
1581
+ props: Schema.Struct({
1582
+ ...TelemetryEnvelopeProps,
1583
+ change: Schema.Literals([
1584
+ "added",
1585
+ "renamed",
1586
+ "hidden",
1587
+ "restored"
1588
+ ]),
1589
+ scope_kind: Schema.Literals(["account", "organization"]),
1590
+ scope_id: Schema.String,
1591
+ owner_party_id: Schema.String,
1592
+ party_id: Schema.String,
1593
+ hidden: Schema.Boolean,
1594
+ occurred_at: Schema.Number,
1595
+ operation: Schema.Literals([
1596
+ CAPXUL_OPERATIONS.addressBook.add,
1597
+ CAPXUL_OPERATIONS.addressBook.label,
1598
+ CAPXUL_OPERATIONS.addressBook.hide,
1599
+ CAPXUL_OPERATIONS.addressBook.unhide
1600
+ ])
1601
+ })
1602
+ });
1603
+ const ContactActionProps = {
1604
+ ...TelemetryEnvelopeProps,
1605
+ scope_kind: Schema.Literals(["account", "organization"]),
1606
+ party_id: OptionalString,
1607
+ reason_code: Schema.optional(Schema.Literals(CAPXUL_ERROR_CODES))
1608
+ };
1609
+ Schema.Struct({
1610
+ name: Schema.Literal("ui_contact_action_completed"),
1611
+ props: Schema.Union([
1612
+ Schema.Struct({
1613
+ ...ContactActionProps,
1614
+ action: Schema.Literal("add"),
1615
+ outcome: Schema.Literals(["opened", "cancelled"])
1616
+ }),
1617
+ Schema.Struct({
1618
+ ...ContactActionProps,
1619
+ action: Schema.Literal("refusal"),
1620
+ outcome: Schema.Literal("displayed")
1621
+ }),
1622
+ Schema.Struct({
1623
+ ...ContactActionProps,
1624
+ action: Schema.Literal("retry"),
1625
+ outcome: Schema.Literal("requested")
1626
+ })
1627
+ ])
1628
+ });
1629
+ Schema.Struct({
1630
+ name: Schema.Literal("activity_annotation_saved"),
1631
+ props: Schema.Struct({
1632
+ ...TelemetryEnvelopeProps,
1633
+ ...ActivityReferenceProps,
1634
+ scope_kind: Schema.Literals(["account", "organization"]),
1635
+ scope_id: Schema.String,
1636
+ occurred_at: Schema.Number
1637
+ })
1638
+ });
1639
+ Schema.Struct({
1640
+ name: Schema.Literal("ui_activity_action_completed"),
1641
+ props: Schema.Union([
1642
+ Schema.Struct({
1643
+ ...ActivityActionProps,
1644
+ ...ActivityFilterProps,
1645
+ action: Schema.Literal("filter"),
1646
+ outcome: Schema.Literal("committed")
1647
+ }),
1648
+ Schema.Struct({
1649
+ ...ActivityActionProps,
1650
+ action: Schema.Literal("refusal"),
1651
+ outcome: Schema.Literal("displayed")
1652
+ }),
1653
+ Schema.Struct({
1654
+ ...ActivityActionProps,
1655
+ action: Schema.Literal("retry"),
1656
+ outcome: Schema.Literal("requested")
1657
+ }),
1658
+ Schema.Struct({
1659
+ ...ActivityActionProps,
1660
+ ...ActivityReferenceProps,
1661
+ action: Schema.Literal("detail"),
1662
+ outcome: Schema.Literals(["opened", "failed"])
1663
+ }),
1664
+ Schema.Struct({
1665
+ ...ActivityActionProps,
1666
+ ...ActivityReferenceProps,
1667
+ action: Schema.Literal("receipt"),
1668
+ outcome: Schema.Literals([
1669
+ "document_rendered",
1670
+ "explorer_opened",
1671
+ "popup_blocked",
1672
+ "failed"
1673
+ ])
1674
+ }),
1675
+ Schema.Struct({
1676
+ ...ActivityActionProps,
1677
+ ...ActivityFilterProps,
1678
+ action: Schema.Literal("export"),
1679
+ outcome: Schema.Literals([
1680
+ "completed",
1681
+ "partial",
1682
+ "failed"
1683
+ ]),
1684
+ row_count: Schema.optional(Schema.Number),
1685
+ truncated: Schema.optional(Schema.Boolean)
1686
+ })
1687
+ ])
1688
+ });
1541
1689
  function redactTelemetryEvent(event, options = {}) {
1542
1690
  const props = redactTelemetryProps(event.name, event.props, options);
1543
1691
  return props === void 0 ? { name: event.name } : {
@@ -3497,9 +3645,10 @@ const INVOCATION_OBSERVATION = Symbol("capxul.invocation-observation");
3497
3645
  const FAILURE_INVOCATION_SNAPSHOT = Symbol("capxul.failure-invocation-snapshot");
3498
3646
  /** @internal Attach one immutable, non-wire invocation snapshot to an SDK-owned object. */
3499
3647
  function attachInvocationObservation(target, source) {
3500
- const snapshot = Object.freeze(source.context === void 0 ? { active: source.active } : {
3648
+ const snapshot = Object.freeze({
3501
3649
  active: source.active,
3502
- context: Object.freeze({ ...source.context })
3650
+ ...source.actorId === void 0 ? {} : { actorId: source.actorId },
3651
+ ...source.context === void 0 ? {} : { context: Object.freeze({ ...source.context }) }
3503
3652
  });
3504
3653
  Object.defineProperty(target, INVOCATION_OBSERVATION, {
3505
3654
  configurable: false,
@@ -3751,10 +3900,10 @@ const logIdentityTransition = (record) => (record.outcome === "applied" ? Effect
3751
3900
  //#region src/domain/machine/shell.ts
3752
3901
  const INVOCATION_PARENT_SPAN = Symbol("@capxul/sdk/identity-invocation-parent-span");
3753
3902
  function carryInvocationParentSpan(controls, parent) {
3754
- return {
3903
+ return copyInvocationObservation(controls, {
3755
3904
  ...controls,
3756
3905
  [INVOCATION_PARENT_SPAN]: parent
3757
- };
3906
+ });
3758
3907
  }
3759
3908
  function withInvocationParentSpan(effect, controls) {
3760
3909
  const parent = controls?.[INVOCATION_PARENT_SPAN];
@@ -4105,13 +4254,13 @@ async function toCapxulResult(program, layer) {
4105
4254
  * with `{ publicError }` rather than a bare `CapxulError`, so the wrapper is
4106
4255
  * unwrapped here — once — instead of at every call site.
4107
4256
  */
4108
- async function runIfActive(signal, operation, effect, runPromise = Effect.runPromise) {
4109
- if (signal?.aborted === true) return {
4257
+ async function runIfActive(signal, operation, effect, runPromise = Effect.runPromise, observe) {
4258
+ if (signal?.aborted === true && observe === void 0) return {
4110
4259
  ok: false,
4111
4260
  error: Errors.cancelled({ operation })
4112
4261
  };
4113
- const program = effect().pipe(Effect.mapError((error) => error.publicError));
4114
- return runProgram(signal === void 0 ? program : Effect.raceFirst(program, Effect.callback((resume) => {
4262
+ const program = signal?.aborted === true ? Effect.fail(Errors.cancelled({ operation })) : Effect.suspend(effect).pipe(Effect.mapError((error) => error.publicError));
4263
+ const controlled = signal === void 0 ? program : Effect.raceFirst(program, Effect.callback((resume) => {
4115
4264
  if (signal.aborted) {
4116
4265
  resume(Effect.fail(Errors.cancelled({ operation })));
4117
4266
  return Effect.void;
@@ -4119,7 +4268,8 @@ async function runIfActive(signal, operation, effect, runPromise = Effect.runPro
4119
4268
  const onAbort = () => resume(Effect.fail(Errors.cancelled({ operation })));
4120
4269
  signal.addEventListener("abort", onAbort, { once: true });
4121
4270
  return Effect.sync(() => signal.removeEventListener("abort", onAbort));
4122
- })), runPromise);
4271
+ }));
4272
+ return runProgram(observe === void 0 ? controlled : observe(controlled), runPromise);
4123
4273
  }
4124
4274
  //#endregion
4125
4275
  //#region src/surface/_shared/effect-actor-bridge.ts
@@ -4170,22 +4320,52 @@ async function runPortEffect(effect, controls, operation = CAPXUL_OPERATIONS.run
4170
4320
  orElse: () => Effect.fail({ publicError: Errors.providerTimeout("sdk", operation, timeoutMs) })
4171
4321
  }))).pipe(Effect.mapError((failure) => failure.publicError)), controls, operation, runPromise);
4172
4322
  }
4323
+ /** Keep observation metadata while the compound operation owns cancellation. */
4324
+ function observationOnlyControls(controls) {
4325
+ const { signal: _signal, timeoutMs: _timeoutMs, deadlineMs: _deadlineMs, ...observation } = controls ?? {};
4326
+ return copyInvocationObservation(controls, observation);
4327
+ }
4173
4328
  /** Observe a public Effect that already uses the canonical CapxulError channel. */
4174
4329
  async function runCapxulEffect(effect, controls, operation = CAPXUL_OPERATIONS.runtime.port, runPromise = Effect.runPromise) {
4175
4330
  const invocation = readInvocationObservation(controls);
4176
- const correlationId = safeEngineeringIdentifier(controls?.correlation_id ?? invocation?.context?.correlationId);
4177
- const observed = effect.pipe(Effect.tap(() => Effect.annotateCurrentSpan({ outcome: "succeeded" })), Effect.tapError((error) => {
4178
- const mode = error.mode ?? error.details?.failure_mode;
4179
- return Effect.annotateCurrentSpan({
4180
- outcome: portFailureOutcome(error.code),
4181
- failure_code: error.code,
4182
- ...typeof mode === "string" ? { mode } : {}
4183
- });
4184
- }), Effect.tapDefect(() => Effect.annotateCurrentSpan({
4185
- outcome: "failed",
4186
- failure_code: "UNKNOWN"
4187
- })), Effect.withSpan(`identity.port.${operation}`), Effect.annotateSpans(correlationId === void 0 ? {} : { correlation_id: correlationId }));
4188
- return runIfActive(controls?.signal, operation, () => withInvocationParentSpan(observed, controls).pipe(Effect.mapError((publicError) => ({ publicError }))), runPromise);
4331
+ const correlationId = safeEngineeringIdentifier(invocation?.context?.correlationId ?? controls?.correlation_id);
4332
+ const context = invocation?.active === false ? void 0 : sanitizeObservationContext(invocation?.context);
4333
+ const fields = {
4334
+ operation,
4335
+ ...correlationId === void 0 ? {} : { correlation_id: correlationId },
4336
+ ...context?.sessionId === void 0 ? {} : {
4337
+ session_id: context.sessionId,
4338
+ sessionId: context.sessionId
4339
+ },
4340
+ ...context?.journeyId === void 0 ? {} : { journey_id: context.journeyId },
4341
+ ...context?.release === void 0 ? {} : { release: context.release },
4342
+ ...context?.application === void 0 ? {} : { application: context.application },
4343
+ ...safeEngineeringIdentifier(invocation?.actorId) === void 0 ? {} : {
4344
+ actor_id: invocation.actorId,
4345
+ actor_kind: "authenticated",
4346
+ posthogDistinctId: invocation.actorId
4347
+ }
4348
+ };
4349
+ const result = await runIfActive(controls?.signal, operation, () => effect.pipe(Effect.mapError((publicError) => ({ publicError }))), runPromise, (program) => withInvocationParentSpan(Effect.gen(function* () {
4350
+ const startedAt = yield* Clock.currentTimeMillis;
4351
+ const exit = yield* Effect.exit(program.pipe(Effect.catchDefect((cause) => Effect.fail(Errors.unknown(cause)))));
4352
+ const duration_ms = (yield* Clock.currentTimeMillis) - startedAt;
4353
+ const error = Exit.isFailure(exit) ? Cause.squash(exit.cause) : void 0;
4354
+ const failure = error instanceof CapxulError ? error : void 0;
4355
+ const outcome = Exit.isSuccess(exit) ? "succeeded" : failure?.code === "CANCELLED" ? "cancelled" : failure !== void 0 && EXPECTED_OPERATION_OUTCOMES.has(failure.code) ? "refused" : "failed";
4356
+ const completion = {
4357
+ ...fields,
4358
+ duration_ms,
4359
+ outcome,
4360
+ ...failure === void 0 ? {} : { failure_code: failure.code },
4361
+ ...typeof failure?.mode === "string" ? { mode: failure.mode } : {},
4362
+ ...failure?.mode === void 0 && typeof failure?.details?.failure_mode === "string" ? { mode: failure.details.failure_mode } : {}
4363
+ };
4364
+ yield* Effect.annotateCurrentSpan(completion).pipe(Effect.catchCause(() => Effect.void));
4365
+ yield* (outcome === "failed" ? Effect.logError("capxul_sdk_operation") : Effect.logInfo("capxul_sdk_operation")).pipe(Effect.annotateLogs(completion), Effect.catchCause(() => Effect.void));
4366
+ return yield* Exit.isSuccess(exit) ? Effect.succeed(exit.value) : Effect.failCause(exit.cause);
4367
+ }).pipe(Effect.withSpan(operation)), controls));
4368
+ return !result.ok && invocation !== void 0 ? markFailureInvocationSnapshot(result, invocation) : result;
4189
4369
  }
4190
4370
  /** Map machine-internal failure state onto the public SDK error vocabulary. */
4191
4371
  function publicIdentityFailure(failure) {
@@ -4399,76 +4579,110 @@ function makeActorRelationshipMethods(deps) {
4399
4579
  const fns = actorScopeContract;
4400
4580
  return {
4401
4581
  addressBook: {
4402
- list: (input, options) => mapOk$1(CAPXUL_OPERATIONS.addressBook.list, awaitableConvex(options?.signal, CAPXUL_OPERATIONS.addressBook.list, () => convexCall.query(fns.addressBookList, {
4403
- actor,
4404
- ...input?.includeHidden === void 0 ? {} : { includeHidden: input.includeHidden }
4405
- })), (entries) => entries.map(mapAddressBookEntry)),
4406
- get: (entryId, options) => mapOk$1(CAPXUL_OPERATIONS.addressBook.get, awaitableConvex(options?.signal, CAPXUL_OPERATIONS.addressBook.get, () => convexCall.query(fns.addressBookGet, {
4407
- actor,
4408
- partyId: entryId
4409
- })), (entry) => entry === null ? null : mapAddressBookEntry(entry)),
4410
- add: async (input, options) => {
4582
+ list: (input, options) => {
4583
+ const controls = deps.invocationControls?.(options) ?? options;
4584
+ return runPortEffect(mapReply(CAPXUL_OPERATIONS.addressBook.list, Effect.suspend(() => convexCall.query(fns.addressBookList, copyInvocationObservation(controls, {
4585
+ actor,
4586
+ ...input?.includeHidden === void 0 ? {} : { includeHidden: input.includeHidden }
4587
+ }))), (entries) => entries.map(mapAddressBookEntry)), controls, CAPXUL_OPERATIONS.addressBook.list, deps.runPromise);
4588
+ },
4589
+ get: (entryId, options) => {
4590
+ const controls = deps.invocationControls?.(options) ?? options;
4591
+ return runPortEffect(mapReply(CAPXUL_OPERATIONS.addressBook.get, Effect.suspend(() => convexCall.query(fns.addressBookGet, copyInvocationObservation(controls, {
4592
+ actor,
4593
+ partyId: entryId
4594
+ }))), (entry) => entry === null ? null : mapAddressBookEntry(entry)), controls, CAPXUL_OPERATIONS.addressBook.get, deps.runPromise);
4595
+ },
4596
+ add: (input, options) => {
4597
+ const controls = deps.invocationControls?.(options) ?? options;
4411
4598
  const ref = normalizeRefForBackend$1(input.ref, "ref");
4412
- if (!ref.ok) return ref;
4413
- return mapOk$1(CAPXUL_OPERATIONS.addressBook.add, await awaitableConvex(options?.signal, CAPXUL_OPERATIONS.addressBook.add, () => convexCall.mutation(fns.addressBookAdd, {
4599
+ if (!ref.ok) return runCapxulEffect(Effect.fail(ref.error), controls, CAPXUL_OPERATIONS.addressBook.add, deps.runPromise);
4600
+ return runPortEffect(mapReply(CAPXUL_OPERATIONS.addressBook.add, Effect.suspend(() => convexCall.mutation(fns.addressBookAdd, copyInvocationObservation(controls, {
4414
4601
  actor,
4415
4602
  ref: ref.value,
4416
4603
  ...input.label === void 0 ? {} : { label: input.label }
4417
- })), mapAddressBookEntry);
4604
+ }))), mapAddressBookEntry), controls, CAPXUL_OPERATIONS.addressBook.add, deps.runPromise);
4605
+ },
4606
+ hide: (entryId, options) => {
4607
+ const controls = deps.invocationControls?.(options) ?? options;
4608
+ return runPortEffect(mapReply(CAPXUL_OPERATIONS.addressBook.hide, Effect.suspend(() => convexCall.mutation(fns.addressBookHide, copyInvocationObservation(controls, {
4609
+ actor,
4610
+ partyId: entryId
4611
+ }))), mapAddressBookEntry), controls, CAPXUL_OPERATIONS.addressBook.hide, deps.runPromise);
4418
4612
  },
4419
- hide: (entryId, options) => mapOk$1(CAPXUL_OPERATIONS.addressBook.hide, awaitableConvex(options?.signal, CAPXUL_OPERATIONS.addressBook.hide, () => convexCall.mutation(fns.addressBookHide, {
4420
- actor,
4421
- partyId: entryId
4422
- })), mapAddressBookEntry),
4423
- unhide: (entryId, options) => mapOk$1(CAPXUL_OPERATIONS.addressBook.unhide, awaitableConvex(options?.signal, CAPXUL_OPERATIONS.addressBook.unhide, () => convexCall.mutation(fns.addressBookUnhide, {
4424
- actor,
4425
- partyId: entryId
4426
- })), mapAddressBookEntry),
4427
- label: (input, options) => mapOk$1(CAPXUL_OPERATIONS.addressBook.label, awaitableConvex(options?.signal, CAPXUL_OPERATIONS.addressBook.label, () => convexCall.mutation(fns.addressBookLabel, {
4428
- actor,
4429
- partyId: input.entryId,
4430
- label: input.label
4431
- })), mapAddressBookEntry)
4613
+ unhide: (entryId, options) => {
4614
+ const controls = deps.invocationControls?.(options) ?? options;
4615
+ return runPortEffect(mapReply(CAPXUL_OPERATIONS.addressBook.unhide, Effect.suspend(() => convexCall.mutation(fns.addressBookUnhide, copyInvocationObservation(controls, {
4616
+ actor,
4617
+ partyId: entryId
4618
+ }))), mapAddressBookEntry), controls, CAPXUL_OPERATIONS.addressBook.unhide, deps.runPromise);
4619
+ },
4620
+ label: (input, options) => {
4621
+ const controls = deps.invocationControls?.(options) ?? options;
4622
+ return runPortEffect(mapReply(CAPXUL_OPERATIONS.addressBook.label, Effect.suspend(() => convexCall.mutation(fns.addressBookLabel, copyInvocationObservation(controls, {
4623
+ actor,
4624
+ partyId: input.entryId,
4625
+ label: input.label
4626
+ }))), mapAddressBookEntry), controls, CAPXUL_OPERATIONS.addressBook.label, deps.runPromise);
4627
+ }
4432
4628
  },
4433
4629
  requests: {
4434
- issue: async (input, options) => {
4630
+ issue: (input, options) => {
4631
+ const controls = deps.invocationControls?.(options) ?? options;
4435
4632
  const payer = normalizeRefForBackend$1(input.payer, "payer");
4436
- if (!payer.ok) return payer;
4437
- return mapOk$1(CAPXUL_OPERATIONS.requests.issue, await awaitableConvex(options?.signal, CAPXUL_OPERATIONS.requests.issue, () => convexCall.mutation(fns.requestsIssue, {
4633
+ if (!payer.ok) return runCapxulEffect(Effect.fail(payer.error), controls, CAPXUL_OPERATIONS.requests.issue, deps.runPromise);
4634
+ return runPortEffect(mapReply(CAPXUL_OPERATIONS.requests.issue, Effect.suspend(() => convexCall.mutation(fns.requestsIssue, copyInvocationObservation(controls, {
4438
4635
  actor,
4439
4636
  payer: payer.value,
4440
4637
  amount: input.amount,
4441
4638
  reference: input.reference,
4442
4639
  ...input.memo === void 0 ? {} : { memo: input.memo },
4443
4640
  ...input.expiresAt === void 0 ? {} : { expiresAt: input.expiresAt }
4444
- })), (request) => mapActorRequest(request, input.payer));
4641
+ }))), (request) => mapActorRequest(request, input.payer)), controls, CAPXUL_OPERATIONS.requests.issue, deps.runPromise);
4642
+ },
4643
+ list: (options) => {
4644
+ const controls = deps.invocationControls?.(options) ?? options;
4645
+ return runPortEffect(mapReply(CAPXUL_OPERATIONS.requests.list, Effect.suspend(() => convexCall.query(fns.requestsList, copyInvocationObservation(controls, { actor }))), (requests) => requests.map((request) => mapActorRequest(request))), controls, CAPXUL_OPERATIONS.requests.list, deps.runPromise);
4445
4646
  },
4446
- list: (options) => mapOk$1(CAPXUL_OPERATIONS.requests.list, awaitableConvex(options?.signal, CAPXUL_OPERATIONS.requests.list, () => convexCall.query(fns.requestsList, { actor })), (requests) => requests.map((request) => mapActorRequest(request))),
4447
- get: (requestId, options) => mapOk$1(CAPXUL_OPERATIONS.requests.get, awaitableConvex(options?.signal, CAPXUL_OPERATIONS.requests.get, () => convexCall.query(fns.requestsGet, {
4448
- actor,
4449
- paymentRequestId: requestId
4450
- })), (request) => request === null ? null : mapActorRequest(request)),
4451
- cancel: (requestId, options) => mapOk$1(CAPXUL_OPERATIONS.requests.cancel, awaitableConvex(options?.signal, CAPXUL_OPERATIONS.requests.cancel, () => convexCall.mutation(fns.requestsCancel, {
4452
- actor,
4453
- paymentRequestId: requestId
4454
- })), (request) => mapActorRequest(request))
4647
+ get: (requestId, options) => {
4648
+ const controls = deps.invocationControls?.(options) ?? options;
4649
+ return runPortEffect(mapReply(CAPXUL_OPERATIONS.requests.get, Effect.suspend(() => convexCall.query(fns.requestsGet, copyInvocationObservation(controls, {
4650
+ actor,
4651
+ paymentRequestId: requestId
4652
+ }))), (request) => request === null ? null : mapActorRequest(request)), controls, CAPXUL_OPERATIONS.requests.get, deps.runPromise);
4653
+ },
4654
+ cancel: (requestId, options) => {
4655
+ const controls = deps.invocationControls?.(options) ?? options;
4656
+ return runPortEffect(mapReply(CAPXUL_OPERATIONS.requests.cancel, Effect.suspend(() => convexCall.mutation(fns.requestsCancel, copyInvocationObservation(controls, {
4657
+ actor,
4658
+ paymentRequestId: requestId
4659
+ }))), (request) => mapActorRequest(request)), controls, CAPXUL_OPERATIONS.requests.cancel, deps.runPromise);
4660
+ }
4455
4661
  },
4456
4662
  inbox: {
4457
- list: (options) => mapOk$1(CAPXUL_OPERATIONS.inbox.list, awaitableConvex(options?.signal, CAPXUL_OPERATIONS.inbox.list, () => convexCall.query(fns.inboxList, { actor })), (items) => items.map(mapInboxItem)),
4458
- approve: async (input, options) => {
4459
- const result = await awaitableConvex(options?.signal, CAPXUL_OPERATIONS.inbox.approve, () => convexCall.mutation(fns.inboxApprove, {
4663
+ list: (options) => {
4664
+ const controls = deps.invocationControls?.(options) ?? options;
4665
+ return runPortEffect(mapReply(CAPXUL_OPERATIONS.inbox.list, Effect.suspend(() => convexCall.query(fns.inboxList, copyInvocationObservation(controls, { actor }))), (items) => items.map(mapInboxItem)), controls, CAPXUL_OPERATIONS.inbox.list, deps.runPromise);
4666
+ },
4667
+ approve: (input, options) => {
4668
+ const controls = deps.invocationControls?.(options) ?? options;
4669
+ return runPortEffect(Effect.suspend(() => convexCall.mutation(fns.inboxApprove, copyInvocationObservation(controls, {
4460
4670
  actor,
4461
4671
  paymentRequestId: input.requestId,
4462
4672
  ...input.timing === void 0 ? {} : { timing: input.timing },
4463
4673
  ...input.permissionId === void 0 ? {} : { permissionId: input.permissionId }
4464
- }));
4465
- if (!result.ok) return result;
4466
- return mapApprovedInboxPayment(result.value, input);
4674
+ }))).pipe(Effect.flatMap((prepared) => {
4675
+ const result = mapApprovedInboxPayment(prepared, input);
4676
+ return result.ok ? Effect.succeed(result.value) : Effect.fail({ publicError: result.error });
4677
+ })), controls, CAPXUL_OPERATIONS.inbox.approve, deps.runPromise);
4467
4678
  },
4468
- decline: (requestId, options) => mapOk$1(CAPXUL_OPERATIONS.inbox.decline, awaitableConvex(options?.signal, CAPXUL_OPERATIONS.inbox.decline, () => convexCall.mutation(fns.inboxDecline, {
4469
- actor,
4470
- paymentRequestId: requestId
4471
- })), mapInboxItem)
4679
+ decline: (requestId, options) => {
4680
+ const controls = deps.invocationControls?.(options) ?? options;
4681
+ return runPortEffect(mapReply(CAPXUL_OPERATIONS.inbox.decline, Effect.suspend(() => convexCall.mutation(fns.inboxDecline, copyInvocationObservation(controls, {
4682
+ actor,
4683
+ paymentRequestId: requestId
4684
+ }))), mapInboxItem), controls, CAPXUL_OPERATIONS.inbox.decline, deps.runPromise);
4685
+ }
4472
4686
  },
4473
4687
  profile: {
4474
4688
  get: (options) => {
@@ -4545,22 +4759,12 @@ function missingConvexCall(operation) {
4545
4759
  * promise and the caller's `if (!result.ok)` never runs (ADR-0023: errors are
4546
4760
  * values, and a code crosses the seam).
4547
4761
  */
4548
- async function mapOk$1(operation, resultOrPromise, f) {
4549
- const result = await resultOrPromise;
4550
- if (!result.ok) return result;
4551
- try {
4552
- return {
4553
- ok: true,
4554
- value: f(result.value)
4555
- };
4556
- } catch (cause) {
4557
- return {
4558
- ok: false,
4559
- error: cause instanceof CapxulError ? cause : Errors.providerError("convex", operation, cause)
4560
- };
4561
- }
4762
+ function mapReply(operation, program, project) {
4763
+ return program.pipe(Effect.flatMap((value) => Effect.try({
4764
+ try: () => project(value),
4765
+ catch: (cause) => ({ publicError: cause instanceof CapxulError ? cause : Errors.providerError("convex", operation, cause) })
4766
+ })));
4562
4767
  }
4563
- const awaitableConvex = runIfActive;
4564
4768
  const ADDRESS_BOOK_RELATIONSHIPS = [
4565
4769
  "paid",
4566
4770
  "paidBy",
@@ -4928,6 +5132,8 @@ function makeAccountMethods(deps) {
4928
5132
  return {
4929
5133
  methods: {
4930
5134
  ...makeActorRelationshipMethods({
5135
+ ...deps.runPromise === void 0 ? {} : { runPromise: deps.runPromise },
5136
+ ...deps.invocationControls === void 0 ? {} : { invocationControls: deps.invocationControls },
4931
5137
  actor: { kind: "account" },
4932
5138
  ...deps.convexCall === void 0 ? {} : { convexCall: deps.convexCall },
4933
5139
  ...deps.profileMethods === void 0 ? {} : { accountProfileMethods: deps.profileMethods }
@@ -4981,7 +5187,7 @@ const moneyExecutionContract = {
4981
5187
  };
4982
5188
  //#endregion
4983
5189
  //#region package.json
4984
- var version = "4.0.0";
5190
+ var version = "4.1.0";
4985
5191
  //#endregion
4986
5192
  //#region src/telemetry/exception-projection.ts
4987
5193
  /** Fixed fallback for failures that have no safe message. */
@@ -5037,7 +5243,16 @@ function postHogFailureObservation(policy, fixedSnapshot) {
5037
5243
  const directSnapshot = callStartSnapshot === void 0 ? policy.snapshot() : void 0;
5038
5244
  if (!(callStartSnapshot?.active ?? directSnapshot?.active) || policy.client === null || policy.client === void 0) return;
5039
5245
  const safeFailure = sanitizeFailureObservation(failure);
5040
- return [safeFailure, postHogProperties(safeFailure, callStartSnapshot?.context ?? directSnapshot?.context)];
5246
+ const directContext = callStartSnapshot?.context ?? directSnapshot?.context;
5247
+ const actorId = callStartSnapshot?.actorId;
5248
+ return [safeFailure, {
5249
+ ...postHogProperties(safeFailure, directContext),
5250
+ ...actorId !== void 0 && /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u.test(actorId) ? {
5251
+ actor_id: actorId,
5252
+ actor_kind: "authenticated",
5253
+ distinct_id: actorId
5254
+ } : {}
5255
+ }];
5041
5256
  };
5042
5257
  const captureOperationFailure = (failure) => {
5043
5258
  const prepared = prepare(failure);
@@ -5142,7 +5357,8 @@ function observeSdkClient(client, adapter, snapshot) {
5142
5357
  };
5143
5358
  const processOutput = (output, path, invocation) => {
5144
5359
  if (isFailedResult(output)) {
5145
- report(adapter, "operation", path.join("."), output.error, invocation);
5360
+ const captured = readFailureInvocationSnapshot(output);
5361
+ report(adapter, "operation", path.join("."), output.error, captured ?? invocation, void 0, captured !== void 0);
5146
5362
  return output;
5147
5363
  }
5148
5364
  if (isCapxulResult(output)) return output;
@@ -5174,7 +5390,7 @@ function reportedByMachine(cause) {
5174
5390
  }
5175
5391
  return false;
5176
5392
  }
5177
- function report(adapter, kind, operation, cause, invocation, origin) {
5393
+ function report(adapter, kind, operation, cause, invocation, origin, authoritativeSnapshot = false) {
5178
5394
  if (origin === "machine") {
5179
5395
  let link = cause;
5180
5396
  for (let depth = 0; depth < 8 && typeof link === "object" && link !== null; depth++) {
@@ -5186,7 +5402,7 @@ function report(adapter, kind, operation, cause, invocation, origin) {
5186
5402
  const kindName = normalizeErrorKind(errorKind(cause));
5187
5403
  const context = sanitizeObservationContext({
5188
5404
  ...invocation.context,
5189
- ...isCapxulError(cause) && cause.correlationId !== void 0 ? { correlationId: cause.correlationId } : {}
5405
+ ...!authoritativeSnapshot && isCapxulError(cause) && cause.correlationId !== void 0 ? { correlationId: cause.correlationId } : {}
5190
5406
  });
5191
5407
  const detail = failureDetail(cause);
5192
5408
  const evidence = failureEvidence(cause);
@@ -5200,6 +5416,7 @@ function report(adapter, kind, operation, cause, invocation, origin) {
5200
5416
  ...evidence
5201
5417
  }, {
5202
5418
  active: invocation.active,
5419
+ ...invocation.actorId === void 0 ? {} : { actorId: invocation.actorId },
5203
5420
  ...context === void 0 ? {} : { context }
5204
5421
  });
5205
5422
  try {
@@ -5728,17 +5945,17 @@ async function fingerprintPaymentIntent(intent) {
5728
5945
  function matchesIntent(expected) {
5729
5946
  return async (request) => await fingerprintPaymentIntent(request) === await fingerprintPaymentIntent(expected);
5730
5947
  }
5731
- async function abandonPrepared$1(deps, executionId, closePayment, reason, result, onPreparedClosed) {
5948
+ async function abandonPrepared$1(deps, executionId, closePayment, reason, result, onPreparedClosed, controls) {
5732
5949
  if (!closePayment) return result;
5733
- const abandoned = await runIfActive(void 0, CAPXUL_OPERATIONS.moneyExecution.abandonPaymentExecution, () => deps.convexCall.action(deps.functions.abandonPaymentExecution, { input: {
5950
+ const abandoned = await runIfActive(void 0, CAPXUL_OPERATIONS.moneyExecution.abandonPaymentExecution, () => withInvocationParentSpan(Effect.suspend(() => deps.convexCall.action(deps.functions.abandonPaymentExecution, copyInvocationObservation(controls, { input: {
5734
5951
  executionId,
5735
5952
  reason
5736
- } }));
5953
+ } }))), controls), deps.runPromise);
5737
5954
  if (!abandoned.ok) return abandoned;
5738
5955
  if (abandoned.value) onPreparedClosed?.();
5739
5956
  return result;
5740
5957
  }
5741
- async function executePrepared(deps, prepare, isExpectedRequest, closePaymentOnExit, onPreparedClosed, signal) {
5958
+ async function executePrepared(deps, prepare, isExpectedRequest, closePaymentOnExit, onPreparedClosed, signal, controls) {
5742
5959
  if (isAborted$2(signal)) return {
5743
5960
  ok: false,
5744
5961
  error: Errors.cancelled({ operation: "payments" })
@@ -5762,16 +5979,16 @@ async function executePrepared(deps, prepare, isExpectedRequest, closePaymentOnE
5762
5979
  if (!await isExpectedRequest(prepared.value.request)) return abandonPrepared$1(deps, prepared.value.executionId, closePaymentOnExit, "prepared_mismatch", {
5763
5980
  ok: false,
5764
5981
  error: Errors.invalidInput("payment", "prepared command mismatch")
5765
- }, onPreparedClosed);
5982
+ }, onPreparedClosed, controls);
5766
5983
  const expectedSafe = deriveCapxulSafeAddress({ email: session.email });
5767
5984
  if (prepared.value.chainId !== deps.chainId || prepared.value.signerAddress.toLowerCase() !== signerAddress.toLowerCase() || prepared.value.userOpSenderSafe.toLowerCase() !== expectedSafe.toLowerCase()) return abandonPrepared$1(deps, prepared.value.executionId, closePaymentOnExit, "prepared_mismatch", {
5768
5985
  ok: false,
5769
5986
  error: Errors.invalidInput("payment", "prepared authority mismatch")
5770
- }, onPreparedClosed);
5987
+ }, onPreparedClosed, controls);
5771
5988
  if (isAborted$2(signal)) return abandonPrepared$1(deps, prepared.value.executionId, closePaymentOnExit, "cancelled", {
5772
5989
  ok: false,
5773
5990
  error: Errors.cancelled({ operation: "payments" })
5774
- }, onPreparedClosed);
5991
+ }, onPreparedClosed, controls);
5775
5992
  if (prepared.value.emitPaymentInitiated && "items" in prepared.value.request) for (const [index, item] of prepared.value.request.items.entries()) {
5776
5993
  const paymentId = prepared.value.paymentIds[index];
5777
5994
  const recipient = prepared.value.recipientObservations[index];
@@ -5792,28 +6009,28 @@ async function executePrepared(deps, prepare, isExpectedRequest, closePaymentOnE
5792
6009
  return abandonPrepared$1(deps, prepared.value.executionId, closePaymentOnExit, "signer_rejected", {
5793
6010
  ok: false,
5794
6011
  error: signerFailure(deps.signer.source, "signUserOpHash", cause)
5795
- }, onPreparedClosed);
6012
+ }, onPreparedClosed, controls);
5796
6013
  }
5797
6014
  if (isAborted$2(signal)) return abandonPrepared$1(deps, prepared.value.executionId, closePaymentOnExit, "cancelled", {
5798
6015
  ok: false,
5799
6016
  error: Errors.cancelled({ operation: "payments" })
5800
- }, onPreparedClosed);
5801
- return runIfActive(void 0, CAPXUL_OPERATIONS.payments.submitCommandExecution, () => deps.convexCall.action(deps.functions.submitPaymentCommandExecution, { input: {
6017
+ }, onPreparedClosed, controls);
6018
+ return runIfActive(void 0, CAPXUL_OPERATIONS.payments.submitCommandExecution, () => withInvocationParentSpan(Effect.suspend(() => deps.convexCall.action(deps.functions.submitPaymentCommandExecution, copyInvocationObservation(controls, { input: {
5802
6019
  executionId: prepared.value.executionId,
5803
6020
  signature
5804
- } }));
6021
+ } }))), controls), deps.runPromise);
5805
6022
  }
5806
- function executePaymentLifecycle(deps, intent, signal) {
5807
- return executePrepared(deps, (signerAddress) => runIfActive(signal, CAPXUL_OPERATIONS.payments.prepareLifecycleExecution, () => deps.convexCall.action(deps.functions.preparePaymentLifecycleExecution, { input: {
6023
+ function executePaymentLifecycle(deps, intent, signal, controls) {
6024
+ return executePrepared(deps, (signerAddress) => runIfActive(signal, CAPXUL_OPERATIONS.payments.prepareLifecycleExecution, () => withInvocationParentSpan(Effect.suspend(() => deps.convexCall.action(deps.functions.preparePaymentLifecycleExecution, copyInvocationObservation(controls, { input: {
5808
6025
  signerAddress,
5809
6026
  intent
5810
- } })), matchesIntent(intent), false, void 0, signal);
6027
+ } }))), controls), deps.runPromise), matchesIntent(intent), false, void 0, signal, controls);
5811
6028
  }
5812
- function executeOrganizationPayment(deps, input, signal, onPreparedClosed) {
5813
- return executePrepared(deps, (signerAddress) => runIfActive(signal, CAPXUL_OPERATIONS.organizationPayments.prepareExecution, () => deps.convexCall.action(deps.functions.prepareOrganizationPaymentExecution, { input: {
6029
+ function executeOrganizationPayment(deps, input, signal, onPreparedClosed, controls) {
6030
+ return executePrepared(deps, (signerAddress) => runIfActive(signal, CAPXUL_OPERATIONS.organizationPayments.prepareExecution, () => withInvocationParentSpan(Effect.suspend(() => deps.convexCall.action(deps.functions.prepareOrganizationPaymentExecution, copyInvocationObservation(controls, { input: {
5814
6031
  ...input,
5815
6032
  signerAddress
5816
- } })), matchesIntent(input), true, onPreparedClosed, signal);
6033
+ } }))), controls), deps.runPromise), matchesIntent(input), true, onPreparedClosed, signal, controls);
5817
6034
  }
5818
6035
  //#endregion
5819
6036
  //#region src/surface/payment-execution.ts
@@ -6252,51 +6469,52 @@ function makeFinancialOpsMethods(deps) {
6252
6469
  chainId: deps.chainId,
6253
6470
  convexCall: deps.convexCall,
6254
6471
  functions: executionFns,
6255
- signer: deps.signer
6256
- }
6257
- };
6258
- const runLifecycle = async (intent, signal) => {
6259
- const execution = lifecycleDependencies();
6260
- if (!execution.ok) return execution;
6261
- try {
6262
- const submitted = await executePaymentLifecycle(execution.value, intent, signal);
6263
- if (!submitted.ok) return submitted;
6264
- const payments = submitted.value.payments;
6265
- const payment = payments[0];
6266
- if (payment === void 0 || payments.length !== 1) return {
6267
- ok: false,
6268
- error: Errors.unknown()
6269
- };
6270
- return {
6271
- ok: true,
6272
- value: normalizePaymentTiming(payment)
6273
- };
6274
- } catch (cause) {
6275
- return {
6276
- ok: false,
6277
- error: cause instanceof CapxulError ? cause : Errors.unknown(cause)
6278
- };
6279
- }
6280
- };
6281
- const retryPayment = async (paymentId, signal) => {
6282
- const execution = lifecycleDependencies();
6283
- if (!execution.ok) return execution;
6284
- try {
6285
- const submitted = await executePaymentLifecycle(execution.value, {
6286
- kind: "retry",
6287
- paymentId
6288
- }, signal);
6289
- return submitted.ok ? {
6290
- ok: true,
6291
- value: submitted.value.payments.map((payment) => normalizePaymentTiming(payment))
6292
- } : submitted;
6293
- } catch (cause) {
6294
- return {
6295
- ok: false,
6296
- error: cause instanceof CapxulError ? cause : Errors.unknown(cause)
6297
- };
6472
+ signer: deps.signer,
6473
+ ...deps.runPromise === void 0 ? {} : { runPromise: deps.runPromise }
6298
6474
  }
6299
6475
  };
6476
+ const runLifecycle = (intent, controls, operation) => runCapxulEffect(Effect.gen(function* () {
6477
+ const captured = carryInvocationParentSpan(controls, yield* Effect.currentSpan.pipe(Effect.orDie));
6478
+ const result = yield* Effect.tryPromise({
6479
+ try: async () => {
6480
+ const execution = lifecycleDependencies();
6481
+ if (!execution.ok) return execution;
6482
+ const submitted = await executePaymentLifecycle(execution.value, intent, controls?.signal, captured);
6483
+ if (!submitted.ok) return submitted;
6484
+ const payments = submitted.value.payments;
6485
+ const payment = payments[0];
6486
+ if (payment === void 0 || payments.length !== 1) return {
6487
+ ok: false,
6488
+ error: Errors.unknown()
6489
+ };
6490
+ return {
6491
+ ok: true,
6492
+ value: normalizePaymentTiming(payment)
6493
+ };
6494
+ },
6495
+ catch: (cause) => cause instanceof CapxulError ? cause : Errors.unknown(cause)
6496
+ });
6497
+ return yield* result.ok ? Effect.succeed(result.value) : Effect.fail(result.error);
6498
+ }), observationOnlyControls(controls), operation, deps.runPromise);
6499
+ const retryPayment = (paymentId, controls) => runCapxulEffect(Effect.gen(function* () {
6500
+ const captured = carryInvocationParentSpan(controls, yield* Effect.currentSpan.pipe(Effect.orDie));
6501
+ const result = yield* Effect.tryPromise({
6502
+ try: async () => {
6503
+ const execution = lifecycleDependencies();
6504
+ if (!execution.ok) return execution;
6505
+ const submitted = await executePaymentLifecycle(execution.value, {
6506
+ kind: "retry",
6507
+ paymentId
6508
+ }, controls?.signal, captured);
6509
+ return submitted.ok ? {
6510
+ ok: true,
6511
+ value: submitted.value.payments.map((payment) => normalizePaymentTiming(payment))
6512
+ } : submitted;
6513
+ },
6514
+ catch: (cause) => cause instanceof CapxulError ? cause : Errors.unknown(cause)
6515
+ });
6516
+ return yield* result.ok ? Effect.succeed(result.value) : Effect.fail(result.error);
6517
+ }), observationOnlyControls(controls), CAPXUL_OPERATIONS.payments.retry, deps.runPromise);
6300
6518
  return {
6301
6519
  me: {
6302
6520
  get: (options) => runIfActive(options?.signal, CAPXUL_OPERATIONS.me.get, () => deps.convexCall.query(fns.me, {})),
@@ -6348,58 +6566,64 @@ function makeFinancialOpsMethods(deps) {
6348
6566
  },
6349
6567
  payments: {
6350
6568
  pay,
6351
- retry: (paymentId, options) => retryPayment(paymentId, options?.signal),
6569
+ retry: (paymentId, options) => retryPayment(paymentId, deps.invocationControls?.(options) ?? options),
6352
6570
  createCommitment: (input, options) => pay(input, options),
6353
6571
  claim: (paymentId, options) => runLifecycle({
6354
6572
  kind: "claim",
6355
6573
  paymentId
6356
- }, options?.signal),
6574
+ }, deps.invocationControls?.(options) ?? options, CAPXUL_OPERATIONS.payments.claim),
6357
6575
  list: async (options) => mapOk(await runIfActive(options?.signal, CAPXUL_OPERATIONS.payments.list, () => deps.convexCall.query(fns.listPayments, {})), (payments) => payments.map(normalizePaymentTiming)),
6358
6576
  get: async (paymentId, options) => mapOk(await runIfActive(options?.signal, CAPXUL_OPERATIONS.payments.get, () => deps.convexCall.query(fns.getPayment, { paymentId })), (payment) => payment === null ? null : normalizePaymentTiming(payment)),
6359
6577
  cancel: (paymentId, options) => runLifecycle({
6360
6578
  kind: "cancel",
6361
6579
  paymentId
6362
- }, options?.signal),
6580
+ }, deps.invocationControls?.(options) ?? options, CAPXUL_OPERATIONS.payments.cancel),
6363
6581
  redirect: async (input, options) => {
6582
+ const controls = deps.invocationControls?.(options) ?? options;
6364
6583
  const recipient = normalizeTargetForBackend(input.to, "to");
6365
- if (!recipient.ok) return recipient;
6584
+ if (!recipient.ok) return runCapxulEffect(Effect.fail(recipient.error), observationOnlyControls(controls), CAPXUL_OPERATIONS.payments.redirect, deps.runPromise);
6366
6585
  return runLifecycle({
6367
6586
  kind: "redirect",
6368
6587
  paymentId: input.paymentId,
6369
6588
  recipient: recipient.value
6370
- }, options?.signal);
6589
+ }, controls, CAPXUL_OPERATIONS.payments.redirect);
6371
6590
  }
6372
6591
  },
6373
6592
  activity: {
6374
- list: (params, options) => runIfActive(options?.signal, CAPXUL_OPERATIONS.activity.list, () => deps.convexCall.query(fns.activityList, { input: {
6375
- ...activityActorField(params?.actor),
6376
- ...params?.cursor === void 0 ? {} : { cursor: params.cursor },
6377
- ...params?.limit === void 0 ? {} : { limit: params.limit },
6378
- ...params?.range === void 0 ? {} : { range: params.range },
6379
- ...params?.filter === void 0 ? {} : { filter: params.filter }
6380
- } })),
6381
- summary: (params, options) => runIfActive(options?.signal, CAPXUL_OPERATIONS.activity.summary, () => deps.convexCall.query(fns.activitySummary, { input: {
6382
- ...activityActorField(params?.actor),
6383
- ...params?.window === void 0 ? {} : { window: params.window }
6384
- } })),
6593
+ list: (params, options) => {
6594
+ const controls = deps.invocationControls?.(options) ?? options;
6595
+ return runPortEffect(Effect.suspend(() => deps.convexCall.query(fns.activityList, copyInvocationObservation(controls, { input: {
6596
+ ...activityActorField(params?.actor),
6597
+ ...params?.cursor === void 0 ? {} : { cursor: params.cursor },
6598
+ ...params?.limit === void 0 ? {} : { limit: params.limit },
6599
+ ...params?.range === void 0 ? {} : { range: params.range },
6600
+ ...params?.filter === void 0 ? {} : { filter: params.filter }
6601
+ } }))), controls, CAPXUL_OPERATIONS.activity.list, deps.runPromise);
6602
+ },
6603
+ summary: (params, options) => {
6604
+ const controls = deps.invocationControls?.(options) ?? options;
6605
+ return runPortEffect(Effect.suspend(() => deps.convexCall.query(fns.activitySummary, copyInvocationObservation(controls, { input: {
6606
+ ...activityActorField(params?.actor),
6607
+ ...params?.window === void 0 ? {} : { window: params.window }
6608
+ } }))), controls, CAPXUL_OPERATIONS.activity.summary, deps.runPromise);
6609
+ },
6385
6610
  get: (reference, options) => {
6611
+ const controls = deps.invocationControls?.(options) ?? options;
6386
6612
  const actor = actorReferenceToBackend(options?.actor);
6387
- return runIfActive(options?.signal, CAPXUL_OPERATIONS.activity.get, () => deps.convexCall.query(fns.activityGet, {
6613
+ return runPortEffect(Effect.suspend(() => deps.convexCall.query(fns.activityGet, copyInvocationObservation(controls, {
6388
6614
  input: {
6389
6615
  kind: reference.kind,
6390
6616
  id: reference.id,
6391
6617
  ...reference.kind === "payment" ? activityActorField(reference.actor) : {}
6392
6618
  },
6393
6619
  ...actor === void 0 ? {} : { actor }
6394
- }).pipe(Effect.map(normalizeActivityDetail)));
6620
+ }))).pipe(Effect.map(normalizeActivityDetail)), controls, CAPXUL_OPERATIONS.activity.get, deps.runPromise);
6395
6621
  },
6396
6622
  annotate: (input, options) => {
6397
- if (input.actor !== void 0 && input.reference.kind === "payment" && input.reference.actor !== void 0 && !sameActor(input.actor, input.reference.actor)) return Promise.resolve({
6398
- ok: false,
6399
- error: Errors.invalidInput("reference.actor", "must match the annotation actor")
6400
- });
6623
+ const controls = deps.invocationControls?.(options) ?? options;
6624
+ if (input.actor !== void 0 && input.reference.kind === "payment" && input.reference.actor !== void 0 && !sameActor(input.actor, input.reference.actor)) return runCapxulEffect(Effect.fail(Errors.invalidInput("reference.actor", "must match the annotation actor")), controls, CAPXUL_OPERATIONS.activity.annotate, deps.runPromise);
6401
6625
  const referenceActor = input.reference.kind === "payment" ? activityActorField(input.reference.actor).actor : void 0;
6402
- return runIfActive(options?.signal, CAPXUL_OPERATIONS.activity.annotate, () => deps.convexCall.mutation(fns.activityAnnotate, { input: {
6626
+ return runPortEffect(Effect.suspend(() => deps.convexCall.mutation(fns.activityAnnotate, copyInvocationObservation(controls, { input: {
6403
6627
  ...activityActorField(input.actor),
6404
6628
  reference: input.reference.kind === "payment" && referenceActor !== void 0 ? {
6405
6629
  kind: "payment",
@@ -6412,7 +6636,7 @@ function makeFinancialOpsMethods(deps) {
6412
6636
  ...input.counterpartyLabel === void 0 ? {} : { counterpartyLabel: input.counterpartyLabel },
6413
6637
  ...input.accountingCategory === void 0 ? {} : { accountingCategory: input.accountingCategory },
6414
6638
  ...input.memo === void 0 ? {} : { memo: input.memo }
6415
- } }));
6639
+ } }))), controls, CAPXUL_OPERATIONS.activity.annotate, deps.runPromise);
6416
6640
  }
6417
6641
  },
6418
6642
  offramp: {
@@ -6438,8 +6662,14 @@ function makeFinancialOpsMethods(deps) {
6438
6662
  }
6439
6663
  },
6440
6664
  paymentDocuments: {
6441
- verify: (documentHash, options) => runIfActive(options?.signal, CAPXUL_OPERATIONS.paymentDocuments.verify, () => deps.convexCall.query(fns.verifyPaymentDocument, { documentHash })),
6442
- render: (documentHash, options) => runIfActive(options?.signal, CAPXUL_OPERATIONS.paymentDocuments.render, () => deps.convexCall.query(fns.renderStoredDocument, { documentHash }))
6665
+ verify: (documentHash, options) => {
6666
+ const controls = deps.invocationControls?.(options) ?? options;
6667
+ return runPortEffect(Effect.suspend(() => deps.convexCall.query(fns.verifyPaymentDocument, copyInvocationObservation(controls, { documentHash }))), controls, CAPXUL_OPERATIONS.paymentDocuments.verify, deps.runPromise);
6668
+ },
6669
+ render: (documentHash, options) => {
6670
+ const controls = deps.invocationControls?.(options) ?? options;
6671
+ return runPortEffect(Effect.suspend(() => deps.convexCall.query(fns.renderStoredDocument, copyInvocationObservation(controls, { documentHash }))), controls, CAPXUL_OPERATIONS.paymentDocuments.render, deps.runPromise);
6672
+ }
6443
6673
  }
6444
6674
  };
6445
6675
  }
@@ -8336,13 +8566,14 @@ function executionDependencies$1(input) {
8336
8566
  convexCall: input.convexCall,
8337
8567
  functions: moneyExecutionContract,
8338
8568
  signer: input.signer,
8569
+ ...input.runPromise === void 0 ? {} : { runPromise: input.runPromise },
8339
8570
  ...input.telemetry === void 0 ? {} : { telemetry: input.telemetry }
8340
8571
  };
8341
8572
  }
8342
8573
  function makeOrganizationPaymentsMethods(deps, orgId) {
8343
8574
  const requestKeyScope = deps.requestKeyScope ?? `client-${crypto.randomUUID()}`;
8344
8575
  const inFlightOrganizationPayments = /* @__PURE__ */ new Map();
8345
- const execute = async (input, signal, operation = "organization-pay-batch") => {
8576
+ const execute = async (input, signal, operation = "organization-pay-batch", controls) => {
8346
8577
  if (signal?.aborted === true) return {
8347
8578
  ok: false,
8348
8579
  error: Errors.cancelled({ operation })
@@ -8375,7 +8606,7 @@ function makeOrganizationPaymentsMethods(deps, orgId) {
8375
8606
  requestKey: requestKey.key,
8376
8607
  items: input.items,
8377
8608
  ...input.lineage === void 0 ? {} : { lineage: input.lineage }
8378
- }, controller.signal, () => requestState.resolved = true);
8609
+ }, controller.signal, () => requestState.resolved = true, controls);
8379
8610
  flight = {
8380
8611
  controller,
8381
8612
  promise: submission,
@@ -8424,41 +8655,73 @@ function makeOrganizationPaymentsMethods(deps, orgId) {
8424
8655
  return normalized;
8425
8656
  };
8426
8657
  return {
8427
- retry: async (paymentId, options) => {
8428
- const execution = executionDependencies$1(deps);
8429
- if (execution === null) return {
8430
- ok: false,
8431
- error: Errors.notImplemented("organizationPayments", "executionComposition")
8432
- };
8433
- const result = await executePaymentLifecycle(execution, {
8434
- kind: "retry",
8435
- paymentId
8436
- }, options?.signal);
8437
- if (!result.ok) return result;
8438
- return {
8439
- ok: true,
8440
- value: result.value.payments.map((payment) => normalizePaymentTiming(payment))
8441
- };
8658
+ retry: (paymentId, options) => {
8659
+ const controls = deps.invocationControls?.(options) ?? options;
8660
+ return runCapxulEffect(Effect.gen(function* () {
8661
+ const parent = yield* Effect.currentSpan.pipe(Effect.orDie);
8662
+ const captured = carryInvocationParentSpan(controls, parent);
8663
+ const completed = yield* Effect.tryPromise({
8664
+ try: async () => {
8665
+ const execution = executionDependencies$1(deps);
8666
+ if (execution === null) return {
8667
+ ok: false,
8668
+ error: Errors.notImplemented("organizationPayments", "executionComposition")
8669
+ };
8670
+ const result = await executePaymentLifecycle(execution, {
8671
+ kind: "retry",
8672
+ paymentId
8673
+ }, controls?.signal, captured);
8674
+ if (!result.ok) return result;
8675
+ return {
8676
+ ok: true,
8677
+ value: result.value.payments.map((payment) => normalizePaymentTiming(payment))
8678
+ };
8679
+ },
8680
+ catch: (cause) => cause instanceof CapxulError ? cause : Errors.unknown(cause)
8681
+ });
8682
+ return yield* completed.ok ? Effect.succeed(completed.value) : Effect.fail(completed.error);
8683
+ }), observationOnlyControls(controls), CAPXUL_OPERATIONS.organizationPayments.retry, deps.runPromise);
8442
8684
  },
8443
- pay: async (input, options) => {
8444
- const { permissionId, requestKey: providedRequestKey, lineage, ...item } = input;
8445
- const result = await execute({
8446
- permissionId,
8447
- ...providedRequestKey === void 0 ? {} : { requestKey: providedRequestKey },
8448
- items: [item],
8449
- ...lineage === void 0 ? {} : { lineage }
8450
- }, options?.signal, "organization-pay");
8451
- if (!result.ok) return result;
8452
- const payment = result.value[0];
8453
- return payment === void 0 ? {
8454
- ok: false,
8455
- error: Errors.unknown()
8456
- } : {
8457
- ok: true,
8458
- value: payment
8459
- };
8685
+ pay: (input, options) => {
8686
+ const controls = deps.invocationControls?.(options) ?? options;
8687
+ return runCapxulEffect(Effect.gen(function* () {
8688
+ const parent = yield* Effect.currentSpan.pipe(Effect.orDie);
8689
+ const captured = carryInvocationParentSpan(controls, parent);
8690
+ const completed = yield* Effect.tryPromise({
8691
+ try: async () => {
8692
+ const { permissionId, requestKey: providedRequestKey, lineage, ...item } = input;
8693
+ const result = await execute({
8694
+ permissionId,
8695
+ ...providedRequestKey === void 0 ? {} : { requestKey: providedRequestKey },
8696
+ items: [item],
8697
+ ...lineage === void 0 ? {} : { lineage }
8698
+ }, controls?.signal, "organization-pay", captured);
8699
+ if (!result.ok) return result;
8700
+ const payment = result.value[0];
8701
+ return payment === void 0 ? {
8702
+ ok: false,
8703
+ error: Errors.unknown()
8704
+ } : {
8705
+ ok: true,
8706
+ value: payment
8707
+ };
8708
+ },
8709
+ catch: (cause) => cause instanceof CapxulError ? cause : Errors.unknown(cause)
8710
+ });
8711
+ return yield* completed.ok ? Effect.succeed(completed.value) : Effect.fail(completed.error);
8712
+ }), observationOnlyControls(controls), CAPXUL_OPERATIONS.organizationPayments.pay, deps.runPromise);
8460
8713
  },
8461
- payBatch: (input, options) => execute(input, options?.signal)
8714
+ payBatch: (input, options) => {
8715
+ const controls = deps.invocationControls?.(options) ?? options;
8716
+ return runCapxulEffect(Effect.gen(function* () {
8717
+ const parent = yield* Effect.currentSpan.pipe(Effect.orDie);
8718
+ const completed = yield* Effect.tryPromise({
8719
+ try: () => execute(input, controls?.signal, void 0, carryInvocationParentSpan(controls, parent)),
8720
+ catch: (cause) => cause instanceof CapxulError ? cause : Errors.unknown(cause)
8721
+ });
8722
+ return yield* completed.ok ? Effect.succeed(completed.value) : Effect.fail(completed.error);
8723
+ }), observationOnlyControls(controls), CAPXUL_OPERATIONS.organizationPayments.payBatch, deps.runPromise);
8724
+ }
8462
8725
  };
8463
8726
  }
8464
8727
  //#endregion
@@ -8555,12 +8818,14 @@ function executionDependencies(deps) {
8555
8818
  chainId: deps.chainId,
8556
8819
  convexCall: deps.convexCall,
8557
8820
  functions: moneyExecutionContract,
8821
+ ...deps.runPromise === void 0 ? {} : { runPromise: deps.runPromise },
8558
8822
  signer: deps.signer
8559
8823
  };
8560
8824
  }
8561
8825
  function makePayrollMethods(deps, orgId) {
8562
8826
  const requestKeyScope = deps.requestKeyScope ?? `client-${crypto.randomUUID()}`;
8563
- async function authorize(input, signal) {
8827
+ async function authorize(input, controls) {
8828
+ const signal = controls?.signal;
8564
8829
  const execution = executionDependencies(deps);
8565
8830
  if (execution === null) return {
8566
8831
  ok: false,
@@ -8573,14 +8838,14 @@ function makePayrollMethods(deps, orgId) {
8573
8838
  let authorized;
8574
8839
  let preparedClosed = false;
8575
8840
  const submitted = await executePrepared(execution, async (signerAddress) => {
8576
- const prepared = await runIfActive(signal, AUTHORIZE_RUN, () => deps.convexCall.action(payrollContract.authorizeRun, { input: {
8841
+ const prepared = await runIfActive(signal, AUTHORIZE_RUN, () => withInvocationParentSpan(Effect.suspend(() => deps.convexCall.action(payrollContract.authorizeRun, copyInvocationObservation(controls, { input: {
8577
8842
  orgId,
8578
8843
  permissionId: input.permissionId,
8579
8844
  requestKey: requestKey.key,
8580
8845
  signerAddress,
8581
8846
  period: input.period,
8582
8847
  items: input.items
8583
- } }));
8848
+ } }))), controls), deps.runPromise);
8584
8849
  if (!prepared.ok) return prepared;
8585
8850
  authorized = prepared.value.run;
8586
8851
  return {
@@ -8593,7 +8858,7 @@ function makePayrollMethods(deps, orgId) {
8593
8858
  requestKey: requestKey.key,
8594
8859
  runId: authorized.id,
8595
8860
  items: input.items
8596
- })(request), true, () => preparedClosed = true, signal);
8861
+ })(request), true, () => preparedClosed = true, signal, controls);
8597
8862
  try {
8598
8863
  await requestKey.finish(submitted.ok || preparedClosed);
8599
8864
  } catch {}
@@ -8607,35 +8872,48 @@ function makePayrollMethods(deps, orgId) {
8607
8872
  };
8608
8873
  }
8609
8874
  return {
8610
- runs: (options) => runIfActive(options?.signal, CAPXUL_OPERATIONS.payroll.runs, () => Effect.map(deps.convexCall.query(payrollContract.runs, { orgId }), toPayrollRuns)),
8611
- authorizeRun: async (input, options) => {
8612
- if (options?.signal?.aborted === true) return {
8613
- ok: false,
8614
- error: Errors.cancelled({ operation: AUTHORIZE_RUN })
8615
- };
8616
- try {
8617
- return await authorize(input, options?.signal);
8618
- } catch (cause) {
8619
- return {
8620
- ok: false,
8621
- error: cause instanceof CapxulError ? cause : Errors.unknown(cause)
8622
- };
8623
- }
8875
+ runs: (options) => {
8876
+ const controls = deps.invocationControls?.(options) ?? options;
8877
+ return runPortEffect(Effect.suspend(() => deps.convexCall.query(payrollContract.runs, copyInvocationObservation(controls, { orgId }))).pipe(Effect.map(toPayrollRuns)), controls, CAPXUL_OPERATIONS.payroll.runs, deps.runPromise);
8878
+ },
8879
+ authorizeRun: (input, options) => {
8880
+ const controls = deps.invocationControls?.(options) ?? options;
8881
+ return runCapxulEffect(Effect.gen(function* () {
8882
+ if (controls?.signal?.aborted === true) return yield* Effect.fail(Errors.cancelled({ operation: AUTHORIZE_RUN }));
8883
+ const parent = yield* Effect.currentSpan.pipe(Effect.orDie);
8884
+ const result = yield* Effect.tryPromise({
8885
+ try: () => authorize(input, carryInvocationParentSpan(controls, parent)),
8886
+ catch: (cause) => cause instanceof CapxulError ? cause : Errors.unknown(cause)
8887
+ });
8888
+ return yield* result.ok ? Effect.succeed(result.value) : Effect.fail(result.error);
8889
+ }), observationOnlyControls(controls), AUTHORIZE_RUN, deps.runPromise);
8890
+ },
8891
+ terms: (options) => {
8892
+ const controls = deps.invocationControls?.(options) ?? options;
8893
+ return runPortEffect(Effect.suspend(() => deps.convexCall.query(payrollContract.terms, copyInvocationObservation(controls, { orgId }))), controls, CAPXUL_OPERATIONS.payroll.terms, deps.runPromise);
8624
8894
  },
8625
- terms: (options) => runIfActive(options?.signal, CAPXUL_OPERATIONS.payroll.terms, () => deps.convexCall.query(payrollContract.terms, { orgId })),
8626
8895
  groups: {
8627
- list: (options) => runIfActive(options?.signal, CAPXUL_OPERATIONS.payroll.groups.list, () => Effect.map(deps.convexCall.query(payrollContract.groups, { orgId }), (groups) => groups.map(toPayrollGroup))),
8628
- save: (input, options) => runIfActive(options?.signal, CAPXUL_OPERATIONS.payroll.groups.save, () => Effect.map(deps.convexCall.mutation(payrollContract.saveGroup, {
8629
- orgId,
8630
- ...input.id === void 0 ? {} : { id: String(input.id) },
8631
- name: input.name,
8632
- tone: input.tone,
8633
- members: input.members
8634
- }), toPayrollGroup)),
8635
- remove: (id, options) => runIfActive(options?.signal, CAPXUL_OPERATIONS.payroll.groups.remove, () => Effect.map(deps.convexCall.mutation(payrollContract.removeGroup, {
8636
- orgId,
8637
- id
8638
- }), () => void 0))
8896
+ list: (options) => {
8897
+ const controls = deps.invocationControls?.(options) ?? options;
8898
+ return runPortEffect(Effect.suspend(() => deps.convexCall.query(payrollContract.groups, copyInvocationObservation(controls, { orgId }))).pipe(Effect.map((groups) => groups.map(toPayrollGroup))), controls, CAPXUL_OPERATIONS.payroll.groups.list, deps.runPromise);
8899
+ },
8900
+ save: (input, options) => {
8901
+ const controls = deps.invocationControls?.(options) ?? options;
8902
+ return runPortEffect(Effect.suspend(() => deps.convexCall.mutation(payrollContract.saveGroup, copyInvocationObservation(controls, {
8903
+ orgId,
8904
+ ...input.id === void 0 ? {} : { id: String(input.id) },
8905
+ name: input.name,
8906
+ tone: input.tone,
8907
+ members: input.members
8908
+ }))).pipe(Effect.map(toPayrollGroup)), controls, CAPXUL_OPERATIONS.payroll.groups.save, deps.runPromise);
8909
+ },
8910
+ remove: (id, options) => {
8911
+ const controls = deps.invocationControls?.(options) ?? options;
8912
+ return runPortEffect(Effect.suspend(() => deps.convexCall.mutation(payrollContract.removeGroup, copyInvocationObservation(controls, {
8913
+ orgId,
8914
+ id
8915
+ }))).pipe(Effect.asVoid), controls, CAPXUL_OPERATIONS.payroll.groups.remove, deps.runPromise);
8916
+ }
8639
8917
  }
8640
8918
  };
8641
8919
  }
@@ -9084,6 +9362,8 @@ function makeOrgMethods(deps) {
9084
9362
  const convexCall = deps.convexCall;
9085
9363
  return {
9086
9364
  ...makeActorRelationshipMethods({
9365
+ ...deps.runPromise === void 0 ? {} : { runPromise: deps.runPromise },
9366
+ ...deps.invocationControls === void 0 ? {} : { invocationControls: deps.invocationControls },
9087
9367
  actor: {
9088
9368
  kind: "org",
9089
9369
  orgId: String(orgId)
@@ -9213,6 +9493,8 @@ function makeOrgMethods(deps) {
9213
9493
  }, String(orgId)),
9214
9494
  payments: convexCall === void 0 ? makeNotImplementedOrganizationPaymentsMethods() : makeOrganizationPaymentsMethods({
9215
9495
  convexCall,
9496
+ ...deps.runPromise === void 0 ? {} : { runPromise: deps.runPromise },
9497
+ ...deps.invocationControls === void 0 ? {} : { invocationControls: deps.invocationControls },
9216
9498
  ...deps.requestKeyScope === void 0 ? {} : { requestKeyScope: deps.requestKeyScope },
9217
9499
  ...deps.actor === void 0 ? {} : { actor: deps.actor },
9218
9500
  ...deps.chainId === void 0 ? {} : { chainId: Number(deps.chainId) },
@@ -9221,6 +9503,8 @@ function makeOrgMethods(deps) {
9221
9503
  }, String(orgId)),
9222
9504
  payroll: convexCall === void 0 ? makeUnavailablePayrollMethods() : makePayrollMethods({
9223
9505
  convexCall,
9506
+ ...deps.runPromise === void 0 ? {} : { runPromise: deps.runPromise },
9507
+ ...deps.invocationControls === void 0 ? {} : { invocationControls: deps.invocationControls },
9224
9508
  ...deps.requestKeyScope === void 0 ? {} : { requestKeyScope: deps.requestKeyScope },
9225
9509
  ...deps.actor === void 0 ? {} : { actor: deps.actor },
9226
9510
  ...deps.chainId === void 0 ? {} : { chainId: Number(deps.chainId) },
@@ -9522,6 +9806,8 @@ function assembleCapxulClient(input) {
9522
9806
  let detectPendingOrgInvitations;
9523
9807
  let kickProvisioning;
9524
9808
  const financialOps = makeFinancialOpsMethods({
9809
+ runPromise: effectRunner.runPromise,
9810
+ invocationControls: (controls) => withHostObservationControls(observation.hostObservationSnapshot, controls, actor.authSession()?.authUserId),
9525
9811
  actor,
9526
9812
  chainId: input.bootstrap.chainId,
9527
9813
  convexCall: input.ports.convexCall,
@@ -9541,7 +9827,7 @@ function assembleCapxulClient(input) {
9541
9827
  profileMethods: financialOps.me,
9542
9828
  convexCall: input.ports.convexCall,
9543
9829
  runPromise: effectRunner.runPromise,
9544
- invocationControls: (controls) => withHostObservationControls(observation.hostObservationSnapshot, controls),
9830
+ invocationControls: (controls) => withHostObservationControls(observation.hostObservationSnapshot, controls, actor.authSession()?.authUserId),
9545
9831
  ...input.signer === void 0 ? {} : { signer: input.signer }
9546
9832
  });
9547
9833
  kickProvisioning = accountBundle.kickProvisioning;
@@ -9594,21 +9880,21 @@ function assembleCapxulClient(input) {
9594
9880
  convexCall: input.ports.convexCall,
9595
9881
  telemetry: input.ports.telemetry,
9596
9882
  runPromise: effectRunner.runPromise,
9597
- invocationControls: (controls) => withHostObservationControls(observation.hostObservationSnapshot, controls)
9883
+ invocationControls: (controls) => withHostObservationControls(observation.hostObservationSnapshot, controls, actor.authSession()?.authUserId)
9598
9884
  });
9599
9885
  const accounts = makeAccountsMethods({
9600
9886
  accountReadPort: input.ports.accountRead,
9601
9887
  chainId: input.bootstrap.chainId,
9602
9888
  telemetry: input.ports.telemetry,
9603
9889
  runPromise: effectRunner.runPromise,
9604
- invocationControls: (controls) => withHostObservationControls(observation.hostObservationSnapshot, controls)
9890
+ invocationControls: (controls) => withHostObservationControls(observation.hostObservationSnapshot, controls, actor.authSession()?.authUserId)
9605
9891
  });
9606
9892
  const orgMethods = makeOrgMethods({
9607
9893
  actor,
9608
9894
  chainId: input.bootstrap.chainId,
9609
9895
  telemetry: input.ports.telemetry,
9610
9896
  runPromise: effectRunner.runPromise,
9611
- invocationControls: (controls) => withHostObservationControls(observation.hostObservationSnapshot, controls),
9897
+ invocationControls: (controls) => withHostObservationControls(observation.hostObservationSnapshot, controls, actor.authSession()?.authUserId),
9612
9898
  requestKeyScope: `${input.bootstrap.convexUrl}:${String(input.bootstrap.chainId)}`,
9613
9899
  ...selectedOrgPort === void 0 ? {} : { orgPort: selectedOrgPort },
9614
9900
  convexCall: input.ports.convexCall,
@@ -9759,7 +10045,7 @@ function transitionError(record) {
9759
10045
  }
9760
10046
  function withHostObservation(actor, snapshot) {
9761
10047
  if (snapshot === void 0) return actor;
9762
- const controls = (input) => withHostObservationControls(snapshot, input);
10048
+ const controls = (input) => withHostObservationControls(snapshot, input, actor.authSession()?.authUserId);
9763
10049
  return {
9764
10050
  ...actor,
9765
10051
  ask: (event, input) => actor.ask(event, controls(input)),
@@ -9767,10 +10053,14 @@ function withHostObservation(actor, snapshot) {
9767
10053
  restoreAuthSession: (session, input) => actor.restoreAuthSession(session, controls(input))
9768
10054
  };
9769
10055
  }
9770
- function withHostObservationControls(snapshot, input) {
9771
- const copied = { ...input };
9772
- const captured = snapshot?.();
9773
- return captured === void 0 ? copied : attachInvocationObservation(copied, captured);
10056
+ function withHostObservationControls(snapshot, input, actorId) {
10057
+ const previous = readInvocationObservation(input);
10058
+ if (previous !== void 0) return attachInvocationObservation({ ...input }, previous);
10059
+ const captured = snapshot?.() ?? { active: true };
10060
+ return attachInvocationObservation({ ...input }, {
10061
+ ...captured,
10062
+ ...actorId === void 0 ? {} : { actorId }
10063
+ });
9774
10064
  }
9775
10065
  //#endregion
9776
10066
  export { stampTelemetryEnvelope as $, safeExceptionLabel as A, resolveFailureMode as B, observeFailedResult as C, normalizeExceptionErrorKind as D, SDK_VERSION as E, causeChain as F, sanitizeObservationContext as G, readInvocationObservation as H, injectedWalletSigner as I, CAPXUL_FUNCTIONS as J, PAYMENT_DIRECTIONS as K, isSignerNotReadySignal as L, fromWei as M, isSettingUpLifecycle as N, normalizeExceptionOperation as O, formatTraceparent as P, redactTelemetryProps as Q, openfortSignerNotReadyCode as R, observationContextProps as S, EXCEPTION_MESSAGE as T, OBSERVATION_CONTEXT_HEADER as U, copyInvocationObservation as V, encodeObservationContextHeader as W, EngineeringTelemetryBootstrapPolicy as X, BootstrapEnvelope as Y, redactTelemetryEvent as Z, fingerprintPaymentIntent as _, AccountReadPortTag as a, isRestoring as at, failureDetail as b, retryIdempotentRead as c, IdentityPortTag as d, CAPXUL_OPERATIONS as et, identityErrorFromCapxul as f, bootstrapErrorFromCapxul as g, BootstrapPortTag as h, smartAccountErrorFromCapxul as i, isClaimed as it, version as j, projectSdkException as k, PRODUCT_INVOCATION as l, convexCallErrorFromCapxul as m, detectAuthCacheAdapter as n, normalizeCapxulOperation as nt, accountReadErrorFromCapxul as o, ConvexCallPortTag as p, PAYMENT_STATUSES as q, SmartAccountPortTag as r, destination as rt, TelemetryPortTag as s, assembleCapxulClient as t, isCapxulOperation as tt, wireChainId as u, toWei as v, postHogFailureObservation as w, failureEvidenceProps as x, CAPXUL_SDK_EXPECTED_OUTCOME_EVENT as y, signerFailure as z };