463 this.router.handle();
464 },
465 async fetchAPI(endpoint, options = {}) {
466 const res = await fetch(new URL(endpoint, "${sourceUrl}"), options);
467 if (!res.ok) throw new Error(\`API Error: \${res.status} on \${endpoint}\`);
468 const contentType = res.headers.get("content-type");
528
529 try {
530 const res = await App.fetchAPI('/api/gather', {
531 method: 'POST', headers: { 'Content-Type': 'application/json' },
532 body: JSON.stringify({ task, domain, history: App.state.conversationHistory }) // CORRECTED: Use App.state
562
563 try {
564 const res = await App.fetchAPI('/api/gather', {
565 method: 'POST', headers: { 'Content-Type': 'application/json' },
566 body: JSON.stringify({
596 const { task, occupation } = App.state.selections;
597 // First, get the refined prompt
598 const promptRes = await App.fetchAPI('/api/prompt/dynamic', {
599 method: 'POST',
600 headers: {'Content-Type': 'application/json'},
649
650 try {
651 const res = await App.fetchAPI('/api/execute-stream', {
652 method: 'POST', headers: {'Content-Type': 'application/json'},
653 body: JSON.stringify({ refined_prompt: App.state.refinedPrompt, user_inputs, company_context: App.state.companyContext }),
671 // 1. Generate Criteria
672 evalContainer.innerHTML = \`<h2 class="text-xl font-bold text-slate-900"><span class="text-violet-500">Step 2:</span> AI Evaluation</h2><div id="evaluation-content" class="mt-4 space-y-4"><p class="text-slate-500">Generating evaluation criteria...</p></div>\`;
673 const criteriaRes = await App.fetchAPI('/api/generate-criteria', {
674 method: 'POST', headers: {'Content-Type': 'application/json'},
675 body: JSON.stringify({ refined_prompt: App.state.refinedPrompt, company_context: App.state.companyContext }),
681 const evalCritiqueEl = getEl('eval-critique');
682 evalCritiqueEl.innerHTML = '<p class="text-slate-500">Evaluating draft against criteria...</p>';
683 const evalRes = await App.fetchAPI('/api/evaluate-output', {
684 method: 'POST', headers: {'Content-Type': 'application/json'},
685 body: JSON.stringify({ refined_prompt: App.state.refinedPrompt, raw_output: App.state.rawOutputV1, criteria: App.state.criteria, language: App.state.companyContext.language }),
700 <div id="v2-diff-content" class="mt-4 prose max-w-none hidden font-mono text-sm leading-relaxed"></div>
701 \`;
702 const refineRes = await App.fetchAPI('/api/refine-output', {
703 method: 'POST', headers: {'Content-Type': 'application/json'},
704 body: JSON.stringify({ refined_prompt: App.state.refinedPrompt, raw_output: App.state.rawOutputV1, evaluation: JSON.parse(App.state.evaluationResult), language: App.state.companyContext.language }),
742 };
743
744 const reevalRes = await App.fetchAPI('/api/reevaluate-output', {
745 method: 'POST',
746 headers: {'Content-Type': 'application/json'},
828 renderUI: {
829 sidebar: async () => {
830 const industriesList = await App.fetchAPI('/api/industries');
831 let html = \`<div class="space-y-1"><h3 class="px-2 text-xs font-semibold text-slate-400 uppercase tracking-wider sidebar-text">Categories</h3>\`;
832 industriesList.forEach(industry => {
928 App.router.updateSidebarUI(industry, occupationName);
929 const occupation = App.state.cache[\`occupations-\${industry}\`]?.find(o => o.name === occupationName) || { name: occupationName, description: '' };
930 const tasks = await App.fetchAPI('/api/generate/tasks', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ occupation: occupation.name, company_context: App.state.companyContext }) }).then(data => data.generated_list);
931 App.state.cache[\`tasks-\${occupationName}\`] = tasks;
932 App.renderUI.tasks(tasks, occupation, industry);
940 App.showScreen('tasks');
941 App.router.updateSidebarUI(industry);
942 const occupations = await App.fetchAPI('/api/generate/occupations', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ industry, company_context: App.state.companyContext }) }).then(data => data.generated_list);
943 App.state.cache[\`occupations-\${industry}\`] = occupations;
944 App.renderUI.occupations(occupations, industry);
1302
1303// --- EXPORT THE VAL ---
1304export default app.fetch;