@g9tm/aiassistant-lynx 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.
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Guiding parts for ReactLynx: an open (a page, maybe a control in it), a tour one step at a time, a draft's form and
3
+ * the things an answer named. What opening, lighting a control and a form look like is the host's (`navigate`,
4
+ * `openDraft`, `openEntity`); without them a tour is a numbered list, a draft its label, a name plain text.
5
+ */
6
+ import type { BlockView } from "@g9tm/aiassistant";
7
+ import type { GuideBlockView, TourView } from "@g9tm/aiassistant/pages";
8
+ import type { Part } from "./context.jsx";
9
+ type OpenView = Extract<BlockView, {
10
+ type: "open";
11
+ }>;
12
+ type DraftBlockView = Extract<GuideBlockView, {
13
+ type: "draft";
14
+ }>;
15
+ type EntitiesView = Extract<GuideBlockView, {
16
+ type: "entities";
17
+ }>;
18
+ /** «Open» a page, or «show me» a control in it. Replaceable as `OpenButton`. */
19
+ export declare const OpenButton: Part<{
20
+ view: OpenView;
21
+ }>;
22
+ /**
23
+ * A tour: the steps as a numbered list with «show me step by step»; once started, one step at a time with back and next,
24
+ * each step opening its page and lighting its control through the host. Replaceable as `TourCard`.
25
+ */
26
+ export declare const TourCard: Part<{
27
+ view: TourView;
28
+ at: string;
29
+ }>;
30
+ /** A draft: one button that opens the host's form with its values. Replaceable as `DraftButton`. */
31
+ export declare const DraftButton: Part<{
32
+ view: DraftBlockView;
33
+ }>;
34
+ /** The things an answer named, as buttons that open them (only when the host can). Replaceable as `EntityChips`. */
35
+ export declare const EntityChips: Part<{
36
+ view: EntitiesView;
37
+ }>;
38
+ export {};
package/dist/guide.jsx ADDED
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Guiding parts for ReactLynx: an open (a page, maybe a control in it), a tour one step at a time, a draft's form and
3
+ * the things an answer named. What opening, lighting a control and a form look like is the host's (`navigate`,
4
+ * `openDraft`, `openEntity`); without them a tour is a numbered list, a draft its label, a name plain text.
5
+ */
6
+ import { useEffect, useState } from "@lynx-js/react";
7
+ import { item } from "@g9tm/aiassistant";
8
+ import { guideOf, openPage, pageTexts } from "@g9tm/aiassistant/pages";
9
+ import { cls, inkOf, rowOf, startText, swappable, tok, useUi } from "./context.jsx";
10
+ import { Button } from "./slots.jsx";
11
+ /** «Open» a page, or «show me» a control in it. Replaceable as `OpenButton`. */
12
+ export const OpenButton = swappable("OpenButton", (props) => {
13
+ const ui = useUi();
14
+ const v = props.view;
15
+ const host = ui.assistant.host;
16
+ const name = v.label ?? host.pageName?.(v.pageId) ?? v.fallbackText;
17
+ if (!host.navigate)
18
+ return <text style={inkOf(ui)}>{name}</text>;
19
+ const t = pageTexts(ui.texts).t;
20
+ return <Button part="block.open" role={v.target ? "show" : "open"} label={(v.target ? t("guide.show") : t("guide.open")) + ": " + name} onTap={() => { openPage(host, v); }}/>;
21
+ });
22
+ /**
23
+ * A tour: the steps as a numbered list with «show me step by step»; once started, one step at a time with back and next,
24
+ * each step opening its page and lighting its control through the host. Replaceable as `TourCard`.
25
+ */
26
+ export const TourCard = swappable("TourCard", (props) => {
27
+ const ui = useUi();
28
+ const t = pageTexts(ui.texts).t;
29
+ const guide = guideOf(ui.assistant);
30
+ const [now, setNow] = useState(guide.tour);
31
+ useEffect(() => guide.subscribe(setNow), [guide]);
32
+ const v = props.view;
33
+ const tour = now && now.key === props.at ? now : null;
34
+ const can = typeof ui.assistant.host.navigate === "function";
35
+ const step = tour ? item(tour.steps, tour.index) : undefined;
36
+ return (<view className={cls(ui, "block.tour")} style={{ padding: "8px", borderRadius: tok(ui, "radius-s", "6px"), borderWidth: "1px", borderColor: tok(ui, "line", "#e4ded6") }}>
37
+ {v.title ? <text style={{ ...inkOf(ui), fontWeight: "bold", ...startText(ui) }}>{v.title}</text> : null}
38
+ {tour && step && !tour.done ? (<view className={cls(ui, "block.tour.step")}>
39
+ <text style={{ fontSize: "12px", color: tok(ui, "muted", "#6b6660"), ...startText(ui) }}>{t("tour.step", { n: tour.index + 1, count: tour.steps.length })}</text>
40
+ <text style={{ ...inkOf(ui), ...startText(ui) }}>{step.text}</text>
41
+ <view style={{ ...rowOf(ui, "8px"), marginTop: "6px" }}>
42
+ {tour.index > 0 ? <Button role="tour" label={t("tour.back")} onTap={() => guide.back()}/> : null}
43
+ <Button role="tour" primary label={tour.index < tour.steps.length - 1 ? t("tour.next") : t("tour.done")} onTap={() => guide.next()}/>
44
+ </view>
45
+ </view>) : (<view>
46
+ {v.steps.map((x, i) => (<view key={i} style={{ ...rowOf(ui), alignItems: "flex-start" }}>
47
+ <text style={{ ...inkOf(ui), width: "22px", flexShrink: 0 }}>{String(i + 1) + "."}</text>
48
+ <text style={{ ...inkOf(ui), flexGrow: 1, flexShrink: 1, minWidth: 0, opacity: tour?.done ? 0.6 : 1, ...startText(ui) }}>{x.text}</text>
49
+ </view>))}
50
+ {can && v.steps.some((x) => x.page) ? <Button role="tour" label={t("tour.start")} onTap={() => guide.start(props.at, v)}/> : null}
51
+ </view>)}
52
+ </view>);
53
+ });
54
+ /** A draft: one button that opens the host's form with its values. Replaceable as `DraftButton`. */
55
+ export const DraftButton = swappable("DraftButton", (props) => {
56
+ const ui = useUi();
57
+ const v = props.view;
58
+ const host = ui.assistant.host;
59
+ const label = v.label ?? pageTexts(ui.texts).t("draft.open");
60
+ if (!host.openDraft)
61
+ return <text className={cls(ui, "block.draft")} style={inkOf(ui)}>{v.label ?? v.fallbackText}</text>;
62
+ return (<view className={cls(ui, "block.draft")}>
63
+ <Button part="block.action" role="draft" primary label={label} onTap={() => host.openDraft?.({ kind: v.kind, values: v.values, ...(v.page ? { page: v.page } : {}), ...(v.subject ? { subject: v.subject } : {}), ...(v.label ? { label: v.label } : {}) })}/>
64
+ </view>);
65
+ });
66
+ /** The things an answer named, as buttons that open them (only when the host can). Replaceable as `EntityChips`. */
67
+ export const EntityChips = swappable("EntityChips", (props) => {
68
+ const ui = useUi();
69
+ const open = ui.assistant.host.openEntity;
70
+ if (!open || props.view.items.length === 0)
71
+ return null;
72
+ return (<view className={cls(ui, "block.entities")} style={{ ...rowOf(ui, "6px"), flexWrap: "wrap", marginTop: "4px" }}>
73
+ {props.view.items.map((e) => <Button key={e.kind + ":" + e.id} role="entity" label={e.text} onTap={() => open.call(ui.assistant.host, e)}/>)}
74
+ </view>);
75
+ });
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export { AssistantRoot, AssistantChat, AssistantPanel, MessageList, PdfDownload,
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";
6
+ export { DraftButton, EntityChips, OpenButton, TourCard } from "./guide.jsx";
6
7
  export type { ChartView } from "./chart.jsx";
7
8
  export { Button, Dialog, field, PinPad, SecretField } from "./slots.jsx";
8
9
  export type { ButtonProps } from "./slots.jsx";
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@
2
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
+ export { DraftButton, EntityChips, OpenButton, TourCard } from "./guide.jsx";
5
6
  export { Button, Dialog, field, PinPad, SecretField } from "./slots.jsx";
6
7
  export { Abilities, ActionsPage, FindingsPage, History, HistoryRow, KnowledgePage, LearnedPage, Page, RoutineWizard, SlotPicker } from "./pages.jsx";
7
8
  export { cls, fill, inkOf, override, blockOverride, rowOf, swappable, tok, useSnapshot, useUi, UiProvider } from "./context.jsx";
package/dist/parts.d.ts CHANGED
@@ -5,6 +5,11 @@
5
5
  */
6
6
  import type { AssistantState, MessageView, PlanView, Provenance, RunView } from "@g9tm/aiassistant";
7
7
  import type { Part } from "./context.jsx";
8
+ /**
9
+ * The model's text: paragraphs, and lists as real lists (the marker in its own column, a hanging indent, in the reading
10
+ * direction). The text can be selected (`chat.selectable`, on by default); with selection off and a host `copy`, a long
11
+ * press copies one paragraph or one list.
12
+ */
8
13
  export declare function TextView(props: {
9
14
  text: string;
10
15
  }): import("@lynx-js/react").JSX.Element;
@@ -30,6 +35,7 @@ export declare const CsvButton: Part<CsvButtonProps>;
30
35
  export declare function BlockView(props: {
31
36
  block: unknown;
32
37
  compact?: boolean;
38
+ at?: string;
33
39
  }): import("@lynx-js/react").JSX.Element;
34
40
  export declare function ApprovalCard(props: {
35
41
  plan: PlanView;
@@ -38,6 +44,7 @@ export declare function Message(props: {
38
44
  message: MessageView;
39
45
  plans: ReadonlyMap<string, PlanView>;
40
46
  runId: string | null;
47
+ last?: boolean;
41
48
  }): import("@lynx-js/react").JSX.Element;
42
49
  /** The other cards: undo all (its steps, then what the undo said), a question (options, a field or a secret field), "learn this?" and "make it a routine?". */
43
50
  export declare function Cards(props: {
@@ -58,6 +65,12 @@ export declare const StagesThinking: Part<{
58
65
  export declare function WorkCard(props: {
59
66
  run: RunView;
60
67
  }): import("@lynx-js/react").JSX.Element | null;
68
+ /**
69
+ * The composer: grows with its text up to `chat.maxLines`; with `chat.enterSends` Enter sends (Shift+Enter breaks a line
70
+ * where the platform has one); `/` lists the host's ready requests (`quickRequests`); `@` picks a real thing of the
71
+ * host's kinds (`pickKinds`, searched through `GET pick`) and sends its kind and id with the question. A Lynx input has
72
+ * no value prop, so a new text (an edit, a pick) is drawn by a new key.
73
+ */
61
74
  export declare function Composer(props: {
62
75
  busy: boolean;
63
76
  attachments: {
package/dist/parts.jsx CHANGED
@@ -5,18 +5,31 @@
5
5
  */
6
6
  import { useEffect, useState } from "@lynx-js/react";
7
7
  import { arr, blockView, can, finished, item, LONG_RUNNING_MS, needsCode, obj, parseText, REMOTE_EXPIRED, REVEAL_MS, str, visibleText, windowView } from "@g9tm/aiassistant";
8
- import { pageTexts, saveCsv } from "@g9tm/aiassistant/pages";
8
+ import { askAgain, atWord, blockText, chatOf, composerOf, editLast, guideBlock, matchQuick, pageTexts, pickRefs, putPick, refsIn, saveCsv, slashQuery, statusOf, tableText } from "@g9tm/aiassistant/pages";
9
9
  import { Chart } from "./chart.jsx";
10
- import { blockOverride, cls, fill, inkOf, override, rowOf, swappable, tok, useUi } from "./context.jsx";
10
+ import { blockOverride, cls, fill, inkOf, override, rowOf, startText, swappable, tok, useUi } from "./context.jsx";
11
11
  import { Button, field, hint, PinPad, SecretField } from "./slots.jsx";
12
+ import { DraftButton, EntityChips, OpenButton, TourCard } from "./guide.jsx";
12
13
  const grow = { ...fill, minWidth: 0 };
14
+ /**
15
+ * The model's text: paragraphs, and lists as real lists (the marker in its own column, a hanging indent, in the reading
16
+ * direction). The text can be selected (`chat.selectable`, on by default); with selection off and a host `copy`, a long
17
+ * press copies one paragraph or one list.
18
+ */
13
19
  export function TextView(props) {
14
20
  const ui = useUi();
15
- const line = (xs) => xs.map((x, i) => (<text key={i} style={x.kind === "bold" ? { fontWeight: "bold" } : x.kind === "code" ? { fontFamily: "monospace" } : x.kind === "link" && x.href ? { color: tok(ui, "accent", "#8a4b2a") } : {}} {...(x.kind === "link" && x.href ? { bindtap: () => ui.assistant.host.openUrl?.(x.href ?? "") } : {})}>{x.text}</text>));
21
+ const host = ui.assistant.host;
22
+ const select = chatOf(ui.assistant).selectable;
23
+ const ink = { color: tok(ui, "ink", "#22201d"), ...startText(ui) };
24
+ const line = (xs) => xs.map((x, i) => (<text key={i} style={x.kind === "bold" ? { fontWeight: "bold" } : x.kind === "code" ? { fontFamily: "monospace" } : x.kind === "link" && x.href ? { color: tok(ui, "accent", "#8a4b2a") } : {}} {...(x.kind === "link" && x.href ? { bindtap: () => host.openUrl?.(x.href ?? "") } : {})}>{x.text}</text>));
25
+ const copy = (b) => (!select && chatOf(ui.assistant).copyParts && host.copy ? { bindlongpress: () => { void host.copy?.(blockText(b)); host.haptic?.("tick"); } } : {});
16
26
  return (<view>
17
- {parseText(props.text, ui.assistant.host.linkHosts ?? []).map((b, i) => b.kind === "paragraph"
18
- ? <text key={i} style={{ color: tok(ui, "ink", "#22201d"), marginBottom: "6px" }}>{line(b.inlines)}</text>
19
- : <view key={i}>{b.items.map((it, n) => <text key={n}>{b.ordered ? String(n + 1) + ". " : "• "}{line(it)}</text>)}</view>)}
27
+ {parseText(props.text, host.linkHosts ?? []).map((b, i) => b.kind === "paragraph"
28
+ ? <text key={i} text-selection={select} style={{ ...ink, marginBottom: "6px" }} {...copy(b)}>{line(b.inlines)}</text>
29
+ : <view key={i} className="g9a-list" style={{ marginBottom: "6px" }} {...copy(b)}>{b.items.map((it, n) => (<view key={n} style={{ ...rowOf(ui), alignItems: "flex-start" }}>
30
+ <text style={{ ...ink, width: b.ordered ? "24px" : "16px", flexShrink: 0 }}>{b.ordered ? String(n + 1) + "." : "•"}</text>
31
+ <text text-selection={select} style={{ ...ink, ...grow }}>{line(it)}</text>
32
+ </view>))}</view>)}
20
33
  </view>);
21
34
  }
22
35
  export function RevealText(props) {
@@ -71,6 +84,13 @@ export function BlockView(props) {
71
84
  const t = ui.texts.t;
72
85
  const v = blockView(props.block, ui.texts.locale, ui.assistant.customBlocks);
73
86
  const [open, setOpen] = useState(false);
87
+ const g = guideBlock(props.block);
88
+ if (g) {
89
+ const OwnGuide = blockOverride(ui, g.type);
90
+ if (OwnGuide)
91
+ return <OwnGuide view={g} block={props.block} compact={props.compact ?? false}/>;
92
+ return g.type === "tour" ? <TourCard view={g} at={props.at ?? "tour"}/> : g.type === "draft" ? <DraftButton view={g}/> : <EntityChips view={g}/>;
93
+ }
74
94
  const Own = blockOverride(ui, v.type === "custom" ? v.name : v.type);
75
95
  if (Own)
76
96
  return <Own view={v} block={props.block} compact={props.compact ?? false}/>;
@@ -87,7 +107,10 @@ export function BlockView(props) {
87
107
  </view>
88
108
  : <view key={i} style={rowOf(ui)}>{r.map((c, j) => <text key={j} style={grow} text-maxline="1">{c}</text>)}</view>)}
89
109
  {v.more > 0 && !open ? <Button label={t("block.more_rows", { count: v.more })} onTap={() => setOpen(true)}/> : null}
90
- <CsvButton title={v.title} labels={v.columns.map((c) => c.label)} rows={v.rows}/>
110
+ <view style={rowOf(ui, "8px")}>
111
+ <CsvButton title={v.title} labels={v.columns.map((c) => c.label)} rows={v.rows}/>
112
+ {chatOf(ui.assistant).copyParts && ui.assistant.host.copy ? <Button role="copy" label={pageTexts(ui.texts).t("copy.table")} onTap={() => void ui.assistant.host.copy?.(tableText(v.columns.map((c) => c.label), v.rows))}/> : null}
113
+ </view>
91
114
  </view>);
92
115
  case "export":
93
116
  return (<view className="g9a-block-export">
@@ -101,12 +124,12 @@ export function BlockView(props) {
101
124
  <Chart view={v}/>
102
125
  {v.fewData ? <text style={{ fontSize: "12px" }}>{t("block.few_data")}</text> : null}
103
126
  </view>);
104
- case "kpi": return <view className={cls(ui, "block.kpi")} style={{ ...rowOf(ui), flexWrap: "wrap" }}>{v.items.map((k, i) => <view key={i} style={{ marginRight: "8px" }}><text style={inkOf(ui)}>{k.label}</text><text style={{ ...inkOf(ui), fontWeight: "bold" }}>{k.value}</text></view>)}</view>;
127
+ case "kpi": return <view className={cls(ui, "block.kpi")} style={{ ...rowOf(ui), flexWrap: "wrap" }}>{v.items.map((k, i) => <view key={i} style={{ marginRight: "8px" }}><text style={inkOf(ui)}>{k.label}</text><text text-selection={chatOf(ui.assistant).selectable} style={{ ...inkOf(ui), fontWeight: "bold" }} {...(chatOf(ui.assistant).copyParts && ui.assistant.host.copy ? { bindlongpress: () => { void ui.assistant.host.copy?.(k.value); ui.assistant.host.haptic?.("tick"); } } : {})}>{k.value}</text></view>)}</view>;
105
128
  case "steps": return <view className={cls(ui, "block.steps")}>{v.items.map((s, i) => <text key={i}>{s.text}</text>)}</view>;
106
- case "actions": return <view className={cls(ui, "block.actions")} style={{ ...rowOf(ui), flexWrap: "wrap" }}>{v.items.map((a, i) => <Button key={i} part="block.action" label={a.label + (a.suggested ? " · " + t("block.suggested") : "")} onTap={() => void ui.assistant.send(a.send)}/>)}</view>;
129
+ case "actions": return <view className={cls(ui, "block.actions")} style={{ ...rowOf(ui), flexWrap: "wrap" }}>{v.items.map((a, i) => <Button key={i} part="block.action" role="action" label={a.label + (a.suggested ? " · " + t("block.suggested") : "")} onTap={() => void ui.assistant.send(a.send)}/>)}</view>;
107
130
  case "flow": return <text className={cls(ui, "block.flow")}>{v.line}</text>;
108
131
  case "image": return <view className={cls(ui, "block.image")}>{v.fileIds.map((id) => <image key={id} src={"/api/assistant/files/" + encodeURIComponent(id)} style={{ width: "100%", height: "200px" }} mode="aspectFit"/>)}</view>;
109
- case "open": return ui.assistant.host.navigate ? <Button part="block.open" label={ui.assistant.host.pageName?.(v.pageId) ?? v.fallbackText} onTap={() => ui.assistant.host.navigate?.(v.pageId)}/> : <text style={inkOf(ui)}>{v.fallbackText}</text>;
132
+ case "open": return <OpenButton view={v}/>;
110
133
  default: return <text className={cls(ui, "block.fallback")}>{v.fallbackText}</text>;
111
134
  }
112
135
  }
@@ -158,12 +181,14 @@ export function Message(props) {
158
181
  backgroundColor: m.role === "user" ? tok(ui, "user-bubble", "#f1e9e5") : tok(ui, "surface-2", "#f6f4f1"), opacity: m.pending ? 0.7 : 1 }}>
159
182
  {plan ? <Approval plan={plan}/> : m.card ? <Other card={m.card} runId={props.runId}/> : (<view>
160
183
  {m.text.length > 0 ? <RevealText text={m.text} reveal={reveal}/> : null}
161
- {m.blocks.map((b, i) => <BlockView key={i} block={b}/>)}
162
- {m.next.length > 0 ? <view className={cls(ui, "block.actions")} style={{ ...rowOf(ui), flexWrap: "wrap" }}>{m.next.map((n) => <Button key={n} part="block.action" label={n} onTap={() => void ui.assistant.send(n)}/>)}</view> : null}
163
- {m.role === "assistant" ? (<view className={cls(ui, "message.feedback")} style={rowOf(ui)}>
184
+ {m.blocks.map((b, i) => <BlockView key={i} block={b} at={m.id + ":" + String(i)}/>)}
185
+ {m.next.length > 0 ? <view className={cls(ui, "block.actions")} style={{ ...rowOf(ui), flexWrap: "wrap" }}>{m.next.map((n) => <Button key={n} part="block.action" role="next" label={n} onTap={() => void ui.assistant.send(n)}/>)}</view> : null}
186
+ {m.role === "assistant" ? (<view className={cls(ui, "message.feedback")} style={{ ...rowOf(ui, "6px"), flexWrap: "wrap" }}>
164
187
  <Small kind="provenance" provenance={m.provenance}/>
165
- {ui.assistant.host.copy ? <Button label={t("feedback.copy")} onTap={() => void ui.assistant.host.copy?.(m.text)}/> : null}
166
- {m.provenance === "learned" ? <Button label={t("feedback.not_right")} onTap={() => void ui.assistant.notRight(m.id)}/> : null}
188
+ {ui.assistant.host.copy ? <Button role="copy" label={t("feedback.copy")} onTap={() => void ui.assistant.host.copy?.(m.text)}/> : null}
189
+ {m.provenance === "learned" ? <Button role="feedback" label={t("feedback.not_right")} onTap={() => void ui.assistant.notRight(m.id)}/> : null}
190
+ {props.last && chatOf(ui.assistant).again && !m.pending && !m.card ? <Button role="again" label={pageTexts(ui.texts).t("message.again")} onTap={() => void askAgain(ui.assistant)}/> : null}
191
+ {props.last && chatOf(ui.assistant).again && !m.pending && !m.card ? <Button role="edit" label={pageTexts(ui.texts).t("message.edit")} onTap={() => editLast(ui.assistant)}/> : null}
167
192
  </view>) : null}
168
193
  </view>)}
169
194
  </view>);
@@ -251,31 +276,83 @@ export function WorkCard(props) {
251
276
  <ThinkingOrb />
252
277
  <view style={grow}>
253
278
  <view style={rowOf(ui)}><text style={{ ...grow, ...inkOf(ui) }}>{long ? t("work.long") : t("work.title")}</text><text className={cls(ui, "work.elapsed")}>{t("work.elapsed", { seconds })}</text></view>
279
+ {chatOf(ui.assistant).status && statusOf(r) ? <text className={cls(ui, "work.status")} style={inkOf(ui)} text-maxline="1">{pageTexts(ui.texts).t("work.status", { what: t(statusOf(r)?.key ?? "", statusOf(r)?.args) })}</text> : null}
254
280
  <StagesThinking run={r}/>
255
281
  {r.progress ? <text className={cls(ui, "work.progress")} text-maxline="2">{t(r.progress.key, r.progress.args)}</text> : null}
256
282
  {r.tools.slice(-3).map((x, i) => <text key={i} className={cls(ui, "work.tool")} style={{ fontSize: "12px", color: tok(ui, "muted", "#6b6660") }} text-maxline="1">{t(x.title.key) === x.title.key ? x.name : t(x.title.key)}</text>)}
257
283
  {r.streamingText ? <text className="g9a-stream" text-maxline="4">{r.streamingText}</text> : null}
258
284
  </view>
259
- <Button part="composer.stop" label={t("composer.stop")} onTap={() => void ui.assistant.stop()}/>
285
+ <Button part="composer.stop" role="stop" label={t("composer.stop")} onTap={() => void ui.assistant.stop()}/>
260
286
  </view>);
261
287
  }
288
+ /**
289
+ * The composer: grows with its text up to `chat.maxLines`; with `chat.enterSends` Enter sends (Shift+Enter breaks a line
290
+ * where the platform has one); `/` lists the host's ready requests (`quickRequests`); `@` picks a real thing of the
291
+ * host's kinds (`pickKinds`, searched through `GET pick`) and sends its kind and id with the question. A Lynx input has
292
+ * no value prop, so a new text (an edit, a pick) is drawn by a new key.
293
+ */
262
294
  export function Composer(props) {
263
295
  const ui = useUi();
264
296
  const t = ui.texts.t;
265
297
  const host = ui.assistant.host;
266
- const [text, setText] = useState("");
267
- const [epoch, setEpoch] = useState(0); // a Lynx input has no value prop: a new key clears it
298
+ const box = composerOf(ui.assistant);
299
+ const [text, setText] = useState(box.value.text);
300
+ const [epoch, setEpoch] = useState(0);
301
+ const [refs, setRefs] = useState([]);
302
+ const [quick, setQuick] = useState([]);
303
+ const [found, setFound] = useState([]);
304
+ useEffect(() => box.subscribe((c) => { setText(c.text); setEpoch((n) => n + 1); }), [box]);
305
+ const lines = chatOf(ui.assistant).maxLines;
306
+ const slash = host.quickRequests ? slashQuery(text) : null;
307
+ useEffect(() => {
308
+ if (slash === null) {
309
+ setQuick([]);
310
+ return;
311
+ }
312
+ void Promise.resolve(host.quickRequests?.() ?? []).then((all) => setQuick(matchQuick(all, slash)));
313
+ }, [slash]);
314
+ const word = host.pickKinds && host.pickKinds.length > 0 ? atWord(text) : null;
315
+ useEffect(() => {
316
+ if (word === null) {
317
+ setFound([]);
318
+ return;
319
+ }
320
+ let live = true;
321
+ void Promise.all((host.pickKinds ?? []).map((k) => pickRefs(ui.assistant.api, k, word))).then((xs) => { if (live)
322
+ setFound(xs.flat().slice(0, 8)); });
323
+ return () => { live = false; };
324
+ }, [word]);
325
+ const redraw = (next) => { setText(next); setEpoch((n) => n + 1); };
326
+ const send = async () => {
327
+ if (props.busy) {
328
+ await ui.assistant.stop();
329
+ return;
330
+ }
331
+ const used = refsIn(text, refs);
332
+ if ((await ui.assistant.ask(text, undefined, used)) !== "refused") {
333
+ setRefs([]);
334
+ redraw("");
335
+ }
336
+ };
337
+ const pickOne = (r) => {
338
+ setRefs([...refs.filter((x) => x.kind !== r.kind || x.id !== r.id), r]);
339
+ redraw(putPick(text, r));
340
+ };
341
+ const field1 = { ...field(ui), width: "100%" };
268
342
  return (<view className={cls(ui, "composer")} style={{ padding: "12px" }}>
269
343
  {props.attachments.length > 0 ? <view className={cls(ui, "file-chips")} style={{ ...rowOf(ui), flexWrap: "wrap" }}>{props.attachments.map((a) => <Button key={a.id} part="file-chip" label={a.name + " ×"} onTap={() => ui.assistant.detach(a.id)}/>)}</view> : null}
270
- <view style={rowOf(ui)}>
271
- {host.pickFile || host.uploadFile ? <Button part="composer.attach" label={t("composer.attach")} onTap={() => ui.assistant.attachFromDevice()}/> : null}
272
- <view style={{ ...grow, marginLeft: "8px", marginRight: "8px" }}><input placeholder-color={hint(ui)} key={epoch} className={cls(ui, "composer.input")} style={{ ...field(ui), width: "100%" }} placeholder={t("composer.placeholder")} accessibility-label={t("composer.placeholder")} bindinput={(e) => setText(e.detail.value)}/></view>
273
- <Button part={props.busy ? "composer.stop" : "composer.send"} primary label={props.busy ? t("composer.stop") : t("composer.send")} onTap={async () => { if (props.busy)
274
- await ui.assistant.stop();
275
- else if ((await ui.assistant.ask(text)) !== "refused") {
276
- setText("");
277
- setEpoch((n) => n + 1);
278
- } }}/>
344
+ {quick.length > 0 || found.length > 0 ? (<view className={cls(ui, "composer.menu")} style={{ ...rowOf(ui, "6px"), flexWrap: "wrap", marginBottom: "6px" }}>
345
+ {quick.map((q) => <Button key={"q" + q.label} role="quick" label={q.label} onTap={() => { redraw(""); void ui.assistant.ask(q.send); }}/>)}
346
+ {found.map((r) => <Button key={"p" + r.kind + r.id} role="pick" label={r.label} onTap={() => pickOne(r)}/>)}
347
+ </view>) : null}
348
+ <view style={{ ...rowOf(ui), alignItems: "flex-end" }}>
349
+ {host.pickFile || host.uploadFile ? <Button part="composer.attach" role="attach" label={t("composer.attach")} onTap={() => ui.assistant.attachFromDevice()}/> : null}
350
+ <view style={{ ...grow, marginLeft: "8px", marginRight: "8px" }}>
351
+ {lines > 1
352
+ ? <textarea key={epoch} default-value={text} maxlines={lines} placeholder-color={hint(ui)} className={cls(ui, "composer.input")} style={{ ...field1, height: "auto", minHeight: "40px", paddingTop: "9px", paddingBottom: "9px" }} placeholder={t("composer.placeholder")} accessibility-label={t("composer.placeholder")} {...(chatOf(ui.assistant).enterSends === true ? { "confirm-type": "send", bindconfirm: () => void send() } : {})} bindinput={(e) => setText(e.detail.value)}/>
353
+ : <input key={epoch} default-value={text} placeholder-color={hint(ui)} className={cls(ui, "composer.input")} style={field1} placeholder={t("composer.placeholder")} accessibility-label={t("composer.placeholder")} {...(chatOf(ui.assistant).enterSends === true ? { "confirm-type": "send", bindconfirm: () => void send() } : {})} bindinput={(e) => setText(e.detail.value)}/>}
354
+ </view>
355
+ <Button part={props.busy ? "composer.stop" : "composer.send"} role={props.busy ? "stop" : "send"} primary label={props.busy ? t("composer.stop") : t("composer.send")} onTap={() => void send()}/>
279
356
  </view>
280
357
  </view>);
281
358
  }
package/dist/slots.d.ts CHANGED
@@ -3,7 +3,7 @@
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 type { ReactNode } from "@lynx-js/react";
6
- import type { PartName } from "@g9tm/aiassistant";
6
+ import type { ButtonRole, PartName } from "@g9tm/aiassistant";
7
7
  import type { LynxUi } from "./context.jsx";
8
8
  /** An input's placeholder colour: Lynx's own grey is nearly invisible on a dark theme, so it follows the theme's `muted`. */
9
9
  export declare function hint(ui: LynxUi): string;
@@ -21,11 +21,13 @@ export declare function field(ui: LynxUi): {
21
21
  readonly color: string;
22
22
  readonly backgroundColor: string;
23
23
  };
24
+ /** A button: its part (where it sits) and its role (what it is for), so a host's own Button draws each its own way. */
24
25
  export interface ButtonProps {
25
26
  label: string;
26
27
  onTap: () => void;
27
28
  primary?: boolean;
28
29
  part?: PartName;
30
+ role?: ButtonRole;
29
31
  }
30
32
  export declare const Button: import("./context.jsx").Part<ButtonProps>;
31
33
  /** The code field of an approval: what is typed goes to onInput; a new key clears it (a Lynx input has no value prop). */
@@ -17,8 +17,9 @@ export declare function AssistantRoot(props: {
17
17
  export declare const RECYCLE_FROM = 80;
18
18
  /**
19
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.
20
+ * when a message comes or grows (asked twice: charts and pictures settle late) — unless the person scrolled up to read:
21
+ * then the view stays where they are and a «to the newest» button appears. It fills what its parent gives it (no pixel
22
+ * height of its own). A long history (RECYCLE_FROM and more) uses the recycled list with the growing answer drawn below it.
22
23
  */
23
24
  export declare function MessageList(props: {
24
25
  messages: MessageView[];
package/dist/surfaces.jsx CHANGED
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { useEffect, useState } from "@lynx-js/react";
7
7
  import { formatNumber, obj, pickLayout, str, timer } from "@g9tm/aiassistant";
8
- import { loadHostTexts, withHostTexts } from "@g9tm/aiassistant/pages";
8
+ import { loadHostTexts, pageTexts, withHostTexts } from "@g9tm/aiassistant/pages";
9
9
  import { cls, fill, inkOf, override, rowOf, swappable, tok, UiProvider, useSnapshot, useUi } from "./context.jsx";
10
10
  import { Composer, Message, Small, WorkCard } from "./parts.jsx";
11
11
  import { Button, field, hint } from "./slots.jsx";
@@ -27,32 +27,46 @@ export const RECYCLE_FROM = 80;
27
27
  let lists = 0;
28
28
  /**
29
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.
30
+ * when a message comes or grows (asked twice: charts and pictures settle late) — unless the person scrolled up to read:
31
+ * then the view stays where they are and a «to the newest» button appears. It fills what its parent gives it (no pixel
32
+ * height of its own). A long history (RECYCLE_FROM and more) uses the recycled list with the growing answer drawn below it.
32
33
  */
33
34
  export function MessageList(props) {
34
35
  const ui = useUi();
35
36
  const Item = override(ui, "Message") ?? Message;
36
37
  const [id] = useState(() => "g9a-messages-" + String(++lists));
38
+ const [atEnd, setAtEnd] = useState(true);
39
+ const [missed, setMissed] = useState(false);
40
+ const [top, setTop] = useState(0);
37
41
  const count = props.messages.length;
38
42
  const last = props.messages[count - 1];
39
43
  const size = last ? last.text.length + last.blocks.length : 0; // the answer still growing changes this
44
+ const end = () => { try {
45
+ lynx?.createSelectorQuery?.().select("#" + id).invoke({ method: "scrollTo", params: { offset: 1000000 } }).exec();
46
+ }
47
+ catch { /* not drawn yet */ } };
40
48
  useEffect(() => {
41
49
  if (count === 0 || count >= RECYCLE_FROM || typeof lynx === "undefined" || !lynx?.createSelectorQuery)
42
50
  return undefined;
43
- const end = () => { try {
44
- lynx?.createSelectorQuery?.().select("#" + id).invoke({ method: "scrollTo", params: { offset: 1000000 } }).exec();
45
- }
46
- catch { /* not drawn yet */ } };
51
+ if (!atEnd) {
52
+ setMissed(true);
53
+ return undefined;
54
+ } // the person reads above: no jump
47
55
  const t = timer(ui.assistant.host);
48
56
  const first = t.set(end, 120);
49
57
  const second = t.set(end, 600);
50
58
  return () => { t.clear(first); t.clear(second); };
51
59
  }, [count, size]);
52
60
  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>);
61
+ return (<view style={{ ...fill, minHeight: "0px", display: "flex", flexDirection: "column" }}>
62
+ <scroll-view id={id} className={cls(ui, "messages")} scroll-orientation="vertical" style={{ ...fill, minHeight: "0px" }} lower-threshold={48} bindscroll={(e) => { const y = e.detail?.scrollTop ?? 0; if (y < top - 4)
63
+ setAtEnd(false); setTop(y); }} bindscrolltolower={() => { setAtEnd(true); setMissed(false); }}>
64
+ {props.messages.map((m, i) => <Item key={m.id} message={m} plans={props.plans} runId={props.runId} last={i === count - 1 && m.role === "assistant"}/>)}
65
+ </scroll-view>
66
+ {missed && !atEnd ? (<view className={cls(ui, "messages.newest")} style={{ position: "absolute", bottom: "8px", left: "0px", right: "0px", display: "flex", alignItems: "center" }}>
67
+ <Button role="newest" label={pageTexts(ui.texts).t("messages.newest")} onTap={() => { setAtEnd(true); setMissed(false); end(); }}/>
68
+ </view>) : null}
69
+ </view>);
56
70
  }
57
71
  const settled = props.messages.slice(0, -1);
58
72
  return (<view className={cls(ui, "messages")} style={{ display: "flex", flexDirection: "column", ...fill, minHeight: 0 }}>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@g9tm/aiassistant-lynx",
3
- "version": "1.8.2",
3
+ "version": "1.9.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.8.2"
32
+ "@g9tm/aiassistant": "1.9.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@lynx-js/react": "0.129.2",