feat: add automation reactions event-trigger layer
This commit is contained in:
@@ -1272,6 +1272,142 @@ describe('daemon tts routing integration', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('daemon reactions routing integration', () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('rewrites automation event prompts when a reaction rule matches', async () => {
|
||||
const processSpy = vi.spyOn(AgentOrchestrator.prototype, 'process').mockResolvedValue('ok');
|
||||
|
||||
const session = {
|
||||
id: 'gmail:reaction-user-1',
|
||||
addMessage: vi.fn(),
|
||||
getHistory: vi.fn(() => []),
|
||||
clear: vi.fn(),
|
||||
replaceHistory: vi.fn(),
|
||||
getConfig: vi.fn(() => undefined),
|
||||
setConfig: vi.fn(),
|
||||
deleteConfig: vi.fn(),
|
||||
};
|
||||
|
||||
const router = createMessageRouter({
|
||||
sessionManager: { getSession: vi.fn(() => session) } as unknown as MessageRouterDeps['sessionManager'],
|
||||
modelRouter: {
|
||||
getAvailableTiers: () => ['default'],
|
||||
getAllLabels: () => ({ default: 'default' }),
|
||||
getLabel: (tier: string) => tier,
|
||||
} as unknown as MessageRouterDeps['modelRouter'],
|
||||
systemPrompt: 'test prompt',
|
||||
toolRegistry: { clone() { return this; }, register: vi.fn() } as unknown as MessageRouterDeps['toolRegistry'],
|
||||
toolExecutor: {} as unknown as MessageRouterDeps['toolExecutor'],
|
||||
config: {
|
||||
agents: {
|
||||
primary_tier: 'default',
|
||||
delegation: {
|
||||
compaction: 'default',
|
||||
memory_extraction: 'default',
|
||||
classification: 'default',
|
||||
tool_summarisation: 'default',
|
||||
complex_reasoning: 'default',
|
||||
},
|
||||
max_delegation_depth: 1,
|
||||
max_iterations: 3,
|
||||
},
|
||||
automation: {
|
||||
reactions: [{
|
||||
name: 'boss-email',
|
||||
enabled: true,
|
||||
on: ['gmail'],
|
||||
filter: { contains: 'boss@company.com' },
|
||||
run: 'Summarize and suggest next steps:\n\n{{text}}',
|
||||
}],
|
||||
},
|
||||
compaction: { enabled: false },
|
||||
models: { default: { provider: 'anthropic', model: 'claude' } },
|
||||
} as unknown as MessageRouterDeps['config'],
|
||||
});
|
||||
|
||||
await router.handler({
|
||||
id: 'r1',
|
||||
channel: 'gmail',
|
||||
senderId: 'reaction-user-1',
|
||||
text: 'New email from boss@company.com: Please share timeline',
|
||||
timestamp: Date.now(),
|
||||
} as MessageRouterInput, vi.fn(async (_message: OutboundMessage) => {}));
|
||||
|
||||
expect(processSpy).toHaveBeenCalledTimes(1);
|
||||
const [prompt] = processSpy.mock.calls[0] ?? [];
|
||||
expect(prompt).toBe(
|
||||
'Summarize and suggest next steps:\n\nNew email from boss@company.com: Please share timeline',
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps original prompt when no reaction rule matches', async () => {
|
||||
const processSpy = vi.spyOn(AgentOrchestrator.prototype, 'process').mockResolvedValue('ok');
|
||||
|
||||
const session = {
|
||||
id: 'gmail:reaction-user-2',
|
||||
addMessage: vi.fn(),
|
||||
getHistory: vi.fn(() => []),
|
||||
clear: vi.fn(),
|
||||
replaceHistory: vi.fn(),
|
||||
getConfig: vi.fn(() => undefined),
|
||||
setConfig: vi.fn(),
|
||||
deleteConfig: vi.fn(),
|
||||
};
|
||||
|
||||
const router = createMessageRouter({
|
||||
sessionManager: { getSession: vi.fn(() => session) } as unknown as MessageRouterDeps['sessionManager'],
|
||||
modelRouter: {
|
||||
getAvailableTiers: () => ['default'],
|
||||
getAllLabels: () => ({ default: 'default' }),
|
||||
getLabel: (tier: string) => tier,
|
||||
} as unknown as MessageRouterDeps['modelRouter'],
|
||||
systemPrompt: 'test prompt',
|
||||
toolRegistry: { clone() { return this; }, register: vi.fn() } as unknown as MessageRouterDeps['toolRegistry'],
|
||||
toolExecutor: {} as unknown as MessageRouterDeps['toolExecutor'],
|
||||
config: {
|
||||
agents: {
|
||||
primary_tier: 'default',
|
||||
delegation: {
|
||||
compaction: 'default',
|
||||
memory_extraction: 'default',
|
||||
classification: 'default',
|
||||
tool_summarisation: 'default',
|
||||
complex_reasoning: 'default',
|
||||
},
|
||||
max_delegation_depth: 1,
|
||||
max_iterations: 3,
|
||||
},
|
||||
automation: {
|
||||
reactions: [{
|
||||
name: 'boss-email',
|
||||
enabled: true,
|
||||
on: ['gmail'],
|
||||
filter: { contains: 'boss@company.com' },
|
||||
run: 'Summarize: {{text}}',
|
||||
}],
|
||||
},
|
||||
compaction: { enabled: false },
|
||||
models: { default: { provider: 'anthropic', model: 'claude' } },
|
||||
} as unknown as MessageRouterDeps['config'],
|
||||
});
|
||||
|
||||
await router.handler({
|
||||
id: 'r2',
|
||||
channel: 'gmail',
|
||||
senderId: 'reaction-user-2',
|
||||
text: 'New email from teammate@company.com: FYI',
|
||||
timestamp: Date.now(),
|
||||
} as MessageRouterInput, vi.fn(async (_message: OutboundMessage) => {}));
|
||||
|
||||
expect(processSpy).toHaveBeenCalledTimes(1);
|
||||
const [prompt] = processSpy.mock.calls[0] ?? [];
|
||||
expect(prompt).toBe('New email from teammate@company.com: FYI');
|
||||
});
|
||||
});
|
||||
|
||||
describe('daemon auto-escalate integration', () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
|
||||
Reference in New Issue
Block a user