返回 DeepSeek-Reasonix
turnRateSample.ts
根目录 / desktop / frontend / src / lib / turnRateSample.ts
1 import type { State } from "./useController";
2
3 export function beginTurnModelActivity(s: State, now = Date.now()): State {
4 return s.turnModelActiveAt && s.turnModelActiveAt > 0
5 ? s
6 : { ...s, turnModelActiveAt: now };
7 }
8
9 export function endTurnModelActivity(s: State, now = Date.now(), stashForUsage = false): State {
10 if (!s.turnModelActiveAt || s.turnModelActiveAt <= 0) return s;
11 const closedMs = Math.max(0, now - s.turnModelActiveAt);
12 return { ...s, turnModelActiveAt: undefined, turnModelActiveMs: Math.max(0, s.turnModelActiveMs) + closedMs,
13 pendingRequestModelMs: stashForUsage ? closedMs : s.pendingRequestModelMs };
14 }
15
16 /** Tool progress is cumulative, and its first restored reading is a baseline. */
17 export function sampleTurnArguments(s: State, argChars: number | undefined): State {
18 const sample = s.turnRateSample;
19 if (!sample || argChars === undefined || argChars <= 0) return s;
20 return { ...s, turnRateSample: { ...sample, argChars,
21 outputQuarters: sample.outputQuarters + (sample.argChars === undefined ? 0 : Math.max(0, argChars - sample.argChars)) } };
22 }
23
23 lines TYPESCRIPT