@g9tm/aiassistant-react 0.0.0-stage → 1.8.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/README.md +34 -2
- package/dist/admin.d.ts +10 -0
- package/dist/admin.js +191 -0
- package/dist/blocks.d.ts +36 -0
- package/dist/blocks.js +112 -0
- package/dist/browser.d.ts +16 -0
- package/dist/browser.js +80 -0
- package/dist/cards.d.ts +19 -0
- package/dist/cards.js +58 -0
- package/dist/context.d.ts +46 -0
- package/dist/context.js +68 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +12 -0
- package/dist/pages.d.ts +41 -0
- package/dist/pages.js +274 -0
- package/dist/parts.d.ts +63 -0
- package/dist/parts.js +200 -0
- package/dist/slots.d.ts +24 -0
- package/dist/slots.js +42 -0
- package/dist/styles.d.ts +5 -0
- package/dist/styles.js +105 -0
- package/dist/surfaces.d.ts +68 -0
- package/dist/surfaces.js +138 -0
- package/dist/theme.d.ts +10 -0
- package/dist/theme.js +22 -0
- package/package.json +42 -3
package/dist/parts.js
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The conversation's parts for React DOM, each exported on its own so a host can compose its own panel: a message, the
|
|
4
|
+
* work card, the composer, the model picker, the PDF button, the small chips, the thinking orb and the stages.
|
|
5
|
+
*/
|
|
6
|
+
import { useEffect, useRef, useState } from "react";
|
|
7
|
+
import { can, finished, LONG_RUNNING_MS, obj, REVEAL_MS, str, visibleText, windowView } from "@g9tm/aiassistant";
|
|
8
|
+
import { pageCalls, pageTexts, readModels } from "@g9tm/aiassistant/pages";
|
|
9
|
+
import { BlockView, TextView } from "./blocks.js";
|
|
10
|
+
import { ApprovalCard, Cards } from "./cards.js";
|
|
11
|
+
import { cls, override, sty, swappable, useSnapshot, useUi } from "./context.js";
|
|
12
|
+
/** The time now, ticking every `ms` while `on` (for elapsed time and reveal); still while it is off. */
|
|
13
|
+
function useNow(ms, on) {
|
|
14
|
+
const [now, setNow] = useState(() => Date.now());
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (!on)
|
|
17
|
+
return undefined;
|
|
18
|
+
const h = setInterval(() => setNow(Date.now()), ms);
|
|
19
|
+
return () => clearInterval(h);
|
|
20
|
+
}, [ms, on]);
|
|
21
|
+
return now;
|
|
22
|
+
}
|
|
23
|
+
/** Reveals an answer that arrived in front of the person over about 1.5 s; history and reduced motion show it whole. */
|
|
24
|
+
export function RevealText(props) {
|
|
25
|
+
const ui = useUi();
|
|
26
|
+
const [started] = useState(() => Date.now());
|
|
27
|
+
const animate = (props.reveal ?? false) && !ui.assistant.host.reducedMotion;
|
|
28
|
+
const [done, setDone] = useState(!animate);
|
|
29
|
+
const now = useNow(80, animate && !done); // one render per 80 ms at most
|
|
30
|
+
const elapsed = now - started;
|
|
31
|
+
useEffect(() => { if (elapsed >= REVEAL_MS)
|
|
32
|
+
setDone(true); }, [elapsed]);
|
|
33
|
+
const shown = animate && !done ? visibleText(props.text, elapsed, false) : props.text;
|
|
34
|
+
return _jsx("div", { className: cls(ui, "reveal-text"), "aria-busy": shown.length < props.text.length, children: _jsx(TextView, { text: shown }) });
|
|
35
|
+
}
|
|
36
|
+
/** Small parts used across the components: the provenance chip, the offline banner and the usage chip. */
|
|
37
|
+
export function Small(props) {
|
|
38
|
+
const ui = useUi();
|
|
39
|
+
const t = ui.texts.t;
|
|
40
|
+
const s = props.state ?? null;
|
|
41
|
+
if (props.kind === "provenance" && props.provenance)
|
|
42
|
+
return _jsx("span", { className: cls(ui, "message.provenance"), "data-provenance": props.provenance, children: t("provenance." + props.provenance) });
|
|
43
|
+
if (props.kind === "mode" && s && s.mode !== "on") {
|
|
44
|
+
const until = s.until ? new Date(s.until).toLocaleTimeString(ui.texts.locale === "fa" ? "fa-IR" : "en-GB", { hour: "2-digit", minute: "2-digit" }) : null;
|
|
45
|
+
return _jsx("div", { className: cls(ui, "mode-banner"), role: "status", children: s.mode === "off" ? t("mode.off") : until ? t("mode.offline_until", { until }) : t("mode.offline") });
|
|
46
|
+
}
|
|
47
|
+
const usage = props.kind === "usage" && s?.usage[0] ? windowView(s.usage[0], Date.now()) : null;
|
|
48
|
+
if (usage) {
|
|
49
|
+
const left = Math.round(usage.left * 100);
|
|
50
|
+
return _jsx("span", { className: cls(ui, "usage-chip"), style: { ["--g9a-usage"]: String(left) + "%" }, children: t("usage.left", { percent: String(left) + "%" }) });
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
/** The thinking orb: transform and opacity only; static with reduced motion. */
|
|
55
|
+
export const ThinkingOrb = swappable("ThinkingOrb", () => {
|
|
56
|
+
const ui = useUi();
|
|
57
|
+
return _jsx("span", { className: cls(ui, "thinking-orb"), "data-still": ui.assistant.host.reducedMotion, "aria-hidden": "true" });
|
|
58
|
+
});
|
|
59
|
+
/** Named stages lit by the run's real stage events (a pipeline's roles too, by the names given); never a show of thinking. */
|
|
60
|
+
export const StagesThinking = swappable("StagesThinking", (props) => {
|
|
61
|
+
const ui = useUi();
|
|
62
|
+
const names = new Map(Object.entries(props.names ?? {}));
|
|
63
|
+
const name = (s) => (s.role ? (names.get(s.role) ?? s.role) : ui.texts.t("stage." + s.id));
|
|
64
|
+
return (_jsx("div", { className: cls(ui, "stages-thinking"), children: props.run.stages.filter((s) => s.id === "role" || names.has(s.id) || s.id !== "waiting").map((s, i) => _jsx("span", { "data-state": s.state, "data-stage": s.id, children: name(s) }, i)) }));
|
|
65
|
+
});
|
|
66
|
+
/**
|
|
67
|
+
* "Working": the run's real stages (from its stage events), the progress line, tools, the clock, stop; after 40 s,
|
|
68
|
+
* "still working". The clock starts again when another run comes into the same card.
|
|
69
|
+
*/
|
|
70
|
+
export function WorkCard(props) {
|
|
71
|
+
const ui = useUi();
|
|
72
|
+
const t = ui.texts.t;
|
|
73
|
+
const r = props.run;
|
|
74
|
+
const live = !finished(r);
|
|
75
|
+
const [started, setStarted] = useState(() => Date.now() - r.elapsedMs);
|
|
76
|
+
useEffect(() => { setStarted(Date.now() - r.elapsedMs); }, [r.runId]); // the clock of this run only
|
|
77
|
+
const now = useNow(1000, live);
|
|
78
|
+
if (!live || r.state === "waiting-confirm" || r.state === "waiting-answer")
|
|
79
|
+
return null;
|
|
80
|
+
const seconds = Math.max(0, Math.round((now - started) / 1000));
|
|
81
|
+
const long = r.longRunning || now - started >= LONG_RUNNING_MS;
|
|
82
|
+
const label = (s) => (s.id === "role" ? t("stage.role", { role: s.role ?? "" }) : t("stage." + s.id));
|
|
83
|
+
return (_jsxs("div", { className: cls(ui, "work"), role: "status", children: [_jsx(ThinkingOrb, {}), _jsxs("div", { className: "g9a-work-main", children: [_jsxs("div", { className: "g9a-work-head", children: [_jsx("strong", { children: long ? t("work.long") : t("work.title") }), _jsx("span", { className: cls(ui, "work.elapsed"), children: t("work.elapsed", { seconds }) })] }), _jsx("div", { className: "g9a-stages", children: r.stages.filter((s) => s.id !== "waiting").map((s, i) => _jsx("span", { className: cls(ui, "work.stage"), "data-state": s.state, children: label(s) }, i)) }), r.progress ? _jsx("div", { className: cls(ui, "work.progress"), children: t(r.progress.key, r.progress.args) }) : null, r.tools.slice(-3).map((x, i) => _jsx("div", { className: cls(ui, "work.tool"), "data-state": x.state, children: t(x.title.key) === x.title.key ? x.name : t(x.title.key) }, i)), r.streamingText ? _jsx("div", { className: "g9a-stream", children: r.streamingText }) : null] }), _jsx("button", { type: "button", className: cls(ui, "composer.stop"), onClick: () => void ui.assistant.stop(), children: t("composer.stop") })] }));
|
|
84
|
+
}
|
|
85
|
+
/** One message: its text (revealed only when it arrived in front of the person), blocks, card, provenance and feedback. */
|
|
86
|
+
export function Message(props) {
|
|
87
|
+
const ui = useUi();
|
|
88
|
+
const t = ui.texts.t;
|
|
89
|
+
const m = props.message;
|
|
90
|
+
// Decided once, when the message first appears (the list is keyed by id): an answer seen once is never revealed again.
|
|
91
|
+
const [reveal] = useState(() => ui.assistant.watched.reveal(m.id) && m.role === "assistant" && !m.pending);
|
|
92
|
+
const [copied, setCopied] = useState(false);
|
|
93
|
+
const Approval = override(ui, "ApprovalCard") ?? ApprovalCard;
|
|
94
|
+
const Other = override(ui, "Card") ?? Cards;
|
|
95
|
+
const plan = m.card?.kind === "plan" ? props.plans.get(m.card.id) : undefined;
|
|
96
|
+
return (_jsx("div", { className: cls(ui, "message") + " " + cls(ui, m.role === "user" ? "message.user" : "message.assistant"), "data-kind": m.kind, "data-pending": m.pending, children: m.card ? (plan ? _jsx(Approval, { plan: plan }) : m.card.kind !== "plan" ? _jsx(Other, { card: m.card, runId: props.runId }) : null) : (_jsxs(_Fragment, { children: [m.text.length > 0 ? _jsx("div", { className: cls(ui, "message.text"), children: _jsx(RevealText, { text: m.text, reveal: reveal }) }) : null, m.blocks.map((b, i) => _jsx(BlockView, { block: b }, i)), m.next.length > 0 ? _jsx("div", { className: cls(ui, "block.actions"), children: m.next.map((n) => _jsx("button", { type: "button", className: cls(ui, "block.action"), onClick: () => void ui.assistant.send(n), children: n }, n)) }) : null, m.role === "assistant" ? (_jsxs("div", { className: cls(ui, "message.feedback"), children: [_jsx(Small, { kind: "provenance", provenance: m.provenance }), ui.assistant.host.copy ? _jsx("button", { type: "button", onClick: () => { void ui.assistant.host.copy?.(m.text); setCopied(true); }, children: copied ? "✓" : t("feedback.copy") }) : null, m.provenance === "learned" ? _jsx("button", { type: "button", onClick: () => void ui.assistant.notRight(m.id), children: t("feedback.not_right") }) : null] })) : null] })) }));
|
|
97
|
+
}
|
|
98
|
+
/** The composer: input, attach (only when the host can pick a file), mic (only when the host or the server can dictate), send or stop. */
|
|
99
|
+
export function Composer(props) {
|
|
100
|
+
const ui = useUi();
|
|
101
|
+
const t = ui.texts.t;
|
|
102
|
+
const host = ui.assistant.host;
|
|
103
|
+
const live = ui.assistant.stateWatch;
|
|
104
|
+
const [text, setText] = useState("");
|
|
105
|
+
const [voice, setVoice] = useState(live.state.voice);
|
|
106
|
+
const [recording, setRecording] = useState(null);
|
|
107
|
+
const input = useRef(null);
|
|
108
|
+
useEffect(() => live.subscribe((s) => setVoice(s.voice)), [live]);
|
|
109
|
+
const placeholder = props.placeholder ?? t("composer.placeholder");
|
|
110
|
+
const add = (said) => setText((x) => (x + " " + said).trim());
|
|
111
|
+
const send = async () => {
|
|
112
|
+
if (props.busy) {
|
|
113
|
+
await ui.assistant.stop();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if ((await ui.assistant.ask(text)) !== "refused")
|
|
117
|
+
setText("");
|
|
118
|
+
};
|
|
119
|
+
const dictate = async () => { const said = await host.dictate?.(); if (said)
|
|
120
|
+
add(said); };
|
|
121
|
+
// Recording: a tap starts, a second tap stops and the server turns the audio into text.
|
|
122
|
+
const record = async () => {
|
|
123
|
+
if (recording) {
|
|
124
|
+
const stop = recording;
|
|
125
|
+
setRecording(null);
|
|
126
|
+
const audio = await stop();
|
|
127
|
+
if (audio) {
|
|
128
|
+
const said = await ui.assistant.api.speech(audio.bytes, audio.mime).catch(() => "");
|
|
129
|
+
if (said)
|
|
130
|
+
add(said);
|
|
131
|
+
}
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const stop = (await host.record?.().catch(() => null)) ?? null;
|
|
135
|
+
setRecording(() => stop);
|
|
136
|
+
};
|
|
137
|
+
return (_jsxs("form", { className: cls(ui, "composer"), style: sty(ui, "composer"), onSubmit: (e) => { e.preventDefault(); void send(); }, children: [props.attachments.length > 0 ? (_jsx("div", { className: cls(ui, "file-chips"), children: props.attachments.map((a) => _jsxs("span", { className: cls(ui, "file-chip"), children: [a.name, _jsx("button", { type: "button", "aria-label": t("files.remove"), onClick: () => ui.assistant.detach(a.id), children: "\u00D7" })] }, a.id)) })) : null, _jsxs("div", { className: "g9a-composer-row", children: [can(host, "attach") ? _jsx("button", { type: "button", className: cls(ui, "composer.attach"), "aria-label": t("composer.attach"), onClick: () => void ui.assistant.attachFromDevice(), children: "\uD83D\uDCCE" }) : null, _jsx("textarea", { ref: input, value: text, className: cls(ui, "composer.input"), rows: 1, placeholder: placeholder, "aria-label": placeholder, onChange: (e) => setText(e.currentTarget.value), onKeyDown: (e) => { if (e.key === "Enter" && !e.shiftKey) {
|
|
138
|
+
e.preventDefault();
|
|
139
|
+
void send();
|
|
140
|
+
} } }), can(host, "mic") ? _jsx("button", { type: "button", className: cls(ui, "composer.mic"), "aria-label": t("composer.mic"), onClick: () => void dictate(), children: "\uD83C\uDF99" })
|
|
141
|
+
: voice && can(host, "record") ? _jsx("button", { type: "button", className: cls(ui, "composer.mic"), "aria-label": t("composer.mic"), "aria-pressed": recording !== null, onClick: () => void record(), children: recording ? "■" : "🎙" }) : null, _jsx("button", { type: "submit", className: cls(ui, props.busy ? "composer.stop" : "composer.send"), children: props.busy ? t("composer.stop") : t("composer.send") })] })] }));
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* The model and thinking effort for what the person sends next (`assistant.model`, kept on the conversation by the
|
|
145
|
+
* server). Drawn only where the host lets the person choose (`GET models` says `choose`); "automatic" leaves it to
|
|
146
|
+
* the route. A model that cannot answer now is listed but cannot be picked.
|
|
147
|
+
*/
|
|
148
|
+
export function ModelPicker(props) {
|
|
149
|
+
const ui = useUi();
|
|
150
|
+
const t = pageTexts(ui.texts).t;
|
|
151
|
+
const efforts = props.efforts ?? ["low", "medium", "high"];
|
|
152
|
+
const [choose, setChoose] = useState(false);
|
|
153
|
+
const [models, setModels] = useState([]);
|
|
154
|
+
const at = (ui.assistant.model ?? "").lastIndexOf("@");
|
|
155
|
+
const [id, setId] = useState(at > 0 ? (ui.assistant.model ?? "").slice(0, at) : (ui.assistant.model ?? ""));
|
|
156
|
+
const [effort, setEffort] = useState(at > 0 ? (ui.assistant.model ?? "").slice(at + 1) : "");
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
pageCalls.models(ui.assistant.api).then((raw) => { const r = readModels(raw); setChoose(r.choose && r.models.length > 0); setModels(r.models); }, () => setChoose(false));
|
|
159
|
+
}, [ui.assistant]);
|
|
160
|
+
const pick = (nextId, nextEffort) => {
|
|
161
|
+
setId(nextId);
|
|
162
|
+
setEffort(nextEffort);
|
|
163
|
+
ui.assistant.model = nextId.length === 0 ? null : nextEffort.length > 0 ? nextId + "@" + nextEffort : nextId;
|
|
164
|
+
};
|
|
165
|
+
if (!choose)
|
|
166
|
+
return null;
|
|
167
|
+
const effortLabel = (e) => (t("model.effort." + e) === "model.effort." + e ? e : t("model.effort." + e));
|
|
168
|
+
return (_jsxs("div", { className: cls(ui, "model-picker") + " g9a-model", children: [_jsxs("label", { className: "g9a-row", children: [t("model.label"), _jsxs("select", { value: id, onChange: (e) => pick(e.currentTarget.value, effort), children: [_jsx("option", { value: "", children: t("model.auto") }), models.map((m) => _jsx("option", { value: m.id, disabled: !m.ready, children: m.ready ? m.id : m.id + " (" + t("model.unavailable") + ")" }, m.id))] })] }), id.length > 0 && efforts.length > 0 ? (_jsxs("label", { className: "g9a-row", children: [t("model.effort"), _jsxs("select", { value: effort, onChange: (e) => pick(id, e.currentTarget.value), children: [_jsx("option", { value: "", children: t("model.effort.default") }), efforts.map((e) => _jsx("option", { value: e, children: effortLabel(e) }, e))] })] })) : null] }));
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* "Download PDF" of the open conversation, once it has messages: the server's signed link (ten minutes), opened by the
|
|
172
|
+
* host. Busy while the link is asked for; a notice if it could not be made. Hidden when the host cannot open links.
|
|
173
|
+
*/
|
|
174
|
+
export const PdfButton = swappable("PdfButton", () => {
|
|
175
|
+
const ui = useUi();
|
|
176
|
+
const t = pageTexts(ui.texts).t;
|
|
177
|
+
const s = useSnapshot(ui.assistant);
|
|
178
|
+
const [busy, setBusy] = useState(false);
|
|
179
|
+
const [failed, setFailed] = useState(false);
|
|
180
|
+
const id = s.conversationId;
|
|
181
|
+
if (!id || s.messages.length === 0 || typeof ui.assistant.host.openUrl !== "function")
|
|
182
|
+
return null;
|
|
183
|
+
const download = async () => {
|
|
184
|
+
if (busy)
|
|
185
|
+
return;
|
|
186
|
+
setBusy(true);
|
|
187
|
+
setFailed(false);
|
|
188
|
+
try {
|
|
189
|
+
const url = str(obj(await ui.assistant.api.documentLink(id))["url"]);
|
|
190
|
+
if (!/^(https:\/\/|\/(?!\/))/u.test(url))
|
|
191
|
+
throw new Error("no link"); // the server's own path or https only
|
|
192
|
+
ui.assistant.host.openUrl?.(url);
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
setFailed(true);
|
|
196
|
+
}
|
|
197
|
+
setBusy(false);
|
|
198
|
+
};
|
|
199
|
+
return (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "g9a-pdf", "aria-busy": busy, disabled: busy, onClick: () => void download(), children: busy ? t("pdf.busy") : t("pdf.download") }), failed ? _jsx("span", { className: "g9a-note g9a-pdf__failed", role: "alert", children: t("pdf.failed") }) : null] }));
|
|
200
|
+
});
|
package/dist/slots.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The slots: the library's own simple PinPad, SecretField and Dialog, each replaceable by name (`components` of
|
|
3
|
+
* AssistantRoot), so a host gives its design kit's pieces and the library draws with them everywhere.
|
|
4
|
+
*/
|
|
5
|
+
import type { ReactNode } from "react";
|
|
6
|
+
export interface PinPadProps {
|
|
7
|
+
label: string;
|
|
8
|
+
value: string;
|
|
9
|
+
onInput: (value: string) => void;
|
|
10
|
+
}
|
|
11
|
+
/** A numeric code field (a host may give its own). */
|
|
12
|
+
export declare const PinPad: import("./context.js").Part<PinPadProps>;
|
|
13
|
+
/** A secret the person types: sent once as the answer, then cleared; read from the field, never kept in state. */
|
|
14
|
+
export declare const SecretField: import("./context.js").Part<{
|
|
15
|
+
onSubmit: (value: string) => void;
|
|
16
|
+
}>;
|
|
17
|
+
export interface DialogProps {
|
|
18
|
+
open: boolean;
|
|
19
|
+
label: string;
|
|
20
|
+
onClose?: () => void;
|
|
21
|
+
children?: ReactNode;
|
|
22
|
+
}
|
|
23
|
+
/** A dialog above the panel (sheetLayer + 1): Escape closes it, and focus goes back to what opened it. */
|
|
24
|
+
export declare const Dialog: import("./context.js").Part<DialogProps>;
|
package/dist/slots.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The slots: the library's own simple PinPad, SecretField and Dialog, each replaceable by name (`components` of
|
|
4
|
+
* AssistantRoot), so a host gives its design kit's pieces and the library draws with them everywhere.
|
|
5
|
+
*/
|
|
6
|
+
import { useEffect, useRef } from "react";
|
|
7
|
+
import { cls, swappable, useUi } from "./context.js";
|
|
8
|
+
/** A numeric code field (a host may give its own). */
|
|
9
|
+
export const PinPad = swappable("PinPad", (props) => (_jsx("input", { className: "g9a-pin", type: "password", inputMode: "numeric", autoComplete: "one-time-code", "aria-label": props.label, placeholder: props.label, value: props.value, onChange: (e) => props.onInput(e.currentTarget.value) })));
|
|
10
|
+
/** A secret the person types: sent once as the answer, then cleared; read from the field, never kept in state. */
|
|
11
|
+
export const SecretField = swappable("SecretField", (props) => {
|
|
12
|
+
const ui = useUi();
|
|
13
|
+
const t = ui.texts.t;
|
|
14
|
+
const input = useRef(null);
|
|
15
|
+
return (_jsxs("form", { className: cls(ui, "secret-field"), autoComplete: "off", onSubmit: (e) => {
|
|
16
|
+
e.preventDefault();
|
|
17
|
+
const field = input.current;
|
|
18
|
+
if (!field || field.value.length === 0)
|
|
19
|
+
return;
|
|
20
|
+
const value = field.value;
|
|
21
|
+
field.value = ""; // read straight from the field, never held in state
|
|
22
|
+
props.onSubmit(value);
|
|
23
|
+
}, children: [_jsx("input", { ref: input, type: "password", autoComplete: "off", "aria-label": t("secret.hint"), placeholder: t("secret.hint") }), _jsx("button", { type: "submit", children: t("ask.send") })] }));
|
|
24
|
+
});
|
|
25
|
+
/** A dialog above the panel (sheetLayer + 1): Escape closes it, and focus goes back to what opened it. */
|
|
26
|
+
export const Dialog = swappable("Dialog", (props) => {
|
|
27
|
+
const ui = useUi();
|
|
28
|
+
const before = useRef(null);
|
|
29
|
+
const box = useRef(null);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!props.open)
|
|
32
|
+
return undefined;
|
|
33
|
+
before.current = document.activeElement;
|
|
34
|
+
box.current?.focus();
|
|
35
|
+
return () => { if (before.current instanceof HTMLElement)
|
|
36
|
+
before.current.focus(); };
|
|
37
|
+
}, [props.open]);
|
|
38
|
+
if (!props.open)
|
|
39
|
+
return null;
|
|
40
|
+
return (_jsxs("div", { ref: box, className: "g9a-dialog", role: "dialog", "aria-modal": "true", "aria-label": props.label, tabIndex: -1, style: { zIndex: ui.layer + 1 }, onKeyDown: (e) => { if (e.key === "Escape")
|
|
41
|
+
props.onClose?.(); }, children: [props.onClose ? _jsx("button", { type: "button", className: "g9a-dialog__close", "aria-label": ui.texts.t("panel.close"), onClick: props.onClose, children: "\u00D7" }) : null, props.children] }));
|
|
42
|
+
});
|
package/dist/styles.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The library's own look, from theme tokens only, all under `.g9a-styled` (no global CSS): the same rules as the
|
|
3
|
+
* Svelte renderer. `unstyled` leaves structure and class names only, and this sheet is not drawn.
|
|
4
|
+
*/
|
|
5
|
+
export declare const STYLES = ".g9a-root { display: contents; }\n.g9a-styled { font-family: var(--g9a-font); font-size: var(--g9a-font-size); color: var(--g9a-ink); line-height: 1.6; }\n.g9a-styled button { font: inherit; cursor: pointer; min-block-size: 38px; padding: 0 12px; border-radius: var(--g9a-radius-s); border: 1px solid var(--g9a-line); background: var(--g9a-surface); color: var(--g9a-ink); }\n.g9a-styled input, .g9a-styled textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--g9a-line); border-radius: var(--g9a-radius-s); background: var(--g9a-surface); color: var(--g9a-ink); }\n.g9a-styled .g9a-panel { box-sizing: border-box; display: flex; flex-direction: column; background: var(--g9a-surface); color: var(--g9a-ink); box-shadow: var(--g9a-shadow); overflow: hidden; }\n.g9a-styled .g9a-panel[data-layout=\"side\"] { position: fixed; inset-block: 0; inset-inline-end: 0; inline-size: min(420px, 100%); border-inline-start: 1px solid var(--g9a-line); }\n.g9a-styled .g9a-panel[data-layout=\"sheet\"] { position: fixed; inset-inline: 0; inset-block-end: 0; block-size: 85vh; border-start-start-radius: 16px; border-start-end-radius: 16px; }\n.g9a-styled .g9a-panel[data-layout=\"fullscreen\"] { position: fixed; inset: 0; }\n.g9a-styled .g9a-panel[data-layout=\"inline\"] { inline-size: 100%; block-size: 100%; box-shadow: none; border: 1px solid var(--g9a-line); border-radius: var(--g9a-radius); }\n.g9a-styled .g9a-panel[data-layout=\"card\"] { border-radius: var(--g9a-radius); border: 1px solid var(--g9a-line); max-block-size: 520px; }\n.g9a-styled .g9a-panel[data-layout=\"compact\"] { box-shadow: none; }\n.g9a-styled .g9a-panel__header { display: flex; align-items: center; gap: var(--g9a-gap); padding: var(--g9a-pad); border-bottom: 1px solid var(--g9a-line); }\n.g9a-styled .g9a-panel__header > strong { flex: 1; min-inline-size: 0; }\n.g9a-styled .g9a-panel__body, .g9a-styled .g9a-chat { display: flex; flex-direction: column; flex: 1; min-block-size: 0; }\n.g9a-styled .g9a-messages { flex: 1; overflow-y: auto; padding: var(--g9a-pad); display: flex; flex-direction: column; gap: var(--g9a-gap); }\n.g9a-styled .g9a-message { max-inline-size: 88%; padding: 8px 12px; border-radius: var(--g9a-radius); background: var(--g9a-surface-2); }\n.g9a-styled .g9a-message__user { align-self: flex-start; background: var(--g9a-user-bubble, color-mix(in srgb, var(--g9a-accent) 12%, var(--g9a-surface))); }\n.g9a-styled .g9a-message__assistant { align-self: flex-end; }\n.g9a-styled .g9a-message[data-pending=\"true\"] { opacity: .7; }\n.g9a-styled .g9a-message__feedback { display: flex; gap: 6px; align-items: center; margin-block-start: 4px; }\n.g9a-styled .g9a-message__feedback button { min-block-size: 26px; font-size: 12px; padding: 0 8px; }\n.g9a-styled .g9a-message__provenance { font-size: 11px; color: var(--g9a-muted); }\n.g9a-styled .g9a-p { margin: 0 0 6px; white-space: pre-wrap; overflow-wrap: anywhere; }\n.g9a-styled code { font-family: ui-monospace, monospace; background: var(--g9a-surface); border-radius: 4px; padding: 0 4px; }\n.g9a-styled a { color: var(--g9a-accent); }\n.g9a-styled .g9a-work { display: flex; gap: var(--g9a-gap); align-items: flex-start; padding: var(--g9a-pad); border-top: 1px solid var(--g9a-line); }\n.g9a-styled .g9a-work-main { flex: 1; min-inline-size: 0; }\n.g9a-styled .g9a-work-head { display: flex; justify-content: space-between; gap: var(--g9a-gap); }\n.g9a-styled .g9a-work__elapsed, .g9a-styled .g9a-work__tool, .g9a-styled .g9a-note { color: var(--g9a-muted); font-size: 12px; }\n.g9a-styled .g9a-stages, .g9a-styled .g9a-stages-thinking { display: flex; flex-wrap: wrap; gap: 6px; margin-block: 4px; }\n.g9a-styled .g9a-work__stage, .g9a-styled .g9a-stages-thinking > span { padding: 1px 10px; border-radius: 999px; border: 1px solid var(--g9a-line); font-size: 12px; color: var(--g9a-muted); }\n.g9a-styled [data-state=\"on\"].g9a-work__stage, .g9a-styled .g9a-stages-thinking > [data-state=\"on\"] { background: color-mix(in srgb, var(--g9a-accent) 20%, transparent); color: var(--g9a-ink); border-color: var(--g9a-accent); }\n.g9a-styled .g9a-thinking-orb { inline-size: 18px; block-size: 18px; border-radius: 50%; background: var(--g9a-accent); animation: g9a-pulse 1.2s ease-in-out infinite; flex: none; margin-block-start: 4px; }\n.g9a-styled .g9a-thinking-orb[data-still=\"true\"] { animation: none; }\n@keyframes g9a-pulse { 0%, 100% { transform: scale(.8); opacity: .6; } 50% { transform: scale(1); opacity: 1; } }\n@media (prefers-reduced-motion: reduce) { .g9a-styled .g9a-thinking-orb { animation: none; } }\n.g9a-styled .g9a-composer { padding: var(--g9a-pad); border-top: 1px solid var(--g9a-line); }\n.g9a-styled .g9a-composer-row { display: flex; gap: var(--g9a-gap); align-items: flex-end; }\n.g9a-styled .g9a-composer__input { flex: 1; min-inline-size: 0; resize: none; max-block-size: 30vh; }\n.g9a-styled .g9a-composer__send { background: var(--g9a-accent); color: var(--g9a-accent-ink); border-color: var(--g9a-accent); }\n.g9a-styled .g9a-file-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-block-end: 6px; }\n.g9a-styled .g9a-file-chip { background: var(--g9a-surface-2); border-radius: 999px; padding: 2px 4px 2px 10px; font-size: 12px; }\n.g9a-styled .g9a-file-chip button { min-block-size: 20px; border: 0; background: none; padding: 0 6px; }\n.g9a-styled .g9a-card__approval { border: 1px solid var(--g9a-approval-card-border); border-radius: var(--g9a-radius); padding: var(--g9a-pad); background: var(--g9a-surface); }\n.g9a-styled .g9a-card__approval h3 { margin: 0 0 6px; font-size: 15px; }\n.g9a-styled .g9a-card__approval__fact { font-size: 12px; color: var(--g9a-muted); padding-inline-start: 24px; }\n.g9a-styled .g9a-card__approval__confirm { background: var(--g9a-accent); color: var(--g9a-accent-ink); border-color: var(--g9a-accent); }\n.g9a-styled .g9a-warning { color: var(--g9a-warn); font-size: 13px; }\n.g9a-styled .g9a-irreversible { color: var(--g9a-danger); font-size: 12px; }\n.g9a-styled .g9a-row { display: flex; gap: var(--g9a-gap); margin-block-start: 8px; }\n.g9a-styled .g9a-mode-banner { background: var(--g9a-surface-2); border-bottom: 1px solid var(--g9a-line); color: var(--g9a-warn); padding: 6px var(--g9a-pad); font-size: 13px; }\n.g9a-styled .g9a-usage-chip { display: inline-block; block-size: 22px; line-height: 22px; padding: 0 8px; border-radius: 999px; font-size: 11px;\nbackground: linear-gradient(to left, var(--g9a-surface-2) calc(100% - var(--g9a-usage)), color-mix(in srgb, var(--g9a-accent) 25%, transparent) 0); }\n.g9a-styled .g9a-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--g9a-line); margin-block-end: 8px; }\n.g9a-styled .g9a-tabs [aria-selected=\"true\"] { border-bottom: 2px solid var(--g9a-accent); }\n.g9a-styled .g9a-admin-capability { border: 1px solid var(--g9a-line); border-radius: 8px; padding: 8px; margin-block-end: 8px; display: grid; gap: 4px; }\n.g9a-styled .g9a-admin-capability label { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }\n.g9a-styled [data-bad=\"true\"], .g9a-styled [data-ok=\"false\"] { color: var(--g9a-danger); }\n.g9a-styled .g9a-block-title { font-weight: 600; margin-block: 4px; }\n.g9a-styled .g9a-block__table table { border-collapse: collapse; inline-size: 100%; font-size: 13px; }\n.g9a-styled .g9a-block__table th, .g9a-styled .g9a-block__table td { border-bottom: 1px solid var(--g9a-line); padding: 4px 6px; text-align: start; }\n.g9a-styled [data-kind=\"number\"], .g9a-styled [data-kind=\"money\"], .g9a-styled [data-kind=\"percent\"] { text-align: end; font-variant-numeric: tabular-nums; }\n.g9a-styled .g9a-block__table__card { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0 0 6px; padding: 6px 8px; background: var(--g9a-surface); border-radius: var(--g9a-radius-s); }\n.g9a-styled .g9a-block__table__card dt { color: var(--g9a-muted); }\n.g9a-styled .g9a-block__table__card dd { margin: 0; }\n.g9a-styled .g9a-block__chart__bar { display: grid; grid-template-columns: 1fr; gap: 2px; margin-block-end: 6px; }\n.g9a-styled .g9a-bar-track { display: block; block-size: 10px; background: var(--g9a-surface); border-radius: 5px; overflow: hidden; }\n.g9a-styled .g9a-bar-fill { display: block; block-size: 100%; background: var(--g9a-chart-bar); border-radius: 5px; }\n.g9a-styled .g9a-bar-value { font-size: 12px; color: var(--g9a-muted); }\n.g9a-styled .g9a-block__chart__line { inline-size: 100%; block-size: 140px; }\n.g9a-styled .g9a-block__chart__line path { stroke: var(--g9a-chart-bar); stroke-width: 2; }\n.g9a-styled .g9a-donut { inline-size: 120px; }\n.g9a-styled .g9a-donut path { fill: none; stroke: var(--g9a-chart-bar); stroke-width: 14; }\n.g9a-styled .g9a-block__kpi { display: flex; flex-wrap: wrap; gap: var(--g9a-gap); }\n.g9a-styled .g9a-block__kpi > div { display: flex; flex-direction: column; padding: 6px 10px; background: var(--g9a-surface); border-radius: var(--g9a-radius-s); }\n.g9a-styled .g9a-block__actions { display: flex; flex-wrap: wrap; gap: 6px; margin-block-start: 6px; }\n.g9a-styled .g9a-block__action { background: color-mix(in srgb, var(--g9a-accent) 12%, var(--g9a-surface)); border-color: var(--g9a-accent); }\n.g9a-styled .g9a-block__action::after { content: \" \u2039\"; }\n.g9a-styled [dir=\"ltr\"] .g9a-block__action::after { content: \" \u203A\"; }\n.g9a-styled .g9a-suggested { font-size: 10px; color: var(--g9a-muted); margin-inline-start: 6px; }\n.g9a-styled .g9a-block__callout { border-inline-start: 3px solid var(--g9a-accent); padding: 6px 10px; background: var(--g9a-surface); }\n.g9a-styled .g9a-block__callout[data-tone=\"danger\"] { border-color: var(--g9a-danger); }\n.g9a-styled .g9a-block__callout[data-tone=\"warn\"] { border-color: var(--g9a-warn); }\n.g9a-styled .g9a-block__image img { max-inline-size: 100%; border-radius: var(--g9a-radius-s); }\n.g9a-styled .g9a-dialog { position: fixed; inset: 10% 8%; background: var(--g9a-surface); border-radius: var(--g9a-radius); box-shadow: var(--g9a-shadow); padding: var(--g9a-pad); overflow: auto; }\n.g9a-styled .g9a-hero { padding: var(--g9a-pad); border: 1px solid var(--g9a-line); border-radius: var(--g9a-radius); background: var(--g9a-surface); }\n.g9a-styled .g9a-badge { margin-inline-start: 6px; background: var(--g9a-danger); color: #fff; border-radius: 999px; padding: 0 6px; font-size: 11px; }\n.g9a-styled .g9a-measure { inline-size: 100%; block-size: 0; }\n.g9a-styled .g9a-count { font-size: 11px; color: var(--g9a-muted); margin-inline-start: 4px; }\n.g9a-styled .g9a-history__list, .g9a-styled .g9a-routines__list, .g9a-styled .g9a-picker__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }\n.g9a-styled .g9a-history__row { display: flex; gap: 4px; align-items: center; }\n.g9a-styled .g9a-history__open { flex: 1; min-inline-size: 0; text-align: start; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.g9a-styled .g9a-history__row[data-waiting=\"true\"] .g9a-history__open { border-color: var(--g9a-warn); }\n.g9a-styled .g9a-history__delete, .g9a-styled .g9a-history__delete-yes { color: var(--g9a-danger); }\n.g9a-styled .g9a-routines__form { display: grid; gap: var(--g9a-gap); }\n.g9a-styled .g9a-routines__slot { display: grid; gap: 2px; }\n.g9a-styled .g9a-routines__slot[data-state=\"missing\"] input, .g9a-styled .g9a-routines__slot[data-state=\"invalid\"] input { border-color: var(--g9a-danger); }\n.g9a-styled .g9a-routines__choose { inline-size: 100%; text-align: start; }\n.g9a-styled .g9a-picker__chosen { font-weight: 600; margin-inline-end: 6px; }\n.g9a-styled .g9a-csv { display: flex; gap: 6px; align-items: center; margin-block: 4px; }\n";
|
package/dist/styles.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The library's own look, from theme tokens only, all under `.g9a-styled` (no global CSS): the same rules as the
|
|
3
|
+
* Svelte renderer. `unstyled` leaves structure and class names only, and this sheet is not drawn.
|
|
4
|
+
*/
|
|
5
|
+
export const STYLES = `.g9a-root { display: contents; }
|
|
6
|
+
.g9a-styled { font-family: var(--g9a-font); font-size: var(--g9a-font-size); color: var(--g9a-ink); line-height: 1.6; }
|
|
7
|
+
.g9a-styled button { font: inherit; cursor: pointer; min-block-size: 38px; padding: 0 12px; border-radius: var(--g9a-radius-s); border: 1px solid var(--g9a-line); background: var(--g9a-surface); color: var(--g9a-ink); }
|
|
8
|
+
.g9a-styled input, .g9a-styled textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--g9a-line); border-radius: var(--g9a-radius-s); background: var(--g9a-surface); color: var(--g9a-ink); }
|
|
9
|
+
.g9a-styled .g9a-panel { box-sizing: border-box; display: flex; flex-direction: column; background: var(--g9a-surface); color: var(--g9a-ink); box-shadow: var(--g9a-shadow); overflow: hidden; }
|
|
10
|
+
.g9a-styled .g9a-panel[data-layout="side"] { position: fixed; inset-block: 0; inset-inline-end: 0; inline-size: min(420px, 100%); border-inline-start: 1px solid var(--g9a-line); }
|
|
11
|
+
.g9a-styled .g9a-panel[data-layout="sheet"] { position: fixed; inset-inline: 0; inset-block-end: 0; block-size: 85vh; border-start-start-radius: 16px; border-start-end-radius: 16px; }
|
|
12
|
+
.g9a-styled .g9a-panel[data-layout="fullscreen"] { position: fixed; inset: 0; }
|
|
13
|
+
.g9a-styled .g9a-panel[data-layout="inline"] { inline-size: 100%; block-size: 100%; box-shadow: none; border: 1px solid var(--g9a-line); border-radius: var(--g9a-radius); }
|
|
14
|
+
.g9a-styled .g9a-panel[data-layout="card"] { border-radius: var(--g9a-radius); border: 1px solid var(--g9a-line); max-block-size: 520px; }
|
|
15
|
+
.g9a-styled .g9a-panel[data-layout="compact"] { box-shadow: none; }
|
|
16
|
+
.g9a-styled .g9a-panel__header { display: flex; align-items: center; gap: var(--g9a-gap); padding: var(--g9a-pad); border-bottom: 1px solid var(--g9a-line); }
|
|
17
|
+
.g9a-styled .g9a-panel__header > strong { flex: 1; min-inline-size: 0; }
|
|
18
|
+
.g9a-styled .g9a-panel__body, .g9a-styled .g9a-chat { display: flex; flex-direction: column; flex: 1; min-block-size: 0; }
|
|
19
|
+
.g9a-styled .g9a-messages { flex: 1; overflow-y: auto; padding: var(--g9a-pad); display: flex; flex-direction: column; gap: var(--g9a-gap); }
|
|
20
|
+
.g9a-styled .g9a-message { max-inline-size: 88%; padding: 8px 12px; border-radius: var(--g9a-radius); background: var(--g9a-surface-2); }
|
|
21
|
+
.g9a-styled .g9a-message__user { align-self: flex-start; background: var(--g9a-user-bubble, color-mix(in srgb, var(--g9a-accent) 12%, var(--g9a-surface))); }
|
|
22
|
+
.g9a-styled .g9a-message__assistant { align-self: flex-end; }
|
|
23
|
+
.g9a-styled .g9a-message[data-pending="true"] { opacity: .7; }
|
|
24
|
+
.g9a-styled .g9a-message__feedback { display: flex; gap: 6px; align-items: center; margin-block-start: 4px; }
|
|
25
|
+
.g9a-styled .g9a-message__feedback button { min-block-size: 26px; font-size: 12px; padding: 0 8px; }
|
|
26
|
+
.g9a-styled .g9a-message__provenance { font-size: 11px; color: var(--g9a-muted); }
|
|
27
|
+
.g9a-styled .g9a-p { margin: 0 0 6px; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
28
|
+
.g9a-styled code { font-family: ui-monospace, monospace; background: var(--g9a-surface); border-radius: 4px; padding: 0 4px; }
|
|
29
|
+
.g9a-styled a { color: var(--g9a-accent); }
|
|
30
|
+
.g9a-styled .g9a-work { display: flex; gap: var(--g9a-gap); align-items: flex-start; padding: var(--g9a-pad); border-top: 1px solid var(--g9a-line); }
|
|
31
|
+
.g9a-styled .g9a-work-main { flex: 1; min-inline-size: 0; }
|
|
32
|
+
.g9a-styled .g9a-work-head { display: flex; justify-content: space-between; gap: var(--g9a-gap); }
|
|
33
|
+
.g9a-styled .g9a-work__elapsed, .g9a-styled .g9a-work__tool, .g9a-styled .g9a-note { color: var(--g9a-muted); font-size: 12px; }
|
|
34
|
+
.g9a-styled .g9a-stages, .g9a-styled .g9a-stages-thinking { display: flex; flex-wrap: wrap; gap: 6px; margin-block: 4px; }
|
|
35
|
+
.g9a-styled .g9a-work__stage, .g9a-styled .g9a-stages-thinking > span { padding: 1px 10px; border-radius: 999px; border: 1px solid var(--g9a-line); font-size: 12px; color: var(--g9a-muted); }
|
|
36
|
+
.g9a-styled [data-state="on"].g9a-work__stage, .g9a-styled .g9a-stages-thinking > [data-state="on"] { background: color-mix(in srgb, var(--g9a-accent) 20%, transparent); color: var(--g9a-ink); border-color: var(--g9a-accent); }
|
|
37
|
+
.g9a-styled .g9a-thinking-orb { inline-size: 18px; block-size: 18px; border-radius: 50%; background: var(--g9a-accent); animation: g9a-pulse 1.2s ease-in-out infinite; flex: none; margin-block-start: 4px; }
|
|
38
|
+
.g9a-styled .g9a-thinking-orb[data-still="true"] { animation: none; }
|
|
39
|
+
@keyframes g9a-pulse { 0%, 100% { transform: scale(.8); opacity: .6; } 50% { transform: scale(1); opacity: 1; } }
|
|
40
|
+
@media (prefers-reduced-motion: reduce) { .g9a-styled .g9a-thinking-orb { animation: none; } }
|
|
41
|
+
.g9a-styled .g9a-composer { padding: var(--g9a-pad); border-top: 1px solid var(--g9a-line); }
|
|
42
|
+
.g9a-styled .g9a-composer-row { display: flex; gap: var(--g9a-gap); align-items: flex-end; }
|
|
43
|
+
.g9a-styled .g9a-composer__input { flex: 1; min-inline-size: 0; resize: none; max-block-size: 30vh; }
|
|
44
|
+
.g9a-styled .g9a-composer__send { background: var(--g9a-accent); color: var(--g9a-accent-ink); border-color: var(--g9a-accent); }
|
|
45
|
+
.g9a-styled .g9a-file-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-block-end: 6px; }
|
|
46
|
+
.g9a-styled .g9a-file-chip { background: var(--g9a-surface-2); border-radius: 999px; padding: 2px 4px 2px 10px; font-size: 12px; }
|
|
47
|
+
.g9a-styled .g9a-file-chip button { min-block-size: 20px; border: 0; background: none; padding: 0 6px; }
|
|
48
|
+
.g9a-styled .g9a-card__approval { border: 1px solid var(--g9a-approval-card-border); border-radius: var(--g9a-radius); padding: var(--g9a-pad); background: var(--g9a-surface); }
|
|
49
|
+
.g9a-styled .g9a-card__approval h3 { margin: 0 0 6px; font-size: 15px; }
|
|
50
|
+
.g9a-styled .g9a-card__approval__fact { font-size: 12px; color: var(--g9a-muted); padding-inline-start: 24px; }
|
|
51
|
+
.g9a-styled .g9a-card__approval__confirm { background: var(--g9a-accent); color: var(--g9a-accent-ink); border-color: var(--g9a-accent); }
|
|
52
|
+
.g9a-styled .g9a-warning { color: var(--g9a-warn); font-size: 13px; }
|
|
53
|
+
.g9a-styled .g9a-irreversible { color: var(--g9a-danger); font-size: 12px; }
|
|
54
|
+
.g9a-styled .g9a-row { display: flex; gap: var(--g9a-gap); margin-block-start: 8px; }
|
|
55
|
+
.g9a-styled .g9a-mode-banner { background: var(--g9a-surface-2); border-bottom: 1px solid var(--g9a-line); color: var(--g9a-warn); padding: 6px var(--g9a-pad); font-size: 13px; }
|
|
56
|
+
.g9a-styled .g9a-usage-chip { display: inline-block; block-size: 22px; line-height: 22px; padding: 0 8px; border-radius: 999px; font-size: 11px;
|
|
57
|
+
background: linear-gradient(to left, var(--g9a-surface-2) calc(100% - var(--g9a-usage)), color-mix(in srgb, var(--g9a-accent) 25%, transparent) 0); }
|
|
58
|
+
.g9a-styled .g9a-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--g9a-line); margin-block-end: 8px; }
|
|
59
|
+
.g9a-styled .g9a-tabs [aria-selected="true"] { border-bottom: 2px solid var(--g9a-accent); }
|
|
60
|
+
.g9a-styled .g9a-admin-capability { border: 1px solid var(--g9a-line); border-radius: 8px; padding: 8px; margin-block-end: 8px; display: grid; gap: 4px; }
|
|
61
|
+
.g9a-styled .g9a-admin-capability label { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
|
|
62
|
+
.g9a-styled [data-bad="true"], .g9a-styled [data-ok="false"] { color: var(--g9a-danger); }
|
|
63
|
+
.g9a-styled .g9a-block-title { font-weight: 600; margin-block: 4px; }
|
|
64
|
+
.g9a-styled .g9a-block__table table { border-collapse: collapse; inline-size: 100%; font-size: 13px; }
|
|
65
|
+
.g9a-styled .g9a-block__table th, .g9a-styled .g9a-block__table td { border-bottom: 1px solid var(--g9a-line); padding: 4px 6px; text-align: start; }
|
|
66
|
+
.g9a-styled [data-kind="number"], .g9a-styled [data-kind="money"], .g9a-styled [data-kind="percent"] { text-align: end; font-variant-numeric: tabular-nums; }
|
|
67
|
+
.g9a-styled .g9a-block__table__card { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0 0 6px; padding: 6px 8px; background: var(--g9a-surface); border-radius: var(--g9a-radius-s); }
|
|
68
|
+
.g9a-styled .g9a-block__table__card dt { color: var(--g9a-muted); }
|
|
69
|
+
.g9a-styled .g9a-block__table__card dd { margin: 0; }
|
|
70
|
+
.g9a-styled .g9a-block__chart__bar { display: grid; grid-template-columns: 1fr; gap: 2px; margin-block-end: 6px; }
|
|
71
|
+
.g9a-styled .g9a-bar-track { display: block; block-size: 10px; background: var(--g9a-surface); border-radius: 5px; overflow: hidden; }
|
|
72
|
+
.g9a-styled .g9a-bar-fill { display: block; block-size: 100%; background: var(--g9a-chart-bar); border-radius: 5px; }
|
|
73
|
+
.g9a-styled .g9a-bar-value { font-size: 12px; color: var(--g9a-muted); }
|
|
74
|
+
.g9a-styled .g9a-block__chart__line { inline-size: 100%; block-size: 140px; }
|
|
75
|
+
.g9a-styled .g9a-block__chart__line path { stroke: var(--g9a-chart-bar); stroke-width: 2; }
|
|
76
|
+
.g9a-styled .g9a-donut { inline-size: 120px; }
|
|
77
|
+
.g9a-styled .g9a-donut path { fill: none; stroke: var(--g9a-chart-bar); stroke-width: 14; }
|
|
78
|
+
.g9a-styled .g9a-block__kpi { display: flex; flex-wrap: wrap; gap: var(--g9a-gap); }
|
|
79
|
+
.g9a-styled .g9a-block__kpi > div { display: flex; flex-direction: column; padding: 6px 10px; background: var(--g9a-surface); border-radius: var(--g9a-radius-s); }
|
|
80
|
+
.g9a-styled .g9a-block__actions { display: flex; flex-wrap: wrap; gap: 6px; margin-block-start: 6px; }
|
|
81
|
+
.g9a-styled .g9a-block__action { background: color-mix(in srgb, var(--g9a-accent) 12%, var(--g9a-surface)); border-color: var(--g9a-accent); }
|
|
82
|
+
.g9a-styled .g9a-block__action::after { content: " ‹"; }
|
|
83
|
+
.g9a-styled [dir="ltr"] .g9a-block__action::after { content: " ›"; }
|
|
84
|
+
.g9a-styled .g9a-suggested { font-size: 10px; color: var(--g9a-muted); margin-inline-start: 6px; }
|
|
85
|
+
.g9a-styled .g9a-block__callout { border-inline-start: 3px solid var(--g9a-accent); padding: 6px 10px; background: var(--g9a-surface); }
|
|
86
|
+
.g9a-styled .g9a-block__callout[data-tone="danger"] { border-color: var(--g9a-danger); }
|
|
87
|
+
.g9a-styled .g9a-block__callout[data-tone="warn"] { border-color: var(--g9a-warn); }
|
|
88
|
+
.g9a-styled .g9a-block__image img { max-inline-size: 100%; border-radius: var(--g9a-radius-s); }
|
|
89
|
+
.g9a-styled .g9a-dialog { position: fixed; inset: 10% 8%; background: var(--g9a-surface); border-radius: var(--g9a-radius); box-shadow: var(--g9a-shadow); padding: var(--g9a-pad); overflow: auto; }
|
|
90
|
+
.g9a-styled .g9a-hero { padding: var(--g9a-pad); border: 1px solid var(--g9a-line); border-radius: var(--g9a-radius); background: var(--g9a-surface); }
|
|
91
|
+
.g9a-styled .g9a-badge { margin-inline-start: 6px; background: var(--g9a-danger); color: #fff; border-radius: 999px; padding: 0 6px; font-size: 11px; }
|
|
92
|
+
.g9a-styled .g9a-measure { inline-size: 100%; block-size: 0; }
|
|
93
|
+
.g9a-styled .g9a-count { font-size: 11px; color: var(--g9a-muted); margin-inline-start: 4px; }
|
|
94
|
+
.g9a-styled .g9a-history__list, .g9a-styled .g9a-routines__list, .g9a-styled .g9a-picker__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
|
|
95
|
+
.g9a-styled .g9a-history__row { display: flex; gap: 4px; align-items: center; }
|
|
96
|
+
.g9a-styled .g9a-history__open { flex: 1; min-inline-size: 0; text-align: start; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
97
|
+
.g9a-styled .g9a-history__row[data-waiting="true"] .g9a-history__open { border-color: var(--g9a-warn); }
|
|
98
|
+
.g9a-styled .g9a-history__delete, .g9a-styled .g9a-history__delete-yes { color: var(--g9a-danger); }
|
|
99
|
+
.g9a-styled .g9a-routines__form { display: grid; gap: var(--g9a-gap); }
|
|
100
|
+
.g9a-styled .g9a-routines__slot { display: grid; gap: 2px; }
|
|
101
|
+
.g9a-styled .g9a-routines__slot[data-state="missing"] input, .g9a-styled .g9a-routines__slot[data-state="invalid"] input { border-color: var(--g9a-danger); }
|
|
102
|
+
.g9a-styled .g9a-routines__choose { inline-size: 100%; text-align: start; }
|
|
103
|
+
.g9a-styled .g9a-picker__chosen { font-weight: 600; margin-inline-end: 6px; }
|
|
104
|
+
.g9a-styled .g9a-csv { display: flex; gap: 6px; align-items: center; margin-block: 4px; }
|
|
105
|
+
`;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Surfaces for React DOM: the root (context, theme variables and the library's scoped sheet), the message list, the
|
|
3
|
+
* chat (a composition of exported parts only), the panel in its six layouts, and the small surfaces.
|
|
4
|
+
*/
|
|
5
|
+
import type { ReactNode } from "react";
|
|
6
|
+
import type { Assistant, Layout, LayoutThresholds, MessageView, PartStyles, PlanView } from "@g9tm/aiassistant";
|
|
7
|
+
import type { Overrides } from "./context.js";
|
|
8
|
+
export interface AssistantRootProps {
|
|
9
|
+
assistant: Assistant;
|
|
10
|
+
styles?: PartStyles;
|
|
11
|
+
unstyled?: boolean;
|
|
12
|
+
components?: Overrides;
|
|
13
|
+
children?: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The root of one assistant: shares the core, texts, part styles, overrides and theme with every component inside.
|
|
17
|
+
* All the library's styling is under `.g9a-styled`, from theme tokens; `unstyled` leaves structure and classes only.
|
|
18
|
+
*/
|
|
19
|
+
export declare function AssistantRoot(props: AssistantRootProps): ReactNode;
|
|
20
|
+
/**
|
|
21
|
+
* The messages, opened at the end; a new question stays at the top of the view so its answer is read from the start.
|
|
22
|
+
* New messages are announced politely to screen readers.
|
|
23
|
+
*/
|
|
24
|
+
export declare function MessageList(props: {
|
|
25
|
+
messages: MessageView[];
|
|
26
|
+
plans: ReadonlyMap<string, PlanView>;
|
|
27
|
+
runId: string | null;
|
|
28
|
+
}): ReactNode;
|
|
29
|
+
/** The chat: a composition of exported parts only (mode banner, messages, work card, composer). */
|
|
30
|
+
export declare function AssistantChat(props: {
|
|
31
|
+
placeholder?: string;
|
|
32
|
+
}): ReactNode;
|
|
33
|
+
export interface AssistantPanelProps {
|
|
34
|
+
/** Open or closed; left out, the panel keeps its own state (open at first). */
|
|
35
|
+
open?: boolean;
|
|
36
|
+
/** Told when the panel asks to open or close (Alt+A, Escape, ×). */
|
|
37
|
+
onOpenChange?: (open: boolean) => void;
|
|
38
|
+
onClose?: () => void;
|
|
39
|
+
layout?: Layout;
|
|
40
|
+
thresholds?: LayoutThresholds;
|
|
41
|
+
title?: string;
|
|
42
|
+
/** The header's own content in place of the title. */
|
|
43
|
+
header?: ReactNode;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The panel in six layouts (sheet, side, fullscreen, inline, card, compact) or "auto" by the container's width; the
|
|
47
|
+
* layout can change live without losing the conversation. Escape closes; Alt+A (by key position, so it works with a
|
|
48
|
+
* Persian keyboard) toggles; focus goes back to what opened it. Dialogs inside sit above the panel.
|
|
49
|
+
*/
|
|
50
|
+
export declare function AssistantPanel(props: AssistantPanelProps): ReactNode;
|
|
51
|
+
export type SurfaceKind = "hero" | "bar-button" | "ask-about";
|
|
52
|
+
export interface SurfaceProps {
|
|
53
|
+
kind: SurfaceKind;
|
|
54
|
+
greeting?: string;
|
|
55
|
+
starts?: string[];
|
|
56
|
+
subject?: {
|
|
57
|
+
label: string;
|
|
58
|
+
pageId: string;
|
|
59
|
+
kind?: string;
|
|
60
|
+
id?: string;
|
|
61
|
+
};
|
|
62
|
+
onOpen?: () => void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The small surfaces: the dashboard hero (greeting, one status line, three starts, a place to write), the bar button
|
|
66
|
+
* with the count of cards waiting, and "ask the assistant" about one thing (sent with the page and the subject).
|
|
67
|
+
*/
|
|
68
|
+
export declare function Surfaces(props: SurfaceProps): ReactNode;
|
package/dist/surfaces.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Surfaces for React DOM: the root (context, theme variables and the library's scoped sheet), the message list, the
|
|
4
|
+
* chat (a composition of exported parts only), the panel in its six layouts, and the small surfaces.
|
|
5
|
+
*/
|
|
6
|
+
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
7
|
+
import { pickLayout } from "@g9tm/aiassistant";
|
|
8
|
+
import { loadHostTexts, withHostTexts } from "@g9tm/aiassistant/pages";
|
|
9
|
+
import { cls, override, sty, UiProvider, useSnapshot, useUi } from "./context.js";
|
|
10
|
+
import { Composer, Message, PdfButton, Small, WorkCard } from "./parts.js";
|
|
11
|
+
import { STYLES } from "./styles.js";
|
|
12
|
+
import { themeVars } from "./theme.js";
|
|
13
|
+
/**
|
|
14
|
+
* The root of one assistant: shares the core, texts, part styles, overrides and theme with every component inside.
|
|
15
|
+
* All the library's styling is under `.g9a-styled`, from theme tokens; `unstyled` leaves structure and classes only.
|
|
16
|
+
*/
|
|
17
|
+
export function AssistantRoot(props) {
|
|
18
|
+
const a = props.assistant;
|
|
19
|
+
const host = a.host;
|
|
20
|
+
// The host's server words (its AssistantSetup.Texts), read once: a host key the client does not know shows in words.
|
|
21
|
+
const [own, setOwn] = useState({});
|
|
22
|
+
useEffect(() => { void loadHostTexts(a).then(setOwn); }, [a]);
|
|
23
|
+
const unstyled = props.unstyled ?? false;
|
|
24
|
+
const value = { assistant: a, texts: withHostTexts(a.texts, () => own), styles: props.styles ?? {}, unstyled, components: props.components ?? {}, layer: (host.sheetLayer ?? 1000) + 1 };
|
|
25
|
+
return (_jsx(UiProvider, { value: value, children: _jsxs("div", { className: unstyled ? "g9a-root" : "g9a-root g9a-styled", dir: host.dir, lang: host.locale, style: unstyled ? { display: "contents" } : { display: "contents", ...themeVars(host.theme) }, children: [unstyled ? null : _jsx("style", { children: STYLES }), props.children] }) }));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The messages, opened at the end; a new question stays at the top of the view so its answer is read from the start.
|
|
29
|
+
* New messages are announced politely to screen readers.
|
|
30
|
+
*/
|
|
31
|
+
export function MessageList(props) {
|
|
32
|
+
const ui = useUi();
|
|
33
|
+
const Item = override(ui, "Message") ?? Message;
|
|
34
|
+
const box = useRef(null);
|
|
35
|
+
const count = useRef(0);
|
|
36
|
+
const n = props.messages.length;
|
|
37
|
+
useLayoutEffect(() => {
|
|
38
|
+
const el = box.current;
|
|
39
|
+
if (!el || n === count.current)
|
|
40
|
+
return;
|
|
41
|
+
const last = props.messages[n - 1];
|
|
42
|
+
const node = last ? Array.from(el.children).find((c) => c.dataset["id"] === last.id) : undefined;
|
|
43
|
+
if (count.current === 0)
|
|
44
|
+
el.scrollTop = el.scrollHeight; // history opens at its end
|
|
45
|
+
else if (last?.role === "user" && node)
|
|
46
|
+
el.scrollTop = node.offsetTop - el.offsetTop; // the question at the top
|
|
47
|
+
count.current = n;
|
|
48
|
+
}, [n]);
|
|
49
|
+
return (_jsx("div", { className: cls(ui, "messages"), ref: box, "aria-live": "polite", children: props.messages.map((m) => _jsx("div", { "data-id": m.id, children: _jsx(Item, { message: m, plans: props.plans, runId: props.runId }) }, m.id)) }));
|
|
50
|
+
}
|
|
51
|
+
/** The chat: a composition of exported parts only (mode banner, messages, work card, composer). */
|
|
52
|
+
export function AssistantChat(props) {
|
|
53
|
+
const ui = useUi();
|
|
54
|
+
const s = useSnapshot(ui.assistant);
|
|
55
|
+
const List = override(ui, "MessageList") ?? MessageList;
|
|
56
|
+
const Work = override(ui, "WorkCard") ?? WorkCard;
|
|
57
|
+
const Compose = override(ui, "Composer") ?? Composer;
|
|
58
|
+
useEffect(() => { ui.assistant.stateWatch.start(); }, [ui.assistant]);
|
|
59
|
+
return (_jsxs("div", { className: cls(ui, "chat"), children: [_jsx(Small, { kind: "mode", state: s.state }), _jsx(List, { messages: s.messages, plans: s.plans, runId: s.run?.runId ?? null }), s.run ? _jsx(Work, { run: s.run }) : null, s.error ? _jsx("div", { className: "g9a-note", role: "alert", children: ui.texts.t(s.error) }) : null, _jsx(Compose, { busy: s.busy, attachments: s.attachments, placeholder: props.placeholder })] }));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The panel in six layouts (sheet, side, fullscreen, inline, card, compact) or "auto" by the container's width; the
|
|
63
|
+
* layout can change live without losing the conversation. Escape closes; Alt+A (by key position, so it works with a
|
|
64
|
+
* Persian keyboard) toggles; focus goes back to what opened it. Dialogs inside sit above the panel.
|
|
65
|
+
*/
|
|
66
|
+
export function AssistantPanel(props) {
|
|
67
|
+
const ui = useUi();
|
|
68
|
+
const t = ui.texts.t;
|
|
69
|
+
const [own, setOwn] = useState(true);
|
|
70
|
+
const open = props.open ?? own;
|
|
71
|
+
const [width, setWidth] = useState(1024);
|
|
72
|
+
const measure = useRef(null);
|
|
73
|
+
const opener = useRef(null);
|
|
74
|
+
const current = pickLayout(props.layout ?? "auto", width, props.thresholds);
|
|
75
|
+
const always = current === "inline" || current === "card";
|
|
76
|
+
const Pdf = override(ui, "PdfButton") ?? PdfButton;
|
|
77
|
+
const change = (next) => {
|
|
78
|
+
if (props.open === undefined)
|
|
79
|
+
setOwn(next);
|
|
80
|
+
props.onOpenChange?.(next);
|
|
81
|
+
if (!next) {
|
|
82
|
+
props.onClose?.();
|
|
83
|
+
if (opener.current instanceof HTMLElement)
|
|
84
|
+
opener.current.focus(); // focus goes back to what opened it
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
useLayoutEffect(() => {
|
|
88
|
+
const el = measure.current;
|
|
89
|
+
if (!el)
|
|
90
|
+
return undefined;
|
|
91
|
+
setWidth(el.clientWidth || 1024);
|
|
92
|
+
if (typeof ResizeObserver !== "function")
|
|
93
|
+
return undefined;
|
|
94
|
+
const watch = new ResizeObserver(() => setWidth(el.clientWidth || 1024));
|
|
95
|
+
watch.observe(el);
|
|
96
|
+
return () => watch.disconnect();
|
|
97
|
+
}, []);
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
const onKey = (e) => {
|
|
100
|
+
if (e.altKey && e.code === "KeyA") {
|
|
101
|
+
e.preventDefault();
|
|
102
|
+
if (!open)
|
|
103
|
+
opener.current = document.activeElement;
|
|
104
|
+
change(!open);
|
|
105
|
+
}
|
|
106
|
+
else if (e.key === "Escape" && open && !always)
|
|
107
|
+
change(false);
|
|
108
|
+
};
|
|
109
|
+
window.addEventListener("keydown", onKey);
|
|
110
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
111
|
+
});
|
|
112
|
+
return (_jsxs(_Fragment, { children: [_jsx("div", { className: "g9a-measure", ref: measure }), open || always ? (_jsxs("section", { className: cls(ui, "panel"), style: { ...(sty(ui, "panel") ?? {}), ...(always ? {} : { zIndex: ui.layer - 1 }) }, "data-layout": current, role: current === "sheet" || current === "fullscreen" ? "dialog" : "region", "aria-label": props.title ?? t("assistant.name"), children: [current !== "compact" ? (_jsxs("header", { className: cls(ui, "panel.header"), children: [props.header ?? _jsx("strong", { children: props.title ?? t("assistant.name") }), _jsx("button", { type: "button", onClick: () => ui.assistant.fresh(), children: t("panel.new") }), _jsx(Pdf, {}), always ? null : _jsx("button", { type: "button", "aria-label": t("panel.close"), onClick: () => change(false), children: "\u00D7" })] })) : null, _jsx("div", { className: cls(ui, "panel.body"), children: _jsx(AssistantChat, {}) })] })) : null] }));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The small surfaces: the dashboard hero (greeting, one status line, three starts, a place to write), the bar button
|
|
116
|
+
* with the count of cards waiting, and "ask the assistant" about one thing (sent with the page and the subject).
|
|
117
|
+
*/
|
|
118
|
+
export function Surfaces(props) {
|
|
119
|
+
const ui = useUi();
|
|
120
|
+
const t = ui.texts.t;
|
|
121
|
+
const s = useSnapshot(ui.assistant);
|
|
122
|
+
const [text, setText] = useState("");
|
|
123
|
+
const ask = async (q) => {
|
|
124
|
+
if (!q.trim())
|
|
125
|
+
return;
|
|
126
|
+
const sub = props.subject;
|
|
127
|
+
const page = sub ? { pageId: sub.pageId, ...(sub.kind ? { subjectKind: sub.kind } : {}), ...(sub.id ? { subjectId: sub.id } : {}), subjectLabel: sub.label } : undefined;
|
|
128
|
+
await ui.assistant.send(q, page);
|
|
129
|
+
setText("");
|
|
130
|
+
props.onOpen?.();
|
|
131
|
+
};
|
|
132
|
+
if (props.kind === "bar-button") {
|
|
133
|
+
return (_jsxs("button", { type: "button", className: cls(ui, "bar-button"), "aria-label": t("assistant.name"), onClick: () => props.onOpen?.(), children: [t("assistant.name"), s.state.waiting > 0 ? _jsx("span", { className: "g9a-badge", children: s.state.waiting }) : null] }));
|
|
134
|
+
}
|
|
135
|
+
if (props.kind === "ask-about")
|
|
136
|
+
return _jsx("button", { type: "button", className: cls(ui, "ask-about"), onClick: () => void ask(props.subject?.label ?? ""), children: t("assistant.name") + ": " + (props.subject?.label ?? "") });
|
|
137
|
+
return (_jsxs("div", { className: cls(ui, "hero"), children: [_jsx("h2", { children: props.greeting || t("assistant.name") }), s.state.mode !== "on" ? _jsx("p", { className: "g9a-note", children: t(s.state.mode === "off" ? "mode.off" : "mode.offline") }) : null, _jsx("div", { className: cls(ui, "block.actions"), children: (props.starts ?? []).slice(0, 3).map((x) => _jsx("button", { type: "button", className: cls(ui, "block.action"), onClick: () => void ask(x), children: x }, x)) }), _jsx("form", { onSubmit: (e) => { e.preventDefault(); void ask(text); }, children: _jsx("input", { value: text, placeholder: t("composer.placeholder"), "aria-label": t("composer.placeholder"), onChange: (e) => setText(e.currentTarget.value) }) })] }));
|
|
138
|
+
}
|