import type { SelectedCourseMaterial, SessionDocumentSource, UserRequirements, } from '@/lib/types/generation'; export interface ForegroundDocumentProviderConfig { apiKey?: string; baseUrl?: string; accessKeyId?: string; accessKeySecret?: string; } export interface ForegroundGenerationSession { sessionId: string; requirements: UserRequirements; pdfText: string; documentSources: SessionDocumentSource[]; pdfImages: []; imageStorageIds: []; sceneOutlines: null; currentStep: 'generating'; previewPhase: 'preparing'; taskEngineMode: boolean; pdfProviderId?: string; pdfProviderConfig?: ForegroundDocumentProviderConfig; } interface CreateForegroundGenerationSessionInput { sessionId: string; requirement: string; webSearch: boolean; interactiveMode: boolean; taskEngineMode: boolean; courseMaterials: SelectedCourseMaterial[]; pdfProviderId?: string; pdfProviderConfig?: ForegroundDocumentProviderConfig; storeDocument: (file: File) => Promise; } /** * Persist uploaded materials and build the session consumed by * `/generation-preview`. Keeping this adapter outside the classroom runtime * lets the home page choose foreground/background generation without * duplicating the preview pipeline. */ export async function createForegroundGenerationSession({ sessionId, requirement, webSearch, interactiveMode, taskEngineMode, courseMaterials, pdfProviderId, pdfProviderConfig, storeDocument, }: CreateForegroundGenerationSessionInput): Promise { const sortedMaterials = [...courseMaterials].sort((a, b) => a.order - b.order); const documentSources = await Promise.all( sortedMaterials.map( async (material): Promise => ({ id: material.id, name: material.name, size: material.size, lastModified: material.lastModified, mimeType: material.type, order: material.order, storageKey: await storeDocument(material.file), ...(pdfProviderId ? { providerId: pdfProviderId } : {}), }), ), ); return { sessionId, requirements: { requirement: requirement.trim(), ...(webSearch ? { webSearch: true } : {}), ...(interactiveMode ? { interactiveMode: true } : {}), ...(taskEngineMode ? { taskEngineMode: true } : {}), }, pdfText: '', documentSources, pdfImages: [], imageStorageIds: [], sceneOutlines: null, currentStep: 'generating', previewPhase: 'preparing', taskEngineMode, ...(pdfProviderId ? { pdfProviderId } : {}), ...(pdfProviderConfig ? { pdfProviderConfig } : {}), }; }