@arnaudjnn/billing-tools 2.19.0 → 3.0.0

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 (81) hide show
  1. package/README.md +1 -1
  2. package/dist/adapters/workos-org.d.ts +23 -0
  3. package/dist/adapters/workos-org.d.ts.map +1 -1
  4. package/dist/adapters/workos-org.js +4 -2
  5. package/dist/adapters/workos-org.js.map +1 -1
  6. package/dist/bound-api.d.ts +173 -0
  7. package/dist/bound-api.d.ts.map +1 -0
  8. package/dist/bound-api.js +152 -0
  9. package/dist/bound-api.js.map +1 -0
  10. package/dist/cli/commands.js +25 -0
  11. package/dist/cli/commands.js.map +1 -1
  12. package/dist/create-billing.d.ts +128 -41
  13. package/dist/create-billing.d.ts.map +1 -1
  14. package/dist/create-billing.js +24 -14
  15. package/dist/create-billing.js.map +1 -1
  16. package/dist/doctor.d.ts.map +1 -1
  17. package/dist/doctor.js +7 -0
  18. package/dist/doctor.js.map +1 -1
  19. package/dist/entries/agent-auth.d.ts +5 -0
  20. package/dist/entries/agent-auth.d.ts.map +1 -0
  21. package/dist/entries/agent-auth.js +17 -0
  22. package/dist/entries/agent-auth.js.map +1 -0
  23. package/dist/entries/plans.d.ts +4 -0
  24. package/dist/entries/plans.d.ts.map +1 -0
  25. package/dist/entries/plans.js +36 -0
  26. package/dist/entries/plans.js.map +1 -0
  27. package/dist/entries/routes.d.ts +5 -0
  28. package/dist/entries/routes.d.ts.map +1 -0
  29. package/dist/entries/routes.js +17 -0
  30. package/dist/entries/routes.js.map +1 -0
  31. package/dist/entries/tools.d.ts +6 -0
  32. package/dist/entries/tools.d.ts.map +1 -0
  33. package/dist/entries/tools.js +20 -0
  34. package/dist/entries/tools.js.map +1 -0
  35. package/dist/index.d.ts +6 -7
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +38 -15
  38. package/dist/index.js.map +1 -1
  39. package/dist/metering.d.ts +4 -3
  40. package/dist/metering.d.ts.map +1 -1
  41. package/dist/metering.js.map +1 -1
  42. package/dist/plan-model.d.ts +58 -3
  43. package/dist/plan-model.d.ts.map +1 -1
  44. package/dist/plan-model.js +61 -4
  45. package/dist/plan-model.js.map +1 -1
  46. package/dist/plans.d.ts +2 -2
  47. package/dist/plans.d.ts.map +1 -1
  48. package/dist/plans.js +1 -1
  49. package/dist/plans.js.map +1 -1
  50. package/dist/tools/billing.d.ts +2 -1
  51. package/dist/tools/billing.d.ts.map +1 -1
  52. package/dist/tools/billing.js +185 -64
  53. package/dist/tools/billing.js.map +1 -1
  54. package/dist/tools/management.d.ts +2 -1
  55. package/dist/tools/management.d.ts.map +1 -1
  56. package/dist/tools/management.js +210 -187
  57. package/dist/tools/management.js.map +1 -1
  58. package/dist/tools/register.d.ts +13 -1
  59. package/dist/tools/register.d.ts.map +1 -1
  60. package/dist/tools/register.js +28 -6
  61. package/dist/tools/register.js.map +1 -1
  62. package/dist/tools/subscription.d.ts +2 -1
  63. package/dist/tools/subscription.d.ts.map +1 -1
  64. package/dist/tools/subscription.js +115 -108
  65. package/dist/tools/subscription.js.map +1 -1
  66. package/dist/usage-ledger.d.ts +15 -37
  67. package/dist/usage-ledger.d.ts.map +1 -1
  68. package/dist/usage-ledger.js +24 -119
  69. package/dist/usage-ledger.js.map +1 -1
  70. package/dist/usage-scopes.d.ts +55 -0
  71. package/dist/usage-scopes.d.ts.map +1 -0
  72. package/dist/usage-scopes.js +284 -0
  73. package/dist/usage-scopes.js.map +1 -0
  74. package/dist/util/clearout.d.ts.map +1 -1
  75. package/dist/util/clearout.js +15 -3
  76. package/dist/util/clearout.js.map +1 -1
  77. package/package.json +21 -1
  78. package/dist/usage-counters.d.ts +0 -104
  79. package/dist/usage-counters.d.ts.map +0 -1
  80. package/dist/usage-counters.js +0 -214
  81. package/dist/usage-counters.js.map +0 -1
