import { describe, expect, it } from 'vitest'; import { ConfigError, loadConfig } from '../src/config.ts'; import { matchWake, wakeWordsFor } from '../src/wake.ts'; const agents = [ { id: 'default', wakeWords: ['pepper'] }, { id: 'wendy', wakeWords: ['wendy'] }, { id: 'cody', wakeWords: ['cody', 'kody', 'code e'] }, ]; describe('wake names', () => { it('a name said first addresses that agent, and what follows is the question', () => { expect(matchWake(' Wendy, what is on my calendar?', agents)).toEqual({ matched: true, agentId: 'wendy', text: 'What is on my calendar?' }); expect(matchWake('Pepper. Send Dan a message.', agents)).toEqual({ matched: true, agentId: 'default', text: 'Send Dan a message.' }); expect(matchWake('cody are the tests passing', agents)).toEqual({ matched: true, agentId: 'cody', text: 'Are the tests passing' }); }); it('a greeting before the name is allowed, and nothing else is', () => { expect(matchWake('Hey Wendy, hello', agents)).toMatchObject({ matched: true, agentId: 'wendy', text: 'Hello' }); expect(matchWake('OK, Pepper: lights off', agents)).toMatchObject({ matched: true, agentId: 'default', text: 'Lights off' }); expect(matchWake('So Wendy, hello', agents).matched).toBe(false); expect(matchWake('Hey', agents).matched).toBe(false); }); it('the name alone matches with an empty question', () => { expect(matchWake('Wendy.', agents)).toEqual({ matched: true, agentId: 'wendy', text: '' }); expect(matchWake('Hey Cody!', agents)).toEqual({ matched: true, agentId: 'cody', text: '' }); }); it('a name anywhere but first never matches', () => { for (const said of ['I told Wendy about it', 'ask Pepper later', 'is that Cody', '', ' ', '[BLANK_AUDIO]', '(wind blowing)']) { expect(matchWake(said, agents).matched, said).toBe(false); } }); it('aliases match, including one of two words, and the longest wins', () => { expect(matchWake('Kody, status', agents)).toMatchObject({ matched: true, agentId: 'cody', text: 'Status' }); expect(matchWake('Code E, status', agents)).toMatchObject({ matched: true, agentId: 'cody', text: 'Status' }); }); it('a word that is only close to a name is reported as a near miss and does not match', () => { expect(matchWake('Wendi, what time is it', agents)).toEqual({ matched: false, nearMiss: 'wendi' }); expect(matchWake('Copy that', agents)).toEqual({ matched: false, nearMiss: 'copy' }); expect(matchWake('Paper is on the desk', agents)).toEqual({ matched: false, nearMiss: 'paper' }); expect(matchWake('Wednesday works', agents)).toEqual({ matched: false, nearMiss: null }); }); it('wake words come from the first word of the name plus aliases', () => { expect(wakeWordsFor('Cody R.', ['Kody', ' code-e '])).toEqual(['cody', 'kody', 'code e']); expect(wakeWordsFor('R2', [])).toEqual([]); expect(wakeWordsFor('', ['Friday'])).toEqual(['friday']); }); }); describe('wake names in configuration', () => { const base = { HERMES_API_KEY: 'k'.repeat(24), STT_PROVIDER: 'none' }; it('each agent answers to its name; the unnamed default agent answers to nothing', () => { const config = loadConfig({ ...base, HERMEVEN_AGENTS: 'wendy', HERMEVEN_AGENT_WENDY_API_KEY: 'w'.repeat(24), HERMEVEN_AGENT_WENDY_WAKE: 'wendi, windy' }); expect(config.agents.map((a) => a.wakeWords)).toEqual([[], ['wendy', 'wendi', 'windy']]); expect(loadConfig({ ...base, HERMEVEN_AGENT_NAME: 'Pepper' }).agents[0]!.wakeWords).toEqual(['pepper']); expect(loadConfig({ ...base, HERMEVEN_AGENT_WAKE: 'friday' }).agents[0]!.wakeWords).toEqual(['friday']); }); it('two agents may not answer to the same word', () => { expect(() => loadConfig({ ...base, HERMEVEN_AGENT_NAME: 'Pepper', HERMEVEN_AGENTS: 'wendy', HERMEVEN_AGENT_WENDY_API_KEY: 'w'.repeat(24), HERMEVEN_AGENT_WENDY_WAKE: 'pepper' }), ).toThrow(ConfigError); }); });