@surfaces-ui/chat 0.0.0-stage → 0.3.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.
Files changed (61) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +4 -0
  3. package/README.md +43 -2
  4. package/dist/AnalyticsChat.d.ts +82 -0
  5. package/dist/AnalyticsChat.js +168 -0
  6. package/dist/AnalyticsChat.js.map +1 -0
  7. package/dist/Approval.d.ts +18 -0
  8. package/dist/Approval.js +116 -0
  9. package/dist/Approval.js.map +1 -0
  10. package/dist/Chat.d.ts +112 -0
  11. package/dist/Chat.js +119 -0
  12. package/dist/Chat.js.map +1 -0
  13. package/dist/ChatComposer.d.ts +117 -0
  14. package/dist/ChatComposer.js +186 -0
  15. package/dist/ChatComposer.js.map +1 -0
  16. package/dist/ChatPanels.d.ts +34 -0
  17. package/dist/ChatPanels.js +75 -0
  18. package/dist/ChatPanels.js.map +1 -0
  19. package/dist/DataPanel.d.ts +19 -0
  20. package/dist/DataPanel.js +20 -0
  21. package/dist/DataPanel.js.map +1 -0
  22. package/dist/Menu.d.ts +37 -0
  23. package/dist/Menu.js +85 -0
  24. package/dist/Menu.js.map +1 -0
  25. package/dist/PageStudio.d.ts +103 -0
  26. package/dist/PageStudio.js +166 -0
  27. package/dist/PageStudio.js.map +1 -0
  28. package/dist/SessionList.d.ts +64 -0
  29. package/dist/SessionList.js +225 -0
  30. package/dist/SessionList.js.map +1 -0
  31. package/dist/appComponents.d.ts +6 -0
  32. package/dist/appComponents.js +100 -0
  33. package/dist/appComponents.js.map +1 -0
  34. package/dist/conversation.d.ts +66 -0
  35. package/dist/conversation.js +119 -0
  36. package/dist/conversation.js.map +1 -0
  37. package/dist/icons.d.ts +33 -0
  38. package/dist/icons.js +34 -0
  39. package/dist/icons.js.map +1 -0
  40. package/dist/index.d.ts +18 -0
  41. package/dist/index.js +19 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/selectors.d.ts +106 -0
  44. package/dist/selectors.js +160 -0
  45. package/dist/selectors.js.map +1 -0
  46. package/dist/sessions.d.ts +71 -0
  47. package/dist/sessions.js +194 -0
  48. package/dist/sessions.js.map +1 -0
  49. package/dist/speech.d.ts +43 -0
  50. package/dist/speech.js +89 -0
  51. package/dist/speech.js.map +1 -0
  52. package/dist/thread.d.ts +199 -0
  53. package/dist/thread.js +225 -0
  54. package/dist/thread.js.map +1 -0
  55. package/dist/useChat.d.ts +121 -0
  56. package/dist/useChat.js +293 -0
  57. package/dist/useChat.js.map +1 -0
  58. package/dist/voice.d.ts +41 -0
  59. package/dist/voice.js +128 -0
  60. package/dist/voice.js.map +1 -0
  61. package/package.json +72 -3
