chat: add additional timing information on the model#278449
Conversation
- Add a public created `timestamp` on the IChatModel
- Add a started `timestamp` and optional `completedAt` timestamp on
the IChatResponseModel
- Make `isPendingConfirmation<{startedWaitingAt: number}> | undefined`
to encode the time when the response started waiting for confirmation.
- Add a `confirmationAdjustedTimestamp` that can be used to reflect the
duration a chat response was waiting for user input vs working.
There was a problem hiding this comment.
Pull Request Overview
This PR adds comprehensive timing information to the chat model system to better track when chat responses start, complete, and wait for user confirmation. The changes enable more accurate duration calculations that account for time spent waiting for user input versus time spent actively generating content.
Key Changes
- Added public
timestampproperty toIChatModelandIChatResponseModelto record creation time - Added
completedAttimestamp onIChatResponseModelto track when responses finish - Enhanced
isPendingConfirmationto includestartedWaitingAttimestamp for tracking confirmation wait periods - Introduced
confirmationAdjustedTimestampobservable that adjusts the response timestamp to exclude user confirmation wait time
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/vs/workbench/contrib/chat/test/common/chatModel.test.ts | Adds comprehensive test suite for timestamp and confirmationAdjustedTimestamp behavior, including simulation of pending confirmation states using fake timers |
| src/vs/workbench/contrib/chat/common/chatModel.ts | Implements timing infrastructure with timestamp tracking, state-based completion tracking via ResponseModelState enum, and confirmation-adjusted timestamp calculation; updates serialization to persist timing data |
| src/vs/base/common/types.ts | Adds WithDefinedProps utility type to enforce explicit property definition in objects satisfying interfaces with optional properties |
| const toolState = observableValue<any>('state', { type: 0 /* IChatToolInvocation.StateKind.WaitingForConfirmation */ }); | ||
| const toolInvocation = { | ||
| kind: 'toolInvocation', | ||
| invocationMessage: 'calling tool', | ||
| state: toolState | ||
| } as Partial<IChatToolInvocation> as IChatToolInvocation; | ||
|
|
||
| model.acceptResponseProgress(request, toolInvocation); | ||
|
|
||
| // Advance time while pending | ||
| clock.tick(2000); | ||
| // Timestamp should still be start (it includes the wait time while waiting) | ||
| assert.strictEqual(response.confirmationAdjustedTimestamp.get(), start); | ||
|
|
||
| // Resolve confirmation | ||
| toolState.set({ type: 3 /* IChatToolInvocation.StateKind.Completed */ }, undefined); |
There was a problem hiding this comment.
The magic numbers 0 and 3 used for IChatToolInvocation.StateKind make the code less readable and maintainable. The comments indicate these represent WaitingForConfirmation and Completed respectively, but using the actual enum values would be clearer.
Consider importing the enum and using the named values: IChatToolInvocation.StateKind.WaitingForConfirmation and IChatToolInvocation.StateKind.Completed.
timestampon the IChatModeltimestampand optionalcompletedAttimestamp onthe IChatResponseModel
isPendingConfirmation<{startedWaitingAt: number}> | undefinedto encode the time when the response started waiting for confirmation.
confirmationAdjustedTimestampthat can be used to reflect theduration a chat response was waiting for user input vs working.
cc @bpasero