MCPcopy Create free account
hub / github.com/MigoXLab/coderio / generateComponent

Function generateComponent

src/nodes/code/utils.ts:149–173  ·  view source on GitHub ↗
(node: Protocol, state: GraphState, assetFilesList: string, progressInfo: string)

Source from the content-addressed store, hash-verified

147 * Components are self-contained UI elements driven by props
148 */
149export async function generateComponent(node: Protocol, state: GraphState, assetFilesList: string, progressInfo: string): Promise<void> {
150 const componentName = node.data.componentName || node.data.name || 'UnknownComponent';
151 const componentPath = node.data.componentPath || node.data.path || '';
152
153 logger.printInfoLog(`${progressInfo} 📦 Generating Component: ${componentName}`);
154
155 // Generate prompt
156 const prompt = generateComponentPrompt({
157 componentName,
158 componentDetails: JSON.stringify(node.data),
159 styling: JSON.stringify(DEFAULT_STYLING),
160 assetFiles: assetFilesList,
161 });
162
163 // Call AI model
164 const code = await callModel({
165 question: prompt,
166 imageUrls: state.figmaInfo.thumbnail,
167 });
168
169 // Save generated files
170 const filePath = workspaceManager.resolveAppSrc(state.workspace, workspaceManager.resolveComponentPath(componentPath));
171 saveGeneratedCode(code, filePath);
172 logger.printSuccessLog(`Successfully generated component: ${componentName}`);
173}
174
175/**
176 * Helper function to save generated code (handles both single and multi-file output)

Callers 1

processSingleNodeFunction · 0.85

Calls 5

generateComponentPromptFunction · 0.90
callModelFunction · 0.90
saveGeneratedCodeFunction · 0.85
resolveAppSrcMethod · 0.80
resolveComponentPathMethod · 0.80

Tested by

no test coverage detected