@capxul/mcp 1.0.0-alpha.15 → 1.0.0-alpha.16

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 +151 -17
  2. package/package.json +2 -2
package/dist/main.mjs CHANGED
@@ -232,7 +232,7 @@ function normalizeEmail(email) {
232
232
  }
233
233
  //#endregion
234
234
  //#region package.json
235
- var version$1 = "1.0.0-alpha.15";
235
+ var version$1 = "1.0.0-alpha.16";
236
236
  //#endregion
237
237
  //#region src/tool-result.ts
238
238
  function okResult(structured) {
@@ -286,10 +286,10 @@ function emitToolCall(onToolCall, operation) {
286
286
  toolName: operation,
287
287
  at: (/* @__PURE__ */ new Date()).toISOString()
288
288
  });
289
- if (isPromiseLike(maybePromise)) Promise.resolve(maybePromise).catch(() => void 0);
289
+ if (isPromiseLike$1(maybePromise)) Promise.resolve(maybePromise).catch(() => void 0);
290
290
  } catch {}
291
291
  }
292
- function isPromiseLike(value) {
292
+ function isPromiseLike$1(value) {
293
293
  return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
294
294
  }
295
295
  /** Wraps a tool handler so unexpected throws become structured errors too. */
@@ -5192,7 +5192,7 @@ async function recoverRawDigestSigner(input) {
5192
5192
  }
5193
5193
  //#endregion
5194
5194
  //#region ../../packages/sdk/package.json
5195
- var version = "1.0.0-alpha.15";
5195
+ var version = "1.0.0-alpha.16";
5196
5196
  //#endregion
5197
5197
  //#region ../../packages/sdk/src/ports/auth-client.ts
5198
5198
  var AuthClientError = class extends Data.TaggedError("AuthClientError") {};
@@ -5219,11 +5219,11 @@ function fromResult(operation, run) {
5219
5219
  })
5220
5220
  }).pipe(Effect.flatMap((result) => result.ok ? Effect.succeed(result.value) : Effect.fail(new AuthClientError({
5221
5221
  operation,
5222
- kind: errorKind(result.error),
5222
+ kind: errorKind$1(result.error),
5223
5223
  cause: result.error
5224
5224
  }))));
5225
5225
  }
5226
- function errorKind(error) {
5226
+ function errorKind$1(error) {
5227
5227
  if (error.code === "CANCELLED") return "cancelled";
5228
5228
  if (error.code === "NETWORK_ERROR") return "network";
5229
5229
  if (error.code === "INVALID_INPUT" || error.code === "OTP_EXPIRED") return "validation";
@@ -11183,6 +11183,140 @@ function assembleCapxulClient(input) {
11183
11183
  }
11184
11184
  };
11185
11185
  }
