@vietor/easy-agent 0.7.3 → 0.7.5

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/tui/app.js CHANGED
@@ -34,6 +34,7 @@ function useThrottledText(frameMs) {
34
34
  }
35
35
  function useSessionStream(session) {
36
36
  const [runMetrics, setRunMetrics] = useState(INITIAL_RUN_METRICS);
37
+ const [totalTokens, setTotalTokens] = useState({ cacheInputTokens: 0, missInputTokens: 0, outputTokens: 0 });
37
38
  const streaming = useThrottledText(STREAM_FRAME_MS);
38
39
  const thinking = useThrottledText(STREAM_FRAME_MS);
39
40
  const [showThinking, setShowThinking] = useState(false);
@@ -56,18 +57,25 @@ function useSessionStream(session) {
56
57
  break;
57
58
  case "run_metrics":
58
59
  setRunMetrics(e);
60
+ if (!e.running) {
61
+ setTotalTokens((prev) => ({ cacheInputTokens: prev.cacheInputTokens + e.cacheInputTokens, missInputTokens: prev.missInputTokens + e.missInputTokens, outputTokens: prev.outputTokens + e.outputTokens }));
62
+ }
59
63
  break;
60
64
  }
61
65
  });
62
66
  return unsub;
63
67
  }, [session]);
64
- return { runMetrics, streaming, thinking, showThinking, setShowThinking };
68
+ const resetMetrics = () => {
69
+ setRunMetrics(INITIAL_RUN_METRICS);
70
+ setTotalTokens({ cacheInputTokens: 0, missInputTokens: 0, outputTokens: 0 });
71
+ };
72
+ return { runMetrics, totalTokens, streaming, thinking, showThinking, setShowThinking, resetMetrics };
65
73
  }
