UNPKG

gensx

Version:
183 lines 4.48 kB
import { Definition } from "typescript-json-schema"; /** * Custom error classes for consistent error handling */ export declare class NotFoundError extends Error { statusCode: number; constructor(message: string); } export declare class BadRequestError extends Error { statusCode: number; constructor(message: string); } export declare class ServerError extends Error { statusCode: number; constructor(message: string); } /** * Configuration options for the GenSX dev server */ export interface ServerOptions { port?: number; hostname?: string; logger: { info: (message: string, ...args: unknown[]) => void; error: (message: string, error?: unknown) => void; warn: (message: string) => void; }; } /** * Interface representing a workflow that can be executed */ export interface WorkflowInfo { id: string; name: string; inputSchema?: Definition; outputSchema?: Definition; createdAt: string; updatedAt: string; url: string; } /** * Execution status type */ type ExecutionStatus = "queued" | "starting" | "running" | "completed" | "failed"; /** * Interface representing a workflow execution */ export interface WorkflowExecution { id: string; workflowName: string; executionStatus: ExecutionStatus; createdAt: string; finishedAt?: string; input: unknown; output?: unknown; error?: string; workflowMessages: WorkflowMessage[]; } export type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue; }; export type WorkflowMessage = { id: string; timestamp: string; } & ({ type: "start"; workflowExecutionId?: string; workflowName: string; } | { type: "component-start"; componentName: string; label?: string; componentId: string; } | { type: "component-end"; componentName: string; label?: string; componentId: string; } | { type: "data"; data: JsonValue; } | { type: "object" | "event"; data: Record<string, JsonValue>; label: string; } | { type: "error"; error: string; } | { type: "end"; }); /** * GenSX Server - A development server for GenSX workflows */ export declare class GensxServer { private app; private port; private hostname; private workflowMap; private schemaMap; private executionsMap; private isRunning; private server; private ajv; private logger; /** * Create a new GenSX dev server */ constructor(workflows?: Record<string, unknown>, options?: ServerOptions, schemas?: Record<string, { input: Definition; output: Definition; }>); /** * Set up error handling middleware */ private setupErrorHandler; /** * Register workflows with the server */ private registerWorkflows; /** * Get a workflow by name or throw NotFoundError */ private getWorkflowOrThrow; /** * Get an execution by ID or throw NotFoundError */ private getExecutionOrThrow; /** * Parse request body with error handling */ private parseJsonBody; /** * Validate input against schema * Throws BadRequestError if validation fails */ private validateInput; /** * Set up server routes */ private setupRoutes; /** * Handle streaming responses */ private handleStreamingResponse; /** * Generate OpenAPI specification dynamically based on server configuration */ private generateOpenApiSpec; /** * Generate Swagger UI HTML */ private generateSwaggerUI; /** * Start the server and return this instance for chaining */ start(): this; /** * Stop the server if it's running */ stop(): Promise<void>; /** * Return information about available workflows */ getWorkflows(): WorkflowInfo[]; /** * Async iterator for workflows - allows for the for-await-of pattern */ workflows(): AsyncIterableIterator<WorkflowInfo>; /** * Execute a workflow asynchronously and update its status */ private executeWorkflowAsync; } /** * Create a new GenSX server instance */ export declare function createServer(workflows?: Record<string, unknown>, options?: ServerOptions, schemas?: Record<string, { input: Definition; output: Definition; }>): GensxServer; export {}; //# sourceMappingURL=dev-server.d.ts.map