// Per-tab chat configuration for the migrated chat tabs — the single source // of truth for what each tab sends over the WebSocket and how its pane // renders (empty-state emoji, i18n label key). ChatPane.svelte composes // these helpers instead of hand-rolling per-tab conditionals. export const CHAT_TABS = ["general", "rag", "deep_research", "data", "vision"]; export const isChatTab = (key) => CHAT_TABS.includes(key); /** Empty-state emoji + i18n label key per tab. */ const TAB_PRESENTATION = { general: { emoji: "💬", emptyKey: "tab_general" }, rag: { emoji: "📚", emptyKey: "tab_rag" }, deep_research: { emoji: "🔬", emptyKey: "tab_deep_research" }, vision: { emoji: "🖼️", emptyKey: "tab_vision" }, data: { emoji: "📊", emptyKey: "tab_data" }, }; export const tabEmoji = (tab) => TAB_PRESENTATION[tab]?.emoji ?? "💬"; export const tabEmptyKey = (tab) => TAB_PRESENTATION[tab]?.emptyKey ?? "tab_general"; /** * Build the shared WebSocket payload (type/tab/message/history/model/lang/ * memory). `tool_calling` is skipped for Vision and Data — the VLM path has * no such toggle, and Data ALWAYS runs its EDA CodeAgent (Python * execution), so the flag doesn't exist there either. */ export function buildBasePayload( tab, { message, history, modelLabel, lang, memory, toolCalling } ) { return { type: "chat", tab, message, history, model_label: modelLabel, lang, use_memory: memory, ...(tab !== "vision" && tab !== "data" ? { use_tool_calling: toolCalling } : {}), }; } /** * Tab-specific WebSocket payload fields, built from the pane's per-tab state: * - General / RAG: agentic toggle + the agentic step budgets (max_steps for * the agent, plus RAG's searcher sub-agent budget) (+ General's per-step * execution_timeout) (+ RAG's retrieval topic filters, mirroring the * Gradio theme/subtheme boxes) (+ the whole-run generation timeout). * - Deep Research: Playwright browser-tool toggle, headless flag, the * manager/search step + timeout budgets, and the per-step * execution_timeout. * - Vision: uploaded image temp path, mmproj (projector) label (+ the * whole-run generation timeout). * - Data: the uploaded file temp paths, the manager's step budget, the * data_worker sub-agent's step budget, the per-step code-execution * timeout (+ the whole-run generation timeout). */ export function buildTabPayload(tab, state) { switch (tab) { case "deep_research": return { use_playwright: state.usePlaywright, headless: state.headless, manager_max_steps: state.managerSteps, search_max_steps: state.searchSteps, // Per-step code-execution timeout; null while the control is // untouched ("auto") — the backend then applies the agent // factory's default timeout. execution_timeout: state.execTimeout, timeout: state.drTimeout, }; case "vision": return { image: state.imagePath || null, mmproj_label: state.mmprojLabel, timeout: state.runTimeout, }; case "data": return { files: (state.dataFiles || []).map((f) => f.path), max_steps: state.maxSteps, worker_max_steps: state.workerSteps, execution_timeout: state.execTimeout, timeout: state.runTimeout, }; default: // max_steps / searcher_max_steps are null while their controls are // untouched ("auto") — the backend then applies its model-scaled // step budget instead of a fixed number; only an explicit user value // is sent as-is. (Direct mode ignores these anyway.) Ditto the // whole-run generation timeout: null = no explicit deadline. return { use_agentic: state.agentic, max_steps: state.maxSteps, // General-only: per-step code-execution timeout; null while the // control is untouched ("auto") — the backend then applies the // agent factory's default timeout. execution_timeout: state.execTimeout, timeout: state.runTimeout, ...(tab === "rag" ? { // Multi-select retrieval filters — arrays of selected names; // empty = filter on all (the backend builds Chroma $in // clauses from these). `files` restricts retrieval to the // picked KB source filenames. themes: state.themes || [], subthemes: state.subthemes || [], files: state.ragFiles || [], searcher_max_steps: state.searcherSteps, // RAG-only visual toggle (default OFF) — when false the // backend skips the page-image visual_retriever tool and the // VLM grounding pass (pure text retrieval + the text LLM). visual_retrieval: state.visualRetrieval, } : {}), }; } } /** Data Analysis preset workflow templates (mirror the old DataTab's * ANALYSIS_PROMPTS) — the selected preset becomes the message when the * composer is empty, exactly like the old "question || preset" flow. */ export const ANALYSIS_PROMPTS = { exploratory: "", sales: "Perform a full sales analysis following this workflow:\n1. Show total sales by month (line chart)\n2. Identify top-performing products (bar chart)\n3. Break down by customer segment (pie/donut chart)\n4. Compare this year vs last year (grouped bar chart)\n5. Forecast next quarter based on trends\n\nWrite the final report using the Insight Report template:\n## Executive Summary\n## Key Metrics (table: Metric | Value | Change)\n## Trends\n## Recommendations", customer: "Perform a full customer analysis following this workflow:\n1. Show customer distribution by segment (bar chart)\n2. Calculate key metrics per segment (avg spend, count)\n3. Identify top customers by value\n4. Analyze purchase frequency patterns\n\nWrite the final report using the Insight Report template:\n## Executive Summary\n## Key Metrics\n## Customer Segments\n## Recommendations", financial: "Perform a full financial analysis following this workflow:\n1. Calculate profit margins by product (bar chart)\n2. Show expense breakdown (pie chart)\n3. Analyze revenue vs expense trends over time (line chart)\n4. Compare budget vs actual (grouped bar chart)\n\nWrite the final report using the Insight Report template:\n## Executive Summary\n## Key Metrics\n## Trends\n## Recommendations", payroll: "Perform a full payroll analysis following this workflow:\n1. LOAD & VALIDATE — Load the payroll data; check for missing values in employee ID, hours worked, pay rate, deductions, and tax fields. Report any data quality issues.\n2. GROSS PAY — Calculate gross pay per employee (hours × rate, or salary proration). Show distribution with a histogram + boxplot. Flag any outliers.\n3. DEDUCTIONS & TAX — Break down deductions per employee. Plot a stacked bar chart of deductions by department.\n4. NET PAY — Calculate net pay (gross − deductions − tax). Show summary stats (mean, median, min, max).\n5. DEPARTMENT SUMMARY — Aggregate payroll by department: total gross, total deductions, total net, headcount, avg salary.\n6. COST TRENDS — If the data has a date column, plot total payroll cost over time.\n\nWrite the final report using the Insight Report template:\n## Executive Summary\n## Key Metrics (total gross, total deductions, total net, headcount, avg cost per employee)\n## Department Breakdown (table)\n## Recommendations", };