11186
+ //#endregion
11187
+ //#region ../../packages/sdk/src/observation.ts
11188
+ const SDK_VERSION$1 = version;
11189
+ /** @internal Decorates public client method bundles at the owning SDK boundary. */
11190
+ function observeSdkClient(client, adapter) {
11191
+ if (adapter === void 0) return client;
11192
+ const objectProxies = /* @__PURE__ */ new WeakMap();
11193
+ const functionWrappers = /* @__PURE__ */ new WeakMap();
11194
+ const wrapObject = (target, path, internal = false) => {
11195
+ const cacheKey = `${internal ? "internal" : "public"}:${path.join(".")}`;
11196
+ let targetProxies = objectProxies.get(target);
11197
+ const cached = targetProxies?.get(cacheKey);
11198
+ if (cached !== void 0) return cached;
11199
+ const proxy = new Proxy(target, { get(currentTarget, property, receiver) {
11200
+ const value = Reflect.get(currentTarget, property, receiver);
11201
+ if (typeof property !== "string") return value;
11202
+ if (path.length === 0 && property === "_internal" && isPlainObject(value)) return wrapInternal(value);
11203
+ if (internal && property !== "accounts") return value;
11204
+ return wrapValue(value, [...path, property], currentTarget);
11205
+ } });
11206
+ if (targetProxies === void 0) {
11207
+ targetProxies = /* @__PURE__ */ new Map();
11208
+ objectProxies.set(target, targetProxies);
11209
+ }
11210
+ targetProxies.set(cacheKey, proxy);
11211
+ return proxy;
11212
+ };
11213
+ const wrapInternal = (target) => wrapObject(target, ["_internal"], true);
11214
+ const wrapValue = (value, path, owner) => {
11215
+ if (typeof value === "function") {
11216
+ const callable = value;
11217
+ const operation = path.join(".");
11218
+ let ownerWrappers = functionWrappers.get(owner);
11219
+ if (ownerWrappers === void 0) {
11220
+ ownerWrappers = /* @__PURE__ */ new Map();
11221
+ functionWrappers.set(owner, ownerWrappers);
11222
+ }
11223
+ const cached = ownerWrappers.get(operation);
11224
+ if (cached !== void 0) return cached;
11225
+ const wrapped = new Proxy(callable, {
11226
+ apply(currentTarget, _thisArg, args) {
11227
+ let output;
11228
+ try {
11229
+ output = Reflect.apply(currentTarget, owner, args);
11230
+ } catch (cause) {
11231
+ report(adapter, "exception", operation, cause);
11232
+ throw cause;
11233
+ }
11234
+ if (isPromiseLike(output)) return Promise.resolve(output).then((result) => processOutput(result, path), (cause) => {
11235
+ report(adapter, "exception", operation, cause);
11236
+ throw cause;
11237
+ });
11238
+ return processOutput(output, path);
11239
+ },
11240
+ get(currentTarget, property) {
11241
+ const attached = Reflect.get(currentTarget, property, currentTarget);
11242
+ if (typeof property !== "string") return attached;
11243
+ return wrapValue(attached, [...path, property], currentTarget);
11244
+ }
11245
+ });
11246
+ ownerWrappers.set(operation, wrapped);
11247
+ return wrapped;
11248
+ }
11249
+ return isPlainObject(value) ? wrapObject(value, path) : value;
11250
+ };
11251
+ const processOutput = (output, path) => {
11252
+ if (isFailedResult(output)) {
11253
+ report(adapter, "operation", path.join("."), output.error);
11254
+ return output;
11255
+ }
11256
+ if (isCapxulResult(output)) return output;
11257
+ return isPlainObject(output) ? wrapObject(output, path) : output;
11258
+ };
11259
+ return wrapObject(client, []);
11260
+ }
11261
+ /** @internal Reports a factory-level typed failure without changing its identity. */
11262
+ function observeFailedResult(result, adapter, operation) {
11263
+ if (adapter !== void 0 && isFailedResult(result)) report(adapter, "operation", operation, result.error);
11264
+ return result;
11265
+ }
11266
+ function report(adapter, kind, operation, cause) {
11267
+ const operationName = normalizeOperation(operation);
11268
+ const kindName = normalizeErrorKind(errorKind(cause));
11269
+ const failure = {
11270
+ exception: syntheticException(operationName, kindName),
11271
+ sdkVersion: SDK_VERSION$1,
11272
+ operation: operationName,
11273
+ errorKind: kindName
11274
+ };
11275
+ try {
11276
+ ignoreDeliveryFailure(kind === "operation" ? adapter.captureOperationFailure(failure) : adapter.captureException(failure));
11277
+ } catch {}
11278
+ }
11279
+ function ignoreDeliveryFailure(delivery) {
11280
+ if (!isPromiseLike(delivery)) return;
11281
+ try {
11282
+ Promise.resolve(delivery).catch(() => void 0);
11283
+ } catch {}
11284
+ }
11285
+ function errorKind(cause) {
11286
+ try {
11287
+ if (isCapxulError(cause)) return normalizeErrorKind(cause.code);
11288
+ if (cause instanceof Error) return normalizeErrorKind(cause.name);
11289
+ return "UnknownFailure";
11290
+ } catch {
11291
+ return "Error";
11292
+ }
11293
+ }
11294
+ function normalizeOperation(value) {
11295
+ return typeof value === "string" && /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,255}$/u.test(value) ? value : "unknown";
11296
+ }
11297
+ function normalizeErrorKind(value) {
11298
+ return typeof value === "string" && /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/u.test(value) ? value : "Error";
11299
+ }
11300
+ function syntheticException(operation, kind) {
11301
+ const error = /* @__PURE__ */ new Error("Capxul SDK operation failed");
11302
+ error.name = kind;
11303
+ error.stack = `${kind}: ${error.message}\n at CapxulSdkBoundary.${operation} (capxul-sdk-observation://boundary/${operation}:1:1)`;
11304
+ return error;
11305
+ }
11306
+ function isPromiseLike(value) {
11307
+ return (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
11308
+ }
11309
+ function isPlainObject(value) {
11310
+ if (typeof value !== "object" || value === null) return false;
11311
+ const prototype = Object.getPrototypeOf(value);
11312
+ return prototype === Object.prototype || prototype === null;
11313
+ }
11314
+ function isCapxulResult(value) {
11315
+ return isPlainObject(value) && typeof value.ok === "boolean";
11316
+ }
11317
+ function isFailedResult(value) {
11318
+ return isCapxulResult(value) && value.ok === false && "error" in value;
11319
+ }
11186
11320
  const SDK_VERSION = version;
11187
11321
  const collectProductionFlowPorts = Effect.gen(function* () {
11188
11322
  const authClient = yield* AuthClientPortTag;
@@ -11452,9 +11586,9 @@ function wireOpenfortSignerLifecycle(client, signer) {
11452
11586
  }
11453
11587
  async function createCapxulClient(input) {
11454
11588
  const validation = validateCreateCapxulClientInput(input);
11455
- if (!validation.ok) return validation;
11589
+ if (!validation.ok) return observeFailedResult(validation, input.observation, "createCapxulClient");
11456
11590
  const adapters = await createProductionAdapters(input);
11457
- if (!adapters.ok) return adapters;
11591
+ if (!adapters.ok) return observeFailedResult(adapters, input.observation, "createCapxulClient");
11458
11592
  try {
11459
11593
  const runtime = input.runtime ?? detectRuntime();
11460
11594
  const resolvedAuthBaseUrl = resolveBrowserAuthBaseUrl({
@@ -11480,7 +11614,7 @@ async function createCapxulClient(input) {
11480
11614
  const upstreamClose = adapters.value.close;
11481
11615
  return {
11482
11616
  ok: true,
11483
- value: {
11617
+ value: observeSdkClient({
11484
11618
  ...client,
11485
11619
  _internal: {
11486
11620
  ...client._internal,
@@ -11489,14 +11623,14 @@ async function createCapxulClient(input) {
11489
11623
  await upstreamClose();
11490
11624
  }
11491
11625
  }
11492
- }
11626
+ }, input.observation)
11493
11627
  };
11494
11628
  } catch (cause) {
11495
11629
  await adapters.value.close().catch(() => void 0);
11496
- return {
11630
+ return observeFailedResult({
11497
11631
  ok: false,
11498
11632
  error: toPublicError$1(cause, "createCapxulClient")
11499
- };
11633
+ }, input.observation, "createCapxulClient");
11500
11634
  }
11501
11635
  }
11502
11636
  function validateCreateCapxulClientInput(input) {
@@ -11644,7 +11778,7 @@ function idempotentClose(close) {
11644
11778
  async function createCapxulClientWithOrgDeploymentSeams(input) {
11645
11779
  const { orgDeploymentPortFactory, orgDeploymentConfig, ...productionInput } = input;
11646
11780
  const adapters = await createProductionAdapters(productionInput);
11647
- if (!adapters.ok) return adapters;
11781
+ if (!adapters.ok) return observeFailedResult(adapters, productionInput.observation, "createCapxulClientWithOrgDeploymentSeams");
11648
11782
  try {
11649
11783
  const orgDeploymentPort = orgDeploymentPortFactory(adapters.value.ports.convexCall);
11650
11784
  const client = assembleCapxulClient({
@@ -11663,20 +11797,20 @@ async function createCapxulClientWithOrgDeploymentSeams(input) {
11663
11797
  });
11664
11798
  return {
11665
11799
  ok: true,
11666
- value: {
11800
+ value: observeSdkClient({
11667
11801
  ...client,
11668
11802
  _internal: {
11669
11803
  ...client._internal,
11670
11804
  close: adapters.value.close
11671
11805
  }
11672
- }
11806
+ }, productionInput.observation)
11673
11807
  };
11674
11808
  } catch (cause) {
11675
11809
  await adapters.value.close().catch(() => void 0);
11676
- return {
11810
+ return observeFailedResult({
11677
11811
  ok: false,
11678
11812
  error: toPublicError(cause, "createCapxulClientWithOrgDeploymentSeams")
11679
- };
11813
+ }, productionInput.observation, "createCapxulClientWithOrgDeploymentSeams");
11680
11814
  }
11681
11815
  }
11682
11816
  function toPublicError(cause, operation) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capxul/mcp",
3
- "version": "1.0.0-alpha.15",
3
+ "version": "1.0.0-alpha.16",
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": [
@@ -54,7 +54,7 @@
54
54
  "vite-plus": "0.1.23",
55
55
  "@capxul/backend": "0.1.0-alpha.2",
56
56
  "@capxul/config": "0.1.0-alpha.1",
57
- "@capxul/sdk": "1.0.0-alpha.15",
57
+ "@capxul/sdk": "1.0.0-alpha.16",
58
58
  "@capxul/types": "0.1.0-alpha.0",
59
59
  "@capxul/wire": "0.1.0-alpha.1",
60
60
  "@capxul/errors": "0.0.0",