feat: add agent API and operational analytics

This commit is contained in:
jjbrunton committed 2026-08-08 22:08:14 +01:00
1 parent 720ea0652a
commit e8b730b592
65 files changed
+2650 -1214

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
import { describe, expect, it, vi } from 'vitest';
import { AgentJobManager } from '../src/web/agent-job-manager.js';
describe('AgentJobManager', () => {
it('tracks an asynchronous job through completion', async () => {
const execute = vi.fn(async () => ({ processed: 4 }));
const manager = new AgentJobManager(execute);
const created = manager.create({ type: 'chat-sync', kind: 'delta' });
expect(created.status).toBe('queued');
await vi.waitFor(() => expect(manager.get(created.id)?.status).toBe('succeeded'));
expect(manager.get(created.id)).toMatchObject({ result: { processed: 4 }, error: null });
});
it('records executor failures without losing the job', async () => {
const manager = new AgentJobManager(async () => { throw new Error('sync unavailable'); });
const created = manager.create({ type: 'media-sync', kind: 'full' });
await vi.waitFor(() => expect(manager.get(created.id)?.status).toBe('failed'));
expect(manager.get(created.id)?.error).toBe('sync unavailable');
});
});