@capxul/mcp 1.2.2 → 1.2.3

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 +263 -170
  2. package/package.json +3 -3
package/dist/main.mjs CHANGED
@@ -242,7 +242,7 @@ function normalizeEmail(email) {
242
242
  }
243
243
  //#endregion
244
244
  //#region package.json
245
- var version$2 = "1.2.2";
245
+ var version$2 = "1.2.3";
246
246
  //#endregion
247
247
  //#region src/tool-result.ts
248
248
  function okResult(structured) {
@@ -887,6 +887,25 @@ const EpochMsSchema$1 = Schema.Number.pipe(Schema.refine((n) => Number.isSafeInt
887
887
  const DurationMsSchema$1 = Schema.Number.pipe(Schema.refine((n) => Number.isSafeInteger(n) && n >= 0, { message: "must be a non-negative safe integer" }));
888
888
  //#endregion
889
889
  //#region ../../packages/wire/src/bootstrap.ts
890
+ const PUBLIC_POSTHOG_PROJECT_TOKEN = /^phc_[A-Za-z0-9_-]{1,191}$/u;
891
+ const PostHogIngestOrigin = Schema.String.pipe(Schema.refine((value) => {
892
+ try {
893
+ const url = new URL(value);
894
+ return url.protocol === "https:" && url.username.length === 0 && url.password.length === 0 && url.pathname === "/" && url.search.length === 0 && url.hash.length === 0 && (url.hostname === "posthog.com" || url.hostname.endsWith(".posthog.com"));
895
+ } catch {
896
+ return false;
897
+ }
898
+ }, { message: "must be a credential-free PostHog HTTPS ingest origin" }));
899
+ const EngineeringTelemetryBootstrapPolicy = Schema.Struct({
900
+ host: PostHogIngestOrigin,
901
+ projectToken: Schema.String.pipe(Schema.refine((value) => PUBLIC_POSTHOG_PROJECT_TOKEN.test(value), { message: "must be a public PostHog project token" })),
902
+ capxulEnv: Schema.Union([
903
+ Schema.Literal("development"),
904
+ Schema.Literal("e2e"),
905
+ Schema.Literal("staging"),
906
+ Schema.Literal("production")
907
+ ])
908
+ });
890
909
  /**
891
910
  * `BootstrapEnvelope` v1.
892
911
  *
@@ -912,7 +931,8 @@ const BootstrapEnvelope = Schema.Struct({
912
931
  convexUrl: Schema.String,
913
932
  siteBaseUrl: Schema.String,
914
933
  openfortPublishableKey: Schema.String,
915
- shieldPublishableKey: Schema.String
934
+ shieldPublishableKey: Schema.String,
935
+ engineeringTelemetry: Schema.optional(EngineeringTelemetryBootstrapPolicy)
916
936
  })
917
937
  });
918
938
  //#endregion
@@ -4343,6 +4363,44 @@ function isProvisioningTelemetryDebugEnabled() {
4343
4363
  return globalThis.process?.env?.CAPXUL_DEBUG_TELEMETRY === "1";
4344
4364
  }
4345
4365
  //#endregion
4366
+ //#region ../../packages/sdk/src/internal/invocation-observation.ts
4367
+ const INVOCATION_OBSERVATION = Symbol("capxul.invocation-observation");
4368
+ const FAILURE_INVOCATION_SNAPSHOT = Symbol("capxul.failure-invocation-snapshot");
4369
+ /** @internal Attach one immutable, non-wire invocation snapshot to an SDK-owned object. */
4370
+ function attachInvocationObservation(target, source) {
4371
+ const snapshot = Object.freeze(source.context === void 0 ? { active: source.active } : {
4372
+ active: source.active,
4373
+ context: Object.freeze({ ...source.context })
4374
+ });
4375
+ Object.defineProperty(target, INVOCATION_OBSERVATION, {
4376
+ configurable: false,
4377
+ enumerable: false,
4378
+ value: snapshot,
4379
+ writable: false
4380
+ });
4381
+ return target;
4382
+ }
4383
+ /** @internal Read the snapshot without exposing its symbol or adding a wire field. */
4384
+ function readInvocationObservation(source) {
4385
+ if (typeof source !== "object" || source === null) return void 0;
4386
+ return source[INVOCATION_OBSERVATION];
4387
+ }
4388
+ /** @internal Carry a snapshot across an SDK adapter projection without resolving again. */
4389
+ function copyInvocationObservation(source, target) {
4390
+ const snapshot = readInvocationObservation(source);
4391
+ return snapshot === void 0 ? target : attachInvocationObservation(target, snapshot);
4392
+ }
4393
+ /** @internal Carry the public call-start delivery decision with its failure envelope. */
4394
+ function markFailureInvocationSnapshot(failure, snapshot) {
4395
+ Object.defineProperty(failure, FAILURE_INVOCATION_SNAPSHOT, {
4396
+ configurable: false,
4397
+ enumerable: false,
4398
+ value: Object.freeze(snapshot),
4399
+ writable: false
4400
+ });
4401
+ return failure;
4402
+ }
4403
+ //#endregion
4346
4404
  //#region ../../packages/sdk/src/domain/machine/telemetry.ts
4347
4405
  const definedEntries = (values) => Object.fromEntries(Object.entries(values).filter((entry) => entry[1] !== void 0));
4348
4406
  const SAFE_ENGINEERING_ID = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u;
@@ -4485,7 +4543,7 @@ const boot = (spec, options = {}) => Effect.gen(function* () {
4485
4543
  const makeFailure = (state, event, reason, details) => new ActorFailure(reason, spec.machine, spec.label(state), event._tag, details);
4486
4544
  const nonApplied = (state, event, reason, outcome, env) => {
4487
4545
  const slot = env.origin?.slot ?? spec.slot(event);
4488
- return {
4546
+ return copyInvocationObservation(env.invocation, {
4489
4547
  machine: spec.machine,
4490
4548
  state: spec.label(state),
4491
4549
  event: event._tag,
@@ -4495,9 +4553,9 @@ const boot = (spec, options = {}) => Effect.gen(function* () {
4495
4553
  duration_ms: duration(env.startedAt),
4496
4554
  ...withCarriage(env.invocation),
4497
4555
  ...outcome === "refused" ? { refusal_code: reason } : { error_code: reason }
4498
- };
4556
+ });
4499
4557
  };
4500
- const applied = (from, to, event, slot, epoch, env) => ({
4558
+ const applied = (from, to, event, slot, epoch, env) => copyInvocationObservation(env.invocation, {
4501
4559
  machine: spec.machine,
4502
4560
  from: spec.label(from),
4503
4561
  event: event._tag,
@@ -6146,7 +6204,7 @@ async function recoverRawDigestSigner(input) {
6146
6204
  }
6147
6205
  //#endregion
6148
6206
  //#region ../../packages/sdk/package.json
6149
- var version = "1.2.2";
6207
+ var version = "1.2.3";
6150
6208
  //#endregion
6151
6209
  //#region ../../packages/observability/src/engineering.ts
6152
6210
  const SAFE_TRACED_HEADER_NAMES = [
@@ -6187,7 +6245,7 @@ const validateEngineeringTelemetryConfig = (config) => {
6187
6245
  } catch {
6188
6246
  throw new TypeError("engineering telemetry host must be an absolute HTTPS URL");
6189
6247
  }
6190
- if (url.protocol !== "https:" || url.username.length > 0 || url.password.length > 0 || url.pathname !== "/" || url.search.length > 0 || url.hash.length > 0) throw new TypeError("engineering telemetry host must be a credential-free HTTPS origin");
6248
+ if (url.protocol !== "https:" || url.username.length > 0 || url.password.length > 0 || url.pathname !== "/" || url.search.length > 0 || url.hash.length > 0 || !(url.hostname === "posthog.com" || url.hostname.endsWith(".posthog.com"))) throw new TypeError("engineering telemetry host must be a credential-free HTTPS origin");
6191
6249
  if (!ENGINEERING_CAPXUL_ENVS.has(config.capxulEnv)) throw new TypeError("engineering telemetry capxulEnv is not canonical");
6192
6250
  if (!ENGINEERING_PRODUCERS.has(config.producer)) throw new TypeError("engineering telemetry producer is not canonical");
6193
6251
  if (!SAFE_RESOURCE_VALUE.test(config.sdkVersion)) throw new TypeError("engineering telemetry sdkVersion must be a bounded safe value");
@@ -6297,10 +6355,12 @@ function resolveAuthClientUrl(authBaseUrl, path) {
6297
6355
  //#endregion
6298
6356
  //#region ../../packages/sdk/src/internal/observation-http.ts
6299
6357
  /** Resolve one bounded pre-auth snapshot for an outbound SDK HTTP request. */
6300
- function observationRequestHeaders(adapter) {
6358
+ function observationRequestHeaders(adapter, source) {
6301
6359
  if (adapter === void 0) return {};
6302
6360
  try {
6303
- const encoded = encodeObservationContextHeader(adapter.resolveContext?.());
6361
+ const invocation = readInvocationObservation(source);
6362
+ if (invocation !== void 0 && !invocation.active) return {};
6363
+ const encoded = encodeObservationContextHeader(invocation === void 0 ? adapter.resolveContext?.() : invocation.context);
6304
6364
  return encoded === void 0 ? {} : { [OBSERVATION_CONTEXT_HEADER]: encoded };
6305
6365
  } catch {
6306
6366
  return {};
@@ -6396,7 +6456,7 @@ var BetterAuthBrowserAdapter = class {
6396
6456
  method: "POST",
6397
6457
  headers: {
6398
6458
  "Content-Type": "application/json",
6399
- ...observationRequestHeaders(this.observation)
6459
+ ...observationRequestHeaders(this.observation, input)
6400
6460
  },
6401
6461
  body: JSON.stringify({
6402
6462
  email: input.email,
@@ -6814,7 +6874,7 @@ var BetterAuthNodeAdapter = class {
6814
6874
  headers: {
6815
6875
  "content-type": "application/json",
6816
6876
  ...this.origin ? { origin: this.origin } : {},
6817
- ...observationRequestHeaders(this.observation)
6877
+ ...observationRequestHeaders(this.observation, input)
6818
6878
  },
6819
6879
  body: JSON.stringify({
6820
6880
  email: input.email,
@@ -7082,20 +7142,28 @@ var HttpBootstrapAdapter = class {
7082
7142
  if (res.ok) return Effect.tryPromise({
7083
7143
  try: async () => {
7084
7144
  const body = await res.json();
7085
- const decoded = SchemaParser.decodeUnknownResult(BootstrapEnvelope)(body);
7145
+ const state = typeof body === "object" && body !== null && "state" in body && typeof body.state === "object" && body.state !== null ? body.state : void 0;
7146
+ const rawEngineeringTelemetry = state?.engineeringTelemetry;
7147
+ const baseBody = state === void 0 || rawEngineeringTelemetry === void 0 ? body : {
7148
+ ...body,
7149
+ state: Object.fromEntries(Object.entries(state).filter(([key]) => key !== "engineeringTelemetry"))
7150
+ };
7151
+ const decoded = SchemaParser.decodeUnknownResult(BootstrapEnvelope)(baseBody);
7086
7152
  if (Result.isFailure(decoded)) throw Errors.invalidInput("bootstrapEnvelope", SchemaIssue.makeFormatterDefault()(decoded.failure));
7087
- const { state } = decoded.success;
7153
+ const { state: decodedState } = decoded.success;
7154
+ const decodedEngineeringTelemetry = rawEngineeringTelemetry === void 0 ? void 0 : SchemaParser.decodeUnknownResult(EngineeringTelemetryBootstrapPolicy)(rawEngineeringTelemetry, { onExcessProperty: "error" });
7088
7155
  return {
7089
- applicationId: state.applicationId,
7090
- chainId: state.chainId,
7091
- sessionToken: state.sessionToken,
7092
- issuedAt: state.issuedAt,
7093
- expiresIn: state.expiresIn,
7094
- authBaseUrl: normalizeRuntimeUrl("authBaseUrl", state.authBaseUrl),
7095
- convexUrl: normalizeRuntimeUrl("convexUrl", state.convexUrl),
7096
- siteBaseUrl: normalizeRuntimeUrl("siteBaseUrl", state.siteBaseUrl),
7097
- openfortPublishableKey: state.openfortPublishableKey,
7098
- shieldPublishableKey: state.shieldPublishableKey
7156
+ applicationId: decodedState.applicationId,
7157
+ chainId: decodedState.chainId,
7158
+ sessionToken: decodedState.sessionToken,
7159
+ issuedAt: decodedState.issuedAt,
7160
+ expiresIn: decodedState.expiresIn,
7161
+ authBaseUrl: normalizeRuntimeUrl("authBaseUrl", decodedState.authBaseUrl),
7162
+ convexUrl: normalizeRuntimeUrl("convexUrl", decodedState.convexUrl),
7163
+ siteBaseUrl: normalizeRuntimeUrl("siteBaseUrl", decodedState.siteBaseUrl),
7164
+ openfortPublishableKey: decodedState.openfortPublishableKey,
7165
+ shieldPublishableKey: decodedState.shieldPublishableKey,
7166
+ ...decodedEngineeringTelemetry !== void 0 && Result.isSuccess(decodedEngineeringTelemetry) ? { engineeringTelemetry: decodedEngineeringTelemetry.success } : {}
7099
7167
  };
7100
7168
  },
7101
7169
  catch: (cause) => {
@@ -10095,41 +10163,6 @@ function convexCallErrorFromCapxul(operation, error) {
10095
10163
  }
10096
10164
  var ConvexCallPortTag = class extends Context.Service()("@capxul/sdk/ports/ConvexCallPort") {};
10097
10165
  //#endregion
10098
- //#region ../../packages/sdk/src/internal/invocation-observation.ts
10099
- const INVOCATION_OBSERVATION = Symbol("capxul.invocation-observation");
10100
- const FAILURE_INVOCATION_SNAPSHOT = Symbol("capxul.failure-invocation-snapshot");
10101
- /** @internal Attach one immutable, non-wire invocation snapshot to an SDK-owned object. */
10102
- function attachInvocationObservation(target, context) {
10103
- const snapshot = Object.freeze(context === void 0 ? {} : { context: Object.freeze({ ...context }) });
10104
- Object.defineProperty(target, INVOCATION_OBSERVATION, {
10105
- configurable: false,
10106
- enumerable: false,
10107
- value: snapshot,
10108
- writable: false
10109
- });
10110
- return target;
10111
- }
10112
- /** @internal Read the snapshot without exposing its symbol or adding a wire field. */
10113
- function readInvocationObservation(source) {
10114
- if (typeof source !== "object" || source === null) return void 0;
10115
- return source[INVOCATION_OBSERVATION];
10116
- }
10117
- /** @internal Carry a snapshot across an SDK adapter projection without resolving again. */
10118
- function copyInvocationObservation(source, target) {
10119
- const snapshot = readInvocationObservation(source);
10120
- return snapshot === void 0 ? target : attachInvocationObservation(target, snapshot.context);
10121
- }
10122
- /** @internal Mark a failure envelope as already resolved at the public invocation boundary. */
10123
- function markFailureInvocationSnapshot(failure) {
10124
- Object.defineProperty(failure, FAILURE_INVOCATION_SNAPSHOT, {
10125
- configurable: false,
10126
- enumerable: false,
10127
- value: true,
10128
- writable: false
10129
- });
10130
- return failure;
10131
- }
10132
- //#endregion
10133
10166
  //#region ../../packages/sdk/src/adapters/convex-call/ConvexCallAdapter.ts
10134
10167
  /** Exact floor-first allowlist; every additional handler must migrate its validator first. */
10135
10168
  const OBSERVED_CONVEX_ACTIONS = new Set([
@@ -10610,7 +10643,6 @@ var ConvexSmartAccountAdapter = class {
10610
10643
  return this.#convex.action(this.#fns.confirmDeployment, {
10611
10644
  chainId: wireChainId(input.chainId),
10612
10645
  safeAddress: input.safeAddress,
10613
- ...input.telemetryRunId === void 0 ? {} : { telemetryRunId: input.telemetryRunId },
10614
10646
  evidence
10615
10647
  }).pipe(Effect.mapError((error) => smartAccountErrorFromCapxul("confirmDeployment", error.publicError, error)), Effect.flatMap((row) => Effect.try({
10616
10648
  try: () => brandProvisionedSmartAccount(input.authUserId, row),
@@ -10620,8 +10652,7 @@ var ConvexSmartAccountAdapter = class {
10620
10652
  claim(input) {
10621
10653
  return this.#convex.action(this.#fns.claim, copyInvocationObservation(input, {
10622
10654
  chainId: wireChainId(input.chainId),
10623
- signerAddress: input.signerAddress,
10624
- ...input.telemetryRunId === void 0 ? {} : { telemetryRunId: input.telemetryRunId }
10655
+ signerAddress: input.signerAddress
10625
10656
  })).pipe(Effect.mapError((error) => smartAccountErrorFromCapxul("claim", error.publicError, error)), Effect.flatMap((row) => Effect.try({
10626
10657
  try: () => brandProvisionedSmartAccount(input.authUserId, row),
10627
10658
  catch: (cause) => smartAccountErrorFromUnknown("claim", cause)
@@ -11208,7 +11239,6 @@ const TelemetryEnvelopeProps = {
11208
11239
  "mcp",
11209
11240
  "e2e"
11210
11241
  ]),
11211
- capxul_e2e_run_id: OptionalString,
11212
11242
  journey_id: OptionalString,
11213
11243
  correlation_id: OptionalString,
11214
11244
  sdk_version: OptionalString
@@ -11984,7 +12014,7 @@ var PostHogTelemetryAdapter = class {
11984
12014
  this.#reset = deps.reset ?? (() => void 0);
11985
12015
  }
11986
12016
  emit(event) {
11987
- return this.#run(() => this.#capture(event.name, redactTelemetryProps(event.name, cloneProps(event.props))), "emit", event.name);
12017
+ return this.#run(() => this.#capture(event.name, redactTelemetryProps(event.name, cloneProps(event.props)), event), "emit", event.name);
11988
12018
  }
11989
12019
  identify(input) {
11990
12020
  return this.#run(() => this.#identify(cloneIdentifyInput(input)), "identify");
@@ -35201,7 +35231,7 @@ const identitySpec = (input, sessionStore = { current: null }) => {
35201
35231
  case "RequestOtp": return {
35202
35232
  slot: IDENTITY_SLOT.auth,
35203
35233
  port: "auth-client",
35204
- run: (send) => call("auth-client.send-otp", input.ports.authClient.sendOtp({ email: toEmail(event.email) })).pipe(Effect.andThen(call("clock.now", input.ports.clock.now)), Effect.flatMap((at) => send({
35234
+ run: (send, controls) => call("auth-client.send-otp", input.ports.authClient.sendOtp(copyInvocationObservation(controls, { email: toEmail(event.email) }))).pipe(Effect.andThen(call("clock.now", input.ports.clock.now)), Effect.flatMap((at) => send({
35205
35235
  _tag: "OtpSent",
35206
35236
  at
35207
35237
  })), Effect.catch((failure) => send({
@@ -35212,10 +35242,10 @@ const identitySpec = (input, sessionStore = { current: null }) => {
35212
35242
  case "VerifyOtp": return {
35213
35243
  slot: IDENTITY_SLOT.auth,
35214
35244
  port: "auth-client",
35215
- run: (send) => call("auth-client.verify-otp", input.ports.authClient.verifyOtp({
35245
+ run: (send, controls) => call("auth-client.verify-otp", input.ports.authClient.verifyOtp(copyInvocationObservation(controls, {
35216
35246
  email: toEmail(event.email),
35217
35247
  otp: event.otp
35218
- })).pipe(Effect.tap((session) => Effect.sync(() => {
35248
+ }))).pipe(Effect.tap((session) => Effect.sync(() => {
35219
35249
  sessionStore.current = session;
35220
35250
  })), Effect.flatMap((session) => sessionProfile(input, session).pipe(Effect.flatMap((loaded) => send({
35221
35251
  _tag: "Verified",
@@ -35229,7 +35259,7 @@ const identitySpec = (input, sessionStore = { current: null }) => {
35229
35259
  case "ReadSession": return {
35230
35260
  slot: IDENTITY_SLOT.session,
35231
35261
  port: "auth-client",
35232
- run: (send) => call("auth-client.get-session", input.ports.authClient.getSession()).pipe(Effect.tap((session) => Effect.sync(() => {
35262
+ run: (send, controls) => call("auth-client.get-session", input.ports.authClient.getSession(copyInvocationObservation(controls, {}))).pipe(Effect.tap((session) => Effect.sync(() => {
35233
35263
  sessionStore.current = session;
35234
35264
  })), Effect.flatMap((session) => sessionProfile(input, session)), Effect.flatMap((loaded) => send({
35235
35265
  _tag: "SessionRead",
@@ -35244,7 +35274,7 @@ const identitySpec = (input, sessionStore = { current: null }) => {
35244
35274
  case "SignOut": return {
35245
35275
  slot: IDENTITY_SLOT.auth,
35246
35276
  port: "auth-client",
35247
- run: (send) => call("auth-client.sign-out", input.ports.authClient.signOut()).pipe(Effect.andThen(send({ _tag: "SignedOut" })), Effect.catch((failure) => send({
35277
+ run: (send, controls) => call("auth-client.sign-out", input.ports.authClient.signOut(copyInvocationObservation(controls, {}))).pipe(Effect.andThen(send({ _tag: "SignedOut" })), Effect.catch((failure) => send({
35248
35278
  _tag: "SignOutFailed",
35249
35279
  failure
35250
35280
  }).pipe(Effect.andThen(Effect.fail(failure)))), Effect.ensuring(Effect.sync(() => {
@@ -37730,6 +37760,90 @@ function detectAuthCacheAdapter() {
37730
37760
  return new InMemoryAuthCacheAdapter();
37731
37761
  }
37732
37762
  //#endregion
37763
+ //#region ../../packages/sdk/src/observation.ts
37764
+ const SDK_VERSION$1 = version;
37765
+ /** @internal Reports a factory-level typed failure without changing its identity. */
37766
+ function observeFailedResult(result, adapter, operation) {
37767
+ if (adapter !== void 0 && isFailedResult(result)) report(adapter, "operation", operation, result.error, resolveAdapterContext(adapter));
37768
+ return result;
37769
+ }
37770
+ function report(adapter, kind, operation, cause, invocationContext) {
37771
+ const operationName = normalizeOperation(operation);
37772
+ const kindName = normalizeErrorKind(errorKind(cause));
37773
+ const context = sanitizeObservationContext({
37774
+ ...invocationContext,
37775
+ ...isCapxulError(cause) && cause.correlationId !== void 0 ? { correlationId: cause.correlationId } : {}
37776
+ });
37777
+ const failure = markFailureInvocationSnapshot({
37778
+ exception: syntheticException(operationName, kindName),
37779
+ sdkVersion: SDK_VERSION$1,
37780
+ operation: operationName,
37781
+ errorKind: kindName,
37782
+ ...context === void 0 ? {} : { context }
37783
+ }, {
37784
+ active: invocationContext !== void 0,
37785
+ ...context === void 0 ? {} : { context }
37786
+ });
37787
+ try {
37788
+ ignoreDeliveryFailure(kind === "operation" ? adapter.captureOperationFailure(failure) : adapter.captureException(failure));
37789
+ } catch {}
37790
+ }
37791
+ function resolveAdapterContext(adapter) {
37792
+ try {
37793
+ return adapter.resolveContext?.();
37794
+ } catch {
37795
+ return;
37796
+ }
37797
+ }
37798
+ function ignoreDeliveryFailure(delivery) {
37799
+ if (!isPromiseLike(delivery)) return;
37800
+ try {
37801
+ Promise.resolve(delivery).catch(() => void 0);
37802
+ } catch {}
37803
+ }
37804
+ function errorKind(cause) {
37805
+ try {
37806
+ if (isCapxulError(cause)) return normalizeErrorKind(cause.code);
37807
+ if (cause instanceof Error) return normalizeErrorKind(cause.name);
37808
+ return "UnknownFailure";
37809
+ } catch {
37810
+ return "Error";
37811
+ }
37812
+ }
37813
+ function normalizeOperation(value) {
37814
+ return typeof value === "string" && /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,255}$/u.test(value) ? value : "unknown";
37815
+ }
37816
+ function normalizeErrorKind(value) {
37817
+ return typeof value === "string" && /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/u.test(value) ? value : "Error";
37818
+ }
37819
+ function syntheticException(operation, kind) {
37820
+ const error = /* @__PURE__ */ new Error(EXCEPTION_MESSAGE);
37821
+ error.name = kind;
37822
+ error.stack = `${kind}: ${error.message}\n at CapxulSdkBoundary.${operation} (capxul-sdk-observation://boundary/${operation}:1:1)`;
37823
+ return error;
37824
+ }
37825
+ function isPromiseLike(value) {
37826
+ return (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
37827
+ }
37828
+ function isPlainObject(value) {
37829
+ if (typeof value !== "object" || value === null) return false;
37830
+ const prototype = Object.getPrototypeOf(value);
37831
+ return prototype === Object.prototype || prototype === null;
37832
+ }
37833
+ function isCapxulResult(value) {
37834
+ return isPlainObject(value) && typeof value.ok === "boolean";
37835
+ }
37836
+ function isFailedResult(value) {
37837
+ return isCapxulResult(value) && value.ok === false && "error" in value;
37838
+ }
37839
+ //#endregion
37840
+ //#region ../../packages/sdk/src/telemetry/from-posthog.ts
37841
+ const PRODUCT_INVOCATION = Symbol("capxul.product-telemetry-invocation");
37842
+ /** @internal Bind paired emit/identify/reset work to one call-start snapshot. */
37843
+ function bindProductTelemetryInvocation(telemetry, source) {
37844
+ return telemetry[PRODUCT_INVOCATION]?.(source) ?? telemetry;
37845
+ }
37846
+ //#endregion
37733
37847
  //#region ../../packages/sdk/src/telemetry/identity-product.ts
37734
37848
  const NONE = null;
37735
37849
  const IDENTITY_EVENT_TAG_SET = new Set(IDENTITY_EVENT_TAGS);
@@ -37812,13 +37926,15 @@ const ignoreTransportFailure = (operation, operationName, eventName) => Effect.s
37812
37926
  product_event: eventName
37813
37927
  }), Effect.catchCause(() => Effect.void))));
37814
37928
  function executeIdentityProductObservation(telemetry, record, state) {
37815
- const observation = mapIdentityProductObservation(record, state);
37816
- if (observation === null) return Effect.void;
37817
- const after = () => observation.name === "auth_verified" && state.phase === "authenticated" ? telemetry.identify({
37929
+ const mapped = mapIdentityProductObservation(record, state);
37930
+ if (mapped === null) return Effect.void;
37931
+ copyInvocationObservation(record, mapped);
37932
+ const invocationTelemetry = bindProductTelemetryInvocation(telemetry, mapped);
37933
+ const after = () => mapped.name === "auth_verified" && state.phase === "authenticated" ? invocationTelemetry.identify({
37818
37934
  distinctId: state.session.authUserId,
37819
37935
  traits: { email_domain: emailDomain(state.session.email) }
37820
- }) : observation.name === "auth_signed_out" ? telemetry.reset() : Effect.void;
37821
- return ignoreTransportFailure(() => telemetry.emit(observation), "emit", observation.name).pipe(Effect.andThen(ignoreTransportFailure(after, observation.name === "auth_signed_out" ? "reset" : "identify", observation.name)));
37936
+ }) : mapped.name === "auth_signed_out" ? invocationTelemetry.reset() : Effect.void;
37937
+ return ignoreTransportFailure(() => invocationTelemetry.emit(mapped), "emit", mapped.name).pipe(Effect.andThen(ignoreTransportFailure(after, mapped.name === "auth_signed_out" ? "reset" : "identify", mapped.name)));
37822
37938
  }
37823
37939
  //#endregion
37824
37940
  //#region ../../packages/sdk/src/surface/create-capxul-client.ts
@@ -37845,14 +37961,14 @@ function assembleCapxulClient(input) {
37845
37961
  runPromise: Effect.runPromise
37846
37962
  };
37847
37963
  const scope = effectRunner.runSync(Scope.make());
37848
- const actor = effectRunner.runSync(Scope.provide(bootIdentityFlow({
37964
+ const actor = withHostObservation(effectRunner.runSync(Scope.provide(bootIdentityFlow({
37849
37965
  ports: input.ports,
37850
37966
  chainId: input.bootstrap.chainId,
37851
37967
  requirement: input.requirement,
37852
37968
  ...input.signer === void 0 ? {} : { signer: input.signer },
37853
37969
  ...input.organizationSetup === void 0 ? {} : { organizationSetup: input.organizationSetup },
37854
37970
  ...input.otpTtlMs === void 0 ? {} : { otpTtlMs: input.otpTtlMs }
37855
- }), scope));
37971
+ }), scope)), input.hostObservationSnapshot);
37856
37972
  const unsubscribeProductTelemetry = actor.subscribeTransitions((record) => {
37857
37973
  effectRunner.runPromise(executeIdentityProductObservation(input.ports.telemetry, record, actor.snapshot())).catch(() => {});
37858
37974
  });
@@ -38034,79 +38150,34 @@ function assembleCapxulClient(input) {
38034
38150
  }
38035
38151
  };
38036
38152
  }
38037
- //#endregion
38038
- //#region ../../packages/sdk/src/observation.ts
38039
- const SDK_VERSION$1 = version;
38040
- /** @internal Reports a factory-level typed failure without changing its identity. */
38041
- function observeFailedResult(result, adapter, operation) {
38042
- if (adapter !== void 0 && isFailedResult(result)) report(adapter, "operation", operation, result.error, resolveAdapterContext(adapter));
38043
- return result;
38044
- }
38045
- function report(adapter, kind, operation, cause, invocationContext) {
38046
- const operationName = normalizeOperation(operation);
38047
- const kindName = normalizeErrorKind(errorKind(cause));
38048
- const context = sanitizeObservationContext({
38049
- ...invocationContext,
38050
- ...isCapxulError(cause) && cause.correlationId !== void 0 ? { correlationId: cause.correlationId } : {}
38051
- });
38052
- const failure = markFailureInvocationSnapshot({
38053
- exception: syntheticException(operationName, kindName),
38054
- sdkVersion: SDK_VERSION$1,
38055
- operation: operationName,
38056
- errorKind: kindName,
38057
- ...context === void 0 ? {} : { context }
38058
- });
38059
- try {
38060
- ignoreDeliveryFailure(kind === "operation" ? adapter.captureOperationFailure(failure) : adapter.captureException(failure));
38061
- } catch {}
38062
- }
38063
- function resolveAdapterContext(adapter) {
38064
- try {
38065
- return adapter.resolveContext?.();
38066
- } catch {
38067
- return;
38068
- }
38069
- }
38070
- function ignoreDeliveryFailure(delivery) {
38071
- if (!isPromiseLike(delivery)) return;
38072
- try {
38073
- Promise.resolve(delivery).catch(() => void 0);
38074
- } catch {}
38075
- }
38076
- function errorKind(cause) {
38077
- try {
38078
- if (isCapxulError(cause)) return normalizeErrorKind(cause.code);
38079
- if (cause instanceof Error) return normalizeErrorKind(cause.name);
38080
- return "UnknownFailure";
38081
- } catch {
38082
- return "Error";
38083
- }
38084
- }
38085
- function normalizeOperation(value) {
38086
- return typeof value === "string" && /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,255}$/u.test(value) ? value : "unknown";
38087
- }
38088
- function normalizeErrorKind(value) {
38089
- return typeof value === "string" && /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/u.test(value) ? value : "Error";
38090
- }
38091
- function syntheticException(operation, kind) {
38092
- const error = /* @__PURE__ */ new Error(EXCEPTION_MESSAGE);
38093
- error.name = kind;
38094
- error.stack = `${kind}: ${error.message}\n at CapxulSdkBoundary.${operation} (capxul-sdk-observation://boundary/${operation}:1:1)`;
38095
- return error;
38096
- }
38097
- function isPromiseLike(value) {
38098
- return (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
38099
- }
38100
- function isPlainObject(value) {
38101
- if (typeof value !== "object" || value === null) return false;
38102
- const prototype = Object.getPrototypeOf(value);
38103
- return prototype === Object.prototype || prototype === null;
38153
+ function withHostObservation(actor, snapshot) {
38154
+ if (snapshot === void 0) return actor;
38155
+ const controls = (input) => {
38156
+ const captured = snapshot();
38157
+ const copied = { ...input };
38158
+ return captured === void 0 ? copied : attachInvocationObservation(copied, captured);
38159
+ };
38160
+ return {
38161
+ ...actor,
38162
+ ask: (event, input) => actor.ask(event, controls(input)),
38163
+ tell: (event, input) => actor.tell(event, controls(input)),
38164
+ restoreAuthSession: (session, input) => actor.restoreAuthSession(session, controls(input))
38165
+ };
38104
38166
  }
38105
- function isCapxulResult(value) {
38106
- return isPlainObject(value) && typeof value.ok === "boolean";
38167
+ //#endregion
38168
+ //#region ../../packages/sdk/src/host-observability.ts
38169
+ const HOST_INVOCATION = Symbol("capxul.host-observability-invocation");
38170
+ /** @internal Bind both projections to one call-start decision/context snapshot. */
38171
+ function bindHostObservabilityInvocation(observability) {
38172
+ return observability?.[HOST_INVOCATION]?.bind() ?? observability;
38107
38173
  }
38108
- function isFailedResult(value) {
38109
- return isCapxulResult(value) && value.ok === false && "error" in value;
38174
+ /** @internal Read one call-start snapshot for actor/transition carriage. */
38175
+ function snapshotHostObservability(observability) {
38176
+ const snapshot = observability?.[HOST_INVOCATION]?.snapshot();
38177
+ return snapshot === void 0 ? void 0 : {
38178
+ active: snapshot.active,
38179
+ ...snapshot.context === void 0 ? {} : { context: snapshot.context }
38180
+ };
38110
38181
  }
38111
38182
  const SDK_VERSION = version;
38112
38183
  /**
@@ -38259,7 +38330,19 @@ function productionConvexCallLayer(input, refreshConvexAuthRef) {
38259
38330
  function isRefreshableConvexCallPort(convexCall) {
38260
38331
  return "refreshAuth" in convexCall && typeof convexCall.refreshAuth === "function";
38261
38332
  }
38333
+ function resolveProductionObservability(input) {
38334
+ const observation = input.observability?.failures ?? input.observation;
38335
+ const telemetry = input.observability?.product ?? input.telemetry;
38336
+ const invocationObservability = input.invocationObservability;
38337
+ return {
38338
+ observation,
38339
+ telemetry,
38340
+ invocationObservation: invocationObservability?.failures ?? observation,
38341
+ invocationTelemetry: invocationObservability?.product ?? telemetry
38342
+ };
38343
+ }
38262
38344
  async function createProductionAdapters(input) {
38345
+ const { observation, telemetry, invocationObservation, invocationTelemetry } = resolveProductionObservability(input);
38263
38346
  const resolvedInput = resolveInput(input);
38264
38347
  if (!resolvedInput.ok) return resolvedInput;
38265
38348
  const scope = await Effect.runPromise(Scope.make());
@@ -38267,7 +38350,7 @@ async function createProductionAdapters(input) {
38267
38350
  const bootstrapLayer = HttpBootstrapLayer({
38268
38351
  bootstrapBaseUrl: resolvedInput.value.bootstrapBaseUrl,
38269
38352
  ...input.fetch === void 0 ? {} : { fetch: input.fetch },
38270
- ...input.observation === void 0 ? {} : { observation: input.observation }
38353
+ ...invocationObservation === void 0 ? {} : { observation: invocationObservation }
38271
38354
  });
38272
38355
  try {
38273
38356
  const bootstrapContext = await Effect.runPromise(Layer.buildWithScope(bootstrapLayer, scope));
@@ -38277,7 +38360,7 @@ async function createProductionAdapters(input) {
38277
38360
  ...resolvedInput.value.origin === void 0 ? {} : { origin: resolvedInput.value.origin }
38278
38361
  }));
38279
38362
  if (!bootstrapResult.ok) {
38280
- await emitBootstrapTelemetry(input.telemetry, {
38363
+ await emitBootstrapTelemetry(invocationTelemetry, {
38281
38364
  name: "bootstrap_failed",
38282
38365
  props: {
38283
38366
  ...bootstrapTelemetryEnvelope(input, resolvedInput.value),
@@ -38294,7 +38377,7 @@ async function createProductionAdapters(input) {
38294
38377
  }
38295
38378
  const runtimeUrlsResult = resolveRuntimeUrls(bootstrapResult.value, resolvedInput.value.runtime, input.authBaseUrl);
38296
38379
  if (!runtimeUrlsResult.ok) {
38297
- await emitBootstrapTelemetry(input.telemetry, {
38380
+ await emitBootstrapTelemetry(invocationTelemetry, {
38298
38381
  name: "bootstrap_failed",
38299
38382
  props: {
38300
38383
  ...bootstrapTelemetryEnvelope(input, resolvedInput.value),
@@ -38306,7 +38389,7 @@ async function createProductionAdapters(input) {
38306
38389
  return runtimeUrlsResult;
38307
38390
  }
38308
38391
  const runtimeUrls = runtimeUrlsResult;
38309
- await emitBootstrapTelemetry(input.telemetry, {
38392
+ await emitBootstrapTelemetry(invocationTelemetry, {
38310
38393
  name: "bootstrap_resolved",
38311
38394
  props: {
38312
38395
  ...bootstrapTelemetryEnvelope(input, resolvedInput.value),
@@ -38331,19 +38414,15 @@ async function createProductionAdapters(input) {
38331
38414
  runtimeUrls: runtimeUrls.value,
38332
38415
  chainId: bootstrapResult.value.chainId,
38333
38416
  applicationId: bootstrapResult.value.applicationId,
38334
- ...input.observation === void 0 ? {} : { observation: input.observation },
38417
+ ...observation === void 0 ? {} : { observation },
38335
38418
  ...input.authCache === void 0 ? {} : { authCache: input.authCache },
38336
- ...input.telemetry === void 0 ? {} : { telemetry: input.telemetry },
38419
+ ...telemetry === void 0 ? {} : { telemetry },
38337
38420
  ...injectedClient === void 0 ? {} : { convexClient: injectedClient },
38338
38421
  ...input.fetch === void 0 ? {} : { fetch: input.fetch },
38339
38422
  ...input.signal === void 0 ? {} : { signal: input.signal },
38340
38423
  ...input.resetSignerSession === void 0 ? {} : { resetSignerSession: input.resetSignerSession }
38341
38424
  }));
38342
- const applicationLayer = input.engineeringTelemetry === void 0 ? portsLayer : Layer.merge(portsLayer, makeEngineeringTelemetryLayer({
38343
- ...input.engineeringTelemetry,
38344
- producer: resolvedInput.value.runtime === "browser" ? "browser" : "server",
38345
- sdkVersion: SDK_VERSION
38346
- }));
38425
+ const applicationLayer = Layer.merge(portsLayer, optionalEngineeringTelemetryLayer(bootstrapResult.value.engineeringTelemetry, resolvedInput.value.runtime));
38347
38426
  const context = await Effect.runPromise(Layer.buildWithScope(applicationLayer, scope));
38348
38427
  return {
38349
38428
  ok: true,
@@ -38362,6 +38441,20 @@ async function createProductionAdapters(input) {
38362
38441
  };
38363
38442
  }
38364
38443
  }
38444
+ function optionalEngineeringTelemetryLayer(policy, runtime) {
38445
+ if (policy === void 0) return Layer.empty;
38446
+ try {
38447
+ return makeEngineeringTelemetryLayer({
38448
+ host: policy.host,
38449
+ headers: { authorization: `Bearer ${policy.projectToken}` },
38450
+ capxulEnv: policy.capxulEnv,
38451
+ producer: runtime === "browser" ? "browser" : "server",
38452
+ sdkVersion: SDK_VERSION
38453
+ });
38454
+ } catch {
38455
+ return Layer.empty;
38456
+ }
38457
+ }
38365
38458
  function refreshConvexAuthOnSession(authClient, refresh) {
38366
38459
  return {
38367
38460
  ...authClient,
@@ -38391,14 +38484,17 @@ function resetSignerSessionOnSignOut(authClient, resetRef) {
38391
38484
  };
38392
38485
  }
38393
38486
  async function createCapxulClient(input) {
38487
+ const invocationObservability = bindHostObservabilityInvocation(input.observability);
38488
+ const observation = invocationObservability?.failures ?? input.observation;
38394
38489
  const validation = validateCreateCapxulClientInput(input);
38395
- if (!validation.ok) return observeFailedResult(validation, input.observation, "createCapxulClient");
38490
+ if (!validation.ok) return observeFailedResult(validation, observation, "createCapxulClient");
38396
38491
  const resetSignerSession = { current: null };
38397
38492
  const adapters = await createProductionAdapters({
38398
38493
  ...input,
38399
- resetSignerSession
38494
+ resetSignerSession,
38495
+ ...invocationObservability === void 0 ? {} : { invocationObservability }
38400
38496
  });
38401
- if (!adapters.ok) return observeFailedResult(adapters, input.observation, "createCapxulClient");
38497
+ if (!adapters.ok) return observeFailedResult(adapters, observation, "createCapxulClient");
38402
38498
  try {
38403
38499
  const runtime = input.runtime ?? detectRuntime();
38404
38500
  const resolvedAuthBaseUrl = resolveBrowserAuthBaseUrl({
@@ -38435,6 +38531,7 @@ async function createCapxulClient(input) {
38435
38531
  ...input.signal === void 0 ? {} : { signal: input.signal },
38436
38532
  ...input.otpTtlMs === void 0 ? {} : { otpTtlMs: input.otpTtlMs },
38437
38533
  invokeTimeoutMs: input.invokeTimeoutMs ?? 3e4,
38534
+ ...input.observability === void 0 ? {} : { hostObservationSnapshot: () => snapshotHostObservability(input.observability) },
38438
38535
  effectRunner: {
38439
38536
  runSync: Effect.runSyncWith(adapters.value.context),
38440
38537
  runPromise: Effect.runPromiseWith(adapters.value.context)
@@ -38463,7 +38560,7 @@ async function createCapxulClient(input) {
38463
38560
  return observeFailedResult({
38464
38561
  ok: false,
38465
38562
  error: toPublicError$1(cause, "createCapxulClient")
38466
- }, input.observation, "createCapxulClient");
38563
+ }, observation, "createCapxulClient");
38467
38564
  }
38468
38565
  }
38469
38566
  function validateCreateCapxulClientInput(input) {
@@ -40774,8 +40871,7 @@ var LiveOrgDeploymentAdapter = class {
40774
40871
  return this.#convex.action(orgInviteMemberAction, {
40775
40872
  orgId: input.orgId,
40776
40873
  email: input.input.email,
40777
- role: input.input.role,
40778
- ...process.env.CAPXUL_E2E_RUN_ID === void 0 ? {} : { telemetryRunId: process.env.CAPXUL_E2E_RUN_ID }
40874
+ role: input.input.role
40779
40875
  }).pipe(Effect.mapError((error) => orgErrorFromCapxul("inviteMember", error.publicError, error)), Effect.map(brandOrgMember));
40780
40876
  }
40781
40877
  resendInviteToken(input) {
@@ -40785,7 +40881,7 @@ var LiveOrgDeploymentAdapter = class {
40785
40881
  }).pipe(Effect.mapError((error) => orgErrorFromCapxul("resendInviteToken", error.publicError, error)), Effect.map(brandOrgMember));
40786
40882
  }
40787
40883
  detectAndAcceptPendingInvitations(_input) {
40788
- return this.#convex.action(orgDetectAndAcceptPendingInvitationsAction, process.env.CAPXUL_E2E_RUN_ID === void 0 ? {} : { telemetryRunId: process.env.CAPXUL_E2E_RUN_ID }).pipe(Effect.mapError((error) => orgErrorFromCapxul("detectAndAcceptPendingInvitations", error.publicError, error)), Effect.map((result) => ({ matched: result.matched.map(toOrgId) })));
40884
+ return this.#convex.action(orgDetectAndAcceptPendingInvitationsAction, {}).pipe(Effect.mapError((error) => orgErrorFromCapxul("detectAndAcceptPendingInvitations", error.publicError, error)), Effect.map((result) => ({ matched: result.matched.map(toOrgId) })));
40789
40885
  }
40790
40886
  deployRoles(input) {
40791
40887
  return this.#convex.query(orgLoadByOrgIdQuery, { orgId: input.orgId }).pipe(Effect.mapError((error) => orgErrorFromCapxul("deployRoles", error.publicError, error)), Effect.flatMap((wire) => this.#convex.query(orgListRolesByOrgIdQuery, { orgId: input.orgId }).pipe(Effect.mapError((error) => orgErrorFromCapxul("deployRoles", error.publicError, error)), Effect.map((roles) => ({
@@ -40798,8 +40894,7 @@ var LiveOrgDeploymentAdapter = class {
40798
40894
  orgId: input.orgId,
40799
40895
  rolesModuleAddress: deployment.rolesModuleAddress,
40800
40896
  allowanceModuleAddress: deployment.rolesModuleAddress,
40801
- txHash: deployment.txHash,
40802
- ...process.env.CAPXUL_E2E_RUN_ID === void 0 ? {} : { telemetryRunId: process.env.CAPXUL_E2E_RUN_ID }
40897
+ txHash: deployment.txHash
40803
40898
  }).pipe(Effect.mapError((error) => orgErrorFromCapxul("deployRoles", error.publicError, error)))), Effect.flatMap(() => this.listRoles({ orgId: input.orgId })), Effect.map((roles) => ({
40804
40899
  orgId: input.orgId,
40805
40900
  roles
@@ -40816,8 +40911,7 @@ var LiveOrgDeploymentAdapter = class {
40816
40911
  orgId: input.orgId,
40817
40912
  memberSafeAddress: input.input.memberSafeAddress,
40818
40913
  role: input.input.role,
40819
- txHash,
40820
- ...process.env.CAPXUL_E2E_RUN_ID === void 0 ? {} : { telemetryRunId: process.env.CAPXUL_E2E_RUN_ID }
40914
+ txHash
40821
40915
  })), Effect.mapError((error) => orgErrorFromCapxul("grantRole", error.publicError, error)), Effect.map(brandOrgMember));
40822
40916
  }
40823
40917
  revokeRole(input) {
@@ -40834,8 +40928,7 @@ var LiveOrgDeploymentAdapter = class {
40834
40928
  })), Effect.flatMap((txHash) => this.#convex.action(orgRemoveMemberAction, {
40835
40929
  orgId: input.orgId,
40836
40930
  memberSafeAddress: input.input.memberSafeAddress,
40837
- txHash,
40838
- ...process.env.CAPXUL_E2E_RUN_ID === void 0 ? {} : { telemetryRunId: process.env.CAPXUL_E2E_RUN_ID }
40931
+ txHash
40839
40932
  }).pipe(Effect.mapError((error) => orgErrorFromCapxul("revokeRole", error.publicError, error)))), Effect.asVoid);
40840
40933
  }
40841
40934
  readSpendAuthority(input) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capxul/mcp",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "private": false,
5
5
  "description": "Capxul MCP server — agent-facing financial-ops tools (auth, account readiness, balances, testnet faucet, payments) exposed over Streamable HTTP with OAuth bearer auth and a dev-mode custody gate.",
6
6
  "keywords": [
@@ -48,9 +48,9 @@
48
48
  "typescript": "5.9.2",
49
49
  "vite": "npm:@voidzero-dev/vite-plus-core@0.1.23",
50
50
  "vite-plus": "0.1.23",
51
- "@capxul/backend": "0.1.4",
51
+ "@capxul/backend": "0.1.5",
52
52
  "@capxul/config": "0.1.0",
53
- "@capxul/sdk": "1.2.2",
53
+ "@capxul/sdk": "1.2.3",
54
54
  "@capxul/types": "0.1.0",
55
55
  "@capxul/wire": "0.1.0"
56
56
  },