@g9tm/aiassistant-svelte 1.9.0 → 1.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,27 +1,27 @@
1
- <script lang="ts">
2
- // "Save as CSV" for a table or an export block, through the host's file save (hidden when the host cannot save). The
3
- // file is the core's: a BOM, every cell quoted, no formula injection. A short notice says whether it was saved.
4
- import { can } from "@g9tm/aiassistant";
5
- import { saveCsv } from "@g9tm/aiassistant/pages";
6
- import { useUi } from "../context.js";
7
- import { pageTexts } from "../pages/texts.js";
8
-
9
- let { title = undefined, labels, rows }: { title?: string | undefined; labels: readonly string[]; rows: readonly (readonly string[])[] } = $props();
10
- const ui = useUi();
11
- const t = pageTexts(ui.texts).t;
12
- let saved = $state<boolean | null>(null);
13
- let busy = $state(false);
14
-
15
- async function save(): Promise<void> {
16
- busy = true;
17
- saved = await saveCsv(ui.assistant.host, title, labels, rows);
18
- busy = false;
19
- }
20
- </script>
21
-
22
- {#if can(ui.assistant.host, "save")}
23
- <div class="g9a-csv">
24
- <button type="button" class="g9a-csv__save" disabled={busy} onclick={save}>{t("csv.save")}</button>
25
- {#if saved !== null}<span class="g9a-note" role="status" data-saved={saved}>{t(saved ? "csv.saved" : "csv.not_saved")}</span>{/if}
26
- </div>
27
- {/if}
1
+ <script lang="ts">
2
+ // "Save as CSV" for a table or an export block, through the host's file save (hidden when the host cannot save). The
3
+ // file is the core's: a BOM, every cell quoted, no formula injection. A short notice says whether it was saved.
4
+ import { can } from "@g9tm/aiassistant";
5
+ import { saveCsv } from "@g9tm/aiassistant/pages";
6
+ import { useUi } from "../context.js";
7
+ import { pageTexts } from "../pages/texts.js";
8
+
9
+ let { title = undefined, labels, rows }: { title?: string | undefined; labels: readonly string[]; rows: readonly (readonly string[])[] } = $props();
10
+ const ui = useUi();
11
+ const t = pageTexts(ui.texts).t;
12
+ let saved = $state<boolean | null>(null);
13
+ let busy = $state(false);
14
+
15
+ async function save(): Promise<void> {
16
+ busy = true;
17
+ saved = await saveCsv(ui.assistant.host, title, labels, rows);
18
+ busy = false;
19
+ }
20
+ </script>
21
+
22
+ {#if can(ui.assistant.host, "save")}
23
+ <div class="g9a-csv">
24
+ <button type="button" class="g9a-csv__save" disabled={busy} onclick={save}>{t("csv.save")}</button>
25
+ {#if saved !== null}<span class="g9a-note" role="status" data-saved={saved}>{t(saved ? "csv.saved" : "csv.not_saved")}</span>{/if}
26
+ </div>
27
+ {/if}
@@ -1,96 +1,96 @@
1
- <script lang="ts">
2
- // The person's conversations in four tabs with their counts (today, earlier, pinned, waiting for a code), one search
3
- // over all of them, pin or unpin, delete after a confirmation, and open. The rows and tabs come from the core's
4
- // page helpers; this only draws them.
5
- import { HISTORY_TABS, historyTabs, pageCalls, readConversations, tabCounts, type ConversationRow, type HistoryTab } from "@g9tm/aiassistant/pages";
6
- import { faDigits } from "@g9tm/aiassistant";
7
- import { cls, override, useUi } from "../context.js";
8
- import Dialog from "../slots/Dialog.svelte";
9
- import { pageTexts } from "./texts.js";
10
-
11
- let { onopen = undefined }: { onopen?: ((conversationId: string) => void) | undefined } = $props();
12
- const ui = useUi();
13
- const t = pageTexts(ui.texts).t;
14
- const api = ui.assistant.api;
15
- const Confirm = $derived(override(ui, "Dialog") ?? Dialog);
16
- let rows = $state<ConversationRow[]>([]);
17
- let failed = $state(false);
18
- let search = $state("");
19
- let tab = $state<HistoryTab>("today");
20
- let removing = $state<ConversationRow | null>(null);
21
- let asking = $state(false);
22
- const digits = (n: number): string => (ui.texts.locale === "fa" ? faDigits(String(n)) : String(n));
23
-
24
- async function load(): Promise<void> {
25
- try {
26
- rows = readConversations(await api.conversations());
27
- failed = false;
28
- } catch {
29
- failed = true;
30
- }
31
- }
32
- $effect(() => { void load(); });
33
-
34
- const tabs = $derived(historyTabs(rows, new Date(), search));
35
- const counts = $derived(tabCounts(tabs));
36
- const shown = $derived(new Map(Object.entries(tabs)).get(tab) ?? []);
37
-
38
- async function call(work: Promise<unknown>): Promise<void> {
39
- try {
40
- await work;
41
- } catch {
42
- failed = true;
43
- }
44
- await load();
45
- }
46
-
47
- function askRemove(row: ConversationRow): void {
48
- removing = row;
49
- asking = true;
50
- }
51
-
52
- async function remove(): Promise<void> {
53
- const row = removing;
54
- asking = false;
55
- removing = null;
56
- if (row) await call(pageCalls.remove(api, row.id));
57
- }
58
-
59
- async function open(id: string): Promise<void> {
60
- await ui.assistant.open(id);
61
- onopen?.(id);
62
- }
63
- </script>
64
-
65
- <div class={cls(ui, "panel.body") + " g9a-history"} data-page="history">
66
- {#if failed}<p class="g9a-note" role="alert">{t("error.network")}</p>{/if}
67
- <input type="search" bind:value={search} placeholder={t("history.search")} aria-label={t("history.search")} />
68
- <div role="tablist" class="g9a-tabs" aria-label={t("history.tabs")}>
69
- {#each HISTORY_TABS as x (x)}
70
- <button type="button" role="tab" data-tab={x} aria-selected={tab === x} onclick={() => { tab = x; }}>
71
- {t("history." + x)} <span class="g9a-count">{digits(new Map(Object.entries(counts)).get(x) ?? 0)}</span>
72
- </button>
73
- {/each}
74
- </div>
75
- <div role="tabpanel" data-tab={tab}><ul class="g9a-history__list">
76
- {#each shown as row (row.id)}
77
- <li class="g9a-history__row" data-id={row.id} data-pinned={row.pinned} data-waiting={row.waiting}>
78
- <button type="button" class="g9a-history__open" onclick={() => open(row.id)}>{row.title || t("history.untitled")}</button>
79
- <button type="button" class="g9a-history__pin" aria-pressed={row.pinned} onclick={() => call(pageCalls.pin(api, row.id, !row.pinned))}>
80
- {row.pinned ? t("history.unpin") : t("history.pin")}
81
- </button>
82
- <button type="button" class="g9a-history__delete" onclick={() => askRemove(row)}>{t("history.delete")}</button>
83
- </li>
84
- {:else}
85
- <li class="g9a-note">{t("history.empty")}</li>
86
- {/each}
87
- </ul></div>
88
- <Confirm bind:open={asking} label={t("history.delete_confirm")}>
89
- <p>{t("history.delete_confirm")}</p>
90
- <p><strong>{removing?.title || t("history.untitled")}</strong></p>
91
- <div class="g9a-row">
92
- <button type="button" class="g9a-history__delete-yes" onclick={remove}>{t("history.delete")}</button>
93
- <button type="button" onclick={() => { asking = false; removing = null; }}>{t("no")}</button>
94
- </div>
95
- </Confirm>
96
- </div>
1
+ <script lang="ts">
2
+ // The person's conversations in four tabs with their counts (today, earlier, pinned, waiting for a code), one search
3
+ // over all of them, pin or unpin, delete after a confirmation, and open. The rows and tabs come from the core's
4
+ // page helpers; this only draws them.
5
+ import { HISTORY_TABS, historyTabs, pageCalls, readConversations, tabCounts, type ConversationRow, type HistoryTab } from "@g9tm/aiassistant/pages";
6
+ import { faDigits } from "@g9tm/aiassistant";
7
+ import { cls, override, useUi } from "../context.js";
8
+ import Dialog from "../slots/Dialog.svelte";
9
+ import { pageTexts } from "./texts.js";
10
+
11
+ let { onopen = undefined }: { onopen?: ((conversationId: string) => void) | undefined } = $props();
12
+ const ui = useUi();
13
+ const t = pageTexts(ui.texts).t;
14
+ const api = ui.assistant.api;
15
+ const Confirm = $derived(override(ui, "Dialog") ?? Dialog);
16
+ let rows = $state<ConversationRow[]>([]);
17
+ let failed = $state(false);
18
+ let search = $state("");
19
+ let tab = $state<HistoryTab>("today");
20
+ let removing = $state<ConversationRow | null>(null);
21
+ let asking = $state(false);
22
+ const digits = (n: number): string => (ui.texts.locale === "fa" ? faDigits(String(n)) : String(n));
23
+
24
+ async function load(): Promise<void> {
25
+ try {
26
+ rows = readConversations(await api.conversations());
27
+ failed = false;
28
+ } catch {
29
+ failed = true;
30
+ }
31
+ }
32
+ $effect(() => { void load(); });
33
+
34
+ const tabs = $derived(historyTabs(rows, new Date(), search));
35
+ const counts = $derived(tabCounts(tabs));
36
+ const shown = $derived(new Map(Object.entries(tabs)).get(tab) ?? []);
37
+
38
+ async function call(work: Promise<unknown>): Promise<void> {
39
+ try {
40
+ await work;
41
+ } catch {
42
+ failed = true;
43
+ }
44
+ await load();
45
+ }
46
+
47
+ function askRemove(row: ConversationRow): void {
48
+ removing = row;
49
+ asking = true;
50
+ }
51
+
52
+ async function remove(): Promise<void> {
53
+ const row = removing;
54
+ asking = false;
55
+ removing = null;
56
+ if (row) await call(pageCalls.remove(api, row.id));
57
+ }
58
+
59
+ async function open(id: string): Promise<void> {
60
+ await ui.assistant.open(id);
61
+ onopen?.(id);
62
+ }
63
+ </script>
64
+
65
+ <div class={cls(ui, "panel.body") + " g9a-history"} data-page="history">
66
+ {#if failed}<p class="g9a-note" role="alert">{t("error.network")}</p>{/if}
67
+ <input type="search" bind:value={search} placeholder={t("history.search")} aria-label={t("history.search")} />
68
+ <div role="tablist" class="g9a-tabs" aria-label={t("history.tabs")}>
69
+ {#each HISTORY_TABS as x (x)}
70
+ <button type="button" role="tab" data-tab={x} aria-selected={tab === x} onclick={() => { tab = x; }}>
71
+ {t("history." + x)} <span class="g9a-count">{digits(new Map(Object.entries(counts)).get(x) ?? 0)}</span>
72
+ </button>
73
+ {/each}
74
+ </div>
75
+ <div role="tabpanel" data-tab={tab}><ul class="g9a-history__list">
76
+ {#each shown as row (row.id)}
77
+ <li class="g9a-history__row" data-id={row.id} data-pinned={row.pinned} data-waiting={row.waiting}>
78
+ <button type="button" class="g9a-history__open" onclick={() => open(row.id)}>{row.title || t("history.untitled")}</button>
79
+ <button type="button" class="g9a-history__pin" aria-pressed={row.pinned} onclick={() => call(pageCalls.pin(api, row.id, !row.pinned))}>
80
+ {row.pinned ? t("history.unpin") : t("history.pin")}
81
+ </button>
82
+ <button type="button" class="g9a-history__delete" onclick={() => askRemove(row)}>{t("history.delete")}</button>
83
+ </li>
84
+ {:else}
85
+ <li class="g9a-note">{t("history.empty")}</li>
86
+ {/each}
87
+ </ul></div>
88
+ <Confirm bind:open={asking} label={t("history.delete_confirm")}>
89
+ <p>{t("history.delete_confirm")}</p>
90
+ <p><strong>{removing?.title || t("history.untitled")}</strong></p>
91
+ <div class="g9a-row">
92
+ <button type="button" class="g9a-history__delete-yes" onclick={remove}>{t("history.delete")}</button>
93
+ <button type="button" onclick={() => { asking = false; removing = null; }}>{t("no")}</button>
94
+ </div>
95
+ </Confirm>
96
+ </div>
@@ -1,89 +1,89 @@
1
- <script lang="ts" module>
2
- export type PageKind = "history" | "abilities" | "knowledge" | "learned" | "findings" | "routines" | "actions" | "admin";
3
- </script>
4
-
5
- <script lang="ts">
6
- // The assistant's pages, each from its own endpoint, read with type checks only.
7
- import { arr, num, obj, str } from "@g9tm/aiassistant";
8
- import { pageTexts } from "@g9tm/aiassistant/pages";
9
- import { cls, override, useUi } from "../context.js";
10
- import History from "./History.svelte";
11
- import RoutineWizard from "./RoutineWizard.svelte";
12
-
13
- let { kind, onopen = undefined }: { kind: PageKind; onopen?: ((conversationId: string) => void) | undefined } = $props();
14
- const ui = useUi();
15
- const t = ui.texts.t;
16
- const api = ui.assistant.api;
17
- let data = $state<Record<string, unknown>>({});
18
- let error = $state<string | null>(null);
19
- let loaded = $state(false); // an empty page says so only once its answer came
20
- const empty = $derived(pageTexts(ui.texts).t("page." + kind + ".empty"));
21
- let purpose = $state("");
22
- let code = $state("");
23
- let token = $state<string | null>(null);
24
-
25
- const PATHS: Record<PageKind, string> = {
26
- history: "conversations", abilities: "capabilities", knowledge: "knowledge", learned: "learned/dashboard?capability=chat",
27
- findings: "findings", routines: "routines", actions: "conversations", admin: "gates",
28
- };
29
-
30
- async function load(): Promise<void> {
31
- try {
32
- data = obj(await api.get(new Map(Object.entries(PATHS)).get(kind) ?? ""));
33
- error = null;
34
- } catch (e) {
35
- error = e instanceof Error ? e.message : "error.network";
36
- }
37
- loaded = true;
38
- }
39
- // History and the routine wizard are their own (replaceable) pages and read their own data.
40
- const Own = $derived(kind === "history" ? override(ui, "History") ?? History : kind === "routines" ? override(ui, "RoutineWizard") ?? RoutineWizard : null);
41
- $effect(() => { if (kind !== "history" && kind !== "routines") void load(); });
42
- async function act(path: string, body?: unknown): Promise<void> {
43
- await api.post(path, body).catch(() => undefined);
44
- await load();
45
- }
46
- </script>
47
-
48
- {#if Own}
49
- <Own {onopen} />
50
- {:else}
51
- <div class={cls(ui, "panel.body")} data-page={kind}>
52
- {#if error}<p class="g9a-note" role="alert">{t("error.network")}</p>{/if}
53
- {#if kind === "abilities"}
54
- {#each arr(data["groups"]).map(obj) as g (str(g["name"]))}
55
- <h4>{str(g["title"], str(g["name"]))}</h4>
56
- <ul>{#each arr(g["tools"]).map(obj) as tool (str(tool["name"]))}<li>{str(tool["title"], str(tool["name"]))}</li>{/each}</ul>
57
- {/each}
58
- {#each arr(data["closed"]).map(obj) as c (str(c["name"]))}<p class="g9a-note">{str(c["name"])} · {str(c["layer"])}</p>{/each}
59
- {#if loaded && arr(data["groups"]).length === 0 && arr(data["closed"]).length === 0}<p class="g9a-note g9a-empty">{empty}</p>{/if}
60
- {:else if kind === "knowledge"}
61
- <ul>{#each arr(data["notes"] ?? data["items"]).map(obj) as n, i (i)}<li>{str(n["text"], str(n["name"]))}</li>{:else}{#if loaded}<li class="g9a-note g9a-empty">{empty}</li>{/if}{/each}</ul>
62
- {:else if kind === "learned"}
63
- <p>{Math.round(num(data["modelFreeRate"]) * 100)}% · {num(data["tokensSaved"])}</p>
64
- <ul>{#each arr(data["items"]).map(obj) as it, i (i)}<li data-status={str(it["status"])}>{str(it["signature"])} · {str(it["status"])} · {num(it["hits"])}</li>{:else}{#if loaded}<li class="g9a-note g9a-empty">{empty}</li>{/if}{/each}</ul>
65
- {:else if kind === "findings"}
66
- <ul>
67
- {#each arr(data["findings"]).map(obj) as f (str(f["id"]))}
68
- <li>
69
- {str(obj(f["title"])["text"], t(str(obj(f["title"])["key"])))}
70
- <button type="button" onclick={() => act("findings/" + encodeURIComponent(str(f["id"])) + "/fixed")}>✓</button>
71
- <button type="button" onclick={() => act("findings/" + encodeURIComponent(str(f["id"])) + "/dismiss", { reason: "—" })}>{t("no")}</button>
72
- </li>
73
- {:else}
74
- {#if loaded}<li class="g9a-note g9a-empty">{empty}</li>{/if}
75
- {/each}
76
- </ul>
77
- {:else if kind === "actions"}
78
- <ul>{#each [...ui.assistant.snapshot().plans.values()].filter((p) => p.answered === "confirmed") as p (p.id)}<li>{p.title} <button type="button" onclick={() => ui.assistant.undo(p.id)}>{t("undo.all")}</button></li>{:else}<li class="g9a-note g9a-empty">{empty}</li>{/each}</ul>
79
- {:else if kind === "admin"}
80
- <form onsubmit={async (e) => { e.preventDefault(); const r = obj(await api.post("gates", { purpose, code }).catch(() => null)); token = str(r["token"]) || null; purpose = ""; code = ""; await load(); }}>
81
- <input bind:value={purpose} placeholder="purpose" aria-label="purpose" />
82
- <input bind:value={code} type="password" placeholder={t("card.code")} aria-label={t("card.code")} />
83
- <button type="submit">+</button>
84
- </form>
85
- {#if token}<p class="g9a-note"><code>{token}</code></p>{/if}
86
- <ul>{#each arr(data["gates"]).map(obj) as g (str(g["id"]))}<li data-revoked={g["revoked"] === true}>{str(g["purpose"])} · {num(g["callsToday"])} <button type="button" onclick={async () => { await api.delete("gates/" + encodeURIComponent(str(g["id"]))); await load(); }}>×</button></li>{/each}</ul>
87
- {/if}
88
- </div>
89
- {/if}
1
+ <script lang="ts" module>
2
+ export type PageKind = "history" | "abilities" | "knowledge" | "learned" | "findings" | "routines" | "actions" | "admin";
3
+ </script>
4
+
5
+ <script lang="ts">
6
+ // The assistant's pages, each from its own endpoint, read with type checks only.
7
+ import { arr, num, obj, str } from "@g9tm/aiassistant";
8
+ import { pageTexts } from "@g9tm/aiassistant/pages";
9
+ import { cls, override, useUi } from "../context.js";
10
+ import History from "./History.svelte";
11
+ import RoutineWizard from "./RoutineWizard.svelte";
12
+
13
+ let { kind, onopen = undefined }: { kind: PageKind; onopen?: ((conversationId: string) => void) | undefined } = $props();
14
+ const ui = useUi();
15
+ const t = ui.texts.t;
16
+ const api = ui.assistant.api;
17
+ let data = $state<Record<string, unknown>>({});
18
+ let error = $state<string | null>(null);
19
+ let loaded = $state(false); // an empty page says so only once its answer came
20
+ const empty = $derived(pageTexts(ui.texts).t("page." + kind + ".empty"));
21
+ let purpose = $state("");
22
+ let code = $state("");
23
+ let token = $state<string | null>(null);
24
+
25
+ const PATHS: Record<PageKind, string> = {
26
+ history: "conversations", abilities: "capabilities", knowledge: "knowledge", learned: "learned/dashboard?capability=chat",
27
+ findings: "findings", routines: "routines", actions: "conversations", admin: "gates",
28
+ };
29
+
30
+ async function load(): Promise<void> {
31
+ try {
32
+ data = obj(await api.get(new Map(Object.entries(PATHS)).get(kind) ?? ""));
33
+ error = null;
34
+ } catch (e) {
35
+ error = e instanceof Error ? e.message : "error.network";
36
+ }
37
+ loaded = true;
38
+ }
39
+ // History and the routine wizard are their own (replaceable) pages and read their own data.
40
+ const Own = $derived(kind === "history" ? override(ui, "History") ?? History : kind === "routines" ? override(ui, "RoutineWizard") ?? RoutineWizard : null);
41
+ $effect(() => { if (kind !== "history" && kind !== "routines") void load(); });
42
+ async function act(path: string, body?: unknown): Promise<void> {
43
+ await api.post(path, body).catch(() => undefined);
44
+ await load();
45
+ }
46
+ </script>
47
+
48
+ {#if Own}
49
+ <Own {onopen} />
50
+ {:else}
51
+ <div class={cls(ui, "panel.body")} data-page={kind}>
52
+ {#if error}<p class="g9a-note" role="alert">{t("error.network")}</p>{/if}
53
+ {#if kind === "abilities"}
54
+ {#each arr(data["groups"]).map(obj) as g (str(g["name"]))}
55
+ <h4>{str(g["title"], str(g["name"]))}</h4>
56
+ <ul>{#each arr(g["tools"]).map(obj) as tool (str(tool["name"]))}<li>{str(tool["title"], str(tool["name"]))}</li>{/each}</ul>
57
+ {/each}
58
+ {#each arr(data["closed"]).map(obj) as c (str(c["name"]))}<p class="g9a-note">{str(c["name"])} · {str(c["layer"])}</p>{/each}
59
+ {#if loaded && arr(data["groups"]).length === 0 && arr(data["closed"]).length === 0}<p class="g9a-note g9a-empty">{empty}</p>{/if}
60
+ {:else if kind === "knowledge"}
61
+ <ul>{#each arr(data["notes"] ?? data["items"]).map(obj) as n, i (i)}<li>{str(n["text"], str(n["name"]))}</li>{:else}{#if loaded}<li class="g9a-note g9a-empty">{empty}</li>{/if}{/each}</ul>
62
+ {:else if kind === "learned"}
63
+ <p>{Math.round(num(data["modelFreeRate"]) * 100)}% · {num(data["tokensSaved"])}</p>
64
+ <ul>{#each arr(data["items"]).map(obj) as it, i (i)}<li data-status={str(it["status"])}>{str(it["signature"])} · {str(it["status"])} · {num(it["hits"])}</li>{:else}{#if loaded}<li class="g9a-note g9a-empty">{empty}</li>{/if}{/each}</ul>
65
+ {:else if kind === "findings"}
66
+ <ul>
67
+ {#each arr(data["findings"]).map(obj) as f (str(f["id"]))}
68
+ <li>
69
+ {str(obj(f["title"])["text"], t(str(obj(f["title"])["key"])))}
70
+ <button type="button" onclick={() => act("findings/" + encodeURIComponent(str(f["id"])) + "/fixed")}>✓</button>
71
+ <button type="button" onclick={() => act("findings/" + encodeURIComponent(str(f["id"])) + "/dismiss", { reason: "—" })}>{t("no")}</button>
72
+ </li>
73
+ {:else}
74
+ {#if loaded}<li class="g9a-note g9a-empty">{empty}</li>{/if}
75
+ {/each}
76
+ </ul>
77
+ {:else if kind === "actions"}
78
+ <ul>{#each [...ui.assistant.snapshot().plans.values()].filter((p) => p.answered === "confirmed") as p (p.id)}<li>{p.title} <button type="button" onclick={() => ui.assistant.undo(p.id)}>{t("undo.all")}</button></li>{:else}<li class="g9a-note g9a-empty">{empty}</li>{/each}</ul>
79
+ {:else if kind === "admin"}
80
+ <form onsubmit={async (e) => { e.preventDefault(); const r = obj(await api.post("gates", { purpose, code }).catch(() => null)); token = str(r["token"]) || null; purpose = ""; code = ""; await load(); }}>
81
+ <input bind:value={purpose} placeholder="purpose" aria-label="purpose" />
82
+ <input bind:value={code} type="password" placeholder={t("card.code")} aria-label={t("card.code")} />
83
+ <button type="submit">+</button>
84
+ </form>
85
+ {#if token}<p class="g9a-note"><code>{token}</code></p>{/if}
86
+ <ul>{#each arr(data["gates"]).map(obj) as g (str(g["id"]))}<li data-revoked={g["revoked"] === true}>{str(g["purpose"])} · {num(g["callsToday"])} <button type="button" onclick={async () => { await api.delete("gates/" + encodeURIComponent(str(g["id"]))); await load(); }}>×</button></li>{/each}</ul>
87
+ {/if}
88
+ </div>
89
+ {/if}
@@ -1,197 +1,197 @@
1
- <script lang="ts">
2
- // The routine wizard: the routines the person may run; choosing one asks for its slots (entity slots through a
3
- // searchable picker, the rest typed and checked by the core's slotValue), then "Preview". A read-only routine answers
4
- // with its report; one that changes things returns its card, confirmed here (with the code its method asks for) and
5
- // run bound to the preview's run and hash.
6
- import { ApiError, arr, needsCode, num, obj, planView, str, type PlanView } from "@g9tm/aiassistant";
7
- import { missingSlots, pageCalls, readRoutines, slotValue, type Routine, type RoutineSlot } from "@g9tm/aiassistant/pages";
8
- import { cls, override, useUi } from "../context.js";
9
- import BlockView from "../blocks/BlockView.svelte";
10
- import PinPad from "../slots/PinPad.svelte";
11
- import SlotPicker from "./SlotPicker.svelte";
12
- import { pageTexts } from "./texts.js";
13
-
14
- // The same props as the other pages (a routine opens no conversation).
15
- let {}: { onopen?: ((conversationId: string) => void) | undefined } = $props();
16
- const ui = useUi();
17
- const texts = pageTexts(ui.texts);
18
- const t = texts.t;
19
- const api = ui.assistant.api;
20
- const Picker = $derived(override(ui, "SlotPicker") ?? SlotPicker);
21
- const Pin = $derived(override(ui, "PinPad") ?? PinPad);
22
-
23
- type Card = { plan: PlanView; routineRunId: string; hash: string };
24
- let routines = $state<Routine[]>([]);
25
- let loadFailed = $state(false);
26
- let chosen = $state<Routine | null>(null);
27
- let typed = $state<Record<string, string>>({});
28
- let picks = $state<Record<string, { id: string; label: string }>>({});
29
- let tried = $state(false);
30
- let serverMissing = $state<string[]>([]);
31
- let report = $state<unknown[] | null>(null);
32
- let card = $state<Card | null>(null);
33
- let code = $state("");
34
- let busy = $state(false);
35
- let failure = $state<string | null>(null);
36
- let triesLeft = $state<number | null>(null);
37
- let result = $state<string | null>(null);
38
-
39
- $effect(() => {
40
- pageCalls.routines(api).then((raw) => { routines = readRoutines(raw); loadFailed = false; }, () => { loadFailed = true; });
41
- });
42
-
43
- const has = (o: Record<string, unknown>, k: string): boolean => Object.prototype.hasOwnProperty.call(o, k);
44
- const textOf = (name: string): string => (has(typed, name) ? String(new Map(Object.entries(typed)).get(name) ?? "") : "");
45
- const pickOf = (name: string): { id: string; label: string } | null => new Map(Object.entries(picks)).get(name) ?? null;
46
- const valueOf = (slot: RoutineSlot): string | null => (slot.field === "pick" ? pickOf(slot.name)?.id ?? null : slotValue(slot, textOf(slot.name)));
47
- const values = $derived(Object.fromEntries((chosen?.slots ?? []).flatMap((s) => { const v = valueOf(s); return v === null ? [] : [[s.name, v]]; })) as Record<string, string>);
48
- const missing = $derived(chosen ? missingSlots(chosen.slots, values).map((s) => s.name) : []);
49
- /** A slot's state: filled, missing (shown once the person asked for the preview, or the server said so) or not right. */
50
- function stateOf(slot: RoutineSlot): "ok" | "missing" | "invalid" {
51
- if (slot.field !== "pick" && textOf(slot.name).trim().length > 0 && valueOf(slot) === null) return "invalid";
52
- if (serverMissing.includes(slot.name)) return "missing";
53
- return tried && missing.includes(slot.name) ? "missing" : "ok";
54
- }
55
- function labelOf(slot: RoutineSlot): string {
56
- const key = "slot." + slot.name;
57
- const v = t(key);
58
- return v === key ? slot.name : v;
59
- }
60
- const say = (key: string, args: Record<string, string>): string => {
61
- const text = t(key, args);
62
- return text === key ? Object.values(args).join(" ") || key : text;
63
- };
64
-
65
- function choose(r: Routine | null): void {
66
- chosen = r;
67
- typed = {};
68
- picks = {};
69
- tried = false;
70
- serverMissing = [];
71
- report = null;
72
- card = null;
73
- code = "";
74
- failure = null;
75
- triesLeft = null;
76
- result = null;
77
- }
78
-
79
- function failed(e: unknown): void {
80
- failure = e instanceof ApiError ? e.code : "error.network";
81
- const left = e instanceof ApiError ? obj(e.body)["triesLeft"] : undefined;
82
- triesLeft = typeof left === "number" ? left : null;
83
- }
84
-
85
- async function preview(): Promise<void> {
86
- tried = true;
87
- failure = null;
88
- serverMissing = [];
89
- const r0 = chosen;
90
- if (!r0 || missing.length > 0 || chosen?.slots.some((s) => stateOf(s) === "invalid")) return;
91
- busy = true;
92
- try {
93
- const r = obj(await pageCalls.preview(api, r0.id, values, ui.assistant.snapshot().conversationId ?? undefined));
94
- const state = str(r["state"]);
95
- if (state === "report") report = arr(r["blocks"]);
96
- else if (state === "missing" || !r["card"]) serverMissing = arr(r["missing"]).filter((m): m is string => typeof m === "string");
97
- else {
98
- const plan = planView(r["card"]);
99
- card = { plan, routineRunId: str(r["routineRunId"]), hash: str(r["hash"], plan.hash) };
100
- }
101
- } catch (e) {
102
- failed(e);
103
- }
104
- busy = false;
105
- }
106
-
107
- async function run(): Promise<void> {
108
- const r0 = chosen;
109
- const c = card;
110
- if (!r0 || !c) return;
111
- busy = true;
112
- failure = null;
113
- triesLeft = null;
114
- try {
115
- const r = obj(await pageCalls.run(api, r0.id, c.routineRunId, c.hash, needsCode(c.plan.method) ? code : undefined));
116
- if (r["ok"] === false) {
117
- failure = str(obj(r["error"])["code"], "routine.failed");
118
- triesLeft = typeof r["triesLeft"] === "number" ? num(r["triesLeft"]) : null;
119
- } else {
120
- result = str(r["text"]) || t("routine.done");
121
- card = null;
122
- }
123
- } catch (e) {
124
- failed(e);
125
- }
126
- code = "";
127
- busy = false;
128
- }
129
- </script>
130
-
131
- <div class={cls(ui, "panel.body") + " g9a-routines"} data-page="routines">
132
- {#if loadFailed}<p class="g9a-note" role="alert">{t("error.network")}</p>{/if}
133
- {#if !chosen}
134
- <h4>{t("routine.list")}</h4>
135
- <ul class="g9a-routines__list">
136
- {#each routines as r (r.id)}
137
- <li><button type="button" class="g9a-routines__choose" data-id={r.id} onclick={() => choose(r)}>{r.title || r.id}</button></li>
138
- {:else}
139
- <li class="g9a-note">{t("routine.empty")}</li>
140
- {/each}
141
- </ul>
142
- {:else}
143
- <div class="g9a-row"><button type="button" class="g9a-routines__back" onclick={() => choose(null)}>{t("routine.back")}</button></div>
144
- <h4>{chosen.title || chosen.id}</h4>
145
- {#if result !== null}
146
- <p class="g9a-note g9a-routines__result" role="status">{result}</p>
147
- {:else if report}
148
- <div class="g9a-routines__report">{#each report as b, i (i)}<BlockView block={b} />{/each}</div>
149
- {:else if card}
150
- {@const plan = card.plan}
151
- <div class={cls(ui, "card.approval")} data-routine-card={plan.id}>
152
- <h3>{plan.readOnly ? t("card.readonly_routine") : plan.title}</h3>
153
- {#if plan.warning}<p class="g9a-warning" role="note">{t("card.tainted")}</p>{/if}
154
- <ol>
155
- {#each plan.steps as s (s.index)}
156
- <li class={cls(ui, "card.approval.step")}>
157
- {s.text}{#if !s.undoable}<span class="g9a-irreversible"> ({t("card.irreversible")})</span>{/if}
158
- {#each s.facts as f, i (i)}<div class={cls(ui, "card.approval.fact")}>{say(f.key, f.args)}</div>{/each}
159
- {#each s.diff as d, i (i)}<div class={cls(ui, "card.approval.fact")}>{say(d.name, d.args)}: {d.before ?? "—"} ← {d.after ?? "—"}</div>{/each}
160
- </li>
161
- {/each}
162
- </ol>
163
- {#if needsCode(plan.method)}<Pin bind:value={code} label={t("card.code")} />{/if}
164
- {#if failure}
165
- <p class="g9a-note" role="alert" data-code={failure}>{failure === "confirm.waiting" ? t("card.waiting") : t("routine.failed")}{#if triesLeft !== null} · {t("card.tries_left", { count: triesLeft })}{/if}</p>
166
- {/if}
167
- <div class="g9a-row">
168
- <button type="button" class={cls(ui, "card.approval.confirm")} disabled={busy || (needsCode(plan.method) && code.length === 0)} onclick={run}>{t("card.confirm")}</button>
169
- <button type="button" class={cls(ui, "card.approval.refuse")} disabled={busy} onclick={() => { card = null; failure = null; }}>{t("card.refuse")}</button>
170
- </div>
171
- </div>
172
- {:else}
173
- <form class="g9a-routines__form" onsubmit={(e) => { e.preventDefault(); void preview(); }} novalidate>
174
- {#each chosen.slots as slot (slot.name)}
175
- {@const st = stateOf(slot)}
176
- <div class="g9a-routines__slot" data-slot={slot.name} data-field={slot.field} data-state={st}>
177
- {#if slot.field === "pick"}
178
- <span class="g9a-routines__label">{labelOf(slot)}</span>
179
- <Picker {slot} label={labelOf(slot)} picked={pickOf(slot.name)} onpick={(p: { id: string; label: string } | null) => {
180
- const next = { ...picks };
181
- if (p) next[slot.name] = p; else delete next[slot.name];
182
- picks = next;
183
- }} />
184
- {:else}
185
- <label for={"g9a-slot-" + slot.name}>{labelOf(slot)}</label>
186
- <input id={"g9a-slot-" + slot.name} value={textOf(slot.name)} inputmode={slot.field === "number" || slot.field === "money" ? "decimal" : undefined}
187
- aria-invalid={st !== "ok"} oninput={(e) => { typed = { ...typed, [slot.name]: e.currentTarget.value }; }} />
188
- {/if}
189
- {#if st !== "ok"}<span class="g9a-note" data-bad="true">{t(st === "missing" ? "routine.missing" : "routine.invalid")}</span>{/if}
190
- </div>
191
- {/each}
192
- {#if failure}<p class="g9a-note" role="alert" data-code={failure}>{t("routine.failed")}</p>{/if}
193
- <div class="g9a-row"><button type="submit" class="g9a-routines__preview" disabled={busy}>{t("routine.preview")}</button></div>
194
- </form>
195
- {/if}
196
- {/if}
197
- </div>
1
+ <script lang="ts">
2
+ // The routine wizard: the routines the person may run; choosing one asks for its slots (entity slots through a
3
+ // searchable picker, the rest typed and checked by the core's slotValue), then "Preview". A read-only routine answers
4
+ // with its report; one that changes things returns its card, confirmed here (with the code its method asks for) and
5
+ // run bound to the preview's run and hash.
6
+ import { ApiError, arr, needsCode, num, obj, planView, str, type PlanView } from "@g9tm/aiassistant";
7
+ import { missingSlots, pageCalls, readRoutines, slotValue, type Routine, type RoutineSlot } from "@g9tm/aiassistant/pages";
8
+ import { cls, override, useUi } from "../context.js";
9
+ import BlockView from "../blocks/BlockView.svelte";
10
+ import PinPad from "../slots/PinPad.svelte";
11
+ import SlotPicker from "./SlotPicker.svelte";
12
+ import { pageTexts } from "./texts.js";
13
+
14
+ // The same props as the other pages (a routine opens no conversation).
15
+ let {}: { onopen?: ((conversationId: string) => void) | undefined } = $props();
16
+ const ui = useUi();
17
+ const texts = pageTexts(ui.texts);
18
+ const t = texts.t;
19
+ const api = ui.assistant.api;
20
+ const Picker = $derived(override(ui, "SlotPicker") ?? SlotPicker);
21
+ const Pin = $derived(override(ui, "PinPad") ?? PinPad);
22
+
23
+ type Card = { plan: PlanView; routineRunId: string; hash: string };
24
+ let routines = $state<Routine[]>([]);
25
+ let loadFailed = $state(false);
26
+ let chosen = $state<Routine | null>(null);
27
+ let typed = $state<Record<string, string>>({});
28
+ let picks = $state<Record<string, { id: string; label: string }>>({});
29
+ let tried = $state(false);
30
+ let serverMissing = $state<string[]>([]);
31
+ let report = $state<unknown[] | null>(null);
32
+ let card = $state<Card | null>(null);
33
+ let code = $state("");
34
+ let busy = $state(false);
35
+ let failure = $state<string | null>(null);
36
+ let triesLeft = $state<number | null>(null);
37
+ let result = $state<string | null>(null);
38
+
39
+ $effect(() => {
40
+ pageCalls.routines(api).then((raw) => { routines = readRoutines(raw); loadFailed = false; }, () => { loadFailed = true; });
41
+ });
42
+
43
+ const has = (o: Record<string, unknown>, k: string): boolean => Object.prototype.hasOwnProperty.call(o, k);
44
+ const textOf = (name: string): string => (has(typed, name) ? String(new Map(Object.entries(typed)).get(name) ?? "") : "");
45
+ const pickOf = (name: string): { id: string; label: string } | null => new Map(Object.entries(picks)).get(name) ?? null;
46
+ const valueOf = (slot: RoutineSlot): string | null => (slot.field === "pick" ? pickOf(slot.name)?.id ?? null : slotValue(slot, textOf(slot.name)));
47
+ const values = $derived(Object.fromEntries((chosen?.slots ?? []).flatMap((s) => { const v = valueOf(s); return v === null ? [] : [[s.name, v]]; })) as Record<string, string>);
48
+ const missing = $derived(chosen ? missingSlots(chosen.slots, values).map((s) => s.name) : []);
49
+ /** A slot's state: filled, missing (shown once the person asked for the preview, or the server said so) or not right. */
50
+ function stateOf(slot: RoutineSlot): "ok" | "missing" | "invalid" {
51
+ if (slot.field !== "pick" && textOf(slot.name).trim().length > 0 && valueOf(slot) === null) return "invalid";
52
+ if (serverMissing.includes(slot.name)) return "missing";
53
+ return tried && missing.includes(slot.name) ? "missing" : "ok";
54
+ }
55
+ function labelOf(slot: RoutineSlot): string {
56
+ const key = "slot." + slot.name;
57
+ const v = t(key);
58
+ return v === key ? slot.name : v;
59
+ }
60
+ const say = (key: string, args: Record<string, string>): string => {
61
+ const text = t(key, args);
62
+ return text === key ? Object.values(args).join(" ") || key : text;
63
+ };
64
+
65
+ function choose(r: Routine | null): void {
66
+ chosen = r;
67
+ typed = {};
68
+ picks = {};
69
+ tried = false;
70
+ serverMissing = [];
71
+ report = null;
72
+ card = null;
73
+ code = "";
74
+ failure = null;
75
+ triesLeft = null;
76
+ result = null;
77
+ }
78
+
79
+ function failed(e: unknown): void {
80
+ failure = e instanceof ApiError ? e.code : "error.network";
81
+ const left = e instanceof ApiError ? obj(e.body)["triesLeft"] : undefined;
82
+ triesLeft = typeof left === "number" ? left : null;
83
+ }
84
+
85
+ async function preview(): Promise<void> {
86
+ tried = true;
87
+ failure = null;
88
+ serverMissing = [];
89
+ const r0 = chosen;
90
+ if (!r0 || missing.length > 0 || chosen?.slots.some((s) => stateOf(s) === "invalid")) return;
91
+ busy = true;
92
+ try {
93
+ const r = obj(await pageCalls.preview(api, r0.id, values, ui.assistant.snapshot().conversationId ?? undefined));
94
+ const state = str(r["state"]);
95
+ if (state === "report") report = arr(r["blocks"]);
96
+ else if (state === "missing" || !r["card"]) serverMissing = arr(r["missing"]).filter((m): m is string => typeof m === "string");
97
+ else {
98
+ const plan = planView(r["card"]);
99
+ card = { plan, routineRunId: str(r["routineRunId"]), hash: str(r["hash"], plan.hash) };
100
+ }
101
+ } catch (e) {
102
+ failed(e);
103
+ }
104
+ busy = false;
105
+ }
106
+
107
+ async function run(): Promise<void> {
108
+ const r0 = chosen;
109
+ const c = card;
110
+ if (!r0 || !c) return;
111
+ busy = true;
112
+ failure = null;
113
+ triesLeft = null;
114
+ try {
115
+ const r = obj(await pageCalls.run(api, r0.id, c.routineRunId, c.hash, needsCode(c.plan.method) ? code : undefined));
116
+ if (r["ok"] === false) {
117
+ failure = str(obj(r["error"])["code"], "routine.failed");
118
+ triesLeft = typeof r["triesLeft"] === "number" ? num(r["triesLeft"]) : null;
119
+ } else {
120
+ result = str(r["text"]) || t("routine.done");
121
+ card = null;
122
+ }
123
+ } catch (e) {
124
+ failed(e);
125
+ }
126
+ code = "";
127
+ busy = false;
128
+ }
129
+ </script>
130
+
131
+ <div class={cls(ui, "panel.body") + " g9a-routines"} data-page="routines">
132
+ {#if loadFailed}<p class="g9a-note" role="alert">{t("error.network")}</p>{/if}
133
+ {#if !chosen}
134
+ <h4>{t("routine.list")}</h4>
135
+ <ul class="g9a-routines__list">
136
+ {#each routines as r (r.id)}
137
+ <li><button type="button" class="g9a-routines__choose" data-id={r.id} onclick={() => choose(r)}>{r.title || r.id}</button></li>
138
+ {:else}
139
+ <li class="g9a-note">{t("routine.empty")}</li>
140
+ {/each}
141
+ </ul>
142
+ {:else}
143
+ <div class="g9a-row"><button type="button" class="g9a-routines__back" onclick={() => choose(null)}>{t("routine.back")}</button></div>
144
+ <h4>{chosen.title || chosen.id}</h4>
145
+ {#if result !== null}
146
+ <p class="g9a-note g9a-routines__result" role="status">{result}</p>
147
+ {:else if report}
148
+ <div class="g9a-routines__report">{#each report as b, i (i)}<BlockView block={b} />{/each}</div>
149
+ {:else if card}
150
+ {@const plan = card.plan}
151
+ <div class={cls(ui, "card.approval")} data-routine-card={plan.id}>
152
+ <h3>{plan.readOnly ? t("card.readonly_routine") : plan.title}</h3>
153
+ {#if plan.warning}<p class="g9a-warning" role="note">{t("card.tainted")}</p>{/if}
154
+ <ol>
155
+ {#each plan.steps as s (s.index)}
156
+ <li class={cls(ui, "card.approval.step")}>
157
+ {s.text}{#if !s.undoable}<span class="g9a-irreversible"> ({t("card.irreversible")})</span>{/if}
158
+ {#each s.facts as f, i (i)}<div class={cls(ui, "card.approval.fact")}>{say(f.key, f.args)}</div>{/each}
159
+ {#each s.diff as d, i (i)}<div class={cls(ui, "card.approval.fact")}>{say(d.name, d.args)}: {d.before ?? "—"} ← {d.after ?? "—"}</div>{/each}
160
+ </li>
161
+ {/each}
162
+ </ol>
163
+ {#if needsCode(plan.method)}<Pin bind:value={code} label={t("card.code")} />{/if}
164
+ {#if failure}
165
+ <p class="g9a-note" role="alert" data-code={failure}>{failure === "confirm.waiting" ? t("card.waiting") : t("routine.failed")}{#if triesLeft !== null} · {t("card.tries_left", { count: triesLeft })}{/if}</p>
166
+ {/if}
167
+ <div class="g9a-row">
168
+ <button type="button" class={cls(ui, "card.approval.confirm")} disabled={busy || (needsCode(plan.method) && code.length === 0)} onclick={run}>{t("card.confirm")}</button>
169
+ <button type="button" class={cls(ui, "card.approval.refuse")} disabled={busy} onclick={() => { card = null; failure = null; }}>{t("card.refuse")}</button>
170
+ </div>
171
+ </div>
172
+ {:else}
173
+ <form class="g9a-routines__form" onsubmit={(e) => { e.preventDefault(); void preview(); }} novalidate>
174
+ {#each chosen.slots as slot (slot.name)}
175
+ {@const st = stateOf(slot)}
176
+ <div class="g9a-routines__slot" data-slot={slot.name} data-field={slot.field} data-state={st}>
177
+ {#if slot.field === "pick"}
178
+ <span class="g9a-routines__label">{labelOf(slot)}</span>
179
+ <Picker {slot} label={labelOf(slot)} picked={pickOf(slot.name)} onpick={(p: { id: string; label: string } | null) => {
180
+ const next = { ...picks };
181
+ if (p) next[slot.name] = p; else delete next[slot.name];
182
+ picks = next;
183
+ }} />
184
+ {:else}
185
+ <label for={"g9a-slot-" + slot.name}>{labelOf(slot)}</label>
186
+ <input id={"g9a-slot-" + slot.name} value={textOf(slot.name)} inputmode={slot.field === "number" || slot.field === "money" ? "decimal" : undefined}
187
+ aria-invalid={st !== "ok"} oninput={(e) => { typed = { ...typed, [slot.name]: e.currentTarget.value }; }} />
188
+ {/if}
189
+ {#if st !== "ok"}<span class="g9a-note" data-bad="true">{t(st === "missing" ? "routine.missing" : "routine.invalid")}</span>{/if}
190
+ </div>
191
+ {/each}
192
+ {#if failure}<p class="g9a-note" role="alert" data-code={failure}>{t("routine.failed")}</p>{/if}
193
+ <div class="g9a-row"><button type="submit" class="g9a-routines__preview" disabled={busy}>{t("routine.preview")}</button></div>
194
+ </form>
195
+ {/if}
196
+ {/if}
197
+ </div>
@@ -2,7 +2,7 @@
2
2
  // One message: its text (revealed only when it arrived in front of the person), blocks, card, provenance and feedback.
3
3
  import { untrack } from "svelte";
4
4
  import type { MessageView } from "@g9tm/aiassistant";
5
- import { askAgain, chatOf, editLast, pageTexts } from "@g9tm/aiassistant/pages";
5
+ import { askAgain, chatOf, editLast, FEEDBACK_REASONS, pageTexts, rateAnswer, ratingsOf } from "@g9tm/aiassistant/pages";
6
6
  import { cls, override, useUi } from "../context.js";
7
7
  import BlockView from "../blocks/BlockView.svelte";
8
8
  import ApprovalCard from "../cards/ApprovalCard.svelte";
@@ -20,6 +20,10 @@
20
20
  const Other = $derived(override(ui, "Card") ?? Cards);
21
21
  const plan = $derived(message.card?.kind === "plan" ? plans.get(message.card.id) : undefined);
22
22
  let copied = $state(false);
23
+ // «Helpful?» (chat.feedback): the rating kept per message by the assistant, so a redraw keeps it.
24
+ const ratings = ratingsOf(ui.assistant);
25
+ let rating = $state(untrack(() => ratings.of(message.id)));
26
+ $effect(() => ratings.subscribe(() => { rating = ratings.of(message.id); }));
23
27
  </script>
24
28
 
25
29
  <div class={cls(ui, "message") + " " + cls(ui, message.role === "user" ? "message.user" : "message.assistant")} data-kind={message.kind} data-pending={message.pending}>
@@ -38,6 +42,13 @@
38
42
  {#if message.provenance === "learned"}<button type="button" data-role="feedback" onclick={() => ui.assistant.notRight(message.id)}>{t("feedback.not_right")}</button>{/if}
39
43
  {#if last && chatOf(ui.assistant).again && !message.pending}<button type="button" data-role="again" onclick={() => askAgain(ui.assistant)}>{pt("message.again")}</button><button type="button" data-role="edit" onclick={() => editLast(ui.assistant)}>{pt("message.edit")}</button>{/if}
40
44
  </div>
45
+ {#if chatOf(ui.assistant).feedback && !message.pending && message.id}
46
+ <div class={cls(ui, "message.rate")}>
47
+ {#if rating === "good" || rating === "bad"}<span>{pt("feedback.thanks")}</span>
48
+ {:else if rating === "asking"}<span>{pt("feedback.why")}</span>{#each FEEDBACK_REASONS as r (r)}<button type="button" data-role="reason" onclick={() => rateAnswer(ui.assistant, message, false, r)}>{pt("feedback.reason." + r)}</button>{/each}<button type="button" data-role="reason" onclick={() => rateAnswer(ui.assistant, message, false, null)}>{pt("feedback.skip")}</button>
49
+ {:else}<span>{pt("feedback.ask")}</span><button type="button" data-role="good" aria-label={pt("feedback.good")} onclick={() => rateAnswer(ui.assistant, message, true)}>👍</button><button type="button" data-role="bad" aria-label={pt("feedback.bad")} onclick={() => rateAnswer(ui.assistant, message, false)}>👎</button>{/if}
50
+ </div>
51
+ {/if}
41
52
  {/if}
42
53
  {/if}
43
54
  </div>
@@ -1,37 +1,37 @@
1
- <script lang="ts">
2
- // "Download PDF" of the open conversation, once it has messages: the server's signed link (ten minutes), opened by the
3
- // host. Busy while the link is asked for; a notice if it could not be made. Hidden when the host cannot open links.
4
- import { onDestroy } from "svelte";
5
- import { obj, str } from "@g9tm/aiassistant";
6
- import { useUi } from "../context.js";
7
- import { AssistantState } from "../store.svelte.js";
8
- import { pageTexts } from "../pages/texts.js";
9
-
10
- const ui = useUi();
11
- const t = pageTexts(ui.texts).t;
12
- const live = new AssistantState(ui.assistant);
13
- onDestroy(() => live.dispose());
14
- const id = $derived(live.current.conversationId);
15
- const shown = $derived(id !== null && live.current.messages.length > 0 && typeof ui.assistant.host.openUrl === "function");
16
- let busy = $state(false);
17
- let failed = $state(false);
18
-
19
- async function download(): Promise<void> {
20
- if (!id || busy) return;
21
- busy = true;
22
- failed = false;
23
- try {
24
- const url = str(obj(await ui.assistant.api.documentLink(id))["url"]);
25
- if (!/^(https:\/\/|\/(?!\/))/u.test(url)) throw new Error("no link"); // the server's own path or https only
26
- ui.assistant.host.openUrl?.(url);
27
- } catch {
28
- failed = true;
29
- }
30
- busy = false;
31
- }
32
- </script>
33
-
34
- {#if shown}
35
- <button type="button" class="g9a-pdf" aria-busy={busy} disabled={busy} onclick={download}>{busy ? t("pdf.busy") : t("pdf.download")}</button>
36
- {#if failed}<span class="g9a-note g9a-pdf__failed" role="alert">{t("pdf.failed")}</span>{/if}
37
- {/if}
1
+ <script lang="ts">
2
+ // "Download PDF" of the open conversation, once it has messages: the server's signed link (ten minutes), opened by the
3
+ // host. Busy while the link is asked for; a notice if it could not be made. Hidden when the host cannot open links.
4
+ import { onDestroy } from "svelte";
5
+ import { obj, str } from "@g9tm/aiassistant";
6
+ import { useUi } from "../context.js";
7
+ import { AssistantState } from "../store.svelte.js";
8
+ import { pageTexts } from "../pages/texts.js";
9
+
10
+ const ui = useUi();
11
+ const t = pageTexts(ui.texts).t;
12
+ const live = new AssistantState(ui.assistant);
13
+ onDestroy(() => live.dispose());
14
+ const id = $derived(live.current.conversationId);
15
+ const shown = $derived(id !== null && live.current.messages.length > 0 && typeof ui.assistant.host.openUrl === "function");
16
+ let busy = $state(false);
17
+ let failed = $state(false);
18
+
19
+ async function download(): Promise<void> {
20
+ if (!id || busy) return;
21
+ busy = true;
22
+ failed = false;
23
+ try {
24
+ const url = str(obj(await ui.assistant.api.documentLink(id))["url"]);
25
+ if (!/^(https:\/\/|\/(?!\/))/u.test(url)) throw new Error("no link"); // the server's own path or https only
26
+ ui.assistant.host.openUrl?.(url);
27
+ } catch {
28
+ failed = true;
29
+ }
30
+ busy = false;
31
+ }
32
+ </script>
33
+
34
+ {#if shown}
35
+ <button type="button" class="g9a-pdf" aria-busy={busy} disabled={busy} onclick={download}>{busy ? t("pdf.busy") : t("pdf.download")}</button>
36
+ {#if failed}<span class="g9a-note g9a-pdf__failed" role="alert">{t("pdf.failed")}</span>{/if}
37
+ {/if}
@@ -1,52 +1,52 @@
1
- <script lang="ts">
2
- // The panel in six layouts (sheet, side, fullscreen, inline, card, compact) or "auto" by the container's width; the
3
- // layout can change live without losing the conversation. Escape closes; Alt+A (by key position, so it works with a
4
- // Persian keyboard) toggles. Dialogs inside sit above the panel.
5
- import type { Snippet } from "svelte";
6
- import { pickLayout, type Layout, type LayoutThresholds } from "@g9tm/aiassistant";
7
- import { cls, override, sty, useUi } from "../context.js";
8
- import PdfButton from "../parts/PdfButton.svelte";
9
- import AssistantChat from "./AssistantChat.svelte";
10
-
11
- let { open = $bindable(true), layout = "auto", thresholds = undefined, title = undefined, header = undefined, onclose = undefined }: {
12
- open?: boolean; layout?: Layout; thresholds?: LayoutThresholds | undefined; title?: string | undefined; header?: Snippet | undefined; onclose?: (() => void) | undefined;
13
- } = $props();
14
- const ui = useUi();
15
- const t = ui.texts.t;
16
- let width = $state(1024);
17
- let opener: Element | null = null;
18
- const current = $derived(pickLayout(layout, width, thresholds));
19
- const Pdf = $derived(override(ui, "PdfButton") ?? PdfButton);
20
-
21
- function close(): void {
22
- open = false;
23
- onclose?.();
24
- if (opener instanceof HTMLElement) opener.focus(); // focus goes back to what opened it
25
- }
26
-
27
- function onkey(e: KeyboardEvent): void {
28
- if (e.altKey && e.code === "KeyA") {
29
- e.preventDefault();
30
- if (!open) opener = document.activeElement;
31
- open = !open;
32
- } else if (e.key === "Escape" && open && current !== "inline" && current !== "card") close();
33
- }
34
- </script>
35
-
36
- <svelte:window onkeydown={onkey} />
37
-
38
- <div class="g9a-measure" bind:clientWidth={width}></div>
39
- {#if open || current === "inline" || current === "card"}
40
- <section class={cls(ui, "panel")} style={sty(ui, "panel") ?? ""} data-layout={current} role={current === "sheet" || current === "fullscreen" ? "dialog" : "region"}
41
- aria-label={title ?? t("assistant.name")} style:z-index={current === "inline" || current === "card" ? undefined : ui.layer - 1}>
42
- {#if current !== "compact"}
43
- <header class={cls(ui, "panel.header")}>
44
- {#if header}{@render header()}{:else}<strong>{title ?? t("assistant.name")}</strong>{/if}
45
- <button type="button" onclick={() => ui.assistant.fresh()}>{t("panel.new")}</button>
46
- <Pdf />
47
- {#if current !== "inline" && current !== "card"}<button type="button" aria-label={t("panel.close")} onclick={close}>×</button>{/if}
48
- </header>
49
- {/if}
50
- <div class={cls(ui, "panel.body")}><AssistantChat /></div>
51
- </section>
52
- {/if}
1
+ <script lang="ts">
2
+ // The panel in six layouts (sheet, side, fullscreen, inline, card, compact) or "auto" by the container's width; the
3
+ // layout can change live without losing the conversation. Escape closes; Alt+A (by key position, so it works with a
4
+ // Persian keyboard) toggles. Dialogs inside sit above the panel.
5
+ import type { Snippet } from "svelte";
6
+ import { pickLayout, type Layout, type LayoutThresholds } from "@g9tm/aiassistant";
7
+ import { cls, override, sty, useUi } from "../context.js";
8
+ import PdfButton from "../parts/PdfButton.svelte";
9
+ import AssistantChat from "./AssistantChat.svelte";
10
+
11
+ let { open = $bindable(true), layout = "auto", thresholds = undefined, title = undefined, header = undefined, onclose = undefined }: {
12
+ open?: boolean; layout?: Layout; thresholds?: LayoutThresholds | undefined; title?: string | undefined; header?: Snippet | undefined; onclose?: (() => void) | undefined;
13
+ } = $props();
14
+ const ui = useUi();
15
+ const t = ui.texts.t;
16
+ let width = $state(1024);
17
+ let opener: Element | null = null;
18
+ const current = $derived(pickLayout(layout, width, thresholds));
19
+ const Pdf = $derived(override(ui, "PdfButton") ?? PdfButton);
20
+
21
+ function close(): void {
22
+ open = false;
23
+ onclose?.();
24
+ if (opener instanceof HTMLElement) opener.focus(); // focus goes back to what opened it
25
+ }
26
+
27
+ function onkey(e: KeyboardEvent): void {
28
+ if (e.altKey && e.code === "KeyA") {
29
+ e.preventDefault();
30
+ if (!open) opener = document.activeElement;
31
+ open = !open;
32
+ } else if (e.key === "Escape" && open && current !== "inline" && current !== "card") close();
33
+ }
34
+ </script>
35
+
36
+ <svelte:window onkeydown={onkey} />
37
+
38
+ <div class="g9a-measure" bind:clientWidth={width}></div>
39
+ {#if open || current === "inline" || current === "card"}
40
+ <section class={cls(ui, "panel")} style={sty(ui, "panel") ?? ""} data-layout={current} role={current === "sheet" || current === "fullscreen" ? "dialog" : "region"}
41
+ aria-label={title ?? t("assistant.name")} style:z-index={current === "inline" || current === "card" ? undefined : ui.layer - 1}>
42
+ {#if current !== "compact"}
43
+ <header class={cls(ui, "panel.header")}>
44
+ {#if header}{@render header()}{:else}<strong>{title ?? t("assistant.name")}</strong>{/if}
45
+ <button type="button" onclick={() => ui.assistant.fresh()}>{t("panel.new")}</button>
46
+ <Pdf />
47
+ {#if current !== "inline" && current !== "card"}<button type="button" aria-label={t("panel.close")} onclick={close}>×</button>{/if}
48
+ </header>
49
+ {/if}
50
+ <div class={cls(ui, "panel.body")}><AssistantChat /></div>
51
+ </section>
52
+ {/if}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@g9tm/aiassistant-svelte",
3
- "version": "1.9.0",
3
+ "version": "1.9.2",
4
4
  "description": "Svelte 5 components for the G9 AI assistant, fully customisable (layouts, tokens, per-part classes, overrides, parts).",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -31,7 +31,7 @@
31
31
  "access": "public"
32
32
  },
33
33
  "dependencies": {
34
- "@g9tm/aiassistant": "1.9.0"
34
+ "@g9tm/aiassistant": "1.9.2"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@sveltejs/package": "2.5.8",