@telnyx/ai-agent-lib 0.2.10 → 0.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-state.d.ts +3 -0
- package/dist/audio-stream-monitor.d.ts +55 -0
- package/dist/client.d.ts +109 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +4130 -0
- package/dist/logger.d.ts +3 -0
- package/dist/message.d.ts +61 -0
- package/dist/react/agent-state-auto-update.d.ts +1 -0
- package/dist/react/client-context.d.ts +5 -0
- package/dist/react/connection-state-auto-update.d.ts +1 -0
- package/dist/react/conversation-auto-update.d.ts +1 -0
- package/dist/react/transcript-auto-update.d.ts +1 -0
- package/dist/react/use-agent-state.d.ts +3 -0
- package/dist/react/use-client-connection-state.d.ts +3 -0
- package/dist/react/use-client.d.ts +1 -0
- package/dist/react/use-conversation.d.ts +3 -0
- package/dist/react/use-transcript.d.ts +3 -0
- package/dist/transcript.d.ts +9 -0
- package/dist/types.d.ts +67 -0
- package/dist/util.d.ts +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { VADOptions } from "./types";
|
|
2
|
+
export declare class AudioStreamMonitor {
|
|
3
|
+
private remoteIntervalId;
|
|
4
|
+
private localIntervalId;
|
|
5
|
+
private remoteStream;
|
|
6
|
+
private localStream;
|
|
7
|
+
private remoteAudioContext;
|
|
8
|
+
private remoteSource;
|
|
9
|
+
private remoteAnalyser;
|
|
10
|
+
private localAudioContext;
|
|
11
|
+
private localSource;
|
|
12
|
+
private localAnalyser;
|
|
13
|
+
private thinkingStartTime;
|
|
14
|
+
private lastState;
|
|
15
|
+
private userIsSpeaking;
|
|
16
|
+
private lastUserAudioTime;
|
|
17
|
+
private userSpeechStartTime;
|
|
18
|
+
private userSilenceStartTime;
|
|
19
|
+
private isFirstAgentSpeech;
|
|
20
|
+
private monitorStartTime;
|
|
21
|
+
private volumeThreshold;
|
|
22
|
+
private silenceDurationMs;
|
|
23
|
+
private minSpeechDurationMs;
|
|
24
|
+
private maxLatencyMs;
|
|
25
|
+
constructor(options?: VADOptions);
|
|
26
|
+
private updateAgentState;
|
|
27
|
+
/**
|
|
28
|
+
* Set the remote audio stream (agent's voice) to monitor for speech detection
|
|
29
|
+
*/
|
|
30
|
+
setRemoteStream(stream: MediaStream): void;
|
|
31
|
+
/**
|
|
32
|
+
* Set the local audio stream (user's microphone) to monitor for VAD
|
|
33
|
+
*/
|
|
34
|
+
setLocalStream(stream: MediaStream): void;
|
|
35
|
+
setMonitoredAudioStream(stream: MediaStream): void;
|
|
36
|
+
private stopRemoteMonitor;
|
|
37
|
+
private stopLocalMonitor;
|
|
38
|
+
/**
|
|
39
|
+
* Reset all latency tracking state for a fresh call.
|
|
40
|
+
* Should be called when a call ends to prevent stale data affecting the next call.
|
|
41
|
+
*/
|
|
42
|
+
private resetLatencyState;
|
|
43
|
+
stopAudioStreamMonitor(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Monitor remote stream (agent's audio) for speech detection
|
|
46
|
+
* Detects when agent starts speaking to calculate latency
|
|
47
|
+
*/
|
|
48
|
+
private startRemoteMonitor;
|
|
49
|
+
/**
|
|
50
|
+
* Monitor local stream (user's microphone) for VAD
|
|
51
|
+
* Detects when user stops speaking (1000ms of silence) to start latency measurement
|
|
52
|
+
*/
|
|
53
|
+
private startLocalMonitor;
|
|
54
|
+
destroy(): void;
|
|
55
|
+
}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Call } from "@telnyx/webrtc";
|
|
2
|
+
import EventEmitter from "eventemitter3";
|
|
3
|
+
import type { AIAgentEvents, TranscriptItem, VADOptions } from "./types";
|
|
4
|
+
export type TelnyxAIAgentConstructorParams = {
|
|
5
|
+
agentId: string;
|
|
6
|
+
versionId?: string;
|
|
7
|
+
environment?: "production" | "development";
|
|
8
|
+
debug?: boolean;
|
|
9
|
+
trickleIce?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Voice Activity Detection options for controlling speech detection and latency measurement.
|
|
12
|
+
*/
|
|
13
|
+
vad?: VADOptions;
|
|
14
|
+
};
|
|
15
|
+
export declare class TelnyxAIAgent extends EventEmitter<AIAgentEvents> {
|
|
16
|
+
private telnyxRTC;
|
|
17
|
+
private transcription;
|
|
18
|
+
agentId: string;
|
|
19
|
+
versionId: string;
|
|
20
|
+
debug: boolean;
|
|
21
|
+
private audioStreamMonitor;
|
|
22
|
+
activeCall: Call | null;
|
|
23
|
+
constructor(params: TelnyxAIAgentConstructorParams);
|
|
24
|
+
/**
|
|
25
|
+
* Connects to the Telnyx WebRTC service and establishes a session with the AI agent.
|
|
26
|
+
*
|
|
27
|
+
* @returns Promise that resolves when the connection is established
|
|
28
|
+
*/
|
|
29
|
+
connect(): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Disconnects from the Telnyx WebRTC service and cleans up all event listeners.
|
|
32
|
+
* Emits an 'agent.disconnected' event before completing cleanup.
|
|
33
|
+
*/
|
|
34
|
+
disconnect(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Sends a text message to the AI agent during an active conversation.
|
|
37
|
+
* Requires an active conversation to be in progress.
|
|
38
|
+
*
|
|
39
|
+
* @param message - The text message to send to the AI agent
|
|
40
|
+
* @param attachments - Optional array of base64 encoded file attachments (defaults to empty array)
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* client.sendConversationMessage('Hello, I need help with my account');
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* // With attachments
|
|
47
|
+
* client.sendConversationMessage('Please review this document', ['base64EncodedData...']);
|
|
48
|
+
*/
|
|
49
|
+
sendConversationMessage(message: string, attachments?: string[]): void;
|
|
50
|
+
/**
|
|
51
|
+
* Gets the current conversation transcript.
|
|
52
|
+
*
|
|
53
|
+
* @returns Array of transcript items containing all messages exchanged during the conversation
|
|
54
|
+
*/
|
|
55
|
+
get transcript(): TranscriptItem[];
|
|
56
|
+
/**
|
|
57
|
+
* Initiates a conversation with the AI agent.
|
|
58
|
+
*
|
|
59
|
+
* @param options - Optional configuration for the call.
|
|
60
|
+
* Note: This method will ALWAYS call the AI agent, the optional parameters are primarily used for log referencing or passing parameters to the agent via the custom headers.
|
|
61
|
+
* @param options.destinationNumber - The destination phone number (defaults to "xxx"). Note, regardless of the destination number, the call will be made to the AI agent.
|
|
62
|
+
* @param options.callerNumber - The caller's phone number
|
|
63
|
+
* @param options.callerName - The caller's display name
|
|
64
|
+
* @param options.customHeaders - Custom SIP headers to pass to the AI agent. Headers with the `X-` prefix
|
|
65
|
+
* will be mapped to dynamic variables in the AI assistant (e.g., `X-Account-Number` becomes `{{account_number}}`).
|
|
66
|
+
* Note: Hyphens in header names are converted to underscores in variable names.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* // Start conversation with custom headers for dynamic variables
|
|
70
|
+
* client.startConversation({
|
|
71
|
+
* callerName: 'John Doe',
|
|
72
|
+
* customHeaders: [
|
|
73
|
+
* { name: 'X-User-Name', value: 'user-name' },
|
|
74
|
+
* { name: 'X-Agent-Session', value: 'session-abc' }
|
|
75
|
+
* ]
|
|
76
|
+
* });
|
|
77
|
+
* // These headers will be available in your AI assistant as {{user_name}} and {{agent_session}}
|
|
78
|
+
* @param options.audio - Audio constraints for the call (boolean or MediaTrackConstraints)
|
|
79
|
+
*/
|
|
80
|
+
startConversation(options?: {
|
|
81
|
+
destinationNumber?: string;
|
|
82
|
+
callerNumber?: string;
|
|
83
|
+
callerName?: string;
|
|
84
|
+
customHeaders?: {
|
|
85
|
+
name: string;
|
|
86
|
+
value: string;
|
|
87
|
+
}[];
|
|
88
|
+
audio?: boolean | MediaTrackConstraints;
|
|
89
|
+
}): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Ends the current active conversation with the AI agent.
|
|
92
|
+
*
|
|
93
|
+
* @returns Promise that resolves when the call is hung up, or undefined if there is no active call
|
|
94
|
+
*/
|
|
95
|
+
endConversation(): void | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* Sets the remote audio stream for monitoring agent speech.
|
|
98
|
+
* Use this when call.remoteStream is not available and you need to provide
|
|
99
|
+
* the stream from the peer connection receiver.
|
|
100
|
+
*
|
|
101
|
+
* @param stream - The MediaStream containing the remote (agent) audio
|
|
102
|
+
*/
|
|
103
|
+
setRemoteStream(stream: MediaStream): void;
|
|
104
|
+
private onClientReady;
|
|
105
|
+
private onClientOrSocketError;
|
|
106
|
+
private onNotification;
|
|
107
|
+
private onTranscriptItem;
|
|
108
|
+
private onAgentStateChange;
|
|
109
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./client";
|
|
2
|
+
export * from "./react/client-context";
|
|
3
|
+
export * from "./react/use-transcript";
|
|
4
|
+
export * from "./react/use-client-connection-state";
|
|
5
|
+
export * from "./react/use-client";
|
|
6
|
+
export * from "./react/use-conversation";
|
|
7
|
+
export * from "./react/use-agent-state";
|
|
8
|
+
export * from "./types";
|