mui-hermes-chat 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/react/avatar/ParticipantAvatar.js +1 -1
- package/dist/react/chat/HermesChat.d.ts +45 -0
- package/dist/react/chat/HermesChat.js +35 -2
- package/dist/react/chat/ThinkingPart.d.ts +8 -0
- package/dist/react/chat/ThinkingPart.js +97 -0
- package/dist/react/chat/labels.d.ts +5 -0
- package/dist/react/chat/labels.js +5 -0
- package/dist/react/chat/parts.js +2 -0
- package/dist/react/composer/JumpToLatest.d.ts +18 -1
- package/dist/react/composer/JumpToLatest.js +17 -16
- package/dist/react/composer/slots.js +20 -4
- package/dist/react/tools/ToolRow.d.ts +5 -1
- package/dist/react/tools/ToolRow.js +9 -3
- package/dist/react/tools/ToolStepGroup.d.ts +1 -1
- package/dist/react/tools/ToolStepGroup.js +5 -15
- package/dist/react/tools/labels.d.ts +2 -0
- package/dist/react/tools/labels.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,6 +49,7 @@ import { HermesChat } from "mui-hermes-chat";
|
|
|
49
49
|
| `onTurnEnd?` | `() => void` | after each finished turn and after New chat |
|
|
50
50
|
| `mode?` | `inline \| sheet \| auto` | `auto` = sheet on phones |
|
|
51
51
|
| `fit?` | `{ minHeight?, bottomGap? }` | fit the card to the viewport (theme spacing units) |
|
|
52
|
+
| `bubbleOppositeGap?` | `number \| string` | min gap on the side opposite the avatar; default avatar size + gutter |
|
|
52
53
|
| `toolbarActions?` | `ReactNode` | extra toolbar content |
|
|
53
54
|
|
|
54
55
|
## Labels
|
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
|
+
export declare const MUI_HERMES_CHAT_VERSION = "0.3.0";
|
|
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
|
+
export const MUI_HERMES_CHAT_VERSION = "0.3.0";
|
|
3
3
|
export * from "./core";
|
|
4
4
|
export * from "./adapter";
|
|
5
5
|
export * from "./react/avatar";
|
|
@@ -14,7 +14,7 @@ export function ParticipantAvatar({ participant, size = "md" }) {
|
|
|
14
14
|
const bg = accentToPalette(theme, participant.color || avatarColor(participant.name));
|
|
15
15
|
const text = participant.initials ?? initials(participant.name);
|
|
16
16
|
const showImage = !!participant.avatarUrl && !failed;
|
|
17
|
-
const dim = size === "sm" ?
|
|
17
|
+
const dim = size === "sm" ? 2 : 4;
|
|
18
18
|
return (_jsx(Tooltip, { title: participant.name, children: _jsx(Avatar, { "aria-label": participant.name, src: showImage ? participant.avatarUrl : undefined, alt: participant.name, slotProps: { img: { onError: () => setFailed(true) } }, sx: {
|
|
19
19
|
width: theme.spacing(dim * 2),
|
|
20
20
|
height: theme.spacing(dim * 2),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Theme } from "@mui/material/styles";
|
|
1
2
|
import { type ReactNode } from "react";
|
|
2
3
|
import type { ChatUrls, CsrfSource, HermesMessage, Participant, SessionInfo, Target } from "../../core/types";
|
|
3
4
|
import { type ChatLabels } from "./labels";
|
|
@@ -38,6 +39,50 @@ export interface HermesChatProps {
|
|
|
38
39
|
bottomGap?: number;
|
|
39
40
|
};
|
|
40
41
|
toolbarActions?: ReactNode;
|
|
42
|
+
/** Minimum gap on the side opposite a bubble's avatar (CSS length or px). Default: the avatar column (avatar + gutter). */
|
|
43
|
+
bubbleOppositeGap?: number | string;
|
|
41
44
|
}
|
|
45
|
+
/** Default `bubbleOppositeGap`: avatar + gutter. */
|
|
46
|
+
export declare const AVATAR_COLUMN: (theme: Theme) => string;
|
|
47
|
+
/** x-chat message slot styling: content-sized bubbles, capped at thread − own column − opposite column. */
|
|
48
|
+
export declare function bubbleSlotProps(theme: Theme, oppositeGap?: number | string): {
|
|
49
|
+
messageRoot: {
|
|
50
|
+
sx: {
|
|
51
|
+
"&&": {
|
|
52
|
+
"--MuiChatMessage-avatarSize": string;
|
|
53
|
+
gridTemplateColumns: string;
|
|
54
|
+
columnGap: string;
|
|
55
|
+
paddingInline: string;
|
|
56
|
+
paddingBlock: string;
|
|
57
|
+
alignItems: string;
|
|
58
|
+
};
|
|
59
|
+
"&&.MuiChatMessage-roleUser": {
|
|
60
|
+
gridTemplateColumns: string;
|
|
61
|
+
};
|
|
62
|
+
"&.MuiChatMessage-roleUser .MuiChatMessage-content": {
|
|
63
|
+
justifySelf: string;
|
|
64
|
+
};
|
|
65
|
+
"&.MuiChatMessage-roleUser .MuiChatMessage-bubble": {
|
|
66
|
+
bgcolor: string;
|
|
67
|
+
color: string;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
messageContent: {
|
|
72
|
+
sx: {
|
|
73
|
+
maxWidth: string;
|
|
74
|
+
width: string;
|
|
75
|
+
minWidth: number;
|
|
76
|
+
overflowWrap: string;
|
|
77
|
+
justifySelf: string;
|
|
78
|
+
"& .MuiChatMessage-bubble": {
|
|
79
|
+
borderRadius: string | number;
|
|
80
|
+
padding: string;
|
|
81
|
+
bgcolor: string;
|
|
82
|
+
color: string;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
};
|
|
42
87
|
export declare function HermesChat(props: HermesChatProps): import("react").JSX.Element;
|
|
43
88
|
export default HermesChat;
|
|
@@ -33,6 +33,37 @@ import { defaultChatLabels } from "./labels";
|
|
|
33
33
|
import { hermesPartRenderers } from "./parts";
|
|
34
34
|
import { useFitHeight } from "./useFitHeight";
|
|
35
35
|
const CONVERSATION = "hermes";
|
|
36
|
+
/** Small avatar column (= ParticipantAvatar sm: `spacing(dim * 2)`, dim 2) and the gutter between avatar and bubble. */
|
|
37
|
+
const AVATAR_SPACING = 4;
|
|
38
|
+
const GUTTER_SPACING = 1;
|
|
39
|
+
/** Default `bubbleOppositeGap`: avatar + gutter. */
|
|
40
|
+
export const AVATAR_COLUMN = (theme) => theme.spacing(AVATAR_SPACING + GUTTER_SPACING);
|
|
41
|
+
/** x-chat message slot styling: content-sized bubbles, capped at thread − own column − opposite column. */
|
|
42
|
+
export function bubbleSlotProps(theme, oppositeGap) {
|
|
43
|
+
const gap = oppositeGap === undefined ? AVATAR_COLUMN(theme) : typeof oppositeGap === "number" ? `${oppositeGap}px` : oppositeGap;
|
|
44
|
+
return {
|
|
45
|
+
messageRoot: {
|
|
46
|
+
sx: {
|
|
47
|
+
// fixed avatar track: grouped (follow-up) messages keep an empty cell of the same width (x-chat sizes it by this var)
|
|
48
|
+
"&&": { "--MuiChatMessage-avatarSize": theme.spacing(AVATAR_SPACING), gridTemplateColumns: `${theme.spacing(AVATAR_SPACING)} minmax(0, 1fr)`, columnGap: theme.spacing(GUTTER_SPACING), paddingInline: theme.spacing(1.5), paddingBlock: `0 ${theme.spacing(1.5)}`, alignItems: "start" },
|
|
49
|
+
"&&.MuiChatMessage-roleUser": { gridTemplateColumns: `minmax(0, 1fr) ${theme.spacing(AVATAR_SPACING)}` },
|
|
50
|
+
"&.MuiChatMessage-roleUser .MuiChatMessage-content": { justifySelf: "end" },
|
|
51
|
+
"&.MuiChatMessage-roleUser .MuiChatMessage-bubble": { bgcolor: "primary.main", color: "primary.contrastText" },
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
messageContent: {
|
|
55
|
+
sx: {
|
|
56
|
+
// the grid cell already excludes the own avatar column; subtract the opposite column
|
|
57
|
+
maxWidth: `calc(100% - ${gap})`,
|
|
58
|
+
width: "fit-content",
|
|
59
|
+
minWidth: 0,
|
|
60
|
+
overflowWrap: "anywhere",
|
|
61
|
+
justifySelf: "start",
|
|
62
|
+
"& .MuiChatMessage-bubble": { borderRadius: theme.shape.borderRadius, padding: theme.spacing(1, 1.5), bgcolor: "action.hover", color: "text.primary" },
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
36
67
|
/** Per-message avatar from the participants (the message role picks which). */
|
|
37
68
|
function avatarSlot(participants) {
|
|
38
69
|
return function MessageAvatarSlot({ className }) {
|
|
@@ -53,7 +84,9 @@ function HistoryBar({ labels }) {
|
|
|
53
84
|
return (_jsx(Box, { sx: { display: "flex", justifyContent: "center", alignItems: "center", gap: 1, px: 1.5, py: 0.5, flexShrink: 0 }, children: isLoadingHistory ? (_jsx(Typography, { variant: "caption", color: "text.secondary", role: "status", children: labels.loadingEarlier })) : failed ? (_jsxs(_Fragment, { children: [_jsx(Typography, { variant: "caption", color: "error", role: "alert", children: labels.loadEarlierFailed }), _jsx(Button, { variant: "outlined", color: "inherit", onClick: () => void loadMoreHistory(), children: labels.retry })] })) : hasMoreHistory ? (_jsx(Button, { variant: "text", color: "inherit", onClick: () => void loadMoreHistory(), children: labels.loadEarlier })) : (_jsx(Typography, { variant: "caption", color: "text.secondary", children: labels.startOfConversation })) }));
|
|
54
85
|
}
|
|
55
86
|
function Panel(props) {
|
|
56
|
-
const { urls, target, csrf, history, renderHtml, participants, session, maxMessage, notice, linkedNote, changed, hasEarlier, earlierHref, onTurnEnd, toolbarActions, fit, fitHeight } = props;
|
|
87
|
+
const { urls, target, csrf, history, renderHtml, participants, session, maxMessage, notice, linkedNote, changed, hasEarlier, earlierHref, onTurnEnd, toolbarActions, fit, fitHeight, bubbleOppositeGap } = props;
|
|
88
|
+
const theme = useTheme();
|
|
89
|
+
const bubbles = useMemo(() => bubbleSlotProps(theme, bubbleOppositeGap), [theme, bubbleOppositeGap]);
|
|
57
90
|
const labels = useMemo(() => ({ ...defaultChatLabels, ...props.labels }), [props.labels]);
|
|
58
91
|
const [epoch, setEpoch] = useState(0);
|
|
59
92
|
const [error, setError] = useState("");
|
|
@@ -107,7 +140,7 @@ function Panel(props) {
|
|
|
107
140
|
{ id: AGENT_AUTHOR_ID, displayName: participants.agent.name, role: "assistant" },
|
|
108
141
|
], 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
142
|
messageList: { autoScroll: true, slotProps: { messageListScroller: { ref: scroller, "aria-live": "off", "aria-label": labels.messageList } } },
|
|
110
|
-
|
|
143
|
+
...bubbles,
|
|
111
144
|
}, 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 })] })] })] }));
|
|
112
145
|
}
|
|
113
146
|
export function HermesChat(props) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ChatLabels } from "./labels";
|
|
2
|
+
export interface ThinkingPartProps {
|
|
3
|
+
text: string;
|
|
4
|
+
/** x-chat part state: "streaming" while tokens arrive. */
|
|
5
|
+
state?: string;
|
|
6
|
+
labels?: Partial<ChatLabels>;
|
|
7
|
+
}
|
|
8
|
+
export declare function ThinkingPart({ text, state, labels }: ThinkingPartProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** Own "Thinking" block: capped inner-scroll viewport that never changes height by itself; only the reader toggles it. */
|
|
3
|
+
import PsychologyOutlined from "@mui/icons-material/PsychologyOutlined";
|
|
4
|
+
import ExpandMore from "@mui/icons-material/ExpandMore";
|
|
5
|
+
import Box from "@mui/material/Box";
|
|
6
|
+
import ButtonBase from "@mui/material/ButtonBase";
|
|
7
|
+
import Link from "@mui/material/Link";
|
|
8
|
+
import Typography from "@mui/material/Typography";
|
|
9
|
+
import { keyframes } from "@mui/system";
|
|
10
|
+
import { useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
11
|
+
import { defaultChatLabels } from "./labels";
|
|
12
|
+
const pulse = keyframes `0%,100%{opacity:1}50%{opacity:.45}`;
|
|
13
|
+
const LINES = 6;
|
|
14
|
+
function scrollParent(el) {
|
|
15
|
+
for (let p = el?.parentElement ?? null; p; p = p.parentElement) {
|
|
16
|
+
const oy = getComputedStyle(p).overflowY;
|
|
17
|
+
if (oy === "auto" || oy === "scroll")
|
|
18
|
+
return p;
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
export function ThinkingPart({ text, state, labels }) {
|
|
23
|
+
const l = { ...defaultChatLabels, ...labels };
|
|
24
|
+
const streaming = state === "streaming";
|
|
25
|
+
const startedStreaming = useRef(streaming);
|
|
26
|
+
const t0 = useRef(Date.now());
|
|
27
|
+
const [seconds, setSeconds] = useState(0);
|
|
28
|
+
const [duration, setDuration] = useState(null);
|
|
29
|
+
// History (done at mount) starts collapsed; a live part starts in the capped viewport.
|
|
30
|
+
const [open, setOpen] = useState(streaming);
|
|
31
|
+
const [all, setAll] = useState(false);
|
|
32
|
+
const [overflow, setOverflow] = useState(false);
|
|
33
|
+
const [scrolled, setScrolled] = useState(false);
|
|
34
|
+
const id = useId();
|
|
35
|
+
const root = useRef(null);
|
|
36
|
+
const header = useRef(null);
|
|
37
|
+
const body = useRef(null);
|
|
38
|
+
const stick = useRef(true);
|
|
39
|
+
const anchor = useRef(null);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (!streaming)
|
|
42
|
+
return;
|
|
43
|
+
const tick = () => setSeconds(Math.round((Date.now() - t0.current) / 1000));
|
|
44
|
+
const h = setInterval(tick, 1000);
|
|
45
|
+
return () => clearInterval(h);
|
|
46
|
+
}, [streaming]);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (!streaming && startedStreaming.current && duration === null)
|
|
49
|
+
setDuration(Math.max(1, Math.round((Date.now() - t0.current) / 1000)));
|
|
50
|
+
}, [streaming, duration]);
|
|
51
|
+
// Keep the header where it was after a user toggle.
|
|
52
|
+
useLayoutEffect(() => {
|
|
53
|
+
if (anchor.current === null || !header.current)
|
|
54
|
+
return;
|
|
55
|
+
const delta = header.current.getBoundingClientRect().top - anchor.current;
|
|
56
|
+
anchor.current = null;
|
|
57
|
+
const sp = scrollParent(root.current);
|
|
58
|
+
if (sp && delta)
|
|
59
|
+
sp.scrollTop += delta;
|
|
60
|
+
}, [open, all]);
|
|
61
|
+
useLayoutEffect(() => {
|
|
62
|
+
const el = body.current;
|
|
63
|
+
if (!el || !open)
|
|
64
|
+
return;
|
|
65
|
+
setOverflow(el.scrollHeight > el.clientHeight + 1 || all);
|
|
66
|
+
if (streaming && stick.current && !all)
|
|
67
|
+
el.scrollTop = el.scrollHeight;
|
|
68
|
+
}, [text, streaming, open, all]);
|
|
69
|
+
const toggle = (fn) => {
|
|
70
|
+
anchor.current = header.current?.getBoundingClientRect().top ?? null;
|
|
71
|
+
fn();
|
|
72
|
+
};
|
|
73
|
+
const onScroll = () => {
|
|
74
|
+
const el = body.current;
|
|
75
|
+
if (!el)
|
|
76
|
+
return;
|
|
77
|
+
stick.current = el.scrollHeight - el.scrollTop - el.clientHeight < 4;
|
|
78
|
+
setScrolled(el.scrollTop > 0);
|
|
79
|
+
};
|
|
80
|
+
const title = streaming ? `${l.thinking}${seconds ? ` ${seconds} s` : ""}` : duration !== null ? l.thoughtFor(duration) : l.thoughts;
|
|
81
|
+
const capped = !all;
|
|
82
|
+
return (_jsxs(Box, { ref: root, "data-testid": "thinking", sx: { minWidth: 0, borderLeft: 1, borderColor: "divider", pl: 1.5, color: "text.secondary" }, children: [_jsxs(ButtonBase, { ref: header, onClick: () => toggle(() => setOpen((o) => !o)), "aria-expanded": open, "aria-controls": id, sx: { display: "flex", width: "100%", justifyContent: "flex-start", gap: 0.75, py: 0.5, borderRadius: 1, textAlign: "left" }, children: [_jsx(PsychologyOutlined, { fontSize: "small" }), _jsx(Typography, { variant: "caption", sx: {
|
|
83
|
+
flex: 1,
|
|
84
|
+
animation: streaming ? `${pulse} 1.6s ease-in-out infinite` : undefined,
|
|
85
|
+
"@media (prefers-reduced-motion: reduce)": { animation: "none" },
|
|
86
|
+
}, children: title }), _jsx(ExpandMore, { fontSize: "small", sx: { transform: open ? "rotate(180deg)" : "none" } })] }), _jsxs(Box, { id: id, hidden: !open, sx: { display: open ? "block" : "none" }, children: [_jsx(Box, { ref: body, "data-testid": "thinking-body", onScroll: onScroll, sx: {
|
|
87
|
+
maxHeight: capped ? `calc(${LINES} * 1.5em)` : "none",
|
|
88
|
+
overflowY: capped ? "auto" : "visible",
|
|
89
|
+
lineHeight: 1.5,
|
|
90
|
+
whiteSpace: "pre-wrap",
|
|
91
|
+
overflowWrap: "anywhere",
|
|
92
|
+
typography: "caption",
|
|
93
|
+
...(capped && scrolled
|
|
94
|
+
? { maskImage: "linear-gradient(to bottom, transparent, #000 1.5em)", WebkitMaskImage: "linear-gradient(to bottom, transparent, #000 1.5em)" }
|
|
95
|
+
: {}),
|
|
96
|
+
}, children: text }), overflow && (_jsx(Box, { sx: { textAlign: "right" }, children: _jsx(Link, { component: "button", type: "button", variant: "caption", underline: "hover", onClick: () => toggle(() => setAll((a) => !a)), children: all ? l.showLess : l.showAll }) }))] })] }));
|
|
97
|
+
}
|
|
@@ -36,6 +36,11 @@ export interface ChatOwnLabels {
|
|
|
36
36
|
expired: string;
|
|
37
37
|
expiresIn: (clock: string) => string;
|
|
38
38
|
messageList: string;
|
|
39
|
+
thinking: string;
|
|
40
|
+
thoughtFor: (seconds: number) => string;
|
|
41
|
+
thoughts: string;
|
|
42
|
+
showAll: string;
|
|
43
|
+
showLess: string;
|
|
39
44
|
}
|
|
40
45
|
export type ChatLabels = ComposerLabels & ToolLabels & SessionInfoLabels & ChatOwnLabels;
|
|
41
46
|
export declare const defaultChatLabels: ChatLabels;
|
|
@@ -39,4 +39,9 @@ export const defaultChatLabels = {
|
|
|
39
39
|
expired: "Expired",
|
|
40
40
|
expiresIn: (c) => `Expires in ${c}`,
|
|
41
41
|
messageList: "Conversation",
|
|
42
|
+
thinking: "Thinking…",
|
|
43
|
+
thoughtFor: (s) => `Thought for ${s} s`,
|
|
44
|
+
thoughts: "Thoughts",
|
|
45
|
+
showAll: "Show all",
|
|
46
|
+
showLess: "Show less",
|
|
42
47
|
};
|
package/dist/react/chat/parts.js
CHANGED
|
@@ -6,6 +6,7 @@ import Typography from "@mui/material/Typography";
|
|
|
6
6
|
import { ChatCodeBlock } from "@mui/x-chat";
|
|
7
7
|
import { useEffect, useRef } from "react";
|
|
8
8
|
import { ToolStepGroup } from "../tools/ToolStepGroup";
|
|
9
|
+
import { ThinkingPart } from "./ThinkingPart";
|
|
9
10
|
import { Approval } from "./Approval";
|
|
10
11
|
import { defaultChatLabels } from "./labels";
|
|
11
12
|
const wrap = { whiteSpace: "pre-wrap", overflowWrap: "anywhere", minWidth: 0 };
|
|
@@ -98,6 +99,7 @@ export function hermesPartRenderers({ decide, renderHtml, onOpenTool, labels })
|
|
|
98
99
|
};
|
|
99
100
|
return {
|
|
100
101
|
text: ({ part, message }) => message.parts.some((p) => p.type === "data-reply") ? null : _jsx(StreamedText, { text: part.text }),
|
|
102
|
+
reasoning: ({ part }) => _jsx(ThinkingPart, { text: part.text, state: part.state, labels: labels }),
|
|
101
103
|
"data-reply": ({ part }) => _jsx(ReplyHtml, { html: part.data.html ?? "", renderHtml: renderHtml, labels: labels }),
|
|
102
104
|
"data-commentary": ({ part }) => (_jsx(Typography, { variant: "caption", color: "text.secondary", component: "p", sx: { ...wrap, fontStyle: "italic", m: 0 }, children: part.data.text ?? "" })),
|
|
103
105
|
"data-approval": ({ part }) => {
|
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import { type ComposerLabels } from "./labels";
|
|
2
|
-
export
|
|
2
|
+
export interface JumpState {
|
|
3
|
+
isAtBottom: boolean;
|
|
4
|
+
unseenMessageCount: number;
|
|
5
|
+
scrollToBottom: (o?: {
|
|
6
|
+
behavior?: "smooth" | "auto";
|
|
7
|
+
}) => void;
|
|
8
|
+
}
|
|
9
|
+
/** Presentational button: rendered in the composer area, in flow above the composer (never over message text). */
|
|
10
|
+
export declare function JumpButton({ labels, state }: {
|
|
3
11
|
labels?: Partial<ComposerLabels>;
|
|
12
|
+
state: JumpState | null;
|
|
4
13
|
}): import("react").JSX.Element | null;
|
|
14
|
+
/** Public, self-contained: reads the list scroll state and renders the button (usable as any ChatBox scrollToBottom slot). */
|
|
15
|
+
export declare function JumpToLatest({ labels }: {
|
|
16
|
+
labels?: Partial<ComposerLabels>;
|
|
17
|
+
}): import("react").JSX.Element;
|
|
18
|
+
/** Module-only: reads the list scroll state (only available inside the message list) and hands it to `publish`; renders nothing. */
|
|
19
|
+
export declare function JumpStatePublisher({ publish }: {
|
|
20
|
+
publish: (s: JumpState) => void;
|
|
21
|
+
}): null;
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
/** Round "jump to latest" button,
|
|
2
|
+
/** Round "jump to latest" button: `JumpToLatest` (public, standalone) and the composer-area split (publisher + button). */
|
|
3
3
|
import KeyboardArrowDown from "@mui/icons-material/KeyboardArrowDown";
|
|
4
4
|
import Box from "@mui/material/Box";
|
|
5
5
|
import Button from "@mui/material/Button";
|
|
6
6
|
import Tooltip from "@mui/material/Tooltip";
|
|
7
|
+
import { useEffect } from "react";
|
|
7
8
|
import { useMessageListContext } from "@mui/x-chat-headless";
|
|
8
9
|
import { defaultComposerLabels } from "./labels";
|
|
9
|
-
|
|
10
|
+
/** Presentational button: rendered in the composer area, in flow above the composer (never over message text). */
|
|
11
|
+
export function JumpButton({ labels, state }) {
|
|
10
12
|
const l = { ...defaultComposerLabels, ...labels };
|
|
11
|
-
|
|
12
|
-
if (isAtBottom)
|
|
13
|
+
if (!state || state.isAtBottom)
|
|
13
14
|
return null;
|
|
14
|
-
const fresh = unseenMessageCount > 0;
|
|
15
|
-
return (_jsx(Box, {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
const fresh = state.unseenMessageCount > 0;
|
|
16
|
+
return (_jsx(Box, { "data-testid": "jump-to-latest", sx: { display: "flex", justifyContent: "center", pb: 1 }, children: _jsx(Tooltip, { title: l.jumpToLatest, children: _jsx(Button, { variant: "contained", color: "inherit", "aria-label": l.jumpToLatest, onClick: () => state.scrollToBottom({ behavior: "smooth" }), startIcon: fresh ? _jsx(KeyboardArrowDown, {}) : undefined, sx: { borderRadius: 4, minWidth: 0, bgcolor: "background.paper", color: "text.primary", border: 1, borderColor: "divider" }, children: fresh ? l.newMessages : _jsx(KeyboardArrowDown, {}) }) }) }));
|
|
17
|
+
}
|
|
18
|
+
/** Public, self-contained: reads the list scroll state and renders the button (usable as any ChatBox scrollToBottom slot). */
|
|
19
|
+
export function JumpToLatest({ labels }) {
|
|
20
|
+
return _jsx(JumpButton, { labels: labels, state: useMessageListContext() });
|
|
21
|
+
}
|
|
22
|
+
/** Module-only: reads the list scroll state (only available inside the message list) and hands it to `publish`; renders nothing. */
|
|
23
|
+
export function JumpStatePublisher({ publish }) {
|
|
24
|
+
const { isAtBottom, unseenMessageCount, scrollToBottom } = useMessageListContext();
|
|
25
|
+
useEffect(() => { publish({ isAtBottom, unseenMessageCount, scrollToBottom }); }, [publish, isAtBottom, unseenMessageCount, scrollToBottom]);
|
|
26
|
+
return null;
|
|
26
27
|
}
|
|
@@ -1,10 +1,26 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** `composerSlots(labels, maxMessage)`: x-chat ChatBox `slots`/`slotProps` that swap in the single-surface composer. */
|
|
3
|
+
import { useSyncExternalStore } from "react";
|
|
4
|
+
import Box from "@mui/material/Box";
|
|
2
5
|
import { ChatComposer } from "./ChatComposer";
|
|
3
|
-
import {
|
|
6
|
+
import { JumpButton, JumpStatePublisher } from "./JumpToLatest";
|
|
4
7
|
export function composerSlots(labels, maxMessage) {
|
|
8
|
+
// The list-side slot publishes scroll state; the composer area renders the button above the composer.
|
|
9
|
+
let state = null;
|
|
10
|
+
const subs = new Set();
|
|
11
|
+
const publish = (s) => {
|
|
12
|
+
if (state && state.isAtBottom === s.isAtBottom && state.unseenMessageCount === s.unseenMessageCount && state.scrollToBottom === s.scrollToBottom)
|
|
13
|
+
return;
|
|
14
|
+
state = s;
|
|
15
|
+
subs.forEach((f) => f());
|
|
16
|
+
};
|
|
17
|
+
const subscribe = (f) => { subs.add(f); return () => { subs.delete(f); }; };
|
|
5
18
|
// composerRoot receives the stock children; we ignore them and render the whole composer.
|
|
6
|
-
const Composer = () =>
|
|
7
|
-
|
|
19
|
+
const Composer = () => {
|
|
20
|
+
const s = useSyncExternalStore(subscribe, () => state, () => null);
|
|
21
|
+
return (_jsxs(Box, { "data-testid": "composer-area", sx: { flexShrink: 0 }, children: [_jsx(JumpButton, { labels: labels, state: s }), _jsx(ChatComposer, { labels: labels, maxMessage: maxMessage })] }));
|
|
22
|
+
};
|
|
23
|
+
const Jump = () => _jsx(JumpStatePublisher, { publish: publish });
|
|
8
24
|
return {
|
|
9
25
|
slots: { composerRoot: Composer, scrollToBottom: Jump },
|
|
10
26
|
slotProps: {},
|
|
@@ -6,6 +6,10 @@ export interface ToolRowProps {
|
|
|
6
6
|
running?: boolean;
|
|
7
7
|
onOpen?: (call: HermesToolCall) => void;
|
|
8
8
|
labels?: Partial<ToolLabels>;
|
|
9
|
+
/** Rendered inside the Steps card: status icon on a vertical connector, no own background box. */
|
|
10
|
+
inCard?: boolean;
|
|
11
|
+
first?: boolean;
|
|
12
|
+
last?: boolean;
|
|
9
13
|
}
|
|
10
14
|
export declare function statusOf(call: HermesToolCall, running?: boolean): ToolRunStatus;
|
|
11
|
-
export declare function ToolRow({ call, running, onOpen, labels }: ToolRowProps): import("react").JSX.Element;
|
|
15
|
+
export declare function ToolRow({ call, running, onOpen, labels, inCard, first, last }: ToolRowProps): import("react").JSX.Element;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
/** One tool call row: family icon, name, args line,
|
|
2
|
+
/** One tool call row: status icon, family icon, name, args line, duration; opens detail, chevron toggles an inline preview. */
|
|
3
3
|
import { useEffect, useState } from "react";
|
|
4
4
|
import Box from "@mui/material/Box";
|
|
5
5
|
import ButtonBase from "@mui/material/ButtonBase";
|
|
@@ -7,6 +7,7 @@ import CircularProgress from "@mui/material/CircularProgress";
|
|
|
7
7
|
import IconButton from "@mui/material/IconButton";
|
|
8
8
|
import Tooltip from "@mui/material/Tooltip";
|
|
9
9
|
import Typography from "@mui/material/Typography";
|
|
10
|
+
import { alpha } from "@mui/material/styles";
|
|
10
11
|
import CheckCircleOutline from "@mui/icons-material/CheckCircleOutlined";
|
|
11
12
|
import ErrorOutline from "@mui/icons-material/ErrorOutlined";
|
|
12
13
|
import ExpandMore from "@mui/icons-material/ExpandMore";
|
|
@@ -32,7 +33,7 @@ function Elapsed() {
|
|
|
32
33
|
}, []);
|
|
33
34
|
return _jsxs("span", { "data-testid": "tool-elapsed", children: [s, " s"] });
|
|
34
35
|
}
|
|
35
|
-
export function ToolRow({ call, running, onOpen, labels }) {
|
|
36
|
+
export function ToolRow({ call, running, onOpen, labels, inCard, first, last }) {
|
|
36
37
|
const l = { ...defaultToolLabels, ...labels };
|
|
37
38
|
const [expanded, setExpanded] = useState(false);
|
|
38
39
|
const status = statusOf(call, running);
|
|
@@ -41,5 +42,10 @@ export function ToolRow({ call, running, onOpen, labels }) {
|
|
|
41
42
|
const hasPreview = preview.kind !== "none";
|
|
42
43
|
const dur = ToolRowFormat.duration(call.duration_s);
|
|
43
44
|
const label = ToolRowFormat.accessibilityLabel({ name: call.name, status, duration: call.duration_s, argsLine: args });
|
|
44
|
-
|
|
45
|
+
const statusIcon = status === "running" ? _jsx(CircularProgress, { size: 16, "aria-label": l.running })
|
|
46
|
+
: status === "failed" ? _jsx(ErrorOutline, { fontSize: "small", color: "error", titleAccess: l.failed })
|
|
47
|
+
: _jsx(CheckCircleOutline, { fontSize: "small", color: "success", titleAccess: l.done });
|
|
48
|
+
return (_jsxs(Box, { "data-testid": "tool-row", "data-status": status, sx: inCard
|
|
49
|
+
? (t) => ({ borderRadius: 1, p: 0.5, bgcolor: status === "done" ? alpha(t.palette.success.main, 0.06) : status === "failed" ? alpha(t.palette.error.main, 0.06) : "transparent" })
|
|
50
|
+
: { bgcolor: "action.hover", borderRadius: 1, p: 0.5 }, children: [_jsxs(Box, { sx: { display: "flex", alignItems: "stretch", gap: 0.5 }, children: [inCard && (_jsxs(Box, { "aria-hidden": true, sx: { position: "relative", width: 24, flexShrink: 0, display: "flex", justifyContent: "center", alignItems: "center" }, children: [_jsx(Box, { sx: { position: "absolute", left: "50%", width: "1px", bgcolor: "divider", top: first ? "50%" : -4, bottom: last ? "50%" : -4 } }), _jsx(Box, { sx: { position: "relative", display: "flex", bgcolor: "background.paper", borderRadius: "50%", color: "text.secondary" }, children: statusIcon })] })), _jsxs(ButtonBase, { "aria-label": label, onClick: () => onOpen?.(call), sx: { flex: 1, minWidth: 0, display: "flex", alignItems: "center", gap: 1, p: 0.5, borderRadius: 1, textAlign: "left", justifyContent: "flex-start" }, children: [_jsx(ToolIcon, { name: call.name }), _jsxs(Box, { sx: { minWidth: 0, flex: 1 }, children: [_jsx(Typography, { variant: "body2", noWrap: true, sx: { fontWeight: "fontWeightMedium" }, children: call.name }), args && _jsx(Typography, { variant: "caption", color: "text.secondary", noWrap: true, component: "div", sx: { fontFamily: "monospace" }, children: args })] }), _jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 0.5, color: "text.secondary", flexShrink: 0 }, children: [status === "running" && (_jsxs(_Fragment, { children: [_jsx(Elapsed, {}), !inCard && _jsx(CircularProgress, { size: 14, "aria-label": l.running })] })), status === "done" && (_jsxs(_Fragment, { children: [dur && _jsx(Typography, { variant: "caption", children: dur }), !inCard && _jsx(CheckCircleOutline, { fontSize: "small", color: "success", titleAccess: l.done })] })), status === "failed" && (_jsxs(_Fragment, { children: [dur && _jsx(Typography, { variant: "caption", children: dur }), !inCard && _jsx(ErrorOutline, { fontSize: "small", color: "error" }), _jsx(Typography, { variant: "caption", color: "error", children: l.failed })] }))] })] }), hasPreview && (_jsx(Tooltip, { title: expanded ? l.hidePreview : l.showPreview, children: _jsx(IconButton, { "aria-label": expanded ? l.hidePreview : l.showPreview, "aria-expanded": expanded, onClick: () => setExpanded((v) => !v), children: expanded ? _jsx(ExpandLess, { fontSize: "small" }) : _jsx(ExpandMore, { fontSize: "small" }) }) }))] }), expanded && hasPreview && (_jsx(Box, { sx: { p: 1 }, children: _jsx(ToolPreviewView, { preview: preview, labels: labels }) }))] }));
|
|
45
51
|
}
|
|
@@ -2,7 +2,7 @@ import type { HermesToolCall } from "../../core/types";
|
|
|
2
2
|
import { type ToolLabels } from "./labels";
|
|
3
3
|
export interface ToolStepGroupProps {
|
|
4
4
|
calls: HermesToolCall[];
|
|
5
|
-
/** The turn is still running:
|
|
5
|
+
/** The turn is still running: the header shows live progress. Rows never fold or expand by themselves. */
|
|
6
6
|
running?: boolean;
|
|
7
7
|
onOpen?: (call: HermesToolCall) => void;
|
|
8
8
|
labels?: Partial<ToolLabels>;
|
|
@@ -1,28 +1,18 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
/**
|
|
3
|
-
import { useState } from "react";
|
|
2
|
+
/** The Steps card: one outlined card, a header with a quiet count, one row per tool call appended in arrival order; never folds. */
|
|
4
3
|
import Box from "@mui/material/Box";
|
|
5
|
-
import ButtonBase from "@mui/material/ButtonBase";
|
|
6
4
|
import Typography from "@mui/material/Typography";
|
|
7
|
-
import ExpandMore from "@mui/icons-material/ExpandMore";
|
|
8
|
-
import ExpandLess from "@mui/icons-material/ExpandLess";
|
|
9
5
|
import { ToolRow } from "./ToolRow";
|
|
10
6
|
import { ToolRowFormat } from "./format";
|
|
11
7
|
import { defaultToolLabels } from "./labels";
|
|
12
8
|
export function ToolStepGroup({ calls, running, onOpen, labels }) {
|
|
13
9
|
const l = { ...defaultToolLabels, ...labels };
|
|
14
|
-
// null = follow the running default; a click pins the user's choice.
|
|
15
|
-
const [pinned, setPinned] = useState(null);
|
|
16
10
|
if (calls.length === 0)
|
|
17
11
|
return null;
|
|
18
|
-
const
|
|
19
|
-
if (calls.length === 1)
|
|
20
|
-
return _jsx(ToolRow, { call: calls[0], running: rowRunning(calls[0], 0), onOpen: onOpen, labels: labels });
|
|
21
|
-
const open = pinned ?? !!running;
|
|
22
|
-
const total = calls.reduce((s, c) => s + (c.duration_s ?? 0), 0);
|
|
12
|
+
const live = calls.filter((c) => c.state === "start").length;
|
|
23
13
|
const failed = calls.filter((c) => c.state === "failed").length;
|
|
14
|
+
const total = calls.reduce((s, c) => s + (c.duration_s ?? 0), 0);
|
|
24
15
|
const dur = ToolRowFormat.duration(calls.some((c) => c.duration_s !== undefined) ? total : undefined);
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
return (_jsxs(Box, { "data-testid": "tool-step-group", sx: { display: "flex", flexDirection: "column", gap: 0.5 }, children: [_jsxs(ButtonBase, { "aria-expanded": open, "aria-label": `${title}. ${action}`, onClick: () => setPinned(!open), sx: { display: "flex", alignItems: "center", gap: 0.5, justifyContent: "flex-start", p: 0.5, borderRadius: 1, bgcolor: "action.hover" }, children: [_jsx(Typography, { variant: "body2", sx: { fontWeight: "fontWeightMedium" }, children: title }), failed > 0 && _jsx(Typography, { variant: "caption", color: "error", children: l.failedCount(failed) }), _jsx(Box, { sx: { flex: 1 } }), open ? _jsx(ExpandLess, { fontSize: "small" }) : _jsx(ExpandMore, { fontSize: "small" })] }), open && calls.map((c, i) => _jsx(ToolRow, { call: c, running: rowRunning(c, i), onOpen: onOpen, labels: labels }, c.id))] }));
|
|
16
|
+
const count = running && live > 0 ? l.stepsProgress(calls.length - live, live) : l.steps(calls.length) + (dur ? ` · ${dur}` : "");
|
|
17
|
+
return (_jsxs(Box, { "data-testid": "tool-step-group", sx: { display: "flex", flexDirection: "column", gap: 0.5, border: 1, borderColor: "divider", borderRadius: 1, p: 1, width: "100%", boxSizing: "border-box" }, children: [_jsxs(Box, { sx: { display: "flex", alignItems: "baseline", gap: 1, px: 0.5 }, children: [_jsx(Typography, { variant: "body2", sx: { fontWeight: "fontWeightMedium" }, children: l.stepsHeader }), _jsx(Typography, { variant: "caption", color: "text.secondary", children: count }), failed > 0 && _jsx(Typography, { variant: "caption", color: "error", children: l.failedCount(failed) })] }), calls.map((c, i) => (_jsx(ToolRow, { call: c, running: !!running && c.state === "start", onOpen: onOpen, labels: labels, inCard: true, first: i === 0, last: i === calls.length - 1 }, c.id)))] }));
|
|
28
18
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const defaultToolLabels = {
|
|
2
2
|
running: "Running", done: "Done", failed: "Failed", showPreview: "Show preview", hidePreview: "Hide preview",
|
|
3
3
|
steps: (n) => `${n} steps`, failedCount: (n) => `${n} failed`, showSteps: "Show steps", hideSteps: "Hide steps",
|
|
4
|
+
stepsHeader: "Steps", stepsProgress: (d, r) => `${d} done · ${r} running`,
|
|
4
5
|
request: "Request", response: "Response", copy: "Copy", copied: "Copied", close: "Close",
|
|
5
6
|
argsClipped: "Arguments were clipped by the server.", noArgs: "No arguments.", noResponse: "No response yet.",
|
|
6
7
|
more: (n) => `… ${n} more`, details: "Tool details",
|