Skip to content

Commit 16d45df

Browse files
author
linyuan.yang
committed
查看think
1 parent f5c66ba commit 16d45df

4 files changed

Lines changed: 95 additions & 24 deletions

File tree

‎.vscode/launch.json‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@
6666
"name": "Launch app",
6767
"command": "pnpm dev",
6868
"cwd": "${workspaceFolder}/packages/app"
69+
},
70+
{
71+
"name": "Launch AdminUI",
72+
"type": "pwa-chrome",
73+
"request": "launch",
74+
"url": "http://localhost:5173/webui/",
75+
"webRoot": "${workspaceFolder}/packages/admin",
76+
"sourceMapPathOverrides": {
77+
"webpack:///./*": "${webRoot}/*",
78+
"/@fs/*": "/*"
79+
},
80+
"preLaunchTask": "launch:adminui"
6981
}
7082
]
7183
}

‎.vscode/tasks.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@
8787
"label": "launch:sbot",
8888
"dependsOn": ["admin:kill", "debug:sbot", "admin:dev"],
8989
"dependsOrder": "sequence"
90+
},
91+
{
92+
"label": "launch:adminui",
93+
"dependsOn": ["admin:kill", "admin:dev"],
94+
"dependsOrder": "sequence"
9095
}
9196
]
9297
}

