@lilbox/contracts 0.0.0-stage → 0.0.2
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/LICENSE +21 -0
- package/README.md +66 -2
- package/dist/account.d.ts +175 -0
- package/dist/account.js +156 -0
- package/dist/app.d.ts +860 -0
- package/dist/app.js +169 -0
- package/dist/billing.d.ts +396 -0
- package/dist/billing.js +215 -0
- package/dist/common.d.ts +43 -0
- package/dist/common.js +59 -0
- package/dist/define.d.ts +29 -0
- package/dist/define.js +16 -0
- package/dist/deployment.d.ts +1495 -0
- package/dist/deployment.js +297 -0
- package/dist/errors.d.ts +141 -0
- package/dist/errors.js +58 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +20 -0
- package/dist/manifest.d.ts +101 -0
- package/dist/manifest.js +78 -0
- package/dist/mcp-tools.json +7748 -0
- package/dist/openapi.d.ts +60 -0
- package/dist/openapi.js +156 -0
- package/dist/openapi.json +5349 -0
- package/dist/registry.d.ts +2393 -0
- package/dist/registry.js +49 -0
- package/dist/runtime.d.ts +277 -0
- package/dist/runtime.js +144 -0
- package/dist/schemas/app.schema.json +256 -0
- package/dist/security.d.ts +127 -0
- package/dist/security.js +64 -0
- package/package.json +29 -4
package/dist/billing.js
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// Group 6: Billing. What does the account pay for, what did it use, and what happens at a limit?
|
|
2
|
+
//
|
|
3
|
+
// Entities:
|
|
4
|
+
// Plan the catalog: static, defined here, not stored per user
|
|
5
|
+
// Subscription one per owner (a user today): plan and status, updated in place; points at the open period
|
|
6
|
+
// Billing period one per owner per period, kept forever: dates, plan, usage (hourly while open, frozen at
|
|
7
|
+
// close, per app too) and a copy of the period's Stripe invoice
|
|
8
|
+
// Bonus extra on top of the plan's limits; today only the referral (+6 apps: Starter 3 → 9)
|
|
9
|
+
//
|
|
10
|
+
// Billing is the only group that talks to Stripe. Stripe charges, retries, emails receipts and keeps the
|
|
11
|
+
// invoice PDFs; Billing mirrors what it needs from webhooks, and Stripe wins if the two disagree. Usage is
|
|
12
|
+
// lilbox's own data (Starter is a flat price, so Stripe never sees it); frozen periods feed unit economics and,
|
|
13
|
+
// in phase 2, overage.
|
|
14
|
+
//
|
|
15
|
+
// Billing never stops anything itself: at a limit, or when a trial or subscription ends, it tells Runtime to
|
|
16
|
+
// stop(app, reason) and Deployment to refuse builds. Nothing is deleted.
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
import { AppId, BillingPeriodId, BillingPlanCode, NextCursor, PageInput, RuntimeKind, Timestamp } from "./common.js";
|
|
19
|
+
import { defineOperation } from "./define.js";
|
|
20
|
+
import { CapabilityCode } from "./manifest.js";
|
|
21
|
+
// -----------------------------------------------------------------------------------------------------------
|
|
22
|
+
// Plan (catalog)
|
|
23
|
+
// -----------------------------------------------------------------------------------------------------------
|
|
24
|
+
export const Meter = z.enum([
|
|
25
|
+
"apps", // apps existing (a level, not a sum)
|
|
26
|
+
"compute_hours", // CH: GB-hours of the apps' functions, normalised to the nano size
|
|
27
|
+
"requests",
|
|
28
|
+
"egress_gb", // responses to visitors, through CloudFront
|
|
29
|
+
"build_minutes",
|
|
30
|
+
]);
|
|
31
|
+
export const BillingPlan = z
|
|
32
|
+
.object({
|
|
33
|
+
code: BillingPlanCode,
|
|
34
|
+
name: z.string(),
|
|
35
|
+
monthly_usd: z.number(),
|
|
36
|
+
available: z.boolean().meta({ description: "False for plans that can't be bought yet (Pro in phase 1)." }),
|
|
37
|
+
waitlist_url: z.url().optional(),
|
|
38
|
+
runtimes: z.array(RuntimeKind),
|
|
39
|
+
limits: z.record(Meter, z.number()).meta({ description: "Per billing period, before bonuses." }),
|
|
40
|
+
capabilities: z.array(CapabilityCode).meta({ description: "Capabilities this plan's runtimes provide." }),
|
|
41
|
+
features: z.array(z.string()),
|
|
42
|
+
})
|
|
43
|
+
.meta({ id: "BillingPlan" });
|
|
44
|
+
// -----------------------------------------------------------------------------------------------------------
|
|
45
|
+
// Subscription
|
|
46
|
+
// -----------------------------------------------------------------------------------------------------------
|
|
47
|
+
export const SubscriptionStatus = z.enum([
|
|
48
|
+
"trialing", // trial; the clock starts at the first live deployment
|
|
49
|
+
"active",
|
|
50
|
+
"past_due", // a payment failed; Stripe retries during the grace period and apps keep running
|
|
51
|
+
"canceled", // cancelled, or Stripe gave up on payment; apps stopped, nothing deleted
|
|
52
|
+
"expired", // the trial ended without subscribing; apps stopped, nothing deleted
|
|
53
|
+
]);
|
|
54
|
+
export const Subscription = z
|
|
55
|
+
.object({
|
|
56
|
+
plan: BillingPlanCode,
|
|
57
|
+
status: SubscriptionStatus,
|
|
58
|
+
trial_started_at: Timestamp.nullable().meta({ description: "Null until the first deployment goes live." }),
|
|
59
|
+
trial_ends_at: Timestamp.nullable(),
|
|
60
|
+
cancel_at_period_end: z.boolean(),
|
|
61
|
+
current_period_id: BillingPeriodId.nullable().meta({ description: "The open billing period. Null before the trial clock starts." }),
|
|
62
|
+
})
|
|
63
|
+
.meta({ id: "Subscription" });
|
|
64
|
+
// -----------------------------------------------------------------------------------------------------------
|
|
65
|
+
// Billing period
|
|
66
|
+
// -----------------------------------------------------------------------------------------------------------
|
|
67
|
+
export const MeterUsage = z.object({
|
|
68
|
+
meter: Meter,
|
|
69
|
+
used: z.number(),
|
|
70
|
+
limit: z.number().meta({ description: "The plan's limit plus bonuses." }),
|
|
71
|
+
unit: z.string(),
|
|
72
|
+
state: z.enum(["ok", "warning", "exceeded"]).meta({ description: "warning from 80%. For a closed period: the highest reached." }),
|
|
73
|
+
by_app: z
|
|
74
|
+
.array(z.object({ app_id: AppId, used: z.number() }))
|
|
75
|
+
.optional()
|
|
76
|
+
.meta({ description: "Per app; returned when asked for, always stored." }),
|
|
77
|
+
});
|
|
78
|
+
export const InvoiceCopy = z
|
|
79
|
+
.object({
|
|
80
|
+
number: z.string().meta({ description: 'Stripe\'s invoice number, e.g. "LILBOX-0042".' }),
|
|
81
|
+
amount: z.number().meta({ description: "In the currency's major unit, e.g. 20.00." }),
|
|
82
|
+
currency: z.string().length(3),
|
|
83
|
+
status: z.enum(["draft", "open", "paid", "failed", "void"]),
|
|
84
|
+
paid_at: Timestamp.nullable(),
|
|
85
|
+
hosted_url: z.url().nullable().meta({ description: "Stripe's page for the invoice." }),
|
|
86
|
+
pdf_url: z.url().nullable(),
|
|
87
|
+
})
|
|
88
|
+
.meta({ id: "InvoiceCopy", description: "A copy of the Stripe invoice for this period. Stripe is the source of truth." });
|
|
89
|
+
export const BillingPeriod = z
|
|
90
|
+
.object({
|
|
91
|
+
id: BillingPeriodId,
|
|
92
|
+
from: Timestamp,
|
|
93
|
+
to: Timestamp,
|
|
94
|
+
plan: BillingPlanCode,
|
|
95
|
+
status: z.enum(["open", "closed"]).meta({ description: "open: usage updated hourly. closed: usage frozen." }),
|
|
96
|
+
usage: z.array(MeterUsage),
|
|
97
|
+
measured_at: Timestamp.meta({ description: "When usage was last measured (about hourly while open)." }),
|
|
98
|
+
invoice: InvoiceCopy.nullable().meta({ description: "Null for trial periods. Starter is invoiced at the start of the period it pays for." }),
|
|
99
|
+
})
|
|
100
|
+
.meta({ id: "BillingPeriod" });
|
|
101
|
+
export const Bonus = z.object({
|
|
102
|
+
meter: Meter,
|
|
103
|
+
amount: z.number(),
|
|
104
|
+
source: z.enum(["referral", "promotion", "support"]),
|
|
105
|
+
});
|
|
106
|
+
export const Referral = z
|
|
107
|
+
.object({
|
|
108
|
+
url: z.url(),
|
|
109
|
+
code: z.string(),
|
|
110
|
+
reward: z.object({ apps: z.number().int() }),
|
|
111
|
+
redeemed: z.boolean(),
|
|
112
|
+
})
|
|
113
|
+
.meta({ id: "Referral" });
|
|
114
|
+
// -----------------------------------------------------------------------------------------------------------
|
|
115
|
+
// Tools
|
|
116
|
+
// -----------------------------------------------------------------------------------------------------------
|
|
117
|
+
export const get_plans = defineOperation({
|
|
118
|
+
name: "get_plans",
|
|
119
|
+
title: "Get plans",
|
|
120
|
+
description: "Lists billing plans with price, limits, runtimes and capabilities, and whether each can be bought now. Plans " +
|
|
121
|
+
"marked available: false have a waitlist_url.",
|
|
122
|
+
http: { method: "GET", path: "/v1/plans" },
|
|
123
|
+
scopes: [],
|
|
124
|
+
mutating: false,
|
|
125
|
+
phase: 1,
|
|
126
|
+
audience: "agent",
|
|
127
|
+
input: z.object({}),
|
|
128
|
+
output: z.object({ plans: z.array(BillingPlan) }),
|
|
129
|
+
hints: { readOnly: true },
|
|
130
|
+
});
|
|
131
|
+
export const get_subscription = defineOperation({
|
|
132
|
+
name: "get_subscription",
|
|
133
|
+
title: "Get subscription",
|
|
134
|
+
description: "Returns the account's plan, status (trialing, active, past_due, canceled, expired), when the trial ends and " +
|
|
135
|
+
"the bonuses on top of the plan's limits.",
|
|
136
|
+
http: { method: "GET", path: "/v1/subscription" },
|
|
137
|
+
scopes: ["billing:read"],
|
|
138
|
+
mutating: false,
|
|
139
|
+
phase: 1,
|
|
140
|
+
audience: "agent",
|
|
141
|
+
input: z.object({}),
|
|
142
|
+
output: z.object({ subscription: Subscription, bonuses: z.array(Bonus) }),
|
|
143
|
+
hints: { readOnly: true },
|
|
144
|
+
});
|
|
145
|
+
export const get_usage = defineOperation({
|
|
146
|
+
name: "get_usage",
|
|
147
|
+
title: "Get usage",
|
|
148
|
+
description: "Returns the open billing period: its dates, and each meter's use against its limit. At a limit, builds are " +
|
|
149
|
+
"refused and apps stop until the period resets or the plan changes; nothing is deleted. Usage is measured " +
|
|
150
|
+
"about hourly.",
|
|
151
|
+
http: { method: "GET", path: "/v1/usage" },
|
|
152
|
+
scopes: ["billing:read"],
|
|
153
|
+
mutating: false,
|
|
154
|
+
phase: 1,
|
|
155
|
+
audience: "agent",
|
|
156
|
+
input: z.object({ by_app: z.boolean().default(false).optional().meta({ description: "Include each app's share." }) }),
|
|
157
|
+
output: z.object({ period: BillingPeriod.nullable().meta({ description: "Null before the trial clock starts." }) }),
|
|
158
|
+
hints: { readOnly: true },
|
|
159
|
+
});
|
|
160
|
+
export const list_billing_periods = defineOperation({
|
|
161
|
+
name: "list_billing_periods",
|
|
162
|
+
title: "List billing periods",
|
|
163
|
+
description: "Lists past and current billing periods, newest first, each with its dates, plan, frozen usage and invoice " +
|
|
164
|
+
"(number, amount, status, links). Use it to answer what was paid and what was used in a given month.",
|
|
165
|
+
http: { method: "GET", path: "/v1/billing-periods" },
|
|
166
|
+
scopes: ["billing:read"],
|
|
167
|
+
mutating: false,
|
|
168
|
+
phase: 1,
|
|
169
|
+
audience: "agent",
|
|
170
|
+
input: z.object({ by_app: z.boolean().default(false).optional(), ...PageInput }),
|
|
171
|
+
output: z.object({ periods: z.array(BillingPeriod), next_cursor: NextCursor }),
|
|
172
|
+
hints: { readOnly: true },
|
|
173
|
+
});
|
|
174
|
+
export const request_upgrade = defineOperation({
|
|
175
|
+
name: "request_upgrade",
|
|
176
|
+
title: "Subscribe or change plan",
|
|
177
|
+
description: "Returns a checkout URL for the human to subscribe or change plan. You can't complete it yourself: send them " +
|
|
178
|
+
"the link. Fails with plan_unavailable (with a waitlist_url) for plans that can't be bought yet.",
|
|
179
|
+
http: { method: "POST", path: "/v1/subscription/upgrade" },
|
|
180
|
+
scopes: ["billing:read"],
|
|
181
|
+
mutating: true,
|
|
182
|
+
phase: 1,
|
|
183
|
+
audience: "agent",
|
|
184
|
+
input: z.object({ plan: BillingPlanCode.exclude(["trial"]) }),
|
|
185
|
+
output: z.object({
|
|
186
|
+
status: z.enum(["checkout_required", "already_on_plan"]),
|
|
187
|
+
checkout_url: z.url().optional().meta({ description: "Stripe Checkout. Only a human can complete it." }),
|
|
188
|
+
}),
|
|
189
|
+
});
|
|
190
|
+
export const get_referral = defineOperation({
|
|
191
|
+
name: "get_referral",
|
|
192
|
+
title: "Get referral link",
|
|
193
|
+
description: "Returns the account's referral link: a friend who signs up through it unlocks 6 more apps for this " +
|
|
194
|
+
"account. Share it with the human only; never put it in app code, READMEs or deployed files.",
|
|
195
|
+
http: { method: "GET", path: "/v1/referral" },
|
|
196
|
+
scopes: ["billing:read"],
|
|
197
|
+
mutating: false,
|
|
198
|
+
phase: 1,
|
|
199
|
+
audience: "agent",
|
|
200
|
+
input: z.object({}),
|
|
201
|
+
output: Referral,
|
|
202
|
+
hints: { readOnly: true },
|
|
203
|
+
});
|
|
204
|
+
export const open_billing_portal = defineOperation({
|
|
205
|
+
name: "open_billing_portal",
|
|
206
|
+
title: "Open the billing portal",
|
|
207
|
+
description: "Returns a Stripe Customer Portal URL to change the card, see invoices or cancel.",
|
|
208
|
+
http: { method: "POST", path: "/v1/subscription/portal" },
|
|
209
|
+
scopes: [],
|
|
210
|
+
mutating: true,
|
|
211
|
+
phase: 1,
|
|
212
|
+
audience: "human",
|
|
213
|
+
input: z.object({ return_url: z.url().optional() }),
|
|
214
|
+
output: z.object({ url: z.url() }),
|
|
215
|
+
});
|
package/dist/common.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Builds an ID schema for one prefix, e.g. id("app") accepts "app_01jabc…". */
|
|
3
|
+
export declare const id: (prefix: string) => z.ZodString;
|
|
4
|
+
export declare const UserId: z.ZodString;
|
|
5
|
+
export declare const AppId: z.ZodString;
|
|
6
|
+
export declare const DeploymentId: z.ZodString;
|
|
7
|
+
export declare const ActivityEventId: z.ZodString;
|
|
8
|
+
export declare const ApiKeyId: z.ZodString;
|
|
9
|
+
export declare const BillingPeriodId: z.ZodString;
|
|
10
|
+
export declare const AgentGrantId: z.ZodString;
|
|
11
|
+
/** Billing plans. Shared because Account (whoami), Deployment (check options) and Billing all name them. */
|
|
12
|
+
export declare const BillingPlanCode: z.ZodEnum<{
|
|
13
|
+
trial: "trial";
|
|
14
|
+
starter: "starter";
|
|
15
|
+
pro: "pro";
|
|
16
|
+
scale: "scale";
|
|
17
|
+
}>;
|
|
18
|
+
/** Where a deployment runs: serverless (Lambda, every plan) or container (Fargate, Pro). */
|
|
19
|
+
export declare const RuntimeKind: z.ZodEnum<{
|
|
20
|
+
serverless: "serverless";
|
|
21
|
+
container: "container";
|
|
22
|
+
}>;
|
|
23
|
+
/** RFC 3339 timestamp in UTC, e.g. "2026-12-02T18:30:00Z". */
|
|
24
|
+
export declare const Timestamp: z.ZodISODateTime;
|
|
25
|
+
/**
|
|
26
|
+
* App names are also the hostname: <name>.lilbox.app. One DNS label: lowercase letters, digits and hyphens,
|
|
27
|
+
* starting with a letter, 3–32 characters, no trailing hyphen. Names in RESERVED_APP_NAMES are refused by
|
|
28
|
+
* the API with `conflict`.
|
|
29
|
+
*/
|
|
30
|
+
export declare const AppName: z.ZodString;
|
|
31
|
+
/** Names the API never gives to an app (checked server-side; exported so clients can warn early). */
|
|
32
|
+
export declare const RESERVED_APP_NAMES: readonly string[];
|
|
33
|
+
/** Environment variable and secret names: what a POSIX shell accepts, uppercase by convention. */
|
|
34
|
+
export declare const EnvName: z.ZodString;
|
|
35
|
+
/** Cursor-based pagination input, shared by every list operation. */
|
|
36
|
+
export declare const PageInput: {
|
|
37
|
+
limit: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
38
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
39
|
+
};
|
|
40
|
+
/** Cursor for the next page, absent on the last page. */
|
|
41
|
+
export declare const NextCursor: z.ZodOptional<z.ZodString>;
|
|
42
|
+
/** Present on every mutating operation: preview the effect without changing anything. */
|
|
43
|
+
export declare const DryRun: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
package/dist/common.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Shared building blocks: IDs, names, timestamps, pagination.
|
|
2
|
+
//
|
|
3
|
+
// Every ID is a type prefix plus a lowercase base32 ULID-like body (app_01j…). The prefix lets humans, agents
|
|
4
|
+
// and logs tell IDs apart, and lets the API reject the wrong kind of ID with a clear error.
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
/** Builds an ID schema for one prefix, e.g. id("app") accepts "app_01jabc…". */
|
|
7
|
+
export const id = (prefix) => z
|
|
8
|
+
.string()
|
|
9
|
+
.regex(new RegExp(`^${prefix}_[0-9a-z]{16,40}$`), `must be an ID starting with "${prefix}_"`)
|
|
10
|
+
.meta({ description: `ID with the "${prefix}_" prefix.` });
|
|
11
|
+
export const UserId = id("usr"); // Account: owns apps and the subscription
|
|
12
|
+
export const AppId = id("app"); // Application
|
|
13
|
+
export const DeploymentId = id("dep"); // Deployment
|
|
14
|
+
export const ActivityEventId = id("evt"); // Security & Safety
|
|
15
|
+
export const ApiKeyId = id("key"); // Account
|
|
16
|
+
export const BillingPeriodId = id("bpr"); // Billing
|
|
17
|
+
export const AgentGrantId = id("agt"); // Account: a connected agent
|
|
18
|
+
/** Billing plans. Shared because Account (whoami), Deployment (check options) and Billing all name them. */
|
|
19
|
+
export const BillingPlanCode = z.enum(["trial", "starter", "pro", "scale"]);
|
|
20
|
+
/** Where a deployment runs: serverless (Lambda, every plan) or container (Fargate, Pro). */
|
|
21
|
+
export const RuntimeKind = z.enum(["serverless", "container"]);
|
|
22
|
+
/** RFC 3339 timestamp in UTC, e.g. "2026-12-02T18:30:00Z". */
|
|
23
|
+
export const Timestamp = z.iso.datetime().meta({ description: "RFC 3339 timestamp, UTC." });
|
|
24
|
+
/**
|
|
25
|
+
* App names are also the hostname: <name>.lilbox.app. One DNS label: lowercase letters, digits and hyphens,
|
|
26
|
+
* starting with a letter, 3–32 characters, no trailing hyphen. Names in RESERVED_APP_NAMES are refused by
|
|
27
|
+
* the API with `conflict`.
|
|
28
|
+
*/
|
|
29
|
+
export const AppName = z
|
|
30
|
+
.string()
|
|
31
|
+
.regex(/^[a-z][a-z0-9-]{1,30}[a-z0-9]$/, "3–32 characters: lowercase letters, digits and hyphens, starting with a letter")
|
|
32
|
+
.refine((n) => !n.includes("--"), "no consecutive hyphens")
|
|
33
|
+
.meta({ description: "App name, also its hostname: <name>.lilbox.app." });
|
|
34
|
+
/** Names the API never gives to an app (checked server-side; exported so clients can warn early). */
|
|
35
|
+
export const RESERVED_APP_NAMES = [
|
|
36
|
+
"www", "api", "app", "apps", "admin", "auth", "mcp", "dashboard", "docs", "status", "mail", "email",
|
|
37
|
+
"smtp", "imap", "ftp", "cdn", "static", "assets", "edge", "internal", "lilbox", "support", "help",
|
|
38
|
+
"security", "abuse", "billing", "login", "signin", "signup", "account", "oauth", "root", "test",
|
|
39
|
+
];
|
|
40
|
+
/** Environment variable and secret names: what a POSIX shell accepts, uppercase by convention. */
|
|
41
|
+
export const EnvName = z
|
|
42
|
+
.string()
|
|
43
|
+
.regex(/^[A-Za-z_][A-Za-z0-9_]{0,127}$/, "letters, digits and underscores, not starting with a digit")
|
|
44
|
+
.refine((n) => !n.toUpperCase().startsWith("LILBOX_"), "the LILBOX_ prefix is reserved for the platform")
|
|
45
|
+
.refine((n) => !n.toUpperCase().startsWith("AWS_"), "the AWS_ prefix is reserved by the runtime")
|
|
46
|
+
.meta({ description: "Environment variable or secret name." });
|
|
47
|
+
/** Cursor-based pagination input, shared by every list operation. */
|
|
48
|
+
export const PageInput = {
|
|
49
|
+
limit: z.number().int().min(1).max(100).default(50).optional().meta({ description: "Page size, 1–100." }),
|
|
50
|
+
cursor: z.string().max(512).optional().meta({ description: "next_cursor from the previous page." }),
|
|
51
|
+
};
|
|
52
|
+
/** Cursor for the next page, absent on the last page. */
|
|
53
|
+
export const NextCursor = z.string().optional().meta({ description: "Pass as cursor to get the next page. Absent on the last page." });
|
|
54
|
+
/** Present on every mutating operation: preview the effect without changing anything. */
|
|
55
|
+
export const DryRun = z
|
|
56
|
+
.boolean()
|
|
57
|
+
.default(false)
|
|
58
|
+
.optional()
|
|
59
|
+
.meta({ description: "Validate and return what would happen, without changing anything." });
|
package/dist/define.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { Scope } from "./account.js";
|
|
3
|
+
export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
4
|
+
export interface OperationDef<I extends z.ZodObject = z.ZodObject, O extends z.ZodType = z.ZodType> {
|
|
5
|
+
name: string;
|
|
6
|
+
title: string;
|
|
7
|
+
description: string;
|
|
8
|
+
http: {
|
|
9
|
+
method: HttpMethod;
|
|
10
|
+
path: `/v1/${string}`;
|
|
11
|
+
};
|
|
12
|
+
scopes: z.infer<typeof Scope>[];
|
|
13
|
+
mutating: boolean;
|
|
14
|
+
phase: 1 | 2;
|
|
15
|
+
audience: "agent" | "human";
|
|
16
|
+
input: I;
|
|
17
|
+
output: O;
|
|
18
|
+
/** MCP hints: no side effects / may destroy data / safe to repeat. */
|
|
19
|
+
hints?: {
|
|
20
|
+
readOnly?: boolean;
|
|
21
|
+
destructive?: boolean;
|
|
22
|
+
idempotent?: boolean;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export declare const defineOperation: <I extends z.ZodObject, O extends z.ZodType>(def: OperationDef<I, O>) => OperationDef<I, O>;
|
|
26
|
+
/** Path parameter names in an operation's path, e.g. ["app_id"]. */
|
|
27
|
+
export declare const pathParams: (op: OperationDef) => string[];
|
|
28
|
+
export type Input<O extends OperationDef> = z.input<O["input"]>;
|
|
29
|
+
export type Output<O extends OperationDef> = z.output<O["output"]>;
|
package/dist/define.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// One definition per API operation ("operation" in the OpenAPI sense: an endpoint, not a domain entity). Each one is both a REST endpoint and an MCP tool with the same name,
|
|
2
|
+
// input and output (01 §11.1: "each operation is defined once").
|
|
3
|
+
//
|
|
4
|
+
// - `name` the MCP tool name, and the OpenAPI operationId.
|
|
5
|
+
// - `description` the MCP tool description: written for an agent, says when to call it and what comes next.
|
|
6
|
+
// - `http` method and path. `{param}` segments come from input fields of the same name; for GET and
|
|
7
|
+
// DELETE the remaining fields are query parameters, otherwise the JSON body.
|
|
8
|
+
// - `scopes` token scopes required (all of them).
|
|
9
|
+
// - `mutating` accepts Idempotency-Key and dry_run.
|
|
10
|
+
// - `phase` 1 = available at launch. Later operations are added, never changed.
|
|
11
|
+
// - `audience` agent = an MCP tool and a REST endpoint, callable with OAuth tokens and API keys.
|
|
12
|
+
// human = REST only, with the dashboard's session cookie (and a recent sign-in for sensitive
|
|
13
|
+
// actions). Never an MCP tool: an agent can't create its own credentials or widen its access.
|
|
14
|
+
export const defineOperation = (def) => def;
|
|
15
|
+
/** Path parameter names in an operation's path, e.g. ["app_id"]. */
|
|
16
|
+
export const pathParams = (op) => [...op.http.path.matchAll(/\{([a-z_]+)\}/g)].map((m) => m[1]);
|