@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,297 @@
1
+ // Group 3: Deployment. How does source become a live version?
2
+ //
3
+ // One entity, the Deployment: an attempt to make a new version of an app live, triggered by new source, a
4
+ // config change or a rollback. It goes through steps; it gets a number (v1, v2…) when created; when it
5
+ // succeeds it becomes live and the previous live one is superseded. Exactly one deployment per app is live.
6
+ //
7
+ // Source is a property of the deployment (upload, inline files, or a GitHub ref). Whatever the type, the worker
8
+ // stores an immutable source snapshot, which rollbacks and base_deployment_id reuse. Build is a step, not an
9
+ // entity. `check` is a stateless preview, run again as the first step of every deployment.
10
+ import { z } from "zod";
11
+ import { AppId, BillingPlanCode, DeploymentId, DryRun, NextCursor, PageInput, RuntimeKind, Timestamp, } from "./common.js";
12
+ import { defineOperation } from "./define.js";
13
+ import { ApiError } from "./errors.js";
14
+ import { CapabilityCode } from "./manifest.js";
15
+ // -----------------------------------------------------------------------------------------------------------
16
+ // Source
17
+ // -----------------------------------------------------------------------------------------------------------
18
+ /** Size limits for sources (01 §11.4b), by billing plan. Enforced server-side; exported for clients. */
19
+ export const SOURCE_LIMITS = {
20
+ trial: { upload_bytes: 50 * 1024 * 1024, inline_bytes: 2 * 1024 * 1024 },
21
+ starter: { upload_bytes: 100 * 1024 * 1024, inline_bytes: 4 * 1024 * 1024 },
22
+ pro: { upload_bytes: 500 * 1024 * 1024, inline_bytes: 4 * 1024 * 1024 },
23
+ scale: { upload_bytes: 500 * 1024 * 1024, inline_bytes: 4 * 1024 * 1024 },
24
+ };
25
+ export const InlineFile = z.object({
26
+ path: z
27
+ .string()
28
+ .min(1)
29
+ .max(512)
30
+ .refine((p) => !p.startsWith("/") && !p.split("/").includes(".."), "relative path inside the source, no ..")
31
+ .meta({ description: 'Path relative to the source root, e.g. "src/index.js".' }),
32
+ content: z.string(),
33
+ encoding: z.enum(["utf8", "base64"]).default("utf8").optional().meta({ description: "base64 for binary files." }),
34
+ });
35
+ /** A .tar.gz the caller PUTs to the upload_url returned with the deployment. What the lilbox CLI uses. */
36
+ export const UploadSource = z.object({
37
+ type: z.literal("upload"),
38
+ size_bytes: z.number().int().min(1),
39
+ sha256: z.string().regex(/^[0-9a-f]{64}$/),
40
+ });
41
+ /** Files in the call itself, for agents without a shell. With base_deployment_id, only what changed. */
42
+ export const FilesSource = z.object({
43
+ type: z.literal("files"),
44
+ files: z.array(InlineFile).max(2000),
45
+ base_deployment_id: DeploymentId.optional().meta({
46
+ description: "Start from this earlier deployment's source and apply only these files and deletions.",
47
+ }),
48
+ delete: z.array(z.string()).optional().meta({ description: "With base_deployment_id: paths to remove." }),
49
+ });
50
+ /** A commit from the app's connected GitHub repo (phase 2: not_available until then). */
51
+ export const GithubSource = z.object({
52
+ type: z.literal("github"),
53
+ ref: z.string().min(1).max(255).meta({ description: 'Branch, tag or commit SHA, e.g. "main".' }),
54
+ });
55
+ export const SourceInput = z
56
+ .discriminatedUnion("type", [UploadSource, FilesSource, GithubSource])
57
+ .refine((s) => s.type !== "files" || s.delete === undefined || s.base_deployment_id !== undefined, "delete needs base_deployment_id");
58
+ /** What a deployment records about where its source came from. */
59
+ export const SourceSummary = z.object({
60
+ type: z.enum(["upload", "files", "github"]),
61
+ sha256: z.string().optional(),
62
+ size_bytes: z.number().int().optional(),
63
+ file_count: z.number().int().optional(),
64
+ base_deployment_id: DeploymentId.optional(),
65
+ github: z.object({ repo: z.string(), ref: z.string(), commit_sha: z.string(), commit_message: z.string().optional() }).optional(),
66
+ });
67
+ // -----------------------------------------------------------------------------------------------------------
68
+ // Check: the stateless preview
69
+ // -----------------------------------------------------------------------------------------------------------
70
+ export const CheckIssueCode = z.union([
71
+ CapabilityCode,
72
+ z.enum([
73
+ "database_not_configured", // a database client or DATABASE_URL reference with no secret set
74
+ "feature_unavailable", // a manifest field the current phase or plan can't honour (database, runtime: container…)
75
+ "missing_secret", // a name in secrets: with no value set
76
+ "manifest_warning",
77
+ ]),
78
+ ]);
79
+ export const CheckIssue = z
80
+ .object({
81
+ code: CheckIssueCode,
82
+ severity: z.enum(["blocker", "warning"]),
83
+ where: z.string().optional().meta({ description: "file:line, manifest path, or 'smoke test: …'." }),
84
+ evidence: z.string().optional(),
85
+ fix_in_code: z.string().optional().meta({ description: "The code change that removes the issue, when there is one." }),
86
+ fix_by_plan: BillingPlanCode.optional().meta({ description: "The billing plan that removes the issue without code changes." }),
87
+ docs_url: z.url().optional(),
88
+ })
89
+ .meta({ id: "CheckIssue" });
90
+ export const PlanOption = z.object({
91
+ plan: BillingPlanCode,
92
+ monthly_usd: z.number(),
93
+ requires: z.string(),
94
+ available: z.boolean().meta({ description: "False for plans that can't be bought yet (Pro during phase 1)." }),
95
+ waitlist_url: z.url().optional(),
96
+ });
97
+ export const CheckResult = z
98
+ .object({
99
+ deployable: z.boolean().meta({ description: "False while any issue is a blocker." }),
100
+ runtime: RuntimeKind,
101
+ issues: z.array(CheckIssue),
102
+ options: z.array(PlanOption).meta({ description: "Ways to remove blockers: code changes first (in issues), then billing plans." }),
103
+ warnings: z.array(z.string()),
104
+ })
105
+ .meta({ id: "CheckResult" });
106
+ // -----------------------------------------------------------------------------------------------------------
107
+ // Deployment
108
+ // -----------------------------------------------------------------------------------------------------------
109
+ export const DeploymentStatus = z.enum([
110
+ "awaiting_source", // source.type upload: waiting for the PUT to upload_url
111
+ "queued",
112
+ "running",
113
+ "live", // the one serving the app's URL
114
+ "superseded", // was live; a newer deployment replaced it
115
+ "failed",
116
+ "cancelled",
117
+ ]);
118
+ export const DeploymentTrigger = z.enum([
119
+ "source", // create_deployment with new source
120
+ "config", // set_env, set_secret, generate_secret, unset_env
121
+ "rollback",
122
+ "git_push", // phase 2: push to the connected branch
123
+ ]);
124
+ export const StepName = z.enum([
125
+ "receive_source", // upload received, or files/commit turned into a snapshot
126
+ "check", // the same check as the check tool
127
+ "build", // the image
128
+ "smoke_test", // the image run under runtime conditions
129
+ "release", // Runtime runs the new image + config
130
+ "route", // the URL points at it
131
+ "health_check",
132
+ ]);
133
+ export const DeploymentStep = z.object({
134
+ name: StepName,
135
+ status: z.enum(["pending", "running", "succeeded", "failed", "skipped"]),
136
+ started_at: Timestamp.optional(),
137
+ finished_at: Timestamp.optional(),
138
+ message: z.string().optional(),
139
+ });
140
+ export const Deployment = z
141
+ .object({
142
+ id: DeploymentId,
143
+ app_id: AppId,
144
+ number: z.number().int().min(1).meta({ description: "v1, v2… per app, in creation order." }),
145
+ status: DeploymentStatus,
146
+ trigger: DeploymentTrigger,
147
+ source: SourceSummary,
148
+ rollback_of: DeploymentId.optional().meta({ description: "For rollbacks: the deployment whose image and config this reuses." }),
149
+ config_version: z.number().int(),
150
+ runtime: RuntimeKind.optional(),
151
+ image_digest: z.string().optional(),
152
+ steps: z.array(DeploymentStep),
153
+ check: CheckResult.optional().meta({ description: "The check step's result." }),
154
+ upload: z
155
+ .object({
156
+ url: z.url(),
157
+ method: z.literal("PUT"),
158
+ headers: z.record(z.string(), z.string()),
159
+ expires_at: Timestamp,
160
+ })
161
+ .optional()
162
+ .meta({ description: "While awaiting_source: PUT the .tar.gz here. The deployment starts when it arrives." }),
163
+ url: z.url().optional().meta({ description: "The app's URL, once live." }),
164
+ error: ApiError.optional().meta({ description: "Set when failed: code, log excerpt, suggestion." }),
165
+ created_by: z.object({ kind: z.enum(["user", "api_key", "github", "system"]), id: z.string() }),
166
+ created_at: Timestamp,
167
+ updated_at: Timestamp,
168
+ finished_at: Timestamp.optional(),
169
+ })
170
+ .meta({ id: "Deployment" });
171
+ // -----------------------------------------------------------------------------------------------------------
172
+ // Tools
173
+ // -----------------------------------------------------------------------------------------------------------
174
+ export const check = defineOperation({
175
+ name: "check",
176
+ title: "Check a source before deploying",
177
+ description: "Previews whether a source would deploy on this app's plan: validates app.yaml, detects what the app needs " +
178
+ "from the runtime, and lists blockers with the code fix first and the billing plan that would remove them " +
179
+ "second. Changes nothing. create_deployment runs the same check, so this is optional; use it to fix issues " +
180
+ "before spending a build.",
181
+ http: { method: "POST", path: "/v1/apps/{app_id}/check" },
182
+ scopes: ["deploy"],
183
+ mutating: false,
184
+ phase: 1,
185
+ audience: "agent",
186
+ input: z.object({
187
+ app_id: AppId,
188
+ source: z.discriminatedUnion("type", [FilesSource, GithubSource]).meta({
189
+ description: "Inline files or a GitHub ref. To check a CLI upload, create the deployment: it fails at the check step with the same issues.",
190
+ }),
191
+ ack: z.array(CapabilityCode).optional().meta({ description: "Capabilities you confirm the app does NOT need, after capability_unconfirmed." }),
192
+ }),
193
+ output: CheckResult,
194
+ hints: { readOnly: true },
195
+ });
196
+ export const create_deployment = defineOperation({
197
+ name: "create_deployment",
198
+ title: "Deploy",
199
+ description: "Deploys new source to the app and returns the deployment right away. Source is one of: upload (the " +
200
+ "lilbox CLI: PUT the .tar.gz to the returned upload.url and the deployment starts), files (inline, for agents " +
201
+ "without a shell), or github (a ref from the connected repo). Then poll get_deployment(wait_seconds) until it's " +
202
+ "live (it has the URL) or failed (it has an error with a log excerpt and a suggestion).",
203
+ http: { method: "POST", path: "/v1/apps/{app_id}/deployments" },
204
+ scopes: ["deploy"],
205
+ mutating: true,
206
+ phase: 1,
207
+ audience: "agent",
208
+ input: z.object({
209
+ app_id: AppId,
210
+ source: SourceInput,
211
+ ack: z.array(CapabilityCode).optional(),
212
+ dry_run: DryRun,
213
+ }),
214
+ output: z.object({ deployment: Deployment }),
215
+ });
216
+ export const get_deployment = defineOperation({
217
+ name: "get_deployment",
218
+ title: "Get a deployment",
219
+ description: "Returns a deployment's status and steps. With wait_seconds, waits up to that long for it to change before " +
220
+ "answering, so you can poll without sleeping. Repeat until live, failed or cancelled.",
221
+ http: { method: "GET", path: "/v1/deployments/{deployment_id}" },
222
+ scopes: ["apps:read"],
223
+ mutating: false,
224
+ phase: 1,
225
+ audience: "agent",
226
+ input: z.object({
227
+ deployment_id: DeploymentId,
228
+ wait_seconds: z.number().int().min(0).max(25).default(0).optional().meta({ description: "Long-poll up to 25 s." }),
229
+ }),
230
+ output: z.object({ deployment: Deployment }),
231
+ hints: { readOnly: true },
232
+ });
233
+ export const list_deployments = defineOperation({
234
+ name: "list_deployments",
235
+ title: "List deployments",
236
+ description: "Lists an app's deployments, newest first, with each one's status (one is live), trigger and source. Use a " +
237
+ "deployment ID with rollback.",
238
+ http: { method: "GET", path: "/v1/apps/{app_id}/deployments" },
239
+ scopes: ["apps:read"],
240
+ mutating: false,
241
+ phase: 1,
242
+ audience: "agent",
243
+ input: z.object({ app_id: AppId, status: DeploymentStatus.optional(), ...PageInput }),
244
+ output: z.object({ deployments: z.array(Deployment), next_cursor: NextCursor }),
245
+ hints: { readOnly: true },
246
+ });
247
+ export const cancel_deployment = defineOperation({
248
+ name: "cancel_deployment",
249
+ title: "Cancel a deployment",
250
+ description: "Cancels a deployment that isn't finished. The live deployment keeps serving.",
251
+ http: { method: "POST", path: "/v1/deployments/{deployment_id}/cancel" },
252
+ scopes: ["deploy"],
253
+ mutating: true,
254
+ phase: 1,
255
+ audience: "agent",
256
+ input: z.object({ deployment_id: DeploymentId }),
257
+ output: z.object({ deployment: Deployment }),
258
+ hints: { idempotent: true },
259
+ });
260
+ export const DeploymentLogLine = z.object({
261
+ ts: Timestamp,
262
+ step: StepName,
263
+ message: z.string(),
264
+ });
265
+ export const get_deployment_logs = defineOperation({
266
+ name: "get_deployment_logs",
267
+ title: "Get deployment logs",
268
+ description: "Returns a deployment's logs: the image build and each step (smoke test, release, health check). Use it when a " +
269
+ "deployment failed and its error's log_excerpt isn't enough. For the running app's output, use get_logs.",
270
+ http: { method: "GET", path: "/v1/deployments/{deployment_id}/logs" },
271
+ scopes: ["apps:read"],
272
+ mutating: false,
273
+ phase: 1,
274
+ audience: "agent",
275
+ input: z.object({
276
+ deployment_id: DeploymentId,
277
+ step: StepName.optional().meta({ description: "Only this step's lines, e.g. build." }),
278
+ grep: z.string().max(200).optional().meta({ description: "Case-insensitive substring filter." }),
279
+ limit: z.number().int().min(1).max(1000).default(200).optional(),
280
+ cursor: PageInput.cursor,
281
+ }),
282
+ output: z.object({ lines: z.array(DeploymentLogLine), next_cursor: NextCursor }),
283
+ hints: { readOnly: true },
284
+ });
285
+ export const rollback = defineOperation({
286
+ name: "rollback",
287
+ title: "Roll back",
288
+ description: "Creates a new deployment that reuses an earlier deployment's image and config, so it's fast (no build) and " +
289
+ "restores a combination that worked. Poll get_deployment.",
290
+ http: { method: "POST", path: "/v1/apps/{app_id}/rollback" },
291
+ scopes: ["deploy"],
292
+ mutating: true,
293
+ phase: 1,
294
+ audience: "agent",
295
+ input: z.object({ app_id: AppId, to_deployment_id: DeploymentId }),
296
+ output: z.object({ deployment: Deployment }),
297
+ });
@@ -0,0 +1,141 @@
1
+ import { z } from "zod";
2
+ export declare const ERROR_CODES: {
3
+ readonly unauthenticated: "No valid credentials. Sign in again or use a valid API key.";
4
+ readonly forbidden_scope: "The token lacks a scope this call needs. `details.required_scopes` lists them.";
5
+ readonly approval_required: "A human must approve this. `details.approval_url` is the page to send them to. (Phase 2: policy approvals.)";
6
+ readonly payment_required: "The account must subscribe (trial ended, or the feature needs a paid plan). `details.checkout_url` when available.";
7
+ readonly quota_exceeded: "A plan limit is used up this billing period. `details` has meter, used, limit and resets_at.";
8
+ readonly rate_limited: "Too many requests from this credential or IP. Retry after `details.retry_after_seconds`.";
9
+ readonly suspended: "lilbox suspended the app or account. `details.reason` says why (abuse, phishing, malware, spam, fraud, legal); contact support@lilbox.ai.";
10
+ readonly invalid_request: "The input failed validation. `details.issues` lists each problem with its path.";
11
+ readonly invalid_manifest: "app.yaml is invalid. `details.issues` lists each problem with its path.";
12
+ readonly not_found: "No such resource, or the token can't see it.";
13
+ readonly conflict: "The request conflicts with the current state. `details.reason`: name_taken, name_reserved, name_not_allowed (brand or lookalike names), or busy (a deployment is in progress).";
14
+ readonly not_available: "This feature isn't available yet. `details.waitlist_url` when there is one.";
15
+ readonly plan_unavailable: "That plan can't be bought yet. `details.waitlist_url` adds the account to the waitlist.";
16
+ readonly source_too_large: "The upload or inline files exceed the size limit. `details.largest_paths` lists the biggest files.";
17
+ readonly build_failed: "The image build failed. `log_excerpt` has the relevant lines; get_deployment_logs has all of them.";
18
+ readonly image_too_large: "The built image exceeds the runtime's size limit.";
19
+ readonly migration_failed: "The release's migrate command exited non-zero.";
20
+ readonly healthcheck_failed: "The app started but its health check didn't pass.";
21
+ readonly app_crashed_on_start: "The app exited before its health check could pass.";
22
+ readonly deploy_timeout: "The deploy didn't finish in time.";
23
+ readonly capability_requires_plan: "The app needs something the current plan's runtime can't do. `details.issues` has each finding and both fixes.";
24
+ readonly capability_unconfirmed: "Detection is unsure whether the app needs a capability. Declare it in `needs:` or acknowledge it with `ack`.";
25
+ readonly domain_unverified: "The custom domain's ownership TXT record isn't in place yet.";
26
+ readonly cert_pending: "The certificate for the custom domain isn't issued yet.";
27
+ readonly db_quota_exceeded: "The database is over its storage quota and is read-only.";
28
+ readonly internal: "Something failed on our side. Retry; if it persists, quote request_id to support.";
29
+ };
30
+ export type ErrorCode = keyof typeof ERROR_CODES;
31
+ export declare const ErrorCodeSchema: z.ZodEnum<{
32
+ internal: "internal";
33
+ unauthenticated: "unauthenticated";
34
+ forbidden_scope: "forbidden_scope";
35
+ approval_required: "approval_required";
36
+ payment_required: "payment_required";
37
+ quota_exceeded: "quota_exceeded";
38
+ rate_limited: "rate_limited";
39
+ suspended: "suspended";
40
+ invalid_request: "invalid_request";
41
+ invalid_manifest: "invalid_manifest";
42
+ not_found: "not_found";
43
+ conflict: "conflict";
44
+ not_available: "not_available";
45
+ plan_unavailable: "plan_unavailable";
46
+ source_too_large: "source_too_large";
47
+ build_failed: "build_failed";
48
+ image_too_large: "image_too_large";
49
+ migration_failed: "migration_failed";
50
+ healthcheck_failed: "healthcheck_failed";
51
+ app_crashed_on_start: "app_crashed_on_start";
52
+ deploy_timeout: "deploy_timeout";
53
+ capability_requires_plan: "capability_requires_plan";
54
+ capability_unconfirmed: "capability_unconfirmed";
55
+ domain_unverified: "domain_unverified";
56
+ cert_pending: "cert_pending";
57
+ db_quota_exceeded: "db_quota_exceeded";
58
+ }>;
59
+ export declare const ApiError: z.ZodObject<{
60
+ code: z.ZodEnum<{
61
+ internal: "internal";
62
+ unauthenticated: "unauthenticated";
63
+ forbidden_scope: "forbidden_scope";
64
+ approval_required: "approval_required";
65
+ payment_required: "payment_required";
66
+ quota_exceeded: "quota_exceeded";
67
+ rate_limited: "rate_limited";
68
+ suspended: "suspended";
69
+ invalid_request: "invalid_request";
70
+ invalid_manifest: "invalid_manifest";
71
+ not_found: "not_found";
72
+ conflict: "conflict";
73
+ not_available: "not_available";
74
+ plan_unavailable: "plan_unavailable";
75
+ source_too_large: "source_too_large";
76
+ build_failed: "build_failed";
77
+ image_too_large: "image_too_large";
78
+ migration_failed: "migration_failed";
79
+ healthcheck_failed: "healthcheck_failed";
80
+ app_crashed_on_start: "app_crashed_on_start";
81
+ deploy_timeout: "deploy_timeout";
82
+ capability_requires_plan: "capability_requires_plan";
83
+ capability_unconfirmed: "capability_unconfirmed";
84
+ domain_unverified: "domain_unverified";
85
+ cert_pending: "cert_pending";
86
+ db_quota_exceeded: "db_quota_exceeded";
87
+ }>;
88
+ message: z.ZodString;
89
+ retryable: z.ZodBoolean;
90
+ suggestion: z.ZodOptional<z.ZodString>;
91
+ docs_url: z.ZodOptional<z.ZodURL>;
92
+ request_id: z.ZodOptional<z.ZodString>;
93
+ deployment_id: z.ZodOptional<z.ZodString>;
94
+ log_excerpt: z.ZodOptional<z.ZodArray<z.ZodString>>;
95
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
96
+ }, z.core.$strip>;
97
+ /** Body of every non-2xx REST response. MCP tools return the same object with isError: true. */
98
+ export declare const ErrorResponse: z.ZodObject<{
99
+ error: z.ZodObject<{
100
+ code: z.ZodEnum<{
101
+ internal: "internal";
102
+ unauthenticated: "unauthenticated";
103
+ forbidden_scope: "forbidden_scope";
104
+ approval_required: "approval_required";
105
+ payment_required: "payment_required";
106
+ quota_exceeded: "quota_exceeded";
107
+ rate_limited: "rate_limited";
108
+ suspended: "suspended";
109
+ invalid_request: "invalid_request";
110
+ invalid_manifest: "invalid_manifest";
111
+ not_found: "not_found";
112
+ conflict: "conflict";
113
+ not_available: "not_available";
114
+ plan_unavailable: "plan_unavailable";
115
+ source_too_large: "source_too_large";
116
+ build_failed: "build_failed";
117
+ image_too_large: "image_too_large";
118
+ migration_failed: "migration_failed";
119
+ healthcheck_failed: "healthcheck_failed";
120
+ app_crashed_on_start: "app_crashed_on_start";
121
+ deploy_timeout: "deploy_timeout";
122
+ capability_requires_plan: "capability_requires_plan";
123
+ capability_unconfirmed: "capability_unconfirmed";
124
+ domain_unverified: "domain_unverified";
125
+ cert_pending: "cert_pending";
126
+ db_quota_exceeded: "db_quota_exceeded";
127
+ }>;
128
+ message: z.ZodString;
129
+ retryable: z.ZodBoolean;
130
+ suggestion: z.ZodOptional<z.ZodString>;
131
+ docs_url: z.ZodOptional<z.ZodURL>;
132
+ request_id: z.ZodOptional<z.ZodString>;
133
+ deployment_id: z.ZodOptional<z.ZodString>;
134
+ log_excerpt: z.ZodOptional<z.ZodArray<z.ZodString>>;
135
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
136
+ }, z.core.$strip>;
137
+ }, z.core.$strip>;
138
+ export type ApiError = z.infer<typeof ApiError>;
139
+ export type ErrorResponse = z.infer<typeof ErrorResponse>;
140
+ /** Docs URL for an error code. */
141
+ export declare const errorDocsUrl: (code: ErrorCode) => string;
package/dist/errors.js ADDED
@@ -0,0 +1,58 @@
1
+ // The error shape every REST response and MCP tool result uses (01 §11.1).
2
+ //
3
+ // Agents act on `code` (stable, documented at docs_url) and show `message` and `suggestion` to the human.
4
+ // New codes may be added; existing codes never change meaning.
5
+ import { z } from "zod";
6
+ import { DeploymentId } from "./common.js";
7
+ export const ERROR_CODES = {
8
+ // Auth and policy
9
+ unauthenticated: "No valid credentials. Sign in again or use a valid API key.",
10
+ forbidden_scope: "The token lacks a scope this call needs. `details.required_scopes` lists them.",
11
+ approval_required: "A human must approve this. `details.approval_url` is the page to send them to. (Phase 2: policy approvals.)",
12
+ payment_required: "The account must subscribe (trial ended, or the feature needs a paid plan). `details.checkout_url` when available.",
13
+ quota_exceeded: "A plan limit is used up this billing period. `details` has meter, used, limit and resets_at.",
14
+ rate_limited: "Too many requests from this credential or IP. Retry after `details.retry_after_seconds`.",
15
+ suspended: "lilbox suspended the app or account. `details.reason` says why (abuse, phishing, malware, spam, fraud, legal); contact support@lilbox.ai.",
16
+ // Requests
17
+ invalid_request: "The input failed validation. `details.issues` lists each problem with its path.",
18
+ invalid_manifest: "app.yaml is invalid. `details.issues` lists each problem with its path.",
19
+ not_found: "No such resource, or the token can't see it.",
20
+ conflict: "The request conflicts with the current state. `details.reason`: name_taken, name_reserved, name_not_allowed (brand or lookalike names), or busy (a deployment is in progress).",
21
+ not_available: "This feature isn't available yet. `details.waitlist_url` when there is one.",
22
+ plan_unavailable: "That plan can't be bought yet. `details.waitlist_url` adds the account to the waitlist.",
23
+ source_too_large: "The upload or inline files exceed the size limit. `details.largest_paths` lists the biggest files.",
24
+ // Builds and deploys
25
+ build_failed: "The image build failed. `log_excerpt` has the relevant lines; get_deployment_logs has all of them.",
26
+ image_too_large: "The built image exceeds the runtime's size limit.",
27
+ migration_failed: "The release's migrate command exited non-zero.",
28
+ healthcheck_failed: "The app started but its health check didn't pass.",
29
+ app_crashed_on_start: "The app exited before its health check could pass.",
30
+ deploy_timeout: "The deploy didn't finish in time.",
31
+ capability_requires_plan: "The app needs something the current plan's runtime can't do. `details.issues` has each finding and both fixes.",
32
+ capability_unconfirmed: "Detection is unsure whether the app needs a capability. Declare it in `needs:` or acknowledge it with `ack`.",
33
+ // Domains (phase 2)
34
+ domain_unverified: "The custom domain's ownership TXT record isn't in place yet.",
35
+ cert_pending: "The certificate for the custom domain isn't issued yet.",
36
+ // Databases (phase 2)
37
+ db_quota_exceeded: "The database is over its storage quota and is read-only.",
38
+ // Fallback
39
+ internal: "Something failed on our side. Retry; if it persists, quote request_id to support.",
40
+ };
41
+ export const ErrorCodeSchema = z.enum(Object.keys(ERROR_CODES));
42
+ export const ApiError = z
43
+ .object({
44
+ code: ErrorCodeSchema,
45
+ message: z.string().meta({ description: "What went wrong, for a human." }),
46
+ retryable: z.boolean().meta({ description: "True if the same call may succeed later unchanged." }),
47
+ suggestion: z.string().optional().meta({ description: "What to do next, as concrete as possible." }),
48
+ docs_url: z.url().optional(),
49
+ request_id: z.string().optional(),
50
+ deployment_id: DeploymentId.optional(),
51
+ log_excerpt: z.array(z.string()).max(50).optional().meta({ description: "The log lines that explain the failure." }),
52
+ details: z.record(z.string(), z.unknown()).optional().meta({ description: "Code-specific fields, documented per code." }),
53
+ })
54
+ .meta({ id: "ApiError" });
55
+ /** Body of every non-2xx REST response. MCP tools return the same object with isError: true. */
56
+ export const ErrorResponse = z.object({ error: ApiError }).meta({ id: "ErrorResponse" });
57
+ /** Docs URL for an error code. */
58
+ export const errorDocsUrl = (code) => `https://docs.lilbox.ai/errors/${code}`;
@@ -0,0 +1,12 @@
1
+ export * from "./common.js";
2
+ export * from "./errors.js";
3
+ export * from "./define.js";
4
+ export * from "./account.js";
5
+ export * from "./app.js";
6
+ export * from "./manifest.js";
7
+ export * from "./deployment.js";
8
+ export * from "./runtime.js";
9
+ export * from "./security.js";
10
+ export * from "./billing.js";
11
+ export { operations, operationList, type OperationName } from "./registry.js";
12
+ export { buildOpenApi, mcpTools } from "./openapi.js";
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ // @lilbox/contracts: the lilbox API's shapes, defined once, one file per group of the model (README "Model").
2
+ //
3
+ // Consumers:
4
+ // apps/api validates requests and responses, registers MCP tools from `operations`
5
+ // lilbox-frontend types, form validation
6
+ // lilbox-cli types, input validation, SOURCE_LIMITS
7
+ // lilbox-content openapi.json for the API reference
8
+ // Internal contracts (jobs, route entries) are in ./internal (imported as @lilbox/contracts/internal), left out of the npm package.
9
+ export * from "./common.js";
10
+ export * from "./errors.js";
11
+ export * from "./define.js";
12
+ export * from "./account.js";
13
+ export * from "./app.js";
14
+ export * from "./manifest.js";
15
+ export * from "./deployment.js";
16
+ export * from "./runtime.js";
17
+ export * from "./security.js";
18
+ export * from "./billing.js";
19
+ export { operations, operationList } from "./registry.js";
20
+ export { buildOpenApi, mcpTools } from "./openapi.js";
@@ -0,0 +1,101 @@
1
+ import { z } from "zod";
2
+ /** Durations as in app.yaml: "30s", "15m", "2h", "7d". */
3
+ export declare const Duration: z.ZodString;
4
+ export declare const Size: z.ZodEnum<{
5
+ small: "small";
6
+ nano: "nano";
7
+ medium: "medium";
8
+ large: "large";
9
+ }>;
10
+ export declare const CAPABILITY_CODES: readonly ["work_after_response", "in_process_scheduler", "queue_consumer", "websockets", "writes_outside_tmp", "needs_root", "long_requests", "large_bodies", "always_on", "slow_boot"];
11
+ export declare const CapabilityCode: z.ZodEnum<{
12
+ work_after_response: "work_after_response";
13
+ in_process_scheduler: "in_process_scheduler";
14
+ queue_consumer: "queue_consumer";
15
+ websockets: "websockets";
16
+ writes_outside_tmp: "writes_outside_tmp";
17
+ needs_root: "needs_root";
18
+ long_requests: "long_requests";
19
+ large_bodies: "large_bodies";
20
+ always_on: "always_on";
21
+ slow_boot: "slow_boot";
22
+ }>;
23
+ export declare const CronEntry: z.ZodObject<{
24
+ schedule: z.ZodString;
25
+ path: z.ZodString;
26
+ timeout: z.ZodOptional<z.ZodDefault<z.ZodString>>;
27
+ }, z.core.$strip>;
28
+ export declare const Manifest: z.ZodObject<{
29
+ version: z.ZodLiteral<1>;
30
+ name: z.ZodOptional<z.ZodString>;
31
+ build: z.ZodOptional<z.ZodObject<{
32
+ dockerfile: z.ZodOptional<z.ZodDefault<z.ZodString>>;
33
+ context: z.ZodOptional<z.ZodDefault<z.ZodString>>;
34
+ builder: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
35
+ dockerfile: "dockerfile";
36
+ auto: "auto";
37
+ }>>>;
38
+ args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
39
+ }, z.core.$strip>>;
40
+ run: z.ZodOptional<z.ZodObject<{
41
+ port: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
42
+ health: z.ZodOptional<z.ZodObject<{
43
+ path: z.ZodOptional<z.ZodDefault<z.ZodString>>;
44
+ timeout: z.ZodOptional<z.ZodDefault<z.ZodString>>;
45
+ }, z.core.$strip>>;
46
+ size: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
47
+ small: "small";
48
+ nano: "nano";
49
+ medium: "medium";
50
+ large: "large";
51
+ }>>>;
52
+ request_timeout: z.ZodOptional<z.ZodString>;
53
+ max_body: z.ZodOptional<z.ZodString>;
54
+ }, z.core.$strip>>;
55
+ scale: z.ZodOptional<z.ZodObject<{
56
+ min: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
57
+ max: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
58
+ idle_timeout: z.ZodOptional<z.ZodString>;
59
+ }, z.core.$strip>>;
60
+ region: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
61
+ "us-east": "us-east";
62
+ }>>>;
63
+ runtime: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
64
+ serverless: "serverless";
65
+ container: "container";
66
+ auto: "auto";
67
+ }>>>;
68
+ needs: z.ZodOptional<z.ZodArray<z.ZodEnum<{
69
+ work_after_response: "work_after_response";
70
+ in_process_scheduler: "in_process_scheduler";
71
+ queue_consumer: "queue_consumer";
72
+ websockets: "websockets";
73
+ writes_outside_tmp: "writes_outside_tmp";
74
+ needs_root: "needs_root";
75
+ long_requests: "long_requests";
76
+ large_bodies: "large_bodies";
77
+ always_on: "always_on";
78
+ slow_boot: "slow_boot";
79
+ }>>>;
80
+ env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
81
+ secrets: z.ZodOptional<z.ZodArray<z.ZodString>>;
82
+ cron: z.ZodOptional<z.ZodArray<z.ZodObject<{
83
+ schedule: z.ZodString;
84
+ path: z.ZodString;
85
+ timeout: z.ZodOptional<z.ZodDefault<z.ZodString>>;
86
+ }, z.core.$strip>>>;
87
+ release: z.ZodOptional<z.ZodObject<{
88
+ migrate: z.ZodOptional<z.ZodArray<z.ZodString>>;
89
+ seed: z.ZodOptional<z.ZodArray<z.ZodString>>;
90
+ }, z.core.$strip>>;
91
+ database: z.ZodOptional<z.ZodObject<{
92
+ postgres: z.ZodObject<{
93
+ tier: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
94
+ shared: "shared";
95
+ dedicated: "dedicated";
96
+ }>>>;
97
+ version: z.ZodOptional<z.ZodString>;
98
+ }, z.core.$strip>;
99
+ }, z.core.$strip>>;
100
+ }, z.core.$strip>;
101
+ export type Manifest = z.infer<typeof Manifest>;