@songtonyli/dsh-cli 0.1.29 → 0.1.30
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/README.md +1 -1
- package/bin/dsh.mjs +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-slots/package.json +2 -2
- package/node_modules/@deepseek-ai/dsh-tui-app/README.i18n.yaml +2 -2
- package/node_modules/@deepseek-ai/dsh-tui-app/README.md +3 -3
- package/node_modules/@deepseek-ai/dsh-tui-app/README.zh.md +3 -3
- package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +284 -35
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ workspace and no build step. Native packages that ship one build per platform
|
|
|
26
26
|
ripgrep, the PTY backend's addons, sharp, koffi, and the Landlock launcher — are
|
|
27
27
|
ordinary optional dependencies, so npm resolves the right one for your machine.
|
|
28
28
|
|
|
29
|
-
Requires Node `^22.19.0 || >=24.0.0`. Version 0.1.
|
|
29
|
+
Requires Node `^22.19.0 || >=24.0.0`. Version 0.1.30; `dsh --version`
|
|
30
30
|
also reports the harness build the package was assembled from.
|
|
31
31
|
|
|
32
32
|
## License
|
package/bin/dsh.mjs
CHANGED
|
@@ -18,7 +18,7 @@ const argv = process.argv.slice(2)
|
|
|
18
18
|
// version this package publishes. Reporting only one of the two would make an
|
|
19
19
|
// ordinary `npm install @songtonyli/dsh-cli@x` look like it installed something else.
|
|
20
20
|
if (argv.length === 1 && (argv[0] === '--version' || argv[0] === '-V')) {
|
|
21
|
-
console.log('@songtonyli/dsh-cli 0.1.
|
|
21
|
+
console.log('@songtonyli/dsh-cli 0.1.30 (deepseek-harness 0.1.6-alpha.2)')
|
|
22
22
|
process.exit(0)
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -160,7 +160,7 @@ window.__ModuleLoader__.load({
|
|
|
160
160
|
const SCROLLBAR_LINGER_MS = 2e3;
|
|
161
161
|
/** Format complete-build metadata for the local brand badge. */
|
|
162
162
|
function localBuildVersion() {
|
|
163
|
-
return `0.1.6-alpha.2-
|
|
163
|
+
return `0.1.6-alpha.2-34239dd` + ({}.DSH_CLIENT_GIT_DIRTY === "true" ? "-dirty" : "");
|
|
164
164
|
}
|
|
165
165
|
/** Each panel row subscribes only to its own selection state. */
|
|
166
166
|
function PanelRow({ id, label, wide, usePanelInfo, selectPanel, renderSlot }) {
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/react": "~18.3.1",
|
|
27
|
-
"@deepseek-ai/
|
|
28
|
-
"@deepseek-ai/
|
|
27
|
+
"@deepseek-ai/dsh-client-store": "^0.1.6-alpha.2",
|
|
28
|
+
"@deepseek-ai/cordis": "^4.0.2"
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
31
31
|
"lib/index.js",
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
3
|
# after editing either side, bring the other along and re-record with:
|
|
4
4
|
# pnpm run verify-translation-pairing --write packages/bundle/tui-app/README.md
|
|
5
|
-
README.md:
|
|
6
|
-
README.zh.md:
|
|
5
|
+
README.md: 6ca72d9a72b85bcc8de665c41bdeafd25d379632
|
|
6
|
+
README.zh.md: 4389467ff6efc4267033b3cb5353c568120e3e93
|
|
@@ -40,9 +40,9 @@ On quit the app prints `dsh: session <id> saved; resume with: dsh --profile tui
|
|
|
40
40
|
|
|
41
41
|
### The screen
|
|
42
42
|
|
|
43
|
-
The header names the session by its title once one is generated or set, with the id beside it. The transcript grows in the terminal's own scrollback: your prompts start with `›` (attachments listed under them), assistant reasoning is dim above the Markdown reply, and each tool call is a card with a status glyph, the tool name, the presenter headline, and a body folded to `toolPreviewLines` rows. A nonempty system prompt and each injected context — instructions, catalogs, snapshots, notices, relays, and recalls — draw as a dim `⬡` title over the first `contextPreviewLines` rows of their model-facing text, with each snapshot contribution named above its own rows; an empty system prompt and a compaction replacement are omitted. A tool card and a context block that carry more rows than they draw end on one marker: `… <n> more rows · Space expands` while the conversation's focus holds that block, and `… <n> more rows · Ctrl+O expands` otherwise. Fenced code in a reply, the file rows of a `read` card, and the changed rows of an `edit` or `write` diff card — with `+` additions marked green, `-` removals red, and source text behind those signs drawn in the language the file's extension names — use syntax colours from a theme the terminal's own background picks, light or dark; the grammar of a language loads on the first block that asks for it, so that block draws plain and is repainted in colour a moment later, and a language with no grammar here, a terminal that reports neither 24-bit nor 256 colours, and `codeHighlight: false` each draw every block plain. Headings, links, list markers, quotes, and inline code share one cool dark-mode scale — a pale cyan, a deeper blue, and dim — so a reply sits beside a highlighted fence without contrasting hues. Streamed reply text fades in and every word keeps its own clock: a word enters near the terminal's background color and brightens to the color it settles in over `streamFadeSteps` ticks of `streamFadeStepMs` each, so a fast stream leaves a longer trail of brightening words rather than a darker one. Streamed reasoning and a tool card float out over the same duration: they appear at a lifted color and recede to the dim italic or palette colors they settle in; a card redrawn from persisted history carries no fade, and text that has settled is never dimmed again.
|
|
43
|
+
The header names the session by its title once one is generated or set, with the id beside it. The transcript grows in the terminal's own scrollback: your prompts start with `›` (attachments listed under them), assistant reasoning is dim above the Markdown reply, and each tool call is a card with a status glyph, the tool name, the presenter headline, a loading row while it runs, and a body folded to `toolPreviewLines` rows. The card appears when the model starts the call; the result rows float out when the tool answers. A nonempty system prompt and each injected context — instructions, catalogs, snapshots, notices, relays, and recalls — draw as a dim `⬡` title over the first `contextPreviewLines` rows of their model-facing text, with each snapshot contribution named above its own rows; an empty system prompt and a compaction replacement are omitted. A tool card and a context block that carry more rows than they draw end on one marker: `… <n> more rows · Space expands` while the conversation's focus holds that block, and `… <n> more rows · Ctrl+O expands` otherwise. Fenced code in a reply, the file rows of a `read` card, and the changed rows of an `edit` or `write` diff card — with `+` additions marked green, `-` removals red, and source text behind those signs drawn in the language the file's extension names — use syntax colours from a theme the terminal's own background picks, light or dark; the grammar of a language loads on the first block that asks for it, so that block draws plain and is repainted in colour a moment later, and a language with no grammar here, a terminal that reports neither 24-bit nor 256 colours, and `codeHighlight: false` each draw every block plain. Headings, links, list markers, quotes, and inline code share one cool dark-mode scale — a pale cyan, a deeper blue, and dim — so a reply sits beside a highlighted fence without contrasting hues. Streamed reply text fades in and every word keeps its own clock: a word enters near the terminal's background color and brightens to the color it settles in over `streamFadeSteps` ticks of `streamFadeStepMs` each, so a fast stream leaves a longer trail of brightening words rather than a darker one. Streamed reasoning and a tool card float out over the same duration: they appear at a lifted color and recede to the dim italic or palette colors they settle in; a card redrawn from persisted history carries no fade, and text that has settled is never dimmed again.
|
|
44
44
|
|
|
45
|
-
Below the transcript sit a spinner while the agent works, any open prompt, a boxed follow-ups list while messages wait, the editor, the subagent panel, and the footer: a status bar that, unfocused, is one line built from both ends inward. The editor's caret is the terminal's own blinking bar: the app asks for that shape at start, gives your default back on quit, and draws no caret at all while the status bar or the panel holds the keyboard. The model is anchored at the left edge and is never dropped — past 20 columns it falls back to the bare model name, and only a label still too wide for that is ellipsized — and the two keys that leave the input are anchored at the right edge as `Shift+↑ read · Shift+↓ status`, narrowing to `Shift+↑↓ nav` and dropped below 40 columns. The key facts fill whatever middle is left, in bar order: effort (`effort default` when the selection leaves reasoning to the model), the running turn's elapsed time, the context window percentage, the todo counts, and the workspace path (shortened with `~` and `…/` when long). Every segment that middle cannot hold folds into a trailing `+N`, together with the segments the unfocused line never draws — the permission preset,
|
|
45
|
+
Below the transcript sit a spinner while the agent works — its label carries live `↑` send and `↓` receive tokens for the current model call, as compact `k` / `M` / `B` counts, growing as the stream arrives and settling on the provider usage chunk — any open prompt, a boxed follow-ups list while messages wait, the editor, the subagent panel, and the footer: a status bar that, unfocused, is one line built from both ends inward. The editor's caret is the terminal's own blinking bar: the app asks for that shape at start, gives your default back on quit, and draws no caret at all while the status bar or the panel holds the keyboard. The model is anchored at the left edge and is never dropped — past 20 columns it falls back to the bare model name, and only a label still too wide for that is ellipsized — and the two keys that leave the input are anchored at the right edge as `Shift+↑ read · Shift+↓ status`, narrowing to `Shift+↑↓ nav` and dropped below 40 columns. The key facts fill whatever middle is left, in bar order: effort (`effort default` when the selection leaves reasoning to the model), the running turn's elapsed time, the context window percentage, the todo counts, and the workspace path (shortened with `~` and `…/` when long). Every segment that middle cannot hold folds into a trailing `+N`, together with the segments the unfocused line never draws — the permission preset, token usage (session totals plus the in-flight call), the goal and plan-mode markers from the projection seam, and the count of pending attachments. Compaction and model-request retries appear as notices, the same facts the browser's markers carry.
|
|
46
46
|
|
|
47
47
|
While the keyboard walks the conversation a framed inspector is docked directly above the editor, and the frame is the mode: it is drawn exactly while the conversation holds the keyboard. Its top rule carries an inverse ` ● READ ` chip and the focused section's heading — the section's position among the navigable blocks, the turn it belongs to, and what the section is — as in `╭ ● READ ─ 3/12 · turn 2 · bash git status · result ─╮`. Under it the block's parts draw as a numbered wrapping strip like `← 1 call · [2 result] →` when the block has more than one, the held label bracketed as well as accented so the selection is legible with no color at all; then the section's own source rows, each prefixed with `│ ` and wrapped two columns narrower, folded at `focusPreviewLines` for every section kind — a system prompt and an injected context included — with `… <n> more rows · Ctrl+G reads it` under them. The bottom rule carries the keys the conversation answers, `↑↓ sections · ←→ parts · Space folds · Ctrl+G reader · Esc input`, narrowed to `↑↓ ←→ · Space folds · Esc input` and then to `Esc input` as the terminal loses columns.
|
|
48
48
|
|
|
@@ -242,7 +242,7 @@ The runner awaits the complete application (`ctx.get('loader')?.await()`) and bu
|
|
|
242
242
|
|
|
243
243
|
### Rendering model
|
|
244
244
|
|
|
245
|
-
Durable facts come from the session log: `system/message` (a nonempty prompt draws in full; an empty rendering is omitted), `user/message` (own submissions are drawn once and their echo skipped by message id; injected context — instructions, catalogs, snapshots, notices, relays, recalls, and undeclared forms — draws in full as a dim `⬡` row, a snapshot as one named contribution per part; compaction replacements and tool or model sources are omitted), `assistant/message` (which replaces the streamed block with the committed text and folds usage into the footer), `tool/call` and `tool/result` (drawn through the tool's `presentCall` and `presentResult` views when it declares them, with a raw-argument and raw-result fallback), `turn/end` notices, `workspace/changes` (one notice with the turn's file and line counts while the Host still holds the summary), `session/title` (header), `permission/preset` (footer), and `todo/write` under the enclosing `turn/start` (the turns one todo item's page reports; the list carries no per-item identity, so a reworded item counts as a new one). Live incrementality comes from `agent/assistant-stream` text and
|
|
245
|
+
Durable facts come from the session log: `system/message` (a nonempty prompt draws in full; an empty rendering is omitted), `user/message` (own submissions are drawn once and their echo skipped by message id; injected context — instructions, catalogs, snapshots, notices, relays, recalls, and undeclared forms — draws in full as a dim `⬡` row, a snapshot as one named contribution per part; compaction replacements and tool or model sources are omitted), `assistant/message` (which replaces the streamed block with the committed text and folds usage into the footer), `tool/call` and `tool/result` (drawn through the tool's `presentCall` and `presentResult` views when it declares them, with a raw-argument and raw-result fallback), `turn/end` notices, `workspace/changes` (one notice with the turn's file and line counts while the Host still holds the summary), `session/title` (header), `permission/preset` (footer), and `todo/write` under the enclosing `turn/start` (the turns one todo item's page reports; the list carries no per-item identity, so a reworded item counts as a new one). Live incrementality comes from `agent/assistant-stream` text, reasoning, tool-call, and usage deltas: a card is mounted when the model names the tool, and the working spinner carries live `↑` send and `↓` receive for that call. Session facts outside the log come from the same services the browser reads: `sessionTitle`, `permissionPresets`, `sessionQuery` for the picker, `/deliverables`, and subagent details, `sessionProjections` for the footer, `/status`, `/todos`, and `/outline`, `fileReferences` and `sessionReferenceResolver` for `@` completion, `attachments`, `skills`, `authorization`, `settings`, `subagents`, and the Loader's entries for `/plugins`. Modal prompts are process-local presentation and are never logged.
|
|
246
246
|
|
|
247
247
|
### Patch surface over base
|
|
248
248
|
|
|
@@ -40,9 +40,9 @@ dsh tui --no-open # print sign-in URLs without opening a
|
|
|
40
40
|
|
|
41
41
|
### 屏幕布局
|
|
42
42
|
|
|
43
|
-
页眉在标题生成或设置后以标题命名会话,并在旁边显示 id。对话记录在终端自身的回滚区中增长:你的提示以 `›` 开头(附件列在其下),assistant 的推理以暗色显示在 Markdown
|
|
43
|
+
页眉在标题生成或设置后以标题命名会话,并在旁边显示 id。对话记录在终端自身的回滚区中增长:你的提示以 `›` 开头(附件列在其下),assistant 的推理以暗色显示在 Markdown 回复上方,每次工具调用是一张卡片,含状态符号、工具名、呈现器标题、运行中的一行加载标记,以及折叠到 `toolPreviewLines` 行的正文。卡片在模型开始调用时出现;结果行在工具回答后浮出。非空的系统提示词与每一条注入的上下文——instructions、catalogs、snapshots、notices、relays 与 recalls——绘制为暗色 `⬡` 标题,其下是面向模型文本的前 `contextPreviewLines` 行,快照的每一份贡献具名写在其自身各行上方;空的系统提示词与压缩替换则省略。承载的行数多于其绘制行数的工具卡片与上下文块,结尾都是同一条标记:该块被对话记录的焦点持有时为 `… <n> more rows · Space expands`,否则为 `… <n> more rows · Ctrl+O expands`。回复中的围栏代码、`read` 卡片的文件行,以及 `edit` 或 `write` diff 卡片的变更行——其中 `+` 新增项标为绿色、`-` 删除项标为红色,符号后的源文本按文件扩展名对应的语言绘制——都使用语法高亮,配色主题由终端自身的背景在明暗之间选定;某种语言的语法会在第一个用到它的代码块出现时才加载,因此该块先以纯文本绘制、随后被重绘为彩色;这里没有对应语法的语言、既不支持 24 位也不支持 256 色的终端,以及 `codeHighlight: false`,都会把每个代码块画成纯文本。标题、链接、列表标记、引用与行内代码共用一套暗色冷色阶——浅青、更深的蓝与暗色——因此回复能挨着高亮围栏,而不靠对比色相。流式回复文字会淡入,而且每个词各走各的时钟:一个词以接近终端背景色的亮度出现,并经 `streamFadeSteps` 次、每次 `streamFadeStepMs` 提亮到它最终稳定的颜色,因此流得更快只会留下更长的一串正在提亮的词,而不会更暗。流式推理与工具卡片在同一时长内浮出:它们以抬高的颜色出现,再退回到稳定时的暗色斜体或调色板颜色;从持久化历史重绘的卡片不带淡入,已经稳定下来的文字也不会再被调暗。
|
|
44
44
|
|
|
45
|
-
对话记录下方依次是 agent
|
|
45
|
+
对话记录下方依次是 agent 工作时的旋转指示——其标签带着当前这次模型调用的实时 `↑` 发送与 `↓` 接收 token,以紧凑的 `k` / `M` / `B` 计数,随数据流入增长,并在提供方的 usage 块到达后落定——任何打开的提示、有消息等待时的带框 follow-ups 列表、编辑器、子 agent 面板,以及页脚:未聚焦时是一行由两端向内构建的状态栏。编辑器的光标是终端自身的闪烁竖条:应用在启动时请求这一形状,退出时把你的默认形状还回去,而状态栏或面板持有键盘期间完全不绘制光标。模型锚定在左端且永不丢弃——超过 20 列时退回到裸模型名,只有仍然过宽的标签才会被省略号截断——离开编辑器的那两个按键则锚定在右端,写作 `Shift+↑ read · Shift+↓ status`,窄到一定程度收缩为 `Shift+↑↓ nav`,不足 40 列时整体丢弃。关键事实填满剩下的中间部分,按状态栏顺序排列:推理强度(选择把推理交给模型时标为 `effort default`)、进行中轮次的已用时间、上下文窗口百分比、todo 计数,以及 workspace 路径(过长时以 `~` 与 `…/` 缩短)。中间部分容纳不下的每个分段都折进末尾的 `+N`,未聚焦行从不绘制的那些分段也一并折入——权限预设、token 用量(会话合计加上进行中的这次调用)、来自投影接缝的目标与计划模式标记,以及待发送附件的数量。压缩与模型请求重试以通知形式出现,与浏览器标记承载的事实相同。
|
|
46
46
|
|
|
47
47
|
键盘在对话记录中移动时,编辑器正上方停靠着一个带边框的检视面板,边框即模式:它恰好在对话记录持有键盘时绘制。其顶边线带有一个反白的 ` ● READ ` 徽标与当前聚焦小节的标题——该小节在可导航块中的位置、所属轮次,以及这是哪一种小节——例如 `╭ ● READ ─ 3/12 · turn 2 · bash git status · result ─╮`。其下在块含多个部分时,把这些部分绘制成形如 `← 1 call · [2 result] →` 的带编号、会折行的选择行,被持有的标签除强调色外还加上方括号,因此完全无颜色时选择仍然可读;再往下是该小节自身的源文本行,每行以 `│ ` 起头并按窄两列换行,对每一种小节——含系统提示词与注入的上下文——都折叠到 `focusPreviewLines` 行,其下写出 `… <n> more rows · Ctrl+G reads it`。底边线列出对话记录所应答的按键 `↑↓ sections · ←→ parts · Space folds · Ctrl+G reader · Esc input`,随着终端列数减少收缩为 `↑↓ ←→ · Space folds · Esc input`,再收缩为 `Esc input`。
|
|
48
48
|
|
|
@@ -242,7 +242,7 @@ runner 等待完整应用就绪(`ctx.get('loader')?.await()`),并在核心
|
|
|
242
242
|
|
|
243
243
|
### 渲染模型
|
|
244
244
|
|
|
245
|
-
持久事实来自会话日志:`system/message`(非空提示词完整画出;空的绘制则省略)、`user/message`(自己提交的消息只绘制一次,其回显按消息 id 跳过;注入的上下文——instructions、catalogs、snapshots、notices、relays、recalls 以及未声明的形式——以暗色 `⬡` 行完整画出,快照按具名贡献各成一部分;压缩替换以及工具或模型来源则省略)、`assistant/message`(用已提交文本替换流式块,并把用量折入页脚)、`tool/call` 与 `tool/result`(工具声明 `presentCall` 与 `presentResult` 视图时据此绘制,否则回退到原始参数与原始结果)、`turn/end` 通知、`workspace/changes`(在 Host 仍保存摘要时,以一行通知给出该轮的文件数与行数)、`session/title`(页眉)、`permission/preset`(页脚),以及所属 `turn/start` 之下的 `todo/write`(某条 todo 的详情页所报告的轮次;该列表不带逐条标识,因此改写措辞的条目算作新条目)。实时增量来自 `agent/assistant-stream`
|
|
245
|
+
持久事实来自会话日志:`system/message`(非空提示词完整画出;空的绘制则省略)、`user/message`(自己提交的消息只绘制一次,其回显按消息 id 跳过;注入的上下文——instructions、catalogs、snapshots、notices、relays、recalls 以及未声明的形式——以暗色 `⬡` 行完整画出,快照按具名贡献各成一部分;压缩替换以及工具或模型来源则省略)、`assistant/message`(用已提交文本替换流式块,并把用量折入页脚)、`tool/call` 与 `tool/result`(工具声明 `presentCall` 与 `presentResult` 视图时据此绘制,否则回退到原始参数与原始结果)、`turn/end` 通知、`workspace/changes`(在 Host 仍保存摘要时,以一行通知给出该轮的文件数与行数)、`session/title`(页眉)、`permission/preset`(页脚),以及所属 `turn/start` 之下的 `todo/write`(某条 todo 的详情页所报告的轮次;该列表不带逐条标识,因此改写措辞的条目算作新条目)。实时增量来自 `agent/assistant-stream` 的文本、推理、工具调用与用量增量:模型一报出工具名就挂上卡片,工作时的旋转指示带着该次调用的实时 `↑` 发送与 `↓` 接收。日志之外的会话事实来自浏览器读取的同一批服务:`sessionTitle`、`permissionPresets`、供选择器、`/deliverables` 与子 agent 详情使用的 `sessionQuery`、供页脚、`/status`、`/todos` 与 `/outline` 使用的 `sessionProjections`、供 `@` 补全使用的 `fileReferences` 与 `sessionReferenceResolver`、`attachments`、`skills`、`authorization`、`settings`、`subagents`,以及供 `/plugins` 使用的 Loader 条目。模态提示是进程本地的呈现,从不写入日志。
|
|
246
246
|
|
|
247
247
|
### 基于 base 的 patch 面
|
|
248
248
|
|
|
@@ -345,14 +345,26 @@ function contentText(blocks) {
|
|
|
345
345
|
}).filter((part) => part !== "").join("\n");
|
|
346
346
|
}
|
|
347
347
|
/**
|
|
348
|
-
* Compact token count: `950`, `1.2k`,
|
|
348
|
+
* Compact token count with a thousands/millions/billions unit: `950`, `1.2k`,
|
|
349
|
+
* `12.3k`, `3.4M`, `1.2B`. A trailing `.0` is dropped so `1000` reads `1k`.
|
|
349
350
|
* @param count - a non-negative token count.
|
|
350
351
|
* @returns the formatted count.
|
|
351
352
|
*/
|
|
352
353
|
function formatTokens(count) {
|
|
353
354
|
if (count < 1e3) return String(count);
|
|
354
|
-
if (count < 1e6) return
|
|
355
|
-
return
|
|
355
|
+
if (count < 1e6) return formatScaled(count / 1e3, "k");
|
|
356
|
+
if (count < 1e9) return formatScaled(count / 1e6, "M");
|
|
357
|
+
return formatScaled(count / 1e9, "B");
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* One decimal place and a unit letter, dropping a trailing `.0`.
|
|
361
|
+
* @param value - the count already divided by the unit's base.
|
|
362
|
+
* @param unit - `k`, `M`, or `B`.
|
|
363
|
+
* @returns the compact count.
|
|
364
|
+
*/
|
|
365
|
+
function formatScaled(value, unit) {
|
|
366
|
+
const fixed = value.toFixed(1);
|
|
367
|
+
return `${fixed.endsWith(".0") ? fixed.slice(0, -2) : fixed}${unit}`;
|
|
356
368
|
}
|
|
357
369
|
/**
|
|
358
370
|
* Compact elapsed time for the live counters: `0s`, `8s`, `1m12s`, `1h04m`,
|
|
@@ -391,6 +403,59 @@ const EMPTY_USAGE = {
|
|
|
391
403
|
cacheReadTokens: 0,
|
|
392
404
|
lastInputTokens: 0
|
|
393
405
|
};
|
|
406
|
+
/** Characters treated as one token when the provider has not yet reported usage. */
|
|
407
|
+
const CHARS_PER_TOKEN = 4;
|
|
408
|
+
/**
|
|
409
|
+
* Approximate a token count from streamed character length, the same 4-chars
|
|
410
|
+
* rule the Cursor adapter uses when a provider omits prompt usage.
|
|
411
|
+
* @param chars - non-negative character count; a negative value counts as 0.
|
|
412
|
+
* @returns `ceil(chars / 4)`.
|
|
413
|
+
*/
|
|
414
|
+
function estimateTokens(chars) {
|
|
415
|
+
return Math.ceil(Math.max(0, chars) / CHARS_PER_TOKEN);
|
|
416
|
+
}
|
|
417
|
+
/** Prompt tokens occupying the context window: uncached input plus cache read. */
|
|
418
|
+
function promptTokens(usage) {
|
|
419
|
+
return usage.inputTokens + (usage.cacheReadTokens ?? 0);
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Billed prompt tokens of one usage record: uncached input plus cache read
|
|
423
|
+
* and cache write.
|
|
424
|
+
* @param usage - one model call's usage.
|
|
425
|
+
* @returns the billed send count.
|
|
426
|
+
*/
|
|
427
|
+
function billedInputTokens(usage) {
|
|
428
|
+
return promptTokens(usage) + (usage.cacheWriteTokens ?? 0);
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Fold an in-flight model call into the session totals for the footer.
|
|
432
|
+
* @param totals - committed totals so far.
|
|
433
|
+
* @param live - the current call; absent leaves `totals` unchanged.
|
|
434
|
+
* @returns the totals the footer should draw right now.
|
|
435
|
+
*/
|
|
436
|
+
function withLiveUsage(totals, live) {
|
|
437
|
+
if (live === void 0) return totals;
|
|
438
|
+
const prompt = promptTokens(live);
|
|
439
|
+
return {
|
|
440
|
+
inputTokens: totals.inputTokens + live.inputTokens,
|
|
441
|
+
outputTokens: totals.outputTokens + live.outputTokens,
|
|
442
|
+
cacheReadTokens: totals.cacheReadTokens + (live.cacheReadTokens ?? 0),
|
|
443
|
+
lastInputTokens: prompt > 0 ? prompt : totals.lastInputTokens
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* The ↑send ↓receive suffix the working spinner draws for the current call.
|
|
448
|
+
* @param usage - the in-flight call; absent or zero draws nothing.
|
|
449
|
+
* @returns the suffix without a leading space, or the empty string.
|
|
450
|
+
*/
|
|
451
|
+
function formatLiveUsage(usage) {
|
|
452
|
+
if (usage === void 0) return "";
|
|
453
|
+
const send = billedInputTokens(usage);
|
|
454
|
+
const parts = [];
|
|
455
|
+
if (send > 0) parts.push(`↑${formatTokens(send)}`);
|
|
456
|
+
if (usage.outputTokens > 0) parts.push(`↓${formatTokens(usage.outputTokens)}`);
|
|
457
|
+
return parts.length === 0 ? "" : `${parts.join(" ")} tokens`;
|
|
458
|
+
}
|
|
394
459
|
/**
|
|
395
460
|
* Fold one committed usage record into the totals.
|
|
396
461
|
* @param totals - the totals so far.
|
|
@@ -402,7 +467,7 @@ function addUsage(totals, usage) {
|
|
|
402
467
|
inputTokens: totals.inputTokens + usage.inputTokens,
|
|
403
468
|
outputTokens: totals.outputTokens + usage.outputTokens,
|
|
404
469
|
cacheReadTokens: totals.cacheReadTokens + (usage.cacheReadTokens ?? 0),
|
|
405
|
-
lastInputTokens:
|
|
470
|
+
lastInputTokens: promptTokens(usage)
|
|
406
471
|
};
|
|
407
472
|
}
|
|
408
473
|
/**
|
|
@@ -3047,13 +3112,13 @@ var AssistantBlock = class {
|
|
|
3047
3112
|
* A tool call card: status glyph, tool name, headline, then a foldable body.
|
|
3048
3113
|
*
|
|
3049
3114
|
* The card arrives in two pieces, and each floats out on its own: the header
|
|
3050
|
-
* and the call rows when the
|
|
3051
|
-
*
|
|
3115
|
+
* and the call rows when the model starts the call (a stream delta, or the
|
|
3116
|
+
* logged `tool/call`), the result rows when the tool answers. While it runs
|
|
3117
|
+
* the body carries {@link TOOL_RUNNING_ROW} in place of a result. A card
|
|
3118
|
+
* rebuilt from history carries neither fade.
|
|
3052
3119
|
*/
|
|
3053
3120
|
var ToolBlock = class {
|
|
3054
3121
|
theme;
|
|
3055
|
-
name;
|
|
3056
|
-
call;
|
|
3057
3122
|
turn;
|
|
3058
3123
|
navigable = true;
|
|
3059
3124
|
blockKind = "tool";
|
|
@@ -3073,13 +3138,19 @@ var ToolBlock = class {
|
|
|
3073
3138
|
highlightLevel = 0;
|
|
3074
3139
|
/** The coloured, folded, wrapped body, by width, fold, focus, status, and result. */
|
|
3075
3140
|
drawn = new LastDrawn();
|
|
3076
|
-
/** Counts every result the card was given. */
|
|
3141
|
+
/** Counts every call or result the card was given. */
|
|
3077
3142
|
revision = 0;
|
|
3143
|
+
toolName;
|
|
3144
|
+
call;
|
|
3078
3145
|
constructor(theme, name, call, turn) {
|
|
3079
3146
|
this.theme = theme;
|
|
3080
|
-
this.name = name;
|
|
3081
|
-
this.call = call;
|
|
3082
3147
|
this.turn = turn;
|
|
3148
|
+
this.toolName = name;
|
|
3149
|
+
this.call = call;
|
|
3150
|
+
}
|
|
3151
|
+
/** The tool the model called. */
|
|
3152
|
+
get name() {
|
|
3153
|
+
return this.toolName;
|
|
3083
3154
|
}
|
|
3084
3155
|
/** The card headline, as the section heading names this call. */
|
|
3085
3156
|
get title() {
|
|
@@ -3111,6 +3182,17 @@ var ToolBlock = class {
|
|
|
3111
3182
|
this.highlightLevel = level;
|
|
3112
3183
|
}
|
|
3113
3184
|
/**
|
|
3185
|
+
* Replace the call half as streamed arguments arrive or the logged call
|
|
3186
|
+
* confirms them.
|
|
3187
|
+
* @param name - the tool the model called.
|
|
3188
|
+
* @param call - the headline and rows for those arguments.
|
|
3189
|
+
*/
|
|
3190
|
+
setCall(name, call) {
|
|
3191
|
+
this.toolName = name;
|
|
3192
|
+
this.call = call;
|
|
3193
|
+
this.revision += 1;
|
|
3194
|
+
}
|
|
3195
|
+
/**
|
|
3114
3196
|
* Draw the header and the call rows through `fade` until it settles.
|
|
3115
3197
|
* @param fade - the level and drawing settings of this card's own fade.
|
|
3116
3198
|
*/
|
|
@@ -3204,12 +3286,21 @@ var ToolBlock = class {
|
|
|
3204
3286
|
*/
|
|
3205
3287
|
layout(outer, marked) {
|
|
3206
3288
|
const palette = this.theme.palette;
|
|
3207
|
-
const header = `${this.status === "running" ? palette.warning("●") : this.status === "done" ? palette.success("●") : palette.error("●")} ${palette.bold(this.
|
|
3208
|
-
const
|
|
3209
|
-
const
|
|
3289
|
+
const header = `${this.status === "running" ? palette.warning("●") : this.status === "done" ? palette.success("●") : palette.error("●")} ${palette.bold(this.toolName)}${this.call.title === "" ? "" : ` ${palette.dim(this.call.title)}`}`;
|
|
3290
|
+
const loading = this.status === "running" ? ["…"] : [];
|
|
3291
|
+
const body = [
|
|
3292
|
+
...this.call.lines,
|
|
3293
|
+
...loading,
|
|
3294
|
+
...this.resultLines
|
|
3295
|
+
];
|
|
3296
|
+
const code = this.call.code === void 0 && this.resultCode === void 0 ? void 0 : [
|
|
3297
|
+
...this.call.code ?? new Array(this.call.lines.length).fill(void 0),
|
|
3298
|
+
...new Array(loading.length).fill(void 0),
|
|
3299
|
+
...this.resultCode ?? new Array(this.resultLines.length).fill(void 0)
|
|
3300
|
+
];
|
|
3210
3301
|
const kept = this.expanded ? body : foldRows(body, this.theme.toolPreviewLines, (hidden) => foldMarker(hidden, marked ? "marked" : "transcript"));
|
|
3211
3302
|
const shown = paintDiffRows(paintCodeRows(kept, code, this.theme.codeHighlight), kept, palette);
|
|
3212
|
-
const callCount = Math.min(this.call.lines.length, shown.length);
|
|
3303
|
+
const callCount = Math.min(this.call.lines.length + loading.length, shown.length);
|
|
3213
3304
|
const inner = Math.max(1, outer - 4);
|
|
3214
3305
|
const rows = (lines) => lines.flatMap((line) => wrapTextWithAnsi(line, inner).map((part) => ` ${palette.dim("│")} ${part}`));
|
|
3215
3306
|
const call = [...wrapTextWithAnsi(header, outer), ...rows(shown.slice(0, callCount))];
|
|
@@ -8580,6 +8671,10 @@ var TuiApp = class {
|
|
|
8580
8671
|
theme;
|
|
8581
8672
|
toolBlocks = /* @__PURE__ */ new Map();
|
|
8582
8673
|
toolArguments = /* @__PURE__ */ new Map();
|
|
8674
|
+
/** Raw argument text accumulated from `tool-call-delta` chunks, keyed by call id. */
|
|
8675
|
+
toolStreamArgs = /* @__PURE__ */ new Map();
|
|
8676
|
+
/** Cards mounted from the live stream that no logged `tool/call` has confirmed yet. */
|
|
8677
|
+
unconfirmedTools = /* @__PURE__ */ new Map();
|
|
8583
8678
|
submittedIds = /* @__PURE__ */ new Set();
|
|
8584
8679
|
disposers = [];
|
|
8585
8680
|
/** Turn facts of the bound session's todo lines, keyed by content. */
|
|
@@ -8679,6 +8774,14 @@ var TuiApp = class {
|
|
|
8679
8774
|
/** Serializes `/attach` reads so pending attachments keep the typed order. */
|
|
8680
8775
|
attaching = Promise.resolve();
|
|
8681
8776
|
usage = EMPTY_USAGE;
|
|
8777
|
+
/** The in-flight model call's tokens, shown on the spinner and in the footer. */
|
|
8778
|
+
liveUsage;
|
|
8779
|
+
/** Streamed characters of the current call, used until a usage chunk arrives. */
|
|
8780
|
+
streamedChars = 0;
|
|
8781
|
+
/** Whether {@link TuiApp.liveUsage} came from a provider `usage` chunk. */
|
|
8782
|
+
usageExact = false;
|
|
8783
|
+
/** Spinner label without the live ↑↓ suffix (`thinking`, `calling read`, …). */
|
|
8784
|
+
loaderActivity = "thinking";
|
|
8682
8785
|
lastCtrlC = 0;
|
|
8683
8786
|
stopped = false;
|
|
8684
8787
|
constructor(deps) {
|
|
@@ -8876,6 +8979,8 @@ var TuiApp = class {
|
|
|
8876
8979
|
this.chat.clear();
|
|
8877
8980
|
this.toolBlocks.clear();
|
|
8878
8981
|
this.toolArguments.clear();
|
|
8982
|
+
this.toolStreamArgs.clear();
|
|
8983
|
+
this.unconfirmedTools.clear();
|
|
8879
8984
|
this.submittedIds.clear();
|
|
8880
8985
|
this.todoTurns.clear();
|
|
8881
8986
|
this.turn = 0;
|
|
@@ -8885,6 +8990,7 @@ var TuiApp = class {
|
|
|
8885
8990
|
this.endFade();
|
|
8886
8991
|
this.blockFades.clear();
|
|
8887
8992
|
this.usage = EMPTY_USAGE;
|
|
8993
|
+
this.clearLiveUsage();
|
|
8888
8994
|
this.pending = [];
|
|
8889
8995
|
this.queueView = [];
|
|
8890
8996
|
this.queueSelection = void 0;
|
|
@@ -8989,9 +9095,12 @@ var TuiApp = class {
|
|
|
8989
9095
|
this.statusSlot.addChild(this.loader);
|
|
8990
9096
|
this.loader.start();
|
|
8991
9097
|
}
|
|
9098
|
+
this.refreshLoader();
|
|
8992
9099
|
} else if (this.statusSlot.children.length > 0) {
|
|
8993
9100
|
this.loader.stop();
|
|
8994
9101
|
this.statusSlot.removeChild(this.loader);
|
|
9102
|
+
this.loaderActivity = "thinking";
|
|
9103
|
+
this.clearLiveUsage();
|
|
8995
9104
|
this.loader.setMessage("thinking");
|
|
8996
9105
|
}
|
|
8997
9106
|
this.tui.requestRender();
|
|
@@ -9018,7 +9127,7 @@ var TuiApp = class {
|
|
|
9018
9127
|
queuedNextTurn: inbox.nextTurn.length,
|
|
9019
9128
|
queuedNextStep: inbox.nextStep.length
|
|
9020
9129
|
} },
|
|
9021
|
-
usage: formatUsage(this.usage),
|
|
9130
|
+
usage: formatUsage(withLiveUsage(this.usage, this.liveUsage)),
|
|
9022
9131
|
facts: this.statusFacts(),
|
|
9023
9132
|
cwd: this.deps.cwd,
|
|
9024
9133
|
home: this.home,
|
|
@@ -11327,22 +11436,33 @@ var TuiApp = class {
|
|
|
11327
11436
|
case "start":
|
|
11328
11437
|
this.streaming = void 0;
|
|
11329
11438
|
this.endFade();
|
|
11439
|
+
this.beginLiveUsage();
|
|
11440
|
+
if (this.dropUnconfirmedTools()) this.tui.requestRender();
|
|
11330
11441
|
return;
|
|
11331
11442
|
case "chunk": {
|
|
11332
11443
|
const chunk = frame.chunk;
|
|
11333
11444
|
switch (chunk.type) {
|
|
11334
11445
|
case "text-delta":
|
|
11335
|
-
if (chunk.text !== "")
|
|
11446
|
+
if (chunk.text !== "") {
|
|
11447
|
+
this.appendStreamedText(chunk.text);
|
|
11448
|
+
this.noteStreamedChars(chunk.text.length);
|
|
11449
|
+
}
|
|
11336
11450
|
break;
|
|
11337
11451
|
case "reasoning-delta":
|
|
11338
|
-
if (chunk.text !== "")
|
|
11452
|
+
if (chunk.text !== "") {
|
|
11453
|
+
this.appendStreamedReasoning(chunk.text);
|
|
11454
|
+
this.noteStreamedChars(chunk.text.length);
|
|
11455
|
+
}
|
|
11339
11456
|
break;
|
|
11340
11457
|
case "tool-call-delta":
|
|
11341
|
-
|
|
11458
|
+
this.onToolCallDelta(chunk);
|
|
11459
|
+
this.noteStreamedChars(chunk.argumentsDelta.length);
|
|
11460
|
+
break;
|
|
11461
|
+
case "usage":
|
|
11462
|
+
this.applyLiveUsage(chunk.usage);
|
|
11342
11463
|
break;
|
|
11343
11464
|
case "block-start":
|
|
11344
11465
|
case "block-end":
|
|
11345
|
-
case "usage":
|
|
11346
11466
|
case "finish": break;
|
|
11347
11467
|
/* v8 ignore next -- closed-union exhaustiveness guard */
|
|
11348
11468
|
default: assertNever(chunk, "tui stream chunk");
|
|
@@ -11353,6 +11473,7 @@ var TuiApp = class {
|
|
|
11353
11473
|
case "end":
|
|
11354
11474
|
this.streaming = void 0;
|
|
11355
11475
|
this.endFade();
|
|
11476
|
+
if (frame.outcome.kind === "abandoned" || frame.outcome.kind === "committed" && frame.outcome.eventType === "assistant/attempt") this.dropUnconfirmedTools();
|
|
11356
11477
|
this.tui.requestRender();
|
|
11357
11478
|
return;
|
|
11358
11479
|
/* v8 ignore next -- closed-union exhaustiveness guard */
|
|
@@ -11387,23 +11508,15 @@ var TuiApp = class {
|
|
|
11387
11508
|
this.streamingBlock().commit(text, reasoning, interrupted === true);
|
|
11388
11509
|
this.streaming = void 0;
|
|
11389
11510
|
this.endFade();
|
|
11390
|
-
|
|
11391
|
-
|
|
11392
|
-
|
|
11393
|
-
}
|
|
11511
|
+
this.clearLiveUsage();
|
|
11512
|
+
if (usage !== void 0) this.usage = addUsage(this.usage, usage);
|
|
11513
|
+
this.refreshFooter();
|
|
11394
11514
|
break;
|
|
11395
11515
|
}
|
|
11396
11516
|
case "tool/call": {
|
|
11397
11517
|
const { callId, name, arguments: argumentsJson } = event.data;
|
|
11398
|
-
|
|
11399
|
-
this.
|
|
11400
|
-
const block = new ToolBlock(this.theme, name, toolCallText(argumentsJson, this.presentCall(name, args)), this.turn);
|
|
11401
|
-
block.setExpanded(this.toolsExpanded);
|
|
11402
|
-
this.toolBlocks.set(callId, block);
|
|
11403
|
-
this.chat.addChild(block);
|
|
11404
|
-
this.fadeBlock((fade) => {
|
|
11405
|
-
block.setFade(fade);
|
|
11406
|
-
});
|
|
11518
|
+
this.toolStreamArgs.delete(callId);
|
|
11519
|
+
this.upsertToolCard(callId, name, argumentsJson, "log");
|
|
11407
11520
|
break;
|
|
11408
11521
|
}
|
|
11409
11522
|
case "tool/result": {
|
|
@@ -11416,13 +11529,14 @@ var TuiApp = class {
|
|
|
11416
11529
|
this.fadeBlock((fade) => {
|
|
11417
11530
|
block.setResultFade(fade);
|
|
11418
11531
|
});
|
|
11419
|
-
this.
|
|
11532
|
+
this.setLoaderActivity("thinking");
|
|
11420
11533
|
break;
|
|
11421
11534
|
}
|
|
11422
11535
|
case "turn/end": {
|
|
11423
11536
|
this.turnStartedAt = void 0;
|
|
11424
11537
|
this.updateTicker();
|
|
11425
11538
|
this.endFade();
|
|
11539
|
+
this.clearLiveUsage();
|
|
11426
11540
|
this.refreshFooter();
|
|
11427
11541
|
const notice = turnEndNotice(event.data.reason);
|
|
11428
11542
|
if (notice !== void 0) this.notice(notice, event.data.reason.kind === "error" ? "error" : "dim");
|
|
@@ -11444,11 +11558,12 @@ var TuiApp = class {
|
|
|
11444
11558
|
break;
|
|
11445
11559
|
}
|
|
11446
11560
|
case "llm/retry":
|
|
11447
|
-
this.
|
|
11561
|
+
this.setLoaderActivity(retryMessage(event.data));
|
|
11448
11562
|
break;
|
|
11449
11563
|
default: return;
|
|
11450
11564
|
}
|
|
11451
11565
|
this.tui.requestRender();
|
|
11566
|
+
if (event.type === "tool/call" && !this.replaying) this.tui.renderNow();
|
|
11452
11567
|
}
|
|
11453
11568
|
/**
|
|
11454
11569
|
* Fold one whole-list todo write into the turn facts: a content this
|
|
@@ -11509,6 +11624,140 @@ var TuiApp = class {
|
|
|
11509
11624
|
block.setExpanded(this.toolsExpanded);
|
|
11510
11625
|
this.chat.addChild(block);
|
|
11511
11626
|
}
|
|
11627
|
+
/**
|
|
11628
|
+
* Replace the spinner's activity word and redraw its live ↑↓ suffix.
|
|
11629
|
+
* @param activity - `thinking`, `calling <name>`, or a retry notice.
|
|
11630
|
+
*/
|
|
11631
|
+
setLoaderActivity(activity) {
|
|
11632
|
+
this.loaderActivity = activity;
|
|
11633
|
+
this.refreshLoader();
|
|
11634
|
+
}
|
|
11635
|
+
/**
|
|
11636
|
+
* Start a new model call's live counters: seed send from the projected
|
|
11637
|
+
* next-request size or the last committed prompt, and zero receive.
|
|
11638
|
+
*/
|
|
11639
|
+
beginLiveUsage() {
|
|
11640
|
+
this.streamedChars = 0;
|
|
11641
|
+
this.usageExact = false;
|
|
11642
|
+
this.liveUsage = {
|
|
11643
|
+
inputTokens: this.seedLiveSend(),
|
|
11644
|
+
outputTokens: 0
|
|
11645
|
+
};
|
|
11646
|
+
this.loaderActivity = "thinking";
|
|
11647
|
+
this.refreshLiveUsage();
|
|
11648
|
+
}
|
|
11649
|
+
/**
|
|
11650
|
+
* Prompt tokens the current call is likely sending, before a usage chunk.
|
|
11651
|
+
* @returns context occupancy when the projection has one, else the last
|
|
11652
|
+
* committed prompt size, else 0.
|
|
11653
|
+
*/
|
|
11654
|
+
seedLiveSend() {
|
|
11655
|
+
const used = this.statusFacts().context?.used;
|
|
11656
|
+
if (used !== void 0 && used > 0) return used;
|
|
11657
|
+
return this.usage.lastInputTokens;
|
|
11658
|
+
}
|
|
11659
|
+
/**
|
|
11660
|
+
* Grow the receive estimate from streamed characters until the provider
|
|
11661
|
+
* reports usage.
|
|
11662
|
+
* @param chars - characters just appended to the live stream.
|
|
11663
|
+
*/
|
|
11664
|
+
noteStreamedChars(chars) {
|
|
11665
|
+
if (chars <= 0 || this.usageExact) return;
|
|
11666
|
+
this.streamedChars += chars;
|
|
11667
|
+
const send = this.liveUsage === void 0 ? this.seedLiveSend() : this.liveUsage.inputTokens;
|
|
11668
|
+
this.liveUsage = {
|
|
11669
|
+
inputTokens: send,
|
|
11670
|
+
outputTokens: estimateTokens(this.streamedChars)
|
|
11671
|
+
};
|
|
11672
|
+
this.refreshLiveUsage();
|
|
11673
|
+
}
|
|
11674
|
+
/**
|
|
11675
|
+
* Replace the live counters with a provider usage chunk.
|
|
11676
|
+
* @param usage - the call's reported usage.
|
|
11677
|
+
*/
|
|
11678
|
+
applyLiveUsage(usage) {
|
|
11679
|
+
this.usageExact = true;
|
|
11680
|
+
this.liveUsage = usage;
|
|
11681
|
+
this.refreshLiveUsage();
|
|
11682
|
+
}
|
|
11683
|
+
/** Forget the in-flight call's counters and drop them from the spinner and footer. */
|
|
11684
|
+
clearLiveUsage() {
|
|
11685
|
+
this.liveUsage = void 0;
|
|
11686
|
+
this.streamedChars = 0;
|
|
11687
|
+
this.usageExact = false;
|
|
11688
|
+
this.refreshLiveUsage();
|
|
11689
|
+
}
|
|
11690
|
+
/** Redraw the spinner and the footer from the current live counters. */
|
|
11691
|
+
refreshLiveUsage() {
|
|
11692
|
+
this.refreshLoader();
|
|
11693
|
+
this.refreshFooter();
|
|
11694
|
+
}
|
|
11695
|
+
/** Draw the spinner label plus the current call's ↑send ↓receive suffix. */
|
|
11696
|
+
refreshLoader() {
|
|
11697
|
+
const suffix = formatLiveUsage(this.liveUsage);
|
|
11698
|
+
this.loader.setMessage(suffix === "" ? this.loaderActivity : `${this.loaderActivity} ${suffix}`);
|
|
11699
|
+
}
|
|
11700
|
+
/**
|
|
11701
|
+
* Mount or refresh a tool card from a stream delta: the name as soon as
|
|
11702
|
+
* the model sends one, then the presenter headline once the arguments
|
|
11703
|
+
* parse as JSON.
|
|
11704
|
+
* @param chunk - one `tool-call-delta` of the live assistant stream.
|
|
11705
|
+
*/
|
|
11706
|
+
onToolCallDelta(chunk) {
|
|
11707
|
+
if (chunk.name !== void 0 && chunk.name !== "") this.setLoaderActivity(`calling ${chunk.name}`);
|
|
11708
|
+
if (chunk.id === "") return;
|
|
11709
|
+
const argumentsJson = (this.toolStreamArgs.get(chunk.id) ?? "") + chunk.argumentsDelta;
|
|
11710
|
+
this.toolStreamArgs.set(chunk.id, argumentsJson);
|
|
11711
|
+
const name = chunk.name === "" ? void 0 : chunk.name ?? this.toolBlocks.get(chunk.id)?.name;
|
|
11712
|
+
if (name === void 0) return;
|
|
11713
|
+
this.upsertToolCard(chunk.id, name, argumentsJson, "stream");
|
|
11714
|
+
}
|
|
11715
|
+
/**
|
|
11716
|
+
* Draw one tool card, creating it on the first sighting and updating the
|
|
11717
|
+
* call half when later arguments arrive. A streamed card stays unconfirmed
|
|
11718
|
+
* until the matching `tool/call` is logged.
|
|
11719
|
+
* @param callId - the model's call id.
|
|
11720
|
+
* @param name - the tool name.
|
|
11721
|
+
* @param argumentsJson - arguments accumulated so far, or the logged string.
|
|
11722
|
+
* @param source - `stream` for a live delta, `log` for the durable call.
|
|
11723
|
+
*/
|
|
11724
|
+
upsertToolCard(callId, name, argumentsJson, source) {
|
|
11725
|
+
const args = parseArguments(argumentsJson);
|
|
11726
|
+
if (args !== void 0) this.toolArguments.set(callId, args);
|
|
11727
|
+
const call = source === "stream" && args === void 0 ? {
|
|
11728
|
+
title: "",
|
|
11729
|
+
lines: []
|
|
11730
|
+
} : toolCallText(argumentsJson, args === void 0 ? void 0 : this.presentCall(name, args));
|
|
11731
|
+
const existing = this.toolBlocks.get(callId);
|
|
11732
|
+
if (existing !== void 0) {
|
|
11733
|
+
existing.setCall(name, call);
|
|
11734
|
+
if (source === "log") this.unconfirmedTools.delete(callId);
|
|
11735
|
+
return;
|
|
11736
|
+
}
|
|
11737
|
+
const block = new ToolBlock(this.theme, name, call, this.turn);
|
|
11738
|
+
block.setExpanded(this.toolsExpanded);
|
|
11739
|
+
this.toolBlocks.set(callId, block);
|
|
11740
|
+
this.chat.addChild(block);
|
|
11741
|
+
this.fadeBlock((fade) => {
|
|
11742
|
+
block.setFade(fade);
|
|
11743
|
+
});
|
|
11744
|
+
if (source === "stream") this.unconfirmedTools.set(callId, block);
|
|
11745
|
+
}
|
|
11746
|
+
/**
|
|
11747
|
+
* Take down every card the live stream mounted that no `tool/call` confirmed.
|
|
11748
|
+
* @returns true when at least one card left the transcript.
|
|
11749
|
+
*/
|
|
11750
|
+
dropUnconfirmedTools() {
|
|
11751
|
+
if (this.unconfirmedTools.size === 0) return false;
|
|
11752
|
+
for (const [callId, block] of this.unconfirmedTools) {
|
|
11753
|
+
this.chat.removeChild(block);
|
|
11754
|
+
this.toolBlocks.delete(callId);
|
|
11755
|
+
this.toolArguments.delete(callId);
|
|
11756
|
+
this.toolStreamArgs.delete(callId);
|
|
11757
|
+
}
|
|
11758
|
+
this.unconfirmedTools.clear();
|
|
11759
|
+
return true;
|
|
11760
|
+
}
|
|
11512
11761
|
presentCall(name, args) {
|
|
11513
11762
|
const definition = this.deps.ctx.get("tools")?.get(name, this.agent);
|
|
11514
11763
|
if (definition?.presentCall === void 0) return void 0;
|
package/package.json
CHANGED