@voxket-ai/voxket-live
Version:
A React widget for embedding Voxket-powered audio/video/chat experiences.
144 lines (143 loc) • 3.94 kB
TypeScript
import * as React from 'react';
/**
* RPC Invocation data received from LiveKit
*/
export interface RpcInvocationData {
callerIdentity: string;
payload: string;
requestId?: string;
responseTimeout?: number;
}
/**
* Presentation modes for interactive components
*/
export type ViewPresentationMode = 'embedded' | 'modal' | 'fullscreen';
/**
* Handler for interactive component responses
*/
export interface VoxketInteractiveUIHandler {
/**
* Called when user interaction is successful
* @param data Response data from user interaction
* @param successView Optional React component to show on success
*/
didSuccess(data: Record<string, any>, successView?: React.ReactElement): void;
/**
* Called when user interaction fails or times out
* @param error Error data
*/
didFail(error: Record<string, any>): void;
/**
* Dismiss the current view and send decline response to agent
* This notifies the agent that the user dismissed/declined the interaction
* and sends a structured response indicating the dismissal
*/
dismissView(): void;
/**
* Called when user interaction times out
* @param timeoutView Optional React component to show on timeout
*/
didTimeout?(timeoutView?: React.ReactElement): void;
}
/**
* Props passed to interactive components
*/
export interface VoxketInteractiveViewProps {
/**
* Handler for component responses
*/
handler?: VoxketInteractiveUIHandler;
/**
* Load data into the component
* @param data JSON data from the agent
*/
loadData?(data: any): Promise<void>;
/**
* Timeout for user interaction (in seconds)
*/
timeout?: number;
/**
* Presentation mode
*/
presentationMode?: ViewPresentationMode;
/**
* Data passed to the component from the RPC call
*/
data?: any;
/**
* VoxketClient instance for sending messages and interacting with the session
*/
client?: any;
/**
* Function to add a local message to the chat without sending to agent
*/
addLocalMessage?: (content: string) => void;
}
/**
* Interface that interactive components must implement
*/
export type VoxketInteractiveView = React.ComponentType<VoxketInteractiveViewProps>;
/**
* RPC Method registration
*/
export interface RpcMethodRegistration {
methodName: string;
component: VoxketInteractiveView;
presentationMode: ViewPresentationMode;
timeout?: number;
}
/**
* RPC Response data
*/
export interface RpcResponseData {
success: boolean;
data?: Record<string, any>;
message?: string;
error?: Record<string, any>;
timestamp: Date;
}
/**
* RPC Method handler function
*/
export type RpcMethodHandler = (data: RpcInvocationData) => Promise<string>;
/**
* Interactive UI state
*/
export interface InteractiveUIState {
isVisible: boolean;
methodName: string;
component: VoxketInteractiveView | null;
presentationMode: ViewPresentationMode;
timeout: number;
data: any;
handler: VoxketInteractiveUIHandler | null;
}
/**
* Events related to RPC interactions
*/
export interface RpcEvents {
'rpc.method.registered': (data: {
methodName: string;
}) => void;
'rpc.method.called': (data: {
methodName: string;
data: RpcInvocationData;
}) => void;
'rpc.interaction.started': (data: {
methodName: string;
presentationMode: ViewPresentationMode;
}) => void;
'rpc.interaction.completed': (data: {
methodName: string;
response: RpcResponseData;
}) => void;
'rpc.interaction.timeout': (data: {
methodName: string;
response: RpcResponseData;
}) => void;
'rpc.interaction.dismissed': (data: {
methodName: string;
response: RpcResponseData;
}) => void;
[key: string]: (...args: any[]) => void;
}