MCPcopy Create free account
hub / github.com/abi/screenshot-to-code / doGenerateCode

Function doGenerateCode

frontend/src/App.tsx:307–556  ·  view source on GitHub ↗
(params: GenerationRequest)

Source from the content-addressed store, hash-verified

305 };
306
307 function doGenerateCode(params: GenerationRequest) {
308 // Reset the execution console
309 resetExecutionConsoles();
310
311 // Set the app state to coding during generation
312 setAppState(AppState.CODING);
313
314 const { variantHistory, ...requestParams } = params;
315
316 const selectedDesignSystem = designSystems.find(
317 (designSystem) => designSystem.id === settings.selectedDesignSystemId
318 );
319
320 // Merge settings with params
321 const updatedParams = {
322 ...requestParams,
323 ...settings,
324 designSystem: selectedDesignSystem?.content ?? null,
325 };
326
327 // Use 4 variants for create, 2 for edits to match backend counts
328 // and avoid a flash when the backend sends the actual variant count
329 const initialVariantCount =
330 requestParams.generationType === "create" ? 4 : 2;
331 const baseCommitObject = {
332 variants: Array(initialVariantCount)
333 .fill(null)
334 .map(() => ({
335 code: "",
336 history: cloneVariantHistory(variantHistory),
337 })),
338 };
339
340 const commitInputObject =
341 requestParams.generationType === "create"
342 ? {
343 ...baseCommitObject,
344 type: "ai_create" as const,
345 parentHash: null,
346 inputs: requestParams.prompt,
347 }
348 : {
349 ...baseCommitObject,
350 type: "ai_edit" as const,
351 parentHash: head,
352 inputs: requestParams.prompt,
353 };
354
355 // Create a new commit and set it as the head
356 const commit = createCommit(commitInputObject);
357 addCommit(commit);
358 setHead(commit.hash);
359
360 lastThinkingEventIdRef.current = {};
361 lastAssistantEventIdRef.current = {};
362 lastToolEventIdRef.current = {};
363
364 const finishThinkingEvent = (variantIndex: number, status: "complete" | "error") => {

Callers 3

doCreateFunction · 0.85
doCreateFromTextFunction · 0.85
doUpdateFunction · 0.85

Calls 9

cloneVariantHistoryFunction · 0.90
createCommitFunction · 0.90
generateCodeFunction · 0.90
finishThinkingEventFunction · 0.85
finishAssistantEventFunction · 0.85
finishToolEventFunction · 0.85
finishInFlightEventsFunction · 0.85

Tested by

no test coverage detected