@surfaces-ui/chat 0.4.0 → 0.5.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.
@@ -1,11 +1,12 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { addDataRefs, dataRefLabel, hasDataRefs, readDataRefs, sameDataRef } from "@surfaces-ui/components";
3
- import { useEffect, useRef, useState } from "react";
2
+ import { addDataRefs, dataRefLabel, hasDataRefs, readDataRefs, safeImageAddress, sameDataRef } from "@surfaces-ui/components";
3
+ import { useEffect, useImperativeHandle, useRef, useState } from "react";
4
4
  import { DataPanel } from "./DataPanel.js";
5
5
  import { MenuButton, MenuGroup, MenuItem } from "./Menu.js";
6
6
  import { ChatIcon } from "./icons.js";
7
7
  import { ModelMenu, SetupMenu } from "./selectors.js";
8
8
  import { useVoice } from "./voice.js";
9
+ const attachmentKey = (one) => one.id ?? one.name;
9
10
  /**
10
11
  * Where the person writes. Enter sends; Shift+Enter starts a new line.
11
12
  * Everything beyond the box is optional: files from the computer (the `+`
@@ -19,6 +20,15 @@ export function ChatComposer(props) {
19
20
  const references = given ?? kept;
20
21
  const latest = useRef(references);
21
22
  latest.current = references;
23
+ const [keptAttachments, setKeptAttachments] = useState([]);
24
+ const attachments = props.attachments ?? keptAttachments;
25
+ const latestAttachments = useRef(attachments);
26
+ latestAttachments.current = attachments;
27
+ const setAttachments = (next) => {
28
+ latestAttachments.current = next;
29
+ setKeptAttachments(next);
30
+ props.onAttachmentsChange?.(next);
31
+ };
22
32
  const setReferences = (next) => {
23
33
  latest.current = next;
24
34
  setKept(next);
@@ -43,9 +53,15 @@ export function ChatComposer(props) {
43
53
  const send = (words) => {
44
54
  if (streaming || disabled || !words.trim())
45
55
  return;
46
- onSend(words, latest.current);
56
+ const withThem = latestAttachments.current;
57
+ if (withThem.length > 0)
58
+ onSend(words, latest.current, withThem);
59
+ else
60
+ onSend(words, latest.current);
47
61
  setText("");
48
62
  setReferences([]);
63
+ if (withThem.length > 0)
64
+ setAttachments([]);
49
65
  setPending((all) => all.filter((p) => !p.error));
50
66
  setSaid("");
51
67
  };
@@ -91,17 +107,41 @@ export function ChatComposer(props) {
91
107
  }
92
108
  const failed = new Map();
93
109
  results.forEach((result, i) => {
94
- if (!result.ref)
110
+ if (!result.ref && !result.attachment && !result.taken)
95
111
  failed.set(keys[i].key, result.error || "This file cannot be used as data.");
96
112
  });
97
113
  setPending((all) => all.flatMap((p) => (keys.some((k) => k.key === p.key) ? (failed.has(p.key) ? [{ ...p, error: failed.get(p.key) }] : []) : [p])));
98
114
  const refs = results.flatMap((r) => (r.ref ? [r.ref] : []));
99
115
  if (refs.length > 0)
100
116
  attach(refs);
117
+ const pictures = results.flatMap((r) => (r.attachment ? [r.attachment] : []));
118
+ if (pictures.length > 0) {
119
+ const have = latestAttachments.current;
120
+ const fresh = pictures.filter((one) => !have.some((other) => attachmentKey(other) === attachmentKey(one)));
121
+ if (fresh.length > 0)
122
+ setAttachments([...have, ...fresh]);
123
+ if (refs.length === 0)
124
+ setSaid(fresh.length === 0 ? "Already attached." : `Attached ${fresh.length === 1 ? fresh[0].name : `${fresh.length} files`}.`);
125
+ }
101
126
  if (failed.size > 0)
102
127
  setSaid(`${failed.size === 1 ? "One file" : `${failed.size} files`} could not be used.`);
103
128
  };
129
+ // What a host's `attach(files)` and a drop outside the form call must see the latest props.
130
+ const uploadNow = useRef(upload);
131
+ uploadNow.current = upload;
132
+ useImperativeHandle(props.handleRef, () => ({ attach: (files) => uploadNow.current(files), focus: () => textArea.current?.focus({ preventScroll: true }) }), []);
133
+ // A drop on the form is also seen by `dropTarget` around it (and the other way round); each event is handled once.
134
+ const seen = useRef(new WeakSet());
135
+ const firstSight = (event) => {
136
+ const native = "nativeEvent" in event && event.nativeEvent ? event.nativeEvent : event;
137
+ if (seen.current.has(native))
138
+ return false;
139
+ seen.current.add(native);
140
+ return true;
141
+ };
104
142
  const onDragOver = (event) => {
143
+ if (!event.dataTransfer)
144
+ return;
105
145
  const files = attachFiles && Array.from(event.dataTransfer.types).includes("Files");
106
146
  if (disabled || (!hasDataRefs(event.dataTransfer) && !files))
107
147
  return;
@@ -111,7 +151,7 @@ export function ChatComposer(props) {
111
151
  };
112
152
  const onDrop = (event) => {
113
153
  setOver(false);
114
- if (disabled)
154
+ if (disabled || !event.dataTransfer)
115
155
  return;
116
156
  const dropped = readDataRefs(event.dataTransfer);
117
157
  if (dropped.length > 0) {
@@ -126,6 +166,29 @@ export function ChatComposer(props) {
126
166
  void upload(files);
127
167
  }
128
168
  };
169
+ const around = useRef({ onDragOver, onDrop });
170
+ around.current = { onDragOver, onDrop };
171
+ const outside = props.dropTarget;
172
+ useEffect(() => {
173
+ const element = outside && "current" in outside ? outside.current : outside;
174
+ if (!element)
175
+ return;
176
+ const over = (event) => firstSight(event) && around.current.onDragOver(event);
177
+ const drop = (event) => firstSight(event) && around.current.onDrop(event);
178
+ const leave = (event) => {
179
+ const into = event.relatedTarget;
180
+ if (!(into instanceof Node) || !element.contains(into))
181
+ setOver(false);
182
+ };
183
+ element.addEventListener("dragover", over);
184
+ element.addEventListener("drop", drop);
185
+ element.addEventListener("dragleave", leave);
186
+ return () => {
187
+ element.removeEventListener("dragover", over);
188
+ element.removeEventListener("drop", drop);
189
+ element.removeEventListener("dragleave", leave);
190
+ };
191
+ });
129
192
  const onPaste = (event) => {
130
193
  const files = Array.from(event.clipboardData?.files ?? []);
131
194
  if (!attachFiles || files.length === 0)
@@ -151,20 +214,27 @@ export function ChatComposer(props) {
151
214
  const chooses = !!onSettingsChange && (agents.length > 0 || (props.providers?.length ?? 0) > 0);
152
215
  const talking = voice.state !== "off" && voice.state !== "dictating";
153
216
  const empty = !text.trim();
154
- return (_jsxs("form", { ref: form, className: "sf-chat-composer", "data-compact": compact || undefined, "data-rich": attachFiles || canBrowse || chooses || voice.supported || undefined, "data-over": over || undefined, onSubmit: submit, onDragOver: onDragOver, onDragLeave: () => setOver(false), onDrop: onDrop, onKeyDown: onFormKeyDown, children: [(context.length > 0 || references.length > 0 || pending.length > 0) && (_jsxs("ul", { className: "sf-chat-references sf-chat-attached", "aria-label": "Attached to this message", children: [context.map((about) => (_jsxs("li", { className: "sf-chat-reference", "data-kind": "context", children: [_jsx(ChatIcon, { name: "about" }), _jsx("span", { children: about.label }), about.detail && _jsx("span", { className: "sf-chat-reference-note", children: about.detail }), about.onClear && (_jsx("button", { type: "button", className: "sf-chat-reference-remove", "aria-label": about.clearLabel ?? `Remove ${about.label}`, title: about.clearLabel, onClick: () => {
217
+ return (_jsxs("form", { ref: form, className: "sf-chat-composer", "data-compact": compact || undefined, "data-rich": !!attachFiles || canBrowse || chooses || voice.supported || undefined, "data-over": over || undefined, onSubmit: submit, onDragOver: (event) => firstSight(event) && onDragOver(event), onDragLeave: () => setOver(false), onDrop: (event) => firstSight(event) && onDrop(event), onKeyDown: onFormKeyDown, children: [(context.length > 0 || references.length > 0 || attachments.length > 0 || pending.length > 0) && (_jsxs("ul", { className: "sf-chat-references sf-chat-attached", "aria-label": "Attached to this message", children: [context.map((about) => (_jsxs("li", { className: "sf-chat-reference", "data-kind": "context", children: [_jsx(ChatIcon, { name: "about" }), _jsx("span", { children: about.label }), about.detail && _jsx("span", { className: "sf-chat-reference-note", children: about.detail }), about.onClear && (_jsx("button", { type: "button", className: "sf-chat-reference-remove", "aria-label": about.clearLabel ?? `Remove ${about.label}`, title: about.clearLabel, onClick: () => {
155
218
  about.onClear?.();
156
219
  setSaid(`Removed ${about.label}.`);
157
220
  textArea.current?.focus({ preventScroll: true });
158
221
  }, children: _jsx(ChatIcon, { name: "close" }) }))] }, about.id ?? about.label))), references.map((ref) => (_jsxs("li", { className: "sf-chat-reference", "data-kind": ref.kind, children: [_jsx(ChatIcon, { name: ref.kind === "file" ? "file" : "data" }), _jsx("span", { children: dataRefLabel(ref) }), _jsx("button", { type: "button", className: "sf-chat-reference-remove", "aria-label": `Remove ${dataRefLabel(ref)}`, onClick: () => {
159
222
  setReferences(latest.current.filter((have) => !sameDataRef(have, ref)));
160
223
  setSaid(`Removed ${dataRefLabel(ref)}.`);
161
- }, children: _jsx(ChatIcon, { name: "close" }) })] }, `${ref.sourceId}/${ref.kind}/${dataRefLabel(ref)}`))), pending.map((p) => (_jsxs("li", { className: "sf-chat-reference", "data-kind": "file", "data-state": p.error ? "failed" : "reading", children: [_jsx(ChatIcon, { name: "file" }), _jsx("span", { children: p.name }), _jsx("span", { className: "sf-chat-reference-note", children: p.error ?? "Reading…" }), p.error && (_jsx("button", { type: "button", className: "sf-chat-reference-remove", "aria-label": `Remove ${p.name}`, onClick: () => setPending((all) => all.filter((x) => x.key !== p.key)), children: _jsx(ChatIcon, { name: "close" }) }))] }, p.key)))] })), _jsx("textarea", { ref: textArea, className: "sf-input", rows: 2, "aria-label": props.label ?? "Message", placeholder: placeholder ?? "Ask about your data", value: text, disabled: disabled, onChange: (e) => setText(e.target.value), onKeyDown: onKeyDown, onPaste: onPaste }), _jsxs("div", { className: "sf-chat-toolbar", children: [(attachFiles || manages("data")) && (_jsx(MenuButton, { label: "Add files or data", icon: "plus", iconOnly: true, disabled: disabled, children: (close) => (_jsxs(MenuGroup, { label: "Add", children: [attachFiles && (_jsx(MenuItem, { detail: "Any file; those that can be read become tables", onSelect: () => {
224
+ }, children: _jsx(ChatIcon, { name: "close" }) })] }, `${ref.sourceId}/${ref.kind}/${dataRefLabel(ref)}`))), attachments.map((one) => {
225
+ const picture = one.mediaType.startsWith("image/") ? safeImageAddress(one.preview) : undefined;
226
+ return (_jsxs("li", { className: "sf-chat-reference", "data-kind": "attachment", "data-thumbnail": picture ? true : undefined, children: [picture ? _jsx("img", { className: "sf-chat-thumbnail", src: picture, alt: "" }) : _jsx(ChatIcon, { name: "file" }), _jsx("span", { children: one.name }), _jsx("button", { type: "button", className: "sf-chat-reference-remove", "aria-label": `Remove ${one.name}`, onClick: () => {
227
+ setAttachments(latestAttachments.current.filter((have) => attachmentKey(have) !== attachmentKey(one)));
228
+ setSaid(`Removed ${one.name}.`);
229
+ textArea.current?.focus({ preventScroll: true });
230
+ }, children: _jsx(ChatIcon, { name: "close" }) })] }, attachmentKey(one)));
231
+ }), pending.map((p) => (_jsxs("li", { className: "sf-chat-reference", "data-kind": "file", "data-state": p.error ? "failed" : "reading", children: [_jsx(ChatIcon, { name: "file" }), _jsx("span", { children: p.name }), _jsx("span", { className: "sf-chat-reference-note", children: p.error ?? "Reading…" }), p.error && (_jsx("button", { type: "button", className: "sf-chat-reference-remove", "aria-label": `Remove ${p.name}`, onClick: () => setPending((all) => all.filter((x) => x.key !== p.key)), children: _jsx(ChatIcon, { name: "close" }) }))] }, p.key)))] })), _jsx("textarea", { ref: textArea, className: "sf-input", rows: 2, "aria-label": props.label ?? "Message", placeholder: placeholder ?? "Ask about your data", value: text, disabled: disabled, onChange: (e) => setText(e.target.value), onKeyDown: onKeyDown, onPaste: onPaste }), _jsxs("div", { className: "sf-chat-toolbar", children: [(attachFiles || manages("data")) && (_jsx(MenuButton, { label: "Add files or data", icon: "plus", iconOnly: true, disabled: disabled, children: (close) => (_jsxs(MenuGroup, { label: "Add", children: [attachFiles && (_jsx(MenuItem, { detail: props.uploadDetail ?? "Any file; those that can be read become tables", onSelect: () => {
162
232
  close();
163
233
  fileInput.current?.click();
164
234
  }, children: "Upload files\u2026" })), manages("data") && (_jsx(MenuItem, { detail: "Tables, columns and files from a connection", onSelect: () => {
165
235
  close();
166
236
  onManage?.("data");
167
- }, children: "Add tables and files\u2026" }))] })) })), attachFiles && (_jsx("input", { ref: fileInput, type: "file", multiple: true, hidden: true, tabIndex: -1, "aria-hidden": "true", onChange: (e) => {
237
+ }, children: "Add tables and files\u2026" }))] })) })), attachFiles && (_jsx("input", { ref: fileInput, type: "file", multiple: true, accept: props.accept, hidden: true, tabIndex: -1, "aria-hidden": "true", onChange: (e) => {
168
238
  const files = Array.from(e.target.files ?? []);
169
239
  e.target.value = "";
170
240
  void upload(files);
@@ -1 +1 @@
1
- {"version":3,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b,CACT,CAAC,GACE,CACP,EACA,KAAK,CAAC,SAAS,IAAI,MAAM,IAAI,CAC5B,eAAK,SAAS,EAAC,uBAAuB,EAAC,IAAI,EAAC,OAAO,gBAAY,YAAY,aACzE,wBACG,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,wCAAwC,OAAG,MAAO,CAAC,KAAK,IAC7G,EACJ,gBAAM,SAAS,EAAC,+BAA+B,aAC7C,iBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,WAAW,kBACR,SAAS;gCACtB,qHAAqH;gCACrH,SAAS,QACT,OAAO,EAAE,GAAG,EAAE;oCACZ,MAAM,IAAI,GAAG,MAAM,CAAC;oCACpB,SAAS,CAAC,IAAI,CAAC,CAAC;oCAChB,OAAO,EAAE,MAAM,EAAE,CAAC;oCAClB,IAAI,IAAI,KAAK,SAAS;wCAAE,KAAK,CAAC,OAAO,EAAE,CAAC;;wCACnC,KAAK,CAAC,QAAQ,EAAE,CAAC;gCACxB,CAAC,0BAGM,EACT,iBAAQ,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,WAAW,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,wBAEjE,IACJ,IACH,CACP,EACA,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,MAAM,IAAI,CAClC,YAAG,SAAS,EAAC,eAAe,EAAC,IAAI,EAAC,QAAQ,gBAAa,KAAK,CAAC,KAAK,YAC/D,KAAK,CAAC,MAAM,GACX,CACL,EACD,YAAG,SAAS,EAAC,uBAAuB,EAAC,IAAI,EAAC,QAAQ,YAC/C,IAAI,GACH,IACC,CACR,CAAC;AACJ,CAAC;AAED,mFAAmF;AACnF,MAAM,CAAC,MAAM,QAAQ,GAAG,YAAY,CAAC","sourcesContent":["import { type DataRef, addDataRefs, dataRefLabel, hasDataRefs, readDataRefs, sameDataRef } from \"@surfaces-ui/components\";\nimport type { AgentInfo, ToolConnector } from \"@surfaces-ui/proto\";\nimport { type ClipboardEvent, type DragEvent, type FormEvent, type KeyboardEvent, useEffect, useRef, useState } from \"react\";\nimport { DataPanel, type DataPanelProps } from \"./DataPanel.js\";\nimport { MenuButton, MenuGroup, MenuItem } from \"./Menu.js\";\nimport { ChatIcon } from \"./icons.js\";\nimport { type ChatPanel, type ChatProvider, ModelMenu, SetupMenu } from \"./selectors.js\";\nimport type { SpeechAdapter } from \"./speech.js\";\nimport type { ChatSettings } from \"./useChat.js\";\nimport { type VoiceReply, useVoice } from \"./voice.js\";\n\n/** What became of one file a person attached. */\nexport interface AttachResult {\n file: File;\n /** The table or file it became, by name. */\n ref?: DataRef;\n /** Why it could not be used. */\n error?: string;\n}\n\nexport interface ComposerProps {\n onSend(text: string, references: DataRef[]): void;\n /** Shown in place of Send while a reply is streaming. */\n onStop?(): void;\n streaming?: boolean;\n disabled?: boolean;\n placeholder?: string;\n /** The box's name for assistive technology. Default \"Message\". */\n label?: string;\n /**\n * Tables and columns attached to the message being written. Give it with\n * `onReferencesChange` to hold them yourself, so something beside the chat\n * (a browser's \"Add to chat\") can add to them; otherwise the composer keeps\n * them. Either way they can be dropped onto the composer.\n */\n references?: DataRef[];\n onReferencesChange?(references: DataRef[]): void;\n\n /** Turns files from the person's computer into data the agent can name. Without it there is no upload. Any file is offered; the host says which it can use. */\n attachFiles?(files: File[]): Promise<AttachResult[]>;\n /** Browsing tables and files from the composer (\"Add data\"). Without `onManage`, it opens in a popover. */\n browse?: Omit<DataPanelProps, \"onAttach\">;\n /** Agents with their models, skills and connectors (`DescribeAgents`). Each menu shows only when there is something to choose. */\n agents?: AgentInfo[];\n settings?: ChatSettings;\n onSettingsChange?(settings: ChatSettings): void;\n /** Data connections for the Connectors menu's Data group. */\n sources?: { id: string; label: string }[];\n onAddConnection?(): void;\n onConnect?(connector: ToolConnector): void;\n /** Opens a panel with the whole list (\"View all…\", \"Manage…\", \"Add data\"). */\n onManage?(panel: ChatPanel): void;\n /** The panels `onManage` can open. Default: all of them. */\n managed?: ChatPanel[];\n /** Items a menu lists before \"View all…\". Default 5. */\n menuLimit?: number;\n /** Where models run, when the host can reach several: the Model menu groups models by provider. */\n providers?: ChatProvider[];\n /** \"Manage providers…\" at the foot of the Model menu. */\n onManageProviders?(): void;\n /** Talking instead of typing. The microphone shows only where the adapter is supported. */\n speech?: SpeechAdapter;\n /** The latest reply, for a spoken conversation to read and to know when to listen again. */\n voiceReply?: VoiceReply;\n /**\n * Ask before the microphone is first used. The microphone shows, and its\n * first press says where audio goes (`speech.label`) with \"Use voice\" and\n * \"Not now\"; nothing listens until the person agrees. The host keeps the\n * answer (`given`) so it is asked once. Without it, passing `speech` is the consent.\n */\n speechConsent?: SpeechConsent;\n /** What the message is about beyond attached data, as chips before the attached tables and files. */\n context?: ComposerContext[];\n /** Choices for the next message, as checkboxes under the box. */\n toggles?: ComposerToggle[];\n}\n\n/**\n * A choice that goes with the next message, drawn as a checkbox under the\n * box (\"Try three ways\"). The host keeps `checked`, and clears it after a send\n * when it holds for one message only.\n */\nexport interface ComposerToggle {\n id: string;\n label: string;\n /** More about it, after the label and part of its name. */\n detail?: string;\n checked: boolean;\n onChange(checked: boolean): void;\n disabled?: boolean;\n}\n\n/**\n * Something the message is about that is not a table or a file: the part of\n * a page a person selected (\"About Chart amount-by-region\"). Shown as a chip\n * beside the attached data; the host keeps it and says what it means.\n */\nexport interface ComposerContext {\n /** Keeps the chip steady across renders; defaults to the label. */\n id?: string;\n label: string;\n /** Shown after the label, smaller. */\n detail?: string;\n /** Given, the chip has a remove button that calls it (\"Whole page instead\"). */\n onClear?(): void;\n /** The remove button's name. Default \"Remove \" and the label. */\n clearLabel?: string;\n}\n\n/** Whether the person agreed to use voice, kept by the host. */\nexport interface SpeechConsent {\n given: boolean;\n onGive(): void;\n}\n\ntype Pending = { key: string; name: string; error?: string };\n\n/**\n * Where the person writes. Enter sends; Shift+Enter starts a new line.\n * Everything beyond the box is optional: files from the computer (the `+`\n * menu, a drop or a paste), tables and files from a browser, the agent,\n * model, skills and connectors, and the microphone. Send is the arrow.\n */\nexport function ChatComposer(props: ComposerProps) {\n const { onSend, onStop, streaming, disabled, placeholder, references: given, onReferencesChange, attachFiles, browse, agents = [], settings = {}, onSettingsChange, onManage, speech, context = [], toggles = [] } = props;\n const [text, setText] = useState(\"\");\n const [kept, setKept] = useState<DataRef[]>([]);\n const references = given ?? kept;\n const latest = useRef(references);\n latest.current = references;\n const setReferences = (next: DataRef[]) => {\n latest.current = next;\n setKept(next);\n onReferencesChange?.(next);\n };\n const [pending, setPending] = useState<Pending[]>([]);\n const [over, setOver] = useState(false);\n const [said, setSaid] = useState(\"\");\n const fileInput = useRef<HTMLInputElement>(null);\n const form = useRef<HTMLFormElement>(null);\n // A narrow composer shows its menus as icons, so the row stays one or two lines.\n const [compact, setCompact] = useState(false);\n useEffect(() => {\n const el = form.current;\n if (!el || typeof ResizeObserver === \"undefined\") return;\n const watch = new ResizeObserver(([entry]) => setCompact((entry?.contentRect.width ?? 999) < 420));\n watch.observe(el);\n return () => watch.disconnect();\n }, []);\n const textArea = useRef<HTMLTextAreaElement>(null);\n\n const send = (words: string) => {\n if (streaming || disabled || !words.trim()) return;\n onSend(words, latest.current);\n setText(\"\");\n setReferences([]);\n setPending((all) => all.filter((p) => !p.error));\n setSaid(\"\");\n };\n const voice = useVoice({ speech, onText: setText, onSend: send, reply: props.voiceReply });\n // A press before consent asks first, then starts what was pressed.\n const [asking, setAsking] = useState<\"dictate\" | \"converse\" | null>(null);\n const consent = props.speechConsent;\n const start = (mode: \"dictate\" | \"converse\") => {\n if (consent && !consent.given) return setAsking(mode);\n if (mode === \"dictate\") voice.dictate();\n else voice.converse();\n };\n const submit = (event?: FormEvent) => {\n event?.preventDefault();\n send(text);\n };\n const onKeyDown = (event: KeyboardEvent<HTMLTextAreaElement>) => {\n if (event.key === \"Enter\" && !event.shiftKey && !event.nativeEvent.isComposing) submit(event);\n };\n\n const attach = (refs: DataRef[]) => {\n const next = addDataRefs(latest.current, refs);\n const added = next.length - latest.current.length;\n const fresh = refs.find((ref) => !latest.current.some((have) => sameDataRef(have, ref))) ?? refs[0];\n setReferences(next);\n setSaid(added === 0 ? \"Already attached.\" : `Attached ${added === 1 && fresh ? dataRefLabel(fresh) : `${added} items`}.`);\n };\n\n const upload = async (files: File[]) => {\n if (!attachFiles || files.length === 0) return;\n const keys = files.map((f, i) => ({ key: `${Date.now()}-${i}-${f.name}`, name: f.name }));\n setPending((all) => [...all, ...keys]);\n setSaid(`Reading ${files.length === 1 ? files[0]!.name : `${files.length} files`}…`);\n let results: AttachResult[];\n try {\n results = await attachFiles(files);\n } catch (error) {\n results = files.map((file) => ({ file, error: error instanceof Error ? error.message : String(error) }));\n }\n const failed = new Map<string, string>();\n results.forEach((result, i) => {\n if (!result.ref) failed.set(keys[i]!.key, result.error || \"This file cannot be used as data.\");\n });\n setPending((all) => all.flatMap((p) => (keys.some((k) => k.key === p.key) ? (failed.has(p.key) ? [{ ...p, error: failed.get(p.key) }] : []) : [p])));\n const refs = results.flatMap((r) => (r.ref ? [r.ref] : []));\n if (refs.length > 0) attach(refs);\n if (failed.size > 0) setSaid(`${failed.size === 1 ? \"One file\" : `${failed.size} files`} could not be used.`);\n };\n\n const onDragOver = (event: DragEvent) => {\n const files = attachFiles && Array.from(event.dataTransfer.types).includes(\"Files\");\n if (disabled || (!hasDataRefs(event.dataTransfer) && !files)) return;\n event.preventDefault();\n event.dataTransfer.dropEffect = \"copy\";\n setOver(true);\n };\n const onDrop = (event: DragEvent) => {\n setOver(false);\n if (disabled) return;\n const dropped = readDataRefs(event.dataTransfer);\n if (dropped.length > 0) {\n // The names would otherwise be typed into the box as text as well.\n event.preventDefault();\n attach(dropped);\n return;\n }\n const files = Array.from(event.dataTransfer.files ?? []);\n if (attachFiles && files.length > 0) {\n event.preventDefault();\n void upload(files);\n }\n };\n const onPaste = (event: ClipboardEvent) => {\n const files = Array.from(event.clipboardData?.files ?? []);\n if (!attachFiles || files.length === 0) return;\n event.preventDefault();\n void upload(files);\n };\n\n // Escape stops a spoken conversation from anywhere in the composer.\n const onFormKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\" && voice.state !== \"off\") {\n event.stopPropagation();\n voice.stop(\"Stopped.\");\n }\n };\n useEffect(() => {\n if (voice.state === \"off\") textArea.current?.focus({ preventScroll: true });\n }, [voice.state]);\n\n const manages = (panel: ChatPanel) => !!onManage && (!props.managed || props.managed.includes(panel));\n const canBrowse = !!browse || manages(\"data\");\n const selectorProps = { agents, settings, onSettingsChange: onSettingsChange ?? (() => {}), limit: props.menuLimit, compact };\n const manageIf = (panel: ChatPanel) => (manages(panel) ? onManage : undefined);\n const chooses = !!onSettingsChange && (agents.length > 0 || (props.providers?.length ?? 0) > 0);\n const talking = voice.state !== \"off\" && voice.state !== \"dictating\";\n const empty = !text.trim();\n\n return (\n <form\n ref={form}\n className=\"sf-chat-composer\"\n data-compact={compact || undefined}\n data-rich={attachFiles || canBrowse || chooses || voice.supported || undefined}\n data-over={over || undefined}\n onSubmit={submit}\n onDragOver={onDragOver}\n onDragLeave={() => setOver(false)}\n onDrop={onDrop}\n onKeyDown={onFormKeyDown}\n >\n {(context.length > 0 || references.length > 0 || pending.length > 0) && (\n <ul className=\"sf-chat-references sf-chat-attached\" aria-label=\"Attached to this message\">\n {context.map((about) => (\n <li key={about.id ?? about.label} className=\"sf-chat-reference\" data-kind=\"context\">\n <ChatIcon name=\"about\" />\n <span>{about.label}</span>\n {about.detail && <span className=\"sf-chat-reference-note\">{about.detail}</span>}\n {about.onClear && (\n <button\n type=\"button\"\n className=\"sf-chat-reference-remove\"\n aria-label={about.clearLabel ?? `Remove ${about.label}`}\n title={about.clearLabel}\n onClick={() => {\n about.onClear?.();\n setSaid(`Removed ${about.label}.`);\n textArea.current?.focus({ preventScroll: true });\n }}\n >\n <ChatIcon name=\"close\" />\n </button>\n )}\n </li>\n ))}\n {references.map((ref) => (\n <li key={`${ref.sourceId}/${ref.kind}/${dataRefLabel(ref)}`} className=\"sf-chat-reference\" data-kind={ref.kind}>\n <ChatIcon name={ref.kind === \"file\" ? \"file\" : \"data\"} />\n <span>{dataRefLabel(ref)}</span>\n <button\n type=\"button\"\n className=\"sf-chat-reference-remove\"\n aria-label={`Remove ${dataRefLabel(ref)}`}\n onClick={() => {\n setReferences(latest.current.filter((have) => !sameDataRef(have, ref)));\n setSaid(`Removed ${dataRefLabel(ref)}.`);\n }}\n >\n <ChatIcon name=\"close\" />\n </button>\n </li>\n ))}\n {pending.map((p) => (\n <li key={p.key} className=\"sf-chat-reference\" data-kind=\"file\" data-state={p.error ? \"failed\" : \"reading\"}>\n <ChatIcon name=\"file\" />\n <span>{p.name}</span>\n <span className=\"sf-chat-reference-note\">{p.error ?? \"Reading…\"}</span>\n {p.error && (\n <button type=\"button\" className=\"sf-chat-reference-remove\" aria-label={`Remove ${p.name}`} onClick={() => setPending((all) => all.filter((x) => x.key !== p.key))}>\n <ChatIcon name=\"close\" />\n </button>\n )}\n </li>\n ))}\n </ul>\n )}\n <textarea\n ref={textArea}\n className=\"sf-input\"\n rows={2}\n aria-label={props.label ?? \"Message\"}\n placeholder={placeholder ?? \"Ask about your data\"}\n value={text}\n disabled={disabled}\n onChange={(e) => setText(e.target.value)}\n onKeyDown={onKeyDown}\n onPaste={onPaste}\n />\n <div className=\"sf-chat-toolbar\">\n {(attachFiles || manages(\"data\")) && (\n <MenuButton label=\"Add files or data\" icon=\"plus\" iconOnly disabled={disabled}>\n {(close) => (\n <MenuGroup label=\"Add\">\n {attachFiles && (\n <MenuItem\n detail=\"Any file; those that can be read become tables\"\n onSelect={() => {\n close();\n fileInput.current?.click();\n }}\n >\n Upload files…\n </MenuItem>\n )}\n {manages(\"data\") && (\n <MenuItem\n detail=\"Tables, columns and files from a connection\"\n onSelect={() => {\n close();\n onManage?.(\"data\");\n }}\n >\n Add tables and files…\n </MenuItem>\n )}\n </MenuGroup>\n )}\n </MenuButton>\n )}\n {attachFiles && (\n <input\n ref={fileInput}\n type=\"file\"\n multiple\n hidden\n tabIndex={-1}\n aria-hidden=\"true\"\n onChange={(e) => {\n const files = Array.from(e.target.files ?? []);\n e.target.value = \"\";\n void upload(files);\n }}\n />\n )}\n {canBrowse &&\n (manages(\"data\") ? (\n <button type=\"button\" className=\"sf-chat-tool\" data-icon-only={compact || undefined} aria-label={compact ? \"Add data\" : undefined} title={compact ? \"Add data\" : undefined} disabled={disabled} onClick={() => onManage?.(\"data\")}>\n <ChatIcon name=\"data\" />\n {!compact && <span className=\"sf-chat-tool-text\">Add data</span>}\n </button>\n ) : (\n <MenuButton label=\"Add data\" text=\"Add data\" icon=\"data\" iconOnly={compact} disabled={disabled} className=\"sf-chat-data-menu\">\n {() => <DataPanel {...browse} onAttach={attach} />}\n </MenuButton>\n ))}\n {chooses && (\n <div className=\"sf-chat-selectors\">\n <ModelMenu {...selectorProps} onManage={manageIf(\"setup\")} providers={props.providers} onManageProviders={props.onManageProviders} />\n <SetupMenu {...selectorProps} onManage={manageIf(\"setup\")} sources={props.sources} onAddConnection={props.onAddConnection} onConnect={props.onConnect} />\n </div>\n )}\n <span className=\"sf-chat-toolbar-end\">\n {voice.supported && (\n <>\n <button\n type=\"button\"\n className=\"sf-chat-tool\"\n data-icon-only\n aria-pressed={voice.state === \"dictating\"}\n aria-label={voice.state === \"dictating\" ? \"Stop dictating\" : \"Dictate\"}\n title={voice.state === \"dictating\" ? \"Stop dictating\" : `Dictate. ${speech!.label}`}\n disabled={disabled || talking}\n onClick={() => (voice.state === \"dictating\" ? voice.stop() : start(\"dictate\"))}\n >\n <ChatIcon name=\"mic\" />\n </button>\n <button\n type=\"button\"\n className=\"sf-chat-tool\"\n data-icon-only\n data-live={talking || undefined}\n aria-pressed={talking}\n aria-label={talking ? \"End conversation\" : \"Talk\"}\n title={talking ? \"End conversation (Escape)\" : `Talk back and forth. ${speech!.label}`}\n disabled={disabled}\n onClick={() => (talking ? voice.stop(\"Conversation ended.\") : start(\"converse\"))}\n >\n <ChatIcon name=\"talk\" />\n </button>\n </>\n )}\n {streaming && onStop ? (\n <button type=\"button\" className=\"sf-chat-send\" aria-label=\"Stop\" title=\"Stop\" onClick={onStop}>\n <ChatIcon name=\"stop\" />\n </button>\n ) : (\n <button type=\"submit\" className=\"sf-chat-send\" aria-label=\"Send\" title=\"Send (Enter)\" disabled={disabled || empty}>\n <ChatIcon name=\"send\" />\n </button>\n )}\n </span>\n </div>\n {toggles.length > 0 && (\n <div className=\"sf-chat-options\" role=\"group\" aria-label=\"Options for this message\">\n {toggles.map((toggle) => (\n <label key={toggle.id} className=\"sf-chat-option\">\n <input type=\"checkbox\" checked={toggle.checked} disabled={disabled || toggle.disabled} onChange={(e) => toggle.onChange(e.target.checked)} />\n <span>\n {toggle.label}\n {toggle.detail && <span className=\"sf-chat-option-detail\">: {toggle.detail}</span>}\n </span>\n </label>\n ))}\n </div>\n )}\n {voice.supported && asking && (\n <div className=\"sf-chat-voice-consent\" role=\"group\" aria-label=\"Use voice?\">\n <p>\n {asking === \"dictate\" ? \"Dictate instead of typing?\" : \"Talk back and forth instead of typing?\"} {speech!.label}\n </p>\n <span className=\"sf-chat-voice-consent-actions\">\n <button\n type=\"button\"\n className=\"sf-button\"\n data-variant=\"primary\"\n // biome-ignore lint/a11y/noAutofocus: the person just pressed the microphone; the question is what they answer next.\n autoFocus\n onClick={() => {\n const mode = asking;\n setAsking(null);\n consent?.onGive();\n if (mode === \"dictate\") voice.dictate();\n else voice.converse();\n }}\n >\n Use voice\n </button>\n <button type=\"button\" className=\"sf-button\" onClick={() => setAsking(null)}>\n Not now\n </button>\n </span>\n </div>\n )}\n {voice.supported && voice.status && (\n <p className=\"sf-chat-voice\" role=\"status\" data-state={voice.state}>\n {voice.status}\n </p>\n )}\n <p className=\"sf-a2-visually-hidden\" role=\"status\">\n {said}\n </p>\n </form>\n );\n}\n\n/** The composer. Kept under its first name; everything added since is optional. */\nexport const Composer = ChatComposer;\n"]}
1
+ {"version":3,"file":"ChatComposer.js","sourceRoot":"","sources":["../src/ChatCom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S,EAAC,WAAW,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,wBAEjE,IACJ,IACH,CACP,EACA,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,MAAM,IAAI,CAClC,YAAG,SAAS,EAAC,eAAe,EAAC,IAAI,EAAC,QAAQ,gBAAa,KAAK,CAAC,KAAK,YAC/D,KAAK,CAAC,MAAM,GACX,CACL,EACD,YAAG,SAAS,EAAC,uBAAuB,EAAC,IAAI,EAAC,QAAQ,YAC/C,IAAI,GACH,IACC,CACR,CAAC;AACJ,CAAC;AAED,mFAAmF;AACnF,MAAM,CAAC,MAAM,QAAQ,GAAG,YAAY,CAAC","sourcesContent":["import { type DataRef, addDataRefs, dataRefLabel, hasDataRefs, readDataRefs, safeImageAddress, sameDataRef } from \"@surfaces-ui/components\";\nimport type { AgentInfo, ToolConnector } from \"@surfaces-ui/proto\";\nimport { type ClipboardEvent, type DragEvent, type FormEvent, type KeyboardEvent, type ReactNode, type Ref, type RefObject, useEffect, useImperativeHandle, useRef, useState } from \"react\";\nimport { DataPanel, type DataPanelProps } from \"./DataPanel.js\";\nimport { MenuButton, MenuGroup, MenuItem } from \"./Menu.js\";\nimport { ChatIcon } from \"./icons.js\";\nimport { type ChatPanel, type ChatProvider, ModelMenu, SetupMenu } from \"./selectors.js\";\nimport type { SpeechAdapter } from \"./speech.js\";\nimport type { ChatAttachment } from \"./thread.js\";\nimport type { ChatSettings } from \"./useChat.js\";\nimport { type VoiceReply, useVoice } from \"./voice.js\";\n\n/**\n * What became of one file a person attached. Exactly one of `ref`, `attachment` and `taken` says it was used; a result\n * with none of them (and no `error`) reads as failed, \"This file cannot be used as data.\"\n */\nexport interface AttachResult {\n file: File;\n /** The table or file of data it became, by name. */\n ref?: DataRef;\n /**\n * It was attached as something other than data, such as a picture: the composer shows a chip with a thumbnail (when\n * `preview` is an image address) and gives the attachment to `onSend`.\n */\n attachment?: ChatAttachment;\n /** The host took the file and handled it elsewhere: no chip and no error. */\n taken?: boolean;\n /** Why it could not be used. */\n error?: string;\n}\n\n/** What a host can do with a mounted composer, through `handleRef`. */\nexport interface ComposerHandle {\n /** Hands files in from outside the composer, as if they were dropped on it: they get \"Reading…\" chips and go through `attachFiles`. Resolves once the host has answered. */\n attach(files: File[]): Promise<void>;\n /** Puts the cursor in the box. */\n focus(): void;\n}\n\nexport interface ComposerProps {\n /** Called with the message, the data attached to it and, only when there are some, its attachments (`AttachResult.attachment`). */\n onSend(text: string, references: DataRef[], attachments?: ChatAttachment[]): void;\n /** Shown in place of Send while a reply is streaming. */\n onStop?(): void;\n streaming?: boolean;\n disabled?: boolean;\n placeholder?: string;\n /** The box's name for assistive technology. Default \"Message\". */\n label?: string;\n /**\n * Tables and columns attached to the message being written. Give it with\n * `onReferencesChange` to hold them yourself, so something beside the chat\n * (a browser's \"Add to chat\") can add to them; otherwise the composer keeps\n * them. Either way they can be dropped onto the composer.\n */\n references?: DataRef[];\n onReferencesChange?(references: DataRef[]): void;\n\n /**\n * Pictures and other files attached to the message being written that are not data. Give it with `onAttachmentsChange`\n * to hold them yourself; otherwise the composer keeps them.\n */\n attachments?: ChatAttachment[];\n onAttachmentsChange?(attachments: ChatAttachment[]): void;\n\n /** Turns files from the person's computer into data the agent can name. Without it there is no upload. Any file is offered (see `accept`); the host says which it can use. */\n attachFiles?(files: File[]): Promise<AttachResult[]>;\n /** What the file picker offers, as an `<input type=\"file\">` `accept` (\"image/*,.csv\"). It does not limit what is dropped or pasted. Default: any file. */\n accept?: string;\n /** Replaces the line under \"Upload files…\" in the + menu. Default: \"Any file; those that can be read become tables\". */\n uploadDetail?: ReactNode;\n /**\n * Widens where files can be dropped from the composer's own form to this element (a panel around the chat), given as\n * the element or a ref to it. Files and tables dropped on it are handled as if dropped on the composer, and the composer\n * is highlighted while they are over it.\n */\n dropTarget?: HTMLElement | RefObject<HTMLElement | null> | null;\n /** Gives the host `attach(files)` and `focus()`, to hand in files from anywhere (its own drop handling, a paste elsewhere). */\n handleRef?: Ref<ComposerHandle>;\n /** Browsing tables and files from the composer (\"Add data\"). Without `onManage`, it opens in a popover. */\n browse?: Omit<DataPanelProps, \"onAttach\">;\n /** Agents with their models, skills and connectors (`DescribeAgents`). Each menu shows only when there is something to choose. */\n agents?: AgentInfo[];\n settings?: ChatSettings;\n onSettingsChange?(settings: ChatSettings): void;\n /** Data connections for the Connectors menu's Data group. */\n sources?: { id: string; label: string }[];\n onAddConnection?(): void;\n onConnect?(connector: ToolConnector): void;\n /** Opens a panel with the whole list (\"View all…\", \"Manage…\", \"Add data\"). */\n onManage?(panel: ChatPanel): void;\n /** The panels `onManage` can open. Default: all of them. */\n managed?: ChatPanel[];\n /** Items a menu lists before \"View all…\". Default 5. */\n menuLimit?: number;\n /** Where models run, when the host can reach several: the Model menu groups models by provider. */\n providers?: ChatProvider[];\n /** \"Manage providers…\" at the foot of the Model menu. */\n onManageProviders?(): void;\n /** Talking instead of typing. The microphone shows only where the adapter is supported. */\n speech?: SpeechAdapter;\n /** The latest reply, for a spoken conversation to read and to know when to listen again. */\n voiceReply?: VoiceReply;\n /**\n * Ask before the microphone is first used. The microphone shows, and its\n * first press says where audio goes (`speech.label`) with \"Use voice\" and\n * \"Not now\"; nothing listens until the person agrees. The host keeps the\n * answer (`given`) so it is asked once. Without it, passing `speech` is the consent.\n */\n speechConsent?: SpeechConsent;\n /** What the message is about beyond attached data, as chips before the attached tables and files. */\n context?: ComposerContext[];\n /** Choices for the next message, as checkboxes under the box. */\n toggles?: ComposerToggle[];\n}\n\n/**\n * A choice that goes with the next message, drawn as a checkbox under the\n * box (\"Try three ways\"). The host keeps `checked`, and clears it after a send\n * when it holds for one message only.\n */\nexport interface ComposerToggle {\n id: string;\n label: string;\n /** More about it, after the label and part of its name. */\n detail?: string;\n checked: boolean;\n onChange(checked: boolean): void;\n disabled?: boolean;\n}\n\n/**\n * Something the message is about that is not a table or a file: the part of\n * a page a person selected (\"About Chart amount-by-region\"). Shown as a chip\n * beside the attached data; the host keeps it and says what it means.\n */\nexport interface ComposerContext {\n /** Keeps the chip steady across renders; defaults to the label. */\n id?: string;\n label: string;\n /** Shown after the label, smaller. */\n detail?: string;\n /** Given, the chip has a remove button that calls it (\"Whole page instead\"). */\n onClear?(): void;\n /** The remove button's name. Default \"Remove \" and the label. */\n clearLabel?: string;\n}\n\n/** Whether the person agreed to use voice, kept by the host. */\nexport interface SpeechConsent {\n given: boolean;\n onGive(): void;\n}\n\nconst attachmentKey = (one: ChatAttachment) => one.id ?? one.name;\n\ntype Pending = { key: string; name: string; error?: string };\n\n/**\n * Where the person writes. Enter sends; Shift+Enter starts a new line.\n * Everything beyond the box is optional: files from the computer (the `+`\n * menu, a drop or a paste), tables and files from a browser, the agent,\n * model, skills and connectors, and the microphone. Send is the arrow.\n */\nexport function ChatComposer(props: ComposerProps) {\n const { onSend, onStop, streaming, disabled, placeholder, references: given, onReferencesChange, attachFiles, browse, agents = [], settings = {}, onSettingsChange, onManage, speech, context = [], toggles = [] } = props;\n const [text, setText] = useState(\"\");\n const [kept, setKept] = useState<DataRef[]>([]);\n const references = given ?? kept;\n const latest = useRef(references);\n latest.current = references;\n const [keptAttachments, setKeptAttachments] = useState<ChatAttachment[]>([]);\n const attachments = props.attachments ?? keptAttachments;\n const latestAttachments = useRef(attachments);\n latestAttachments.current = attachments;\n const setAttachments = (next: ChatAttachment[]) => {\n latestAttachments.current = next;\n setKeptAttachments(next);\n props.onAttachmentsChange?.(next);\n };\n const setReferences = (next: DataRef[]) => {\n latest.current = next;\n setKept(next);\n onReferencesChange?.(next);\n };\n const [pending, setPending] = useState<Pending[]>([]);\n const [over, setOver] = useState(false);\n const [said, setSaid] = useState(\"\");\n const fileInput = useRef<HTMLInputElement>(null);\n const form = useRef<HTMLFormElement>(null);\n // A narrow composer shows its menus as icons, so the row stays one or two lines.\n const [compact, setCompact] = useState(false);\n useEffect(() => {\n const el = form.current;\n if (!el || typeof ResizeObserver === \"undefined\") return;\n const watch = new ResizeObserver(([entry]) => setCompact((entry?.contentRect.width ?? 999) < 420));\n watch.observe(el);\n return () => watch.disconnect();\n }, []);\n const textArea = useRef<HTMLTextAreaElement>(null);\n\n const send = (words: string) => {\n if (streaming || disabled || !words.trim()) return;\n const withThem = latestAttachments.current;\n if (withThem.length > 0) onSend(words, latest.current, withThem);\n else onSend(words, latest.current);\n setText(\"\");\n setReferences([]);\n if (withThem.length > 0) setAttachments([]);\n setPending((all) => all.filter((p) => !p.error));\n setSaid(\"\");\n };\n const voice = useVoice({ speech, onText: setText, onSend: send, reply: props.voiceReply });\n // A press before consent asks first, then starts what was pressed.\n const [asking, setAsking] = useState<\"dictate\" | \"converse\" | null>(null);\n const consent = props.speechConsent;\n const start = (mode: \"dictate\" | \"converse\") => {\n if (consent && !consent.given) return setAsking(mode);\n if (mode === \"dictate\") voice.dictate();\n else voice.converse();\n };\n const submit = (event?: FormEvent) => {\n event?.preventDefault();\n send(text);\n };\n const onKeyDown = (event: KeyboardEvent<HTMLTextAreaElement>) => {\n if (event.key === \"Enter\" && !event.shiftKey && !event.nativeEvent.isComposing) submit(event);\n };\n\n const attach = (refs: DataRef[]) => {\n const next = addDataRefs(latest.current, refs);\n const added = next.length - latest.current.length;\n const fresh = refs.find((ref) => !latest.current.some((have) => sameDataRef(have, ref))) ?? refs[0];\n setReferences(next);\n setSaid(added === 0 ? \"Already attached.\" : `Attached ${added === 1 && fresh ? dataRefLabel(fresh) : `${added} items`}.`);\n };\n\n const upload = async (files: File[]) => {\n if (!attachFiles || files.length === 0) return;\n const keys = files.map((f, i) => ({ key: `${Date.now()}-${i}-${f.name}`, name: f.name }));\n setPending((all) => [...all, ...keys]);\n setSaid(`Reading ${files.length === 1 ? files[0]!.name : `${files.length} files`}…`);\n let results: AttachResult[];\n try {\n results = await attachFiles(files);\n } catch (error) {\n results = files.map((file) => ({ file, error: error instanceof Error ? error.message : String(error) }));\n }\n const failed = new Map<string, string>();\n results.forEach((result, i) => {\n if (!result.ref && !result.attachment && !result.taken) failed.set(keys[i]!.key, result.error || \"This file cannot be used as data.\");\n });\n setPending((all) => all.flatMap((p) => (keys.some((k) => k.key === p.key) ? (failed.has(p.key) ? [{ ...p, error: failed.get(p.key) }] : []) : [p])));\n const refs = results.flatMap((r) => (r.ref ? [r.ref] : []));\n if (refs.length > 0) attach(refs);\n const pictures = results.flatMap((r) => (r.attachment ? [r.attachment] : []));\n if (pictures.length > 0) {\n const have = latestAttachments.current;\n const fresh = pictures.filter((one) => !have.some((other) => attachmentKey(other) === attachmentKey(one)));\n if (fresh.length > 0) setAttachments([...have, ...fresh]);\n if (refs.length === 0) setSaid(fresh.length === 0 ? \"Already attached.\" : `Attached ${fresh.length === 1 ? fresh[0]!.name : `${fresh.length} files`}.`);\n }\n if (failed.size > 0) setSaid(`${failed.size === 1 ? \"One file\" : `${failed.size} files`} could not be used.`);\n };\n // What a host's `attach(files)` and a drop outside the form call must see the latest props.\n const uploadNow = useRef(upload);\n uploadNow.current = upload;\n useImperativeHandle(props.handleRef, () => ({ attach: (files: File[]) => uploadNow.current(files), focus: () => textArea.current?.focus({ preventScroll: true }) }), []);\n\n // A drop on the form is also seen by `dropTarget` around it (and the other way round); each event is handled once.\n const seen = useRef(new WeakSet<Event>());\n const firstSight = (event: { nativeEvent?: Event } | Event) => {\n const native = \"nativeEvent\" in event && event.nativeEvent ? event.nativeEvent : (event as Event);\n if (seen.current.has(native)) return false;\n seen.current.add(native);\n return true;\n };\n type Dragged = { dataTransfer: DataTransfer | null; preventDefault(): void };\n const onDragOver = (event: Dragged) => {\n if (!event.dataTransfer) return;\n const files = attachFiles && Array.from(event.dataTransfer.types).includes(\"Files\");\n if (disabled || (!hasDataRefs(event.dataTransfer) && !files)) return;\n event.preventDefault();\n event.dataTransfer.dropEffect = \"copy\";\n setOver(true);\n };\n const onDrop = (event: Dragged) => {\n setOver(false);\n if (disabled || !event.dataTransfer) return;\n const dropped = readDataRefs(event.dataTransfer);\n if (dropped.length > 0) {\n // The names would otherwise be typed into the box as text as well.\n event.preventDefault();\n attach(dropped);\n return;\n }\n const files = Array.from(event.dataTransfer.files ?? []);\n if (attachFiles && files.length > 0) {\n event.preventDefault();\n void upload(files);\n }\n };\n const around = useRef({ onDragOver, onDrop });\n around.current = { onDragOver, onDrop };\n const outside = props.dropTarget;\n useEffect(() => {\n const element = outside && \"current\" in outside ? outside.current : outside;\n if (!element) return;\n const over = (event: Event) => firstSight(event) && around.current.onDragOver(event as globalThis.DragEvent);\n const drop = (event: Event) => firstSight(event) && around.current.onDrop(event as globalThis.DragEvent);\n const leave = (event: Event) => {\n const into = (event as globalThis.DragEvent).relatedTarget;\n if (!(into instanceof Node) || !element.contains(into)) setOver(false);\n };\n element.addEventListener(\"dragover\", over);\n element.addEventListener(\"drop\", drop);\n element.addEventListener(\"dragleave\", leave);\n return () => {\n element.removeEventListener(\"dragover\", over);\n element.removeEventListener(\"drop\", drop);\n element.removeEventListener(\"dragleave\", leave);\n };\n });\n const onPaste = (event: ClipboardEvent) => {\n const files = Array.from(event.clipboardData?.files ?? []);\n if (!attachFiles || files.length === 0) return;\n event.preventDefault();\n void upload(files);\n };\n\n // Escape stops a spoken conversation from anywhere in the composer.\n const onFormKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\" && voice.state !== \"off\") {\n event.stopPropagation();\n voice.stop(\"Stopped.\");\n }\n };\n useEffect(() => {\n if (voice.state === \"off\") textArea.current?.focus({ preventScroll: true });\n }, [voice.state]);\n\n const manages = (panel: ChatPanel) => !!onManage && (!props.managed || props.managed.includes(panel));\n const canBrowse = !!browse || manages(\"data\");\n const selectorProps = { agents, settings, onSettingsChange: onSettingsChange ?? (() => {}), limit: props.menuLimit, compact };\n const manageIf = (panel: ChatPanel) => (manages(panel) ? onManage : undefined);\n const chooses = !!onSettingsChange && (agents.length > 0 || (props.providers?.length ?? 0) > 0);\n const talking = voice.state !== \"off\" && voice.state !== \"dictating\";\n const empty = !text.trim();\n\n return (\n <form\n ref={form}\n className=\"sf-chat-composer\"\n data-compact={compact || undefined}\n data-rich={!!attachFiles || canBrowse || chooses || voice.supported || undefined}\n data-over={over || undefined}\n onSubmit={submit}\n onDragOver={(event) => firstSight(event) && onDragOver(event)}\n onDragLeave={() => setOver(false)}\n onDrop={(event) => firstSight(event) && onDrop(event)}\n onKeyDown={onFormKeyDown}\n >\n {(context.length > 0 || references.length > 0 || attachments.length > 0 || pending.length > 0) && (\n <ul className=\"sf-chat-references sf-chat-attached\" aria-label=\"Attached to this message\">\n {context.map((about) => (\n <li key={about.id ?? about.label} className=\"sf-chat-reference\" data-kind=\"context\">\n <ChatIcon name=\"about\" />\n <span>{about.label}</span>\n {about.detail && <span className=\"sf-chat-reference-note\">{about.detail}</span>}\n {about.onClear && (\n <button\n type=\"button\"\n className=\"sf-chat-reference-remove\"\n aria-label={about.clearLabel ?? `Remove ${about.label}`}\n title={about.clearLabel}\n onClick={() => {\n about.onClear?.();\n setSaid(`Removed ${about.label}.`);\n textArea.current?.focus({ preventScroll: true });\n }}\n >\n <ChatIcon name=\"close\" />\n </button>\n )}\n </li>\n ))}\n {references.map((ref) => (\n <li key={`${ref.sourceId}/${ref.kind}/${dataRefLabel(ref)}`} className=\"sf-chat-reference\" data-kind={ref.kind}>\n <ChatIcon name={ref.kind === \"file\" ? \"file\" : \"data\"} />\n <span>{dataRefLabel(ref)}</span>\n <button\n type=\"button\"\n className=\"sf-chat-reference-remove\"\n aria-label={`Remove ${dataRefLabel(ref)}`}\n onClick={() => {\n setReferences(latest.current.filter((have) => !sameDataRef(have, ref)));\n setSaid(`Removed ${dataRefLabel(ref)}.`);\n }}\n >\n <ChatIcon name=\"close\" />\n </button>\n </li>\n ))}\n {attachments.map((one) => {\n const picture = one.mediaType.startsWith(\"image/\") ? safeImageAddress(one.preview) : undefined;\n return (\n <li key={attachmentKey(one)} className=\"sf-chat-reference\" data-kind=\"attachment\" data-thumbnail={picture ? true : undefined}>\n {picture ? <img className=\"sf-chat-thumbnail\" src={picture} alt=\"\" /> : <ChatIcon name=\"file\" />}\n <span>{one.name}</span>\n <button\n type=\"button\"\n className=\"sf-chat-reference-remove\"\n aria-label={`Remove ${one.name}`}\n onClick={() => {\n setAttachments(latestAttachments.current.filter((have) => attachmentKey(have) !== attachmentKey(one)));\n setSaid(`Removed ${one.name}.`);\n textArea.current?.focus({ preventScroll: true });\n }}\n >\n <ChatIcon name=\"close\" />\n </button>\n </li>\n );\n })}\n {pending.map((p) => (\n <li key={p.key} className=\"sf-chat-reference\" data-kind=\"file\" data-state={p.error ? \"failed\" : \"reading\"}>\n <ChatIcon name=\"file\" />\n <span>{p.name}</span>\n <span className=\"sf-chat-reference-note\">{p.error ?? \"Reading…\"}</span>\n {p.error && (\n <button type=\"button\" className=\"sf-chat-reference-remove\" aria-label={`Remove ${p.name}`} onClick={() => setPending((all) => all.filter((x) => x.key !== p.key))}>\n <ChatIcon name=\"close\" />\n </button>\n )}\n </li>\n ))}\n </ul>\n )}\n <textarea\n ref={textArea}\n className=\"sf-input\"\n rows={2}\n aria-label={props.label ?? \"Message\"}\n placeholder={placeholder ?? \"Ask about your data\"}\n value={text}\n disabled={disabled}\n onChange={(e) => setText(e.target.value)}\n onKeyDown={onKeyDown}\n onPaste={onPaste}\n />\n <div className=\"sf-chat-toolbar\">\n {(attachFiles || manages(\"data\")) && (\n <MenuButton label=\"Add files or data\" icon=\"plus\" iconOnly disabled={disabled}>\n {(close) => (\n <MenuGroup label=\"Add\">\n {attachFiles && (\n <MenuItem\n detail={props.uploadDetail ?? \"Any file; those that can be read become tables\"}\n onSelect={() => {\n close();\n fileInput.current?.click();\n }}\n >\n Upload files…\n </MenuItem>\n )}\n {manages(\"data\") && (\n <MenuItem\n detail=\"Tables, columns and files from a connection\"\n onSelect={() => {\n close();\n onManage?.(\"data\");\n }}\n >\n Add tables and files…\n </MenuItem>\n )}\n </MenuGroup>\n )}\n </MenuButton>\n )}\n {attachFiles && (\n <input\n ref={fileInput}\n type=\"file\"\n multiple\n accept={props.accept}\n hidden\n tabIndex={-1}\n aria-hidden=\"true\"\n onChange={(e) => {\n const files = Array.from(e.target.files ?? []);\n e.target.value = \"\";\n void upload(files);\n }}\n />\n )}\n {canBrowse &&\n (manages(\"data\") ? (\n <button type=\"button\" className=\"sf-chat-tool\" data-icon-only={compact || undefined} aria-label={compact ? \"Add data\" : undefined} title={compact ? \"Add data\" : undefined} disabled={disabled} onClick={() => onManage?.(\"data\")}>\n <ChatIcon name=\"data\" />\n {!compact && <span className=\"sf-chat-tool-text\">Add data</span>}\n </button>\n ) : (\n <MenuButton label=\"Add data\" text=\"Add data\" icon=\"data\" iconOnly={compact} disabled={disabled} className=\"sf-chat-data-menu\">\n {() => <DataPanel {...browse} onAttach={attach} />}\n </MenuButton>\n ))}\n {chooses && (\n <div className=\"sf-chat-selectors\">\n <ModelMenu {...selectorProps} onManage={manageIf(\"setup\")} providers={props.providers} onManageProviders={props.onManageProviders} />\n <SetupMenu {...selectorProps} onManage={manageIf(\"setup\")} sources={props.sources} onAddConnection={props.onAddConnection} onConnect={props.onConnect} />\n </div>\n )}\n <span className=\"sf-chat-toolbar-end\">\n {voice.supported && (\n <>\n <button\n type=\"button\"\n className=\"sf-chat-tool\"\n data-icon-only\n aria-pressed={voice.state === \"dictating\"}\n aria-label={voice.state === \"dictating\" ? \"Stop dictating\" : \"Dictate\"}\n title={voice.state === \"dictating\" ? \"Stop dictating\" : `Dictate. ${speech!.label}`}\n disabled={disabled || talking}\n onClick={() => (voice.state === \"dictating\" ? voice.stop() : start(\"dictate\"))}\n >\n <ChatIcon name=\"mic\" />\n </button>\n <button\n type=\"button\"\n className=\"sf-chat-tool\"\n data-icon-only\n data-live={talking || undefined}\n aria-pressed={talking}\n aria-label={talking ? \"End conversation\" : \"Talk\"}\n title={talking ? \"End conversation (Escape)\" : `Talk back and forth. ${speech!.label}`}\n disabled={disabled}\n onClick={() => (talking ? voice.stop(\"Conversation ended.\") : start(\"converse\"))}\n >\n <ChatIcon name=\"talk\" />\n </button>\n </>\n )}\n {streaming && onStop ? (\n <button type=\"button\" className=\"sf-chat-send\" aria-label=\"Stop\" title=\"Stop\" onClick={onStop}>\n <ChatIcon name=\"stop\" />\n </button>\n ) : (\n <button type=\"submit\" className=\"sf-chat-send\" aria-label=\"Send\" title=\"Send (Enter)\" disabled={disabled || empty}>\n <ChatIcon name=\"send\" />\n </button>\n )}\n </span>\n </div>\n {toggles.length > 0 && (\n <div className=\"sf-chat-options\" role=\"group\" aria-label=\"Options for this message\">\n {toggles.map((toggle) => (\n <label key={toggle.id} className=\"sf-chat-option\">\n <input type=\"checkbox\" checked={toggle.checked} disabled={disabled || toggle.disabled} onChange={(e) => toggle.onChange(e.target.checked)} />\n <span>\n {toggle.label}\n {toggle.detail && <span className=\"sf-chat-option-detail\">: {toggle.detail}</span>}\n </span>\n </label>\n ))}\n </div>\n )}\n {voice.supported && asking && (\n <div className=\"sf-chat-voice-consent\" role=\"group\" aria-label=\"Use voice?\">\n <p>\n {asking === \"dictate\" ? \"Dictate instead of typing?\" : \"Talk back and forth instead of typing?\"} {speech!.label}\n </p>\n <span className=\"sf-chat-voice-consent-actions\">\n <button\n type=\"button\"\n className=\"sf-button\"\n data-variant=\"primary\"\n // biome-ignore lint/a11y/noAutofocus: the person just pressed the microphone; the question is what they answer next.\n autoFocus\n onClick={() => {\n const mode = asking;\n setAsking(null);\n consent?.onGive();\n if (mode === \"dictate\") voice.dictate();\n else voice.converse();\n }}\n >\n Use voice\n </button>\n <button type=\"button\" className=\"sf-button\" onClick={() => setAsking(null)}>\n Not now\n </button>\n </span>\n </div>\n )}\n {voice.supported && voice.status && (\n <p className=\"sf-chat-voice\" role=\"status\" data-state={voice.state}>\n {voice.status}\n </p>\n )}\n <p className=\"sf-a2-visually-hidden\" role=\"status\">\n {said}\n </p>\n </form>\n );\n}\n\n/** The composer. Kept under its first name; everything added since is optional. */\nexport const Composer = ChatComposer;\n"]}
@@ -43,7 +43,7 @@ export const analyticsChatDoc = describeAppComponent()({
43
43
  { prop: "browse", label: "Data panel", description: "Tables and files to attach to a message, over the source in `settings`.", on: true },
44
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
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." },
46
+ { prop: "attachFiles", label: "Attach files", description: "The + menu, drop and paste. The host decides what a file becomes: data (`ref`), a picture shown as a chip with a thumbnail (`attachment`), or something it handled itself (`taken`); the agent is told a table or a file by name, never its contents. `accept`, `uploadDetail`, `dropTarget` and `composerRef` shape the picker, its menu text and where files can be dropped from." },
47
47
  { prop: "speech", label: "Voice", description: "Dictation and a spoken conversation, asked for once with `speechConsent` (Chrome sends audio to Google)." },
48
48
  ],
49
49
  callbacks: [
@@ -1 +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,QAA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EAAE,SAAS,EAAE,WAAW,EAAE,qCAAqC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC3I;IACD,KAAK,EAAE;QACL,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,iFAAiF,EAAE,QAAQ,EAAE,IAAI,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"]}
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,EAA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CAAC;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,oBAAoB,EAAmB,CAAC;IACnE,IAAI,EAAE,YAAY;IAClB,IAAI,EAAE,IAAI;IACV,WAAW,EACT,kcAAkc;IACpc,KAAK,EAAE;QACL,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,qCAAqC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC3I;IACD,KAAK,EAAE;QACL,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,iFAAiF,EAAE,QAAQ,EAAE,IAAI,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: data (`ref`), a picture shown as a chip with a thumbnail (`attachment`), or something it handled itself (`taken`); the agent is told a table or a file by name, never its contents. `accept`, `uploadDetail`, `dropTarget` and `composerRef` shape the picker, its menu text and where files can be dropped from.\" },\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"]}
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export * from "./Chat.js";
4
4
  export * from "./PageStudio.js";
5
5
  export * from "./Approval.js";
6
6
  export * from "./conversation.js";
7
- export { ChatComposer, Composer, type ComposerProps, type AttachResult, type SpeechConsent, type ComposerContext, type ComposerToggle } from "./ChatComposer.js";
7
+ export { ChatComposer, Composer, type ComposerProps, type AttachResult, type ComposerHandle, type SpeechConsent, type ComposerContext, type ComposerToggle } from "./ChatComposer.js";
8
8
  export * from "./DataPanel.js";
9
9
  export * from "./Menu.js";
10
10
  export * from "./icons.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAwG,MAAM,mBAAmB,CAAC;AACjK,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC","sourcesContent":["export * from \"./thread.js\";\nexport * from \"./useChat.js\";\nexport * from \"./Chat.js\";\nexport * from \"./PageStudio.js\";\nexport * from \"./Approval.js\";\nexport * from \"./conversation.js\";\nexport { ChatComposer, Composer, type ComposerProps, type AttachResult, type SpeechConsent, type ComposerContext, type ComposerToggle } from \"./ChatComposer.js\";\nexport * from \"./DataPanel.js\";\nexport * from \"./Menu.js\";\nexport * from \"./icons.js\";\nexport * from \"./selectors.js\";\nexport * from \"./speech.js\";\nexport * from \"./voice.js\";\nexport * from \"./sessions.js\";\nexport * from \"./SessionList.js\";\nexport * from \"./ChatPanels.js\";\nexport * from \"./AnalyticsChat.js\";\nexport * from \"./appComponents.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAA6H,MAAM,mBAAmB,CAAC;AACtL,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC","sourcesContent":["export * from \"./thread.js\";\nexport * from \"./useChat.js\";\nexport * from \"./Chat.js\";\nexport * from \"./PageStudio.js\";\nexport * from \"./Approval.js\";\nexport * from \"./conversation.js\";\nexport { ChatComposer, Composer, type ComposerProps, type AttachResult, type ComposerHandle, type SpeechConsent, type ComposerContext, type ComposerToggle } from \"./ChatComposer.js\";\nexport * from \"./DataPanel.js\";\nexport * from \"./Menu.js\";\nexport * from \"./icons.js\";\nexport * from \"./selectors.js\";\nexport * from \"./speech.js\";\nexport * from \"./voice.js\";\nexport * from \"./sessions.js\";\nexport * from \"./SessionList.js\";\nexport * from \"./ChatPanels.js\";\nexport * from \"./AnalyticsChat.js\";\nexport * from \"./appComponents.js\";\n"]}
package/dist/thread.d.ts CHANGED
@@ -97,6 +97,27 @@ export interface ChatActions {
97
97
  /** What became of it ("Applied.", "Discarded."). Replaces the buttons. */
98
98
  outcome?: string;
99
99
  }
100
+ /**
101
+ * Something a person attached to a message that is not a table or a file of data: a picture, usually. The host
102
+ * keeps the bytes; the thread keeps this description, which is what the message list shows.
103
+ */
104
+ export interface ChatAttachment {
105
+ /** Tells it apart, and lets the host find what it kept. Default: the name. */
106
+ id?: string;
107
+ /** The file's name, shown under or beside the thumbnail. */
108
+ name: string;
109
+ /** Its media type, such as "image/png". A thumbnail is drawn only for an `image/*` type. */
110
+ mediaType: string;
111
+ /** Its size in bytes, when known. */
112
+ size?: number;
113
+ /**
114
+ * An address a small picture of it can be drawn from (a `blob:` URL the host made, a raster `data:image/` URL, an
115
+ * http(s) or same-origin address). It comes from the host, never from a model: nothing an agent wrote is put here, and
116
+ * an address that is not one of those kinds is ignored. A blob URL does not outlive the page, so a thread kept
117
+ * across reloads shows the name alone until the host supplies a preview again.
118
+ */
119
+ preview?: string;
120
+ }
100
121
  /** One piece of a reply, in the order it arrived. */
101
122
  export type ChatPart = {
102
123
  kind: "text";
@@ -106,6 +127,11 @@ export type ChatPart = {
106
127
  | {
107
128
  kind: "references";
108
129
  references: DataRef[];
130
+ }
131
+ /** Pictures and other files a person attached to their message that are not data (`ChatAttachment`). */
132
+ | {
133
+ kind: "attachments";
134
+ attachments: ChatAttachment[];
109
135
  } | {
110
136
  kind: "steps";
111
137
  steps: ChatStep[];
@@ -157,6 +183,7 @@ export type ChatAction = {
157
183
  type: "user";
158
184
  text: string;
159
185
  references?: DataRef[];
186
+ attachments?: ChatAttachment[];
160
187
  }
161
188
  /** A turn has started; the reply is added to the latest assistant message when `resume` is set. */
162
189
  | {
package/dist/thread.js CHANGED
@@ -73,7 +73,11 @@ export function reduceThread(thread, action, catalog) {
73
73
  suggestions: [],
74
74
  messages: [
75
75
  ...thread.messages,
76
- { id: nextId, role: "user", parts: [{ kind: "text", text: action.text }, ...(action.references?.length ? [{ kind: "references", references: action.references }] : [])], generatedBy: "", streaming: false },
76
+ { id: nextId, role: "user", parts: [
77
+ { kind: "text", text: action.text },
78
+ ...(action.references?.length ? [{ kind: "references", references: action.references }] : []),
79
+ ...(action.attachments?.length ? [{ kind: "attachments", attachments: action.attachments }] : []),
80
+ ], generatedBy: "", streaming: false },
77
81
  ],
78
82
  };
79
83
  case "begin": {
@@ -183,7 +187,7 @@ export function reduceThread(thread, action, catalog) {
183
187
  }
184
188
  }
185
189
  }
186
- const PART_KINDS = new Set(["text", "references", "steps", "surface", "approval", "actions", "error"]);
190
+ const PART_KINDS = new Set(["text", "references", "attachments", "steps", "surface", "approval", "actions", "error"]);
187
191
  const isRecord = (value) => !!value && typeof value === "object" && !Array.isArray(value);
188
192
  /**
189
193
  * Checks a thread loaded from storage before it is used, since anyone with