/** * Copyright 2023 Kapeta Inc. * SPDX-License-Identifier: BUSL-1.1 */ import { StormDefinitions } from './event-parser'; export type StormResourceType = | 'API' | 'DATABASE' | 'CLIENT' | 'JWTPROVIDER' | 'JWTCONSUMER' | 'WEBFRAGMENT' | 'WEBPAGE' | 'SMTPCLIENT' | 'EXTERNAL_API' | 'SUBSCRIBER' | 'PUBLISHER' | 'QUEUE' | 'EXCHANGE'; export type StormBlockType = 'BACKEND' | 'FRONTEND' | 'GATEWAY' | 'MQ' | 'CLI' | 'DESKTOP'; export interface StormBlockInfo { type: StormBlockType; name: string; description: string; resources: { type: StormResourceType; name: string; description: string; }[]; blockRef?: string; instanceId?: string; archetype?: string; } export interface StormBlockInfoFilled extends StormBlockInfo { apis: string[]; types: string[]; models: string[]; } export interface StormEventCreateBlock { type: 'CREATE_BLOCK'; reason: string; created: number; payload: StormBlockInfo; } export interface StormConnection { fromComponent: string; fromBlockId?: string; fromResource: string; fromResourceType: StormResourceType; toComponent: string; toBlockId?: string; toResource: string; toResourceType: StormResourceType; } export interface StormEventCreateConnection { type: 'CREATE_CONNECTION'; reason: string; created: number; payload: StormConnection; } export interface StormEventCreatePlanProperties { type: 'CREATE_PLAN_PROPERTIES'; reason: string; created: number; payload: { name: string; description: string; }; } export interface StormEventInvalidResponse { type: 'INVALID_RESPONSE'; reason: string; created: number; payload: { error: string; }; } export interface StormEventPlanRetry { type: 'PLAN_RETRY' | 'PLAN_RETRY_FAILED'; reason: string; created: number; payload: { error: string; }; } export interface StormEventCreateDSL { type: 'CREATE_TYPE'; reason: string; created: number; payload: { blockName: string; content: string; blockRef?: string; instanceId?: string; }; } export interface StormEventCreateDSLResource extends Omit { type: 'CREATE_API' | 'CREATE_MODEL'; reason: string; created: number; payload: { blockName: string; content: string; blockRef?: string; instanceId?: string; resourceName?: string; }; } export interface StormEventCreateDSLRetry { type: 'API_RETRY' | 'MODELS_RETRY'; reason: string; created: number; payload: ApiRetryPayload | ModelsRetryPayload; } interface ApiRetryPayload { error: string[]; } interface ModelsRetryPayload extends ApiRetryPayload { blockName: string; } export interface StormEventError { type: 'INVALID_RESPONSE' | 'ERROR_INTERNAL'; reason: string; created: number; payload: { error: string; stack?: string; }; } export interface StormEventErrorClassifier { type: 'ERROR_CLASSIFIER'; reason: string; created: number; payload: StormEventErrorClassifierInfo; } export interface StormEventCodeFix { type: 'CODE_FIX'; reason: string; created: number; payload: { filename: string; content: string; }; } export interface StormEventErrorClassifierInfo { error: string; filename: string; lineNumber: number; column: number; } export interface StormEventErrorDetailsFile { filename: string; content: string; } export interface StormEventErrorDetails { type: 'ERROR_DETAILS'; reason: string; created: number; payload: { files: string[]; }; } export interface ScreenTemplate { name: string; template: string; description: string; url: string; } export interface StormEventScreen { type: 'SCREEN'; reason: string; created: number; payload: { blockName: string; blockRef?: string; instanceId?: string; name: string; template: string; description: string; url: string; filename: string; }; } export interface StormEventScreenCandidate { type: 'SCREEN_CANDIDATE'; reason: string; created: number; payload: { name: string; description: string; url: string; }; } export interface StormEventFileBasePayload { filename: string; path: string; blockName: string; blockRef: string; instanceId: string; } export interface StormEventFileBase { type: string; reason: string; created: number; payload: StormEventFileBasePayload; } export interface StormEventFileLogical extends StormEventFileBase { type: 'FILE_START' | 'FILE_CHUNK_RESET'; } export interface StormEventFileState extends StormEventFileBase { type: 'FILE_STATE'; payload: StormEventFileBasePayload & { state: string; }; } export interface StormEventFileDone extends StormEventFileBase { type: 'FILE_DONE'; payload: StormEventFileBasePayload & { content: string; }; } export interface StormEventFileFailed extends StormEventFileBase { type: 'FILE_FAILED'; payload: StormEventFileBasePayload & { error: string; }; } export interface StormEventFileChunk extends StormEventFileBase { type: 'FILE_CHUNK'; payload: StormEventFileBasePayload & { content: string; lineNumber: number; }; } export interface StormEventApiBase { type: | 'API_STREAM_CHUNK' | 'API_STREAM_DONE' | 'API_STREAM_FAILED' | 'API_STREAM_STATE' | 'API_STREAM_START' | 'API_STREAM_CHUNK_RESET'; payload: StormEventFileBasePayload; } export interface StormEventBlockReady { type: 'BLOCK_READY'; reason: string; created: number; payload: { path: string; blockName: string; blockRef: string; instanceId: string; }; } export enum StormEventBlockStatusType { QA = 'QA', FIXING = 'FIXING', PLANNING_FIX = 'PLANNING_FIX', FIX_DONE = 'FIX_DONE', BUILDING = 'BUILDING', } export interface StormEventBlockStatus { type: 'BLOCK_STATUS'; reason: string; created: number; payload: { status: StormEventBlockStatusType; blockName: string; blockRef: string; instanceId: string; }; } export interface StormEventDone { type: 'DONE'; created: number; } export interface StormImage { type: 'IMAGE'; reason: string; created: number; payload: { href: string; }; } export interface StormEventDefinitionChange { type: 'DEFINITION_CHANGE'; reason: string; created: number; payload: StormDefinitions; } export enum StormEventPhaseType { IMPLEMENT_APIS = 'IMPLEMENT_APIS', // Implement APIs in the html pages COMPOSE_SYSTEM_PROMPT = 'COMPOSE_SYSTEM_PROMPT', // Compose system prompt for bottom-up approach COMPOSE_SYSTEM = 'COMPOSE_SYSTEM', META = 'META', DEFINITIONS = 'DEFINITIONS', IMPLEMENTATION = 'IMPLEMENTATION', QA = 'QA', } export interface StormEventPhases { type: 'PHASE_START' | 'PHASE_END'; created: number; payload: { phaseType: StormEventPhaseType; }; } export interface Page { id: string; name: string; filename: string; title: string; description: string; content: string; path: string; method: string; conversationId: string; prompt: string; shellPage?: string; } // Event for creating a page export interface StormEventPage { type: 'PAGE'; reason: string; created: number; payload: Page; } // Event for creating a page export interface StormEventPageUrl { type: 'PAGE_URL'; reason: string; created: number; payload: { id: string; name: string; filename: string; title: string; description: string; path: string; url: string; method: string; conversationId: string; prompt: string; }; } export interface UserJourneyScreen { name: string; title: string; filename: string; requirements: string; path: string; method: string; nextScreens: string[]; conversationId?: string; } export interface UserJourney { title: string; screens: UserJourneyScreen[]; } // Event for defining a user journey export interface StormEventUserJourney { type: 'USER_JOURNEY'; reason: string; created: number; payload: UserJourney; } export interface UIShell { name: string; content: string; screens: string[]; } export interface StormEventUIShell { type: 'UI_SHELL'; reason: string; created: number; payload: UIShell; } export interface StormEventPromptImprove { type: 'PROMPT_IMPROVE'; reason: string; payload: { prompt: string; }; } export interface LandingPage { name: string; title: string; filename: string; create_prompt: string; path: string; archetype: string; requires_authentication: boolean; } // Event for defining a landing pages export interface StormEventLandingPage { type: 'LANDING_PAGE'; reason: string; created: number; payload: LandingPage; } export interface ReferenceClassification { name: string; title: string; url: string; description: string; type: 'image' | 'css' | 'javascript' | 'html'; source: 'local' | 'cdn' | 'example'; } // Event for reference classification export interface StormEventReferenceClassification { type: 'REF_CLASSIFICATION'; reason: string; created: number; payload: ReferenceClassification; } export interface StormEventUIStarted { type: 'UI_SERVER_STARTED'; reason: string; created: number; payload: { conversationId: string; resetUrl: string; }; } export interface StormEventSystemReady { type: 'SYSTEM_READY'; reason: string; created: number; payload: { systemUrl: string; }; } export interface StormEventModelResponse { type: 'MODEL_RESPONSE'; reason: string; created: number; payload: { text: string; }; } export type StormEvent = | StormEventCreateBlock | StormEventCreateConnection | StormEventCreatePlanProperties | StormEventInvalidResponse | StormEventPlanRetry | StormEventCreateDSL | StormEventCreateDSLResource | StormEventError | StormEventScreen | StormEventScreenCandidate | StormEventFileLogical | StormEventFileState | StormEventFileDone | StormEventFileFailed | StormEventFileChunk | StormEventDone | StormEventDefinitionChange | StormEventErrorClassifier | StormEventCodeFix | StormEventErrorDetails | StormEventBlockReady | StormEventPhases | StormEventBlockStatus | StormEventCreateDSLRetry | StormEventUserJourney | StormEventUIShell | StormEventPage | StormEventPageUrl | StormEventPromptImprove | StormEventLandingPage | StormEventReferenceClassification | StormEventApiBase | StormEventUIStarted | StormImage | StormEventSystemReady | StormEventModelResponse;