(
input: Parameters<typeof generateViaAgent>[0],
id: string,
designId: string,
previousSource: string | null,
workspaceRoot: string,
attachmentsForRuntimeFs?: Parameters<typeof createRuntimeTextEditorFs>[0]['attachments'],
memoryCallbacks?: {
onAggressivePrune?: () => void;
onComplete?: (messages: DesignBriefConversationMessages) => void;
},
)
| 432 | * sidebar chat can render incremental output. |
| 433 | */ |
| 434 | const runGenerate = async ( |
| 435 | input: Parameters<typeof generateViaAgent>[0], |
| 436 | id: string, |
| 437 | designId: string, |
| 438 | previousSource: string | null, |
| 439 | workspaceRoot: string, |
| 440 | attachmentsForRuntimeFs?: Parameters<typeof createRuntimeTextEditorFs>[0]['attachments'], |
| 441 | memoryCallbacks?: { |
| 442 | onAggressivePrune?: () => void; |
| 443 | onComplete?: (messages: DesignBriefConversationMessages) => void; |
| 444 | }, |
| 445 | ): ReturnType<typeof generateViaAgent> => { |
| 446 | const sendEvent = (event: AgentStreamEvent) => { |
| 447 | getMainWindow()?.webContents.send('agent:event:v1', event); |
| 448 | }; |
| 449 | const baseCtx = { designId, generationId: id } as const; |
| 450 | const toolStartedAt = new Map<string, number>(); |
| 451 | const runtimeVerify = makeRuntimeVerifier(); |
| 452 | const templatesRoot = path_module.join(app.getPath('userData'), 'templates'); |
| 453 | const currentWorkspaceRoot = () => requireWorkspaceRootForDesign(designId).workspaceRoot; |
| 454 | const [frames, designSkills, initialWorkspaceFiles] = await Promise.all([ |
| 455 | loadFrameTemplates(path_module.join(templatesRoot, 'frames')), |
| 456 | loadDesignSkills(path_module.join(templatesRoot, 'design-skills')), |
| 457 | withStableWorkspacePath(designId, () => readWorkspaceFilesAt(currentWorkspaceRoot())), |
| 458 | ]); |
| 459 | const { fs, fsMap, syncWorkspaceTextFile } = createRuntimeTextEditorFs({ |
| 460 | db, |
| 461 | designId, |
| 462 | generationId: id, |
| 463 | logger: logIpc, |
| 464 | previousSource, |
| 465 | initialFiles: initialWorkspaceFiles, |
| 466 | attachments: attachmentsForRuntimeFs ?? input.attachments, |
| 467 | sendEvent, |
| 468 | frames, |
| 469 | designSkills, |
| 470 | }); |
| 471 | const cfg = getCachedConfig(); |
| 472 | const imageConfig = cfg ? await resolveImageGenerationConfig(cfg) : null; |
| 473 | const imageLog = getLogger('image-generation'); |
| 474 | const generateImageAsset = imageConfig |
| 475 | ? async ( |
| 476 | request: GenerateImageAssetRequest, |
| 477 | signal?: AbortSignal, |
| 478 | ): Promise<GenerateImageAssetResult> => { |
| 479 | const started = Date.now(); |
| 480 | const options = toGenerateImageOptions( |
| 481 | imageConfig, |
| 482 | request.prompt, |
| 483 | signal, |
| 484 | request.aspectRatio, |
| 485 | ); |
| 486 | imageLog.info('provider.request', { |
| 487 | generationId: id, |
| 488 | provider: options.provider, |
| 489 | model: options.model, |
| 490 | size: options.size, |
| 491 | aspectRatio: request.aspectRatio ?? 'default', |
no test coverage detected