66
74
  export function App({ session, persist }) {
67
75
  const { exit } = useApp();
68
76
  const { columns } = useWindowSize();
69
77
  const view = useSyncExternalStore(session.subscribe, session.getSnapshot);
70
- const { runMetrics, streaming, thinking, showThinking, setShowThinking } = useSessionStream(session);
78
+ const { runMetrics, totalTokens, streaming, thinking, showThinking, setShowThinking, resetMetrics } = useSessionStream(session);
71
79
  const allCmds = useMemo(() => slashCommandInfos(session), [session]);
72
80
  const pendingQuestion = session.pendingQuestion;
73
81
  useInput((_input, key) => {
@@ -92,6 +100,8 @@ export function App({ session, persist }) {
92
100
  });
93
101
  async function handleCommand(name) {
94
102
  await executeSlashCommand(name, session, exit, persist);
103
+ if (name === "clear")
104
+ resetMetrics();
95
105
  }
96
106
  async function handlePrompt(text) {
97
107
  try {
@@ -109,10 +119,10 @@ export function App({ session, persist }) {
109
119
  }
110
120
  else {
111
121
  const spinnerLabel = streaming.text ? "replying" : "working";
112
- runningView = (_jsxs(_Fragment, { children: [thinking.text ? renderThinking(thinking.text, showThinking) : null, streaming.text ? (_jsx(Box, { marginTop: 1, paddingLeft: 1, paddingRight: 1, children: _jsx(Markdown, { children: streaming.text }) })) : null, _jsx(Box, { marginTop: 1, paddingLeft: 1, children: _jsx(Spinner, { label: spinnerLabel, thinkingElapsed: runMetrics.thinkingElapsed, replyElapsed: runMetrics.replyElapsed, inputTokens: runMetrics.inputTokens, outputTokens: runMetrics.outputTokens }) })] }));
122
+ runningView = (_jsxs(_Fragment, { children: [thinking.text ? renderThinking(thinking.text, showThinking) : null, streaming.text ? (_jsx(Box, { marginTop: 1, paddingLeft: 1, paddingRight: 1, children: _jsx(Markdown, { children: streaming.text }) })) : null, _jsx(Box, { marginTop: 1, paddingLeft: 1, children: _jsx(Spinner, { label: spinnerLabel, thinkingElapsed: runMetrics.thinkingElapsed, replyElapsed: runMetrics.replyElapsed, cacheInputTokens: runMetrics.cacheInputTokens, missInputTokens: runMetrics.missInputTokens, outputTokens: runMetrics.outputTokens }) })] }));
113
123
  }
114
124
  }
115
- return (_jsxs(Box, { width: columns, flexDirection: "column", children: [_jsx(AppHeader, { cwd: session.cwd, model: session.model, thinkingEffort: session.thinkingEffort }), view.timeline.length > 0 ? (_jsx(Box, { flexDirection: "column", paddingLeft: 1, paddingRight: 1, children: view.timeline.map((entry, i) => (_jsx(TimelineView, { entry: entry }, i))) })) : null, runningView, view.todos.length > 0 ? _jsx(TodoView, { todos: view.todos }) : null, !runMetrics.running ? (_jsx(PromptOrCommandInput, { commands: allCmds, onCommand: handleCommand, onPrompt: handlePrompt })) : null, _jsx(StatusBar, { contextTokens: session.contextTokens, contextLimit: session.contextLimit, running: runMetrics.running, questionPending: !!pendingQuestion, thinkingAvailable: !!thinking.text })] }));
125
+ return (_jsxs(Box, { width: columns, flexDirection: "column", children: [_jsx(AppHeader, { cwd: session.cwd, model: session.model, thinkingEffort: session.thinkingEffort }), view.timeline.length > 0 ? (_jsx(Box, { flexDirection: "column", paddingLeft: 1, paddingRight: 1, children: view.timeline.map((entry, i) => (_jsx(TimelineView, { entry: entry }, i))) })) : null, runningView, view.todos.length > 0 ? _jsx(TodoView, { todos: view.todos }) : null, !runMetrics.running ? (_jsx(PromptOrCommandInput, { commands: allCmds, onCommand: handleCommand, onPrompt: handlePrompt })) : null, _jsx(StatusBar, { contextTokens: session.contextTokens, contextLimit: session.contextLimit, running: runMetrics.running, questionPending: !!pendingQuestion, thinkingAvailable: !!thinking.text, cacheInputTokens: totalTokens.cacheInputTokens, missInputTokens: totalTokens.missInputTokens, outputTokens: totalTokens.outputTokens })] }));
116
126
  }
117
127
  function renderThinking(text, expanded) {
118
128
  const lines = text.split("\n");
@@ -3,11 +3,11 @@ import { useEffect, useState } from "react";
3
3
  import { Text } from "ink";
4
4
  import { formatCompactNumber, formatDuration } from "@vietor/agent-core/util";
5
5
  const SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
6
- export function Spinner({ label, thinkingElapsed, replyElapsed, inputTokens, outputTokens, }) {
6
+ export function Spinner({ label, thinkingElapsed, replyElapsed, cacheInputTokens, missInputTokens, outputTokens, }) {
7
7
  const [frame, setFrame] = useState(0);
8
8
  useEffect(() => {
9
9
  const id = setInterval(() => setFrame((f) => (f + 1) % SPINNER_FRAMES.length), 80);
10
10
  return () => clearInterval(id);
11
11
  }, []);
12
- return (_jsxs(Text, { children: [_jsx(Text, { color: "cyan", children: SPINNER_FRAMES[frame] }), _jsxs(Text, { children: [" ", label] }), _jsxs(Text, { dimColor: true, children: [" \u00B7 work ", formatDuration(thinkingElapsed), " \u00B7 reply ", formatDuration(replyElapsed), " \u00B7 \u2191", formatCompactNumber(inputTokens), " \u00B7 \u2193", formatCompactNumber(outputTokens)] })] }));
12
+ return (_jsxs(Text, { children: [_jsx(Text, { color: "cyan", children: SPINNER_FRAMES[frame] }), _jsxs(Text, { children: [" ", label] }), _jsxs(Text, { dimColor: true, children: [" \u00B7 work ", formatDuration(thinkingElapsed), " \u00B7 reply ", formatDuration(replyElapsed), " \u00B7 \u2191(", formatCompactNumber(cacheInputTokens), " / ", formatCompactNumber(missInputTokens), ") \u00B7 \u2193", formatCompactNumber(outputTokens)] })] }));
13
13
  }
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { memo } from "react";
3
3
  import { Box, Text, useWindowSize } from "ink";
4
4
  import { formatCompactNumber } from "@vietor/agent-core/util";
5
- export const StatusBar = memo(function StatusBar({ contextTokens, contextLimit, running, questionPending, thinkingAvailable }) {
5
+ export const StatusBar = memo(function StatusBar({ contextTokens, contextLimit, running, questionPending, thinkingAvailable, cacheInputTokens, missInputTokens, outputTokens }) {
6
6
  const { columns } = useWindowSize();
7
7
  const pct = Math.min(100, contextLimit > 0 ? Math.round((contextTokens / contextLimit) * 100) : 0);
8
8
  const filled = Math.round((pct / 100) * 10);
@@ -15,5 +15,5 @@ export const StatusBar = memo(function StatusBar({ contextTokens, contextLimit,
15
15
  hints = thinkingAvailable ? "esc stop · t thinking" : "esc stop";
16
16
  else
17
17
  hints = "/ commands";
18
- return (_jsxs(Box, { width: columns, paddingX: 1, flexDirection: "row", justifyContent: "space-between", borderStyle: "single", borderTop: true, borderBottom: false, borderLeft: false, borderRight: false, borderColor: "gray", children: [_jsxs(Text, { children: [_jsx(Text, { dimColor: true, children: `context ${formatCompactNumber(contextTokens)} ` }), _jsx(Text, { color: ctxColor, children: `▕${bar}▏ ${pct}%` })] }), _jsx(Text, { dimColor: true, children: hints })] }));
18
+ return (_jsxs(Box, { width: columns, paddingX: 1, flexDirection: "row", justifyContent: "space-between", borderStyle: "single", borderTop: true, borderBottom: false, borderLeft: false, borderRight: false, borderColor: "gray", children: [_jsxs(Box, { flexDirection: "row", children: [_jsxs(Text, { children: [_jsx(Text, { dimColor: true, children: `Context ${formatCompactNumber(contextTokens)} ` }), _jsx(Text, { color: ctxColor, children: `▕${bar}▏ ${pct}%` })] }), _jsxs(Text, { dimColor: true, children: [" Tokens \u2191(", formatCompactNumber(cacheInputTokens), " / ", formatCompactNumber(missInputTokens), ") \u00B7 \u2193", formatCompactNumber(outputTokens)] })] }), _jsx(Text, { dimColor: true, children: hints })] }));
19
19
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vietor/easy-agent",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -23,7 +23,7 @@
23
23
  "react": "^19.2.8",
24
24
  "string-width": "^8.2.2",
25
25
  "zod": "^4.4.3",
26
- "@vietor/agent-core": "0.7.3"
26
+ "@vietor/agent-core": "0.7.5"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/node": "^22.20.1",