feat(companion): add typed agent stream subscription helpers

This commit is contained in:
William Valentin
2026-02-16 19:08:13 -08:00
parent fc0dd8b73a
commit 0a43abd531
5 changed files with 62 additions and 1 deletions
+28
View File
@@ -196,6 +196,34 @@ describe('CompanionRuntimeClient', () => {
expect(streamHandler).toHaveBeenCalledTimes(1);
});
it('supports subscribeAgentStream and subscribeAgentTyping helpers', () => {
const client = new CompanionRuntimeClient({
url: 'ws://127.0.0.1:1',
});
const streamHandler = vi.fn();
const typingHandler = vi.fn();
client.subscribeAgentStream(streamHandler);
client.subscribeAgentTyping(typingHandler);
(client as unknown as { handleMessage: (raw: string) => void }).handleMessage(
JSON.stringify({
id: 52,
event: 'agent.stream',
data: { token: 'x' },
}),
);
(client as unknown as { handleMessage: (raw: string) => void }).handleMessage(
JSON.stringify({
id: 53,
event: 'agent.typing',
data: { active: true },
}),
);
expect(streamHandler).toHaveBeenCalledWith({ token: 'x' });
expect(typingHandler).toHaveBeenCalledWith({ active: true });
});
it('clears all event subscriptions', () => {
const client = new CompanionRuntimeClient({
url: 'ws://127.0.0.1:1',