@deeprelay/mcp 0.0.1 → 0.1.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 (77) hide show
  1. package/README.md +188 -1
  2. package/dist/auth.d.ts +52 -0
  3. package/dist/auth.js +122 -0
  4. package/dist/auth.js.map +1 -0
  5. package/dist/errors.d.ts +83 -0
  6. package/dist/errors.js +307 -0
  7. package/dist/errors.js.map +1 -0
  8. package/dist/guardrail/budget.d.ts +95 -0
  9. package/dist/guardrail/budget.js +225 -0
  10. package/dist/guardrail/budget.js.map +1 -0
  11. package/dist/guardrail/elicitation.d.ts +12 -0
  12. package/dist/guardrail/elicitation.js +79 -0
  13. package/dist/guardrail/elicitation.js.map +1 -0
  14. package/dist/guardrail/estimate.d.ts +67 -0
  15. package/dist/guardrail/estimate.js +171 -0
  16. package/dist/guardrail/estimate.js.map +1 -0
  17. package/dist/guardrail/handshake.d.ts +32 -0
  18. package/dist/guardrail/handshake.js +164 -0
  19. package/dist/guardrail/handshake.js.map +1 -0
  20. package/dist/guardrail/types.d.ts +61 -0
  21. package/dist/guardrail/types.js +10 -0
  22. package/dist/guardrail/types.js.map +1 -0
  23. package/dist/index.d.ts +18 -0
  24. package/dist/index.js +61 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/roster.d.ts +36 -0
  27. package/dist/roster.js +130 -0
  28. package/dist/roster.js.map +1 -0
  29. package/dist/tools/crypto-deposit-gate.d.ts +21 -0
  30. package/dist/tools/crypto-deposit-gate.js +91 -0
  31. package/dist/tools/crypto-deposit-gate.js.map +1 -0
  32. package/dist/tools/index.d.ts +16 -0
  33. package/dist/tools/index.js +108 -0
  34. package/dist/tools/index.js.map +1 -0
  35. package/dist/tools/readonly/define.d.ts +32 -0
  36. package/dist/tools/readonly/define.js +64 -0
  37. package/dist/tools/readonly/define.js.map +1 -0
  38. package/dist/tools/readonly/index.d.ts +7 -0
  39. package/dist/tools/readonly/index.js +292 -0
  40. package/dist/tools/readonly/index.js.map +1 -0
  41. package/dist/tools/readonly/video-reads.d.ts +11 -0
  42. package/dist/tools/readonly/video-reads.js +170 -0
  43. package/dist/tools/readonly/video-reads.js.map +1 -0
  44. package/dist/tools/result.d.ts +22 -0
  45. package/dist/tools/result.js +63 -0
  46. package/dist/tools/result.js.map +1 -0
  47. package/dist/tools/spend/define.d.ts +93 -0
  48. package/dist/tools/spend/define.js +286 -0
  49. package/dist/tools/spend/define.js.map +1 -0
  50. package/dist/tools/spend/index.d.ts +11 -0
  51. package/dist/tools/spend/index.js +163 -0
  52. package/dist/tools/spend/index.js.map +1 -0
  53. package/dist/tools/spend/media.d.ts +9 -0
  54. package/dist/tools/spend/media.js +164 -0
  55. package/dist/tools/spend/media.js.map +1 -0
  56. package/dist/tools/spend/pricing.d.ts +17 -0
  57. package/dist/tools/spend/pricing.js +58 -0
  58. package/dist/tools/spend/pricing.js.map +1 -0
  59. package/dist/tools/types.d.ts +45 -0
  60. package/dist/tools/types.js +3 -0
  61. package/dist/tools/types.js.map +1 -0
  62. package/dist/tools/write/define.d.ts +60 -0
  63. package/dist/tools/write/define.js +110 -0
  64. package/dist/tools/write/define.js.map +1 -0
  65. package/dist/tools/write/index.d.ts +12 -0
  66. package/dist/tools/write/index.js +159 -0
  67. package/dist/tools/write/index.js.map +1 -0
  68. package/dist/tools/write/payment-links.d.ts +3 -0
  69. package/dist/tools/write/payment-links.js +161 -0
  70. package/dist/tools/write/payment-links.js.map +1 -0
  71. package/dist/tools/write/spending-limit.d.ts +2 -0
  72. package/dist/tools/write/spending-limit.js +229 -0
  73. package/dist/tools/write/spending-limit.js.map +1 -0
  74. package/dist/version.d.ts +3 -0
  75. package/dist/version.js +36 -0
  76. package/dist/version.js.map +1 -0
  77. package/package.json +39 -3
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.writeTools = exports.WEBHOOK_EVENT_TYPES = exports.spendingLimitUpdateTool = exports.spendingLimitClearTool = exports.paymentLinkTools = exports.WriteNothingToDo = exports.WRITE_TIER_SENTENCE = exports.defineWriteTool = exports.CONFIRMATION_TOKEN_SHAPE = void 0;
4
+ // The write tier (Phase 104, D-02/D-03/D-09/D-10). Authored fresh (D-12).
5
+ //
6
+ // Eight mutations, none of which charges the account, and every one of which
7
+ // confirms once. Each is built with defineWriteTool (define.ts), which wraps
8
+ // the tool in withWriteConfirmation and puts elicitation in front of that same
9
+ // handshake, so no write can be registered without its confirmation.
10
+ //
11
+ // deeprelay_webhooks_create — returns the signing secret ONCE
12
+ // deeprelay_webhooks_delete — destructive; the secret is gone for good
13
+ // deeprelay_videos_cancel — destructive; releases the session's
14
+ // video reservation (D-02/D-07)
15
+ // deeprelay_spending_limit_update — lower-only (spending-limit.ts)
16
+ // deeprelay_spending_limit_clear — destructive; removes the limit entirely,
17
+ // "nothing to clear" is not an error
18
+ // (spending-limit.ts, Plan 104-12)
19
+ // deeprelay_subscription_checkout — link only (payment-links.ts, D-09)
20
+ // deeprelay_billing_portal — link only (payment-links.ts, D-09)
21
+ // deeprelay_deposits_create_crypto — link only, off at boot (payment-links.ts, D-03)
22
+ const sdk_1 = require("@deeprelay/sdk");
23
+ const zod_1 = require("zod");
24
+ const video_reads_js_1 = require("../readonly/video-reads.js");
25
+ const define_js_1 = require("./define.js");
26
+ const payment_links_js_1 = require("./payment-links.js");
27
+ const spending_limit_js_1 = require("./spending-limit.js");
28
+ var define_js_2 = require("./define.js");
29
+ Object.defineProperty(exports, "CONFIRMATION_TOKEN_SHAPE", { enumerable: true, get: function () { return define_js_2.CONFIRMATION_TOKEN_SHAPE; } });
30
+ Object.defineProperty(exports, "defineWriteTool", { enumerable: true, get: function () { return define_js_2.defineWriteTool; } });
31
+ Object.defineProperty(exports, "WRITE_TIER_SENTENCE", { enumerable: true, get: function () { return define_js_2.WRITE_TIER_SENTENCE; } });
32
+ Object.defineProperty(exports, "WriteNothingToDo", { enumerable: true, get: function () { return define_js_2.WriteNothingToDo; } });
33
+ var payment_links_js_2 = require("./payment-links.js");
34
+ Object.defineProperty(exports, "paymentLinkTools", { enumerable: true, get: function () { return payment_links_js_2.paymentLinkTools; } });
35
+ var spending_limit_js_2 = require("./spending-limit.js");
36
+ Object.defineProperty(exports, "spendingLimitClearTool", { enumerable: true, get: function () { return spending_limit_js_2.spendingLimitClearTool; } });
37
+ Object.defineProperty(exports, "spendingLimitUpdateTool", { enumerable: true, get: function () { return spending_limit_js_2.spendingLimitUpdateTool; } });
38
+ /**
39
+ * The webhook events an agent may subscribe to. The API also accepts
40
+ * instance.* events, but those belong to the unpublished GPU-instance surface
41
+ * (Phase 101 D-04) and are not offered here.
42
+ */
43
+ exports.WEBHOOK_EVENT_TYPES = ["video.completed", "video.failed"];
44
+ function endpointView(endpoint) {
45
+ return {
46
+ id: endpoint.id,
47
+ url: endpoint.url,
48
+ event_types: endpoint.eventTypes,
49
+ enabled: endpoint.enabled,
50
+ created_at: endpoint.createdAt,
51
+ };
52
+ }
53
+ const webhooksCreateTool = (0, define_js_1.defineWriteTool)({
54
+ name: "deeprelay_webhooks_create",
55
+ title: "Create a webhook endpoint",
56
+ description: "Register an HTTPS URL that deeprelay will SEND event data to (video.completed, video.failed). The endpoint's " +
57
+ "signing secret is returned exactly once, in this tool's result, and can never be read again: tell the user to " +
58
+ "store it immediately. Charges nothing.",
59
+ inputSchema: {
60
+ url: zod_1.z
61
+ .url({ protocol: /^https$/, hostname: zod_1.z.regexes.domain })
62
+ .describe("The https:// URL deeprelay will POST events to."),
63
+ event_types: zod_1.z
64
+ .array(zod_1.z.enum(exports.WEBHOOK_EVENT_TYPES))
65
+ .min(1)
66
+ .describe("Events to deliver to this URL. At least one."),
67
+ },
68
+ destructive: false,
69
+ question: (args) => `deeprelay will send event data to ${args.url}. Create this webhook endpoint?`,
70
+ context: "creating a webhook endpoint",
71
+ async quote(args) {
72
+ return {
73
+ summary: `deeprelay will SEND event data to ${args.url} for: ${args.event_types.join(", ")}. ` +
74
+ "The signing secret is shown once, in the result, and never again.",
75
+ resolvedParams: { url: args.url, event_types: args.event_types },
76
+ };
77
+ },
78
+ async execute(p, config) {
79
+ const endpoint = await new sdk_1.WebhooksApi(config).createWebhookEndpoint({
80
+ createWebhookEndpointRequest: { url: p.url, eventTypes: p.event_types },
81
+ });
82
+ const secret = endpoint.secret;
83
+ if (typeof secret !== "string" || secret === "") {
84
+ return {
85
+ lead: `Webhook endpoint ${endpoint.id} created. The API returned no signing secret for it.`,
86
+ payload: endpointView(endpoint),
87
+ };
88
+ }
89
+ return {
90
+ lead: `Webhook endpoint ${endpoint.id} created. The signing_secret below is shown ONCE and never again — ` +
91
+ "store it now; it cannot be retrieved later.",
92
+ payload: endpointView(endpoint),
93
+ revealOnce: { signing_secret: secret },
94
+ };
95
+ },
96
+ });
97
+ const webhooksDeleteTool = (0, define_js_1.defineWriteTool)({
98
+ name: "deeprelay_webhooks_delete",
99
+ title: "Delete a webhook endpoint",
100
+ description: "Delete a webhook endpoint. deeprelay stops sending events to it, and its signing secret is lost for good: " +
101
+ "re-creating the endpoint issues a different secret. This cannot be undone. Charges nothing.",
102
+ inputSchema: {
103
+ webhook_endpoint_id: zod_1.z.string().min(1).describe("Endpoint id, as returned by deeprelay_webhooks_list."),
104
+ },
105
+ destructive: true,
106
+ question: (args) => `Delete webhook endpoint ${args.webhook_endpoint_id}? This cannot be undone.`,
107
+ context: "deleting a webhook endpoint",
108
+ async quote(args) {
109
+ return {
110
+ summary: `Delete webhook endpoint ${args.webhook_endpoint_id}. deeprelay stops sending events to it and its signing ` +
111
+ "secret is permanently lost. This cannot be undone.",
112
+ resolvedParams: { webhook_endpoint_id: args.webhook_endpoint_id },
113
+ };
114
+ },
115
+ async execute(p, config) {
116
+ await new sdk_1.WebhooksApi(config).deleteWebhookEndpoint({ id: p.webhook_endpoint_id });
117
+ return {
118
+ lead: `Webhook endpoint ${p.webhook_endpoint_id} deleted. Its signing secret no longer exists.`,
119
+ payload: { id: p.webhook_endpoint_id, deleted: true },
120
+ };
121
+ },
122
+ });
123
+ const videosCancelTool = (0, define_js_1.defineWriteTool)({
124
+ name: "deeprelay_videos_cancel",
125
+ title: "Cancel a video generation job",
126
+ description: "Cancel a queued or in-progress video job. A cancelled job is never billed, and this session's reservation for " +
127
+ "it is released. A job that already completed cannot be cancelled. This cannot be undone.",
128
+ inputSchema: {
129
+ video_id: zod_1.z.string().min(1).describe("Video job id, as returned by deeprelay_videos_create."),
130
+ },
131
+ destructive: true,
132
+ question: (args) => `Cancel video job ${args.video_id}? This cannot be undone.`,
133
+ context: "cancelling a video job",
134
+ async quote(args) {
135
+ return {
136
+ summary: `Cancel video job ${args.video_id}. Its output is abandoned; a cancelled job is not billed.`,
137
+ resolvedParams: { video_id: args.video_id },
138
+ };
139
+ },
140
+ async execute(p, config) {
141
+ const job = await new sdk_1.InferenceApi(config).cancelVideo({ id: p.video_id });
142
+ // Settles through budget.settleVideo: cancelled releases the hold.
143
+ const view = (0, video_reads_js_1.observeVideoJob)(job);
144
+ return {
145
+ lead: `Video job ${job.id} is now ${String(job.status)}. Session reservation: ${String(view.session_settlement)}.`,
146
+ payload: view,
147
+ };
148
+ },
149
+ });
150
+ /** The eight write tools, in WRITE_TOOLS order (test/write.test.ts asserts it). */
151
+ exports.writeTools = [
152
+ webhooksCreateTool,
153
+ webhooksDeleteTool,
154
+ spending_limit_js_1.spendingLimitUpdateTool,
155
+ spending_limit_js_1.spendingLimitClearTool,
156
+ ...payment_links_js_1.paymentLinkTools,
157
+ videosCancelTool,
158
+ ];
159
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/write/index.ts"],"names":[],"mappings":";;;AAAA,0EAA0E;AAC1E,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,+EAA+E;AAC/E,qEAAqE;AACrE,EAAE;AACF,wEAAwE;AACxE,iFAAiF;AACjF,4EAA4E;AAC5E,sEAAsE;AACtE,uEAAuE;AACvE,iFA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IAAI,CAAC,QAAQ,0BAA0B;IAC/E,OAAO,EAAE,wBAAwB;IACjC,KAAK,CAAC,KAAK,CAAC,IAAI;QACd,OAAO;YACL,OAAO,EAAE,oBAAoB,IAAI,CAAC,QAAQ,2DAA2D;YACrG,cAAc,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE;SAC5C,CAAC;IACJ,CAAC;IACD,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM;QACrB,MAAM,GAAG,GAAG,MAAM,IAAI,kBAAY,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC3E,mEAAmE;QACnE,MAAM,IAAI,GAAG,IAAA,gCAAe,EAAC,GAAG,CAAC,CAAC;QAClC,OAAO;YACL,IAAI,EAAE,aAAa,GAAG,CAAC,EAAE,WAAW,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,0BAA0B,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG;YAClH,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAEH,mFAAmF;AACtE,QAAA,UAAU,GAAqB;IAC1C,kBAAkB;IAClB,kBAAkB;IAClB,2CAAuB;IACvB,0CAAsB;IACtB,GAAG,mCAAgB;IACnB,gBAAgB;CACjB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ToolDefinition } from "../types.js";
2
+ export declare const CRYPTO_NOT_ENABLED: string;
3
+ export declare const paymentLinkTools: ToolDefinition[];
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.paymentLinkTools = exports.CRYPTO_NOT_ENABLED = void 0;
4
+ // Payment-link writes: subscription checkout, billing portal, crypto deposit
5
+ // (Phase 104 D-03/D-09). Authored fresh (D-12).
6
+ //
7
+ // None of these moves money. Each creates a link (or a deposit address) the
8
+ // user acts on outside the agent, in their own browser or wallet, and nothing
9
+ // is charged until they do. They still confirm once like every write (D-10),
10
+ // with no price quote, because there is nothing to price (D-09).
11
+ //
12
+ // Status wording is tool-specific where the shared mapper would mislead:
13
+ // * Subscription checkout returns 503 by design on deployments without a
14
+ // configured Stripe price. That is "not available here", not "retry".
15
+ // * Crypto deposits 404 when the account's crypto_deposits_enabled is false.
16
+ // That is final for this account; the agent must not retry. The tool is
17
+ // also off at boot (enabledAtBoot: false) and advertised only when the
18
+ // account has the feature (D-03).
19
+ const sdk_1 = require("@deeprelay/sdk");
20
+ const zod_1 = require("zod");
21
+ const define_js_1 = require("./define.js");
22
+ const LINK_ONLY = "It only creates a link and never charges: nothing is paid until the user completes it themselves.";
23
+ const httpsUrl = (what) => zod_1.z
24
+ .url({ protocol: /^https$/, hostname: zod_1.z.regexes.domain })
25
+ .describe(`https:// URL ${what}.`);
26
+ const SUBSCRIPTION_UNAVAILABLE = "Subscription checkout is not available on this deployment yet.";
27
+ const SUBSCRIPTION_FORBIDDEN = "Not permitted — managing the subscription requires the org-admin role on this deeprelay account.";
28
+ /** 503 is by design where no Stripe price is configured: legible, not a retry prompt. */
29
+ function subscriptionError(status) {
30
+ if (status === 503) {
31
+ return SUBSCRIPTION_UNAVAILABLE;
32
+ }
33
+ if (status === 403) {
34
+ return SUBSCRIPTION_FORBIDDEN;
35
+ }
36
+ return undefined;
37
+ }
38
+ exports.CRYPTO_NOT_ENABLED = "Crypto deposits are not enabled for this account — this tool cannot be used here. Do not retry; use " +
39
+ "deeprelay_subscription_checkout or the dashboard to add funds.";
40
+ const CRYPTO_UNAVAILABLE = "Crypto deposit service is temporarily unavailable — try later.";
41
+ function iso(d) {
42
+ return d instanceof Date && !Number.isNaN(d.getTime()) ? d.toISOString() : null;
43
+ }
44
+ const subscriptionCheckoutTool = (0, define_js_1.defineWriteTool)({
45
+ name: "deeprelay_subscription_checkout",
46
+ title: "Create a subscription checkout link",
47
+ description: "Create a checkout link the user opens in their browser to subscribe to a deeprelay plan (the default plan when " +
48
+ `plan_key is omitted). ${LINK_ONLY} Requires the org-admin role.`,
49
+ inputSchema: {
50
+ plan_key: zod_1.z.string().min(1).optional().describe("Plan to subscribe to. Omit for the default plan."),
51
+ success_url: httpsUrl("the browser returns to after a completed checkout").optional(),
52
+ cancel_url: httpsUrl("the browser returns to if checkout is abandoned").optional(),
53
+ },
54
+ destructive: false,
55
+ question: (args) => `This will create a checkout link for plan ${args.plan_key ?? "default"} — confirm?`,
56
+ context: "creating a subscription checkout link",
57
+ async quote(args) {
58
+ return {
59
+ summary: `Create a subscription checkout link for plan ${args.plan_key ?? "default"}. ` +
60
+ "Nothing is charged until the user completes checkout in their browser.",
61
+ resolvedParams: { plan_key: args.plan_key, success_url: args.success_url, cancel_url: args.cancel_url },
62
+ };
63
+ },
64
+ async execute(p, config) {
65
+ const session = await new sdk_1.BillingApi(config).createSubscriptionCheckout({
66
+ subscriptionCheckoutRequest: { planKey: p.plan_key, successUrl: p.success_url, cancelUrl: p.cancel_url },
67
+ });
68
+ return {
69
+ lead: "Checkout link created. Give it to the user to open in their browser; nothing is charged until they " +
70
+ "complete checkout there.",
71
+ payload: {
72
+ checkout_url: session.checkoutUrl,
73
+ session_id: session.sessionId,
74
+ plan: session.plan,
75
+ },
76
+ };
77
+ },
78
+ overrideError: subscriptionError,
79
+ });
80
+ const billingPortalTool = (0, define_js_1.defineWriteTool)({
81
+ name: "deeprelay_billing_portal",
82
+ title: "Create a billing portal link",
83
+ description: "Create a link to the billing portal, where the user manages their subscription and payment methods in their " +
84
+ `browser. ${LINK_ONLY} Requires the org-admin role.`,
85
+ inputSchema: {
86
+ return_url: httpsUrl("the browser returns to when the user leaves the portal").optional(),
87
+ },
88
+ destructive: false,
89
+ question: "This will create a billing portal link — confirm?",
90
+ context: "creating a billing portal link",
91
+ async quote(args) {
92
+ return {
93
+ summary: "Create a billing portal link. Nothing is charged by creating or opening it.",
94
+ resolvedParams: { return_url: args.return_url },
95
+ };
96
+ },
97
+ async execute(p, config) {
98
+ const portal = await new sdk_1.BillingApi(config).createSubscriptionPortal({
99
+ subscriptionPortalRequest: { returnUrl: p.return_url },
100
+ });
101
+ return {
102
+ lead: "Billing portal link created. Give it to the user to open in their browser.",
103
+ payload: { portal_url: portal.portalUrl },
104
+ };
105
+ },
106
+ overrideError: subscriptionError,
107
+ });
108
+ const cryptoDepositCreateTool = (0, define_js_1.defineWriteTool)({
109
+ name: "deeprelay_deposits_create_crypto",
110
+ title: "Create a crypto deposit",
111
+ description: "Available only on accounts with crypto deposits enabled. Creates a deposit request and returns the address and " +
112
+ "exact amount the user sends from their own wallet to add prepaid credit. It never charges and moves no funds " +
113
+ "itself: only the user's own transfer does. Deposits expire if unpaid; check progress with deeprelay_deposits_get.",
114
+ inputSchema: {
115
+ amount_cents: zod_1.z.number().int().min(100).describe("Amount to deposit, in US cents (minimum 100)."),
116
+ chain: zod_1.z.enum(sdk_1.CreateCryptoDepositRequestChainEnum).describe("Blockchain to send on."),
117
+ asset: zod_1.z.enum(sdk_1.CreateCryptoDepositRequestAssetEnum).describe("Stablecoin to send."),
118
+ },
119
+ destructive: false,
120
+ enabledAtBoot: false,
121
+ question: (args) => `This will create a $${(args.amount_cents / 100).toFixed(2)} ${args.asset.toUpperCase()} deposit address on ` +
122
+ `${args.chain} — confirm?`,
123
+ context: "creating a crypto deposit",
124
+ async quote(args) {
125
+ return {
126
+ summary: `Create a crypto deposit request for $${(args.amount_cents / 100).toFixed(2)} in ${args.asset.toUpperCase()} ` +
127
+ `on ${args.chain}. No funds move until the user sends them from their own wallet.`,
128
+ resolvedParams: { amount_cents: args.amount_cents, chain: args.chain, asset: args.asset },
129
+ };
130
+ },
131
+ async execute(p, config) {
132
+ const deposit = await new sdk_1.BillingApi(config).createCryptoDeposit({
133
+ createCryptoDepositRequest: { amountCents: p.amount_cents, chain: p.chain, asset: p.asset },
134
+ });
135
+ return {
136
+ lead: "Deposit created. The user sends exactly pay_amount of the asset to pay_address from their own wallet " +
137
+ "before expires_at; credit is applied once the transfer confirms.",
138
+ payload: {
139
+ deposit_id: deposit.depositId,
140
+ status: deposit.status,
141
+ chain: deposit.chain,
142
+ asset: deposit.asset,
143
+ pay_address: deposit.payAddress ?? null,
144
+ pay_amount: deposit.payAmount ?? null,
145
+ amount_usd_cents: deposit.amountUsdCents,
146
+ expires_at: iso(deposit.expiresAt),
147
+ },
148
+ };
149
+ },
150
+ overrideError(status) {
151
+ if (status === 404) {
152
+ return exports.CRYPTO_NOT_ENABLED;
153
+ }
154
+ if (status !== undefined && status >= 500) {
155
+ return CRYPTO_UNAVAILABLE;
156
+ }
157
+ return undefined;
158
+ },
159
+ });
160
+ exports.paymentLinkTools = [subscriptionCheckoutTool, billingPortalTool, cryptoDepositCreateTool];
161
+ //# sourceMappingURL=payment-links.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payment-links.js","sourceRoot":"","sources":["../../../src/tools/write/payment-links.ts"],"names":[],"mappings":";;;AAAA,6EAA6E;AAC7E,gDAAgD;AAChD,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,iEAAiE;AACjE,EAAE;AACF,yEAAyE;AACzE,2EAA2E;AAC3E,0EAA0E;AAC1E,+EAA+E;AAC/E,4EAA4E;AAC5E,2EAA2E;AAC3E,sCAAsC;AACtC,wCAIwB;AACxB,6BAAwB;AAGxB,2CAA8C;AAE9C,MAAM,SAAS,GAAG,mGAAmG,CAAC;AAEtH,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,EAAE,CAChC,OAAC;KACE,GAAG,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAC,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;KACxD,QAAQ,CAAC,gBAAgB,IAAI,GAAG,CAAC,CAAC;AAEvC,MAAM,wBAAwB,GAAG,gEAAgE,CAAC;AAClG,MAAM,sBAAsB,GAC1B,kGAAkG,CAAC;AAErG,yFAAyF;AACzF,SAAS,iBAAiB,CAAC,MAA0B;IAC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qB,CAAC,wBAAwB,EAAE,iBAAiB,EAAE,uBAAuB,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const spendingLimitUpdateTool: import("../types.js").ToolDefinition;
2
+ export declare const spendingLimitClearTool: import("../types.js").ToolDefinition;
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.spendingLimitClearTool = exports.spendingLimitUpdateTool = void 0;
4
+ // The spending-limit write tools (Phase 104 D-03). Authored fresh (D-12).
5
+ //
6
+ // deeprelay_spending_limit_update — lower-only (carrying Phase 82 D-06)
7
+ // deeprelay_spending_limit_clear — remove the limit entirely (Plan 104-12:
8
+ // @deeprelay/sdk@0.2.0 ships
9
+ // BillingApi.deleteSpendingLimit)
10
+ //
11
+ // So from the agent's side a limit can be lowered or cleared, never raised.
12
+ // Raising is done in the dashboard.
13
+ //
14
+ // The update tool may only tighten the limit, never raise it. That is enforced
15
+ // structurally, twice:
16
+ //
17
+ // quote — GET the current limit. A requested monthly (or daily) value that
18
+ // is not strictly below the current one throws
19
+ // QuoteUnavailableError, so no confirmation token is minted: a
20
+ // raise cannot be confirmed, not merely "is discouraged".
21
+ // execute — GET again and re-apply the same checks. A token lives for its
22
+ // whole TTL and the limit can move during it, so time-of-check
23
+ // must be time-of-use.
24
+ //
25
+ // The PUT resends every field (enforcement, auto-terminate hours, daily
26
+ // limit) from the fresh GET, because the API has no partial update: an
27
+ // omitted field is defaulted server-side, which could silently change
28
+ // behaviour the confirmation never described (T-104-25).
29
+ //
30
+ // The clear tool quotes against a live GET and re-reads at execute, the same
31
+ // time-of-check/time-of-use discipline as the update. "No limit configured"
32
+ // (the API's typed 404 `no_spending_limit`, on either the GET or the DELETE)
33
+ // is a plain "nothing to clear" result, never an error: the account is
34
+ // already in the state the user asked for.
35
+ const sdk_1 = require("@deeprelay/sdk");
36
+ const zod_1 = require("zod");
37
+ const errors_js_1 = require("../../errors.js");
38
+ const define_js_1 = require("./define.js");
39
+ /** Run the limit GET; a 404 means "no limit configured" and becomes undefined. */
40
+ async function orNoLimit(read) {
41
+ try {
42
+ return await read();
43
+ }
44
+ catch (err) {
45
+ if ((0, errors_js_1.httpStatusOf)(err) === 404) {
46
+ return undefined;
47
+ }
48
+ throw err;
49
+ }
50
+ }
51
+ function usd(v) {
52
+ return `$${v.toFixed(2)}`;
53
+ }
54
+ /** The reason a request is not a decrease against `current`, or undefined when it is. */
55
+ function notADecrease(current, monthly, daily) {
56
+ if (current === undefined) {
57
+ return undefined;
58
+ }
59
+ if (monthly >= current.monthlyLimitDollars) {
60
+ return `${usd(monthly)} is not a decrease from the current ${usd(current.monthlyLimitDollars)}/month limit`;
61
+ }
62
+ if (daily !== undefined && current.dailyLimitDollars !== undefined && daily >= current.dailyLimitDollars) {
63
+ return `${usd(daily)} is not a decrease from the current ${usd(current.dailyLimitDollars)}/day limit`;
64
+ }
65
+ return undefined;
66
+ }
67
+ const LOWER_ONLY = "This tool only lowers limits; raises are done in the dashboard.";
68
+ exports.spendingLimitUpdateTool = (0, define_js_1.defineWriteTool)({
69
+ name: "deeprelay_spending_limit_update",
70
+ title: "Lower the deeprelay spending limit",
71
+ description: "LOWER the account's monthly spending limit (and optionally the daily one). Lower-only: a value at or above the " +
72
+ "current limit is refused before any confirmation is offered, and raising a limit is done in the dashboard. " +
73
+ "Requires the org-admin role. To remove the limit entirely use deeprelay_spending_limit_clear instead. Check " +
74
+ "the current value first with deeprelay_spending_limit_get. Charges nothing.",
75
+ inputSchema: {
76
+ monthly_limit_dollars: zod_1.z.number().positive().describe("New monthly limit in US dollars. Must be below the current one."),
77
+ daily_limit_dollars: zod_1.z
78
+ .number()
79
+ .positive()
80
+ .optional()
81
+ .describe("New daily limit in US dollars. If a daily limit exists, must be below it."),
82
+ },
83
+ destructive: false,
84
+ question: (args) => `Lower the monthly spending limit to ${usd(args.monthly_limit_dollars)}?`,
85
+ context: "updating the spending limit",
86
+ async quote(args, config) {
87
+ const current = await orNoLimit(() => new sdk_1.BillingApi(config).getSpendingLimit());
88
+ const refusal = notADecrease(current, args.monthly_limit_dollars, args.daily_limit_dollars);
89
+ if (refusal !== undefined) {
90
+ throw new errors_js_1.QuoteUnavailableError(`Refused: ${refusal}. ${LOWER_ONLY}`);
91
+ }
92
+ const monthlyPart = current === undefined
93
+ ? `Set a monthly spending limit of ${usd(args.monthly_limit_dollars)} (none is configured today)`
94
+ : `Lower the monthly spending limit from ${usd(current.monthlyLimitDollars)} to ${usd(args.monthly_limit_dollars)}`;
95
+ const dailyPart = args.daily_limit_dollars === undefined
96
+ ? ""
97
+ : current?.dailyLimitDollars === undefined
98
+ ? `, and set a daily limit of ${usd(args.daily_limit_dollars)}`
99
+ : `, and lower the daily limit from ${usd(current.dailyLimitDollars)} to ${usd(args.daily_limit_dollars)}`;
100
+ const plan = {
101
+ monthly_limit_dollars: args.monthly_limit_dollars,
102
+ daily_limit_dollars: args.daily_limit_dollars,
103
+ previous_monthly: current?.monthlyLimitDollars,
104
+ previous_daily: current?.dailyLimitDollars,
105
+ enforcement: current?.enforcement,
106
+ auto_terminate_hours: current?.autoTerminateHours,
107
+ };
108
+ return {
109
+ summary: `${monthlyPart}${dailyPart}. Raising it again cannot be done through this server.`,
110
+ resolvedParams: plan,
111
+ };
112
+ },
113
+ async execute(p, config) {
114
+ const fresh = await orNoLimit(() => new sdk_1.BillingApi(config).getSpendingLimit());
115
+ if (notADecrease(fresh, p.monthly_limit_dollars, p.daily_limit_dollars) !== undefined) {
116
+ throw new errors_js_1.QuoteUnavailableError("Refused at execution: the limit changed since the quote. The confirmation has been discarded.");
117
+ }
118
+ // Resend every field; prefer the fresh record, fall back to what was quoted.
119
+ const request = {
120
+ monthlyLimitDollars: p.monthly_limit_dollars,
121
+ dailyLimitDollars: p.daily_limit_dollars ?? fresh?.dailyLimitDollars ?? p.previous_daily,
122
+ enforcement: (fresh?.enforcement ?? p.enforcement),
123
+ autoTerminateHours: fresh?.autoTerminateHours ?? p.auto_terminate_hours,
124
+ };
125
+ const updated = await new sdk_1.BillingApi(config).updateSpendingLimit({ updateSpendingLimitRequest: request });
126
+ return {
127
+ lead: `Spending limit is now ${usd(updated.monthlyLimitDollars)}/month` +
128
+ (updated.dailyLimitDollars === undefined ? "." : ` and ${usd(updated.dailyLimitDollars)}/day.`),
129
+ payload: {
130
+ previous_monthly_limit_dollars: fresh?.monthlyLimitDollars ?? null,
131
+ monthly_limit_dollars: updated.monthlyLimitDollars,
132
+ daily_limit_dollars: updated.dailyLimitDollars ?? null,
133
+ enforcement: updated.enforcement,
134
+ current_month_spend_dollars: updated.currentMonthSpendDollars,
135
+ percent_used: updated.percentUsed,
136
+ },
137
+ };
138
+ },
139
+ });
140
+ /** The API's typed code for "this org has no spending limit", on GET and DELETE alike. */
141
+ const NO_SPENDING_LIMIT = "no_spending_limit";
142
+ /** A 404 carrying the typed `no_spending_limit` code; any other 404 is a real error. */
143
+ async function isNoSpendingLimit(err) {
144
+ if ((0, errors_js_1.httpStatusOf)(err) !== 404) {
145
+ return false;
146
+ }
147
+ return (await (0, errors_js_1.readErrorEnvelope)(err)).code === NO_SPENDING_LIMIT;
148
+ }
149
+ /**
150
+ * Clear-path read: only the API's typed `no_spending_limit` 404 means "nothing
151
+ * to clear". Any other 404 (a proxy, a missing route) is a real error, so the
152
+ * agent is never told "no limit is configured" when one may exist.
153
+ */
154
+ async function orTypedNoLimit(read) {
155
+ try {
156
+ return await read();
157
+ }
158
+ catch (err) {
159
+ if (await isNoSpendingLimit(err)) {
160
+ return undefined;
161
+ }
162
+ throw err;
163
+ }
164
+ }
165
+ const NOTHING_TO_CLEAR = {
166
+ lead: "No spending limit is configured on this account, so there is nothing to clear. Nothing was changed.",
167
+ payload: { cleared: false, reason: NO_SPENDING_LIMIT },
168
+ };
169
+ function limitPhrase(monthly, daily) {
170
+ return daily === undefined ? `${usd(monthly)}/month limit` : `${usd(monthly)}/month limit and the ${usd(daily)}/day cap`;
171
+ }
172
+ exports.spendingLimitClearTool = (0, define_js_1.defineWriteTool)({
173
+ name: "deeprelay_spending_limit_clear",
174
+ title: "Clear the deeprelay spending limit",
175
+ description: "REMOVE the account's spending limit entirely: the monthly limit and the daily cap. Afterwards inference is " +
176
+ "bounded only by the account balance. Requires the org-admin role. If no limit is configured this reports " +
177
+ "that there is nothing to clear and changes nothing. A new limit can be set again with " +
178
+ "deeprelay_spending_limit_update. Charges nothing.",
179
+ inputSchema: {},
180
+ destructive: true,
181
+ question: "Remove the spending limit entirely? Inference will then be bounded only by the account balance.",
182
+ context: "clearing the spending limit",
183
+ async quote(_args, config) {
184
+ const current = await orTypedNoLimit(() => new sdk_1.BillingApi(config).getSpendingLimit());
185
+ if (current === undefined) {
186
+ throw new define_js_1.WriteNothingToDo(NOTHING_TO_CLEAR);
187
+ }
188
+ const plan = {
189
+ previous_monthly: current.monthlyLimitDollars,
190
+ previous_daily: current.dailyLimitDollars,
191
+ };
192
+ return {
193
+ summary: `This removes the ${limitPhrase(current.monthlyLimitDollars, current.dailyLimitDollars)} entirely — ` +
194
+ "inference is then bounded only by the account balance.",
195
+ resolvedParams: plan,
196
+ };
197
+ },
198
+ async execute(p, config) {
199
+ const fresh = await orTypedNoLimit(() => new sdk_1.BillingApi(config).getSpendingLimit());
200
+ if (fresh === undefined) {
201
+ throw new define_js_1.WriteNothingToDo(NOTHING_TO_CLEAR);
202
+ }
203
+ if (fresh.monthlyLimitDollars !== p.previous_monthly || fresh.dailyLimitDollars !== p.previous_daily) {
204
+ throw new errors_js_1.QuoteUnavailableError("Refused at execution: the limit changed since the quote. The confirmation has been discarded.");
205
+ }
206
+ try {
207
+ await new sdk_1.BillingApi(config).deleteSpendingLimit();
208
+ }
209
+ catch (err) {
210
+ // Cleared by someone else between the re-read and the DELETE.
211
+ if (await isNoSpendingLimit(err)) {
212
+ throw new define_js_1.WriteNothingToDo(NOTHING_TO_CLEAR);
213
+ }
214
+ throw err;
215
+ }
216
+ return {
217
+ lead: `Spending limit cleared. Removed: the ${limitPhrase(p.previous_monthly, p.previous_daily)}. ` +
218
+ "Inference is now bounded only by the account balance.",
219
+ payload: {
220
+ cleared: true,
221
+ previous: {
222
+ monthly_limit_dollars: p.previous_monthly,
223
+ daily_limit_dollars: p.previous_daily ?? null,
224
+ },
225
+ },
226
+ };
227
+ },
228
+ });
229
+ //# sourceMappingURL=spending-limit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spending-limit.js","sourceRoot":"","sources":["../../../src/tools/write/spending-limit.ts"],"names":[],"mappings":";;;AAAA,0EAA0E;AAC1E,EAAE;AACF,0EAA0E;AAC1E,8EAA8E;AAC9E,iEAAiE;AACjE,sEAAsE;AACtE,EAAE;AACF,4EAA4E;AAC5E,oCAAoC;AACpC,EAAE;AACF,+EAA+E;AAC/E,uBAAuB;AACvB,EAAE;AACF,+EAA+E;AAC/E,2DAA2D;AAC3D,2EAA2E;AAC3E,sEAAsE;AACtE,4EAA4E;AAC5E,2EAA2E;AAC3E,mCAAmC;AACnC,EAAE;AACF,wEAAwE;AACxE,uEAAuE;AACvE,sEAAsE;AACtE,yDAAyD;AACzD,EAAE;AACF,6EAA6E;AAC7E,4EAA4E;AAC5E,6EAA6E;AAC7E,uEAAuE;AACvE,2CAA2C;AAC3C,wCAAiG;AACjG,6BAAwB;AAExB,+CAAyF;AACzF,2CAAgE;AAYhE,kFAAkF;AAClF,KAAK,UAAU,SAAS,CAAC,IAAkC;IACzD,IAAI,CAAC;QACH,OAAO,MAAM,IAAI,EAAE,CAAC;IACtB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,IAAA,wBAAY,EAAC,GAAG,CAAC,KAAK,GAAG,EAAE,CAAC;YAC9B,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC;AAED,SAAS,GAAG,CAAC,CAAS;IACpB,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;AAC5B,CAAC;AAED,yFAAyF;AACzF,SAAS,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J,CAAC;QACD,IAAI,CAAC;YACH,MAAM,IAAI,gBAAU,CAAC,MAAM,CAAC,CAAC,mBAAmB,EAAE,CAAC;QACrD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,8DAA8D;YAC9D,IAAI,MAAM,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;gBACjC,MAAM,IAAI,4BAAgB,CAAC,gBAAgB,CAAC,CAAC;YAC/C,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC;QACD,OAAO;YACL,IAAI,EACF,wCAAwC,WAAW,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC,CAAC,cAAc,CAAC,IAAI;gBAC7F,uDAAuD;YACzD,OAAO,EAAE;gBACP,OAAO,EAAE,IAAI;gBACb,QAAQ,EAAE;oBACR,qBAAqB,EAAE,CAAC,CAAC,gBAAgB;oBACzC,mBAAmB,EAAE,CAAC,CAAC,cAAc,IAAI,IAAI;iBAC9C;aACF;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** Reported when package.json cannot be read. Matches the committed placeholder. */
2
+ export declare const FALLBACK_VERSION = "0.0.0-dev";
3
+ export declare function readVersion(): string;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FALLBACK_VERSION = void 0;
4
+ exports.readVersion = readVersion;
5
+ // The package's own version, read at runtime (Phase 104, D-12: authored fresh).
6
+ //
7
+ // Two places need the same number: the server identity MCP clients see in the
8
+ // handshake, and the outbound User-Agent that auth.ts stamps on every API
9
+ // call. Keeping it in its own module lets auth.ts import it without importing
10
+ // the server entry point.
11
+ //
12
+ // The value is read from package.json at runtime rather than compiled in, so a
13
+ // release that injects the version into package.json is reported correctly
14
+ // without a rebuild. The compiled file is dist/version.js, so the manifest is
15
+ // one directory up. Under vitest the source file is src/version.ts, which also
16
+ // sits one directory below package.json.
17
+ const node_fs_1 = require("node:fs");
18
+ const node_path_1 = require("node:path");
19
+ /** Reported when package.json cannot be read. Matches the committed placeholder. */
20
+ exports.FALLBACK_VERSION = "0.0.0-dev";
21
+ function readVersion() {
22
+ try {
23
+ const manifest = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, "..", "package.json"), "utf8"));
24
+ if (typeof manifest === "object" && manifest !== null) {
25
+ const version = manifest.version;
26
+ if (typeof version === "string" && version.trim() !== "") {
27
+ return version;
28
+ }
29
+ }
30
+ }
31
+ catch {
32
+ // An unreadable manifest must never stop the server from starting.
33
+ }
34
+ return exports.FALLBACK_VERSION;
35
+ }
36
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;;AAkBA,kCAeC;AAjCD,gFAAgF;AAChF,EAAE;AACF,8EAA8E;AAC9E,0EAA0E;AAC1E,8EAA8E;AAC9E,0BAA0B;AAC1B,EAAE;AACF,+EAA+E;AAC/E,2EAA2E;AAC3E,8EAA8E;AAC9E,+EAA+E;AAC/E,yCAAyC;AACzC,qCAAuC;AACvC,yCAAiC;AAEjC,oFAAoF;AACvE,QAAA,gBAAgB,GAAG,WAAW,CAAC;AAE5C,SAAgB,WAAW;IACzB,IAAI,CAAC;QACH,MAAM,QAAQ,GAAY,IAAI,CAAC,KAAK,CAClC,IAAA,sBAAY,EAAC,IAAA,gBAAI,EAAC,SAAS,EAAE,IAAI,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAC5D,CAAC;QACF,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YACtD,MAAM,OAAO,GAAI,QAAkC,CAAC,OAAO,CAAC;YAC5D,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;gBACzD,OAAO,OAAO,CAAC;YACjB,CAAC;QACH,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,mEAAmE;IACrE,CAAC;IACD,OAAO,wBAAgB,CAAC;AAC1B,CAAC"}