@capxul/mcp 1.0.0-alpha.11 → 1.0.0-alpha.12

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 +451 -128
  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.11";
235
+ var version$1 = "1.0.0-alpha.12";
236
236
  //#endregion
237
237
  //#region src/tool-result.ts
238
238
  function okResult(structured) {
@@ -1709,7 +1709,7 @@ const ORG_VIEW = {
1709
1709
  handle: z.string(),
1710
1710
  role: z.string()
1711
1711
  };
1712
- const MEMBER_VIEW$1 = {
1712
+ const MEMBER_VIEW = {
1713
1713
  orgId: z.string(),
1714
1714
  email: z.string(),
1715
1715
  name: z.string().nullable(),
@@ -1782,7 +1782,7 @@ function registerOrgTools(server, deps) {
1782
1782
  sessionToken: z.string(),
1783
1783
  orgId: z.string()
1784
1784
  },
1785
- outputSchema: { members: z.array(z.object(MEMBER_VIEW$1)) }
1785
+ outputSchema: { members: z.array(z.object(MEMBER_VIEW)) }
1786
1786
  }, ({ sessionToken, orgId }) => guarded(async () => {
1787
1787
  const entry = requireSession(deps, sessionToken);
1788
1788
  if (entry === void 0) return errorResult(unknownSessionError$4());
@@ -1816,7 +1816,7 @@ function registerOrgTools(server, deps) {
1816
1816
  email: z.string(),
1817
1817
  role: z.string()
1818
1818
  },
1819
- outputSchema: MEMBER_VIEW$1
1819
+ outputSchema: MEMBER_VIEW
1820
1820
  }, ({ sessionToken, orgId, email, role }) => guarded(async () => {
1821
1821
  const entry = requireSession(deps, sessionToken);
1822
1822
  if (entry === void 0) return errorResult(unknownSessionError$4());
@@ -1838,7 +1838,7 @@ function registerOrgTools(server, deps) {
1838
1838
  email: z.string(),
1839
1839
  role: z.string()
1840
1840
  },
1841
- outputSchema: MEMBER_VIEW$1
1841
+ outputSchema: MEMBER_VIEW
1842
1842
  }, ({ sessionToken, orgId, email, role }) => guarded(async () => {
1843
1843
  const entry = requireSession(deps, sessionToken);
1844
1844
  if (entry === void 0) return errorResult(unknownSessionError$4());
@@ -2515,23 +2515,15 @@ const DESTINATION = z.object({
2515
2515
  counterpartyId: z.string(),
2516
2516
  ref: REF,
2517
2517
  kind: z.enum([
2518
- "bank",
2519
- "mobile-money",
2520
- "wallet"
2518
+ "bank_account",
2519
+ "mobile_money",
2520
+ "external_account"
2521
2521
  ]),
2522
2522
  label: z.string().nullable(),
2523
2523
  payload: DESTINATION_PAYLOAD,
2524
2524
  createdAt: z.number(),
2525
2525
  updatedAt: z.number()
2526
2526
  });
2527
- const MEMBER_VIEW = {
2528
- orgId: z.string(),
2529
- email: z.string(),
2530
- name: z.string().nullable(),
2531
- role: z.string(),
2532
- roleKey: z.string().nullable(),
2533
- status: z.string()
2534
- };
2535
2527
  const PAYROLL_LINE = z.object({
2536
2528
  id: z.string(),
2537
2529
  employee: REF,
@@ -2604,7 +2596,6 @@ function registerSdkRestartTools(server, deps) {
2604
2596
  registerInsightsTools(server, deps, "org");
2605
2597
  registerDestinationTools(server, deps);
2606
2598
  registerMoneyTools(server, deps);
2607
- registerOrgTailTools(server, deps);
2608
2599
  registerPayrollTools(server, deps);
2609
2600
  }
2610
2601
  function registerAddressBookTools(server, deps, scope) {
@@ -2837,15 +2828,15 @@ function registerDestinationTools(server, deps) {
2837
2828
  }));
2838
2829
  server.registerTool("destinations.add", {
2839
2830
  title: "Add destination",
2840
- description: "Attach a bank, mobile-money, or wallet destination to a typed counterparty.",
2831
+ description: "Attach a bank account, mobile-money account, or external chain destination to a typed counterparty.",
2841
2832
  inputSchema: {
2842
2833
  sessionToken: z.string(),
2843
2834
  actor: actorSchema.optional(),
2844
2835
  ref: REF,
2845
2836
  kind: z.enum([
2846
- "bank",
2847
- "mobile-money",
2848
- "wallet"
2837
+ "bank_account",
2838
+ "mobile_money",
2839
+ "external_account"
2849
2840
  ]),
2850
2841
  label: z.string().optional(),
2851
2842
  payload: DESTINATION_PAYLOAD
@@ -2946,39 +2937,6 @@ function registerMoneyTools(server, deps) {
2946
2937
  }));
2947
2938
  }));
2948
2939
  }
2949
- function registerOrgTailTools(server, deps) {
2950
- server.registerTool("org.pendingMembers", {
2951
- title: "Pending org members",
2952
- description: "List pending member invitations for an organization.",
2953
- inputSchema: {
2954
- sessionToken: z.string(),
2955
- orgId: z.string()
2956
- },
2957
- outputSchema: { members: z.array(z.object(MEMBER_VIEW)) }
2958
- }, (args) => withSession(deps, args.sessionToken, "org.pendingMembers", async (handle) => {
2959
- const method = requireMethod(handle, "orgPendingMembers", "org");
2960
- if (!method.ok) return methodNotImplemented("org", "pendingMembers");
2961
- const res = await method.value(args.orgId);
2962
- return res.ok ? okResult({ members: res.value }) : errorResult(res.error);
2963
- }));
2964
- server.registerTool("org.inviteToken.resend", {
2965
- title: "Resend invite token",
2966
- description: "Resend an existing pending invite token without duplicating membership.",
2967
- inputSchema: {
2968
- sessionToken: z.string(),
2969
- orgId: z.string(),
2970
- email: z.string()
2971
- },
2972
- outputSchema: MEMBER_VIEW
2973
- }, (args) => withSession(deps, args.sessionToken, "org.inviteToken.resend", async (handle) => {
2974
- const method = requireMethod(handle, "orgInviteTokenResend", "org");
2975
- if (!method.ok) return methodNotImplemented("org", "inviteToken.resend");
2976
- return result(await method.value({
2977
- orgId: args.orgId,
2978
- email: args.email
2979
- }));
2980
- }));
2981
- }
2982
2940
  function registerPayrollTools(server, deps) {
2983
2941
  server.registerTool("org.payroll.roster.add", {
2984
2942
  title: "Add payroll roster line",
@@ -5212,7 +5170,7 @@ async function recoverRawDigestSigner(input) {
5212
5170
  }
5213
5171
  //#endregion
5214
5172
  //#region ../../packages/sdk/package.json
5215
- var version = "1.0.0-alpha.11";
5173
+ var version = "1.0.0-alpha.12";
5216
5174
  //#endregion
5217
5175
  //#region ../../packages/sdk/src/ports/auth-client.ts
5218
5176
  var AuthClientError = class extends Data.TaggedError("AuthClientError") {};
@@ -9150,7 +9108,77 @@ function makeAccountsMethods(deps) {
9150
9108
  };
9151
9109
  }
9152
9110
  //#endregion
9111
+ //#region ../../packages/sdk/src/client/current-user.ts
9112
+ function makeCurrentUserMethods(deps) {
9113
+ return { async get(options) {
9114
+ if (options?.signal?.aborted) return {
9115
+ ok: false,
9116
+ error: Errors.cancelled({ operation: "currentUser.get" })
9117
+ };
9118
+ const user = await deps.me.get(options);
9119
+ if (!user.ok) return {
9120
+ ok: false,
9121
+ error: user.error
9122
+ };
9123
+ const [account, smartAccount, organizations] = await Promise.all([
9124
+ deps.accounts.read(options),
9125
+ deps.smartAccount.loadCurrent(options),
9126
+ deps.orgs(options)
9127
+ ]);
9128
+ if (!account.ok) return {
9129
+ ok: false,
9130
+ error: account.error
9131
+ };
9132
+ if (!smartAccount.ok) return {
9133
+ ok: false,
9134
+ error: smartAccount.error
9135
+ };
9136
+ if (!organizations.ok) return {
9137
+ ok: false,
9138
+ error: organizations.error
9139
+ };
9140
+ return {
9141
+ ok: true,
9142
+ value: {
9143
+ user: {
9144
+ id: user.value.authUserId,
9145
+ email: user.value.email,
9146
+ displayName: user.value.displayName,
9147
+ handle: null,
9148
+ paymentLink: null
9149
+ },
9150
+ personalAccount: {
9151
+ id: account.value.id,
9152
+ address: smartAccount.value?.smartAccountAddress ?? null
9153
+ },
9154
+ organizations: organizations.value.map((organization) => ({
9155
+ id: organization.id,
9156
+ name: organization.name,
9157
+ handle: organization.handle,
9158
+ role: organization.role,
9159
+ account: {
9160
+ id: organization.treasury.id,
9161
+ address: organization.safeAddress
9162
+ }
9163
+ }))
9164
+ }
9165
+ };
9166
+ } };
9167
+ }
9168
+ //#endregion
9153
9169
  //#region ../../packages/sdk/src/client/financial-ops.ts
9170
+ function actorReferenceToBackend(actor) {
9171
+ if (actor === void 0) return void 0;
9172
+ switch (actor.kind) {
9173
+ case "personal": return { kind: "account" };
9174
+ case "organization": return {
9175
+ kind: "org",
9176
+ orgId: actor.organizationId
9177
+ };
9178
+ case "account":
9179
+ case "org": return actor;
9180
+ }
9181
+ }
9154
9182
  const DEFAULT_FUNCTIONS = {
9155
9183
  me: makeFunctionReference("financialOps/queries:me"),
9156
9184
  depositInstructions: makeFunctionReference("financialOps/queries:depositInstructions"),
@@ -9210,40 +9238,88 @@ function makeFinancialOpsMethods(deps) {
9210
9238
  get: (payeeId, options) => runIfActive(options?.signal, "payees.get", () => deps.convexCall.query(fns.getPayee, { payeeId })),
9211
9239
  resolve: (recipient, options) => runIfActive(options?.signal, "payees.resolve", () => deps.convexCall.query(fns.resolvePayee, { recipient }))
9212
9240
  },
9241
+ targets: { resolve: async (reference, options) => {
9242
+ switch (reference.kind) {
9243
+ case "handle": return mapOk$1(await runIfActive(options?.signal, "targets.resolve.handle", () => deps.convexCall.query(fns.resolveHandle, { handle: reference.handle })), (target) => resolvedTargetFromResolution(reference, target));
9244
+ case "email": return mapOk$1(await runIfActive(options?.signal, "targets.resolve.email", () => deps.convexCall.query(fns.resolvePayee, { recipient: reference.email })), (target) => resolvedTargetFromResolution(reference, target));
9245
+ case "organization": {
9246
+ const resolved = await runIfActive(options?.signal, "targets.resolve.organization", () => deps.convexCall.query(fns.resolveHandle, { handle: reference.handle }));
9247
+ if (!resolved.ok) return {
9248
+ ok: false,
9249
+ error: resolved.error
9250
+ };
9251
+ if (resolved.value.kind !== "org") return {
9252
+ ok: false,
9253
+ error: Errors.invalidInput("reference", "organization handle could not be resolved")
9254
+ };
9255
+ return {
9256
+ ok: true,
9257
+ value: resolvedTargetFromResolution(reference, resolved.value)
9258
+ };
9259
+ }
9260
+ case "payee": {
9261
+ const payee = await runIfActive(options?.signal, "targets.resolve.payee", () => deps.convexCall.query(fns.getPayee, { payeeId: reference.id }));
9262
+ if (!payee.ok) return {
9263
+ ok: false,
9264
+ error: payee.error
9265
+ };
9266
+ if (payee.value === null) return {
9267
+ ok: false,
9268
+ error: Errors.invalidInput("reference", "payee not found")
9269
+ };
9270
+ return {
9271
+ ok: true,
9272
+ value: resolvedTargetFromPayee(reference, payee.value)
9273
+ };
9274
+ }
9275
+ case "destination": return Promise.resolve({
9276
+ ok: false,
9277
+ error: Errors.notImplemented("targets", "resolve.destination")
9278
+ });
9279
+ }
9280
+ } },
9213
9281
  destinations: {
9214
9282
  add: async (input, options) => {
9215
- const ref = normalizeRefForBackend(input.ref, "ref");
9283
+ const ref = normalizeDestinationInputRef(input, "target");
9216
9284
  if (!ref.ok) return {
9217
9285
  ok: false,
9218
9286
  error: ref.error
9219
9287
  };
9220
- return runIfActive(options?.signal, "destinations.add", () => deps.convexCall.mutation(fns.addDestination, {
9221
- ...input.actor === void 0 ? {} : { actor: input.actor },
9288
+ if (ref.value === void 0) return {
9289
+ ok: false,
9290
+ error: Errors.invalidInput("target", "required for destinations.add")
9291
+ };
9292
+ return mapOk$1(await runIfActive(options?.signal, "destinations.add", () => deps.convexCall.mutation(fns.addDestination, {
9293
+ ...input.actor === void 0 ? {} : { actor: actorReferenceToBackend(input.actor) },
9222
9294
  ref: ref.value,
9223
- kind: input.kind,
9295
+ kind: destinationKindToBackend(input.kind),
9224
9296
  ...input.label === void 0 ? {} : { label: input.label },
9225
9297
  payload: input.payload
9226
- }));
9298
+ })), destinationFromBackend);
9227
9299
  },
9228
9300
  list: async (input, options) => {
9229
- const ref = normalizeRefForBackend(input.ref, "ref");
9301
+ const ref = normalizeDestinationInputRef(input, "target");
9230
9302
  if (!ref.ok) return {
9231
9303
  ok: false,
9232
9304
  error: ref.error
9233
9305
  };
9234
- return runIfActive(options?.signal, "destinations.list", () => deps.convexCall.query(fns.listDestinations, {
9235
- ...input.actor === void 0 ? {} : { actor: input.actor },
9236
- ref: ref.value
9237
- }));
9306
+ return mapOk$1(await runIfActive(options?.signal, "destinations.list", () => deps.convexCall.query(fns.listDestinations, {
9307
+ ...input.actor === void 0 ? {} : { actor: actorReferenceToBackend(input.actor) },
9308
+ ...ref.value === void 0 ? {} : { ref: ref.value }
9309
+ })), (destinations) => destinations.map(destinationFromBackend).filter((destination) => input.kind === void 0 || destination.kind === input.kind));
9238
9310
  },
9239
9311
  remove: (input, options) => runIfActive(options?.signal, "destinations.remove", () => deps.convexCall.mutation(fns.removeDestination, {
9240
- ...input.actor === void 0 ? {} : { actor: input.actor },
9312
+ ...input.actor === void 0 ? {} : { actor: actorReferenceToBackend(input.actor) },
9241
9313
  destinationId: input.destinationId
9242
9314
  }))
9243
9315
  },
9244
9316
  payments: {
9245
9317
  pay: async (input, options) => {
9246
- const to = normalizeRefForBackend(input.to, "to");
9318
+ if (actorReferenceToBackend(input.actor)?.kind === "org") return {
9319
+ ok: false,
9320
+ error: Errors.notImplemented("payments", "pay.organizationActor")
9321
+ };
9322
+ const to = normalizeTargetForBackend(input.to, "to");
9247
9323
  if (!to.ok) return {
9248
9324
  ok: false,
9249
9325
  error: to.error
@@ -9251,13 +9327,14 @@ function makeFinancialOpsMethods(deps) {
9251
9327
  return mapOk$1(await runIfActive(options?.signal, "payments.pay", () => deps.convexCall.mutation(fns.pay, {
9252
9328
  to: to.value,
9253
9329
  amount: input.amount,
9330
+ ...input.paymentType === void 0 ? {} : { paymentType: input.paymentType },
9254
9331
  ...input.document === void 0 ? {} : { document: input.document },
9255
9332
  ...input.timing === void 0 ? {} : { timing: input.timing },
9256
9333
  ...input.lineItems === void 0 ? {} : { lineItems: input.lineItems }
9257
9334
  })), normalizePaymentTiming$1);
9258
9335
  },
9259
9336
  payout: async (input, options) => mapOk$1(await runIfActive(options?.signal, "payments.payout", () => deps.convexCall.mutation(fns.payout, {
9260
- ...input.actor === void 0 ? {} : { actor: input.actor },
9337
+ ...input.actor === void 0 ? {} : { actor: actorReferenceToBackend(input.actor) },
9261
9338
  destinationId: input.destinationId,
9262
9339
  amount: input.amount
9263
9340
  })), normalizePaymentTiming$1),
@@ -9268,6 +9345,16 @@ function makeFinancialOpsMethods(deps) {
9268
9345
  })),
9269
9346
  list: async (options) => mapOk$1(await runIfActive(options?.signal, "payments.list", () => deps.convexCall.query(fns.listPayments, {})), (payments) => payments.map(normalizePaymentTiming$1)),
9270
9347
  get: async (paymentId, options) => mapOk$1(await runIfActive(options?.signal, "payments.get", () => deps.convexCall.query(fns.getPayment, { paymentId })), (payment) => payment === null ? null : normalizePaymentTiming$1(payment)),
9348
+ cancel: (paymentId, options) => {
9349
+ if (options?.signal?.aborted) return Promise.resolve({
9350
+ ok: false,
9351
+ error: Errors.cancelled({ operation: "payments.cancel" })
9352
+ });
9353
+ return Promise.resolve({
9354
+ ok: false,
9355
+ error: Errors.notImplemented("payments", "cancel")
9356
+ });
9357
+ },
9271
9358
  _internal: {
9272
9359
  markSettled: (input, options) => runIfActive(options?.signal, "payments.markSettled", () => deps.convexCall.action(fns.markPaymentSettled, {
9273
9360
  paymentId: input.paymentId,
@@ -9328,6 +9415,38 @@ function makeFinancialOpsMethods(deps) {
9328
9415
  commitmentRef: (paymentId, options) => runIfActive(options?.signal, "payments.commitmentRef", () => deps.convexCall.query(fns.getCommitmentRef, { paymentId }))
9329
9416
  }
9330
9417
  },
9418
+ activity: { list: (params, options) => {
9419
+ if (options?.signal?.aborted) return Promise.resolve({
9420
+ ok: false,
9421
+ error: Errors.cancelled({ operation: "activity.list" })
9422
+ });
9423
+ return Promise.resolve({
9424
+ ok: false,
9425
+ error: Errors.notImplemented("activity", "list")
9426
+ });
9427
+ } },
9428
+ offramp: {
9429
+ quote: (input, options) => {
9430
+ if (options?.signal?.aborted) return Promise.resolve({
9431
+ ok: false,
9432
+ error: Errors.cancelled({ operation: "offramp.quote" })
9433
+ });
9434
+ return Promise.resolve({
9435
+ ok: false,
9436
+ error: Errors.notImplemented("offramp", "quote")
9437
+ });
9438
+ },
9439
+ status: (offrampId, options) => {
9440
+ if (options?.signal?.aborted) return Promise.resolve({
9441
+ ok: false,
9442
+ error: Errors.cancelled({ operation: "offramp.status" })
9443
+ });
9444
+ return Promise.resolve({
9445
+ ok: false,
9446
+ error: Errors.notImplemented("offramp", "status")
9447
+ });
9448
+ }
9449
+ },
9331
9450
  paymentDocuments: {
9332
9451
  verify: (documentHash, options) => runIfActive(options?.signal, "paymentDocuments.verify", () => deps.convexCall.query(fns.verifyPaymentDocument, { documentHash })),
9333
9452
  render: (documentHash, options) => runIfActive(options?.signal, "paymentDocuments.render", () => deps.convexCall.query(fns.renderStoredDocument, { documentHash }))
@@ -9407,6 +9526,169 @@ function handleRefValue(value, field) {
9407
9526
  const trimmed = nonEmptyRefValue(value, field);
9408
9527
  return trimmed.startsWith("@") ? trimmed.slice(1) : trimmed;
9409
9528
  }
9529
+ function refFromTargetReference(reference, field) {
9530
+ try {
9531
+ if (typeof reference === "string") throw Errors.invalidInput(field, "target must be a typed TargetReference variant");
9532
+ if (typeof reference !== "object" || reference === null || !("kind" in reference)) throw Errors.invalidInput(field, "target must be a typed TargetReference variant");
9533
+ switch (reference.kind) {
9534
+ case "handle": return {
9535
+ ok: true,
9536
+ value: {
9537
+ kind: "handle",
9538
+ handle: reference.handle
9539
+ }
9540
+ };
9541
+ case "email": return {
9542
+ ok: true,
9543
+ value: {
9544
+ kind: "email",
9545
+ email: reference.email
9546
+ }
9547
+ };
9548
+ case "organization": return {
9549
+ ok: true,
9550
+ value: {
9551
+ kind: "orgHandle",
9552
+ orgHandle: reference.handle
9553
+ }
9554
+ };
9555
+ case "payee": return {
9556
+ ok: true,
9557
+ value: {
9558
+ kind: "payeeId",
9559
+ payeeId: reference.id
9560
+ }
9561
+ };
9562
+ case "destination": return {
9563
+ ok: false,
9564
+ error: Errors.notImplemented("targets", "reference.destination")
9565
+ };
9566
+ default: throw Errors.invalidInput(field, "target must be a known TargetReference variant");
9567
+ }
9568
+ } catch (cause) {
9569
+ if (cause instanceof Error && "code" in cause) return {
9570
+ ok: false,
9571
+ error: cause
9572
+ };
9573
+ return {
9574
+ ok: false,
9575
+ error: Errors.invalidInput(field, "target must be a typed TargetReference variant")
9576
+ };
9577
+ }
9578
+ }
9579
+ function normalizeTargetForBackend(reference, field) {
9580
+ const ref = refFromTargetReference(reference, field);
9581
+ return ref.ok ? normalizeRefForBackend(ref.value, field) : ref;
9582
+ }
9583
+ function normalizeDestinationInputRef(input, field) {
9584
+ if (input.target !== void 0) return normalizeTargetForBackend(input.target, field);
9585
+ if (input.ref !== void 0) return normalizeDestinationRefForBackend(input.ref, "ref");
9586
+ return {
9587
+ ok: true,
9588
+ value: void 0
9589
+ };
9590
+ }
9591
+ function targetReferenceFromBackendRef(ref) {
9592
+ switch (ref.kind) {
9593
+ case "handle": return {
9594
+ kind: "handle",
9595
+ handle: ref.handle
9596
+ };
9597
+ case "email": return {
9598
+ kind: "email",
9599
+ email: ref.email
9600
+ };
9601
+ case "orgHandle": return {
9602
+ kind: "organization",
9603
+ handle: ref.orgHandle
9604
+ };
9605
+ case "payeeId": return {
9606
+ kind: "payee",
9607
+ id: ref.payeeId
9608
+ };
9609
+ case "capxulUserId": throw Errors.notImplemented("targets", "reference.capxulUserId");
9610
+ }
9611
+ }
9612
+ function resolvedTargetFromResolution(reference, resolution) {
9613
+ const kind = resolution.kind === "org" ? "organization" : resolution.kind === "payee" ? "payee" : "person";
9614
+ return {
9615
+ reference,
9616
+ label: resolution.label,
9617
+ kind,
9618
+ capabilities: {
9619
+ canPay: true,
9620
+ canRequest: true,
9621
+ canPayout: false
9622
+ }
9623
+ };
9624
+ }
9625
+ function resolvedTargetFromPayee(reference, payee) {
9626
+ return {
9627
+ reference,
9628
+ label: payee.label,
9629
+ kind: "payee",
9630
+ capabilities: {
9631
+ canPay: true,
9632
+ canRequest: true,
9633
+ canPayout: false
9634
+ }
9635
+ };
9636
+ }
9637
+ function destinationKindToBackend(kind) {
9638
+ switch (kind) {
9639
+ case "bank_account": return "bank";
9640
+ case "mobile_money": return "mobile-money";
9641
+ case "external_account": return "wallet";
9642
+ }
9643
+ }
9644
+ function destinationKindFromBackend(kind) {
9645
+ switch (kind) {
9646
+ case "bank": return "bank_account";
9647
+ case "mobile-money": return "mobile_money";
9648
+ case "wallet": return "external_account";
9649
+ }
9650
+ }
9651
+ function destinationRailFromBackend(destination) {
9652
+ switch (destination.kind) {
9653
+ case "bank": {
9654
+ const payload = destination.payload;
9655
+ return {
9656
+ kind: "bank",
9657
+ country: payload.country,
9658
+ currency: payload.currency
9659
+ };
9660
+ }
9661
+ case "mobile-money": {
9662
+ const payload = destination.payload;
9663
+ return {
9664
+ kind: "mobile_money",
9665
+ country: payload.country,
9666
+ currency: payload.currency,
9667
+ provider: payload.provider
9668
+ };
9669
+ }
9670
+ case "wallet": return {
9671
+ kind: "chain",
9672
+ network: destination.payload.network,
9673
+ asset: "USD"
9674
+ };
9675
+ }
9676
+ }
9677
+ function destinationFromBackend(destination) {
9678
+ return {
9679
+ ...destination,
9680
+ target: targetReferenceFromBackendRef(destination.ref),
9681
+ kind: destinationKindFromBackend(destination.kind),
9682
+ rail: destinationRailFromBackend(destination)
9683
+ };
9684
+ }
9685
+ function normalizeDestinationRefForBackend(ref, field) {
9686
+ if (typeof ref === "object" && ref !== null && "kind" in ref && ref.kind === "capxulUserId") return {
9687
+ ok: false,
9688
+ error: Errors.notImplemented("targets", "reference.capxulUserId")
9689
+ };
9690
+ return normalizeRefForBackend(ref, field);
9691
+ }
9410
9692
  function normalizeRefForBackend(ref, field) {
9411
9693
  try {
9412
9694
  if (typeof ref === "string") throw Errors.invalidInput(field, "recipient must be a typed Ref variant");
@@ -9469,10 +9751,18 @@ function normalizePaymentTiming$1(payment) {
9469
9751
  }
9470
9752
  function mapOk$1(result, f) {
9471
9753
  if (!result.ok) return result;
9472
- return {
9473
- ok: true,
9474
- value: f(result.value)
9475
- };
9754
+ try {
9755
+ return {
9756
+ ok: true,
9757
+ value: f(result.value)
9758
+ };
9759
+ } catch (cause) {
9760
+ if (cause instanceof Error && "code" in cause) return {
9761
+ ok: false,
9762
+ error: cause
9763
+ };
9764
+ throw cause;
9765
+ }
9476
9766
  }
9477
9767
  async function runIfActive(signal, operation, effect) {
9478
9768
  if (signal?.aborted === true) return {
@@ -9994,30 +10284,6 @@ function inviteMemberProgram(orgId, input) {
9994
10284
  return member;
9995
10285
  });
9996
10286
  }
9997
- function pendingMembersProgram(orgId) {
9998
- return Effect.gen(function* () {
9999
- const deps = yield* OrgDepsTag;
10000
- if (deps.orgPort?.pendingMembers !== void 0) return yield* deps.orgPort.pendingMembers({ orgId }).pipe(Effect.mapError((error) => error.publicError));
10001
- if (deps.orgPort !== void 0) return (yield* deps.orgPort.listMembers({ orgId }).pipe(Effect.mapError((error) => error.publicError))).filter((member) => member.status === "pending" || member.status === "pending_safe" || member.status === "pending_grant");
10002
- return [];
10003
- });
10004
- }
10005
- function resendInviteTokenProgram(orgId, email) {
10006
- return Effect.gen(function* () {
10007
- const deps = yield* OrgDepsTag;
10008
- if (deps.orgPort?.resendInviteToken !== void 0) return yield* deps.orgPort.resendInviteToken({
10009
- orgId,
10010
- email
10011
- }).pipe(Effect.mapError((error) => error.publicError));
10012
- if (!isHermeticOrgDeps(deps)) return yield* Effect.fail(missingLiveOrgDep("orgPort.resendInviteToken"));
10013
- return hermeticMember({
10014
- orgId,
10015
- email,
10016
- role: "Member",
10017
- status: "pending"
10018
- });
10019
- });
10020
- }
10021
10287
  function detectAndAcceptPendingInvitationsProgram() {
10022
10288
  return Effect.gen(function* () {
10023
10289
  const deps = yield* OrgDepsTag;
@@ -10286,6 +10552,32 @@ function makeOrgMethods(deps) {
10286
10552
  });
10287
10553
  return toCapxulResult(readTreasuryProgram(orgId), layer);
10288
10554
  },
10555
+ account: { async get(options) {
10556
+ if (options?.signal?.aborted) return {
10557
+ ok: false,
10558
+ error: Errors.cancelled({ operation: "org.account.get" })
10559
+ };
10560
+ const treasury = await toCapxulResult(readTreasuryProgram(orgId), layer);
10561
+ if (!treasury.ok) return {
10562
+ ok: false,
10563
+ error: treasury.error
10564
+ };
10565
+ const orgs = await toCapxulResult(listOrgsProgram(), layer);
10566
+ if (!orgs.ok) return {
10567
+ ok: false,
10568
+ error: orgs.error
10569
+ };
10570
+ const org = orgs.value.find((candidate) => candidate.id === orgId);
10571
+ return {
10572
+ ok: true,
10573
+ value: {
10574
+ id: treasury.value.id,
10575
+ address: org?.safeAddress ?? null,
10576
+ balance: treasury.value.balance,
10577
+ available: treasury.value.available
10578
+ }
10579
+ };
10580
+ } },
10289
10581
  members(_options) {
10290
10582
  if (_options?.signal?.aborted) return Promise.resolve({
10291
10583
  ok: false,
@@ -10314,20 +10606,6 @@ function makeOrgMethods(deps) {
10314
10606
  });
10315
10607
  return toCapxulResult(inviteMemberProgram(orgId, _input), layer);
10316
10608
  },
10317
- pendingMembers(_options) {
10318
- if (_options?.signal?.aborted) return Promise.resolve({
10319
- ok: false,
10320
- error: Errors.cancelled({ operation: "org.pendingMembers" })
10321
- });
10322
- return toCapxulResult(pendingMembersProgram(orgId), layer);
10323
- },
10324
- inviteToken: { resend(_input, _options) {
10325
- if (_options?.signal?.aborted) return Promise.resolve({
10326
- ok: false,
10327
- error: Errors.cancelled({ operation: "org.inviteToken.resend" })
10328
- });
10329
- return toCapxulResult(resendInviteTokenProgram(orgId, String(_input.email)), layer);
10330
- } },
10331
10609
  removeMember(_input, _options) {
10332
10610
  if (_options?.signal?.aborted) return Promise.resolve({
10333
10611
  ok: false,
@@ -10356,6 +10634,16 @@ function makeOrgMethods(deps) {
10356
10634
  });
10357
10635
  return toCapxulResult(batchPayrollProgram(orgId, _input), layer);
10358
10636
  },
10637
+ auditLog(_options) {
10638
+ if (_options?.signal?.aborted) return Promise.resolve({
10639
+ ok: false,
10640
+ error: Errors.cancelled({ operation: "org.auditLog" })
10641
+ });
10642
+ return Promise.resolve({
10643
+ ok: false,
10644
+ error: Errors.notImplemented("organizationAuditLog", "list")
10645
+ });
10646
+ },
10359
10647
  payroll: convexCall === void 0 ? makeNotImplementedPayrollMethods() : makePayrollMethods({
10360
10648
  orgId: String(orgId),
10361
10649
  convexCall
@@ -10818,6 +11106,12 @@ function assembleCapxulClient(input) {
10818
11106
  if (selectedOrgPort !== void 0) detectPendingOrgInvitations = async () => {
10819
11107
  await orgMethods.orgs.detectAndAcceptPendingInvitations();
10820
11108
  };
11109
+ const currentUser = makeCurrentUserMethods({
11110
+ me: financialOps.me,
11111
+ accounts,
11112
+ smartAccount,
11113
+ orgs: orgMethods.orgs
11114
+ });
10821
11115
  const onboarding = makeOnboardingMethods({
10822
11116
  currentSession: async () => {
10823
11117
  const session = await currentSession(actor, authCache);
@@ -10838,11 +11132,15 @@ function assembleCapxulClient(input) {
10838
11132
  identity,
10839
11133
  account,
10840
11134
  accounts,
11135
+ currentUser,
10841
11136
  me: financialOps.me,
10842
11137
  handles: financialOps.handles,
10843
11138
  payees: financialOps.payees,
11139
+ targets: financialOps.targets,
10844
11140
  destinations: financialOps.destinations,
10845
11141
  payments: financialOps.payments,
11142
+ activity: financialOps.activity,
11143
+ offramp: financialOps.offramp,
10846
11144
  paymentDocuments: financialOps.paymentDocuments,
10847
11145
  paymentRequests: financialOps.paymentRequests,
10848
11146
  workbench: financialOps.workbench,
@@ -14901,6 +15199,43 @@ function refFromMcpRecipient(recipient) {
14901
15199
  orgHandle: trimmed
14902
15200
  };
14903
15201
  }
15202
+ function targetFromMcpRecipient(recipient) {
15203
+ const ref = refFromMcpRecipient(recipient);
15204
+ switch (ref.kind) {
15205
+ case "handle": return {
15206
+ ok: true,
15207
+ value: {
15208
+ kind: "handle",
15209
+ handle: ref.handle
15210
+ }
15211
+ };
15212
+ case "email": return {
15213
+ ok: true,
15214
+ value: {
15215
+ kind: "email",
15216
+ email: ref.email
15217
+ }
15218
+ };
15219
+ case "orgHandle": return {
15220
+ ok: true,
15221
+ value: {
15222
+ kind: "organization",
15223
+ handle: ref.orgHandle
15224
+ }
15225
+ };
15226
+ case "payeeId": return {
15227
+ ok: true,
15228
+ value: {
15229
+ kind: "payee",
15230
+ id: ref.payeeId
15231
+ }
15232
+ };
15233
+ case "capxulUserId": return {
15234
+ ok: false,
15235
+ error: Errors.notImplemented("payments", "target.capxulUserId")
15236
+ };
15237
+ }
15238
+ }
14904
15239
  function toMcpOrgView(view) {
14905
15240
  return {
14906
15241
  orgId: String(view.id),
@@ -14966,9 +15301,9 @@ function actorBundle(client, actor) {
14966
15301
  }
14967
15302
  function actorForSdk(actor) {
14968
15303
  if (actor === void 0) return void 0;
14969
- return actor.kind === "account" ? { kind: "account" } : {
14970
- kind: "org",
14971
- orgId: actor.orgId
15304
+ return actor.kind === "account" ? { kind: "personal" } : {
15305
+ kind: "organization",
15306
+ organizationId: actor.orgId
14972
15307
  };
14973
15308
  }
14974
15309
  function moneyForSdk(amount) {
@@ -15211,13 +15546,6 @@ function makeSdkClientFactory(config, options = { mode: { mode: "live" } }) {
15211
15546
  value: res.value.map(toMcpRoleView)
15212
15547
  } : res;
15213
15548
  },
15214
- orgPendingMembers: async (orgId) => {
15215
- const res = await client.org(toOrgId(orgId)).pendingMembers();
15216
- return res.ok ? {
15217
- ok: true,
15218
- value: res.value.map(toMcpMemberView)
15219
- } : res;
15220
- },
15221
15549
  addressBookList: (actor) => actorBundle(client, actor).addressBook.list(),
15222
15550
  addressBookGet: (actor, entryId) => actorBundle(client, actor).addressBook.get(entryId),
15223
15551
  addressBookAdd: (input) => actorBundle(client, input.actor).addressBook.add({
@@ -15316,8 +15644,10 @@ function makeSdkClientFactory(config, options = { mode: { mode: "live" } }) {
15316
15644
  ok: false,
15317
15645
  error: Errors.notAuthenticated("no active session")
15318
15646
  };
15647
+ const target = targetFromMcpRecipient(input.to);
15648
+ if (!target.ok) return target;
15319
15649
  const recorded = await client.payments.pay({
15320
- to: refFromMcpRecipient(input.to),
15650
+ to: target.value,
15321
15651
  amount: input.amount,
15322
15652
  ...input.document === void 0 ? {} : { document: input.document },
15323
15653
  ...input.release === void 0 ? {} : { timing: input.release },
@@ -15566,13 +15896,6 @@ function makeSdkClientFactory(config, options = { mode: { mode: "live" } }) {
15566
15896
  value: toMcpMemberView(res.value)
15567
15897
  } : res;
15568
15898
  },
15569
- orgInviteTokenResend: async (input) => {
15570
- const res = await client.org(toOrgId(input.orgId)).inviteToken.resend({ email: input.email });
15571
- return res.ok ? {
15572
- ok: true,
15573
- value: toMcpMemberView(res.value)
15574
- } : res;
15575
- },
15576
15899
  orgAssignRole: async (input) => {
15577
15900
  const resolved = await resolveMemberSafeAddress(client, input.orgId, input.email, "org.assignRole");
15578
15901
  if (!resolved.ok) return resolved;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capxul/mcp",
3
- "version": "1.0.0-alpha.11",
3
+ "version": "1.0.0-alpha.12",
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.1",
56
56
  "@capxul/config": "0.1.0-alpha.1",
57
- "@capxul/sdk": "1.0.0-alpha.11",
57
+ "@capxul/sdk": "1.0.0-alpha.12",
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",