The Coline App SDK: apps, tools, file types and surfaces that run inside Coline workspaces, and public websites with Coline Sites. TypeScript, with an in-memory test workspace. MIT.
| 4 | import { appHostingV2Schema, appNetworkPolicySchema } from "./hosting"; |
| 5 | import { appNotificationsV2Schema } from "./notifications"; |
| 6 | import { appPermissionV2ListSchema } from "./permissions"; |
| 7 | import { appSurfacesSchema } from "./surfaces"; |
| 8 | import { appToolMetadataSchema } from "./tool"; |
| 9 | import { appTriggersV2Schema } from "./triggers"; |
| 10 |
| 11 | /** |
| 12 | * The Coline App manifest, v2 (plan §6). |
| 13 | * |
| 14 | * The manifest is the serializable artifact of an app definition: it tells |
| 15 | * Coline everything the app contributes without executing app code. It is |
| 16 | * produced by the extraction step (`define/extraction.ts`), re-verified at |
| 17 | * publish time, and stored on `app_versions`. |
| 18 | */ |
| 19 |
| 20 | export const appKeySchema = z |
| 21 | .string() |
| 22 | .trim() |
| 23 | .regex(/^[a-z][a-z0-9-]{1,63}$/, "App keys are lowercase kebab-case, 2-64 chars."); |
| 24 |
| 25 | export const colineAppManifestV2Schema = z |
| 26 | .strictObject({ |
| 27 | key: appKeySchema, |
| 28 | name: z.string().trim().min(1).max(120), |
| 29 | description: z.string().trim().max(1000).optional(), |
| 30 | iconUrl: z.url().max(2000).optional(), |
| 31 | icon: z.string().trim().max(120).optional(), |
| 32 | permissions: appPermissionV2ListSchema, |
| 33 | surfaces: appSurfacesSchema, |
| 34 | files: z |
| 35 | .array(appFileTypeV2Schema) |
| 36 | .max(50) |
| 37 | .default([]) |
| 38 | .refine( |
| 39 | (files) => new Set(files.map((file) => file.typeKey)).size === files.length, |
| 40 | "File type keys must be unique.", |
| 41 | ), |
| 42 | tools: z |
| 43 | .array(appToolMetadataSchema) |
| 44 | .max(100) |
| 45 | .default([]) |
| 46 | .refine( |
| 47 | (tools) => new Set(tools.map((tool) => tool.name)).size === tools.length, |
| 48 | "Tool names must be unique.", |
| 49 | ), |
| 50 | commands: z |
| 51 | .array(appCommandSchema) |
| 52 | .max(50) |
| 53 | .default([]) |
| 54 | .refine( |
| 55 | (commands) => new Set(commands.map((command) => command.id)).size === commands.length, |
| 56 | "Command ids must be unique.", |
| 57 | ), |
| 58 | notifications: appNotificationsV2Schema, |
| 59 | hosting: appHostingV2Schema, |
| 60 | network: appNetworkPolicySchema, |
| 61 | kairo: z |
| 62 | .strictObject({ |
| 63 | enabled: z.boolean().default(true), |
| 64 | description: z.string().trim().min(1).max(500).optional(), |
| 65 | instructions: z.string().trim().min(1).max(4000).optional(), |
| 66 | }) |
| 67 | .optional(), |
| 68 | triggers: appTriggersV2Schema, |
| 69 | }) |
| 70 | .superRefine((manifest, ctx) => { |
| 71 | const prefix = `${manifest.key}.`; |
| 72 |
| 73 | for (const [index, tool] of manifest.tools.entries()) { |
| 74 | if (!tool.name.startsWith(prefix)) { |
| 75 | ctx.addIssue({ |
| 76 | code: "custom", |
| 77 | path: ["tools", index, "name"], |
| 78 | message: `Tool names must be namespaced under the app key ("${prefix}…").`, |
| 79 | }); |
| 80 | } |
| 81 | } |
| 82 |
| 83 | for (const [index, file] of manifest.files.entries()) { |
| 84 | if (!file.typeKey.startsWith(prefix)) { |
| 85 | ctx.addIssue({ |
| 86 | code: "custom", |
| 87 | path: ["files", index, "typeKey"], |
| 88 | message: `File type keys must be namespaced under the app key ("${prefix}…").`, |
| 89 | }); |
| 90 | } |
| 91 | } |
| 92 |
| 93 | const toolNames = new Set(manifest.tools.map((tool) => tool.name)); |
| 94 | for (const [index, command] of manifest.commands.entries()) { |
| 95 | if (command.target.kind === "tool" && !toolNames.has(command.target.tool)) { |
| 96 | ctx.addIssue({ |
| 97 | code: "custom", |
| 98 | path: ["commands", index, "target", "tool"], |
| 99 | message: `Command targets undeclared tool "${command.target.tool}".`, |
| 100 | }); |
| 101 | } |
| 102 | } |
| 103 |
| 104 | if (manifest.tools.length > 0 && !manifest.permissions.includes("ai.tools")) { |
| 105 | ctx.addIssue({ |
| 106 | code: "custom", |
| 107 | path: ["permissions"], |
| 108 | message: 'Declaring tools requires the "ai.tools" permission.', |
| 109 | }); |
| 110 | } |
| 111 | if (manifest.commands.length > 0 && !manifest.permissions.includes("commands.register")) { |
| 112 | ctx.addIssue({ |
| 113 | code: "custom", |
| 114 | path: ["permissions"], |
| 115 | message: 'Declaring commands requires the "commands.register" permission.', |
| 116 | }); |
| 117 | } |
| 118 | if ( |
| 119 | manifest.triggers.webhooks.length > 0 && |
| 120 | !manifest.permissions.includes("webhooks.subscribe") |
| 121 | ) { |
| 122 | ctx.addIssue({ |
| 123 | code: "custom", |
| 124 | path: ["permissions"], |
| 125 | message: 'Declaring webhook triggers requires the "webhooks.subscribe" permission.', |
| 126 | }); |
| 127 | } |
| 128 | if (manifest.notifications.channels.length > 0 && !manifest.permissions.includes("notifications.write")) { |
| 129 | ctx.addIssue({ |
| 130 | code: "custom", |
| 131 | path: ["permissions"], |
| 132 | message: 'Declaring notification channels requires the "notifications.write" permission.', |
| 133 | }); |
| 134 | } |
| 135 |
| 136 | const fileTypeKeys = new Set(manifest.files.map((file) => file.typeKey)); |
| 137 | const validOverrideKeys = new Set<string>(["home", ...toolNames, ...fileTypeKeys]); |
| 138 | for (const key of Object.keys(manifest.hosting.overrides)) { |
| 139 | if (!validOverrideKeys.has(key)) { |
| 140 | ctx.addIssue({ |
| 141 | code: "custom", |
| 142 | path: ["hosting", "overrides", key], |
| 143 | message: |
| 144 | "Hosting override keys must name a declared tool, a declared file type, or \"home\".", |
| 145 | }); |
| 146 | } |
| 147 | } |
| 148 |
| 149 | const webSurfaceTiers: string[] = []; |
| 150 | if (manifest.surfaces.home?.tier === "web") webSurfaceTiers.push("surfaces.home"); |
| 151 | for (const file of manifest.files) { |
| 152 | if (file.surfaces.editor?.tier === "web") { |
| 153 | webSurfaceTiers.push(`files.${file.typeKey}.editor`); |
| 154 | } |
| 155 | } |
| 156 | if (webSurfaceTiers.length > 0 && !manifest.hosting.external) { |
| 157 | ctx.addIssue({ |
| 158 | code: "custom", |
| 159 | path: ["hosting", "external"], |
| 160 | message: `Web-tier surfaces (${webSurfaceTiers.join(", ")}) require external hosting.`, |
| 161 | }); |
| 162 | } |
| 163 |
| 164 | if (manifest.triggers.webhooks.length > 0 && !manifest.hosting.external) { |
| 165 | ctx.addIssue({ |
| 166 | code: "custom", |
| 167 | path: ["hosting", "external"], |
| 168 | message: "Webhook triggers deliver to the app backend and require external hosting.", |
| 169 | }); |
| 170 | } |
| 171 | }); |
| 172 |
| 173 | export type ColineAppManifestV2 = z.infer<typeof colineAppManifestV2Schema>; |
| 174 | export type ColineAppManifestV2Input = z.input<typeof colineAppManifestV2Schema>; |
| 175 |
| 176 | /** Registration payload: what `coline apps publish` submits (plan §5.3, §6.2). */ |
| 177 | export const colineAppRegistrationPayloadV2Schema = z.strictObject({ |
| 178 | protocolVersion: z.literal(2), |
| 179 | manifest: colineAppManifestV2Schema, |
| 180 | }); |
| 181 | export type ColineAppRegistrationPayloadV2 = z.infer< |
| 182 | typeof colineAppRegistrationPayloadV2Schema |
| 183 | >; |
| 184 |