(url: string, mode?: ValidationMode)
| 11 | import { logger } from './utils/logger'; |
| 12 | |
| 13 | export async function design2code(url: string, mode?: ValidationMode): Promise<void> { |
| 14 | const urlInfo = parseFigmaUrl(url); |
| 15 | const threadId = urlInfo.projectName!; |
| 16 | const workspace = workspaceManager.initWorkspace(threadId); |
| 17 | |
| 18 | // Initialize SqliteSaver with the database path |
| 19 | const checkpointer = initializeSqliteSaver(workspace.db); |
| 20 | const resume = await promptCheckpointChoice(checkpointer, threadId); |
| 21 | |
| 22 | logger.printInfoLog(`Starting design-to-code process for: ${urlInfo.projectName}`); |
| 23 | |
| 24 | // If not resuming, delete workspace and reinitialize checkpointer |
| 25 | if (resume !== true) { |
| 26 | // Preserve only the database file to avoid EBUSY error on Windows (SQLite lock) |
| 27 | workspaceManager.deleteWorkspace(workspace, [ |
| 28 | 'checkpoint/coderio-cli.db', |
| 29 | 'checkpoint/coderio-cli.db-shm', |
| 30 | 'checkpoint/coderio-cli.db-wal', |
| 31 | ]); |
| 32 | logger.printInfoLog('Starting fresh...'); |
| 33 | |
| 34 | // Clear existing checkpoints for this thread instead of deleting the file |
| 35 | await clearThreadCheckpoint(checkpointer, threadId); |
| 36 | } else { |
| 37 | logger.printInfoLog('Resuming from cache...'); |
| 38 | } |
| 39 | |
| 40 | // Compile graph with checkpointer (after potential reinitialization) |
| 41 | const graph = new StateGraph(GraphStateAnnotation) |
| 42 | .addNode(GraphNode.INITIAL, initialProject) |
| 43 | .addNode(GraphNode.PROCESS, generateProtocol) |
| 44 | .addNode(GraphNode.CODE, generateCode) |
| 45 | .addNode(GraphNode.VALIDATION, runValidation) |
| 46 | .addEdge(START, GraphNode.INITIAL) |
| 47 | .addEdge(GraphNode.INITIAL, GraphNode.PROCESS) |
| 48 | .addEdge(GraphNode.PROCESS, GraphNode.CODE) |
| 49 | .addEdge(GraphNode.CODE, GraphNode.VALIDATION) |
| 50 | .addEdge(GraphNode.VALIDATION, END) |
| 51 | .compile({ checkpointer }); |
| 52 | |
| 53 | const config = { configurable: { thread_id: threadId } }; |
| 54 | |
| 55 | // If resuming from checkpoint, pass null to let LangGraph resume from saved state |
| 56 | // Otherwise, pass initial state to start fresh |
| 57 | const validationMode: ValidationMode = mode ?? ValidationMode.Full; |
| 58 | const state = |
| 59 | resume === true |
| 60 | ? null |
| 61 | : { |
| 62 | messages: [], |
| 63 | urlInfo, |
| 64 | workspace, |
| 65 | config: { |
| 66 | validationMode, |
| 67 | }, |
| 68 | }; |
| 69 | await graph.invoke(state, config); |
| 70 |
no test coverage detected