import { completePrompt } from '../models'; import { getTransformInstr } from '../service/transformPage'; import { parseBuilderResponse } from './anthropic'; import { Builder, BuilderResult, CHANGE_OPS_FORMAT_INSTRUCTION } from './types'; /** * Create a FireworksAI-tuned builder. * Currently identical to the Anthropic builder — separate file enables * future per-provider tuning. */ export function createFireworksAIBuilder(complete: completePrompt, userInstructions?: string, productName?: string): Builder { const name = productName ?? 'SynthOS'; return { async run(currentPage, additionalSections, userMessage, newBuild, _attachments?): Promise { try { // -- System message -- const systemParts: string[] = [ `${currentPage.title}\n${currentPage.content}`, ]; for (const section of additionalSections) { if (section.content) { systemParts.push(`${section.title}\n${section.content}`); } } const systemContent = systemParts.join('\n\n'); // -- User message -- const instructionParts: string[] = []; if (userInstructions?.trim()) { instructionParts.push(userInstructions); } for (const section of additionalSections) { if (section.instructions?.trim()) { instructionParts.push(section.instructions); } } instructionParts.push(getTransformInstr(name)); instructionParts.push(CHANGE_OPS_FORMAT_INSTRUCTION); const instructions = instructionParts.filter(s => s.trim() !== '').join('\n'); const promptContent = `\n${userMessage}\n\n\n${instructions}`; const result = await complete({ system: { role: 'system', content: systemContent }, prompt: { role: 'user', content: promptContent }, }); if (!result.completed) { return { kind: 'error', error: result.error ?? new Error('Model call failed') }; } return parseBuilderResponse(result.value!); } catch (err: unknown) { return { kind: 'error', error: err instanceof Error ? err : new Error(String(err)) }; } } }; }