Add attention inbox and AI usage observability
This commit is contained in:
1 parent
ca59ba0f1f
commit
83b5f1f5b6
30 files changed
+702
-28
No files matched your search
@@ -703,6 +703,36 @@ describe('OpenRouterClient', () => {
|
||||
).rejects.toThrow('network');
|
||||
});
|
||||
});
|
||||
|
||||
it('records model, token, cost, latency, and outcome for each request attempt', async () => {
|
||||
const usageRecorder = vi.fn();
|
||||
const config = getTestConfig();
|
||||
const localClient = new OpenRouterClient(
|
||||
config,
|
||||
logger,
|
||||
{ chat: { completions: { create: mockCreate } } } as unknown as OpenAI,
|
||||
usageRecorder,
|
||||
);
|
||||
mockCreate.mockResolvedValueOnce({
|
||||
model: 'provider/model-a',
|
||||
choices: [{ message: { content: 'A useful reply' } }],
|
||||
usage: { prompt_tokens: 100, completion_tokens: 12, total_tokens: 112, cost: 0.0017 },
|
||||
});
|
||||
|
||||
await localClient.generateReply([{ sender: 'them', text: 'hello?', isSelf: false }], 'them');
|
||||
|
||||
expect(usageRecorder).toHaveBeenCalledWith(expect.objectContaining({
|
||||
operation: 'generateReply',
|
||||
requestedModel: config.openrouter.chatModel,
|
||||
actualModel: 'provider/model-a',
|
||||
outcome: 'success',
|
||||
promptTokens: 100,
|
||||
completionTokens: 12,
|
||||
totalTokens: 112,
|
||||
costUsd: 0.0017,
|
||||
latencyMs: expect.any(Number),
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('stripDashes', () => {
|
||||
|
||||
Reference in new issue
Block a user