@g9tm/aiassistant-lynx 0.0.0-stage → 1.0.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,41 @@
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
+ - Customising: theme tokens as an object (Lynx has no CSS variables), per-part classes and styles, `unstyled`, and
11
+ replaced components by name.
12
+ - Laid out by the rules a device engine holds: rows reversed for right to left, growth by the long-hand flex
13
+ properties, a size on every input, `display: "flex"` on every container.
14
+ - `@g9tm/aiassistant-lynx/admin`: the manager's page as a separate entry.
15
+
16
+ ```tsx
17
+ import { createAssistant } from "@g9tm/aiassistant";
18
+ import type { AssistantHost } from "@g9tm/aiassistant";
19
+ import { AssistantPanel, AssistantRoot } from "@g9tm/aiassistant-lynx";
20
+
21
+ const SERVER = "https://assistant.example.com";
22
+ const f = fetch; // on a device, fetch is a name in scope, not a property of globalThis
23
+ const host: AssistantHost = {
24
+ locale: "fa", dir: "rtl", theme: { mode: "light", tokens: {} }, reducedMotion: false,
25
+ async fetch(input, init) {
26
+ const r = await f(SERVER + input, { method: init?.method ?? "GET", headers: init?.headers ?? {}, ...(init?.body === undefined ? {} : { body: init.body }) });
27
+ return { status: r.status, ok: r.ok, text: () => r.text() };
28
+ },
29
+ };
30
+ const assistant = createAssistant(host, { sse: false }); // no EventSource on a device: poll
31
+
32
+ export function App() {
33
+ return (
34
+ <AssistantRoot assistant={assistant}>
35
+ <AssistantPanel open={true} layout="fullscreen" width={400} />
36
+ </AssistantRoot>
37
+ );
38
+ }
39
+ ```
40
+
41
+ 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 "./parts.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,45 @@
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
+ export interface Overrides {
10
+ [name: string]: HostComponent | Record<string, HostComponent> | undefined;
11
+ Block?: Record<string, HostComponent>;
12
+ }
13
+ export interface LynxUi {
14
+ assistant: Assistant;
15
+ texts: Texts;
16
+ styles: PartStyles;
17
+ unstyled: boolean;
18
+ components: Overrides;
19
+ theme: Readonly<Record<string, string>>;
20
+ layer: number;
21
+ }
22
+ /** Shares the assistant's UI with the components inside. */
23
+ export declare function UiProvider(props: {
24
+ value: LynxUi;
25
+ children: ReactNode;
26
+ }): ReactNode;
27
+ export declare function useUi(): LynxUi;
28
+ /** The assistant's snapshot, kept up to date. */
29
+ export declare function useSnapshot(assistant: Assistant): AssistantSnapshot;
30
+ export declare function cls(ui: LynxUi, part: PartName): string;
31
+ /** 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. */
32
+ export declare const fill: {
33
+ readonly flexGrow: 1;
34
+ readonly flexShrink: 1;
35
+ readonly flexBasis: "0px";
36
+ };
37
+ /**
38
+ * A row in the reading direction. On a device `direction` does not reverse a row, and a browser would: so the
39
+ * panel itself stays left to right and an RTL row is drawn reversed, the same on both.
40
+ */
41
+ export declare function rowOf(ui: LynxUi, gap?: string): Record<string, string>;
42
+ /** A theme token (the host's over the defaults), or the fallback. */
43
+ export declare function tok(ui: LynxUi, name: string, fallback?: string): string;
44
+ export declare function override(ui: LynxUi, name: string): HostComponent | undefined;
45
+ export declare function blockOverride(ui: LynxUi, type: string): HostComponent | undefined;
@@ -0,0 +1,46 @@
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
+ export function blockOverride(ui, type) {
45
+ return ui.components.Block ? new Map(Object.entries(ui.components.Block)).get(type) : undefined;
46
+ }
@@ -0,0 +1,5 @@
1
+ /** @g9tm/aiassistant-lynx: ReactLynx components of the G9 AI assistant, customisable like the Svelte ones. */
2
+ export { AssistantRoot, AssistantChat, AssistantPanel, MessageList } from "./surfaces.jsx";
3
+ export { ApprovalCard, BlockView, Cards, Composer, Message, RevealText, Small, TextView, WorkCard } from "./parts.jsx";
4
+ export { cls, override, blockOverride, tok, useSnapshot, useUi, UiProvider } from "./context.jsx";
5
+ export type { HostComponent, LynxUi, Overrides } from "./context.jsx";
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ /** @g9tm/aiassistant-lynx: ReactLynx components of the G9 AI assistant, customisable like the Svelte ones. */
2
+ export { AssistantRoot, AssistantChat, AssistantPanel, MessageList } from "./surfaces.jsx";
3
+ export { ApprovalCard, BlockView, Cards, Composer, Message, RevealText, Small, TextView, WorkCard } from "./parts.jsx";
4
+ export { cls, override, blockOverride, tok, useSnapshot, useUi, UiProvider } from "./context.jsx";
@@ -0,0 +1,56 @@
1
+ /**
2
+ * The conversation's parts for ReactLynx. Lynx rules: only transform and opacity animate; every multi-line text
3
+ * has a line limit or a bounded box; text in a row is flex 1 with minWidth 0; a number and its label are separate texts;
4
+ * every interactive element has an accessibility label; the growing message is drawn below the recycled list.
5
+ */
6
+ import type { AssistantState, MessageView, PlanView, Provenance, RunView } from "@g9tm/aiassistant";
7
+ import { cls } from "./context.jsx";
8
+ export declare function Button(props: {
9
+ label: string;
10
+ onTap: () => void;
11
+ primary?: boolean;
12
+ part?: Parameters<typeof cls>[1];
13
+ }): import("@lynx-js/react").JSX.Element;
14
+ export declare function TextView(props: {
15
+ text: string;
16
+ }): import("@lynx-js/react").JSX.Element;
17
+ export declare function RevealText(props: {
18
+ text: string;
19
+ reveal: boolean;
20
+ }): import("@lynx-js/react").JSX.Element;
21
+ export declare function Small(props: {
22
+ kind: "provenance" | "mode" | "usage";
23
+ provenance?: Provenance | null;
24
+ state?: AssistantState | null;
25
+ }): import("@lynx-js/react").JSX.Element | null;
26
+ export declare function BlockView(props: {
27
+ block: unknown;
28
+ compact?: boolean;
29
+ }): import("@lynx-js/react").JSX.Element;
30
+ export declare function ApprovalCard(props: {
31
+ plan: PlanView;
32
+ }): import("@lynx-js/react").JSX.Element;
33
+ export declare function Message(props: {
34
+ message: MessageView;
35
+ plans: ReadonlyMap<string, PlanView>;
36
+ runId: string | null;
37
+ }): import("@lynx-js/react").JSX.Element;
38
+ export declare function Cards(props: {
39
+ card: {
40
+ kind: string;
41
+ id: string;
42
+ body: Record<string, unknown>;
43
+ };
44
+ runId: string | null;
45
+ }): import("@lynx-js/react").JSX.Element;
46
+ export declare function WorkCard(props: {
47
+ run: RunView;
48
+ }): import("@lynx-js/react").JSX.Element | null;
49
+ export declare function Composer(props: {
50
+ busy: boolean;
51
+ attachments: {
52
+ id: string;
53
+ name: string;
54
+ kind: string;
55
+ }[];
56
+ }): import("@lynx-js/react").JSX.Element;
package/dist/parts.jsx ADDED
@@ -0,0 +1,223 @@
1
+ /**
2
+ * The conversation's parts for ReactLynx. Lynx rules: only transform and opacity animate; every multi-line text
3
+ * has a line limit or a bounded box; text in a row is flex 1 with minWidth 0; a number and its label are separate texts;
4
+ * every interactive element has an accessibility label; the growing message is drawn below the recycled list.
5
+ */
6
+ import { useEffect, useState } from "@lynx-js/react";
7
+ import { blockView, formatNumber, needsCode, parseText, shares, visibleText, REVEAL_MS, windowView } from "@g9tm/aiassistant";
8
+ import { blockOverride, cls, fill, override, rowOf, tok, useUi } from "./context.jsx";
9
+ const grow = { ...fill, minWidth: 0 };
10
+ /** A Lynx input has no size of its own (on a device it is drawn zero high): every input of the renderer gets one. */
11
+ function field(ui) {
12
+ return { height: "40px", fontSize: "15px", paddingLeft: "10px", paddingRight: "10px", borderWidth: "1px", borderStyle: "solid", borderRadius: "8px",
13
+ borderColor: tok(ui, "border", "#d0d0d0"), color: tok(ui, "ink", "#111"), backgroundColor: tok(ui, "field", "#fff") };
14
+ }
15
+ export function Button(props) {
16
+ const ui = useUi();
17
+ return (<view className={props.part ? cls(ui, props.part) : "g9a-button"} accessibility-element={true} accessibility-label={props.label} bindtap={props.onTap} style={{ minHeight: "38px", paddingLeft: "12px", paddingRight: "12px", borderRadius: tok(ui, "radius-s", "6px"), justifyContent: "center",
18
+ backgroundColor: props.primary ? tok(ui, "accent", "#8a4b2a") : tok(ui, "surface", "#fff"), borderWidth: "1px", borderColor: tok(ui, "line", "#e4ded6") }}>
19
+ <text style={{ color: props.primary ? tok(ui, "accent-ink", "#fff") : tok(ui, "ink", "#22201d") }} text-maxline="1">{props.label}</text>
20
+ </view>);
21
+ }
22
+ export function TextView(props) {
23
+ const ui = useUi();
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: () => ui.assistant.host.openUrl?.(x.href ?? "") } : {})}>{x.text}</text>));
25
+ return (<view>
26
+ {parseText(props.text, ui.assistant.host.linkHosts ?? []).map((b, i) => b.kind === "paragraph"
27
+ ? <text key={i} style={{ color: tok(ui, "ink", "#22201d"), marginBottom: "6px" }}>{line(b.inlines)}</text>
28
+ : <view key={i}>{b.items.map((it, n) => <text key={n}>{b.ordered ? String(n + 1) + ". " : "• "}{line(it)}</text>)}</view>)}
29
+ </view>);
30
+ }
31
+ export function RevealText(props) {
32
+ const ui = useUi();
33
+ const animate = props.reveal && !ui.assistant.host.reducedMotion;
34
+ const [elapsed, setElapsed] = useState(animate ? 0 : REVEAL_MS);
35
+ useEffect(() => {
36
+ if (!animate)
37
+ return;
38
+ const start = Date.now();
39
+ const h = setInterval(() => { const e = Date.now() - start; setElapsed(e); if (e >= REVEAL_MS)
40
+ clearInterval(h); }, 80); // one render per 80 ms at most
41
+ return () => clearInterval(h);
42
+ }, [animate]);
43
+ return <view className={cls(ui, "reveal-text")}><TextView text={animate ? visibleText(props.text, elapsed, false) : props.text}/></view>;
44
+ }
45
+ export function Small(props) {
46
+ const ui = useUi();
47
+ const t = ui.texts.t;
48
+ if (props.kind === "provenance" && props.provenance)
49
+ return <text className={cls(ui, "message.provenance")} style={{ fontSize: "11px", color: tok(ui, "muted", "#6b6660") }}>{t("provenance." + props.provenance)}</text>;
50
+ const s = props.state;
51
+ if (props.kind === "mode" && s && s.mode !== "on")
52
+ return <view className={cls(ui, "mode-banner")} style={{ padding: "6px 12px", backgroundColor: tok(ui, "surface-2", "#f6f4f1") }}><text style={{ color: tok(ui, "warn", "#a35a00") }}>{s.mode === "off" ? t("mode.off") : t("mode.offline")}</text></view>;
53
+ const w = s?.usage[0] ? windowView(s.usage[0], Date.now()) : null;
54
+ if (props.kind === "usage" && w) {
55
+ return (<view className={cls(ui, "usage-chip")} style={{ ...rowOf(ui), height: "22px", borderRadius: "11px", overflow: "hidden", backgroundColor: tok(ui, "surface-2", "#f6f4f1") }}>
56
+ <view style={{ position: "absolute", left: 0, top: 0, bottom: 0, width: String(Math.round(w.left * 100)) + "%", backgroundColor: tok(ui, "accent", "#8a4b2a"), opacity: 0.25 }}/>
57
+ <text style={{ fontSize: "11px", paddingLeft: "8px", paddingRight: "8px" }}>{t("usage.left", { percent: Math.round(w.left * 100) + "%" })}</text>
58
+ </view>);
59
+ }
60
+ return null;
61
+ }
62
+ export function BlockView(props) {
63
+ const ui = useUi();
64
+ const t = ui.texts.t;
65
+ const v = blockView(props.block, ui.texts.locale, ui.assistant.customBlocks);
66
+ const [open, setOpen] = useState(false);
67
+ const Own = blockOverride(ui, v.type === "custom" ? v.name : v.type);
68
+ if (Own)
69
+ return <Own view={v} block={props.block} compact={props.compact ?? false}/>;
70
+ switch (v.type) {
71
+ case "text":
72
+ case "callout": return <view className={cls(ui, v.type === "text" ? "block.text" : "block.callout")}><TextView text={v.text}/></view>;
73
+ case "table":
74
+ return (<view className={cls(ui, "block.table")}>
75
+ {v.title ? <text style={{ fontWeight: "bold" }}>{v.title}</text> : null}
76
+ {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>}
77
+ {v.rows.slice(0, open ? v.rows.length : v.shown).map((r, i) => v.asCards || props.compact
78
+ ? <view key={i} className={cls(ui, "block.table.card")} style={{ padding: "6px 8px", marginBottom: "6px", borderRadius: "6px", backgroundColor: tok(ui, "surface", "#fff") }}>
79
+ {v.columns.map((c, j) => <view key={c.name} style={rowOf(ui)}><text style={{ ...grow, color: tok(ui, "muted", "#6b6660") }} text-maxline="1">{c.label}</text><text text-maxline="2">{r.at(j)}</text></view>)}
80
+ </view>
81
+ : <view key={i} style={rowOf(ui)}>{r.map((c, j) => <text key={j} style={grow} text-maxline="1">{c}</text>)}</view>)}
82
+ {v.more > 0 && !open ? <Button label={t("block.more_rows", { count: v.more })} onTap={() => setOpen(true)}/> : null}
83
+ </view>);
84
+ case "chart": {
85
+ const first = v.series[0]?.values ?? [];
86
+ const sh = shares(first);
87
+ return (<view className={cls(ui, "block.chart")} accessibility-label={v.fallbackText}>
88
+ {v.title ? <text style={{ fontWeight: "bold" }}>{v.title}</text> : null}
89
+ {v.labels.map((l, i) => (<view key={i} className={cls(ui, "block.chart.bar")} style={{ marginBottom: "6px" }}>
90
+ <text text-maxline="1">{l}</text>
91
+ <view style={{ height: "10px", borderRadius: "5px", backgroundColor: tok(ui, "surface", "#fff") }}>
92
+ <view style={{ height: "10px", borderRadius: "5px", width: String(Math.round((sh.at(i) ?? 0) * 100)) + "%", backgroundColor: tok(ui, "chart-bar", "#8a4b2a") }}/>
93
+ </view>
94
+ <text style={{ fontSize: "12px" }}>{formatNumber(first.at(i) ?? 0, ui.texts.locale)}</text>
95
+ </view>))}
96
+ {v.fewData ? <text style={{ fontSize: "12px" }}>{t("block.few_data")}</text> : null}
97
+ </view>);
98
+ }
99
+ 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>;
100
+ case "steps": return <view className={cls(ui, "block.steps")}>{v.items.map((s, i) => <text key={i}>{s.text}</text>)}</view>;
101
+ 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>;
102
+ case "flow": return <text className={cls(ui, "block.flow")}>{v.line}</text>;
103
+ 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>;
104
+ 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>;
105
+ default: return <text className={cls(ui, "block.fallback")}>{v.fallbackText}</text>;
106
+ }
107
+ }
108
+ export function ApprovalCard(props) {
109
+ const ui = useUi();
110
+ const t = ui.texts.t;
111
+ const p = props.plan;
112
+ const [code, setCode] = useState("");
113
+ // A fact without a text of its own shows its values (as in Svelte), never its key.
114
+ const say = (key, args) => { const text = t(key, args); return text === key ? Object.values(args).join(" ") || key : text; };
115
+ return (<view className={cls(ui, "card.approval")} style={{ padding: "12px", borderRadius: "10px", borderWidth: "1px", borderColor: tok(ui, "approval-card-border", "#8a4b2a") }}>
116
+ <text style={{ fontWeight: "bold" }}>{p.readOnly ? t("card.readonly_routine") : p.title}</text>
117
+ {p.warning ? <text style={{ color: tok(ui, "warn", "#a35a00") }}>{t("card.tainted")}</text> : null}
118
+ {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)}>
119
+ <view style={rowOf(ui)}><text>{s.ticked ? "☑ " : "☐ "}</text><text style={grow}>{s.text}{s.undoable ? "" : " (" + t("card.irreversible") + ")"}</text></view>
120
+ {s.facts.map((f, i) => <text key={i} className={cls(ui, "card.approval.fact")} style={{ fontSize: "12px" }}>{say(f.key, f.args)}</text>)}
121
+ {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>)}
122
+ </view>))}
123
+ {p.answered === null ? (<view>
124
+ {needsCode(p.method) ? <input className={cls(ui, "card.approval.code")} style={{ ...field(ui), marginTop: "8px" }} type="password" accessibility-label={t("card.code")} placeholder={t("card.code")} bindinput={(e) => setCode(e.detail.value)}/> : null}
125
+ {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}
126
+ <view style={rowOf(ui)}>
127
+ <Button part="card.approval.confirm" primary label={t("card.confirm")} onTap={() => void ui.assistant.confirm(p.id, needsCode(p.method) ? code : null)}/>
128
+ <Button part="card.approval.refuse" label={t("card.refuse")} onTap={() => void ui.assistant.refuse(p.id)}/>
129
+ </view>
130
+ </view>) : <text>{t("card.answered")}</text>}
131
+ </view>);
132
+ }
133
+ export function Message(props) {
134
+ const ui = useUi();
135
+ const t = ui.texts.t;
136
+ const m = props.message;
137
+ const [reveal] = useState(() => ui.assistant.watched.reveal(m.id) && m.role === "assistant" && !m.pending);
138
+ const Approval = override(ui, "ApprovalCard") ?? ApprovalCard;
139
+ const plan = m.card?.kind === "plan" ? props.plans.get(m.card.id) : undefined;
140
+ 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%",
141
+ backgroundColor: tok(ui, "surface-2", "#f6f4f1"), opacity: m.pending ? 0.7 : 1 }}>
142
+ {plan ? <Approval plan={plan}/> : m.card ? <Cards card={m.card} runId={props.runId}/> : (<view>
143
+ {m.text.length > 0 ? <RevealText text={m.text} reveal={reveal}/> : null}
144
+ {m.blocks.map((b, i) => <BlockView key={i} block={b}/>)}
145
+ {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}
146
+ {m.role === "assistant" ? (<view className={cls(ui, "message.feedback")} style={rowOf(ui)}>
147
+ <Small kind="provenance" provenance={m.provenance}/>
148
+ {ui.assistant.host.copy ? <Button label={t("feedback.copy")} onTap={() => void ui.assistant.host.copy?.(m.text)}/> : null}
149
+ {m.provenance === "learned" ? <Button label={t("feedback.not_right")} onTap={() => void ui.assistant.notRight(m.id)}/> : null}
150
+ </view>) : null}
151
+ </view>)}
152
+ </view>);
153
+ }
154
+ export function Cards(props) {
155
+ const ui = useUi();
156
+ const t = ui.texts.t;
157
+ const c = props.card;
158
+ const answered = ui.assistant.answered.of(c.id);
159
+ const [text, setText] = useState("");
160
+ const options = Array.isArray(c.body["options"]) ? c.body["options"].map((o) => String(o.label ?? "")).filter((l) => l.length > 0) : [];
161
+ if (c.kind === "undo")
162
+ return <view className={cls(ui, "card.undo")}><Button label={t("undo.all")} onTap={() => void ui.assistant.undo(c.id)}/></view>;
163
+ if (c.kind === "ask" && props.runId) {
164
+ const runId = props.runId;
165
+ return (<view className={cls(ui, "card.ask")}>
166
+ <text>{String(c.body["question"] ?? "")}</text>
167
+ {answered ? <text>{t("card.answered")}</text> : (<view>
168
+ {options.map((o) => <Button key={o} label={o} onTap={() => void ui.assistant.answer(runId, c.id, [o], null)}/>)}
169
+ <input style={{ ...field(ui), ...grow }} type={c.body["secret"] === true ? "password" : "text"} accessibility-label={t("ask.send")} bindinput={(e) => setText(e.detail.value)}/>
170
+ <Button label={t("ask.send")} onTap={() => { const v = text; setText(""); void ui.assistant.answer(runId, c.id, [], v); }}/>
171
+ </view>)}
172
+ </view>);
173
+ }
174
+ const kind = c.kind === "learn" ? "knowledge" : "learned";
175
+ const id = typeof c.body["id"] === "string" ? c.body["id"] : c.id;
176
+ return (<view className={cls(ui, "card.choice")}>
177
+ <text>{c.kind === "learn" ? t("learn.ask") : t("routine.ask")}</text>
178
+ {answered ? <text>{t("card.answered")}</text> : (<view style={rowOf(ui)}>
179
+ <Button label={t("yes")} onTap={() => void ui.assistant.choose(kind, id, c.kind === "learn" ? "accept" : "approve")}/>
180
+ <Button label={t("no")} onTap={() => void ui.assistant.choose(kind, id, c.kind === "learn" ? "refuse" : "retire")}/>
181
+ </view>)}
182
+ </view>);
183
+ }
184
+ export function WorkCard(props) {
185
+ const ui = useUi();
186
+ const t = ui.texts.t;
187
+ const r = props.run;
188
+ const [now, setNow] = useState(Date.now());
189
+ useEffect(() => { const h = setInterval(() => setNow(Date.now()), 1000); return () => clearInterval(h); }, []);
190
+ if (r.state === "done" || r.state === "failed" || r.state === "cancelled" || r.state === "waiting-confirm" || r.state === "waiting-answer")
191
+ return null;
192
+ const seconds = Math.max(0, Math.round((now - (r.startedAt ?? now)) / 1000));
193
+ return (<view className={cls(ui, "work")} style={{ ...rowOf(ui), padding: "12px" }}>
194
+ <view className={cls(ui, "thinking-orb")} style={{ width: "18px", height: "18px", borderRadius: "9px", backgroundColor: tok(ui, "accent", "#8a4b2a") }}/>
195
+ <view style={grow}>
196
+ <view style={rowOf(ui)}><text style={grow}>{r.longRunning ? t("work.long") : t("work.title")}</text><text>{t("work.elapsed", { seconds })}</text></view>
197
+ <view style={{ ...rowOf(ui), flexWrap: "wrap" }}>{r.stages.filter((s) => s.id !== "waiting").map((s, i) => <text key={i} className={cls(ui, "work.stage")} style={{ marginRight: "6px", opacity: s.state === "on" ? 1 : 0.5 }}>{s.id === "role" ? (s.role ?? "") : t("stage." + s.id)}</text>)}</view>
198
+ {r.progress ? <text className={cls(ui, "work.progress")} text-maxline="2">{t(r.progress.key, r.progress.args)}</text> : null}
199
+ </view>
200
+ <Button part="composer.stop" label={t("composer.stop")} onTap={() => void ui.assistant.stop()}/>
201
+ </view>);
202
+ }
203
+ export function Composer(props) {
204
+ const ui = useUi();
205
+ const t = ui.texts.t;
206
+ const host = ui.assistant.host;
207
+ const [text, setText] = useState("");
208
+ const [epoch, setEpoch] = useState(0); // a Lynx input has no value prop: a new key clears it
209
+ return (<view className={cls(ui, "composer")} style={{ padding: "12px" }}>
210
+ {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}
211
+ <view style={rowOf(ui)}>
212
+ {host.pickFile ? <Button part="composer.attach" label={t("composer.attach")} onTap={async () => { const f = await host.pickFile?.([".pdf", ".xlsx", ".csv", "image/*"]); if (f)
213
+ await ui.assistant.attach(f.name, f.bytes); }}/> : null}
214
+ <view style={{ ...grow, marginLeft: "8px", marginRight: "8px" }}><input 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>
215
+ <Button part={props.busy ? "composer.stop" : "composer.send"} primary label={props.busy ? t("composer.stop") : t("composer.send")} onTap={async () => { if (props.busy)
216
+ await ui.assistant.stop();
217
+ else if (await ui.assistant.send(text)) {
218
+ setText("");
219
+ setEpoch((n) => n + 1);
220
+ } }}/>
221
+ </view>
222
+ </view>);
223
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Surfaces for ReactLynx: the root (context and theme), the chat (a composition of the parts), and the panel in its
3
+ * layouts. Messages use a recycled list with a stable key; the answer still growing is drawn below the list so its
4
+ * measurement does not break.
5
+ */
6
+ import type { ReactNode } from "@lynx-js/react";
7
+ import type { Assistant, Layout, MessageView, PartStyles, PlanView } from "@g9tm/aiassistant";
8
+ import type { Overrides } from "./context.jsx";
9
+ export declare function AssistantRoot(props: {
10
+ assistant: Assistant;
11
+ styles?: PartStyles;
12
+ unstyled?: boolean;
13
+ components?: Overrides;
14
+ children: ReactNode;
15
+ }): import("@lynx-js/react").JSX.Element;
16
+ export declare function MessageList(props: {
17
+ messages: MessageView[];
18
+ plans: ReadonlyMap<string, PlanView>;
19
+ runId: string | null;
20
+ }): import("@lynx-js/react").JSX.Element;
21
+ export declare function AssistantChat(): import("@lynx-js/react").JSX.Element;
22
+ export declare function AssistantPanel(props: {
23
+ open: boolean;
24
+ layout?: Layout;
25
+ width: number;
26
+ onClose?: () => void;
27
+ title?: string;
28
+ }): import("@lynx-js/react").JSX.Element | null;
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Surfaces for ReactLynx: the root (context and theme), the chat (a composition of the parts), and the panel in its
3
+ * layouts. Messages use a recycled list with a stable key; the answer still growing is drawn below the list so its
4
+ * measurement does not break.
5
+ */
6
+ import { useEffect } from "@lynx-js/react";
7
+ import { pickLayout } from "@g9tm/aiassistant";
8
+ import { cls, fill, override, rowOf, tok, UiProvider, useSnapshot, useUi } from "./context.jsx";
9
+ import { Composer, Message, Small, WorkCard } from "./parts.jsx";
10
+ /** Default tokens (light and dark); the host's theme tokens override them. */
11
+ const LIGHT = { "surface": "#ffffff", "surface-2": "#f6f4f1", "ink": "#22201d", "muted": "#6b6660", "line": "#e4ded6", "accent": "#8a4b2a", "accent-ink": "#ffffff", "warn": "#a35a00", "danger": "#b42318", "radius": "10px", "radius-s": "6px", "chart-bar": "#8a4b2a", "approval-card-border": "#8a4b2a" };
12
+ const DARK = { ...LIGHT, "surface": "#1d1b19", "surface-2": "#272421", "ink": "#efeae4", "muted": "#a39c94", "line": "#3a3632", "accent": "#e0a074", "accent-ink": "#1d1b19", "chart-bar": "#e0a074", "approval-card-border": "#e0a074" };
13
+ export function AssistantRoot(props) {
14
+ const host = props.assistant.host;
15
+ const theme = { ...(host.theme.mode === "dark" ? DARK : LIGHT), ...host.theme.tokens };
16
+ 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 }}>
17
+ {props.children}
18
+ </UiProvider>);
19
+ }
20
+ export function MessageList(props) {
21
+ const ui = useUi();
22
+ const Item = override(ui, "Message") ?? Message;
23
+ const settled = props.messages.slice(0, -1);
24
+ const last = props.messages[props.messages.length - 1];
25
+ return (<view className={cls(ui, "messages")} style={{ display: "flex", flexDirection: "column", ...fill, minHeight: 0 }}>
26
+ <list scroll-orientation="vertical" style={{ ...fill }} list-type="single">
27
+ {settled.map((m) => (<list-item key={m.id} item-key={m.id}>
28
+ <Item message={m} plans={props.plans} runId={props.runId}/>
29
+ </list-item>))}
30
+ </list>
31
+ {last ? <Item key={last.id} message={last} plans={props.plans} runId={props.runId}/> : null}
32
+ </view>);
33
+ }
34
+ export function AssistantChat() {
35
+ const ui = useUi();
36
+ const s = useSnapshot(ui.assistant);
37
+ const List = override(ui, "MessageList") ?? MessageList;
38
+ const Work = override(ui, "WorkCard") ?? WorkCard;
39
+ const Compose = override(ui, "Composer") ?? Composer;
40
+ useEffect(() => { ui.assistant.stateWatch.start(); }, [ui.assistant]); // the mode, cards waiting and usage (as in Svelte)
41
+ return (<view className={cls(ui, "chat")} style={{ display: "flex", flexDirection: "column", ...fill, minHeight: 0, backgroundColor: tok(ui, "surface", "#fff") }}>
42
+ <Small kind="mode" state={s.state}/>
43
+ <List messages={s.messages} plans={s.plans} runId={s.run?.runId ?? null}/>
44
+ {s.run ? <Work run={s.run}/> : null}
45
+ {s.error ? <text style={{ color: tok(ui, "danger", "#b42318") }}>{ui.texts.t(s.error)}</text> : null}
46
+ <Compose busy={s.busy} attachments={s.attachments}/>
47
+ </view>);
48
+ }
49
+ export function AssistantPanel(props) {
50
+ const ui = useUi();
51
+ const t = ui.texts.t;
52
+ const layout = pickLayout(props.layout ?? "auto", props.width);
53
+ if (!props.open && layout !== "inline" && layout !== "card")
54
+ return null;
55
+ const frame = layout === "sheet" ? { position: "fixed", left: 0, right: 0, bottom: 0, height: "85%", borderTopLeftRadius: "16px", borderTopRightRadius: "16px" }
56
+ : layout === "side" ? { position: "fixed", top: 0, bottom: 0, right: 0, width: "420px" }
57
+ : layout === "fullscreen" ? { position: "fixed", top: 0, bottom: 0, left: 0, right: 0 }
58
+ : layout === "card" ? { borderRadius: tok(ui, "radius", "10px"), maxHeight: "520px" }
59
+ : { width: "100%", height: "100%" };
60
+ return (<view className={cls(ui, "panel")} style={{ ...frame, direction: "ltr", display: "flex", flexDirection: "column", zIndex: layout === "inline" || layout === "card" ? 0 : ui.layer - 1, backgroundColor: tok(ui, "surface", "#fff") }}>
61
+ {layout !== "compact" ? (<view className={cls(ui, "panel.header")} style={{ ...rowOf(ui), padding: "12px" }}>
62
+ {/* on a device a text does not grow in a row: a view takes the room, and the link keeps its distance */}
63
+ <view style={{ ...fill, minWidth: 0 }}><text style={{ fontWeight: "bold" }} text-maxline="1">{props.title ?? t("assistant.name")}</text></view>
64
+ <view accessibility-element={true} accessibility-label={t("panel.new")} bindtap={() => ui.assistant.fresh()} style={{ marginLeft: "12px", marginRight: "12px" }}><text>{t("panel.new")}</text></view>
65
+ {props.onClose ? <view accessibility-element={true} accessibility-label={t("panel.close")} bindtap={props.onClose} style={{ marginLeft: "12px" }}><text>×</text></view> : null}
66
+ </view>) : null}
67
+ <AssistantChat />
68
+ </view>);
69
+ }
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "@g9tm/aiassistant-lynx",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0",
4
+ "description": "ReactLynx components for the G9 AI assistant, fully customisable (layouts, tokens, per-part classes, overrides, parts).",
5
+ "license": "MIT",
6
+ "author": {
7
+ "name": "Iman Kari",
8
+ "url": "G9TM"
9
+ },
10
+ "type": "module",
11
+ "sideEffects": false,
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ },
19
+ "./admin": {
20
+ "types": "./dist/admin.d.ts",
21
+ "import": "./dist/admin.jsx"
22
+ }
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "README.md"
27
+ ],
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "dependencies": {
32
+ "@g9tm/aiassistant": "1.0.0"
33
+ },
34
+ "devDependencies": {
35
+ "@lynx-js/react": "0.129.2",
36
+ "@lynx-js/types": "4.4.2"
37
+ },
38
+ "peerDependencies": {
39
+ "@lynx-js/react": ">=0.100.0"
40
+ },
41
+ "scripts": {
42
+ "build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.json",
43
+ "typecheck": "tsc -p tsconfig.json --noEmit"
44
+ }
6
45
  }