@g9tm/aiassistant-react 1.8.2 → 1.9.0

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.
package/dist/blocks.d.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import type { ReactNode } from "react";
6
6
  import type { BlockView as BlockViewModel } from "@g9tm/aiassistant";
7
+ import type { TourView } from "@g9tm/aiassistant/pages";
7
8
  import type { Part } from "./context.js";
8
9
  /** The model's text as safe tokens: paragraphs, lists, bold, code, links (https on the host's hosts only). Never HTML. */
9
10
  export declare function TextView(props: {
@@ -30,7 +31,16 @@ export type ChartView = Extract<BlockViewModel, {
30
31
  export declare const Chart: Part<{
31
32
  view: ChartView;
32
33
  }>;
34
+ /**
35
+ * A tour: its steps as a numbered list with «show me step by step»; once started, one step at a time with back and
36
+ * next, each opening its page and lighting its control through the host. Replaceable as `TourCard`.
37
+ */
38
+ export declare const TourCard: Part<{
39
+ view: TourView;
40
+ at: string;
41
+ }>;
33
42
  export declare function BlockView(props: {
34
43
  block: unknown;
35
44
  compact?: boolean;
45
+ at?: string;
36
46
  }): ReactNode;
package/dist/blocks.js CHANGED
@@ -3,9 +3,9 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
3
3
  * Every block type from the core's view model, and the safe text view. The host may replace any block type (its x:*
4
4
  * blocks too) through `components.Block`; a block no renderer knows shows its fallback text, never an error or a hole.
5
5
  */
6
- import { useState } from "react";
6
+ import { useEffect, useState } from "react";
7
7
  import { blockView, can, formatNumber, item, obj, parseText, shares } from "@g9tm/aiassistant";
8
- import { pageTexts, saveCsv } from "@g9tm/aiassistant/pages";
8
+ import { chatOf, guideBlock, guideOf, openPage, pageTexts, saveCsv, tableText } from "@g9tm/aiassistant/pages";
9
9
  import { blockOverride, cls, swappable, useUi } from "./context.js";
10
10
  /** The model's text as safe tokens: paragraphs, lists, bold, code, links (https on the host's hosts only). Never HTML. */
11
11
  export function TextView(props) {
@@ -72,14 +72,44 @@ export const Chart = swappable("Chart", (props) => {
72
72
  });
73
73
  /** Only the server's own files. */
74
74
  const fileUrl = (id) => "/api/assistant/files/" + encodeURIComponent(id);
75
+ /**
76
+ * A tour: its steps as a numbered list with «show me step by step»; once started, one step at a time with back and
77
+ * next, each opening its page and lighting its control through the host. Replaceable as `TourCard`.
78
+ */
79
+ export const TourCard = swappable("TourCard", (props) => {
80
+ const ui = useUi();
81
+ const t = pageTexts(ui.texts).t;
82
+ const guide = guideOf(ui.assistant);
83
+ const [now, setNow] = useState(guide.tour);
84
+ useEffect(() => guide.subscribe(setNow), [guide]);
85
+ const v = props.view;
86
+ const tour = now && now.key === props.at ? now : null;
87
+ const step = tour ? item(tour.steps, tour.index) : undefined;
88
+ return (_jsxs("div", { className: cls(ui, "block.tour"), children: [v.title ? _jsx("div", { className: "g9a-block-title", children: v.title }) : null, tour && step && !tour.done ? (_jsxs("div", { className: cls(ui, "block.tour.step"), children: [_jsx("div", { className: "g9a-note", children: t("tour.step", { n: tour.index + 1, count: tour.steps.length }) }), _jsx("div", { children: step.text }), _jsxs("div", { className: "g9a-tour-nav", children: [tour.index > 0 ? _jsx("button", { type: "button", "data-role": "tour", onClick: () => guide.back(), children: t("tour.back") }) : null, _jsx("button", { type: "button", "data-role": "tour", className: "g9a-primary", onClick: () => guide.next(), children: tour.index < tour.steps.length - 1 ? t("tour.next") : t("tour.done") })] })] })) : (_jsxs(_Fragment, { children: [_jsx("ol", { className: "g9a-list", "data-done": tour?.done === true, children: v.steps.map((x, i) => _jsx("li", { children: x.text }, i)) }), ui.assistant.host.navigate && v.steps.some((x) => x.page) ? _jsx("button", { type: "button", "data-role": "tour", onClick: () => guide.start(props.at, v), children: t("tour.start") }) : null] }))] }));
89
+ });
75
90
  export function BlockView(props) {
76
91
  const ui = useUi();
77
92
  const t = ui.texts.t;
78
93
  const v = blockView(props.block, ui.texts.locale, ui.assistant.customBlocks);
79
94
  const [open, setOpen] = useState(false);
80
- const Own = blockOverride(ui, v.type === "custom" ? v.name : v.type);
95
+ const g = guideBlock(props.block);
96
+ const Own = blockOverride(ui, g ? g.type : v.type === "custom" ? v.name : v.type);
81
97
  if (Own)
82
- return _jsx(Own, { view: v, block: props.block, compact: props.compact ?? false });
98
+ return _jsx(Own, { view: g ?? v, block: props.block, compact: props.compact ?? false });
99
+ if (g?.type === "tour")
100
+ return _jsx(TourCard, { view: g, at: props.at ?? "tour" });
101
+ if (g?.type === "draft") {
102
+ const host = ui.assistant.host;
103
+ return (_jsx("div", { className: cls(ui, "block.draft"), children: host.openDraft
104
+ ? _jsx("button", { type: "button", className: cls(ui, "block.action"), "data-role": "draft", onClick: () => host.openDraft?.({ kind: g.kind, values: g.values, ...(g.page ? { page: g.page } : {}), ...(g.subject ? { subject: g.subject } : {}), ...(g.label ? { label: g.label } : {}) }), children: g.label ?? pageTexts(ui.texts).t("draft.open") })
105
+ : (g.label ?? g.fallbackText) }));
106
+ }
107
+ if (g?.type === "entities") {
108
+ const openEntity = ui.assistant.host.openEntity;
109
+ if (!openEntity || g.items.length === 0)
110
+ return null;
111
+ return _jsx("div", { className: cls(ui, "block.entities"), children: g.items.map((e) => _jsx("button", { type: "button", "data-role": "entity", onClick: () => openEntity.call(ui.assistant.host, e), children: e.text }, e.kind + ":" + e.id)) });
112
+ }
83
113
  switch (v.type) {
84
114
  case "text": return _jsx("div", { className: cls(ui, "block.text"), children: _jsx(TextView, { text: v.text }) });
85
115
  case "callout": return _jsx("div", { className: cls(ui, "block.callout"), "data-tone": v.tone, children: _jsx(TextView, { text: v.text }) });
@@ -89,7 +119,7 @@ export function BlockView(props) {
89
119
  const rows = v.rows.slice(0, open ? v.rows.length : v.shown);
90
120
  return (_jsxs(_Fragment, { children: [_jsxs("div", { className: cls(ui, "block.table"), children: [v.title ? _jsx("div", { className: "g9a-block-title", children: v.title }) : null, v.asCards || props.compact
91
121
  ? rows.map((row, r) => (_jsx("dl", { className: cls(ui, "block.table.card"), children: v.columns.map((c, i) => [_jsx("dt", { children: c.label }, c.name + ":t"), _jsx("dd", { "data-kind": c.kind, children: item(row, i) }, c.name + ":d")]) }, r)))
92
- : (_jsxs("table", { children: [_jsx("thead", { children: _jsx("tr", { children: v.columns.map((c) => _jsx("th", { "data-kind": c.kind, children: c.label }, c.name)) }) }), _jsx("tbody", { children: rows.map((row, r) => _jsx("tr", { children: row.map((x, i) => _jsx("td", { "data-kind": item(v.columns, i)?.kind, children: x }, i)) }, r)) })] })), v.more > 0 && !open ? _jsx("button", { type: "button", className: "g9a-more", onClick: () => setOpen(true), children: t("block.more_rows", { count: v.more }) }) : null] }), raw.type === "export" ? _jsx(CsvButton, { title: v.title, labels: raw.columns.map((c) => c.label), rows: raw.rows }) : null] }));
122
+ : (_jsxs("table", { children: [_jsx("thead", { children: _jsx("tr", { children: v.columns.map((c) => _jsx("th", { "data-kind": c.kind, children: c.label }, c.name)) }) }), _jsx("tbody", { children: rows.map((row, r) => _jsx("tr", { children: row.map((x, i) => _jsx("td", { "data-kind": item(v.columns, i)?.kind, children: x }, i)) }, r)) })] })), v.more > 0 && !open ? _jsx("button", { type: "button", className: "g9a-more", onClick: () => setOpen(true), children: t("block.more_rows", { count: v.more }) }) : null] }), raw.type === "export" ? _jsx(CsvButton, { title: v.title, labels: raw.columns.map((c) => c.label), rows: raw.rows }) : null, chatOf(ui.assistant).copyParts && ui.assistant.host.copy ? _jsx("button", { type: "button", className: "g9a-copy", "data-role": "copy", onClick: () => void ui.assistant.host.copy?.(tableText(v.columns.map((c) => c.label), v.rows)), children: pageTexts(ui.texts).t("copy.table") }) : null] }));
93
123
  }
