feat:优化会话历史中工具执行请求的处理逻辑

- 实现工具执行请求的检测和处理
- 关联工具执行结果与请求
- 跳过已处理的工具执行结果消息
- 构建包含工具执行信息的segments
This commit is contained in:
Roe-xin
2026-03-20 18:26:14 +08:00
parent 3b0dca6467
commit 4e06d08106
4 changed files with 37 additions and 5 deletions

View File

@ -42,9 +42,9 @@ const ENV_CONFIG: Record<Environment, IccoderConfig> = {
},
/** 测试服务器环境 - 通过 Gateway 路由 */
test: {
backendUrl: "http://192.168.1.108:2029/iccoder",
backendUrlStrongeLoop: "http://192.168.1.108:2029",
loginUrl: "http://192.168.1.108:2005/login",
backendUrl: "http://192.168.1.134:2233",
backendUrlStrongeLoop: "http://192.168.1.134:2233",
loginUrl: "http://192.168.1.134/login",
timeout: 60000,
userId: "default-user",
serviceTier: "max",

View File

@ -45,6 +45,8 @@ export interface MessageSegment {
toolDescription?: string;
askId?: string;
questions?: import("../types/api").QuestionItem[];
answered?: boolean;
answers?: { [questionIndex: string]: string[] };
// 智能体相关字段
agentId?: string;
agentName?: string;
@ -1125,6 +1127,7 @@ export class DialogSession {
// 直接调用 receiveAnswer传递 taskId 作为 fallbackTaskId
// 如果 pendingQuestions 中有问题,走正常流程
// 如果没有receiveAnswer 会使用 fallbackTaskId 直接发送到后端
this.markQuestionAnswered(askId, selected, customInput, answers);
await userInteractionManager.receiveAnswer(
askId,
selected,
@ -1133,6 +1136,30 @@ export class DialogSession {
this.taskId
);
}
private markQuestionAnswered(
askId: string,
selected?: string[],
customInput?: string,
answers?: { [questionIndex: string]: string[] }
): void {
const normalizedAnswers =
answers && Object.keys(answers).length > 0
? answers
: { "0": customInput ? [customInput] : selected || [] };
for (let i = this.segments.length - 1; i >= 0; i--) {
const segment = this.segments[i];
if (
segment.askId === askId &&
(segment.type === "question" || segment.type === "plan")
) {
segment.answered = true;
segment.answers = normalizedAnswers;
break;
}
}
}
}
/**

View File

@ -147,8 +147,10 @@ export function getSegmentRendererScript(): string {
options: segment.options || [],
multiSelect: false
}] : []);
const isAnswered = answeredQuestions.has(segment.askId);
const savedAnswers = answeredQuestions.get(segment.askId) || {};
const segmentAnswers = segment.answers || {};
const runtimeAnswers = answeredQuestions.get(segment.askId) || {};
const savedAnswers = Object.keys(segmentAnswers).length > 0 ? segmentAnswers : runtimeAnswers;
const isAnswered = segment.answered === true || answeredQuestions.has(segment.askId);
if (isAnswered) {
segmentDiv.classList.add('answered');
}

View File

@ -894,6 +894,9 @@ export function getWebviewContent(
if (messagesContainer) {
messagesContainer.innerHTML = '';
}
if (typeof answeredQuestions !== 'undefined' && answeredQuestions.clear) {
answeredQuestions.clear();
}
// 重置输入框布局到居中
if (typeof window.resetInputAreaLayout === 'function') {
window.resetInputAreaLayout();