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,58 @@
|
|
|
1
|
+
/** Shared contract types for mui-hermes-chat (pure TS, no React/MUI). */
|
|
2
|
+
export declare const ACCENTS: readonly ["indigo", "blue", "teal", "green", "orange", "red", "purple", "pink"];
|
|
3
|
+
export type AccentName = (typeof ACCENTS)[number];
|
|
4
|
+
export interface HermesToolCall {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
state: "done" | "failed" | "start";
|
|
8
|
+
preview?: string;
|
|
9
|
+
args?: Record<string, unknown>;
|
|
10
|
+
args_clipped?: boolean;
|
|
11
|
+
duration_s?: number;
|
|
12
|
+
result_preview?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface HermesMessage {
|
|
15
|
+
id: string;
|
|
16
|
+
role: "user" | "assistant";
|
|
17
|
+
text: string;
|
|
18
|
+
html: string;
|
|
19
|
+
created?: number;
|
|
20
|
+
tools?: HermesToolCall[];
|
|
21
|
+
}
|
|
22
|
+
export interface HistoryPage {
|
|
23
|
+
messages: HermesMessage[];
|
|
24
|
+
cursor: string | null;
|
|
25
|
+
hasMore: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface Participant {
|
|
28
|
+
name: string;
|
|
29
|
+
initials?: string;
|
|
30
|
+
color?: string | null;
|
|
31
|
+
avatarUrl?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface SessionInfo {
|
|
34
|
+
id: string;
|
|
35
|
+
profile: string;
|
|
36
|
+
title: string;
|
|
37
|
+
source: string;
|
|
38
|
+
created: number | null;
|
|
39
|
+
lastTurn: number | null;
|
|
40
|
+
messages: number | null;
|
|
41
|
+
active: boolean;
|
|
42
|
+
resumeCmd: string;
|
|
43
|
+
}
|
|
44
|
+
export interface AgentInfo {
|
|
45
|
+
profile: string;
|
|
46
|
+
label: string;
|
|
47
|
+
initials: string;
|
|
48
|
+
color: string | null;
|
|
49
|
+
}
|
|
50
|
+
export type Target = Record<string, string>;
|
|
51
|
+
export interface ChatUrls {
|
|
52
|
+
turn: string;
|
|
53
|
+
approval?: string;
|
|
54
|
+
new?: string;
|
|
55
|
+
history?: string;
|
|
56
|
+
messages?: string;
|
|
57
|
+
}
|
|
58
|
+
export type CsrfSource = (refresh?: boolean) => Promise<string>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
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";
|
|
3
|
+
export * from "./core";
|
|
4
|
+
export * from "./adapter";
|
|
5
|
+
export * from "./react/avatar";
|
|
6
|
+
export * from "./react/chat";
|
|
7
|
+
export * from "./react/composer";
|
|
8
|
+
export * from "./react/info";
|
|
9
|
+
export * from "./react/tools";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
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";
|
|
3
|
+
export * from "./core";
|
|
4
|
+
export * from "./adapter";
|
|
5
|
+
export * from "./react/avatar";
|
|
6
|
+
export * from "./react/chat";
|
|
7
|
+
export * from "./react/composer";
|
|
8
|
+
export * from "./react/info";
|
|
9
|
+
export * from "./react/tools";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Participant } from "../../core/types";
|
|
2
|
+
export interface ParticipantAvatarProps {
|
|
3
|
+
participant: Participant;
|
|
4
|
+
size?: "sm" | "md";
|
|
5
|
+
}
|
|
6
|
+
export declare function ParticipantAvatar({ participant, size }: ParticipantAvatarProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/** Avatar for a chat participant: image, else initials, else a person icon; stable accent colour. */
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import Avatar from "@mui/material/Avatar";
|
|
5
|
+
import Tooltip from "@mui/material/Tooltip";
|
|
6
|
+
import PersonIcon from "@mui/icons-material/Person";
|
|
7
|
+
import { useTheme } from "@mui/material/styles";
|
|
8
|
+
import { avatarColor, initials } from "../../core/initials";
|
|
9
|
+
import { accentToPalette } from "./accent";
|
|
10
|
+
export function ParticipantAvatar({ participant, size = "md" }) {
|
|
11
|
+
const theme = useTheme();
|
|
12
|
+
const [failed, setFailed] = useState(false);
|
|
13
|
+
useEffect(() => setFailed(false), [participant.avatarUrl]);
|
|
14
|
+
const bg = accentToPalette(theme, participant.color || avatarColor(participant.name));
|
|
15
|
+
const text = participant.initials ?? initials(participant.name);
|
|
16
|
+
const showImage = !!participant.avatarUrl && !failed;
|
|
17
|
+
const dim = size === "sm" ? 3 : 4;
|
|
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
|
+
width: theme.spacing(dim * 2),
|
|
20
|
+
height: theme.spacing(dim * 2),
|
|
21
|
+
bgcolor: bg,
|
|
22
|
+
color: theme.palette.getContrastText(bg),
|
|
23
|
+
fontSize: size === "sm" ? theme.typography.caption.fontSize : theme.typography.body2.fontSize,
|
|
24
|
+
}, children: text || _jsx(PersonIcon, { fontSize: "inherit" }) }) }));
|
|
25
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { blue, green, grey, indigo, orange, pink, purple, red, teal } from "@mui/material/colors";
|
|
2
|
+
const SHADES = { indigo, blue, teal, green, orange, red, purple, pink, gray: grey, grey };
|
|
3
|
+
export function accentToPalette(theme, name) {
|
|
4
|
+
const role = theme.palette[name];
|
|
5
|
+
if (role && typeof role.main === "string")
|
|
6
|
+
return role.main;
|
|
7
|
+
const shades = SHADES[name] ?? indigo;
|
|
8
|
+
return theme.palette.mode === "dark" ? shades[300] : shades[600];
|
|
9
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ApprovalEvent } from "../../core/events";
|
|
2
|
+
import { type ChatLabels } from "./labels";
|
|
3
|
+
export type { ApprovalEvent };
|
|
4
|
+
export declare function clock(left: number): string;
|
|
5
|
+
export interface ApprovalProps {
|
|
6
|
+
event: ApprovalEvent;
|
|
7
|
+
/** Resolves true when the server accepted the answer. */
|
|
8
|
+
onDecide: (choice: "once" | "deny") => Promise<boolean>;
|
|
9
|
+
labels?: Partial<ChatLabels>;
|
|
10
|
+
}
|
|
11
|
+
export declare function Approval({ event, onDecide, labels }: ApprovalProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** Approval card for a pending tool approval: countdown, Approve once / Deny, result line. */
|
|
3
|
+
import Button from "@mui/material/Button";
|
|
4
|
+
import Paper from "@mui/material/Paper";
|
|
5
|
+
import Stack from "@mui/material/Stack";
|
|
6
|
+
import Typography from "@mui/material/Typography";
|
|
7
|
+
import { useEffect, useState } from "react";
|
|
8
|
+
import { defaultChatLabels } from "./labels";
|
|
9
|
+
export function clock(left) {
|
|
10
|
+
return Math.floor(left / 60) + ":" + String(left % 60).padStart(2, "0");
|
|
11
|
+
}
|
|
12
|
+
export function Approval({ event, onDecide, labels }) {
|
|
13
|
+
const l = { ...defaultChatLabels, ...labels };
|
|
14
|
+
const [left, setLeft] = useState(Number(event.expires_s) || 0);
|
|
15
|
+
const [decided, setDecided] = useState(false);
|
|
16
|
+
const [result, setResult] = useState("");
|
|
17
|
+
const live = !decided && left > 0;
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!live)
|
|
20
|
+
return;
|
|
21
|
+
const id = setInterval(() => setLeft((n) => n - 1), 1000);
|
|
22
|
+
return () => clearInterval(id);
|
|
23
|
+
}, [live]);
|
|
24
|
+
const decide = async (choice) => {
|
|
25
|
+
if (decided)
|
|
26
|
+
return;
|
|
27
|
+
setDecided(true); // both buttons lock before anything is awaited
|
|
28
|
+
setResult(l.approvalSending);
|
|
29
|
+
let ok = false;
|
|
30
|
+
try {
|
|
31
|
+
ok = await onDecide(choice);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
setResult(l.approvalFailed);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
setResult(ok ? (choice === "once" ? l.approved : l.denied) : l.approvalRejected);
|
|
38
|
+
};
|
|
39
|
+
const expired = !decided && left <= 0 && Number(event.expires_s) > 0;
|
|
40
|
+
return (_jsxs(Paper, { variant: "outlined", "data-testid": "approval", sx: { p: 1.5 }, children: [_jsx(Typography, { variant: "subtitle2", component: "strong", children: event.title || l.approvalTitle }), _jsx(Typography, { variant: "body2", sx: { overflowWrap: "anywhere", whiteSpace: "pre-wrap" }, children: event.text || "" }), live && _jsx(Typography, { variant: "caption", color: "text.secondary", component: "p", children: l.expiresIn(clock(left)) }), expired && _jsx(Typography, { variant: "caption", color: "text.secondary", component: "p", children: l.expired }), _jsxs(Stack, { direction: "row", spacing: 1, sx: { mt: 1 }, children: [_jsx(Button, { variant: "contained", disabled: decided || expired, onClick: () => void decide("once"), children: l.approveOnce }), _jsx(Button, { variant: "outlined", color: "inherit", disabled: decided || expired, onClick: () => void decide("deny"), children: l.deny })] }), _jsx(Typography, { role: "status", variant: "caption", color: "text.secondary", component: "p", children: result })] }));
|
|
41
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { ChatUrls, CsrfSource, HermesMessage, Participant, SessionInfo, Target } from "../../core/types";
|
|
3
|
+
import { type ChatLabels } from "./labels";
|
|
4
|
+
export interface HermesChatProps {
|
|
5
|
+
urls: ChatUrls;
|
|
6
|
+
target: Target;
|
|
7
|
+
csrf: CsrfSource;
|
|
8
|
+
/** Newest history page from the read model; older pages load through `urls.messages`. */
|
|
9
|
+
history: {
|
|
10
|
+
messages: HermesMessage[];
|
|
11
|
+
cursor: string | null;
|
|
12
|
+
hasMore: boolean;
|
|
13
|
+
};
|
|
14
|
+
/** Renders server-sanitised reply html (the package never injects html itself). */
|
|
15
|
+
renderHtml: (html: string) => ReactNode;
|
|
16
|
+
participants: {
|
|
17
|
+
user: Participant;
|
|
18
|
+
agent: Participant;
|
|
19
|
+
};
|
|
20
|
+
/** Enables the Info button. */
|
|
21
|
+
session?: SessionInfo;
|
|
22
|
+
labels?: Partial<ChatLabels>;
|
|
23
|
+
maxMessage?: number;
|
|
24
|
+
/** Server notice, e.g. "The earlier messages could not be loaded just now." */
|
|
25
|
+
notice?: string;
|
|
26
|
+
linkedNote?: string;
|
|
27
|
+
/** The subject changed under the user: show the note. */
|
|
28
|
+
changed?: boolean;
|
|
29
|
+
/** Earlier conversations: a link to `earlierHref` in the toolbar. */
|
|
30
|
+
hasEarlier?: boolean;
|
|
31
|
+
earlierHref?: string;
|
|
32
|
+
/** Called after every finished turn and after New chat. */
|
|
33
|
+
onTurnEnd?: () => void;
|
|
34
|
+
/** `inline` is the card in place; `sheet` a full-screen dialog behind a button; `auto` = sheet on phones. */
|
|
35
|
+
mode?: "inline" | "sheet" | "auto";
|
|
36
|
+
fit?: {
|
|
37
|
+
minHeight?: number;
|
|
38
|
+
bottomGap?: number;
|
|
39
|
+
};
|
|
40
|
+
toolbarActions?: ReactNode;
|
|
41
|
+
}
|
|
42
|
+
export declare function HermesChat(props: HermesChatProps): import("react").JSX.Element;
|
|
43
|
+
export default HermesChat;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* `<HermesChat />`: one card (toolbar → notes → message list → composer) on `@mui/x-chat`, fed by `hermesChatAdapter`.
|
|
4
|
+
* Final replies render through the consumer's `renderHtml`; history pages in when the list is scrolled to the top.
|
|
5
|
+
*/
|
|
6
|
+
import AddCommentOutlined from "@mui/icons-material/AddCommentOutlined";
|
|
7
|
+
import Alert from "@mui/material/Alert";
|
|
8
|
+
import Box from "@mui/material/Box";
|
|
9
|
+
import Button from "@mui/material/Button";
|
|
10
|
+
import Dialog from "@mui/material/Dialog";
|
|
11
|
+
import DialogActions from "@mui/material/DialogActions";
|
|
12
|
+
import DialogContent from "@mui/material/DialogContent";
|
|
13
|
+
import DialogContentText from "@mui/material/DialogContentText";
|
|
14
|
+
import DialogTitle from "@mui/material/DialogTitle";
|
|
15
|
+
import IconButton from "@mui/material/IconButton";
|
|
16
|
+
import Link from "@mui/material/Link";
|
|
17
|
+
import Paper from "@mui/material/Paper";
|
|
18
|
+
import Tooltip from "@mui/material/Tooltip";
|
|
19
|
+
import Typography from "@mui/material/Typography";
|
|
20
|
+
import useMediaQuery from "@mui/material/useMediaQuery";
|
|
21
|
+
import { useTheme } from "@mui/material/styles";
|
|
22
|
+
import { visuallyHidden } from "@mui/utils";
|
|
23
|
+
import { ChatBox } from "@mui/x-chat";
|
|
24
|
+
import { useChat, useMessageContext } from "@mui/x-chat/headless";
|
|
25
|
+
import { useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
26
|
+
import { AGENT_AUTHOR_ID, USER_AUTHOR_ID, hermesChatAdapter, toChatMessages } from "../../adapter/adapter";
|
|
27
|
+
import { sendApproval, startOver } from "../../core/transport";
|
|
28
|
+
import { ParticipantAvatar } from "../avatar/ParticipantAvatar";
|
|
29
|
+
import { composerSlots } from "../composer/slots";
|
|
30
|
+
import { SessionInfoButton } from "../info/SessionInfo";
|
|
31
|
+
import { ToolDetailDrawer } from "../tools/ToolDetailDrawer";
|
|
32
|
+
import { defaultChatLabels } from "./labels";
|
|
33
|
+
import { hermesPartRenderers } from "./parts";
|
|
34
|
+
import { useFitHeight } from "./useFitHeight";
|
|
35
|
+
const CONVERSATION = "hermes";
|
|
36
|
+
/** Per-message avatar from the participants (the message role picks which). */
|
|
37
|
+
function avatarSlot(participants) {
|
|
38
|
+
return function MessageAvatarSlot({ className }) {
|
|
39
|
+
const { role } = useMessageContext();
|
|
40
|
+
return (_jsx(Box, { className: className, sx: { display: "flex", alignItems: "flex-start" }, children: _jsx(ParticipantAvatar, { participant: role === "user" ? participants.user : participants.agent, size: "sm" }) }));
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** The author line is dropped visually (compact header) but stays for screen readers. */
|
|
44
|
+
function HiddenAuthor({ children }) {
|
|
45
|
+
return _jsx(Box, { component: "span", sx: visuallyHidden, children: children });
|
|
46
|
+
}
|
|
47
|
+
/** Paging status above the list: loading row, error + Retry, keyboard "Load earlier", start marker. */
|
|
48
|
+
function HistoryBar({ labels }) {
|
|
49
|
+
const { messages, hasMoreHistory, isLoadingHistory, error, loadMoreHistory } = useChat();
|
|
50
|
+
if (!messages.length)
|
|
51
|
+
return null;
|
|
52
|
+
const failed = error?.source === "history";
|
|
53
|
+
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
|
+
}
|
|
55
|
+
function Panel(props) {
|
|
56
|
+
const { urls, target, csrf, history, renderHtml, participants, session, maxMessage, notice, linkedNote, changed, hasEarlier, earlierHref, onTurnEnd, toolbarActions, fit, fitHeight } = props;
|
|
57
|
+
const labels = useMemo(() => ({ ...defaultChatLabels, ...props.labels }), [props.labels]);
|
|
58
|
+
const [epoch, setEpoch] = useState(0);
|
|
59
|
+
const [error, setError] = useState("");
|
|
60
|
+
const [confirming, setConfirming] = useState(false);
|
|
61
|
+
const [said, setSaid] = useState("");
|
|
62
|
+
const [tool, setTool] = useState(null);
|
|
63
|
+
const scroller = useRef(null);
|
|
64
|
+
const { ref, maxHeight } = useFitHeight(fit, fitHeight);
|
|
65
|
+
// After New chat the history is gone: an empty first page.
|
|
66
|
+
const page = useMemo(() => (epoch ? { messages: [], cursor: null, hasMore: false } : history), [epoch, history]);
|
|
67
|
+
const adapter = useMemo(() => hermesChatAdapter({ urls, target, csrf, initialPage: page }), [urls, target, csrf, page]);
|
|
68
|
+
const initialMessages = useMemo(() => toChatMessages(page.messages), [page]);
|
|
69
|
+
const partRenderers = useMemo(() => hermesPartRenderers({
|
|
70
|
+
decide: (ev, choice) => sendApproval(urls.approval ?? "", target, ev, choice, csrf),
|
|
71
|
+
renderHtml,
|
|
72
|
+
onOpenTool: setTool,
|
|
73
|
+
labels,
|
|
74
|
+
}), [urls.approval, target, csrf, renderHtml, labels]);
|
|
75
|
+
const composer = useMemo(() => composerSlots(labels, maxMessage), [labels, maxMessage]);
|
|
76
|
+
const slots = useMemo(() => ({
|
|
77
|
+
...composer.slots,
|
|
78
|
+
messageAvatar: avatarSlot(participants),
|
|
79
|
+
messageAuthorName: HiddenAuthor,
|
|
80
|
+
conversationHeader: () => _jsx(HistoryBar, { labels: labels }),
|
|
81
|
+
}), [composer, participants, labels]);
|
|
82
|
+
// x-chat only follows appends: open (and re-open after New chat) at the newest message.
|
|
83
|
+
useLayoutEffect(() => {
|
|
84
|
+
const el = scroller.current;
|
|
85
|
+
if (!el)
|
|
86
|
+
return;
|
|
87
|
+
el.scrollTop = el.scrollHeight;
|
|
88
|
+
const raf = requestAnimationFrame(() => { el.scrollTop = el.scrollHeight; }); // rows are measured after first paint
|
|
89
|
+
return () => cancelAnimationFrame(raf);
|
|
90
|
+
}, [epoch]);
|
|
91
|
+
const reset = async () => {
|
|
92
|
+
setConfirming(false);
|
|
93
|
+
try {
|
|
94
|
+
if (!urls.new || !(await startOver(urls.new, target, csrf)))
|
|
95
|
+
throw new Error("refused");
|
|
96
|
+
setError("");
|
|
97
|
+
setEpoch((n) => n + 1);
|
|
98
|
+
onTurnEnd?.();
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
setError(labels.startOverFailed);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
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: 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
|
+
messageList: { autoScroll: true, slotProps: { messageListScroller: { ref: scroller, "aria-live": "off", "aria-label": labels.messageList } } },
|
|
110
|
+
messageContent: { sx: { maxWidth: "72ch", overflowWrap: "anywhere" } },
|
|
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 })] })] })] }));
|
|
112
|
+
}
|
|
113
|
+
export function HermesChat(props) {
|
|
114
|
+
const theme = useTheme();
|
|
115
|
+
const phone = useMediaQuery(theme.breakpoints.down("md"));
|
|
116
|
+
const labels = { ...defaultChatLabels, ...props.labels };
|
|
117
|
+
const sheet = props.mode === "sheet" || (props.mode !== "inline" && phone);
|
|
118
|
+
// lazy initialiser: mounting on a phone opens the sheet once; closing never reopens it
|
|
119
|
+
const [open, setOpen] = useState(sheet);
|
|
120
|
+
if (!sheet)
|
|
121
|
+
return _jsx(Panel, { ...props, fitHeight: true });
|
|
122
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "outlined", onClick: () => setOpen(true), children: labels.chatOpen }), _jsx(Dialog, { fullScreen: true, keepMounted: true, open: open, onClose: () => setOpen(false), "aria-label": labels.chat, children: _jsxs(Box, { sx: { display: "flex", flexDirection: "column", height: "100dvh", p: 1.5, gap: 1 }, children: [_jsx(Box, { sx: { display: "flex", justifyContent: "flex-end" }, children: _jsx(Button, { onClick: () => setOpen(false), children: labels.close }) }), _jsx(Box, { sx: { flex: 1, minHeight: 0, display: "flex", flexDirection: "column" }, children: _jsx(Panel, { ...props, fitHeight: false }) })] }) })] }));
|
|
123
|
+
}
|
|
124
|
+
export default HermesChat;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Chat area: `<HermesChat />`, Approval, part renderers, fit-height hook, labels. */
|
|
2
|
+
export { HermesChat, type HermesChatProps } from "./HermesChat";
|
|
3
|
+
export { Approval, type ApprovalProps } from "./Approval";
|
|
4
|
+
export { hermesPartRenderers, StreamedText, ReplyHtml, toolCallsOf, type PartDeps } from "./parts";
|
|
5
|
+
export { useFitHeight, fitMaxHeight, type FitHeightOptions } from "./useFitHeight";
|
|
6
|
+
export { defaultChatLabels, type ChatLabels, type ChatOwnLabels } from "./labels";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Chat area: `<HermesChat />`, Approval, part renderers, fit-height hook, labels. */
|
|
2
|
+
export { HermesChat } from "./HermesChat";
|
|
3
|
+
export { Approval } from "./Approval";
|
|
4
|
+
export { hermesPartRenderers, StreamedText, ReplyHtml, toolCallsOf } from "./parts";
|
|
5
|
+
export { useFitHeight, fitMaxHeight } from "./useFitHeight";
|
|
6
|
+
export { defaultChatLabels } from "./labels";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Every user-visible string of `<HermesChat />` (own + the composer, tool and info areas) with English defaults. */
|
|
2
|
+
import { type ComposerLabels } from "../composer/labels";
|
|
3
|
+
import { type SessionInfoLabels } from "../info/SessionInfo";
|
|
4
|
+
import { type ToolLabels } from "../tools/labels";
|
|
5
|
+
export interface ChatOwnLabels {
|
|
6
|
+
newChat: string;
|
|
7
|
+
newChatTitle: string;
|
|
8
|
+
newChatBody: string;
|
|
9
|
+
newChatConfirm: string;
|
|
10
|
+
cancel: string;
|
|
11
|
+
startOverFailed: string;
|
|
12
|
+
earlierConversations: string;
|
|
13
|
+
loadingEarlier: string;
|
|
14
|
+
startOfConversation: string;
|
|
15
|
+
loadEarlier: string;
|
|
16
|
+
loadEarlierFailed: string;
|
|
17
|
+
retry: string;
|
|
18
|
+
changedNote: string;
|
|
19
|
+
replied: string;
|
|
20
|
+
chat: string;
|
|
21
|
+
chatOpen: string;
|
|
22
|
+
author: (name: string) => string;
|
|
23
|
+
commentary: string;
|
|
24
|
+
errorDefault: string;
|
|
25
|
+
copyCode: string;
|
|
26
|
+
copyCodeShort: string;
|
|
27
|
+
copiedCode: string;
|
|
28
|
+
approvalTitle: string;
|
|
29
|
+
approveOnce: string;
|
|
30
|
+
deny: string;
|
|
31
|
+
approvalSending: string;
|
|
32
|
+
approvalFailed: string;
|
|
33
|
+
approved: string;
|
|
34
|
+
denied: string;
|
|
35
|
+
approvalRejected: string;
|
|
36
|
+
expired: string;
|
|
37
|
+
expiresIn: (clock: string) => string;
|
|
38
|
+
messageList: string;
|
|
39
|
+
}
|
|
40
|
+
export type ChatLabels = ComposerLabels & ToolLabels & SessionInfoLabels & ChatOwnLabels;
|
|
41
|
+
export declare const defaultChatLabels: ChatLabels;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** Every user-visible string of `<HermesChat />` (own + the composer, tool and info areas) with English defaults. */
|
|
2
|
+
import { defaultComposerLabels } from "../composer/labels";
|
|
3
|
+
import { DEFAULT_INFO_LABELS } from "../info/SessionInfo";
|
|
4
|
+
import { defaultToolLabels } from "../tools/labels";
|
|
5
|
+
export const defaultChatLabels = {
|
|
6
|
+
...defaultComposerLabels,
|
|
7
|
+
...defaultToolLabels,
|
|
8
|
+
...DEFAULT_INFO_LABELS,
|
|
9
|
+
newChat: "New chat",
|
|
10
|
+
newChatTitle: "Start over?",
|
|
11
|
+
newChatBody: "This conversation will be archived.",
|
|
12
|
+
newChatConfirm: "Start over",
|
|
13
|
+
cancel: "Cancel",
|
|
14
|
+
startOverFailed: "Could not start over just now.",
|
|
15
|
+
earlierConversations: "Earlier conversations",
|
|
16
|
+
loadingEarlier: "Loading earlier messages…",
|
|
17
|
+
startOfConversation: "Start of conversation",
|
|
18
|
+
loadEarlier: "Load earlier messages",
|
|
19
|
+
loadEarlierFailed: "Could not load earlier messages.",
|
|
20
|
+
retry: "Retry",
|
|
21
|
+
changedNote: "Card changed: the next message will tell the agent.",
|
|
22
|
+
replied: "Hermes replied.",
|
|
23
|
+
chat: "Chat",
|
|
24
|
+
chatOpen: "Open chat",
|
|
25
|
+
author: (name) => `${name}:`,
|
|
26
|
+
commentary: "Note",
|
|
27
|
+
errorDefault: "Something went wrong.",
|
|
28
|
+
copyCode: "Copy code",
|
|
29
|
+
copyCodeShort: "Copy",
|
|
30
|
+
copiedCode: "Copied",
|
|
31
|
+
approvalTitle: "Approval needed",
|
|
32
|
+
approveOnce: "Approve once",
|
|
33
|
+
deny: "Deny",
|
|
34
|
+
approvalSending: "Sending…",
|
|
35
|
+
approvalFailed: "Could not send the answer.",
|
|
36
|
+
approved: "Approved once.",
|
|
37
|
+
denied: "Denied.",
|
|
38
|
+
approvalRejected: "The answer was not accepted (it may have expired).",
|
|
39
|
+
expired: "Expired",
|
|
40
|
+
expiresIn: (c) => `Expires in ${c}`,
|
|
41
|
+
messageList: "Conversation",
|
|
42
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ChatPartRendererMap } from "@mui/x-chat/headless";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
import type { ApprovalEvent } from "../../core/events";
|
|
4
|
+
import type { HermesToolCall } from "../../core/types";
|
|
5
|
+
import { type ChatLabels } from "./labels";
|
|
6
|
+
/** Streamed text: plain, but ``` fences become code blocks (with the library's copy button). */
|
|
7
|
+
export declare function StreamedText({ text }: {
|
|
8
|
+
text: string;
|
|
9
|
+
}): ReactNode;
|
|
10
|
+
/** Server-sanitised reply html via the consumer's `renderHtml`, with a Copy button on every code block (DOM calls only). */
|
|
11
|
+
export declare function ReplyHtml({ html, renderHtml, labels }: {
|
|
12
|
+
html: string;
|
|
13
|
+
renderHtml: (html: string) => ReactNode;
|
|
14
|
+
labels?: Partial<ChatLabels>;
|
|
15
|
+
}): import("react").JSX.Element;
|
|
16
|
+
export interface PartDeps {
|
|
17
|
+
/** Decide an approval through the approval endpoint (same POST + CSRF). */
|
|
18
|
+
decide: (event: ApprovalEvent, choice: "once" | "deny") => Promise<boolean>;
|
|
19
|
+
renderHtml: (html: string) => ReactNode;
|
|
20
|
+
/** A tool row was opened (opens the detail drawer). */
|
|
21
|
+
onOpenTool?: (call: HermesToolCall) => void;
|
|
22
|
+
labels?: Partial<ChatLabels>;
|
|
23
|
+
}
|
|
24
|
+
interface ToolInvocationLike {
|
|
25
|
+
toolCallId?: string;
|
|
26
|
+
toolName: string;
|
|
27
|
+
state: string;
|
|
28
|
+
input?: unknown;
|
|
29
|
+
output?: unknown;
|
|
30
|
+
errorText?: string;
|
|
31
|
+
}
|
|
32
|
+
/** x-chat tool invocation → a contract tool call (live parts carry the adapter's input/output shapes). */
|
|
33
|
+
export declare function toolCallOf(inv: ToolInvocationLike): HermesToolCall;
|
|
34
|
+
/** Consecutive tool parts of one message (history `data-tools` + live dynamic-tool) as the calls to show. */
|
|
35
|
+
export declare function toolCallsOf(parts: ReadonlyArray<{
|
|
36
|
+
type: string;
|
|
37
|
+
data?: unknown;
|
|
38
|
+
toolInvocation?: unknown;
|
|
39
|
+
}>): HermesToolCall[];
|
|
40
|
+
export declare function hermesPartRenderers({ decide, renderHtml, onOpenTool, labels }: PartDeps): ChatPartRendererMap;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/** Part renderers for the x-chat message parts the Hermes adapter emits. */
|
|
3
|
+
import Alert from "@mui/material/Alert";
|
|
4
|
+
import Box from "@mui/material/Box";
|
|
5
|
+
import Typography from "@mui/material/Typography";
|
|
6
|
+
import { ChatCodeBlock } from "@mui/x-chat";
|
|
7
|
+
import { useEffect, useRef } from "react";
|
|
8
|
+
import { ToolStepGroup } from "../tools/ToolStepGroup";
|
|
9
|
+
import { Approval } from "./Approval";
|
|
10
|
+
import { defaultChatLabels } from "./labels";
|
|
11
|
+
const wrap = { whiteSpace: "pre-wrap", overflowWrap: "anywhere", minWidth: 0 };
|
|
12
|
+
/** Streamed text: plain, but ``` fences become code blocks (with the library's copy button). */
|
|
13
|
+
export function StreamedText({ text }) {
|
|
14
|
+
const chunks = text.split(/```/);
|
|
15
|
+
return (_jsx(_Fragment, { children: chunks.map((c, i) => {
|
|
16
|
+
if (i % 2 === 0)
|
|
17
|
+
return c ? _jsx(Typography, { variant: "body2", component: "div", sx: wrap, children: c }, i) : null;
|
|
18
|
+
const nl = c.indexOf("\n");
|
|
19
|
+
const lang = nl >= 0 ? c.slice(0, nl).trim() : "";
|
|
20
|
+
const code = nl >= 0 && /^[\w+#.-]*$/.test(lang) ? c.slice(nl + 1) : c;
|
|
21
|
+
return _jsx(ChatCodeBlock, { language: lang || undefined, children: code.replace(/\n$/, "") }, i);
|
|
22
|
+
}) }));
|
|
23
|
+
}
|
|
24
|
+
/** Server-sanitised reply html via the consumer's `renderHtml`, with a Copy button on every code block (DOM calls only). */
|
|
25
|
+
export function ReplyHtml({ html, renderHtml, labels }) {
|
|
26
|
+
const l = { ...defaultChatLabels, ...labels };
|
|
27
|
+
const ref = useRef(null);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const root = ref.current;
|
|
30
|
+
if (!root)
|
|
31
|
+
return;
|
|
32
|
+
const added = [];
|
|
33
|
+
root.querySelectorAll("pre").forEach((pre) => {
|
|
34
|
+
const host = pre.parentElement;
|
|
35
|
+
if (!host || host.dataset.hcCopy)
|
|
36
|
+
return;
|
|
37
|
+
host.dataset.hcCopy = "1";
|
|
38
|
+
host.style.position = "relative";
|
|
39
|
+
const b = document.createElement("button");
|
|
40
|
+
b.type = "button";
|
|
41
|
+
b.textContent = l.copyCodeShort;
|
|
42
|
+
b.setAttribute("aria-label", l.copyCode);
|
|
43
|
+
b.style.cssText = "position:absolute;top:4px;right:4px"; // CSSOM, allowed by style-src
|
|
44
|
+
b.addEventListener("click", () => {
|
|
45
|
+
void navigator.clipboard?.writeText(pre.textContent ?? "").then(() => {
|
|
46
|
+
b.textContent = l.copiedCode;
|
|
47
|
+
setTimeout(() => { b.textContent = l.copyCodeShort; }, 1500);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
host.appendChild(b);
|
|
51
|
+
added.push(b);
|
|
52
|
+
});
|
|
53
|
+
return () => added.forEach((b) => { b.parentElement?.removeAttribute("data-hc-copy"); b.remove(); });
|
|
54
|
+
}, [html, l.copyCode, l.copyCodeShort, l.copiedCode]);
|
|
55
|
+
return _jsx(Box, { ref: ref, "data-testid": "reply-html", children: renderHtml(html) });
|
|
56
|
+
}
|
|
57
|
+
/** x-chat tool invocation → a contract tool call (live parts carry the adapter's input/output shapes). */
|
|
58
|
+
export function toolCallOf(inv) {
|
|
59
|
+
const state = inv.state === "output-available" ? "done" : inv.state === "output-error" ? "failed" : "start";
|
|
60
|
+
const input = (inv.input && typeof inv.input === "object" ? inv.input : {});
|
|
61
|
+
const out = (inv.output && typeof inv.output === "object" ? inv.output : {});
|
|
62
|
+
const call = { id: inv.toolCallId ?? inv.toolName, name: inv.toolName, state };
|
|
63
|
+
const keys = Object.keys(input);
|
|
64
|
+
if (keys.length === 1 && keys[0] === "preview" && typeof input.preview === "string")
|
|
65
|
+
call.preview = input.preview;
|
|
66
|
+
else if (keys.length)
|
|
67
|
+
call.args = input;
|
|
68
|
+
if (typeof out.result_preview === "string")
|
|
69
|
+
call.result_preview = out.result_preview;
|
|
70
|
+
else if (inv.errorText && inv.errorText !== "failed")
|
|
71
|
+
call.result_preview = inv.errorText;
|
|
72
|
+
if (typeof out.duration_s === "number")
|
|
73
|
+
call.duration_s = out.duration_s;
|
|
74
|
+
return call;
|
|
75
|
+
}
|
|
76
|
+
/** Consecutive tool parts of one message (history `data-tools` + live dynamic-tool) as the calls to show. */
|
|
77
|
+
export function toolCallsOf(parts) {
|
|
78
|
+
const calls = [];
|
|
79
|
+
for (const p of parts) {
|
|
80
|
+
if (p.type === "data-tools" && Array.isArray(p.data))
|
|
81
|
+
calls.push(...p.data);
|
|
82
|
+
else if ((p.type === "dynamic-tool" || p.type === "tool") && p.toolInvocation)
|
|
83
|
+
calls.push(toolCallOf(p.toolInvocation));
|
|
84
|
+
}
|
|
85
|
+
return calls;
|
|
86
|
+
}
|
|
87
|
+
export function hermesPartRenderers({ decide, renderHtml, onOpenTool, labels }) {
|
|
88
|
+
const l = { ...defaultChatLabels, ...labels };
|
|
89
|
+
// The first tool-ish part of a message renders the whole group; later ones render nothing.
|
|
90
|
+
const group = ({ part, message }) => {
|
|
91
|
+
const parts = message.parts;
|
|
92
|
+
const first = parts.find((p) => p.type === "data-tools" || p.type === "dynamic-tool" || p.type === "tool");
|
|
93
|
+
if (first !== part)
|
|
94
|
+
return null;
|
|
95
|
+
const calls = toolCallsOf(parts);
|
|
96
|
+
const running = calls.some((c) => c.state === "start");
|
|
97
|
+
return _jsx(ToolStepGroup, { calls: calls, running: running, onOpen: onOpenTool, labels: labels });
|
|
98
|
+
};
|
|
99
|
+
return {
|
|
100
|
+
text: ({ part, message }) => message.parts.some((p) => p.type === "data-reply") ? null : _jsx(StreamedText, { text: part.text }),
|
|
101
|
+
"data-reply": ({ part }) => _jsx(ReplyHtml, { html: part.data.html ?? "", renderHtml: renderHtml, labels: labels }),
|
|
102
|
+
"data-commentary": ({ part }) => (_jsx(Typography, { variant: "caption", color: "text.secondary", component: "p", sx: { ...wrap, fontStyle: "italic", m: 0 }, children: part.data.text ?? "" })),
|
|
103
|
+
"data-approval": ({ part }) => {
|
|
104
|
+
const ev = part.data;
|
|
105
|
+
return _jsx(Approval, { event: ev, onDecide: (choice) => decide(ev, choice), labels: labels });
|
|
106
|
+
},
|
|
107
|
+
"data-error": ({ part }) => _jsx(Alert, { severity: "error", children: part.data.text || l.errorDefault }),
|
|
108
|
+
"data-tools": group,
|
|
109
|
+
"dynamic-tool": group,
|
|
110
|
+
tool: group,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Card `maxHeight = max(minHeight, innerHeight − card.top − bottomGap)`, kept current on resize, scroll-settle and layout change. */
|
|
2
|
+
import { type RefObject } from "react";
|
|
3
|
+
export interface FitHeightOptions {
|
|
4
|
+
minHeight?: number;
|
|
5
|
+
bottomGap?: number;
|
|
6
|
+
}
|
|
7
|
+
/** Pure math, exported for tests. */
|
|
8
|
+
export declare function fitMaxHeight(innerHeight: number, top: number, minHeight?: number, bottomGap?: number): number;
|
|
9
|
+
export declare function useFitHeight<T extends HTMLElement>({ minHeight, bottomGap }?: FitHeightOptions, enabled?: boolean): {
|
|
10
|
+
ref: RefObject<T | null>;
|
|
11
|
+
maxHeight: number | undefined;
|
|
12
|
+
};
|