Timothy J. Baek 6 月之前
父節點
當前提交
a4a5614de5
共有 1 個文件被更改,包括 11 次插入11 次删除
  1. 11 11
      src/lib/components/chat/Chat.svelte

+ 11 - 11
src/lib/components/chat/Chat.svelte

@@ -176,22 +176,22 @@
 				}
 			} else if (type === 'citation') {
 				if (data?.type === 'code_execution') {
-					// Code execution; update existing code execution by ID,
-					// otherwise append.
+					// Code execution; update existing code execution by ID, or add new one.
 					if (!message?.code_executions) {
 						message.code_executions = [];
 					}
-					let is_update = false;
-					for (let i = 0; i < message.code_executions.length; i++) {
-						if (message.code_executions[i].id === data.id) {
-							message.code_executions[i] = data;
-							is_update = true;
-							break;
-						}
-					}
-					if (!is_update) {
+
+					const existingCodeExecutionIndex = message.code_executions.findIndex(
+						(execution) => execution.id === data.id
+					);
+
+					if (existingCodeExecutionIndex !== -1) {
+						message.code_executions[existingCodeExecutionIndex] = data;
+					} else {
 						message.code_executions.push(data);
 					}
+
+					message.code_executions = message.code_executions;
 				} else {
 					// Regular citation.
 					if (message?.citations) {