Spaces:
Paused

assistant / ui /web /src /components /chat /DataControls.svelte
localailb's picture
Deploy Full LocalAiLab Application (FastAPI + Svelte + Agents)
bc9f3e6 verified
Raw History Blame Contribute Delete
6.22 kB
<script>
import { app, t } from "../../lib/stores.svelte.js";
import { dataOpenOutputs, dataOutputDir, dataUpload } from "../../lib/api.js";
import "./Controls.css";
import MiniSelect from "./MiniSelect.svelte";
import PresetSelect from "./PresetSelect.svelte";
import {
EXEC_TIMEOUT_OPTIONS,
STEP_OPTIONS,
SUBSTEP_OPTIONS,
} from "../../lib/chatPresets.js";
/**
* dataFiles: [{name, path}] uploaded via /api/data/upload β€” the WS payload
* carries the temp paths to chat.chat_data, which deletes them after the
* run. analysisType / maxSteps / execTimeout live in ChatPane: the preset
* becomes the message when the composer is empty (ANALYSIS_PROMPTS), and
* the budgets follow the AUTO semantics of the other agentic tabs
* (null = the backend applies its default).
*
* Split into two halves like VisionControls so the layout can keep the
* upload chip next to the composer (the tab's INPUT) while tucking the
* preset + step budgets into the collapsed Generation Settings section:
* - fileOnly β€” render ONLY the upload chip + the uploaded file list.
* - settingsOnly β€” render ONLY the preset + step-budget fields.
* Default (neither) keeps the combined layout.
*/
let {
dataFiles = $bindable(),
analysisType = $bindable(),
maxSteps = $bindable(),
workerSteps = $bindable(),
execTimeout = $bindable(),
/** The concrete values the Data tab's "auto" controls resolve to
* (computed in ChatPane from /api/meta autoDefaults + the live model) β€”
* shown as the placeholder so an empty field reveals the real default. */
autoMaxSteps = 20,
autoWorkerSteps = 10,
autoExecTimeout = 120,
notify,
/** (settingKey, value) fired on blur/Enter β€” the pane persists the
* budget (value null = back to auto) and refreshes the meta store. */
onSteps = () => {},
fileOnly = false,
settingsOnly = false,
} = $props();
async function onPickFiles(e) {
const picked = [...(e.currentTarget.files || [])];
e.currentTarget.value = ""; // allow re-picking the same file
if (!picked.length) return;
try {
const r = await dataUpload(picked);
const paths = r.paths || [];
const merged = [...dataFiles];
picked.forEach((f, i) => merged.push({ name: f.name, path: paths[i] || "" }));
dataFiles = merged.filter((f) => f.path);
notify("", false);
} catch {
notify(t("web_upload_fail"), true);
}
}
function removeFile(path) {
dataFiles = dataFiles.filter((f) => f.path !== path);
}
/** The Data Analysis charts folder β€” its FULL path is displayed on the
* tab (the agent saves every chart PNG there) with an Open button
* (mirrors the STT outputs folder). The path is fetched once on mount;
* opening re-reads it. */
let outDirPath = $state("");
async function loadOutDir() {
try {
const r = await dataOutputDir();
if (r?.path) outDirPath = r.path;
} catch {
/* non-fatal β€” the row just shows the button without a path */
}
}
$effect(() => {
if (!fileOnly) loadOutDir();
});
async function openOutputs() {
try {
const r = await dataOpenOutputs();
if (r?.path) outDirPath = r.path;
notify("", false);
} catch {
notify(t("web_upload_fail"), true);
}
}
</script>
{#if !settingsOnly}
<div class="image-row">
<label class="chip upload-chip" data-tooltip={t("web_tt_upload_data")}>
<input type="file" accept=".csv,.xlsx,.xls,text/csv" multiple onchange={onPickFiles} hidden />
{t("web_upload_data")}
</label>
{#each dataFiles as f (f.path)}
<span class="file-chip" data-tooltip={t("web_tt_upload_data")}>
πŸ“Ž {f.name}
<button
type="button"
class="file-remove"
onclick={() => removeFile(f.path)}
data-tooltip={t("web_tt_remove_data_file")}
aria-label={t("web_tt_remove_data_file")}
>Γ—</button>
</span>
{/each}
</div>
{/if}
{#if !fileOnly}
<p class="data-model-tip">{t("data_model_tip")}</p>
<div class="theme-row">
<label class="mini-field" data-tooltip={t("web_tt_analysis_type")}>
<span>{t("label_analysis_type")}</span>
<MiniSelect
bind:value={analysisType}
options={(app?.meta?.analysisTypes ?? ["exploratory"]).map((ty) => ({
value: ty,
label: t(`analysis_${ty}`),
}))}
tip={t("web_tt_analysis_type")}
/>
</label>
</div>
<div class="theme-row">
<label class="mini-field" data-tooltip={t("info_max_steps")}>
<span>{t("label_max_steps")}</span>
<PresetSelect
bind:value={maxSteps}
options={STEP_OPTIONS}
autoLabel={`${t("exec_timeout_auto")} Β· ${autoMaxSteps}`}
tip={t("info_max_steps")}
onchange={() => onSteps("max_steps", maxSteps)}
/>
</label>
<label class="mini-field" data-tooltip={t("web_tt_worker_steps")}>
<span>{t("web_worker_steps")}</span>
<PresetSelect
bind:value={workerSteps}
options={SUBSTEP_OPTIONS}
autoLabel={`${t("exec_timeout_auto")} Β· ${autoWorkerSteps}`}
tip={t("web_tt_worker_steps")}
onchange={() => onSteps("worker_max_steps", workerSteps)}
/>
</label>
<label class="mini-field" data-tooltip={t("info_code_timeout")}>
<span>{t("label_code_timeout")}</span>
<PresetSelect
bind:value={execTimeout}
options={EXEC_TIMEOUT_OPTIONS}
autoLabel={`${t("exec_timeout_auto")} Β· ${autoExecTimeout}s`}
tip={t("info_code_timeout")}
onchange={() => onSteps("execution_timeout", execTimeout)}
/>
</label>
</div>
<!-- The charts folder: the full path of the folder where the agent saves
every generated chart PNG, with an Open button (Explorer). -->
<div class="theme-row data-out-row">
<button
type="button"
class="data-out-btn"
onclick={openOutputs}
data-tooltip={t("web_tt_data_out_dir")}
>
πŸ“‚ {t("data_out_dir_label")}
</button>
{#if outDirPath}
<code class="data-out-path">{outDirPath}</code>
{/if}
</div>
{/if}