Spaces:
Paused

File size: 6,216 Bytes
bc9f3e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<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}