‎packages/chat-ui/src/components/MessageList.vue‎

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,10 @@ function contentCharLen(content?: DisplayContent): number {
227227
<span class="tool-call-name">{{ tc.name }}</span>
228228
<span class="tool-call-summary">
229229
<span v-if="inlineArgs(tc)" class="tool-call-inline-args" :title="inlineArgs(tc)">{{ inlineArgs(tc) }}</span>
230-
<!-- 子任务进行中:不必先展开 tool_call,直接从这里进思考过程 -->
230+
<!-- 子任务进行中且未展开:不必先展开 tool_call,直接从这里进思考过程。
231+
展开后详情区已有同样的入口,这里就不再重复 -->
231232
<span
232-
v-if="isToolRunning(tc.id) && findToolResult(tc.id)?.thinkId && thinksUrlPrefix"
233+
v-if="isToolRunning(tc.id) && !isToolCallExpanded(tc.id) && findToolResult(tc.id)?.thinkId && thinksUrlPrefix"
233234
class="think-toggle think-toggle-running"
234235
@click.stop="openThink(findToolResult(tc.id)!.thinkId!, findToolResult(tc.id)!.taskId, { live: true })"
235236
>
@@ -238,25 +239,30 @@ function contentCharLen(content?: DisplayContent): number {
238239
<span v-else-if="toolResultPreviewMap.get(tc.id)" class="tool-call-result-preview" :title="toolResultPreviewMap.get(tc.id)">↳ {{ toolResultPreviewMap.get(tc.id) }}</span>
239240
</span>
240241
</button>
242+
<!-- inner 包一层:grid-template-rows: 0fr 的折叠动画只能约束单个子元素 -->
241243
<div class="tool-call-detail" :class="{ show: isToolCallExpanded(tc.id) }">
242-
<div class="tool-call-args">{{ JSON.stringify(tc.args, null, 2) }}</div>
243-
<template v-if="findToolResult(tc.id)">
244-
<div class="tool-call-result">
245-
<div class="tool-call-result-top">
246-
<div class="tool-call-result-label">{{ isToolRunning(tc.id) ? L.thinking : L.toolResult }}</div>
247-
<span v-if="!isToolRunning(tc.id)" class="msg-char-len" :title="`${contentCharLen(findToolResult(tc.id)!.message.content)} chars`">{{ contentCharLen(findToolResult(tc.id)!.message.content) }} chars</span>
248-
<div v-if="findToolResult(tc.id)?.thinkId && thinksUrlPrefix"
249-
class="think-toggle" :class="{ 'think-toggle-running': isToolRunning(tc.id) }"
250-
@click="openThink(findToolResult(tc.id)!.thinkId!, findToolResult(tc.id)!.taskId, { live: isToolRunning(tc.id) })">
251-
<span v-if="isToolRunning(tc.id)" class="think-live-dot" /><span v-else>▸</span><span>{{ L.think }}</span>
244+
<div class="tool-call-detail-inner">
245+
<div class="tool-call-args">{{ JSON.stringify(tc.args, null, 2) }}</div>
246+
<template v-if="findToolResult(tc.id)">
247+
<!-- 进行中时没有结果体,只剩一个入口按钮:去掉水平内边距,让它与上方 args 块左对齐 -->
248+
<div class="tool-call-result" :class="{ 'is-running': isToolRunning(tc.id) }">
249+
<div class="tool-call-result-top">
250+
<!-- 进行中时不显示标题:按钮本身就写着"思考中" -->
251+
<div v-if="!isToolRunning(tc.id)" class="tool-call-result-label">{{ L.toolResult }}</div>
252+
<span v-if="!isToolRunning(tc.id)" class="msg-char-len" :title="`${contentCharLen(findToolResult(tc.id)!.message.content)} chars`">{{ contentCharLen(findToolResult(tc.id)!.message.content) }} chars</span>
253+
<div v-if="findToolResult(tc.id)?.thinkId && thinksUrlPrefix"
254+
class="think-toggle" :class="{ 'think-toggle-running': isToolRunning(tc.id) }"
255+
@click="openThink(findToolResult(tc.id)!.thinkId!, findToolResult(tc.id)!.taskId, { live: isToolRunning(tc.id) })">
256+
<span v-if="isToolRunning(tc.id)" class="think-live-dot" /><span v-else>▸</span><span>{{ isToolRunning(tc.id) ? L.thinking : L.think }}</span>
257+
</div>
252258
</div>
259+
<!-- 进行中的占位没有 content,不渲染结果体 -->
260+
<ContentParts v-if="!isToolRunning(tc.id)" :content="findToolResult(tc.id)!.message.content"
261+
text-class="md-content tool-result-content"
262+
@open-image="openLightbox" />
253263
</div>
254-
<!-- 进行中的占位没有 content,不渲染结果体 -->
255-
<ContentParts v-if="!isToolRunning(tc.id)" :content="findToolResult(tc.id)!.message.content"
256-
text-class="md-content tool-result-content"
257-
@open-image="openLightbox" />
258-
</div>
259-
</template>
264+
</template>
265+
</div>
260266
</div>
261267
</div>
262268
</div>
@@ -459,14 +465,18 @@ function contentCharLen(content?: DisplayContent): number {
459465
:deep(.inline-audio audio) { max-width: 100%; border-radius: 6px; }
460466
461467
/* Tool calls */
468+
/* 宽度由布局给定,不由内容决定:否则折叠态是 "grep" 的窄宽度,
469+
展开态是 args JSON 最长行的宽度,切换时整块会横向跳变。 */
462470
.msg-tool-calls {
463471
background: var(--chatui-bg-ai);
464472
border: 1px solid var(--chatui-border);
465473
border-radius: 8px;
466474
padding: 10px 12px;
467475
margin-top: 6px;
468476
font-size: 12px;
477+
width: 100%;
469478
max-width: 90%;
479+
box-sizing: border-box;
470480
}
471481
.msg-role.has-think {
472482
display: flex;
@@ -478,6 +488,8 @@ function contentCharLen(content?: DisplayContent): number {
478488
border-radius: 6px;
479489
margin-top: 6px;
480490
overflow: hidden;
491+
/* min-width 默认是 max-content,不归零会让长内容顶穿上面的宽度约束 */
492+
min-width: 0;
481493
}
482494
.tool-call-header {
483495
width: 100%;
@@ -521,6 +533,9 @@ function contentCharLen(content?: DisplayContent): number {
521533
overflow: hidden;
522534
padding-top: 2px;
523535
}
536+
/* 按钮按内容宽度收缩。注意不能改父级的 align-items:摘要行要靠 stretch 拿到
537+
确定宽度,text-overflow: ellipsis 才生效。 */
538+
.tool-call-summary > .think-toggle { align-self: flex-start; }
524539
.tool-call-inline-args {
525540
font-family: monospace;
526541
font-size: 11px;
@@ -540,13 +555,29 @@ function contentCharLen(content?: DisplayContent): number {
540555
opacity: 0.85;
541556
}
542557
.tool-call-header.expanded .tool-call-result-preview { display: none; }
543-
.tool-call-detail { display: none; }
544-
.tool-call-detail.show { display: block; }
558+
/* 展开只改变高度,从不改变宽度 */
559+
.tool-call-detail {
560+
display: grid;
561+
grid-template-rows: 0fr;
562+
transition: grid-template-rows 0.18s ease;
563+
min-width: 0;
564+
}
565+
.tool-call-detail.show { grid-template-rows: 1fr; }
566+
.tool-call-detail-inner {
567+
min-height: 0;
568+
min-width: 0;
569+
overflow: hidden;
570+
}
571+
@media (prefers-reduced-motion: reduce) {
572+
.tool-call-detail { transition: none; }
573+
}
545574
.tool-call-args {
546575
font-family: monospace;
547576
font-size: 11px;
548577
white-space: pre-wrap;
549-
word-break: break-all;
578+
/* anywhere 而非 break-all:优先在正常断点折行,只在长 token 无处可断时才切开 */
579+
overflow-wrap: anywhere;
580+
min-width: 0;
550581
color: var(--chatui-fg-primary);
551582
background: var(--chatui-bg-code);
552583
padding: 6px 8px;
@@ -558,6 +589,8 @@ function contentCharLen(content?: DisplayContent): number {
558589
padding: 8px;
559590
border-top: 1px solid var(--chatui-border);
560591
}
592+
/* 进行中:只有入口按钮,与上方 args 块共用左基线 */
593+
.tool-call-result.is-running { padding: 8px 0; }
561594
.tool-call-result-top {
562595
display: flex;
563596
align-items: center;

‎packages/chat-ui/src/toolCallFormat.ts‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,35 @@ function stringify(v: unknown): string {
99
return typeof v === 'string' ? v : JSON.stringify(v)
1010
}
1111

12-
/** Render the args of a tool call as a compact inline summary (only when ≤2 args). */
12+
/** 一行摘要里最多放几个参数。 */
13+
const INLINE_ARGS_MAX = 2
14+
15+
/**
16+
* 只有标量适合塞进一行摘要:布尔几乎不含区分度(`useRegex=true` 说明不了任何事),
17+
* 对象和数组要展开才有意义。
18+
*/
19+
function isSummarizable(v: unknown): boolean {
20+
return (typeof v === 'string' && v !== '') || typeof v === 'number'
21+
}
22+
23+
/**
24+
* Render the args of a tool call as a compact inline summary.
25+
*
26+
* 参数多的工具同样需要摘要 —— 一屏 7 个 `grep` 如果都不显示参数就完全无法区分,
27+
* 所以这里从中挑出有区分度的几个,而不是放弃。
28+
*/
1329
export function inlineArgs(tc: ToolCall): string {
1430
const args = tc.args
1531
if (!args || typeof args !== 'object' || Array.isArray(args)) return ''
1632
const obj = args as Record<string, unknown>
1733
const keys = Object.keys(obj)
18-
if (keys.length === 0 || keys.length > 2) return ''
19-
return keys.map((k) => `${k}=${truncate(stringify(obj[k]), 40)}`).join(' ')
34+
if (keys.length === 0) return ''
35+
// 保持参数原有顺序:工具定义通常把主要参数排在前面(grep 的 path/pattern 就在
36+
// maxMatches/timeoutSec 之前),比按类型重排更可预测。
37+
const picked = keys.filter((k) => isSummarizable(obj[k]))
38+
// 全是布尔/对象时回退到原始顺序:低信息量的摘要仍然好过没有摘要。
39+
const use = (picked.length ? picked : keys).slice(0, INLINE_ARGS_MAX)
40+
return use.map((k) => `${k}=${truncate(stringify(obj[k]), 40)}`).join(' ')
2041
}
2142

2243
/** Produce a short single-line preview for a tool-result message. */

0 commit comments

Comments
 (0)