返回 DeepSeek-Reasonix
projectTreeRequestDiagnostics.ts
根目录 / desktop / frontend / src / lib / projectTreeRequestDiagnostics.ts
1 import { recordFrontendDiagnostic } from "./frontendDiagnosticBridge";
2
3 type RequestStats = { active: number; queued: number };
4
5 type RequestDiagnosticOptions = {
6 projectKind: string;
7 creationTopics: boolean;
8 sequence: number;
9 stats: () => RequestStats;
10 };
11
12 export function createProjectTreeRequestDiagnostic(options: RequestDiagnosticOptions): (phase: string, fields?: Record<string, unknown>) => void {
13 const startedAt = typeof performance !== "undefined" ? performance.now() : Date.now();
14 const now = () => typeof performance !== "undefined" ? performance.now() : Date.now();
15 const emit = (phase: string, fields: Record<string, unknown> = {}) => {
16 const stats = options.stats();
17 recordFrontendDiagnostic("workspace", "workspace.session-list", {
18 phase,
19 sequence: options.sequence,
20 durationMs: Math.max(0, now() - startedAt),
21 queueDepth: stats.queued,
22 activeRequests: stats.active,
23 scope: options.projectKind === "global_folder" ? "global" : "project",
24 variant: options.creationTopics ? "creation" : "workbench",
25 ...fields,
26 });
27 };
28 emit("queued");
29 return emit;
30 }
31
31 lines TYPESCRIPT