返回 DeepSeek-Reasonix
mcpListAttribution.ts
根目录 / desktop / frontend / src / lib / mcpListAttribution.ts
1 import type { Item } from "./useController";
2
3 export type McpListAttribution = {
4 sharedHost: number;
5 diskCache: number;
6 remote: number;
7 networkCalls: number;
8 };
9
10 export function mcpListAttribution(items: Item[]): McpListAttribution {
11 const counts: McpListAttribution = { sharedHost: 0, diskCache: 0, remote: 0, networkCalls: 0 };
12 for (const item of items) {
13 if (item.kind !== "notice") continue;
14 const legacyNotice = item.code === undefined && item.text.trim().toLowerCase() === "mcp tools/list";
15 if (item.code !== "mcp_tools_list" && !legacyNotice) continue;
16 try {
17 const detail = JSON.parse(item.detail ?? "") as Record<string, unknown>;
18 if (detail.source === "shared_host") counts.sharedHost += 1;
19 else if (detail.source === "disk_cache") counts.diskCache += 1;
20 else if (detail.source === "remote") counts.remote += 1;
21 if (detail.network_call === true) counts.networkCalls += 1;
22 } catch {
23 // Legacy notices may lack structured detail; do not infer a source from
24 // arbitrary model-visible tool output.
25 }
26 }
27 return counts;
28 }
29
29 lines TYPESCRIPT