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';