@@ -5,6 +5,7 @@ import { requestTopUp, listTopUpRequests, approveTopUp, denyTopUp, grantExtraAll
5
5
  import { currentCycle } from "../allowance.js";
6
6
  import { assignSeatType, listSeatAssignments } from "../seats.js";
7
7
  import { normalizePlans } from "../plans.js";
8
+ import { ALL_TOOL_CAPABILITIES } from "../plan-model.js";
8
9
  import { usageSummary } from "../usage.js";
9
10
  function json(obj) {
10
11
  return { content: [{ type: "text", text: JSON.stringify(obj, null, 2) }] };
@@ -19,7 +20,12 @@ function err(text) {
19
20
  // user-seat top-up request/approval flow. All ORG-SCOPED (auth = the org's key /
20
21
  // session). Seat + top-up tools require the adapter's metadata methods; when they
21
22
  // are absent (an adapter without an org-metadata store) only get_usage registers.
22
- export function registerManagementTools(server, adapter, config, opts = {}) {
23
+ //
24
+ // Two independent gates, and both have to pass. `caps` says whether the plan
25
+ // CATALOGUE can ever need the group (seats to assign, requests to approve); the
26
+ // metadata check below says whether this adapter can STORE the answer. Neither
27
+ // implies the other, which is why they are not merged.
28
+ export function registerManagementTools(server, adapter, config, opts = {}, caps = ALL_TOOL_CAPABILITIES) {
23
29
  // Every tool here that names a cycle resolves it the same way the meter does,
24
30
  // including the plan lookup — a pooled or annual plan's cycle is its
25
31
  // subscription period, and guessing it from the calendar silently misfiles.
@@ -55,207 +61,224 @@ number of days instead of the calendar month.`, {
55
61
  const usage = await usageSince(cid, since, filter);
56
62
  return json({ usage, since, cycle: cycle.key, filter: filter ?? null });
57
63
  });
58
- // What an agent needs BEFORE it spends: every window that applies, how much of
59
- // each is gone, and when each resets. Without this a caller can only discover a
60
- // limit by being refused by it, which is a poor way to pace a long run — the
61
- // `resets_at` on each window is what lets an agent wait instead of retrying.
62
- server.tool("get_usage_limits", `Get every usage limit that applies to you right now (per hour/day/week/month and
64
+ // Only where a plan HAS a window to report: an included cap, or a rate limit.
65
+ // `get_usage` above stays unconditional it is the historical spend read, and
66
+ // that question is answerable on any catalogue.
67
+ if (caps.usage) {
68
+ // What an agent needs BEFORE it spends: every window that applies, how much of
69
+ // each is gone, and when each resets. Without this a caller can only discover a
70
+ // limit by being refused by it, which is a poor way to pace a long run — the
71
+ // `resets_at` on each window is what lets an agent wait instead of retrying.
72
+ server.tool("get_usage_limits", `Get every usage limit that applies to you right now (per hour/day/week/month and
63
73
  per billing cycle), how much of each is used, and when each resets.`, {
64
- caller_kind: z
65
- .enum(["user", "api"])
66
- .optional()
67
- .describe("Whose limits to report. Defaults to `api` — a tool call is an API caller"),
68
- caller_id: z.string().optional().describe("Member or API-key id, for per-caller windows"),
69
- }, async ({ caller_kind, caller_id }) => {
70
- const auth = await enforceAccess(adapter);
71
- if ("isError" in auth)
72
- return auth;
73
- if (!stripeConfigured())
74
- return err("Billing is not configured (STRIPE_SECRET_KEY unset).");
75
- if (!opts.plans)
76
- return json({ limits: [], note: "No plans configured." });
77
- const plan = opts.resolvePlan
78
- ? await opts.resolvePlan(auth.orgId)
79
- : ((await adapter.getSubscription?.(auth.orgId))?.plan ?? null);
80
- const summary = await usageSummary(adapter, config, {
81
- orgId: auth.orgId,
82
- plans: opts.plans,
83
- plan,
84
- caller: { kind: caller_kind ?? "api", id: caller_id ?? auth.orgId },
85
- });
86
- // Flattened for a reader: one array of windows, whether a window came from
87
- // a rate limit, the pool or the seat pack. `remaining` is what decides
88
- // whether to make the next call; `resets_at` is what decides when to retry.
89
- const windows = [
90
- ...summary.windows.map((w) => ({ kind: "rate_limit", ...w })),
91
- ...(summary.pool ? [{ kind: "included_pool", ...summary.pool }] : []),
92
- ...(summary.pack ? [{ kind: "seat_pack", ...summary.pack }] : []),
93
- ].map((w) => ({
94
- kind: w.kind,
95
- every: w.every,
96
- scope: w.scope,
97
- label: w.label,
98
- limit: w.size,
99
- used: w.used,
100
- remaining: w.remaining,
101
- percent_used: w.percent,
102
- resets_at: w.resetsAt ? new Date(w.resetsAt).toISOString() : null,
103
- }));
104
- return json({
105
- plan: summary.plan,
106
- windows,
107
- wallet_balance: summary.wallet,
108
- cycle: { start: new Date(summary.cycle.start).toISOString(), key: summary.cycle.key },
109
- checked_at: new Date(summary.at).toISOString(),
74
+ caller_kind: z
75
+ .enum(["user", "api"])
76
+ .optional()
77
+ .describe("Whose limits to report. Defaults to `api` — a tool call is an API caller"),
78
+ caller_id: z.string().optional().describe("Member or API-key id, for per-caller windows"),
79
+ }, async ({ caller_kind, caller_id }) => {
80
+ const auth = await enforceAccess(adapter);
81
+ if ("isError" in auth)
82
+ return auth;
83
+ if (!stripeConfigured())
84
+ return err("Billing is not configured (STRIPE_SECRET_KEY unset).");
85
+ if (!opts.plans)
86
+ return json({ limits: [], note: "No plans configured." });
87
+ const plan = opts.resolvePlan
88
+ ? await opts.resolvePlan(auth.orgId)
89
+ : ((await adapter.getSubscription?.(auth.orgId))?.plan ?? null);
90
+ const summary = await usageSummary(adapter, config, {
91
+ orgId: auth.orgId,
92
+ plans: opts.plans,
93
+ plan,
94
+ caller: { kind: caller_kind ?? "api", id: caller_id ?? auth.orgId },
95
+ });
96
+ // Flattened for a reader: one array of windows, whether a window came from
97
+ // a rate limit, the pool or the seat pack. `remaining` is what decides
98
+ // whether to make the next call; `resets_at` is what decides when to retry.
99
+ const windows = [
100
+ ...summary.windows.map((w) => ({ kind: "rate_limit", ...w })),
101
+ ...(summary.pool ? [{ kind: "included_pool", ...summary.pool }] : []),
102
+ ...(summary.pack ? [{ kind: "seat_pack", ...summary.pack }] : []),
103
+ ].map((w) => ({
104
+ kind: w.kind,
105
+ every: w.every,
106
+ scope: w.scope,
107
+ label: w.label,
108
+ limit: w.size,
109
+ used: w.used,
110
+ remaining: w.remaining,
111
+ percent_used: w.percent,
112
+ resets_at: w.resetsAt ? new Date(w.resetsAt).toISOString() : null,
113
+ }));
114
+ return json({
115
+ plan: summary.plan,
116
+ windows,
117
+ wallet_balance: summary.wallet,
118
+ cycle: { start: new Date(summary.cycle.start).toISOString(), key: summary.cycle.key },
119
+ checked_at: new Date(summary.at).toISOString(),
120
+ });
110
121
  });
111
- });
122
+ }
112
123
  // The rest need an org-metadata store on the adapter.
113
124
  if (!adapter.getOrgMetadata || !adapter.setOrgMetadata)
114
125
  return;
115
- // Union of seat-type keys across all plans, for validating assign_seat_type.
116
- // Through the model, so it works whichever shape the config is written in.
117
- const knownSeatTypes = new Set();
118
- for (const model of normalizePlans(opts.plans ?? {})) {
119
- for (const seat of model.seatTypes)
120
- knownSeatTypes.add(seat.key);
121
- }
122
- server.tool("list_seats", `List the workspace's per-member seat-type assignments. Members without an entry
126
+ // Seats are assignable only where a plan sells them. On a flat or free
127
+ // catalogue `list_seats` answered `seat_types: []` and `assign_seat_type`
128
+ // refused everything with "(none configured)" — two tools whose only possible
129
+ // reply was that they do not apply here.
130
+ if (caps.seats) {
131
+ // Union of seat-type keys across all plans, for validating assign_seat_type.
132
+ // Through the model, so it works whichever shape the config is written in.
133
+ const knownSeatTypes = new Set();
134
+ for (const model of normalizePlans(opts.plans ?? {})) {
135
+ for (const seat of model.seatTypes)
136
+ knownSeatTypes.add(seat.key);
137
+ }
138
+ server.tool("list_seats", `List the workspace's per-member seat-type assignments. Members without an entry
123
139
  draw the default seat.`, {}, async () => {
124
- const auth = await enforceAccess(adapter);
125
- if ("isError" in auth)
126
- return auth;
127
- return json({
128
- assignments: await listSeatAssignments(adapter, auth.orgId),
129
- seat_types: [...knownSeatTypes],
140
+ const auth = await enforceAccess(adapter);
141
+ if ("isError" in auth)
142
+ return auth;
143
+ return json({
144
+ assignments: await listSeatAssignments(adapter, auth.orgId),
145
+ seat_types: [...knownSeatTypes],
146
+ });
130
147
  });
131
- });
132
- server.tool("assign_seat_type", `Assign a workspace member to a seat type (e.g. standard, premium). The member's
148
+ server.tool("assign_seat_type", `Assign a workspace member to a seat type (e.g. standard, premium). The member's
133
149
  usage then draws that seat's per-cycle credit pack. Pass an empty seat_type to clear
134
150
  the assignment (back to the default seat).`, {
135
- member_id: z.string().describe("The member's user id"),
136
- seat_type: z.string().optional().describe("Seat type key, or empty to clear"),
137
- }, async ({ member_id, seat_type }) => {
138
- // Who sits on which seat decides who spends what, so it is an admin action
139
- // wherever the caller is a known person.
140
- const auth = await enforceAdmin(adapter, "assign_seat_type");
141
- if ("isError" in auth)
142
- return auth;
143
- const st = seat_type && seat_type.length ? seat_type : null;
144
- if (st && knownSeatTypes.size && !knownSeatTypes.has(st)) {
145
- return err(`Unknown seat type "${st}". Known: ${[...knownSeatTypes].join(", ") || "(none configured)"}.`);
146
- }
147
- await assignSeatType(adapter, auth.orgId, member_id, st);
148
- return json({ status: "ok", member_id, seat_type: st });
149
- });
150
- server.tool("list_top_up_requests", `List the workspace's credit top-up requests (pending and handled) — the extra
151
+ member_id: z.string().describe("The member's user id"),
152
+ seat_type: z.string().optional().describe("Seat type key, or empty to clear"),
153
+ }, async ({ member_id, seat_type }) => {
154
+ // Who sits on which seat decides who spends what, so it is an admin action
155
+ // wherever the caller is a known person.
156
+ const auth = await enforceAdmin(adapter, "assign_seat_type");
157
+ if ("isError" in auth)
158
+ return auth;
159
+ const st = seat_type && seat_type.length ? seat_type : null;
160
+ if (st && knownSeatTypes.size && !knownSeatTypes.has(st)) {
161
+ return err(`Unknown seat type "${st}". Known: ${[...knownSeatTypes].join(", ") || "(none configured)"}.`);
162
+ }
163
+ await assignSeatType(adapter, auth.orgId, member_id, st);
164
+ return json({ status: "ok", member_id, seat_type: st });
165
+ });
166
+ }
167
+ // The top-up flow exists only where a plan lets a member ask for extra
168
+ // allowance (`replenish.request`). Without it there is nothing to grant: the
169
+ // request landed in org metadata, the approval raised a pack the plan does not
170
+ // have, and the owner was asked to rubber-stamp a no-op.
171
+ if (caps.request) {
172
+ server.tool("list_top_up_requests", `List the workspace's credit top-up requests (pending and handled) — the extra
151
173
  allowance members have asked the owner to grant this cycle.`, {}, async () => {
152
- const auth = await enforceAccess(adapter);
153
- if ("isError" in auth)
154
- return auth;
155
- return json({ requests: await listTopUpRequests(adapter, auth.orgId) });
156
- });
157
- server.tool("request_top_up", `Request extra credits for a member's seat this cycle (the owner approves with
174
+ const auth = await enforceAccess(adapter);
175
+ if ("isError" in auth)
176
+ return auth;
177
+ return json({ requests: await listTopUpRequests(adapter, auth.orgId) });
178
+ });
179
+ server.tool("request_top_up", `Request extra credits for a member's seat this cycle (the owner approves with
158
180
  approve_top_up). Use when a user seat has hit its per-cycle pack.`, {
159
- member_id: z.string().describe("The member the extra allowance is for"),
160
- amount: z.number().int().min(1).describe("Extra credits requested (e.g. 25% of the seat pack)"),
161
- cycle: z
162
- .string()
163
- .optional()
164
- .describe("Cycle key the grant applies to. Defaults to the current billing cycle — pass one only to backfill"),
165
- }, async ({ member_id, amount, cycle }) => {
166
- const auth = await enforceAccess(adapter);
167
- if ("isError" in auth)
168
- return auth;
169
- // Requesting is not an admin action — asking is the whole point. But a
170
- // known non-admin caller may only ask for THEMSELVES: `member_id` arrives
171
- // from the caller, and an unchecked one lets a member queue a grant against
172
- // anyone's seat, which an owner approving in bulk would rubber-stamp.
173
- const principal = currentPrincipal();
174
- if (principal && member_id !== principal.userId) {
175
- const admin = principal.isAdmin ?? (await adapter.isAdmin?.(auth.orgId, principal.userId)) ?? true;
176
- if (!admin)
177
- return err("Forbidden (403): you can only request a top-up for yourself.");
178
- }
179
- const id = crypto.randomUUID();
180
- const c = cycle ?? (await cycleFor(auth.orgId)).key;
181
- await requestTopUp(adapter, auth.orgId, {
182
- id,
183
- memberId: member_id,
184
- amount,
185
- cycle: c,
186
- createdAt: new Date().toISOString(),
181
+ member_id: z.string().describe("The member the extra allowance is for"),
182
+ amount: z.number().int().min(1).describe("Extra credits requested (e.g. 25% of the seat pack)"),
183
+ cycle: z
184
+ .string()
185
+ .optional()
186
+ .describe("Cycle key the grant applies to. Defaults to the current billing cycle — pass one only to backfill"),
187
+ }, async ({ member_id, amount, cycle }) => {
188
+ const auth = await enforceAccess(adapter);
189
+ if ("isError" in auth)
190
+ return auth;
191
+ // Requesting is not an admin action — asking is the whole point. But a
192
+ // known non-admin caller may only ask for THEMSELVES: `member_id` arrives
193
+ // from the caller, and an unchecked one lets a member queue a grant against
194
+ // anyone's seat, which an owner approving in bulk would rubber-stamp.
195
+ const principal = currentPrincipal();
196
+ if (principal && member_id !== principal.userId) {
197
+ const admin = principal.isAdmin ?? (await adapter.isAdmin?.(auth.orgId, principal.userId)) ?? true;
198
+ if (!admin)
199
+ return err("Forbidden (403): you can only request a top-up for yourself.");
200
+ }
201
+ const id = crypto.randomUUID();
202
+ const c = cycle ?? (await cycleFor(auth.orgId)).key;
203
+ await requestTopUp(adapter, auth.orgId, {
204
+ id,
205
+ memberId: member_id,
206
+ amount,
207
+ cycle: c,
208
+ createdAt: new Date().toISOString(),
209
+ });
210
+ return json({ status: "requested", id, member_id, amount, cycle: c });
187
211
  });
188
- return json({ status: "requested", id, member_id, amount, cycle: c });
189
- });
190
- server.tool("approve_top_up", `Approve a pending top-up request → grants the requested extra credits to that
212
+ server.tool("approve_top_up", `Approve a pending top-up request → grants the requested extra credits to that
191
213
  member for the cycle (added on top of their seat pack by the meter).`, { request_id: z.string().describe("The request id from list_top_up_requests") }, async ({ request_id }) => {
192
- const auth = await enforceAdmin(adapter, "approve_top_up");
193
- if ("isError" in auth)
194
- return auth;
195
- const r = await approveTopUp(adapter, auth.orgId, request_id);
196
- if (!r.ok)
197
- return err(`Request not found or already handled: ${request_id}`);
198
- return json({ status: "approved", request_id });
199
- });
200
- server.tool("grant_top_up", `Grant a member extra allowance for the current cycle WITHOUT waiting for them to
214
+ const auth = await enforceAdmin(adapter, "approve_top_up");
215
+ if ("isError" in auth)
216
+ return auth;
217
+ const r = await approveTopUp(adapter, auth.orgId, request_id);
218
+ if (!r.ok)
219
+ return err(`Request not found or already handled: ${request_id}`);
220
+ return json({ status: "approved", request_id });
221
+ });
222
+ server.tool("grant_top_up", `Grant a member extra allowance for the current cycle WITHOUT waiting for them to
201
223
  request it, as a percentage of their own seat pack (default 25%). Admin action.`, {
202
- member_id: z.string().describe("WorkOS user id of the member to top up"),
203
- percent: z
204
- .number()
205
- .min(1)
206
- .max(1000)
207
- .optional()
208
- .default(25)
209
- .describe("Percentage of the member's seat pack to add (25 = +25%)"),
210
- credits: z
211
- .number()
212
- .int()
213
- .min(1)
214
- .optional()
215
- .describe("Absolute credits instead of a percentage"),
216
- }, async ({ member_id, percent, credits }) => {
217
- // Guarded like approve_top_up, and more so: this hands out allowance with
218
- // no request behind it, so leaving it open while approval is checked would
219
- // let a member simply grant themselves what they would have had to ask for.
220
- const auth = await enforceAdmin(adapter, "grant_top_up");
221
- if ("isError" in auth)
222
- return auth;
223
- if (!opts.plans)
224
- return err("No plans configured.");
225
- const plan = opts.resolvePlan
226
- ? await opts.resolvePlan(auth.orgId)
227
- : ((await adapter.getSubscription?.(auth.orgId))?.plan ?? null);
228
- const res = await grantExtraAllowance(adapter, {
229
- orgId: auth.orgId,
230
- plans: opts.plans,
231
- plan,
232
- memberId: member_id,
233
- // An explicit credit figure wins; otherwise the percentage (default 25).
234
- ...(credits != null ? { amount: credits } : { percent }),
224
+ member_id: z.string().describe("WorkOS user id of the member to top up"),
225
+ percent: z
226
+ .number()
227
+ .min(1)
228
+ .max(1000)
229
+ .optional()
230
+ .default(25)
231
+ .describe("Percentage of the member's seat pack to add (25 = +25%)"),
232
+ credits: z
233
+ .number()
234
+ .int()
235
+ .min(1)
236
+ .optional()
237
+ .describe("Absolute credits instead of a percentage"),
238
+ }, async ({ member_id, percent, credits }) => {
239
+ // Guarded like approve_top_up, and more so: this hands out allowance with
240
+ // no request behind it, so leaving it open while approval is checked would
241
+ // let a member simply grant themselves what they would have had to ask for.
242
+ const auth = await enforceAdmin(adapter, "grant_top_up");
243
+ if ("isError" in auth)
244
+ return auth;
245
+ if (!opts.plans)
246
+ return err("No plans configured.");
247
+ const plan = opts.resolvePlan
248
+ ? await opts.resolvePlan(auth.orgId)
249
+ : ((await adapter.getSubscription?.(auth.orgId))?.plan ?? null);
250
+ const res = await grantExtraAllowance(adapter, {
251
+ orgId: auth.orgId,
252
+ plans: opts.plans,
253
+ plan,
254
+ memberId: member_id,
255
+ // An explicit credit figure wins; otherwise the percentage (default 25).
256
+ ...(credits != null ? { amount: credits } : { percent }),
257
+ });
258
+ if (!res.ok) {
259
+ return err(res.reason === "not_capped"
260
+ ? "This plan has no per-seat packs, so extra allowance cannot be granted. " +
261
+ "Its limits are workspace-wide (see get_usage_limits)."
262
+ : "Invalid amount.");
263
+ }
264
+ return json({
265
+ status: "granted",
266
+ member_id,
267
+ granted: res.granted,
268
+ seat_pack: res.packSize,
269
+ total_extra_this_cycle: res.total,
270
+ cycle: res.cycle,
271
+ });
235
272
  });
236
- if (!res.ok) {
237
- return err(res.reason === "not_capped"
238
- ? "This plan has no per-seat packs, so extra allowance cannot be granted. " +
239
- "Its limits are workspace-wide (see get_usage_limits)."
240
- : "Invalid amount.");
241
- }
242
- return json({
243
- status: "granted",
244
- member_id,
245
- granted: res.granted,
246
- seat_pack: res.packSize,
247
- total_extra_this_cycle: res.total,
248
- cycle: res.cycle,
273
+ server.tool("deny_top_up", `Deny a pending top-up request.`, { request_id: z.string().describe("The request id from list_top_up_requests") }, async ({ request_id }) => {
274
+ const auth = await enforceAdmin(adapter, "deny_top_up");
275
+ if ("isError" in auth)
276
+ return auth;
277
+ const r = await denyTopUp(adapter, auth.orgId, request_id);
278
+ if (!r.ok)
279
+ return err(`Request not found or already handled: ${request_id}`);
280
+ return json({ status: "denied", request_id });
249
281
  });
250
- });
251
- server.tool("deny_top_up", `Deny a pending top-up request.`, { request_id: z.string().describe("The request id from list_top_up_requests") }, async ({ request_id }) => {
252
- const auth = await enforceAdmin(adapter, "deny_top_up");
253
- if ("isError" in auth)
254
- return auth;
255
- const r = await denyTopUp(adapter, auth.orgId, request_id);
256
- if (!r.ok)
257
- return err(`Request not found or already handled: ${request_id}`);
258
- return json({ status: "denied", request_id });
259
- });
282
+ }
260
283
  }
261
284
  //# sourceMappingURL=management.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"management.js","sourceRoot":"","sources":["../../src/tools/management.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;A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AAC,KAAK;gBACjC,KAAK,EAAE,GAAG,CAAC,KAAK;aACjB,CAAC,CAAC;QACL,CAAC,CACF,CAAC;QAEF,MAAM,CAAC,IAAI,CACT,aAAa,EACb,gCAAgC,EAChC,EAAE,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,0CAA0C,CAAC,EAAE,EAC/E,KAAK,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE;YACvB,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;YACxD,IAAI,SAAS,IAAI,IAAI;gBAAE,OAAO,IAAI,CAAC;YACnC,MAAM,CAAC,GAAG,MAAM,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;YAC3D,IAAI,CAAC,CAAC,CAAC,EAAE;gBAAE,OAAO,GAAG,CAAC,yCAAyC,UAAU,EAAE,CAAC,CAAC;YAC7E,OAAO,IAAI,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;QAChD,CAAC,CACF,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -3,6 +3,7 @@ import type { BillingAdapter, BillingConfig } from "../types.js";
3
3
  import { type TopUpToolOptions } from "./billing.js";
4
4
  import { type SubscriptionToolOptions } from "./subscription.js";
5
5
  import { type PlanCatalog } from "../plans.js";
6
+ import { type ToolCapabilities } from "../plan-model.js";
6
7
  export declare function installInputLogging(server: McpServer): void;
7
8
  export interface RegisterBillingToolsOptions {
8
9
  adapter: BillingAdapter;
@@ -30,7 +31,18 @@ export interface RegisterBillingToolsOptions {
30
31
  /** Tax and return URLs for `buy_credits`. Supply `taxRates` on any account that
31
32
  * charges tax on its subscriptions: without it a top-up invoices at 0%. */
32
33
  topUp?: TopUpToolOptions;
34
+ /**
35
+ * Per-group overrides for the surface derived from `plans`.
36
+ *
37
+ * The derivation is the default because the catalogue already declares every
38
+ * precondition (see `toolCapabilities`), and a tool no plan can satisfy is a
39
+ * false advertisement rather than merely wasted context. This is the escape
40
+ * hatch for the one case the catalogue cannot express: a group the app wants
41
+ * registered for a plan it has not shipped yet, or one it wants withheld
42
+ * because its own UI owns the flow. An explicit value always wins.
43
+ */
44
+ capabilities?: Partial<ToolCapabilities>;
33
45
  }
34
46
  export declare function registerBillingTools(server: McpServer, opts: RegisterBillingToolsOptions): void;
35
- export declare const BILLING_TOOL_NAMES: readonly ["get_api_key", "list_api_keys", "revoke_api_key", "get_credit_balance", "buy_credits", "preview_credit_purchase", "set_auto_reload", "get_billing_portal", "list_invoices", "view_invoice", "download_invoice", "get_usage", "get_usage_limits", "list_seats", "assign_seat_type", "list_top_up_requests", "request_top_up", "approve_top_up", "grant_top_up", "deny_top_up", "get_billing_profile", "set_billing_profile", "set_tax_id", "list_payment_methods", "set_default_payment_method", "remove_payment_method", "get_plan", "preview_plan_change", "change_plan", "cancel_plan"];
47
+ export declare const BILLING_TOOL_NAMES: readonly ["get_api_key", "list_api_keys", "revoke_api_key", "get_credit_balance", "buy_credits", "preview_credit_purchase", "set_auto_reload", "get_spend_controls", "set_spend_controls", "get_billing_portal", "list_invoices", "view_invoice", "download_invoice", "list_plans", "get_usage", "get_usage_limits", "list_seats", "assign_seat_type", "list_top_up_requests", "request_top_up", "approve_top_up", "grant_top_up", "deny_top_up", "get_billing_profile", "set_billing_profile", "set_tax_id", "list_payment_methods", "set_default_payment_method", "remove_payment_method", "get_plan", "preview_plan_change", "change_plan", "cancel_plan"];
36
48
  //# sourceMappingURL=register.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/tools/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjE,OAAO,EAA4B,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAG/E,O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AmB,CAAC;AAC5F,OAAO,EAA2C,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AACxF,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,kBAAkB,CAAC;AAyB1B,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,QAkBpD;AAED,MAAM,WAAW,2BAA2B;IAC1C,OAAO,EAAE,cAAc,CAAC;IACxB,MAAM,EAAE,aAAa,CAAC;IACtB,uFAAuF;IACvF,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,uEAAuE;IACvE,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;+EAC2E;IAC3E,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,uCAAuC;IACvC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;sEAEkE;IAClE,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACxD;2DACuD;IACvD,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;uCAEmC;IACnC,iBAAiB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;IACrE;gFAC4E;IAC5E,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC1C;AAID,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,2BAA2B,QAkCxF;AA0DD,eAAO,MAAM,kBAAkB,+nBA4CrB,CAAC"}
@@ -5,6 +5,7 @@ import { registerManagementTools } from "./management.js";
5
5
  import { registerProfileTools } from "./profile.js";
6
6
  import { registerSubscriptionTools } from "./subscription.js";
7
7
  import { ensurePlans, normalizePlans, poolSizeOf } from "../plans.js";
8
+ import { ALL_TOOL_CAPABILITIES, toolCapabilities, } from "../plan-model.js";
8
9
  // Keys whose values must never hit the logs (magic-auth codes, API keys, etc.).
9
10
  const SENSITIVE_KEY_RE = /cookie|token|secret|password|passwd|authorization|api[_-]?key|session|credential|code/i;
10
11
  function redactForLog(value, depth = 0) {
@@ -53,19 +54,30 @@ export function registerBillingTools(server, opts) {
53
54
  const config = resolveConfig(opts.config);
54
55
  if (opts.installLogging !== false)
55
56
  installInputLogging(server);
57
+ // No catalogue means no declaration to read, so every group registers — which is
58
+ // what every consumer got before this derivation existed, and what an app with
59
+ // no plans (pure pay-as-you-go) still wants. `undefined` is "the caller did not
60
+ // say", never "nothing applies"; the same distinction `checkPlansConfig` draws
61
+ // for its `usageLedger` option, and for the same reason: inventing a `false`
62
+ // here would silently delete tools from a working deployment.
63
+ const caps = {
64
+ ...(opts.plans ? toolCapabilities(opts.plans) : ALL_TOOL_CAPABILITIES),
65
+ ...opts.capabilities,
66
+ };
56
67
  registerKeyTools(server, opts.adapter, config);
57
- registerBillingOnlyTools(server, opts.adapter, config, opts.toolCosts ?? {}, opts.topUp ?? {});
58
- registerManagementTools(server, opts.adapter, config, {
59
- plans: opts.plans,
60
- resolvePlan: opts.resolvePlan,
61
- });
68
+ registerBillingOnlyTools(server, opts.adapter, config, opts.toolCosts ?? {}, opts.topUp ?? {}, caps);
69
+ registerManagementTools(server, opts.adapter, config, { plans: opts.plans, resolvePlan: opts.resolvePlan }, caps);
62
70
  if (opts.profileTools !== false)
63
71
  registerProfileTools(server, opts.adapter);
64
72
  if (opts.plans) {
73
+ // `list_plans` and `get_plan` are READS and always register: "what is on offer"
74
+ // and "what am I on" are answerable on any catalogue, including one that is
75
+ // entirely quote-only. Only the four tools that CHANGE a subscription need a
76
+ // plan a customer can actually move to without a salesperson.
65
77
  registerPlanTools(server, opts.plans, opts.defaultPlan, config.currency);
66
78
  if (opts.subscriptionTools !== false) {
67
79
  const sub = typeof opts.subscriptionTools === "object" ? opts.subscriptionTools : {};
68
- registerSubscriptionTools(server, opts.adapter, config, { ...sub, plans: opts.plans });
80
+ registerSubscriptionTools(server, opts.adapter, config, { ...sub, plans: opts.plans }, caps);
69
81
  }
70
82
  }
71
83
  }
@@ -119,10 +131,20 @@ export const BILLING_TOOL_NAMES = [
119
131
  "buy_credits",
120
132
  "preview_credit_purchase",
121
133
  "set_auto_reload",
134
+ // The customer's own monthly ceiling. Ungated: it funds nothing and only refuses,
135
+ // so it needs no plan — and it was UI-only until this audit, which is the parity
136
+ // rule's own failure mode.
137
+ "get_spend_controls",
138
+ "set_spend_controls",
122
139
  "get_billing_portal",
123
140
  "list_invoices",
124
141
  "view_invoice",
125
142
  "download_invoice",
143
+ // The catalogue read (registerPlanTools). It was registered but NOT advertised
144
+ // here — exactly the drift the list exists to prevent, and invisible because the
145
+ // surface test only checked that everything advertised was registered. It now
146
+ // checks both directions.
147
+ "list_plans",
126
148
  // Workspace-management tools (registerManagementTools).
127
149
  "get_usage",
128
150
  "get_usage_limits",