devnonla-ui 0.17.2 → 0.18.1
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/avatar/AgentAvatar.tsx +16 -4
- package/src/avatar/AgentBody.tsx +458 -0
- package/src/avatar/avatar.css +552 -4
- 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/message-ui/ChatWelcome.tsx +1 -1
- 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/index.ts +2 -0
- package/src/markdown-editor/MarkdownTable.tsx +1 -1
- package/src/markdown-editor/MarkdownViewer.tsx +1 -1
- package/src/markdown-editor/MermaidBlock.tsx +12 -0
- package/src/sortable-tree/SortableTree.tsx +92 -45
- package/src/styles.css +14 -6
- package/src/chat/tool-ui/CallAgentToolUI.tsx +0 -176
|
@@ -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
|
-
}
|