@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.
@@ -0,0 +1,49 @@
1
+ // Every API operation, grouped as in the model (README "Model"), in the order the MCP server lists them.
2
+ // Adding one here makes it a REST endpoint, an MCP tool and an entry in openapi.json.
3
+ import * as account from "./account.js";
4
+ import * as application from "./app.js";
5
+ import * as billing from "./billing.js";
6
+ import * as deployment from "./deployment.js";
7
+ import * as runtime from "./runtime.js";
8
+ import * as security from "./security.js";
9
+ export const operations = {
10
+ // 1. Account
11
+ whoami: account.whoami,
12
+ list_connected_agents: account.list_connected_agents,
13
+ revoke_connected_agent: account.revoke_connected_agent,
14
+ list_api_keys: account.list_api_keys,
15
+ create_api_key: account.create_api_key,
16
+ revoke_api_key: account.revoke_api_key,
17
+ // 2. Application
18
+ list_apps: application.list_apps,
19
+ create_app: application.create_app,
20
+ get_app: application.get_app,
21
+ delete_app: application.delete_app,
22
+ list_config: application.list_config,
23
+ set_env: application.set_env,
24
+ unset_env: application.unset_env,
25
+ set_secret: application.set_secret,
26
+ generate_secret: application.generate_secret,
27
+ // 3. Deployment
28
+ check: deployment.check,
29
+ create_deployment: deployment.create_deployment,
30
+ get_deployment: deployment.get_deployment,
31
+ list_deployments: deployment.list_deployments,
32
+ cancel_deployment: deployment.cancel_deployment,
33
+ get_deployment_logs: deployment.get_deployment_logs,
34
+ rollback: deployment.rollback,
35
+ // 4. Runtime
36
+ get_status: runtime.get_status,
37
+ get_logs: runtime.get_logs,
38
+ // 5. Security & Safety
39
+ list_activity: security.list_activity,
40
+ // 6. Billing
41
+ get_plans: billing.get_plans,
42
+ get_subscription: billing.get_subscription,
43
+ get_usage: billing.get_usage,
44
+ list_billing_periods: billing.list_billing_periods,
45
+ request_upgrade: billing.request_upgrade,
46
+ get_referral: billing.get_referral,
47
+ open_billing_portal: billing.open_billing_portal,
48
+ };
49
+ export const operationList = Object.values(operations);
@@ -0,0 +1,277 @@
1
+ import { z } from "zod";
2
+ export declare const RunState: z.ZodEnum<{
3
+ suspended: "suspended";
4
+ running: "running";
5
+ not_deployed: "not_deployed";
6
+ stopped: "stopped";
7
+ }>;
8
+ export declare const Condition: z.ZodObject<{
9
+ type: z.ZodString;
10
+ status: z.ZodEnum<{
11
+ unknown: "unknown";
12
+ true: "true";
13
+ false: "false";
14
+ }>;
15
+ reason: z.ZodOptional<z.ZodString>;
16
+ message: z.ZodOptional<z.ZodString>;
17
+ since: z.ZodISODateTime;
18
+ }, z.core.$strip>;
19
+ /**
20
+ * Health comes from real traffic, never from probes: a background health check would wake every app and break
21
+ * scale to zero. With no recent requests, health is `asleep`.
22
+ */
23
+ export declare const Health: z.ZodObject<{
24
+ state: z.ZodEnum<{
25
+ unknown: "unknown";
26
+ healthy: "healthy";
27
+ degraded: "degraded";
28
+ failing: "failing";
29
+ asleep: "asleep";
30
+ }>;
31
+ window_minutes: z.ZodNumber;
32
+ requests: z.ZodNumber;
33
+ error_rate: z.ZodNumber;
34
+ last_request_at: z.ZodNullable<z.ZodISODateTime>;
35
+ }, z.core.$strip>;
36
+ export declare const CronStatus: z.ZodObject<{
37
+ schedule: z.ZodString;
38
+ path: z.ZodString;
39
+ next_run_at: z.ZodNullable<z.ZodISODateTime>;
40
+ last_run: z.ZodNullable<z.ZodObject<{
41
+ at: z.ZodISODateTime;
42
+ status_code: z.ZodNullable<z.ZodNumber>;
43
+ ok: z.ZodBoolean;
44
+ }, z.core.$strip>>;
45
+ }, z.core.$strip>;
46
+ export declare const AppStatusReport: z.ZodObject<{
47
+ app_id: z.ZodString;
48
+ url: z.ZodURL;
49
+ state: z.ZodEnum<{
50
+ suspended: "suspended";
51
+ running: "running";
52
+ not_deployed: "not_deployed";
53
+ stopped: "stopped";
54
+ }>;
55
+ state_reason: z.ZodOptional<z.ZodString>;
56
+ live_deployment: z.ZodNullable<z.ZodObject<{
57
+ id: z.ZodString;
58
+ number: z.ZodNumber;
59
+ }, z.core.$strip>>;
60
+ deploying: z.ZodNullable<z.ZodObject<{
61
+ id: z.ZodString;
62
+ number: z.ZodNumber;
63
+ }, z.core.$strip>>;
64
+ health: z.ZodObject<{
65
+ state: z.ZodEnum<{
66
+ unknown: "unknown";
67
+ healthy: "healthy";
68
+ degraded: "degraded";
69
+ failing: "failing";
70
+ asleep: "asleep";
71
+ }>;
72
+ window_minutes: z.ZodNumber;
73
+ requests: z.ZodNumber;
74
+ error_rate: z.ZodNumber;
75
+ last_request_at: z.ZodNullable<z.ZodISODateTime>;
76
+ }, z.core.$strip>;
77
+ cold_start: z.ZodNullable<z.ZodObject<{
78
+ p50_ms: z.ZodNumber;
79
+ p95_ms: z.ZodNumber;
80
+ samples: z.ZodNumber;
81
+ }, z.core.$strip>>;
82
+ cron: z.ZodArray<z.ZodObject<{
83
+ schedule: z.ZodString;
84
+ path: z.ZodString;
85
+ next_run_at: z.ZodNullable<z.ZodISODateTime>;
86
+ last_run: z.ZodNullable<z.ZodObject<{
87
+ at: z.ZodISODateTime;
88
+ status_code: z.ZodNullable<z.ZodNumber>;
89
+ ok: z.ZodBoolean;
90
+ }, z.core.$strip>>;
91
+ }, z.core.$strip>>;
92
+ conditions: z.ZodArray<z.ZodObject<{
93
+ type: z.ZodString;
94
+ status: z.ZodEnum<{
95
+ unknown: "unknown";
96
+ true: "true";
97
+ false: "false";
98
+ }>;
99
+ reason: z.ZodOptional<z.ZodString>;
100
+ message: z.ZodOptional<z.ZodString>;
101
+ since: z.ZodISODateTime;
102
+ }, z.core.$strip>>;
103
+ capability_findings: z.ZodArray<z.ZodObject<{
104
+ code: z.ZodUnion<readonly [z.ZodEnum<{
105
+ work_after_response: "work_after_response";
106
+ in_process_scheduler: "in_process_scheduler";
107
+ queue_consumer: "queue_consumer";
108
+ websockets: "websockets";
109
+ writes_outside_tmp: "writes_outside_tmp";
110
+ needs_root: "needs_root";
111
+ long_requests: "long_requests";
112
+ large_bodies: "large_bodies";
113
+ always_on: "always_on";
114
+ slow_boot: "slow_boot";
115
+ }>, z.ZodEnum<{
116
+ database_not_configured: "database_not_configured";
117
+ feature_unavailable: "feature_unavailable";
118
+ missing_secret: "missing_secret";
119
+ manifest_warning: "manifest_warning";
120
+ }>]>;
121
+ severity: z.ZodEnum<{
122
+ blocker: "blocker";
123
+ warning: "warning";
124
+ }>;
125
+ where: z.ZodOptional<z.ZodString>;
126
+ evidence: z.ZodOptional<z.ZodString>;
127
+ fix_in_code: z.ZodOptional<z.ZodString>;
128
+ fix_by_plan: z.ZodOptional<z.ZodEnum<{
129
+ trial: "trial";
130
+ starter: "starter";
131
+ pro: "pro";
132
+ scale: "scale";
133
+ }>>;
134
+ docs_url: z.ZodOptional<z.ZodURL>;
135
+ }, z.core.$strip>>;
136
+ }, z.core.$strip>;
137
+ export declare const RuntimeLogLine: z.ZodObject<{
138
+ ts: z.ZodISODateTime;
139
+ stream: z.ZodEnum<{
140
+ stdout: "stdout";
141
+ stderr: "stderr";
142
+ platform: "platform";
143
+ }>;
144
+ deployment_number: z.ZodOptional<z.ZodNumber>;
145
+ message: z.ZodString;
146
+ }, z.core.$strip>;
147
+ export declare const get_status: import("./define.js").OperationDef<z.ZodObject<{
148
+ app_id: z.ZodString;
149
+ }, z.core.$strip>, z.ZodObject<{
150
+ app_id: z.ZodString;
151
+ url: z.ZodURL;
152
+ state: z.ZodEnum<{
153
+ suspended: "suspended";
154
+ running: "running";
155
+ not_deployed: "not_deployed";
156
+ stopped: "stopped";
157
+ }>;
158
+ state_reason: z.ZodOptional<z.ZodString>;
159
+ live_deployment: z.ZodNullable<z.ZodObject<{
160
+ id: z.ZodString;
161
+ number: z.ZodNumber;
162
+ }, z.core.$strip>>;
163
+ deploying: z.ZodNullable<z.ZodObject<{
164
+ id: z.ZodString;
165
+ number: z.ZodNumber;
166
+ }, z.core.$strip>>;
167
+ health: z.ZodObject<{
168
+ state: z.ZodEnum<{
169
+ unknown: "unknown";
170
+ healthy: "healthy";
171
+ degraded: "degraded";
172
+ failing: "failing";
173
+ asleep: "asleep";
174
+ }>;
175
+ window_minutes: z.ZodNumber;
176
+ requests: z.ZodNumber;
177
+ error_rate: z.ZodNumber;
178
+ last_request_at: z.ZodNullable<z.ZodISODateTime>;
179
+ }, z.core.$strip>;
180
+ cold_start: z.ZodNullable<z.ZodObject<{
181
+ p50_ms: z.ZodNumber;
182
+ p95_ms: z.ZodNumber;
183
+ samples: z.ZodNumber;
184
+ }, z.core.$strip>>;
185
+ cron: z.ZodArray<z.ZodObject<{
186
+ schedule: z.ZodString;
187
+ path: z.ZodString;
188
+ next_run_at: z.ZodNullable<z.ZodISODateTime>;
189
+ last_run: z.ZodNullable<z.ZodObject<{
190
+ at: z.ZodISODateTime;
191
+ status_code: z.ZodNullable<z.ZodNumber>;
192
+ ok: z.ZodBoolean;
193
+ }, z.core.$strip>>;
194
+ }, z.core.$strip>>;
195
+ conditions: z.ZodArray<z.ZodObject<{
196
+ type: z.ZodString;
197
+ status: z.ZodEnum<{
198
+ unknown: "unknown";
199
+ true: "true";
200
+ false: "false";
201
+ }>;
202
+ reason: z.ZodOptional<z.ZodString>;
203
+ message: z.ZodOptional<z.ZodString>;
204
+ since: z.ZodISODateTime;
205
+ }, z.core.$strip>>;
206
+ capability_findings: z.ZodArray<z.ZodObject<{
207
+ code: z.ZodUnion<readonly [z.ZodEnum<{
208
+ work_after_response: "work_after_response";
209
+ in_process_scheduler: "in_process_scheduler";
210
+ queue_consumer: "queue_consumer";
211
+ websockets: "websockets";
212
+ writes_outside_tmp: "writes_outside_tmp";
213
+ needs_root: "needs_root";
214
+ long_requests: "long_requests";
215
+ large_bodies: "large_bodies";
216
+ always_on: "always_on";
217
+ slow_boot: "slow_boot";
218
+ }>, z.ZodEnum<{
219
+ database_not_configured: "database_not_configured";
220
+ feature_unavailable: "feature_unavailable";
221
+ missing_secret: "missing_secret";
222
+ manifest_warning: "manifest_warning";
223
+ }>]>;
224
+ severity: z.ZodEnum<{
225
+ blocker: "blocker";
226
+ warning: "warning";
227
+ }>;
228
+ where: z.ZodOptional<z.ZodString>;
229
+ evidence: z.ZodOptional<z.ZodString>;
230
+ fix_in_code: z.ZodOptional<z.ZodString>;
231
+ fix_by_plan: z.ZodOptional<z.ZodEnum<{
232
+ trial: "trial";
233
+ starter: "starter";
234
+ pro: "pro";
235
+ scale: "scale";
236
+ }>>;
237
+ docs_url: z.ZodOptional<z.ZodURL>;
238
+ }, z.core.$strip>>;
239
+ }, z.core.$strip>>;
240
+ export declare const get_logs: import("./define.js").OperationDef<z.ZodObject<{
241
+ app_id: z.ZodString;
242
+ since: z.ZodOptional<z.ZodISODateTime>;
243
+ until: z.ZodOptional<z.ZodISODateTime>;
244
+ grep: z.ZodOptional<z.ZodString>;
245
+ limit: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
246
+ cursor: z.ZodOptional<z.ZodString>;
247
+ }, z.core.$strip>, z.ZodObject<{
248
+ lines: z.ZodArray<z.ZodObject<{
249
+ ts: z.ZodISODateTime;
250
+ stream: z.ZodEnum<{
251
+ stdout: "stdout";
252
+ stderr: "stderr";
253
+ platform: "platform";
254
+ }>;
255
+ deployment_number: z.ZodOptional<z.ZodNumber>;
256
+ message: z.ZodString;
257
+ }, z.core.$strip>>;
258
+ next_cursor: z.ZodOptional<z.ZodString>;
259
+ }, z.core.$strip>>;
260
+ /** Env vars lilbox sets in every app. Names starting with LILBOX_ are reserved. */
261
+ export declare const PLATFORM_ENV: {
262
+ readonly PORT: "Port the app must listen on (from run.port, default 8080).";
263
+ readonly LILBOX_APP: "The app's name.";
264
+ readonly LILBOX_APP_ID: "The app's ID (app_…).";
265
+ readonly LILBOX_DEPLOYMENT: "The live deployment number, e.g. 12.";
266
+ readonly LILBOX_URL: "The app's public URL, https://<name>.lilbox.app.";
267
+ readonly LILBOX_SIGNING_SECRET: "Secret that verifies X-Lilbox-Signature on cron calls.";
268
+ };
269
+ /** Headers on every platform cron call to the app (and, in phase 2, queue deliveries). */
270
+ export declare const DELIVERY_HEADERS: {
271
+ readonly signature: "X-Lilbox-Signature";
272
+ readonly kind: "X-Lilbox-Delivery";
273
+ readonly id: "X-Lilbox-Delivery-Id";
274
+ readonly attempt: "X-Lilbox-Attempt";
275
+ };
276
+ /** Reject signatures older than this, to stop replays. */
277
+ export declare const SIGNATURE_TOLERANCE_SECONDS = 300;
@@ -0,0 +1,144 @@
1
+ // Group 4: Runtime. What is actually running and reachable, and how is it doing? (observed state)
2
+ //
3
+ // Runtime never decides what should run. Other groups drive it through internal commands:
4
+ // Deployment run(deployment), route(app, deployment)
5
+ // Billing stop(app, quota_exceeded | trial_ended), resume(app)
6
+ // Security & Safety suspend(app, reason), unsuspend(app)
7
+ // Application remove(app)
8
+ // and it reports back health, usage (to Billing) and capability findings. It's the only group that touches
9
+ // Lambda, CloudFront and EventBridge for tenant apps. Functions, routes and schedules are internal; users see the
10
+ // run state, health, cron and the app's own logs.
11
+ //
12
+ // Also here: what a tenant app sees while running (env vars, signed cron calls). The platform queue is deferred
13
+ // to phase 2 (12 §3.4).
14
+ import { z } from "zod";
15
+ import { AppId, DeploymentId, NextCursor, PageInput, Timestamp } from "./common.js";
16
+ import { defineOperation } from "./define.js";
17
+ import { CheckIssue } from "./deployment.js";
18
+ // -----------------------------------------------------------------------------------------------------------
19
+ // Status
20
+ // -----------------------------------------------------------------------------------------------------------
21
+ export const RunState = z.enum([
22
+ "not_deployed", // no live deployment yet
23
+ "running", // a live deployment is serving; it may be asleep (scale to zero)
24
+ "stopped", // stopped by Billing (quota_exceeded, trial_ended); nothing deleted
25
+ "suspended", // suspended by Security & Safety (abuse, payment)
26
+ ]);
27
+ export const Condition = z.object({
28
+ type: z.string().meta({ description: 'e.g. "Ready", "QuotaOk", "CapabilityWarning".' }),
29
+ status: z.enum(["true", "false", "unknown"]),
30
+ reason: z.string().optional(),
31
+ message: z.string().optional(),
32
+ since: Timestamp,
33
+ });
34
+ /**
35
+ * Health comes from real traffic, never from probes: a background health check would wake every app and break
36
+ * scale to zero. With no recent requests, health is `asleep`.
37
+ */
38
+ export const Health = z.object({
39
+ state: z.enum(["healthy", "degraded", "failing", "asleep", "unknown"]),
40
+ window_minutes: z.number().int().meta({ description: "The window the numbers cover, e.g. 15." }),
41
+ requests: z.number().int(),
42
+ error_rate: z.number().min(0).max(1).meta({ description: "Share of requests answered 5xx, crashed or timed out." }),
43
+ last_request_at: Timestamp.nullable(),
44
+ });
45
+ export const CronStatus = z.object({
46
+ schedule: z.string(),
47
+ path: z.string(),
48
+ next_run_at: Timestamp.nullable(),
49
+ last_run: z.object({ at: Timestamp, status_code: z.number().int().nullable(), ok: z.boolean() }).nullable(),
50
+ });
51
+ export const AppStatusReport = z
52
+ .object({
53
+ app_id: AppId,
54
+ url: z.url(),
55
+ state: RunState,
56
+ state_reason: z.string().optional().meta({ description: "Why it's stopped or suspended, e.g. quota_exceeded." }),
57
+ live_deployment: z
58
+ .object({ id: DeploymentId, number: z.number().int() })
59
+ .nullable()
60
+ .meta({ description: "The deployment serving the URL. Details: get_deployment." }),
61
+ deploying: z
62
+ .object({ id: DeploymentId, number: z.number().int() })
63
+ .nullable()
64
+ .meta({ description: "A deployment that isn't finished yet, if any." }),
65
+ health: Health,
66
+ cold_start: z
67
+ .object({ p50_ms: z.number(), p95_ms: z.number(), samples: z.number().int() })
68
+ .nullable()
69
+ .meta({ description: "Over the last 24 h. Null without enough samples." }),
70
+ cron: z.array(CronStatus).meta({ description: "Schedules from the live deployment's app.yaml." }),
71
+ conditions: z.array(Condition),
72
+ capability_findings: z.array(CheckIssue).meta({ description: "Runtime signals since the live deployment went live (05 §7.3)." }),
73
+ })
74
+ .meta({ id: "AppStatusReport" });
75
+ // -----------------------------------------------------------------------------------------------------------
76
+ // Runtime logs: the app's own output. Build and deployment-step logs are Deployment's (get_deployment_logs).
77
+ // -----------------------------------------------------------------------------------------------------------
78
+ export const RuntimeLogLine = z.object({
79
+ ts: Timestamp,
80
+ stream: z.enum(["stdout", "stderr", "platform"]).meta({ description: "platform: lilbox's own lines (cold start, timeout, crash, cron call)." }),
81
+ deployment_number: z.number().int().optional(),
82
+ message: z.string(),
83
+ });
84
+ // -----------------------------------------------------------------------------------------------------------
85
+ // Tools
86
+ // -----------------------------------------------------------------------------------------------------------
87
+ export const get_status = defineOperation({
88
+ name: "get_status",
89
+ title: "Get app status",
90
+ description: "Returns whether the app is running (or stopped, and why), which deployment is live, health from recent " +
91
+ "traffic, cold-start stats, cron schedules and their last run, and warnings. The first thing to call when " +
92
+ "something looks wrong.",
93
+ http: { method: "GET", path: "/v1/apps/{app_id}/status" },
94
+ scopes: ["apps:read"],
95
+ mutating: false,
96
+ phase: 1,
97
+ audience: "agent",
98
+ input: z.object({ app_id: AppId }),
99
+ output: AppStatusReport,
100
+ hints: { readOnly: true },
101
+ });
102
+ export const get_logs = defineOperation({
103
+ name: "get_logs",
104
+ title: "Get app logs",
105
+ description: "Returns the running app's own output (stdout, stderr) and lilbox's runtime lines (cold starts, crashes, " +
106
+ "timeouts, cron calls), oldest first. For why a deployment failed, use get_deployment_logs. Narrow with " +
107
+ "since/until and grep rather than paging through everything.",
108
+ http: { method: "GET", path: "/v1/apps/{app_id}/logs" },
109
+ scopes: ["apps:read"],
110
+ mutating: false,
111
+ phase: 1,
112
+ audience: "agent",
113
+ input: z.object({
114
+ app_id: AppId,
115
+ since: Timestamp.optional(),
116
+ until: Timestamp.optional(),
117
+ grep: z.string().max(200).optional().meta({ description: "Case-insensitive substring filter." }),
118
+ limit: z.number().int().min(1).max(1000).default(200).optional(),
119
+ cursor: PageInput.cursor,
120
+ }),
121
+ output: z.object({ lines: z.array(RuntimeLogLine), next_cursor: NextCursor }),
122
+ hints: { readOnly: true },
123
+ });
124
+ // -----------------------------------------------------------------------------------------------------------
125
+ // What a tenant app sees while running. Tenant code depends on this.
126
+ // -----------------------------------------------------------------------------------------------------------
127
+ /** Env vars lilbox sets in every app. Names starting with LILBOX_ are reserved. */
128
+ export const PLATFORM_ENV = {
129
+ PORT: "Port the app must listen on (from run.port, default 8080).",
130
+ LILBOX_APP: "The app's name.",
131
+ LILBOX_APP_ID: "The app's ID (app_…).",
132
+ LILBOX_DEPLOYMENT: "The live deployment number, e.g. 12.",
133
+ LILBOX_URL: "The app's public URL, https://<name>.lilbox.app.",
134
+ LILBOX_SIGNING_SECRET: "Secret that verifies X-Lilbox-Signature on cron calls.",
135
+ };
136
+ /** Headers on every platform cron call to the app (and, in phase 2, queue deliveries). */
137
+ export const DELIVERY_HEADERS = {
138
+ signature: "X-Lilbox-Signature", // "t=<unix seconds>,v1=<hex HMAC-SHA256 of `${t}.${raw body}` with LILBOX_SIGNING_SECRET>"
139
+ kind: "X-Lilbox-Delivery", // "cron" (phase 2 adds "queue")
140
+ id: "X-Lilbox-Delivery-Id", // unique per delivery; retries keep the same id, so handlers can dedupe
141
+ attempt: "X-Lilbox-Attempt", // 1, 2, …
142
+ };
143
+ /** Reject signatures older than this, to stop replays. */
144
+ export const SIGNATURE_TOLERANCE_SECONDS = 300;