@g9tm/aiassistant-lynx 1.2.0 → 1.4.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/admin.d.ts CHANGED
@@ -4,4 +4,6 @@
4
4
  * windows, the latest calls and a run's black box) and the audit. The logic is the core's; this file only draws.
5
5
  */
6
6
  /** The manager's page: capabilities, models, connections, usage, audit and suggestions, each loaded when its tab opens. */
7
- export declare function AdminPage(): import("@lynx-js/react").JSX.Element;
7
+ export declare function AdminPage(props?: {
8
+ flow?: boolean;
9
+ }): import("@lynx-js/react").JSX.Element;
package/dist/admin.jsx CHANGED
@@ -147,16 +147,18 @@ function Feedback() {
147
147
  return <view>{(rows ?? []).map((f) => <Line key={f.id} text={f.title + " · " + f.kind + " · ×" + String(f.count) + " · " + f.status}/>)}</view>;
148
148
  }
149
149
  /** The manager's page: capabilities, models, connections, usage, audit and suggestions, each loaded when its tab opens. */
150
- export function AdminPage() {
150
+ export function AdminPage(props = {}) {
151
151
  const ui = useUi();
152
152
  const { t } = useAdmin();
153
153
  const [tab, setTab] = useState("capabilities");
154
- return (<view className={cls(ui, "panel.body")} style={{ display: "flex", flexDirection: "column", ...fill, minHeight: 0, direction: "ltr" }}>
154
+ return (<view className={cls(ui, "panel.body")} style={{ display: "flex", flexDirection: "column", ...(props.flow ? {} : { ...fill, minHeight: 0 }), direction: "ltr" }}>
155
155
  <view style={rowOf(ui, "6px")}>
156
156
  {["capabilities", "models", "connections", "usage", "audit", "feedback"].map((x) => <Button key={x} label={t("admin." + x)} primary={tab === x} onTap={() => setTab(x)}/>)}
157
157
  </view>
158
- <scroll-view scroll-orientation="vertical" style={{ ...fill }}>
158
+ {props.flow ? <view>
159
159
  {tab === "capabilities" ? <Capabilities /> : tab === "models" ? <Models /> : tab === "connections" ? <Connections /> : tab === "usage" ? <Usage /> : tab === "feedback" ? <Feedback /> : <Audit />}
160
- </scroll-view>
160
+ </view> : <scroll-view scroll-orientation="vertical" style={{ ...fill }}>
161
+ {tab === "capabilities" ? <Capabilities /> : tab === "models" ? <Models /> : tab === "connections" ? <Connections /> : tab === "usage" ? <Usage /> : tab === "feedback" ? <Feedback /> : <Audit />}
162
+ </scroll-view>}
161
163
  </view>);
162
164
  }
package/dist/context.d.ts CHANGED
@@ -41,6 +41,10 @@ export declare const fill: {
41
41
  * panel itself stays left to right and an RTL row is drawn reversed, the same on both.
42
42
  */
43
43
  export declare function rowOf(ui: LynxUi, gap?: string): Record<string, string>;
44
+ /** Text that starts where reading starts: the panel stays left to right on a device, so RTL text is aligned right. */
45
+ export declare function startText(ui: LynxUi): {
46
+ textAlign: "left" | "right";
47
+ };
44
48
  /** A theme token (the host's over the defaults), or the fallback. */
45
49
  export declare function tok(ui: LynxUi, name: string, fallback?: string): string;
46
50
  export declare function override(ui: LynxUi, name: string): HostComponent | undefined;
package/dist/context.jsx CHANGED
@@ -33,6 +33,10 @@ export const fill = { flexGrow: 1, flexShrink: 1, flexBasis: "0px" };
33
33
  export function rowOf(ui, gap) {
34
34
  return { display: "flex", flexDirection: ui.assistant.host.dir === "rtl" ? "row-reverse" : "row", alignItems: "center", ...(gap ? { gap } : {}) };
35
35
  }
36
+ /** Text that starts where reading starts: the panel stays left to right on a device, so RTL text is aligned right. */
37
+ export function startText(ui) {
38
+ return { textAlign: ui.assistant.host.dir === "rtl" ? "right" : "left" };
39
+ }
36
40
  /** A theme token (the host's over the defaults), or the fallback. */
37
41
  export function tok(ui, name, fallback = "") {
38
42
  return ui.unstyled ? fallback : (new Map(Object.entries(ui.theme)).get(name) ?? fallback);
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /** @g9tm/aiassistant-lynx: ReactLynx components of the G9 AI assistant, customisable like the Svelte ones. */
2
- export { AssistantRoot, AssistantChat, AssistantPanel, MessageList, PdfDownload, Surfaces } from "./surfaces.jsx";
2
+ export { AssistantRoot, AssistantChat, AssistantPanel, MessageList, PdfDownload, RECYCLE_FROM, Surfaces } from "./surfaces.jsx";
3
3
  export type { SurfaceKind, SurfaceProps } from "./surfaces.jsx";
4
4
  export { ApprovalCard, BlockView, Cards, Composer, CsvButton, Message, RevealText, Small, StagesThinking, TextView, ThinkingOrb, WorkCard } from "./parts.jsx";
5
5
  export { Chart } from "./chart.jsx";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /** @g9tm/aiassistant-lynx: ReactLynx components of the G9 AI assistant, customisable like the Svelte ones. */
2
- export { AssistantRoot, AssistantChat, AssistantPanel, MessageList, PdfDownload, Surfaces } from "./surfaces.jsx";
2
+ export { AssistantRoot, AssistantChat, AssistantPanel, MessageList, PdfDownload, RECYCLE_FROM, Surfaces } from "./surfaces.jsx";
3
3
  export { ApprovalCard, BlockView, Cards, Composer, CsvButton, Message, RevealText, Small, StagesThinking, TextView, ThinkingOrb, WorkCard } from "./parts.jsx";
4
4
  export { Chart } from "./chart.jsx";
5
5
  export { Button, Dialog, field, PinPad, SecretField } from "./slots.jsx";
package/dist/pages.d.ts CHANGED
@@ -9,6 +9,8 @@ import type { ConversationRow, RoutineSlot } from "@g9tm/aiassistant/pages";
9
9
  export type PageKind = "history" | "abilities" | "knowledge" | "learned" | "findings" | "routines" | "actions";
10
10
  export interface PageProps {
11
11
  onOpen?: (conversationId: string) => void;
12
+ /** Drawn inside a host page that flows (a settings screen): no inner scroll and no fill, the host's page scrolls. */
13
+ flow?: boolean;
12
14
  }
13
15
  /** A page by its kind (history and the routine wizard have their own state; the rest read one endpoint). */
14
16
  export declare function Page(props: PageProps & {
package/dist/pages.jsx CHANGED
@@ -8,7 +8,7 @@
8
8
  import { useEffect, useRef, useState } from "@lynx-js/react";
9
9
  import { afterConfirm, ApiError, arr, formatNumber, needsCode, num, obj, planView, str, timer } from "@g9tm/aiassistant";
10
10
  import { HISTORY_TABS, historyTabs, missingSlots, pageCalls, pageTexts, readConversations, readPicks, readRoutines, slotValue, tabCounts } from "@g9tm/aiassistant/pages";
11
- import { cls, fill, rowOf, swappable, tok, useSnapshot, useUi } from "./context.jsx";
11
+ import { cls, fill, rowOf, startText, swappable, tok, useSnapshot, useUi } from "./context.jsx";
12
12
  import { BlockView } from "./parts.jsx";
13
13
  import { Button, Dialog, field, PinPad } from "./slots.jsx";
14
14
  const PATHS = new Map([
@@ -22,29 +22,36 @@ function Title(props) {
22
22
  function Line(props) {
23
23
  const ui = useUi();
24
24
  return (<view style={{ ...rowOf(ui, "6px"), minHeight: "32px" }}>
25
- <view style={grow}><text style={{ color: props.muted ? tok(ui, "muted", "#6b6660") : tok(ui, "ink", "#22201d") }} text-maxline="2">{props.text}</text></view>
25
+ <view style={grow}><text style={{ ...startText(ui), color: props.muted ? tok(ui, "muted", "#6b6660") : tok(ui, "ink", "#22201d") }} text-maxline="2">{props.text}</text></view>
26
26
  {props.children}
27
27
  </view>);
28
28
  }
29
- /** Nothing to show yet: a dash, never an empty hole or a key. */
30
- function Empty() {
29
+ /** Nothing to show yet: one sentence at the start of the line, never an empty hole or a key. */
30
+ function Empty(props) {
31
31
  const ui = useUi();
32
- return <text className="g9a-empty" style={{ color: tok(ui, "muted", "#6b6660") }}>—</text>;
32
+ return (<view style={{ display: "flex", flexDirection: "column", alignItems: ui.assistant.host.dir === "rtl" ? "flex-end" : "flex-start", paddingTop: "8px" }}>
33
+ <text className="g9a-empty" style={{ ...startText(ui), color: tok(ui, "muted", "#6b6660") }} text-maxline="2">{props.words}</text>
34
+ </view>);
33
35
  }
34
- /** A page's frame: the network notice above, the body in a vertical scroll. */
36
+ /** A page's frame: the network notice above, the body in a vertical scroll (or, in a flowing host page, as it is). */
35
37
  function Frame(props) {
36
38
  const ui = useUi();
37
- return (<view className={cls(ui, "panel.body")} style={{ display: "flex", flexDirection: "column", ...fill, minHeight: 0, padding: "12px", backgroundColor: tok(ui, "surface", "#fff") }}>
38
- {props.failed ? <text style={{ color: tok(ui, "danger", "#b42318") }} text-maxline="2">{ui.texts.t("error.network")}</text> : null}
39
- <scroll-view scroll-orientation="vertical" style={{ ...fill }}>{props.children}</scroll-view>
39
+ return (<view className={cls(ui, "panel.body")} style={{ display: "flex", flexDirection: "column", ...(props.flow ? {} : { ...fill, minHeight: 0 }), padding: "12px", backgroundColor: tok(ui, "surface", "#fff") }}>
40
+ {props.failed ? <text style={{ ...startText(ui), color: tok(ui, "danger", "#b42318") }} text-maxline="2">{ui.texts.t("error.network")}</text> : null}
41
+ {props.flow ? <view>{props.children}</view> : <scroll-view scroll-orientation="vertical" style={{ ...fill }}>{props.children}</scroll-view>}
40
42
  </view>);
41
43
  }
44
+ /** A slot's label: the host's words for `slot.<name>` (its texts, read from the server too), or the name itself. */
45
+ function slotLabel(t, name) {
46
+ const v = t("slot." + name);
47
+ return v === "slot." + name ? name : v;
48
+ }
42
49
  /** A page by its kind (history and the routine wizard have their own state; the rest read one endpoint). */
43
50
  export function Page(props) {
44
51
  if (props.kind === "history")
45
52
  return <HistoryBody {...props}/>;
46
53
  if (props.kind === "routines")
47
- return <RoutineBody />;
54
+ return <RoutineBody flow={props.flow}/>;
48
55
  return <PlainPage {...props}/>;
49
56
  }
50
57
  function PlainPage(props) {
@@ -58,14 +65,15 @@ function PlainPage(props) {
58
65
  useEffect(() => { void load(); }, [props.kind]);
59
66
  const act = (path, body) => { void api.post(path, body).catch(() => undefined).then(load); };
60
67
  const d = data ?? {};
61
- const list = (rows, draw) => (data !== null && rows.length === 0 ? <Empty /> : rows.map(draw));
68
+ const empty = <Empty words={t("page." + props.kind + ".empty")}/>;
69
+ const list = (rows, draw) => (data !== null && rows.length === 0 ? empty : rows.map(draw));
62
70
  const id = (r) => encodeURIComponent(str(r["id"]));
63
71
  let body = null;
64
72
  if (props.kind === "abilities") {
65
73
  const groups = arr(d["groups"]).map(obj);
66
74
  const closed = arr(d["closed"]).map(obj);
67
75
  body = (<view>
68
- {data !== null && groups.length === 0 && closed.length === 0 ? <Empty /> : null}
76
+ {data !== null && groups.length === 0 && closed.length === 0 ? empty : null}
69
77
  {groups.map((g) => (<view key={str(g["name"])}>
70
78
  <Title text={str(g["title"], str(g["name"]))}/>
71
79
  {arr(g["tools"]).map(obj).map((x) => <Line key={str(x["name"])} text={str(x["title"], str(x["name"]))}/>)}
@@ -93,10 +101,10 @@ function PlainPage(props) {
93
101
  else {
94
102
  const done = [...snap.plans.values()].filter((p) => p.answered === "confirmed");
95
103
  body = (<view>
96
- {done.length === 0 ? <Empty /> : done.map((p) => <Line key={p.id} text={p.title}><Button label={t("undo.all")} onTap={() => void ui.assistant.undo(p.id)}/></Line>)}
104
+ {done.length === 0 ? empty : done.map((p) => <Line key={p.id} text={p.title}><Button label={t("undo.all")} onTap={() => void ui.assistant.undo(p.id)}/></Line>)}
97
105
  </view>);
98
106
  }
99
- return <Frame failed={failed}>{body}</Frame>;
107
+ return <Frame failed={failed} flow={props.flow}>{body}</Frame>;
100
108
  }
101
109
  /** One tab of the history: its name and its count in separate texts (a number and a Persian word in one text reverse). */
102
110
  function Tab(props) {
@@ -140,12 +148,12 @@ function HistoryBody(props) {
140
148
  const counts = tabCounts(tabs);
141
149
  const shown = tabs[tab];
142
150
  const open = async (id) => { await ui.assistant.open(id); props.onOpen?.(id); };
143
- return (<Frame failed={failed}>
151
+ return (<Frame failed={failed} flow={props.flow}>
144
152
  <input style={{ ...field(ui), marginBottom: "8px" }} placeholder={t("history.search")} accessibility-label={t("history.search")} bindinput={(e) => setSearch(e.detail.value)}/>
145
153
  <view className="g9a-history-tabs" style={{ ...rowOf(ui, "6px"), flexWrap: "wrap", marginBottom: "8px" }}>
146
154
  {HISTORY_TABS.map((k) => <Tab key={k} label={t("history." + k)} count={counts[k]} on={tab === k} onTap={() => setTab(k)}/>)}
147
155
  </view>
148
- {rows !== null && shown.length === 0 ? <Empty /> : shown.map((c) => (<HistoryRow key={c.id} row={c} onOpen={() => void open(c.id)} onPin={() => change(pageCalls.pin(api, c.id, !c.pinned))} onDelete={() => setDoomed(c)}/>))}
156
+ {rows !== null && shown.length === 0 ? <Empty words={t("history.empty")}/> : shown.map((c) => (<HistoryRow key={c.id} row={c} onOpen={() => void open(c.id)} onPin={() => change(pageCalls.pin(api, c.id, !c.pinned))} onDelete={() => setDoomed(c)}/>))}
149
157
  <Dialog open={doomed !== null} label={t("history.delete_confirm")} onClose={() => setDoomed(null)}>
150
158
  <text style={{ marginBottom: "8px" }} text-maxline="3">{doomed?.title ?? ""}</text>
151
159
  <view style={rowOf(ui, "8px")}>
@@ -187,11 +195,11 @@ export const SlotPicker = swappable("SlotPicker", (props) => {
187
195
  clock.clear(wait.current);
188
196
  wait.current = clock.set(() => { wait.current = null; find(q); }, PICK_WAIT_MS);
189
197
  };
190
- return (<Dialog open={true} label={props.slot.name} onClose={props.onClose}>
198
+ return (<Dialog open={true} label={slotLabel(t, props.slot.name)} onClose={props.onClose}>
191
199
  <view className="g9a-slot-picker">
192
200
  <input style={{ ...field(ui), marginBottom: "8px" }} placeholder={t("history.search")} accessibility-label={t("history.search")} bindinput={(e) => typed(e.detail.value)}/>
193
201
  {failed ? <text style={{ color: tok(ui, "danger", "#b42318") }} text-maxline="2">{t("error.network")}</text> : null}
194
- {items !== null && items.length === 0 && !failed ? <Empty /> : (items ?? []).map((p) => <Button key={p.id} label={p.label} onTap={() => props.onPick(p)}/>)}
202
+ {items !== null && items.length === 0 && !failed ? <Empty words={t("routine.none_found")}/> : (items ?? []).map((p) => <Button key={p.id} label={p.label} onTap={() => props.onPick(p)}/>)}
195
203
  </view>
196
204
  </Dialog>);
197
205
  });
@@ -286,7 +294,7 @@ function RoutineForm(props) {
286
294
  {r.slots.map((s) => {
287
295
  const flag = wrong.has(s.name) ? "routine.invalid" : tried && missing.has(s.name) ? "routine.missing" : null;
288
296
  return (<view key={s.name} className="g9a-routine-slot" style={{ marginBottom: "8px" }}>
289
- <text style={{ fontSize: "13px", color: tok(ui, "muted", "#6b6660") }} text-maxline="1">{s.name}</text>
297
+ <text style={{ ...startText(ui), fontSize: "13px", color: tok(ui, "muted", "#6b6660") }} text-maxline="1">{slotLabel(t, s.name)}</text>
290
298
  {s.field === "pick" ? (<view style={rowOf(ui, "8px")}>
291
299
  <view style={grow}><text text-maxline="1">{picked.get(s.name)?.label ?? "—"}</text></view>
292
300
  <Button label={t("routine.choose")} onTap={() => setPicking(s)}/>
@@ -303,7 +311,7 @@ function RoutineForm(props) {
303
311
  {p.steps.map((s) => <text key={s.index} className={cls(ui, "card.approval.step")} text-maxline="2">{String(s.index) + ". " + s.text + (s.undoable ? "" : " (" + t("card.irreversible") + ")")}</text>)}
304
312
  {p.answered === null ? (<view>
305
313
  {needsCode(p.method) ? <view className={cls(ui, "card.approval.code")}><PinPad key={epoch} label={t("card.code")} onInput={(v) => { code.current = v; }}/></view> : null}
306
- {p.failCode === "confirm.waiting" ? <text>{t("card.waiting")}</text> : p.failCode ? <text text-maxline="2">{p.failCode + (p.triesLeft !== null ? " · " + t("card.tries_left", { count: p.triesLeft }) : "")}</text> : null}
314
+ {p.failCode === "confirm.waiting" ? <text>{t("card.waiting")}</text> : p.failCode ? <text text-maxline="2">{t(p.failCode) + (p.triesLeft !== null ? " · " + t("card.tries_left", { count: p.triesLeft }) : "")}</text> : null}
307
315
  <view style={rowOf(ui, "8px")}>
308
316
  <Button part="card.approval.confirm" primary label={t("card.confirm")} onTap={() => void run()}/>
309
317
  <Button part="card.approval.refuse" label={t("card.refuse")} onTap={() => setPending(null)}/>
@@ -315,15 +323,16 @@ function RoutineForm(props) {
315
323
  </view>);
316
324
  }
317
325
  /** The routines the person may run; choosing one opens its form. */
318
- function RoutineBody() {
326
+ function RoutineBody(props) {
319
327
  const ui = useUi();
328
+ const t = pageTexts(ui.texts).t;
320
329
  const [list, setList] = useState(null);
321
330
  const [failed, setFailed] = useState(false);
322
331
  const [chosen, setChosen] = useState(null);
323
332
  useEffect(() => { pageCalls.routines(ui.assistant.api).then((r) => { setList(readRoutines(r)); setFailed(false); }, () => { setList([]); setFailed(true); }); }, []);
324
- return (<Frame failed={failed}>
333
+ return (<Frame failed={failed} flow={props.flow}>
325
334
  {chosen ? <RoutineForm key={chosen.id} routine={chosen} onBack={() => setChosen(null)}/>
326
- : list === null ? null : list.length === 0 ? <Empty /> : list.map((r) => <Button key={r.id} label={r.title} onTap={() => setChosen(r)}/>)}
335
+ : list === null ? null : list.length === 0 ? <Empty words={t("routine.empty")}/> : list.map((r) => <Button key={r.id} label={r.title} onTap={() => setChosen(r)}/>)}
327
336
  </Frame>);
328
337
  }
329
338
  const pageOf = (name, kind) => swappable(name, (props) => <Page {...props} kind={kind}/>);
package/dist/parts.jsx CHANGED
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { useEffect, useState } from "@lynx-js/react";
7
7
  import { arr, blockView, can, finished, needsCode, obj, parseText, str, visibleText, LONG_RUNNING_MS, REVEAL_MS, windowView } from "@g9tm/aiassistant";
8
- import { saveCsv } from "@g9tm/aiassistant/pages";
8
+ import { pageTexts, saveCsv } from "@g9tm/aiassistant/pages";
9
9
  import { Chart } from "./chart.jsx";
10
10
  import { blockOverride, cls, fill, override, rowOf, swappable, tok, useUi } from "./context.jsx";
11
11
  import { Button, field, PinPad, SecretField } from "./slots.jsx";
@@ -135,7 +135,7 @@ export function ApprovalCard(props) {
135
135
  </view>))}
136
136
  {p.answered === null ? (<view>
137
137
  {needsCode(p.method) ? <view className={cls(ui, "card.approval.code")}><PinPad key={epoch} label={t("card.code")} onInput={setCode}/></view> : null}
138
- {p.failCode === "confirm.waiting" ? <text>{t("card.waiting")}</text> : p.failCode ? <text>{p.failCode}{p.triesLeft !== null ? " · " + t("card.tries_left", { count: p.triesLeft }) : ""}</text> : null}
138
+ {p.failCode === "confirm.waiting" ? <text>{t("card.waiting")}</text> : p.failCode ? <text>{pageTexts(ui.texts).t(p.failCode)}{p.triesLeft !== null ? " · " + t("card.tries_left", { count: p.triesLeft }) : ""}</text> : null}
139
139
  <view style={rowOf(ui)}>
140
140
  <Button part="card.approval.confirm" primary label={t("card.confirm")} onTap={() => void confirm()}/>
141
141
  <Button part="card.approval.refuse" label={t("card.refuse")} onTap={() => void ui.assistant.refuse(p.id)}/>
package/dist/slots.d.ts CHANGED
@@ -7,6 +7,7 @@ import type { PartName } from "@g9tm/aiassistant";
7
7
  import type { LynxUi } from "./context.jsx";
8
8
  /** A Lynx input has no size of its own (on a device it is drawn zero high): every input of the renderer gets one. */
9
9
  export declare function field(ui: LynxUi): {
10
+ readonly textAlign: "left" | "right";
10
11
  readonly height: "40px";
11
12
  readonly fontSize: "15px";
12
13
  readonly paddingLeft: "10px";
package/dist/slots.jsx CHANGED
@@ -3,11 +3,11 @@
3
3
  * of AssistantRoot), so a host gives its design kit's pieces and the library draws with them everywhere.
4
4
  */
5
5
  import { useRef, useState } from "@lynx-js/react";
6
- import { cls, fill, rowOf, swappable, tok, useUi } from "./context.jsx";
6
+ import { cls, fill, rowOf, swappable, tok, useUi, startText } from "./context.jsx";
7
7
  /** A Lynx input has no size of its own (on a device it is drawn zero high): every input of the renderer gets one. */
8
8
  export function field(ui) {
9
9
  return { height: "40px", fontSize: "15px", paddingLeft: "10px", paddingRight: "10px", borderWidth: "1px", borderStyle: "solid", borderRadius: "8px",
10
- borderColor: tok(ui, "border", "#d0d0d0"), color: tok(ui, "ink", "#111"), backgroundColor: tok(ui, "field", "#fff") };
10
+ borderColor: tok(ui, "border", "#d0d0d0"), color: tok(ui, "ink", "#111"), backgroundColor: tok(ui, "field", "#fff"), ...startText(ui) };
11
11
  }
12
12
  export const Button = swappable("Button", (props) => {
13
13
  const ui = useUi();
@@ -13,6 +13,13 @@ export declare function AssistantRoot(props: {
13
13
  components?: Overrides;
14
14
  children: ReactNode;
15
15
  }): import("@lynx-js/react").JSX.Element;
16
+ /** Above this many messages the list recycles its rows (a long history); below, one column that grows with them. */
17
+ export declare const RECYCLE_FROM = 80;
18
+ /**
19
+ * The conversation: one column of messages, the answer still growing inside it as the last one, scrolled to the end
20
+ * when a message comes or grows (asked twice: charts and pictures settle late). A long history (RECYCLE_FROM and more)
21
+ * uses the recycled list with the growing answer drawn below it.
22
+ */
16
23
  export declare function MessageList(props: {
17
24
  messages: MessageView[];
18
25
  plans: ReadonlyMap<string, PlanView>;
package/dist/surfaces.jsx CHANGED
@@ -4,7 +4,8 @@
4
4
  * measurement does not break.
5
5
  */
6
6
  import { useEffect, useState } from "@lynx-js/react";
7
- import { formatNumber, obj, pickLayout, str } from "@g9tm/aiassistant";
7
+ import { formatNumber, obj, pickLayout, str, timer } from "@g9tm/aiassistant";
8
+ import { loadHostTexts, withHostTexts } from "@g9tm/aiassistant/pages";
8
9
  import { cls, fill, override, rowOf, swappable, tok, UiProvider, useSnapshot, useUi } from "./context.jsx";
9
10
  import { Composer, Message, Small, WorkCard } from "./parts.jsx";
10
11
  import { Button, field } from "./slots.jsx";
@@ -14,15 +15,46 @@ const DARK = { ...LIGHT, "surface": "#1d1b19", "surface-2": "#272421", "ink": "#
14
15
  export function AssistantRoot(props) {
15
16
  const host = props.assistant.host;
16
17
  const theme = { ...(host.theme.mode === "dark" ? DARK : LIGHT), ...host.theme.tokens };
17
- return (<UiProvider value={{ assistant: props.assistant, texts: props.assistant.texts, styles: props.styles ?? {}, unstyled: props.unstyled ?? false, components: props.components ?? {}, theme, layer: (host.sheetLayer ?? 1000) + 1 }}>
18
+ // The host's server words (its AssistantSetup.Texts), read once: a host key the client does not know shows in words.
19
+ const [own, setOwn] = useState({});
20
+ useEffect(() => { void loadHostTexts(props.assistant).then(setOwn); }, [props.assistant]);
21
+ return (<UiProvider value={{ assistant: props.assistant, texts: withHostTexts(props.assistant.texts, () => own), styles: props.styles ?? {}, unstyled: props.unstyled ?? false, components: props.components ?? {}, theme, layer: (host.sheetLayer ?? 1000) + 1 }}>
18
22
  {props.children}
19
23
  </UiProvider>);
20
24
  }
25
+ /** Above this many messages the list recycles its rows (a long history); below, one column that grows with them. */
26
+ export const RECYCLE_FROM = 80;
27
+ let lists = 0;
28
+ /**
29
+ * The conversation: one column of messages, the answer still growing inside it as the last one, scrolled to the end
30
+ * when a message comes or grows (asked twice: charts and pictures settle late). A long history (RECYCLE_FROM and more)
31
+ * uses the recycled list with the growing answer drawn below it.
32
+ */
21
33
  export function MessageList(props) {
22
34
  const ui = useUi();
23
35
  const Item = override(ui, "Message") ?? Message;
36
+ const [id] = useState(() => "g9a-messages-" + String(++lists));
37
+ const count = props.messages.length;
38
+ const last = props.messages[count - 1];
39
+ const size = last ? last.text.length + last.blocks.length : 0; // the answer still growing changes this
40
+ useEffect(() => {
41
+ if (count === 0 || count >= RECYCLE_FROM || typeof lynx === "undefined" || !lynx?.createSelectorQuery)
42
+ return undefined;
43
+ const end = () => { try {
44
+ lynx?.createSelectorQuery?.().select("#" + id).invoke({ method: "scrollTo", params: { offset: 1000000 } }).exec();
45
+ }
46
+ catch { /* not drawn yet */ } };
47
+ const t = timer(ui.assistant.host);
48
+ const first = t.set(end, 120);
49
+ const second = t.set(end, 600);
50
+ return () => { t.clear(first); t.clear(second); };
51
+ }, [count, size]);
52
+ if (count < RECYCLE_FROM) {
53
+ return (<scroll-view id={id} className={cls(ui, "messages")} scroll-orientation="vertical" style={{ ...fill, minHeight: "0px" }}>
54
+ {props.messages.map((m) => <Item key={m.id} message={m} plans={props.plans} runId={props.runId}/>)}
55
+ </scroll-view>);
56
+ }
24
57
  const settled = props.messages.slice(0, -1);
25
- const last = props.messages[props.messages.length - 1];
26
58
  return (<view className={cls(ui, "messages")} style={{ display: "flex", flexDirection: "column", ...fill, minHeight: 0 }}>
27
59
  <list scroll-orientation="vertical" style={{ ...fill }} list-type="single">
28
60
  {settled.map((m) => (<list-item key={m.id} item-key={m.id}>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@g9tm/aiassistant-lynx",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "ReactLynx 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.2.0"
32
+ "@g9tm/aiassistant": "1.4.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@lynx-js/react": "0.129.2",