@cerebriline/ui 0.0.0-stage → 4.100.313
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/ADOPTION.md +833 -0
- package/LICENSE +201 -0
- package/RADIX-COLORS-LICENSE +21 -0
- package/README.md +427 -2
- package/components/agent-approval-card.css +70 -0
- package/components/agent-approval-card.tsx +109 -0
- package/components/agent-ask-question.css +103 -0
- package/components/agent-ask-question.tsx +276 -0
- package/components/agent-aurora.css +228 -0
- package/components/agent-aurora.tsx +96 -0
- package/components/agent-changes.css +13 -0
- package/components/agent-changes.tsx +167 -0
- package/components/agent-chat/agent-chat.css +556 -0
- package/components/agent-chat/index.tsx +1037 -0
- package/components/agent-chat/tool-diff.tsx +165 -0
- package/components/agent-chat/tool-summary/agents.ts +114 -0
- package/components/agent-chat/tool-summary/diff.ts +152 -0
- package/components/agent-chat/tool-summary/index.ts +928 -0
- package/components/agent-chat/tool-summary/parsers.ts +611 -0
- package/components/agent-chat/tool-summary/paths.ts +84 -0
- package/components/agent-chat/tool-summary/team.ts +401 -0
- package/components/agent-command-output.tsx +63 -0
- package/components/agent-composer.tsx +263 -0
- package/components/agent-context-usage.tsx +181 -0
- package/components/agent-conversation-layout.tsx +139 -0
- package/components/agent-hero-heading.css +53 -0
- package/components/agent-hero-heading.tsx +45 -0
- package/components/agent-image-lightbox.tsx +48 -0
- package/components/agent-prompt-queue.css +20 -0
- package/components/agent-prompt-queue.tsx +350 -0
- package/components/agent-pull-request-bar.css +13 -0
- package/components/agent-pull-request-bar.tsx +346 -0
- package/components/agent-quick-actions.css +19 -0
- package/components/agent-quick-actions.tsx +70 -0
- package/components/agent-session-row.tsx +183 -0
- package/components/agent-welcome-hero-pointer.ts +199 -0
- package/components/agent-welcome-hero.css +205 -0
- package/components/agent-welcome-hero.tsx +68 -0
- package/components/attachment-drop-zone.tsx +154 -0
- package/components/badge.tsx +21 -0
- package/components/button.tsx +324 -0
- package/components/generated-media.tsx +173 -0
- package/components/github-icon.tsx +19 -0
- package/components/index.ts +133 -0
- package/components/markdown.css +490 -0
- package/components/markdown.ts +365 -0
- package/components/mermaid-block.tsx +722 -0
- package/components/mermaid-diagram.ts +1260 -0
- package/components/mermaid-dom.ts +301 -0
- package/components/message-scroller.css +118 -0
- package/components/message-scroller.tsx +114 -0
- package/components/search-combobox.css +67 -0
- package/components/search-combobox.tsx +433 -0
- package/components/session-status.css +19 -0
- package/components/session-status.tsx +39 -0
- package/components/switch.css +221 -0
- package/components/switch.tsx +48 -0
- package/components.css +16 -0
- package/dist/components/agent-approval-card.d.ts +14 -0
- package/dist/components/agent-approval-card.d.ts.map +1 -0
- package/dist/components/agent-approval-card.js +12 -0
- package/dist/components/agent-approval-card.js.map +1 -0
- package/dist/components/agent-ask-question.d.ts +18 -0
- package/dist/components/agent-ask-question.d.ts.map +1 -0
- package/dist/components/agent-ask-question.js +101 -0
- package/dist/components/agent-ask-question.js.map +1 -0
- package/dist/components/agent-aurora.d.ts +3 -0
- package/dist/components/agent-aurora.d.ts.map +1 -0
- package/dist/components/agent-aurora.js +60 -0
- package/dist/components/agent-aurora.js.map +1 -0
- package/dist/components/agent-changes.d.ts +26 -0
- package/dist/components/agent-changes.d.ts.map +1 -0
- package/dist/components/agent-changes.js +19 -0
- package/dist/components/agent-changes.js.map +1 -0
- package/dist/components/agent-chat/disclosure.d.ts +25 -0
- package/dist/components/agent-chat/disclosure.d.ts.map +1 -0
- package/dist/components/agent-chat/disclosure.js +39 -0
- package/dist/components/agent-chat/disclosure.js.map +1 -0
- package/dist/components/agent-chat/index.d.ts +140 -0
- package/dist/components/agent-chat/index.d.ts.map +1 -0
- package/dist/components/agent-chat/index.js +379 -0
- package/dist/components/agent-chat/index.js.map +1 -0
- package/dist/components/agent-chat/tool-diff.d.ts +32 -0
- package/dist/components/agent-chat/tool-diff.d.ts.map +1 -0
- package/dist/components/agent-chat/tool-diff.js +97 -0
- package/dist/components/agent-chat/tool-diff.js.map +1 -0
- package/dist/components/agent-chat/tool-summary/agents.d.ts +10 -0
- package/dist/components/agent-chat/tool-summary/agents.d.ts.map +1 -0
- package/dist/components/agent-chat/tool-summary/agents.js +100 -0
- package/dist/components/agent-chat/tool-summary/agents.js.map +1 -0
- package/dist/components/agent-chat/tool-summary/diff.d.ts +22 -0
- package/dist/components/agent-chat/tool-summary/diff.d.ts.map +1 -0
- package/dist/components/agent-chat/tool-summary/diff.js +127 -0
- package/dist/components/agent-chat/tool-summary/diff.js.map +1 -0
- package/dist/components/agent-chat/tool-summary/index.d.ts +145 -0
- package/dist/components/agent-chat/tool-summary/index.d.ts.map +1 -0
- package/dist/components/agent-chat/tool-summary/index.js +663 -0
- package/dist/components/agent-chat/tool-summary/index.js.map +1 -0
- package/dist/components/agent-chat/tool-summary/parsers.d.ts +114 -0
- package/dist/components/agent-chat/tool-summary/parsers.d.ts.map +1 -0
- package/dist/components/agent-chat/tool-summary/parsers.js +502 -0
- package/dist/components/agent-chat/tool-summary/parsers.js.map +1 -0
- package/dist/components/agent-chat/tool-summary/paths.d.ts +10 -0
- package/dist/components/agent-chat/tool-summary/paths.d.ts.map +1 -0
- package/dist/components/agent-chat/tool-summary/paths.js +88 -0
- package/dist/components/agent-chat/tool-summary/paths.js.map +1 -0
- package/dist/components/agent-chat/tool-summary/team.d.ts +16 -0
- package/dist/components/agent-chat/tool-summary/team.d.ts.map +1 -0
- package/dist/components/agent-chat/tool-summary/team.js +283 -0
- package/dist/components/agent-chat/tool-summary/team.js.map +1 -0
- package/dist/components/agent-command-output.d.ts +14 -0
- package/dist/components/agent-command-output.d.ts.map +1 -0
- package/dist/components/agent-command-output.js +22 -0
- package/dist/components/agent-command-output.js.map +1 -0
- package/dist/components/agent-composer.d.ts +34 -0
- package/dist/components/agent-composer.d.ts.map +1 -0
- package/dist/components/agent-composer.js +65 -0
- package/dist/components/agent-composer.js.map +1 -0
- package/dist/components/agent-context-usage.d.ts +28 -0
- package/dist/components/agent-context-usage.d.ts.map +1 -0
- package/dist/components/agent-context-usage.js +51 -0
- package/dist/components/agent-context-usage.js.map +1 -0
- package/dist/components/agent-conversation-layout.d.ts +30 -0
- package/dist/components/agent-conversation-layout.d.ts.map +1 -0
- package/dist/components/agent-conversation-layout.js +24 -0
- package/dist/components/agent-conversation-layout.js.map +1 -0
- package/dist/components/agent-hero-heading.d.ts +2 -0
- package/dist/components/agent-hero-heading.d.ts.map +1 -0
- package/dist/components/agent-hero-heading.js +20 -0
- package/dist/components/agent-hero-heading.js.map +1 -0
- package/dist/components/agent-image-lightbox.d.ts +11 -0
- package/dist/components/agent-image-lightbox.d.ts.map +1 -0
- package/dist/components/agent-image-lightbox.js +8 -0
- package/dist/components/agent-image-lightbox.js.map +1 -0
- package/dist/components/agent-prompt-queue.d.ts +14 -0
- package/dist/components/agent-prompt-queue.d.ts.map +1 -0
- package/dist/components/agent-prompt-queue.js +114 -0
- package/dist/components/agent-prompt-queue.js.map +1 -0
- package/dist/components/agent-pull-request-bar.d.ts +72 -0
- package/dist/components/agent-pull-request-bar.d.ts.map +1 -0
- package/dist/components/agent-pull-request-bar.js +90 -0
- package/dist/components/agent-pull-request-bar.js.map +1 -0
- package/dist/components/agent-quick-actions.d.ts +14 -0
- package/dist/components/agent-quick-actions.d.ts.map +1 -0
- package/dist/components/agent-quick-actions.js +12 -0
- package/dist/components/agent-quick-actions.js.map +1 -0
- package/dist/components/agent-session-row.d.ts +45 -0
- package/dist/components/agent-session-row.d.ts.map +1 -0
- package/dist/components/agent-session-row.js +34 -0
- package/dist/components/agent-session-row.js.map +1 -0
- package/dist/components/agent-welcome-hero-pointer.d.ts +3 -0
- package/dist/components/agent-welcome-hero-pointer.d.ts.map +1 -0
- package/dist/components/agent-welcome-hero-pointer.js +169 -0
- package/dist/components/agent-welcome-hero-pointer.js.map +1 -0
- package/dist/components/agent-welcome-hero.d.ts +9 -0
- package/dist/components/agent-welcome-hero.d.ts.map +1 -0
- package/dist/components/agent-welcome-hero.js +14 -0
- package/dist/components/agent-welcome-hero.js.map +1 -0
- package/dist/components/attachment-drop-zone.d.ts +15 -0
- package/dist/components/attachment-drop-zone.d.ts.map +1 -0
- package/dist/components/attachment-drop-zone.js +64 -0
- package/dist/components/attachment-drop-zone.js.map +1 -0
- package/dist/components/badge.d.ts +5 -0
- package/dist/components/badge.d.ts.map +1 -0
- package/dist/components/badge.js +7 -0
- package/dist/components/badge.js.map +1 -0
- package/dist/components/button.d.ts +27 -0
- package/dist/components/button.d.ts.map +1 -0
- package/dist/components/button.js +209 -0
- package/dist/components/button.js.map +1 -0
- package/dist/components/generated-media.d.ts +12 -0
- package/dist/components/generated-media.d.ts.map +1 -0
- package/dist/components/generated-media.js +105 -0
- package/dist/components/generated-media.js.map +1 -0
- package/dist/components/github-icon.d.ts +3 -0
- package/dist/components/github-icon.d.ts.map +1 -0
- package/dist/components/github-icon.js +6 -0
- package/dist/components/github-icon.js.map +1 -0
- package/dist/components/index.d.ts +24 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +25 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/markdown.d.ts +48 -0
- package/dist/components/markdown.d.ts.map +1 -0
- package/dist/components/markdown.js +264 -0
- package/dist/components/markdown.js.map +1 -0
- package/dist/components/mermaid-block.d.ts +14 -0
- package/dist/components/mermaid-block.d.ts.map +1 -0
- package/dist/components/mermaid-block.js +339 -0
- package/dist/components/mermaid-block.js.map +1 -0
- package/dist/components/mermaid-diagram.d.ts +264 -0
- package/dist/components/mermaid-diagram.d.ts.map +1 -0
- package/dist/components/mermaid-diagram.js +999 -0
- package/dist/components/mermaid-diagram.js.map +1 -0
- package/dist/components/mermaid-dom.d.ts +51 -0
- package/dist/components/mermaid-dom.d.ts.map +1 -0
- package/dist/components/mermaid-dom.js +246 -0
- package/dist/components/mermaid-dom.js.map +1 -0
- package/dist/components/message-scroller.d.ts +23 -0
- package/dist/components/message-scroller.d.ts.map +1 -0
- package/dist/components/message-scroller.js +31 -0
- package/dist/components/message-scroller.js.map +1 -0
- package/dist/components/search-combobox.d.ts +44 -0
- package/dist/components/search-combobox.d.ts.map +1 -0
- package/dist/components/search-combobox.js +191 -0
- package/dist/components/search-combobox.js.map +1 -0
- package/dist/components/session-status.d.ts +9 -0
- package/dist/components/session-status.d.ts.map +1 -0
- package/dist/components/session-status.js +11 -0
- package/dist/components/session-status.js.map +1 -0
- package/dist/components/switch.d.ts +7 -0
- package/dist/components/switch.d.ts.map +1 -0
- package/dist/components/switch.js +14 -0
- package/dist/components/switch.js.map +1 -0
- package/package.json +177 -5
- package/theme/base.css +83 -0
- package/theme/component-theme.css +126 -0
- package/theme/index.css +3 -0
- package/theme/palette.css +347 -0
- package/theme/scoped-tokens.css +503 -0
- package/theme/theme.css +90 -0
- package/theme/tokens.css +165 -0
|
@@ -0,0 +1,1037 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type ButtonHTMLAttributes,
|
|
5
|
+
createContext,
|
|
6
|
+
forwardRef,
|
|
7
|
+
type HTMLAttributes,
|
|
8
|
+
type MouseEvent as ReactMouseEvent,
|
|
9
|
+
type ReactNode,
|
|
10
|
+
type Ref,
|
|
11
|
+
type RefCallback,
|
|
12
|
+
useCallback,
|
|
13
|
+
useContext,
|
|
14
|
+
useEffect,
|
|
15
|
+
useLayoutEffect,
|
|
16
|
+
useMemo,
|
|
17
|
+
useRef,
|
|
18
|
+
useState,
|
|
19
|
+
} from "react";
|
|
20
|
+
import { IconButton } from "../button.js";
|
|
21
|
+
import {
|
|
22
|
+
DisclosureContent,
|
|
23
|
+
type DisclosureContentPresentation,
|
|
24
|
+
type DisclosureState,
|
|
25
|
+
useDisclosureState,
|
|
26
|
+
} from "./disclosure.js";
|
|
27
|
+
|
|
28
|
+
const STICK_TO_BOTTOM_THRESHOLD_PX = 24;
|
|
29
|
+
const SCROLL_BUTTON_THRESHOLD_PX = 120;
|
|
30
|
+
|
|
31
|
+
function classNames(...values: Array<string | undefined | false>): string {
|
|
32
|
+
return values.filter(Boolean).join(" ");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function assignRef<T>(ref: Ref<T> | undefined, value: T | null): void {
|
|
36
|
+
if (typeof ref === "function") {
|
|
37
|
+
ref(value);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (ref) {
|
|
41
|
+
ref.current = value;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type ConversationContextValue = {
|
|
46
|
+
setContent: (element: HTMLDivElement | null) => void;
|
|
47
|
+
setViewport: (element: HTMLDivElement | null) => void;
|
|
48
|
+
showScrollButton: boolean;
|
|
49
|
+
scrollToBottom: (behavior?: ScrollBehavior) => void;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const ConversationContext = createContext<ConversationContextValue | null>(
|
|
53
|
+
null,
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Access the surrounding Conversation's scroll controls — e.g. to force a
|
|
58
|
+
* scroll to the latest message when the user submits, regardless of where
|
|
59
|
+
* they had scrolled. Must be called under a `Conversation`.
|
|
60
|
+
*/
|
|
61
|
+
export function useConversation(): ConversationContextValue {
|
|
62
|
+
const context = useContext(ConversationContext);
|
|
63
|
+
if (!context) {
|
|
64
|
+
throw new Error(
|
|
65
|
+
"Conversation components must be rendered inside Conversation",
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
return context;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type ConversationProps = HTMLAttributes<HTMLDivElement>;
|
|
72
|
+
|
|
73
|
+
export const Conversation = forwardRef<HTMLDivElement, ConversationProps>(
|
|
74
|
+
({ children, className, ...props }, ref) => {
|
|
75
|
+
const [viewport, setViewport] = useState<HTMLDivElement | null>(null);
|
|
76
|
+
const [content, setContent] = useState<HTMLDivElement | null>(null);
|
|
77
|
+
const [showScrollButton, setShowScrollButton] = useState(false);
|
|
78
|
+
const shouldStickToBottom = useRef(true);
|
|
79
|
+
const isProgrammaticScroll = useRef(false);
|
|
80
|
+
const lastProgrammaticScrollTop = useRef(0);
|
|
81
|
+
const lastObservedScrollTop = useRef(0);
|
|
82
|
+
const programmaticScrollTimer = useRef<number | null>(null);
|
|
83
|
+
|
|
84
|
+
const clearProgrammaticScroll = useCallback(() => {
|
|
85
|
+
if (programmaticScrollTimer.current !== null) {
|
|
86
|
+
window.clearTimeout(programmaticScrollTimer.current);
|
|
87
|
+
programmaticScrollTimer.current = null;
|
|
88
|
+
}
|
|
89
|
+
}, []);
|
|
90
|
+
|
|
91
|
+
const updateScrollPosition = useCallback(() => {
|
|
92
|
+
if (!viewport) return;
|
|
93
|
+
const distance =
|
|
94
|
+
viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight;
|
|
95
|
+
const scrolledUp = viewport.scrollTop < lastObservedScrollTop.current - 1;
|
|
96
|
+
lastObservedScrollTop.current = viewport.scrollTop;
|
|
97
|
+
if (isProgrammaticScroll.current) {
|
|
98
|
+
if (viewport.scrollTop + 1 < lastProgrammaticScrollTop.current) {
|
|
99
|
+
isProgrammaticScroll.current = false;
|
|
100
|
+
clearProgrammaticScroll();
|
|
101
|
+
} else {
|
|
102
|
+
lastProgrammaticScrollTop.current = viewport.scrollTop;
|
|
103
|
+
shouldStickToBottom.current = true;
|
|
104
|
+
setShowScrollButton(false);
|
|
105
|
+
if (distance <= STICK_TO_BOTTOM_THRESHOLD_PX) {
|
|
106
|
+
isProgrammaticScroll.current = false;
|
|
107
|
+
clearProgrammaticScroll();
|
|
108
|
+
}
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Sticking is an intent, not a position: content growing under a
|
|
113
|
+
// pinned viewport briefly widens `distance` before the resize
|
|
114
|
+
// observer re-pins, and a scroll event landing in that window must
|
|
115
|
+
// not read as the user leaving the bottom. Only an actual upward
|
|
116
|
+
// scroll releases the pin; reaching the bottom always restores it.
|
|
117
|
+
if (distance <= STICK_TO_BOTTOM_THRESHOLD_PX) {
|
|
118
|
+
shouldStickToBottom.current = true;
|
|
119
|
+
} else if (scrolledUp) {
|
|
120
|
+
shouldStickToBottom.current = false;
|
|
121
|
+
}
|
|
122
|
+
setShowScrollButton(distance > SCROLL_BUTTON_THRESHOLD_PX);
|
|
123
|
+
}, [clearProgrammaticScroll, viewport]);
|
|
124
|
+
|
|
125
|
+
const scrollToBottom = useCallback(
|
|
126
|
+
(behavior: ScrollBehavior = "smooth") => {
|
|
127
|
+
if (!viewport) return;
|
|
128
|
+
clearProgrammaticScroll();
|
|
129
|
+
const prefersReducedMotion =
|
|
130
|
+
behavior === "smooth" &&
|
|
131
|
+
typeof window.matchMedia === "function" &&
|
|
132
|
+
window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
133
|
+
const effectiveBehavior = prefersReducedMotion ? "auto" : behavior;
|
|
134
|
+
const isSmooth = effectiveBehavior === "smooth";
|
|
135
|
+
isProgrammaticScroll.current = isSmooth;
|
|
136
|
+
lastProgrammaticScrollTop.current = viewport.scrollTop;
|
|
137
|
+
shouldStickToBottom.current = true;
|
|
138
|
+
viewport.scrollTo({
|
|
139
|
+
top: viewport.scrollHeight,
|
|
140
|
+
behavior: effectiveBehavior,
|
|
141
|
+
});
|
|
142
|
+
lastObservedScrollTop.current = viewport.scrollTop;
|
|
143
|
+
setShowScrollButton(false);
|
|
144
|
+
if (!isSmooth) return;
|
|
145
|
+
programmaticScrollTimer.current = window.setTimeout(() => {
|
|
146
|
+
isProgrammaticScroll.current = false;
|
|
147
|
+
programmaticScrollTimer.current = null;
|
|
148
|
+
updateScrollPosition();
|
|
149
|
+
}, 1500);
|
|
150
|
+
},
|
|
151
|
+
[clearProgrammaticScroll, updateScrollPosition, viewport],
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
if (!viewport) return;
|
|
156
|
+
updateScrollPosition();
|
|
157
|
+
viewport.addEventListener("scroll", updateScrollPosition);
|
|
158
|
+
const cancelProgrammaticScroll = () => {
|
|
159
|
+
if (!isProgrammaticScroll.current) return;
|
|
160
|
+
isProgrammaticScroll.current = false;
|
|
161
|
+
clearProgrammaticScroll();
|
|
162
|
+
updateScrollPosition();
|
|
163
|
+
};
|
|
164
|
+
viewport.addEventListener("touchstart", cancelProgrammaticScroll, {
|
|
165
|
+
passive: true,
|
|
166
|
+
});
|
|
167
|
+
viewport.addEventListener("pointerdown", cancelProgrammaticScroll, {
|
|
168
|
+
passive: true,
|
|
169
|
+
});
|
|
170
|
+
const cancelProgrammaticScrollOnKeydown = (event: KeyboardEvent) => {
|
|
171
|
+
if (
|
|
172
|
+
[
|
|
173
|
+
"ArrowDown",
|
|
174
|
+
"ArrowUp",
|
|
175
|
+
"End",
|
|
176
|
+
"Home",
|
|
177
|
+
"PageDown",
|
|
178
|
+
"PageUp",
|
|
179
|
+
" ",
|
|
180
|
+
].includes(event.key)
|
|
181
|
+
) {
|
|
182
|
+
cancelProgrammaticScroll();
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
viewport.addEventListener("keydown", cancelProgrammaticScrollOnKeydown);
|
|
186
|
+
viewport.addEventListener("wheel", cancelProgrammaticScroll, {
|
|
187
|
+
passive: true,
|
|
188
|
+
});
|
|
189
|
+
return () => {
|
|
190
|
+
viewport.removeEventListener("scroll", updateScrollPosition);
|
|
191
|
+
viewport.removeEventListener("touchstart", cancelProgrammaticScroll);
|
|
192
|
+
viewport.removeEventListener("pointerdown", cancelProgrammaticScroll);
|
|
193
|
+
viewport.removeEventListener(
|
|
194
|
+
"keydown",
|
|
195
|
+
cancelProgrammaticScrollOnKeydown,
|
|
196
|
+
);
|
|
197
|
+
viewport.removeEventListener("wheel", cancelProgrammaticScroll);
|
|
198
|
+
};
|
|
199
|
+
}, [clearProgrammaticScroll, updateScrollPosition, viewport]);
|
|
200
|
+
|
|
201
|
+
useEffect(() => () => clearProgrammaticScroll(), [clearProgrammaticScroll]);
|
|
202
|
+
|
|
203
|
+
useLayoutEffect(() => {
|
|
204
|
+
if (!viewport || !content) return;
|
|
205
|
+
scrollToBottom("auto");
|
|
206
|
+
}, [content, scrollToBottom, viewport]);
|
|
207
|
+
|
|
208
|
+
useEffect(() => {
|
|
209
|
+
if (!content || !viewport || typeof ResizeObserver === "undefined")
|
|
210
|
+
return;
|
|
211
|
+
const observer = new ResizeObserver(() => {
|
|
212
|
+
if (shouldStickToBottom.current) {
|
|
213
|
+
scrollToBottom("auto");
|
|
214
|
+
} else {
|
|
215
|
+
updateScrollPosition();
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
observer.observe(content);
|
|
219
|
+
observer.observe(viewport);
|
|
220
|
+
return () => observer.disconnect();
|
|
221
|
+
}, [content, scrollToBottom, updateScrollPosition, viewport]);
|
|
222
|
+
|
|
223
|
+
const value = useMemo<ConversationContextValue>(
|
|
224
|
+
() => ({
|
|
225
|
+
scrollToBottom,
|
|
226
|
+
setContent,
|
|
227
|
+
setViewport,
|
|
228
|
+
showScrollButton,
|
|
229
|
+
}),
|
|
230
|
+
[scrollToBottom, showScrollButton],
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
return (
|
|
234
|
+
<ConversationContext.Provider value={value}>
|
|
235
|
+
<div
|
|
236
|
+
className={classNames("cline-chat-conversation", className)}
|
|
237
|
+
ref={ref}
|
|
238
|
+
{...props}
|
|
239
|
+
>
|
|
240
|
+
{children}
|
|
241
|
+
</div>
|
|
242
|
+
</ConversationContext.Provider>
|
|
243
|
+
);
|
|
244
|
+
},
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
Conversation.displayName = "Conversation";
|
|
248
|
+
|
|
249
|
+
export type ConversationViewportProps = Omit<
|
|
250
|
+
HTMLAttributes<HTMLDivElement>,
|
|
251
|
+
"role"
|
|
252
|
+
>;
|
|
253
|
+
|
|
254
|
+
export const ConversationViewport = forwardRef<
|
|
255
|
+
HTMLDivElement,
|
|
256
|
+
ConversationViewportProps
|
|
257
|
+
>(
|
|
258
|
+
(
|
|
259
|
+
{
|
|
260
|
+
"aria-label": ariaLabel = "Agent conversation",
|
|
261
|
+
"aria-live": ariaLive = "polite",
|
|
262
|
+
className,
|
|
263
|
+
tabIndex = 0,
|
|
264
|
+
...props
|
|
265
|
+
},
|
|
266
|
+
forwardedRef,
|
|
267
|
+
) => {
|
|
268
|
+
const { setViewport } = useConversation();
|
|
269
|
+
const ref = useCallback<RefCallback<HTMLDivElement>>(
|
|
270
|
+
(element) => {
|
|
271
|
+
setViewport(element);
|
|
272
|
+
assignRef(forwardedRef, element);
|
|
273
|
+
},
|
|
274
|
+
[forwardedRef, setViewport],
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
return (
|
|
278
|
+
<div
|
|
279
|
+
{...props}
|
|
280
|
+
aria-label={ariaLabel}
|
|
281
|
+
aria-live={ariaLive}
|
|
282
|
+
className={classNames("cline-chat-conversation-viewport", className)}
|
|
283
|
+
ref={ref}
|
|
284
|
+
role="log"
|
|
285
|
+
tabIndex={tabIndex}
|
|
286
|
+
/>
|
|
287
|
+
);
|
|
288
|
+
},
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
ConversationViewport.displayName = "ConversationViewport";
|
|
292
|
+
|
|
293
|
+
export type ConversationContentProps = HTMLAttributes<HTMLDivElement>;
|
|
294
|
+
|
|
295
|
+
export const ConversationContent = forwardRef<
|
|
296
|
+
HTMLDivElement,
|
|
297
|
+
ConversationContentProps
|
|
298
|
+
>(({ className, ...props }, forwardedRef) => {
|
|
299
|
+
const { setContent } = useConversation();
|
|
300
|
+
const ref = useCallback<RefCallback<HTMLDivElement>>(
|
|
301
|
+
(element) => {
|
|
302
|
+
setContent(element);
|
|
303
|
+
assignRef(forwardedRef, element);
|
|
304
|
+
},
|
|
305
|
+
[forwardedRef, setContent],
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
return (
|
|
309
|
+
<div
|
|
310
|
+
className={classNames("cline-chat-conversation-content", className)}
|
|
311
|
+
ref={ref}
|
|
312
|
+
{...props}
|
|
313
|
+
/>
|
|
314
|
+
);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
ConversationContent.displayName = "ConversationContent";
|
|
318
|
+
|
|
319
|
+
export type ConversationEmptyStateProps = HTMLAttributes<HTMLDivElement> & {
|
|
320
|
+
title?: string;
|
|
321
|
+
description?: string;
|
|
322
|
+
icon?: ReactNode;
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
export const ConversationEmptyState = ({
|
|
326
|
+
children,
|
|
327
|
+
className,
|
|
328
|
+
description = "Start a conversation to see messages here.",
|
|
329
|
+
icon,
|
|
330
|
+
title = "No messages yet",
|
|
331
|
+
...props
|
|
332
|
+
}: ConversationEmptyStateProps) => (
|
|
333
|
+
<div className={classNames("cline-chat-empty-state", className)} {...props}>
|
|
334
|
+
{children ?? (
|
|
335
|
+
<>
|
|
336
|
+
{icon ? (
|
|
337
|
+
<div className="cline-chat-empty-state-icon">{icon}</div>
|
|
338
|
+
) : null}
|
|
339
|
+
<div>
|
|
340
|
+
<h3>{title}</h3>
|
|
341
|
+
{description ? <p>{description}</p> : null}
|
|
342
|
+
</div>
|
|
343
|
+
</>
|
|
344
|
+
)}
|
|
345
|
+
</div>
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
export type ConversationScrollButtonProps = Omit<
|
|
349
|
+
ButtonHTMLAttributes<HTMLButtonElement>,
|
|
350
|
+
"type"
|
|
351
|
+
>;
|
|
352
|
+
|
|
353
|
+
export const ConversationScrollButton = ({
|
|
354
|
+
"aria-label": ariaLabel = "Scroll to latest message",
|
|
355
|
+
children,
|
|
356
|
+
className,
|
|
357
|
+
onClick,
|
|
358
|
+
...props
|
|
359
|
+
}: ConversationScrollButtonProps) => {
|
|
360
|
+
const { scrollToBottom, showScrollButton } = useConversation();
|
|
361
|
+
if (!showScrollButton) return null;
|
|
362
|
+
|
|
363
|
+
return (
|
|
364
|
+
<button
|
|
365
|
+
{...props}
|
|
366
|
+
aria-label={ariaLabel}
|
|
367
|
+
className={classNames("cline-chat-scroll-button", className)}
|
|
368
|
+
onClick={(event) => {
|
|
369
|
+
onClick?.(event);
|
|
370
|
+
if (!event.defaultPrevented) scrollToBottom();
|
|
371
|
+
}}
|
|
372
|
+
type="button"
|
|
373
|
+
>
|
|
374
|
+
{children ?? <ChevronDownIcon />}
|
|
375
|
+
</button>
|
|
376
|
+
);
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
export type AgentMessageRole =
|
|
380
|
+
| "user"
|
|
381
|
+
| "assistant"
|
|
382
|
+
| "system"
|
|
383
|
+
| "status"
|
|
384
|
+
| "error";
|
|
385
|
+
|
|
386
|
+
export type MessageProps = HTMLAttributes<HTMLDivElement> & {
|
|
387
|
+
from: AgentMessageRole;
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
export const Message = ({ className, from, ...props }: MessageProps) => (
|
|
391
|
+
<div
|
|
392
|
+
{...props}
|
|
393
|
+
className={classNames("cline-chat-message", className)}
|
|
394
|
+
data-role={from}
|
|
395
|
+
/>
|
|
396
|
+
);
|
|
397
|
+
|
|
398
|
+
export type MessageContentProps = HTMLAttributes<HTMLDivElement>;
|
|
399
|
+
|
|
400
|
+
export const MessageContent = ({
|
|
401
|
+
className,
|
|
402
|
+
...props
|
|
403
|
+
}: MessageContentProps) => (
|
|
404
|
+
<div
|
|
405
|
+
className={classNames("cline-chat-message-content", className)}
|
|
406
|
+
{...props}
|
|
407
|
+
/>
|
|
408
|
+
);
|
|
409
|
+
|
|
410
|
+
export type MessageActionsProps = HTMLAttributes<HTMLDivElement> & {
|
|
411
|
+
side?: "start" | "end";
|
|
412
|
+
visible?: boolean;
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
export const MessageActions = ({
|
|
416
|
+
className,
|
|
417
|
+
side,
|
|
418
|
+
visible = false,
|
|
419
|
+
...props
|
|
420
|
+
}: MessageActionsProps) => (
|
|
421
|
+
<div
|
|
422
|
+
{...props}
|
|
423
|
+
className={classNames("cline-chat-message-actions", className)}
|
|
424
|
+
data-side={side}
|
|
425
|
+
data-visible={visible || undefined}
|
|
426
|
+
/>
|
|
427
|
+
);
|
|
428
|
+
|
|
429
|
+
export type MessageActionProps = Omit<
|
|
430
|
+
ButtonHTMLAttributes<HTMLButtonElement>,
|
|
431
|
+
"type"
|
|
432
|
+
> & {
|
|
433
|
+
label: string;
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
export const MessageAction = ({
|
|
437
|
+
"aria-label": ariaLabel,
|
|
438
|
+
className,
|
|
439
|
+
label,
|
|
440
|
+
...props
|
|
441
|
+
}: MessageActionProps) => (
|
|
442
|
+
<IconButton
|
|
443
|
+
{...props}
|
|
444
|
+
aria-label={ariaLabel ?? label}
|
|
445
|
+
className={classNames("cline-chat-message-action", className)}
|
|
446
|
+
variant="ghost"
|
|
447
|
+
tone="neutral"
|
|
448
|
+
size="xs"
|
|
449
|
+
/>
|
|
450
|
+
);
|
|
451
|
+
|
|
452
|
+
type ReasoningContextValue = DisclosureState & {
|
|
453
|
+
isStreaming: boolean;
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
const ReasoningContext = createContext<ReasoningContextValue | null>(null);
|
|
457
|
+
|
|
458
|
+
function useReasoning(): ReasoningContextValue {
|
|
459
|
+
const context = useContext(ReasoningContext);
|
|
460
|
+
if (!context) {
|
|
461
|
+
throw new Error("Reasoning components must be rendered inside Reasoning");
|
|
462
|
+
}
|
|
463
|
+
return context;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export type ReasoningProps = Omit<
|
|
467
|
+
HTMLAttributes<HTMLDivElement>,
|
|
468
|
+
"onChange"
|
|
469
|
+
> & {
|
|
470
|
+
isStreaming?: boolean;
|
|
471
|
+
open?: boolean;
|
|
472
|
+
defaultOpen?: boolean;
|
|
473
|
+
onOpenChange?: (open: boolean) => void;
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
export const Reasoning = ({
|
|
477
|
+
className,
|
|
478
|
+
defaultOpen = false,
|
|
479
|
+
isStreaming = false,
|
|
480
|
+
onOpenChange,
|
|
481
|
+
open,
|
|
482
|
+
...props
|
|
483
|
+
}: ReasoningProps) => {
|
|
484
|
+
const { isOpen, panelId, setIsOpen } = useDisclosureState({
|
|
485
|
+
defaultOpen,
|
|
486
|
+
onOpenChange,
|
|
487
|
+
open,
|
|
488
|
+
});
|
|
489
|
+
const value = useMemo(
|
|
490
|
+
() => ({ isOpen, isStreaming, panelId, setIsOpen }),
|
|
491
|
+
[isOpen, isStreaming, panelId, setIsOpen],
|
|
492
|
+
);
|
|
493
|
+
|
|
494
|
+
return (
|
|
495
|
+
<ReasoningContext.Provider value={value}>
|
|
496
|
+
<div
|
|
497
|
+
{...props}
|
|
498
|
+
className={classNames("cline-chat-reasoning", className)}
|
|
499
|
+
data-streaming={isStreaming || undefined}
|
|
500
|
+
/>
|
|
501
|
+
</ReasoningContext.Provider>
|
|
502
|
+
);
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
export type ReasoningTriggerProps = Omit<
|
|
506
|
+
ButtonHTMLAttributes<HTMLButtonElement>,
|
|
507
|
+
"aria-controls" | "aria-expanded" | "type"
|
|
508
|
+
> & {
|
|
509
|
+
completeLabel?: string;
|
|
510
|
+
streamingLabel?: string;
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
export const ReasoningTrigger = ({
|
|
514
|
+
children,
|
|
515
|
+
className,
|
|
516
|
+
completeLabel = "Thinking",
|
|
517
|
+
onClick,
|
|
518
|
+
streamingLabel = "Thinking",
|
|
519
|
+
...props
|
|
520
|
+
}: ReasoningTriggerProps) => {
|
|
521
|
+
const { isOpen, isStreaming, panelId, setIsOpen } = useReasoning();
|
|
522
|
+
return (
|
|
523
|
+
<button
|
|
524
|
+
{...props}
|
|
525
|
+
aria-controls={panelId}
|
|
526
|
+
aria-expanded={isOpen}
|
|
527
|
+
className={classNames("cline-chat-reasoning-trigger", className)}
|
|
528
|
+
onClick={(event) => {
|
|
529
|
+
onClick?.(event);
|
|
530
|
+
if (!event.defaultPrevented) setIsOpen(!isOpen);
|
|
531
|
+
}}
|
|
532
|
+
type="button"
|
|
533
|
+
>
|
|
534
|
+
{children ?? (
|
|
535
|
+
<>
|
|
536
|
+
<span>{isStreaming ? streamingLabel : completeLabel}</span>
|
|
537
|
+
<ChevronDownIcon className="cline-chat-disclosure-icon" />
|
|
538
|
+
</>
|
|
539
|
+
)}
|
|
540
|
+
</button>
|
|
541
|
+
);
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
export type ReasoningContentProps = Omit<
|
|
545
|
+
HTMLAttributes<HTMLDivElement>,
|
|
546
|
+
"hidden" | "id"
|
|
547
|
+
> & {
|
|
548
|
+
presentation?: DisclosureContentPresentation;
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
export const ReasoningContent = ({
|
|
552
|
+
presentation,
|
|
553
|
+
...props
|
|
554
|
+
}: ReasoningContentProps) => {
|
|
555
|
+
const { isOpen, panelId } = useReasoning();
|
|
556
|
+
return (
|
|
557
|
+
<DisclosureContent
|
|
558
|
+
{...props}
|
|
559
|
+
contentClassName="cline-chat-reasoning-content"
|
|
560
|
+
isOpen={isOpen}
|
|
561
|
+
lazyContent
|
|
562
|
+
panelId={panelId}
|
|
563
|
+
presentation={presentation}
|
|
564
|
+
/>
|
|
565
|
+
);
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
/** "Thinking" while the duration is unknown, "Thought for Ns" once it is. */
|
|
569
|
+
export function formatThoughtLabel(durationMilliseconds?: number): string {
|
|
570
|
+
if (durationMilliseconds === undefined) {
|
|
571
|
+
return "Thinking";
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
const seconds =
|
|
575
|
+
durationMilliseconds === 0
|
|
576
|
+
? 0
|
|
577
|
+
: Math.max(1, Math.round(durationMilliseconds / 1000));
|
|
578
|
+
|
|
579
|
+
return `Thought for ${seconds}s`;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
export type ThinkingBlockProps = Omit<
|
|
583
|
+
HTMLAttributes<HTMLDivElement>,
|
|
584
|
+
"children" | "onChange"
|
|
585
|
+
> & {
|
|
586
|
+
durationMilliseconds?: number;
|
|
587
|
+
isStreaming?: boolean;
|
|
588
|
+
redacted?: boolean;
|
|
589
|
+
/** Overrides the derived "Thinking" / "Thought for Ns" label. */
|
|
590
|
+
label?: string;
|
|
591
|
+
open?: boolean;
|
|
592
|
+
defaultOpen?: boolean;
|
|
593
|
+
onOpenChange?: (open: boolean) => void;
|
|
594
|
+
/** Rendered reasoning body — typically the product's Markdown output. */
|
|
595
|
+
children?: ReactNode;
|
|
596
|
+
};
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* The standard thinking-trace row: brain icon, "Thinking"/"Thought for Ns"
|
|
600
|
+
* label (shimmering while streaming), and the reasoning body under the shared
|
|
601
|
+
* disclosure rail, capped to a scrollable height. Products supply the rendered
|
|
602
|
+
* body as children so they keep their own Markdown policy.
|
|
603
|
+
*/
|
|
604
|
+
export const ThinkingBlock = ({
|
|
605
|
+
children,
|
|
606
|
+
className,
|
|
607
|
+
defaultOpen,
|
|
608
|
+
durationMilliseconds,
|
|
609
|
+
isStreaming = false,
|
|
610
|
+
label,
|
|
611
|
+
onOpenChange,
|
|
612
|
+
open,
|
|
613
|
+
redacted = false,
|
|
614
|
+
...props
|
|
615
|
+
}: ThinkingBlockProps) => {
|
|
616
|
+
const resolvedLabel =
|
|
617
|
+
label ??
|
|
618
|
+
(isStreaming ? "Thinking" : formatThoughtLabel(durationMilliseconds));
|
|
619
|
+
return (
|
|
620
|
+
<Reasoning
|
|
621
|
+
{...props}
|
|
622
|
+
className={className}
|
|
623
|
+
defaultOpen={defaultOpen}
|
|
624
|
+
isStreaming={isStreaming}
|
|
625
|
+
onOpenChange={onOpenChange}
|
|
626
|
+
open={open}
|
|
627
|
+
>
|
|
628
|
+
<ReasoningTrigger aria-label={resolvedLabel}>
|
|
629
|
+
<BrainIcon className="cline-chat-thinking-icon" />
|
|
630
|
+
<span
|
|
631
|
+
className={isStreaming ? "cline-chat-streaming-title" : undefined}
|
|
632
|
+
>
|
|
633
|
+
{resolvedLabel}
|
|
634
|
+
</span>
|
|
635
|
+
</ReasoningTrigger>
|
|
636
|
+
<ReasoningContent
|
|
637
|
+
className="cline-chat-thinking-content"
|
|
638
|
+
presentation="rail"
|
|
639
|
+
>
|
|
640
|
+
{children ?? (redacted ? "[redacted]" : null)}
|
|
641
|
+
</ReasoningContent>
|
|
642
|
+
</Reasoning>
|
|
643
|
+
);
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
export type ToolActivityStatus = "pending" | "running" | "success" | "error";
|
|
647
|
+
|
|
648
|
+
type ToolActivityContextValue = DisclosureState & {
|
|
649
|
+
expandable: boolean;
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
const ToolActivityContext = createContext<ToolActivityContextValue | null>(
|
|
653
|
+
null,
|
|
654
|
+
);
|
|
655
|
+
|
|
656
|
+
function useToolActivity(): ToolActivityContextValue {
|
|
657
|
+
const context = useContext(ToolActivityContext);
|
|
658
|
+
if (!context) {
|
|
659
|
+
throw new Error(
|
|
660
|
+
"ToolActivity components must be rendered inside ToolActivity",
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
return context;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
export type ToolActivityProps = Omit<
|
|
667
|
+
HTMLAttributes<HTMLDivElement>,
|
|
668
|
+
"onChange"
|
|
669
|
+
> & {
|
|
670
|
+
expandable?: boolean;
|
|
671
|
+
open?: boolean;
|
|
672
|
+
defaultOpen?: boolean;
|
|
673
|
+
onOpenChange?: (open: boolean) => void;
|
|
674
|
+
};
|
|
675
|
+
|
|
676
|
+
export const ToolActivity = ({
|
|
677
|
+
className,
|
|
678
|
+
defaultOpen = false,
|
|
679
|
+
expandable = true,
|
|
680
|
+
onOpenChange,
|
|
681
|
+
open,
|
|
682
|
+
...props
|
|
683
|
+
}: ToolActivityProps) => {
|
|
684
|
+
const { isOpen, panelId, setIsOpen } = useDisclosureState({
|
|
685
|
+
defaultOpen,
|
|
686
|
+
enabled: expandable,
|
|
687
|
+
onOpenChange,
|
|
688
|
+
open,
|
|
689
|
+
});
|
|
690
|
+
const value = useMemo(
|
|
691
|
+
() => ({ expandable, isOpen, panelId, setIsOpen }),
|
|
692
|
+
[expandable, isOpen, panelId, setIsOpen],
|
|
693
|
+
);
|
|
694
|
+
|
|
695
|
+
return (
|
|
696
|
+
<ToolActivityContext.Provider value={value}>
|
|
697
|
+
<div
|
|
698
|
+
{...props}
|
|
699
|
+
className={classNames("cline-chat-tool", className)}
|
|
700
|
+
data-expandable={expandable || undefined}
|
|
701
|
+
/>
|
|
702
|
+
</ToolActivityContext.Provider>
|
|
703
|
+
);
|
|
704
|
+
};
|
|
705
|
+
|
|
706
|
+
export type ToolActivityTriggerProps = Omit<
|
|
707
|
+
HTMLAttributes<HTMLElement>,
|
|
708
|
+
"aria-controls" | "aria-expanded"
|
|
709
|
+
> & {
|
|
710
|
+
icon?: ReactNode;
|
|
711
|
+
label: ReactNode;
|
|
712
|
+
status?: ToolActivityStatus;
|
|
713
|
+
additions?: number;
|
|
714
|
+
deletions?: number;
|
|
715
|
+
disabled?: boolean;
|
|
716
|
+
/** Show the chevron that hints the row expands. The row stays clickable when hidden. */
|
|
717
|
+
showDisclosureIcon?: boolean;
|
|
718
|
+
};
|
|
719
|
+
|
|
720
|
+
export const ToolActivityTrigger = ({
|
|
721
|
+
additions,
|
|
722
|
+
children,
|
|
723
|
+
className,
|
|
724
|
+
deletions,
|
|
725
|
+
disabled = false,
|
|
726
|
+
icon,
|
|
727
|
+
label,
|
|
728
|
+
onClick,
|
|
729
|
+
showDisclosureIcon = true,
|
|
730
|
+
status = "success",
|
|
731
|
+
...props
|
|
732
|
+
}: ToolActivityTriggerProps) => {
|
|
733
|
+
const { expandable, isOpen, panelId, setIsOpen } = useToolActivity();
|
|
734
|
+
// While the tool is still working, the spinner takes the icon's slot so the
|
|
735
|
+
// row reads as one glyph + label instead of sprouting chrome on the right.
|
|
736
|
+
const inFlight = status === "running" || status === "pending";
|
|
737
|
+
const content = children ?? (
|
|
738
|
+
<>
|
|
739
|
+
{inFlight ? (
|
|
740
|
+
<output aria-label={status} className="cline-chat-tool-progress" />
|
|
741
|
+
) : icon ? (
|
|
742
|
+
<span className="cline-chat-tool-icon">{icon}</span>
|
|
743
|
+
) : null}
|
|
744
|
+
<span className="cline-chat-tool-label">{label}</span>
|
|
745
|
+
{additions !== undefined || deletions !== undefined ? (
|
|
746
|
+
<span className="cline-chat-tool-diff">
|
|
747
|
+
{additions !== undefined ? (
|
|
748
|
+
<span data-diff="additions">+{additions}</span>
|
|
749
|
+
) : null}{" "}
|
|
750
|
+
{deletions !== undefined ? (
|
|
751
|
+
<span data-diff="deletions">-{deletions}</span>
|
|
752
|
+
) : null}
|
|
753
|
+
</span>
|
|
754
|
+
) : null}
|
|
755
|
+
{expandable && showDisclosureIcon ? (
|
|
756
|
+
<ChevronDownIcon className="cline-chat-disclosure-icon" />
|
|
757
|
+
) : null}
|
|
758
|
+
</>
|
|
759
|
+
);
|
|
760
|
+
const handleClick = (event: ReactMouseEvent<HTMLElement>) => {
|
|
761
|
+
onClick?.(event);
|
|
762
|
+
if (expandable && !event.defaultPrevented) setIsOpen(!isOpen);
|
|
763
|
+
};
|
|
764
|
+
const triggerClassName = classNames("cline-chat-tool-trigger", className);
|
|
765
|
+
|
|
766
|
+
if (expandable) {
|
|
767
|
+
return (
|
|
768
|
+
<button
|
|
769
|
+
{...(props as ButtonHTMLAttributes<HTMLButtonElement>)}
|
|
770
|
+
aria-controls={panelId}
|
|
771
|
+
aria-expanded={isOpen}
|
|
772
|
+
className={triggerClassName}
|
|
773
|
+
data-status={status}
|
|
774
|
+
disabled={disabled}
|
|
775
|
+
onClick={handleClick}
|
|
776
|
+
type="button"
|
|
777
|
+
>
|
|
778
|
+
{content}
|
|
779
|
+
</button>
|
|
780
|
+
);
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
return (
|
|
784
|
+
<div
|
|
785
|
+
{...(props as HTMLAttributes<HTMLDivElement>)}
|
|
786
|
+
className={triggerClassName}
|
|
787
|
+
data-status={status}
|
|
788
|
+
>
|
|
789
|
+
{content}
|
|
790
|
+
</div>
|
|
791
|
+
);
|
|
792
|
+
};
|
|
793
|
+
|
|
794
|
+
export type ToolActivityContentProps = Omit<
|
|
795
|
+
HTMLAttributes<HTMLDivElement>,
|
|
796
|
+
"hidden" | "id"
|
|
797
|
+
> & {
|
|
798
|
+
presentation?: DisclosureContentPresentation;
|
|
799
|
+
};
|
|
800
|
+
|
|
801
|
+
export const ToolActivityContent = ({
|
|
802
|
+
presentation,
|
|
803
|
+
...props
|
|
804
|
+
}: ToolActivityContentProps) => {
|
|
805
|
+
const { expandable, isOpen, panelId } = useToolActivity();
|
|
806
|
+
if (!expandable) return null;
|
|
807
|
+
return (
|
|
808
|
+
<DisclosureContent
|
|
809
|
+
{...props}
|
|
810
|
+
contentClassName="cline-chat-tool-content"
|
|
811
|
+
isOpen={isOpen}
|
|
812
|
+
lazyContent
|
|
813
|
+
panelId={panelId}
|
|
814
|
+
presentation={presentation}
|
|
815
|
+
/>
|
|
816
|
+
);
|
|
817
|
+
};
|
|
818
|
+
|
|
819
|
+
const WorkActivityContext = createContext<DisclosureState | null>(null);
|
|
820
|
+
|
|
821
|
+
function useWorkActivity(): DisclosureState {
|
|
822
|
+
const context = useContext(WorkActivityContext);
|
|
823
|
+
if (!context) {
|
|
824
|
+
throw new Error(
|
|
825
|
+
"WorkActivity components must be rendered inside WorkActivity",
|
|
826
|
+
);
|
|
827
|
+
}
|
|
828
|
+
return context;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
export type WorkActivityLabelOptions = {
|
|
832
|
+
durationMilliseconds?: number;
|
|
833
|
+
toolCallCount?: number;
|
|
834
|
+
};
|
|
835
|
+
|
|
836
|
+
/** Compact "3s" / "4m 12s" / "1h 3m" duration for work summary rows. */
|
|
837
|
+
export function formatWorkDuration(durationMilliseconds: number): string {
|
|
838
|
+
const totalSeconds = Math.max(1, Math.round(durationMilliseconds / 1000));
|
|
839
|
+
const hours = Math.floor(totalSeconds / 3600);
|
|
840
|
+
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
|
841
|
+
const seconds = totalSeconds % 60;
|
|
842
|
+
if (hours > 0) return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`;
|
|
843
|
+
if (minutes > 0)
|
|
844
|
+
return seconds > 0 ? `${minutes}m ${seconds}s` : `${minutes}m`;
|
|
845
|
+
return `${seconds}s`;
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
/** "Worked for 4m 12s and made 14 tool calls" with graceful fallbacks when
|
|
849
|
+
* either number is unknown. */
|
|
850
|
+
export function formatWorkActivityLabel({
|
|
851
|
+
durationMilliseconds,
|
|
852
|
+
toolCallCount,
|
|
853
|
+
}: WorkActivityLabelOptions): string {
|
|
854
|
+
const worked =
|
|
855
|
+
durationMilliseconds !== undefined &&
|
|
856
|
+
Number.isFinite(durationMilliseconds) &&
|
|
857
|
+
durationMilliseconds >= 0
|
|
858
|
+
? `Worked for ${formatWorkDuration(durationMilliseconds)}`
|
|
859
|
+
: undefined;
|
|
860
|
+
const calls = toolCallCount
|
|
861
|
+
? `${toolCallCount} ${toolCallCount === 1 ? "tool call" : "tool calls"}`
|
|
862
|
+
: undefined;
|
|
863
|
+
if (worked && calls) return `${worked} and made ${calls}`;
|
|
864
|
+
if (worked) return worked;
|
|
865
|
+
if (calls) return `Made ${calls}`;
|
|
866
|
+
return "Worked";
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
export type WorkActivityProps = Omit<
|
|
870
|
+
HTMLAttributes<HTMLDivElement>,
|
|
871
|
+
"onChange"
|
|
872
|
+
> & {
|
|
873
|
+
open?: boolean;
|
|
874
|
+
defaultOpen?: boolean;
|
|
875
|
+
onOpenChange?: (open: boolean) => void;
|
|
876
|
+
};
|
|
877
|
+
|
|
878
|
+
/**
|
|
879
|
+
* Collapsed summary of a finished agent run: the tool calls, thinking traces,
|
|
880
|
+
* and working narration that produced an answer fold into a single "Worked
|
|
881
|
+
* for 4m 12s and made 14 tool calls" row that expands back into the full rows.
|
|
882
|
+
*/
|
|
883
|
+
export const WorkActivity = ({
|
|
884
|
+
className,
|
|
885
|
+
defaultOpen = false,
|
|
886
|
+
onOpenChange,
|
|
887
|
+
open,
|
|
888
|
+
...props
|
|
889
|
+
}: WorkActivityProps) => {
|
|
890
|
+
const value = useDisclosureState({ defaultOpen, onOpenChange, open });
|
|
891
|
+
|
|
892
|
+
return (
|
|
893
|
+
<WorkActivityContext.Provider value={value}>
|
|
894
|
+
<div {...props} className={classNames("cline-chat-work", className)} />
|
|
895
|
+
</WorkActivityContext.Provider>
|
|
896
|
+
);
|
|
897
|
+
};
|
|
898
|
+
|
|
899
|
+
export type WorkActivityTriggerProps = Omit<
|
|
900
|
+
ButtonHTMLAttributes<HTMLButtonElement>,
|
|
901
|
+
"aria-controls" | "aria-expanded" | "type"
|
|
902
|
+
> &
|
|
903
|
+
WorkActivityLabelOptions;
|
|
904
|
+
|
|
905
|
+
export const WorkActivityTrigger = ({
|
|
906
|
+
children,
|
|
907
|
+
className,
|
|
908
|
+
durationMilliseconds,
|
|
909
|
+
onClick,
|
|
910
|
+
toolCallCount,
|
|
911
|
+
...props
|
|
912
|
+
}: WorkActivityTriggerProps) => {
|
|
913
|
+
const { isOpen, panelId, setIsOpen } = useWorkActivity();
|
|
914
|
+
return (
|
|
915
|
+
<button
|
|
916
|
+
{...props}
|
|
917
|
+
aria-controls={panelId}
|
|
918
|
+
aria-expanded={isOpen}
|
|
919
|
+
className={classNames("cline-chat-work-trigger", className)}
|
|
920
|
+
onClick={(event) => {
|
|
921
|
+
onClick?.(event);
|
|
922
|
+
if (!event.defaultPrevented) setIsOpen(!isOpen);
|
|
923
|
+
}}
|
|
924
|
+
type="button"
|
|
925
|
+
>
|
|
926
|
+
{children ?? (
|
|
927
|
+
<>
|
|
928
|
+
<span className="cline-chat-tool-label">
|
|
929
|
+
{formatWorkActivityLabel({ durationMilliseconds, toolCallCount })}
|
|
930
|
+
</span>
|
|
931
|
+
<ChevronDownIcon className="cline-chat-disclosure-icon" />
|
|
932
|
+
</>
|
|
933
|
+
)}
|
|
934
|
+
</button>
|
|
935
|
+
);
|
|
936
|
+
};
|
|
937
|
+
|
|
938
|
+
export type WorkActivityContentProps = Omit<
|
|
939
|
+
HTMLAttributes<HTMLDivElement>,
|
|
940
|
+
"hidden" | "id"
|
|
941
|
+
> & {
|
|
942
|
+
presentation?: DisclosureContentPresentation;
|
|
943
|
+
};
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
* Expanded work re-shows the run's normal chat rows at transcript level — no
|
|
947
|
+
* rail or extra indent, since the rows inside (tool disclosures, thinking
|
|
948
|
+
* traces) already carry their own nesting when expanded.
|
|
949
|
+
*/
|
|
950
|
+
export const WorkActivityContent = ({
|
|
951
|
+
presentation,
|
|
952
|
+
...props
|
|
953
|
+
}: WorkActivityContentProps) => {
|
|
954
|
+
const { isOpen, panelId } = useWorkActivity();
|
|
955
|
+
return (
|
|
956
|
+
<DisclosureContent
|
|
957
|
+
{...props}
|
|
958
|
+
contentClassName="cline-chat-work-content"
|
|
959
|
+
isOpen={isOpen}
|
|
960
|
+
lazyContent
|
|
961
|
+
panelId={panelId}
|
|
962
|
+
presentation={presentation}
|
|
963
|
+
/>
|
|
964
|
+
);
|
|
965
|
+
};
|
|
966
|
+
|
|
967
|
+
export type ToolActivityDetailsProps = HTMLAttributes<HTMLDivElement>;
|
|
968
|
+
|
|
969
|
+
export const ToolActivityDetails = ({
|
|
970
|
+
className,
|
|
971
|
+
...props
|
|
972
|
+
}: ToolActivityDetailsProps) => (
|
|
973
|
+
<div
|
|
974
|
+
className={classNames("cline-chat-tool-details", className)}
|
|
975
|
+
{...props}
|
|
976
|
+
/>
|
|
977
|
+
);
|
|
978
|
+
|
|
979
|
+
export type ToolActivityCodeProps = HTMLAttributes<HTMLPreElement>;
|
|
980
|
+
|
|
981
|
+
export const ToolActivityCode = ({
|
|
982
|
+
className,
|
|
983
|
+
...props
|
|
984
|
+
}: ToolActivityCodeProps) => (
|
|
985
|
+
<pre className={classNames("cline-chat-tool-code", className)} {...props} />
|
|
986
|
+
);
|
|
987
|
+
|
|
988
|
+
function BrainIcon({ className }: { className?: string }) {
|
|
989
|
+
return (
|
|
990
|
+
<svg
|
|
991
|
+
aria-hidden="true"
|
|
992
|
+
className={className}
|
|
993
|
+
fill="none"
|
|
994
|
+
height="16"
|
|
995
|
+
viewBox="0 0 24 24"
|
|
996
|
+
width="16"
|
|
997
|
+
>
|
|
998
|
+
<g
|
|
999
|
+
stroke="currentColor"
|
|
1000
|
+
strokeLinecap="round"
|
|
1001
|
+
strokeLinejoin="round"
|
|
1002
|
+
strokeWidth="2"
|
|
1003
|
+
>
|
|
1004
|
+
<path d="M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z" />
|
|
1005
|
+
<path d="M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z" />
|
|
1006
|
+
<path d="M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4" />
|
|
1007
|
+
<path d="M17.599 6.5a3 3 0 0 0 .399-1.375" />
|
|
1008
|
+
<path d="M6.003 5.125A3 3 0 0 0 6.401 6.5" />
|
|
1009
|
+
<path d="M3.477 10.896a4 4 0 0 1 .585-.396" />
|
|
1010
|
+
<path d="M19.938 10.5a4 4 0 0 1 .585.396" />
|
|
1011
|
+
<path d="M6 18a4 4 0 0 1-1.967-.516" />
|
|
1012
|
+
<path d="M19.967 17.484A4 4 0 0 1 18 18" />
|
|
1013
|
+
</g>
|
|
1014
|
+
</svg>
|
|
1015
|
+
);
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
function ChevronDownIcon({ className }: { className?: string }) {
|
|
1019
|
+
return (
|
|
1020
|
+
<svg
|
|
1021
|
+
aria-hidden="true"
|
|
1022
|
+
className={className}
|
|
1023
|
+
fill="none"
|
|
1024
|
+
height="16"
|
|
1025
|
+
viewBox="0 0 24 24"
|
|
1026
|
+
width="16"
|
|
1027
|
+
>
|
|
1028
|
+
<path
|
|
1029
|
+
d="m6 9 6 6 6-6"
|
|
1030
|
+
stroke="currentColor"
|
|
1031
|
+
strokeLinecap="round"
|
|
1032
|
+
strokeLinejoin="round"
|
|
1033
|
+
strokeWidth="2"
|
|
1034
|
+
/>
|
|
1035
|
+
</svg>
|
|
1036
|
+
);
|
|
1037
|
+
}
|