@g9tm/aiassistant-lynx 1.6.1 → 1.7.1

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/context.d.ts CHANGED
@@ -47,6 +47,11 @@ export declare function startText(ui: LynxUi): {
47
47
  };
48
48
  /** A theme token (the host's over the defaults), or the fallback. */
49
49
  export declare function tok(ui: LynxUi, name: string, fallback?: string): string;
50
+ /**
51
+ * The theme's text colour for a `text`: Lynx does not pass a colour from a view to its text, so a bare `text` is black —
52
+ * invisible on a dark theme (a host's iPhone: «New conversation», the approval card's steps).
53
+ */
54
+ export declare function inkOf(ui: LynxUi, name?: string): Record<string, string>;
50
55
  export declare function override(ui: LynxUi, name: string): HostComponent | undefined;
51
56
  /**
52
57
  * A component a host can replace by name wherever it is drawn, by the library or by the host's own composition. The
package/dist/context.jsx CHANGED
@@ -41,6 +41,14 @@ export function startText(ui) {
41
41
  export function tok(ui, name, fallback = "") {
42
42
  return ui.unstyled ? fallback : (new Map(Object.entries(ui.theme)).get(name) ?? fallback);
43
43
  }
44
+ /**
45
+ * The theme's text colour for a `text`: Lynx does not pass a colour from a view to its text, so a bare `text` is black —
46
+ * invisible on a dark theme (a host's iPhone: «New conversation», the approval card's steps).
47
+ */
48
+ export function inkOf(ui, name = "ink") {
49
+ const c = tok(ui, name, "");
50
+ return c ? { color: c } : {};
51
+ }
44
52
  export function override(ui, name) {
45
53
  const c = new Map(Object.entries(ui.components)).get(name);
46
54
  return typeof c === "function" ? c : undefined;
package/dist/index.d.ts CHANGED
@@ -9,5 +9,5 @@ export type { ButtonProps } from "./slots.jsx";
9
9
  export type { CsvButtonProps } from "./parts.jsx";
10
10
  export { Abilities, ActionsPage, FindingsPage, History, HistoryRow, KnowledgePage, LearnedPage, Page, RoutineWizard, SlotPicker } from "./pages.jsx";
11
11
  export type { HistoryRowProps, PageKind, PageProps, SlotPickerProps } from "./pages.jsx";
12
- export { cls, fill, override, blockOverride, rowOf, swappable, tok, useSnapshot, useUi, UiProvider } from "./context.jsx";
12
+ export { cls, fill, inkOf, override, blockOverride, rowOf, swappable, tok, useSnapshot, useUi, UiProvider } from "./context.jsx";
13
13
  export type { HostComponent, LynxUi, Overrides } from "./context.jsx";
package/dist/index.js CHANGED
@@ -4,4 +4,4 @@ export { ApprovalCard, BlockView, Cards, Composer, CsvButton, Message, RevealTex
4
4
  export { Chart } from "./chart.jsx";
5
5
  export { Button, Dialog, field, PinPad, SecretField } from "./slots.jsx";
6
6
  export { Abilities, ActionsPage, FindingsPage, History, HistoryRow, KnowledgePage, LearnedPage, Page, RoutineWizard, SlotPicker } from "./pages.jsx";
7
- export { cls, fill, override, blockOverride, rowOf, swappable, tok, useSnapshot, useUi, UiProvider } from "./context.jsx";
7
+ export { cls, fill, inkOf, override, blockOverride, rowOf, swappable, tok, useSnapshot, useUi, UiProvider } from "./context.jsx";
package/dist/parts.jsx CHANGED
@@ -7,7 +7,7 @@ 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
8
  import { pageTexts, saveCsv } from "@g9tm/aiassistant/pages";
9
9
  import { Chart } from "./chart.jsx";
10
- import { blockOverride, cls, fill, override, rowOf, swappable, tok, useUi } from "./context.jsx";
10
+ import { blockOverride, cls, fill, inkOf, override, rowOf, swappable, tok, useUi } from "./context.jsx";
11
11
  import { Button, field, hint, PinPad, SecretField } from "./slots.jsx";
12
12
  const grow = { ...fill, minWidth: 0 };
13
13
  export function TextView(props) {
@@ -79,7 +79,7 @@ export function BlockView(props) {
79
79
  case "callout": return <view className={cls(ui, v.type === "text" ? "block.text" : "block.callout")}><TextView text={v.text}/></view>;
80
80
  case "table":
81
81
  return (<view className={cls(ui, "block.table")}>
82
- {v.title ? <text style={{ fontWeight: "bold" }}>{v.title}</text> : null}
82
+ {v.title ? <text style={{ ...inkOf(ui), fontWeight: "bold" }}>{v.title}</text> : null}
83
83
  {v.asCards || props.compact ? null : <view style={rowOf(ui)}>{v.columns.map((c) => <text key={c.name} style={{ ...grow, fontWeight: "bold" }} text-maxline="1">{c.label}</text>)}</view>}
84
84
  {v.rows.slice(0, open ? v.rows.length : v.shown).map((r, i) => v.asCards || props.compact
85
85
  ? <view key={i} className={cls(ui, "block.table.card")} style={{ padding: "6px 8px", marginBottom: "6px", borderRadius: "6px", backgroundColor: tok(ui, "surface", "#fff") }}>
@@ -97,16 +97,16 @@ export function BlockView(props) {
97
97
  </view>);
98
98
  case "chart":
99
99
  return (<view className={cls(ui, "block.chart")} accessibility-label={v.fallbackText}>
100
- {v.title ? <text style={{ fontWeight: "bold" }}>{v.title}</text> : null}
100
+ {v.title ? <text style={{ ...inkOf(ui), fontWeight: "bold" }}>{v.title}</text> : null}
101
101
  <Chart view={v}/>
102
102
  {v.fewData ? <text style={{ fontSize: "12px" }}>{t("block.few_data")}</text> : null}
103
103
  </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>{k.label}</text><text style={{ fontWeight: "bold" }}>{k.value}</text></view>)}</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>;
105
105
  case "steps": return <view className={cls(ui, "block.steps")}>{v.items.map((s, i) => <text key={i}>{s.text}</text>)}</view>;
106
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>;
107
107
  case "flow": return <text className={cls(ui, "block.flow")}>{v.line}</text>;
108
108
  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>{v.fallbackText}</text>;
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>;
110
110
  default: return <text className={cls(ui, "block.fallback")}>{v.fallbackText}</text>;
111
111
  }
112
112
  }
@@ -126,21 +126,21 @@ export function ApprovalCard(props) {
126
126
  setEpoch((n) => n + 1);
127
127
  };
128
128
  return (<view className={cls(ui, "card.approval")} style={{ padding: "12px", borderRadius: "10px", borderWidth: "1px", borderColor: tok(ui, "approval-card-border", "#8a4b2a") }}>
129
- <text style={{ fontWeight: "bold" }}>{p.readOnly ? t("card.readonly_routine") : p.title}</text>
129
+ <text style={{ ...inkOf(ui), fontWeight: "bold" }}>{p.readOnly ? t("card.readonly_routine") : p.title}</text>
130
130
  {p.warning ? <text style={{ color: tok(ui, "warn", "#a35a00") }}>{t("card.tainted")}</text> : null}
131
131
  {p.steps.map((s) => (<view key={s.index} className={cls(ui, "card.approval.step")} accessibility-element={true} accessibility-label={s.text} bindtap={() => ui.assistant.tick(p.id, s.index)}>
132
- <view style={rowOf(ui)}><text>{s.ticked ? "☑ " : "☐ "}</text><text style={grow}>{s.text}{s.undoable ? "" : " (" + t("card.irreversible") + ")"}</text></view>
133
- {s.facts.map((f, i) => <text key={i} className={cls(ui, "card.approval.fact")} style={{ fontSize: "12px" }}>{say(f.key, f.args)}</text>)}
134
- {s.diff.map((d, i) => <text key={"d" + String(i)} className={cls(ui, "card.approval.fact")} style={{ fontSize: "12px" }}>{say(d.name, d.args) + ": " + (d.before ?? "—") + " ← " + (d.after ?? "—")}</text>)}
132
+ <view style={rowOf(ui)}><text style={inkOf(ui)}>{s.ticked ? "☑ " : "☐ "}</text><text style={{ ...grow, ...inkOf(ui) }}>{s.text}{s.undoable ? "" : " (" + t("card.irreversible") + ")"}</text></view>
133
+ {s.facts.map((f, i) => <text key={i} className={cls(ui, "card.approval.fact")} style={{ ...inkOf(ui), fontSize: "12px" }}>{say(f.key, f.args)}</text>)}
134
+ {s.diff.map((d, i) => <text key={"d" + String(i)} className={cls(ui, "card.approval.fact")} style={{ ...inkOf(ui), fontSize: "12px" }}>{say(d.name, d.args) + ": " + (d.before ?? "—") + " ← " + (d.after ?? "—")}</text>)}
135
135
  </view>))}
136
136
  {p.answered === null ? (<view>
137
137
  {needsCode(p.method) || p.failCode === REMOTE_EXPIRED ? <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>{pageTexts(ui.texts).t(p.failCode)}{p.triesLeft !== null ? " · " + t("card.tries_left", { count: p.triesLeft }) : ""}</text> : null}
138
+ {p.failCode === "confirm.waiting" ? <text style={inkOf(ui)}>{t("card.waiting")}</text> : p.failCode ? <text style={inkOf(ui)}>{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)}/>
142
142
  </view>
143
- </view>) : <text>{t("card.answered")}</text>}
143
+ </view>) : <text style={inkOf(ui)}>{t("card.answered")}</text>}
144
144
  </view>);
145
145
  }
146
146
  export function Message(props) {
@@ -151,7 +151,10 @@ export function Message(props) {
151
151
  const Approval = override(ui, "ApprovalCard") ?? ApprovalCard;
152
152
  const Other = override(ui, "Card") ?? Cards;
153
153
  const plan = m.card?.kind === "plan" ? props.plans.get(m.card.id) : undefined;
154
- return (<view className={cls(ui, "message") + " " + cls(ui, m.role === "user" ? "message.user" : "message.assistant")} style={{ padding: "8px 12px", borderRadius: "10px", marginBottom: "8px", alignSelf: m.role === "user" ? "flex-start" : "flex-end", maxWidth: "88%",
154
+ return (<view className={cls(ui, "message") + " " + cls(ui, m.role === "user" ? "message.user" : "message.assistant")}
155
+ // A card's rows grow from a zero basis: in a bubble sized by its content they had no width and a step's text ran one
156
+ // letter per line (a host's phone). A message with a card takes a definite width.
157
+ style={{ padding: "8px 12px", borderRadius: "10px", marginBottom: "8px", alignSelf: m.role === "user" ? "flex-start" : "flex-end", ...(m.card ? { width: "88%" } : { maxWidth: "88%" }),
155
158
  backgroundColor: m.role === "user" ? tok(ui, "user-bubble", "#f1e9e5") : tok(ui, "surface-2", "#f6f4f1"), opacity: m.pending ? 0.7 : 1 }}>
156
159
  {plan ? <Approval plan={plan}/> : m.card ? <Other card={m.card} runId={props.runId}/> : (<view>
157
160
  {m.text.length > 0 ? <RevealText text={m.text} reveal={reveal}/> : null}
@@ -187,8 +190,8 @@ export function Cards(props) {
187
190
  if (c.kind === "ask" && props.runId) {
188
191
  const runId = props.runId;
189
192
  return (<view className={cls(ui, "card.ask")}>
190
- <text>{str(b["question"])}</text>
191
- {answered ? <text>{t("card.answered")}</text> : (<view>
193
+ <text style={inkOf(ui)}>{str(b["question"])}</text>
194
+ {answered ? <text style={inkOf(ui)}>{t("card.answered")}</text> : (<view>
192
195
  {options.map((o) => <Button key={o} label={o} onTap={() => void ui.assistant.answer(runId, c.id, [o], null)}/>)}
193
196
  {b["secret"] === true ? <SecretField onSubmit={(v) => void ui.assistant.answer(runId, c.id, [], v)}/> : (<view style={rowOf(ui, "8px")}>
194
197
  <view style={grow}><input placeholder-color={hint(ui)} style={{ ...field(ui), width: "100%" }} type="text" accessibility-label={t("ask.send")} bindinput={(e) => setText(e.detail.value)}/></view>
@@ -202,9 +205,9 @@ export function Cards(props) {
202
205
  const learn = c.kind === "learn";
203
206
  const id = str(b["id"], c.id);
204
207
  return (<view className={cls(ui, "card.choice")}>
205
- <text>{learn ? t("learn.ask") : t("routine.ask")}</text>
208
+ <text style={inkOf(ui)}>{learn ? t("learn.ask") : t("routine.ask")}</text>
206
209
  {learn ? <text style={{ color: tok(ui, "muted", "#6b6660") }} text-maxline="6">{str(b["text"])}</text> : list}
207
- {answered ? <text>{t("card.answered")}</text> : (<view style={rowOf(ui)}>
210
+ {answered ? <text style={inkOf(ui)}>{t("card.answered")}</text> : (<view style={rowOf(ui)}>
208
211
  <Button label={t("yes")} onTap={() => void ui.assistant.choose(learn ? "knowledge" : "learned", id, learn ? "accept" : "approve")}/>
209
212
  <Button label={t("no")} onTap={() => void ui.assistant.choose(learn ? "knowledge" : "learned", id, learn ? "refuse" : "retire")}/>
210
213
  </view>)}
@@ -247,7 +250,7 @@ export function WorkCard(props) {
247
250
  return (<view className={cls(ui, "work")} style={{ ...rowOf(ui, "8px"), alignItems: "flex-start", padding: "12px" }}>
248
251
  <ThinkingOrb />
249
252
  <view style={grow}>
250
- <view style={rowOf(ui)}><text style={grow}>{long ? t("work.long") : t("work.title")}</text><text className={cls(ui, "work.elapsed")}>{t("work.elapsed", { seconds })}</text></view>
253
+ <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>
251
254
  <StagesThinking run={r}/>
252
255
  {r.progress ? <text className={cls(ui, "work.progress")} text-maxline="2">{t(r.progress.key, r.progress.args)}</text> : null}
253
256
  {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>)}
@@ -269,7 +272,7 @@ export function Composer(props) {
269
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>
270
273
  <Button part={props.busy ? "composer.stop" : "composer.send"} primary label={props.busy ? t("composer.stop") : t("composer.send")} onTap={async () => { if (props.busy)
271
274
  await ui.assistant.stop();
272
- else if (await ui.assistant.send(text)) {
275
+ else if ((await ui.assistant.ask(text)) !== "refused") {
273
276
  setText("");
274
277
  setEpoch((n) => n + 1);
275
278
  } }}/>
package/dist/surfaces.jsx CHANGED
@@ -6,7 +6,7 @@
6
6
  import { useEffect, useState } from "@lynx-js/react";
7
7
  import { formatNumber, obj, pickLayout, str, timer } from "@g9tm/aiassistant";
8
8
  import { loadHostTexts, withHostTexts } from "@g9tm/aiassistant/pages";
9
- import { cls, fill, override, rowOf, swappable, tok, UiProvider, useSnapshot, useUi } from "./context.jsx";
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";
12
12
  /** Default tokens (light and dark); the host's theme tokens override them. */
@@ -132,8 +132,8 @@ export function AssistantPanel(props) {
132
132
  {/* on a device a text does not grow in a row: a view takes the room, and the link keeps its distance */}
133
133
  <view style={{ ...fill, minWidth: 0 }}><text style={{ fontWeight: "bold" }} text-maxline="1">{props.title ?? t("assistant.name")}</text></view>
134
134
  <PdfDownload />
135
- <view accessibility-element={true} accessibility-label={t("panel.new")} bindtap={() => ui.assistant.fresh()} style={{ marginLeft: "12px", marginRight: "12px" }}><text>{t("panel.new")}</text></view>
136
- {props.onClose ? <view accessibility-element={true} accessibility-label={t("panel.close")} bindtap={props.onClose} style={{ marginLeft: "12px" }}><text>×</text></view> : null}
135
+ <view accessibility-element={true} accessibility-label={t("panel.new")} bindtap={() => ui.assistant.fresh()} style={{ marginLeft: "12px", marginRight: "12px" }}><text style={inkOf(ui, "accent")}>{t("panel.new")}</text></view>
136
+ {props.onClose ? <view accessibility-element={true} accessibility-label={t("panel.close")} bindtap={props.onClose} style={{ marginLeft: "12px" }}><text style={inkOf(ui)}>×</text></view> : null}
137
137
  </view>) : null;
138
138
  if (Sheet) {
139
139
  return (<Sheet open={props.open} onClose={props.onClose} label={props.title ?? t("assistant.name")} layer={ui.layer - 1}>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@g9tm/aiassistant-lynx",
3
- "version": "1.6.1",
3
+ "version": "1.7.1",
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.6.1"
32
+ "@g9tm/aiassistant": "1.7.1"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@lynx-js/react": "0.129.2",