23df8bf967
* make waitlist code field required all existing rows have been backfilled with unique codes via the consolidation script. Co-authored-by: Cursor <cursoragent@cursor.com> * fix lint errors Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import { log } from "./cli.ts";
|
|
|
|
export class Timer {
|
|
private initialTimestamp: number;
|
|
private lastCheckpointTimestamp: number | null = null;
|
|
|
|
constructor() {
|
|
this.initialTimestamp = Date.now();
|
|
}
|
|
|
|
checkpoint(name: string): void {
|
|
const now = Date.now();
|
|
const duration = this.lastCheckpointTimestamp
|
|
? now - this.lastCheckpointTimestamp
|
|
: now - this.initialTimestamp;
|
|
|
|
log.debug(`» ${name}: ${duration}ms`);
|
|
this.lastCheckpointTimestamp = now;
|
|
}
|
|
}
|
|
|
|
const THINKING_THRESHOLD = 3000; // ms
|
|
|
|
export class ThinkingTimer {
|
|
private readonly durationFormatter = new Intl.NumberFormat("en-US", {
|
|
style: "unit",
|
|
unit: "second",
|
|
unitDisplay: "long",
|
|
minimumFractionDigits: 0,
|
|
maximumFractionDigits: 1,
|
|
});
|
|
|
|
private lastToolResultTimestamp: number | null = null;
|
|
|
|
markToolResult(): void {
|
|
this.lastToolResultTimestamp = Date.now();
|
|
log.debug(`» thinking timer: markToolResult at ${this.lastToolResultTimestamp}`);
|
|
}
|
|
|
|
markToolCall(): void {
|
|
const now = Date.now();
|
|
log.debug(
|
|
`» thinking timer: markToolCall at ${now}, lastToolResult=${this.lastToolResultTimestamp}`
|
|
);
|
|
if (this.lastToolResultTimestamp === null) return;
|
|
const elapsed = now - this.lastToolResultTimestamp;
|
|
if (elapsed < THINKING_THRESHOLD) return;
|
|
const seconds = elapsed / 1000;
|
|
log.info(`» thought for ${this.durationFormatter.format(seconds)}`);
|
|
}
|
|
}
|