@capxul/mcp 2.5.2 → 2.5.4

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 (2) hide show
  1. package/dist/main.mjs +296 -87
  2. package/package.json +3 -3
package/dist/main.mjs CHANGED
@@ -240,7 +240,7 @@ function normalizeEmail(email) {
240
240
  }
241
241
  //#endregion
242
242
  //#region package.json
243
- var version$2 = "2.5.2";
243
+ var version$2 = "2.5.4";
244
244
  //#endregion
245
245
  //#region ../../packages/errors/src/errors.ts
246
246
  const CAPXUL_ERROR_CODES = [
@@ -7757,73 +7757,8 @@ function isMoneyTelemetryDebugEnabled() {
7757
7757
  return globalThis.process?.env?.CAPXUL_DEBUG_TELEMETRY === "1";
7758
7758
  }
7759
7759
  //#endregion
7760
- //#region ../../packages/sdk/src/surface/payment-execution.ts
7761
- function mismatch(field, message) {
7762
- return {
7763
- ok: false,
7764
- error: Errors.invalidInput(field, message)
7765
- };
7766
- }
7767
- function cancelled(operation) {
7768
- return {
7769
- ok: false,
7770
- error: Errors.cancelled({ operation })
7771
- };
7772
- }
7773
- function isAborted$2(signal) {
7774
- return signal?.aborted === true;
7775
- }
7776
- async function signerCall(source, operation, run) {
7777
- try {
7778
- return {
7779
- ok: true,
7780
- value: await run()
7781
- };
7782
- } catch (cause) {
7783
- return {
7784
- ok: false,
7785
- error: signerFailure(source, operation, cause)
7786
- };
7787
- }
7788
- }
7789
- async function executePersonalPayment(deps, payment, signal, requestKey) {
7790
- if (isAborted$2(signal)) return cancelled("payments.pay");
7791
- if (deps.signer === void 0) return mismatch("signer", "payments.pay requires a configured CapxulSigner");
7792
- const session = deps.actor.authSession();
7793
- if (session === null) return {
7794
- ok: false,
7795
- error: Errors.notAuthenticated()
7796
- };
7797
- const signerAddress = await signerCall(deps.signer.source, "getAddress", () => deps.signer.getAddress());
7798
- if (!signerAddress.ok) return signerAddress;
7799
- const expectedSafe = deriveCapxulSafeAddress({ email: session.email });
7800
- const resolvedRequestKey = requestKey ?? `pay_${crypto.randomUUID()}`;
7801
- const prepared = await runIfActive(signal, "payments.prepareExecution", () => deps.convexCall.action(deps.functions.preparePaymentExecution, { input: {
7802
- requestKey: resolvedRequestKey,
7803
- signerAddress: signerAddress.value,
7804
- payment
7805
- } }));
7806
- if (!prepared.ok) return prepared;
7807
- if (prepared.value.requestKey !== resolvedRequestKey || JSON.stringify(prepared.value.payment) !== JSON.stringify(payment)) return mismatch("payment", "prepared Payment execution uses another request");
7808
- if (prepared.value.chainId !== deps.chainId) return mismatch("chainId", "prepared Payment execution uses another chain");
7809
- if (prepared.value.signerAddress.toLowerCase() !== signerAddress.value.toLowerCase()) return mismatch("signerAddress", "prepared Payment execution uses another signer");
7810
- if (prepared.value.userOpSenderSafe.toLowerCase() !== expectedSafe.toLowerCase()) return mismatch("userOpSenderSafe", "prepared Payment execution uses another Account Safe");
7811
- if (prepared.value.emitPaymentInitiated) await emitPaymentInitiated(deps.telemetry, {
7812
- kind: prepared.value.purposeKind,
7813
- paymentId: prepared.value.paymentId
7814
- });
7815
- if (isAborted$2(signal)) return cancelled("payments.pay");
7816
- const signature = await signerCall(deps.signer.source, "signUserOpHash", () => deps.signer.signUserOpHash(prepared.value.digest));
7817
- if (!signature.ok) return signature;
7818
- if (isAborted$2(signal)) return cancelled("payments.pay");
7819
- return runIfActive(void 0, "payments.submitExecution", () => deps.convexCall.action(deps.functions.submitPaymentExecution, { input: {
7820
- executionId: prepared.value.executionId,
7821
- signature: signature.value
7822
- } }));
7823
- }
7824
- //#endregion
7825
7760
  //#region ../../packages/sdk/src/surface/payment-command-execution.ts
7826
- function isAborted$1(signal) {
7761
+ function isAborted$2(signal) {
7827
7762
  return signal?.aborted === true;
7828
7763
  }
7829
7764
  function canonicalJson(value) {
@@ -7839,7 +7774,7 @@ function matchesIntent(expected) {
7839
7774
  return async (request) => await fingerprintPaymentIntent(request) === await fingerprintPaymentIntent(expected);
7840
7775
  }
7841
7776
  async function executePrepared(deps, prepare, isExpectedRequest, signal) {
7842
- if (isAborted$1(signal)) return {
7777
+ if (isAborted$2(signal)) return {
7843
7778
  ok: false,
7844
7779
  error: Errors.cancelled({ operation: "payments" })
7845
7780
  };
@@ -7868,7 +7803,7 @@ async function executePrepared(deps, prepare, isExpectedRequest, signal) {
7868
7803
  ok: false,
7869
7804
  error: Errors.invalidInput("payment", "prepared authority mismatch")
7870
7805
  };
7871
- if (isAborted$1(signal)) return {
7806
+ if (isAborted$2(signal)) return {
7872
7807
  ok: false,
7873
7808
  error: Errors.cancelled({ operation: "payments" })
7874
7809
  };
@@ -7881,7 +7816,7 @@ async function executePrepared(deps, prepare, isExpectedRequest, signal) {
7881
7816
  error: signerFailure(deps.signer.source, "signUserOpHash", cause)
7882
7817
  };
7883
7818
  }
7884
- if (isAborted$1(signal)) return {
7819
+ if (isAborted$2(signal)) return {
7885
7820
  ok: false,
7886
7821
  error: Errors.cancelled({ operation: "payments" })
7887
7822
  };
@@ -7903,6 +7838,71 @@ function executeOrganizationPayment(deps, input, signal) {
7903
7838
  } })), matchesIntent(input), signal);
7904
7839
  }
7905
7840
  //#endregion
7841
+ //#region ../../packages/sdk/src/surface/payment-execution.ts
7842
+ function mismatch(field, message) {
7843
+ return {
7844
+ ok: false,
7845
+ error: Errors.invalidInput(field, message)
7846
+ };
7847
+ }
7848
+ function cancelled(operation) {
7849
+ return {
7850
+ ok: false,
7851
+ error: Errors.cancelled({ operation })
7852
+ };
7853
+ }
7854
+ function isAborted$1(signal) {
7855
+ return signal?.aborted === true;
7856
+ }
7857
+ async function signerCall(source, operation, run) {
7858
+ try {
7859
+ return {
7860
+ ok: true,
7861
+ value: await run()
7862
+ };
7863
+ } catch (cause) {
7864
+ return {
7865
+ ok: false,
7866
+ error: signerFailure(source, operation, cause)
7867
+ };
7868
+ }
7869
+ }
7870
+ async function executePersonalPayment(deps, payment, signal, requestKey) {
7871
+ if (isAborted$1(signal)) return cancelled("payments.pay");
7872
+ if (deps.signer === void 0) return mismatch("signer", "payments.pay requires a configured CapxulSigner");
7873
+ const session = deps.actor.authSession();
7874
+ if (session === null) return {
7875
+ ok: false,
7876
+ error: Errors.notAuthenticated()
7877
+ };
7878
+ const signerAddress = await signerCall(deps.signer.source, "getAddress", () => deps.signer.getAddress());
7879
+ if (!signerAddress.ok) return signerAddress;
7880
+ const expectedSafe = deriveCapxulSafeAddress({ email: session.email });
7881
+ const resolvedRequestKey = requestKey ?? `pay_${crypto.randomUUID()}`;
7882
+ const prepared = await runIfActive(signal, "payments.prepareExecution", () => deps.convexCall.action(deps.functions.preparePaymentExecution, { input: {
7883
+ requestKey: resolvedRequestKey,
7884
+ signerAddress: signerAddress.value,
7885
+ payment
7886
+ } }));
7887
+ if (!prepared.ok) return prepared;
7888
+ if (prepared.value.requestKey !== resolvedRequestKey || canonicalJson(prepared.value.payment) !== canonicalJson(payment)) return mismatch("payment", "prepared Payment execution uses another request");
7889
+ if (prepared.value.chainId !== deps.chainId) return mismatch("chainId", "prepared Payment execution uses another chain");
7890
+ if (prepared.value.signerAddress.toLowerCase() !== signerAddress.value.toLowerCase()) return mismatch("signerAddress", "prepared Payment execution uses another signer");
7891
+ if (prepared.value.userOpSenderSafe.toLowerCase() !== expectedSafe.toLowerCase()) return mismatch("userOpSenderSafe", "prepared Payment execution uses another Account Safe");
7892
+ if (prepared.value.emitPaymentInitiated) await emitPaymentInitiated(deps.telemetry, {
7893
+ kind: prepared.value.purposeKind,
7894
+ paymentId: prepared.value.paymentId
7895
+ });
7896
+ if (isAborted$1(signal)) return cancelled("payments.pay");
7897
+ const signature = await signerCall(deps.signer.source, "signUserOpHash", () => deps.signer.signUserOpHash(prepared.value.digest));
7898
+ if (!signature.ok) return signature;
7899
+ if (isAborted$1(signal)) return cancelled("payments.pay");
7900
+ return runIfActive(void 0, "payments.submitExecution", () => deps.convexCall.action(deps.functions.submitPaymentExecution, { input: {
7901
+ executionId: prepared.value.executionId,
7902
+ signature: signature.value
7903
+ } }));
7904
+ }
7905
+ //#endregion
7906
7906
  //#region ../../packages/sdk/src/surface/money.ts
7907
7907
  function actorReferenceToBackend(actor) {
7908
7908
  if (actor === void 0) return void 0;
@@ -8912,7 +8912,7 @@ async function recoverRawDigestSigner(input) {
8912
8912
  }
8913
8913
  //#endregion
8914
8914
  //#region ../../packages/sdk/package.json
8915
- var version = "2.5.2";
8915
+ var version = "2.5.4";
8916
8916
  //#endregion
8917
8917
  //#region ../../packages/observability/src/engineering.ts
8918
8918
  const ENGINEERING_CAPXUL_ENVS = [
@@ -13622,7 +13622,8 @@ var ConvexOrganizationSetupAdapter = class {
13622
13622
  confirmSubmittedBootstrap(input) {
13623
13623
  return this.#lifecycleAction("confirmBootstrap", input, () => this.#convex.action(this.#fns.confirmBootstrap, copyInvocationObservation(input, {
13624
13624
  orgId: input.orgId,
13625
- ...input.observationContext === void 0 ? {} : { observationContext: input.observationContext }
13625
+ ...input.observationContext === void 0 ? {} : { observationContext: input.observationContext },
13626
+ ...input.retryDelayMs === void 0 ? {} : { retryDelayMs: input.retryDelayMs }
13626
13627
  })));
13627
13628
  }
