@nexface/chat 0.1.1-alpha.8 → 0.1.1-alpha.9

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 +1 @@
1
- {"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,cAAc,GAAG,uBAAuB,CAAC;AAWtD,MAAM,kBAAkB,GAAG,2BAA2B,CAAC;AACvD,MAAM,MAAM,GAAG,CAAC,KAAc,EAAoC,EAAE,CAClE,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAEvE,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACjC,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC;IACjE,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC;IAClE,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC;WAC/D,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,KAAK,QAAQ;WACtC,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,KAAK,SAAS,IAAI,OAAO,KAAK,CAAC,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC;AAC1F,CAAC;AACD,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,EAAE,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;WACjF,SAA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MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI;YAC1E,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,aAAa,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa;gBAC1D,CAAC,CAAC,8BAA8B;gBAChC,CAAC,CAAC,UAAU,IAAI,CAAC,IAAI,QAAQ,IAAI,CAAC,SAAS,QAAQ,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,YAAY,IAAI,kBAAkB,EAAE,CAC9G,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACb,OAAO,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;IACvE,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { AgentInputContent, AgentMessage } from \"@nexface/agent\";\nimport type { UIMessage, UIMessagePart } from \"./react.js\";\nimport type { Attachment } from \"./attachments.js\";\n\nexport const chatStorageKey = \"nexface:chat:sessions\";\n\ninterface StoredSession {\n id: string;\n title?: string;\n messages: UIMessage[];\n}\ninterface StoredChat {\n sessions: StoredSession[];\n activeSessionId: string;\n}\nconst interruptedMessage = \"页面已刷新,之前的操作未恢复,执行结果请重新核实。\";\nconst record = (value: unknown): value is Record<string, unknown> =>\n value !== null && typeof value === \"object\" && !Array.isArray(value);\n\nfunction isContent(value: unknown): value is AgentInputContent {\n if (!record(value)) return false;\n if (value.type === \"text\") return typeof value.text === \"string\";\n if (value.type !== \"image\" || !record(value.source)) return false;\n return (value.source.type === \"data\" || value.source.type === \"url\")\n && typeof value.source.value === \"string\"\n && (value.source.mimeType === undefined || typeof value.source.mimeType === \"string\");\n}\nfunction isAttachment(value: unknown): value is Attachment {\n return record(value) && typeof value.id === \"string\" && typeof value.name === \"string\"\n && isContent(value.content) && (value.preview === undefined || typeof value.preview === \"string\");\n}\nfunction isPart(value: unknown): value is UIMessagePart {\n if (!record(value)) return false;\n if (value.type === \"text\") return typeof value.text === \"string\";\n return value.type === \"tool\" && typeof value.toolCallId === \"string\"\n && typeof value.name === \"string\" && typeof value.arguments === \"string\"\n && [\"result\", \"parseError\", \"errorMessage\"].every((key) => value[key] === undefined || typeof value[key] === \"string\")\n && (value.isError === undefined || typeof value.isError === \"boolean\");\n}\nfunction isMessage(value: unknown): value is UIMessage {\n return record(value) && typeof value.id === \"string\" && (value.role === \"user\" || value.role === \"assistant\")\n && Array.isArray(value.parts) && value.parts.every(isPart)\n && (value.attachments === undefined || Array.isArray(value.attachments) && value.attachments.every(isAttachment))\n && (value.revisionOf === undefined || typeof value.revisionOf === \"string\")\n && (value.state === undefined || [\"running\", \"success\", \"error\"].includes(String(value.state)));\n}\nfunction restoreMessage(message: UIMessage): UIMessage {\n const unfinished = message.state === \"running\" || message.parts.some((part) => part.type === \"tool\" && part.result === undefined && !part.isError);\n return {\n id: message.id, role: message.role,\n parts: message.parts.map((part) => part.type === \"tool\" && part.result === undefined && !part.isError\n ? { ...part, isError: true, errorMessage: interruptedMessage, result: interruptedMessage }\n : part),\n ...(message.attachments ? { attachments: message.attachments } : {}),\n ...(message.revisionOf ? { revisionOf: message.revisionOf } : {}),\n ...(unfinished ? { state: \"error\" as const } : message.state ? { state: message.state } : {}),\n ...(unfinished && !message.parts.some((part) => part.type === \"tool\")\n ? { parts: [...message.parts, { type: \"text\" as const, text: interruptedMessage }] } : {}),\n };\n}\n\nexport interface ChatStorageVersion { value: string | null }\n\nexport function readChatStorage(key: string, version?: ChatStorageVersion): StoredChat | undefined {\n try {\n const raw = localStorage.getItem(key);\n if (version) version.value = raw;\n const value: unknown = JSON.parse(raw ?? \"null\");\n if (!record(value) || value.version !== 1 || !Array.isArray(value.sessions) || !value.sessions.length) return;\n const sessions: StoredSession[] = [];\n for (const session of value.sessions) {\n if (!record(session) || typeof session.id !== \"string\" || !session.id\n || (session.title !== undefined && typeof session.title !== \"string\")\n || !Array.isArray(session.messages) || !session.messages.every(isMessage)\n || sessions.some((existing) => existing.id === session.id)) return;\n sessions.push({ id: session.id, ...(session.title ? { title: session.title } : {}), messages: session.messages.map(restoreMessage) });\n }\n const activeSessionId = sessions.find((session) => session.id === value.activeSessionId)?.id ?? sessions[0]!.id;\n return { sessions, activeSessionId };\n } catch {\n return undefined;\n }\n}\n\nexport function writeChatStorage(key: string, state: StoredChat, version: ChatStorageVersion): \"saved\" | \"unchanged\" | \"conflict\" | \"unavailable\" {\n try {\n const next = JSON.stringify({\n version: 1,\n activeSessionId: state.activeSessionId,\n sessions: state.sessions.map(({ id, title, messages }) => ({ id, title, messages })),\n });\n if (next === version.value) return \"unchanged\";\n if (localStorage.getItem(key) !== version.value) return \"conflict\";\n localStorage.setItem(key, next);\n version.value = next;\n return \"saved\";\n } catch {\n // Storage restrictions or quota exhaustion must not break the active chat.\n return \"unavailable\";\n }\n}\n\nexport function conversationFromMessages(messages: readonly UIMessage[]): AgentMessage[] {\n // Restore conversation content only. Runtime catalogs, snapshots, approvals and Skills belong to the new page.\n return messages.map((message): AgentMessage => {\n if (message.role === \"user\") {\n const text = message.parts.flatMap((part) => part.type === \"text\" ? [part.text] : []).join(\"\\n\");\n return { id: message.id, role: \"user\", content: message.attachments?.length\n ? [{ type: \"text\", text }, ...message.attachments.map((attachment) => attachment.content)] : text };\n }\n const content = message.parts.map((part) => part.type === \"text\" ? part.text\n : part.name === \"getSnapshot\" || part.name === \"executeCode\"\n ? \"之前调用了页面自动化工具;页面已刷新,需要重新观察页面。\"\n : `历史工具记录 ${part.name}\\n输入:${part.arguments}\\n结果:${part.result ?? part.errorMessage ?? interruptedMessage}`,\n ).join(\"\\n\");\n return { id: message.id, role: \"assistant\", content, toolCalls: [] };\n });\n}\n"]}
1
+ {"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAEA,OAAO,E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C,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI;YAC1E,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,aAAa,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa;gBAC1D,CAAC,CAAC,8BAA8B;gBAChC,CAAC,CAAC,UAAU,IAAI,CAAC,IAAI,QAAQ,IAAI,CAAC,SAAS,QAAQ,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,YAAY,IAAI,kBAAkB,EAAE,CAC9G,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACb,OAAO,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;IACvE,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { AgentInputContent, AgentMessage } from \"@nexface/agent\";\nimport type { UIMessage, UIMessagePart } from \"./react.js\";\nimport { attachmentContent, type Attachment } from \"./attachments.js\";\n\nexport const chatStorageKey = \"nexface:chat:sessions\";\n\ninterface StoredSession {\n id: string;\n title?: string;\n messages: UIMessage[];\n}\ninterface StoredChat {\n sessions: StoredSession[];\n activeSessionId: string;\n}\nconst interruptedMessage = \"页面已刷新,之前的操作未恢复,执行结果请重新核实。\";\nconst record = (value: unknown): value is Record<string, unknown> =>\n value !== null && typeof value === \"object\" && !Array.isArray(value);\n\nfunction isContent(value: unknown): value is AgentInputContent {\n if (!record(value)) return false;\n if (value.type === \"text\") return typeof value.text === \"string\";\n if (value.type !== \"image\" || !record(value.source)) return false;\n return (value.source.type === \"data\" || value.source.type === \"url\")\n && typeof value.source.value === \"string\"\n && (value.source.mimeType === undefined || typeof value.source.mimeType === \"string\");\n}\nfunction isAttachment(value: unknown): value is Attachment {\n return record(value) && typeof value.id === \"string\" && typeof value.name === \"string\"\n && (isContent(value.content) || Array.isArray(value.content) && value.content.length > 0 && value.content.every(isContent))\n && (value.preview === undefined || typeof value.preview === \"string\");\n}\nfunction isPart(value: unknown): value is UIMessagePart {\n if (!record(value)) return false;\n if (value.type === \"text\") return typeof value.text === \"string\";\n return value.type === \"tool\" && typeof value.toolCallId === \"string\"\n && typeof value.name === \"string\" && typeof value.arguments === \"string\"\n && [\"result\", \"parseError\", \"errorMessage\"].every((key) => value[key] === undefined || typeof value[key] === \"string\")\n && (value.isError === undefined || typeof value.isError === \"boolean\");\n}\nfunction isMessage(value: unknown): value is UIMessage {\n return record(value) && typeof value.id === \"string\" && (value.role === \"user\" || value.role === \"assistant\")\n && Array.isArray(value.parts) && value.parts.every(isPart)\n && (value.attachments === undefined || Array.isArray(value.attachments) && value.attachments.every(isAttachment))\n && (value.revisionOf === undefined || typeof value.revisionOf === \"string\")\n && (value.state === undefined || [\"running\", \"success\", \"error\"].includes(String(value.state)));\n}\nfunction restoreMessage(message: UIMessage): UIMessage {\n const unfinished = message.state === \"running\" || message.parts.some((part) => part.type === \"tool\" && part.result === undefined && !part.isError);\n return {\n id: message.id, role: message.role,\n parts: message.parts.map((part) => part.type === \"tool\" && part.result === undefined && !part.isError\n ? { ...part, isError: true, errorMessage: interruptedMessage, result: interruptedMessage }\n : part),\n ...(message.attachments ? { attachments: message.attachments } : {}),\n ...(message.revisionOf ? { revisionOf: message.revisionOf } : {}),\n ...(unfinished ? { state: \"error\" as const } : message.state ? { state: message.state } : {}),\n ...(unfinished && !message.parts.some((part) => part.type === \"tool\")\n ? { parts: [...message.parts, { type: \"text\" as const, text: interruptedMessage }] } : {}),\n };\n}\n\nexport interface ChatStorageVersion { value: string | null }\n\nexport function readChatStorage(key: string, version?: ChatStorageVersion): StoredChat | undefined {\n try {\n const raw = localStorage.getItem(key);\n if (version) version.value = raw;\n const value: unknown = JSON.parse(raw ?? \"null\");\n if (!record(value) || value.version !== 1 || !Array.isArray(value.sessions) || !value.sessions.length) return;\n const sessions: StoredSession[] = [];\n for (const session of value.sessions) {\n if (!record(session) || typeof session.id !== \"string\" || !session.id\n || (session.title !== undefined && typeof session.title !== \"string\")\n || !Array.isArray(session.messages) || !session.messages.every(isMessage)\n || sessions.some((existing) => existing.id === session.id)) return;\n sessions.push({ id: session.id, ...(session.title ? { title: session.title } : {}), messages: session.messages.map(restoreMessage) });\n }\n const activeSessionId = sessions.find((session) => session.id === value.activeSessionId)?.id ?? sessions[0]!.id;\n return { sessions, activeSessionId };\n } catch {\n return undefined;\n }\n}\n\nexport function writeChatStorage(key: string, state: StoredChat, version: ChatStorageVersion): \"saved\" | \"unchanged\" | \"conflict\" | \"unavailable\" {\n try {\n const next = JSON.stringify({\n version: 1,\n activeSessionId: state.activeSessionId,\n sessions: state.sessions.map(({ id, title, messages }) => ({ id, title, messages })),\n });\n if (next === version.value) return \"unchanged\";\n if (localStorage.getItem(key) !== version.value) return \"conflict\";\n localStorage.setItem(key, next);\n version.value = next;\n return \"saved\";\n } catch {\n // Storage restrictions or quota exhaustion must not break the active chat.\n return \"unavailable\";\n }\n}\n\nexport function conversationFromMessages(messages: readonly UIMessage[]): AgentMessage[] {\n // Restore conversation content only. Runtime catalogs, snapshots, approvals and Skills belong to the new page.\n return messages.map((message): AgentMessage => {\n if (message.role === \"user\") {\n const text = message.parts.flatMap((part) => part.type === \"text\" ? [part.text] : []).join(\"\\n\");\n return { id: message.id, role: \"user\", content: message.attachments?.length\n ? [{ type: \"text\", text }, ...message.attachments.flatMap(attachmentContent)] : text };\n }\n const content = message.parts.map((part) => part.type === \"text\" ? part.text\n : part.name === \"getSnapshot\" || part.name === \"executeCode\"\n ? \"之前调用了页面自动化工具;页面已刷新,需要重新观察页面。\"\n : `历史工具记录 ${part.name}\\n输入:${part.arguments}\\n结果:${part.result ?? part.errorMessage ?? interruptedMessage}`,\n ).join(\"\\n\");\n return { id: message.id, role: \"assistant\", content, toolCalls: [] };\n });\n}\n"]}
package/dist/styles.css CHANGED
@@ -1,22 +1,24 @@
1
+ /* assistant-ui's neutral thread composition, scoped for embedding in host apps. */
1
2
  .nexface-chat {
2
- --_accent: var(--nexface-chat-accent, #27272a);
3
- --_hover: var(--nexface-chat-accent-hover, #404044);
3
+ --_accent: var(--nexface-chat-accent, #18181b);
4
+ --_hover: var(--nexface-chat-accent-hover, #3f3f46);
4
5
  --_on-accent: var(--nexface-chat-on-accent, #fff);
5
- --_text: var(--nexface-chat-text, #202024);
6
- --_muted: var(--nexface-chat-muted-text, #777780);
6
+ --_text: var(--nexface-chat-text, #18181b);
7
+ --_muted: var(--nexface-chat-muted-text, #71717a);
7
8
  --_background: var(--nexface-chat-background, #fff);
8
- --_surface: var(--nexface-chat-surface, #f6f6f8);
9
- --_border: var(--nexface-chat-border, #e5e5eb);
9
+ --_surface: var(--nexface-chat-surface, #f4f4f5);
10
+ --_border: var(--nexface-chat-border, #e4e4e7);
10
11
  color: var(--_text); font: 14px/1.65 var(--nexface-chat-font-family, "PingFang SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);
11
- position: relative; min-width: 0; isolation: isolate; box-sizing: border-box;
12
- border: 1px solid var(--_border); border-radius: 12px;
12
+ position: relative; min-width: 0; isolation: isolate; border: 1px solid var(--_border); border-radius: 16px;
13
13
  }
14
- .nexface-chat *, .nexface-chat *::before, .nexface-chat *::after { box-sizing: border-box; }
15
- .nexface-chat button, .nexface-chat input, .nexface-chat textarea { font: inherit; color: inherit; }
14
+ .nexface-chat, .nexface-chat *, .nexface-chat *::before, .nexface-chat *::after { box-sizing: border-box; }
15
+ .nexface-chat :is(button, input, textarea) { font: inherit; color: inherit; }
16
16
  .nexface-chat button { cursor: pointer; border: 1px solid var(--_border); background: var(--_background); border-radius: 8px; padding: 5px 12px; }
17
17
  .nexface-chat button:hover:not(:disabled) { background: var(--_surface); }
18
18
  .nexface-chat button:disabled { opacity: .4; cursor: not-allowed; }
19
19
  .nexface-chat :focus-visible { outline: 2px solid var(--_accent); outline-offset: 3px; }
20
+ .nexface-chat svg { width: 18px; height: 18px; flex-shrink: 0; }
21
+ .nexface-chat :is(small, .nexface-chat__muted) { color: var(--_muted); }
20
22
  .nexface-chat[data-layout="floating"] { position: fixed; right: 24px; bottom: 24px; z-index: 10000; }
21
23
  .nexface-chat[data-layout="floating"][data-side="left"] { left: 24px; right: auto; }
22
24
  .nexface-chat[data-layout="floating"] .nexface-chat__panel { width: min(546px, calc(100vw - 32px)); height: min(760px, calc(100dvh - 48px)); box-shadow: 0 8px 40px #00000015; }
@@ -27,64 +29,56 @@
27
29
  .nexface-chat[data-fullscreen] .nexface-chat__panel { width: 100%; height: 100%; border-radius: 0; }
28
30
  .nexface-chat__panel { height: 100%; min-height: 0; display: flex; flex-direction: column; background: var(--_background); border-radius: inherit; position: relative; }
29
31
  .nexface-chat__header { min-height: 64px; padding: 12px 20px; display: flex; align-items: center; gap: 12px; }
30
- .nexface-chat__brand { display: flex; align-items: center; gap: 5px; min-width: 0; flex: 1; white-space: nowrap; }
31
- .nexface-chat__brand strong { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; }
32
- .nexface-chat__avatar { width: 32px; height: 32px; flex: 0 0 32px; display: grid; place-items: center; border-radius: 50%; background: var(--_surface); margin-right: 2px; overflow: hidden; }
32
+ .nexface-chat__brand { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1; white-space: nowrap; }
33
+ .nexface-chat__brand strong { font-size: 15px; overflow: hidden; text-overflow: ellipsis; }
34
+ .nexface-chat__avatar { width: 32px; height: 32px; flex-shrink: 0; display: grid; place-items: center; border-radius: 50%; background: var(--_surface); overflow: hidden; }
33
35
  .nexface-chat__avatar img { width: 100%; height: 100%; object-fit: cover; }
34
- .nexface-chat__muted, .nexface-chat small { color: var(--_muted); }
35
- .nexface-chat__header-actions { display: flex; gap: 5px; }
36
+ .nexface-chat :is(.nexface-chat__header-actions, .nexface-chat__message-actions, .nexface-chat__attachments) { display: flex; gap: 6px; }
36
37
  .nexface-chat .nexface-chat__icon-button { border: 0; padding: 0; width: 28px; height: 28px; display: inline-grid; place-items: center; color: var(--_muted); flex-shrink: 0; }
37
- .nexface-chat svg { width: 18px; height: 18px; flex-shrink: 0; }
38
38
  .nexface-chat__body { flex: 1; display: flex; min-height: 0; position: relative; }
39
39
  .nexface-chat__thread { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; }
40
- .nexface-chat__messages { flex: 1; overflow: auto; padding: 12px 32px 20px; overscroll-behavior: contain; scrollbar-width: thin; }
40
+ .nexface-chat__messages { flex: 1; overflow: auto; padding: 16px 24px; overscroll-behavior: contain; scrollbar-width: thin; }
41
41
  .nexface-chat__messages:has(.nexface-chat__welcome) { display: flex; flex-direction: column; justify-content: center; }
42
- .nexface-chat__welcome { max-width: 480px; margin: 0 auto; width: 100%; }
43
- .nexface-chat__welcome h2 { font-size: 20px; font-weight: 500; line-height: 1.5; margin: 0 0 8px; }
44
- .nexface-chat__welcome p { color: var(--_muted); font-size: 13px; margin: 0; }
45
- .nexface-chat__suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
46
- .nexface-chat__suggestions button { font-size: 12px; border-radius: 10px; }
47
- .nexface-chat__message { margin: 0 0 22px; min-width: 0; overflow-wrap: anywhere; }
48
- .nexface-chat__message--user { display: flex; flex-direction: column; align-items: flex-end; margin-bottom: 32px; }
49
- .nexface-chat__message--user .nexface-chat__bubble { background: var(--_surface); border-radius: 0 20px 20px 20px; padding: 10px 16px; max-width: 85%; white-space: pre-wrap; }
50
- .nexface-chat__bubble > p { margin: 0 0 12px; }
51
- .nexface-chat__bubble > p:last-child { margin-bottom: 0; }
42
+ .nexface-chat__welcome { max-width: 480px; margin: auto; width: 100%; }
43
+ .nexface-chat__welcome h2 { font-size: 22px; font-weight: 600; line-height: 1.4; margin: 0 0 8px; }
44
+ .nexface-chat__welcome p { color: var(--_muted); margin: 0; }
45
+ .nexface-chat__suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
46
+ .nexface-chat__suggestions button { font-size: 13px; border-radius: 16px; padding: 8px 14px; }
47
+ .nexface-chat__message { margin: 0 0 24px; min-width: 0; overflow-wrap: anywhere; }
48
+ .nexface-chat__message--user { display: flex; flex-direction: column; align-items: flex-end; }
49
+ .nexface-chat__message--user .nexface-chat__bubble { background: var(--_surface); border-radius: 20px; padding: 10px 16px; max-width: 85%; }
50
+ .nexface-chat__bubble p { margin: 0 0 12px; white-space: pre-wrap; }
51
+ .nexface-chat__bubble p:last-child { margin-bottom: 0; }
52
52
  .nexface-chat__bubble pre { background: var(--_surface); padding: 12px; overflow: auto; border-radius: 8px; font-size: 12px; white-space: pre-wrap; }
53
53
  .nexface-chat__bubble table { display: block; overflow: auto; border-collapse: collapse; }
54
- .nexface-chat__bubble th, .nexface-chat__bubble td { border: 1px solid var(--_border); padding: 6px 10px; }
55
- .nexface-chat__bubble a { color: var(--_accent); text-decoration: underline; }
56
- .nexface-chat__message-actions { display: flex; gap: 4px; margin-top: 5px; }
57
- .nexface-chat__message-actions svg { width: 14px; height: 14px; }
54
+ .nexface-chat__bubble :is(th, td) { border: 1px solid var(--_border); padding: 6px 10px; }
55
+ .nexface-chat__bubble a { color: var(--_accent); }
58
56
  .nexface-chat__tool-summary { color: var(--_muted); font-weight: 600; margin: 12px 0; }
59
57
  .nexface-chat__tool { margin: 10px 0; }
60
- .nexface-chat__tool summary { cursor: pointer; list-style: none; color: var(--_muted); }
61
- .nexface-chat__tool summary::-webkit-details-marker { display: none; }
62
- .nexface-chat__tool summary span { margin-left: 5px; display: inline-block; }
63
- .nexface-chat__tool[open] summary span { transform: rotate(90deg); }
64
- .nexface-chat__tool > strong, .nexface-chat__tool > small { display: block; }
65
- .nexface-chat__tool[data-error] > small { color: #b42318; }
66
- .nexface-chat__confirmation { margin: 20px 0; padding: 16px; background: var(--_surface); border-radius: 16px; }
58
+ .nexface-chat__tool summary { cursor: pointer; color: var(--_muted); }
59
+ .nexface-chat__tool > :is(strong, small) { display: block; }
60
+ .nexface-chat__confirmation, .nexface-chat__editor { margin: 16px 0; padding: 16px; background: var(--_surface); border-radius: 16px; }
67
61
  .nexface-chat__confirmation p { color: var(--_muted); margin: 3px 0; }
68
62
  .nexface-chat__confirmation button { margin: 10px 8px 0 0; }
69
- .nexface-chat__thinking { color: #c8c8d0; letter-spacing: 3px; }
70
- .nexface-chat__composer-area { position: relative; padding: 12px 18px 16px; background: var(--_background); }
71
- .nexface-chat__composer { border: 1px solid var(--_border); box-shadow: 0 1px 3px #00000008; border-radius: 24px; padding: 14px 16px 12px; }
72
- .nexface-chat .nexface-chat__composer textarea { width: 100%; min-height: 48px; max-height: 180px; border: 0; resize: none; background: transparent; outline: none; line-height: 24px; padding: 0; }
63
+ .nexface-chat__thinking { color: var(--_muted); letter-spacing: 3px; }
64
+ .nexface-chat__composer-area { position: relative; padding: 12px 18px 16px; }
65
+ .nexface-chat__composer { border: 1px solid var(--_border); border-radius: 24px; padding: 12px 16px; box-shadow: 0 2px 6px #00000008; }
66
+ .nexface-chat :is(.nexface-chat__composer, .nexface-chat__editor) textarea { display: block; width: 100%; border: 0; resize: none; background: transparent; outline: none; padding: 0; }
73
67
  .nexface-chat__composer textarea::placeholder { color: var(--_muted); }
74
68
  .nexface-chat__composer-toolbar { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
75
69
  .nexface-chat__composer-toolbar > span { flex: 1; }
76
70
  .nexface-chat .nexface-chat__primary { background: var(--_accent); color: var(--_on-accent); border-color: transparent; }
77
71
  .nexface-chat .nexface-chat__primary:hover:not(:disabled) { background: var(--_hover); }
78
- .nexface-chat .nexface-chat__send { border-radius: 50%; width: 30px; height: 30px; padding: 0; display: inline-grid; place-items: center; }
72
+ .nexface-chat .nexface-chat__send { border-radius: 50%; width: 32px; height: 32px; padding: 0; display: inline-grid; place-items: center; }
79
73
  .nexface-chat__stop { width: 10px; height: 10px; background: currentColor; border-radius: 2px; }
80
74
  .nexface-chat .nexface-chat__scroll-bottom { position: absolute; top: -34px; left: calc(50% - 16px); width: 32px; height: 32px; border-radius: 50%; padding: 0; display: grid; place-items: center; box-shadow: 0 2px 12px #00000008; }
81
- .nexface-chat__attachments { display: flex; flex-wrap: wrap; gap: 6px; }
82
- .nexface-chat__attachment { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; border: 1px solid var(--_border); border-radius: 8px; padding: 5px; font-size: 12px; }
75
+ .nexface-chat .nexface-chat__scroll-bottom:disabled { display: none; }
76
+ .nexface-chat__attachments { flex-wrap: wrap; }
77
+ .nexface-chat__attachment { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; border: 1px solid var(--_border); border-radius: 12px; padding: 6px; font-size: 12px; }
83
78
  .nexface-chat__attachment img { width: 48px; height: 48px; object-fit: contain; }
84
79
  .nexface-chat__attachment span { overflow: hidden; text-overflow: ellipsis; }
85
80
  .nexface-chat__notice { font-size: 12px; padding: 4px; color: var(--_muted); }
86
81
  .nexface-chat__sidebar { position: relative; flex: 0 0 var(--nexface-chat-sidebar-width); width: var(--nexface-chat-sidebar-width); background: var(--_surface); padding: 12px; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
87
- .nexface-chat__sidebar > small { margin-top: 12px; }
88
82
  .nexface-chat__session { display: flex; align-items: center; position: relative; border-radius: 8px; }
89
83
  .nexface-chat__session[data-active] { background: var(--_background); }
90
84
  .nexface-chat__session > button { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; border: 0; background: transparent; }
@@ -93,23 +87,19 @@
93
87
  .nexface-chat__session-menu button { text-align: left; border: 0; }
94
88
  .nexface-chat__clear-all { margin-top: auto; }
95
89
  .nexface-chat .nexface-chat__danger { color: #b42318; }
96
- .nexface-chat .nexface-chat__danger:hover:not(:disabled) { background: #fff1f0; }
97
90
  .nexface-chat .nexface-chat__danger-action { color: #fff; background: #b42318; border-color: transparent; }
98
- .nexface-chat .nexface-chat__danger-action:hover:not(:disabled) { background: #912018; }
99
91
  .nexface-chat__resizer { position: absolute; top: 0; bottom: 0; left: -3px; width: 6px; cursor: col-resize; touch-action: none; z-index: 3; }
100
92
  .nexface-chat[data-side="left"] > .nexface-chat__panel > .nexface-chat__resizer, .nexface-chat__sidebar > .nexface-chat__resizer { left: auto; right: -3px; }
101
93
  .nexface-chat__backdrop { position: absolute; inset: 0; background: #00000030; display: grid; place-items: center; z-index: 5; border-radius: inherit; padding: 20px; }
102
94
  .nexface-chat__dialog { width: min(360px, 100%); background: var(--_background); padding: 20px; border-radius: 16px; }
103
95
  .nexface-chat__dialog h3 { margin: 0; }
104
- .nexface-chat__dialog p { color: var(--_muted); }
105
96
  .nexface-chat__dialog input { width: 100%; border: 1px solid var(--_border); border-radius: 6px; padding: 6px; background: var(--_background); }
106
- .nexface-chat__dialog footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
107
- .nexface-chat__trigger { display: flex; align-items: center; gap: 8px; }
97
+ .nexface-chat__dialog footer, .nexface-chat__editor-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
98
+ .nexface-chat__editor { width: 100%; }
108
99
  @media (max-width: 600px) {
109
100
  .nexface-chat__header { padding: 10px 12px; gap: 4px; }
110
101
  .nexface-chat__brand .nexface-chat__muted { display: none; }
111
102
  .nexface-chat__header-actions { gap: 0; }
112
- .nexface-chat__messages { padding: 12px 20px; }
113
103
  .nexface-chat__composer-area { padding: 10px; }
114
104
  .nexface-chat__sidebar { position: absolute; inset: 0 auto 0 0; z-index: 4; max-width: 85%; box-shadow: 4px 0 12px #00000010; }
115
105
  .nexface-chat__resizer { display: none; }
@@ -0,0 +1 @@
1
+ export declare function getToolResultError(content: string): string | undefined;
@@ -0,0 +1,12 @@
1
+ export function getToolResultError(content) {
2
+ try {
3
+ const error = JSON.parse(content)?.error;
4
+ if (typeof error === "string")
5
+ return error;
6
+ if (error && typeof error === "object" && "message" in error && typeof error.message === "string")
7
+ return error.message;
8
+ }
9
+ catch { /* Tool results may contain plain text. */ }
10
+ return undefined;
11
+ }
12
+ //# sourceMappingURL=tool-result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-result.js","sourceRoot":"","sources":["../src/tool-result.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,kBAAkB,CAAC,OAAe;IAChD,IAAI,CAAC;QACH,MAAM,KAAK,GAAY,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC;QAClD,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC;QAC5C,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,SAAS,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC,OAAO,CAAC;IAC1H,CAAC;IAAC,MAAM,CAAC,CAAC,0CAA0C,CAAC,CAAC;IACtD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["export function getToolResultError(content: string): string | undefined {\n try {\n const error: unknown = JSON.parse(content)?.error;\n if (typeof error === \"string\") return error;\n if (error && typeof error === \"object\" && \"message\" in error && typeof error.message === \"string\") return error.message;\n } catch { /* Tool results may contain plain text. */ }\n return undefined;\n}\n"]}
package/dist/types.d.ts CHANGED
@@ -10,6 +10,8 @@ export interface ChatSuggestion {
10
10
  readonly prompt: string;
11
11
  }
12
12
  export interface ChatProps {
13
+ open?: boolean;
14
+ onOpenChange?: (open: boolean) => void;
13
15
  showToolDetails?: boolean;
14
16
  onFullscreenChange?: (fullscreen: boolean) => void;
15
17
  avatar?: string;
@@ -29,5 +31,38 @@ export interface ChatAttachmentOptions {
29
31
  accept?: string;
30
32
  maxCount?: number;
31
33
  maxSizeBytes?: number;
34
+ adapter?: {
35
+ add(input: {
36
+ id: string;
37
+ file: File;
38
+ signal: AbortSignal;
39
+ }): Promise<{
40
+ data?: unknown;
41
+ preview?: string;
42
+ }>;
43
+ send(input: {
44
+ id: string;
45
+ file: File;
46
+ data?: unknown;
47
+ signal: AbortSignal;
48
+ }): Promise<{
49
+ content: readonly ({
50
+ type: "text";
51
+ text: string;
52
+ } | {
53
+ type: "image";
54
+ source: {
55
+ type: "data";
56
+ value: string;
57
+ mimeType: string;
58
+ };
59
+ })[];
60
+ }>;
61
+ remove?(input: {
62
+ id: string;
63
+ file: File;
64
+ data?: unknown;
65
+ }): void | Promise<void>;
66
+ };
32
67
  }
33
68
  export type { AgentModelConfig, AgentModelInfo } from "@nexface/agent";
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AgentRunResult } from \"@nexface/agent\";\nimport type { CSSProperties } from \"react\";\nexport type ChatRunResult = Extract<AgentRunResult, { outcome: { type: \"success\" } }>;\n\nexport interface ChatSuggestion {\n readonly label: string;\n readonly prompt: string;\n}\n\nexport interface ChatProps {\n showToolDetails?: boolean;\n onFullscreenChange?: (fullscreen: boolean) => void;\n avatar?: string;\n welcomeDescription?: string;\n side?: \"left\" | \"right\";\n className?: string;\n style?: CSSProperties;\n attachments?: false | ChatAttachmentOptions;\n title?: string;\n welcomeMessage?: string;\n placeholder?: string;\n layout?: \"floating\" | \"docked\" | \"inline\";\n suggestions?: readonly ChatSuggestion[];\n onRunResult?: (result: ChatRunResult) => void;\n}\n\nexport interface ChatAttachmentOptions {\n accept?: string;\n maxCount?: number;\n maxSizeBytes?: number;\n}\n\nexport type { AgentModelConfig, AgentModelInfo } from \"@nexface/agent\";\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AgentRunResult } from \"@nexface/agent\";\nimport type { CSSProperties } from \"react\";\nexport type ChatRunResult = Extract<AgentRunResult, { outcome: { type: \"success\" } }>;\n\nexport interface ChatSuggestion {\n readonly label: string;\n readonly prompt: string;\n}\n\nexport interface ChatProps {\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n showToolDetails?: boolean;\n onFullscreenChange?: (fullscreen: boolean) => void;\n avatar?: string;\n welcomeDescription?: string;\n side?: \"left\" | \"right\";\n className?: string;\n style?: CSSProperties;\n attachments?: false | ChatAttachmentOptions;\n title?: string;\n welcomeMessage?: string;\n placeholder?: string;\n layout?: \"floating\" | \"docked\" | \"inline\";\n suggestions?: readonly ChatSuggestion[];\n onRunResult?: (result: ChatRunResult) => void;\n}\n\nexport interface ChatAttachmentOptions {\n accept?: string;\n maxCount?: number;\n maxSizeBytes?: number;\n adapter?: {\n add(input: { id: string; file: File; signal: AbortSignal }): Promise<{ data?: unknown; preview?: string }>;\n send(input: { id: string; file: File; data?: unknown; signal: AbortSignal }): Promise<{\n content: readonly ({ type: \"text\"; text: string } | { type: \"image\"; source: { type: \"data\"; value: string; mimeType: string } })[];\n }>;\n remove?(input: { id: string; file: File; data?: unknown }): void | Promise<void>;\n };\n}\n\nexport type { AgentModelConfig, AgentModelInfo } from \"@nexface/agent\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexface/chat",
3
- "version": "0.1.1-alpha.8",
3
+ "version": "0.1.1-alpha.9",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=22.19.0"
@@ -14,18 +14,26 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@ag-ui/core": "0.0.59",
17
- "@nexface/agent": "0.1.1-alpha.8",
17
+ "@assistant-ui/react": "0.15.21",
18
18
  "@phosphor-icons/react": "^2.1.10",
19
19
  "fast-json-patch": "3.1.1",
20
20
  "react-markdown": "10.1.0",
21
- "remark-gfm": "4.0.1"
21
+ "remark-gfm": "4.0.1",
22
+ "@nexface/agent": "0.1.1-alpha.9"
22
23
  },
23
24
  "peerDependencies": {
24
- "@nexface/tools": "0.1.1-alpha.8",
25
25
  "react": ">=18",
26
- "react-dom": ">=18"
26
+ "react-dom": ">=18",
27
+ "@nexface/tools": "0.1.1-alpha.9"
28
+ },
29
+ "devDependencies": {
30
+ "@nexface/tools": "0.1.1-alpha.9"
27
31
  },
28
32
  "files": [
29
33
  "dist"
30
- ]
31
- }
34
+ ],
35
+ "scripts": {
36
+ "build": "tsc -p tsconfig.json && cp src/styles.css dist/styles.css",
37
+ "typecheck": "tsc -p tsconfig.json --noEmit"
38
+ }
39
+ }