@surfaces-ui/chat 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AnalyticsChat.d.ts +13 -1
- package/dist/AnalyticsChat.js +1 -1
- package/dist/AnalyticsChat.js.map +1 -1
- package/dist/Chat.d.ts +19 -1
- package/dist/Chat.js +14 -4
- package/dist/Chat.js.map +1 -1
- package/dist/ChatComposer.d.ts +42 -4
- package/dist/ChatComposer.js +78 -8
- package/dist/ChatComposer.js.map +1 -1
- package/dist/appComponents.js +1 -1
- package/dist/appComponents.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/thread.d.ts +27 -0
- package/dist/thread.js +6 -2
- package/dist/thread.js.map +1 -1
- package/dist/useChat.d.ts +6 -2
- package/dist/useChat.js +2 -2
- package/dist/useChat.js.map +1 -1
- package/package.json +8 -8
package/dist/AnalyticsChat.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ import { type FullLayout, type WorkspaceLayout } from "@surfaces-ui/components";
|
|
|
3
3
|
import type { AgentInfo, ToolConnector } from "@surfaces-ui/proto";
|
|
4
4
|
import { type Catalog } from "@surfaces-ui/spec";
|
|
5
5
|
import { type ComponentRenderer, type SurfaceNote } from "@surfaces-ui/spec/react";
|
|
6
|
-
import { type
|
|
6
|
+
import { type ReactNode } from "react";
|
|
7
|
+
import { type MessageListProps } from "./Chat.js";
|
|
8
|
+
import { type AttachResult, type ComposerProps, type SpeechConsent } from "./ChatComposer.js";
|
|
7
9
|
import { type DataPanelProps } from "./DataPanel.js";
|
|
8
10
|
import { type SessionListState } from "./SessionList.js";
|
|
9
11
|
import type { ChatProvider } from "./selectors.js";
|
|
@@ -32,6 +34,16 @@ export interface AnalyticsChatProps {
|
|
|
32
34
|
sessions?: ChatSessions;
|
|
33
35
|
/** Files from the person's computer, turned into data by the host. */
|
|
34
36
|
attachFiles?(files: File[]): Promise<AttachResult[]>;
|
|
37
|
+
/** What the file picker offers; see `ComposerProps.accept`. */
|
|
38
|
+
accept?: string;
|
|
39
|
+
/** Replaces the line under "Upload files…"; see `ComposerProps.uploadDetail`. */
|
|
40
|
+
uploadDetail?: ReactNode;
|
|
41
|
+
/** Widens where files can be dropped beyond the composer; see `ComposerProps.dropTarget`. */
|
|
42
|
+
dropTarget?: ComposerProps["dropTarget"];
|
|
43
|
+
/** Hands files in from outside the composer; see `ComposerProps.handleRef`. */
|
|
44
|
+
composerRef?: ComposerProps["handleRef"];
|
|
45
|
+
/** How an image an agent named is drawn in a reply; see `MessageListProps.resolveImage`. */
|
|
46
|
+
resolveImage?: MessageListProps["resolveImage"];
|
|
35
47
|
/** A Data panel of tables and files to attach. `sourceId` defaults to the settings' source. */
|
|
36
48
|
browse?: Omit<DataPanelProps, "onAttach">;
|
|
37
49
|
/** Agents with their models, skills and connectors (`DescribeAgents`). */
|
package/dist/AnalyticsChat.js
CHANGED
|
@@ -163,6 +163,6 @@ function Conversation(props) {
|
|
|
163
163
|
}, [thread, sessions, settings, onSaved]);
|
|
164
164
|
const suggestions = thread.messages.length === 0 ? (props.starters ?? []) : thread.status === "idle" ? thread.suggestions : [];
|
|
165
165
|
const onContext = props.onContext;
|
|
166
|
-
return (_jsxs("section", { className: "sf-chat sf-analytics-conversation", "aria-label": "Conversation", children: [_jsx(MessageList, { thread: thread, catalog: catalog, renderers: renderers, onAction: chat.act, onAnswer: chat.answer, onReport: chat.report, onProblem: chat.problem, onContext: onContext, empty: props.empty }), _jsx(Suggestions, { items: suggestions, onPick: (text) => chat.send(text, props.references) }), _jsx(ChatComposer, { onSend: (text, refs) => chat.send(text, refs), onStop: chat.stop, streaming: thread.status === "streaming", placeholder: thread.status === "waiting" ? "Answer above, or type to say something else" : props.placeholder, references: props.references, onReferencesChange: props.onReferencesChange, attachFiles: props.attachFiles, browse: props.panels.includes("data") ? undefined : props.browse, agents: props.agents, settings: settings, onSettingsChange: props.onSettingsChange, sources: props.sources, onAddConnection: props.onAddConnection, onConnect: props.onConnect, onManage: props.onManage, managed: props.panels, menuLimit: props.menuLimit, providers: props.providers, onManageProviders: props.onManageProviders, speech: props.speech, speechConsent: props.speechConsent, voiceReply: voiceReplyOf(thread) }), _jsx(UsageGauge, { usage: thread.usage })] }));
|
|
166
|
+
return (_jsxs("section", { className: "sf-chat sf-analytics-conversation", "aria-label": "Conversation", children: [_jsx(MessageList, { thread: thread, catalog: catalog, renderers: renderers, onAction: chat.act, onAnswer: chat.answer, onReport: chat.report, onProblem: chat.problem, onContext: onContext, empty: props.empty, resolveImage: props.resolveImage }), _jsx(Suggestions, { items: suggestions, onPick: (text) => chat.send(text, props.references) }), _jsx(ChatComposer, { onSend: (text, refs, attachments) => chat.send(text, refs, attachments), onStop: chat.stop, streaming: thread.status === "streaming", placeholder: thread.status === "waiting" ? "Answer above, or type to say something else" : props.placeholder, references: props.references, onReferencesChange: props.onReferencesChange, attachFiles: props.attachFiles, accept: props.accept, uploadDetail: props.uploadDetail, dropTarget: props.dropTarget, handleRef: props.composerRef, browse: props.panels.includes("data") ? undefined : props.browse, agents: props.agents, settings: settings, onSettingsChange: props.onSettingsChange, sources: props.sources, onAddConnection: props.onAddConnection, onConnect: props.onConnect, onManage: props.onManage, managed: props.panels, menuLimit: props.menuLimit, providers: props.providers, onManageProviders: props.onManageProviders, speech: props.speech, speechConsent: props.speechConsent, voiceReply: voiceReplyOf(thread) }), _jsx(UsageGauge, { usage: thread.usage })] }));
|
|
167
167
|
}
|
|
168
168
|
//# sourceMappingURL=AnalyticsChat.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnalyticsChat.js","sourceRoot":"","sources":["../src/AnalyticsChat.tsx"],"names":[],"mappings":";AACA,OAAO,EAAiC,SAAS,EAA6C,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,oBAAoB,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAErN,OAAO,EAAgB,gBAAgB,EAAE,MAA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AC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAC7C,MAAM,EAAE,IAAI,CAAC,IAAI,EACjB,SAAS,EAAE,MAAM,CAAC,MAAM,KAAK,WAAW,EACxC,WAAW,EAAE,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,6CAA6C,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,EAC5G,UAAU,EAAE,KAAK,CAAC,UAAU,EAC5B,kBAAkB,EAAE,KAAK,CAAC,kBAAkB,EAC5C,WAAW,EAAE,KAAK,CAAC,WAAW,EAC9B,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAChE,MAAM,EAAE,KAAK,CAAC,MAAM,EACpB,QAAQ,EAAE,QAAQ,EAClB,gBAAgB,EAAE,KAAK,CAAC,gBAAgB,EACxC,OAAO,EAAE,KAAK,CAAC,OAAO,EACtB,eAAe,EAAE,KAAK,CAAC,eAAe,EACtC,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,QAAQ,EAAE,KAAK,CAAC,QAAQ,EACxB,OAAO,EAAE,KAAK,CAAC,MAAM,EACrB,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,iBAAiB,EAAE,KAAK,CAAC,iBAAiB,EAC1C,MAAM,EAAE,KAAK,CAAC,MAAM,EACpB,aAAa,EAAE,KAAK,CAAC,aAAa,EAClC,UAAU,EAAE,YAAY,CAAC,MAAM,CAAC,GAChC,EACF,KAAC,UAAU,IAAC,KAAK,EAAE,MAAM,CAAC,KAAK,GAAI,IAC3B,CACX,CAAC;AACJ,CAAC","sourcesContent":["import type { AgentBackend } from \"@surfaces-ui/agent\";\nimport { type DataRef, type FullLayout, Workspace, type WorkspaceLayout, type WorkspacePanel, addDataRefs, expandPanel, movePanel, movePanelToNewColumn, normalizeLayout, showPanel } from \"@surfaces-ui/components\";\nimport type { AgentInfo, ToolConnector } from \"@surfaces-ui/proto\";\nimport { type Catalog, analyticsCatalog } from \"@surfaces-ui/spec\";\nimport { type ComponentRenderer, type SurfaceNote, lazyAnalyticsRenderers } from \"@surfaces-ui/spec/react\";\nimport { type ReactNode, useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { MessageList, Suggestions, UsageGauge } from \"./Chat.js\";\nimport { type AttachResult, ChatComposer, type SpeechConsent } from \"./ChatComposer.js\";\nimport { AgentSetupPanel, choosesModel } from \"./ChatPanels.js\";\nimport { DataPanel, type DataPanelProps } from \"./DataPanel.js\";\nimport { SessionList, type SessionListState } from \"./SessionList.js\";\nimport { conversationThread } from \"./conversation.js\";\nimport { ChatIcon } from \"./icons.js\";\nimport type { ChatPanel, ChatProvider } from \"./selectors.js\";\nimport type { ChatSessionSummary, ChatSessions } from \"./sessions.js\";\nimport type { SpeechAdapter } from \"./speech.js\";\nimport type { ChatActor, ChatThread } from \"./thread.js\";\nimport { type ChatSettings, useChat } from \"./useChat.js\";\nimport type { VoiceReply } from \"./voice.js\";\n\nexport interface AnalyticsChatProps {\n agent: AgentBackend;\n catalog?: Catalog;\n renderers?: Record<string, ComponentRenderer>;\n user?: ChatActor;\n starters?: string[];\n placeholder?: string;\n /** Shown before anything is said. */\n empty?: string;\n /** What a person does in a drawn component, as it happens (it also goes with the next turn). */\n onContext?(note: SurfaceNote & { surfaceId: string; componentId: string }): void;\n /** Height of the whole chat. Default 640. */\n height?: number | string;\n\n /** Saved conversations: a Sessions panel to search, filter, sort and group them, and every conversation saved as it goes. */\n sessions?: ChatSessions;\n /** Files from the person's computer, turned into data by the host. */\n attachFiles?(files: File[]): Promise<AttachResult[]>;\n /** A Data panel of tables and files to attach. `sourceId` defaults to the settings' source. */\n browse?: Omit<DataPanelProps, \"onAttach\">;\n /** Agents with their models, skills and connectors (`DescribeAgents`). */\n agents?: AgentInfo[];\n settings?: ChatSettings;\n defaultSettings?: ChatSettings;\n onSettingsChange?(settings: ChatSettings): void;\n /** Data connections, offered in the Connectors menu and panel. */\n sources?: { id: string; label: string; detail?: string }[];\n onAddConnection?(): void;\n onConnect?(connector: ToolConnector): void;\n speech?: SpeechAdapter;\n /** Where models run, when the host can reach several; see `ChatProvider`. */\n providers?: ChatProvider[];\n onManageProviders?(): void;\n /** Ask before the microphone is first used; see `ChatComposer`. */\n speechConsent?: SpeechConsent;\n /** Items a composer menu shows before \"View all…\". Default 5. */\n menuLimit?: number;\n /** Where the panels are. Plain JSON, so a host can keep it. */\n layout?: WorkspaceLayout;\n onLayoutChange?(layout: FullLayout): void;\n /** Where the session list's search, filters, sort and grouping are. */\n sessionList?: SessionListState;\n onSessionListChange?(state: SessionListState): void;\n className?: string;\n}\n\nconst PANEL_TITLES: Record<ChatPanel, { title: string; shortTitle?: string; icon: ReactNode }> = {\n sessions: { title: \"Conversations\", icon: <ChatIcon name=\"sessions\" /> },\n data: { title: \"Data\", icon: <ChatIcon name=\"data\" /> },\n setup: { title: \"Agent setup\", shortTitle: \"Setup\", icon: <ChatIcon name=\"agent\" /> },\n};\n\n/**\n * Shows a panel beside the conversation: in the column the other panels\n * use, or in a new one to the right, so the thread keeps its height. A\n * panel a person has put somewhere else stays there.\n */\nexport function placeChatPanel(layout: WorkspaceLayout, panel: string, ids: string[]): FullLayout {\n const before = normalizeLayout(layout, ids);\n const wasHidden = before.hidden.includes(panel);\n let next = showPanel(before, panel);\n const column = (id: string) => next.columns.findIndex((c) => c.includes(id));\n if (wasHidden && column(panel) === column(\"chat\")) {\n const side = next.columns.findIndex((c) => !c.includes(\"chat\"));\n if (side >= 0) next = movePanel(next, panel, side, 0);\n else {\n next = movePanelToNewColumn(next, panel, next.columns.length);\n const chat = column(\"chat\");\n next = normalizeLayout({ ...next, columnWidths: next.columns.map((_, i) => (i === chat ? 0.64 : 0.36 / (next.columns.length - 1))) }, ids);\n }\n }\n return expandPanel(next, panel);\n}\n\n/** The latest reply as the voice loop needs it. */\nexport function voiceReplyOf(thread: ChatThread): VoiceReply | undefined {\n const last = [...thread.messages].reverse().find((m) => m.role === \"assistant\");\n if (!last) return undefined;\n const text = last.parts.flatMap((p) => (p.kind === \"text\" ? [p.text] : [])).join(\"\\n\\n\");\n return { id: String(last.id), text, status: thread.status === \"waiting\" ? \"waiting\" : last.streaming || thread.status === \"streaming\" ? \"streaming\" : \"idle\" };\n}\n\n/**\n * A chat for people who work with data. The conversation is always there;\n * every other part comes only when its prop is given: saved conversations,\n * files and tables to attach, the agent, model, skills and connectors, and\n * the microphone. Short lists are menus in the composer; each ends in \"View\n * all…\" or \"Manage…\", which opens its panel. Panels sit in a workspace with\n * a rail of icons on the right, and a person arranges them.\n */\nexport function AnalyticsChat(props: AnalyticsChatProps) {\n const { sessions, agents = [], browse } = props;\n const [keptSettings, setKeptSettings] = useState<ChatSettings>(props.defaultSettings ?? {});\n const settings = props.settings ?? keptSettings;\n const setSettings = useCallback(\n (next: ChatSettings) => {\n setKeptSettings(next);\n props.onSettingsChange?.(next);\n },\n [props.onSettingsChange],\n );\n const [references, setReferences] = useState<DataRef[]>([]);\n\n // Which conversation is open. A new key starts a fresh thread.\n const [open, setOpen] = useState<{ key: number; id?: string; thread?: ChatThread }>({ key: 0 });\n const [list, setList] = useState<ChatSessionSummary[]>([]);\n const [listError, setListError] = useState(\"\");\n const refresh = useCallback(async () => {\n if (!sessions) return;\n try {\n setList(await sessions.list());\n setListError(\"\");\n } catch (error) {\n setListError(error instanceof Error ? error.message : String(error));\n }\n }, [sessions]);\n useEffect(() => {\n void refresh();\n }, [refresh]);\n const run = (work: Promise<unknown>) => void work.then(refresh, (error) => setListError(error instanceof Error ? error.message : String(error)));\n const openSession = (id: string) =>\n run(\n sessions!.load(id).then((document) => {\n setOpen((o) => ({ key: o.key + 1, id, thread: conversationThread(document) }));\n setReferences([]);\n }),\n );\n const newSession = () => {\n setOpen((o) => ({ key: o.key + 1 }));\n setReferences([]);\n };\n\n const panelIds = useMemo(\n () => ([\"sessions\", \"data\", \"setup\"] as ChatPanel[]).filter((p) => (p === \"sessions\" ? !!sessions : p === \"data\" ? !!browse : choosesModel(agents, props.providers) || agents.length > 1 || agents.some((a) => a.skills.length > 0 || a.connectors.length > 0) || !!props.sources?.length || !!props.onAddConnection)),\n [sessions, browse, agents, props.providers, props.sources, props.onAddConnection],\n );\n const [keptLayout, setKeptLayout] = useState<WorkspaceLayout>(() => ({ columns: [[\"chat\"]], hidden: panelIds }));\n // A panel the layout has never placed (one that appears when an agent starts offering skills) starts hidden, on the rail.\n const given = props.layout ?? keptLayout;\n const placed = new Set([...given.columns.flat(), ...(given.hidden ?? [])]);\n const layout: WorkspaceLayout = { ...given, hidden: [...(given.hidden ?? []), ...panelIds.filter((id) => !placed.has(id))] };\n const latestLayout = useRef(layout);\n latestLayout.current = layout;\n const setLayout = (given: FullLayout) => {\n // A panel shown from the rail goes beside the conversation too, not under it.\n const before = normalizeLayout(latestLayout.current, [\"chat\", ...panelIds]);\n let next = given;\n for (const id of panelIds) if (before.hidden.includes(id) && !given.hidden.includes(id)) next = placeChatPanel({ ...next, columns: next.columns.map((c) => c.filter((p) => p !== id)), hidden: [...next.hidden, id] }, id, [\"chat\", ...panelIds]);\n latestLayout.current = next;\n setKeptLayout(next);\n props.onLayoutChange?.(next);\n };\n const manage = (panel: ChatPanel) => {\n if (!panelIds.includes(panel)) return;\n setLayout(placeChatPanel(latestLayout.current, panel, [\"chat\", ...panelIds]));\n // Focus the panel once it is drawn, so a keyboard user lands in it.\n requestAnimationFrame(() => document.querySelector<HTMLElement>(`[data-chat-panel=\"${panel}\"] input, [data-chat-panel=\"${panel}\"] button`)?.focus());\n };\n\n const sourceId = settings.sourceId ?? browse?.sourceId;\n const attach = (refs: DataRef[]) => setReferences((have) => addDataRefs(have, refs));\n const content: Record<ChatPanel, () => ReactNode> = {\n sessions: () => (\n <div data-chat-panel=\"sessions\">\n {listError && (\n <p className=\"sf-notice\" role=\"alert\">\n {listError}\n </p>\n )}\n <SessionList\n label=\"Conversation list\"\n sessions={list}\n current={open.id}\n value={props.sessionList}\n onChange={props.onSessionListChange}\n onOpen={openSession}\n onNew={newSession}\n onRename={(id, title) => run(sessions!.rename(id, title))}\n onPin={(id, pinned) => run(sessions!.pin(id, pinned))}\n onRemove={(id) => {\n if (id === open.id) newSession();\n run(sessions!.remove(id));\n }}\n agentName={(id) => agents.find((a) => a.id === id)?.name ?? id}\n height={420}\n />\n </div>\n ),\n data: () => (\n <div data-chat-panel=\"data\">\n <DataPanel {...browse} sourceId={sourceId} sourceLabel={props.sources?.find((s) => s.id === sourceId)?.label ?? browse?.sourceLabel} onAttach={attach} />\n </div>\n ),\n setup: () => (\n <div data-chat-panel=\"setup\">\n <AgentSetupPanel agents={agents} settings={settings} onSettingsChange={setSettings} providers={props.providers} onManageProviders={props.onManageProviders} sources={props.sources} onAddConnection={props.onAddConnection} onConnect={props.onConnect} />\n </div>\n ),\n };\n\n const conversation = (\n <Conversation\n key={open.key}\n {...props}\n sessionId={open.id}\n initial={open.thread}\n settings={settings}\n onSettingsChange={setSettings}\n references={references}\n onReferencesChange={setReferences}\n onManage={panelIds.length > 0 ? manage : undefined}\n panels={panelIds}\n onSaved={(id) => {\n setOpen((o) => (o.id === id ? o : { ...o, id }));\n void refresh();\n }}\n />\n );\n\n if (panelIds.length === 0)\n return (\n <section className={[\"sf-analytics-chat\", props.className].filter(Boolean).join(\" \")} style={{ height: props.height ?? 640 }} aria-label=\"Chat\">\n {conversation}\n </section>\n );\n const panels: WorkspacePanel[] = [{ id: \"chat\", title: \"Chat\", icon: <ChatIcon name=\"chat\" />, fill: true, content: conversation }, ...panelIds.map((id) => ({ id, ...PANEL_TITLES[id], content: content[id]() }))];\n return (\n <div className={[\"sf-analytics-chat\", props.className].filter(Boolean).join(\" \")}>\n <Workspace label=\"Chat panels\" panels={panels} layout={layout} onLayoutChange={setLayout} rail=\"right\" height={props.height ?? 640} />\n </div>\n );\n}\n\ninterface ConversationProps extends AnalyticsChatProps {\n sessionId?: string;\n initial?: ChatThread;\n settings: ChatSettings;\n onSettingsChange(settings: ChatSettings): void;\n references: DataRef[];\n onReferencesChange(references: DataRef[]): void;\n onManage?(panel: ChatPanel): void;\n panels: ChatPanel[];\n onSaved(id: string): void;\n}\n\n/** One conversation: the thread, the suggestions and the composer. Saved whenever a reply finishes. */\nfunction Conversation(props: ConversationProps) {\n const catalog = props.catalog ?? analyticsCatalog;\n const renderers = props.renderers ?? lazyAnalyticsRenderers;\n const chat = useChat(props.agent, { catalog, user: props.user, initial: props.initial, settings: props.settings });\n const { thread } = chat;\n const { sessions, onSaved, settings } = props;\n\n // Save once a turn is over, and only when something new was said.\n const id = useRef(props.sessionId);\n const saved = useRef(props.initial?.messages.length ?? 0);\n useEffect(() => {\n if (!sessions || thread.status === \"streaming\" || thread.messages.length === 0 || thread.messages.length === saved.current) return;\n saved.current = thread.messages.length;\n void sessions\n .save({ ...(id.current ? { id: id.current } : {}), thread, ...(settings.agentId ? { agentId: settings.agentId } : {}), ...(settings.model ? { model: settings.model } : {}), ...(settings.sourceId ? { sources: [settings.sourceId] } : {}) })\n .then((summary) => {\n id.current = summary.id;\n onSaved(summary.id);\n })\n .catch(() => {\n // Let the next turn try again.\n saved.current = 0;\n });\n }, [thread, sessions, settings, onSaved]);\n\n const suggestions = thread.messages.length === 0 ? (props.starters ?? []) : thread.status === \"idle\" ? thread.suggestions : [];\n const onContext = props.onContext;\n return (\n <section className=\"sf-chat sf-analytics-conversation\" aria-label=\"Conversation\">\n <MessageList thread={thread} catalog={catalog} renderers={renderers} onAction={chat.act} onAnswer={chat.answer} onReport={chat.report} onProblem={chat.problem} onContext={onContext} empty={props.empty} />\n <Suggestions items={suggestions} onPick={(text) => chat.send(text, props.references)} />\n <ChatComposer\n onSend={(text, refs) => chat.send(text, refs)}\n onStop={chat.stop}\n streaming={thread.status === \"streaming\"}\n placeholder={thread.status === \"waiting\" ? \"Answer above, or type to say something else\" : props.placeholder}\n references={props.references}\n onReferencesChange={props.onReferencesChange}\n attachFiles={props.attachFiles}\n browse={props.panels.includes(\"data\") ? undefined : props.browse}\n agents={props.agents}\n settings={settings}\n onSettingsChange={props.onSettingsChange}\n sources={props.sources}\n onAddConnection={props.onAddConnection}\n onConnect={props.onConnect}\n onManage={props.onManage}\n managed={props.panels}\n menuLimit={props.menuLimit}\n providers={props.providers}\n onManageProviders={props.onManageProviders}\n speech={props.speech}\n speechConsent={props.speechConsent}\n voiceReply={voiceReplyOf(thread)}\n />\n <UsageGauge usage={thread.usage} />\n </section>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AnalyticsChat.js","sourceRoot":"","sources":["../src/AnalyticsChat.tsx"],"names":[],"mappings":";AACA,OAAO,EAAiC,SAAS,EAA6C,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,oBAAoB,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAErN,OAAO,EAAgB,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAA4C,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAC3G,OAAO,EAAkB,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC1F,OAAO,EAAE,WAAW,EAAyB,WAAW,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACxF,OAAO,EAAqB,YAAY,EAA0C,MAAM,mBAAmB,CAAC;AAC5G,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,SAAS,EAAuB,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAyB,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAKtC,OAAO,EAAqB,OAAO,EAAE,MAAM,cAAc,CAAC;AA2D1D,MAAM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AM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAChE,MAAM,EAAE,KAAK,CAAC,MAAM,EACpB,QAAQ,EAAE,QAAQ,EAClB,gBAAgB,EAAE,KAAK,CAAC,gBAAgB,EACxC,OAAO,EAAE,KAAK,CAAC,OAAO,EACtB,eAAe,EAAE,KAAK,CAAC,eAAe,EACtC,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,QAAQ,EAAE,KAAK,CAAC,QAAQ,EACxB,OAAO,EAAE,KAAK,CAAC,MAAM,EACrB,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,iBAAiB,EAAE,KAAK,CAAC,iBAAiB,EAC1C,MAAM,EAAE,KAAK,CAAC,MAAM,EACpB,aAAa,EAAE,KAAK,CAAC,aAAa,EAClC,UAAU,EAAE,YAAY,CAAC,MAAM,CAAC,GAChC,EACF,KAAC,UAAU,IAAC,KAAK,EAAE,MAAM,CAAC,KAAK,GAAI,IAC3B,CACX,CAAC;AACJ,CAAC","sourcesContent":["import type { AgentBackend } from \"@surfaces-ui/agent\";\nimport { type DataRef, type FullLayout, Workspace, type WorkspaceLayout, type WorkspacePanel, addDataRefs, expandPanel, movePanel, movePanelToNewColumn, normalizeLayout, showPanel } from \"@surfaces-ui/components\";\nimport type { AgentInfo, ToolConnector } from \"@surfaces-ui/proto\";\nimport { type Catalog, analyticsCatalog } from \"@surfaces-ui/spec\";\nimport { type ComponentRenderer, type SurfaceNote, lazyAnalyticsRenderers } from \"@surfaces-ui/spec/react\";\nimport { type ReactNode, useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { MessageList, type MessageListProps, Suggestions, UsageGauge } from \"./Chat.js\";\nimport { type AttachResult, ChatComposer, type ComposerProps, type SpeechConsent } from \"./ChatComposer.js\";\nimport { AgentSetupPanel, choosesModel } from \"./ChatPanels.js\";\nimport { DataPanel, type DataPanelProps } from \"./DataPanel.js\";\nimport { SessionList, type SessionListState } from \"./SessionList.js\";\nimport { conversationThread } from \"./conversation.js\";\nimport { ChatIcon } from \"./icons.js\";\nimport type { ChatPanel, ChatProvider } from \"./selectors.js\";\nimport type { ChatSessionSummary, ChatSessions } from \"./sessions.js\";\nimport type { SpeechAdapter } from \"./speech.js\";\nimport type { ChatActor, ChatThread } from \"./thread.js\";\nimport { type ChatSettings, useChat } from \"./useChat.js\";\nimport type { VoiceReply } from \"./voice.js\";\n\nexport interface AnalyticsChatProps {\n agent: AgentBackend;\n catalog?: Catalog;\n renderers?: Record<string, ComponentRenderer>;\n user?: ChatActor;\n starters?: string[];\n placeholder?: string;\n /** Shown before anything is said. */\n empty?: string;\n /** What a person does in a drawn component, as it happens (it also goes with the next turn). */\n onContext?(note: SurfaceNote & { surfaceId: string; componentId: string }): void;\n /** Height of the whole chat. Default 640. */\n height?: number | string;\n\n /** Saved conversations: a Sessions panel to search, filter, sort and group them, and every conversation saved as it goes. */\n sessions?: ChatSessions;\n /** Files from the person's computer, turned into data by the host. */\n attachFiles?(files: File[]): Promise<AttachResult[]>;\n /** What the file picker offers; see `ComposerProps.accept`. */\n accept?: string;\n /** Replaces the line under \"Upload files…\"; see `ComposerProps.uploadDetail`. */\n uploadDetail?: ReactNode;\n /** Widens where files can be dropped beyond the composer; see `ComposerProps.dropTarget`. */\n dropTarget?: ComposerProps[\"dropTarget\"];\n /** Hands files in from outside the composer; see `ComposerProps.handleRef`. */\n composerRef?: ComposerProps[\"handleRef\"];\n /** How an image an agent named is drawn in a reply; see `MessageListProps.resolveImage`. */\n resolveImage?: MessageListProps[\"resolveImage\"];\n /** A Data panel of tables and files to attach. `sourceId` defaults to the settings' source. */\n browse?: Omit<DataPanelProps, \"onAttach\">;\n /** Agents with their models, skills and connectors (`DescribeAgents`). */\n agents?: AgentInfo[];\n settings?: ChatSettings;\n defaultSettings?: ChatSettings;\n onSettingsChange?(settings: ChatSettings): void;\n /** Data connections, offered in the Connectors menu and panel. */\n sources?: { id: string; label: string; detail?: string }[];\n onAddConnection?(): void;\n onConnect?(connector: ToolConnector): void;\n speech?: SpeechAdapter;\n /** Where models run, when the host can reach several; see `ChatProvider`. */\n providers?: ChatProvider[];\n onManageProviders?(): void;\n /** Ask before the microphone is first used; see `ChatComposer`. */\n speechConsent?: SpeechConsent;\n /** Items a composer menu shows before \"View all…\". Default 5. */\n menuLimit?: number;\n /** Where the panels are. Plain JSON, so a host can keep it. */\n layout?: WorkspaceLayout;\n onLayoutChange?(layout: FullLayout): void;\n /** Where the session list's search, filters, sort and grouping are. */\n sessionList?: SessionListState;\n onSessionListChange?(state: SessionListState): void;\n className?: string;\n}\n\nconst PANEL_TITLES: Record<ChatPanel, { title: string; shortTitle?: string; icon: ReactNode }> = {\n sessions: { title: \"Conversations\", icon: <ChatIcon name=\"sessions\" /> },\n data: { title: \"Data\", icon: <ChatIcon name=\"data\" /> },\n setup: { title: \"Agent setup\", shortTitle: \"Setup\", icon: <ChatIcon name=\"agent\" /> },\n};\n\n/**\n * Shows a panel beside the conversation: in the column the other panels\n * use, or in a new one to the right, so the thread keeps its height. A\n * panel a person has put somewhere else stays there.\n */\nexport function placeChatPanel(layout: WorkspaceLayout, panel: string, ids: string[]): FullLayout {\n const before = normalizeLayout(layout, ids);\n const wasHidden = before.hidden.includes(panel);\n let next = showPanel(before, panel);\n const column = (id: string) => next.columns.findIndex((c) => c.includes(id));\n if (wasHidden && column(panel) === column(\"chat\")) {\n const side = next.columns.findIndex((c) => !c.includes(\"chat\"));\n if (side >= 0) next = movePanel(next, panel, side, 0);\n else {\n next = movePanelToNewColumn(next, panel, next.columns.length);\n const chat = column(\"chat\");\n next = normalizeLayout({ ...next, columnWidths: next.columns.map((_, i) => (i === chat ? 0.64 : 0.36 / (next.columns.length - 1))) }, ids);\n }\n }\n return expandPanel(next, panel);\n}\n\n/** The latest reply as the voice loop needs it. */\nexport function voiceReplyOf(thread: ChatThread): VoiceReply | undefined {\n const last = [...thread.messages].reverse().find((m) => m.role === \"assistant\");\n if (!last) return undefined;\n const text = last.parts.flatMap((p) => (p.kind === \"text\" ? [p.text] : [])).join(\"\\n\\n\");\n return { id: String(last.id), text, status: thread.status === \"waiting\" ? \"waiting\" : last.streaming || thread.status === \"streaming\" ? \"streaming\" : \"idle\" };\n}\n\n/**\n * A chat for people who work with data. The conversation is always there;\n * every other part comes only when its prop is given: saved conversations,\n * files and tables to attach, the agent, model, skills and connectors, and\n * the microphone. Short lists are menus in the composer; each ends in \"View\n * all…\" or \"Manage…\", which opens its panel. Panels sit in a workspace with\n * a rail of icons on the right, and a person arranges them.\n */\nexport function AnalyticsChat(props: AnalyticsChatProps) {\n const { sessions, agents = [], browse } = props;\n const [keptSettings, setKeptSettings] = useState<ChatSettings>(props.defaultSettings ?? {});\n const settings = props.settings ?? keptSettings;\n const setSettings = useCallback(\n (next: ChatSettings) => {\n setKeptSettings(next);\n props.onSettingsChange?.(next);\n },\n [props.onSettingsChange],\n );\n const [references, setReferences] = useState<DataRef[]>([]);\n\n // Which conversation is open. A new key starts a fresh thread.\n const [open, setOpen] = useState<{ key: number; id?: string; thread?: ChatThread }>({ key: 0 });\n const [list, setList] = useState<ChatSessionSummary[]>([]);\n const [listError, setListError] = useState(\"\");\n const refresh = useCallback(async () => {\n if (!sessions) return;\n try {\n setList(await sessions.list());\n setListError(\"\");\n } catch (error) {\n setListError(error instanceof Error ? error.message : String(error));\n }\n }, [sessions]);\n useEffect(() => {\n void refresh();\n }, [refresh]);\n const run = (work: Promise<unknown>) => void work.then(refresh, (error) => setListError(error instanceof Error ? error.message : String(error)));\n const openSession = (id: string) =>\n run(\n sessions!.load(id).then((document) => {\n setOpen((o) => ({ key: o.key + 1, id, thread: conversationThread(document) }));\n setReferences([]);\n }),\n );\n const newSession = () => {\n setOpen((o) => ({ key: o.key + 1 }));\n setReferences([]);\n };\n\n const panelIds = useMemo(\n () => ([\"sessions\", \"data\", \"setup\"] as ChatPanel[]).filter((p) => (p === \"sessions\" ? !!sessions : p === \"data\" ? !!browse : choosesModel(agents, props.providers) || agents.length > 1 || agents.some((a) => a.skills.length > 0 || a.connectors.length > 0) || !!props.sources?.length || !!props.onAddConnection)),\n [sessions, browse, agents, props.providers, props.sources, props.onAddConnection],\n );\n const [keptLayout, setKeptLayout] = useState<WorkspaceLayout>(() => ({ columns: [[\"chat\"]], hidden: panelIds }));\n // A panel the layout has never placed (one that appears when an agent starts offering skills) starts hidden, on the rail.\n const given = props.layout ?? keptLayout;\n const placed = new Set([...given.columns.flat(), ...(given.hidden ?? [])]);\n const layout: WorkspaceLayout = { ...given, hidden: [...(given.hidden ?? []), ...panelIds.filter((id) => !placed.has(id))] };\n const latestLayout = useRef(layout);\n latestLayout.current = layout;\n const setLayout = (given: FullLayout) => {\n // A panel shown from the rail goes beside the conversation too, not under it.\n const before = normalizeLayout(latestLayout.current, [\"chat\", ...panelIds]);\n let next = given;\n for (const id of panelIds) if (before.hidden.includes(id) && !given.hidden.includes(id)) next = placeChatPanel({ ...next, columns: next.columns.map((c) => c.filter((p) => p !== id)), hidden: [...next.hidden, id] }, id, [\"chat\", ...panelIds]);\n latestLayout.current = next;\n setKeptLayout(next);\n props.onLayoutChange?.(next);\n };\n const manage = (panel: ChatPanel) => {\n if (!panelIds.includes(panel)) return;\n setLayout(placeChatPanel(latestLayout.current, panel, [\"chat\", ...panelIds]));\n // Focus the panel once it is drawn, so a keyboard user lands in it.\n requestAnimationFrame(() => document.querySelector<HTMLElement>(`[data-chat-panel=\"${panel}\"] input, [data-chat-panel=\"${panel}\"] button`)?.focus());\n };\n\n const sourceId = settings.sourceId ?? browse?.sourceId;\n const attach = (refs: DataRef[]) => setReferences((have) => addDataRefs(have, refs));\n const content: Record<ChatPanel, () => ReactNode> = {\n sessions: () => (\n <div data-chat-panel=\"sessions\">\n {listError && (\n <p className=\"sf-notice\" role=\"alert\">\n {listError}\n </p>\n )}\n <SessionList\n label=\"Conversation list\"\n sessions={list}\n current={open.id}\n value={props.sessionList}\n onChange={props.onSessionListChange}\n onOpen={openSession}\n onNew={newSession}\n onRename={(id, title) => run(sessions!.rename(id, title))}\n onPin={(id, pinned) => run(sessions!.pin(id, pinned))}\n onRemove={(id) => {\n if (id === open.id) newSession();\n run(sessions!.remove(id));\n }}\n agentName={(id) => agents.find((a) => a.id === id)?.name ?? id}\n height={420}\n />\n </div>\n ),\n data: () => (\n <div data-chat-panel=\"data\">\n <DataPanel {...browse} sourceId={sourceId} sourceLabel={props.sources?.find((s) => s.id === sourceId)?.label ?? browse?.sourceLabel} onAttach={attach} />\n </div>\n ),\n setup: () => (\n <div data-chat-panel=\"setup\">\n <AgentSetupPanel agents={agents} settings={settings} onSettingsChange={setSettings} providers={props.providers} onManageProviders={props.onManageProviders} sources={props.sources} onAddConnection={props.onAddConnection} onConnect={props.onConnect} />\n </div>\n ),\n };\n\n const conversation = (\n <Conversation\n key={open.key}\n {...props}\n sessionId={open.id}\n initial={open.thread}\n settings={settings}\n onSettingsChange={setSettings}\n references={references}\n onReferencesChange={setReferences}\n onManage={panelIds.length > 0 ? manage : undefined}\n panels={panelIds}\n onSaved={(id) => {\n setOpen((o) => (o.id === id ? o : { ...o, id }));\n void refresh();\n }}\n />\n );\n\n if (panelIds.length === 0)\n return (\n <section className={[\"sf-analytics-chat\", props.className].filter(Boolean).join(\" \")} style={{ height: props.height ?? 640 }} aria-label=\"Chat\">\n {conversation}\n </section>\n );\n const panels: WorkspacePanel[] = [{ id: \"chat\", title: \"Chat\", icon: <ChatIcon name=\"chat\" />, fill: true, content: conversation }, ...panelIds.map((id) => ({ id, ...PANEL_TITLES[id], content: content[id]() }))];\n return (\n <div className={[\"sf-analytics-chat\", props.className].filter(Boolean).join(\" \")}>\n <Workspace label=\"Chat panels\" panels={panels} layout={layout} onLayoutChange={setLayout} rail=\"right\" height={props.height ?? 640} />\n </div>\n );\n}\n\ninterface ConversationProps extends AnalyticsChatProps {\n sessionId?: string;\n initial?: ChatThread;\n settings: ChatSettings;\n onSettingsChange(settings: ChatSettings): void;\n references: DataRef[];\n onReferencesChange(references: DataRef[]): void;\n onManage?(panel: ChatPanel): void;\n panels: ChatPanel[];\n onSaved(id: string): void;\n}\n\n/** One conversation: the thread, the suggestions and the composer. Saved whenever a reply finishes. */\nfunction Conversation(props: ConversationProps) {\n const catalog = props.catalog ?? analyticsCatalog;\n const renderers = props.renderers ?? lazyAnalyticsRenderers;\n const chat = useChat(props.agent, { catalog, user: props.user, initial: props.initial, settings: props.settings });\n const { thread } = chat;\n const { sessions, onSaved, settings } = props;\n\n // Save once a turn is over, and only when something new was said.\n const id = useRef(props.sessionId);\n const saved = useRef(props.initial?.messages.length ?? 0);\n useEffect(() => {\n if (!sessions || thread.status === \"streaming\" || thread.messages.length === 0 || thread.messages.length === saved.current) return;\n saved.current = thread.messages.length;\n void sessions\n .save({ ...(id.current ? { id: id.current } : {}), thread, ...(settings.agentId ? { agentId: settings.agentId } : {}), ...(settings.model ? { model: settings.model } : {}), ...(settings.sourceId ? { sources: [settings.sourceId] } : {}) })\n .then((summary) => {\n id.current = summary.id;\n onSaved(summary.id);\n })\n .catch(() => {\n // Let the next turn try again.\n saved.current = 0;\n });\n }, [thread, sessions, settings, onSaved]);\n\n const suggestions = thread.messages.length === 0 ? (props.starters ?? []) : thread.status === \"idle\" ? thread.suggestions : [];\n const onContext = props.onContext;\n return (\n <section className=\"sf-chat sf-analytics-conversation\" aria-label=\"Conversation\">\n <MessageList thread={thread} catalog={catalog} renderers={renderers} onAction={chat.act} onAnswer={chat.answer} onReport={chat.report} onProblem={chat.problem} onContext={onContext} empty={props.empty} resolveImage={props.resolveImage} />\n <Suggestions items={suggestions} onPick={(text) => chat.send(text, props.references)} />\n <ChatComposer\n onSend={(text, refs, attachments) => chat.send(text, refs, attachments)}\n onStop={chat.stop}\n streaming={thread.status === \"streaming\"}\n placeholder={thread.status === \"waiting\" ? \"Answer above, or type to say something else\" : props.placeholder}\n references={props.references}\n onReferencesChange={props.onReferencesChange}\n attachFiles={props.attachFiles}\n accept={props.accept}\n uploadDetail={props.uploadDetail}\n dropTarget={props.dropTarget}\n handleRef={props.composerRef}\n browse={props.panels.includes(\"data\") ? undefined : props.browse}\n agents={props.agents}\n settings={settings}\n onSettingsChange={props.onSettingsChange}\n sources={props.sources}\n onAddConnection={props.onAddConnection}\n onConnect={props.onConnect}\n onManage={props.onManage}\n managed={props.panels}\n menuLimit={props.menuLimit}\n providers={props.providers}\n onManageProviders={props.onManageProviders}\n speech={props.speech}\n speechConsent={props.speechConsent}\n voiceReply={voiceReplyOf(thread)}\n />\n <UsageGauge usage={thread.usage} />\n </section>\n );\n}\n"]}
|
package/dist/Chat.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { AgentBackend } from "@surfaces-ui/agent";
|
|
2
2
|
import type { AgentInfo } from "@surfaces-ui/proto";
|
|
3
|
-
import { type DataRef } from "@surfaces-ui/components";
|
|
3
|
+
import { type DataRef, type ImageResolver } from "@surfaces-ui/components";
|
|
4
4
|
import { type Catalog, type SurfaceAction } from "@surfaces-ui/spec";
|
|
5
5
|
import { type ComponentRenderer, type SurfaceNote } from "@surfaces-ui/spec/react";
|
|
6
|
+
import { type Ref } from "react";
|
|
7
|
+
import { type AttachResult, type ComposerHandle, type ComposerProps } from "./ChatComposer.js";
|
|
6
8
|
import type { ChatActions, ChatActor, ChatStep, ChatThread, ChatUsage } from "./thread.js";
|
|
7
9
|
import type { ChatProvider } from "./selectors.js";
|
|
8
10
|
import { type ChatSettings, type UseChat, type UseChatOptions } from "./useChat.js";
|
|
@@ -41,6 +43,12 @@ export interface MessageListProps {
|
|
|
41
43
|
onPartAction?(partId: string, actionId: string, choiceId?: string): void;
|
|
42
44
|
/** Shown when the thread is empty. */
|
|
43
45
|
empty?: string;
|
|
46
|
+
/**
|
|
47
|
+
* How an image an agent named is drawn, in its replies' Markdown and in any `Image` it draws: turns the name or address
|
|
48
|
+
* it wrote into the address to load, or nothing (the description is shown). Without it, or a resolver given above
|
|
49
|
+
* (`ImageResolverProvider`), no image an agent wrote is loaded. Not used for a person's own attachments (`ChatAttachment.preview`).
|
|
50
|
+
*/
|
|
51
|
+
resolveImage?: ImageResolver;
|
|
44
52
|
}
|
|
45
53
|
/**
|
|
46
54
|
* The conversation so far. Replies can hold text, tool steps, approvals and
|
|
@@ -89,6 +97,16 @@ export interface ChatProps {
|
|
|
89
97
|
/** Offered before the first message. */
|
|
90
98
|
starters?: string[];
|
|
91
99
|
placeholder?: string;
|
|
100
|
+
/** How an image an agent named is drawn; see `MessageListProps.resolveImage`. */
|
|
101
|
+
resolveImage?: ImageResolver;
|
|
102
|
+
/** Turns files a person drops, pastes or picks into data or attachments; see `ComposerProps.attachFiles`. Without it there is no upload. */
|
|
103
|
+
attachFiles?(files: File[]): Promise<AttachResult[]>;
|
|
104
|
+
/** What the file picker offers; see `ComposerProps.accept`. */
|
|
105
|
+
accept?: string;
|
|
106
|
+
/** Widens the drop target beyond the composer; see `ComposerProps.dropTarget`. */
|
|
107
|
+
dropTarget?: ComposerProps["dropTarget"];
|
|
108
|
+
/** Hands files in from outside; see `ComposerProps.handleRef`. */
|
|
109
|
+
composerRef?: Ref<ComposerHandle>;
|
|
92
110
|
/** The agent, model, skills and connectors a person chose, sent with each turn; with `onSettingsChange` the composer offers them. */
|
|
93
111
|
settings?: ChatSettings;
|
|
94
112
|
onSettingsChange?(settings: ChatSettings): void;
|
package/dist/Chat.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Markdown, addDataRefs, dataRefLabel, hasDataRefs, readDataRefs, sameDataRef } from "@surfaces-ui/components";
|
|
2
|
+
import { ImageResolverProvider, Markdown, addDataRefs, dataRefLabel, hasDataRefs, readDataRefs, safeImageAddress, sameDataRef } from "@surfaces-ui/components";
|
|
3
3
|
import { analyticsCatalog } from "@surfaces-ui/spec";
|
|
4
4
|
import { SurfaceView, lazyAnalyticsRenderers } from "@surfaces-ui/spec/react";
|
|
5
5
|
import { useEffect, useId, useRef, useState } from "react";
|
|
@@ -35,9 +35,17 @@ export function ActionsCard({ actions, onPress }) {
|
|
|
35
35
|
const choices = actions.choices ?? [];
|
|
36
36
|
return (_jsxs("div", { className: "sf-chat-actions", role: "group", "aria-label": actions.title || "Actions", "data-handled": actions.outcome !== undefined || undefined, children: [actions.title && _jsx("p", { className: "sf-chat-actions-title", children: actions.title }), actions.detail && _jsx("p", { className: "sf-chat-actions-detail", children: actions.detail }), actions.outcome !== undefined ? (_jsx("p", { className: "sf-chat-actions-outcome", role: "status", children: actions.outcome })) : (_jsxs(_Fragment, { children: [choices.length > 0 && (_jsx("ul", { className: "sf-chat-actions-choices", "aria-label": "Choices", children: choices.map((choice) => (_jsxs("li", { children: [_jsxs("p", { className: "sf-chat-actions-choice", children: [_jsx("span", { className: "sf-chat-actions-title", children: choice.title }), choice.detail && _jsxs("span", { className: "sf-chat-actions-detail", children: [" \u00B7 ", choice.detail] })] }), _jsx(ActionButtons, { buttons: choice.buttons, label: choice.title, onPress: (id) => onPress(id, choice.id) })] }, choice.id))) })), _jsx(ActionButtons, { buttons: actions.buttons ?? [], label: choices.length > 0 ? "All choices" : undefined, onPress: (id) => onPress(id) })] }))] }));
|
|
37
37
|
}
|
|
38
|
+
/** Pictures and files a person attached to their message, as chips with a thumbnail where there is one. */
|
|
39
|
+
function AttachedChips({ attachments }) {
|
|
40
|
+
return (_jsx("ul", { className: "sf-chat-references sf-chat-attachments", "aria-label": "Attached files", children: attachments.map((one) => {
|
|
41
|
+
// The preview is the host's own (a blob it made from the file), never an address a model wrote.
|
|
42
|
+
const picture = one.mediaType.startsWith("image/") ? safeImageAddress(one.preview) : undefined;
|
|
43
|
+
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: "", loading: "lazy", decoding: "async" }) : null, _jsx("span", { children: one.name })] }, one.id ?? one.name));
|
|
44
|
+
}) }));
|
|
45
|
+
}
|
|
38
46
|
function MessageView({ message, thread, catalog, renderers, onAction, onAnswer, onReport, onProblem, onContext, onPartAction }) {
|
|
39
47
|
if (message.role === "user") {
|
|
40
|
-
return (_jsxs("article", { className: "sf-chat-message", "data-role": "user", children: [_jsx("span", { className: "sf-a2-visually-hidden", children: "You said:" }), _jsx("p", { children: message.parts.map((p) => (p.kind === "text" ? p.text : "")).join("") }), message.parts.map((p, i) => p.kind === "references" ? (_jsx("ul", { className: "sf-chat-references", "aria-label": "Attached", children: p.references.map((ref) => (_jsx("li", { className: "sf-chat-reference", "data-kind": ref.kind, children: dataRefLabel(ref) }, `${ref.sourceId}/${dataRefLabel(ref)}`))) }, i)) : null)] }));
|
|
48
|
+
return (_jsxs("article", { className: "sf-chat-message", "data-role": "user", children: [_jsx("span", { className: "sf-a2-visually-hidden", children: "You said:" }), _jsx("p", { children: message.parts.map((p) => (p.kind === "text" ? p.text : "")).join("") }), message.parts.map((p, i) => p.kind === "references" ? (_jsx("ul", { className: "sf-chat-references", "aria-label": "Attached", children: p.references.map((ref) => (_jsx("li", { className: "sf-chat-reference", "data-kind": ref.kind, children: dataRefLabel(ref) }, `${ref.sourceId}/${dataRefLabel(ref)}`))) }, i)) : p.kind === "attachments" ? (_jsx(AttachedChips, { attachments: p.attachments }, i)) : null)] }));
|
|
41
49
|
}
|
|
42
50
|
return (_jsxs("article", { className: "sf-chat-message", "data-role": "assistant", "aria-busy": message.streaming, children: [_jsx("span", { className: "sf-a2-visually-hidden", children: "The agent replied:" }), message.parts.map((part, index) => {
|
|
43
51
|
switch (part.kind) {
|
|
@@ -59,6 +67,7 @@ function MessageView({ message, thread, catalog, renderers, onAction, onAnswer,
|
|
|
59
67
|
case "actions":
|
|
60
68
|
return _jsx(ActionsCard, { actions: part.actions, onPress: (actionId, choiceId) => onPartAction?.(part.actions.id, actionId, choiceId) }, index);
|
|
61
69
|
case "references":
|
|
70
|
+
case "attachments":
|
|
62
71
|
// Attachments belong to what a person sent; a reply has none.
|
|
63
72
|
return null;
|
|
64
73
|
default:
|
|
@@ -80,10 +89,11 @@ export function MessageList(props) {
|
|
|
80
89
|
if (element && pinned.current)
|
|
81
90
|
element.scrollTop = element.scrollHeight;
|
|
82
91
|
}, [thread]);
|
|
83
|
-
|
|
92
|
+
const list_ = (_jsxs("div", { ref: list, className: "sf-chat-list", role: "log", "aria-label": "Conversation", "aria-live": "polite", tabIndex: 0, onScroll: (event) => {
|
|
84
93
|
const element = event.currentTarget;
|
|
85
94
|
pinned.current = element.scrollHeight - element.scrollTop - element.clientHeight < 48;
|
|
86
95
|
}, children: [thread.messages.length === 0 && props.empty && _jsx("div", { className: "sf-chat-empty", children: props.empty }), thread.messages.map((message) => (_jsx(MessageView, { ...props, message: message }, message.id)))] }));
|
|
96
|
+
return props.resolveImage ? _jsx(ImageResolverProvider, { resolve: props.resolveImage, children: list_ }) : list_;
|
|
87
97
|
}
|
|
88
98
|
/** Things the person might say next, one press each. */
|
|
89
99
|
export function Suggestions({ items, onPick }) {
|
|
@@ -114,6 +124,6 @@ export function Chat(props) {
|
|
|
114
124
|
onThreadChange.current = props.onThreadChange;
|
|
115
125
|
useEffect(() => onThreadChange.current?.(thread), [thread]);
|
|
116
126
|
const suggestions = thread.messages.length === 0 ? (props.starters ?? []) : thread.status === "idle" ? thread.suggestions : [];
|
|
117
|
-
return (_jsxs("section", { className: ["sf-chat", props.className].filter(Boolean).join(" "), style: { height: props.height ?? 640 }, "aria-label": "Chat", children: [_jsx(MessageList, { thread: thread, catalog: catalog, renderers: renderers, onAction: chat.act, onAnswer: chat.answer, onReport: chat.report, onProblem: chat.problem, onContext: props.onContext, empty: props.empty }), _jsx(Suggestions, { items: suggestions, onPick: (text) => chat.send(text) }), _jsx(Composer, { agents: props.agents, settings: props.settings, onSettingsChange: props.onSettingsChange, providers: props.providers, onManageProviders: props.onManageProviders, references: props.references, onReferencesChange: props.onReferencesChange, onSend: chat.send, onStop: chat.stop, streaming: thread.status === "streaming", placeholder: thread.status === "waiting" ? "Answer above, or type to say something else" : props.placeholder }), _jsx(UsageGauge, { usage: thread.usage })] }));
|
|
127
|
+
return (_jsxs("section", { className: ["sf-chat", props.className].filter(Boolean).join(" "), style: { height: props.height ?? 640 }, "aria-label": "Chat", children: [_jsx(MessageList, { thread: thread, catalog: catalog, renderers: renderers, onAction: chat.act, onAnswer: chat.answer, onReport: chat.report, onProblem: chat.problem, onContext: props.onContext, empty: props.empty, resolveImage: props.resolveImage }), _jsx(Suggestions, { items: suggestions, onPick: (text) => chat.send(text) }), _jsx(Composer, { agents: props.agents, settings: props.settings, onSettingsChange: props.onSettingsChange, providers: props.providers, onManageProviders: props.onManageProviders, references: props.references, onReferencesChange: props.onReferencesChange, attachFiles: props.attachFiles, accept: props.accept, dropTarget: props.dropTarget, handleRef: props.composerRef, onSend: chat.send, onStop: chat.stop, streaming: thread.status === "streaming", placeholder: thread.status === "waiting" ? "Answer above, or type to say something else" : props.placeholder }), _jsx(UsageGauge, { usage: thread.usage })] }));
|
|
118
128
|
}
|
|
119
129
|
//# sourceMappingURL=Chat.js.map
|
package/dist/Chat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chat.js","sourceRoot":"","sources":["../src/Chat.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAgB,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACpI,OAAO,EAAoC,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACvF,OAAO,EAA4C,WAAW,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACxH,OAAO,EAAsD,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC/G,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,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KAAK,GAAI,EAClN,KAAC,WAAW,IAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAI,EACtE,KAAC,QAAQ,IACP,MAAM,EAAE,KAAK,CAAC,MAAM,EACpB,QAAQ,EAAE,KAAK,CAAC,QAAQ,EACxB,gBAAgB,EAAE,KAAK,CAAC,gBAAgB,EACxC,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,iBAAiB,EAAE,KAAK,CAAC,iBAAiB,EAC1C,UAAU,EAAE,KAAK,CAAC,UAAU,EAC5B,kBAAkB,EAAE,KAAK,CAAC,kBAAkB,EAC5C,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,MAAM,KAAK,WAAW,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,6CAA6C,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,GAAI,EAClM,KAAC,UAAU,IAAC,KAAK,EAAE,MAAM,CAAC,KAAK,GAAI,IAC3B,CACX,CAAC;AACJ,CAAC","sourcesContent":["import type { AgentBackend } from \"@surfaces-ui/agent\";\nimport type { AgentInfo } from \"@surfaces-ui/proto\";\nimport { type DataRef, Markdown, addDataRefs, dataRefLabel, hasDataRefs, readDataRefs, sameDataRef } from \"@surfaces-ui/components\";\nimport { type Catalog, type SurfaceAction, analyticsCatalog } from \"@surfaces-ui/spec\";\nimport { type ComponentRenderer, type SurfaceNote, SurfaceView, lazyAnalyticsRenderers } from \"@surfaces-ui/spec/react\";\nimport { type DragEvent, type FormEvent, type KeyboardEvent, useEffect, useId, useRef, useState } from \"react\";\nimport { ApprovalCard } from \"./Approval.js\";\nimport { Composer } from \"./ChatComposer.js\";\nimport type { ChatActions, ChatActor, ChatButton, ChatMessage, ChatStep, ChatThread, ChatUsage } from \"./thread.js\";\nimport type { ChatProvider } from \"./selectors.js\";\nimport { type ChatSettings, type UseChat, type UseChatOptions, useChat } from \"./useChat.js\";\n\nconst count = new Intl.NumberFormat(\"en-US\");\nconst STEP_MARK: Record<ChatStep[\"status\"], string> = { running: \"…\", done: \"✓\", failed: \"!\" };\nconst STEP_WORD: Record<ChatStep[\"status\"], string> = { running: \"running\", done: \"done\", failed: \"failed\" };\n\nexport interface ToolStepsProps {\n steps: ChatStep[];\n}\n\n/** The work an agent did for a reply, such as tool calls. Each step opens to show its detail. */\nexport function ToolSteps({ steps }: ToolStepsProps) {\n return (\n <ul className=\"sf-chat-steps\" aria-label=\"Steps\">\n {steps.map((step) => (\n <li key={step.id} data-status={step.status}>\n <details>\n <summary>\n <span className=\"sf-chat-step-mark\" aria-hidden=\"true\">\n {STEP_MARK[step.status]}\n </span>\n <span className=\"sf-chat-step-title\">{step.title || step.tool}</span>\n <span className=\"sf-chat-step-meta\">\n {STEP_WORD[step.status]}\n {step.durationMs > 0 ? ` · ${count.format(step.durationMs)} ms` : \"\"}\n </span>\n </summary>\n {step.tool && <p className=\"sf-chat-step-tool\">Tool: {step.tool}</p>}\n {step.detail && <pre tabIndex={0}>{step.detail}</pre>}\n </details>\n </li>\n ))}\n </ul>\n );\n}\n\nexport interface ActionsCardProps {\n actions: ChatActions;\n /** A press: the button's id, and the choice it belongs to when it is in one. Never called for a disabled button. */\n onPress(buttonId: string, choiceId?: string): void;\n}\n\nfunction ActionButtons({ buttons, label, onPress }: { buttons: ChatButton[]; label?: string; onPress(id: string): void }) {\n const uid = useId();\n if (buttons.length === 0) return null;\n return (\n <div className=\"sf-chat-actions-row\" role={label ? \"group\" : undefined} aria-label={label}>\n {buttons.map((button, i) => {\n const why = button.reason ? `${uid}-${i}` : undefined;\n return (\n <span key={button.id} className=\"sf-chat-actions-button\">\n <button\n type=\"button\"\n className=\"sf-button\"\n data-variant={button.variant}\n // Not `disabled`: a disabled button cannot be reached by keyboard, and then neither can its reason.\n aria-disabled={button.disabled || undefined}\n aria-label={button.ariaLabel}\n aria-describedby={why}\n title={button.reason}\n onClick={() => {\n if (!button.disabled) onPress(button.id);\n }}\n >\n {button.label}\n </button>\n {why && (\n <span id={why} className=\"sf-a2-visually-hidden\">\n {button.reason}\n </span>\n )}\n </span>\n );\n })}\n </div>\n );\n}\n\n/**\n * What a person can do about a reply, under it: a row of buttons, or several\n * alternatives one row each with buttons for the whole set after them. The\n * host decides what a press does and, once it is handled, replaces the\n * buttons with what became of it (`outcome`).\n */\nexport function ActionsCard({ actions, onPress }: ActionsCardProps) {\n const choices = actions.choices ?? [];\n return (\n <div className=\"sf-chat-actions\" role=\"group\" aria-label={actions.title || \"Actions\"} data-handled={actions.outcome !== undefined || undefined}>\n {actions.title && <p className=\"sf-chat-actions-title\">{actions.title}</p>}\n {actions.detail && <p className=\"sf-chat-actions-detail\">{actions.detail}</p>}\n {actions.outcome !== undefined ? (\n <p className=\"sf-chat-actions-outcome\" role=\"status\">\n {actions.outcome}\n </p>\n ) : (\n <>\n {choices.length > 0 && (\n <ul className=\"sf-chat-actions-choices\" aria-label=\"Choices\">\n {choices.map((choice) => (\n <li key={choice.id}>\n <p className=\"sf-chat-actions-choice\">\n <span className=\"sf-chat-actions-title\">{choice.title}</span>\n {choice.detail && <span className=\"sf-chat-actions-detail\"> · {choice.detail}</span>}\n </p>\n <ActionButtons buttons={choice.buttons} label={choice.title} onPress={(id) => onPress(id, choice.id)} />\n </li>\n ))}\n </ul>\n )}\n <ActionButtons buttons={actions.buttons ?? []} label={choices.length > 0 ? \"All choices\" : undefined} onPress={(id) => onPress(id)} />\n </>\n )}\n </div>\n );\n}\n\nexport interface MessageListProps {\n thread: ChatThread;\n catalog: Catalog;\n renderers: Record<string, ComponentRenderer>;\n onAction(action: SurfaceAction): void;\n onAnswer: UseChat[\"answer\"];\n /** Where each drawn surface stands and what went wrong with it, kept for the agent's next turn (`useChat`'s `report` and `problem`). */\n onReport?: UseChat[\"report\"];\n onProblem?: UseChat[\"problem\"];\n /** Told what a person does in a drawn component as they do it, with where. For a host that keeps its own context for an agent. */\n onContext?(note: SurfaceNote & { surfaceId: string; componentId: string }): void;\n /** A press on a button in an actions part (`ChatActions`): the part's id, the button's id, and its choice's id when it is in one. */\n onPartAction?(partId: string, actionId: string, choiceId?: string): void;\n /** Shown when the thread is empty. */\n empty?: string;\n}\n\nfunction MessageView({ message, thread, catalog, renderers, onAction, onAnswer, onReport, onProblem, onContext, onPartAction }: MessageListProps & { message: ChatMessage }) {\n if (message.role === \"user\") {\n return (\n <article className=\"sf-chat-message\" data-role=\"user\">\n <span className=\"sf-a2-visually-hidden\">You said:</span>\n <p>{message.parts.map((p) => (p.kind === \"text\" ? p.text : \"\")).join(\"\")}</p>\n {message.parts.map((p, i) =>\n p.kind === \"references\" ? (\n // biome-ignore lint/suspicious/noArrayIndexKey: a message's parts do not move.\n <ul key={i} className=\"sf-chat-references\" aria-label=\"Attached\">\n {p.references.map((ref) => (\n <li key={`${ref.sourceId}/${dataRefLabel(ref)}`} className=\"sf-chat-reference\" data-kind={ref.kind}>\n {dataRefLabel(ref)}\n </li>\n ))}\n </ul>\n ) : null,\n )}\n </article>\n );\n }\n return (\n <article className=\"sf-chat-message\" data-role=\"assistant\" aria-busy={message.streaming}>\n <span className=\"sf-a2-visually-hidden\">The agent replied:</span>\n {message.parts.map((part, index) => {\n switch (part.kind) {\n case \"text\":\n return <Markdown key={index} text={part.text} />;\n case \"steps\":\n return <ToolSteps key={index} steps={part.steps} />;\n case \"surface\": {\n const surface = thread.surfaces[part.surfaceId];\n // Agent-drawn components are checked against the catalog before they are drawn.\n const key = part.surfaceId;\n return surface ? (\n <SurfaceView\n key={index}\n surface={surface}\n catalog={catalog}\n renderers={renderers}\n onAction={onAction}\n onDataChange={(data) => onReport?.(key, { data })}\n onControlsChange={(componentId, controls) => onReport?.(key, { componentId, controls })}\n onContext={(componentId, note) => {\n onReport?.(key, { componentId, note });\n onContext?.({ ...note, surfaceId: key, componentId });\n }}\n onProblem={(problem) => onProblem?.(key, problem)}\n className=\"sf-chat-surface\"\n />\n ) : null;\n }\n case \"approval\":\n return <ApprovalCard key={index} approval={part.approval} onAnswer={onAnswer} />;\n case \"actions\":\n return <ActionsCard key={index} actions={part.actions} onPress={(actionId, choiceId) => onPartAction?.(part.actions.id, actionId, choiceId)} />;\n case \"references\":\n // Attachments belong to what a person sent; a reply has none.\n return null;\n default:\n return (\n <p key={index} className=\"sf-chat-error\" role=\"alert\">\n {part.code === \"CANCELLED\" ? \"Stopped.\" : part.message}\n </p>\n );\n }\n })}\n {message.streaming && message.parts.length === 0 && <p className=\"sf-chat-thinking\">Working…</p>}\n {!message.streaming && message.generatedBy && <p className=\"sf-chat-by\">Answered by {message.generatedBy}</p>}\n </article>\n );\n}\n\n/**\n * The conversation so far. Replies can hold text, tool steps, approvals and\n * components the agent drew. The list follows new content while the reader\n * is at the bottom and stays put when they have scrolled up.\n */\nexport function MessageList(props: MessageListProps) {\n const { thread } = props;\n const list = useRef<HTMLDivElement>(null);\n const pinned = useRef(true);\n useEffect(() => {\n const element = list.current;\n if (element && pinned.current) element.scrollTop = element.scrollHeight;\n }, [thread]);\n return (\n <div\n ref={list}\n className=\"sf-chat-list\"\n role=\"log\"\n aria-label=\"Conversation\"\n aria-live=\"polite\"\n tabIndex={0}\n onScroll={(event) => {\n const element = event.currentTarget;\n pinned.current = element.scrollHeight - element.scrollTop - element.clientHeight < 48;\n }}\n >\n {thread.messages.length === 0 && props.empty && <div className=\"sf-chat-empty\">{props.empty}</div>}\n {thread.messages.map((message) => (\n <MessageView key={message.id} {...props} message={message} />\n ))}\n </div>\n );\n}\n\nexport interface SuggestionsProps {\n items: string[];\n onPick(text: string): void;\n}\n\n/** Things the person might say next, one press each. */\nexport function Suggestions({ items, onPick }: SuggestionsProps) {\n if (items.length === 0) return null;\n return (\n <div className=\"sf-chat-suggestions\" role=\"group\" aria-label=\"Suggestions\">\n {items.map((item) => (\n <button key={item} type=\"button\" className=\"sf-button\" onClick={() => onPick(item)}>\n {item}\n </button>\n ))}\n </div>\n );\n}\n\n/** How full the agent's context is, and what the conversation has cost when known. */\nexport function UsageGauge({ usage }: { usage: ChatUsage | undefined }) {\n if (!usage || usage.contextLimit <= 0) return null;\n const share = Math.min(1, usage.contextTokens / usage.contextLimit);\n return (\n <p className=\"sf-chat-usage\">\n <meter min={0} max={1} high={0.8} value={share} aria-label=\"Context used\" />\n <span>\n {Math.round(share * 100)}% of context used\n {usage.costUsd !== undefined ? ` · $${usage.costUsd.toFixed(2)}` : \"\"}\n </span>\n </p>\n );\n}\n\nexport interface ChatProps {\n /** Any agent runtime behind the AgentBackend interface. */\n agent: AgentBackend;\n /** The catalog agent-drawn components are checked against. Defaults to the analytics catalog. */\n catalog?: Catalog;\n renderers?: Record<string, ComponentRenderer>;\n agentId?: string;\n /** Limit the agent to the data in this saved context pack. */\n contextPackId?: string;\n /** Who is using the chat, from the host's sign-in; recorded on approval answers and surface events. */\n user?: ChatActor;\n /** Where to keep the conversation across reloads (`browserStorage()` from `@surfaces-ui/state`, or your own). */\n storage?: UseChatOptions[\"storage\"];\n storageKey?: string;\n /** Tables and columns attached to the message being written, when the host holds them (see `Composer`). */\n references?: DataRef[];\n onReferencesChange?(references: DataRef[]): void;\n /** The thread to open with: a saved or written conversation. Read once. */\n initialThread?: ChatThread;\n /** Told the thread after every change, so a host can save it or build from what was drawn. */\n onThreadChange?(thread: ChatThread): void;\n /**\n * Told what a person does in a drawn component as they do it (a view\n * added, a field changed, a filter set). The chat already keeps these and\n * gives them to the agent with its next turn; this is for a host that\n * wants them too.\n */\n onContext?: MessageListProps[\"onContext\"];\n /** Offered before the first message. */\n starters?: string[];\n placeholder?: string;\n /** The agent, model, skills and connectors a person chose, sent with each turn; with `onSettingsChange` the composer offers them. */\n settings?: ChatSettings;\n onSettingsChange?(settings: ChatSettings): void;\n /** What the agent offers (`DescribeAgents`), for the composer's menus. */\n agents?: AgentInfo[];\n /** Where models run, when the host can reach several: the Model menu groups models by provider. */\n providers?: ChatProvider[];\n onManageProviders?(): void;\n /** Shown when the thread is empty. */\n empty?: string;\n /** Height of the whole chat. A number is px. Defaults to 640. */\n height?: number | string;\n className?: string;\n}\n\n/**\n * A complete chat: the conversation, suggestions and the composer. Agent\n * replies stream in as Markdown, with tool steps, approvals and any catalog\n * component (charts, tables, pivots, model diagrams, decision cards) drawn\n * inline. Data components need a DataSourceProvider above the chat.\n */\nexport function Chat(props: ChatProps) {\n const catalog = props.catalog ?? analyticsCatalog;\n const renderers = props.renderers ?? lazyAnalyticsRenderers;\n const chat = useChat(props.agent, { catalog, agentId: props.agentId, contextPackId: props.contextPackId, user: props.user, storage: props.storage, storageKey: props.storageKey, initial: props.initialThread, settings: props.settings });\n const { thread } = chat;\n // Told on a change of thread only: a host passing a new function each render must not be told again (and set state in a loop).\n const onThreadChange = useRef(props.onThreadChange);\n onThreadChange.current = props.onThreadChange;\n useEffect(() => onThreadChange.current?.(thread), [thread]);\n const suggestions = thread.messages.length === 0 ? (props.starters ?? []) : thread.status === \"idle\" ? thread.suggestions : [];\n return (\n <section className={[\"sf-chat\", props.className].filter(Boolean).join(\" \")} style={{ height: props.height ?? 640 }} aria-label=\"Chat\">\n <MessageList thread={thread} catalog={catalog} renderers={renderers} onAction={chat.act} onAnswer={chat.answer} onReport={chat.report} onProblem={chat.problem} onContext={props.onContext} empty={props.empty} />\n <Suggestions items={suggestions} onPick={(text) => chat.send(text)} />\n <Composer\n agents={props.agents}\n settings={props.settings}\n onSettingsChange={props.onSettingsChange}\n providers={props.providers}\n onManageProviders={props.onManageProviders}\n references={props.references}\n onReferencesChange={props.onReferencesChange}\n onSend={chat.send} onStop={chat.stop} streaming={thread.status === \"streaming\"} placeholder={thread.status === \"waiting\" ? \"Answer above, or type to say something else\" : props.placeholder} />\n <UsageGauge usage={thread.usage} />\n </section>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Chat.js","sourceRoot":"","sources":["../src/Chat.tsx"],"names":[],"mappings":";AAEA,OA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,EAAE,MAAM,CAAC,KAAK,GAAI,IAC3B,CACX,CAAC;AACJ,CAAC","sourcesContent":["import type { AgentBackend } from \"@surfaces-ui/agent\";\nimport type { AgentInfo } from \"@surfaces-ui/proto\";\nimport { type DataRef, type ImageResolver, ImageResolverProvider, Markdown, addDataRefs, dataRefLabel, hasDataRefs, readDataRefs, safeImageAddress, sameDataRef } from \"@surfaces-ui/components\";\nimport { type Catalog, type SurfaceAction, analyticsCatalog } from \"@surfaces-ui/spec\";\nimport { type ComponentRenderer, type SurfaceNote, SurfaceView, lazyAnalyticsRenderers } from \"@surfaces-ui/spec/react\";\nimport { type DragEvent, type FormEvent, type KeyboardEvent, type Ref, useEffect, useId, useRef, useState } from \"react\";\nimport { ApprovalCard } from \"./Approval.js\";\nimport { type AttachResult, Composer, type ComposerHandle, type ComposerProps } from \"./ChatComposer.js\";\nimport type { ChatActions, ChatActor, ChatAttachment, ChatButton, ChatMessage, ChatStep, ChatThread, ChatUsage } from \"./thread.js\";\nimport type { ChatProvider } from \"./selectors.js\";\nimport { type ChatSettings, type UseChat, type UseChatOptions, useChat } from \"./useChat.js\";\n\nconst count = new Intl.NumberFormat(\"en-US\");\nconst STEP_MARK: Record<ChatStep[\"status\"], string> = { running: \"…\", done: \"✓\", failed: \"!\" };\nconst STEP_WORD: Record<ChatStep[\"status\"], string> = { running: \"running\", done: \"done\", failed: \"failed\" };\n\nexport interface ToolStepsProps {\n steps: ChatStep[];\n}\n\n/** The work an agent did for a reply, such as tool calls. Each step opens to show its detail. */\nexport function ToolSteps({ steps }: ToolStepsProps) {\n return (\n <ul className=\"sf-chat-steps\" aria-label=\"Steps\">\n {steps.map((step) => (\n <li key={step.id} data-status={step.status}>\n <details>\n <summary>\n <span className=\"sf-chat-step-mark\" aria-hidden=\"true\">\n {STEP_MARK[step.status]}\n </span>\n <span className=\"sf-chat-step-title\">{step.title || step.tool}</span>\n <span className=\"sf-chat-step-meta\">\n {STEP_WORD[step.status]}\n {step.durationMs > 0 ? ` · ${count.format(step.durationMs)} ms` : \"\"}\n </span>\n </summary>\n {step.tool && <p className=\"sf-chat-step-tool\">Tool: {step.tool}</p>}\n {step.detail && <pre tabIndex={0}>{step.detail}</pre>}\n </details>\n </li>\n ))}\n </ul>\n );\n}\n\nexport interface ActionsCardProps {\n actions: ChatActions;\n /** A press: the button's id, and the choice it belongs to when it is in one. Never called for a disabled button. */\n onPress(buttonId: string, choiceId?: string): void;\n}\n\nfunction ActionButtons({ buttons, label, onPress }: { buttons: ChatButton[]; label?: string; onPress(id: string): void }) {\n const uid = useId();\n if (buttons.length === 0) return null;\n return (\n <div className=\"sf-chat-actions-row\" role={label ? \"group\" : undefined} aria-label={label}>\n {buttons.map((button, i) => {\n const why = button.reason ? `${uid}-${i}` : undefined;\n return (\n <span key={button.id} className=\"sf-chat-actions-button\">\n <button\n type=\"button\"\n className=\"sf-button\"\n data-variant={button.variant}\n // Not `disabled`: a disabled button cannot be reached by keyboard, and then neither can its reason.\n aria-disabled={button.disabled || undefined}\n aria-label={button.ariaLabel}\n aria-describedby={why}\n title={button.reason}\n onClick={() => {\n if (!button.disabled) onPress(button.id);\n }}\n >\n {button.label}\n </button>\n {why && (\n <span id={why} className=\"sf-a2-visually-hidden\">\n {button.reason}\n </span>\n )}\n </span>\n );\n })}\n </div>\n );\n}\n\n/**\n * What a person can do about a reply, under it: a row of buttons, or several\n * alternatives one row each with buttons for the whole set after them. The\n * host decides what a press does and, once it is handled, replaces the\n * buttons with what became of it (`outcome`).\n */\nexport function ActionsCard({ actions, onPress }: ActionsCardProps) {\n const choices = actions.choices ?? [];\n return (\n <div className=\"sf-chat-actions\" role=\"group\" aria-label={actions.title || \"Actions\"} data-handled={actions.outcome !== undefined || undefined}>\n {actions.title && <p className=\"sf-chat-actions-title\">{actions.title}</p>}\n {actions.detail && <p className=\"sf-chat-actions-detail\">{actions.detail}</p>}\n {actions.outcome !== undefined ? (\n <p className=\"sf-chat-actions-outcome\" role=\"status\">\n {actions.outcome}\n </p>\n ) : (\n <>\n {choices.length > 0 && (\n <ul className=\"sf-chat-actions-choices\" aria-label=\"Choices\">\n {choices.map((choice) => (\n <li key={choice.id}>\n <p className=\"sf-chat-actions-choice\">\n <span className=\"sf-chat-actions-title\">{choice.title}</span>\n {choice.detail && <span className=\"sf-chat-actions-detail\"> · {choice.detail}</span>}\n </p>\n <ActionButtons buttons={choice.buttons} label={choice.title} onPress={(id) => onPress(id, choice.id)} />\n </li>\n ))}\n </ul>\n )}\n <ActionButtons buttons={actions.buttons ?? []} label={choices.length > 0 ? \"All choices\" : undefined} onPress={(id) => onPress(id)} />\n </>\n )}\n </div>\n );\n}\n\nexport interface MessageListProps {\n thread: ChatThread;\n catalog: Catalog;\n renderers: Record<string, ComponentRenderer>;\n onAction(action: SurfaceAction): void;\n onAnswer: UseChat[\"answer\"];\n /** Where each drawn surface stands and what went wrong with it, kept for the agent's next turn (`useChat`'s `report` and `problem`). */\n onReport?: UseChat[\"report\"];\n onProblem?: UseChat[\"problem\"];\n /** Told what a person does in a drawn component as they do it, with where. For a host that keeps its own context for an agent. */\n onContext?(note: SurfaceNote & { surfaceId: string; componentId: string }): void;\n /** A press on a button in an actions part (`ChatActions`): the part's id, the button's id, and its choice's id when it is in one. */\n onPartAction?(partId: string, actionId: string, choiceId?: string): void;\n /** Shown when the thread is empty. */\n empty?: string;\n /**\n * How an image an agent named is drawn, in its replies' Markdown and in any `Image` it draws: turns the name or address\n * it wrote into the address to load, or nothing (the description is shown). Without it, or a resolver given above\n * (`ImageResolverProvider`), no image an agent wrote is loaded. Not used for a person's own attachments (`ChatAttachment.preview`).\n */\n resolveImage?: ImageResolver;\n}\n\n/** Pictures and files a person attached to their message, as chips with a thumbnail where there is one. */\nfunction AttachedChips({ attachments }: { attachments: ChatAttachment[] }) {\n return (\n <ul className=\"sf-chat-references sf-chat-attachments\" aria-label=\"Attached files\">\n {attachments.map((one) => {\n // The preview is the host's own (a blob it made from the file), never an address a model wrote.\n const picture = one.mediaType.startsWith(\"image/\") ? safeImageAddress(one.preview) : undefined;\n return (\n <li key={one.id ?? one.name} className=\"sf-chat-reference\" data-kind=\"attachment\" data-thumbnail={picture ? true : undefined}>\n {picture ? <img className=\"sf-chat-thumbnail\" src={picture} alt=\"\" loading=\"lazy\" decoding=\"async\" /> : null}\n <span>{one.name}</span>\n </li>\n );\n })}\n </ul>\n );\n}\n\nfunction MessageView({ message, thread, catalog, renderers, onAction, onAnswer, onReport, onProblem, onContext, onPartAction }: MessageListProps & { message: ChatMessage }) {\n if (message.role === \"user\") {\n return (\n <article className=\"sf-chat-message\" data-role=\"user\">\n <span className=\"sf-a2-visually-hidden\">You said:</span>\n <p>{message.parts.map((p) => (p.kind === \"text\" ? p.text : \"\")).join(\"\")}</p>\n {message.parts.map((p, i) =>\n p.kind === \"references\" ? (\n // biome-ignore lint/suspicious/noArrayIndexKey: a message's parts do not move.\n <ul key={i} className=\"sf-chat-references\" aria-label=\"Attached\">\n {p.references.map((ref) => (\n <li key={`${ref.sourceId}/${dataRefLabel(ref)}`} className=\"sf-chat-reference\" data-kind={ref.kind}>\n {dataRefLabel(ref)}\n </li>\n ))}\n </ul>\n ) : p.kind === \"attachments\" ? (\n // biome-ignore lint/suspicious/noArrayIndexKey: a message's parts do not move.\n <AttachedChips key={i} attachments={p.attachments} />\n ) : null,\n )}\n </article>\n );\n }\n return (\n <article className=\"sf-chat-message\" data-role=\"assistant\" aria-busy={message.streaming}>\n <span className=\"sf-a2-visually-hidden\">The agent replied:</span>\n {message.parts.map((part, index) => {\n switch (part.kind) {\n case \"text\":\n return <Markdown key={index} text={part.text} />;\n case \"steps\":\n return <ToolSteps key={index} steps={part.steps} />;\n case \"surface\": {\n const surface = thread.surfaces[part.surfaceId];\n // Agent-drawn components are checked against the catalog before they are drawn.\n const key = part.surfaceId;\n return surface ? (\n <SurfaceView\n key={index}\n surface={surface}\n catalog={catalog}\n renderers={renderers}\n onAction={onAction}\n onDataChange={(data) => onReport?.(key, { data })}\n onControlsChange={(componentId, controls) => onReport?.(key, { componentId, controls })}\n onContext={(componentId, note) => {\n onReport?.(key, { componentId, note });\n onContext?.({ ...note, surfaceId: key, componentId });\n }}\n onProblem={(problem) => onProblem?.(key, problem)}\n className=\"sf-chat-surface\"\n />\n ) : null;\n }\n case \"approval\":\n return <ApprovalCard key={index} approval={part.approval} onAnswer={onAnswer} />;\n case \"actions\":\n return <ActionsCard key={index} actions={part.actions} onPress={(actionId, choiceId) => onPartAction?.(part.actions.id, actionId, choiceId)} />;\n case \"references\":\n case \"attachments\":\n // Attachments belong to what a person sent; a reply has none.\n return null;\n default:\n return (\n <p key={index} className=\"sf-chat-error\" role=\"alert\">\n {part.code === \"CANCELLED\" ? \"Stopped.\" : part.message}\n </p>\n );\n }\n })}\n {message.streaming && message.parts.length === 0 && <p className=\"sf-chat-thinking\">Working…</p>}\n {!message.streaming && message.generatedBy && <p className=\"sf-chat-by\">Answered by {message.generatedBy}</p>}\n </article>\n );\n}\n\n/**\n * The conversation so far. Replies can hold text, tool steps, approvals and\n * components the agent drew. The list follows new content while the reader\n * is at the bottom and stays put when they have scrolled up.\n */\nexport function MessageList(props: MessageListProps) {\n const { thread } = props;\n const list = useRef<HTMLDivElement>(null);\n const pinned = useRef(true);\n useEffect(() => {\n const element = list.current;\n if (element && pinned.current) element.scrollTop = element.scrollHeight;\n }, [thread]);\n const list_ = (\n <div\n ref={list}\n className=\"sf-chat-list\"\n role=\"log\"\n aria-label=\"Conversation\"\n aria-live=\"polite\"\n tabIndex={0}\n onScroll={(event) => {\n const element = event.currentTarget;\n pinned.current = element.scrollHeight - element.scrollTop - element.clientHeight < 48;\n }}\n >\n {thread.messages.length === 0 && props.empty && <div className=\"sf-chat-empty\">{props.empty}</div>}\n {thread.messages.map((message) => (\n <MessageView key={message.id} {...props} message={message} />\n ))}\n </div>\n );\n return props.resolveImage ? <ImageResolverProvider resolve={props.resolveImage}>{list_}</ImageResolverProvider> : list_;\n}\n\nexport interface SuggestionsProps {\n items: string[];\n onPick(text: string): void;\n}\n\n/** Things the person might say next, one press each. */\nexport function Suggestions({ items, onPick }: SuggestionsProps) {\n if (items.length === 0) return null;\n return (\n <div className=\"sf-chat-suggestions\" role=\"group\" aria-label=\"Suggestions\">\n {items.map((item) => (\n <button key={item} type=\"button\" className=\"sf-button\" onClick={() => onPick(item)}>\n {item}\n </button>\n ))}\n </div>\n );\n}\n\n/** How full the agent's context is, and what the conversation has cost when known. */\nexport function UsageGauge({ usage }: { usage: ChatUsage | undefined }) {\n if (!usage || usage.contextLimit <= 0) return null;\n const share = Math.min(1, usage.contextTokens / usage.contextLimit);\n return (\n <p className=\"sf-chat-usage\">\n <meter min={0} max={1} high={0.8} value={share} aria-label=\"Context used\" />\n <span>\n {Math.round(share * 100)}% of context used\n {usage.costUsd !== undefined ? ` · $${usage.costUsd.toFixed(2)}` : \"\"}\n </span>\n </p>\n );\n}\n\nexport interface ChatProps {\n /** Any agent runtime behind the AgentBackend interface. */\n agent: AgentBackend;\n /** The catalog agent-drawn components are checked against. Defaults to the analytics catalog. */\n catalog?: Catalog;\n renderers?: Record<string, ComponentRenderer>;\n agentId?: string;\n /** Limit the agent to the data in this saved context pack. */\n contextPackId?: string;\n /** Who is using the chat, from the host's sign-in; recorded on approval answers and surface events. */\n user?: ChatActor;\n /** Where to keep the conversation across reloads (`browserStorage()` from `@surfaces-ui/state`, or your own). */\n storage?: UseChatOptions[\"storage\"];\n storageKey?: string;\n /** Tables and columns attached to the message being written, when the host holds them (see `Composer`). */\n references?: DataRef[];\n onReferencesChange?(references: DataRef[]): void;\n /** The thread to open with: a saved or written conversation. Read once. */\n initialThread?: ChatThread;\n /** Told the thread after every change, so a host can save it or build from what was drawn. */\n onThreadChange?(thread: ChatThread): void;\n /**\n * Told what a person does in a drawn component as they do it (a view\n * added, a field changed, a filter set). The chat already keeps these and\n * gives them to the agent with its next turn; this is for a host that\n * wants them too.\n */\n onContext?: MessageListProps[\"onContext\"];\n /** Offered before the first message. */\n starters?: string[];\n placeholder?: string;\n /** How an image an agent named is drawn; see `MessageListProps.resolveImage`. */\n resolveImage?: ImageResolver;\n /** Turns files a person drops, pastes or picks into data or attachments; see `ComposerProps.attachFiles`. Without it there is no upload. */\n attachFiles?(files: File[]): Promise<AttachResult[]>;\n /** What the file picker offers; see `ComposerProps.accept`. */\n accept?: string;\n /** Widens the drop target beyond the composer; see `ComposerProps.dropTarget`. */\n dropTarget?: ComposerProps[\"dropTarget\"];\n /** Hands files in from outside; see `ComposerProps.handleRef`. */\n composerRef?: Ref<ComposerHandle>;\n /** The agent, model, skills and connectors a person chose, sent with each turn; with `onSettingsChange` the composer offers them. */\n settings?: ChatSettings;\n onSettingsChange?(settings: ChatSettings): void;\n /** What the agent offers (`DescribeAgents`), for the composer's menus. */\n agents?: AgentInfo[];\n /** Where models run, when the host can reach several: the Model menu groups models by provider. */\n providers?: ChatProvider[];\n onManageProviders?(): void;\n /** Shown when the thread is empty. */\n empty?: string;\n /** Height of the whole chat. A number is px. Defaults to 640. */\n height?: number | string;\n className?: string;\n}\n\n/**\n * A complete chat: the conversation, suggestions and the composer. Agent\n * replies stream in as Markdown, with tool steps, approvals and any catalog\n * component (charts, tables, pivots, model diagrams, decision cards) drawn\n * inline. Data components need a DataSourceProvider above the chat.\n */\nexport function Chat(props: ChatProps) {\n const catalog = props.catalog ?? analyticsCatalog;\n const renderers = props.renderers ?? lazyAnalyticsRenderers;\n const chat = useChat(props.agent, { catalog, agentId: props.agentId, contextPackId: props.contextPackId, user: props.user, storage: props.storage, storageKey: props.storageKey, initial: props.initialThread, settings: props.settings });\n const { thread } = chat;\n // Told on a change of thread only: a host passing a new function each render must not be told again (and set state in a loop).\n const onThreadChange = useRef(props.onThreadChange);\n onThreadChange.current = props.onThreadChange;\n useEffect(() => onThreadChange.current?.(thread), [thread]);\n const suggestions = thread.messages.length === 0 ? (props.starters ?? []) : thread.status === \"idle\" ? thread.suggestions : [];\n return (\n <section className={[\"sf-chat\", props.className].filter(Boolean).join(\" \")} style={{ height: props.height ?? 640 }} aria-label=\"Chat\">\n <MessageList thread={thread} catalog={catalog} renderers={renderers} onAction={chat.act} onAnswer={chat.answer} onReport={chat.report} onProblem={chat.problem} onContext={props.onContext} empty={props.empty} resolveImage={props.resolveImage} />\n <Suggestions items={suggestions} onPick={(text) => chat.send(text)} />\n <Composer\n agents={props.agents}\n settings={props.settings}\n onSettingsChange={props.onSettingsChange}\n providers={props.providers}\n onManageProviders={props.onManageProviders}\n references={props.references}\n onReferencesChange={props.onReferencesChange}\n attachFiles={props.attachFiles}\n accept={props.accept}\n dropTarget={props.dropTarget}\n handleRef={props.composerRef}\n onSend={chat.send} onStop={chat.stop} streaming={thread.status === \"streaming\"} placeholder={thread.status === \"waiting\" ? \"Answer above, or type to say something else\" : props.placeholder} />\n <UsageGauge usage={thread.usage} />\n </section>\n );\n}\n"]}
|
package/dist/ChatComposer.d.ts
CHANGED
|
@@ -1,20 +1,40 @@
|
|
|
1
1
|
import { type DataRef } from "@surfaces-ui/components";
|
|
2
2
|
import type { AgentInfo, ToolConnector } from "@surfaces-ui/proto";
|
|
3
|
+
import { type ReactNode, type Ref, type RefObject } from "react";
|
|
3
4
|
import { type DataPanelProps } from "./DataPanel.js";
|
|
4
5
|
import { type ChatPanel, type ChatProvider } from "./selectors.js";
|
|
5
6
|
import type { SpeechAdapter } from "./speech.js";
|
|
7
|
+
import type { ChatAttachment } from "./thread.js";
|
|
6
8
|
import type { ChatSettings } from "./useChat.js";
|
|
7
9
|
import { type VoiceReply } from "./voice.js";
|
|
8
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* What became of one file a person attached. Exactly one of `ref`, `attachment` and `taken` says it was used; a result
|
|
12
|
+
* with none of them (and no `error`) reads as failed, "This file cannot be used as data."
|
|
13
|
+
*/
|
|
9
14
|
export interface AttachResult {
|
|
10
15
|
file: File;
|
|
11
|
-
/** The table or file it became, by name. */
|
|
16
|
+
/** The table or file of data it became, by name. */
|
|
12
17
|
ref?: DataRef;
|
|
18
|
+
/**
|
|
19
|
+
* It was attached as something other than data, such as a picture: the composer shows a chip with a thumbnail (when
|
|
20
|
+
* `preview` is an image address) and gives the attachment to `onSend`.
|
|
21
|
+
*/
|
|
22
|
+
attachment?: ChatAttachment;
|
|
23
|
+
/** The host took the file and handled it elsewhere: no chip and no error. */
|
|
24
|
+
taken?: boolean;
|
|
13
25
|
/** Why it could not be used. */
|
|
14
26
|
error?: string;
|
|
15
27
|
}
|
|
28
|
+
/** What a host can do with a mounted composer, through `handleRef`. */
|
|
29
|
+
export interface ComposerHandle {
|
|
30
|
+
/** 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. */
|
|
31
|
+
attach(files: File[]): Promise<void>;
|
|
32
|
+
/** Puts the cursor in the box. */
|
|
33
|
+
focus(): void;
|
|
34
|
+
}
|
|
16
35
|
export interface ComposerProps {
|
|
17
|
-
|
|
36
|
+
/** Called with the message, the data attached to it and, only when there are some, its attachments (`AttachResult.attachment`). */
|
|
37
|
+
onSend(text: string, references: DataRef[], attachments?: ChatAttachment[]): void;
|
|
18
38
|
/** Shown in place of Send while a reply is streaming. */
|
|
19
39
|
onStop?(): void;
|
|
20
40
|
streaming?: boolean;
|
|
@@ -30,8 +50,26 @@ export interface ComposerProps {
|
|
|
30
50
|
*/
|
|
31
51
|
references?: DataRef[];
|
|
32
52
|
onReferencesChange?(references: DataRef[]): void;
|
|
33
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Pictures and other files attached to the message being written that are not data. Give it with `onAttachmentsChange`
|
|
55
|
+
* to hold them yourself; otherwise the composer keeps them.
|
|
56
|
+
*/
|
|
57
|
+
attachments?: ChatAttachment[];
|
|
58
|
+
onAttachmentsChange?(attachments: ChatAttachment[]): void;
|
|
59
|
+
/** 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. */
|
|
34
60
|
attachFiles?(files: File[]): Promise<AttachResult[]>;
|
|
61
|
+
/** 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. */
|
|
62
|
+
accept?: string;
|
|
63
|
+
/** Replaces the line under "Upload files…" in the + menu. Default: "Any file; those that can be read become tables". */
|
|
64
|
+
uploadDetail?: ReactNode;
|
|
65
|
+
/**
|
|
66
|
+
* Widens where files can be dropped from the composer's own form to this element (a panel around the chat), given as
|
|
67
|
+
* the element or a ref to it. Files and tables dropped on it are handled as if dropped on the composer, and the composer
|
|
68
|
+
* is highlighted while they are over it.
|
|
69
|
+
*/
|
|
70
|
+
dropTarget?: HTMLElement | RefObject<HTMLElement | null> | null;
|
|
71
|
+
/** Gives the host `attach(files)` and `focus()`, to hand in files from anywhere (its own drop handling, a paste elsewhere). */
|
|
72
|
+
handleRef?: Ref<ComposerHandle>;
|
|
35
73
|
/** Browsing tables and files from the composer ("Add data"). Without `onManage`, it opens in a popover. */
|
|
36
74
|
browse?: Omit<DataPanelProps, "onAttach">;
|
|
37
75
|
/** Agents with their models, skills and connectors (`DescribeAgents`). Each menu shows only when there is something to choose. */
|