13628
13629
  async recordFailure(input) {
@@ -13941,6 +13942,28 @@ const FaucetFailedProps = Schema.Struct({
13941
13942
  ...TelemetryEnvelopeProps,
13942
13943
  reason: OptionalString
13943
13944
  });
13945
+ const AaGatewayUpstreamFallbackProps = Schema.Struct({
13946
+ ...TelemetryEnvelopeProps,
13947
+ method: Schema.String,
13948
+ from_upstream: Schema.Literals([
13949
+ "alchemy",
13950
+ "infura",
13951
+ "public"
13952
+ ]),
13953
+ to_upstream: Schema.optional(Schema.Literals([
13954
+ "alchemy",
13955
+ "infura",
13956
+ "public"
13957
+ ])),
13958
+ failure: Schema.Literals([
13959
+ "http-429",
13960
+ "http-5xx",
13961
+ "rpc-rate-limit",
13962
+ "timeout",
13963
+ "network"
13964
+ ]),
13965
+ status: Schema.optional(Schema.Number)
13966
+ });
13944
13967
  const ORG_ID_TELEMETRY_RE = /^org_[0-9A-Za-z]+$/;
13945
13968
  const OrgIdTelemetrySchema = Schema.String.pipe(Schema.refine((value) => ORG_ID_TELEMETRY_RE.test(value), { message: "must be org_ plus an alphanumeric id" }));
13946
13969
  const OptionalOrgId = Schema.optional(OrgIdTelemetrySchema);
@@ -13991,6 +14014,8 @@ const OrganizationCreationFailedProps = Schema.Struct({
13991
14014
  stage: OnboardingStageSchema,
13992
14015
  error_code: Schema.String,
13993
14016
  retryable: Schema.Boolean,
14017
+ /** #1655: the SDK's backoff before this attempt. Absent on the first attempt. */
14018
+ backoff_ms: Schema.optional(DurationMsSchema),
13994
14019
  failure_reason: Schema.optional(Schema.Literals([
13995
14020
  "deterministic_address_mismatch",
13996
14021
  "receipt_provider_unavailable",
@@ -14241,6 +14266,10 @@ Schema.Struct({
14241
14266
  name: Schema.Literal("faucet_failed"),
14242
14267
  props: FaucetFailedProps
14243
14268
  });
14269
+ Schema.Struct({
14270
+ name: Schema.Literal("aa_gateway_upstream_fallback"),
14271
+ props: AaGatewayUpstreamFallbackProps
14272
+ });
14244
14273
  Schema.Struct({
14245
14274
  name: Schema.Literal("org_create_started"),
14246
14275
  props: OrgCreateStartedProps
@@ -37456,6 +37485,7 @@ function createOpenfortBrowserSignerFromBootstrap(bootstrap, options = {}) {
37456
37485
  return {
37457
37486
  ...signer,
37458
37487
  statusStore,
37488
+ ensureWalletReady: ensureOpenfortWalletReady,
37459
37489
  getAddress: async () => {
37460
37490
  try {
37461
37491
  const address = await signer.getAddress();
@@ -37524,6 +37554,29 @@ const IDENTITY_SLOT_BY_EVENT = {
37524
37554
  OrgFailed: IDENTITY_SLOT.org
37525
37555
  };
37526
37556
  const identitySlot = (event) => IDENTITY_SLOT_BY_EVENT[event._tag];
37557
+ /** 2 s, 4 s, 8 s, 16 s, 32 s, 60 s, 60 s: about three minutes, then the user decides. */
37558
+ const DEFAULT_CONFIRMATION_BACKOFF = {
37559
+ initialDelayMs: 2e3,
37560
+ maxDelayMs: 6e4,
37561
+ maxRetries: 7
37562
+ };
37563
+ /**
37564
+ * A public partial override must not bring the tight loop back: a zero,
37565
+ * negative, or non-finite delay, or a non-integer or infinite retry count,
37566
+ * falls back to the default for that field. `maxDelayMs` is never below
37567
+ * `initialDelayMs`.
37568
+ */
37569
+ const positiveMs = (value, fallback) => value !== void 0 && Number.isFinite(value) && value > 0 ? value : fallback;
37570
+ function normalizeConfirmationBackoff(override) {
37571
+ const initialDelayMs = positiveMs(override?.initialDelayMs, DEFAULT_CONFIRMATION_BACKOFF.initialDelayMs);
37572
+ const maxDelayMs = Math.max(initialDelayMs, positiveMs(override?.maxDelayMs, DEFAULT_CONFIRMATION_BACKOFF.maxDelayMs));
37573
+ const retries = override?.maxRetries;
37574
+ return {
37575
+ initialDelayMs,
37576
+ maxDelayMs,
37577
+ maxRetries: retries !== void 0 && Number.isSafeInteger(retries) && retries >= 0 ? retries : DEFAULT_CONFIRMATION_BACKOFF.maxRetries
37578
+ };
37579
+ }
37527
37580
  const failureOf = (error) => {
37528
37581
  if (error instanceof CapxulError) {
37529
37582
  const mode = error.details?.failure_mode;
@@ -37632,7 +37685,7 @@ const orgEngineeringContext = (controls, parent) => {
37632
37685
  ...traceparent === void 0 ? {} : { traceparent }
37633
37686
  };
37634
37687
  };
37635
- const runOrgStep = (setup, orgId, step, controls) => {
37688
+ const runOrgStep = (setup, orgId, step, controls, retryDelayMs) => {
37636
37689
  const [name, invoke] = step === "preparingFounderAccount" ? ["organization-setup.prepare-founder-account", (parent) => setup.prepareFounderAccount({
37637
37690
  orgId,
37638
37691
  observationContext: orgEngineeringContext(controls, parent)
@@ -37644,11 +37697,12 @@ const runOrgStep = (setup, orgId, step, controls) => {
37644
37697
  observationContext: orgEngineeringContext(controls, parent)
37645
37698
  })] : ["organization-setup.confirm-submitted-bootstrap", (parent) => setup.confirmSubmittedBootstrap({
37646
37699
  orgId,
37647
- observationContext: orgEngineeringContext(controls, parent)
37700
+ observationContext: orgEngineeringContext(controls, parent),
37701
+ ...retryDelayMs === void 0 ? {} : { retryDelayMs }
37648
37702
  })];
37649
37703
  return resultEffect(name, invoke);
37650
37704
  };
37651
- const orgLane = (setup, start, send, controls) => Effect.gen(function* () {
37705
+ const orgLane = (setup, start, send, controls, backoff) => Effect.gen(function* () {
37652
37706
  let orgId;
37653
37707
  let lifecycle;
37654
37708
  if (start.kind === "create") {
@@ -37711,9 +37765,12 @@ const orgLane = (setup, start, send, controls) => Effect.gen(function* () {
37711
37765
  orgId,
37712
37766
  step
37713
37767
  });
37768
+ let retries = 0;
37769
+ let retryDelayMs;
37714
37770
  while (step !== "ready") {
37715
37771
  const current = step;
37716
- const advanced = yield* Effect.result(runOrgStep(setup, orgId, current, controls));
37772
+ const advanced = yield* Effect.result(runOrgStep(setup, orgId, current, controls, retryDelayMs));
37773
+ retryDelayMs = void 0;
37717
37774
  if (Result.isFailure(advanced)) {
37718
37775
  yield* send({
37719
37776
  _tag: "OrgFailed",
@@ -37725,6 +37782,38 @@ const orgLane = (setup, start, send, controls) => Effect.gen(function* () {
37725
37782
  }
37726
37783
  lifecycle = advanced.success;
37727
37784
  if (lifecycle.status === "failed") {
37785
+ if (lifecycle.at === "confirmingBootstrap" && lifecycle.retryable && retries < backoff.maxRetries) {
37786
+ const delayMs = Math.min(backoff.initialDelayMs * 2 ** retries, backoff.maxDelayMs);
37787
+ retries += 1;
37788
+ yield* Effect.sleep(Duration.millis(delayMs));
37789
+ const reset = yield* Effect.result(resultEffect("organization-setup.retry", (parent) => setup.retry({
37790
+ orgId,
37791
+ observationContext: orgEngineeringContext(controls, parent)
37792
+ })));
37793
+ if (Result.isFailure(reset)) {
37794
+ yield* send({
37795
+ _tag: "OrgFailed",
37796
+ orgId,
37797
+ step: current,
37798
+ failure: reset.failure
37799
+ });
37800
+ return yield* Effect.fail(reset.failure);
37801
+ }
37802
+ lifecycle = reset.success;
37803
+ if (lifecycle.status !== "failed") {
37804
+ retryDelayMs = delayMs;
37805
+ step = orgStep(lifecycle);
37806
+ yield* step === "ready" ? send({
37807
+ _tag: "OrgReady",
37808
+ orgId
37809
+ }) : send({
37810
+ _tag: "OrgAt",
37811
+ orgId,
37812
+ step
37813
+ });
37814
+ continue;
37815
+ }
37816
+ }
37728
37817
  const failure = failureOf(lifecycle.error);
37729
37818
  yield* send({
37730
37819
  _tag: "OrgFailed",
@@ -37803,6 +37892,7 @@ const identitySpec = (input, sessionStore = { current: null }) => {
37803
37892
  hasSigner: input.signer !== void 0,
37804
37893
  ...input.otpTtlMs === void 0 ? {} : { otpTtlMs: input.otpTtlMs }
37805
37894
  };
37895
+ const backoff = normalizeConfirmationBackoff(input.confirmationBackoff);
37806
37896
  return {
37807
37897
  machine: "identity",
37808
37898
  initial: RESTORING,
@@ -37908,7 +37998,7 @@ const identitySpec = (input, sessionStore = { current: null }) => {
37908
37998
  run: (send, controls) => orgLane(input.organizationSetup, {
37909
37999
  kind: "create",
37910
38000
  draft: event.draft
37911
- }, send, controls)
38001
+ }, send, controls, backoff)
37912
38002
  };
37913
38003
  case "AttachOrganization": return input.organizationSetup === void 0 || org?.at !== "loading" ? void 0 : {
37914
38004
  slot: IDENTITY_SLOT.org,
@@ -37916,7 +38006,7 @@ const identitySpec = (input, sessionStore = { current: null }) => {
37916
38006
  run: (send, controls) => orgLane(input.organizationSetup, {
37917
38007
  kind: "attach",
37918
38008
  orgId: org.orgId
37919
- }, send, controls)
38009
+ }, send, controls, backoff)
37920
38010
  };
37921
38011
  case "RetryOrganization": return input.organizationSetup === void 0 || org?.at !== "settingUp" ? void 0 : {
37922
38012
  slot: IDENTITY_SLOT.org,
@@ -37924,7 +38014,7 @@ const identitySpec = (input, sessionStore = { current: null }) => {
37924
38014
  run: (send, controls) => orgLane(input.organizationSetup, {
37925
38015
  kind: "retry",
37926
38016
  orgId: org.orgId
37927
- }, send, controls)
38017
+ }, send, controls, backoff)
37928
38018
  };
37929
38019
  default: return;
37930
38020
  }
@@ -40094,6 +40184,43 @@ function executeIdentityProductObservation(telemetry, record, state) {
40094
40184
  }
40095
40185
  //#endregion
40096
40186
  //#region ../../packages/sdk/src/surface/create-capxul-client.ts
40187
+ /**
40188
+ * Start the signer readiness cycle when the identity becomes claimed (#1667).
40189
+ *
40190
+ * The cycle used to run only from the embedded-wallet port's `getAddress` and
40191
+ * `signRawDigest`. Nothing calls those after a sign-in or a session restore,
40192
+ * and `resetSession`, which every OTP verify performs, sets the status back to
40193
+ * `unknown`. Thus `client.signer.status()` never left `unknown` on a fresh
40194
+ * session, and each `.Actions` gate that requires `ready` stayed closed. A
40195
+ * claimed identity is the first point where the browser signer has a session to
40196
+ * recover. A signed-out client starts no cycle and reports `unknown`.
40197
+ *
40198
+ * The assembly does not await the call, on purpose: readiness must converge
40199
+ * without a signature. The cycle reports its own failure. It writes
40200
+ * `unavailable` to the same store the gate reads, and adds a DiagnosticPort
40201
+ * breadcrumb, and the next `getAddress` retries it, as before. The rejection is
40202
+ * thus observed and not discarded. A throw here would only cause an unhandled
40203
+ * rejection, and the actor shell removes an observer that throws.
40204
+ *
40205
+ * The `unknown` test holds this to ONE cycle per session. The call sets the
40206
+ * status to `recovering` synchronously, so the later claimed transitions of the
40207
+ * same session, such as the org lane, start no second cycle, and a
40208
+ * `resetSession` that sets the status back to `unknown` permits one more.
40209
+ *
40210
+ * ponytail: one cycle per claim. A cycle that fails stays `unavailable` until
40211
+ * a `getAddress` or a new claim, so a gate that refuses to sign while
40212
+ * `unavailable` needs a reload. Give the action part an explicit retry if that
40213
+ * becomes the common failure.
40214
+ */
40215
+ function startSignerReadinessOnClaim(actor, signer) {
40216
+ if (signer?.statusStore === void 0 || signer.ensureWalletReady === void 0) return () => {};
40217
+ const browserSigner = signer;
40218
+ return actor.subscribe((state) => {
40219
+ if (state.phase !== "authenticated" || state.account.at !== "claimed") return;
40220
+ if (browserSigner.statusStore?.status() !== "unknown") return;
40221
+ browserSigner.ensureWalletReady?.().catch(() => {});
40222
+ });
40223
+ }
40097
40224
  /** Join the assembled actor lifetime to the adapter lifetime for internal client factories. */
40098
40225
  function withAdapterClose(client, closeAdapter) {
40099
40226
  const closeActor = client._internal.close;
@@ -40137,11 +40264,13 @@ function assembleCapxulClient(input) {
40137
40264
  error: transitionError(record)
40138
40265
  }, failureObservation, `identity.${record.event}`, "machine");
40139
40266
  });
40267
+ const unsubscribeSignerReadiness = startSignerReadinessOnClaim(actor, input.signer);
40140
40268
  let stopPromise = null;
40141
40269
  const stopActor = () => {
40142
40270
  if (stopPromise === null) {
40143
40271
  unsubscribeProductTelemetry();
40144
40272
  unsubscribeFailureObservation();
40273
+ unsubscribeSignerReadiness();
40145
40274
  stopPromise = effectRunner.runPromise(Scope.close(scope, Exit.void));
40146
40275
  }
40147
40276
  return stopPromise;
@@ -42793,6 +42922,18 @@ const envFields = {
42793
42922
  "required": false,
42794
42923
  "example": "https://aa-gateway.example.test/token"
42795
42924
  },
42925
+ BASE_SEPOLIA_ALCHEMY_RPC_URL: {
42926
+ "runtime": "server",
42927
+ "kind": "url",
42928
+ "required": false,
42929
+ "example": "https://base-sepolia.g.alchemy.com/v2/key"
42930
+ },
42931
+ BASE_SEPOLIA_INFURA_RPC_URL: {
42932
+ "runtime": "server",
42933
+ "kind": "url",
42934
+ "required": false,
42935
+ "example": "https://base-sepolia.infura.io/v3/key"
42936
+ },
42796
42937
  CONVEX_SITE_URL: {
42797
42938
  "runtime": "server",
42798
42939
  "kind": "url",
@@ -43214,7 +43355,7 @@ const BUNDLER_RPC_METHODS = new Set([
43214
43355
  ]);
43215
43356
  function rpcProviderRole(chainId, method) {
43216
43357
  if (BUNDLER_RPC_METHODS.has(method)) return "account-abstraction";
43217
- if (chainId === 84532 && EVIDENCE_RPC_METHODS.has(method) && optionalEnv("BASE_SEPOLIA_EVIDENCE_RPC_URL") !== void 0) return "chain-evidence";
43358
+ if (EVIDENCE_RPC_METHODS.has(method) && hostedUpstreams(chainId).length > 0) return "chain-evidence";
43218
43359
  return "chain-rpc";
43219
43360
  }
43220
43361
  function accountAbstractionUrl(chainId) {
@@ -43225,9 +43366,25 @@ function rpcProviderError(operation, cause, chainId) {
43225
43366
  const method = operation.split(" ", 1)[0] ?? operation;
43226
43367
  return Errors.providerError(rpcProviderRole(chainId, method), operation, cause);
43227
43368
  }
43228
- function rethrowProvider(chainId, method) {
43369
+ /**
43370
+ * A failure the next upstream may not share: transport, timeout, 5xx, or a
43371
+ * rate limit. `rateLimited` sets the `rate-limited` failure mode the SDK
43372
+ * treats as retryable (#1684, #1655).
43373
+ */
43374
+ function transientProviderError(operation, cause, chainId, rateLimited) {
43375
+ const method = operation.split(" ", 1)[0] ?? operation;
43376
+ return Errors.providerError(rpcProviderRole(chainId, method), operation, cause, {
43377
+ ...rateLimited ? { failure_mode: "rate-limited" } : {},
43378
+ details: { transient: true }
43379
+ });
43380
+ }
43381
+ function isTransientProviderError(error) {
43382
+ return error instanceof CapxulError && error.details?.transient === true;
43383
+ }
43384
+ function rethrowTransient(chainId, method, externalSignal) {
43229
43385
  return (e) => {
43230
- throw rpcProviderError(method, e, chainId);
43386
+ if (externalSignal?.aborted === true) throw rpcProviderError(method, e, chainId);
43387
+ throw transientProviderError(method, e, chainId, false);
43231
43388
  };
43232
43389
  }
43233
43390
  function parseRpcQuantity(value, operation, field, chainId) {
@@ -43268,6 +43425,37 @@ function nodeRpcUrl(chainId) {
43268
43425
  default: throw Errors.invalidInput("chainId", `unsupported chainId ${String(chainId)}`);
43269
43426
  }
43270
43427
  }
43428
+ /**
43429
+ * JSON-RPC "limit exceeded". Providers use it for rate limits and the AA
43430
+ * Gateway returns it when alto failed while its upstream chain was exhausted
43431
+ * (`packages/aa-gateway/src/modules/upstream/types.ts`).
43432
+ */
43433
+ const RATE_LIMITED_RPC_CODE = -32005;
43434
+ const RATE_LIMIT_MESSAGE = /rate limit|too many requests|throttl|capacity/iu;
43435
+ /** Alchemy's free tier caps `eth_getLogs` at 10 blocks; evidence reads span thousands. */
43436
+ const WIDE_LOG_READS = new Set(["eth_getLogs"]);
43437
+ function stripSlash(url) {
43438
+ return url.replace(/\/+$/u, "");
43439
+ }
43440
+ function hostedUpstreams(chainId) {
43441
+ if (chainId !== 84532) return [];
43442
+ const alchemy = optionalEnv("BASE_SEPOLIA_ALCHEMY_RPC_URL");
43443
+ const infura = optionalEnv("BASE_SEPOLIA_INFURA_RPC_URL") ?? optionalEnv("BASE_SEPOLIA_EVIDENCE_RPC_URL");
43444
+ return [...alchemy === void 0 ? [] : [{
43445
+ name: "alchemy",
43446
+ url: stripSlash(alchemy)
43447
+ }], ...infura === void 0 ? [] : [{
43448
+ name: "infura",
43449
+ url: stripSlash(infura)
43450
+ }]];
43451
+ }
43452
+ /** Node upstreams in the order one method tries them. Always ends on the public node. */
43453
+ function nodeRpcCandidates(chainId, method) {
43454
+ return [...hostedUpstreams(chainId).filter((upstream) => !(WIDE_LOG_READS.has(method) && upstream.name === "alchemy")), {
43455
+ name: "public",
43456
+ url: nodeRpcUrl(chainId)
43457
+ }];
43458
+ }
43271
43459
  function isRecord(value) {
43272
43460
  return typeof value === "object" && value !== null && !Array.isArray(value);
43273
43461
  }
@@ -43285,9 +43473,27 @@ var DefinitiveBundlerJsonRpcRejection = class extends Error {
43285
43473
  }
43286
43474
  };
43287
43475
  async function alchemyRpc(chainId, method, params, timeoutMs, externalSignal) {
43288
- const bundlerUrl = BUNDLER_RPC_METHODS.has(method) ? accountAbstractionUrl(chainId) : void 0;
43289
- const evidenceUrl = chainId === 84532 && EVIDENCE_RPC_METHODS.has(method) ? optionalEnv("BASE_SEPOLIA_EVIDENCE_RPC_URL") : void 0;
43290
- const url = bundlerUrl?.replace(/\/+$/u, "") ?? evidenceUrl?.replace(/\/+$/u, "") ?? nodeRpcUrl(chainId);
43476
+ if (BUNDLER_RPC_METHODS.has(method)) return jsonRpcOnce(chainId, method, params, stripSlash(accountAbstractionUrl(chainId)), timeoutMs, externalSignal);
43477
+ const candidates = nodeRpcCandidates(chainId, method);
43478
+ let lastError;
43479
+ for (const [index, upstream] of candidates.entries()) try {
43480
+ return await jsonRpcOnce(chainId, method, params, upstream.url, timeoutMs, externalSignal);
43481
+ } catch (error) {
43482
+ const next = candidates[index + 1];
43483
+ if (next === void 0 || !isTransientProviderError(error)) throw error;
43484
+ lastError = error;
43485
+ console.warn(JSON.stringify({
43486
+ event: "rpc_upstream_fallback",
43487
+ method,
43488
+ from: upstream.name,
43489
+ to: next.name,
43490
+ operation: error.details?.operation,
43491
+ rate_limited: error.details?.failure_mode === "rate-limited"
43492
+ }));
43493
+ }
43494
+ throw lastError ?? rpcProviderError(method, "no upstream configured", chainId);
43495
+ }
43496
+ async function jsonRpcOnce(chainId, method, params, url, timeoutMs, externalSignal) {
43291
43497
  const timeoutSignal = timeoutMs === void 0 ? void 0 : AbortSignal.timeout(timeoutMs);
43292
43498
  const signal = externalSignal === void 0 ? timeoutSignal : timeoutSignal === void 0 ? externalSignal : AbortSignal.any([externalSignal, timeoutSignal]);
43293
43499
  const res = await fetch(url, {
@@ -43300,10 +43506,12 @@ async function alchemyRpc(chainId, method, params, timeoutMs, externalSignal) {
43300
43506
  params
43301
43507
  }),
43302
43508
  ...signal === void 0 ? {} : { signal }
43303
- }).catch(rethrowProvider(chainId, method));
43509
+ }).catch(rethrowTransient(chainId, method, externalSignal));
43304
43510
  if (!res.ok) {
43305
43511
  const body = await res.text().catch(() => "<no body>");
43306
- throw rpcProviderError(`${method} ${res.status}`, body, chainId);
43512
+ const operation = `${method} ${res.status}`;
43513
+ if (res.status === 429 || res.status >= 500) throw transientProviderError(operation, body, chainId, res.status === 429);
43514
+ throw rpcProviderError(operation, body, chainId);
43307
43515
  }
43308
43516
  let json;
43309
43517
  try {
@@ -43314,6 +43522,7 @@ async function alchemyRpc(chainId, method, params, timeoutMs, externalSignal) {
43314
43522
  if (!isValidJsonRpcEnvelope(json)) throw rpcProviderError(method, "malformed JSON-RPC envelope", chainId);
43315
43523
  if (json.error !== void 0) {
43316
43524
  if (!isValidJsonRpcError(json.error)) throw rpcProviderError(method, "malformed JSON-RPC error", chainId);
43525
+ if (json.error.code === RATE_LIMITED_RPC_CODE || RATE_LIMIT_MESSAGE.test(json.error.message)) throw transientProviderError(method, json.error.message, chainId, true);
43317
43526
  throw rpcProviderError(method, method === "eth_sendUserOperation" ? new DefinitiveBundlerJsonRpcRejection() : json.error.message, chainId);
43318
43527
  }
43319
43528
  if (json.result === void 0) throw rpcProviderError(method, "missing result", chainId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capxul/mcp",
3
- "version": "2.5.2",
3
+ "version": "2.5.4",
4
4
  "private": false,
5
5
  "description": "Capxul MCP server for auth, Account readiness, identity, Organizations, relationships, requests, destinations, and testnet funding over Streamable HTTP.",
6
6
  "keywords": [
@@ -47,9 +47,9 @@
47
47
  "typescript": "npm:@typescript/typescript6@6.0.2",
48
48
  "vite": "npm:@voidzero-dev/vite-plus-core@0.1.23",
49
49
  "vite-plus": "0.1.23",
50
- "@capxul/backend": "0.2.9",
50
+ "@capxul/backend": "0.2.11",
51
51
  "@capxul/config": "0.2.1",
52
- "@capxul/sdk": "2.5.2",
52
+ "@capxul/sdk": "2.5.4",
53
53
  "@capxul/types": "0.2.1",
54
54
  "@capxul/typescript-config": "0.0.0",
55
55
  "@capxul/wire": "0.5.1"