devnonla-ui 0.17.2 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/chat/common/utils.ts +2 -17
- package/src/chat/index.ts +1 -2
- package/src/chat/message-ui/ChatMarkdown.tsx +6 -3
- package/src/chat/tool-ui/BackgroundTaskToolUI.tsx +1 -1
- package/src/chat/tool-ui/BackgroundTasksBar.tsx +31 -33
- package/src/chat/tool-ui/ChatToolCall.tsx +1 -1
- package/src/chat/tool-ui/GetCurrentTimeToolUI.tsx +1 -1
- package/src/chat/tool-ui/ReadSkillToolUI.tsx +1 -1
- package/src/chat/tool-ui/RunJsToolUI.tsx +1 -1
- package/src/chat/tool-ui/WebFetchToolUI.tsx +1 -1
- package/src/chat/tool-ui/registry.ts +6 -8
- package/src/markdown-editor/MarkdownTable.tsx +1 -1
- package/src/markdown-editor/MarkdownViewer.tsx +1 -1
- package/src/sortable-tree/SortableTree.tsx +92 -45
- package/src/styles.css +14 -6
- package/src/chat/tool-ui/CallAgentToolUI.tsx +0 -176
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "devnonla-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "NonlaUI — React controls for Nonla Agents",
|
|
6
6
|
"author": "devlangla <devlangla0x01@gmail.com>",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"@dnd-kit/core": "6.3.1",
|
|
45
45
|
"@dnd-kit/sortable": "10.0.0",
|
|
46
46
|
"@dnd-kit/utilities": "3.2.2",
|
|
47
|
+
"@fontsource-variable/geist-mono": "^5.3.0",
|
|
47
48
|
"@fontsource-variable/inter": "^5.3.0",
|
|
48
|
-
"@fontsource-variable/plus-jakarta-sans": "^5.3.0",
|
|
49
49
|
"@radix-ui/react-checkbox": "^1.3.3",
|
|
50
50
|
"@radix-ui/react-context-menu": "^2.3.7",
|
|
51
51
|
"@radix-ui/react-dialog": "^1.1.15",
|
package/src/chat/common/utils.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { AgentToolNameMatch } from "./types";
|
|
2
2
|
|
|
3
|
-
/** snake_case / camelCase → Title Case (
|
|
3
|
+
/** snake_case / camelCase → Title Case. A leading `nonla_` stays on the function name and is dropped here (`nonla_read_skill` → Read Skill). */
|
|
4
4
|
export function formatToolName(name: string): string {
|
|
5
5
|
return name
|
|
6
|
+
.replace(/^nonla_/i, "")
|
|
6
7
|
.replace(/([A-Z])/g, " $1")
|
|
7
8
|
.replace(/[_-]+/g, " ")
|
|
8
9
|
.trim()
|
|
@@ -48,22 +49,6 @@ export function parseJsonObject<T extends object>(raw: unknown): T | null {
|
|
|
48
49
|
return null;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
const CALL_AGENT_PREFIX = "call_agent__";
|
|
52
|
-
|
|
53
|
-
/** True for legacy `call_agent` and per-target `call_agent__<uuid>` tools. */
|
|
54
|
-
export function isCallAgentToolName(name: string | null | undefined): boolean {
|
|
55
|
-
if (!name) return false;
|
|
56
|
-
return name === "call_agent" || name.startsWith(CALL_AGENT_PREFIX);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** Reconstruct target agent UUID from `call_agent__<uuid_with_underscores>`. */
|
|
60
|
-
export function parseCallAgentToolTargetId(toolName: string): string | null {
|
|
61
|
-
if (!toolName.startsWith(CALL_AGENT_PREFIX)) return null;
|
|
62
|
-
const parts = toolName.slice(CALL_AGENT_PREFIX.length).split("_");
|
|
63
|
-
if (parts.length !== 5) return null;
|
|
64
|
-
return parts.join("-");
|
|
65
|
-
}
|
|
66
|
-
|
|
67
52
|
export function timestampMs(value: unknown): number {
|
|
68
53
|
if (value instanceof Date) return value.getTime();
|
|
69
54
|
if (typeof value === "number" && Number.isFinite(value)) return value;
|
package/src/chat/index.ts
CHANGED
|
@@ -12,7 +12,7 @@ export type { AgentChatResumeRequest, AgentChatSendRequest, UseAgentChatStreamOp
|
|
|
12
12
|
export { useAgentChatStream } from "./common/useAgentChatStream";
|
|
13
13
|
export type { UseAgentStreamOptions } from "./common/useAgentStream";
|
|
14
14
|
export { buildAgentHistory, useAgentStream } from "./common/useAgentStream";
|
|
15
|
-
export { formatToolName,
|
|
15
|
+
export { formatToolName, matchesToolHook, matchesToolName, prettyJson } from "./common/utils";
|
|
16
16
|
export type { ChatAgentMessageProps } from "./message-ui/ChatAgentMessage";
|
|
17
17
|
export { ChatAgentMessage } from "./message-ui/ChatAgentMessage";
|
|
18
18
|
export type { ChatErrorProps } from "./message-ui/ChatError";
|
|
@@ -31,7 +31,6 @@ export { ChatWelcome } from "./message-ui/ChatWelcome";
|
|
|
31
31
|
export type { BackgroundTasksBarProps } from "./tool-ui/BackgroundTasksBar";
|
|
32
32
|
export { BackgroundTasksBar } from "./tool-ui/BackgroundTasksBar";
|
|
33
33
|
export { BackgroundTaskToolUI } from "./tool-ui/BackgroundTaskToolUI";
|
|
34
|
-
export { CallAgentToolUI } from "./tool-ui/CallAgentToolUI";
|
|
35
34
|
export type { ChatToolCallProps } from "./tool-ui/ChatToolCall";
|
|
36
35
|
export { ChatToolCall } from "./tool-ui/ChatToolCall";
|
|
37
36
|
export { GetCurrentTimeToolUI } from "./tool-ui/GetCurrentTimeToolUI";
|
|
@@ -8,8 +8,10 @@ export type ChatMarkdownProps = {
|
|
|
8
8
|
components?: MarkdownComponents;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
/** Reply headings are `text-lg` at the strong weight. Body
|
|
11
|
+
/** Reply headings are `text-lg` at the strong weight. Body is `text-base`. Strong is 500. Tables are `text-sm`. */
|
|
12
12
|
const chatHeadingScale = {
|
|
13
|
+
"--md-body-size": "var(--nonla-base-text-size)",
|
|
14
|
+
"--md-body-leading": "calc(var(--nonla-base-text-size) * 1.6)",
|
|
13
15
|
"--md-h1-size": "var(--text-lg)",
|
|
14
16
|
"--md-h2-size": "var(--text-lg)",
|
|
15
17
|
"--md-h3-size": "var(--text-lg)",
|
|
@@ -34,11 +36,12 @@ const chatHeadingScale = {
|
|
|
34
36
|
/**
|
|
35
37
|
* Headings use the paragraph box, so `#` does not keep the article margin.
|
|
36
38
|
* The first and last line drop that padding so the row padding is the only gap.
|
|
39
|
+
* List rows keep their own marker padding, so this box skips `[data-md-list]`.
|
|
37
40
|
*/
|
|
38
41
|
const chatEdgeClass = [
|
|
39
42
|
"[&_:is(h1,h2,h3,h4,h5,h6)]:my-(--md-p-my,1px)! [&_:is(h1,h2,h3,h4,h5,h6)]:py-(--md-p-py,4px)!",
|
|
40
|
-
"[&_[data-md-block]:not(:first-child)_p:first-child]:mt-(--md-p-my,1px)! [&_[data-md-block]:not(:first-child)_p:first-child]:pt-(--md-p-py,4px)!",
|
|
41
|
-
"[&_[data-md-block]:first-
|
|
43
|
+
"[&_[data-md-block]:not(:first-child):not(:has([data-md-list]))_p:first-child]:mt-(--md-p-my,1px)! [&_[data-md-block]:not(:first-child):not(:has([data-md-list]))_p:first-child]:pt-(--md-p-py,4px)!",
|
|
44
|
+
"[&_[data-md-block]:first-child:not(:has([data-md-list]))_:is(p,h1,h2,h3,h4,h5,h6,ul,ol)]:mt-0! [&_[data-md-block]:first-child:not(:has([data-md-list]))_:is(p,h1,h2,h3,h4,h5,h6)]:pt-0! [&_[data-md-block]:last-child:not(:has([data-md-list]))_:is(p,h1,h2,h3,h4,h5,h6,ul,ol)]:mb-0! [&_[data-md-block]:last-child:not(:has([data-md-list]))_:is(p,h1,h2,h3,h4,h5,h6)]:pb-0!",
|
|
42
45
|
].join(" ");
|
|
43
46
|
|
|
44
47
|
/** Agent markdown. Headings are `text-lg` at the strong weight. */
|
|
@@ -23,7 +23,7 @@ export function BackgroundTaskToolUI({ msg, assistantLabel = "Assistant", assist
|
|
|
23
23
|
<div className="px-4">
|
|
24
24
|
<div className={chatToolLineClass}>
|
|
25
25
|
<Spin variant="agent" size="small" className="shrink-0" />
|
|
26
|
-
<Shimmer className="min-w-0 truncate font-
|
|
26
|
+
<Shimmer className="min-w-0 truncate font-normal text-muted-foreground">
|
|
27
27
|
{label}
|
|
28
28
|
<span className="text-muted-foreground [-webkit-text-fill-color:currentcolor]"> in background</span>
|
|
29
29
|
</Shimmer>
|
|
@@ -51,7 +51,7 @@ function TaskRow({
|
|
|
51
51
|
<div className="flex items-center gap-1 px-1.5 py-0.5">
|
|
52
52
|
<button type="button" onClick={onLogs} title="Logs" aria-label={`Logs ${formatToolName(task.toolName)}`} className="flex min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-md px-1 py-[3px] text-left transition-colors hover:bg-muted">
|
|
53
53
|
<Spin variant="agent" size="small" className="shrink-0" />
|
|
54
|
-
<span className="min-w-0 flex-1 truncate text-sm font-
|
|
54
|
+
<span className="min-w-0 flex-1 truncate text-sm font-normal text-foreground">{formatToolName(task.toolName)}</span>
|
|
55
55
|
<span className="shrink-0 text-sm tabular-nums text-tertiary-foreground">{formatBgElapsed(task.startedAt, now)}</span>
|
|
56
56
|
</button>
|
|
57
57
|
<Popconfirm title={`Stop ${formatToolName(task.toolName)}?`} okText="Stop" okType="danger" onConfirm={onCancel} getPopupContainer={() => document.body}>
|
|
@@ -100,50 +100,48 @@ export function BackgroundTasksBar({ children, tasks = [], cancellingIds, onCanc
|
|
|
100
100
|
setListH(0);
|
|
101
101
|
return;
|
|
102
102
|
}
|
|
103
|
-
const update = () =>
|
|
103
|
+
const update = () => {
|
|
104
|
+
const next = el.offsetHeight;
|
|
105
|
+
setListH((h) => (h === next ? h : next));
|
|
106
|
+
};
|
|
104
107
|
update();
|
|
105
108
|
const ro = new ResizeObserver(update);
|
|
106
109
|
ro.observe(el);
|
|
107
110
|
return () => ro.disconnect();
|
|
108
|
-
}, [tasks.length
|
|
111
|
+
}, [tasks.length]);
|
|
109
112
|
|
|
110
113
|
const label = tasks.length === 1 ? "1 background task" : `${tasks.length} background tasks`;
|
|
111
|
-
const reserve = tasks.length > 0 ? 28 + (open ? listH : 0) : 0;
|
|
112
114
|
|
|
113
115
|
return (
|
|
114
116
|
<>
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
<Icon name="arrow-down" size={13} className={cn("shrink-0 transition-transform duration-150", !open && "-rotate-90")} />
|
|
124
|
-
<span className="truncate">{label}</span>
|
|
125
|
-
</button>
|
|
126
|
-
</div>
|
|
117
|
+
{tasks.length > 0 ? (
|
|
118
|
+
<div className="mx-8 rounded-t-lg bg-muted-strong shadow-[inset_0_1px_0_0_var(--nonla-border),inset_1px_0_0_0_var(--nonla-border),inset_-1px_0_0_0_var(--nonla-border)] [.light:not(.dark)_&]:bg-background [.light_.nonla-ui:not(.dark)_&]:bg-background">
|
|
119
|
+
<div className={cn("flex h-7.5 items-center gap-1 border-b px-1", open ? "border-border-secondary" : "border-transparent")}>
|
|
120
|
+
<button type="button" onClick={() => setOpen((v) => !v)} className="flex min-w-0 flex-1 cursor-pointer font-normal items-center gap-1 rounded-md px-1.5 py-1 text-sm text-muted-foreground/90 transition-colors hover:text-foreground" aria-expanded={open} aria-label={label}>
|
|
121
|
+
<Icon name="arrow-down" size={13} className={cn("shrink-0 transition-transform duration-200 ease-out", !open && "-rotate-90")} />
|
|
122
|
+
<span className="truncate">{label}</span>
|
|
123
|
+
</button>
|
|
124
|
+
</div>
|
|
127
125
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
</div>
|
|
126
|
+
<div className="overflow-hidden transition-[height] duration-200 ease-out" style={{ height: open ? listH : 0 }}>
|
|
127
|
+
<div ref={listInnerRef} className="max-h-55 overflow-y-auto py-0.5">
|
|
128
|
+
{tasks.map((task) => (
|
|
129
|
+
<TaskRow
|
|
130
|
+
key={task.taskId}
|
|
131
|
+
task={task}
|
|
132
|
+
now={now}
|
|
133
|
+
cancelling={cancellingIds?.has(task.taskId) ?? false}
|
|
134
|
+
onCancel={() => {
|
|
135
|
+
void onCancel?.(task.taskId);
|
|
136
|
+
}}
|
|
137
|
+
onLogs={() => setLogsTaskId(task.taskId)}
|
|
138
|
+
/>
|
|
139
|
+
))}
|
|
143
140
|
</div>
|
|
144
141
|
</div>
|
|
145
|
-
|
|
146
|
-
|
|
142
|
+
</div>
|
|
143
|
+
) : null}
|
|
144
|
+
{children}
|
|
147
145
|
|
|
148
146
|
<TaskLogsModal task={logsTask} open={Boolean(logsTask)} onClose={() => setLogsTaskId(null)} />
|
|
149
147
|
</>
|
|
@@ -35,7 +35,7 @@ export function ChatToolCall({ toolName = "Tool", label, toolInput, toolOutput,
|
|
|
35
35
|
<>
|
|
36
36
|
{identityIcon}
|
|
37
37
|
<span className="flex min-w-0 items-center gap-1">
|
|
38
|
-
<Shimmer active={running} className={cn("min-w-0 truncate text-left font-
|
|
38
|
+
<Shimmer active={running} className={cn("min-w-0 truncate text-left font-normal", !running && "text-muted-foreground")}>{displayLabel}</Shimmer>
|
|
39
39
|
<ToolUiTrailing failed={hasError} chevron={expandable} chevronClassName={cn("text-muted-foreground group-hover:opacity-100", open && "opacity-100 rotate-90")} />
|
|
40
40
|
</span>
|
|
41
41
|
</>
|
|
@@ -42,7 +42,7 @@ export function GetCurrentTimeToolUI({ msg, assistantLabel = "Assistant", assist
|
|
|
42
42
|
<div className="px-4">
|
|
43
43
|
<div className={chatToolLineClass}>
|
|
44
44
|
<Icon name="clock" size={13} className="shrink-0 text-muted-foreground" />
|
|
45
|
-
<Shimmer active={running} className="truncate font-
|
|
45
|
+
<Shimmer active={running} className="truncate font-normal tabular-nums text-muted-foreground">{hasError ? "Failed to get time" : running ? "Getting time…" : label}</Shimmer>
|
|
46
46
|
<ToolUiTrailing failed={hasError} />
|
|
47
47
|
</div>
|
|
48
48
|
</div>
|
|
@@ -57,7 +57,7 @@ export function ReadSkillToolUI({ msg, assistantLabel = "Assistant", assistantCo
|
|
|
57
57
|
<details className="group/readskill px-4" style={{ overflowAnchor: "none" }}>
|
|
58
58
|
<summary className={cn(chatToolLineClass, "cursor-pointer list-none select-none [&::-webkit-details-marker]:hidden")}>
|
|
59
59
|
<Icon name={reference ? "document" : "book"} size={13} className="shrink-0 text-muted-foreground" />
|
|
60
|
-
<Shimmer active={running} className="min-w-0 truncate font-
|
|
60
|
+
<Shimmer active={running} className="min-w-0 truncate font-normal text-muted-foreground">
|
|
61
61
|
{verb}
|
|
62
62
|
{targetLabel ? <span className="text-tertiary-foreground"> {targetLabel}</span> : null}
|
|
63
63
|
</Shimmer>
|
|
@@ -89,7 +89,7 @@ export function RunJsToolUI({ msg, assistantLabel = "Assistant", assistantColor,
|
|
|
89
89
|
<details className="group/runjs px-4" style={{ overflowAnchor: "none" }}>
|
|
90
90
|
<summary className={cn(chatToolLineClass, "cursor-pointer list-none select-none [&::-webkit-details-marker]:hidden")}>
|
|
91
91
|
<Icon name="code" size={13} className="shrink-0 text-muted-foreground" />
|
|
92
|
-
<Shimmer active={running} className="min-w-0 truncate font-
|
|
92
|
+
<Shimmer active={running} className="min-w-0 truncate font-normal text-muted-foreground">{verb}</Shimmer>
|
|
93
93
|
<ToolUiTrailing running={running} failed={failed} chevron chevronClassName="group-hover/runjs:opacity-100 group-open/runjs:opacity-100 group-open/runjs:rotate-90" />
|
|
94
94
|
</summary>
|
|
95
95
|
|
|
@@ -39,7 +39,7 @@ export function WebFetchToolUI({ msg, assistantLabel = "Assistant", assistantCol
|
|
|
39
39
|
const header = (
|
|
40
40
|
<>
|
|
41
41
|
<Icon name="globe" size={13} className="shrink-0 text-muted-foreground" />
|
|
42
|
-
<Shimmer active={running} className="min-w-0 truncate font-
|
|
42
|
+
<Shimmer active={running} className="min-w-0 truncate font-normal text-muted-foreground">
|
|
43
43
|
{verb} <span className="text-tertiary-foreground">{url}</span>
|
|
44
44
|
</Shimmer>
|
|
45
45
|
<ToolUiTrailing failed={failed} chevron={expandable} chevronClassName="group-hover/webfetch:opacity-100 group-open/webfetch:opacity-100 group-open/webfetch:rotate-90" />
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import type { ComponentType } from "react";
|
|
2
2
|
import type { AgentToolNameMatch } from "../common/types";
|
|
3
|
-
import {
|
|
4
|
-
import { CallAgentToolUI } from "./CallAgentToolUI";
|
|
3
|
+
import { matchesToolName } from "../common/utils";
|
|
5
4
|
import { GetCurrentTimeToolUI } from "./GetCurrentTimeToolUI";
|
|
6
5
|
import { ReadSkillToolUI } from "./ReadSkillToolUI";
|
|
7
6
|
import { RunJsToolUI } from "./RunJsToolUI";
|
|
8
7
|
import type { ToolUIProps } from "./types";
|
|
9
8
|
import { WebFetchToolUI } from "./WebFetchToolUI";
|
|
10
9
|
|
|
11
|
-
/** Exact name, aliases, or a predicate
|
|
10
|
+
/** Exact name, aliases, or a predicate. */
|
|
12
11
|
export type AgentToolUIName = AgentToolNameMatch;
|
|
13
12
|
|
|
14
13
|
export type AgentToolUI = {
|
|
@@ -21,11 +20,10 @@ export function matchesToolUIName(name: AgentToolUIName, toolName: string): bool
|
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
export const builtinToolUis: AgentToolUI[] = [
|
|
24
|
-
{ name:
|
|
25
|
-
{ name:
|
|
26
|
-
{ name: "
|
|
27
|
-
{ name: "
|
|
28
|
-
{ name: "run_js", component: RunJsToolUI },
|
|
23
|
+
{ name: "nonla_web_fetch", component: WebFetchToolUI },
|
|
24
|
+
{ name: "nonla_get_current_time", component: GetCurrentTimeToolUI },
|
|
25
|
+
{ name: "nonla_read_skill", component: ReadSkillToolUI },
|
|
26
|
+
{ name: "nonla_run_js", component: RunJsToolUI },
|
|
29
27
|
];
|
|
30
28
|
|
|
31
29
|
/** App `toolUis` win on the same name; builtins are the fallback. */
|
|
@@ -23,7 +23,7 @@ function tableToMarkdown(table: HTMLTableElement): string {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const tableClass =
|
|
26
|
-
"w-max min-w-full border-separate border-spacing-0 text-
|
|
26
|
+
"w-max min-w-full border-separate border-spacing-0 text-sm [&_th]:whitespace-normal [&_td]:whitespace-normal [&_th]:wrap-normal [&_td]:wrap-normal [&_th]:border-b [&_th]:border-border-secondary [&_th]:px-4 [&_th]:py-1.5 [&_th]:text-left [&_th]:align-top [&_th]:font-medium [&_td]:border-b [&_td]:border-border-secondary [&_td]:px-4 [&_td]:py-1.5 [&_td]:align-top";
|
|
27
27
|
|
|
28
28
|
export function MarkdownTable({ children }: { children: ReactNode }) {
|
|
29
29
|
const tableRef = useRef<HTMLTableElement>(null);
|
|
@@ -137,7 +137,7 @@ export function ListItem({ view, children }: { view: Extract<InlineEdit, { kind:
|
|
|
137
137
|
const ordinal = Number(/^(\d+)/.exec(view.marker)?.[1] ?? "1");
|
|
138
138
|
const marker = "w-6 shrink-0 pt-0.5 text-(length:--md-body-size,var(--nonla-md-text-size,16px)) leading-(--md-p-leading,1.6)";
|
|
139
139
|
return (
|
|
140
|
-
<div className="flex items-start gap-1.5 pl-(--md-item-pl,4px)" style={level > 0 ? { marginLeft: `calc(${level} * var(--md-nest, 1.25rem))` } : undefined}>
|
|
140
|
+
<div data-md-list="" className="flex items-start gap-1.5 pl-(--md-item-pl,4px)" style={level > 0 ? { marginLeft: `calc(${level} * var(--md-nest, 1.25rem))` } : undefined}>
|
|
141
141
|
{view.task ? (
|
|
142
142
|
<span className={cn(marker, "pointer-events-none inline-flex justify-center")}>
|
|
143
143
|
<span className="mt-[calc((1lh-1rem)/2)] inline-flex">
|
|
@@ -47,18 +47,34 @@ export type SortableTreeProps<T = unknown> = {
|
|
|
47
47
|
|
|
48
48
|
const DROP_ANIMATION = { duration: 180, easing: "cubic-bezier(0.16, 1, 0.3, 1)" };
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
type OverlayOrigin = { key: string; left: number; top: number; width: number; height: number };
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The overlay is `position: fixed` at the rect from drag start, then translated.
|
|
54
|
+
* `activeNodeRect` keeps moving as the list scrolls, so clamping against it
|
|
55
|
+
* walks the preview off the pointer. Lock the origin for the whole drag.
|
|
56
|
+
*/
|
|
57
|
+
let overlayOrigin: OverlayOrigin | null = null;
|
|
58
|
+
|
|
59
|
+
const clampOverlayToWindow: Modifier = ({ transform, active, activeNodeRect, windowRect }) => {
|
|
60
|
+
if (!active) {
|
|
61
|
+
overlayOrigin = null;
|
|
62
|
+
return transform;
|
|
63
|
+
}
|
|
52
64
|
if (!activeNodeRect || !windowRect) return transform;
|
|
65
|
+
const key = String(active.id);
|
|
66
|
+
if (!overlayOrigin || overlayOrigin.key !== key) {
|
|
67
|
+
overlayOrigin = { key, left: activeNodeRect.left, top: activeNodeRect.top, width: activeNodeRect.width, height: activeNodeRect.height };
|
|
68
|
+
}
|
|
53
69
|
const next = { ...transform };
|
|
54
|
-
const left =
|
|
55
|
-
const top =
|
|
56
|
-
const maxLeft = windowRect.left + windowRect.width -
|
|
57
|
-
const maxTop = windowRect.top + windowRect.height -
|
|
58
|
-
if (left < windowRect.left) next.x = windowRect.left -
|
|
59
|
-
else if (left > maxLeft) next.x = maxLeft -
|
|
60
|
-
if (top < windowRect.top) next.y = windowRect.top -
|
|
61
|
-
else if (top > maxTop) next.y = maxTop -
|
|
70
|
+
const left = overlayOrigin.left + transform.x;
|
|
71
|
+
const top = overlayOrigin.top + transform.y;
|
|
72
|
+
const maxLeft = windowRect.left + windowRect.width - overlayOrigin.width;
|
|
73
|
+
const maxTop = windowRect.top + windowRect.height - overlayOrigin.height;
|
|
74
|
+
if (left < windowRect.left) next.x = windowRect.left - overlayOrigin.left;
|
|
75
|
+
else if (left > maxLeft) next.x = maxLeft - overlayOrigin.left;
|
|
76
|
+
if (top < windowRect.top) next.y = windowRect.top - overlayOrigin.top;
|
|
77
|
+
else if (top > maxTop) next.y = maxTop - overlayOrigin.top;
|
|
62
78
|
return next;
|
|
63
79
|
};
|
|
64
80
|
|
|
@@ -87,10 +103,9 @@ function faceRect(root: HTMLElement | null, id: string): DOMRect | null {
|
|
|
87
103
|
return node instanceof HTMLElement ? node.getBoundingClientRect() : null;
|
|
88
104
|
}
|
|
89
105
|
|
|
90
|
-
/**
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
*/
|
|
106
|
+
/** Only the last few pixels of a trailing child belong to the next parent. The rest of the row stays with that child. */
|
|
107
|
+
const PARENT_SEAM = 6;
|
|
108
|
+
|
|
94
109
|
function gapTarget<T>(items: SortableTreeItem<T>[], hitId: string, pointerY: number | null, root: HTMLElement | null, blocked: Set<string>): string {
|
|
95
110
|
if (pointerY == null) return hitId;
|
|
96
111
|
const flat = flatten(items);
|
|
@@ -106,10 +121,28 @@ function gapTarget<T>(items: SortableTreeItem<T>[], hitId: string, pointerY: num
|
|
|
106
121
|
const following = flat[scan];
|
|
107
122
|
if (!following || following.depth >= hit.depth || blocked.has(following.id)) return hitId;
|
|
108
123
|
const rect = faceRect(root, hitId);
|
|
109
|
-
if (!rect || pointerY < rect.
|
|
124
|
+
if (!rect || pointerY < rect.bottom - PARENT_SEAM) return hitId;
|
|
110
125
|
return following.id;
|
|
111
126
|
}
|
|
112
127
|
|
|
128
|
+
/** Distance from the pointer. `closestCenter` measures the overlay rect, which already includes the drag delta, so it drifts off the cursor. */
|
|
129
|
+
function closestToPointer(containers: Parameters<CollisionDetection>[0]["droppableContainers"], rects: Parameters<CollisionDetection>[0]["droppableRects"], pointer: { x: number; y: number }): Collision | undefined {
|
|
130
|
+
let best: Collision | undefined;
|
|
131
|
+
let bestDistance = Number.POSITIVE_INFINITY;
|
|
132
|
+
for (const container of containers) {
|
|
133
|
+
const rect = rects.get(container.id);
|
|
134
|
+
if (!rect) continue;
|
|
135
|
+
const dx = rect.left + rect.width / 2 - pointer.x;
|
|
136
|
+
const dy = rect.top + rect.height / 2 - pointer.y;
|
|
137
|
+
const distance = dx * dx + dy * dy;
|
|
138
|
+
if (distance < bestDistance) {
|
|
139
|
+
bestDistance = distance;
|
|
140
|
+
best = { id: container.id };
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return best;
|
|
144
|
+
}
|
|
145
|
+
|
|
113
146
|
function smallestHit(hits: Collision[], rects: Parameters<CollisionDetection>[0]["droppableRects"]): Collision {
|
|
114
147
|
let best = hits[0];
|
|
115
148
|
let bestArea = Number.POSITIVE_INFINITY;
|
|
@@ -147,14 +180,14 @@ function collideTree<T>(args: Parameters<CollisionDetection>[0], items: Sortable
|
|
|
147
180
|
const containers = args.droppableContainers.filter((container) => !blocked.has(String(container.id)));
|
|
148
181
|
const scoped = { ...args, droppableContainers: containers };
|
|
149
182
|
const inside = pointerWithin(scoped);
|
|
150
|
-
let hit = inside.length > 0 ? smallestHit(inside, args.droppableRects) : closestCenter(scoped)[0];
|
|
183
|
+
let hit = inside.length > 0 ? smallestHit(inside, args.droppableRects) : pointer ? closestToPointer(containers, args.droppableRects, pointer) : closestCenter(scoped)[0];
|
|
151
184
|
if (!hit) return [];
|
|
152
185
|
|
|
153
186
|
const activeId = String(args.active.id);
|
|
154
187
|
if (isAncestor(items, activeId, String(hit.id)) && !pointerInside(faceRect(root, String(hit.id)), pointer)) {
|
|
155
188
|
const parentId = parentIdOf(args.active.data.current);
|
|
156
189
|
const siblings = containers.filter((container) => parentIdOf(container.data.current) === parentId);
|
|
157
|
-
const siblingHit = closestCenter({ ...scoped, droppableContainers: siblings })[0];
|
|
190
|
+
const siblingHit = pointer ? closestToPointer(siblings, args.droppableRects, pointer) : closestCenter({ ...scoped, droppableContainers: siblings })[0];
|
|
158
191
|
if (siblingHit) hit = siblingHit;
|
|
159
192
|
}
|
|
160
193
|
|
|
@@ -395,8 +428,12 @@ function OverlayBranch<T>({ item, renderItem }: { item: SortableTreeItem<T>; ren
|
|
|
395
428
|
);
|
|
396
429
|
}
|
|
397
430
|
|
|
398
|
-
|
|
399
|
-
|
|
431
|
+
/** Insertion edge, painted above the drag preview so the ghost cannot hide it. */
|
|
432
|
+
function FloatingDropLine({ root, hint }: { root: HTMLElement | null; hint: DropHint }) {
|
|
433
|
+
const rect = faceRect(root, hint.overId);
|
|
434
|
+
if (!rect) return null;
|
|
435
|
+
const top = hint.edge === "top" ? rect.top : rect.bottom;
|
|
436
|
+
return <span aria-hidden className="pointer-events-none fixed z-1100 h-0.5 rounded-full bg-foreground" style={{ top: top - 1, left: rect.left + 6, width: Math.max(0, rect.width - 12) }} />;
|
|
400
437
|
}
|
|
401
438
|
|
|
402
439
|
function SortableNode<T>({
|
|
@@ -404,20 +441,19 @@ function SortableNode<T>({
|
|
|
404
441
|
parentId,
|
|
405
442
|
depth,
|
|
406
443
|
renderItem,
|
|
407
|
-
|
|
444
|
+
sorting,
|
|
408
445
|
}: {
|
|
409
446
|
item: SortableTreeItem<T>;
|
|
410
447
|
parentId: string | null;
|
|
411
448
|
depth: number;
|
|
412
449
|
renderItem?: SortableTreeProps<T>["renderItem"];
|
|
413
|
-
|
|
450
|
+
sorting: boolean;
|
|
414
451
|
}) {
|
|
415
452
|
const { attributes, listeners, setActivatorNodeRef, setNodeRef, transform, transition, isDragging } = useSortable({
|
|
416
453
|
id: item.id,
|
|
417
454
|
data: { parentId },
|
|
418
455
|
disabled: item.disabled ? { draggable: true } : false,
|
|
419
456
|
});
|
|
420
|
-
const edge = hint?.overId === item.id ? hint.edge : null;
|
|
421
457
|
|
|
422
458
|
return (
|
|
423
459
|
<div
|
|
@@ -426,11 +462,10 @@ function SortableNode<T>({
|
|
|
426
462
|
className={cn("relative min-w-0 max-w-full", isDragging && "rounded-md bg-muted shadow-[inset_0_0_0_1px_var(--nonla-border)]")}
|
|
427
463
|
style={{
|
|
428
464
|
transform: verticalShift(transform),
|
|
429
|
-
transition,
|
|
465
|
+
transition: sorting ? undefined : transition,
|
|
430
466
|
zIndex: isDragging ? 1 : undefined,
|
|
431
467
|
}}
|
|
432
468
|
>
|
|
433
|
-
{edge ? <DropLine edge={edge} /> : null}
|
|
434
469
|
<div className={cn("min-w-0", isDragging && "invisible")}>
|
|
435
470
|
<RowFace
|
|
436
471
|
item={item}
|
|
@@ -447,7 +482,7 @@ function SortableNode<T>({
|
|
|
447
482
|
/>
|
|
448
483
|
{item.children?.length ? (
|
|
449
484
|
<div className="min-w-0 ps-4">
|
|
450
|
-
<SortableLevel items={item.children} parentId={item.id} depth={depth + 1} renderItem={renderItem}
|
|
485
|
+
<SortableLevel items={item.children} parentId={item.id} depth={depth + 1} renderItem={renderItem} sorting={sorting} />
|
|
451
486
|
</div>
|
|
452
487
|
) : null}
|
|
453
488
|
</div>
|
|
@@ -460,19 +495,19 @@ function SortableLevel<T>({
|
|
|
460
495
|
parentId,
|
|
461
496
|
depth,
|
|
462
497
|
renderItem,
|
|
463
|
-
|
|
498
|
+
sorting,
|
|
464
499
|
}: {
|
|
465
500
|
items: SortableTreeItem<T>[];
|
|
466
501
|
parentId: string | null;
|
|
467
502
|
depth: number;
|
|
468
503
|
renderItem?: SortableTreeProps<T>["renderItem"];
|
|
469
|
-
|
|
504
|
+
sorting: boolean;
|
|
470
505
|
}) {
|
|
471
506
|
return (
|
|
472
507
|
<SortableContext items={items.map((item) => item.id)} strategy={verticalListSortingStrategy}>
|
|
473
508
|
<div className="flex min-w-0 flex-col gap-0.5">
|
|
474
509
|
{items.map((item) => (
|
|
475
|
-
<SortableNode key={item.id} item={item} parentId={parentId} depth={depth} renderItem={renderItem}
|
|
510
|
+
<SortableNode key={item.id} item={item} parentId={parentId} depth={depth} renderItem={renderItem} sorting={sorting} />
|
|
476
511
|
))}
|
|
477
512
|
</div>
|
|
478
513
|
</SortableContext>
|
|
@@ -486,6 +521,7 @@ export function SortableTree<T = unknown>({ items, onChange, onDragEnd, renderIt
|
|
|
486
521
|
const overRef = useRef<string | null>(null);
|
|
487
522
|
const blockedRef = useRef<Set<string>>(new Set());
|
|
488
523
|
const rootRef = useRef<HTMLDivElement>(null);
|
|
524
|
+
const pointerRef = useRef<{ x: number; y: number } | null>(null);
|
|
489
525
|
const onChangeRef = useRef(onChange);
|
|
490
526
|
const onDragEndRef = useRef(onDragEnd);
|
|
491
527
|
const itemsRef = useRef(items);
|
|
@@ -499,7 +535,12 @@ export function SortableTree<T = unknown>({ items, onChange, onDragEnd, renderIt
|
|
|
499
535
|
useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }),
|
|
500
536
|
);
|
|
501
537
|
|
|
502
|
-
const collisionDetection: CollisionDetection = (args) =>
|
|
538
|
+
const collisionDetection: CollisionDetection = (args) => {
|
|
539
|
+
if (args.pointerCoordinates) pointerRef.current = args.pointerCoordinates;
|
|
540
|
+
return collideTree(args, itemsRef.current, blockedRef.current, rootRef.current);
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
const cursorY = (event: DragMoveEvent | DragEndEvent) => pointerRef.current?.y ?? pointerY(event);
|
|
503
544
|
|
|
504
545
|
const assignHint = (next: DropHint | null) => {
|
|
505
546
|
const prev = hintRef.current;
|
|
@@ -524,6 +565,8 @@ export function SortableTree<T = unknown>({ items, onChange, onDragEnd, renderIt
|
|
|
524
565
|
|
|
525
566
|
const onDragStart = (event: DragStartEvent) => {
|
|
526
567
|
const id = String(event.active.id);
|
|
568
|
+
overlayOrigin = null;
|
|
569
|
+
pointerRef.current = null;
|
|
527
570
|
setActiveId(id);
|
|
528
571
|
overRef.current = null;
|
|
529
572
|
const node = findItem(itemsRef.current, id);
|
|
@@ -533,27 +576,28 @@ export function SortableTree<T = unknown>({ items, onChange, onDragEnd, renderIt
|
|
|
533
576
|
const onDragOver = (event: DragMoveEvent) => {
|
|
534
577
|
const id = event.over ? String(event.over.id) : null;
|
|
535
578
|
overRef.current = id;
|
|
536
|
-
showPlace(String(event.active.id), id,
|
|
579
|
+
showPlace(String(event.active.id), id, cursorY(event));
|
|
537
580
|
};
|
|
538
581
|
|
|
539
582
|
const onDragMove = (event: DragMoveEvent) => {
|
|
540
583
|
const id = event.over ? String(event.over.id) : overRef.current;
|
|
541
584
|
if (!id) return;
|
|
542
585
|
if (event.over) overRef.current = id;
|
|
543
|
-
showPlace(String(event.active.id), id,
|
|
586
|
+
showPlace(String(event.active.id), id, cursorY(event));
|
|
544
587
|
};
|
|
545
588
|
|
|
546
589
|
const stopDrag = () => {
|
|
547
590
|
setActiveId(null);
|
|
548
591
|
overRef.current = null;
|
|
549
592
|
blockedRef.current = new Set();
|
|
593
|
+
pointerRef.current = null;
|
|
550
594
|
assignHint(null);
|
|
551
595
|
};
|
|
552
596
|
|
|
553
597
|
const handleDragEnd = (event: DragEndEvent) => {
|
|
554
598
|
const activeDragId = String(event.active.id);
|
|
555
599
|
const overId = event.over ? String(event.over.id) : overRef.current;
|
|
556
|
-
const place = placeFor(activeDragId, overId,
|
|
600
|
+
const place = placeFor(activeDragId, overId, cursorY(event));
|
|
557
601
|
stopDrag();
|
|
558
602
|
if (!place || !overId) return;
|
|
559
603
|
const current = itemsRef.current;
|
|
@@ -575,21 +619,24 @@ export function SortableTree<T = unknown>({ items, onChange, onDragEnd, renderIt
|
|
|
575
619
|
return (
|
|
576
620
|
<div ref={rootRef} className={cn("w-full min-w-0 max-w-full overscroll-x-none", className)} style={{ overflowX: "clip" }}>
|
|
577
621
|
<DndContext sensors={sensors} collisionDetection={collisionDetection} onDragStart={onDragStart} onDragOver={onDragOver} onDragMove={onDragMove} onDragEnd={handleDragEnd} onDragCancel={onDragCancel}>
|
|
578
|
-
<SortableLevel items={items} parentId={null} depth={0} renderItem={renderItem}
|
|
622
|
+
<SortableLevel items={items} parentId={null} depth={0} renderItem={renderItem} sorting={activeId != null} />
|
|
579
623
|
{portalNode
|
|
580
624
|
? createPortal(
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
<
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
625
|
+
<>
|
|
626
|
+
<DragOverlay
|
|
627
|
+
zIndex={1050}
|
|
628
|
+
dropAnimation={DROP_ANIMATION}
|
|
629
|
+
modifiers={[clampOverlayToWindow]}
|
|
630
|
+
className="pointer-events-none overflow-hidden rounded-md bg-card shadow-(--nonla-card-shadow)"
|
|
631
|
+
>
|
|
632
|
+
{activeItem ? (
|
|
633
|
+
<div data-sortable-overlay="">
|
|
634
|
+
<OverlayBranch item={activeItem} renderItem={renderItem} />
|
|
635
|
+
</div>
|
|
636
|
+
) : null}
|
|
637
|
+
</DragOverlay>
|
|
638
|
+
{hint ? <FloatingDropLine root={rootRef.current} hint={hint} /> : null}
|
|
639
|
+
</>,
|
|
593
640
|
portalNode,
|
|
594
641
|
)
|
|
595
642
|
: null}
|
package/src/styles.css
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
@import "highlight.js/styles/github-dark-dimmed.css";
|
|
2
|
+
@import "@fontsource-variable/inter/opsz.css";
|
|
3
|
+
@import "@fontsource-variable/inter/opsz-italic.css";
|
|
4
|
+
@import "@fontsource-variable/geist-mono/wght.css";
|
|
5
|
+
@import "@fontsource-variable/geist-mono/wght-italic.css";
|
|
2
6
|
@import "./avatar/avatar.css";
|
|
3
7
|
|
|
4
8
|
/**
|
|
@@ -19,7 +23,6 @@
|
|
|
19
23
|
color-scheme: dark;
|
|
20
24
|
|
|
21
25
|
/* ── Config. Set these. `.nonla-ui.light` repeats the same keys. ───── */
|
|
22
|
-
/* Claude dark (claude.com). Warm gray, hue ~60. Page 950, sidebar 900, cards 850, bar 800. */
|
|
23
26
|
--nonla-bg: #141413;
|
|
24
27
|
--nonla-text-main: #faf9f5;
|
|
25
28
|
--nonla-text-secondary: #b0aea5;
|
|
@@ -39,15 +42,16 @@
|
|
|
39
42
|
--nonla-border-secondary: #242322;
|
|
40
43
|
--nonla-input: rgb(250 249 245 / 14%);
|
|
41
44
|
|
|
42
|
-
--nonla-font: ui-sans-serif, -apple-system, system-ui, "Segoe UI Variable Display", "Segoe UI", Helvetica, "Apple Color Emoji", "Noto Sans Arabic", "Noto Sans Hebrew", Arial, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol";
|
|
45
|
+
--nonla-font: "Inter Variable", ui-sans-serif, -apple-system, system-ui, "Segoe UI Variable Display", "Segoe UI", Helvetica, "Apple Color Emoji", "Noto Sans Arabic", "Noto Sans Hebrew", Arial, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol";
|
|
46
|
+
--nonla-mono-font: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Courier New", monospace;
|
|
43
47
|
/* Default body size. Tailwind `text-base` follows this. Leading is 1.6. */
|
|
44
48
|
--nonla-base-text-size: 15px;
|
|
45
|
-
/* `text-md`. MarkdownViewer body
|
|
49
|
+
/* `text-md`. MarkdownViewer body uses this. Agent replies use `text-base`. */
|
|
46
50
|
--nonla-md-text-size: 16px;
|
|
47
51
|
/* `text-sm`. Composer, tool lines, and errors use this. User bubbles use `text-base`. */
|
|
48
52
|
--nonla-sm-text-size: 14px;
|
|
49
|
-
/* Code.
|
|
50
|
-
--nonla-mono-text-size: calc(var(--nonla-base-text-size)
|
|
53
|
+
/* Code. One pixel under the body, so mono does not look larger than the text around it. */
|
|
54
|
+
--nonla-mono-text-size: calc(var(--nonla-base-text-size) - 1px);
|
|
51
55
|
--nonla-radius: 8px;
|
|
52
56
|
--nonla-height: 32px;
|
|
53
57
|
--nonla-height-sm: 24px;
|
|
@@ -226,7 +230,7 @@
|
|
|
226
230
|
|
|
227
231
|
--font-sans: var(--nonla-font);
|
|
228
232
|
--font-family-sans: var(--font-sans);
|
|
229
|
-
--font-mono:
|
|
233
|
+
--font-mono: var(--nonla-mono-font);
|
|
230
234
|
--font-family-mono: var(--font-mono);
|
|
231
235
|
|
|
232
236
|
--animate-fadeIn: fadeIn 0.28s ease-out both;
|
|
@@ -525,6 +529,10 @@
|
|
|
525
529
|
}
|
|
526
530
|
}
|
|
527
531
|
|
|
532
|
+
.nonla-ui :is(pre, code, kbd, samp) {
|
|
533
|
+
font-family: var(--nonla-mono-font);
|
|
534
|
+
}
|
|
535
|
+
|
|
528
536
|
.nonla-codeblock-pre code,
|
|
529
537
|
.nonla-codeblock-pre .hljs {
|
|
530
538
|
color: var(--foreground);
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { type ReactNode, useEffect, useRef, useState } from "react";
|
|
2
|
-
import { Icon } from "../../icon/Icon";
|
|
3
|
-
import { cn } from "../../lib/cn";
|
|
4
|
-
import { Shimmer } from "../../shimmer/Shimmer";
|
|
5
|
-
import { Spin } from "../../spin/Spin";
|
|
6
|
-
import { chatRowBoxClass, chatRowClass } from "../chatRhythm";
|
|
7
|
-
import { formatBgElapsed, parseBgTaskRef } from "../common/bgTasks";
|
|
8
|
-
import { parseJsonObject, prettyJson, timestampMs } from "../common/utils";
|
|
9
|
-
import { ChatMarkdown } from "../message-ui/ChatMarkdown";
|
|
10
|
-
import { ChatSpinner } from "../message-ui/ChatSpinner";
|
|
11
|
-
import { ToolUiBadge } from "./ToolUiBadge";
|
|
12
|
-
import { ToolUiTrailing } from "./ToolUiTrailing";
|
|
13
|
-
import type { ToolUIProps } from "./types";
|
|
14
|
-
|
|
15
|
-
type CallAgentParsed = {
|
|
16
|
-
success: boolean;
|
|
17
|
-
response: string | null;
|
|
18
|
-
agentId: string | null;
|
|
19
|
-
error: string | null;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
function parseCallAgentOutput(raw: unknown): CallAgentParsed | null {
|
|
23
|
-
if (raw == null) return null;
|
|
24
|
-
const parsed = typeof raw === "string" ? parseJsonObject<Record<string, unknown>>(raw) : typeof raw === "object" ? (raw as Record<string, unknown>) : null;
|
|
25
|
-
if (!parsed || !("success" in parsed)) return null;
|
|
26
|
-
return {
|
|
27
|
-
success: Boolean(parsed.success),
|
|
28
|
-
response: (parsed.response as string | null | undefined) ?? null,
|
|
29
|
-
agentId: (parsed.agent_id as string | null | undefined) ?? null,
|
|
30
|
-
error: (parsed.error as string | null | undefined) ?? null,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function TypingDots() {
|
|
35
|
-
return (
|
|
36
|
-
<div className="flex items-center gap-1 px-0.5 py-0.5" role="status" aria-label="Typing">
|
|
37
|
-
{[0, 1, 2].map((i) => (
|
|
38
|
-
<span key={i} className="size-1.5 rounded-full bg-muted-foreground/50 animate-bounce" style={{ animationDelay: `${i * 150}ms` }} />
|
|
39
|
-
))}
|
|
40
|
-
</div>
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function AgentAvatar({ name, size = 22, className }: { name: string; size?: number; className?: string }) {
|
|
45
|
-
const initial = (name.trim()[0] ?? "?").toUpperCase();
|
|
46
|
-
return (
|
|
47
|
-
<div className={cn("flex items-center justify-center rounded-full bg-muted text-[10px] font-semibold text-muted-foreground", className)} style={{ width: size, height: size }} aria-hidden>
|
|
48
|
-
{initial}
|
|
49
|
-
</div>
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function AgentTurn({
|
|
54
|
-
name,
|
|
55
|
-
children,
|
|
56
|
-
align = "start",
|
|
57
|
-
}: {
|
|
58
|
-
name: string;
|
|
59
|
-
children: ReactNode;
|
|
60
|
-
align?: "start" | "end";
|
|
61
|
-
}) {
|
|
62
|
-
return (
|
|
63
|
-
<div className={cn("flex items-start gap-2", align === "end" && "flex-row-reverse")}>
|
|
64
|
-
<AgentAvatar name={name} className="mt-0.5 shrink-0" />
|
|
65
|
-
<div className={cn("flex min-w-0 flex-1 flex-col gap-0.5", align === "end" ? "items-end" : "items-start")}>
|
|
66
|
-
<span className="select-none text-sm font-medium text-tertiary-foreground">{name}</span>
|
|
67
|
-
<div className="w-fit max-w-[92%]">{children}</div>
|
|
68
|
-
</div>
|
|
69
|
-
</div>
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function ExpandableBody({ children, className }: { children: ReactNode; className?: string }) {
|
|
74
|
-
const [expanded, setExpanded] = useState(false);
|
|
75
|
-
const [overflows, setOverflows] = useState(false);
|
|
76
|
-
const bodyRef = useRef<HTMLDivElement>(null);
|
|
77
|
-
|
|
78
|
-
useEffect(() => {
|
|
79
|
-
const el = bodyRef.current;
|
|
80
|
-
if (el) setOverflows(el.scrollHeight > 160);
|
|
81
|
-
}, [children]);
|
|
82
|
-
|
|
83
|
-
return (
|
|
84
|
-
<div>
|
|
85
|
-
<div ref={bodyRef} className={cn("overflow-hidden transition-[max-height] duration-200", !expanded && "max-h-40", className)}>
|
|
86
|
-
{children}
|
|
87
|
-
</div>
|
|
88
|
-
{overflows ? (
|
|
89
|
-
<button type="button" onClick={() => setExpanded((v) => !v)} className="mt-1 cursor-pointer border-0 bg-transparent p-0 text-sm text-tertiary-foreground hover:text-foreground">
|
|
90
|
-
{expanded ? "Show less" : "Show more"}
|
|
91
|
-
</button>
|
|
92
|
-
) : null}
|
|
93
|
-
</div>
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function CallAgentToolUI({ msg, assistantLabel = "Assistant", assistantColor, showAvatar = false }: ToolUIProps) {
|
|
98
|
-
const hasOutput = msg.toolOutput != null;
|
|
99
|
-
const hasError = Boolean(msg.toolError);
|
|
100
|
-
const bgRef = parseBgTaskRef(msg.toolOutput);
|
|
101
|
-
const parsed = parseCallAgentOutput(msg.toolOutput);
|
|
102
|
-
const failed = hasError || parsed?.success === false;
|
|
103
|
-
const bgRunning = Boolean(bgRef) && !failed && !parsed;
|
|
104
|
-
const [now, setNow] = useState(() => Date.now());
|
|
105
|
-
|
|
106
|
-
useEffect(() => {
|
|
107
|
-
if (!bgRunning) return;
|
|
108
|
-
const id = setInterval(() => setNow(Date.now()), 1000);
|
|
109
|
-
return () => clearInterval(id);
|
|
110
|
-
}, [bgRunning]);
|
|
111
|
-
|
|
112
|
-
const requestMessage = ((msg.toolInput as Record<string, unknown> | null)?.message as string | undefined)?.trim() ?? "";
|
|
113
|
-
const hasRequest = requestMessage.length > 0;
|
|
114
|
-
const composing = !hasOutput && !hasError && !hasRequest;
|
|
115
|
-
const awaitingReply = bgRunning || (!hasOutput && !hasError && hasRequest);
|
|
116
|
-
const calling = composing || awaitingReply;
|
|
117
|
-
const showCallee = awaitingReply || failed || parsed != null;
|
|
118
|
-
const calleeName = msg.toolLabel?.replace(/^Call\s+/i, "") ?? "Agent";
|
|
119
|
-
const statusLabel = failed && !awaitingReply ? (parsed?.error ?? "Call failed") : null;
|
|
120
|
-
|
|
121
|
-
return (
|
|
122
|
-
<div className={`${chatRowClass} animate-fadeIn`}>
|
|
123
|
-
<ToolUiBadge show={showAvatar} label={assistantLabel} color={assistantColor} />
|
|
124
|
-
<div className={chatRowBoxClass}>
|
|
125
|
-
<div className={cn("overflow-hidden rounded-xl border bg-card", failed ? "border-destructive/35" : "border-border")}>
|
|
126
|
-
<div className="flex items-center gap-2 border-b border-border-secondary px-3 py-2">
|
|
127
|
-
{calling ? (
|
|
128
|
-
<Spin variant="agent" size="small" className="shrink-0" />
|
|
129
|
-
) : (
|
|
130
|
-
<Icon name="dialog" size={13} className="shrink-0 text-muted-foreground" />
|
|
131
|
-
)}
|
|
132
|
-
<Shimmer active={calling} className="min-w-0 flex-1 truncate text-sm font-medium text-foreground">Calling {calleeName}</Shimmer>
|
|
133
|
-
{bgRunning ? <span className="text-sm tabular-nums text-muted-foreground">{formatBgElapsed(timestampMs(msg.timestamp), now)}</span> : null}
|
|
134
|
-
{statusLabel ? <span className="max-w-40 truncate text-sm italic text-destructive">{statusLabel}</span> : null}
|
|
135
|
-
<ToolUiTrailing failed={failed && !awaitingReply} />
|
|
136
|
-
</div>
|
|
137
|
-
|
|
138
|
-
{composing || hasRequest || showCallee ? (
|
|
139
|
-
<div className="flex flex-col gap-3 px-3 py-3">
|
|
140
|
-
{composing || hasRequest ? (
|
|
141
|
-
<AgentTurn name={assistantLabel} align="end">
|
|
142
|
-
<div className="nonla-chat-user rounded-2xl rounded-tr-sm border border-solid border-(--nonla-input) bg-muted-strong px-3 py-2 text-left [.light:not(.dark)_&]:bg-sidebar [.light_.nonla-ui:not(.dark)_&]:bg-sidebar">
|
|
143
|
-
{composing ? <TypingDots /> : <p className="m-0 text-sm leading-[1.55] whitespace-pre-wrap text-foreground">{requestMessage}</p>}
|
|
144
|
-
</div>
|
|
145
|
-
</AgentTurn>
|
|
146
|
-
) : null}
|
|
147
|
-
|
|
148
|
-
{showCallee ? (
|
|
149
|
-
<AgentTurn name={calleeName} align="start">
|
|
150
|
-
<div className={cn("w-fit rounded-2xl rounded-tl-sm border bg-transparent px-3 py-2 text-left", failed && !awaitingReply ? "border-destructive/35" : "border-border")}>
|
|
151
|
-
{awaitingReply ? (
|
|
152
|
-
<div className="flex items-center gap-1.5 py-0.5">
|
|
153
|
-
<ChatSpinner />
|
|
154
|
-
<span className="text-sm italic text-muted-foreground">Replying…</span>
|
|
155
|
-
</div>
|
|
156
|
-
) : failed ? (
|
|
157
|
-
<p className="m-0 text-sm leading-[1.55] text-destructive">{parsed?.error ?? "Agent call failed"}</p>
|
|
158
|
-
) : parsed ? (
|
|
159
|
-
<ExpandableBody>
|
|
160
|
-
<ChatMarkdown content={parsed.response ?? "(no response)"} />
|
|
161
|
-
</ExpandableBody>
|
|
162
|
-
) : (
|
|
163
|
-
<ExpandableBody>
|
|
164
|
-
<pre className="m-0 font-mono text-sm leading-normal break-all whitespace-pre-wrap text-muted-foreground">{prettyJson(msg.toolOutput)}</pre>
|
|
165
|
-
</ExpandableBody>
|
|
166
|
-
)}
|
|
167
|
-
</div>
|
|
168
|
-
</AgentTurn>
|
|
169
|
-
) : null}
|
|
170
|
-
</div>
|
|
171
|
-
) : null}
|
|
172
|
-
</div>
|
|
173
|
-
</div>
|
|
174
|
-
</div>
|
|
175
|
-
);
|
|
176
|
-
}
|