优化:ai chat 工具调用的图标颜色从tool的color字段获取

This commit is contained in:
jingrow 2026-06-30 01:44:05 +08:00
parent 9c64658722
commit dfbca1b0a7
4 changed files with 33 additions and 12 deletions

View File

@ -39,6 +39,7 @@ export interface ToolCallBegin {
label?: string
arguments: string
icon?: string
color?: string
}
// 保持与后端 _summarize_tool_result 一致的摘要结构

View File

@ -212,6 +212,7 @@ export function useChat() {
name: data.name,
label: data.label,
icon: data.icon,
color: data.color,
arguments: data.arguments,
status: 'running',
})

View File

@ -20,7 +20,7 @@ const props = defineProps<{
/** 思考耗时(秒) */
thinkingElapsed?: number
/** 当前轮次的实时 Tool Call 列表(在 thinking 面板与消息内容之间渲染) */
toolCalls?: { id: string; name: string; label?: string; icon?: string; status: string; summary?: string }[]
toolCalls?: { id: string; name: string; label?: string; icon?: string; color?: string; status: string; summary?: string }[]
}>()
const emit = defineEmits<{
@ -44,7 +44,7 @@ const displayToolCalls = computed(() => {
? JSON.parse(props.message.tool_calls)
: props.message.tool_calls
if (Array.isArray(raw) && raw.length > 0) {
return raw as { id: string; name: string; label?: string; icon?: string; status: string; summary?: string }[]
return raw as { id: string; name: string; label?: string; icon?: string; color?: string; status: string; summary?: string }[]
}
}
return null
@ -412,6 +412,7 @@ onMounted(() => {
<Icon
:icon="tc.icon || 'tabler:tool'"
class="tool-call-icon"
:style="tc.color ? { color: tc.color } : undefined"
/>
<span class="tool-call-label">{{ t(tc.label || tc.name) }}</span>
<span class="tool-call-status-icon">
@ -636,18 +637,28 @@ onMounted(() => {
transition: color 0.2s ease;
}
.tool-call-details.running .tool-call-icon {
/* 有 tool color 时:状态通过 status-icon 和透明度区分 */
.tool-call-details.running .tool-call-icon:not([style*="color"]) {
color: #3b82f6;
}
.tool-call-details.completed .tool-call-icon {
.tool-call-details.completed .tool-call-icon:not([style*="color"]) {
color: #22c55e;
}
.tool-call-details.failed .tool-call-icon {
.tool-call-details.failed .tool-call-icon:not([style*="color"]) {
color: #ef4444;
}
/* 有 tool color 时仅调整透明度 */
.tool-call-details.completed .tool-call-icon[style*="color"] {
opacity: 0.7;
}
.tool-call-details.failed .tool-call-icon[style*="color"] {
opacity: 0.5;
}
.tool-call-label {
font-size: 11px;
color: #374151;

View File

@ -53,15 +53,20 @@ def _get_tool_label(tool_name: str) -> str:
return tool_name
def _get_tool_icon(tool_name: str) -> str:
"""根据工具名称返回 icon 完整标识(如 "tabler:search"),透传 JSON 配置值"""
def _get_tool_icon(tool_name: str) -> tuple[str, str]:
"""根据工具名称返回 (icon, color),透传 JSON 配置值
Returns:
(icon, color) 二元组 ("tabler:search", "#3b82f6")
"""
default = ("", "")
try:
tool = ToolRegistry.get(tool_name)
if tool and tool.icon:
return tool.icon
if tool:
return (tool.icon or "", tool.color or "")
except Exception:
pass
return ""
return default
# 默认上下文窗口 token 上限(适配主流 200K 窗口模型)
DEFAULT_MAX_CONTEXT_TOKENS = 200000
@ -244,12 +249,14 @@ def chat_stream_sse(chat_name, content, file_record_names=None):
for tc in tool_calls_this_round:
# ----- 实时 Tool Call SSE: begin -----
tc_icon, tc_color = _get_tool_icon(tc["name"])
begin_data = {
"id": tc["id"],
"name": tc["name"],
"label": _get_tool_label(tc["name"]),
"arguments": tc.get("arguments", "{}"),
"icon": _get_tool_icon(tc["name"]),
"icon": tc_icon,
"color": tc_color,
}
yield sse_event("tool_call_begin", begin_data)
@ -275,7 +282,8 @@ def chat_stream_sse(chat_name, content, file_record_names=None):
"id": tc["id"],
"name": tc["name"],
"label": _get_tool_label(tc["name"]),
"icon": _get_tool_icon(tc["name"]),
"icon": tc_icon,
"color": tc_color,
"status": "completed" if success else "failed",
"summary": _summarize_tool_result(result),
})