返回 DeepSeek-Reasonix
archivedToolItems.ts
根目录 / desktop / frontend / src / lib / archivedToolItems.ts
1 import type { Item } from "./useController";
2
3 const ARCHIVED_TOOL_ARG_LIMIT = 200;
4
5 function archivedToolArgs(args: string): string {
6 return args && args.length > ARCHIVED_TOOL_ARG_LIMIT ? args.slice(0, ARCHIVED_TOOL_ARG_LIMIT) + "…" : args;
7 }
8
9 function latestCanonicalTodoToolIndex(items: Item[]): number {
10 for (let index = items.length - 1; index >= 0; index -= 1) {
11 const item = items[index];
12 if (item.kind === "tool" && item.name === "todo_write" && !item.parentId && item.status === "done" && !item.error) return index;
13 }
14 return -1;
15 }
16
17 export function compactArchivedToolItems(items: Item[]): Item[] {
18 const canonicalTodoIndex = latestCanonicalTodoToolIndex(items);
19 return items.map((item, index) => {
20 if (item.kind !== "tool" || item.status === "running") return item;
21 const nextArgs = index === canonicalTodoIndex ? item.args : archivedToolArgs(item.args);
22 if (nextArgs === item.args && item.output === undefined && item.dataArchived === true) return item;
23 return { ...item, args: nextArgs, output: undefined, dataArchived: true };
24 });
25 }
26
26 lines TYPESCRIPT