94
124
  case "export":
95
125
  return (_jsxs("div", { className: cls(ui, "block") + " g9a-block__export", children: [v.title ? _jsx("div", { className: "g9a-block-title", children: v.title }) : null, can(ui.assistant.host, "save") ? _jsx(CsvButton, { title: v.title, labels: v.columns.map((c) => c.label), rows: v.rows }) : _jsx("div", { children: v.fallbackText })] }));
@@ -98,14 +128,15 @@ export function BlockView(props) {
98
128
  case "kpi": return _jsx("div", { className: cls(ui, "block.kpi"), children: v.items.map((k, i) => _jsxs("div", { children: [_jsx("span", { children: k.label }), _jsx("strong", { children: k.value })] }, i)) });
99
129
  case "steps": return _jsx("ol", { className: cls(ui, "block.steps"), children: v.items.map((s, i) => _jsx("li", { "data-state": s.state, children: s.text }, i)) });
100
130
  case "actions":
101
- return (_jsx("div", { className: cls(ui, "block.actions"), children: v.items.map((a, i) => (_jsxs("button", { type: "button", className: cls(ui, "block.action"), onClick: () => void ui.assistant.send(a.send), children: [a.label, a.suggested ? _jsx("span", { className: "g9a-suggested", children: t("block.suggested") }) : null] }, i))) }));
131
+ return (_jsx("div", { className: cls(ui, "block.actions"), children: v.items.map((a, i) => (_jsxs("button", { type: "button", className: cls(ui, "block.action"), "data-role": "action", onClick: () => void ui.assistant.send(a.send), children: [a.label, a.suggested ? _jsx("span", { className: "g9a-suggested", children: t("block.suggested") }) : null] }, i))) }));
102
132
  case "flow": return _jsx("div", { className: cls(ui, "block.flow"), children: v.line });
103
133
  case "image": return _jsx("div", { className: cls(ui, "block.image"), children: v.fileIds.map((id) => _jsx("img", { src: fileUrl(id), alt: v.fallbackText, loading: "lazy" }, id)) });
104
134
  case "open": {
105
- const navigate = ui.assistant.host.navigate;
106
- if (!navigate)
107
- return _jsx("div", { className: cls(ui, "block.fallback"), children: v.fallbackText });
108
- return _jsx("button", { type: "button", className: cls(ui, "block.open"), onClick: () => navigate(v.pageId), children: ui.assistant.host.pageName?.(v.pageId) ?? v.fallbackText });
135
+ const host = ui.assistant.host;
136
+ const name = v.label ?? host.pageName?.(v.pageId) ?? v.fallbackText;
137
+ if (!host.navigate)
138
+ return _jsx("div", { className: cls(ui, "block.fallback"), children: name });
139
+ return _jsx("button", { type: "button", className: cls(ui, "block.open"), "data-role": v.target ? "show" : "open", onClick: () => { openPage(host, v); }, children: (v.target ? pageTexts(ui.texts).t("guide.show") : pageTexts(ui.texts).t("guide.open")) + ": " + name });
109
140
  }
110
141
  default: return _jsx("div", { className: cls(ui, "block.fallback"), children: v.fallbackText });
111
142
  }
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { AssistantRoot, AssistantChat, AssistantPanel, MessageList, Surfaces } f
3
3
  export type { AssistantPanelProps, AssistantRootProps, SurfaceKind, SurfaceProps } from "./surfaces.js";
4
4
  export { Composer, Message, ModelPicker, PdfButton, RevealText, Small, StagesThinking, ThinkingOrb, WorkCard } from "./parts.js";
5
5
  export type { ComposerProps, SmallKind } from "./parts.js";
6
- export { BlockView, Chart, CsvButton, TextView } from "./blocks.js";
6
+ export { BlockView, Chart, CsvButton, TextView, TourCard } from "./blocks.js";
7
7
  export type { ChartView, CsvButtonProps } from "./blocks.js";
8
8
  export { ApprovalCard, Cards } from "./cards.js";
9
9
  export { Dialog, PinPad, SecretField } from "./slots.js";
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /** @g9tm/aiassistant-react: React DOM components of the G9 AI assistant, customisable in five layers like the Svelte ones. */
2
2
  export { AssistantRoot, AssistantChat, AssistantPanel, MessageList, Surfaces } from "./surfaces.js";
3
3
  export { Composer, Message, ModelPicker, PdfButton, RevealText, Small, StagesThinking, ThinkingOrb, WorkCard } from "./parts.js";
4
- export { BlockView, Chart, CsvButton, TextView } from "./blocks.js";
4
+ export { BlockView, Chart, CsvButton, TextView, TourCard } from "./blocks.js";
5
5
  export { ApprovalCard, Cards } from "./cards.js";
6
6
  export { Dialog, PinPad, SecretField } from "./slots.js";
7
7
  export { Abilities, ActionsPage, FindingsPage, History, KnowledgePage, LearnedPage, Page, RoutineWizard, SlotPicker } from "./pages.js";
package/dist/parts.d.ts CHANGED
@@ -36,6 +36,7 @@ export declare function Message(props: {
36
36
  message: MessageView;
37
37
  plans: ReadonlyMap<string, PlanView>;
38
38
  runId: string | null;
39
+ last?: boolean;
39
40
  }): ReactNode;
