|
| 1 | +import { z } from 'zod'; |
| 2 | +import { ManifestSchema } from './manifest.zod'; |
| 3 | + |
| 4 | +/** |
| 5 | + * # Cloud Composer Protocol |
| 6 | + * |
| 7 | + * Defines the interface for the ObjectStack Composer Service. |
| 8 | + * The Composer is responsible for "compiling" a Tenant's configuration (BOM) |
| 9 | + * into a single executable System Manifest. |
| 10 | + */ |
| 11 | + |
| 12 | +/** |
| 13 | + * Dependency Requirement |
| 14 | + * Specifies a plugin and its version constraints. |
| 15 | + */ |
| 16 | +export const DependencyRequirementSchema = z.object({ |
| 17 | + id: z.string().describe('Plugin ID (e.g. "com.example.crm")'), |
| 18 | + version: z.string().default('latest').describe('SemVer range or "latest"'), |
| 19 | + |
| 20 | + /** |
| 21 | + * Configuration Overrides |
| 22 | + * Tenant-specific settings that override plugin defaults. |
| 23 | + * Example: { "currency": "USD", "apiKey": "..." } |
| 24 | + */ |
| 25 | + configuration: z.record(z.any()).optional().describe('Configuration overrides'), |
| 26 | + |
| 27 | + /** |
| 28 | + * Feature Flags |
| 29 | + * Enable/Disable specific features within the plugin. |
| 30 | + */ |
| 31 | + features: z.record(z.boolean()).optional().describe('Feature toggles'), |
| 32 | +}); |
| 33 | + |
| 34 | +/** |
| 35 | + * Bill of Materials (BOM) |
| 36 | + * The "Shopping List" for a specific tenant. |
| 37 | + * Represents the high-level intent of what the tenant wants to install. |
| 38 | + */ |
| 39 | +export const BillOfMaterialsSchema = z.object({ |
| 40 | + tenantId: z.string().describe('Target Tenant ID'), |
| 41 | + |
| 42 | + /** |
| 43 | + * List of installed plugins/apps. |
| 44 | + * implementation order matters (later plugins override earlier ones by default). |
| 45 | + */ |
| 46 | + dependencies: z.array(DependencyRequirementSchema).describe('Installed packages'), |
| 47 | + |
| 48 | + /** |
| 49 | + * Environment Variables injection. |
| 50 | + * Maps abstract keys to secure vault references or concrete values. |
| 51 | + */ |
| 52 | + environment: z.record(z.string()).optional(), |
| 53 | + |
| 54 | + /** |
| 55 | + * Global Resolution Strategy |
| 56 | + * How to handle conflicts when multiple plugins define the same resource. |
| 57 | + */ |
| 58 | + resolutionStrategy: z.enum(['strict', 'override', 'merge']).default('override') |
| 59 | + .describe('Conflict resolution strategy (strict=fail, override=last-wins, merge=deep-merge)'), |
| 60 | +}); |
| 61 | + |
| 62 | +/** |
| 63 | + * Conflict Report |
| 64 | + * Detailed information about collision during composition. |
| 65 | + */ |
| 66 | +export const ConflictReportSchema = z.object({ |
| 67 | + resourceType: z.enum(['object', 'field', 'api', 'ui']).describe('Type of colliding resource'), |
| 68 | + resourceId: z.string().describe('ID of the resource'), |
| 69 | + sources: z.array(z.string()).describe('List of plugin IDs defining this resource'), |
| 70 | + resolution: z.string().describe('How it was resolved (e.g. "com.example.erp won")'), |
| 71 | + severity: z.enum(['info', 'warning', 'error']).describe('Severity of the conflict'), |
| 72 | +}); |
| 73 | + |
| 74 | +/** |
| 75 | + * Composer Request |
| 76 | + * The RPC payload sent to the Composer Service. |
| 77 | + */ |
| 78 | +export const ComposerRequestSchema = z.object({ |
| 79 | + bom: BillOfMaterialsSchema, |
| 80 | + |
| 81 | + /** |
| 82 | + * Target Runtime Version |
| 83 | + * Ensure generated manifest is compatible with the specific runtime version. |
| 84 | + */ |
| 85 | + runtimeVersion: z.string().optional(), |
| 86 | + |
| 87 | + /** |
| 88 | + * Dry Run |
| 89 | + * If true, generates report but does not persist the manifest. |
| 90 | + */ |
| 91 | + dryRun: z.boolean().default(false), |
| 92 | +}); |
| 93 | + |
| 94 | +/** |
| 95 | + * Composer Response |
| 96 | + * The result of the compilation process. |
| 97 | + */ |
| 98 | +export const ComposerResponseSchema = z.object({ |
| 99 | + success: z.boolean(), |
| 100 | + |
| 101 | + /** |
| 102 | + * The Holy Grail: The Executable System Manifest. |
| 103 | + * This is what the Runtime loads to boot. |
| 104 | + */ |
| 105 | + manifest: ManifestSchema.optional().describe('The compiled System Manifest'), |
| 106 | + |
| 107 | + /** |
| 108 | + * Compilation Metadata |
| 109 | + */ |
| 110 | + buildId: z.string(), |
| 111 | + timestamp: z.string().datetime(), |
| 112 | + duration: z.number().describe('Compilation time in ms'), |
| 113 | + |
| 114 | + /** |
| 115 | + * Analysis |
| 116 | + */ |
| 117 | + conflicts: z.array(ConflictReportSchema).optional(), |
| 118 | + errors: z.array(z.string()).optional(), |
| 119 | +}); |
| 120 | + |
| 121 | +export type BillOfMaterials = z.infer<typeof BillOfMaterialsSchema>; |
| 122 | +export type ComposerRequest = z.infer<typeof ComposerRequestSchema>; |
| 123 | +export type ComposerResponse = z.infer<typeof ComposerResponseSchema>; |
0 commit comments