Skip to content

Commit 8a0d8de

Browse files
voice mode handling
1 parent 4ead469 commit 8a0d8de

3 files changed

Lines changed: 591 additions & 129 deletions

File tree

src/directLine.mock.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface Conversation {
4141
export interface Server {
4242
scheduler: TestScheduler;
4343
conversation: Conversation;
44+
webSocketUrl?: string;
4445
}
4546

4647
const tokenPrefix = 'token';
@@ -223,6 +224,7 @@ type EventHandler<E extends Event> = (this: WebSocket, ev: E) => any;
223224
export const mockWebSocket = (server: Server): WebSocketConstructor =>
224225
class MockWebSocket implements WebSocket, ActivitySocket {
225226
constructor(url: string, protocols?: string | string[]) {
227+
server.webSocketUrl = url;
226228

227229
server.scheduler.schedule(() => {
228230
this.readyState = WebSocket.CONNECTING;
@@ -297,3 +299,36 @@ export const mockServices = (server: Server, scheduler: TestScheduler): DirectLi
297299
ajax: mockAjax(server),
298300
random: () => 0,
299301
});
302+
303+
// Helper to inject agent.capabilities event with audio support
304+
export const mockAgentCapabilitiesEvent = (): DirectLineExport.Activity => ({
305+
type: 'event',
306+
from: { id: 'bot' },
307+
name: 'agent.capabilities',
308+
value: {
309+
modalities: {
310+
text: {},
311+
audio: {
312+
fonts: [],
313+
tools: [],
314+
instructions: []
315+
}
316+
}
317+
}
318+
});
319+
320+
// Helper to inject agent.capabilities event into WebSocket
321+
export const injectAgentCapabilities = (server: Server): void => {
322+
const capabilitiesEvent = mockAgentCapabilitiesEvent();
323+
const activityGroup: DirectLineExport.ActivityGroup = {
324+
activities: [capabilitiesEvent],
325+
watermark: server.conversation.history.length.toString(),
326+
};
327+
const message = new MessageEvent('type', { data: JSON.stringify(activityGroup) });
328+
server.conversation.sockets.forEach(s => s.onmessage(message));
329+
};
330+
331+
// Helper to check if WebSocket URL contains multimodal path
332+
export const hasMultimodalUrl = (server: Server): boolean => {
333+
return !!server.webSocketUrl?.includes('/stream/multimodal');
334+
};

0 commit comments

Comments
 (0)