40
41
  export interface ComposerProps {
41
42
  busy: boolean;
package/dist/parts.js CHANGED
@@ -5,7 +5,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
5
5
  */
6
6
  import { useEffect, useRef, useState } from "react";
7
7
  import { can, finished, LONG_RUNNING_MS, obj, REVEAL_MS, str, visibleText, windowView } from "@g9tm/aiassistant";
8
- import { pageCalls, pageTexts, readModels } from "@g9tm/aiassistant/pages";
8
+ import { askAgain, atWord, chatOf, composerOf, editLast, matchQuick, pageCalls, pageTexts, pickRefs, putPick, readModels, refsIn, slashQuery, statusOf } from "@g9tm/aiassistant/pages";
9
9
  import { BlockView, TextView } from "./blocks.js";
10
10
  import { ApprovalCard, Cards } from "./cards.js";
11
11
  import { cls, override, sty, swappable, useSnapshot, useUi } from "./context.js";
@@ -80,7 +80,7 @@ export function WorkCard(props) {
80
80
  const seconds = Math.max(0, Math.round((now - started) / 1000));
81
81
  const long = r.longRunning || now - started >= LONG_RUNNING_MS;
82
82
  const label = (s) => (s.id === "role" ? t("stage.role", { role: s.role ?? "" }) : t("stage." + s.id));
83
- return (_jsxs("div", { className: cls(ui, "work"), role: "status", children: [_jsx(ThinkingOrb, {}), _jsxs("div", { className: "g9a-work-main", children: [_jsxs("div", { className: "g9a-work-head", children: [_jsx("strong", { children: long ? t("work.long") : t("work.title") }), _jsx("span", { className: cls(ui, "work.elapsed"), children: t("work.elapsed", { seconds }) })] }), _jsx("div", { className: "g9a-stages", children: r.stages.filter((s) => s.id !== "waiting").map((s, i) => _jsx("span", { className: cls(ui, "work.stage"), "data-state": s.state, children: label(s) }, i)) }), r.progress ? _jsx("div", { className: cls(ui, "work.progress"), children: t(r.progress.key, r.progress.args) }) : null, r.tools.slice(-3).map((x, i) => _jsx("div", { className: cls(ui, "work.tool"), "data-state": x.state, children: t(x.title.key) === x.title.key ? x.name : t(x.title.key) }, i)), r.streamingText ? _jsx("div", { className: "g9a-stream", children: r.streamingText }) : null] }), _jsx("button", { type: "button", className: cls(ui, "composer.stop"), onClick: () => void ui.assistant.stop(), children: t("composer.stop") })] }));
83
+ return (_jsxs("div", { className: cls(ui, "work"), role: "status", children: [_jsx(ThinkingOrb, {}), _jsxs("div", { className: "g9a-work-main", children: [_jsxs("div", { className: "g9a-work-head", children: [_jsx("strong", { children: long ? t("work.long") : t("work.title") }), _jsx("span", { className: cls(ui, "work.elapsed"), children: t("work.elapsed", { seconds }) })] }), chatOf(ui.assistant).status && statusOf(r) ? _jsx("div", { className: cls(ui, "work.status"), children: pageTexts(ui.texts).t("work.status", { what: t(statusOf(r)?.key ?? "", statusOf(r)?.args) }) }) : null, _jsx("div", { className: "g9a-stages", children: r.stages.filter((s) => s.id !== "waiting").map((s, i) => _jsx("span", { className: cls(ui, "work.stage"), "data-state": s.state, children: label(s) }, i)) }), r.progress ? _jsx("div", { className: cls(ui, "work.progress"), children: t(r.progress.key, r.progress.args) }) : null, r.tools.slice(-3).map((x, i) => _jsx("div", { className: cls(ui, "work.tool"), "data-state": x.state, children: t(x.title.key) === x.title.key ? x.name : t(x.title.key) }, i)), r.streamingText ? _jsx("div", { className: "g9a-stream", children: r.streamingText }) : null] }), _jsx("button", { type: "button", className: cls(ui, "composer.stop"), onClick: () => void ui.assistant.stop(), children: t("composer.stop") })] }));
84
84
  }
85
85
  /** One message: its text (revealed only when it arrived in front of the person), blocks, card, provenance and feedback. */
86
86
  export function Message(props) {
@@ -93,7 +93,7 @@ export function Message(props) {
93
93
  const Approval = override(ui, "ApprovalCard") ?? ApprovalCard;
94
94
  const Other = override(ui, "Card") ?? Cards;
95
95
  const plan = m.card?.kind === "plan" ? props.plans.get(m.card.id) : undefined;
96
- return (_jsx("div", { className: cls(ui, "message") + " " + cls(ui, m.role === "user" ? "message.user" : "message.assistant"), "data-kind": m.kind, "data-pending": m.pending, children: m.card ? (plan ? _jsx(Approval, { plan: plan }) : m.card.kind !== "plan" ? _jsx(Other, { card: m.card, runId: props.runId }) : null) : (_jsxs(_Fragment, { children: [m.text.length > 0 ? _jsx("div", { className: cls(ui, "message.text"), children: _jsx(RevealText, { text: m.text, reveal: reveal }) }) : null, m.blocks.map((b, i) => _jsx(BlockView, { block: b }, i)), m.next.length > 0 ? _jsx("div", { className: cls(ui, "block.actions"), children: m.next.map((n) => _jsx("button", { type: "button", className: cls(ui, "block.action"), onClick: () => void ui.assistant.send(n), children: n }, n)) }) : null, m.role === "assistant" ? (_jsxs("div", { className: cls(ui, "message.feedback"), children: [_jsx(Small, { kind: "provenance", provenance: m.provenance }), ui.assistant.host.copy ? _jsx("button", { type: "button", onClick: () => { void ui.assistant.host.copy?.(m.text); setCopied(true); }, children: copied ? "✓" : t("feedback.copy") }) : null, m.provenance === "learned" ? _jsx("button", { type: "button", onClick: () => void ui.assistant.notRight(m.id), children: t("feedback.not_right") }) : null] })) : null] })) }));
96
+ return (_jsx("div", { className: cls(ui, "message") + " " + cls(ui, m.role === "user" ? "message.user" : "message.assistant"), "data-kind": m.kind, "data-pending": m.pending, children: m.card ? (plan ? _jsx(Approval, { plan: plan }) : m.card.kind !== "plan" ? _jsx(Other, { card: m.card, runId: props.runId }) : null) : (_jsxs(_Fragment, { children: [m.text.length > 0 ? _jsx("div", { className: cls(ui, "message.text"), children: _jsx(RevealText, { text: m.text, reveal: reveal }) }) : null, m.blocks.map((b, i) => _jsx(BlockView, { block: b, at: m.id + ":" + String(i) }, i)), m.next.length > 0 ? _jsx("div", { className: cls(ui, "block.actions"), children: m.next.map((n) => _jsx("button", { type: "button", className: cls(ui, "block.action"), "data-role": "next", onClick: () => void ui.assistant.send(n), children: n }, n)) }) : null, m.role === "assistant" ? (_jsxs("div", { className: cls(ui, "message.feedback"), children: [_jsx(Small, { kind: "provenance", provenance: m.provenance }), ui.assistant.host.copy ? _jsx("button", { type: "button", "data-role": "copy", onClick: () => { void ui.assistant.host.copy?.(m.text); setCopied(true); }, children: copied ? "✓" : t("feedback.copy") }) : null, m.provenance === "learned" ? _jsx("button", { type: "button", "data-role": "feedback", onClick: () => void ui.assistant.notRight(m.id), children: t("feedback.not_right") }) : null, props.last && chatOf(ui.assistant).again && !m.pending ? _jsxs(_Fragment, { children: [_jsx("button", { type: "button", "data-role": "again", onClick: () => void askAgain(ui.assistant), children: pageTexts(ui.texts).t("message.again") }), _jsx("button", { type: "button", "data-role": "edit", onClick: () => editLast(ui.assistant), children: pageTexts(ui.texts).t("message.edit") })] }) : null] })) : null] })) }));
97
97
  }
98
98
  /** The composer: input, attach (only when the host can pick a file), mic (only when the host or the server can dictate), send or stop. */
99
99
  export function Composer(props) {
@@ -102,6 +102,39 @@ export function Composer(props) {
102
102
  const host = ui.assistant.host;
103
103
  const live = ui.assistant.stateWatch;
104
104
  const [text, setText] = useState("");
105
+ const [refs, setRefs] = useState([]);
106
+ const [quick, setQuick] = useState([]);
107
+ const [found, setFound] = useState([]);
108
+ const chat = chatOf(ui.assistant);
109
+ useEffect(() => composerOf(ui.assistant).subscribe((c) => { setText(c.text); input.current?.focus(); }), [ui.assistant]);
110
+ // The field grows with its text up to chat.maxLines (one line, as before, unless the host asks for more).
111
+ useEffect(() => {
112
+ const el = input.current;
113
+ if (!el || chat.maxLines <= 1)
114
+ return;
115
+ el.style.height = "auto";
116
+ const line = parseFloat(getComputedStyle(el).lineHeight) || 20;
117
+ el.style.height = String(Math.min(el.scrollHeight, line * chat.maxLines + 16)) + "px";
118
+ }, [text]);
119
+ const slash = host.quickRequests ? slashQuery(text) : null;
120
+ useEffect(() => {
121
+ if (slash === null) {
122
+ setQuick([]);
123
+ return;
124
+ }
125
+ void Promise.resolve(host.quickRequests?.() ?? []).then((all) => setQuick(matchQuick(all, slash)));
126
+ }, [slash]);
127
+ const word = host.pickKinds && host.pickKinds.length > 0 ? atWord(text) : null;
128
+ useEffect(() => {
129
+ if (word === null) {
130
+ setFound([]);
131
+ return undefined;
132
+ }
133
+ let alive = true;
134
+ void Promise.all((host.pickKinds ?? []).map((k) => pickRefs(ui.assistant.api, k, word))).then((xs) => { if (alive)
135
+ setFound(xs.flat().slice(0, 8)); });
136
+ return () => { alive = false; };
137
+ }, [word]);
105
138
  const [voice, setVoice] = useState(live.state.voice);
106
139
  const [recording, setRecording] = useState(null);
107
140
  const input = useRef(null);
@@ -113,8 +146,15 @@ export function Composer(props) {
113
146
  await ui.assistant.stop();
114
147
  return;
115
148
  }
116
- if ((await ui.assistant.ask(text)) !== "refused")
149
+ if ((await ui.assistant.ask(text, undefined, refsIn(text, refs))) !== "refused") {
117
150
  setText("");
151
+ setRefs([]);
152
+ }
153
+ };
154
+ const pickOne = (r) => {
155
+ setRefs([...refs.filter((x) => x.kind !== r.kind || x.id !== r.id), r]);
156
+ setText(putPick(text, r));
157
+ input.current?.focus();
118
158
  };
119
159
  const dictate = async () => { const said = await host.dictate?.(); if (said)
120
160
  add(said); };
@@ -134,7 +174,7 @@ export function Composer(props) {
134
174
  const stop = (await host.record?.().catch(() => null)) ?? null;
135
175
  setRecording(() => stop);
136
176
  };
137
- return (_jsxs("form", { className: cls(ui, "composer"), style: sty(ui, "composer"), onSubmit: (e) => { e.preventDefault(); void send(); }, children: [props.attachments.length > 0 ? (_jsx("div", { className: cls(ui, "file-chips"), children: props.attachments.map((a) => _jsxs("span", { className: cls(ui, "file-chip"), children: [a.name, _jsx("button", { type: "button", "aria-label": t("files.remove"), onClick: () => ui.assistant.detach(a.id), children: "\u00D7" })] }, a.id)) })) : null, _jsxs("div", { className: "g9a-composer-row", children: [can(host, "attach") ? _jsx("button", { type: "button", className: cls(ui, "composer.attach"), "aria-label": t("composer.attach"), onClick: () => void ui.assistant.attachFromDevice(), children: "\uD83D\uDCCE" }) : null, _jsx("textarea", { ref: input, value: text, className: cls(ui, "composer.input"), rows: 1, placeholder: placeholder, "aria-label": placeholder, onChange: (e) => setText(e.currentTarget.value), onKeyDown: (e) => { if (e.key === "Enter" && !e.shiftKey) {
177
+ return (_jsxs("form", { className: cls(ui, "composer"), style: sty(ui, "composer"), onSubmit: (e) => { e.preventDefault(); void send(); }, children: [props.attachments.length > 0 ? (_jsx("div", { className: cls(ui, "file-chips"), children: props.attachments.map((a) => _jsxs("span", { className: cls(ui, "file-chip"), children: [a.name, _jsx("button", { type: "button", "aria-label": t("files.remove"), onClick: () => ui.assistant.detach(a.id), children: "\u00D7" })] }, a.id)) })) : null, quick.length > 0 || found.length > 0 ? (_jsxs("div", { className: cls(ui, "composer.menu"), role: "listbox", children: [quick.map((q) => _jsx("button", { type: "button", "data-role": "quick", onClick: () => { setText(""); void ui.assistant.ask(q.send); }, children: q.label }, q.label)), found.map((r) => _jsx("button", { type: "button", "data-role": "pick", onClick: () => pickOne(r), children: r.label }, r.kind + ":" + r.id))] })) : null, _jsxs("div", { className: "g9a-composer-row", children: [can(host, "attach") ? _jsx("button", { type: "button", className: cls(ui, "composer.attach"), "aria-label": t("composer.attach"), onClick: () => void ui.assistant.attachFromDevice(), children: "\uD83D\uDCCE" }) : null, _jsx("textarea", { ref: input, value: text, className: cls(ui, "composer.input"), rows: 1, placeholder: placeholder, "aria-label": placeholder, onChange: (e) => setText(e.currentTarget.value), onKeyDown: (e) => { if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing && chat.enterSends !== false) {
138
178
  e.preventDefault();
139
179
  void send();
140
180
  } } }), can(host, "mic") ? _jsx("button", { type: "button", className: cls(ui, "composer.mic"), "aria-label": t("composer.mic"), onClick: () => void dictate(), children: "\uD83C\uDF99" })
package/dist/styles.d.ts CHANGED
@@ -2,4 +2,4 @@
2
2
  * The library's own look, from theme tokens only, all under `.g9a-styled` (no global CSS): the same rules as the
3
3
  * Svelte renderer. `unstyled` leaves structure and class names only, and this sheet is not drawn.
4
4
  */
5
- export declare const STYLES = ".g9a-root { display: contents; }\n.g9a-styled { font-family: var(--g9a-font); font-size: var(--g9a-font-size); color: var(--g9a-ink); line-height: 1.6; }\n.g9a-styled button { font: inherit; cursor: pointer; min-block-size: 38px; padding: 0 12px; border-radius: var(--g9a-radius-s); border: 1px solid var(--g9a-line); background: var(--g9a-surface); color: var(--g9a-ink); }\n.g9a-styled input, .g9a-styled textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--g9a-line); border-radius: var(--g9a-radius-s); background: var(--g9a-surface); color: var(--g9a-ink); }\n.g9a-styled .g9a-panel { box-sizing: border-box; display: flex; flex-direction: column; background: var(--g9a-surface); color: var(--g9a-ink); box-shadow: var(--g9a-shadow); overflow: hidden; }\n.g9a-styled .g9a-panel[data-layout=\"side\"] { position: fixed; inset-block: 0; inset-inline-end: 0; inline-size: min(420px, 100%); border-inline-start: 1px solid var(--g9a-line); }\n.g9a-styled .g9a-panel[data-layout=\"sheet\"] { position: fixed; inset-inline: 0; inset-block-end: 0; block-size: 85vh; border-start-start-radius: 16px; border-start-end-radius: 16px; }\n.g9a-styled .g9a-panel[data-layout=\"fullscreen\"] { position: fixed; inset: 0; }\n.g9a-styled .g9a-panel[data-layout=\"inline\"] { inline-size: 100%; block-size: 100%; box-shadow: none; border: 1px solid var(--g9a-line); border-radius: var(--g9a-radius); }\n.g9a-styled .g9a-panel[data-layout=\"card\"] { border-radius: var(--g9a-radius); border: 1px solid var(--g9a-line); max-block-size: 520px; }\n.g9a-styled .g9a-panel[data-layout=\"compact\"] { box-shadow: none; }\n.g9a-styled .g9a-panel__header { display: flex; align-items: center; gap: var(--g9a-gap); padding: var(--g9a-pad); border-bottom: 1px solid var(--g9a-line); }\n.g9a-styled .g9a-panel__header > strong { flex: 1; min-inline-size: 0; }\n.g9a-styled .g9a-panel__body, .g9a-styled .g9a-chat { display: flex; flex-direction: column; flex: 1; min-block-size: 0; }\n.g9a-styled .g9a-messages { flex: 1; overflow-y: auto; padding: var(--g9a-pad); display: flex; flex-direction: column; gap: var(--g9a-gap); }\n.g9a-styled .g9a-message { max-inline-size: 88%; padding: 8px 12px; border-radius: var(--g9a-radius); background: var(--g9a-surface-2); }\n.g9a-styled .g9a-message__user { align-self: flex-start; background: var(--g9a-user-bubble, color-mix(in srgb, var(--g9a-accent) 12%, var(--g9a-surface))); }\n.g9a-styled .g9a-message__assistant { align-self: flex-end; }\n.g9a-styled .g9a-message[data-pending=\"true\"] { opacity: .7; }\n.g9a-styled .g9a-message__feedback { display: flex; gap: 6px; align-items: center; margin-block-start: 4px; }\n.g9a-styled .g9a-message__feedback button { min-block-size: 26px; font-size: 12px; padding: 0 8px; }\n.g9a-styled .g9a-message__provenance { font-size: 11px; color: var(--g9a-muted); }\n.g9a-styled .g9a-p { margin: 0 0 6px; white-space: pre-wrap; overflow-wrap: anywhere; }\n.g9a-styled code { font-family: ui-monospace, monospace; background: var(--g9a-surface); border-radius: 4px; padding: 0 4px; }\n.g9a-styled a { color: var(--g9a-accent); }\n.g9a-styled .g9a-work { display: flex; gap: var(--g9a-gap); align-items: flex-start; padding: var(--g9a-pad); border-top: 1px solid var(--g9a-line); }\n.g9a-styled .g9a-work-main { flex: 1; min-inline-size: 0; }\n.g9a-styled .g9a-work-head { display: flex; justify-content: space-between; gap: var(--g9a-gap); }\n.g9a-styled .g9a-work__elapsed, .g9a-styled .g9a-work__tool, .g9a-styled .g9a-note { color: var(--g9a-muted); font-size: 12px; }\n.g9a-styled .g9a-stages, .g9a-styled .g9a-stages-thinking { display: flex; flex-wrap: wrap; gap: 6px; margin-block: 4px; }\n.g9a-styled .g9a-work__stage, .g9a-styled .g9a-stages-thinking > span { padding: 1px 10px; border-radius: 999px; border: 1px solid var(--g9a-line); font-size: 12px; color: var(--g9a-muted); }\n.g9a-styled [data-state=\"on\"].g9a-work__stage, .g9a-styled .g9a-stages-thinking > [data-state=\"on\"] { background: color-mix(in srgb, var(--g9a-accent) 20%, transparent); color: var(--g9a-ink); border-color: var(--g9a-accent); }\n.g9a-styled .g9a-thinking-orb { inline-size: 18px; block-size: 18px; border-radius: 50%; background: var(--g9a-accent); animation: g9a-pulse 1.2s ease-in-out infinite; flex: none; margin-block-start: 4px; }\n.g9a-styled .g9a-thinking-orb[data-still=\"true\"] { animation: none; }\n@keyframes g9a-pulse { 0%, 100% { transform: scale(.8); opacity: .6; } 50% { transform: scale(1); opacity: 1; } }\n@media (prefers-reduced-motion: reduce) { .g9a-styled .g9a-thinking-orb { animation: none; } }\n.g9a-styled .g9a-composer { padding: var(--g9a-pad); border-top: 1px solid var(--g9a-line); }\n.g9a-styled .g9a-composer-row { display: flex; gap: var(--g9a-gap); align-items: flex-end; }\n.g9a-styled .g9a-composer__input { flex: 1; min-inline-size: 0; resize: none; max-block-size: 30vh; }\n.g9a-styled .g9a-composer__send { background: var(--g9a-accent); color: var(--g9a-accent-ink); border-color: var(--g9a-accent); }\n.g9a-styled .g9a-file-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-block-end: 6px; }\n.g9a-styled .g9a-file-chip { background: var(--g9a-surface-2); border-radius: 999px; padding: 2px 4px 2px 10px; font-size: 12px; }\n.g9a-styled .g9a-file-chip button { min-block-size: 20px; border: 0; background: none; padding: 0 6px; }\n.g9a-styled .g9a-card__approval { border: 1px solid var(--g9a-approval-card-border); border-radius: var(--g9a-radius); padding: var(--g9a-pad); background: var(--g9a-surface); }\n.g9a-styled .g9a-card__approval h3 { margin: 0 0 6px; font-size: 15px; }\n.g9a-styled .g9a-card__approval__fact { font-size: 12px; color: var(--g9a-muted); padding-inline-start: 24px; }\n.g9a-styled .g9a-card__approval__confirm { background: var(--g9a-accent); color: var(--g9a-accent-ink); border-color: var(--g9a-accent); }\n.g9a-styled .g9a-warning { color: var(--g9a-warn); font-size: 13px; }\n.g9a-styled .g9a-irreversible { color: var(--g9a-danger); font-size: 12px; }\n.g9a-styled .g9a-row { display: flex; gap: var(--g9a-gap); margin-block-start: 8px; }\n.g9a-styled .g9a-mode-banner { background: var(--g9a-surface-2); border-bottom: 1px solid var(--g9a-line); color: var(--g9a-warn); padding: 6px var(--g9a-pad); font-size: 13px; }\n.g9a-styled .g9a-usage-chip { display: inline-block; block-size: 22px; line-height: 22px; padding: 0 8px; border-radius: 999px; font-size: 11px;\nbackground: linear-gradient(to left, var(--g9a-surface-2) calc(100% - var(--g9a-usage)), color-mix(in srgb, var(--g9a-accent) 25%, transparent) 0); }\n.g9a-styled .g9a-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--g9a-line); margin-block-end: 8px; }\n.g9a-styled .g9a-tabs [aria-selected=\"true\"] { border-bottom: 2px solid var(--g9a-accent); }\n.g9a-styled [data-page] { background: var(--g9a-surface); color: var(--g9a-ink); border-radius: var(--g9a-radius-s); }\n.g9a-styled .g9a-admin-capability { border: 1px solid var(--g9a-line); border-radius: 8px; padding: 8px; margin-block-end: 8px; display: grid; gap: 4px; }\n.g9a-styled .g9a-admin-capability label { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }\n.g9a-styled [data-bad=\"true\"], .g9a-styled [data-ok=\"false\"] { color: var(--g9a-danger); }\n.g9a-styled .g9a-block-title { font-weight: 600; margin-block: 4px; }\n.g9a-styled .g9a-block__table table { border-collapse: collapse; inline-size: 100%; font-size: 13px; }\n.g9a-styled .g9a-block__table th, .g9a-styled .g9a-block__table td { border-bottom: 1px solid var(--g9a-line); padding: 4px 6px; text-align: start; }\n.g9a-styled [data-kind=\"number\"], .g9a-styled [data-kind=\"money\"], .g9a-styled [data-kind=\"percent\"] { text-align: end; font-variant-numeric: tabular-nums; }\n.g9a-styled .g9a-block__table__card { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0 0 6px; padding: 6px 8px; background: var(--g9a-surface); border-radius: var(--g9a-radius-s); }\n.g9a-styled .g9a-block__table__card dt { color: var(--g9a-muted); }\n.g9a-styled .g9a-block__table__card dd { margin: 0; }\n.g9a-styled .g9a-block__chart__bar { display: grid; grid-template-columns: 1fr; gap: 2px; margin-block-end: 6px; }\n.g9a-styled .g9a-bar-track { display: block; block-size: 10px; background: var(--g9a-surface); border-radius: 5px; overflow: hidden; }\n.g9a-styled .g9a-bar-fill { display: block; block-size: 100%; background: var(--g9a-chart-bar); border-radius: 5px; }\n.g9a-styled .g9a-bar-value { font-size: 12px; color: var(--g9a-muted); }\n.g9a-styled .g9a-block__chart__line { inline-size: 100%; block-size: 140px; }\n.g9a-styled .g9a-block__chart__line path { stroke: var(--g9a-chart-bar); stroke-width: 2; }\n.g9a-styled .g9a-donut { inline-size: 120px; }\n.g9a-styled .g9a-donut path { fill: none; stroke: var(--g9a-chart-bar); stroke-width: 14; }\n.g9a-styled .g9a-block__kpi { display: flex; flex-wrap: wrap; gap: var(--g9a-gap); }\n.g9a-styled .g9a-block__kpi > div { display: flex; flex-direction: column; padding: 6px 10px; background: var(--g9a-surface); border-radius: var(--g9a-radius-s); }\n.g9a-styled .g9a-block__actions { display: flex; flex-wrap: wrap; gap: 6px; margin-block-start: 6px; }\n.g9a-styled .g9a-block__action { background: color-mix(in srgb, var(--g9a-accent) 12%, var(--g9a-surface)); border-color: var(--g9a-accent); }\n.g9a-styled .g9a-block__action::after { content: \" \u2039\"; }\n.g9a-styled [dir=\"ltr\"] .g9a-block__action::after { content: \" \u203A\"; }\n.g9a-styled .g9a-suggested { font-size: 10px; color: var(--g9a-muted); margin-inline-start: 6px; }\n.g9a-styled .g9a-block__callout { border-inline-start: 3px solid var(--g9a-accent); padding: 6px 10px; background: var(--g9a-surface); }\n.g9a-styled .g9a-block__callout[data-tone=\"danger\"] { border-color: var(--g9a-danger); }\n.g9a-styled .g9a-block__callout[data-tone=\"warn\"] { border-color: var(--g9a-warn); }\n.g9a-styled .g9a-block__image img { max-inline-size: 100%; border-radius: var(--g9a-radius-s); }\n.g9a-styled .g9a-dialog { position: fixed; inset: 10% 8%; background: var(--g9a-surface); border-radius: var(--g9a-radius); box-shadow: var(--g9a-shadow); padding: var(--g9a-pad); overflow: auto; }\n.g9a-styled .g9a-hero { padding: var(--g9a-pad); border: 1px solid var(--g9a-line); border-radius: var(--g9a-radius); background: var(--g9a-surface); }\n.g9a-styled .g9a-badge { margin-inline-start: 6px; background: var(--g9a-danger); color: #fff; border-radius: 999px; padding: 0 6px; font-size: 11px; }\n.g9a-styled .g9a-measure { inline-size: 100%; block-size: 0; }\n.g9a-styled .g9a-count { font-size: 11px; color: var(--g9a-muted); margin-inline-start: 4px; }\n.g9a-styled .g9a-history__list, .g9a-styled .g9a-routines__list, .g9a-styled .g9a-picker__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }\n.g9a-styled .g9a-history__row { display: flex; gap: 4px; align-items: center; }\n.g9a-styled .g9a-history__open { flex: 1; min-inline-size: 0; text-align: start; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.g9a-styled .g9a-history__row[data-waiting=\"true\"] .g9a-history__open { border-color: var(--g9a-warn); }\n.g9a-styled .g9a-history__delete, .g9a-styled .g9a-history__delete-yes { color: var(--g9a-danger); }\n.g9a-styled .g9a-routines__form { display: grid; gap: var(--g9a-gap); }\n.g9a-styled .g9a-routines__slot { display: grid; gap: 2px; }\n.g9a-styled .g9a-routines__slot[data-state=\"missing\"] input, .g9a-styled .g9a-routines__slot[data-state=\"invalid\"] input { border-color: var(--g9a-danger); }\n.g9a-styled .g9a-routines__choose { inline-size: 100%; text-align: start; }\n.g9a-styled .g9a-picker__chosen { font-weight: 600; margin-inline-end: 6px; }\n.g9a-styled .g9a-csv { display: flex; gap: 6px; align-items: center; margin-block: 4px; }\n";
5
+ export declare const STYLES = ".g9a-root { display: contents; }\n.g9a-styled { font-family: var(--g9a-font); font-size: var(--g9a-font-size); color: var(--g9a-ink); line-height: 1.6; }\n.g9a-styled button { font: inherit; cursor: pointer; min-block-size: 38px; padding: 0 12px; border-radius: var(--g9a-radius-s); border: 1px solid var(--g9a-line); background: var(--g9a-surface); color: var(--g9a-ink); }\n.g9a-styled input, .g9a-styled textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--g9a-line); border-radius: var(--g9a-radius-s); background: var(--g9a-surface); color: var(--g9a-ink); }\n.g9a-styled .g9a-panel { box-sizing: border-box; display: flex; flex-direction: column; background: var(--g9a-surface); color: var(--g9a-ink); box-shadow: var(--g9a-shadow); overflow: hidden; }\n.g9a-styled .g9a-panel[data-layout=\"side\"] { position: fixed; inset-block: 0; inset-inline-end: 0; inline-size: min(420px, 100%); border-inline-start: 1px solid var(--g9a-line); }\n.g9a-styled .g9a-panel[data-layout=\"sheet\"] { position: fixed; inset-inline: 0; inset-block-end: 0; block-size: 85vh; border-start-start-radius: 16px; border-start-end-radius: 16px; }\n.g9a-styled .g9a-panel[data-layout=\"fullscreen\"] { position: fixed; inset: 0; }\n.g9a-styled .g9a-panel[data-layout=\"inline\"] { inline-size: 100%; block-size: 100%; box-shadow: none; border: 1px solid var(--g9a-line); border-radius: var(--g9a-radius); }\n.g9a-styled .g9a-panel[data-layout=\"card\"] { border-radius: var(--g9a-radius); border: 1px solid var(--g9a-line); max-block-size: 520px; }\n.g9a-styled .g9a-panel[data-layout=\"compact\"] { box-shadow: none; }\n.g9a-styled .g9a-panel__header { display: flex; align-items: center; gap: var(--g9a-gap); padding: var(--g9a-pad); border-bottom: 1px solid var(--g9a-line); }\n.g9a-styled .g9a-panel__header > strong { flex: 1; min-inline-size: 0; }\n.g9a-styled .g9a-panel__body, .g9a-styled .g9a-chat { display: flex; flex-direction: column; flex: 1; min-block-size: 0; }\n.g9a-styled .g9a-messages { flex: 1; overflow-y: auto; padding: var(--g9a-pad); display: flex; flex-direction: column; gap: var(--g9a-gap); }\n.g9a-styled .g9a-messages-frame { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }\n.g9a-styled .g9a-messages[data-selectable=\"true\"] { user-select: text; -webkit-user-select: text; }\n.g9a-styled .g9a-messages__newest { position: absolute; bottom: 8px; inset-inline-start: 50%; transform: translateX(-50%); }\n.g9a-styled .g9a-list { margin: 0 0 6px; padding-inline-start: 1.4em; }\n.g9a-styled .g9a-list li { padding-inline-start: 0.2em; }\n.g9a-styled .g9a-composer__menu, .g9a-styled .g9a-block__entities, .g9a-styled .g9a-tour-nav { display: flex; flex-wrap: wrap; gap: 6px; }\n.g9a-styled .g9a-message { max-inline-size: 88%; padding: 8px 12px; border-radius: var(--g9a-radius); background: var(--g9a-surface-2); }\n.g9a-styled .g9a-message__user { align-self: flex-start; background: var(--g9a-user-bubble, color-mix(in srgb, var(--g9a-accent) 12%, var(--g9a-surface))); }\n.g9a-styled .g9a-message__assistant { align-self: flex-end; }\n.g9a-styled .g9a-message[data-pending=\"true\"] { opacity: .7; }\n.g9a-styled .g9a-message__feedback { display: flex; gap: 6px; align-items: center; margin-block-start: 4px; }\n.g9a-styled .g9a-message__feedback button { min-block-size: 26px; font-size: 12px; padding: 0 8px; }\n.g9a-styled .g9a-message__provenance { font-size: 11px; color: var(--g9a-muted); }\n.g9a-styled .g9a-p { margin: 0 0 6px; white-space: pre-wrap; overflow-wrap: anywhere; }\n.g9a-styled code { font-family: ui-monospace, monospace; background: var(--g9a-surface); border-radius: 4px; padding: 0 4px; }\n.g9a-styled a { color: var(--g9a-accent); }\n.g9a-styled .g9a-work { display: flex; gap: var(--g9a-gap); align-items: flex-start; padding: var(--g9a-pad); border-top: 1px solid var(--g9a-line); }\n.g9a-styled .g9a-work-main { flex: 1; min-inline-size: 0; }\n.g9a-styled .g9a-work-head { display: flex; justify-content: space-between; gap: var(--g9a-gap); }\n.g9a-styled .g9a-work__elapsed, .g9a-styled .g9a-work__tool, .g9a-styled .g9a-note { color: var(--g9a-muted); font-size: 12px; }\n.g9a-styled .g9a-stages, .g9a-styled .g9a-stages-thinking { display: flex; flex-wrap: wrap; gap: 6px; margin-block: 4px; }\n.g9a-styled .g9a-work__stage, .g9a-styled .g9a-stages-thinking > span { padding: 1px 10px; border-radius: 999px; border: 1px solid var(--g9a-line); font-size: 12px; color: var(--g9a-muted); }\n.g9a-styled [data-state=\"on\"].g9a-work__stage, .g9a-styled .g9a-stages-thinking > [data-state=\"on\"] { background: color-mix(in srgb, var(--g9a-accent) 20%, transparent); color: var(--g9a-ink); border-color: var(--g9a-accent); }\n.g9a-styled .g9a-thinking-orb { inline-size: 18px; block-size: 18px; border-radius: 50%; background: var(--g9a-accent); animation: g9a-pulse 1.2s ease-in-out infinite; flex: none; margin-block-start: 4px; }\n.g9a-styled .g9a-thinking-orb[data-still=\"true\"] { animation: none; }\n@keyframes g9a-pulse { 0%, 100% { transform: scale(.8); opacity: .6; } 50% { transform: scale(1); opacity: 1; } }\n@media (prefers-reduced-motion: reduce) { .g9a-styled .g9a-thinking-orb { animation: none; } }\n.g9a-styled .g9a-composer { padding: var(--g9a-pad); border-top: 1px solid var(--g9a-line); }\n.g9a-styled .g9a-composer-row { display: flex; gap: var(--g9a-gap); align-items: flex-end; }\n.g9a-styled .g9a-composer__input { flex: 1; min-inline-size: 0; resize: none; max-block-size: 30vh; }\n.g9a-styled .g9a-composer__send { background: var(--g9a-accent); color: var(--g9a-accent-ink); border-color: var(--g9a-accent); }\n.g9a-styled .g9a-file-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-block-end: 6px; }\n.g9a-styled .g9a-file-chip { background: var(--g9a-surface-2); border-radius: 999px; padding: 2px 4px 2px 10px; font-size: 12px; }\n.g9a-styled .g9a-file-chip button { min-block-size: 20px; border: 0; background: none; padding: 0 6px; }\n.g9a-styled .g9a-card__approval { border: 1px solid var(--g9a-approval-card-border); border-radius: var(--g9a-radius); padding: var(--g9a-pad); background: var(--g9a-surface); }\n.g9a-styled .g9a-card__approval h3 { margin: 0 0 6px; font-size: 15px; }\n.g9a-styled .g9a-card__approval__fact { font-size: 12px; color: var(--g9a-muted); padding-inline-start: 24px; }\n.g9a-styled .g9a-card__approval__confirm { background: var(--g9a-accent); color: var(--g9a-accent-ink); border-color: var(--g9a-accent); }\n.g9a-styled .g9a-warning { color: var(--g9a-warn); font-size: 13px; }\n.g9a-styled .g9a-irreversible { color: var(--g9a-danger); font-size: 12px; }\n.g9a-styled .g9a-row { display: flex; gap: var(--g9a-gap); margin-block-start: 8px; }\n.g9a-styled .g9a-mode-banner { background: var(--g9a-surface-2); border-bottom: 1px solid var(--g9a-line); color: var(--g9a-warn); padding: 6px var(--g9a-pad); font-size: 13px; }\n.g9a-styled .g9a-usage-chip { display: inline-block; block-size: 22px; line-height: 22px; padding: 0 8px; border-radius: 999px; font-size: 11px;\nbackground: linear-gradient(to left, var(--g9a-surface-2) calc(100% - var(--g9a-usage)), color-mix(in srgb, var(--g9a-accent) 25%, transparent) 0); }\n.g9a-styled .g9a-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--g9a-line); margin-block-end: 8px; }\n.g9a-styled .g9a-tabs [aria-selected=\"true\"] { border-bottom: 2px solid var(--g9a-accent); }\n.g9a-styled [data-page] { background: var(--g9a-surface); color: var(--g9a-ink); border-radius: var(--g9a-radius-s); }\n.g9a-styled .g9a-admin-capability { border: 1px solid var(--g9a-line); border-radius: 8px; padding: 8px; margin-block-end: 8px; display: grid; gap: 4px; }\n.g9a-styled .g9a-admin-capability label { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }\n.g9a-styled [data-bad=\"true\"], .g9a-styled [data-ok=\"false\"] { color: var(--g9a-danger); }\n.g9a-styled .g9a-block-title { font-weight: 600; margin-block: 4px; }\n.g9a-styled .g9a-block__table table { border-collapse: collapse; inline-size: 100%; font-size: 13px; }\n.g9a-styled .g9a-block__table th, .g9a-styled .g9a-block__table td { border-bottom: 1px solid var(--g9a-line); padding: 4px 6px; text-align: start; }\n.g9a-styled [data-kind=\"number\"], .g9a-styled [data-kind=\"money\"], .g9a-styled [data-kind=\"percent\"] { text-align: end; font-variant-numeric: tabular-nums; }\n.g9a-styled .g9a-block__table__card { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0 0 6px; padding: 6px 8px; background: var(--g9a-surface); border-radius: var(--g9a-radius-s); }\n.g9a-styled .g9a-block__table__card dt { color: var(--g9a-muted); }\n.g9a-styled .g9a-block__table__card dd { margin: 0; }\n.g9a-styled .g9a-block__chart__bar { display: grid; grid-template-columns: 1fr; gap: 2px; margin-block-end: 6px; }\n.g9a-styled .g9a-bar-track { display: block; block-size: 10px; background: var(--g9a-surface); border-radius: 5px; overflow: hidden; }\n.g9a-styled .g9a-bar-fill { display: block; block-size: 100%; background: var(--g9a-chart-bar); border-radius: 5px; }\n.g9a-styled .g9a-bar-value { font-size: 12px; color: var(--g9a-muted); }\n.g9a-styled .g9a-block__chart__line { inline-size: 100%; block-size: 140px; }\n.g9a-styled .g9a-block__chart__line path { stroke: var(--g9a-chart-bar); stroke-width: 2; }\n.g9a-styled .g9a-donut { inline-size: 120px; }\n.g9a-styled .g9a-donut path { fill: none; stroke: var(--g9a-chart-bar); stroke-width: 14; }\n.g9a-styled .g9a-block__kpi { display: flex; flex-wrap: wrap; gap: var(--g9a-gap); }\n.g9a-styled .g9a-block__kpi > div { display: flex; flex-direction: column; padding: 6px 10px; background: var(--g9a-surface); border-radius: var(--g9a-radius-s); }\n.g9a-styled .g9a-block__actions { display: flex; flex-wrap: wrap; gap: 6px; margin-block-start: 6px; }\n.g9a-styled .g9a-block__action { background: color-mix(in srgb, var(--g9a-accent) 12%, var(--g9a-surface)); border-color: var(--g9a-accent); }\n.g9a-styled .g9a-block__action::after { content: \" \u2039\"; }\n.g9a-styled [dir=\"ltr\"] .g9a-block__action::after { content: \" \u203A\"; }\n.g9a-styled .g9a-suggested { font-size: 10px; color: var(--g9a-muted); margin-inline-start: 6px; }\n.g9a-styled .g9a-block__callout { border-inline-start: 3px solid var(--g9a-accent); padding: 6px 10px; background: var(--g9a-surface); }\n.g9a-styled .g9a-block__callout[data-tone=\"danger\"] { border-color: var(--g9a-danger); }\n.g9a-styled .g9a-block__callout[data-tone=\"warn\"] { border-color: var(--g9a-warn); }\n.g9a-styled .g9a-block__image img { max-inline-size: 100%; border-radius: var(--g9a-radius-s); }\n.g9a-styled .g9a-dialog { position: fixed; inset: 10% 8%; background: var(--g9a-surface); border-radius: var(--g9a-radius); box-shadow: var(--g9a-shadow); padding: var(--g9a-pad); overflow: auto; }\n.g9a-styled .g9a-hero { padding: var(--g9a-pad); border: 1px solid var(--g9a-line); border-radius: var(--g9a-radius); background: var(--g9a-surface); }\n.g9a-styled .g9a-badge { margin-inline-start: 6px; background: var(--g9a-danger); color: #fff; border-radius: 999px; padding: 0 6px; font-size: 11px; }\n.g9a-styled .g9a-measure { inline-size: 100%; block-size: 0; }\n.g9a-styled .g9a-count { font-size: 11px; color: var(--g9a-muted); margin-inline-start: 4px; }\n.g9a-styled .g9a-history__list, .g9a-styled .g9a-routines__list, .g9a-styled .g9a-picker__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }\n.g9a-styled .g9a-history__row { display: flex; gap: 4px; align-items: center; }\n.g9a-styled .g9a-history__open { flex: 1; min-inline-size: 0; text-align: start; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.g9a-styled .g9a-history__row[data-waiting=\"true\"] .g9a-history__open { border-color: var(--g9a-warn); }\n.g9a-styled .g9a-history__delete, .g9a-styled .g9a-history__delete-yes { color: var(--g9a-danger); }\n.g9a-styled .g9a-routines__form { display: grid; gap: var(--g9a-gap); }\n.g9a-styled .g9a-routines__slot { display: grid; gap: 2px; }\n.g9a-styled .g9a-routines__slot[data-state=\"missing\"] input, .g9a-styled .g9a-routines__slot[data-state=\"invalid\"] input { border-color: var(--g9a-danger); }\n.g9a-styled .g9a-routines__choose { inline-size: 100%; text-align: start; }\n.g9a-styled .g9a-picker__chosen { font-weight: 600; margin-inline-end: 6px; }\n.g9a-styled .g9a-csv { display: flex; gap: 6px; align-items: center; margin-block: 4px; }\n";
package/dist/styles.js CHANGED
@@ -17,6 +17,12 @@ export const STYLES = `.g9a-root { display: contents; }
17
17
  .g9a-styled .g9a-panel__header > strong { flex: 1; min-inline-size: 0; }
18
18
  .g9a-styled .g9a-panel__body, .g9a-styled .g9a-chat { display: flex; flex-direction: column; flex: 1; min-block-size: 0; }
19
19
  .g9a-styled .g9a-messages { flex: 1; overflow-y: auto; padding: var(--g9a-pad); display: flex; flex-direction: column; gap: var(--g9a-gap); }
20
+ .g9a-styled .g9a-messages-frame { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
21
+ .g9a-styled .g9a-messages[data-selectable="true"] { user-select: text; -webkit-user-select: text; }
22
+ .g9a-styled .g9a-messages__newest { position: absolute; bottom: 8px; inset-inline-start: 50%; transform: translateX(-50%); }
23
+ .g9a-styled .g9a-list { margin: 0 0 6px; padding-inline-start: 1.4em; }
24
+ .g9a-styled .g9a-list li { padding-inline-start: 0.2em; }
25
+ .g9a-styled .g9a-composer__menu, .g9a-styled .g9a-block__entities, .g9a-styled .g9a-tour-nav { display: flex; flex-wrap: wrap; gap: 6px; }
20
26
  .g9a-styled .g9a-message { max-inline-size: 88%; padding: 8px 12px; border-radius: var(--g9a-radius); background: var(--g9a-surface-2); }
21
27
  .g9a-styled .g9a-message__user { align-self: flex-start; background: var(--g9a-user-bubble, color-mix(in srgb, var(--g9a-accent) 12%, var(--g9a-surface))); }
22
28
  .g9a-styled .g9a-message__assistant { align-self: flex-end; }
package/dist/surfaces.js CHANGED
@@ -5,7 +5,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
5
5
  */
6
6
  import { useEffect, useLayoutEffect, useRef, useState } from "react";
7
7
  import { pickLayout } from "@g9tm/aiassistant";
8
- import { loadHostTexts, withHostTexts } from "@g9tm/aiassistant/pages";
8
+ import { chatOf, loadHostTexts, pageTexts, withHostTexts } from "@g9tm/aiassistant/pages";
9
9
  import { cls, override, sty, UiProvider, useSnapshot, useUi } from "./context.js";
10
10
  import { Composer, Message, PdfButton, Small, WorkCard } from "./parts.js";
11
11
  import { STYLES } from "./styles.js";
@@ -34,10 +34,19 @@ export function MessageList(props) {
34
34
  const box = useRef(null);
35
35
  const count = useRef(0);
36
36
  const n = props.messages.length;
37
+ const lastOne = props.messages[n - 1];
38
+ // New content below the view while the person reads above: the view stays, and «to the newest» appears.
39
+ const [below, setBelow] = useState(false);
40
+ const measure = () => { const el = box.current; if (el)
41
+ setBelow(el.scrollTop + el.clientHeight < el.scrollHeight - 40); };
37
42
  useLayoutEffect(() => {
38
43
  const el = box.current;
39
- if (!el || n === count.current)
44
+ if (!el)
45
+ return;
46
+ if (n === count.current) {
47
+ measure();
40
48
  return;
49
+ }
41
50
  const last = props.messages[n - 1];
42
51
  const node = last ? Array.from(el.children).find((c) => c.dataset["id"] === last.id) : undefined;
43
52
  if (count.current === 0)
@@ -45,8 +54,11 @@ export function MessageList(props) {
45
54
  else if (last?.role === "user" && node)
46
55
  el.scrollTop = node.offsetTop - el.offsetTop; // the question at the top
47
56
  count.current = n;
48
- }, [n]);
49
- return (_jsx("div", { className: cls(ui, "messages"), ref: box, "aria-live": "polite", children: props.messages.map((m) => _jsx("div", { "data-id": m.id, children: _jsx(Item, { message: m, plans: props.plans, runId: props.runId }) }, m.id)) }));
57
+ measure();
58
+ }, [n, lastOne?.text.length]);
59
+ const lastAnswer = lastOne?.role === "assistant" ? lastOne.id : null;
60
+ return (_jsxs("div", { className: "g9a-messages-frame", children: [_jsx("div", { className: cls(ui, "messages"), ref: box, "aria-live": "polite", onScroll: measure, "data-selectable": chatOf(ui.assistant).selectable, children: props.messages.map((m) => _jsx("div", { "data-id": m.id, children: _jsx(Item, { message: m, plans: props.plans, runId: props.runId, last: m.id === lastAnswer }) }, m.id)) }), below ? _jsx("button", { type: "button", className: cls(ui, "messages.newest"), "data-role": "newest", onClick: () => { const el = box.current; if (el)
61
+ el.scrollTop = el.scrollHeight; setBelow(false); }, children: pageTexts(ui.texts).t("messages.newest") }) : null] }));
50
62
  }
51
63
  /** The chat: a composition of exported parts only (mode banner, messages, work card, composer). */
52
64
  export function AssistantChat(props) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@g9tm/aiassistant-react",
3
- "version": "1.8.2",
3
+ "version": "1.9.0",
4
4
  "description": "React DOM components for the G9 AI assistant, fully customisable (layouts, tokens, per-part classes, overrides, parts).",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -29,7 +29,7 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "@g9tm/aiassistant": "1.8.2"
32
+ "@g9tm/aiassistant": "1.9.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/react": "19.3.0",