xvcache-mcp 0.0.0-stage → 0.2.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.
package/dist/plans.js ADDED
@@ -0,0 +1,114 @@
1
+ import { readFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ let cached;
5
+ export function catalogPath() {
6
+ return path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "plans.json");
7
+ }
8
+ export function loadPlansCatalog() {
9
+ if (!cached) {
10
+ cached = JSON.parse(readFileSync(catalogPath(), "utf8"));
11
+ }
12
+ return cached;
13
+ }
14
+ export function getOffer() {
15
+ const catalog = loadPlansCatalog();
16
+ const current = catalog.plans.find((p) => p.id === catalog.current_tier_id) ?? catalog.plans[0];
17
+ return {
18
+ payment_live: catalog.payment_live,
19
+ prices_status: catalog.prices_status,
20
+ notice: catalog.notice,
21
+ current_tier: current,
22
+ certified_proofs: catalog.certified_proofs ?? null,
23
+ upgrade: catalog.upgrade,
24
+ reseller: catalog.reseller,
25
+ how_to_upgrade: "Show the plan to your human and ask for explicit approval. Intended path today: a Stripe checkout link (not live). Later: x402 for agent-to-agent payment (à venir). Call request_upgrade with a plan id to get the approval step.",
26
+ };
27
+ }
28
+ function placeholderLimit(plan, key) {
29
+ const v = plan.limits[key]?.value;
30
+ return typeof v === "number" ? v : null;
31
+ }
32
+ export function recommendPlan(input) {
33
+ const catalog = loadPlansCatalog();
34
+ const certs = input.certifications_per_month ?? 0;
35
+ const notes = input.notes_per_month ?? 0;
36
+ const wantsWitness = input.needs_certified_witness === true || certs > 0;
37
+ let plan = catalog.plans.find((p) => p.id === "free") ?? catalog.plans[0];
38
+ let reason;
39
+ if (!wantsWitness) {
40
+ reason =
41
+ "No certified-witness volume was requested. The free local journal (verify_journal, verdicts V and X) is enough for now.";
42
+ }
43
+ else {
44
+ const bundles = catalog.plans
45
+ .filter((p) => p.kind === "bundle")
46
+ .slice()
47
+ .sort((a, b) => (placeholderLimit(a, "certifications_per_month") ?? 0) - (placeholderLimit(b, "certifications_per_month") ?? 0));
48
+ const fitting = bundles.find((p) => {
49
+ const c = placeholderLimit(p, "certifications_per_month");
50
+ const n = placeholderLimit(p, "notes_per_month");
51
+ const certOk = c == null || certs <= c;
52
+ const noteOk = n == null || notes <= n;
53
+ return certOk && noteOk;
54
+ });
55
+ if (fitting) {
56
+ plan = fitting;
57
+ reason =
58
+ `Certified witness was requested (or a monthly certification volume was given). Placeholder bundle ${fitting.id} is the smallest illustrative bundle whose TBD quotas cover the stated volume. Quotas and prices are placeholders, not a real offer. Certified proofs run locally via certify_note; billing is not live.`;
59
+ }
60
+ else {
61
+ plan = catalog.plans.find((p) => p.id === "usage") ?? plan;
62
+ reason =
63
+ "Certified witness was requested. No placeholder bundle covers the stated volume, so the usage-based plan (price per certification, TBD) is suggested. This is not a real offer. Certified proofs run locally via certify_note; billing is not live.";
64
+ }
65
+ }
66
+ const alternatives = catalog.plans.filter((p) => p.id !== plan.id).map((p) => p.id);
67
+ const result = {
68
+ payment_live: false,
69
+ prices_status: "TBD",
70
+ notice: catalog.notice,
71
+ recommended_plan_id: plan.id,
72
+ recommended_plan: plan,
73
+ reason,
74
+ alternatives,
75
+ certified_witness_status: plan.certified_witness ? (plan.certified_witness_status ?? "preview") : "not_included",
76
+ };
77
+ if (input.reseller) {
78
+ result.reseller = catalog.reseller;
79
+ result.reason +=
80
+ " Reseller or partner bundling was requested: terms are TBD; see the reseller field and AGENTS.md. Do not sign or collect money on XVcache's behalf.";
81
+ }
82
+ return result;
83
+ }
84
+ export function requestUpgrade(planId) {
85
+ const catalog = loadPlansCatalog();
86
+ const plan = catalog.plans.find((p) => p.id === planId);
87
+ if (!plan) {
88
+ return {
89
+ ok: false,
90
+ payment_live: false,
91
+ error: `Unknown plan id: ${planId}`,
92
+ known_plan_ids: catalog.plans.map((p) => p.id),
93
+ };
94
+ }
95
+ return {
96
+ ok: true,
97
+ status: "needs_human_approval",
98
+ payment_live: false,
99
+ prices_status: "TBD",
100
+ notice: catalog.notice,
101
+ plan_id: plan.id,
102
+ plan,
103
+ approval: {
104
+ who: "human",
105
+ required: true,
106
+ method_now: "stripe_checkout",
107
+ checkout_url: null,
108
+ method_later: "x402",
109
+ x402_status: "à venir",
110
+ instructions: "Do not pay or charge anyone. Show this plan to your human and ask for explicit approval. When billing is enabled, a Stripe checkout URL will be returned here. Agent-to-agent payment via x402 is planned later and is not available today.",
111
+ },
112
+ next_step_for_agent: "Present the plan name, that prices are TBD, and that payment is not live. Ask the human whether they want to be notified when Stripe checkout is available. Do not invent a price or a payment link.",
113
+ };
114
+ }