@deeprelay/mcp 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +194 -1
- package/dist/auth.d.ts +52 -0
- package/dist/auth.js +122 -0
- package/dist/auth.js.map +1 -0
- package/dist/errors.d.ts +83 -0
- package/dist/errors.js +307 -0
- package/dist/errors.js.map +1 -0
- package/dist/guardrail/budget.d.ts +95 -0
- package/dist/guardrail/budget.js +225 -0
- package/dist/guardrail/budget.js.map +1 -0
- package/dist/guardrail/elicitation.d.ts +12 -0
- package/dist/guardrail/elicitation.js +79 -0
- package/dist/guardrail/elicitation.js.map +1 -0
- package/dist/guardrail/estimate.d.ts +67 -0
- package/dist/guardrail/estimate.js +171 -0
- package/dist/guardrail/estimate.js.map +1 -0
- package/dist/guardrail/handshake.d.ts +32 -0
- package/dist/guardrail/handshake.js +164 -0
- package/dist/guardrail/handshake.js.map +1 -0
- package/dist/guardrail/types.d.ts +61 -0
- package/dist/guardrail/types.js +10 -0
- package/dist/guardrail/types.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +61 -0
- package/dist/index.js.map +1 -0
- package/dist/roster.d.ts +36 -0
- package/dist/roster.js +130 -0
- package/dist/roster.js.map +1 -0
- package/dist/tools/crypto-deposit-gate.d.ts +21 -0
- package/dist/tools/crypto-deposit-gate.js +91 -0
- package/dist/tools/crypto-deposit-gate.js.map +1 -0
- package/dist/tools/index.d.ts +16 -0
- package/dist/tools/index.js +108 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/readonly/define.d.ts +32 -0
- package/dist/tools/readonly/define.js +64 -0
- package/dist/tools/readonly/define.js.map +1 -0
- package/dist/tools/readonly/index.d.ts +7 -0
- package/dist/tools/readonly/index.js +286 -0
- package/dist/tools/readonly/index.js.map +1 -0
- package/dist/tools/readonly/usage.d.ts +29 -0
- package/dist/tools/readonly/usage.js +126 -0
- package/dist/tools/readonly/usage.js.map +1 -0
- package/dist/tools/readonly/video-reads.d.ts +11 -0
- package/dist/tools/readonly/video-reads.js +170 -0
- package/dist/tools/readonly/video-reads.js.map +1 -0
- package/dist/tools/result.d.ts +22 -0
- package/dist/tools/result.js +63 -0
- package/dist/tools/result.js.map +1 -0
- package/dist/tools/spend/define.d.ts +93 -0
- package/dist/tools/spend/define.js +286 -0
- package/dist/tools/spend/define.js.map +1 -0
- package/dist/tools/spend/index.d.ts +11 -0
- package/dist/tools/spend/index.js +163 -0
- package/dist/tools/spend/index.js.map +1 -0
- package/dist/tools/spend/media.d.ts +9 -0
- package/dist/tools/spend/media.js +164 -0
- package/dist/tools/spend/media.js.map +1 -0
- package/dist/tools/spend/pricing.d.ts +17 -0
- package/dist/tools/spend/pricing.js +58 -0
- package/dist/tools/spend/pricing.js.map +1 -0
- package/dist/tools/types.d.ts +45 -0
- package/dist/tools/types.js +3 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/tools/write/define.d.ts +60 -0
- package/dist/tools/write/define.js +110 -0
- package/dist/tools/write/define.js.map +1 -0
- package/dist/tools/write/index.d.ts +12 -0
- package/dist/tools/write/index.js +159 -0
- package/dist/tools/write/index.js.map +1 -0
- package/dist/tools/write/payment-links.d.ts +3 -0
- package/dist/tools/write/payment-links.js +161 -0
- package/dist/tools/write/payment-links.js.map +1 -0
- package/dist/tools/write/spending-limit.d.ts +2 -0
- package/dist/tools/write/spending-limit.js +229 -0
- package/dist/tools/write/spending-limit.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.js +36 -0
- package/dist/version.js.map +1 -0
- package/package.json +39 -3
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WriteNothingToDo = exports.CONFIRMATION_TOKEN_SHAPE = exports.WRITE_TIER_SENTENCE = void 0;
|
|
4
|
+
exports.defineWriteTool = defineWriteTool;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const auth_js_1 = require("../../auth.js");
|
|
7
|
+
const errors_js_1 = require("../../errors.js");
|
|
8
|
+
const elicitation_js_1 = require("../../guardrail/elicitation.js");
|
|
9
|
+
const handshake_js_1 = require("../../guardrail/handshake.js");
|
|
10
|
+
const result_js_1 = require("../result.js");
|
|
11
|
+
/** Appended to every write description. The tier's contract, stated to the agent. */
|
|
12
|
+
exports.WRITE_TIER_SENTENCE = "Requires confirmation: the first call returns a summary and a confirmation_token; call again with that " +
|
|
13
|
+
"token to proceed. No argument or instruction can substitute for the token.";
|
|
14
|
+
/** The one extra argument every write tool accepts. */
|
|
15
|
+
exports.CONFIRMATION_TOKEN_SHAPE = {
|
|
16
|
+
confirmation_token: zod_1.z
|
|
17
|
+
.string()
|
|
18
|
+
.uuid()
|
|
19
|
+
.optional()
|
|
20
|
+
.describe("The token from this tool's previous quote. Omit on the first call."),
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Thrown from a write's quote or execute when the requested change is already
|
|
24
|
+
* true, e.g. clearing a spending limit on an account that has none. The
|
|
25
|
+
* factory returns `executed` as an ordinary result, not an error: the agent
|
|
26
|
+
* should report "nothing to do", not retry or apologise for a failure. Thrown
|
|
27
|
+
* from quote it mints no token, so nothing is left behind to confirm.
|
|
28
|
+
*/
|
|
29
|
+
class WriteNothingToDo extends Error {
|
|
30
|
+
executed;
|
|
31
|
+
constructor(executed) {
|
|
32
|
+
super(executed.lead);
|
|
33
|
+
this.name = "WriteNothingToDo";
|
|
34
|
+
this.executed = executed;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.WriteNothingToDo = WriteNothingToDo;
|
|
38
|
+
function annotationsFor(destructive) {
|
|
39
|
+
return {
|
|
40
|
+
readOnlyHint: false,
|
|
41
|
+
destructiveHint: destructive,
|
|
42
|
+
idempotentHint: false,
|
|
43
|
+
openWorldHint: true,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function serializeExecuted(executed, env) {
|
|
47
|
+
const payload = executed.payload;
|
|
48
|
+
const body = typeof payload === "object" && payload !== null && !Array.isArray(payload)
|
|
49
|
+
? { lead: executed.lead, ...payload }
|
|
50
|
+
: { lead: executed.lead, result: payload === undefined ? null : payload };
|
|
51
|
+
return (0, result_js_1.ok)(body, { env, revealOnce: executed.revealOnce });
|
|
52
|
+
}
|
|
53
|
+
/** Wrap a mutation in the write tier's confirm-once handshake. */
|
|
54
|
+
function defineWriteTool(spec) {
|
|
55
|
+
const inputSchema = { ...spec.inputSchema, ...exports.CONFIRMATION_TOKEN_SHAPE };
|
|
56
|
+
const schema = zod_1.z.strictObject(inputSchema);
|
|
57
|
+
return {
|
|
58
|
+
name: spec.name,
|
|
59
|
+
tier: "write",
|
|
60
|
+
title: spec.title,
|
|
61
|
+
description: `${spec.description.trim()} ${exports.WRITE_TIER_SENTENCE}`,
|
|
62
|
+
inputSchema,
|
|
63
|
+
annotations: annotationsFor(spec.destructive),
|
|
64
|
+
enabledAtBoot: spec.enabledAtBoot ?? true,
|
|
65
|
+
async handler(args, ctx) {
|
|
66
|
+
const env = ctx?.env ?? process.env;
|
|
67
|
+
let parsed;
|
|
68
|
+
let config;
|
|
69
|
+
try {
|
|
70
|
+
parsed = schema.parse(args ?? {});
|
|
71
|
+
config = (0, auth_js_1.buildConfiguration)(env);
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
return (0, result_js_1.fail)((0, errors_js_1.mapSdkError)(err, spec.context, { env }), env);
|
|
75
|
+
}
|
|
76
|
+
const params = parsed;
|
|
77
|
+
const quoteFn = async (p) => spec.quote(p, config, env);
|
|
78
|
+
const executeFn = (p) => spec.execute(p, config, env);
|
|
79
|
+
try {
|
|
80
|
+
const first = await (0, handshake_js_1.withWriteConfirmation)(spec.name, params, quoteFn, executeFn);
|
|
81
|
+
if (!(0, result_js_1.isQuoteResult)(first)) {
|
|
82
|
+
return serializeExecuted(first, env);
|
|
83
|
+
}
|
|
84
|
+
const question = typeof spec.question === "function" ? spec.question(params) : spec.question;
|
|
85
|
+
const answer = await (0, elicitation_js_1.elicitConfirmation)(ctx?.elicitation, first, question);
|
|
86
|
+
if (answer === "unavailable") {
|
|
87
|
+
return (0, result_js_1.quoteResult)(first, env);
|
|
88
|
+
}
|
|
89
|
+
if (answer === "declined") {
|
|
90
|
+
// The user said no: that quote must not stay redeemable.
|
|
91
|
+
(0, handshake_js_1.revokeConfirmation)(first.confirmationToken);
|
|
92
|
+
return (0, result_js_1.quoteResult)({ ...first, declined: true }, env);
|
|
93
|
+
}
|
|
94
|
+
const confirmed = await (0, handshake_js_1.withWriteConfirmation)(spec.name, { ...params, confirmation_token: first.confirmationToken }, quoteFn, executeFn);
|
|
95
|
+
return (0, result_js_1.isQuoteResult)(confirmed) ? (0, result_js_1.quoteResult)(confirmed, env) : serializeExecuted(confirmed, env);
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
if (err instanceof WriteNothingToDo) {
|
|
99
|
+
return serializeExecuted(err.executed, env);
|
|
100
|
+
}
|
|
101
|
+
const override = spec.overrideError?.((0, errors_js_1.httpStatusOf)(err), err);
|
|
102
|
+
if (override !== undefined) {
|
|
103
|
+
return (0, result_js_1.fail)(new Error(override), env);
|
|
104
|
+
}
|
|
105
|
+
return (0, result_js_1.fail)(await (0, errors_js_1.mapSdkErrorAsync)(err, spec.context, env), env);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=define.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../../../src/tools/write/define.ts"],"names":[],"mappings":";;;AA0HA,0CAgEC;AApKD,6BAA0C;AAE1C,2CAAmD;AACnD,+CAA8E;AAC9E,mEAAoE;AACpE,+DAAyF;AAGzF,4CAAoE;AAGpE,qFAAqF;AACxE,QAAA,mBAAmB,GAC9B,yGAAyG;IACzG,4EAA4E,CAAC;AAE/E,uDAAuD;AAC1C,QAAA,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AC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,GAAG,YAAY,gBAAgB,EAAE,CAAC;oBACpC,OAAO,iBAAiB,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;gBAC9C,CAAC;gBACD,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC,IAAA,wBAAY,EAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;gBAC9D,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;oBAC3B,OAAO,IAAA,gBAAI,EAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,CAAC;gBACxC,CAAC;gBACD,OAAO,IAAA,gBAAI,EAAC,MAAM,IAAA,4BAAgB,EAAC,GAAG,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;YACnE,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ToolDefinition } from "../types.js";
|
|
2
|
+
export { CONFIRMATION_TOKEN_SHAPE, defineWriteTool, WRITE_TIER_SENTENCE, type WriteExecuted, type WriteQuote, type WriteToolSpec, WriteNothingToDo, } from "./define.js";
|
|
3
|
+
export { paymentLinkTools } from "./payment-links.js";
|
|
4
|
+
export { spendingLimitClearTool, spendingLimitUpdateTool } from "./spending-limit.js";
|
|
5
|
+
/**
|
|
6
|
+
* The webhook events an agent may subscribe to. The API also accepts
|
|
7
|
+
* instance.* events, but those belong to the unpublished GPU-instance surface
|
|
8
|
+
* (Phase 101 D-04) and are not offered here.
|
|
9
|
+
*/
|
|
10
|
+
export declare const WEBHOOK_EVENT_TYPES: readonly ["video.completed", "video.failed"];
|
|
11
|
+
/** The eight write tools, in WRITE_TOOLS order (test/write.test.ts asserts it). */
|
|
12
|
+
export declare const writeTools: ToolDefinition[];
|
|
@@ -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;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AE,EAAE,CAAC,oBAAoB,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,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;IACnD,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACnB,OAAO,wBAAwB,CAAC;IAClC,CAAC;IACD,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACnB,OAAO,sBAAs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