feat: enhance token usage tracking and history management

- Updated HTML assets for improved loading.
- Integrated token usage tracking in chat processing, appending usage details to transcripts.
- Enhanced OpenAIProvider to include usage data in chat completion responses.
- Implemented asynchronous retrieval of recent token usage history.
- Added utility functions for managing transcript files and parsing usage data.
- Updated UI components to reflect changes in usage status handling.
- Ensured consistent usage status definitions across the application.
This commit is contained in:
DEV_DSW
2026-04-15 11:45:33 +08:00
parent 9afb518a19
commit 78d3235ab6
12 changed files with 533 additions and 2577 deletions

View File

@@ -5,9 +5,11 @@ import logManager from "@electron/service/logger"
function _transformChunk(chunk: OpenAI.Chat.Completions.ChatCompletionChunk): UniversalChunk {
const choice = chunk.choices[0];
const usage = (chunk as any).usage;
return {
isEnd: choice?.finish_reason != null,
isEnd: choice?.finish_reason != null || (chunk.choices.length === 0 && usage != null),
result: choice?.delta?.content ?? '',
usage: usage ?? undefined,
}
}
@@ -35,6 +37,7 @@ export class OpenAIProvider extends BaseProvider {
model,
messages: messages as any,
stream: true,
stream_options: { include_usage: true },
}, {
signal: options?.signal,
});