mui-hermes-chat 0.2.0 → 0.2.2
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/adapter/adapter.d.ts +2 -0
- package/dist/adapter/adapter.js +5 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/react/chat/HermesChat.js +5 -5
- package/dist/react/composer/ChatComposer.js +2 -2
- package/dist/react/composer/SendOrStopButton.js +1 -0
- package/package.json +1 -1
|
@@ -12,6 +12,8 @@ export interface HermesAdapterOptions {
|
|
|
12
12
|
networkErrorText?: string;
|
|
13
13
|
}
|
|
14
14
|
export declare const NOTE_NETWORK = "The connection to Hermes was lost. Your message is still in the box: send it again.";
|
|
15
|
+
export declare const USER_AUTHOR_ID = "user";
|
|
16
|
+
export declare const AGENT_AUTHOR_ID = "hermes";
|
|
15
17
|
/**
|
|
16
18
|
* History rows → x-chat messages. User: one text part. Assistant: a `data-tools` part (`HermesToolCall[]`)
|
|
17
19
|
* when it carries tools, then a `data-reply` part (`{text, html}`) when it has html, else a text part.
|
package/dist/adapter/adapter.js
CHANGED
|
@@ -11,6 +11,8 @@ function toolOutput(e) {
|
|
|
11
11
|
out.duration_s = e.duration_s;
|
|
12
12
|
return out;
|
|
13
13
|
}
|
|
14
|
+
export const USER_AUTHOR_ID = "user";
|
|
15
|
+
export const AGENT_AUTHOR_ID = "hermes";
|
|
14
16
|
/**
|
|
15
17
|
* History rows → x-chat messages. User: one text part. Assistant: a `data-tools` part (`HermesToolCall[]`)
|
|
16
18
|
* when it carries tools, then a `data-reply` part (`{text, html}`) when it has html, else a text part.
|
|
@@ -29,7 +31,9 @@ export function toChatMessages(messages) {
|
|
|
29
31
|
else {
|
|
30
32
|
parts.push({ type: "text", text: m.text });
|
|
31
33
|
}
|
|
32
|
-
|
|
34
|
+
// Author ids match `currentUser`/`members` in HermesChat: x-chat decides viewer ownership by author id.
|
|
35
|
+
const author = { id: m.role === "user" ? USER_AUTHOR_ID : AGENT_AUTHOR_ID };
|
|
36
|
+
const msg = { id: m.id, role: m.role, author, parts, status: "sent" };
|
|
33
37
|
if (typeof m.created === "number")
|
|
34
38
|
msg.createdAt = new Date(m.created * 1000).toISOString();
|
|
35
39
|
return msg;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** mui-hermes-chat: embeddable Hermes chat for React + MUI. Public API only; see README. */
|
|
2
|
-
export declare const MUI_HERMES_CHAT_VERSION = "0.2.
|
|
2
|
+
export declare const MUI_HERMES_CHAT_VERSION = "0.2.2";
|
|
3
3
|
export * from "./core";
|
|
4
4
|
export * from "./adapter";
|
|
5
5
|
export * from "./react/avatar";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** mui-hermes-chat: embeddable Hermes chat for React + MUI. Public API only; see README. */
|
|
2
|
-
export const MUI_HERMES_CHAT_VERSION = "0.2.
|
|
2
|
+
export const MUI_HERMES_CHAT_VERSION = "0.2.2";
|
|
3
3
|
export * from "./core";
|
|
4
4
|
export * from "./adapter";
|
|
5
5
|
export * from "./react/avatar";
|
|
@@ -23,7 +23,7 @@ import { visuallyHidden } from "@mui/utils";
|
|
|
23
23
|
import { ChatBox } from "@mui/x-chat";
|
|
24
24
|
import { useChat, useMessageContext } from "@mui/x-chat/headless";
|
|
25
25
|
import { useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
26
|
-
import { hermesChatAdapter, toChatMessages } from "../../adapter/adapter";
|
|
26
|
+
import { AGENT_AUTHOR_ID, USER_AUTHOR_ID, hermesChatAdapter, toChatMessages } from "../../adapter/adapter";
|
|
27
27
|
import { sendApproval, startOver } from "../../core/transport";
|
|
28
28
|
import { ParticipantAvatar } from "../avatar/ParticipantAvatar";
|
|
29
29
|
import { composerSlots } from "../composer/slots";
|
|
@@ -102,10 +102,10 @@ function Panel(props) {
|
|
|
102
102
|
}
|
|
103
103
|
};
|
|
104
104
|
const earlier = hasEarlier && earlierHref;
|
|
105
|
-
return (_jsxs(Paper, { ref: ref, variant: "outlined", "data-testid": "hermes-chat", sx: { display: "flex", flexDirection: "column", minHeight: 0, minWidth: 0, bgcolor: "background.paper", overflow: "hidden", maxHeight: fitHeight && maxHeight ? maxHeight : undefined, height: fitHeight ? "auto" : "100%" }, children: [_jsxs(Box, { "data-testid": "hermes-chat-toolbar", sx: { display: "flex", alignItems: "center", gap: 1, px: 1.5, py: 1, flexShrink: 0, borderBottom: 1, borderColor: "divider" }, children: [_jsx(ParticipantAvatar, { participant: participants.agent, size: "sm" }), _jsx(Typography, { variant: "subtitle1", component: "h2", noWrap: true, sx: { flex: 1, minWidth: 0 }, children: participants.agent.name }), earlier && _jsx(Link, { href: earlierHref, children: labels.earlierConversations }), toolbarActions, session && _jsx(SessionInfoButton, { session: session, labels: labels, agentAvatar: _jsx(ParticipantAvatar, { participant: participants.agent }) }), _jsx(Tooltip, { title: labels.newChat, children: _jsx(IconButton, { "aria-label": labels.newChat, onClick: () => setConfirming(true), children: _jsx(AddCommentOutlined, {}) }) })] }), (linkedNote || notice || changed || error) && (_jsxs(Box, { sx: { display: "flex", flexDirection: "column", gap: 1, px: 1.5, pt: 1, flexShrink: 0 }, children: [linkedNote && _jsx(Typography, { variant: "body2", color: "text.secondary", children: linkedNote }), notice && _jsx(Alert, { severity: "warning", children: notice }), changed && _jsx(Typography, { variant: "caption", color: "text.secondary", role: "status", children: labels.changedNote }), error && _jsx(Alert, { severity: "error", onClose: () => setError(""), children: error })] })), _jsx(ChatBox, { adapter: adapter, initialMessages: initialMessages, initialActiveConversationId: CONVERSATION, currentUser: { id:
|
|
106
|
-
{ id:
|
|
107
|
-
{ id:
|
|
108
|
-
], partRenderers: partRenderers, features: { attachments: false }, onFinish: () => { setSaid((s) => (s.endsWith("") ? labels.replied : labels.replied + "")); onTurnEnd?.(); }, slots: slots, slotProps: {
|
|
105
|
+
return (_jsxs(Paper, { ref: ref, variant: "outlined", "data-testid": "hermes-chat", sx: { display: "flex", flexDirection: "column", minHeight: 0, minWidth: 0, bgcolor: "background.paper", overflow: "hidden", maxHeight: fitHeight && maxHeight ? maxHeight : undefined, height: fitHeight ? "auto" : "100%" }, children: [_jsxs(Box, { "data-testid": "hermes-chat-toolbar", sx: { display: "flex", alignItems: "center", gap: 1, px: 1.5, py: 1, flexShrink: 0, borderBottom: 1, borderColor: "divider" }, children: [_jsx(ParticipantAvatar, { participant: participants.agent, size: "sm" }), _jsx(Typography, { variant: "subtitle1", component: "h2", noWrap: true, sx: { flex: 1, minWidth: 0 }, children: participants.agent.name }), earlier && _jsx(Link, { href: earlierHref, children: labels.earlierConversations }), toolbarActions, session && _jsx(SessionInfoButton, { session: session, labels: labels, agentAvatar: _jsx(ParticipantAvatar, { participant: participants.agent }) }), _jsx(Tooltip, { title: labels.newChat, children: _jsx(IconButton, { "aria-label": labels.newChat, onClick: () => setConfirming(true), children: _jsx(AddCommentOutlined, {}) }) })] }), (linkedNote || notice || changed || error) && (_jsxs(Box, { sx: { display: "flex", flexDirection: "column", gap: 1, px: 1.5, pt: 1, flexShrink: 0 }, children: [linkedNote && _jsx(Typography, { variant: "body2", color: "text.secondary", children: linkedNote }), notice && _jsx(Alert, { severity: "warning", children: notice }), changed && _jsx(Typography, { variant: "caption", color: "text.secondary", role: "status", children: labels.changedNote }), error && _jsx(Alert, { severity: "error", onClose: () => setError(""), children: error })] })), _jsx(ChatBox, { adapter: adapter, initialMessages: initialMessages, initialActiveConversationId: CONVERSATION, currentUser: { id: USER_AUTHOR_ID, displayName: participants.user.name, role: "user" }, members: [
|
|
106
|
+
{ id: USER_AUTHOR_ID, displayName: participants.user.name, role: "user" },
|
|
107
|
+
{ id: AGENT_AUTHOR_ID, displayName: participants.agent.name, role: "assistant" },
|
|
108
|
+
], getMessageAuthorId: (m) => m.author?.id ?? (m.role === "user" ? USER_AUTHOR_ID : AGENT_AUTHOR_ID), partRenderers: partRenderers, features: { attachments: false }, onFinish: () => { setSaid((s) => (s.endsWith("") ? labels.replied : labels.replied + "")); onTurnEnd?.(); }, slots: slots, slotProps: {
|
|
109
109
|
messageList: { autoScroll: true, slotProps: { messageListScroller: { ref: scroller, "aria-live": "off", "aria-label": labels.messageList } } },
|
|
110
110
|
messageContent: { sx: { maxWidth: "72ch", overflowWrap: "anywhere" } },
|
|
111
111
|
}, sx: { flex: "0 1 auto", minHeight: 0, height: "auto", border: 0, bgcolor: "transparent" } }, epoch), _jsx(Box, { role: "status", "data-testid": "hermes-said", sx: visuallyHidden, children: said }), _jsx(ToolDetailDrawer, { call: tool, open: !!tool, onClose: () => setTool(null), labels: labels }), _jsxs(Dialog, { open: confirming, onClose: () => setConfirming(false), children: [_jsx(DialogTitle, { children: labels.newChatTitle }), _jsx(DialogContent, { children: _jsx(DialogContentText, { children: labels.newChatBody }) }), _jsxs(DialogActions, { children: [_jsx(Button, { onClick: () => setConfirming(false), children: labels.cancel }), _jsx(Button, { variant: "contained", onClick: () => void reset(), children: labels.newChatConfirm })] })] })] }));
|
|
@@ -29,9 +29,9 @@ export function ChatComposer({ labels, maxMessage, disabled }) {
|
|
|
29
29
|
display: "flex",
|
|
30
30
|
alignItems: "flex-end",
|
|
31
31
|
gap: 1,
|
|
32
|
-
py:
|
|
32
|
+
py: 1,
|
|
33
33
|
pl: 1.5,
|
|
34
|
-
pr:
|
|
34
|
+
pr: 1,
|
|
35
35
|
bgcolor: "background.paper",
|
|
36
36
|
border: 1,
|
|
37
37
|
borderColor: "divider",
|
|
@@ -8,6 +8,7 @@ export function SendOrStopButton({ streaming, canSend, onSend, onStop, sendLabel
|
|
|
8
8
|
const label = streaming ? stopLabel : sendLabel;
|
|
9
9
|
return (_jsx(Tooltip, { title: label, children: _jsx("span", { children: _jsx(IconButton, { color: "primary", "aria-label": label, disabled: !streaming && !canSend, onClick: streaming ? onStop : onSend, sx: (t) => ({
|
|
10
10
|
flexShrink: 0,
|
|
11
|
+
borderRadius: "50%",
|
|
11
12
|
backgroundColor: "primary.main",
|
|
12
13
|
color: "primary.contrastText",
|
|
13
14
|
"&:hover": { backgroundColor: "primary.dark" },
|