summaryrefslogtreecommitdiffhomepage
path: root/src/app/views/VisionPane.svelte
blob: 5d535457db4e1bb43c9368a75001e8e945bcabe6 (plain)
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
<script lang="ts">
  /**
   * The `vision` view — global vision settings (image-compaction limit +
   * model) with the store adapters. Not conversation-scoped (no {#key}), so
   * the settings stay mounted across tab switches (like today).
   */
  import {
    VisionSettingsView,
    type LoadVisionSettingsResult,
    type SaveVisionSettingsResult,
    type VisionSettingsPatch,
  } from "../../features/vision";
  import type { AppViewPorts } from "../view-ports";

  let { ports }: { ports: AppViewPorts } = $props();
  const store = $derived(ports.store);

  // Adapt the store's global vision-settings API to the vision feature's ports.
  async function loadVisionSettings(): Promise<LoadVisionSettingsResult> {
    // The store seeds `visionSettings` on boot; a refresh keeps it current.
    await store.refreshVisionSettings();
    const settings = store.visionSettings;
    if (settings === null) {
      return { ok: false, error: "Vision settings not available." };
    }
    return { ok: true, settings };
  }

  async function saveVisionSettings(
    patch: VisionSettingsPatch,
  ): Promise<SaveVisionSettingsResult> {
    const result = await store.setVisionSettings(patch);
    if (result === null) return { ok: false, error: "Vision settings not available." };
    return result.ok
      ? { ok: true, settings: result.settings }
      : { ok: false, error: result.error };
  }
</script>

<VisionSettingsView
  models={store.models}
  modelInfo={store.modelInfo}
  load={loadVisionSettings}
  save={saveVisionSettings}
/>