@capxul/mcp 1.0.0-alpha.15 → 1.0.0-alpha.17
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.
- package/dist/main.mjs +351 -27
- 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.
|
|
235
|
+
var version$1 = "1.0.0-alpha.17";
|
|
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. */
|
|
@@ -1609,6 +1609,73 @@ function redactError(error, operation, replace) {
|
|
|
1609
1609
|
};
|
|
1610
1610
|
}
|
|
1611
1611
|
//#endregion
|
|
1612
|
+
//#region ../../packages/wire/src/observation-context.ts
|
|
1613
|
+
/** Single bounded HTTP carrier used before a Convex action envelope exists. */
|
|
1614
|
+
const OBSERVATION_CONTEXT_HEADER = "x-capxul-observation-context";
|
|
1615
|
+
const FIELD_RULES = {
|
|
1616
|
+
application: {
|
|
1617
|
+
maxLength: 64,
|
|
1618
|
+
pattern: /^[A-Za-z0-9][A-Za-z0-9._-]*$/u
|
|
1619
|
+
},
|
|
1620
|
+
applicationId: {
|
|
1621
|
+
maxLength: 30,
|
|
1622
|
+
pattern: APP_ID_RE
|
|
1623
|
+
},
|
|
1624
|
+
release: {
|
|
1625
|
+
maxLength: 128,
|
|
1626
|
+
pattern: /^[A-Za-z0-9][A-Za-z0-9._+@:/-]*$/u
|
|
1627
|
+
},
|
|
1628
|
+
sessionId: {
|
|
1629
|
+
maxLength: 128,
|
|
1630
|
+
pattern: /^[A-Za-z0-9][A-Za-z0-9._:-]*$/u
|
|
1631
|
+
},
|
|
1632
|
+
organizationId: {
|
|
1633
|
+
maxLength: 128,
|
|
1634
|
+
pattern: /^[A-Za-z0-9][A-Za-z0-9._:-]*$/u
|
|
1635
|
+
},
|
|
1636
|
+
correlationId: {
|
|
1637
|
+
maxLength: 128,
|
|
1638
|
+
pattern: /^[A-Za-z0-9][A-Za-z0-9._:-]*$/u
|
|
1639
|
+
},
|
|
1640
|
+
anonymousId: {
|
|
1641
|
+
maxLength: 128,
|
|
1642
|
+
pattern: /^anon_[A-Za-z0-9-]+$/u
|
|
1643
|
+
}
|
|
1644
|
+
};
|
|
1645
|
+
const EMBEDDED_WALLET_MATERIAL = /0x[a-fA-F0-9]{40,}/u;
|
|
1646
|
+
const RAW_PRIVATE_KEY_MATERIAL = /(?:^|[^a-fA-F0-9])[a-fA-F0-9]{64}(?:$|[^a-fA-F0-9])/u;
|
|
1647
|
+
const COMPACT_JWT = /eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/u;
|
|
1648
|
+
const KNOWN_CREDENTIAL_PREFIX = /(?:(?:sk|pk|rk)_(?:live|test)|(?:phc|phx|ghp|gho|ghu|ghs|ghr|whsec)_|github_pat_|xox[baprs]-|AKIA[0-9A-Z]{16}|AIza)[A-Za-z0-9_-]*/iu;
|
|
1649
|
+
/**
|
|
1650
|
+
* Copy only the canonical allowlist and silently omit malformed/sensitive
|
|
1651
|
+
* values. Observation metadata is best effort and may never reject a domain
|
|
1652
|
+
* operation.
|
|
1653
|
+
*/
|
|
1654
|
+
function sanitizeObservationContext(input) {
|
|
1655
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) return void 0;
|
|
1656
|
+
const source = input;
|
|
1657
|
+
const sanitized = {};
|
|
1658
|
+
for (const field of Object.keys(FIELD_RULES)) {
|
|
1659
|
+
const value = source[field];
|
|
1660
|
+
if (!isSafeField(field, value)) continue;
|
|
1661
|
+
sanitized[field] = value;
|
|
1662
|
+
}
|
|
1663
|
+
return Object.keys(sanitized).length === 0 ? void 0 : sanitized;
|
|
1664
|
+
}
|
|
1665
|
+
/** Encode only the sanitized allowlist; absence stays absence. */
|
|
1666
|
+
function encodeObservationContextHeader(input) {
|
|
1667
|
+
const sanitized = sanitizeObservationContext(input);
|
|
1668
|
+
return sanitized === void 0 ? void 0 : JSON.stringify(sanitized);
|
|
1669
|
+
}
|
|
1670
|
+
function isSafeField(field, value) {
|
|
1671
|
+
if (typeof value !== "string") return false;
|
|
1672
|
+
const rule = FIELD_RULES[field];
|
|
1673
|
+
return value.length > 0 && value.length <= rule.maxLength && value === value.trim() && !value.includes("://") && !containsSensitiveMaterial(value) && rule.pattern.test(value);
|
|
1674
|
+
}
|
|
1675
|
+
function containsSensitiveMaterial(value) {
|
|
1676
|
+
return EMBEDDED_WALLET_MATERIAL.test(value) || RAW_PRIVATE_KEY_MATERIAL.test(value) || COMPACT_JWT.test(value) || KNOWN_CREDENTIAL_PREFIX.test(value);
|
|
1677
|
+
}
|
|
1678
|
+
//#endregion
|
|
1612
1679
|
//#region src/payment-wire.ts
|
|
1613
1680
|
const MONEY_RE$1 = /^\s*([0-9]+(?:\.[0-9]+)?)\s+([A-Za-z][A-Za-z0-9]*)\s*$/;
|
|
1614
1681
|
const MONEY_SCHEMA = z.object({
|
|
@@ -5192,7 +5259,7 @@ async function recoverRawDigestSigner(input) {
|
|
|
5192
5259
|
}
|
|
5193
5260
|
//#endregion
|
|
5194
5261
|
//#region ../../packages/sdk/package.json
|
|
5195
|
-
var version = "1.0.0-alpha.
|
|
5262
|
+
var version = "1.0.0-alpha.17";
|
|
5196
5263
|
//#endregion
|
|
5197
5264
|
//#region ../../packages/sdk/src/ports/auth-client.ts
|
|
5198
5265
|
var AuthClientError = class extends Data.TaggedError("AuthClientError") {};
|
|
@@ -5219,11 +5286,11 @@ function fromResult(operation, run) {
|
|
|
5219
5286
|
})
|
|
5220
5287
|
}).pipe(Effect.flatMap((result) => result.ok ? Effect.succeed(result.value) : Effect.fail(new AuthClientError({
|
|
5221
5288
|
operation,
|
|
5222
|
-
kind: errorKind(result.error),
|
|
5289
|
+
kind: errorKind$1(result.error),
|
|
5223
5290
|
cause: result.error
|
|
5224
5291
|
}))));
|
|
5225
5292
|
}
|
|
5226
|
-
function errorKind(error) {
|
|
5293
|
+
function errorKind$1(error) {
|
|
5227
5294
|
if (error.code === "CANCELLED") return "cancelled";
|
|
5228
5295
|
if (error.code === "NETWORK_ERROR") return "network";
|
|
5229
5296
|
if (error.code === "INVALID_INPUT" || error.code === "OTP_EXPIRED") return "validation";
|
|
@@ -5238,6 +5305,18 @@ function resolveAuthClientUrl(authBaseUrl, path) {
|
|
|
5238
5305
|
return `${base}${path}`;
|
|
5239
5306
|
}
|
|
5240
5307
|
//#endregion
|
|
5308
|
+
//#region ../../packages/sdk/src/internal/observation-http.ts
|
|
5309
|
+
/** Resolve one bounded pre-auth snapshot for an outbound SDK HTTP request. */
|
|
5310
|
+
function observationRequestHeaders(adapter) {
|
|
5311
|
+
if (adapter === void 0) return {};
|
|
5312
|
+
try {
|
|
5313
|
+
const encoded = encodeObservationContextHeader(adapter.resolveContext?.());
|
|
5314
|
+
return encoded === void 0 ? {} : { [OBSERVATION_CONTEXT_HEADER]: encoded };
|
|
5315
|
+
} catch {
|
|
5316
|
+
return {};
|
|
5317
|
+
}
|
|
5318
|
+
}
|
|
5319
|
+
//#endregion
|
|
5241
5320
|
//#region ../../packages/sdk/src/adapters/auth-client/BetterAuthBrowserAdapter.ts
|
|
5242
5321
|
function withSignal$1(init, signal) {
|
|
5243
5322
|
return signal === void 0 ? init : {
|
|
@@ -5295,8 +5374,10 @@ function mapFetchError$1(operation, err, signal) {
|
|
|
5295
5374
|
var BetterAuthBrowserAdapter = class {
|
|
5296
5375
|
authBaseUrl;
|
|
5297
5376
|
fetchImpl;
|
|
5377
|
+
observation;
|
|
5298
5378
|
constructor(deps) {
|
|
5299
5379
|
this.authBaseUrl = deps.authBaseUrl.replace(/\/$/, "");
|
|
5380
|
+
this.observation = deps.observation;
|
|
5300
5381
|
this.fetchImpl = deps.fetch ?? ((input, init) => globalThis.fetch(input, init));
|
|
5301
5382
|
}
|
|
5302
5383
|
url(path) {
|
|
@@ -5323,7 +5404,10 @@ var BetterAuthBrowserAdapter = class {
|
|
|
5323
5404
|
try {
|
|
5324
5405
|
const res = await this.fetchImpl(this.url("/api/auth/email-otp/send-verification-otp"), withSignal$1({
|
|
5325
5406
|
method: "POST",
|
|
5326
|
-
headers: {
|
|
5407
|
+
headers: {
|
|
5408
|
+
"Content-Type": "application/json",
|
|
5409
|
+
...observationRequestHeaders(this.observation)
|
|
5410
|
+
},
|
|
5327
5411
|
body: JSON.stringify({
|
|
5328
5412
|
email: input.email,
|
|
5329
5413
|
type: "sign-in"
|
|
@@ -5697,12 +5781,14 @@ var BetterAuthNodeAdapter = class {
|
|
|
5697
5781
|
origin;
|
|
5698
5782
|
cookieJar;
|
|
5699
5783
|
fetchImpl;
|
|
5784
|
+
observation;
|
|
5700
5785
|
constructor(deps) {
|
|
5701
5786
|
this.authBaseUrl = deps.authBaseUrl.replace(/\/$/, "");
|
|
5702
5787
|
this.host = hostFromBaseUrl(this.authBaseUrl);
|
|
5703
5788
|
this.origin = deps.origin?.replace(/\/$/, "");
|
|
5704
5789
|
this.cookieJar = deps.cookieJar ?? new CookieJar();
|
|
5705
5790
|
this.fetchImpl = deps.fetch ?? fetch;
|
|
5791
|
+
this.observation = deps.observation;
|
|
5706
5792
|
}
|
|
5707
5793
|
url(path) {
|
|
5708
5794
|
return resolveAuthClientUrl(this.authBaseUrl, path);
|
|
@@ -5737,7 +5823,8 @@ var BetterAuthNodeAdapter = class {
|
|
|
5737
5823
|
method: "POST",
|
|
5738
5824
|
headers: {
|
|
5739
5825
|
"content-type": "application/json",
|
|
5740
|
-
...this.origin ? { origin: this.origin } : {}
|
|
5826
|
+
...this.origin ? { origin: this.origin } : {},
|
|
5827
|
+
...observationRequestHeaders(this.observation)
|
|
5741
5828
|
},
|
|
5742
5829
|
body: JSON.stringify({
|
|
5743
5830
|
email: input.email,
|
|
@@ -5978,8 +6065,10 @@ async function safeText(res) {
|
|
|
5978
6065
|
var HttpBootstrapAdapter = class {
|
|
5979
6066
|
bootstrapBaseUrl;
|
|
5980
6067
|
fetchImpl;
|
|
6068
|
+
observation;
|
|
5981
6069
|
constructor(deps) {
|
|
5982
6070
|
this.bootstrapBaseUrl = deps.bootstrapBaseUrl.replace(/\/$/, "");
|
|
6071
|
+
this.observation = deps.observation;
|
|
5983
6072
|
this.fetchImpl = deps.fetch ?? ((input, init) => globalThis.fetch(input, init));
|
|
5984
6073
|
}
|
|
5985
6074
|
resolve(input) {
|
|
@@ -5987,7 +6076,8 @@ var HttpBootstrapAdapter = class {
|
|
|
5987
6076
|
try: () => {
|
|
5988
6077
|
const headers = {
|
|
5989
6078
|
"content-type": "application/json",
|
|
5990
|
-
...input.origin === void 0 ? {} : { origin: input.origin }
|
|
6079
|
+
...input.origin === void 0 ? {} : { origin: input.origin },
|
|
6080
|
+
...observationRequestHeaders(this.observation)
|
|
5991
6081
|
};
|
|
5992
6082
|
return this.fetchImpl(`${this.bootstrapBaseUrl}/v1/client/bootstrap`, {
|
|
5993
6083
|
method: "POST",
|
|
@@ -6081,13 +6171,54 @@ function convexCallErrorFromCapxul(operation, error) {
|
|
|
6081
6171
|
}
|
|
6082
6172
|
var ConvexCallPortTag = class extends Context.Tag("@capxul/sdk/ports/ConvexCallPort")() {};
|
|
6083
6173
|
//#endregion
|
|
6174
|
+
//#region ../../packages/sdk/src/internal/invocation-observation.ts
|
|
6175
|
+
const INVOCATION_OBSERVATION = Symbol("capxul.invocation-observation");
|
|
6176
|
+
const FAILURE_INVOCATION_SNAPSHOT = Symbol("capxul.failure-invocation-snapshot");
|
|
6177
|
+
/** @internal Attach one immutable, non-wire invocation snapshot to an SDK-owned object. */
|
|
6178
|
+
function attachInvocationObservation(target, context) {
|
|
6179
|
+
const snapshot = Object.freeze(context === void 0 ? {} : { context: Object.freeze({ ...context }) });
|
|
6180
|
+
Object.defineProperty(target, INVOCATION_OBSERVATION, {
|
|
6181
|
+
configurable: false,
|
|
6182
|
+
enumerable: false,
|
|
6183
|
+
value: snapshot,
|
|
6184
|
+
writable: false
|
|
6185
|
+
});
|
|
6186
|
+
return target;
|
|
6187
|
+
}
|
|
6188
|
+
/** @internal Read the snapshot without exposing its symbol or adding a wire field. */
|
|
6189
|
+
function readInvocationObservation(source) {
|
|
6190
|
+
if (typeof source !== "object" || source === null) return void 0;
|
|
6191
|
+
return source[INVOCATION_OBSERVATION];
|
|
6192
|
+
}
|
|
6193
|
+
/** @internal Carry a snapshot across an SDK adapter projection without resolving again. */
|
|
6194
|
+
function copyInvocationObservation(source, target) {
|
|
6195
|
+
const snapshot = readInvocationObservation(source);
|
|
6196
|
+
return snapshot === void 0 ? target : attachInvocationObservation(target, snapshot.context);
|
|
6197
|
+
}
|
|
6198
|
+
/** @internal Mark a failure envelope as already resolved at the public invocation boundary. */
|
|
6199
|
+
function markFailureInvocationSnapshot(failure) {
|
|
6200
|
+
Object.defineProperty(failure, FAILURE_INVOCATION_SNAPSHOT, {
|
|
6201
|
+
configurable: false,
|
|
6202
|
+
enumerable: false,
|
|
6203
|
+
value: true,
|
|
6204
|
+
writable: false
|
|
6205
|
+
});
|
|
6206
|
+
return failure;
|
|
6207
|
+
}
|
|
6208
|
+
//#endregion
|
|
6084
6209
|
//#region ../../packages/sdk/src/adapters/convex-call/ConvexCallAdapter.ts
|
|
6210
|
+
/** Exact floor-first allowlist; every additional handler must migrate its validator first. */
|
|
6211
|
+
const OBSERVED_CONVEX_ACTIONS = new Set(["subAccount/actions:transfer"]);
|
|
6085
6212
|
var ConvexCallAdapter = class {
|
|
6086
6213
|
#client;
|
|
6087
6214
|
#tokenProvider;
|
|
6215
|
+
#applicationId;
|
|
6216
|
+
#observation;
|
|
6088
6217
|
constructor(deps) {
|
|
6089
6218
|
this.#client = deps.client ?? new ConvexClient(deps.convexUrl);
|
|
6090
6219
|
this.#tokenProvider = deps.tokenProvider;
|
|
6220
|
+
this.#applicationId = deps.applicationId;
|
|
6221
|
+
this.#observation = deps.observation;
|
|
6091
6222
|
if (this.#tokenProvider) this.#client.setAuth(this.#tokenProvider);
|
|
6092
6223
|
}
|
|
6093
6224
|
refreshAuth() {
|
|
@@ -6106,11 +6237,37 @@ var ConvexCallAdapter = class {
|
|
|
6106
6237
|
});
|
|
6107
6238
|
}
|
|
6108
6239
|
action(fn, args) {
|
|
6240
|
+
const path = getFunctionName(fn);
|
|
6109
6241
|
return Effect.tryPromise({
|
|
6110
|
-
try: () => this.#client.action(fn, args),
|
|
6111
|
-
catch: (cause) => mapToConvexCallError(
|
|
6242
|
+
try: () => this.#client.action(fn, this.#observedActionArgs(path, args)),
|
|
6243
|
+
catch: (cause) => mapToConvexCallError(path, cause)
|
|
6112
6244
|
});
|
|
6113
6245
|
}
|
|
6246
|
+
#observedActionArgs(path, args) {
|
|
6247
|
+
if (!OBSERVED_CONVEX_ACTIONS.has(path)) return args;
|
|
6248
|
+
let hostContext;
|
|
6249
|
+
const invocationSnapshot = readInvocationObservation(args);
|
|
6250
|
+
if (invocationSnapshot !== void 0) hostContext = invocationSnapshot.context;
|
|
6251
|
+
else {
|
|
6252
|
+
const resolveContext = this.#observation?.resolveContext;
|
|
6253
|
+
if (resolveContext === void 0) return args;
|
|
6254
|
+
try {
|
|
6255
|
+
hostContext = resolveContext();
|
|
6256
|
+
} catch {
|
|
6257
|
+
return args;
|
|
6258
|
+
}
|
|
6259
|
+
}
|
|
6260
|
+
if (hostContext === void 0) return args;
|
|
6261
|
+
hostContext = sanitizeObservationContext({
|
|
6262
|
+
...hostContext,
|
|
6263
|
+
...this.#applicationId === void 0 ? {} : { applicationId: this.#applicationId }
|
|
6264
|
+
});
|
|
6265
|
+
if (hostContext === void 0) return args;
|
|
6266
|
+
return {
|
|
6267
|
+
...args,
|
|
6268
|
+
observationContext: hostContext
|
|
6269
|
+
};
|
|
6270
|
+
}
|
|
6114
6271
|
subscribe(fn, args, callback) {
|
|
6115
6272
|
return Effect.try({
|
|
6116
6273
|
try: () => {
|
|
@@ -6882,12 +7039,12 @@ var ConvexSubAccountAdapter = class {
|
|
|
6882
7039
|
const operation = "transfer";
|
|
6883
7040
|
return Effect.suspend(() => {
|
|
6884
7041
|
const rawAmount = toWei(input.amount);
|
|
6885
|
-
return this.#convex.action(this.#fns.transfer, {
|
|
7042
|
+
return this.#convex.action(this.#fns.transfer, copyInvocationObservation(input, {
|
|
6886
7043
|
chainId: this.#chainId,
|
|
6887
7044
|
from: input.from,
|
|
6888
7045
|
to: input.to,
|
|
6889
7046
|
rawAmount
|
|
6890
|
-
});
|
|
7047
|
+
}));
|
|
6891
7048
|
}).pipe(Effect.mapError((error) => subAccountErrorFromCapxul(operation, error.publicError, error)), Effect.map((wire) => brandTransferResult(wire)), Effect.catchAllDefect((cause) => Effect.fail(subAccountErrorFromUnknown(operation, cause))));
|
|
6892
7049
|
}
|
|
6893
7050
|
#runMutation(operation, ref, args) {
|
|
@@ -7184,6 +7341,10 @@ const TransferRequestedProps = Schema.Struct({
|
|
|
7184
7341
|
amount: OptionalWeiAmount,
|
|
7185
7342
|
direction: OptionalTransferDirection
|
|
7186
7343
|
});
|
|
7344
|
+
const TransferBackendReceivedProps = Schema.Struct({
|
|
7345
|
+
...TelemetryEnvelopeProps,
|
|
7346
|
+
direction: OptionalTransferDirection
|
|
7347
|
+
});
|
|
7187
7348
|
const TransferConfirmedProps = Schema.Struct({
|
|
7188
7349
|
...TelemetryEnvelopeProps,
|
|
7189
7350
|
amount: OptionalWeiAmount,
|
|
@@ -7400,6 +7561,10 @@ Schema.Struct({
|
|
|
7400
7561
|
name: Schema.Literal("transfer_requested"),
|
|
7401
7562
|
props: Schema.optional(TransferRequestedProps)
|
|
7402
7563
|
});
|
|
7564
|
+
Schema.Struct({
|
|
7565
|
+
name: Schema.Literal("transfer_backend_received"),
|
|
7566
|
+
props: Schema.optional(TransferBackendReceivedProps)
|
|
7567
|
+
});
|
|
7403
7568
|
Schema.Struct({
|
|
7404
7569
|
name: Schema.Literal("transfer_confirmed"),
|
|
7405
7570
|
props: Schema.optional(TransferConfirmedProps)
|
|
@@ -11183,6 +11348,158 @@ function assembleCapxulClient(input) {
|
|
|
11183
11348
|
}
|
|
11184
11349
|
};
|
|
11185
11350
|
}
|
|
11351
|
+
//#endregion
|
|
11352
|
+
//#region ../../packages/sdk/src/observation.ts
|
|
11353
|
+
const SDK_VERSION$1 = version;
|
|
11354
|
+
/** @internal Decorates public client method bundles at the owning SDK boundary. */
|
|
11355
|
+
function observeSdkClient(client, adapter) {
|
|
11356
|
+
if (adapter === void 0) return client;
|
|
11357
|
+
const objectProxies = /* @__PURE__ */ new WeakMap();
|
|
11358
|
+
const functionWrappers = /* @__PURE__ */ new WeakMap();
|
|
11359
|
+
const wrapObject = (target, path, internal = false) => {
|
|
11360
|
+
const cacheKey = `${internal ? "internal" : "public"}:${path.join(".")}`;
|
|
11361
|
+
let targetProxies = objectProxies.get(target);
|
|
11362
|
+
const cached = targetProxies?.get(cacheKey);
|
|
11363
|
+
if (cached !== void 0) return cached;
|
|
11364
|
+
const proxy = new Proxy(target, { get(currentTarget, property, receiver) {
|
|
11365
|
+
const value = Reflect.get(currentTarget, property, receiver);
|
|
11366
|
+
if (typeof property !== "string") return value;
|
|
11367
|
+
if (path.length === 0 && property === "_internal" && isPlainObject(value)) return wrapInternal(value);
|
|
11368
|
+
if (internal && property !== "accounts") return value;
|
|
11369
|
+
return wrapValue(value, [...path, property], currentTarget);
|
|
11370
|
+
} });
|
|
11371
|
+
if (targetProxies === void 0) {
|
|
11372
|
+
targetProxies = /* @__PURE__ */ new Map();
|
|
11373
|
+
objectProxies.set(target, targetProxies);
|
|
11374
|
+
}
|
|
11375
|
+
targetProxies.set(cacheKey, proxy);
|
|
11376
|
+
return proxy;
|
|
11377
|
+
};
|
|
11378
|
+
const wrapInternal = (target) => wrapObject(target, ["_internal"], true);
|
|
11379
|
+
const wrapValue = (value, path, owner) => {
|
|
11380
|
+
if (typeof value === "function") {
|
|
11381
|
+
const callable = value;
|
|
11382
|
+
const operation = path.join(".");
|
|
11383
|
+
let ownerWrappers = functionWrappers.get(owner);
|
|
11384
|
+
if (ownerWrappers === void 0) {
|
|
11385
|
+
ownerWrappers = /* @__PURE__ */ new Map();
|
|
11386
|
+
functionWrappers.set(owner, ownerWrappers);
|
|
11387
|
+
}
|
|
11388
|
+
const cached = ownerWrappers.get(operation);
|
|
11389
|
+
if (cached !== void 0) return cached;
|
|
11390
|
+
const wrapped = new Proxy(callable, {
|
|
11391
|
+
apply(currentTarget, _thisArg, args) {
|
|
11392
|
+
const invocationContext = resolveAdapterContext(adapter);
|
|
11393
|
+
const invocationArgs = carryInvocationContext(operation, args, invocationContext);
|
|
11394
|
+
let output;
|
|
11395
|
+
try {
|
|
11396
|
+
output = Reflect.apply(currentTarget, owner, invocationArgs);
|
|
11397
|
+
} catch (cause) {
|
|
11398
|
+
report(adapter, "exception", operation, cause, invocationContext);
|
|
11399
|
+
throw cause;
|
|
11400
|
+
}
|
|
11401
|
+
if (isPromiseLike(output)) return Promise.resolve(output).then((result) => processOutput(result, path, invocationContext), (cause) => {
|
|
11402
|
+
report(adapter, "exception", operation, cause, invocationContext);
|
|
11403
|
+
throw cause;
|
|
11404
|
+
});
|
|
11405
|
+
return processOutput(output, path, invocationContext);
|
|
11406
|
+
},
|
|
11407
|
+
get(currentTarget, property) {
|
|
11408
|
+
const attached = Reflect.get(currentTarget, property, currentTarget);
|
|
11409
|
+
if (typeof property !== "string") return attached;
|
|
11410
|
+
return wrapValue(attached, [...path, property], currentTarget);
|
|
11411
|
+
}
|
|
11412
|
+
});
|
|
11413
|
+
ownerWrappers.set(operation, wrapped);
|
|
11414
|
+
return wrapped;
|
|
11415
|
+
}
|
|
11416
|
+
return isPlainObject(value) ? wrapObject(value, path) : value;
|
|
11417
|
+
};
|
|
11418
|
+
const processOutput = (output, path, invocationContext) => {
|
|
11419
|
+
if (isFailedResult(output)) {
|
|
11420
|
+
report(adapter, "operation", path.join("."), output.error, invocationContext);
|
|
11421
|
+
return output;
|
|
11422
|
+
}
|
|
11423
|
+
if (isCapxulResult(output)) return output;
|
|
11424
|
+
return isPlainObject(output) ? wrapObject(output, path) : output;
|
|
11425
|
+
};
|
|
11426
|
+
return wrapObject(client, []);
|
|
11427
|
+
}
|
|
11428
|
+
function carryInvocationContext(operation, args, context) {
|
|
11429
|
+
if (operation !== "subAccounts.transfer" || !isPlainObject(args[0])) return args;
|
|
11430
|
+
return [attachInvocationObservation({ ...args[0] }, context), ...args.slice(1)];
|
|
11431
|
+
}
|
|
11432
|
+
/** @internal Reports a factory-level typed failure without changing its identity. */
|
|
11433
|
+
function observeFailedResult(result, adapter, operation) {
|
|
11434
|
+
if (adapter !== void 0 && isFailedResult(result)) report(adapter, "operation", operation, result.error, resolveAdapterContext(adapter));
|
|
11435
|
+
return result;
|
|
11436
|
+
}
|
|
11437
|
+
function report(adapter, kind, operation, cause, invocationContext) {
|
|
11438
|
+
const operationName = normalizeOperation(operation);
|
|
11439
|
+
const kindName = normalizeErrorKind(errorKind(cause));
|
|
11440
|
+
const context = sanitizeObservationContext({
|
|
11441
|
+
...invocationContext,
|
|
11442
|
+
...isCapxulError(cause) && cause.correlationId !== void 0 ? { correlationId: cause.correlationId } : {}
|
|
11443
|
+
});
|
|
11444
|
+
const failure = markFailureInvocationSnapshot({
|
|
11445
|
+
exception: syntheticException(operationName, kindName),
|
|
11446
|
+
sdkVersion: SDK_VERSION$1,
|
|
11447
|
+
operation: operationName,
|
|
11448
|
+
errorKind: kindName,
|
|
11449
|
+
...context === void 0 ? {} : { context }
|
|
11450
|
+
});
|
|
11451
|
+
try {
|
|
11452
|
+
ignoreDeliveryFailure(kind === "operation" ? adapter.captureOperationFailure(failure) : adapter.captureException(failure));
|
|
11453
|
+
} catch {}
|
|
11454
|
+
}
|
|
11455
|
+
function resolveAdapterContext(adapter) {
|
|
11456
|
+
try {
|
|
11457
|
+
return sanitizeObservationContext(adapter.resolveContext?.());
|
|
11458
|
+
} catch {
|
|
11459
|
+
return;
|
|
11460
|
+
}
|
|
11461
|
+
}
|
|
11462
|
+
function ignoreDeliveryFailure(delivery) {
|
|
11463
|
+
if (!isPromiseLike(delivery)) return;
|
|
11464
|
+
try {
|
|
11465
|
+
Promise.resolve(delivery).catch(() => void 0);
|
|
11466
|
+
} catch {}
|
|
11467
|
+
}
|
|
11468
|
+
function errorKind(cause) {
|
|
11469
|
+
try {
|
|
11470
|
+
if (isCapxulError(cause)) return normalizeErrorKind(cause.code);
|
|
11471
|
+
if (cause instanceof Error) return normalizeErrorKind(cause.name);
|
|
11472
|
+
return "UnknownFailure";
|
|
11473
|
+
} catch {
|
|
11474
|
+
return "Error";
|
|
11475
|
+
}
|
|
11476
|
+
}
|
|
11477
|
+
function normalizeOperation(value) {
|
|
11478
|
+
return typeof value === "string" && /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,255}$/u.test(value) ? value : "unknown";
|
|
11479
|
+
}
|
|
11480
|
+
function normalizeErrorKind(value) {
|
|
11481
|
+
return typeof value === "string" && /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/u.test(value) ? value : "Error";
|
|
11482
|
+
}
|
|
11483
|
+
function syntheticException(operation, kind) {
|
|
11484
|
+
const error = /* @__PURE__ */ new Error("Capxul SDK operation failed");
|
|
11485
|
+
error.name = kind;
|
|
11486
|
+
error.stack = `${kind}: ${error.message}\n at CapxulSdkBoundary.${operation} (capxul-sdk-observation://boundary/${operation}:1:1)`;
|
|
11487
|
+
return error;
|
|
11488
|
+
}
|
|
11489
|
+
function isPromiseLike(value) {
|
|
11490
|
+
return (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
|
|
11491
|
+
}
|
|
11492
|
+
function isPlainObject(value) {
|
|
11493
|
+
if (typeof value !== "object" || value === null) return false;
|
|
11494
|
+
const prototype = Object.getPrototypeOf(value);
|
|
11495
|
+
return prototype === Object.prototype || prototype === null;
|
|
11496
|
+
}
|
|
11497
|
+
function isCapxulResult(value) {
|
|
11498
|
+
return isPlainObject(value) && typeof value.ok === "boolean";
|
|
11499
|
+
}
|
|
11500
|
+
function isFailedResult(value) {
|
|
11501
|
+
return isCapxulResult(value) && value.ok === false && "error" in value;
|
|
11502
|
+
}
|
|
11186
11503
|
const SDK_VERSION = version;
|
|
11187
11504
|
const collectProductionFlowPorts = Effect.gen(function* () {
|
|
11188
11505
|
const authClient = yield* AuthClientPortTag;
|
|
@@ -11290,11 +11607,13 @@ function productionBootstrapPortLayer(bootstrap) {
|
|
|
11290
11607
|
function productionAuthClientLayer(input, refreshConvexAuthRef) {
|
|
11291
11608
|
return (input.runtime === "browser" ? BetterAuthBrowserLayer({
|
|
11292
11609
|
authBaseUrl: input.runtimeUrls.authBaseUrl,
|
|
11293
|
-
...input.fetch === void 0 ? {} : { fetch: input.fetch }
|
|
11610
|
+
...input.fetch === void 0 ? {} : { fetch: input.fetch },
|
|
11611
|
+
...input.observation === void 0 ? {} : { observation: input.observation }
|
|
11294
11612
|
}) : BetterAuthNodeLayer({
|
|
11295
11613
|
authBaseUrl: input.runtimeUrls.authBaseUrl,
|
|
11296
11614
|
...input.origin === void 0 ? {} : { origin: input.origin },
|
|
11297
|
-
...input.fetch === void 0 ? {} : { fetch: input.fetch }
|
|
11615
|
+
...input.fetch === void 0 ? {} : { fetch: input.fetch },
|
|
11616
|
+
...input.observation === void 0 ? {} : { observation: input.observation }
|
|
11298
11617
|
})).pipe(Layer.map((context) => {
|
|
11299
11618
|
const authClient = Context.get(context, AuthClientPortTag);
|
|
11300
11619
|
return Context.make(AuthClientPortTag, refreshConvexAuthOnSession(authClient, () => {
|
|
@@ -11313,6 +11632,8 @@ function productionAuthCacheLayer(input) {
|
|
|
11313
11632
|
function productionConvexCallLayer(input, refreshConvexAuthRef) {
|
|
11314
11633
|
return Layer.unwrapEffect(Effect.map(AuthClientPortTag, (authClient) => ConvexCallLayer({
|
|
11315
11634
|
convexUrl: input.runtimeUrls.convexUrl,
|
|
11635
|
+
...input.applicationId === void 0 ? {} : { applicationId: input.applicationId },
|
|
11636
|
+
...input.observation === void 0 ? {} : { observation: input.observation },
|
|
11316
11637
|
...input.convexClient === void 0 ? {} : { client: input.convexClient },
|
|
11317
11638
|
tokenProvider: async ({ forceRefreshToken }) => {
|
|
11318
11639
|
const tokenResult = await Effect.runPromise(Effect.either(authClient.getConvexJwt({
|
|
@@ -11344,7 +11665,8 @@ async function createProductionAdapters(input) {
|
|
|
11344
11665
|
const closeScope = idempotentClose(() => Effect.runPromise(Scope.close(scope, Exit.void)));
|
|
11345
11666
|
const bootstrapLayer = HttpBootstrapLayer({
|
|
11346
11667
|
bootstrapBaseUrl: resolvedInput.value.bootstrapBaseUrl,
|
|
11347
|
-
...input.fetch === void 0 ? {} : { fetch: input.fetch }
|
|
11668
|
+
...input.fetch === void 0 ? {} : { fetch: input.fetch },
|
|
11669
|
+
...input.observation === void 0 ? {} : { observation: input.observation }
|
|
11348
11670
|
});
|
|
11349
11671
|
try {
|
|
11350
11672
|
const bootstrapContext = await Effect.runPromise(Layer.buildWithScope(bootstrapLayer, scope));
|
|
@@ -11402,6 +11724,8 @@ async function createProductionAdapters(input) {
|
|
|
11402
11724
|
...resolvedInput.value.origin === void 0 ? {} : { origin: resolvedInput.value.origin },
|
|
11403
11725
|
runtimeUrls: runtimeUrls.value,
|
|
11404
11726
|
chainId: bootstrapResult.value.chainId,
|
|
11727
|
+
applicationId: bootstrapResult.value.applicationId,
|
|
11728
|
+
...input.observation === void 0 ? {} : { observation: input.observation },
|
|
11405
11729
|
...input.authCache === void 0 ? {} : { authCache: input.authCache },
|
|
11406
11730
|
...input.telemetry === void 0 ? {} : { telemetry: input.telemetry },
|
|
11407
11731
|
...injectedClient === void 0 ? {} : { convexClient: injectedClient },
|
|
@@ -11452,9 +11776,9 @@ function wireOpenfortSignerLifecycle(client, signer) {
|
|
|
11452
11776
|
}
|
|
11453
11777
|
async function createCapxulClient(input) {
|
|
11454
11778
|
const validation = validateCreateCapxulClientInput(input);
|
|
11455
|
-
if (!validation.ok) return validation;
|
|
11779
|
+
if (!validation.ok) return observeFailedResult(validation, input.observation, "createCapxulClient");
|
|
11456
11780
|
const adapters = await createProductionAdapters(input);
|
|
11457
|
-
if (!adapters.ok) return adapters;
|
|
11781
|
+
if (!adapters.ok) return observeFailedResult(adapters, input.observation, "createCapxulClient");
|
|
11458
11782
|
try {
|
|
11459
11783
|
const runtime = input.runtime ?? detectRuntime();
|
|
11460
11784
|
const resolvedAuthBaseUrl = resolveBrowserAuthBaseUrl({
|
|
@@ -11480,7 +11804,7 @@ async function createCapxulClient(input) {
|
|
|
11480
11804
|
const upstreamClose = adapters.value.close;
|
|
11481
11805
|
return {
|
|
11482
11806
|
ok: true,
|
|
11483
|
-
value: {
|
|
11807
|
+
value: observeSdkClient({
|
|
11484
11808
|
...client,
|
|
11485
11809
|
_internal: {
|
|
11486
11810
|
...client._internal,
|
|
@@ -11489,14 +11813,14 @@ async function createCapxulClient(input) {
|
|
|
11489
11813
|
await upstreamClose();
|
|
11490
11814
|
}
|
|
11491
11815
|
}
|
|
11492
|
-
}
|
|
11816
|
+
}, input.observation)
|
|
11493
11817
|
};
|
|
11494
11818
|
} catch (cause) {
|
|
11495
11819
|
await adapters.value.close().catch(() => void 0);
|
|
11496
|
-
return {
|
|
11820
|
+
return observeFailedResult({
|
|
11497
11821
|
ok: false,
|
|
11498
11822
|
error: toPublicError$1(cause, "createCapxulClient")
|
|
11499
|
-
};
|
|
11823
|
+
}, input.observation, "createCapxulClient");
|
|
11500
11824
|
}
|
|
11501
11825
|
}
|
|
11502
11826
|
function validateCreateCapxulClientInput(input) {
|
|
@@ -11644,7 +11968,7 @@ function idempotentClose(close) {
|
|
|
11644
11968
|
async function createCapxulClientWithOrgDeploymentSeams(input) {
|
|
11645
11969
|
const { orgDeploymentPortFactory, orgDeploymentConfig, ...productionInput } = input;
|
|
11646
11970
|
const adapters = await createProductionAdapters(productionInput);
|
|
11647
|
-
if (!adapters.ok) return adapters;
|
|
11971
|
+
if (!adapters.ok) return observeFailedResult(adapters, productionInput.observation, "createCapxulClientWithOrgDeploymentSeams");
|
|
11648
11972
|
try {
|
|
11649
11973
|
const orgDeploymentPort = orgDeploymentPortFactory(adapters.value.ports.convexCall);
|
|
11650
11974
|
const client = assembleCapxulClient({
|
|
@@ -11663,20 +11987,20 @@ async function createCapxulClientWithOrgDeploymentSeams(input) {
|
|
|
11663
11987
|
});
|
|
11664
11988
|
return {
|
|
11665
11989
|
ok: true,
|
|
11666
|
-
value: {
|
|
11990
|
+
value: observeSdkClient({
|
|
11667
11991
|
...client,
|
|
11668
11992
|
_internal: {
|
|
11669
11993
|
...client._internal,
|
|
11670
11994
|
close: adapters.value.close
|
|
11671
11995
|
}
|
|
11672
|
-
}
|
|
11996
|
+
}, productionInput.observation)
|
|
11673
11997
|
};
|
|
11674
11998
|
} catch (cause) {
|
|
11675
11999
|
await adapters.value.close().catch(() => void 0);
|
|
11676
|
-
return {
|
|
12000
|
+
return observeFailedResult({
|
|
11677
12001
|
ok: false,
|
|
11678
12002
|
error: toPublicError(cause, "createCapxulClientWithOrgDeploymentSeams")
|
|
11679
|
-
};
|
|
12003
|
+
}, productionInput.observation, "createCapxulClientWithOrgDeploymentSeams");
|
|
11680
12004
|
}
|
|
11681
12005
|
}
|
|
11682
12006
|
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.
|
|
3
|
+
"version": "1.0.0-alpha.17",
|
|
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.
|
|
57
|
+
"@capxul/sdk": "1.0.0-alpha.17",
|
|
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",
|