@g9tm/aiassistant-lynx 0.0.0-stage → 1.1.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/README.md CHANGED
@@ -1,3 +1,47 @@
1
- # Temporary Holding Version
1
+ # @g9tm/aiassistant-lynx
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ReactLynx components for the G9 AI assistant, drawn from the headless client `@g9tm/aiassistant`, with the same part
4
+ names and the same ways to customise as the Svelte package.
5
+
6
+ - Ships its components as JSX (`dist/*.jsx`): the app's own ReactLynx build compiles them, so classes, styles, taps and
7
+ accessibility labels survive. Do not exclude the package from that build.
8
+ - Surfaces and parts: the root, the chat, the panel in its layouts, a recycled message list (the growing answer is drawn
9
+ below it), the composer, the work card, blocks and approval cards.
10
+ - Pages: `History`, `Abilities`, `KnowledgePage`, `LearnedPage`, `FindingsPage`, `RoutineWizard`, `ActionsPage`
11
+ (or `Page` with a `kind`). Small surfaces: `Surfaces` with `kind` `hero`, `bar-button` or `ask-about`.
12
+ - The built-in `Chart`: bars, one or several lines with a legend, and a donut (lines and the donut use the `svg`
13
+ element, Lynx 3.7). `StagesThinking` and `ThinkingOrb` are their own parts.
14
+ - Customising: theme tokens as an object (Lynx has no CSS variables; series colours `chart-1`, `chart-2`...), per-part
15
+ classes and styles, `unstyled`, and replaced components by name. Every slot (`Button`, `PinPad`, `SecretField`,
16
+ `Dialog`, `Sheet`, `Chart`), every page and `Surfaces` can be replaced through `components` of `AssistantRoot`; the
17
+ replacement gets the same props plus the library's own as `Default`.
18
+ - Laid out by the rules a device engine holds: rows reversed for right to left, growth by the long-hand flex
19
+ properties, a size on every input, `display: "flex"` on every container.
20
+ - `@g9tm/aiassistant-lynx/admin`: the manager's page as a separate entry.
21
+
22
+ ```tsx
23
+ import { createAssistant } from "@g9tm/aiassistant";
24
+ import type { AssistantHost } from "@g9tm/aiassistant";
25
+ import { AssistantPanel, AssistantRoot } from "@g9tm/aiassistant-lynx";
26
+
27
+ const SERVER = "https://assistant.example.com";
28
+ const f = fetch; // on a device, fetch is a name in scope, not a property of globalThis
29
+ const host: AssistantHost = {
30
+ locale: "fa", dir: "rtl", theme: { mode: "light", tokens: {} }, reducedMotion: false,
31
+ async fetch(input, init) {
32
+ const r = await f(SERVER + input, { method: init?.method ?? "GET", headers: init?.headers ?? {}, ...(init?.body === undefined ? {} : { body: init.body }) });
33
+ return { status: r.status, ok: r.ok, text: () => r.text() };
34
+ },
35
+ };
36
+ const assistant = createAssistant(host, { sse: false }); // no EventSource on a device: poll
37
+
38
+ export function App() {
39
+ return (
40
+ <AssistantRoot assistant={assistant}>
41
+ <AssistantPanel open={true} layout="fullscreen" width={400} />
42
+ </AssistantRoot>
43
+ );
44
+ }
45
+ ```
46
+
47
+ Part of the G9 AI assistant library. Documentation: see the guides that ship with the library.
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The manager's pages for ReactLynx, a separate entry (`@g9tm/aiassistant-lynx/admin`) only managers
3
+ * load: capabilities (switch, route, rounds, the entry test), usage (the model-free rate, by capability and model, the
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
+ */
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;
package/dist/admin.jsx ADDED
@@ -0,0 +1,162 @@
1
+ /**
2
+ * The manager's pages for ReactLynx, a separate entry (`@g9tm/aiassistant-lynx/admin`) only managers
3
+ * load: capabilities (switch, route, rounds, the entry test), usage (the model-free rate, by capability and model, the
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
+ */
6
+ import { useEffect, useState } from "@lynx-js/react";
7
+ import { AdminClient, adminTexts } from "@g9tm/aiassistant/admin";
8
+ import { cls, fill, rowOf, tok, useUi } from "./context.jsx";
9
+ import { Button } from "./slots.jsx";
10
+ const grow = { ...fill, minWidth: 0 };
11
+ function useAdmin() {
12
+ const ui = useUi();
13
+ const texts = adminTexts(ui.texts);
14
+ return { admin: new AdminClient(ui.assistant.api), t: texts.t };
15
+ }
16
+ function Line(props) {
17
+ const ui = useUi();
18
+ return <text text-maxline="2" style={{ color: props.bad ? tok(ui, "danger", "#b42318") : props.muted ? tok(ui, "muted", "#6b6660") : tok(ui, "ink", "#22201d"), fontSize: "13px" }}>{props.text}</text>;
19
+ }
20
+ function Capabilities() {
21
+ const ui = useUi();
22
+ const { admin, t } = useAdmin();
23
+ const [list, setList] = useState([]);
24
+ const [probes, setProbes] = useState([]);
25
+ const [results, setResults] = useState([]);
26
+ const [failed, setFailed] = useState(false);
27
+ useEffect(() => {
28
+ admin.capabilities().then((r) => { setList(r.capabilities); setProbes(r.probes); }, () => setFailed(true));
29
+ }, []);
30
+ const replace = (c) => setList((xs) => xs.map((x) => (x.id === c.id ? c : x)));
31
+ const change = (c, patch) => {
32
+ admin.setCapability(c.id, patch).then(replace, () => setFailed(true));
33
+ };
34
+ const probeAll = async (model) => {
35
+ setResults([]);
36
+ for (const p of probes) {
37
+ const r = await admin.probe(p, model).catch(() => ({ probe: p, model, quality: "error", rightKind: false, tokensIn: 0, ms: 0, head: null, error: "error.network" }));
38
+ setResults((xs) => [...xs, r]);
39
+ }
40
+ };
41
+ return (<view>
42
+ {failed ? <Line text={t("error.network")} bad/> : null}
43
+ {list.length === 0 && !failed ? <Line text={t("admin.empty")} muted/> : null}
44
+ {list.map((c) => (<view key={c.id} style={{ borderWidth: "1px", borderColor: tok(ui, "line", "#e4ded6"), borderRadius: tok(ui, "radius-s", "6px"), padding: "8px", marginBottom: "8px" }}>
45
+ <view style={rowOf(ui, "6px")}>
46
+ <view style={grow}><Line text={c.id + " · " + c.kind + (c.overridden ? " · " + t("admin.overridden") : "")}/></view>
47
+ <Button label={(c.enabled ? "✓ " : "○ ") + t("admin.enabled")} onTap={() => change(c, { enabled: !c.enabled })}/>
48
+ </view>
49
+ <Line text={t("admin.route") + ": " + c.route.join(" > ")} muted/>
50
+ <view style={rowOf(ui, "6px")}>
51
+ <view style={grow}><Line text={t("admin.max_rounds") + ": " + String(c.limits.maxRounds)}/></view>
52
+ <Button label="−" onTap={() => change(c, { limits: { ...c.limits, maxRounds: Math.max(1, c.limits.maxRounds - 1) } })}/>
53
+ <Button label="+" onTap={() => change(c, { limits: { ...c.limits, maxRounds: Math.min(64, c.limits.maxRounds + 1) } })}/>
54
+ </view>
55
+ <view style={rowOf(ui, "6px")}>
56
+ {c.overridden ? <Button label={t("admin.reset")} onTap={() => { admin.resetCapability(c.id).then(replace, () => setFailed(true)); }}/> : null}
57
+ {probes.length > 0 && c.route.length > 0 ? <Button label={t("admin.probe")} onTap={() => { void probeAll(c.route.at(0) ?? ""); }}/> : null}
58
+ </view>
59
+ </view>))}
60
+ {results.map((r) => <Line key={r.probe} text={(r.rightKind ? "✓ " : "✗ ") + r.probe + " · " + r.quality + " · " + String(r.ms) + " ms"} bad={!r.rightKind}/>)}
61
+ </view>);
62
+ }
63
+ function Usage() {
64
+ const { admin, t } = useAdmin();
65
+ const [usage, setUsage] = useState(null);
66
+ const [windows, setWindows] = useState([]);
67
+ const [calls, setCalls] = useState([]);
68
+ const [box, setBox] = useState(null);
69
+ useEffect(() => {
70
+ admin.usage(7).then(setUsage, () => setUsage(null));
71
+ admin.windows().then(setWindows, () => setWindows([]));
72
+ admin.calls(7, 30).then(setCalls, () => setCalls([]));
73
+ }, []);
74
+ const pct = (x) => String(Math.round(x * 100)) + "%";
75
+ return (<view>
76
+ {usage ? <Line text={t("admin.without_model", { percent: pct(usage.withoutModelRate) }) + " · " + t("admin.rows", { count: usage.rows })}/> : null}
77
+ {usage?.capabilities.map((g) => <Line key={"c" + g.id} text={g.id + " · " + String(g.rows) + " · " + t("admin.tokens", { in: g.tokensIn, cached: g.tokensCached, out: g.tokensOut })} muted/>)}
78
+ {usage?.models.map((g) => <Line key={"m" + g.id} text={g.id + " · " + String(g.modelCalls) + " · " + String(g.avgMs) + " ms"} bad={g.errors > 0} muted={g.errors === 0}/>)}
79
+ {windows.flatMap((s) => s.windows.map((w) => <Line key={s.backend + w.name} text={s.backend + " · " + w.name + " · " + t("usage.left", { percent: pct(1 - w.usedPercent / 100) })}/>))}
80
+ <Line text={t("admin.calls")}/>
81
+ {calls.map((c) => (<view key={c.id} accessibility-element={true} accessibility-label={c.capability + " " + c.outcome} bindtap={() => { if (c.runId)
82
+ admin.timeline(c.runId).then((r) => setBox(r.lines), () => setBox(null)); }}>
83
+ <Line text={c.capability + " · " + c.role + " #" + String(c.round) + " · " + (c.model ?? "—") + " · " + c.outcome + " · " + String(c.ms) + " ms"} bad={c.outcome === "error"}/>
84
+ </view>))}
85
+ {box ? <Line text={t("admin.timeline")}/> : null}
86
+ {box?.map((l, i) => <Line key={String(i)} text={l.title + " " + l.detail} bad={l.bad} muted={!l.bad}/>)}
87
+ </view>);
88
+ }
89
+ function Audit() {
90
+ const { admin, t } = useAdmin();
91
+ const [rows, setRows] = useState(null);
92
+ useEffect(() => { admin.audit(100).then(setRows, () => setRows([])); }, []);
93
+ if (rows !== null && rows.length === 0)
94
+ return <Line text={t("admin.empty")} muted/>;
95
+ return <view>{(rows ?? []).map((a, i) => <Line key={String(i)} text={a.at.slice(0, 16).replace("T", " ") + " · " + a.user + " · " + a.action + (a.tool ? " · " + a.tool : "") + (a.outcome ? " · " + a.outcome : "")} bad={a.decision?.startsWith("deny") ?? false}/>)}</view>;
96
+ }
97
+ function Models() {
98
+ const { admin, t } = useAdmin();
99
+ const ui = useUi();
100
+ const [providers, setProviders] = useState([]);
101
+ const [backends, setBackends] = useState([]);
102
+ const [keys, setKeys] = useState([]);
103
+ const [shown, setShown] = useState(null);
104
+ const load = () => {
105
+ admin.providers().then((r) => setProviders(r.providers), () => setProviders([]));
106
+ admin.backends().then(setBackends, () => setBackends([]));
107
+ admin.gatewayKeys().then(setKeys, () => setKeys([]));
108
+ };
109
+ useEffect(load, []);
110
+ return (<view>
111
+ <Line text={t("admin.providers")}/>
112
+ {providers.map((p) => (<view key={p.id} style={rowOf(ui, "6px")}>
113
+ <view style={grow}><Line text={p.id + " · " + p.state + " · " + p.level + " · " + p.route + " · " + String(p.models.length)} bad={p.state === "unavailable"}/></view>
114
+ <Button label={t("admin.test")} onTap={() => { admin.testProvider(p.id).then((x) => setProviders((xs) => xs.map((y) => (y.id === x.id ? x : y))), () => undefined); }}/>
115
+ </view>))}
116
+ {backends.length > 0 ? <Line text={t("admin.backends")}/> : null}
117
+ {backends.map((b) => <Line key={b.id} text={b.id + " · " + b.state + (b.usage ? " · " + b.usage.windows.map((w) => w.name + " " + String(Math.round(w.usedPercent)) + "%").join(", ") : "")} muted/>)}
118
+ <Line text={t("admin.gateway")}/>
119
+ {shown ? <Line text={t("admin.key_once") + " " + shown}/> : null}
120
+ {keys.map((k) => <Line key={k.id} text={k.name + (k.revoked ? " ✗" : "")} muted/>)}
121
+ <Button label={t("admin.add")} onTap={() => { admin.createGatewayKey("lynx").then((tok) => { setShown(tok); load(); }, () => undefined); }}/>
122
+ </view>);
123
+ }
124
+ function Connections() {
125
+ const { admin, t } = useAdmin();
126
+ const ui = useUi();
127
+ const [servers, setServers] = useState([]);
128
+ const [client, setClient] = useState(true);
129
+ const [tools, setTools] = useState([]);
130
+ useEffect(() => { admin.mcpServers().then((r) => { setServers(r.servers); setClient(r.client); }, () => setServers([])); }, []);
131
+ return (<view>
132
+ <Line text={t("admin.mcp")}/>
133
+ {!client ? <Line text={t("admin.no_client")} muted/> : null}
134
+ {servers.map((s) => (<view key={s.id} style={rowOf(ui, "6px")}>
135
+ <view style={grow}><Line text={s.id + " · " + s.url + " · " + s.route}/></view>
136
+ <Button label={t("admin.test")} onTap={() => { admin.testMcpServer(s.id).then((r) => setTools(r.tools.map((x) => x.name + (x.readOnly ? " (read)" : " (change)"))), () => setTools([])); }}/>
137
+ </view>))}
138
+ {tools.map((x) => <Line key={x} text={x} muted/>)}
139
+ </view>);
140
+ }
141
+ function Feedback() {
142
+ const { admin, t } = useAdmin();
143
+ const [rows, setRows] = useState(null);
144
+ useEffect(() => { admin.agentFeedback().then((r) => setRows(r.rows), () => setRows([])); }, []);
145
+ if (rows !== null && rows.length === 0)
146
+ return <Line text={t("admin.empty")} muted/>;
147
+ return <view>{(rows ?? []).map((f) => <Line key={f.id} text={f.title + " · " + f.kind + " · ×" + String(f.count) + " · " + f.status}/>)}</view>;
148
+ }
149
+ /** The manager's page: capabilities, models, connections, usage, audit and suggestions, each loaded when its tab opens. */
150
+ export function AdminPage() {
151
+ const ui = useUi();
152
+ const { t } = useAdmin();
153
+ const [tab, setTab] = useState("capabilities");
154
+ return (<view className={cls(ui, "panel.body")} style={{ display: "flex", flexDirection: "column", ...fill, minHeight: 0, direction: "ltr" }}>
155
+ <view style={rowOf(ui, "6px")}>
156
+ {["capabilities", "models", "connections", "usage", "audit", "feedback"].map((x) => <Button key={x} label={t("admin." + x)} primary={tab === x} onTap={() => setTab(x)}/>)}
157
+ </view>
158
+ <scroll-view scroll-orientation="vertical" style={{ ...fill }}>
159
+ {tab === "capabilities" ? <Capabilities /> : tab === "models" ? <Models /> : tab === "connections" ? <Connections /> : tab === "usage" ? <Usage /> : tab === "feedback" ? <Feedback /> : <Audit />}
160
+ </scroll-view>
161
+ </view>);
162
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The built-in light chart for Lynx: horizontal bars for rankings, bars and stacks; one or several lines on a time axis
3
+ * (a legend for several); and a donut with its legend. Lines and the donut are an SVG drawn from numbers and theme
4
+ * colours only (the `svg` element's content, Lynx 3.7). A host gives its own chart library by replacing `Chart`, or
5
+ * the whole block with `components.Block.chart`; either gets the same view.
6
+ */
7
+ import type { BlockView } from "@g9tm/aiassistant";
8
+ import type { Part } from "./context.jsx";
9
+ export type ChartView = Extract<BlockView, {
10
+ type: "chart";
11
+ }>;
12
+ export declare const Chart: Part<{
13
+ view: ChartView;
14
+ }>;
package/dist/chart.jsx ADDED
@@ -0,0 +1,75 @@
1
+ /**
2
+ * The built-in light chart for Lynx: horizontal bars for rankings, bars and stacks; one or several lines on a time axis
3
+ * (a legend for several); and a donut with its legend. Lines and the donut are an SVG drawn from numbers and theme
4
+ * colours only (the `svg` element's content, Lynx 3.7). A host gives its own chart library by replacing `Chart`, or
5
+ * the whole block with `components.Block.chart`; either gets the same view.
6
+ */
7
+ import { formatNumber, shares } from "@g9tm/aiassistant";
8
+ import { cls, fill, rowOf, swappable, tok, useUi } from "./context.jsx";
9
+ const PALETTE = ["#8a4b2a", "#2a6f8a", "#5f8a2a", "#8a2a6a", "#a35a00", "#4b4b8a"];
10
+ const W = 300;
11
+ const H = 140;
12
+ /** The colour of series or slice i: the host's chart-1, chart-2... tokens (the first falls back to chart-bar). */
13
+ function colour(ui, i) {
14
+ const base = i === 0 ? tok(ui, "chart-bar", "#8a4b2a") : (PALETTE.at(i % PALETTE.length) ?? "#888");
15
+ return tok(ui, "chart-" + String(i + 1), base).replace(/[^#\w(),.% -]/gu, ""); // it goes into SVG text: no quotes or tags
16
+ }
17
+ function Legend(props) {
18
+ const ui = useUi();
19
+ return (<view className="g9a-legend" style={{ ...rowOf(ui, "10px"), flexWrap: "wrap", marginTop: "6px" }}>
20
+ {props.names.map((n, i) => (<view key={i} style={rowOf(ui, "4px")}>
21
+ <view style={{ width: "10px", height: "10px", borderRadius: "5px", backgroundColor: colour(ui, i) }}/>
22
+ <text style={{ fontSize: "12px", color: tok(ui, "muted", "#6b6660") }} text-maxline="1">{n}</text>
23
+ </view>))}
24
+ </view>);
25
+ }
26
+ function svg(viewBox, body) {
27
+ return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="' + viewBox + '" preserveAspectRatio="none">' + body + "</svg>";
28
+ }
29
+ export const Chart = swappable("Chart", (props) => {
30
+ const ui = useUi();
31
+ const v = props.view;
32
+ const first = v.series[0]?.values ?? [];
33
+ if (v.kind === "hbars" || v.kind === "bars" || v.kind === "stacked") {
34
+ const sh = shares(first);
35
+ return (<view className="g9a-hbars">
36
+ {v.labels.map((l, i) => (<view key={i} className={cls(ui, "block.chart.bar")} style={{ marginBottom: "6px" }}>
37
+ <text text-maxline="1">{l}</text>
38
+ {/* a row, so in right to left the bar grows from the right */}
39
+ <view style={{ ...rowOf(ui), height: "10px", borderRadius: "5px", backgroundColor: tok(ui, "surface", "#fff") }}>
40
+ <view style={{ height: "10px", borderRadius: "5px", width: String(Math.round((sh.at(i) ?? 0) * 100)) + "%", backgroundColor: colour(ui, 0) }}/>
41
+ </view>
42
+ <text style={{ fontSize: "12px" }}>{formatNumber(first.at(i) ?? 0, ui.texts.locale)}</text>
43
+ </view>))}
44
+ </view>);
45
+ }
46
+ if (v.kind === "donut") {
47
+ const total = first.reduce((a, b) => a + Math.max(0, b), 0) || 1;
48
+ const p = (f) => (50 + 40 * Math.sin(f * 2 * Math.PI)).toFixed(2) + " " + (50 - 40 * Math.cos(f * 2 * Math.PI)).toFixed(2);
49
+ let at = 0;
50
+ const arcs = first.map((x, i) => {
51
+ const from = at;
52
+ at += Math.max(0, x) / total;
53
+ const to = Math.min(at, from + 0.9999);
54
+ return to <= from ? "" : '<path d="M ' + p(from) + " A 40 40 0 " + (to - from > 0.5 ? "1" : "0") + " 1 " + p(to) + '" fill="none" stroke="' + colour(ui, i) + '" stroke-width="14"/>';
55
+ });
56
+ return (<view className="g9a-donut">
57
+ <svg content={svg("0 0 100 100", arcs.join(""))} style={{ width: "120px", height: "120px" }}/>
58
+ <Legend names={v.labels}/>
59
+ </view>);
60
+ }
61
+ // a line (or several) on a time axis: in right to left time runs from the right
62
+ const rtl = ui.assistant.host.dir === "rtl";
63
+ const max = Math.max(1, ...v.series.flatMap((s) => s.values));
64
+ const path = (values) => values.map((x, i) => {
65
+ const across = (i / Math.max(1, values.length - 1)) * W;
66
+ return (i === 0 ? "M" : "L") + (rtl ? W - across : across).toFixed(1) + " " + (H - (x / max) * H).toFixed(1);
67
+ }).join(" ");
68
+ const lines = v.series.map((s, i) => '<path d="' + path(s.values) + '" fill="none" stroke="' + colour(ui, i) + '" stroke-width="2" stroke-linejoin="round"/>');
69
+ return (<view className={cls(ui, "block.chart.line")}>
70
+ <view style={{ ...rowOf(ui), height: String(H) + "px" }}>
71
+ <svg content={svg("0 0 " + String(W) + " " + String(H), lines.join(""))} style={{ ...fill, height: String(H) + "px" }}/>
72
+ </view>
73
+ {v.series.length > 1 ? <Legend names={v.series.map((s) => s.name)}/> : null}
74
+ </view>);
75
+ });
@@ -0,0 +1,52 @@
1
+ /**
2
+ * What every ReactLynx component of one assistant shares: the core assistant, texts, per-part classes and
3
+ * styles, the unstyled switch and component overrides; and the theme as an object (Lynx has no CSS variables).
4
+ */
5
+ import type { ReactNode } from "@lynx-js/react";
6
+ import type { Assistant, AssistantSnapshot, PartName, PartStyles, Texts } from "@g9tm/aiassistant";
7
+ /** Any component a host gives in place of the library's (it gets the same props, plus the default as Default). */
8
+ export type HostComponent = (props: Record<string, unknown>) => ReactNode;
9
+ /** A component of the library (a plain function of its props). */
10
+ export type Part<P> = (props: P) => ReactNode;
11
+ export interface Overrides {
12
+ [name: string]: HostComponent | Record<string, HostComponent> | undefined;
13
+ Block?: Record<string, HostComponent>;
14
+ }
15
+ export interface LynxUi {
16
+ assistant: Assistant;
17
+ texts: Texts;
18
+ styles: PartStyles;
19
+ unstyled: boolean;
20
+ components: Overrides;
21
+ theme: Readonly<Record<string, string>>;
22
+ layer: number;
23
+ }
24
+ /** Shares the assistant's UI with the components inside. */
25
+ export declare function UiProvider(props: {
26
+ value: LynxUi;
27
+ children: ReactNode;
28
+ }): ReactNode;
29
+ export declare function useUi(): LynxUi;
30
+ /** The assistant's snapshot, kept up to date. */
31
+ export declare function useSnapshot(assistant: Assistant): AssistantSnapshot;
32
+ export declare function cls(ui: LynxUi, part: PartName): string;
33
+ /** Fills the room left in a row or a column: on a device the `flex` shorthand does not grow a view, the long hands do. */
34
+ export declare const fill: {
35
+ readonly flexGrow: 1;
36
+ readonly flexShrink: 1;
37
+ readonly flexBasis: "0px";
38
+ };
39
+ /**
40
+ * A row in the reading direction. On a device `direction` does not reverse a row, and a browser would: so the
41
+ * panel itself stays left to right and an RTL row is drawn reversed, the same on both.
42
+ */
43
+ export declare function rowOf(ui: LynxUi, gap?: string): Record<string, string>;
44
+ /** A theme token (the host's over the defaults), or the fallback. */
45
+ export declare function tok(ui: LynxUi, name: string, fallback?: string): string;
46
+ export declare function override(ui: LynxUi, name: string): HostComponent | undefined;
47
+ /**
48
+ * A component a host can replace by name wherever it is drawn, by the library or by the host's own composition. The
49
+ * host's one gets the same props plus the library's as `Default`, so it can wrap it without drawing itself again.
50
+ */
51
+ export declare function swappable<P extends object>(name: string, Base: Part<P>): Part<P>;
52
+ export declare function blockOverride(ui: LynxUi, type: string): HostComponent | undefined;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * What every ReactLynx component of one assistant shares: the core assistant, texts, per-part classes and
3
+ * styles, the unstyled switch and component overrides; and the theme as an object (Lynx has no CSS variables).
4
+ */
5
+ import { createContext, useContext, useEffect, useState } from "@lynx-js/react";
6
+ import { partClass } from "@g9tm/aiassistant";
7
+ const UiContext = createContext(null);
8
+ /** Shares the assistant's UI with the components inside. */
9
+ export function UiProvider(props) {
10
+ return <UiContext.Provider value={props.value}>{props.children}</UiContext.Provider>;
11
+ }
12
+ export function useUi() {
13
+ const ui = useContext(UiContext);
14
+ if (!ui)
15
+ throw new Error("Use the assistant's components inside AssistantRoot.");
16
+ return ui;
17
+ }
18
+ /** The assistant's snapshot, kept up to date. */
19
+ export function useSnapshot(assistant) {
20
+ const [snap, setSnap] = useState(() => assistant.snapshot());
21
+ useEffect(() => assistant.subscribe(setSnap), [assistant]);
22
+ return snap;
23
+ }
24
+ export function cls(ui, part) {
25
+ return partClass(part, ui.styles, ui.unstyled);
26
+ }
27
+ /** Fills the room left in a row or a column: on a device the `flex` shorthand does not grow a view, the long hands do. */
28
+ export const fill = { flexGrow: 1, flexShrink: 1, flexBasis: "0px" };
29
+ /**
30
+ * A row in the reading direction. On a device `direction` does not reverse a row, and a browser would: so the
31
+ * panel itself stays left to right and an RTL row is drawn reversed, the same on both.
32
+ */
33
+ export function rowOf(ui, gap) {
34
+ return { display: "flex", flexDirection: ui.assistant.host.dir === "rtl" ? "row-reverse" : "row", alignItems: "center", ...(gap ? { gap } : {}) };
35
+ }
36
+ /** A theme token (the host's over the defaults), or the fallback. */
37
+ export function tok(ui, name, fallback = "") {
38
+ return ui.unstyled ? fallback : (new Map(Object.entries(ui.theme)).get(name) ?? fallback);
39
+ }
40
+ export function override(ui, name) {
41
+ const c = new Map(Object.entries(ui.components)).get(name);
42
+ return typeof c === "function" ? c : undefined;
43
+ }
44
+ /**
45
+ * A component a host can replace by name wherever it is drawn, by the library or by the host's own composition. The
46
+ * host's one gets the same props plus the library's as `Default`, so it can wrap it without drawing itself again.
47
+ */
48
+ export function swappable(name, Base) {
49
+ return (props) => {
50
+ const Own = override(useUi(), name);
51
+ return Own ? <Own {...props} Default={Base}/> : <Base {...props}/>;
52
+ };
53
+ }
54
+ export function blockOverride(ui, type) {
55
+ return ui.components.Block ? new Map(Object.entries(ui.components.Block)).get(type) : undefined;
56
+ }
@@ -0,0 +1,13 @@
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";
3
+ export type { SurfaceKind, SurfaceProps } from "./surfaces.jsx";
4
+ export { ApprovalCard, BlockView, Cards, Composer, CsvButton, Message, RevealText, Small, StagesThinking, TextView, ThinkingOrb, WorkCard } from "./parts.jsx";
5
+ export { Chart } from "./chart.jsx";
6
+ export type { ChartView } from "./chart.jsx";
7
+ export { Button, Dialog, field, PinPad, SecretField } from "./slots.jsx";
8
+ export type { ButtonProps } from "./slots.jsx";
9
+ export type { CsvButtonProps } from "./parts.jsx";
10
+ export { Abilities, ActionsPage, FindingsPage, History, HistoryRow, KnowledgePage, LearnedPage, Page, RoutineWizard, SlotPicker } from "./pages.jsx";
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";
13
+ export type { HostComponent, LynxUi, Overrides } from "./context.jsx";
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
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";
3
+ export { ApprovalCard, BlockView, Cards, Composer, CsvButton, Message, RevealText, Small, StagesThinking, TextView, ThinkingOrb, WorkCard } from "./parts.jsx";
4
+ export { Chart } from "./chart.jsx";
5
+ export { Button, Dialog, field, PinPad, SecretField } from "./slots.jsx";
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";
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The assistant's pages for ReactLynx: history, abilities, knowledge, what it learned, findings, routines and the
3
+ * actions it took. Each reads its own endpoint (as the Svelte pages do), with type checks only; each page is
4
+ * replaceable by name (`History`, `Abilities`...), and its rows draw with the Button slot. History has four tabs with
5
+ * counts, a search, pin and delete; the routine wizard asks a routine's slots (a picker for things, typed fields for the
6
+ * rest), previews it, and runs it with the person's code.
7
+ */
8
+ import type { ConversationRow, RoutineSlot } from "@g9tm/aiassistant/pages";
9
+ export type PageKind = "history" | "abilities" | "knowledge" | "learned" | "findings" | "routines" | "actions";
10
+ export interface PageProps {
11
+ onOpen?: (conversationId: string) => void;
12
+ }
13
+ /** A page by its kind (history and the routine wizard have their own state; the rest read one endpoint). */
14
+ export declare function Page(props: PageProps & {
15
+ kind: PageKind;
16
+ }): import("@lynx-js/react").JSX.Element;
17
+ export interface HistoryRowProps {
18
+ row: ConversationRow;
19
+ onOpen: () => void;
20
+ onPin: () => void;
21
+ onDelete: () => void;
22
+ }
23
+ /** One conversation: its title opens it; pin (or unpin) and delete keep their size. Replaceable as `HistoryRow`. */
24
+ export declare const HistoryRow: import("./context.jsx").Part<HistoryRowProps>;
25
+ export interface SlotPickerProps {
26
+ slot: RoutineSlot;
27
+ onPick: (pick: {
28
+ id: string;
29
+ label: string;
30
+ }) => void;
31
+ onClose: () => void;
32
+ }
33
+ /** A searchable picker over the host's things of the slot's kind (asked after a short pause). Replaceable as `SlotPicker`. */
34
+ export declare const SlotPicker: import("./context.jsx").Part<SlotPickerProps>;
35
+ export declare const History: import("./context.jsx").Part<PageProps>;
36
+ export declare const Abilities: import("./context.jsx").Part<PageProps>;
37
+ export declare const KnowledgePage: import("./context.jsx").Part<PageProps>;
38
+ export declare const LearnedPage: import("./context.jsx").Part<PageProps>;
39
+ export declare const FindingsPage: import("./context.jsx").Part<PageProps>;
40
+ export declare const RoutineWizard: import("./context.jsx").Part<PageProps>;
41
+ export declare const ActionsPage: import("./context.jsx").Part<PageProps>;