@yuaone/cli 0.1.2 → 0.3.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/dist/cli.js +29 -4
- package/dist/cli.js.map +1 -1
- package/dist/interactive.js +1 -1
- package/dist/interactive.js.map +1 -1
- package/dist/oneshot.js +1 -1
- package/dist/oneshot.js.map +1 -1
- package/dist/tui/App.d.ts +33 -0
- package/dist/tui/App.d.ts.map +1 -0
- package/dist/tui/App.js +244 -0
- package/dist/tui/App.js.map +1 -0
- package/dist/tui/agent-bridge.d.ts +56 -0
- package/dist/tui/agent-bridge.d.ts.map +1 -0
- package/dist/tui/agent-bridge.js +138 -0
- package/dist/tui/agent-bridge.js.map +1 -0
- package/dist/tui/components/BashOutput.d.ts +12 -0
- package/dist/tui/components/BashOutput.d.ts.map +1 -0
- package/dist/tui/components/BashOutput.js +19 -0
- package/dist/tui/components/BashOutput.js.map +1 -0
- package/dist/tui/components/CollapsibleSection.d.ts +14 -0
- package/dist/tui/components/CollapsibleSection.d.ts.map +1 -0
- package/dist/tui/components/CollapsibleSection.js +7 -0
- package/dist/tui/components/CollapsibleSection.js.map +1 -0
- package/dist/tui/components/DiffView.d.ts +11 -0
- package/dist/tui/components/DiffView.d.ts.map +1 -0
- package/dist/tui/components/DiffView.js +20 -0
- package/dist/tui/components/DiffView.js.map +1 -0
- package/dist/tui/components/FooterBar.d.ts +11 -0
- package/dist/tui/components/FooterBar.d.ts.map +1 -0
- package/dist/tui/components/FooterBar.js +14 -0
- package/dist/tui/components/FooterBar.js.map +1 -0
- package/dist/tui/components/InputBox.d.ts +24 -0
- package/dist/tui/components/InputBox.d.ts.map +1 -0
- package/dist/tui/components/InputBox.js +124 -0
- package/dist/tui/components/InputBox.js.map +1 -0
- package/dist/tui/components/MarkdownRenderer.d.ts +11 -0
- package/dist/tui/components/MarkdownRenderer.d.ts.map +1 -0
- package/dist/tui/components/MarkdownRenderer.js +118 -0
- package/dist/tui/components/MarkdownRenderer.js.map +1 -0
- package/dist/tui/components/MessageBubble.d.ts +16 -0
- package/dist/tui/components/MessageBubble.d.ts.map +1 -0
- package/dist/tui/components/MessageBubble.js +38 -0
- package/dist/tui/components/MessageBubble.js.map +1 -0
- package/dist/tui/components/MessageList.d.ts +15 -0
- package/dist/tui/components/MessageList.d.ts.map +1 -0
- package/dist/tui/components/MessageList.js +31 -0
- package/dist/tui/components/MessageList.js.map +1 -0
- package/dist/tui/components/SlashMenu.d.ts +14 -0
- package/dist/tui/components/SlashMenu.d.ts.map +1 -0
- package/dist/tui/components/SlashMenu.js +21 -0
- package/dist/tui/components/SlashMenu.js.map +1 -0
- package/dist/tui/components/Spinner.d.ts +9 -0
- package/dist/tui/components/Spinner.d.ts.map +1 -0
- package/dist/tui/components/Spinner.js +19 -0
- package/dist/tui/components/Spinner.js.map +1 -0
- package/dist/tui/components/StatusBar.d.ts +13 -0
- package/dist/tui/components/StatusBar.d.ts.map +1 -0
- package/dist/tui/components/StatusBar.js +15 -0
- package/dist/tui/components/StatusBar.js.map +1 -0
- package/dist/tui/components/ThinkingDots.d.ts +9 -0
- package/dist/tui/components/ThinkingDots.d.ts.map +1 -0
- package/dist/tui/components/ThinkingDots.js +19 -0
- package/dist/tui/components/ThinkingDots.js.map +1 -0
- package/dist/tui/components/ToolCallTree.d.ts +12 -0
- package/dist/tui/components/ToolCallTree.d.ts.map +1 -0
- package/dist/tui/components/ToolCallTree.js +45 -0
- package/dist/tui/components/ToolCallTree.js.map +1 -0
- package/dist/tui/hooks/useAgentStream.d.ts +27 -0
- package/dist/tui/hooks/useAgentStream.d.ts.map +1 -0
- package/dist/tui/hooks/useAgentStream.js +212 -0
- package/dist/tui/hooks/useAgentStream.js.map +1 -0
- package/dist/tui/hooks/useInputHistory.d.ts +17 -0
- package/dist/tui/hooks/useInputHistory.d.ts.map +1 -0
- package/dist/tui/hooks/useInputHistory.js +49 -0
- package/dist/tui/hooks/useInputHistory.js.map +1 -0
- package/dist/tui/hooks/useKeyHandler.d.ts +12 -0
- package/dist/tui/hooks/useKeyHandler.d.ts.map +1 -0
- package/dist/tui/hooks/useKeyHandler.js +20 -0
- package/dist/tui/hooks/useKeyHandler.js.map +1 -0
- package/dist/tui/hooks/useScrollPosition.d.ts +27 -0
- package/dist/tui/hooks/useScrollPosition.d.ts.map +1 -0
- package/dist/tui/hooks/useScrollPosition.js +54 -0
- package/dist/tui/hooks/useScrollPosition.js.map +1 -0
- package/dist/tui/hooks/useSlashCommands.d.ts +22 -0
- package/dist/tui/hooks/useSlashCommands.d.ts.map +1 -0
- package/dist/tui/hooks/useSlashCommands.js +61 -0
- package/dist/tui/hooks/useSlashCommands.js.map +1 -0
- package/dist/tui/hooks/useTerminalSize.d.ts +11 -0
- package/dist/tui/hooks/useTerminalSize.d.ts.map +1 -0
- package/dist/tui/hooks/useTerminalSize.js +25 -0
- package/dist/tui/hooks/useTerminalSize.js.map +1 -0
- package/dist/tui/lib/ansi.d.ts +36 -0
- package/dist/tui/lib/ansi.d.ts.map +1 -0
- package/dist/tui/lib/ansi.js +40 -0
- package/dist/tui/lib/ansi.js.map +1 -0
- package/dist/tui/lib/box-drawing.d.ts +12 -0
- package/dist/tui/lib/box-drawing.d.ts.map +1 -0
- package/dist/tui/lib/box-drawing.js +30 -0
- package/dist/tui/lib/box-drawing.js.map +1 -0
- package/dist/tui/lib/diff-formatter.d.ts +9 -0
- package/dist/tui/lib/diff-formatter.d.ts.map +1 -0
- package/dist/tui/lib/diff-formatter.js +65 -0
- package/dist/tui/lib/diff-formatter.js.map +1 -0
- package/dist/tui/lib/tokens.d.ts +56 -0
- package/dist/tui/lib/tokens.d.ts.map +1 -0
- package/dist/tui/lib/tokens.js +61 -0
- package/dist/tui/lib/tokens.js.map +1 -0
- package/dist/tui/lib/truncate.d.ts +11 -0
- package/dist/tui/lib/truncate.d.ts.map +1 -0
- package/dist/tui/lib/truncate.js +69 -0
- package/dist/tui/lib/truncate.js.map +1 -0
- package/dist/tui/lib/update-checker.d.ts +21 -0
- package/dist/tui/lib/update-checker.d.ts.map +1 -0
- package/dist/tui/lib/update-checker.js +133 -0
- package/dist/tui/lib/update-checker.js.map +1 -0
- package/dist/tui/types.d.ts +77 -0
- package/dist/tui/types.d.ts.map +1 -0
- package/dist/tui/types.js +5 -0
- package/dist/tui/types.js.map +1 -0
- package/package.json +21 -11
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MessageBubble — renders a single message with role-based styling.
|
|
3
|
+
* User: ● you
|
|
4
|
+
* Assistant: ◆ yuan (with spinner when streaming)
|
|
5
|
+
* Tool: └─ ✓/✗ toolName (duration)
|
|
6
|
+
* System: dimmed text
|
|
7
|
+
*/
|
|
8
|
+
import React from "react";
|
|
9
|
+
import type { TUIMessage } from "../types.js";
|
|
10
|
+
export interface MessageBubbleProps {
|
|
11
|
+
message: TUIMessage;
|
|
12
|
+
width: number;
|
|
13
|
+
isLatest?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function MessageBubble({ message, width, isLatest, }: MessageBubbleProps): React.JSX.Element;
|
|
16
|
+
//# sourceMappingURL=MessageBubble.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageBubble.d.ts","sourceRoot":"","sources":["../../../src/tui/components/MessageBubble.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,OAAO,KAAK,EAAE,UAAU,EAAe,MAAM,aAAa,CAAC;AAE3D,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,UAAU,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AA+BD,wBAAgB,aAAa,CAAC,EAC5B,OAAO,EACP,KAAK,EACL,QAAQ,GACT,EAAE,kBAAkB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CA8ExC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text } from "ink";
|
|
3
|
+
import { TOKENS } from "../lib/tokens.js";
|
|
4
|
+
import { Spinner } from "./Spinner.js";
|
|
5
|
+
import { MarkdownRenderer } from "./MarkdownRenderer.js";
|
|
6
|
+
function ToolCallLine({ tc, isLast }) {
|
|
7
|
+
const connector = isLast ? TOKENS.tree.last : TOKENS.tree.branch;
|
|
8
|
+
const icon = tc.status === "running" ? null :
|
|
9
|
+
tc.status === "success" ? "✓" :
|
|
10
|
+
"✗";
|
|
11
|
+
const iconColor = tc.status === "success" ? "green" :
|
|
12
|
+
tc.status === "error" ? "red" :
|
|
13
|
+
undefined;
|
|
14
|
+
const duration = tc.duration != null ? ` (${tc.duration.toFixed(1)}s)` : "";
|
|
15
|
+
return (_jsxs(Box, { paddingLeft: 2, children: [_jsxs(Text, { dimColor: true, children: [connector, " "] }), tc.status === "running" ? (_jsx(Spinner, { label: tc.toolName })) : (_jsxs(_Fragment, { children: [_jsx(Text, { color: iconColor, children: icon }), _jsxs(Text, { dimColor: true, children: [" ", tc.toolName] }), _jsxs(Text, { dimColor: true, children: [" ", tc.argsSummary] }), _jsx(Text, { dimColor: true, children: duration })] }))] }));
|
|
16
|
+
}
|
|
17
|
+
export function MessageBubble({ message, width, isLatest, }) {
|
|
18
|
+
const msg = message;
|
|
19
|
+
switch (msg.role) {
|
|
20
|
+
case "user":
|
|
21
|
+
return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsxs(Text, { bold: true, color: "white", children: [TOKENS.brand.userPrefix, " you"] }), _jsxs(Text, { children: [" ", msg.content] })] }));
|
|
22
|
+
case "assistant":
|
|
23
|
+
return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Box, { children: msg.isStreaming ? (_jsx(Spinner, { label: TOKENS.brand.name })) : (_jsxs(Text, { bold: true, color: "white", children: [TOKENS.brand.prefix, " ", TOKENS.brand.name] })) }), msg.content && (_jsx(Box, { paddingLeft: 2, children: _jsx(MarkdownRenderer, { content: msg.content, width: width - 4 }) })), msg.isStreaming && isLatest && (_jsx(Box, { paddingLeft: 2, children: _jsx(Text, { dimColor: true, children: "\u2588" }) })), msg.toolCalls && msg.toolCalls.length > 0 && (_jsx(Box, { flexDirection: "column", children: msg.toolCalls.map((tc, i) => (_jsx(ToolCallLine, { tc: tc, isLast: i === msg.toolCalls.length - 1 }, tc.id))) }))] }));
|
|
24
|
+
case "tool": {
|
|
25
|
+
const icon = msg.toolSuccess ? "✓" : "✗";
|
|
26
|
+
const iconColor = msg.toolSuccess ? "green" : "red";
|
|
27
|
+
const duration = msg.toolDurationMs
|
|
28
|
+
? ` (${(msg.toolDurationMs / 1000).toFixed(1)}s)`
|
|
29
|
+
: "";
|
|
30
|
+
return (_jsxs(Box, { paddingLeft: 2, children: [_jsxs(Text, { dimColor: true, children: [TOKENS.tree.last, " "] }), _jsx(Text, { color: iconColor, children: icon }), _jsxs(Text, { dimColor: true, children: [" ", msg.toolName, duration] })] }));
|
|
31
|
+
}
|
|
32
|
+
case "system":
|
|
33
|
+
return (_jsx(Box, { children: _jsxs(Text, { dimColor: true, children: [" ", msg.content] }) }));
|
|
34
|
+
default:
|
|
35
|
+
return _jsx(Box, {});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=MessageBubble.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageBubble.js","sourceRoot":"","sources":["../../../src/tui/components/MessageBubble.tsx"],"names":[],"mappings":";AASA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AASzD,SAAS,YAAY,CAAC,EAAE,EAAE,EAAE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|
+
* Uses MessageBubble for individual message rendering.
|
|
4
|
+
* Supports PageUp/PageDown scroll, auto-scroll on new messages.
|
|
5
|
+
*/
|
|
6
|
+
import React from "react";
|
|
7
|
+
import type { TUIMessage } from "../types.js";
|
|
8
|
+
export type { TUIMessage } from "../types.js";
|
|
9
|
+
export interface MessageListProps {
|
|
10
|
+
messages: TUIMessage[];
|
|
11
|
+
isThinking?: boolean;
|
|
12
|
+
maxHeight?: number;
|
|
13
|
+
}
|
|
14
|
+
export declare function MessageList({ messages, isThinking, maxHeight, }: MessageListProps): React.JSX.Element;
|
|
15
|
+
//# sourceMappingURL=MessageList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageList.d.ts","sourceRoot":"","sources":["../../../src/tui/components/MessageList.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAO1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG9C,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,UAAU,EACV,SAAS,GACV,EAAE,gBAAgB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAsEtC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text, useInput } from "ink";
|
|
3
|
+
import { useTerminalSize } from "../hooks/useTerminalSize.js";
|
|
4
|
+
import { useScrollPosition } from "../hooks/useScrollPosition.js";
|
|
5
|
+
import { MessageBubble } from "./MessageBubble.js";
|
|
6
|
+
import { Spinner } from "./Spinner.js";
|
|
7
|
+
import { TOKENS } from "../lib/tokens.js";
|
|
8
|
+
export function MessageList({ messages, isThinking, maxHeight, }) {
|
|
9
|
+
const { columns, rows } = useTerminalSize();
|
|
10
|
+
const height = maxHeight ?? rows - 4;
|
|
11
|
+
// Approximate: each message takes ~3 lines on average
|
|
12
|
+
const viewportMsgCount = Math.max(3, Math.floor(height / 3));
|
|
13
|
+
const [scroll, scrollActions] = useScrollPosition(messages.length, viewportMsgCount);
|
|
14
|
+
// Key handling for scroll
|
|
15
|
+
useInput((_input, key) => {
|
|
16
|
+
if (key.pageUp) {
|
|
17
|
+
scrollActions.pageUp();
|
|
18
|
+
}
|
|
19
|
+
else if (key.pageDown) {
|
|
20
|
+
scrollActions.pageDown();
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
// Compute visible slice
|
|
24
|
+
const startIdx = scroll.offset;
|
|
25
|
+
const endIdx = Math.min(messages.length, startIdx + viewportMsgCount);
|
|
26
|
+
const visibleMessages = messages.slice(startIdx, endIdx);
|
|
27
|
+
const hasAbove = scroll.aboveCount > 0;
|
|
28
|
+
const hasBelow = scroll.belowCount > 0;
|
|
29
|
+
return (_jsxs(Box, { flexDirection: "column", height: height, overflow: "hidden", children: [hasAbove && (_jsx(Box, { justifyContent: "center", children: _jsxs(Text, { dimColor: true, children: ["\u2191 ", scroll.aboveCount, " more"] }) })), visibleMessages.length === 0 && !isThinking && (_jsx(Box, { justifyContent: "center", marginTop: Math.floor(height / 3), children: _jsx(Text, { dimColor: true, children: "Type a message to start..." }) })), visibleMessages.map((msg, i) => (_jsx(MessageBubble, { message: msg, width: columns, isLatest: startIdx + i === messages.length - 1 }, msg.id))), isThinking && !messages.some((m) => m.isStreaming) && (_jsxs(Box, { marginTop: 0, children: [_jsx(Text, { children: " " }), _jsx(Spinner, { label: `${TOKENS.brand.name} ·····` })] })), hasBelow && (_jsx(Box, { justifyContent: "center", children: _jsxs(Text, { dimColor: true, children: ["\u2193 ", scroll.belowCount, " more"] }) }))] }));
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=MessageList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageList.js","sourceRoot":"","sources":["../../../src/tui/components/MessageList.tsx"],"names":[],"mappings":";AAOA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAY1C,MAAM,UAAU,WAAW,CAAC,EAC1B,QAAQ,EACR,UAAU,EACV,SAAS,GACQ;IACjB,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,eAAe,EAAE,CAAC;IAC5C,MAAM,MAAM,GAAG,SAAS,IAAI,IAAI,GAAG,CAAC,CAAC;IAErC,sDAAsD;IACtD,MAAM,gBAAgB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IAE7D,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,iBAAiB,CAC/C,QAAQ,CAAC,MAAM,EACf,gBAAgB,CACjB,CAAC;IAEF,0BAA0B;IAC1B,QAAQ,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;QACvB,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;YACf,aAAa,CAAC,MAAM,EAAE,CAAC;QACzB,CAAC;aAAM,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;YACxB,aAAa,CAAC,QAAQ,EAAE,CAAC;QAC3B,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,wBAAwB;IACxB,MAAM,QAAQ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IAAI,qBAAU,EACf,KAAC,OAAO,IAAC,KAAK,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,QAAQ,GAAI,IAC5C,CACP,EAGA,QAAQ,IAAI,CACX,KAAC,GAAG,IAAC,cAAc,EAAC,QAAQ,YAC1B,MAAC,IAAI,IAAC,QAAQ,8BAAI,MAAM,CAAC,UAAU,aAAa,GAC5C,CACP,IACG,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SlashMenu — autocomplete dropdown for slash commands.
|
|
3
|
+
* Appears above the input box when user types "/".
|
|
4
|
+
*/
|
|
5
|
+
import React from "react";
|
|
6
|
+
import type { SlashCommand } from "../types.js";
|
|
7
|
+
export interface SlashMenuProps {
|
|
8
|
+
commands: SlashCommand[];
|
|
9
|
+
selectedIndex: number;
|
|
10
|
+
isOpen: boolean;
|
|
11
|
+
width: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function SlashMenu({ commands, selectedIndex, isOpen, width, }: SlashMenuProps): React.JSX.Element | null;
|
|
14
|
+
//# sourceMappingURL=SlashMenu.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SlashMenu.d.ts","sourceRoot":"","sources":["../../../src/tui/components/SlashMenu.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,SAAS,CAAC,EACxB,QAAQ,EACR,aAAa,EACb,MAAM,EACN,KAAK,GACN,EAAE,cAAc,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,CAmD3C"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text } from "ink";
|
|
3
|
+
import { TOKENS } from "../lib/tokens.js";
|
|
4
|
+
export function SlashMenu({ commands, selectedIndex, isOpen, width, }) {
|
|
5
|
+
if (!isOpen || commands.length === 0)
|
|
6
|
+
return null;
|
|
7
|
+
const maxVisible = Math.min(commands.length, 8);
|
|
8
|
+
const visible = commands.slice(0, maxVisible);
|
|
9
|
+
const boxWidth = Math.min(width - 4, 50);
|
|
10
|
+
return (_jsxs(Box, { flexDirection: "column", width: boxWidth, children: [_jsxs(Text, { dimColor: true, children: [TOKENS.box.topLeft, TOKENS.box.horizontal.repeat(boxWidth - 2), TOKENS.box.topRight] }), visible.map((cmd, i) => {
|
|
11
|
+
const isSelected = i === selectedIndex;
|
|
12
|
+
const nameWidth = 12;
|
|
13
|
+
const name = cmd.name.padEnd(nameWidth);
|
|
14
|
+
const descWidth = boxWidth - nameWidth - 6;
|
|
15
|
+
const desc = cmd.description.length > descWidth
|
|
16
|
+
? cmd.description.slice(0, descWidth - 1) + "…"
|
|
17
|
+
: cmd.description;
|
|
18
|
+
return (_jsxs(Box, { children: [_jsxs(Text, { dimColor: true, children: [TOKENS.box.vertical, " "] }), isSelected ? (_jsxs(_Fragment, { children: [_jsx(Text, { bold: true, color: "white", children: name }), _jsxs(Text, { color: "white", children: [" ", desc] })] })) : (_jsxs(_Fragment, { children: [_jsx(Text, { children: name }), _jsxs(Text, { dimColor: true, children: [" ", desc] })] }))] }, cmd.name));
|
|
19
|
+
}), commands.length > maxVisible && (_jsx(Box, { children: _jsxs(Text, { dimColor: true, children: [TOKENS.box.vertical, " ... ", commands.length - maxVisible, " more"] }) })), _jsxs(Text, { dimColor: true, children: [TOKENS.box.bottomLeft, TOKENS.box.horizontal.repeat(boxWidth - 2), TOKENS.box.bottomRight] })] }));
|
|
20
|
+
}
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AAA;;GAEG;AAEH,OAAO,KAA8B,MAAM,OAAO,CAAC;AAInD,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAgBlE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Spinner — braille dot animation (gray, dim).
|
|
4
|
+
*/
|
|
5
|
+
import { useState, useEffect } from "react";
|
|
6
|
+
import { Text } from "ink";
|
|
7
|
+
import { TOKENS } from "../lib/tokens.js";
|
|
8
|
+
export function Spinner({ label }) {
|
|
9
|
+
const { frames, interval } = TOKENS.spinner;
|
|
10
|
+
const [frame, setFrame] = useState(0);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const timer = setInterval(() => {
|
|
13
|
+
setFrame((f) => (f + 1) % frames.length);
|
|
14
|
+
}, interval);
|
|
15
|
+
return () => clearInterval(timer);
|
|
16
|
+
}, [frames.length, interval]);
|
|
17
|
+
return (_jsxs(Text, { dimColor: true, children: [frames[frame], label ? ` ${label}` : ""] }));
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=Spinner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Spinner.js","sourceRoot":"","sources":["../../../src/tui/components/Spinner.tsx"],"names":[],"mappings":";AAAA;;GAEG;AAEH,OAAc,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAM1C,MAAM,UAAU,OAAO,CAAC,EAAE,KAAK,EAAgB;IAC7C,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC;IAC5C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEtC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;YAC7B,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;QAC3C,CAAC,EAAE,QAAQ,CAAC,CAAC;QACb,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE9B,OAAO,CACL,MAAC,IAAI,IAAC,QAAQ,mBACX,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,IACnC,CACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StatusBar — top bar showing version, model, tokens/s, status.
|
|
3
|
+
*/
|
|
4
|
+
import React from "react";
|
|
5
|
+
export interface StatusBarProps {
|
|
6
|
+
version: string;
|
|
7
|
+
model: string;
|
|
8
|
+
provider: string;
|
|
9
|
+
tokensPerSec?: number;
|
|
10
|
+
isRunning?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function StatusBar({ version, model, provider, tokensPerSec, isRunning, }: StatusBarProps): React.JSX.Element;
|
|
13
|
+
//# sourceMappingURL=StatusBar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StatusBar.d.ts","sourceRoot":"","sources":["../../../src/tui/components/StatusBar.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,wBAAgB,SAAS,CAAC,EACxB,OAAO,EACP,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,SAAS,GACV,EAAE,cAAc,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAkBpC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text } from "ink";
|
|
3
|
+
import { useTerminalSize } from "../hooks/useTerminalSize.js";
|
|
4
|
+
import { TOKENS } from "../lib/tokens.js";
|
|
5
|
+
export function StatusBar({ version, model, provider, tokensPerSec, isRunning, }) {
|
|
6
|
+
const { columns, tier } = useTerminalSize();
|
|
7
|
+
const left = `${TOKENS.brand.prefix} YUAN v${version}`;
|
|
8
|
+
const status = isRunning ? "●" : "○";
|
|
9
|
+
const tps = tokensPerSec != null ? `${tokensPerSec} tok/s` : "";
|
|
10
|
+
const right = tier === "compact"
|
|
11
|
+
? `${status} ${model}`
|
|
12
|
+
: `${provider}/${model} ${status} ${tps}`;
|
|
13
|
+
return (_jsxs(Box, { width: columns, justifyContent: "space-between", children: [_jsx(Text, { dimColor: true, children: left }), _jsx(Text, { dimColor: true, children: right })] }));
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=StatusBar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StatusBar.js","sourceRoot":"","sources":["../../../src/tui/components/StatusBar.tsx"],"names":[],"mappings":";AAKA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAU1C,MAAM,UAAU,SAAS,CAAC,EACxB,OAAO,EACP,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,SAAS,GACM;IACf,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,eAAe,EAAE,CAAC;IAE5C,MAAM,IAAI,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,UAAU,OAAO,EAAE,CAAC;IACvD,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IACrC,MAAM,GAAG,GAAG,YAAY,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,YAAY,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;IAEhE,MAAM,KAAK,GACT,IAAI,KAAK,SAAS;QAChB,CAAC,CAAC,GAAG,MAAM,IAAI,KAAK,EAAE;QACtB,CAAC,CAAC,GAAG,QAAQ,IAAI,KAAK,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;IAE9C,OAAO,CACL,MAAC,GAAG,IAAC,KAAK,EAAE,OAAO,EAAE,cAAc,EAAC,eAAe,aACjD,KAAC,IAAI,IAAC,QAAQ,kBAAE,IAAI,GAAQ,EAC5B,KAAC,IAAI,IAAC,QAAQ,kBAAE,KAAK,GAAQ,IACzB,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ThinkingDots — animated "·····" indicator, dim gray.
|
|
3
|
+
*/
|
|
4
|
+
import React from "react";
|
|
5
|
+
export interface ThinkingDotsProps {
|
|
6
|
+
label?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function ThinkingDots({ label }: ThinkingDotsProps): React.JSX.Element;
|
|
9
|
+
//# sourceMappingURL=ThinkingDots.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThinkingDots.d.ts","sourceRoot":"","sources":["../../../src/tui/components/ThinkingDots.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAA8B,MAAM,OAAO,CAAC;AAInD,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,YAAY,CAAC,EAAE,KAAK,EAAE,EAAE,iBAAiB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAgB5E"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* ThinkingDots — animated "·····" indicator, dim gray.
|
|
4
|
+
*/
|
|
5
|
+
import { useState, useEffect } from "react";
|
|
6
|
+
import { Text } from "ink";
|
|
7
|
+
import { TOKENS } from "../lib/tokens.js";
|
|
8
|
+
export function ThinkingDots({ label }) {
|
|
9
|
+
const { frames, interval } = TOKENS.dots;
|
|
10
|
+
const [frame, setFrame] = useState(0);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const timer = setInterval(() => {
|
|
13
|
+
setFrame((f) => (f + 1) % frames.length);
|
|
14
|
+
}, interval);
|
|
15
|
+
return () => clearInterval(timer);
|
|
16
|
+
}, [frames.length, interval]);
|
|
17
|
+
return (_jsxs(Text, { dimColor: true, children: [label ? `${label} ` : "", frames[frame]] }));
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=ThinkingDots.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThinkingDots.js","sourceRoot":"","sources":["../../../src/tui/components/ThinkingDots.tsx"],"names":[],"mappings":";AAAA;;GAEG;AAEH,OAAc,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAM1C,MAAM,UAAU,YAAY,CAAC,EAAE,KAAK,EAAqB;IACvD,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC;IACzC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEtC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;YAC7B,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;QAC3C,CAAC,EAAE,QAAQ,CAAC,CAAC;QACb,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE9B,OAAO,CACL,MAAC,IAAI,IAAC,QAAQ,mBACX,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,IACnC,CACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ToolCallTree — tree-style tool call display with ├─ └─ connectors.
|
|
3
|
+
* Shows status indicators, durations, and expandable results.
|
|
4
|
+
*/
|
|
5
|
+
import React from "react";
|
|
6
|
+
import type { TUIToolCall } from "../types.js";
|
|
7
|
+
export interface ToolCallTreeProps {
|
|
8
|
+
toolCalls: TUIToolCall[];
|
|
9
|
+
width: number;
|
|
10
|
+
}
|
|
11
|
+
export declare function ToolCallTree({ toolCalls, width, }: ToolCallTreeProps): React.JSX.Element;
|
|
12
|
+
//# sourceMappingURL=ToolCallTree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolCallTree.d.ts","sourceRoot":"","sources":["../../../src/tui/components/ToolCallTree.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAgC,MAAM,OAAO,CAAC;AAOrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/C,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,WAAW,EAAE,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;CACf;AA8FD,wBAAgB,YAAY,CAAC,EAC3B,SAAS,EACT,KAAK,GACN,EAAE,iBAAiB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAavC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* ToolCallTree — tree-style tool call display with ├─ └─ connectors.
|
|
4
|
+
* Shows status indicators, durations, and expandable results.
|
|
5
|
+
*/
|
|
6
|
+
import { useState, useCallback } from "react";
|
|
7
|
+
import { Box, Text } from "ink";
|
|
8
|
+
import { TOKENS } from "../lib/tokens.js";
|
|
9
|
+
import { Spinner } from "./Spinner.js";
|
|
10
|
+
import { CollapsibleSection } from "./CollapsibleSection.js";
|
|
11
|
+
import { DiffView } from "./DiffView.js";
|
|
12
|
+
import { BashOutput } from "./BashOutput.js";
|
|
13
|
+
import { truncate } from "../lib/truncate.js";
|
|
14
|
+
import { useTerminalSize } from "../hooks/useTerminalSize.js";
|
|
15
|
+
function ToolCallNode({ tc, isLast, width, }) {
|
|
16
|
+
const [isExpanded, setIsExpanded] = useState(tc.isExpanded);
|
|
17
|
+
const connector = isLast ? TOKENS.tree.last : TOKENS.tree.branch;
|
|
18
|
+
const continuation = isLast ? " " : TOKENS.tree.pipe;
|
|
19
|
+
const toggleExpand = useCallback(() => {
|
|
20
|
+
setIsExpanded((prev) => !prev);
|
|
21
|
+
}, []);
|
|
22
|
+
// Status icon
|
|
23
|
+
let statusEl;
|
|
24
|
+
if (tc.status === "running") {
|
|
25
|
+
statusEl = _jsx(Spinner, {});
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
const icon = tc.status === "success" ? "✓" : "✗";
|
|
29
|
+
const color = tc.status === "success" ? "green" : "red";
|
|
30
|
+
statusEl = _jsx(Text, { color: color, children: icon });
|
|
31
|
+
}
|
|
32
|
+
// Duration
|
|
33
|
+
const durationStr = tc.duration != null ? ` ${tc.duration.toFixed(1)}s` : "";
|
|
34
|
+
// Truncate args summary based on available width
|
|
35
|
+
const { tier } = useTerminalSize();
|
|
36
|
+
const maxArgWidth = tier === "compact" ? 20 : width - 30;
|
|
37
|
+
const args = tc.argsSummary
|
|
38
|
+
? truncate(tc.argsSummary, maxArgWidth)
|
|
39
|
+
: "";
|
|
40
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { children: [_jsxs(Text, { dimColor: true, children: [connector, " "] }), _jsx(Text, { bold: true, children: tc.toolName }), args && _jsxs(Text, { dimColor: true, children: [" ", args] }), _jsx(Text, { children: " " }), statusEl, _jsx(Text, { dimColor: true, children: durationStr })] }), tc.result && tc.result.lineCount > 0 && (_jsxs(Box, { paddingLeft: 2, children: [_jsx(Text, { dimColor: true, children: continuation }), _jsx(Box, { flexDirection: "column", marginLeft: 1, children: tc.result.kind === "diff" && tc.result.diff ? (_jsx(CollapsibleSection, { isExpanded: isExpanded, onToggle: toggleExpand, collapsedSummary: `${tc.result.diff.additions + tc.result.diff.deletions} changes`, children: _jsx(DiffView, { diff: tc.result.diff, width: width - 6 }) })) : tc.result.kind === "bash_output" ? (_jsx(CollapsibleSection, { isExpanded: isExpanded, onToggle: toggleExpand, collapsedSummary: `${tc.result.lineCount} lines of output`, children: _jsx(BashOutput, { command: tc.toolName, output: tc.result.content, width: width - 6 }) })) : tc.result.lineCount > 10 ? (_jsx(CollapsibleSection, { isExpanded: isExpanded, onToggle: toggleExpand, collapsedSummary: `${tc.result.lineCount} lines`, children: _jsx(Text, { dimColor: true, children: tc.result.content }) })) : (_jsx(Text, { dimColor: true, children: tc.result.content })) })] }))] }));
|
|
41
|
+
}
|
|
42
|
+
export function ToolCallTree({ toolCalls, width, }) {
|
|
43
|
+
return (_jsx(Box, { flexDirection: "column", children: toolCalls.map((tc, i) => (_jsx(ToolCallNode, { tc: tc, isLast: i === toolCalls.length - 1, width: width }, tc.id))) }));
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=ToolCallTree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolCallTree.js","sourceRoot":"","sources":["../../../src/tui/components/ToolCallTree.tsx"],"names":[],"mappings":";AAAA;;;GAGG;AAEH,OAAc,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAO9D,SAAS,YAAY,CAAC,EACpB,EAAE,EACF,MAAM,EACN,KAAK,GAKN;IACC,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC;IAC5D,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;IACjE,MAAM,YAAY,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;IAEtD,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,EAAE;QACpC,aAAa,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,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7B,KAAC,kBAAkB,IACjB,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,YAAY,EACtB,gBAAgB,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,SAAS,QAAQ,YAEhD,KAAC,IAAI,IAAC,QAAQ,kBAAE,EAAE,CAAC,MAAM,CAAC,OAAO,GAAQ,GACtB,CACtB,CAAC,CAAC,CAAC,CACF,KAAC,IAAI,IAAC,QAAQ,kBAAE,EAAE,CAAC,MAAM,CAAC,OAAO,GAAQ,CAC1C,GACG,IACF,CACP,IACG,CACP,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,EAC3B,SAAS,EACT,KAAK,GACa;IAClB,OAAO,CACL,KAAC,GAAG,IAAC,aAAa,EAAC,QAAQ,YACxB,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CACxB,KAAC,YAAY,IAEX,EAAE,EAAE,EAAE,EACN,MAAM,EAAE,CAAC,KAAK,SAAS,CAAC,MAAM,GAAG,CAAC,EAClC,KAAK,EAAE,KAAK,IAHP,EAAE,CAAC,EAAE,CAIV,CACH,CAAC,GACE,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useAgentStream — bridges AgentLoop events to TUI React state.
|
|
3
|
+
* Converts agent events into TUIMessage updates, tracks streaming state.
|
|
4
|
+
*/
|
|
5
|
+
import type { AgentStreamState } from "../types.js";
|
|
6
|
+
export interface UseAgentStreamReturn {
|
|
7
|
+
state: AgentStreamState;
|
|
8
|
+
/** Process an incoming agent event */
|
|
9
|
+
handleEvent: (event: AgentEventLike) => void;
|
|
10
|
+
/** Add a user message */
|
|
11
|
+
addUserMessage: (content: string) => void;
|
|
12
|
+
/** Add a system message (for slash commands, etc.) */
|
|
13
|
+
addSystemMessage: (content: string) => void;
|
|
14
|
+
/** Mark agent as started */
|
|
15
|
+
startAgent: () => void;
|
|
16
|
+
/** Interrupt and reset to idle */
|
|
17
|
+
interrupt: () => void;
|
|
18
|
+
/** Clear all messages */
|
|
19
|
+
clearMessages: () => void;
|
|
20
|
+
}
|
|
21
|
+
/** Minimal agent event shape (matches @yuaone/core AgentEvent) */
|
|
22
|
+
export interface AgentEventLike {
|
|
23
|
+
kind: string;
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
}
|
|
26
|
+
export declare function useAgentStream(): UseAgentStreamReturn;
|
|
27
|
+
//# sourceMappingURL=useAgentStream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAgentStream.d.ts","sourceRoot":"","sources":["../../../src/tui/hooks/useAgentStream.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAA2B,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE7E,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,gBAAgB,CAAC;IACxB,sCAAsC;IACtC,WAAW,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IAC7C,yBAAyB;IACzB,cAAc,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,sDAAsD;IACtD,gBAAgB,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,4BAA4B;IAC5B,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,kCAAkC;IAClC,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,yBAAyB;IACzB,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED,kEAAkE;AAClE,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,wBAAgB,cAAc,IAAI,oBAAoB,CA+MrD"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useAgentStream — bridges AgentLoop events to TUI React state.
|
|
3
|
+
* Converts agent events into TUIMessage updates, tracks streaming state.
|
|
4
|
+
*/
|
|
5
|
+
import { useState, useCallback, useRef } from "react";
|
|
6
|
+
export function useAgentStream() {
|
|
7
|
+
const [messages, setMessages] = useState([]);
|
|
8
|
+
const [status, setStatus] = useState("idle");
|
|
9
|
+
const [streamBuffer, setStreamBuffer] = useState("");
|
|
10
|
+
const [tokensPerSecond, setTokensPerSecond] = useState(0);
|
|
11
|
+
const [totalTokensUsed, setTotalTokensUsed] = useState(0);
|
|
12
|
+
const currentMsgIdRef = useRef(null);
|
|
13
|
+
const tokenWindowRef = useRef([]);
|
|
14
|
+
const addUserMessage = useCallback((content) => {
|
|
15
|
+
const msg = {
|
|
16
|
+
id: `user-${Date.now()}`,
|
|
17
|
+
role: "user",
|
|
18
|
+
content,
|
|
19
|
+
timestamp: Date.now(),
|
|
20
|
+
};
|
|
21
|
+
setMessages((prev) => [...prev, msg]);
|
|
22
|
+
}, []);
|
|
23
|
+
const addSystemMessage = useCallback((content) => {
|
|
24
|
+
const msg = {
|
|
25
|
+
id: `sys-${Date.now()}`,
|
|
26
|
+
role: "system",
|
|
27
|
+
content,
|
|
28
|
+
timestamp: Date.now(),
|
|
29
|
+
};
|
|
30
|
+
setMessages((prev) => [...prev, msg]);
|
|
31
|
+
}, []);
|
|
32
|
+
const startAgent = useCallback(() => {
|
|
33
|
+
setStatus("thinking");
|
|
34
|
+
setStreamBuffer("");
|
|
35
|
+
const msgId = `assistant-${Date.now()}`;
|
|
36
|
+
currentMsgIdRef.current = msgId;
|
|
37
|
+
const msg = {
|
|
38
|
+
id: msgId,
|
|
39
|
+
role: "assistant",
|
|
40
|
+
content: "",
|
|
41
|
+
timestamp: Date.now(),
|
|
42
|
+
isStreaming: true,
|
|
43
|
+
toolCalls: [],
|
|
44
|
+
};
|
|
45
|
+
setMessages((prev) => [...prev, msg]);
|
|
46
|
+
}, []);
|
|
47
|
+
const updateCurrentMessage = useCallback((updater) => {
|
|
48
|
+
const id = currentMsgIdRef.current;
|
|
49
|
+
if (!id)
|
|
50
|
+
return;
|
|
51
|
+
setMessages((prev) => prev.map((m) => (m.id === id ? updater(m) : m)));
|
|
52
|
+
}, []);
|
|
53
|
+
const handleEvent = useCallback((event) => {
|
|
54
|
+
switch (event.kind) {
|
|
55
|
+
case "agent:thinking":
|
|
56
|
+
setStatus("thinking");
|
|
57
|
+
break;
|
|
58
|
+
case "agent:text_delta": {
|
|
59
|
+
const text = event.text;
|
|
60
|
+
setStreamBuffer((prev) => prev + text);
|
|
61
|
+
setStatus("streaming");
|
|
62
|
+
updateCurrentMessage((msg) => ({
|
|
63
|
+
...msg,
|
|
64
|
+
content: msg.content + text,
|
|
65
|
+
}));
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
case "agent:tool_call": {
|
|
69
|
+
setStatus("tool_running");
|
|
70
|
+
const tc = {
|
|
71
|
+
id: `tc-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
|
|
72
|
+
toolName: event.tool,
|
|
73
|
+
argsSummary: summarizeArgs(event.input),
|
|
74
|
+
status: "running",
|
|
75
|
+
isExpanded: false,
|
|
76
|
+
};
|
|
77
|
+
updateCurrentMessage((msg) => ({
|
|
78
|
+
...msg,
|
|
79
|
+
toolCalls: [...(msg.toolCalls ?? []), tc],
|
|
80
|
+
}));
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
case "agent:tool_result": {
|
|
84
|
+
const toolName = event.tool;
|
|
85
|
+
const output = event.output;
|
|
86
|
+
const durationMs = event.durationMs;
|
|
87
|
+
updateCurrentMessage((msg) => {
|
|
88
|
+
const toolCalls = [...(msg.toolCalls ?? [])];
|
|
89
|
+
// Find the last running tool call with this name
|
|
90
|
+
for (let i = toolCalls.length - 1; i >= 0; i--) {
|
|
91
|
+
if (toolCalls[i].toolName === toolName && toolCalls[i].status === "running") {
|
|
92
|
+
toolCalls[i] = {
|
|
93
|
+
...toolCalls[i],
|
|
94
|
+
status: "success",
|
|
95
|
+
duration: durationMs / 1000,
|
|
96
|
+
result: {
|
|
97
|
+
kind: detectResultKind(toolName, output),
|
|
98
|
+
content: output,
|
|
99
|
+
lineCount: output.split("\n").length,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return { ...msg, toolCalls };
|
|
106
|
+
});
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
case "agent:error": {
|
|
110
|
+
const errMsg = event.message;
|
|
111
|
+
updateCurrentMessage((msg) => ({
|
|
112
|
+
...msg,
|
|
113
|
+
content: msg.content + `\n\nError: ${errMsg}`,
|
|
114
|
+
isStreaming: false,
|
|
115
|
+
}));
|
|
116
|
+
setStatus("idle");
|
|
117
|
+
currentMsgIdRef.current = null;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
case "agent:completed": {
|
|
121
|
+
const summary = event.summary;
|
|
122
|
+
updateCurrentMessage((msg) => ({
|
|
123
|
+
...msg,
|
|
124
|
+
content: msg.content || summary,
|
|
125
|
+
isStreaming: false,
|
|
126
|
+
}));
|
|
127
|
+
setStatus("idle");
|
|
128
|
+
setStreamBuffer("");
|
|
129
|
+
currentMsgIdRef.current = null;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
case "agent:token_usage": {
|
|
133
|
+
const input = event.input;
|
|
134
|
+
const output = event.output;
|
|
135
|
+
const total = input + output;
|
|
136
|
+
setTotalTokensUsed((prev) => prev + total);
|
|
137
|
+
// Rolling 3-second window for tokens/sec
|
|
138
|
+
const now = Date.now();
|
|
139
|
+
tokenWindowRef.current.push({ time: now, tokens: total });
|
|
140
|
+
tokenWindowRef.current = tokenWindowRef.current.filter((e) => now - e.time < 3000);
|
|
141
|
+
const windowTokens = tokenWindowRef.current.reduce((s, e) => s + e.tokens, 0);
|
|
142
|
+
const windowMs = Math.max(1, now - (tokenWindowRef.current[0]?.time ?? now));
|
|
143
|
+
setTokensPerSecond(Math.round((windowTokens / windowMs) * 1000));
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
case "agent:approval_needed":
|
|
147
|
+
setStatus("awaiting_approval");
|
|
148
|
+
break;
|
|
149
|
+
default:
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
}, [updateCurrentMessage]);
|
|
153
|
+
const interrupt = useCallback(() => {
|
|
154
|
+
updateCurrentMessage((msg) => ({
|
|
155
|
+
...msg,
|
|
156
|
+
isStreaming: false,
|
|
157
|
+
content: msg.content + "\n\n[Interrupted]",
|
|
158
|
+
}));
|
|
159
|
+
setStatus("idle");
|
|
160
|
+
setStreamBuffer("");
|
|
161
|
+
currentMsgIdRef.current = null;
|
|
162
|
+
const sysMsg = {
|
|
163
|
+
id: `sys-${Date.now()}`,
|
|
164
|
+
role: "system",
|
|
165
|
+
content: "Agent interrupted.",
|
|
166
|
+
timestamp: Date.now(),
|
|
167
|
+
};
|
|
168
|
+
setMessages((prev) => [...prev, sysMsg]);
|
|
169
|
+
}, [updateCurrentMessage]);
|
|
170
|
+
const clearMessages = useCallback(() => {
|
|
171
|
+
setMessages([]);
|
|
172
|
+
setStreamBuffer("");
|
|
173
|
+
setStatus("idle");
|
|
174
|
+
currentMsgIdRef.current = null;
|
|
175
|
+
}, []);
|
|
176
|
+
const state = {
|
|
177
|
+
status,
|
|
178
|
+
streamBuffer,
|
|
179
|
+
messages,
|
|
180
|
+
tokensPerSecond,
|
|
181
|
+
totalTokensUsed,
|
|
182
|
+
};
|
|
183
|
+
return { state, handleEvent, addUserMessage, addSystemMessage, startAgent, interrupt, clearMessages };
|
|
184
|
+
}
|
|
185
|
+
function summarizeArgs(input) {
|
|
186
|
+
if (!input || typeof input !== "object")
|
|
187
|
+
return "";
|
|
188
|
+
const obj = input;
|
|
189
|
+
// Common patterns: file path, command, query
|
|
190
|
+
if (obj.path)
|
|
191
|
+
return String(obj.path);
|
|
192
|
+
if (obj.file_path)
|
|
193
|
+
return String(obj.file_path);
|
|
194
|
+
if (obj.command)
|
|
195
|
+
return String(obj.command).slice(0, 60);
|
|
196
|
+
if (obj.pattern)
|
|
197
|
+
return String(obj.pattern);
|
|
198
|
+
if (obj.query)
|
|
199
|
+
return String(obj.query).slice(0, 40);
|
|
200
|
+
return "";
|
|
201
|
+
}
|
|
202
|
+
function detectResultKind(toolName, _output) {
|
|
203
|
+
const name = toolName.toLowerCase();
|
|
204
|
+
if (name.includes("edit") || name.includes("diff"))
|
|
205
|
+
return "diff";
|
|
206
|
+
if (name.includes("bash") || name.includes("shell") || name.includes("exec"))
|
|
207
|
+
return "bash_output";
|
|
208
|
+
if (name.includes("read") || name.includes("file"))
|
|
209
|
+
return "file_content";
|
|
210
|
+
return "text";
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=useAgentStream.js.map
|