feat: implement tier-a4 tts voice output replies

This commit is contained in:
William Valentin
2026-02-18 10:22:28 -08:00
parent 3eb07875f1
commit a71aa5992d
11 changed files with 482 additions and 4 deletions
+150
View File
@@ -1122,6 +1122,156 @@ describe('daemon audio routing integration', () => {
});
});
describe('daemon tts routing integration', () => {
afterEach(() => {
vi.restoreAllMocks();
});
it('attaches synthesized audio reply when tts is enabled for the channel', async () => {
const processSpy = vi.spyOn(AgentOrchestrator.prototype, 'process').mockResolvedValue('voice-enabled response');
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue({
ok: true,
status: 200,
statusText: 'OK',
arrayBuffer: async () => Uint8Array.from([7, 8, 9]).buffer,
} as Response);
const session = {
id: 'telegram:tts-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,
},
compaction: { enabled: false },
models: { default: { provider: 'anthropic', model: 'claude' } },
tts: {
enabled: true,
enabled_channels: ['telegram'],
provider: {
type: 'custom',
endpoint: 'https://example.com/v1/audio/speech',
api_key: 'sk-test',
model: 'gpt-4o-mini-tts',
voice: 'alloy',
format: 'mp3',
},
},
} as unknown as MessageRouterDeps['config'],
});
const reply = vi.fn(async (_message: OutboundMessage) => {});
await router.handler({
id: 'tts-1',
channel: 'telegram',
senderId: 'tts-user-1',
text: 'say hello',
timestamp: Date.now(),
} as MessageRouterInput, reply);
expect(processSpy).toHaveBeenCalledTimes(1);
expect(fetchSpy).toHaveBeenCalledTimes(1);
const outbound = reply.mock.calls[0]?.[0] as OutboundMessage | undefined;
expect(outbound?.attachments).toBeDefined();
expect(outbound?.attachments?.[0]).toMatchObject({
mimeType: 'audio/mpeg',
data: 'BwgJ',
});
});
it('does not synthesize tts when channel is not enabled', async () => {
vi.spyOn(AgentOrchestrator.prototype, 'process').mockResolvedValue('text-only response');
const fetchSpy = vi.spyOn(globalThis, 'fetch');
const session = {
id: 'discord:tts-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,
},
compaction: { enabled: false },
models: { default: { provider: 'anthropic', model: 'claude' } },
tts: {
enabled: true,
enabled_channels: ['telegram'],
provider: {
type: 'custom',
endpoint: 'https://example.com/v1/audio/speech',
},
},
} as unknown as MessageRouterDeps['config'],
});
const reply = vi.fn(async (_message: OutboundMessage) => {});
await router.handler({
id: 'tts-2',
channel: 'discord',
senderId: 'tts-user-2',
text: 'respond as text',
timestamp: Date.now(),
} as MessageRouterInput, reply);
expect(fetchSpy).not.toHaveBeenCalled();
const outbound = reply.mock.calls[0]?.[0] as OutboundMessage | undefined;
expect(outbound?.attachments).toBeUndefined();
});
});
describe('daemon auto-escalate integration', () => {
afterEach(() => {
vi.restoreAllMocks();