react-native-deepgram
Version:
React Native SDK for Deepgram's AI-powered speech-to-text, real-time transcription, and text intelligence APIs. Supports live audio streaming, file transcription, sentiment analysis, and topic detection for iOS and Android.
309 lines (270 loc) • 7.72 kB
text/typescript
/**
* Message in the conversation history.
*/
export interface DeepgramVoiceAgentContextMessage {
type: string;
role?: 'user' | 'assistant' | 'system';
content?: string;
[]: unknown;
}
export interface DeepgramVoiceAgentFlags {
history?: boolean;
[]: unknown;
}
export interface DeepgramVoiceAgentAudioConfig {
encoding?: string;
sample_rate?: number;
bitrate?: number;
container?: string;
[]: unknown;
}
export interface DeepgramVoiceAgentAudioSettings {
input?: DeepgramVoiceAgentAudioConfig;
output?: DeepgramVoiceAgentAudioConfig;
[]: unknown;
}
export interface DeepgramVoiceAgentListenProvider {
type?: string;
model?: string;
keyterms?: string[];
smart_format?: boolean;
[]: unknown;
}
export interface DeepgramVoiceAgentThinkProvider {
type?: string;
model?: string;
temperature?: number;
[]: unknown;
}
export interface DeepgramVoiceAgentFunctionDefinition {
id?: string;
name: string;
description?: string;
arguments?: string;
client_side?: boolean;
[]: unknown;
}
export interface DeepgramVoiceAgentFunctionEndpoint {
url: string;
method?: string;
headers?: Record<string, string>;
[]: unknown;
}
export interface DeepgramVoiceAgentFunctionConfig {
name: string;
description?: string;
parameters?: Record<string, unknown>;
endpoint?: DeepgramVoiceAgentFunctionEndpoint;
[]: unknown;
}
export interface DeepgramVoiceAgentListenConfig {
provider?: DeepgramVoiceAgentListenProvider;
[]: unknown;
}
export interface DeepgramVoiceAgentThinkConfig {
provider?: DeepgramVoiceAgentThinkProvider;
functions?: DeepgramVoiceAgentFunctionConfig[];
prompt?: string;
context_length?: number;
[]: unknown;
}
export interface DeepgramVoiceAgentSpeakConfig {
provider?: Record<string, unknown>;
[]: unknown;
}
export interface DeepgramVoiceAgentAgentConfig {
language?: string;
context?: {
messages?: DeepgramVoiceAgentContextMessage[];
[]: unknown;
};
listen?: DeepgramVoiceAgentListenConfig;
think?: DeepgramVoiceAgentThinkConfig;
speak?: DeepgramVoiceAgentSpeakConfig;
greeting?: string;
[]: unknown;
}
/**
* Configuration for the Voice Agent.
* @example
* ```typescript
* const settings: DeepgramVoiceAgentSettings = {
* agent: {
* think: {
* provider: { type: 'open_ai' },
* model: 'gpt-4o'
* }
* }
* };
* ```
* @see https://developers.deepgram.com/docs/voice-agent
*/
export interface DeepgramVoiceAgentSettings {
tags?: string[];
experimental?: boolean;
flags?: DeepgramVoiceAgentFlags;
mip_opt_out?: boolean;
audio?: DeepgramVoiceAgentAudioSettings;
agent?: DeepgramVoiceAgentAgentConfig;
[]: unknown;
}
export interface DeepgramVoiceAgentSettingsMessage
extends DeepgramVoiceAgentSettings {
type: 'Settings';
}
export interface DeepgramVoiceAgentUpdateSpeakMessage {
type: 'UpdateSpeak';
speak: DeepgramVoiceAgentSpeakConfig;
[]: unknown;
}
export interface DeepgramVoiceAgentInjectUserMessage {
type: 'InjectUserMessage';
content: string;
[]: unknown;
}
export interface DeepgramVoiceAgentInjectAgentMessage {
type: 'InjectAgentMessage';
message: string;
[]: unknown;
}
export interface DeepgramVoiceAgentFunctionCallResponseMessage {
type: 'FunctionCallResponse';
id: string;
name: string;
content: string;
client_side?: boolean;
[]: unknown;
}
export interface DeepgramVoiceAgentKeepAliveMessage {
type: 'KeepAlive';
[]: unknown;
}
export interface DeepgramVoiceAgentUpdatePromptMessage {
type: 'UpdatePrompt';
prompt: string;
[]: unknown;
}
/**
* Union of all messages that can be sent from the Client to the Voice Agent.
*/
export type DeepgramVoiceAgentClientMessage =
| DeepgramVoiceAgentSettingsMessage
| DeepgramVoiceAgentUpdateSpeakMessage
| DeepgramVoiceAgentInjectUserMessage
| DeepgramVoiceAgentInjectAgentMessage
| DeepgramVoiceAgentFunctionCallResponseMessage
| DeepgramVoiceAgentKeepAliveMessage
| DeepgramVoiceAgentUpdatePromptMessage;
export interface DeepgramVoiceAgentWelcomeMessage {
type: 'Welcome';
request_id: string;
[]: unknown;
}
export interface DeepgramVoiceAgentSettingsAppliedMessage {
type: 'SettingsApplied';
[]: unknown;
}
export interface DeepgramVoiceAgentConversationTextMessage {
type: 'ConversationText';
role: string;
content: string;
[]: unknown;
}
export interface DeepgramVoiceAgentAgentThinkingMessage {
type: 'AgentThinking';
content: string;
[]: unknown;
}
export interface DeepgramVoiceAgentAgentStartedSpeakingMessage {
type: 'AgentStartedSpeaking';
total_latency?: number;
tts_latency?: number;
ttt_latency?: number;
[]: unknown;
}
export interface DeepgramVoiceAgentAgentAudioDoneMessage {
type: 'AgentAudioDone';
[]: unknown;
}
export interface DeepgramVoiceAgentUserStartedSpeakingMessage {
type: 'UserStartedSpeaking';
[]: unknown;
}
export interface DeepgramVoiceAgentFunctionCallRequestMessage {
type: 'FunctionCallRequest';
functions: DeepgramVoiceAgentFunctionDefinition[];
[]: unknown;
}
export interface DeepgramVoiceAgentReceiveFunctionCallResponseMessage {
type: 'FunctionCallResponse';
id: string;
name: string;
content: string;
client_side?: boolean;
[]: unknown;
}
export interface DeepgramVoiceAgentPromptUpdatedMessage {
type: 'PromptUpdated';
[]: unknown;
}
export interface DeepgramVoiceAgentSpeakUpdatedMessage {
type: 'SpeakUpdated';
[]: unknown;
}
export interface DeepgramVoiceAgentInjectionRefusedMessage {
type: 'InjectionRefused';
message: string;
[]: unknown;
}
export interface DeepgramVoiceAgentErrorMessage {
type: 'Error';
description: string;
code?: string;
[]: unknown;
}
export interface DeepgramVoiceAgentWarningMessage {
type: 'Warning';
description: string;
code?: string;
[]: unknown;
}
export interface DeepgramVoiceAgentAudioConfigMessage {
type: 'AudioConfig';
sample_rate?: number;
channels?: number;
encoding?: string;
[]: unknown;
}
export interface DeepgramVoiceAgentAudioMessage {
type: 'Audio';
// Binary audio data will be in the WebSocket message payload
[]: unknown;
}
/**
* Union of all messages that can be received from the Voice Agent Server.
*/
export type DeepgramVoiceAgentServerMessage =
| DeepgramVoiceAgentWelcomeMessage
| DeepgramVoiceAgentSettingsAppliedMessage
| DeepgramVoiceAgentConversationTextMessage
| DeepgramVoiceAgentAgentThinkingMessage
| DeepgramVoiceAgentAgentStartedSpeakingMessage
| DeepgramVoiceAgentAgentAudioDoneMessage
| DeepgramVoiceAgentUserStartedSpeakingMessage
| DeepgramVoiceAgentFunctionCallRequestMessage
| DeepgramVoiceAgentReceiveFunctionCallResponseMessage
| DeepgramVoiceAgentPromptUpdatedMessage
| DeepgramVoiceAgentSpeakUpdatedMessage
| DeepgramVoiceAgentInjectionRefusedMessage
| DeepgramVoiceAgentErrorMessage
| DeepgramVoiceAgentWarningMessage
| DeepgramVoiceAgentAudioConfigMessage
| DeepgramVoiceAgentAudioMessage
| DeepgramVoiceAgentSettingsMessage
| DeepgramVoiceAgentUpdateSpeakMessage
| DeepgramVoiceAgentInjectUserMessage
| DeepgramVoiceAgentInjectAgentMessage
| DeepgramVoiceAgentFunctionCallResponseMessage
| DeepgramVoiceAgentKeepAliveMessage
| DeepgramVoiceAgentUpdatePromptMessage
| { type: string; [key: string]: unknown };