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,19 @@
|
|
|
1
|
+
/** Tool family table, labels, icon keys and one-line args summary (port of Jarvis ToolFamily; pure TS). */
|
|
2
|
+
export type ToolFamilyName = "terminal" | "fileRead" | "fileWrite" | "search" | "browser" | "memory" | "mcp" | "delegate" | "notify" | "approvals" | "todo" | "clarify" | "generic";
|
|
3
|
+
export declare const MCP_PREFIX = "mcp__";
|
|
4
|
+
/** Longest line `argsLine` returns. */
|
|
5
|
+
export declare const ARGS_LINE_MAX = 120;
|
|
6
|
+
declare function resolve(name: string): ToolFamilyName;
|
|
7
|
+
/** First line, trimmed, middle-ellipsised to `max` characters. */
|
|
8
|
+
export declare function clipMiddle(input: string | undefined, max?: number): string | undefined;
|
|
9
|
+
/** The most telling part of a call on one line: command, path, quoted query, else `context` (preview), else a scalar arg. */
|
|
10
|
+
declare function argsLine(name: string, args?: Record<string, unknown>, context?: string): string | undefined;
|
|
11
|
+
export declare const ToolFamily: {
|
|
12
|
+
readonly resolve: typeof resolve;
|
|
13
|
+
readonly label: (name: string) => string;
|
|
14
|
+
readonly labelOf: (family: ToolFamilyName) => string;
|
|
15
|
+
readonly icon: (name: string) => string;
|
|
16
|
+
readonly iconOf: (family: ToolFamilyName) => string;
|
|
17
|
+
readonly argsLine: typeof argsLine;
|
|
18
|
+
};
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/** Tool family table, labels, icon keys and one-line args summary (port of Jarvis ToolFamily; pure TS). */
|
|
2
|
+
export const MCP_PREFIX = "mcp__";
|
|
3
|
+
/** Longest line `argsLine` returns. */
|
|
4
|
+
export const ARGS_LINE_MAX = 120;
|
|
5
|
+
const EXACT = {
|
|
6
|
+
terminal: "terminal", process_manage: "terminal", read_terminal: "terminal", close_terminal: "terminal",
|
|
7
|
+
execute_code: "terminal",
|
|
8
|
+
read_file: "fileRead",
|
|
9
|
+
write_file: "fileWrite", patch: "fileWrite",
|
|
10
|
+
search_files: "search", session_search: "search", web_search: "search", web_extract: "search", x_search: "search",
|
|
11
|
+
memory: "memory", skill_manage: "memory", skill_view: "memory", skills_list: "memory",
|
|
12
|
+
delegate_task: "delegate",
|
|
13
|
+
notify: "notify",
|
|
14
|
+
approval_tags: "approvals", manage_approval_tags: "approvals",
|
|
15
|
+
todo: "todo", todo_list: "todo",
|
|
16
|
+
clarify: "clarify",
|
|
17
|
+
};
|
|
18
|
+
const LABELS = {
|
|
19
|
+
terminal: "Terminal", fileRead: "Read file", fileWrite: "Edit file", search: "Search", browser: "Browser",
|
|
20
|
+
memory: "Memory", mcp: "MCP tool", delegate: "Sub-agent", notify: "Notification", approvals: "Approvals",
|
|
21
|
+
todo: "To-do list", clarify: "Question", generic: "Tool",
|
|
22
|
+
};
|
|
23
|
+
/** Icon key per family; the React layer maps keys to MUI icons. */
|
|
24
|
+
const ICONS = {
|
|
25
|
+
terminal: "terminal", fileRead: "fileRead", fileWrite: "fileWrite", search: "search", browser: "browser",
|
|
26
|
+
memory: "memory", mcp: "mcp", delegate: "delegate", notify: "notify", approvals: "approvals", todo: "todo",
|
|
27
|
+
clarify: "clarify", generic: "generic",
|
|
28
|
+
};
|
|
29
|
+
function resolve(name) {
|
|
30
|
+
const n = name.toLowerCase();
|
|
31
|
+
if (n.startsWith("browser_"))
|
|
32
|
+
return "browser";
|
|
33
|
+
if (n.startsWith(MCP_PREFIX))
|
|
34
|
+
return "mcp";
|
|
35
|
+
return Object.hasOwn(EXACT, n) ? EXACT[n] : "generic";
|
|
36
|
+
}
|
|
37
|
+
function text(value) {
|
|
38
|
+
return typeof value === "string" && value.trim() !== "" ? value : undefined;
|
|
39
|
+
}
|
|
40
|
+
function firstScalar(args) {
|
|
41
|
+
if (!args)
|
|
42
|
+
return undefined;
|
|
43
|
+
for (const key of Object.keys(args).sort()) {
|
|
44
|
+
const v = args[key];
|
|
45
|
+
let s;
|
|
46
|
+
if (typeof v === "string")
|
|
47
|
+
s = v.trim() === "" ? undefined : v;
|
|
48
|
+
else if (typeof v === "number" && Number.isFinite(v))
|
|
49
|
+
s = String(v);
|
|
50
|
+
else if (typeof v === "boolean")
|
|
51
|
+
s = String(v);
|
|
52
|
+
if (s !== undefined && s.length <= ARGS_LINE_MAX)
|
|
53
|
+
return s;
|
|
54
|
+
}
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
/** First line, trimmed, middle-ellipsised to `max` characters. */
|
|
58
|
+
export function clipMiddle(input, max = ARGS_LINE_MAX) {
|
|
59
|
+
const line = input?.split(/\r?\n/).find((l) => l.trim() !== "")?.trim();
|
|
60
|
+
if (!line)
|
|
61
|
+
return undefined;
|
|
62
|
+
const chars = Array.from(line);
|
|
63
|
+
if (chars.length <= max)
|
|
64
|
+
return line;
|
|
65
|
+
const keep = max - 1;
|
|
66
|
+
const head = Math.ceil(keep / 2);
|
|
67
|
+
return chars.slice(0, head).join("") + "…" + chars.slice(chars.length - (keep - head)).join("");
|
|
68
|
+
}
|
|
69
|
+
/** The most telling part of a call on one line: command, path, quoted query, else `context` (preview), else a scalar arg. */
|
|
70
|
+
function argsLine(name, args, context) {
|
|
71
|
+
const a = args ?? {};
|
|
72
|
+
let picked;
|
|
73
|
+
switch (resolve(name)) {
|
|
74
|
+
case "terminal":
|
|
75
|
+
picked = text(a.command) ?? text(a.code);
|
|
76
|
+
break;
|
|
77
|
+
case "fileRead":
|
|
78
|
+
case "fileWrite":
|
|
79
|
+
picked = text(a.path);
|
|
80
|
+
break;
|
|
81
|
+
case "search": {
|
|
82
|
+
const q = text(a.query) ?? text(a.pattern);
|
|
83
|
+
const urls = Array.isArray(a.urls) ? text(a.urls[0]) : undefined;
|
|
84
|
+
picked = q !== undefined ? `"${q}"` : (text(a.url) ?? urls);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
case "browser":
|
|
88
|
+
picked = text(a.url);
|
|
89
|
+
break;
|
|
90
|
+
case "delegate":
|
|
91
|
+
picked = text(a.goal);
|
|
92
|
+
break;
|
|
93
|
+
case "clarify":
|
|
94
|
+
picked = text(a.question);
|
|
95
|
+
break;
|
|
96
|
+
default: break;
|
|
97
|
+
}
|
|
98
|
+
return clipMiddle(picked ?? text(context) ?? firstScalar(args));
|
|
99
|
+
}
|
|
100
|
+
export const ToolFamily = {
|
|
101
|
+
resolve,
|
|
102
|
+
label: (name) => LABELS[resolve(name)],
|
|
103
|
+
labelOf: (family) => LABELS[family],
|
|
104
|
+
icon: (name) => ICONS[resolve(name)],
|
|
105
|
+
iconOf: (family) => ICONS[family],
|
|
106
|
+
argsLine,
|
|
107
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Text of a collapsed tool row: duration, status and screen-reader label (port of Jarvis ToolRowFormat; pure TS). */
|
|
2
|
+
export type ToolRunStatus = "running" | "done" | "failed";
|
|
3
|
+
/** Visible duration: `0.4 s`, `12 s`, `2 min 5 s`; undefined when missing or negative. */
|
|
4
|
+
export declare function duration(seconds: number | undefined | null): string | undefined;
|
|
5
|
+
/** Spoken duration: `0.4 seconds`, `1 second`, `2 minutes 5 seconds`. */
|
|
6
|
+
export declare function spokenDuration(seconds: number | undefined | null): string | undefined;
|
|
7
|
+
/** "Tool terminal, done in 0.4 seconds, ls -la, 1 file listed". */
|
|
8
|
+
export declare function accessibilityLabel(o: {
|
|
9
|
+
name: string;
|
|
10
|
+
status: ToolRunStatus;
|
|
11
|
+
duration?: number;
|
|
12
|
+
argsLine?: string;
|
|
13
|
+
summary?: string;
|
|
14
|
+
}): string;
|
|
15
|
+
export declare const ToolRowFormat: {
|
|
16
|
+
duration: typeof duration;
|
|
17
|
+
spokenDuration: typeof spokenDuration;
|
|
18
|
+
accessibilityLabel: typeof accessibilityLabel;
|
|
19
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Text of a collapsed tool row: duration, status and screen-reader label (port of Jarvis ToolRowFormat; pure TS). */
|
|
2
|
+
const valid = (s) => typeof s === "number" && Number.isFinite(s) && s >= 0;
|
|
3
|
+
/** Visible duration: `0.4 s`, `12 s`, `2 min 5 s`; undefined when missing or negative. */
|
|
4
|
+
export function duration(seconds) {
|
|
5
|
+
if (!valid(seconds))
|
|
6
|
+
return undefined;
|
|
7
|
+
if (seconds < 10)
|
|
8
|
+
return `${seconds.toFixed(1)} s`;
|
|
9
|
+
if (seconds < 60)
|
|
10
|
+
return `${Math.round(seconds)} s`;
|
|
11
|
+
const whole = Math.round(seconds);
|
|
12
|
+
return whole % 60 === 0 ? `${whole / 60} min` : `${Math.floor(whole / 60)} min ${whole % 60} s`;
|
|
13
|
+
}
|
|
14
|
+
const unit = (n, w) => `${n} ${w}${n === 1 ? "" : "s"}`;
|
|
15
|
+
/** Spoken duration: `0.4 seconds`, `1 second`, `2 minutes 5 seconds`. */
|
|
16
|
+
export function spokenDuration(seconds) {
|
|
17
|
+
if (!valid(seconds))
|
|
18
|
+
return undefined;
|
|
19
|
+
if (seconds < 10) {
|
|
20
|
+
const tenths = Math.round(seconds * 10) / 10;
|
|
21
|
+
return tenths === 1 ? "1 second" : `${tenths.toFixed(1)} seconds`;
|
|
22
|
+
}
|
|
23
|
+
const whole = Math.round(seconds);
|
|
24
|
+
if (whole < 60)
|
|
25
|
+
return unit(whole, "second");
|
|
26
|
+
const minutes = unit(Math.floor(whole / 60), "minute");
|
|
27
|
+
return whole % 60 === 0 ? minutes : `${minutes} ${unit(whole % 60, "second")}`;
|
|
28
|
+
}
|
|
29
|
+
/** "Tool terminal, done in 0.4 seconds, ls -la, 1 file listed". */
|
|
30
|
+
export function accessibilityLabel(o) {
|
|
31
|
+
const spoken = spokenDuration(o.duration);
|
|
32
|
+
const state = o.status === "running" ? "running"
|
|
33
|
+
: o.status === "done" ? (spoken ? `done in ${spoken}` : "done")
|
|
34
|
+
: spoken ? `failed after ${spoken}` : "failed";
|
|
35
|
+
return [`Tool ${o.name}`, state, o.argsLine, o.summary ? o.summary : undefined].filter(Boolean).join(", ");
|
|
36
|
+
}
|
|
37
|
+
export const ToolRowFormat = { duration, spokenDuration, accessibilityLabel };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import Terminal from "@mui/icons-material/Terminal";
|
|
3
|
+
import Description from "@mui/icons-material/Description";
|
|
4
|
+
import EditNote from "@mui/icons-material/EditNote";
|
|
5
|
+
import Search from "@mui/icons-material/Search";
|
|
6
|
+
import Public from "@mui/icons-material/Public";
|
|
7
|
+
import Psychology from "@mui/icons-material/Psychology";
|
|
8
|
+
import Extension from "@mui/icons-material/Extension";
|
|
9
|
+
import Groups from "@mui/icons-material/Groups";
|
|
10
|
+
import Notifications from "@mui/icons-material/Notifications";
|
|
11
|
+
import VerifiedUser from "@mui/icons-material/VerifiedUser";
|
|
12
|
+
import Checklist from "@mui/icons-material/Checklist";
|
|
13
|
+
import HelpOutline from "@mui/icons-material/HelpOutlineOutlined";
|
|
14
|
+
import Build from "@mui/icons-material/Build";
|
|
15
|
+
import { ToolFamily } from "./family";
|
|
16
|
+
const ICONS = {
|
|
17
|
+
terminal: _jsx(Terminal, { fontSize: "small" }), fileRead: _jsx(Description, { fontSize: "small" }),
|
|
18
|
+
fileWrite: _jsx(EditNote, { fontSize: "small" }), search: _jsx(Search, { fontSize: "small" }), browser: _jsx(Public, { fontSize: "small" }),
|
|
19
|
+
memory: _jsx(Psychology, { fontSize: "small" }), mcp: _jsx(Extension, { fontSize: "small" }), delegate: _jsx(Groups, { fontSize: "small" }),
|
|
20
|
+
notify: _jsx(Notifications, { fontSize: "small" }), approvals: _jsx(VerifiedUser, { fontSize: "small" }),
|
|
21
|
+
todo: _jsx(Checklist, { fontSize: "small" }), clarify: _jsx(HelpOutline, { fontSize: "small" }), generic: _jsx(Build, { fontSize: "small" }),
|
|
22
|
+
};
|
|
23
|
+
export function ToolIcon({ name }) {
|
|
24
|
+
return ICONS[ToolFamily.icon(name)] ?? ICONS.generic;
|
|
25
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Jarvis-style tool call components. */
|
|
2
|
+
export { ToolRow, type ToolRowProps } from "./ToolRow";
|
|
3
|
+
export { ToolStepGroup, type ToolStepGroupProps } from "./ToolStepGroup";
|
|
4
|
+
export { ToolDetailDrawer, type ToolDetailDrawerProps } from "./ToolDetailDrawer";
|
|
5
|
+
export { ToolPreviewView } from "./ToolPreviewView";
|
|
6
|
+
export { JsonTree } from "./JsonTree";
|
|
7
|
+
export { ToolFamily, type ToolFamilyName } from "./family";
|
|
8
|
+
export { ToolRowFormat, type ToolRunStatus } from "./format";
|
|
9
|
+
export { ToolPreview, type ToolPreviewKind } from "./toolPreview";
|
|
10
|
+
export { defaultToolLabels, type ToolLabels } from "./labels";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Jarvis-style tool call components. */
|
|
2
|
+
export { ToolRow } from "./ToolRow";
|
|
3
|
+
export { ToolStepGroup } from "./ToolStepGroup";
|
|
4
|
+
export { ToolDetailDrawer } from "./ToolDetailDrawer";
|
|
5
|
+
export { ToolPreviewView } from "./ToolPreviewView";
|
|
6
|
+
export { JsonTree } from "./JsonTree";
|
|
7
|
+
export { ToolFamily } from "./family";
|
|
8
|
+
export { ToolRowFormat } from "./format";
|
|
9
|
+
export { ToolPreview } from "./toolPreview";
|
|
10
|
+
export { defaultToolLabels } from "./labels";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Default English strings for the tool components. */
|
|
2
|
+
export interface ToolLabels {
|
|
3
|
+
running: string;
|
|
4
|
+
done: string;
|
|
5
|
+
failed: string;
|
|
6
|
+
showPreview: string;
|
|
7
|
+
hidePreview: string;
|
|
8
|
+
steps: (n: number) => string;
|
|
9
|
+
failedCount: (n: number) => string;
|
|
10
|
+
showSteps: string;
|
|
11
|
+
hideSteps: string;
|
|
12
|
+
request: string;
|
|
13
|
+
response: string;
|
|
14
|
+
copy: string;
|
|
15
|
+
copied: string;
|
|
16
|
+
close: string;
|
|
17
|
+
argsClipped: string;
|
|
18
|
+
noArgs: string;
|
|
19
|
+
noResponse: string;
|
|
20
|
+
more: (n: number) => string;
|
|
21
|
+
details: string;
|
|
22
|
+
}
|
|
23
|
+
export declare const defaultToolLabels: ToolLabels;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const defaultToolLabels = {
|
|
2
|
+
running: "Running", done: "Done", failed: "Failed", showPreview: "Show preview", hidePreview: "Hide preview",
|
|
3
|
+
steps: (n) => `${n} steps`, failedCount: (n) => `${n} failed`, showSteps: "Show steps", hideSteps: "Hide steps",
|
|
4
|
+
request: "Request", response: "Response", copy: "Copy", copied: "Copied", close: "Close",
|
|
5
|
+
argsClipped: "Arguments were clipped by the server.", noArgs: "No arguments.", noResponse: "No response yet.",
|
|
6
|
+
more: (n) => `… ${n} more`, details: "Tool details",
|
|
7
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/** Inline tool preview resolver (port of Jarvis ToolPreview.resolve limits; pure TS). */
|
|
2
|
+
import type { HermesToolCall } from "../../core/types";
|
|
3
|
+
export type DiffKind = "added" | "removed" | "hunk" | "context";
|
|
4
|
+
export interface DiffLine {
|
|
5
|
+
kind: DiffKind;
|
|
6
|
+
text: string;
|
|
7
|
+
}
|
|
8
|
+
export interface TodoEntry {
|
|
9
|
+
id?: string;
|
|
10
|
+
content: string;
|
|
11
|
+
status: string;
|
|
12
|
+
}
|
|
13
|
+
export type ToolPreviewKind = {
|
|
14
|
+
kind: "diff";
|
|
15
|
+
lines: DiffLine[];
|
|
16
|
+
more: number;
|
|
17
|
+
} | {
|
|
18
|
+
kind: "todos";
|
|
19
|
+
entries: TodoEntry[];
|
|
20
|
+
more: number;
|
|
21
|
+
} | {
|
|
22
|
+
kind: "subagentGroup";
|
|
23
|
+
children: string[];
|
|
24
|
+
} | {
|
|
25
|
+
kind: "image";
|
|
26
|
+
basename: string;
|
|
27
|
+
} | {
|
|
28
|
+
kind: "generic";
|
|
29
|
+
pairs: {
|
|
30
|
+
key: string;
|
|
31
|
+
value: string;
|
|
32
|
+
}[];
|
|
33
|
+
resultLines: string[];
|
|
34
|
+
} | {
|
|
35
|
+
kind: "none";
|
|
36
|
+
};
|
|
37
|
+
export declare const LIMITS: {
|
|
38
|
+
readonly maxDiffLines: 12;
|
|
39
|
+
readonly maxTodos: 12;
|
|
40
|
+
readonly maxPairs: 3;
|
|
41
|
+
readonly maxResultLines: 3;
|
|
42
|
+
readonly maxKey: 40;
|
|
43
|
+
readonly maxValue: 80;
|
|
44
|
+
readonly maxLine: 160;
|
|
45
|
+
readonly maxInputBytes: number;
|
|
46
|
+
};
|
|
47
|
+
export declare const gutter: (k: DiffKind) => string;
|
|
48
|
+
export declare function clip(text: string, limit: number): string;
|
|
49
|
+
/** First line, SGR and control characters dropped, trimmed. */
|
|
50
|
+
export declare function oneLine(text: string): string;
|
|
51
|
+
/** Null unless `text` is a plausible unified diff of a sane size. */
|
|
52
|
+
export declare function diffPreview(text: string): ToolPreviewKind | null;
|
|
53
|
+
export declare function todoPreview(todos: TodoEntry[]): ToolPreviewKind | null;
|
|
54
|
+
export declare function basename(path: string): string | undefined;
|
|
55
|
+
/** The one dispatch function for inline tool previews. */
|
|
56
|
+
export declare function resolvePreview(call: HermesToolCall | undefined, children?: string[]): ToolPreviewKind;
|
|
57
|
+
export declare const ToolPreview: {
|
|
58
|
+
resolve: typeof resolvePreview;
|
|
59
|
+
diffPreview: typeof diffPreview;
|
|
60
|
+
todoPreview: typeof todoPreview;
|
|
61
|
+
basename: typeof basename;
|
|
62
|
+
oneLine: typeof oneLine;
|
|
63
|
+
clip: typeof clip;
|
|
64
|
+
LIMITS: {
|
|
65
|
+
readonly maxDiffLines: 12;
|
|
66
|
+
readonly maxTodos: 12;
|
|
67
|
+
readonly maxPairs: 3;
|
|
68
|
+
readonly maxResultLines: 3;
|
|
69
|
+
readonly maxKey: 40;
|
|
70
|
+
readonly maxValue: 80;
|
|
71
|
+
readonly maxLine: 160;
|
|
72
|
+
readonly maxInputBytes: number;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
export const LIMITS = {
|
|
2
|
+
maxDiffLines: 12, maxTodos: 12, maxPairs: 3, maxResultLines: 3, maxKey: 40, maxValue: 80, maxLine: 160,
|
|
3
|
+
maxInputBytes: 256 * 1024,
|
|
4
|
+
};
|
|
5
|
+
const NONE = { kind: "none" };
|
|
6
|
+
const bytes = (s) => new TextEncoder().encode(s).length;
|
|
7
|
+
// eslint-disable-next-line no-control-regex
|
|
8
|
+
const SGR = /\u001b\[[0-9;]*m/g;
|
|
9
|
+
// eslint-disable-next-line no-control-regex
|
|
10
|
+
const CONTROL = /[\u0000-\u0008\u000b-\u001f\u007f]/g;
|
|
11
|
+
export const gutter = (k) => ({ added: "+", removed: "−", hunk: "@", context: " " })[k];
|
|
12
|
+
export function clip(text, limit) {
|
|
13
|
+
const c = Array.from(text);
|
|
14
|
+
return c.length <= limit ? text : c.slice(0, limit - 1).join("") + "…";
|
|
15
|
+
}
|
|
16
|
+
/** First line, SGR and control characters dropped, trimmed. */
|
|
17
|
+
export function oneLine(text) {
|
|
18
|
+
const line = text.split(/\r?\n|\r/)[0] ?? "";
|
|
19
|
+
return line.replace(SGR, "").replace(CONTROL, "").trim();
|
|
20
|
+
}
|
|
21
|
+
function diffLine(line, inHeader, next) {
|
|
22
|
+
if (line.startsWith("diff ") || line.startsWith("index "))
|
|
23
|
+
return "fileHeader";
|
|
24
|
+
if (line.startsWith("--- ") && next.startsWith("+++ "))
|
|
25
|
+
return "fileHeader";
|
|
26
|
+
if (inHeader && !line.startsWith("@@"))
|
|
27
|
+
return "skip";
|
|
28
|
+
const first = Array.from(line)[0];
|
|
29
|
+
let kind;
|
|
30
|
+
switch (first) {
|
|
31
|
+
case "+":
|
|
32
|
+
kind = "added";
|
|
33
|
+
break;
|
|
34
|
+
case "-":
|
|
35
|
+
kind = "removed";
|
|
36
|
+
break;
|
|
37
|
+
case "@":
|
|
38
|
+
kind = "hunk";
|
|
39
|
+
break;
|
|
40
|
+
case " ":
|
|
41
|
+
case "\\":
|
|
42
|
+
kind = "context";
|
|
43
|
+
break;
|
|
44
|
+
case "…": return { kind: "hunk", text: clip(oneLine(line), LIMITS.maxLine) };
|
|
45
|
+
case undefined: return "skip";
|
|
46
|
+
default: return line.includes(" → ") ? "fileHeader" : "invalid";
|
|
47
|
+
}
|
|
48
|
+
return { kind, text: clip(kind === "hunk" ? line : line.slice(1), LIMITS.maxLine) };
|
|
49
|
+
}
|
|
50
|
+
/** Null unless `text` is a plausible unified diff of a sane size. */
|
|
51
|
+
export function diffPreview(text) {
|
|
52
|
+
if (!text || bytes(text) > LIMITS.maxInputBytes || text.includes("\u0000"))
|
|
53
|
+
return null;
|
|
54
|
+
const raw = text.replace(SGR, "").split(/\r?\n|\r/);
|
|
55
|
+
let inHeader = true;
|
|
56
|
+
const lines = [];
|
|
57
|
+
for (let i = 0; i < raw.length; i++) {
|
|
58
|
+
const line = raw[i];
|
|
59
|
+
if (line.startsWith("@@"))
|
|
60
|
+
inHeader = false;
|
|
61
|
+
const r = diffLine(line, inHeader, raw[i + 1] ?? "");
|
|
62
|
+
if (r === "skip")
|
|
63
|
+
continue;
|
|
64
|
+
if (r === "invalid")
|
|
65
|
+
return null;
|
|
66
|
+
if (r === "fileHeader") {
|
|
67
|
+
inHeader = true;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
lines.push(r);
|
|
71
|
+
}
|
|
72
|
+
if (!lines.some((l) => l.kind === "added" || l.kind === "removed"))
|
|
73
|
+
return null;
|
|
74
|
+
return { kind: "diff", lines: lines.slice(0, LIMITS.maxDiffLines), more: Math.max(0, lines.length - LIMITS.maxDiffLines) };
|
|
75
|
+
}
|
|
76
|
+
export function todoPreview(todos) {
|
|
77
|
+
const valid = [];
|
|
78
|
+
for (const t of todos) {
|
|
79
|
+
const text = oneLine(t.content);
|
|
80
|
+
if (text)
|
|
81
|
+
valid.push({ id: t.id, content: clip(text, LIMITS.maxLine), status: t.status });
|
|
82
|
+
}
|
|
83
|
+
if (!valid.length)
|
|
84
|
+
return null;
|
|
85
|
+
return { kind: "todos", entries: valid.slice(0, LIMITS.maxTodos), more: Math.max(0, valid.length - LIMITS.maxTodos) };
|
|
86
|
+
}
|
|
87
|
+
function todoList(value) {
|
|
88
|
+
if (!Array.isArray(value))
|
|
89
|
+
return undefined;
|
|
90
|
+
return value.flatMap((v) => {
|
|
91
|
+
if (!v || typeof v !== "object")
|
|
92
|
+
return [];
|
|
93
|
+
const o = v;
|
|
94
|
+
if (typeof o.content !== "string")
|
|
95
|
+
return [];
|
|
96
|
+
return [{ id: o.id === undefined ? undefined : String(o.id), content: o.content, status: typeof o.status === "string" ? o.status : "pending" }];
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function scalar(v) {
|
|
100
|
+
if (typeof v === "string")
|
|
101
|
+
return bytes(v) <= LIMITS.maxInputBytes ? v : v.slice(0, LIMITS.maxValue);
|
|
102
|
+
if (typeof v === "number" && Number.isFinite(v))
|
|
103
|
+
return String(v);
|
|
104
|
+
if (typeof v === "boolean")
|
|
105
|
+
return String(v);
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
export function basename(path) {
|
|
109
|
+
if (bytes(path) > 4096)
|
|
110
|
+
return undefined;
|
|
111
|
+
const name = oneLine(path.replace(/\/+$/, "").split("/").pop() ?? "");
|
|
112
|
+
return name ? clip(name, LIMITS.maxValue) : undefined;
|
|
113
|
+
}
|
|
114
|
+
function genericPreview(call) {
|
|
115
|
+
const pairs = [];
|
|
116
|
+
for (const key of Object.keys(call.args ?? {}).sort()) {
|
|
117
|
+
if (pairs.length >= LIMITS.maxPairs)
|
|
118
|
+
break;
|
|
119
|
+
const s = scalar(call.args[key]);
|
|
120
|
+
if (s === undefined)
|
|
121
|
+
continue;
|
|
122
|
+
const line = oneLine(s);
|
|
123
|
+
if (line)
|
|
124
|
+
pairs.push({ key: clip(oneLine(key), LIMITS.maxKey), value: clip(line, LIMITS.maxValue) });
|
|
125
|
+
}
|
|
126
|
+
const head = (call.result_preview ?? "").slice(0, LIMITS.maxInputBytes);
|
|
127
|
+
const resultLines = head.split(/\r?\n|\r/).map(oneLine).filter(Boolean).slice(0, LIMITS.maxResultLines).map((l) => clip(l, LIMITS.maxLine));
|
|
128
|
+
return pairs.length || resultLines.length ? { kind: "generic", pairs, resultLines } : null;
|
|
129
|
+
}
|
|
130
|
+
/** The one dispatch function for inline tool previews. */
|
|
131
|
+
export function resolvePreview(call, children = []) {
|
|
132
|
+
if (children.length)
|
|
133
|
+
return { kind: "subagentGroup", children };
|
|
134
|
+
if (!call)
|
|
135
|
+
return NONE;
|
|
136
|
+
const a = call.args;
|
|
137
|
+
const diff = typeof a?.inline_diff === "string" ? a.inline_diff : typeof a?.diff === "string" ? a.diff : undefined;
|
|
138
|
+
if (diff) {
|
|
139
|
+
const p = diffPreview(diff);
|
|
140
|
+
if (p)
|
|
141
|
+
return p;
|
|
142
|
+
}
|
|
143
|
+
const todos = todoList(a?.todos);
|
|
144
|
+
if (todos) {
|
|
145
|
+
const p = todoPreview(todos);
|
|
146
|
+
if (p)
|
|
147
|
+
return p;
|
|
148
|
+
}
|
|
149
|
+
if (typeof a?.image_path === "string") {
|
|
150
|
+
const name = basename(a.image_path);
|
|
151
|
+
if (name)
|
|
152
|
+
return { kind: "image", basename: name };
|
|
153
|
+
}
|
|
154
|
+
return genericPreview(call) ?? NONE;
|
|
155
|
+
}
|
|
156
|
+
export const ToolPreview = { resolve: resolvePreview, diffPreview, todoPreview, basename, oneLine, clip, LIMITS };
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mui-hermes-chat",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"description": "Embeddable Hermes chat for React + MUI (on @mui/x-chat)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": { "type": "git", "url": "git+https://github.com/ejlevin1/mui-hermes-chat.git" },
|
|
8
|
+
"homepage": "https://github.com/ejlevin1/mui-hermes-chat#readme",
|
|
9
|
+
"bugs": { "url": "https://github.com/ejlevin1/mui-hermes-chat/issues" },
|
|
10
|
+
"keywords": ["react", "mui", "chat", "hermes", "x-chat", "sse"],
|
|
11
|
+
"publishConfig": { "access": "public", "provenance": true },
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" } },
|
|
15
|
+
"files": ["dist"],
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"engines": { "node": ">=20.19" },
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
20
|
+
"typecheck": "tsc --noEmit",
|
|
21
|
+
"test": "vitest run",
|
|
22
|
+
"prepublishOnly": "npm run typecheck && npm test && npm run build",
|
|
23
|
+
"hooks": "git config core.hooksPath .githooks"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@emotion/react": "^11.14.0",
|
|
27
|
+
"@emotion/styled": "^11.14.0",
|
|
28
|
+
"@mui/icons-material": "^9.5.0",
|
|
29
|
+
"@mui/material": "^9.5.0",
|
|
30
|
+
"@mui/x-chat": "9.0.0-alpha.22",
|
|
31
|
+
"react": "^19.0.0",
|
|
32
|
+
"react-dom": "^19.0.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@emotion/react": "11.14.0",
|
|
36
|
+
"@emotion/styled": "11.14.1",
|
|
37
|
+
"@mui/icons-material": "9.5.0",
|
|
38
|
+
"@mui/material": "9.5.0",
|
|
39
|
+
"@mui/x-chat": "9.0.0-alpha.22",
|
|
40
|
+
"@testing-library/dom": "^10.4.2",
|
|
41
|
+
"@testing-library/react": "^16.3.3",
|
|
42
|
+
"@types/react": "^19.3.0",
|
|
43
|
+
"@types/react-dom": "^19.3.0",
|
|
44
|
+
"jsdom": "^29.1.1",
|
|
45
|
+
"react": "^19.3.1",
|
|
46
|
+
"react-dom": "^19.3.1",
|
|
47
|
+
"typescript": "^7.0.2",
|
|
48
|
+
"vitest": "^4.1.12"
|
|
49
|
+
}
|
|
50
|
+
}
|