@@ -11,43 +11,61 @@ import { TextPill, theme } from "./tui-components";
1111 import type { TUIState } from "./types";
1212
1313 function agentMessageNode(msg: AssistantMessage): Node {
14- const textBlocks: Node[] = msg.content.map((block) => {
15- if (block.type === "text") {
16- return SyntaxHighlight(block.text, "markdown");
17- }
18- if (block.type === "thinking") {
19- if (!block.thinking.length) return Text("");
20-
21- const tokens = estimateTokens(block.thinking);
14+ let thinking = "";
15+ let text = "";
16+ const toolCalls: Node[] = [];
2217
23- return Text(`Thinking... (~${tokens} tokens)`, {
24- fgColor: theme.bblack,
25- italic: true,
26- });
18+ for (const block of msg.content) {
19+ if (block.type === "thinking" && block.thinking.length > 0) {
20+ thinking += block.thinking;
2721 }
2822
29- let text = "";
30- let node: Node | undefined;
31- if ("path" in block.arguments) {
32- text = block.arguments.path;
33- node = Text(text);
34- } else if ("command" in block.arguments) {
35- text = block.arguments.command;
36- node = SyntaxHighlight(text, "bash");
37- } else if ("prompt" in block.arguments) {
38- text = block.arguments.prompt;
39- node = SyntaxHighlight(text, "markdown");
40- } else {
41- text = JSON.stringify(block.arguments);
42- node = Text(text);
23+ if (block.type === "text" && block.text.length > 0) {
24+ text += block.text;
4325 }
4426
45- return VStack({ padding: { x: 4 }, gap: 1 }, [
46- TextPill(block.name, theme.white, theme.bblack),
47- node,
48- ]);
49- });
27+ if (block.type === "toolCall" && block.arguments && block.name) {
28+ let text = "";
29+ let node: Node | undefined;
30+ if ("path" in block.arguments) {
31+ text = block.arguments.path;
32+ node = Text(text);
33+ } else if ("command" in block.arguments) {
34+ text = block.arguments.command;
35+ node = SyntaxHighlight(text, "bash");
36+ } else if ("prompt" in block.arguments) {
37+ text = block.arguments.prompt;
38+ node = SyntaxHighlight(text, "markdown");
39+ } else {
40+ text = JSON.stringify(block.arguments);
41+ node = Text(text);
42+ }
43+
44+ toolCalls.push(
45+ VStack({ padding: { x: 4 }, gap: 1 }, [
46+ TextPill(block.name, theme.white, theme.bblack),
47+ node,
48+ ]),
49+ );
50+ }
51+ }
52+ const textBlocks: Node[] = [];
53+ if (thinking.length > 0) {
54+ const tokens = estimateTokens(thinking);
5055
56+ textBlocks.push(
57+ Text(`Thinking... (~${tokens} tokens)`, {
58+ fgColor: theme.bblack,
59+ italic: true,
60+ }),
61+ );
62+ }
63+ if (text.length > 0) {
64+ textBlocks.push(SyntaxHighlight(text, "markdown"));
65+ }
66+ if (toolCalls.length > 0) {
67+ textBlocks.push(...toolCalls);
68+ }
5169 const error =
5270 ((msg.stopReason === "error" || msg.stopReason === "aborted") &&
5371 msg.errorMessage) ??
@@ -60,6 +78,16 @@ function agentMessageNode(msg: AssistantMessage): Node {
6078 ]),
6179 );
6280 }
81+
82+ if (textBlocks.length === 0) {
83+ textBlocks.push(
84+ Text("Loading...", {
85+ fgColor: theme.bblack,
86+ italic: true,
87+ }),
88+ );
89+ }
90+
6391 return VStack({ gap: 1 }, textBlocks);
6492 }
6593
@@ -125,6 +153,27 @@ function conversationMessageNode(msg: Message): Node {
125153 ]);
126154 }
127155
156+const colors = [
157+ theme.bgreen,
158+ theme.byellow,
159+ theme.bblue,
160+ theme.bcyan,
161+ theme.bmagenta,
162+ theme.bred,
163+];
164+const randColor = colors[Math.floor(Math.random() * colors.length)];
165+
166+export function emptyState(): Node {
167+ return HStack({ flex: 1, alignItems: "center" }, [
168+ VStack({ flex: 1, alignItems: "center" }, [
169+ HStack({ gap: 1 }, [
170+ Text("mini"),
171+ TextPill("coder", theme.black, randColor),
172+ ]),
173+ ]),
174+ ]);
175+}
176+
128177 export function Conversation(state: TUIState) {
129178 return VStack(
130179 {