Skip to content

fix(chat-engine): fix incorrect tool call status Ref #6555#6559

Open
Grnetsky wants to merge 3 commits into
Tencent:developfrom
Grnetsky:fix/chat-engine-toolcall-status
Open

fix(chat-engine): fix incorrect tool call status Ref #6555#6559
Grnetsky wants to merge 3 commits into
Tencent:developfrom
Grnetsky:fix/chat-engine-toolcall-status

Conversation

@Grnetsky
Copy link
Copy Markdown

@Grnetsky Grnetsky commented Mar 31, 2026

🤔 这个 PR 的性质是?

  • 日常 bug 修复
  • 新特性提交
  • 文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • CI/CD 改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他

🔗 相关 Issue

💡 需求背景和解决方案

当工具调用后,eventType发生变化,但result还未返回时,toolstatus错误的变成了complete

这不符合预期,用户无法准确的判断工具当前状态

问题原因

    watch(
      () => [config.value, args.value, props.toolCall.result, props.toolCall.eventType],
      async () => {
        if (!config.value) return;

        if (isNonInteractiveConfig(config.value)) {
          // 非交互式:执行 handler
          try {
            actionState.value = { status: 'executing' }; // =>此处进行了状态更换为executing 

            // 解析后端返回的结果作为 handler 的第二个参数
            let backendResult;
            if (props.toolCall.result) { // =>此处判断是否有结果,即是否tool end
              try {
                backendResult = JSON.parse(props.toolCall.result);
              } catch (error) {
                console.warn('解析后端结果失败,使用原始字符串:', error);
                backendResult = props.toolCall.result;
              }
            }

            // 调用 handler,传入 args 和 backendResult
            const result = await config.value.handler(args.value, backendResult); 
            actionState.value = {  // => 此处无论是否处于toolend阶段都将状态转换为complete,问题所在
              status: 'complete',
              result,
            };
          } catch (error) {
            actionState.value = {
              status: 'error',
              error: error as Error,
            };
          }
        } else if (props.toolCall.result) {
          // 交互式:已有结果,显示完成状态

解决方案

将complete相关代码移入到result判断中

@tdesign-vue-next/chat

  • fix(chat-engine): fix the incorrect toolcall status

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • Changelog 已提供或无须提供

@tdesign-bot
Copy link
Copy Markdown
Collaborator

tdesign-bot commented Apr 1, 2026

TDesign Component Site Preview Open

Component Preview
tdesign-vue-next 完成
@tdesign-vue-next/chat 完成

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 1, 2026

  • tdesign-vue-next-demo

    npm i https://pkg.pr.new/@tdesign-vue-next/auto-import-resolver@6559
    
    npm i https://pkg.pr.new/tdesign-vue-next@6559
    
    npm i https://pkg.pr.new/@tdesign-vue-next/chat@6559
    

commit: 0547f72

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants