From 43627914a300f95cc008db9e11a80e6257ee4bda Mon Sep 17 00:00:00 2001 From: Harry Smaje Date: Tue, 28 Oct 2025 16:57:22 +0000 Subject: [PATCH 1/6] feat: add support for TOOL_CALL and CLIENT_EVENT data channel message types - Added ToolCallEvent and ClientEventEvent type definitions - Extended DataChannelMessage enum with TOOL_CALL and CLIENT_EVENT - Added internal events WEBRTC_TOOL_CALL_RECEIVED and WEBRTC_CLIENT_EVENT_RECEIVED - Added public events TOOL_CALL_RECEIVED and CLIENT_EVENT_RECEIVED - Updated StreamingClient to handle and emit new message types - Added event callbacks for consumers to listen to tool calls and client events --- src/modules/StreamingClient.ts | 40 ++++++++++++++----- src/types/events/internal/InternalEvent.ts | 2 + .../events/internal/InternalEventCallbacks.ts | 6 +++ src/types/events/public/AnamEvent.ts | 2 + src/types/events/public/EventCallbacks.ts | 10 ++++- src/types/streaming/ClientEventEvent.ts | 6 +++ src/types/streaming/DataChannelMessage.ts | 2 + src/types/streaming/ToolCallEvent.ts | 6 +++ src/types/streaming/index.ts | 2 + 9 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 src/types/streaming/ClientEventEvent.ts create mode 100644 src/types/streaming/ToolCallEvent.ts diff --git a/src/modules/StreamingClient.ts b/src/modules/StreamingClient.ts index a668b34..4ec6256 100644 --- a/src/modules/StreamingClient.ts +++ b/src/modules/StreamingClient.ts @@ -1,3 +1,8 @@ +import { + ClientMetricMeasurement, + createRTCStatsReport, + sendClientMetric, +} from '../lib/ClientMetrics'; import { EngineApiRestClient, InternalEventEmitter, @@ -6,24 +11,21 @@ import { } from '../modules'; import { AnamEvent, - InputAudioState, + ApiGatewayConfig, AudioPermissionState, + ClientEventEvent, + ConnectionClosedCode, + DataChannelMessage, + InputAudioState, InternalEvent, SignalMessage, SignalMessageAction, StreamingClientOptions, + ToolCallEvent, WebRtcTextMessageEvent, - ConnectionClosedCode, - ApiGatewayConfig, - DataChannelMessage, } from '../types'; import { TalkMessageStream } from '../types/TalkMessageStream'; import { TalkStreamInterruptedSignalMessage } from '../types/signalling/TalkStreamInterruptedSignalMessage'; -import { - ClientMetricMeasurement, - createRTCStatsReport, - sendClientMetric, -} from '../lib/ClientMetrics'; const SUCCESS_METRIC_POLLING_TIMEOUT_MS = 15000; // After this time we will stop polling for the first frame and consider the session a failure. const STATS_COLLECTION_INTERVAL_MS = 5000; @@ -671,6 +673,26 @@ export class StreamingClient { message.data as WebRtcTextMessageEvent, ); break; + case DataChannelMessage.TOOL_CALL: + this.internalEventEmitter.emit( + InternalEvent.WEBRTC_TOOL_CALL_RECEIVED, + message.data as ToolCallEvent, + ); + this.publicEventEmitter.emit( + AnamEvent.TOOL_CALL_RECEIVED, + message.data as ToolCallEvent, + ); + break; + case DataChannelMessage.CLIENT_EVENT: + this.internalEventEmitter.emit( + InternalEvent.WEBRTC_CLIENT_EVENT_RECEIVED, + message.data as ClientEventEvent, + ); + this.publicEventEmitter.emit( + AnamEvent.CLIENT_EVENT_RECEIVED, + message.data as ClientEventEvent, + ); + break; // Unknown message types are silently ignored to maintain forward compatibility default: break; diff --git a/src/types/events/internal/InternalEvent.ts b/src/types/events/internal/InternalEvent.ts index e7b58dc..5a5497f 100644 --- a/src/types/events/internal/InternalEvent.ts +++ b/src/types/events/internal/InternalEvent.ts @@ -2,4 +2,6 @@ export enum InternalEvent { WEB_SOCKET_OPEN = 'WEB_SOCKET_OPEN', SIGNAL_MESSAGE_RECEIVED = 'SIGNAL_MESSAGE_RECEIVED', WEBRTC_CHAT_MESSAGE_RECEIVED = 'WEBRTC_CHAT_MESSAGE_RECEIVED', + WEBRTC_TOOL_CALL_RECEIVED = 'WEBRTC_TOOL_CALL_RECEIVED', + WEBRTC_CLIENT_EVENT_RECEIVED = 'WEBRTC_CLIENT_EVENT_RECEIVED', } diff --git a/src/types/events/internal/InternalEventCallbacks.ts b/src/types/events/internal/InternalEventCallbacks.ts index 23b233a..9ba626c 100644 --- a/src/types/events/internal/InternalEventCallbacks.ts +++ b/src/types/events/internal/InternalEventCallbacks.ts @@ -2,6 +2,8 @@ import { InternalEvent, SignalMessage, WebRtcTextMessageEvent, + ToolCallEvent, + ClientEventEvent, } from '../../index'; export type InternalEventCallbacks = { @@ -12,4 +14,8 @@ export type InternalEventCallbacks = { [InternalEvent.WEBRTC_CHAT_MESSAGE_RECEIVED]: ( message: WebRtcTextMessageEvent, ) => void; + [InternalEvent.WEBRTC_TOOL_CALL_RECEIVED]: (toolCall: ToolCallEvent) => void; + [InternalEvent.WEBRTC_CLIENT_EVENT_RECEIVED]: ( + clientEvent: ClientEventEvent, + ) => void; }; diff --git a/src/types/events/public/AnamEvent.ts b/src/types/events/public/AnamEvent.ts index 5b4e00a..2f87095 100644 --- a/src/types/events/public/AnamEvent.ts +++ b/src/types/events/public/AnamEvent.ts @@ -14,4 +14,6 @@ export enum AnamEvent { MIC_PERMISSION_GRANTED = 'MIC_PERMISSION_GRANTED', MIC_PERMISSION_DENIED = 'MIC_PERMISSION_DENIED', INPUT_AUDIO_DEVICE_CHANGED = 'INPUT_AUDIO_DEVICE_CHANGED', + TOOL_CALL_RECEIVED = 'TOOL_CALL_RECEIVED', + CLIENT_EVENT_RECEIVED = 'CLIENT_EVENT_RECEIVED', } diff --git a/src/types/events/public/EventCallbacks.ts b/src/types/events/public/EventCallbacks.ts index beca017..6a9c065 100644 --- a/src/types/events/public/EventCallbacks.ts +++ b/src/types/events/public/EventCallbacks.ts @@ -1,5 +1,11 @@ import { ConnectionClosedCode } from './ConnectionClosedCodes'; -import { Message, MessageStreamEvent, AnamEvent } from '../../index'; +import { + Message, + MessageStreamEvent, + AnamEvent, + ToolCallEvent, + ClientEventEvent, +} from '../../index'; export type EventCallbacks = { [AnamEvent.MESSAGE_HISTORY_UPDATED]: (messages: Message[]) => void; @@ -22,4 +28,6 @@ export type EventCallbacks = { [AnamEvent.MIC_PERMISSION_GRANTED]: () => void; [AnamEvent.MIC_PERMISSION_DENIED]: (error: string) => void; [AnamEvent.INPUT_AUDIO_DEVICE_CHANGED]: (deviceId: string) => void; + [AnamEvent.TOOL_CALL_RECEIVED]: (toolCall: ToolCallEvent) => void; + [AnamEvent.CLIENT_EVENT_RECEIVED]: (clientEvent: ClientEventEvent) => void; }; diff --git a/src/types/streaming/ClientEventEvent.ts b/src/types/streaming/ClientEventEvent.ts new file mode 100644 index 0000000..6f37e1c --- /dev/null +++ b/src/types/streaming/ClientEventEvent.ts @@ -0,0 +1,6 @@ +export interface ClientEventEvent { + event_id: string; + event_type: string; + data: Record; + timestamp: string; +} diff --git a/src/types/streaming/DataChannelMessage.ts b/src/types/streaming/DataChannelMessage.ts index 8e3646e..9f9baac 100644 --- a/src/types/streaming/DataChannelMessage.ts +++ b/src/types/streaming/DataChannelMessage.ts @@ -1,3 +1,5 @@ export enum DataChannelMessage { SPEECH_TEXT = 'speechText', + TOOL_CALL = 'toolCall', + CLIENT_EVENT = 'clientEvent', } diff --git a/src/types/streaming/ToolCallEvent.ts b/src/types/streaming/ToolCallEvent.ts new file mode 100644 index 0000000..a7c7b7f --- /dev/null +++ b/src/types/streaming/ToolCallEvent.ts @@ -0,0 +1,6 @@ +export interface ToolCallEvent { + tool_call_id: string; + tool_name: string; + arguments: Record; + timestamp: string; +} diff --git a/src/types/streaming/index.ts b/src/types/streaming/index.ts index d1fdb0b..d1c4a14 100644 --- a/src/types/streaming/index.ts +++ b/src/types/streaming/index.ts @@ -1,4 +1,6 @@ export type { WebRtcTextMessageEvent } from './WebRtcTextMessageEvent'; +export type { ToolCallEvent } from './ToolCallEvent'; +export type { ClientEventEvent } from './ClientEventEvent'; export type { StreamingClientOptions } from './StreamingClientOptions'; export type { InputAudioOptions } from './InputAudioOptions'; export { DataChannelMessage } from './DataChannelMessage'; From 615b0239986ccf06f5f1aeb152253401e1f6a31a Mon Sep 17 00:00:00 2001 From: Harry Smaje Date: Tue, 28 Oct 2025 17:16:00 +0000 Subject: [PATCH 2/6] refactor: rename CLIENT_EVENT to CLIENT_TOOL_EVENT and remove TOOL_CALL - Removed ToolCallEvent type and TOOL_CALL message type - Renamed ClientEventEvent to ClientToolEvent - Renamed CLIENT_EVENT to CLIENT_TOOL_EVENT across all enums and event handlers - Updated internal event WEBRTC_CLIENT_EVENT_RECEIVED to WEBRTC_CLIENT_TOOL_EVENT_RECEIVED - Updated public event CLIENT_EVENT_RECEIVED to CLIENT_TOOL_EVENT_RECEIVED - Updated StreamingClient to handle only CLIENT_TOOL_EVENT message type --- package.json | 2 +- src/modules/StreamingClient.ts | 23 +++++-------------- src/types/events/internal/InternalEvent.ts | 3 +-- .../events/internal/InternalEventCallbacks.ts | 8 +++---- src/types/events/public/AnamEvent.ts | 3 +-- src/types/events/public/EventCallbacks.ts | 8 +++---- ...ClientEventEvent.ts => ClientToolEvent.ts} | 2 +- src/types/streaming/DataChannelMessage.ts | 3 +-- src/types/streaming/ToolCallEvent.ts | 6 ----- src/types/streaming/index.ts | 3 +-- 10 files changed, 19 insertions(+), 42 deletions(-) rename src/types/streaming/{ClientEventEvent.ts => ClientToolEvent.ts} (73%) delete mode 100644 src/types/streaming/ToolCallEvent.ts diff --git a/package.json b/package.json index 0966592..3d43c21 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@anam-ai/js-sdk", - "version": "0.0.0-automated", + "version": "4.3.0-harry-test.alpha.0", "description": "Client side JavaScript SDK for Anam AI", "author": "Anam AI", "main": "dist/main/index.js", diff --git a/src/modules/StreamingClient.ts b/src/modules/StreamingClient.ts index 4ec6256..d28bb7c 100644 --- a/src/modules/StreamingClient.ts +++ b/src/modules/StreamingClient.ts @@ -13,7 +13,7 @@ import { AnamEvent, ApiGatewayConfig, AudioPermissionState, - ClientEventEvent, + ClientToolEvent, ConnectionClosedCode, DataChannelMessage, InputAudioState, @@ -21,7 +21,6 @@ import { SignalMessage, SignalMessageAction, StreamingClientOptions, - ToolCallEvent, WebRtcTextMessageEvent, } from '../types'; import { TalkMessageStream } from '../types/TalkMessageStream'; @@ -673,24 +672,14 @@ export class StreamingClient { message.data as WebRtcTextMessageEvent, ); break; - case DataChannelMessage.TOOL_CALL: + case DataChannelMessage.CLIENT_TOOL_EVENT: this.internalEventEmitter.emit( - InternalEvent.WEBRTC_TOOL_CALL_RECEIVED, - message.data as ToolCallEvent, + InternalEvent.WEBRTC_CLIENT_TOOL_EVENT_RECEIVED, + message.data as ClientToolEvent, ); this.publicEventEmitter.emit( - AnamEvent.TOOL_CALL_RECEIVED, - message.data as ToolCallEvent, - ); - break; - case DataChannelMessage.CLIENT_EVENT: - this.internalEventEmitter.emit( - InternalEvent.WEBRTC_CLIENT_EVENT_RECEIVED, - message.data as ClientEventEvent, - ); - this.publicEventEmitter.emit( - AnamEvent.CLIENT_EVENT_RECEIVED, - message.data as ClientEventEvent, + AnamEvent.CLIENT_TOOL_EVENT_RECEIVED, + message.data as ClientToolEvent, ); break; // Unknown message types are silently ignored to maintain forward compatibility diff --git a/src/types/events/internal/InternalEvent.ts b/src/types/events/internal/InternalEvent.ts index 5a5497f..bd677da 100644 --- a/src/types/events/internal/InternalEvent.ts +++ b/src/types/events/internal/InternalEvent.ts @@ -2,6 +2,5 @@ export enum InternalEvent { WEB_SOCKET_OPEN = 'WEB_SOCKET_OPEN', SIGNAL_MESSAGE_RECEIVED = 'SIGNAL_MESSAGE_RECEIVED', WEBRTC_CHAT_MESSAGE_RECEIVED = 'WEBRTC_CHAT_MESSAGE_RECEIVED', - WEBRTC_TOOL_CALL_RECEIVED = 'WEBRTC_TOOL_CALL_RECEIVED', - WEBRTC_CLIENT_EVENT_RECEIVED = 'WEBRTC_CLIENT_EVENT_RECEIVED', + WEBRTC_CLIENT_TOOL_EVENT_RECEIVED = 'WEBRTC_CLIENT_TOOL_EVENT_RECEIVED', } diff --git a/src/types/events/internal/InternalEventCallbacks.ts b/src/types/events/internal/InternalEventCallbacks.ts index 9ba626c..100a20e 100644 --- a/src/types/events/internal/InternalEventCallbacks.ts +++ b/src/types/events/internal/InternalEventCallbacks.ts @@ -2,8 +2,7 @@ import { InternalEvent, SignalMessage, WebRtcTextMessageEvent, - ToolCallEvent, - ClientEventEvent, + ClientToolEvent, } from '../../index'; export type InternalEventCallbacks = { @@ -14,8 +13,7 @@ export type InternalEventCallbacks = { [InternalEvent.WEBRTC_CHAT_MESSAGE_RECEIVED]: ( message: WebRtcTextMessageEvent, ) => void; - [InternalEvent.WEBRTC_TOOL_CALL_RECEIVED]: (toolCall: ToolCallEvent) => void; - [InternalEvent.WEBRTC_CLIENT_EVENT_RECEIVED]: ( - clientEvent: ClientEventEvent, + [InternalEvent.WEBRTC_CLIENT_TOOL_EVENT_RECEIVED]: ( + clientToolEvent: ClientToolEvent, ) => void; }; diff --git a/src/types/events/public/AnamEvent.ts b/src/types/events/public/AnamEvent.ts index 2f87095..1d8e185 100644 --- a/src/types/events/public/AnamEvent.ts +++ b/src/types/events/public/AnamEvent.ts @@ -14,6 +14,5 @@ export enum AnamEvent { MIC_PERMISSION_GRANTED = 'MIC_PERMISSION_GRANTED', MIC_PERMISSION_DENIED = 'MIC_PERMISSION_DENIED', INPUT_AUDIO_DEVICE_CHANGED = 'INPUT_AUDIO_DEVICE_CHANGED', - TOOL_CALL_RECEIVED = 'TOOL_CALL_RECEIVED', - CLIENT_EVENT_RECEIVED = 'CLIENT_EVENT_RECEIVED', + CLIENT_TOOL_EVENT_RECEIVED = 'CLIENT_TOOL_EVENT_RECEIVED', } diff --git a/src/types/events/public/EventCallbacks.ts b/src/types/events/public/EventCallbacks.ts index 6a9c065..dcd258f 100644 --- a/src/types/events/public/EventCallbacks.ts +++ b/src/types/events/public/EventCallbacks.ts @@ -3,8 +3,7 @@ import { Message, MessageStreamEvent, AnamEvent, - ToolCallEvent, - ClientEventEvent, + ClientToolEvent, } from '../../index'; export type EventCallbacks = { @@ -28,6 +27,7 @@ export type EventCallbacks = { [AnamEvent.MIC_PERMISSION_GRANTED]: () => void; [AnamEvent.MIC_PERMISSION_DENIED]: (error: string) => void; [AnamEvent.INPUT_AUDIO_DEVICE_CHANGED]: (deviceId: string) => void; - [AnamEvent.TOOL_CALL_RECEIVED]: (toolCall: ToolCallEvent) => void; - [AnamEvent.CLIENT_EVENT_RECEIVED]: (clientEvent: ClientEventEvent) => void; + [AnamEvent.CLIENT_TOOL_EVENT_RECEIVED]: ( + clientToolEvent: ClientToolEvent, + ) => void; }; diff --git a/src/types/streaming/ClientEventEvent.ts b/src/types/streaming/ClientToolEvent.ts similarity index 73% rename from src/types/streaming/ClientEventEvent.ts rename to src/types/streaming/ClientToolEvent.ts index 6f37e1c..402bf53 100644 --- a/src/types/streaming/ClientEventEvent.ts +++ b/src/types/streaming/ClientToolEvent.ts @@ -1,4 +1,4 @@ -export interface ClientEventEvent { +export interface ClientToolEvent { event_id: string; event_type: string; data: Record; diff --git a/src/types/streaming/DataChannelMessage.ts b/src/types/streaming/DataChannelMessage.ts index 9f9baac..7913f4b 100644 --- a/src/types/streaming/DataChannelMessage.ts +++ b/src/types/streaming/DataChannelMessage.ts @@ -1,5 +1,4 @@ export enum DataChannelMessage { SPEECH_TEXT = 'speechText', - TOOL_CALL = 'toolCall', - CLIENT_EVENT = 'clientEvent', + CLIENT_TOOL_EVENT = 'clientToolEvent', } diff --git a/src/types/streaming/ToolCallEvent.ts b/src/types/streaming/ToolCallEvent.ts deleted file mode 100644 index a7c7b7f..0000000 --- a/src/types/streaming/ToolCallEvent.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface ToolCallEvent { - tool_call_id: string; - tool_name: string; - arguments: Record; - timestamp: string; -} diff --git a/src/types/streaming/index.ts b/src/types/streaming/index.ts index d1c4a14..21d7b0c 100644 --- a/src/types/streaming/index.ts +++ b/src/types/streaming/index.ts @@ -1,6 +1,5 @@ export type { WebRtcTextMessageEvent } from './WebRtcTextMessageEvent'; -export type { ToolCallEvent } from './ToolCallEvent'; -export type { ClientEventEvent } from './ClientEventEvent'; +export type { ClientToolEvent } from './ClientToolEvent'; export type { StreamingClientOptions } from './StreamingClientOptions'; export type { InputAudioOptions } from './InputAudioOptions'; export { DataChannelMessage } from './DataChannelMessage'; From 31e633b13abffcbb054d440abba9a6d102628a85 Mon Sep 17 00:00:00 2001 From: Harry Smaje Date: Tue, 28 Oct 2025 17:19:56 +0000 Subject: [PATCH 3/6] revert package --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3d43c21..0966592 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@anam-ai/js-sdk", - "version": "4.3.0-harry-test.alpha.0", + "version": "0.0.0-automated", "description": "Client side JavaScript SDK for Anam AI", "author": "Anam AI", "main": "dist/main/index.js", From 1b8ec1165f0e0ecc8a7a23a81df37ca5a34a4c2b Mon Sep 17 00:00:00 2001 From: Harry Smaje Date: Tue, 28 Oct 2025 18:47:24 +0000 Subject: [PATCH 4/6] fix: update ClientToolEvent interface to match engine types - Changed event_id to event_uid - Changed event_type to event_name - Changed data to event_data - Added session_id field - Added timestamp_user_action field - Added user_action_correlation_id field - Added used_outside_engine boolean field - Updated comments to reflect actual usage from engine --- package.json | 2 +- src/types/streaming/ClientToolEvent.ts | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 0966592..3d43c21 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@anam-ai/js-sdk", - "version": "0.0.0-automated", + "version": "4.3.0-harry-test.alpha.0", "description": "Client side JavaScript SDK for Anam AI", "author": "Anam AI", "main": "dist/main/index.js", diff --git a/src/types/streaming/ClientToolEvent.ts b/src/types/streaming/ClientToolEvent.ts index 402bf53..c9a9790 100644 --- a/src/types/streaming/ClientToolEvent.ts +++ b/src/types/streaming/ClientToolEvent.ts @@ -1,6 +1,15 @@ export interface ClientToolEvent { - event_id: string; - event_type: string; - data: Record; - timestamp: string; + // Core event fields + event_uid: string; // Unique ID for this event + session_id: string; // Session ID + event_name: string; // The tool name (e.g., "redirect") + event_data: Record; // LLM-generated parameters + + // Timing & correlation + timestamp: string; // ISO timestamp when event was created + timestamp_user_action: string; // ISO timestamp of user action that triggered this + user_action_correlation_id: string; // Correlation ID for tracking + + // Metadata + used_outside_engine: boolean; // Always true for client events } From e2f3db7fd5b38ba6cee2fc555be13414cbf0dbff Mon Sep 17 00:00:00 2001 From: Harry Smaje Date: Tue, 28 Oct 2025 18:48:25 +0000 Subject: [PATCH 5/6] chore: reset version to 0.0.0-automated --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3d43c21..0966592 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@anam-ai/js-sdk", - "version": "4.3.0-harry-test.alpha.0", + "version": "0.0.0-automated", "description": "Client side JavaScript SDK for Anam AI", "author": "Anam AI", "main": "dist/main/index.js", From 86cb958802483de8bb133d7623d3f7309677fc35 Mon Sep 17 00:00:00 2001 From: Alex Osland <165405455+ao-anam@users.noreply.github.com> Date: Fri, 31 Oct 2025 09:59:09 +0000 Subject: [PATCH 6/6] feat: convert client tool call events to public type (#165) --- src/modules/StreamingClient.ts | 12 +++++++++-- src/modules/ToolCallManager.ts | 20 +++++++++++++++++++ src/modules/index.ts | 1 + .../events/internal/InternalEventCallbacks.ts | 4 ++-- src/types/streaming/ClientToolEvent.ts | 15 ++++++-------- src/types/streaming/WebRtcClientToolEvent.ts | 15 ++++++++++++++ src/types/streaming/index.ts | 1 + 7 files changed, 55 insertions(+), 13 deletions(-) create mode 100644 src/modules/ToolCallManager.ts create mode 100644 src/types/streaming/WebRtcClientToolEvent.ts diff --git a/src/modules/StreamingClient.ts b/src/modules/StreamingClient.ts index d28bb7c..83b1c26 100644 --- a/src/modules/StreamingClient.ts +++ b/src/modules/StreamingClient.ts @@ -8,6 +8,7 @@ import { InternalEventEmitter, PublicEventEmitter, SignallingClient, + ToolCallManager, } from '../modules'; import { AnamEvent, @@ -21,6 +22,7 @@ import { SignalMessage, SignalMessageAction, StreamingClientOptions, + WebRtcClientToolEvent, WebRtcTextMessageEvent, } from '../types'; import { TalkMessageStream } from '../types/TalkMessageStream'; @@ -673,13 +675,19 @@ export class StreamingClient { ); break; case DataChannelMessage.CLIENT_TOOL_EVENT: + const webRtcToolEvent = message.data as WebRtcClientToolEvent; + this.internalEventEmitter.emit( InternalEvent.WEBRTC_CLIENT_TOOL_EVENT_RECEIVED, - message.data as ClientToolEvent, + webRtcToolEvent, ); + const clientToolEvent = + ToolCallManager.WebRTCClientToolEventToClientToolEvent( + webRtcToolEvent, + ); this.publicEventEmitter.emit( AnamEvent.CLIENT_TOOL_EVENT_RECEIVED, - message.data as ClientToolEvent, + clientToolEvent, ); break; // Unknown message types are silently ignored to maintain forward compatibility diff --git a/src/modules/ToolCallManager.ts b/src/modules/ToolCallManager.ts new file mode 100644 index 0000000..e1faf32 --- /dev/null +++ b/src/modules/ToolCallManager.ts @@ -0,0 +1,20 @@ +import { ClientToolEvent, WebRtcClientToolEvent } from '../types/streaming'; + +export class ToolCallManager { + /** + * Converts a WebRtcClientToolEvent to a ClientToolEvent + */ + static WebRTCClientToolEventToClientToolEvent( + webRtcEvent: WebRtcClientToolEvent, + ): ClientToolEvent { + return { + eventUid: webRtcEvent.event_uid, + sessionId: webRtcEvent.session_id, + eventName: webRtcEvent.event_name, + eventData: webRtcEvent.event_data, + timestamp: webRtcEvent.timestamp, + timestampUserAction: webRtcEvent.timestamp_user_action, + userActionCorrelationId: webRtcEvent.user_action_correlation_id, + }; + } +} diff --git a/src/modules/index.ts b/src/modules/index.ts index 08887f7..73698ac 100644 --- a/src/modules/index.ts +++ b/src/modules/index.ts @@ -5,3 +5,4 @@ export { InternalEventEmitter } from './InternalEventEmitter'; export { MessageHistoryClient } from './MessageHistoryClient'; export { PublicEventEmitter } from './PublicEventEmitter'; export { StreamingClient } from './StreamingClient'; +export { ToolCallManager } from './ToolCallManager'; diff --git a/src/types/events/internal/InternalEventCallbacks.ts b/src/types/events/internal/InternalEventCallbacks.ts index 100a20e..5edbbad 100644 --- a/src/types/events/internal/InternalEventCallbacks.ts +++ b/src/types/events/internal/InternalEventCallbacks.ts @@ -2,7 +2,7 @@ import { InternalEvent, SignalMessage, WebRtcTextMessageEvent, - ClientToolEvent, + WebRtcClientToolEvent, } from '../../index'; export type InternalEventCallbacks = { @@ -14,6 +14,6 @@ export type InternalEventCallbacks = { message: WebRtcTextMessageEvent, ) => void; [InternalEvent.WEBRTC_CLIENT_TOOL_EVENT_RECEIVED]: ( - clientToolEvent: ClientToolEvent, + webRtcToolEvent: WebRtcClientToolEvent, ) => void; }; diff --git a/src/types/streaming/ClientToolEvent.ts b/src/types/streaming/ClientToolEvent.ts index c9a9790..aae22b8 100644 --- a/src/types/streaming/ClientToolEvent.ts +++ b/src/types/streaming/ClientToolEvent.ts @@ -1,15 +1,12 @@ export interface ClientToolEvent { // Core event fields - event_uid: string; // Unique ID for this event - session_id: string; // Session ID - event_name: string; // The tool name (e.g., "redirect") - event_data: Record; // LLM-generated parameters + eventUid: string; // Unique ID for this event + sessionId: string; // Session ID + eventName: string; // The tool name (e.g., "redirect") + eventData: Record; // LLM-generated parameters // Timing & correlation timestamp: string; // ISO timestamp when event was created - timestamp_user_action: string; // ISO timestamp of user action that triggered this - user_action_correlation_id: string; // Correlation ID for tracking - - // Metadata - used_outside_engine: boolean; // Always true for client events + timestampUserAction: string; // ISO timestamp of user action that triggered this + userActionCorrelationId: string; // Correlation ID for tracking } diff --git a/src/types/streaming/WebRtcClientToolEvent.ts b/src/types/streaming/WebRtcClientToolEvent.ts new file mode 100644 index 0000000..c5f56c8 --- /dev/null +++ b/src/types/streaming/WebRtcClientToolEvent.ts @@ -0,0 +1,15 @@ +export interface WebRtcClientToolEvent { + // Core event fields + event_uid: string; // Unique ID for this event + session_id: string; // Session ID + event_name: string; // The tool name (e.g., "redirect") + event_data: Record; // LLM-generated parameters + + // Timing & correlation + timestamp: string; // ISO timestamp when event was created + timestamp_user_action: string; // ISO timestamp of user action that triggered this + user_action_correlation_id: string; // Correlation ID for tracking + + // Metadata + used_outside_engine: boolean; // Always true for client events +} diff --git a/src/types/streaming/index.ts b/src/types/streaming/index.ts index 21d7b0c..2d383e2 100644 --- a/src/types/streaming/index.ts +++ b/src/types/streaming/index.ts @@ -1,5 +1,6 @@ export type { WebRtcTextMessageEvent } from './WebRtcTextMessageEvent'; export type { ClientToolEvent } from './ClientToolEvent'; +export type { WebRtcClientToolEvent } from './WebRtcClientToolEvent'; export type { StreamingClientOptions } from './StreamingClientOptions'; export type { InputAudioOptions } from './InputAudioOptions'; export { DataChannelMessage } from './DataChannelMessage';