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.
| 5 |
| } from "./manifest"; |
| 6 |
| 7 | const minimalManifest = { |
| 8 | key: "crm", |
| 9 | name: "CRM", |
| 10 | }; |
| 11 |
| 12 | describe("colineAppManifestV2Schema", () => { |
| 13 | it("accepts a minimal manifest and applies defaults", () => { |
| 14 | const manifest = colineAppManifestV2Schema.parse(minimalManifest); |
| 15 | expect(manifest.permissions).toEqual([]); |
| 16 | expect(manifest.hosting.default).toBe("coline"); |
| 17 | expect(manifest.network.allowedHosts).toEqual([]); |
| 18 | expect(manifest.files).toEqual([]); |
| 19 | expect(manifest.tools).toEqual([]); |
| 20 | expect(manifest.triggers).toEqual({ webhooks: [], schedules: [] }); |
| 21 | }); |
| 22 |
| 23 | it("accepts a full manifest", () => { |
| 24 | const manifest = colineAppManifestV2Schema.parse({ |
| 25 | key: "crm", |
| 26 | name: "CRM", |
| 27 | description: "Customer relationships inside Coline.", |
| 28 | icon: "users", |
| 29 | permissions: [ |
| 30 | "files.read", |
| 31 | "files.write", |
| 32 | "ai.tools", |
| 33 | "commands.register", |
| 34 | "notifications.write", |
| 35 | ], |
| 36 | surfaces: { |
| 37 | home: { tier: "react", entry: "./views/home", mobile: { tier: "tree" } }, |
| 38 | }, |
| 39 | files: [ |
| 40 | { |
| 41 | typeKey: "crm.contact", |
| 42 | name: "Contact", |
| 43 | storage: "json_document", |
| 44 | surfaces: { |
| 45 | editor: { tier: "react", entry: "./files/contact-editor" }, |
| 46 | preview: { tier: "tree" }, |
| 47 | inline: { tier: "tree" }, |
| 48 | }, |
| 49 | }, |
| 50 | ], |
| 51 | tools: [ |
| 52 | { |
| 53 | name: "crm.create_contact", |
| 54 | description: "Create a contact in the CRM.", |
| 55 | inputSchema: { type: "object", properties: { name: { type: "string" } } }, |
| 56 | effect: "write", |
| 57 | }, |
| 58 | ], |
| 59 | commands: [ |
| 60 | { |
| 61 | id: "new-contact", |
| 62 | name: "Create contact", |
| 63 | target: { kind: "tool", tool: "crm.create_contact" }, |
| 64 | }, |
| 65 | ], |
| 66 | notifications: { |
| 67 | channels: [{ key: "deal-updates", name: "Deal updates" }], |
| 68 | }, |
| 69 | hosting: { |
| 70 | default: "coline", |
| 71 | overrides: { "crm.create_contact": "external" }, |
| 72 | external: { baseUrl: "https://crm.example.com" }, |
| 73 | }, |
| 74 | kairo: { instructions: "This workspace tracks customers in the CRM." }, |
| 75 | }); |
| 76 |
| 77 | expect(manifest.surfaces.home?.tier).toBe("react"); |
| 78 | expect(manifest.notifications.channels[0]?.defaultDeliveries).toEqual(["in_app"]); |
| 79 | }); |
| 80 |
| 81 | it("rejects tools that are not namespaced under the app key", () => { |
| 82 | const result = colineAppManifestV2Schema.safeParse({ |
| 83 | ...minimalManifest, |
| 84 | permissions: ["ai.tools"], |
| 85 | tools: [ |
| 86 | { |
| 87 | name: "other.create_contact", |
| 88 | description: "Wrong namespace.", |
| 89 | inputSchema: {}, |
| 90 | effect: "read", |
| 91 | }, |
| 92 | ], |
| 93 | }); |
| 94 | expect(result.success).toBe(false); |
| 95 | }); |
| 96 |
| 97 | it("rejects tools without the ai.tools permission", () => { |
| 98 | const result = colineAppManifestV2Schema.safeParse({ |
| 99 | ...minimalManifest, |
| 100 | tools: [ |
| 101 | { |
| 102 | name: "crm.list_contacts", |
| 103 | description: "List contacts.", |
| 104 | inputSchema: {}, |
| 105 | effect: "read", |
| 106 | }, |
| 107 | ], |
| 108 | }); |
| 109 | expect(result.success).toBe(false); |
| 110 | expect(JSON.stringify(result.error?.issues)).toContain("ai.tools"); |
| 111 | }); |
| 112 |
| 113 | it("rejects commands that target undeclared tools", () => { |
| 114 | const result = colineAppManifestV2Schema.safeParse({ |
| 115 | ...minimalManifest, |
| 116 | permissions: ["commands.register"], |
| 117 | commands: [ |
| 118 | { |
| 119 | id: "new-contact", |
| 120 | name: "Create contact", |
| 121 | target: { kind: "tool", tool: "crm.create_contact" }, |
| 122 | }, |
| 123 | ], |
| 124 | }); |
| 125 | expect(result.success).toBe(false); |
| 126 | }); |
| 127 |
| 128 | it("requires external hosting when any capability overrides to external", () => { |
| 129 | const result = colineAppManifestV2Schema.safeParse({ |
| 130 | ...minimalManifest, |
| 131 | permissions: ["ai.tools"], |
| 132 | tools: [ |
| 133 | { |
| 134 | name: "crm.sync_salesforce", |
| 135 | description: "Sync with Salesforce.", |
| 136 | inputSchema: {}, |
| 137 | effect: "external", |
| 138 | }, |
| 139 | ], |
| 140 | hosting: { |
| 141 | default: "coline", |
| 142 | overrides: { "crm.sync_salesforce": "external" }, |
| 143 | }, |
| 144 | }); |
| 145 | expect(result.success).toBe(false); |
| 146 | expect(JSON.stringify(result.error?.issues)).toContain("hosting.external"); |
| 147 | }); |
| 148 |
| 149 | it("rejects hosting overrides for undeclared capabilities", () => { |
| 150 | const result = colineAppManifestV2Schema.safeParse({ |
| 151 | ...minimalManifest, |
| 152 | hosting: { |
| 153 | default: "coline", |
| 154 | overrides: { "crm.nonexistent_tool": "external" }, |
| 155 | external: { baseUrl: "https://crm.example.com" }, |
| 156 | }, |
| 157 | }); |
| 158 | expect(result.success).toBe(false); |
| 159 | }); |
| 160 |
| 161 | it("requires external hosting for web-tier surfaces", () => { |
| 162 | const result = colineAppManifestV2Schema.safeParse({ |
| 163 | ...minimalManifest, |
| 164 | surfaces: { home: { tier: "web", path: "/embed/home" } }, |
| 165 | }); |
| 166 | expect(result.success).toBe(false); |
| 167 | }); |
| 168 |
| 169 | it("requires external hosting for webhook triggers", () => { |
| 170 | const result = colineAppManifestV2Schema.safeParse({ |
| 171 | ...minimalManifest, |
| 172 | permissions: ["webhooks.subscribe"], |
| 173 | triggers: { webhooks: [{ event: "file.created" }] }, |
| 174 | }); |
| 175 | expect(result.success).toBe(false); |
| 176 | }); |
| 177 |
| 178 | it("rejects unknown top-level keys (strict manifest)", () => { |
| 179 | const result = colineAppManifestV2Schema.safeParse({ |
| 180 | ...minimalManifest, |
| 181 | views: {}, |
| 182 | }); |
| 183 | expect(result.success).toBe(false); |
| 184 | }); |
| 185 |
| 186 | it("rejects file types outside the app namespace", () => { |
| 187 | const result = colineAppManifestV2Schema.safeParse({ |
| 188 | ...minimalManifest, |
| 189 | files: [{ typeKey: "other.contact", name: "Contact" }], |
| 190 | }); |
| 191 | expect(result.success).toBe(false); |
| 192 | }); |
| 193 | }); |
| 194 |
| 195 | describe("colineAppRegistrationPayloadV2Schema", () => { |
| 196 | it("requires protocolVersion 2", () => { |
| 197 | expect( |
| 198 | colineAppRegistrationPayloadV2Schema.safeParse({ |
| 199 | protocolVersion: 1, |
| 200 | manifest: minimalManifest, |
| 201 | }).success, |
| 202 | ).toBe(false); |
| 203 | expect( |
| 204 | colineAppRegistrationPayloadV2Schema.safeParse({ |
| 205 | protocolVersion: 2, |
| 206 | manifest: minimalManifest, |
| 207 | }).success, |
| 208 | ).toBe(true); |
| 209 | }); |
| 210 | }); |
| 211 |