feat:添加描述字段
This commit is contained in:
@ -41,6 +41,7 @@ export interface MessageSegment {
|
||||
toolName?: string;
|
||||
toolStatus?: "running" | "success" | "error";
|
||||
toolResult?: string;
|
||||
toolDescription?: string;
|
||||
askId?: string;
|
||||
question?: string;
|
||||
options?: string[];
|
||||
@ -180,7 +181,8 @@ export class DialogSession {
|
||||
private updateToolSegment(
|
||||
toolName: string,
|
||||
status: "success" | "error",
|
||||
result?: string
|
||||
result?: string,
|
||||
description?: string
|
||||
): void {
|
||||
// 找到最后一个匹配的工具段落
|
||||
for (let i = this.segments.length - 1; i >= 0; i--) {
|
||||
@ -192,6 +194,9 @@ export class DialogSession {
|
||||
) {
|
||||
seg.toolStatus = status;
|
||||
seg.toolResult = result;
|
||||
if (description !== undefined) {
|
||||
seg.toolDescription = description;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -590,7 +595,7 @@ export class DialogSession {
|
||||
},
|
||||
|
||||
onToolComplete: (data) => {
|
||||
this.updateToolSegment(data.tool_name, "success", data.result);
|
||||
this.updateToolSegment(data.tool_name, "success", data.result, data.description);
|
||||
callbacks.onToolComplete?.(data.tool_name, data.result);
|
||||
// 实时发送段落更新
|
||||
callbacks.onSegmentUpdate?.(this.segments);
|
||||
|
||||
@ -96,6 +96,7 @@ export interface ToolStartEvent {
|
||||
export interface ToolCompleteEvent {
|
||||
tool_name: string;
|
||||
result: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
/** tool_error 事件数据 */
|
||||
|
||||
@ -542,6 +542,12 @@ export function getMessageAreaStyles(): string {
|
||||
.tool-segment-content.collapsed {
|
||||
max-height: 0;
|
||||
}
|
||||
.tool-segment-description {
|
||||
margin: 2px 0 0 0px;
|
||||
font-size: 12px;
|
||||
color: #fff;
|
||||
line-height: 1.4;
|
||||
}
|
||||
/* 低调显示的工具调用样式 */
|
||||
.segment-tool.low-profile .tool-segment-header {
|
||||
opacity: 0.65;
|
||||
@ -1064,6 +1070,7 @@ export function getMessageAreaScript(): string {
|
||||
const toolResult = segment.toolResult || '';
|
||||
const toolCount = segment.toolCount || 1;
|
||||
const countSuffix = toolCount > 1 ? \` x\${toolCount}\` : '';
|
||||
const toolDescription = segment.toolDescription || '';
|
||||
|
||||
// 检查工具结果是否过长(超过一行显示不下)
|
||||
const shouldCollapse = toolResult && toolResult.length > 60;
|
||||
@ -1081,6 +1088,7 @@ export function getMessageAreaScript(): string {
|
||||
\${toolResult && !shouldCollapse ? \`<span class="tool-segment-result">\${toolResult}</span>\` : ''}
|
||||
</div>
|
||||
\${shouldCollapse ? \`<div class="tool-segment-content\${isCollapsed ? ' collapsed' : ''}" style="max-height:\${isCollapsed ? '0' : 'none'}"><span class="tool-segment-result" style="display:block;white-space:pre-wrap;max-width:100%;margin-top:8px;margin-left:18px;">\${toolResult}</span></div>\` : ''}
|
||||
\${toolDescription ? \`<p class="tool-segment-description">\${toolDescription}</p>\` : ''}
|
||||
\`;
|
||||
|
||||
// 如果是仿真工具且成功完成,尝试添加波形预览
|
||||
@ -1328,6 +1336,7 @@ export function getMessageAreaScript(): string {
|
||||
const toolResult = segment.toolResult || '';
|
||||
const toolCount = segment.toolCount || 1;
|
||||
const countSuffix = toolCount > 1 ? \` x\${toolCount}\` : '';
|
||||
const toolDescription = segment.toolDescription || '';
|
||||
|
||||
// 检查工具结果是否过长(超过一行显示不下)
|
||||
const shouldCollapse = toolResult && toolResult.length > 60;
|
||||
@ -1339,6 +1348,7 @@ export function getMessageAreaScript(): string {
|
||||
\${toolResult && !shouldCollapse ? \`<span class="tool-segment-result">\${toolResult}</span>\` : ''}
|
||||
</div>
|
||||
\${shouldCollapse ? \`<div class="tool-segment-content collapsed"><span class="tool-segment-result" style="display:block;white-space:pre-wrap;max-width:100%;margin-top:8px;margin-left:18px;">\${toolResult}</span></div>\` : ''}
|
||||
\${toolDescription ? \`<p class="tool-segment-description">\${toolDescription}</p>\` : ''}
|
||||
\`;
|
||||
|
||||
// 如果是仿真工具且成功完成,尝试添加波形预览
|
||||
|
||||
Reference in New Issue
Block a user