mui-hermes-chat 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +103 -2
- package/dist/adapter/adapter.d.ts +22 -0
- package/dist/adapter/adapter.js +183 -0
- package/dist/adapter/index.d.ts +2 -0
- package/dist/adapter/index.js +2 -0
- package/dist/core/events.d.ts +59 -0
- package/dist/core/events.js +57 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.js +5 -0
- package/dist/core/initials.d.ts +5 -0
- package/dist/core/initials.js +28 -0
- package/dist/core/transport.d.ts +20 -0
- package/dist/core/transport.js +89 -0
- package/dist/core/types.d.ts +58 -0
- package/dist/core/types.js +2 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/react/avatar/ParticipantAvatar.d.ts +6 -0
- package/dist/react/avatar/ParticipantAvatar.js +25 -0
- package/dist/react/avatar/accent.d.ts +3 -0
- package/dist/react/avatar/accent.js +9 -0
- package/dist/react/avatar/index.d.ts +3 -0
- package/dist/react/avatar/index.js +3 -0
- package/dist/react/chat/Approval.d.ts +11 -0
- package/dist/react/chat/Approval.js +41 -0
- package/dist/react/chat/HermesChat.d.ts +43 -0
- package/dist/react/chat/HermesChat.js +124 -0
- package/dist/react/chat/index.d.ts +6 -0
- package/dist/react/chat/index.js +6 -0
- package/dist/react/chat/labels.d.ts +41 -0
- package/dist/react/chat/labels.js +42 -0
- package/dist/react/chat/parts.d.ts +41 -0
- package/dist/react/chat/parts.js +112 -0
- package/dist/react/chat/useFitHeight.d.ts +12 -0
- package/dist/react/chat/useFitHeight.js +42 -0
- package/dist/react/composer/ChatComposer.d.ts +7 -0
- package/dist/react/composer/ChatComposer.js +44 -0
- package/dist/react/composer/JumpToLatest.d.ts +4 -0
- package/dist/react/composer/JumpToLatest.js +26 -0
- package/dist/react/composer/SendOrStopButton.d.ts +9 -0
- package/dist/react/composer/SendOrStopButton.js +22 -0
- package/dist/react/composer/index.d.ts +6 -0
- package/dist/react/composer/index.js +6 -0
- package/dist/react/composer/labels.d.ts +10 -0
- package/dist/react/composer/labels.js +8 -0
- package/dist/react/composer/slots.d.ts +8 -0
- package/dist/react/composer/slots.js +12 -0
- package/dist/react/info/SessionInfo.d.ts +37 -0
- package/dist/react/info/SessionInfo.js +91 -0
- package/dist/react/info/index.d.ts +3 -0
- package/dist/react/info/index.js +2 -0
- package/dist/react/tools/JsonTree.d.ts +8 -0
- package/dist/react/tools/JsonTree.js +25 -0
- package/dist/react/tools/ToolDetailDrawer.d.ts +9 -0
- package/dist/react/tools/ToolDetailDrawer.js +47 -0
- package/dist/react/tools/ToolPreviewView.d.ts +6 -0
- package/dist/react/tools/ToolPreviewView.js +32 -0
- package/dist/react/tools/ToolRow.d.ts +11 -0
- package/dist/react/tools/ToolRow.js +45 -0
- package/dist/react/tools/ToolStepGroup.d.ts +10 -0
- package/dist/react/tools/ToolStepGroup.js +28 -0
- package/dist/react/tools/family.d.ts +19 -0
- package/dist/react/tools/family.js +107 -0
- package/dist/react/tools/format.d.ts +19 -0
- package/dist/react/tools/format.js +37 -0
- package/dist/react/tools/icons.d.ts +5 -0
- package/dist/react/tools/icons.js +25 -0
- package/dist/react/tools/index.d.ts +10 -0
- package/dist/react/tools/index.js +10 -0
- package/dist/react/tools/labels.d.ts +23 -0
- package/dist/react/tools/labels.js +7 -0
- package/dist/react/tools/toolPreview.d.ts +74 -0
- package/dist/react/tools/toolPreview.js +156 -0
- package/package.json +48 -4
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** Card `maxHeight = max(minHeight, innerHeight − card.top − bottomGap)`, kept current on resize, scroll-settle and layout change. */
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
/** Pure math, exported for tests. */
|
|
4
|
+
export function fitMaxHeight(innerHeight, top, minHeight = 420, bottomGap = 24) {
|
|
5
|
+
return Math.max(minHeight, Math.floor(innerHeight - top - bottomGap));
|
|
6
|
+
}
|
|
7
|
+
export function useFitHeight({ minHeight = 420, bottomGap = 24 } = {}, enabled = true) {
|
|
8
|
+
const ref = useRef(null);
|
|
9
|
+
const [maxHeight, setMaxHeight] = useState(undefined);
|
|
10
|
+
const measure = useCallback(() => {
|
|
11
|
+
const el = ref.current;
|
|
12
|
+
if (!el)
|
|
13
|
+
return;
|
|
14
|
+
setMaxHeight(fitMaxHeight(window.innerHeight, el.getBoundingClientRect().top, minHeight, bottomGap));
|
|
15
|
+
}, [minHeight, bottomGap]);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!enabled)
|
|
18
|
+
return;
|
|
19
|
+
measure();
|
|
20
|
+
let settle;
|
|
21
|
+
const onScroll = () => {
|
|
22
|
+
clearTimeout(settle);
|
|
23
|
+
settle = setTimeout(measure, 100); // re-measure once scrolling settles
|
|
24
|
+
};
|
|
25
|
+
window.addEventListener("resize", measure);
|
|
26
|
+
window.addEventListener("scroll", onScroll, { passive: true });
|
|
27
|
+
let ro;
|
|
28
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
29
|
+
ro = new ResizeObserver(measure);
|
|
30
|
+
if (ref.current?.parentElement)
|
|
31
|
+
ro.observe(ref.current.parentElement);
|
|
32
|
+
ro.observe(document.documentElement);
|
|
33
|
+
}
|
|
34
|
+
return () => {
|
|
35
|
+
clearTimeout(settle);
|
|
36
|
+
window.removeEventListener("resize", measure);
|
|
37
|
+
window.removeEventListener("scroll", onScroll);
|
|
38
|
+
ro?.disconnect();
|
|
39
|
+
};
|
|
40
|
+
}, [enabled, measure]);
|
|
41
|
+
return { ref, maxHeight: enabled ? maxHeight : undefined };
|
|
42
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ComposerLabels } from "./labels";
|
|
2
|
+
export interface ChatComposerProps {
|
|
3
|
+
labels?: Partial<ComposerLabels>;
|
|
4
|
+
maxMessage?: number;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function ChatComposer({ labels, maxMessage, disabled }: ChatComposerProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** Single-surface chat composer built on the x-chat headless hooks. */
|
|
3
|
+
import Box from "@mui/material/Box";
|
|
4
|
+
import InputBase from "@mui/material/InputBase";
|
|
5
|
+
import Typography from "@mui/material/Typography";
|
|
6
|
+
import useMediaQuery from "@mui/material/useMediaQuery";
|
|
7
|
+
import { useChat, useChatComposer } from "@mui/x-chat-headless";
|
|
8
|
+
import { defaultComposerLabels } from "./labels";
|
|
9
|
+
import { SendOrStopButton } from "./SendOrStopButton";
|
|
10
|
+
export function ChatComposer({ labels, maxMessage, disabled }) {
|
|
11
|
+
const l = { ...defaultComposerLabels, ...labels };
|
|
12
|
+
const { value, setValue, submit } = useChatComposer();
|
|
13
|
+
const { isStreaming, stopStreaming } = useChat();
|
|
14
|
+
const touch = useMediaQuery("(hover: none)");
|
|
15
|
+
const length = value.length;
|
|
16
|
+
const canSend = !disabled && value.trim().length > 0 && (!maxMessage || length <= maxMessage);
|
|
17
|
+
const showCounter = !!maxMessage && length > maxMessage * 0.8;
|
|
18
|
+
const send = () => {
|
|
19
|
+
if (canSend && !isStreaming)
|
|
20
|
+
void submit();
|
|
21
|
+
};
|
|
22
|
+
const onKeyDown = (e) => {
|
|
23
|
+
if (e.key !== "Enter" || e.shiftKey || e.nativeEvent.isComposing)
|
|
24
|
+
return;
|
|
25
|
+
e.preventDefault();
|
|
26
|
+
send();
|
|
27
|
+
};
|
|
28
|
+
return (_jsxs(Box, { component: "form", onSubmit: (e) => { e.preventDefault(); send(); }, sx: { flexShrink: 0, px: 1.5, pb: 1.5 }, children: [_jsxs(Box, { "data-testid": "composer-surface", sx: {
|
|
29
|
+
display: "flex",
|
|
30
|
+
alignItems: "flex-end",
|
|
31
|
+
gap: 1,
|
|
32
|
+
py: 1,
|
|
33
|
+
pl: 1.5,
|
|
34
|
+
pr: 1,
|
|
35
|
+
bgcolor: "background.paper",
|
|
36
|
+
border: 1,
|
|
37
|
+
borderColor: "divider",
|
|
38
|
+
borderRadius: 1,
|
|
39
|
+
"&:focus-within": {
|
|
40
|
+
borderColor: "primary.main",
|
|
41
|
+
boxShadow: (t) => `0 0 0 1px ${(t.vars || t).palette.primary.main}`,
|
|
42
|
+
},
|
|
43
|
+
}, children: [_jsx(InputBase, { multiline: true, fullWidth: true, minRows: 1, maxRows: 8, value: value, disabled: disabled, placeholder: l.placeholder, onChange: (e) => setValue(e.target.value), onKeyDown: onKeyDown, inputProps: { "aria-label": l.placeholder }, sx: { py: 0.5, alignItems: "flex-end", "& textarea": { outline: "none" } } }), _jsx(SendOrStopButton, { streaming: isStreaming, canSend: canSend, onSend: send, onStop: stopStreaming, sendLabel: l.send, stopLabel: l.stop })] }), (!touch || showCounter) && (_jsxs(Box, { sx: { display: "flex", justifyContent: "space-between", gap: 1, mt: 0.5, px: 0.5 }, children: [_jsx(Typography, { variant: "caption", color: "text.secondary", children: touch ? "" : l.hint }), showCounter && (_jsx(Typography, { variant: "caption", color: length > maxMessage ? "error" : "text.secondary", children: `${length} / ${maxMessage}` }))] }))] }));
|
|
44
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/** Round "jump to latest" button, centred above the composer; replaces the x-chat scrollToBottom slot. */
|
|
3
|
+
import KeyboardArrowDown from "@mui/icons-material/KeyboardArrowDown";
|
|
4
|
+
import Box from "@mui/material/Box";
|
|
5
|
+
import Button from "@mui/material/Button";
|
|
6
|
+
import Tooltip from "@mui/material/Tooltip";
|
|
7
|
+
import { useMessageListContext } from "@mui/x-chat-headless";
|
|
8
|
+
import { defaultComposerLabels } from "./labels";
|
|
9
|
+
export function JumpToLatest({ labels }) {
|
|
10
|
+
const l = { ...defaultComposerLabels, ...labels };
|
|
11
|
+
const { isAtBottom, unseenMessageCount, scrollToBottom } = useMessageListContext();
|
|
12
|
+
if (isAtBottom)
|
|
13
|
+
return null;
|
|
14
|
+
const fresh = unseenMessageCount > 0;
|
|
15
|
+
return (_jsx(Box, { sx: { position: "sticky", bottom: 0, height: 0, display: "flex", justifyContent: "center", overflow: "visible", pointerEvents: "none" }, children: _jsx(Tooltip, { title: l.jumpToLatest, children: _jsx(Button, { variant: "contained", color: "inherit", "aria-label": l.jumpToLatest, onClick: () => scrollToBottom({ behavior: "smooth" }), startIcon: fresh ? _jsx(KeyboardArrowDown, {}) : undefined, sx: {
|
|
16
|
+
pointerEvents: "auto",
|
|
17
|
+
position: "absolute",
|
|
18
|
+
bottom: (t) => t.spacing(1),
|
|
19
|
+
borderRadius: 4,
|
|
20
|
+
minWidth: 0,
|
|
21
|
+
bgcolor: "background.paper",
|
|
22
|
+
color: "text.primary",
|
|
23
|
+
border: 1,
|
|
24
|
+
borderColor: "divider",
|
|
25
|
+
}, children: fresh ? l.newMessages : _jsx(KeyboardArrowDown, {}) }) }) }));
|
|
26
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface SendOrStopButtonProps {
|
|
2
|
+
streaming: boolean;
|
|
3
|
+
canSend: boolean;
|
|
4
|
+
onSend: () => void;
|
|
5
|
+
onStop: () => void;
|
|
6
|
+
sendLabel: string;
|
|
7
|
+
stopLabel: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function SendOrStopButton({ streaming, canSend, onSend, onStop, sendLabel, stopLabel }: SendOrStopButtonProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/** Round send / stop button shown inside the composer surface. */
|
|
3
|
+
import ArrowUpward from "@mui/icons-material/ArrowUpward";
|
|
4
|
+
import StopRounded from "@mui/icons-material/StopRounded";
|
|
5
|
+
import IconButton from "@mui/material/IconButton";
|
|
6
|
+
import Tooltip from "@mui/material/Tooltip";
|
|
7
|
+
export function SendOrStopButton({ streaming, canSend, onSend, onStop, sendLabel, stopLabel }) {
|
|
8
|
+
const label = streaming ? stopLabel : sendLabel;
|
|
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
|
+
flexShrink: 0,
|
|
11
|
+
borderRadius: "50%",
|
|
12
|
+
backgroundColor: "primary.main",
|
|
13
|
+
color: "primary.contrastText",
|
|
14
|
+
"&:hover": { backgroundColor: "primary.dark" },
|
|
15
|
+
"&.Mui-disabled": {
|
|
16
|
+
backgroundColor: "action.disabledBackground",
|
|
17
|
+
color: "action.disabled",
|
|
18
|
+
},
|
|
19
|
+
width: t.spacing(4),
|
|
20
|
+
height: t.spacing(4),
|
|
21
|
+
}), children: streaming ? _jsx(StopRounded, { fontSize: "small" }) : _jsx(ArrowUpward, { fontSize: "small" }) }) }) }));
|
|
22
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Composer area: single-surface input, send/stop button, jump-to-latest, ChatBox slot helper. */
|
|
2
|
+
export { ChatComposer, type ChatComposerProps } from "./ChatComposer";
|
|
3
|
+
export { SendOrStopButton, type SendOrStopButtonProps } from "./SendOrStopButton";
|
|
4
|
+
export { JumpToLatest } from "./JumpToLatest";
|
|
5
|
+
export { composerSlots } from "./slots";
|
|
6
|
+
export { defaultComposerLabels, type ComposerLabels } from "./labels";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Composer area: single-surface input, send/stop button, jump-to-latest, ChatBox slot helper. */
|
|
2
|
+
export { ChatComposer } from "./ChatComposer";
|
|
3
|
+
export { SendOrStopButton } from "./SendOrStopButton";
|
|
4
|
+
export { JumpToLatest } from "./JumpToLatest";
|
|
5
|
+
export { composerSlots } from "./slots";
|
|
6
|
+
export { defaultComposerLabels } from "./labels";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Composer user-visible strings with English defaults. */
|
|
2
|
+
export interface ComposerLabels {
|
|
3
|
+
placeholder: string;
|
|
4
|
+
send: string;
|
|
5
|
+
stop: string;
|
|
6
|
+
hint: string;
|
|
7
|
+
jumpToLatest: string;
|
|
8
|
+
newMessages: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const defaultComposerLabels: ComposerLabels;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ComposerLabels } from "./labels";
|
|
2
|
+
export declare function composerSlots(labels?: Partial<ComposerLabels>, maxMessage?: number): {
|
|
3
|
+
readonly slots: {
|
|
4
|
+
readonly composerRoot: import("react").FunctionComponent<{}>;
|
|
5
|
+
readonly scrollToBottom: import("react").FunctionComponent<{}>;
|
|
6
|
+
};
|
|
7
|
+
readonly slotProps: {};
|
|
8
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ChatComposer } from "./ChatComposer";
|
|
3
|
+
import { JumpToLatest } from "./JumpToLatest";
|
|
4
|
+
export function composerSlots(labels, maxMessage) {
|
|
5
|
+
// composerRoot receives the stock children; we ignore them and render the whole composer.
|
|
6
|
+
const Composer = () => _jsx(ChatComposer, { labels: labels, maxMessage: maxMessage });
|
|
7
|
+
const Jump = () => _jsx(JumpToLatest, { labels: labels });
|
|
8
|
+
return {
|
|
9
|
+
slots: { composerRoot: Composer, scrollToBottom: Jump },
|
|
10
|
+
slotProps: {},
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Session info: IconButton + right Drawer (full-screen Dialog under md) with session fields and resume command. */
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
import type { SessionInfo } from "../../core/types";
|
|
4
|
+
export interface SessionInfoLabels {
|
|
5
|
+
button: string;
|
|
6
|
+
title: string;
|
|
7
|
+
close: string;
|
|
8
|
+
sessionId: string;
|
|
9
|
+
sessionTitle: string;
|
|
10
|
+
profile: string;
|
|
11
|
+
type: string;
|
|
12
|
+
created: string;
|
|
13
|
+
lastTurn: string;
|
|
14
|
+
messages: string;
|
|
15
|
+
status: string;
|
|
16
|
+
active: string;
|
|
17
|
+
archived: string;
|
|
18
|
+
resume: string;
|
|
19
|
+
copy: string;
|
|
20
|
+
copied: string;
|
|
21
|
+
empty: string;
|
|
22
|
+
}
|
|
23
|
+
export declare const DEFAULT_INFO_LABELS: SessionInfoLabels;
|
|
24
|
+
export interface SessionInfoDrawerProps {
|
|
25
|
+
session: SessionInfo;
|
|
26
|
+
open: boolean;
|
|
27
|
+
onClose: () => void;
|
|
28
|
+
labels?: Partial<SessionInfoLabels>;
|
|
29
|
+
agentAvatar?: ReactNode;
|
|
30
|
+
}
|
|
31
|
+
export interface SessionInfoButtonProps {
|
|
32
|
+
session: SessionInfo;
|
|
33
|
+
labels?: Partial<SessionInfoLabels>;
|
|
34
|
+
agentAvatar?: ReactNode;
|
|
35
|
+
}
|
|
36
|
+
export declare function SessionInfoDrawer({ session, open, onClose, labels, agentAvatar }: SessionInfoDrawerProps): import("react").JSX.Element;
|
|
37
|
+
export declare function SessionInfoButton({ session, labels, agentAvatar }: SessionInfoButtonProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** Session info: IconButton + right Drawer (full-screen Dialog under md) with session fields and resume command. */
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import Box from "@mui/material/Box";
|
|
5
|
+
import Button from "@mui/material/Button";
|
|
6
|
+
import Dialog from "@mui/material/Dialog";
|
|
7
|
+
import Drawer from "@mui/material/Drawer";
|
|
8
|
+
import IconButton from "@mui/material/IconButton";
|
|
9
|
+
import Stack from "@mui/material/Stack";
|
|
10
|
+
import Tooltip from "@mui/material/Tooltip";
|
|
11
|
+
import Typography from "@mui/material/Typography";
|
|
12
|
+
import useMediaQuery from "@mui/material/useMediaQuery";
|
|
13
|
+
import { useTheme } from "@mui/material/styles";
|
|
14
|
+
import CloseIcon from "@mui/icons-material/Close";
|
|
15
|
+
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
|
|
16
|
+
import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";
|
|
17
|
+
export const DEFAULT_INFO_LABELS = {
|
|
18
|
+
button: "Session info",
|
|
19
|
+
title: "Session",
|
|
20
|
+
close: "Close",
|
|
21
|
+
sessionId: "Session ID",
|
|
22
|
+
sessionTitle: "Title",
|
|
23
|
+
profile: "Profile",
|
|
24
|
+
type: "Type",
|
|
25
|
+
created: "Created",
|
|
26
|
+
lastTurn: "Last turn",
|
|
27
|
+
messages: "Messages",
|
|
28
|
+
status: "Status",
|
|
29
|
+
active: "Active",
|
|
30
|
+
archived: "Archived",
|
|
31
|
+
resume: "Resume in a terminal",
|
|
32
|
+
copy: "Copy",
|
|
33
|
+
copied: "Copied",
|
|
34
|
+
empty: "—",
|
|
35
|
+
};
|
|
36
|
+
const RTF_UNITS = [
|
|
37
|
+
["year", 31536000],
|
|
38
|
+
["month", 2592000],
|
|
39
|
+
["day", 86400],
|
|
40
|
+
["hour", 3600],
|
|
41
|
+
["minute", 60],
|
|
42
|
+
];
|
|
43
|
+
function relative(epoch) {
|
|
44
|
+
const diff = epoch - Date.now() / 1000;
|
|
45
|
+
const rtf = new Intl.RelativeTimeFormat(undefined, { numeric: "auto" });
|
|
46
|
+
for (const [unit, secs] of RTF_UNITS) {
|
|
47
|
+
if (Math.abs(diff) >= secs)
|
|
48
|
+
return rtf.format(Math.round(diff / secs), unit);
|
|
49
|
+
}
|
|
50
|
+
return rtf.format(Math.round(diff), "second");
|
|
51
|
+
}
|
|
52
|
+
const absolute = (epoch) => new Date(epoch * 1000).toLocaleString();
|
|
53
|
+
function CopyButton({ value, labels }) {
|
|
54
|
+
const [copied, setCopied] = useState(false);
|
|
55
|
+
const copy = async () => {
|
|
56
|
+
try {
|
|
57
|
+
await navigator.clipboard.writeText(value);
|
|
58
|
+
setCopied(true);
|
|
59
|
+
setTimeout(() => setCopied(false), 1500);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
/* clipboard unavailable */
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
return (_jsx(Button, { variant: "outlined", startIcon: _jsx(ContentCopyIcon, {}), onClick: copy, children: copied ? labels.copied : labels.copy }));
|
|
66
|
+
}
|
|
67
|
+
function Row({ label, children }) {
|
|
68
|
+
return (_jsxs(Box, { sx: { display: "contents" }, children: [_jsx(Typography, { variant: "body2", color: "text.secondary", component: "dt", children: label }), _jsx(Typography, { variant: "body2", component: "dd", sx: { m: 0, minWidth: 0, overflowWrap: "anywhere" }, children: children })] }));
|
|
69
|
+
}
|
|
70
|
+
const mono = { fontFamily: "monospace", overflowWrap: "anywhere" };
|
|
71
|
+
function InfoBody({ session, labels, agentAvatar, onClose }) {
|
|
72
|
+
const dash = labels.empty;
|
|
73
|
+
const val = (v) => (v === null || v === undefined || v === "" ? dash : v);
|
|
74
|
+
const time = (t) => t === null || t === undefined ? (dash) : (_jsx("span", { title: absolute(t), children: relative(t) }));
|
|
75
|
+
return (_jsxs(Stack, { spacing: 3, sx: { p: 3, width: { xs: "100%", md: 440 }, maxWidth: "100%" }, children: [_jsxs(Stack, { direction: "row", sx: { alignItems: "center", justifyContent: "space-between" }, children: [_jsx(Typography, { variant: "h6", component: "h2", children: labels.title }), _jsx(Tooltip, { title: labels.close, children: _jsx(IconButton, { "aria-label": labels.close, onClick: onClose, children: _jsx(CloseIcon, {}) }) })] }), _jsxs(Box, { component: "dl", sx: { m: 0, display: "grid", gridTemplateColumns: "max-content 1fr", columnGap: 3, rowGap: 1.5 }, children: [_jsx(Row, { label: labels.sessionId, children: _jsxs(Stack, { direction: "row", spacing: 1, sx: { alignItems: "center" }, children: [_jsx(Box, { component: "span", sx: mono, children: val(session.id) }), session.id ? _jsx(CopyButton, { value: session.id, labels: labels }) : null] }) }), _jsx(Row, { label: labels.sessionTitle, children: val(session.title) }), _jsx(Row, { label: labels.profile, children: _jsxs(Stack, { direction: "row", spacing: 1, sx: { alignItems: "center" }, children: [agentAvatar, _jsx("span", { children: val(session.profile) })] }) }), _jsx(Row, { label: labels.type, children: val(session.source) }), _jsx(Row, { label: labels.created, children: time(session.created) }), _jsx(Row, { label: labels.lastTurn, children: time(session.lastTurn) }), _jsx(Row, { label: labels.messages, children: val(session.messages) }), _jsx(Row, { label: labels.status, children: session.active ? labels.active : labels.archived })] }), _jsxs(Stack, { spacing: 1, children: [_jsx(Typography, { variant: "subtitle2", component: "h3", children: labels.resume }), session.resumeCmd ? (_jsxs(_Fragment, { children: [_jsx(Box, { component: "pre", sx: { ...mono, m: 0, p: 1.5, borderRadius: 1, bgcolor: "action.hover", whiteSpace: "pre-wrap", typography: "body2" }, children: session.resumeCmd }), _jsx(Box, { children: _jsx(CopyButton, { value: session.resumeCmd, labels: labels }) })] })) : (_jsx(Typography, { variant: "body2", children: dash }))] })] }));
|
|
76
|
+
}
|
|
77
|
+
export function SessionInfoDrawer({ session, open, onClose, labels, agentAvatar }) {
|
|
78
|
+
const theme = useTheme();
|
|
79
|
+
const wide = useMediaQuery(theme.breakpoints.up("md"));
|
|
80
|
+
const l = { ...DEFAULT_INFO_LABELS, ...labels };
|
|
81
|
+
const body = _jsx(InfoBody, { session: session, labels: l, agentAvatar: agentAvatar, onClose: onClose });
|
|
82
|
+
if (wide) {
|
|
83
|
+
return (_jsx(Drawer, { anchor: "right", open: open, onClose: onClose, "aria-label": l.title, children: body }));
|
|
84
|
+
}
|
|
85
|
+
return (_jsx(Dialog, { fullScreen: true, open: open, onClose: onClose, "aria-label": l.title, children: body }));
|
|
86
|
+
}
|
|
87
|
+
export function SessionInfoButton({ session, labels, agentAvatar }) {
|
|
88
|
+
const [open, setOpen] = useState(false);
|
|
89
|
+
const l = { ...DEFAULT_INFO_LABELS, ...labels };
|
|
90
|
+
return (_jsxs(_Fragment, { children: [_jsx(Tooltip, { title: l.button, children: _jsx(IconButton, { "aria-label": l.button, onClick: () => setOpen(true), children: _jsx(InfoOutlinedIcon, {}) }) }), _jsx(SessionInfoDrawer, { session: session, open: open, onClose: () => setOpen(false), labels: labels, agentAvatar: agentAvatar })] }));
|
|
91
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** Small collapsible JSON tree. Strings render as text, never HTML. */
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import Box from "@mui/material/Box";
|
|
5
|
+
import ButtonBase from "@mui/material/ButtonBase";
|
|
6
|
+
import Typography from "@mui/material/Typography";
|
|
7
|
+
const mono = { fontFamily: "monospace", overflowWrap: "anywhere" };
|
|
8
|
+
function Scalar({ value }) {
|
|
9
|
+
const color = typeof value === "string" ? "success.main" : value === null ? "text.disabled" : "info.main";
|
|
10
|
+
const text = typeof value === "string" ? JSON.stringify(value) : String(value);
|
|
11
|
+
return _jsx(Typography, { variant: "caption", component: "span", sx: { ...mono, color, whiteSpace: "pre-wrap" }, children: text });
|
|
12
|
+
}
|
|
13
|
+
export function JsonNode({ name, value, depth = 0 }) {
|
|
14
|
+
const [open, setOpen] = useState(depth < 1);
|
|
15
|
+
const key = name !== undefined && (_jsxs(Typography, { variant: "caption", component: "span", color: "text.secondary", sx: mono, children: [name, ": "] }));
|
|
16
|
+
if (value === null || typeof value !== "object") {
|
|
17
|
+
return _jsxs(Box, { sx: { pl: depth ? 2 : 0 }, children: [key, _jsx(Scalar, { value: value })] });
|
|
18
|
+
}
|
|
19
|
+
const entries = Array.isArray(value) ? value.map((v, i) => [String(i), v]) : Object.entries(value);
|
|
20
|
+
const summary = Array.isArray(value) ? `[${entries.length}]` : `{${entries.length}}`;
|
|
21
|
+
return (_jsxs(Box, { sx: { pl: depth ? 2 : 0 }, children: [_jsx(ButtonBase, { "aria-expanded": open, "aria-label": `${name ?? "root"} ${summary}`, onClick: () => setOpen((v) => !v), sx: { ...mono, justifyContent: "flex-start", textAlign: "left" }, children: _jsxs(Typography, { variant: "caption", component: "span", sx: mono, children: [open ? "▾" : "▸", " ", key, summary] }) }), open && entries.map(([k, v]) => _jsx(JsonNode, { name: k, value: v, depth: depth + 1 }, k))] }));
|
|
22
|
+
}
|
|
23
|
+
export function JsonTree({ value }) {
|
|
24
|
+
return _jsx(Box, { "data-testid": "json-tree", children: _jsx(JsonNode, { value: value }) });
|
|
25
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HermesToolCall } from "../../core/types";
|
|
2
|
+
import { type ToolLabels } from "./labels";
|
|
3
|
+
export interface ToolDetailDrawerProps {
|
|
4
|
+
call: HermesToolCall | null | undefined;
|
|
5
|
+
open: boolean;
|
|
6
|
+
onClose: () => void;
|
|
7
|
+
labels?: Partial<ToolLabels>;
|
|
8
|
+
}
|
|
9
|
+
export declare function ToolDetailDrawer({ call, open, onClose, labels }: ToolDetailDrawerProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** Tool call detail: right Drawer (full-screen Dialog under `md`) with Request / Response tabs. */
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import Box from "@mui/material/Box";
|
|
5
|
+
import Button from "@mui/material/Button";
|
|
6
|
+
import Dialog from "@mui/material/Dialog";
|
|
7
|
+
import Drawer from "@mui/material/Drawer";
|
|
8
|
+
import IconButton from "@mui/material/IconButton";
|
|
9
|
+
import Tab from "@mui/material/Tab";
|
|
10
|
+
import Tabs from "@mui/material/Tabs";
|
|
11
|
+
import Tooltip from "@mui/material/Tooltip";
|
|
12
|
+
import Typography from "@mui/material/Typography";
|
|
13
|
+
import useMediaQuery from "@mui/material/useMediaQuery";
|
|
14
|
+
import { useTheme } from "@mui/material/styles";
|
|
15
|
+
import Close from "@mui/icons-material/Close";
|
|
16
|
+
import { ToolFamily } from "./family";
|
|
17
|
+
import { ToolRowFormat } from "./format";
|
|
18
|
+
import { ToolIcon } from "./icons";
|
|
19
|
+
import { JsonTree } from "./JsonTree";
|
|
20
|
+
import { statusOf } from "./ToolRow";
|
|
21
|
+
import { defaultToolLabels } from "./labels";
|
|
22
|
+
function CopyButton({ text, labels }) {
|
|
23
|
+
const [copied, setCopied] = useState(false);
|
|
24
|
+
return (_jsx(Button, { variant: "outlined", onClick: () => {
|
|
25
|
+
void navigator.clipboard?.writeText(text);
|
|
26
|
+
setCopied(true);
|
|
27
|
+
setTimeout(() => setCopied(false), 1500);
|
|
28
|
+
}, children: copied ? labels.copied : labels.copy }));
|
|
29
|
+
}
|
|
30
|
+
function Body({ call, onClose, l }) {
|
|
31
|
+
const [tab, setTab] = useState("request");
|
|
32
|
+
const status = statusOf(call);
|
|
33
|
+
const dur = ToolRowFormat.duration(call.duration_s);
|
|
34
|
+
const statusText = status === "failed" ? l.failed : status === "running" ? l.running : l.done;
|
|
35
|
+
const argsJson = JSON.stringify(call.args ?? {}, null, 2);
|
|
36
|
+
const hasArgs = !!call.args && Object.keys(call.args).length > 0;
|
|
37
|
+
return (_jsxs(Box, { sx: { display: "flex", flexDirection: "column", height: "100%" }, children: [_jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1, p: 2 }, children: [_jsx(ToolIcon, { name: call.name }), _jsxs(Box, { sx: { flex: 1, minWidth: 0 }, children: [_jsx(Typography, { variant: "subtitle1", noWrap: true, children: call.name }), _jsxs(Typography, { variant: "caption", color: "text.secondary", children: [ToolFamily.label(call.name), " \u00B7 ", statusText, dur ? ` · ${dur}` : ""] })] }), _jsx(Tooltip, { title: l.close, children: _jsx(IconButton, { "aria-label": l.close, onClick: onClose, children: _jsx(Close, {}) }) })] }), _jsxs(Tabs, { value: tab, onChange: (_, v) => setTab(v), children: [_jsx(Tab, { value: "request", label: l.request, id: "tool-tab-request", "aria-controls": "tool-panel" }), _jsx(Tab, { value: "response", label: l.response, id: "tool-tab-response", "aria-controls": "tool-panel" })] }), _jsx(Box, { role: "tabpanel", id: "tool-panel", "aria-labelledby": `tool-tab-${tab}`, sx: { p: 2, overflow: "auto", flex: 1, display: "flex", flexDirection: "column", gap: 1, alignItems: "flex-start" }, children: tab === "request" ? (_jsxs(_Fragment, { children: [hasArgs ? _jsx(JsonTree, { value: call.args }) : _jsx(Typography, { variant: "body2", color: "text.secondary", children: l.noArgs }), call.args_clipped && _jsx(Typography, { variant: "caption", color: "warning.main", children: l.argsClipped }), hasArgs && _jsx(CopyButton, { text: argsJson, labels: l })] })) : call.result_preview ? (_jsxs(_Fragment, { children: [_jsx(Typography, { variant: "body2", component: "pre", sx: { fontFamily: "monospace", whiteSpace: "pre-wrap", overflowWrap: "anywhere", m: 0 }, children: call.result_preview }), _jsx(CopyButton, { text: call.result_preview, labels: l })] })) : (_jsx(Typography, { variant: "body2", color: "text.secondary", children: l.noResponse })) })] }));
|
|
38
|
+
}
|
|
39
|
+
export function ToolDetailDrawer({ call, open, onClose, labels }) {
|
|
40
|
+
const l = { ...defaultToolLabels, ...labels };
|
|
41
|
+
const theme = useTheme();
|
|
42
|
+
const small = useMediaQuery(theme.breakpoints.down("md"));
|
|
43
|
+
if (!call)
|
|
44
|
+
return null;
|
|
45
|
+
const body = _jsx(Body, { call: call, onClose: onClose, l: l }, call.id);
|
|
46
|
+
return small ? (_jsx(Dialog, { fullScreen: true, open: open, onClose: onClose, "aria-label": l.details, children: body })) : (_jsx(Drawer, { anchor: "right", open: open, onClose: onClose, slotProps: { paper: { sx: { width: { md: 440 }, maxWidth: "100%" }, "aria-label": l.details } }, children: body }));
|
|
47
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** Renders a resolved inline tool preview (monospace; gutter symbols never colour-only). */
|
|
3
|
+
import Box from "@mui/material/Box";
|
|
4
|
+
import Typography from "@mui/material/Typography";
|
|
5
|
+
import CheckBoxOutlined from "@mui/icons-material/CheckBoxOutlined";
|
|
6
|
+
import CheckBoxOutlineBlank from "@mui/icons-material/CheckBoxOutlineBlank";
|
|
7
|
+
import { gutter } from "./toolPreview";
|
|
8
|
+
import { defaultToolLabels } from "./labels";
|
|
9
|
+
const mono = { fontFamily: "monospace", whiteSpace: "pre-wrap", overflowWrap: "anywhere" };
|
|
10
|
+
export function ToolPreviewView({ preview, labels }) {
|
|
11
|
+
const l = { ...defaultToolLabels, ...labels };
|
|
12
|
+
const more = (n) => n > 0 && _jsx(Typography, { variant: "caption", color: "text.secondary", children: l.more(n) });
|
|
13
|
+
switch (preview.kind) {
|
|
14
|
+
case "none": return null;
|
|
15
|
+
case "diff":
|
|
16
|
+
return (_jsxs(Box, { "data-testid": "tool-preview-diff", sx: { overflowX: "auto" }, children: [preview.lines.map((line, i) => (_jsxs(Typography, { variant: "caption", component: "div", sx: {
|
|
17
|
+
...mono,
|
|
18
|
+
color: line.kind === "added" ? "success.main" : line.kind === "removed" ? "error.main" : "text.secondary",
|
|
19
|
+
}, children: [_jsxs("span", { "aria-hidden": "true", children: [gutter(line.kind), " "] }), line.text] }, i))), more(preview.more)] }));
|
|
20
|
+
case "todos":
|
|
21
|
+
return (_jsxs(Box, { "data-testid": "tool-preview-todos", children: [preview.entries.map((t, i) => {
|
|
22
|
+
const done = t.status === "completed" || t.status === "done";
|
|
23
|
+
return (_jsxs(Typography, { variant: "caption", component: "div", sx: { display: "flex", gap: 0.5, alignItems: "center" }, children: [done ? _jsx(CheckBoxOutlined, { fontSize: "inherit", titleAccess: "completed" }) : _jsx(CheckBoxOutlineBlank, { fontSize: "inherit", titleAccess: t.status }), _jsx("span", { children: t.content })] }, t.id ?? i));
|
|
24
|
+
}), more(preview.more)] }));
|
|
25
|
+
case "subagentGroup":
|
|
26
|
+
return _jsx(Typography, { variant: "caption", color: "text.secondary", children: preview.children.length });
|
|
27
|
+
case "image":
|
|
28
|
+
return _jsx(Typography, { variant: "caption", sx: mono, children: preview.basename });
|
|
29
|
+
case "generic":
|
|
30
|
+
return (_jsxs(Box, { "data-testid": "tool-preview-generic", children: [preview.pairs.map((p) => (_jsxs(Typography, { variant: "caption", component: "div", sx: mono, children: [_jsxs(Box, { component: "span", sx: { color: "text.secondary" }, children: [p.key, ": "] }), p.value] }, p.key))), preview.resultLines.map((r, i) => (_jsx(Typography, { variant: "caption", component: "div", color: "text.secondary", sx: mono, children: r }, i)))] }));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HermesToolCall } from "../../core/types";
|
|
2
|
+
import { type ToolRunStatus } from "./format";
|
|
3
|
+
import { type ToolLabels } from "./labels";
|
|
4
|
+
export interface ToolRowProps {
|
|
5
|
+
call: HermesToolCall;
|
|
6
|
+
running?: boolean;
|
|
7
|
+
onOpen?: (call: HermesToolCall) => void;
|
|
8
|
+
labels?: Partial<ToolLabels>;
|
|
9
|
+
}
|
|
10
|
+
export declare function statusOf(call: HermesToolCall, running?: boolean): ToolRunStatus;
|
|
11
|
+
export declare function ToolRow({ call, running, onOpen, labels }: ToolRowProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,45 @@
|
|
|
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, status; opens detail, chevron toggles an inline preview. */
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import Box from "@mui/material/Box";
|
|
5
|
+
import ButtonBase from "@mui/material/ButtonBase";
|
|
6
|
+
import CircularProgress from "@mui/material/CircularProgress";
|
|
7
|
+
import IconButton from "@mui/material/IconButton";
|
|
8
|
+
import Tooltip from "@mui/material/Tooltip";
|
|
9
|
+
import Typography from "@mui/material/Typography";
|
|
10
|
+
import CheckCircleOutline from "@mui/icons-material/CheckCircleOutlined";
|
|
11
|
+
import ErrorOutline from "@mui/icons-material/ErrorOutlined";
|
|
12
|
+
import ExpandMore from "@mui/icons-material/ExpandMore";
|
|
13
|
+
import ExpandLess from "@mui/icons-material/ExpandLess";
|
|
14
|
+
import { ToolFamily } from "./family";
|
|
15
|
+
import { ToolRowFormat } from "./format";
|
|
16
|
+
import { resolvePreview } from "./toolPreview";
|
|
17
|
+
import { ToolPreviewView } from "./ToolPreviewView";
|
|
18
|
+
import { ToolIcon } from "./icons";
|
|
19
|
+
import { defaultToolLabels } from "./labels";
|
|
20
|
+
export function statusOf(call, running) {
|
|
21
|
+
if (call.state === "failed")
|
|
22
|
+
return "failed";
|
|
23
|
+
if (call.state === "start" || running)
|
|
24
|
+
return call.state === "done" ? "done" : "running";
|
|
25
|
+
return "done";
|
|
26
|
+
}
|
|
27
|
+
function Elapsed() {
|
|
28
|
+
const [s, setS] = useState(0);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const t = setInterval(() => setS((n) => n + 1), 1000);
|
|
31
|
+
return () => clearInterval(t);
|
|
32
|
+
}, []);
|
|
33
|
+
return _jsxs("span", { "data-testid": "tool-elapsed", children: [s, " s"] });
|
|
34
|
+
}
|
|
35
|
+
export function ToolRow({ call, running, onOpen, labels }) {
|
|
36
|
+
const l = { ...defaultToolLabels, ...labels };
|
|
37
|
+
const [expanded, setExpanded] = useState(false);
|
|
38
|
+
const status = statusOf(call, running);
|
|
39
|
+
const args = ToolFamily.argsLine(call.name, call.args, call.preview);
|
|
40
|
+
const preview = resolvePreview(call);
|
|
41
|
+
const hasPreview = preview.kind !== "none";
|
|
42
|
+
const dur = ToolRowFormat.duration(call.duration_s);
|
|
43
|
+
const label = ToolRowFormat.accessibilityLabel({ name: call.name, status, duration: call.duration_s, argsLine: args });
|
|
44
|
+
return (_jsxs(Box, { "data-testid": "tool-row", sx: { bgcolor: "action.hover", borderRadius: 1, p: 0.5 }, children: [_jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 0.5 }, children: [_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, {}), _jsx(CircularProgress, { size: 14, "aria-label": l.running })] })), status === "done" && (_jsxs(_Fragment, { children: [dur && _jsx(Typography, { variant: "caption", children: dur }), _jsx(CheckCircleOutline, { fontSize: "small", color: "success", titleAccess: l.done })] })), status === "failed" && (_jsxs(_Fragment, { children: [dur && _jsx(Typography, { variant: "caption", children: dur }), _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
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { HermesToolCall } from "../../core/types";
|
|
2
|
+
import { type ToolLabels } from "./labels";
|
|
3
|
+
export interface ToolStepGroupProps {
|
|
4
|
+
calls: HermesToolCall[];
|
|
5
|
+
/** The turn is still running: expanded by default; collapsed once the reply is in. */
|
|
6
|
+
running?: boolean;
|
|
7
|
+
onOpen?: (call: HermesToolCall) => void;
|
|
8
|
+
labels?: Partial<ToolLabels>;
|
|
9
|
+
}
|
|
10
|
+
export declare function ToolStepGroup({ calls, running, onOpen, labels }: ToolStepGroupProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** Consecutive tool calls: one call is a ToolRow; several collapse to "N steps · 12 s" with expand. */
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import Box from "@mui/material/Box";
|
|
5
|
+
import ButtonBase from "@mui/material/ButtonBase";
|
|
6
|
+
import Typography from "@mui/material/Typography";
|
|
7
|
+
import ExpandMore from "@mui/icons-material/ExpandMore";
|
|
8
|
+
import ExpandLess from "@mui/icons-material/ExpandLess";
|
|
9
|
+
import { ToolRow } from "./ToolRow";
|
|
10
|
+
import { ToolRowFormat } from "./format";
|
|
11
|
+
import { defaultToolLabels } from "./labels";
|
|
12
|
+
export function ToolStepGroup({ calls, running, onOpen, labels }) {
|
|
13
|
+
const l = { ...defaultToolLabels, ...labels };
|
|
14
|
+
// null = follow the running default; a click pins the user's choice.
|
|
15
|
+
const [pinned, setPinned] = useState(null);
|
|
16
|
+
if (calls.length === 0)
|
|
17
|
+
return null;
|
|
18
|
+
const rowRunning = (c, i) => !!running && c.state === "start" && i === calls.length - 1;
|
|
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);
|
|
23
|
+
const failed = calls.filter((c) => c.state === "failed").length;
|
|
24
|
+
const dur = ToolRowFormat.duration(calls.some((c) => c.duration_s !== undefined) ? total : undefined);
|
|
25
|
+
const title = l.steps(calls.length) + (dur ? ` · ${dur}` : "");
|
|
26
|
+
const action = open ? l.hideSteps : l.showSteps;
|
|
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))] }));
|
|
28
|
+
}
|