@@ -0,0 +1,225 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ItemControls, standardControls, useContextMenu } from "@surfaces-ui/components";
3
+ import { useEffect, useId, useMemo, useRef, useState } from "react";
4
+ import { MenuButton, MenuGroup, MenuItem } from "./Menu.js";
5
+ import { ChatIcon } from "./icons.js";
6
+ const DAY = 86_400_000;
7
+ const startOfDay = (now) => Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());
8
+ /** Whether one session matches the filters and the search. */
9
+ export function sessionMatches(session, state, now = new Date()) {
10
+ const words = (state.search ?? "").toLowerCase().split(/\s+/).filter(Boolean);
11
+ const text = `${session.title} ${session.lastMessage} ${session.tags.join(" ")}`.toLowerCase();
12
+ if (!words.every((w) => text.includes(w)))
13
+ return false;
14
+ if (state.pinned && !session.pinned)
15
+ return false;
16
+ if (state.agents?.length && !state.agents.includes(session.agentId ?? ""))
17
+ return false;
18
+ if (state.sources?.length && !session.sources.some((s) => state.sources.includes(s)))
19
+ return false;
20
+ if (state.tags?.length && !session.tags.some((t) => state.tags.includes(t)))
21
+ return false;
22
+ if (state.since) {
23
+ const at = Date.parse(session.updatedAt);
24
+ const today = startOfDay(now);
25
+ if (state.since === "today" && at < today)
26
+ return false;
27
+ if (state.since === "7d" && at < today - 6 * DAY)
28
+ return false;
29
+ if (state.since === "30d" && at < today - 29 * DAY)
30
+ return false;
31
+ if (state.since === "older" && at >= today - 29 * DAY)
32
+ return false;
33
+ }
34
+ return true;
35
+ }
36
+ /** Sorted as the state says; pinned sessions come first. */
37
+ export function sortSessions(sessions, state) {
38
+ const sort = state.sort ?? "updated";
39
+ const flip = (state.direction ?? (sort === "title" ? "asc" : "desc")) === "desc" ? -1 : 1;
40
+ const key = (s) => (sort === "title" ? s.title.toLowerCase() : sort === "created" ? s.createdAt : s.updatedAt);
41
+ return [...sessions].sort((a, b) => Number(b.pinned) - Number(a.pinned) || flip * key(a).localeCompare(key(b)) || a.id.localeCompare(b.id));
42
+ }
43
+ /** The day a session falls in, in words. */
44
+ export function dayBucket(iso, now = new Date()) {
45
+ const at = Date.parse(iso);
46
+ const today = startOfDay(now);
47
+ if (at >= today)
48
+ return "Today";
49
+ if (at >= today - DAY)
50
+ return "Yesterday";
51
+ if (at >= today - 6 * DAY)
52
+ return "Previous 7 days";
53
+ if (at >= today - 29 * DAY)
54
+ return "Previous 30 days";
55
+ return "Older";
56
+ }
57
+ /** Filtered, sorted and grouped, as the list draws it. A session with several sources or tags is listed under each. */
58
+ export function arrangeSessions(sessions, state, options = {}) {
59
+ const now = options.now ?? new Date();
60
+ const sorted = sortSessions(sessions.filter((s) => sessionMatches(s, state, now)), state);
61
+ const by = state.groupBy ?? "none";
62
+ if (by === "none")
63
+ return sorted.length ? [{ label: "", sessions: sorted }] : [];
64
+ const groups = new Map();
65
+ const put = (label, s) => groups.set(label, [...(groups.get(label) ?? []), s]);
66
+ for (const s of sorted) {
67
+ if (by === "day")
68
+ put(s.pinned ? "Pinned" : dayBucket(state.sort === "created" ? s.createdAt : s.updatedAt, now), s);
69
+ else if (by === "agent")
70
+ put(s.agentId ? (options.agentName?.(s.agentId) ?? s.agentId) : "No agent named", s);
71
+ else {
72
+ const keys = by === "source" ? s.sources : s.tags;
73
+ if (keys.length === 0)
74
+ put(by === "source" ? "No data attached" : "No tags", s);
75
+ for (const k of keys)
76
+ put(k, s);
77
+ }
78
+ }
79
+ const order = ["Pinned", "Today", "Yesterday", "Previous 7 days", "Previous 30 days", "Older"];
80
+ return [...groups.entries()]
81
+ .map(([label, list]) => ({ label, sessions: list }))
82
+ .sort((a, b) => (by === "day" ? order.indexOf(a.label) - order.indexOf(b.label) : a.label.startsWith("No ") ? 1 : b.label.startsWith("No ") ? -1 : a.label.localeCompare(b.label)));
83
+ }
84
+ const SORTS = [
85
+ { id: "updated", label: "Last activity" },
86
+ { id: "created", label: "Started" },
87
+ { id: "title", label: "Title" },
88
+ ];
89
+ const GROUPS = [
90
+ { id: "none", label: "No grouping" },
91
+ { id: "day", label: "Day" },
92
+ { id: "agent", label: "Agent" },
93
+ { id: "source", label: "Data source" },
94
+ { id: "tag", label: "Tag" },
95
+ ];
96
+ const SINCE = [
97
+ { id: "today", label: "Today" },
98
+ { id: "7d", label: "Last 7 days" },
99
+ { id: "30d", label: "Last 30 days" },
100
+ { id: "older", label: "Older than 30 days" },
101
+ ];
102
+ const time = new Intl.DateTimeFormat("en", { dateStyle: "medium", timeStyle: "short", timeZone: "UTC" });
103
+ /**
104
+ * Saved conversations a person can search, filter, sort and group. Each row
105
+ * opens its conversation; rename, pin and delete are on its controls and on
106
+ * its right-click menu, and delete asks first.
107
+ */
108
+ export function SessionList(props) {
109
+ const { sessions, current, onOpen, onNew, onRename, onPin, onRemove, agentName, height, rowHeight = 56, now } = props;
110
+ const [kept, setKept] = useState(props.defaultValue ?? {});
111
+ const state = props.value ?? kept;
112
+ const set = (patch) => {
113
+ const next = { ...state, ...patch };
114
+ for (const k of Object.keys(next)) {
115
+ const v = next[k];
116
+ if (v === undefined || v === "" || v === false || (Array.isArray(v) && v.length === 0))
117
+ delete next[k];
118
+ }
119
+ setKept(next);
120
+ props.onChange?.(next);
121
+ };
122
+ const [renaming, setRenaming] = useState();
123
+ const [confirming, setConfirming] = useState();
124
+ const [said, setSaid] = useState("");
125
+ const menu = useContextMenu();
126
+ const id = useId();
127
+ const groups = useMemo(() => arrangeSessions(sessions, state, { now, agentName }), [sessions, state, now, agentName]);
128
+ const rows = useMemo(() => groups.flatMap((g) => [...(g.label ? [{ type: "group", label: g.label, count: g.sessions.length }] : []), ...g.sessions.map((session) => ({ type: "session", session, group: g.label }))]), [groups]);
129
+ const shown = rows.filter((r) => r.type === "session").length;
130
+ // Windowing: only rows in view are drawn when the list scrolls inside.
131
+ const scroller = useRef(null);
132
+ const [top, setTop] = useState(0);
133
+ const first = height ? Math.max(0, Math.floor(top / rowHeight) - 4) : 0;
134
+ const last = height ? Math.min(rows.length, Math.ceil((top + height) / rowHeight) + 4) : rows.length;
135
+ useEffect(() => {
136
+ if (scroller.current && top > rows.length * rowHeight)
137
+ scroller.current.scrollTop = 0;
138
+ }, [rows.length, rowHeight, top]);
139
+ const facets = useMemo(() => {
140
+ const agents = [...new Set(sessions.flatMap((s) => (s.agentId ? [s.agentId] : [])))].sort();
141
+ const sources = [...new Set(sessions.flatMap((s) => s.sources))].sort();
142
+ const tags = [...new Set(sessions.flatMap((s) => s.tags))].sort();
143
+ return { agents, sources, tags };
144
+ }, [sessions]);
145
+ const toggleIn = (list, value) => (list?.includes(value) ? list.filter((x) => x !== value) : [...(list ?? []), value]);
146
+ const filterCount = (state.agents?.length ?? 0) + (state.sources?.length ?? 0) + (state.tags?.length ?? 0) + (state.pinned ? 1 : 0) + (state.since ? 1 : 0);
147
+ const actions = (s) => ({
148
+ rename: onRename ? () => setRenaming({ id: s.id, title: s.title }) : undefined,
149
+ pin: onPin ? () => {
150
+ onPin(s.id, !s.pinned);
151
+ setSaid(s.pinned ? `Unpinned ${s.title}.` : `Pinned ${s.title}.`);
152
+ } : undefined,
153
+ remove: onRemove ? () => setConfirming(s.id) : undefined,
154
+ });
155
+ const openMenu = (event, s) => {
156
+ const a = actions(s);
157
+ menu.open(event, s.title, [
158
+ { label: "Open", onSelect: () => onOpen(s.id) },
159
+ ...(a.rename ? [{ label: "Rename", onSelect: a.rename, hint: "F2" }] : []),
160
+ ...(a.pin ? [{ label: s.pinned ? "Unpin" : "Pin", onSelect: a.pin, hint: "P" }] : []),
161
+ ...(a.remove ? [{ separator: true }, { label: "Delete…", onSelect: a.remove, hint: "Delete" }] : []),
162
+ ]);
163
+ };
164
+ const onRowKey = (event, s) => {
165
+ if (event.target !== event.currentTarget)
166
+ return;
167
+ const a = actions(s);
168
+ if (event.key === "F2" && a.rename)
169
+ a.rename();
170
+ else if ((event.key === "p" || event.key === "P") && a.pin)
171
+ a.pin();
172
+ else if ((event.key === "Delete" || event.key === "Backspace") && a.remove)
173
+ a.remove();
174
+ else if (event.key === "ArrowDown" || event.key === "ArrowUp") {
175
+ const all = Array.from(event.currentTarget.closest(".sf-session-rows")?.querySelectorAll(".sf-session-open") ?? []);
176
+ const at = all.indexOf(event.currentTarget);
177
+ all[at + (event.key === "ArrowDown" ? 1 : -1)]?.focus();
178
+ }
179
+ else
180
+ return;
181
+ event.preventDefault();
182
+ };
183
+ const drawRow = (row, index) => {
184
+ if (row.type === "group")
185
+ return (_jsxs("li", { className: "sf-session-group", style: height ? { height: rowHeight } : undefined, role: "presentation", children: [_jsx("span", { children: row.label }), " ", _jsx("span", { className: "sf-session-count", children: row.count })] }, `g-${row.label}`));
186
+ const s = row.session;
187
+ const key = `${row.group}/${s.id}`;
188
+ if (renaming?.id === s.id)
189
+ return (_jsx("li", { className: "sf-session", style: height ? { height: rowHeight } : undefined, children: _jsxs("form", { className: "sf-session-rename", onSubmit: (e) => {
190
+ e.preventDefault();
191
+ const title = renaming.title.trim();
192
+ if (title && title !== s.title) {
193
+ onRename?.(s.id, title);
194
+ setSaid(`Renamed to ${title}.`);
195
+ }
196
+ setRenaming(undefined);
197
+ }, children: [_jsx("input", { className: "sf-input", "aria-label": `New title for ${s.title}`, value: renaming.title,
198
+ // biome-ignore lint/a11y/noAutofocus: the person asked to rename this row
199
+ autoFocus: true, onChange: (e) => setRenaming({ id: s.id, title: e.target.value }), onKeyDown: (e) => e.key === "Escape" && setRenaming(undefined) }), _jsx("button", { type: "submit", className: "sf-button", "data-variant": "primary", children: "Rename" }), _jsx("button", { type: "button", className: "sf-button", onClick: () => setRenaming(undefined), children: "Cancel" })] }) }, key));
200
+ if (confirming === s.id)
201
+ return (_jsxs("li", { className: "sf-session", "data-confirm": true, style: height ? { height: rowHeight } : undefined, role: "alert", children: [_jsxs("span", { className: "sf-session-confirm-text", children: ["Delete \u201C", s.title, "\u201D? It cannot be brought back."] }), _jsx("button", { type: "button", className: "sf-button", "data-variant": "danger",
202
+ // biome-ignore lint/a11y/noAutofocus: focus moves to the question the person just raised
203
+ autoFocus: true, onClick: () => {
204
+ onRemove?.(s.id);
205
+ setConfirming(undefined);
206
+ setSaid(`Deleted ${s.title}.`);
207
+ }, children: "Delete" }), _jsx("button", { type: "button", className: "sf-button", onClick: () => setConfirming(undefined), children: "Keep" })] }, key));
208
+ const a = actions(s);
209
+ const meta = [s.agentId ? (agentName?.(s.agentId) ?? s.agentId) : "", s.sources.join(", "), time.format(new Date(state.sort === "created" ? s.createdAt : s.updatedAt))].filter(Boolean).join(" · ");
210
+ return (_jsxs("li", { className: "sf-session sf-controls-host", "data-controls": "corner", "data-current": s.id === current || undefined, style: height ? { height: rowHeight } : undefined, children: [_jsxs("button", { type: "button", className: "sf-session-open", "aria-current": s.id === current ? "true" : undefined, "aria-describedby": `${id}-keys`, onClick: () => onOpen(s.id), onContextMenu: (e) => openMenu(e, s), onKeyDown: (e) => onRowKey(e, s), "data-index": index, children: [_jsxs("span", { className: "sf-session-title", children: [s.pinned && (_jsxs("span", { className: "sf-session-pin", title: "Pinned", children: [_jsx(ChatIcon, { name: "pin" }), _jsx("span", { className: "sf-a2-visually-hidden", children: "Pinned: " })] })), s.title] }), _jsx("span", { className: "sf-session-meta", children: meta })] }), (a.rename || a.pin || a.remove) && (_jsx(ItemControls, { label: `${s.title} controls`, controls: [
211
+ ...standardControls(s.title, { edit: a.rename }),
212
+ ...(a.pin ? [{ id: "pin", label: s.pinned ? `Unpin ${s.title}` : `Pin ${s.title}`, icon: _jsx(ChatIcon, { name: "pin" }), onSelect: a.pin, pressed: s.pinned }] : []),
213
+ ...standardControls(s.title, { remove: a.remove }),
214
+ ] }))] }, key));
215
+ };
216
+ return (_jsxs("section", { className: "sf-sessions", "aria-label": props.label ?? "Conversations", children: [_jsxs("div", { className: "sf-sessions-bar", children: [_jsxs("label", { className: "sf-sessions-search", children: [_jsx(ChatIcon, { name: "search" }), _jsx("span", { className: "sf-a2-visually-hidden", children: "Search conversations" }), _jsx("input", { className: "sf-input", type: "search", placeholder: "Search conversations", value: state.search ?? "", onChange: (e) => set({ search: e.target.value }) })] }), onNew && (_jsxs("button", { type: "button", className: "sf-button", onClick: onNew, children: [_jsx(ChatIcon, { name: "plus" }), " New"] }))] }), _jsxs("div", { className: "sf-sessions-controls", children: [_jsx(MenuButton, { label: `Filter${filterCount ? `: ${filterCount} on` : ""}`, text: filterCount ? `Filter (${filterCount})` : "Filter", children: () => (_jsxs(_Fragment, { children: [_jsx(MenuGroup, { label: "Show", children: _jsx(MenuItem, { role: "checkbox", checked: !!state.pinned, onSelect: () => set({ pinned: !state.pinned }), children: "Pinned only" }) }), _jsx(MenuGroup, { label: "When", children: SINCE.map((w) => (_jsx(MenuItem, { role: "radio", checked: state.since === w.id, onSelect: () => set({ since: state.since === w.id ? undefined : w.id }), children: w.label }, w.id))) }), facets.agents.length > 1 && (_jsx(MenuGroup, { label: "Agent", children: facets.agents.map((a) => (_jsx(MenuItem, { role: "checkbox", checked: !!state.agents?.includes(a), onSelect: () => set({ agents: toggleIn(state.agents, a) }), children: agentName?.(a) ?? a }, a))) })), facets.sources.length > 0 && (_jsx(MenuGroup, { label: "Data source", children: facets.sources.map((a) => (_jsx(MenuItem, { role: "checkbox", checked: !!state.sources?.includes(a), onSelect: () => set({ sources: toggleIn(state.sources, a) }), children: a }, a))) })), facets.tags.length > 0 && (_jsx(MenuGroup, { label: "Tag", children: facets.tags.map((a) => (_jsx(MenuItem, { role: "checkbox", checked: !!state.tags?.includes(a), onSelect: () => set({ tags: toggleIn(state.tags, a) }), children: a }, a))) })), filterCount > 0 && (_jsx("button", { type: "button", className: "sf-chat-menu-more", onClick: () => set({ agents: undefined, sources: undefined, tags: undefined, pinned: undefined, since: undefined }), children: "Clear filters" }))] })) }), _jsx(MenuButton, { label: `Sort: ${SORTS.find((s) => s.id === (state.sort ?? "updated")).label}`, text: `Sort: ${SORTS.find((s) => s.id === (state.sort ?? "updated")).label}`, children: () => (_jsxs(_Fragment, { children: [_jsx(MenuGroup, { label: "Sort by", children: SORTS.map((s) => (_jsx(MenuItem, { role: "radio", checked: (state.sort ?? "updated") === s.id, onSelect: () => set({ sort: s.id === "updated" ? undefined : s.id, direction: undefined }), children: s.label }, s.id))) }), _jsx(MenuGroup, { label: "Order", children: ["asc", "desc"].map((d) => {
217
+ const now = state.direction ?? ((state.sort ?? "updated") === "title" ? "asc" : "desc");
218
+ const words = (state.sort ?? "updated") === "title" ? { asc: "A to Z", desc: "Z to A" } : { asc: "Oldest first", desc: "Newest first" };
219
+ return (_jsx(MenuItem, { role: "radio", checked: now === d, onSelect: () => set({ direction: d }), children: words[d] }, d));
220
+ }) })] })) }), _jsx(MenuButton, { label: `Group: ${GROUPS.find((g) => g.id === (state.groupBy ?? "none")).label}`, text: `Group: ${GROUPS.find((g) => g.id === (state.groupBy ?? "none")).label}`, children: (close) => (_jsx(MenuGroup, { label: "Group by", children: GROUPS.map((g) => (_jsx(MenuItem, { role: "radio", checked: (state.groupBy ?? "none") === g.id, onSelect: () => {
221
+ set({ groupBy: g.id === "none" ? undefined : g.id });
222
+ close();
223
+ }, children: g.label }, g.id))) })) })] }), _jsxs("p", { className: "sf-sessions-status", role: "status", children: [sessions.length === 0 ? "" : shown === sessions.length || state.groupBy === "source" || state.groupBy === "tag" ? `${sessions.length} conversation${sessions.length === 1 ? "" : "s"}` : `${shown} of ${sessions.length} conversations`, said ? ` · ${said}` : ""] }), _jsxs("p", { id: `${id}-keys`, className: "sf-a2-visually-hidden", children: ["Enter opens. ", onRename ? "F2 renames. " : "", onPin ? "P pins. " : "", onRemove ? "Delete deletes, after asking. " : "", "Up and down arrows move between conversations."] }), sessions.length === 0 ? (_jsx("div", { className: "sf-sessions-empty", children: props.empty ?? "No conversations yet." })) : rows.length === 0 ? (_jsxs("div", { className: "sf-sessions-empty", children: ["No conversations match.", " ", _jsx("button", { type: "button", className: "sf-button", onClick: () => set({ search: undefined, agents: undefined, sources: undefined, tags: undefined, pinned: undefined, since: undefined }), children: "Clear search and filters" })] })) : (_jsx("div", { ref: scroller, className: "sf-session-scroll", style: height ? { height, overflowY: "auto" } : undefined, onScroll: (e) => setTop(e.currentTarget.scrollTop), children: _jsxs("ul", { className: "sf-session-rows", style: height ? { position: "relative", height: rows.length * rowHeight } : undefined, children: [height && first > 0 && _jsx("li", { "aria-hidden": "true", style: { height: first * rowHeight }, className: "sf-session-spacer" }), rows.slice(first, last).map((row, i) => drawRow(row, first + i))] }) })), menu.element] }));
224
+ }
225
+ //# sourceMappingURL=SessionList.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionList.js","sourceRoot":"","sources":["../src/SessionList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzF,OAAO,EAAuD,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACzH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAqBtC,MAAM,GAAG,GAAG,UAAU,CAAC;AACvB,MAAM,UAAU,GAAG,CAAC,GAAS,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,cAAc,EAAE,EAAE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G,CAAC,CAAC,CAAC,IAC9D,GACD,CACP,EACA,IAAI,CAAC,OAAO,IACL,CACX,CAAC;AACJ,CAAC","sourcesContent":["import { ItemControls, standardControls, useContextMenu } from \"@surfaces-ui/components\";\nimport { type KeyboardEvent, type MouseEvent, type ReactNode, useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport { MenuButton, MenuGroup, MenuItem } from \"./Menu.js\";\nimport { ChatIcon } from \"./icons.js\";\nimport type { ChatSessionSummary } from \"./sessions.js\";\n\nexport type SessionSort = \"updated\" | \"created\" | \"title\";\nexport type SessionGroup = \"none\" | \"day\" | \"agent\" | \"source\" | \"tag\";\n/** How recent, relative to today, so a saved list never goes stale. */\nexport type SessionSince = \"today\" | \"7d\" | \"30d\" | \"older\";\n\n/** Everything a person sets on the list. Plain JSON, so a host can keep it. */\nexport interface SessionListState {\n search?: string;\n sort?: SessionSort;\n direction?: \"asc\" | \"desc\";\n groupBy?: SessionGroup;\n agents?: string[];\n sources?: string[];\n tags?: string[];\n pinned?: boolean;\n since?: SessionSince;\n}\n\nconst DAY = 86_400_000;\nconst startOfDay = (now: Date) => Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());\n\n/** Whether one session matches the filters and the search. */\nexport function sessionMatches(session: ChatSessionSummary, state: SessionListState, now = new Date()): boolean {\n const words = (state.search ?? \"\").toLowerCase().split(/\\s+/).filter(Boolean);\n const text = `${session.title} ${session.lastMessage} ${session.tags.join(\" \")}`.toLowerCase();\n if (!words.every((w) => text.includes(w))) return false;\n if (state.pinned && !session.pinned) return false;\n if (state.agents?.length && !state.agents.includes(session.agentId ?? \"\")) return false;\n if (state.sources?.length && !session.sources.some((s) => state.sources!.includes(s))) return false;\n if (state.tags?.length && !session.tags.some((t) => state.tags!.includes(t))) return false;\n if (state.since) {\n const at = Date.parse(session.updatedAt);\n const today = startOfDay(now);\n if (state.since === \"today\" && at < today) return false;\n if (state.since === \"7d\" && at < today - 6 * DAY) return false;\n if (state.since === \"30d\" && at < today - 29 * DAY) return false;\n if (state.since === \"older\" && at >= today - 29 * DAY) return false;\n }\n return true;\n}\n\n/** Sorted as the state says; pinned sessions come first. */\nexport function sortSessions(sessions: ChatSessionSummary[], state: SessionListState): ChatSessionSummary[] {\n const sort = state.sort ?? \"updated\";\n const flip = (state.direction ?? (sort === \"title\" ? \"asc\" : \"desc\")) === \"desc\" ? -1 : 1;\n const key = (s: ChatSessionSummary) => (sort === \"title\" ? s.title.toLowerCase() : sort === \"created\" ? s.createdAt : s.updatedAt);\n return [...sessions].sort((a, b) => Number(b.pinned) - Number(a.pinned) || flip * key(a).localeCompare(key(b)) || a.id.localeCompare(b.id));\n}\n\n/** The day a session falls in, in words. */\nexport function dayBucket(iso: string, now = new Date()): string {\n const at = Date.parse(iso);\n const today = startOfDay(now);\n if (at >= today) return \"Today\";\n if (at >= today - DAY) return \"Yesterday\";\n if (at >= today - 6 * DAY) return \"Previous 7 days\";\n if (at >= today - 29 * DAY) return \"Previous 30 days\";\n return \"Older\";\n}\n\nexport interface SessionGroupOf {\n label: string;\n sessions: ChatSessionSummary[];\n}\n\n/** Filtered, sorted and grouped, as the list draws it. A session with several sources or tags is listed under each. */\nexport function arrangeSessions(sessions: ChatSessionSummary[], state: SessionListState, options: { now?: Date; agentName?(id: string): string } = {}): SessionGroupOf[] {\n const now = options.now ?? new Date();\n const sorted = sortSessions(\n sessions.filter((s) => sessionMatches(s, state, now)),\n state,\n );\n const by = state.groupBy ?? \"none\";\n if (by === \"none\") return sorted.length ? [{ label: \"\", sessions: sorted }] : [];\n const groups = new Map<string, ChatSessionSummary[]>();\n const put = (label: string, s: ChatSessionSummary) => groups.set(label, [...(groups.get(label) ?? []), s]);\n for (const s of sorted) {\n if (by === \"day\") put(s.pinned ? \"Pinned\" : dayBucket(state.sort === \"created\" ? s.createdAt : s.updatedAt, now), s);\n else if (by === \"agent\") put(s.agentId ? (options.agentName?.(s.agentId) ?? s.agentId) : \"No agent named\", s);\n else {\n const keys = by === \"source\" ? s.sources : s.tags;\n if (keys.length === 0) put(by === \"source\" ? \"No data attached\" : \"No tags\", s);\n for (const k of keys) put(k, s);\n }\n }\n const order = [\"Pinned\", \"Today\", \"Yesterday\", \"Previous 7 days\", \"Previous 30 days\", \"Older\"];\n return [...groups.entries()]\n .map(([label, list]) => ({ label, sessions: list }))\n .sort((a, b) => (by === \"day\" ? order.indexOf(a.label) - order.indexOf(b.label) : a.label.startsWith(\"No \") ? 1 : b.label.startsWith(\"No \") ? -1 : a.label.localeCompare(b.label)));\n}\n\nexport interface SessionListProps {\n sessions: ChatSessionSummary[];\n /** The conversation open now. */\n current?: string;\n value?: SessionListState;\n defaultValue?: SessionListState;\n onChange?(state: SessionListState): void;\n onOpen(id: string): void;\n onNew?(): void;\n onRename?(id: string, title: string): void;\n onPin?(id: string, pinned: boolean): void;\n onRemove?(id: string): void;\n /** An agent's name for its id. */\n agentName?(id: string): string;\n /** With a height the rows scroll inside and only those in view are drawn. */\n height?: number;\n /** Row height for windowing, in px. Default 56. */\n rowHeight?: number;\n /** Set \"now\" for tests. */\n now?: Date;\n /** Shown when there are none at all. */\n empty?: ReactNode;\n /** Names the list for assistive technology. Default \"Conversations\". */\n label?: string;\n}\n\ntype Row = { type: \"group\"; label: string; count: number } | { type: \"session\"; session: ChatSessionSummary; group: string };\n\nconst SORTS: { id: SessionSort; label: string }[] = [\n { id: \"updated\", label: \"Last activity\" },\n { id: \"created\", label: \"Started\" },\n { id: \"title\", label: \"Title\" },\n];\nconst GROUPS: { id: SessionGroup; label: string }[] = [\n { id: \"none\", label: \"No grouping\" },\n { id: \"day\", label: \"Day\" },\n { id: \"agent\", label: \"Agent\" },\n { id: \"source\", label: \"Data source\" },\n { id: \"tag\", label: \"Tag\" },\n];\nconst SINCE: { id: SessionSince; label: string }[] = [\n { id: \"today\", label: \"Today\" },\n { id: \"7d\", label: \"Last 7 days\" },\n { id: \"30d\", label: \"Last 30 days\" },\n { id: \"older\", label: \"Older than 30 days\" },\n];\nconst time = new Intl.DateTimeFormat(\"en\", { dateStyle: \"medium\", timeStyle: \"short\", timeZone: \"UTC\" });\n\n/**\n * Saved conversations a person can search, filter, sort and group. Each row\n * opens its conversation; rename, pin and delete are on its controls and on\n * its right-click menu, and delete asks first.\n */\nexport function SessionList(props: SessionListProps) {\n const { sessions, current, onOpen, onNew, onRename, onPin, onRemove, agentName, height, rowHeight = 56, now } = props;\n const [kept, setKept] = useState<SessionListState>(props.defaultValue ?? {});\n const state = props.value ?? kept;\n const set = (patch: Partial<SessionListState>) => {\n const next = { ...state, ...patch };\n for (const k of Object.keys(next) as (keyof SessionListState)[]) {\n const v = next[k];\n if (v === undefined || v === \"\" || v === false || (Array.isArray(v) && v.length === 0)) delete next[k];\n }\n setKept(next);\n props.onChange?.(next);\n };\n const [renaming, setRenaming] = useState<{ id: string; title: string } | undefined>();\n const [confirming, setConfirming] = useState<string | undefined>();\n const [said, setSaid] = useState(\"\");\n const menu = useContextMenu();\n const id = useId();\n\n const groups = useMemo(() => arrangeSessions(sessions, state, { now, agentName }), [sessions, state, now, agentName]);\n const rows: Row[] = useMemo(() => groups.flatMap((g) => [...(g.label ? [{ type: \"group\" as const, label: g.label, count: g.sessions.length }] : []), ...g.sessions.map((session) => ({ type: \"session\" as const, session, group: g.label }))]), [groups]);\n const shown = rows.filter((r) => r.type === \"session\").length;\n\n // Windowing: only rows in view are drawn when the list scrolls inside.\n const scroller = useRef<HTMLDivElement>(null);\n const [top, setTop] = useState(0);\n const first = height ? Math.max(0, Math.floor(top / rowHeight) - 4) : 0;\n const last = height ? Math.min(rows.length, Math.ceil((top + height) / rowHeight) + 4) : rows.length;\n useEffect(() => {\n if (scroller.current && top > rows.length * rowHeight) scroller.current.scrollTop = 0;\n }, [rows.length, rowHeight, top]);\n\n const facets = useMemo(() => {\n const agents = [...new Set(sessions.flatMap((s) => (s.agentId ? [s.agentId] : [])))].sort();\n const sources = [...new Set(sessions.flatMap((s) => s.sources))].sort();\n const tags = [...new Set(sessions.flatMap((s) => s.tags))].sort();\n return { agents, sources, tags };\n }, [sessions]);\n const toggleIn = (list: string[] | undefined, value: string) => (list?.includes(value) ? list.filter((x) => x !== value) : [...(list ?? []), value]);\n const filterCount = (state.agents?.length ?? 0) + (state.sources?.length ?? 0) + (state.tags?.length ?? 0) + (state.pinned ? 1 : 0) + (state.since ? 1 : 0);\n\n const actions = (s: ChatSessionSummary) => ({\n rename: onRename ? () => setRenaming({ id: s.id, title: s.title }) : undefined,\n pin: onPin ? () => {\n onPin(s.id, !s.pinned);\n setSaid(s.pinned ? `Unpinned ${s.title}.` : `Pinned ${s.title}.`);\n } : undefined,\n remove: onRemove ? () => setConfirming(s.id) : undefined,\n });\n const openMenu = (event: MouseEvent<HTMLElement>, s: ChatSessionSummary) => {\n const a = actions(s);\n menu.open(event, s.title, [\n { label: \"Open\", onSelect: () => onOpen(s.id) },\n ...(a.rename ? [{ label: \"Rename\", onSelect: a.rename, hint: \"F2\" }] : []),\n ...(a.pin ? [{ label: s.pinned ? \"Unpin\" : \"Pin\", onSelect: a.pin, hint: \"P\" }] : []),\n ...(a.remove ? [{ separator: true }, { label: \"Delete…\", onSelect: a.remove, hint: \"Delete\" }] : []),\n ]);\n };\n const onRowKey = (event: KeyboardEvent<HTMLElement>, s: ChatSessionSummary) => {\n if (event.target !== event.currentTarget) return;\n const a = actions(s);\n if (event.key === \"F2\" && a.rename) a.rename();\n else if ((event.key === \"p\" || event.key === \"P\") && a.pin) a.pin();\n else if ((event.key === \"Delete\" || event.key === \"Backspace\") && a.remove) a.remove();\n else if (event.key === \"ArrowDown\" || event.key === \"ArrowUp\") {\n const all = Array.from(event.currentTarget.closest(\".sf-session-rows\")?.querySelectorAll<HTMLElement>(\".sf-session-open\") ?? []);\n const at = all.indexOf(event.currentTarget as HTMLElement);\n all[at + (event.key === \"ArrowDown\" ? 1 : -1)]?.focus();\n } else return;\n event.preventDefault();\n };\n\n const drawRow = (row: Row, index: number) => {\n if (row.type === \"group\")\n return (\n <li key={`g-${row.label}`} className=\"sf-session-group\" style={height ? { height: rowHeight } : undefined} role=\"presentation\">\n <span>{row.label}</span> <span className=\"sf-session-count\">{row.count}</span>\n </li>\n );\n const s = row.session;\n const key = `${row.group}/${s.id}`;\n if (renaming?.id === s.id)\n return (\n <li key={key} className=\"sf-session\" style={height ? { height: rowHeight } : undefined}>\n <form\n className=\"sf-session-rename\"\n onSubmit={(e) => {\n e.preventDefault();\n const title = renaming.title.trim();\n if (title && title !== s.title) {\n onRename?.(s.id, title);\n setSaid(`Renamed to ${title}.`);\n }\n setRenaming(undefined);\n }}\n >\n <input\n className=\"sf-input\"\n aria-label={`New title for ${s.title}`}\n value={renaming.title}\n // biome-ignore lint/a11y/noAutofocus: the person asked to rename this row\n autoFocus\n onChange={(e) => setRenaming({ id: s.id, title: e.target.value })}\n onKeyDown={(e) => e.key === \"Escape\" && setRenaming(undefined)}\n />\n <button type=\"submit\" className=\"sf-button\" data-variant=\"primary\">\n Rename\n </button>\n <button type=\"button\" className=\"sf-button\" onClick={() => setRenaming(undefined)}>\n Cancel\n </button>\n </form>\n </li>\n );\n if (confirming === s.id)\n return (\n <li key={key} className=\"sf-session\" data-confirm style={height ? { height: rowHeight } : undefined} role=\"alert\">\n <span className=\"sf-session-confirm-text\">Delete “{s.title}”? It cannot be brought back.</span>\n <button\n type=\"button\"\n className=\"sf-button\"\n data-variant=\"danger\"\n // biome-ignore lint/a11y/noAutofocus: focus moves to the question the person just raised\n autoFocus\n onClick={() => {\n onRemove?.(s.id);\n setConfirming(undefined);\n setSaid(`Deleted ${s.title}.`);\n }}\n >\n Delete\n </button>\n <button type=\"button\" className=\"sf-button\" onClick={() => setConfirming(undefined)}>\n Keep\n </button>\n </li>\n );\n const a = actions(s);\n const meta = [s.agentId ? (agentName?.(s.agentId) ?? s.agentId) : \"\", s.sources.join(\", \"), time.format(new Date(state.sort === \"created\" ? s.createdAt : s.updatedAt))].filter(Boolean).join(\" · \");\n return (\n <li key={key} className=\"sf-session sf-controls-host\" data-controls=\"corner\" data-current={s.id === current || undefined} style={height ? { height: rowHeight } : undefined}>\n <button type=\"button\" className=\"sf-session-open\" aria-current={s.id === current ? \"true\" : undefined} aria-describedby={`${id}-keys`} onClick={() => onOpen(s.id)} onContextMenu={(e) => openMenu(e, s)} onKeyDown={(e) => onRowKey(e, s)} data-index={index}>\n <span className=\"sf-session-title\">\n {s.pinned && (\n <span className=\"sf-session-pin\" title=\"Pinned\">\n <ChatIcon name=\"pin\" />\n <span className=\"sf-a2-visually-hidden\">Pinned: </span>\n </span>\n )}\n {s.title}\n </span>\n <span className=\"sf-session-meta\">{meta}</span>\n </button>\n {(a.rename || a.pin || a.remove) && (\n <ItemControls\n label={`${s.title} controls`}\n controls={[\n ...standardControls(s.title, { edit: a.rename }),\n ...(a.pin ? [{ id: \"pin\", label: s.pinned ? `Unpin ${s.title}` : `Pin ${s.title}`, icon: <ChatIcon name=\"pin\" />, onSelect: a.pin, pressed: s.pinned }] : []),\n ...standardControls(s.title, { remove: a.remove }),\n ]}\n />\n )}\n </li>\n );\n };\n\n return (\n <section className=\"sf-sessions\" aria-label={props.label ?? \"Conversations\"}>\n <div className=\"sf-sessions-bar\">\n <label className=\"sf-sessions-search\">\n <ChatIcon name=\"search\" />\n <span className=\"sf-a2-visually-hidden\">Search conversations</span>\n <input className=\"sf-input\" type=\"search\" placeholder=\"Search conversations\" value={state.search ?? \"\"} onChange={(e) => set({ search: e.target.value })} />\n </label>\n {onNew && (\n <button type=\"button\" className=\"sf-button\" onClick={onNew}>\n <ChatIcon name=\"plus\" /> New\n </button>\n )}\n </div>\n <div className=\"sf-sessions-controls\">\n <MenuButton label={`Filter${filterCount ? `: ${filterCount} on` : \"\"}`} text={filterCount ? `Filter (${filterCount})` : \"Filter\"}>\n {() => (\n <>\n <MenuGroup label=\"Show\">\n <MenuItem role=\"checkbox\" checked={!!state.pinned} onSelect={() => set({ pinned: !state.pinned })}>\n Pinned only\n </MenuItem>\n </MenuGroup>\n <MenuGroup label=\"When\">\n {SINCE.map((w) => (\n <MenuItem key={w.id} role=\"radio\" checked={state.since === w.id} onSelect={() => set({ since: state.since === w.id ? undefined : w.id })}>\n {w.label}\n </MenuItem>\n ))}\n </MenuGroup>\n {facets.agents.length > 1 && (\n <MenuGroup label=\"Agent\">\n {facets.agents.map((a) => (\n <MenuItem key={a} role=\"checkbox\" checked={!!state.agents?.includes(a)} onSelect={() => set({ agents: toggleIn(state.agents, a) })}>\n {agentName?.(a) ?? a}\n </MenuItem>\n ))}\n </MenuGroup>\n )}\n {facets.sources.length > 0 && (\n <MenuGroup label=\"Data source\">\n {facets.sources.map((a) => (\n <MenuItem key={a} role=\"checkbox\" checked={!!state.sources?.includes(a)} onSelect={() => set({ sources: toggleIn(state.sources, a) })}>\n {a}\n </MenuItem>\n ))}\n </MenuGroup>\n )}\n {facets.tags.length > 0 && (\n <MenuGroup label=\"Tag\">\n {facets.tags.map((a) => (\n <MenuItem key={a} role=\"checkbox\" checked={!!state.tags?.includes(a)} onSelect={() => set({ tags: toggleIn(state.tags, a) })}>\n {a}\n </MenuItem>\n ))}\n </MenuGroup>\n )}\n {filterCount > 0 && (\n <button type=\"button\" className=\"sf-chat-menu-more\" onClick={() => set({ agents: undefined, sources: undefined, tags: undefined, pinned: undefined, since: undefined })}>\n Clear filters\n </button>\n )}\n </>\n )}\n </MenuButton>\n <MenuButton label={`Sort: ${SORTS.find((s) => s.id === (state.sort ?? \"updated\"))!.label}`} text={`Sort: ${SORTS.find((s) => s.id === (state.sort ?? \"updated\"))!.label}`}>\n {() => (\n <>\n <MenuGroup label=\"Sort by\">\n {SORTS.map((s) => (\n <MenuItem key={s.id} role=\"radio\" checked={(state.sort ?? \"updated\") === s.id} onSelect={() => set({ sort: s.id === \"updated\" ? undefined : s.id, direction: undefined })}>\n {s.label}\n </MenuItem>\n ))}\n </MenuGroup>\n <MenuGroup label=\"Order\">\n {([\"asc\", \"desc\"] as const).map((d) => {\n const now = state.direction ?? ((state.sort ?? \"updated\") === \"title\" ? \"asc\" : \"desc\");\n const words = (state.sort ?? \"updated\") === \"title\" ? { asc: \"A to Z\", desc: \"Z to A\" } : { asc: \"Oldest first\", desc: \"Newest first\" };\n return (\n <MenuItem key={d} role=\"radio\" checked={now === d} onSelect={() => set({ direction: d })}>\n {words[d]}\n </MenuItem>\n );\n })}\n </MenuGroup>\n </>\n )}\n </MenuButton>\n <MenuButton label={`Group: ${GROUPS.find((g) => g.id === (state.groupBy ?? \"none\"))!.label}`} text={`Group: ${GROUPS.find((g) => g.id === (state.groupBy ?? \"none\"))!.label}`}>\n {(close) => (\n <MenuGroup label=\"Group by\">\n {GROUPS.map((g) => (\n <MenuItem\n key={g.id}\n role=\"radio\"\n checked={(state.groupBy ?? \"none\") === g.id}\n onSelect={() => {\n set({ groupBy: g.id === \"none\" ? undefined : g.id });\n close();\n }}\n >\n {g.label}\n </MenuItem>\n ))}\n </MenuGroup>\n )}\n </MenuButton>\n </div>\n <p className=\"sf-sessions-status\" role=\"status\">\n {sessions.length === 0 ? \"\" : shown === sessions.length || state.groupBy === \"source\" || state.groupBy === \"tag\" ? `${sessions.length} conversation${sessions.length === 1 ? \"\" : \"s\"}` : `${shown} of ${sessions.length} conversations`}\n {said ? ` · ${said}` : \"\"}\n </p>\n <p id={`${id}-keys`} className=\"sf-a2-visually-hidden\">\n Enter opens. {onRename ? \"F2 renames. \" : \"\"}\n {onPin ? \"P pins. \" : \"\"}\n {onRemove ? \"Delete deletes, after asking. \" : \"\"}Up and down arrows move between conversations.\n </p>\n {sessions.length === 0 ? (\n <div className=\"sf-sessions-empty\">{props.empty ?? \"No conversations yet.\"}</div>\n ) : rows.length === 0 ? (\n <div className=\"sf-sessions-empty\">\n No conversations match.{\" \"}\n <button type=\"button\" className=\"sf-button\" onClick={() => set({ search: undefined, agents: undefined, sources: undefined, tags: undefined, pinned: undefined, since: undefined })}>\n Clear search and filters\n </button>\n </div>\n ) : (\n <div ref={scroller} className=\"sf-session-scroll\" style={height ? { height, overflowY: \"auto\" } : undefined} onScroll={(e) => setTop(e.currentTarget.scrollTop)}>\n <ul className=\"sf-session-rows\" style={height ? { position: \"relative\", height: rows.length * rowHeight } : undefined}>\n {height && first > 0 && <li aria-hidden=\"true\" style={{ height: first * rowHeight }} className=\"sf-session-spacer\" />}\n {rows.slice(first, last).map((row, i) => drawRow(row, first + i))}\n </ul>\n </div>\n )}\n {menu.element}\n </section>\n );\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import { type AppComponentDoc } from "@surfaces-ui/components/app-components";
2
+ export declare const analyticsChatDoc: AppComponentDoc;
3
+ export declare const chatDoc: AppComponentDoc;
4
+ export declare const pageStudioDoc: AppComponentDoc;
5
+ /** Every app component of `@surfaces-ui/chat`. */
6
+ export declare const chatAppComponents: AppComponentDoc[];
@@ -0,0 +1,100 @@
1
+ import { describeAppComponent } from "@surfaces-ui/components/app-components";
2
+ /*
3
+ * The chat package's app components, described once as data (see
4
+ * `describeAppComponent` in @surfaces-ui/components): the playground draws a
5
+ * page for each, and `pnpm docs:gen` writes docs/components.
6
+ */
7
+ const CHAT = "@surfaces-ui/chat";
8
+ const words = {
9
+ starters: { type: "array", items: { type: "string" }, description: "Offered as one-press examples before anything is said." },
10
+ placeholder: { type: "string", description: "The message box's placeholder." },
11
+ empty: { type: "string", description: "Shown before anything is said." },
12
+ height: { type: "integer", minimum: 240, description: "Height of the whole chat in px. Default 640." },
13
+ };
14
+ const settings = {
15
+ type: "object",
16
+ description: "What the person chose: agent, model, provider, skills, connectors and source. Sent with each turn; the backend refuses what it did not offer.",
17
+ properties: {
18
+ agentId: { type: "string" },
19
+ model: { type: "string" },
20
+ provider: { type: "string" },
21
+ skillIds: { type: "array", items: { type: "string" } },
22
+ connectorIds: { type: "array", items: { type: "string" } },
23
+ sourceId: { type: "string" },
24
+ },
25
+ };
26
+ const user = {
27
+ type: "object",
28
+ description: "Who is using it, from the host's sign-in: recorded on approvals, events and arrangements.",
29
+ properties: { id: { type: "string" }, name: { type: "string" } },
30
+ };
31
+ export const analyticsChatDoc = describeAppComponent()({
32
+ name: "AnalyticsChat",
33
+ from: CHAT,
34
+ description: "The chat for data people: the conversation always shown, with a rail of panels beside it for only what the host gives: saved conversations (`sessions`), tables and files to attach (`browse`), and the agent's setup (`agents` or `providers`). Its composer attaches files, switches the model, sets up the agent's skills and connectors, and takes voice behind consent. Every component the agent draws appears in the thread, live.",
35
+ props: {
36
+ type: "object",
37
+ properties: { ...words, menuLimit: { type: "integer", minimum: 1, maximum: 20, description: 'Items a composer menu shows before "View all…". Default 5.' }, user, settings },
38
+ required: [],
39
+ },
40
+ parts: [
41
+ { prop: "agent", label: "Agent", description: "Any `AgentBackend`. On the page, the scripted demo agent answering from a written conversation.", required: true },
42
+ { prop: "sessions", label: "Saved conversations", description: "A Conversations panel to search, filter, sort and group them; every conversation is saved as it goes. `librarySessions(library)` or `memorySessions()`.", on: true },
43
+ { prop: "browse", label: "Data panel", description: "Tables and files to attach to a message, over the source in `settings`.", on: true },
44
+ { prop: "agents", label: "Agent setup", description: "What the backend offers (`DescribeAgents`): agents with their models, skills and connectors, in the Setup menu and panel." },
45
+ { prop: "providers", label: "Model providers", description: "Where models run, each with its models: the Model menu groups them and a pick sets `provider` and `model`. A model's `level` ({ value, of, label }) is drawn as rising bars beside its word." },
46
+ { prop: "attachFiles", label: "Attach files", description: "The + menu, drop and paste. The host decides what a file becomes; the agent is told a table or a file by name, never its contents." },
47
+ { prop: "speech", label: "Voice", description: "Dictation and a spoken conversation, asked for once with `speechConsent` (Chrome sends audio to Google)." },
48
+ ],
49
+ callbacks: [
50
+ { prop: "onSettingsChange", description: "A person changed the agent, model, skills or connectors." },
51
+ { prop: "onContext", description: "What a person does in a drawn component, as it happens; it also goes with the next turn." },
52
+ { prop: "onLayoutChange", description: "Where the panels are, as plain JSON to keep." },
53
+ { prop: "onConnect", description: "A connector's sign-in link, for the host to open." },
54
+ ],
55
+ example: { starters: ["Show the data model", "Browse the data"], menuLimit: 5, height: 640 },
56
+ });
57
+ export const chatDoc = describeAppComponent()({
58
+ name: "Chat",
59
+ from: CHAT,
60
+ description: "A conversation with any agent, on its own: replies hold Markdown, tool steps, approvals and any catalog component drawn inline. Use it inside your own layout; use `AnalyticsChat` for the whole workspace. A thread is a document: open on one with `initialThread` and save every change from `onThreadChange`.",
61
+ props: {
62
+ type: "object",
63
+ properties: { ...words, agentId: { type: "string", description: "The agent to talk to when the backend has several." }, contextPackId: { type: "string", description: "Limit the agent to the data in this saved context pack." }, storageKey: { type: "string" }, user, settings },
64
+ },
65
+ parts: [
66
+ { prop: "agent", label: "Agent", description: "Any `AgentBackend`. On the page, the scripted demo agent.", required: true },
67
+ { prop: "storage", label: "Keep across reloads", description: "Where to keep the thread (`browserStorage()` from `@surfaces-ui/state`, or your own); checked when it loads." },
68
+ { prop: "agents", label: "Agent menus", description: "What the backend offers, for the composer's Setup menu. Needs `onSettingsChange`." },
69
+ { prop: "providers", label: "Model providers", description: "Where models run: the Model menu groups them by provider." },
70
+ ],
71
+ callbacks: [
72
+ { prop: "onThreadChange", description: "The thread after every change, to save it or build from what was drawn." },
73
+ { prop: "onSettingsChange", description: "A person changed the agent, model, skills or connectors." },
74
+ { prop: "onContext", description: "What a person does in a drawn component." },
75
+ { prop: "onReferencesChange", description: "Tables and columns attached to the message being written, when the host holds them." },
76
+ ],
77
+ example: { starters: ["Show the data model"], height: 560 },
78
+ });
79
+ export const pageStudioDoc = describeAppComponent()({
80
+ name: "PageStudio",
81
+ from: CHAT,
82
+ description: "A page beside an instruction box: a person says what to change, an agent answers with A2UI, and its reply becomes page edits checked against the catalog. Each instruction is one undo step and the log says who made each change. With `arrange`, a person can also lay the page out by hand (drag, side by side, heights and widths, all by keyboard too): each arrangement is one undo step, logged by them, and told to the agent with the next instruction.",
83
+ props: {
84
+ type: "object",
85
+ properties: { starters: words.starters, arrange: { type: "boolean", description: "Offer Arrange beside Undo and Redo." }, user, settings },
86
+ },
87
+ parts: [
88
+ { prop: "agent", label: "Agent", description: "Any `AgentBackend`. On the page, the scripted demo agent that edits dashboards.", required: true },
89
+ { prop: "page", label: "Page", description: "The `PageDocument` to start from: a dashboard from the gallery.", required: true },
90
+ { prop: "providers", label: "Model providers", description: "Where models run: the Model menu groups them by provider." },
91
+ ],
92
+ callbacks: [
93
+ { prop: "onChange", description: "The page after each change, to save it." },
94
+ { prop: "onSettingsChange", description: "A person changed the model." },
95
+ ],
96
+ example: { arrange: true, user: { id: "you", name: "you" } },
97
+ });
98
+ /** Every app component of `@surfaces-ui/chat`. */
99
+ export const chatAppComponents = [analyticsChatDoc, chatDoc, pageStudioDoc];
100
+ //# sourceMappingURL=appComponents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appComponents.js","sourceRoot":"","sources":["../src/appComponents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyC,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAKrH;;;;GAIG;AAEH,MAAM,IAAI,GAAG,mBAAmB,CAAC;AACjC,MAAM,KAAK,GAA+B;IACxC,QAAQ,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,WAAW,EAAE,wDAAwD,EAAE;IAC7H,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,gCAAgC,EAAE;IAC9E,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,gCAAgC,EAAE;IACxE,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,8CAA8C,EAAE;CACvG,CAAC;AACF,MAAM,QAAQ,GAAe;IAC3B,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,+IAA+I;IAC5J,UAAU,EAAE;QACV,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC3B,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACzB,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC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AI,EAAE;QACjJ,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,iEAAiE,EAAE,QAAQ,EAAE,IAAI,EAAE;QAC/H,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,2DAA2D,EAAE;KAC1H;IACD,SAAS,EAAE;QACT,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,yCAAyC,EAAE;QAC5E,EAAE,IAAI,EAAE,kBAAkB,EAAE,WAAW,EAAE,6BAA6B,EAAE;KACzE;IACD,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;CAC7D,CAAC,CAAC;AAEH,kDAAkD;AAClD,MAAM,CAAC,MAAM,iBAAiB,GAAsB,CAAC,gBAAgB,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC","sourcesContent":["import { type AppComponentDoc, type PropSchema, describeAppComponent } from \"@surfaces-ui/components/app-components\";\nimport type { AnalyticsChatProps } from \"./AnalyticsChat.js\";\nimport type { ChatProps } from \"./Chat.js\";\nimport type { PageStudioProps } from \"./PageStudio.js\";\n\n/*\n * The chat package's app components, described once as data (see\n * `describeAppComponent` in @surfaces-ui/components): the playground draws a\n * page for each, and `pnpm docs:gen` writes docs/components.\n */\n\nconst CHAT = \"@surfaces-ui/chat\";\nconst words: Record<string, PropSchema> = {\n starters: { type: \"array\", items: { type: \"string\" }, description: \"Offered as one-press examples before anything is said.\" },\n placeholder: { type: \"string\", description: \"The message box's placeholder.\" },\n empty: { type: \"string\", description: \"Shown before anything is said.\" },\n height: { type: \"integer\", minimum: 240, description: \"Height of the whole chat in px. Default 640.\" },\n};\nconst settings: PropSchema = {\n type: \"object\",\n description: \"What the person chose: agent, model, provider, skills, connectors and source. Sent with each turn; the backend refuses what it did not offer.\",\n properties: {\n agentId: { type: \"string\" },\n model: { type: \"string\" },\n provider: { type: \"string\" },\n skillIds: { type: \"array\", items: { type: \"string\" } },\n connectorIds: { type: \"array\", items: { type: \"string\" } },\n sourceId: { type: \"string\" },\n },\n};\nconst user: PropSchema = {\n type: \"object\",\n description: \"Who is using it, from the host's sign-in: recorded on approvals, events and arrangements.\",\n properties: { id: { type: \"string\" }, name: { type: \"string\" } },\n};\n\nexport const analyticsChatDoc = describeAppComponent<AnalyticsChatProps>()({\n name: \"AnalyticsChat\",\n from: CHAT,\n description:\n \"The chat for data people: the conversation always shown, with a rail of panels beside it for only what the host gives: saved conversations (`sessions`), tables and files to attach (`browse`), and the agent's setup (`agents` or `providers`). Its composer attaches files, switches the model, sets up the agent's skills and connectors, and takes voice behind consent. Every component the agent draws appears in the thread, live.\",\n props: {\n type: \"object\",\n properties: { ...words, menuLimit: { type: \"integer\", minimum: 1, maximum: 20, description: 'Items a composer menu shows before \"View all…\". Default 5.' }, user, settings },\n required: [],\n },\n parts: [\n { prop: \"agent\", label: \"Agent\", description: \"Any `AgentBackend`. On the page, the scripted demo agent answering from a written conversation.\", required: true },\n { prop: \"sessions\", label: \"Saved conversations\", description: \"A Conversations panel to search, filter, sort and group them; every conversation is saved as it goes. `librarySessions(library)` or `memorySessions()`.\", on: true },\n { prop: \"browse\", label: \"Data panel\", description: \"Tables and files to attach to a message, over the source in `settings`.\", on: true },\n { prop: \"agents\", label: \"Agent setup\", description: \"What the backend offers (`DescribeAgents`): agents with their models, skills and connectors, in the Setup menu and panel.\" },\n { prop: \"providers\", label: \"Model providers\", description: \"Where models run, each with its models: the Model menu groups them and a pick sets `provider` and `model`. A model's `level` ({ value, of, label }) is drawn as rising bars beside its word.\" },\n { prop: \"attachFiles\", label: \"Attach files\", description: \"The + menu, drop and paste. The host decides what a file becomes; the agent is told a table or a file by name, never its contents.\" },\n { prop: \"speech\", label: \"Voice\", description: \"Dictation and a spoken conversation, asked for once with `speechConsent` (Chrome sends audio to Google).\" },\n ],\n callbacks: [\n { prop: \"onSettingsChange\", description: \"A person changed the agent, model, skills or connectors.\" },\n { prop: \"onContext\", description: \"What a person does in a drawn component, as it happens; it also goes with the next turn.\" },\n { prop: \"onLayoutChange\", description: \"Where the panels are, as plain JSON to keep.\" },\n { prop: \"onConnect\", description: \"A connector's sign-in link, for the host to open.\" },\n ],\n example: { starters: [\"Show the data model\", \"Browse the data\"], menuLimit: 5, height: 640 },\n});\n\nexport const chatDoc = describeAppComponent<ChatProps>()({\n name: \"Chat\",\n from: CHAT,\n description:\n \"A conversation with any agent, on its own: replies hold Markdown, tool steps, approvals and any catalog component drawn inline. Use it inside your own layout; use `AnalyticsChat` for the whole workspace. A thread is a document: open on one with `initialThread` and save every change from `onThreadChange`.\",\n props: {\n type: \"object\",\n properties: { ...words, agentId: { type: \"string\", description: \"The agent to talk to when the backend has several.\" }, contextPackId: { type: \"string\", description: \"Limit the agent to the data in this saved context pack.\" }, storageKey: { type: \"string\" }, user, settings },\n },\n parts: [\n { prop: \"agent\", label: \"Agent\", description: \"Any `AgentBackend`. On the page, the scripted demo agent.\", required: true },\n { prop: \"storage\", label: \"Keep across reloads\", description: \"Where to keep the thread (`browserStorage()` from `@surfaces-ui/state`, or your own); checked when it loads.\" },\n { prop: \"agents\", label: \"Agent menus\", description: \"What the backend offers, for the composer's Setup menu. Needs `onSettingsChange`.\" },\n { prop: \"providers\", label: \"Model providers\", description: \"Where models run: the Model menu groups them by provider.\" },\n ],\n callbacks: [\n { prop: \"onThreadChange\", description: \"The thread after every change, to save it or build from what was drawn.\" },\n { prop: \"onSettingsChange\", description: \"A person changed the agent, model, skills or connectors.\" },\n { prop: \"onContext\", description: \"What a person does in a drawn component.\" },\n { prop: \"onReferencesChange\", description: \"Tables and columns attached to the message being written, when the host holds them.\" },\n ],\n example: { starters: [\"Show the data model\"], height: 560 },\n});\n\nexport const pageStudioDoc = describeAppComponent<PageStudioProps>()({\n name: \"PageStudio\",\n from: CHAT,\n description:\n \"A page beside an instruction box: a person says what to change, an agent answers with A2UI, and its reply becomes page edits checked against the catalog. Each instruction is one undo step and the log says who made each change. With `arrange`, a person can also lay the page out by hand (drag, side by side, heights and widths, all by keyboard too): each arrangement is one undo step, logged by them, and told to the agent with the next instruction.\",\n props: {\n type: \"object\",\n properties: { starters: words.starters, arrange: { type: \"boolean\", description: \"Offer Arrange beside Undo and Redo.\" }, user, settings },\n },\n parts: [\n { prop: \"agent\", label: \"Agent\", description: \"Any `AgentBackend`. On the page, the scripted demo agent that edits dashboards.\", required: true },\n { prop: \"page\", label: \"Page\", description: \"The `PageDocument` to start from: a dashboard from the gallery.\", required: true },\n { prop: \"providers\", label: \"Model providers\", description: \"Where models run: the Model menu groups them by provider.\" },\n ],\n callbacks: [\n { prop: \"onChange\", description: \"The page after each change, to save it.\" },\n { prop: \"onSettingsChange\", description: \"A person changed the model.\" },\n ],\n example: { arrange: true, user: { id: \"you\", name: \"you\" } },\n});\n\n/** Every app component of `@surfaces-ui/chat`. */\nexport const chatAppComponents: AppComponentDoc[] = [analyticsChatDoc, chatDoc, pageStudioDoc];\n"]}
@@ -0,0 +1,66 @@
1
+ import { type AgentBackend, type AgentEvent } from "@surfaces-ui/agent";
2
+ import { type Catalog, type ConversationScript, type ScriptPart } from "@surfaces-ui/spec";
3
+ import { type ChatThread } from "./thread.js";
4
+ /**
5
+ * A conversation as a document: a title and the thread, as plain JSON. It
6
+ * can be saved beside pages in a surface library (kind "conversation"),
7
+ * opened again with `Chat`'s `initialThread`, and shown to someone else.
8
+ * Whatever is in it is checked again when it is opened (`parseConversation`)
9
+ * and when its surfaces are drawn.
10
+ */
11
+ export interface ConversationDocument {
12
+ type: "conversation";
13
+ id: string;
14
+ title: string;
15
+ description?: string;
16
+ thread: Pick<ChatThread, "messages" | "surfaces" | "suggestions">;
17
+ }
18
+ /** A thread as a document to keep. A reply still streaming is kept as it stands; the session and usage are not kept. */
19
+ export declare function conversationDocument(thread: ChatThread, meta: {
20
+ id: string;
21
+ title: string;
22
+ description?: string;
23
+ }): ConversationDocument;
24
+ /** Checks a conversation document from storage, a library or anywhere else before it is used. Undefined for anything that is not one. */
25
+ export declare function parseConversation(input: unknown): ConversationDocument | undefined;
26
+ /** A conversation document's thread, ready for `Chat`'s `initialThread` or `MessageList`. */
27
+ export declare function conversationThread(document: ConversationDocument): ChatThread;
28
+ /** The events one written reply becomes, ending in `done`. */
29
+ export declare function scriptEvents(reply: ScriptPart[], options: {
30
+ catalogId: string;
31
+ answeredBy: string;
32
+ suggestions?: string[];
33
+ sessionId?: string;
34
+ }): AgentEvent[];
35
+ /**
36
+ * A written conversation as a thread, already played: the first `turns`
37
+ * turns (all of them by default), each folded through `reduceThread` exactly
38
+ * as a live reply would be, so what is drawn is what a real agent sending
39
+ * the same content would draw.
40
+ */
41
+ export declare function scriptThread(script: ConversationScript, catalog: Catalog, turns?: number): ChatThread;
42
+ export interface ScriptAgentOptions {
43
+ catalog: Catalog;
44
+ /** Pause between events, so a reply arrives a piece at a time. */
45
+ delayMs?: number;
46
+ /** How many turns the thread it carries on from has already played (`scriptThread`'s `turns`), so it knows what to offer next. */
47
+ played?: number;
48
+ /**
49
+ * What to answer when a control in a drawn component sends an event the
50
+ * script's own `events` do not cover. Without an answer the event is
51
+ * acknowledged in a line.
52
+ */
53
+ onAction?(action: {
54
+ name: string;
55
+ surfaceId: string;
56
+ context: Record<string, unknown>;
57
+ }): ScriptPart[] | undefined;
58
+ }
59
+ /**
60
+ * An agent that answers from a written conversation: a message that matches
61
+ * a turn's `say` gets that turn's reply, an event from a drawn component gets
62
+ * the script's answer to it (`events`), and anything else is told what the
63
+ * script can answer. It is not a model and its replies say so through
64
+ * `answeredBy`. Use it to let people carry on a sample conversation.
65
+ */
66
+ export declare function scriptAgent(script: ConversationScript, options: ScriptAgentOptions): AgentBackend;