fix: prompt caching, conversation length management and token usage display
This commit is contained in:
@@ -63,6 +63,13 @@ vi.mock('../../src/main/engine/OpenCodeManager', () => ({
|
||||
options?.onDelta?.('stream-delta');
|
||||
options?.onToolCall?.({ name: 'search_posts', args: { query: 'q' } });
|
||||
options?.onToolResult?.({ name: 'search_posts', result: { ok: true } });
|
||||
options?.onTokenUsage?.({
|
||||
inputTokens: 100, outputTokens: 50,
|
||||
cacheReadTokens: 80, cacheWriteTokens: 20, totalTokens: 250,
|
||||
cumulativeInputTokens: 100, cumulativeOutputTokens: 50,
|
||||
cumulativeCacheReadTokens: 80, cumulativeCacheWriteTokens: 20,
|
||||
cumulativeTotalTokens: 250,
|
||||
});
|
||||
return {
|
||||
success: true,
|
||||
message: 'assistant reply',
|
||||
@@ -120,6 +127,7 @@ describe('chatHandlers', () => {
|
||||
onDelta: expect.any(Function),
|
||||
onToolCall: expect.any(Function),
|
||||
onToolResult: expect.any(Function),
|
||||
onTokenUsage: expect.any(Function),
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -135,5 +143,11 @@ describe('chatHandlers', () => {
|
||||
conversationId: 'conversation-1',
|
||||
result: { name: 'search_posts', result: { ok: true } },
|
||||
});
|
||||
expect(webContentsSend).toHaveBeenCalledWith('chat-token-usage', expect.objectContaining({
|
||||
conversationId: 'conversation-1',
|
||||
inputTokens: 100,
|
||||
outputTokens: 50,
|
||||
cacheReadTokens: 80,
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -81,6 +81,7 @@ function setupChatApi() {
|
||||
onToolResult: vi.fn(() => vi.fn()),
|
||||
onTitleUpdated: vi.fn(() => vi.fn()),
|
||||
onA2UIMessage: vi.fn(() => vi.fn()),
|
||||
onTokenUsage: vi.fn(() => vi.fn()),
|
||||
dispatchA2UIAction: vi.fn(),
|
||||
} as never;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ describe('AssistantSidebar wiring', () => {
|
||||
onToolResult,
|
||||
onTitleUpdated,
|
||||
onA2UIMessage: vi.fn(() => vi.fn()),
|
||||
onTokenUsage: vi.fn(() => vi.fn()),
|
||||
dispatchA2UIAction: vi.fn(),
|
||||
} as never;
|
||||
});
|
||||
|
||||
@@ -35,6 +35,7 @@ describe('assistant sidebar guard rails', () => {
|
||||
onToolResult: vi.fn(() => vi.fn()),
|
||||
onTitleUpdated: vi.fn(() => vi.fn()),
|
||||
onA2UIMessage: vi.fn(() => vi.fn()),
|
||||
onTokenUsage: vi.fn(() => vi.fn()),
|
||||
dispatchA2UIAction: vi.fn(),
|
||||
} as never;
|
||||
});
|
||||
|
||||
@@ -46,6 +46,7 @@ describe('chat surface mode usage guards', () => {
|
||||
onToolResult: vi.fn(() => vi.fn()),
|
||||
onTitleUpdated: vi.fn(() => vi.fn()),
|
||||
onA2UIMessage: vi.fn(() => vi.fn()),
|
||||
onTokenUsage: vi.fn(() => vi.fn()),
|
||||
dispatchA2UIAction: vi.fn(),
|
||||
} as never;
|
||||
});
|
||||
|
||||
@@ -49,6 +49,7 @@ describe('chat surface shared usage guards', () => {
|
||||
onToolResult: vi.fn(() => vi.fn()),
|
||||
onTitleUpdated: vi.fn(() => vi.fn()),
|
||||
onA2UIMessage: vi.fn(() => vi.fn()),
|
||||
onTokenUsage: vi.fn(() => vi.fn()),
|
||||
dispatchA2UIAction: vi.fn(),
|
||||
} as never;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user