@telnyx/ai-agent-lib 0.1.3 → 0.1.4
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/README.md +254 -2
- package/dist/index.js +70 -63
- package/dist/util.d.ts +1 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1,3 +1,255 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Telnyx AI Agent Library
|
|
2
|
+
|
|
3
|
+
A TypeScript/React library for building AI-powered voice conversation applications using Telnyx's WebRTC infrastructure. This library provides a comprehensive set of tools for managing AI agent connections, real-time transcriptions, conversation states, and audio streaming.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🎯 **Easy AI Agent Integration** - Connect to Telnyx AI agents with minimal setup
|
|
8
|
+
- 🎙️ **Real-time Transcription** - Automatic speech-to-text with live updates
|
|
9
|
+
- 🔊 **Audio Stream Management** - Built-in audio monitoring and playback controls
|
|
10
|
+
- ⚛️ **React Hooks & Components** - Ready-to-use React components and hooks
|
|
11
|
+
- 🔄 **State Management** - Automatic state synchronization using Jotai
|
|
12
|
+
- 📱 **Connection Management** - Robust connection handling with error recovery
|
|
13
|
+
- 🎚️ **Agent State Tracking** - Monitor agent states (listening, speaking, thinking)
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @telnyx/ai-agent-lib
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Peer Dependencies
|
|
22
|
+
|
|
23
|
+
This library requires React 19.1.1+ as a peer dependency:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install react@^19.1.1 react-dom@^19.1.0
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
### 1. Wrap your app with the provider
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
import React from 'react';
|
|
35
|
+
import { createRoot } from 'react-dom/client';
|
|
36
|
+
import { TelnyxAIAgentProvider } from '@telnyx/ai-agent-lib';
|
|
37
|
+
import App from './App';
|
|
38
|
+
|
|
39
|
+
createRoot(document.getElementById('root')!).render(
|
|
40
|
+
<TelnyxAIAgentProvider agentId="your-agent-id">
|
|
41
|
+
<App />
|
|
42
|
+
</TelnyxAIAgentProvider>
|
|
43
|
+
);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 2. Use hooks in your components
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
import React, { useEffect, useRef } from 'react';
|
|
50
|
+
import {
|
|
51
|
+
useClient,
|
|
52
|
+
useTranscript,
|
|
53
|
+
useConnectionState,
|
|
54
|
+
useConversation,
|
|
55
|
+
useAgentState
|
|
56
|
+
} from '@telnyx/ai-agent-lib';
|
|
57
|
+
|
|
58
|
+
function VoiceChat() {
|
|
59
|
+
const client = useClient();
|
|
60
|
+
const transcript = useTranscript();
|
|
61
|
+
const connectionState = useConnectionState();
|
|
62
|
+
const conversation = useConversation();
|
|
63
|
+
const agentState = useAgentState();
|
|
64
|
+
const audioRef = useRef<HTMLAudioElement>(null);
|
|
65
|
+
|
|
66
|
+
// Setup audio playback
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (conversation?.call?.remoteStream && audioRef.current) {
|
|
69
|
+
audioRef.current.srcObject = conversation.call.remoteStream;
|
|
70
|
+
}
|
|
71
|
+
}, [conversation]);
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<div>
|
|
75
|
+
<h2>Connection: {connectionState}</h2>
|
|
76
|
+
<h3>Agent State: {agentState}</h3>
|
|
77
|
+
|
|
78
|
+
<button
|
|
79
|
+
onClick={() => client.startConversation()}
|
|
80
|
+
disabled={connectionState !== 'connected'}
|
|
81
|
+
>
|
|
82
|
+
Start Conversation
|
|
83
|
+
</button>
|
|
84
|
+
|
|
85
|
+
<button onClick={() => client.endConversation()}>
|
|
86
|
+
End Conversation
|
|
87
|
+
</button>
|
|
88
|
+
|
|
89
|
+
<audio ref={audioRef} autoPlay playsInline controls />
|
|
90
|
+
|
|
91
|
+
<div>
|
|
92
|
+
<h3>Transcript ({transcript.length} items)</h3>
|
|
93
|
+
{transcript.map((item) => (
|
|
94
|
+
<div key={item.id}>
|
|
95
|
+
<strong>{item.role}:</strong> {item.content}
|
|
96
|
+
<small> - {item.timestamp.toLocaleTimeString()}</small>
|
|
97
|
+
</div>
|
|
98
|
+
))}
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## API Reference
|
|
106
|
+
|
|
107
|
+
### TelnyxAIAgentProvider Props
|
|
108
|
+
|
|
109
|
+
| Prop | Type | Required | Default | Description |
|
|
110
|
+
|------|------|----------|---------|-------------|
|
|
111
|
+
| `agentId` | `string` | ✅ | - | Your Telnyx AI agent ID |
|
|
112
|
+
| `versionId` | `string` | ❌ | `"main"` | Agent version to use |
|
|
113
|
+
| `environment` | `"production" \| "development"` | ❌ | `"production"` | Telnyx environment |
|
|
114
|
+
|
|
115
|
+
### Hooks
|
|
116
|
+
|
|
117
|
+
#### `useClient()`
|
|
118
|
+
Returns the `TelnyxAIAgent` instance for direct API access.
|
|
119
|
+
|
|
120
|
+
**Methods:**
|
|
121
|
+
- `connect()` - Connect to Telnyx platform
|
|
122
|
+
- `disconnect()` - Disconnect and cleanup
|
|
123
|
+
- `startConversation()` - Start a new conversation
|
|
124
|
+
- `endConversation()` - End the current conversation
|
|
125
|
+
- `transcript` - Get current transcript array
|
|
126
|
+
|
|
127
|
+
**Events:**
|
|
128
|
+
- `agent.connected` - Agent successfully connected
|
|
129
|
+
- `agent.disconnected` - Agent disconnected
|
|
130
|
+
- `agent.error` - Connection or operational error
|
|
131
|
+
- `transcript.item` - New transcript item received
|
|
132
|
+
- `conversation.update` - Conversation state updated
|
|
133
|
+
- `conversation.agent.state` - Agent state changed
|
|
134
|
+
|
|
135
|
+
#### `useConnectionState()`
|
|
136
|
+
Returns the current connection state: `"connecting" | "connected" | "disconnected" | "error"`
|
|
137
|
+
|
|
138
|
+
#### `useTranscript()`
|
|
139
|
+
Returns an array of `TranscriptItem` objects representing the conversation history.
|
|
140
|
+
|
|
141
|
+
**TranscriptItem:**
|
|
142
|
+
```typescript
|
|
143
|
+
{
|
|
144
|
+
id: string;
|
|
145
|
+
role: "user" | "assistant";
|
|
146
|
+
content: string;
|
|
147
|
+
timestamp: Date;
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
#### `useConversation()`
|
|
152
|
+
Returns the current conversation notification object containing call information and state.
|
|
153
|
+
|
|
154
|
+
#### `useAgentState()`
|
|
155
|
+
Returns the current agent state: `"listening" | "speaking" | "thinking"`
|
|
156
|
+
|
|
157
|
+
### Direct Usage (Without React)
|
|
158
|
+
|
|
159
|
+
You can also use the library without React:
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
import { TelnyxAIAgent } from '@telnyx/ai-agent-lib';
|
|
163
|
+
|
|
164
|
+
const agent = new TelnyxAIAgent({
|
|
165
|
+
agentId: 'your-agent-id',
|
|
166
|
+
versionId: 'main',
|
|
167
|
+
environment: 'production'
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Connect to the platform
|
|
171
|
+
await agent.connect();
|
|
172
|
+
|
|
173
|
+
// Listen for events
|
|
174
|
+
agent.on('agent.connected', () => {
|
|
175
|
+
console.log('Agent connected!');
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
agent.on('transcript.item', (item) => {
|
|
179
|
+
console.log(`${item.role}: ${item.content}`);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
agent.on('conversation.agent.state', (state) => {
|
|
183
|
+
console.log(`Agent is now: ${state}`);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// Start a conversation
|
|
187
|
+
await agent.startConversation();
|
|
188
|
+
|
|
189
|
+
// Access transcript
|
|
190
|
+
console.log(agent.transcript);
|
|
191
|
+
|
|
192
|
+
// Cleanup
|
|
193
|
+
await agent.disconnect();
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Advanced Usage
|
|
197
|
+
|
|
198
|
+
### Custom Audio Handling
|
|
199
|
+
|
|
200
|
+
The library automatically handles audio stream monitoring and agent state detection based on audio levels. The audio stream is available through the conversation object:
|
|
201
|
+
|
|
202
|
+
```tsx
|
|
203
|
+
const conversation = useConversation();
|
|
204
|
+
const audioStream = conversation?.call?.remoteStream;
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Error Handling
|
|
208
|
+
|
|
209
|
+
```tsx
|
|
210
|
+
const client = useClient();
|
|
211
|
+
|
|
212
|
+
useEffect(() => {
|
|
213
|
+
const handleError = (error: Error) => {
|
|
214
|
+
console.error('Agent error:', error);
|
|
215
|
+
// Handle error (show notification, retry connection, etc.)
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
client.on('agent.error', handleError);
|
|
219
|
+
|
|
220
|
+
return () => {
|
|
221
|
+
client.off('agent.error', handleError);
|
|
222
|
+
};
|
|
223
|
+
}, [client]);
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### State Persistence
|
|
227
|
+
|
|
228
|
+
The library uses Jotai for state management, which automatically handles state updates across components. All state is ephemeral and resets when the provider unmounts.
|
|
229
|
+
|
|
230
|
+
## TypeScript Support
|
|
231
|
+
|
|
232
|
+
This library is built with TypeScript and provides full type definitions. All hooks and components are fully typed for the best development experience.
|
|
233
|
+
|
|
234
|
+
## Examples
|
|
235
|
+
|
|
236
|
+
Check out the `/src` directory for a complete example application demonstrating all features of the library.
|
|
237
|
+
|
|
238
|
+
## Dependencies
|
|
239
|
+
|
|
240
|
+
- `@telnyx/webrtc` - Telnyx WebRTC SDK
|
|
241
|
+
- `eventemitter3` - Event handling
|
|
242
|
+
- `jotai` - State management
|
|
243
|
+
|
|
244
|
+
## License
|
|
245
|
+
|
|
246
|
+
This library is part of the Telnyx ecosystem. Please refer to Telnyx's terms of service and licensing agreements.
|
|
247
|
+
|
|
248
|
+
## Support
|
|
249
|
+
|
|
250
|
+
For support, please contact Telnyx support or check the [Telnyx documentation](https://developers.telnyx.com/).
|
|
251
|
+
|
|
252
|
+
## Contributing
|
|
253
|
+
|
|
254
|
+
This library is maintained by Telnyx. For bug reports or feature requests, please contact Telnyx support.elnyx AI Agent Library
|
|
2
255
|
|
|
3
|
-
This library provides a set of tools and utilities for building AI agents that can interact with Telnyx's services. It includes components for managing audio streams, handling agent states, and more.
|
package/dist/index.js
CHANGED
|
@@ -2614,16 +2614,23 @@ class mi extends lt {
|
|
|
2614
2614
|
}
|
|
2615
2615
|
};
|
|
2616
2616
|
}
|
|
2617
|
-
|
|
2618
|
-
|
|
2617
|
+
function bi(t, e) {
|
|
2618
|
+
let n = 0;
|
|
2619
|
+
return (...i) => {
|
|
2620
|
+
const s = Date.now();
|
|
2621
|
+
s - n >= e && (n = s, t(...i));
|
|
2622
|
+
};
|
|
2623
|
+
}
|
|
2624
|
+
const yi = 10;
|
|
2625
|
+
class _i {
|
|
2619
2626
|
animationFrameId = null;
|
|
2620
2627
|
stream = null;
|
|
2621
2628
|
audioContext = null;
|
|
2622
2629
|
source = null;
|
|
2623
2630
|
analyser = null;
|
|
2624
|
-
updateAgentState = (e) => {
|
|
2631
|
+
updateAgentState = bi((e) => {
|
|
2625
2632
|
Ee.emit("conversation.agent.state", e);
|
|
2626
|
-
};
|
|
2633
|
+
}, 100);
|
|
2627
2634
|
setMonitoredAudioStream(e) {
|
|
2628
2635
|
this.stream && this.stopAudioStreamMonitor(), this.stream = e, this.startAudioStreamMonitor();
|
|
2629
2636
|
}
|
|
@@ -2635,7 +2642,7 @@ class yi {
|
|
|
2635
2642
|
this.audioContext = new AudioContext(), this.source = this.audioContext.createMediaStreamSource(this.stream), this.analyser = this.audioContext.createAnalyser(), this.source.connect(this.analyser), this.analyser.fftSize = 512;
|
|
2636
2643
|
const e = new Uint8Array(this.analyser.frequencyBinCount), n = () => {
|
|
2637
2644
|
const i = e.reduce((s, c) => s + c, 0) / e.length;
|
|
2638
|
-
this.analyser?.getByteFrequencyData(e), i
|
|
2645
|
+
this.analyser?.getByteFrequencyData(e), i >= yi ? this.updateAgentState("speaking") : this.updateAgentState("listening"), this.animationFrameId = requestAnimationFrame(n);
|
|
2639
2646
|
};
|
|
2640
2647
|
this.animationFrameId = requestAnimationFrame(n);
|
|
2641
2648
|
}
|
|
@@ -2659,7 +2666,7 @@ class Ot extends lt {
|
|
|
2659
2666
|
}), this.telnyxRTC.on(O.Ready, this.onClientReady), this.telnyxRTC.on(O.Error, this.onClientOrSocketError), this.telnyxRTC.on(O.SocketError, this.onClientOrSocketError), this.telnyxRTC.on(O.Notification, this.onNotification), this.transcription = new mi(this.telnyxRTC), this.transcription.addListener("transcript.item", this.onTranscriptItem), Ee.addListener(
|
|
2660
2667
|
"conversation.agent.state",
|
|
2661
2668
|
this.onAgentStateChange
|
|
2662
|
-
), this.audioStreamMonitor = new
|
|
2669
|
+
), this.audioStreamMonitor = new _i();
|
|
2663
2670
|
}
|
|
2664
2671
|
async connect() {
|
|
2665
2672
|
return this.telnyxRTC.connect();
|
|
@@ -2716,7 +2723,7 @@ var Oe = { exports: {} }, ve = {};
|
|
|
2716
2723
|
* LICENSE file in the root directory of this source tree.
|
|
2717
2724
|
*/
|
|
2718
2725
|
var Lt;
|
|
2719
|
-
function
|
|
2726
|
+
function wi() {
|
|
2720
2727
|
if (Lt) return ve;
|
|
2721
2728
|
Lt = 1;
|
|
2722
2729
|
var t = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
|
|
@@ -2748,7 +2755,7 @@ var me = {};
|
|
|
2748
2755
|
* LICENSE file in the root directory of this source tree.
|
|
2749
2756
|
*/
|
|
2750
2757
|
var Mt;
|
|
2751
|
-
function
|
|
2758
|
+
function Si() {
|
|
2752
2759
|
return Mt || (Mt = 1, process.env.NODE_ENV !== "production" && function() {
|
|
2753
2760
|
function t(v) {
|
|
2754
2761
|
if (v == null) return null;
|
|
@@ -2981,10 +2988,10 @@ React keys must be passed directly to JSX without using spread:
|
|
|
2981
2988
|
}()), me;
|
|
2982
2989
|
}
|
|
2983
2990
|
var Nt;
|
|
2984
|
-
function
|
|
2985
|
-
return Nt || (Nt = 1, process.env.NODE_ENV === "production" ? Oe.exports =
|
|
2991
|
+
function Ci() {
|
|
2992
|
+
return Nt || (Nt = 1, process.env.NODE_ENV === "production" ? Oe.exports = wi() : Oe.exports = Si()), Oe.exports;
|
|
2986
2993
|
}
|
|
2987
|
-
var be =
|
|
2994
|
+
var be = Ci();
|
|
2988
2995
|
const we = {}, Dt = (t, e) => t.unstable_is ? t.unstable_is(e) : e === t, Pt = (t) => "init" in t, He = (t) => !!t.write, jt = (t) => "v" in t || "e" in t, Le = (t) => {
|
|
2989
2996
|
if ("e" in t)
|
|
2990
2997
|
throw t.e;
|
|
@@ -2994,7 +3001,7 @@ const we = {}, Dt = (t, e) => t.unstable_is ? t.unstable_is(e) : e === t, Pt = (
|
|
|
2994
3001
|
}, $e = /* @__PURE__ */ new WeakMap(), Ut = (t) => {
|
|
2995
3002
|
var e;
|
|
2996
3003
|
return Ve(t) && !!((e = $e.get(t)) != null && e[0]);
|
|
2997
|
-
},
|
|
3004
|
+
}, Ii = (t) => {
|
|
2998
3005
|
const e = $e.get(t);
|
|
2999
3006
|
e?.[0] && (e[0] = !1, e[1].forEach((n) => n()));
|
|
3000
3007
|
}, rn = (t, e) => {
|
|
@@ -3021,7 +3028,7 @@ const we = {}, Dt = (t, e) => t.unstable_is ? t.unstable_is(e) : e === t, Pt = (
|
|
|
3021
3028
|
if (Ve(e))
|
|
3022
3029
|
for (const a of i.d.keys())
|
|
3023
3030
|
an(t, e, n(a));
|
|
3024
|
-
i.v = e, delete i.e, (!s || !Object.is(c, i.v)) && (++i.n, Ve(c) &&
|
|
3031
|
+
i.v = e, delete i.e, (!s || !Object.is(c, i.v)) && (++i.n, Ve(c) && Ii(c));
|
|
3025
3032
|
}, $t = (t, e, n) => {
|
|
3026
3033
|
var i;
|
|
3027
3034
|
const s = /* @__PURE__ */ new Set();
|
|
@@ -3030,7 +3037,7 @@ const we = {}, Dt = (t, e) => t.unstable_is ? t.unstable_is(e) : e === t, Pt = (
|
|
|
3030
3037
|
for (const c of e.p)
|
|
3031
3038
|
s.add(c);
|
|
3032
3039
|
return s;
|
|
3033
|
-
},
|
|
3040
|
+
}, Ei = () => {
|
|
3034
3041
|
const t = /* @__PURE__ */ new Set(), e = () => {
|
|
3035
3042
|
t.forEach((n) => n());
|
|
3036
3043
|
};
|
|
@@ -3048,7 +3055,7 @@ const we = {}, Dt = (t, e) => t.unstable_is ? t.unstable_is(e) : e === t, Pt = (
|
|
|
3048
3055
|
a?.delete(s), a.size || e.delete(c);
|
|
3049
3056
|
};
|
|
3050
3057
|
}, n;
|
|
3051
|
-
},
|
|
3058
|
+
}, ki = (t) => (t.c || (t.c = Qe()), t.m || (t.m = Qe()), t.u || (t.u = Qe()), t.f || (t.f = Ei()), t), Ti = Symbol(), Ri = (t = /* @__PURE__ */ new WeakMap(), e = /* @__PURE__ */ new WeakMap(), n = /* @__PURE__ */ new WeakMap(), i = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set(), a = {}, l = (C, ...I) => C.read(...I), h = (C, ...I) => C.write(...I), p = (C, I) => {
|
|
3052
3059
|
var w;
|
|
3053
3060
|
return (w = C.unstable_onInit) == null ? void 0 : w.call(C, I);
|
|
3054
3061
|
}, f = (C, I) => {
|
|
@@ -3312,29 +3319,29 @@ const we = {}, Dt = (t, e) => t.unstable_is ? t.unstable_is(e) : e === t, Pt = (
|
|
|
3312
3319
|
};
|
|
3313
3320
|
}
|
|
3314
3321
|
};
|
|
3315
|
-
return Object.defineProperty(ee,
|
|
3316
|
-
}, cn =
|
|
3317
|
-
let
|
|
3322
|
+
return Object.defineProperty(ee, Ti, { value: G }), ee;
|
|
3323
|
+
}, cn = Ri, xi = ki, Vt = rn, ut = {};
|
|
3324
|
+
let Ai = 0;
|
|
3318
3325
|
function Fe(t, e) {
|
|
3319
|
-
const n = `atom${++
|
|
3326
|
+
const n = `atom${++Ai}`, i = {
|
|
3320
3327
|
toString() {
|
|
3321
3328
|
return (ut ? "production" : void 0) !== "production" && this.debugLabel ? n + ":" + this.debugLabel : n;
|
|
3322
3329
|
}
|
|
3323
3330
|
};
|
|
3324
|
-
return typeof t == "function" ? i.read = t : (i.init = t, i.read =
|
|
3331
|
+
return typeof t == "function" ? i.read = t : (i.init = t, i.read = Oi, i.write = Li), i;
|
|
3325
3332
|
}
|
|
3326
|
-
function
|
|
3333
|
+
function Oi(t) {
|
|
3327
3334
|
return t(this);
|
|
3328
3335
|
}
|
|
3329
|
-
function
|
|
3336
|
+
function Li(t, e, n) {
|
|
3330
3337
|
return e(
|
|
3331
3338
|
this,
|
|
3332
3339
|
typeof n == "function" ? n(t(this)) : n
|
|
3333
3340
|
);
|
|
3334
3341
|
}
|
|
3335
|
-
const
|
|
3342
|
+
const Mi = () => {
|
|
3336
3343
|
let t = 0;
|
|
3337
|
-
const e =
|
|
3344
|
+
const e = xi({}), n = /* @__PURE__ */ new WeakMap(), i = /* @__PURE__ */ new WeakMap(), s = cn(
|
|
3338
3345
|
n,
|
|
3339
3346
|
i,
|
|
3340
3347
|
void 0,
|
|
@@ -3374,20 +3381,20 @@ const Li = () => {
|
|
|
3374
3381
|
}
|
|
3375
3382
|
});
|
|
3376
3383
|
};
|
|
3377
|
-
function
|
|
3378
|
-
return (ut ? "production" : void 0) !== "production" ?
|
|
3384
|
+
function Ni() {
|
|
3385
|
+
return (ut ? "production" : void 0) !== "production" ? Mi() : cn();
|
|
3379
3386
|
}
|
|
3380
3387
|
let ye;
|
|
3381
|
-
function
|
|
3382
|
-
return ye || (ye =
|
|
3388
|
+
function Di() {
|
|
3389
|
+
return ye || (ye = Ni(), (ut ? "production" : void 0) !== "production" && (globalThis.__JOTAI_DEFAULT_STORE__ || (globalThis.__JOTAI_DEFAULT_STORE__ = ye), globalThis.__JOTAI_DEFAULT_STORE__ !== ye && console.warn(
|
|
3383
3390
|
"Detected multiple Jotai instances. It may cause unexpected behavior with the default store. https://github.com/pmndrs/jotai/discussions/2044"
|
|
3384
3391
|
))), ye;
|
|
3385
3392
|
}
|
|
3386
|
-
const
|
|
3393
|
+
const Pi = {}, ji = Bt(
|
|
3387
3394
|
void 0
|
|
3388
3395
|
);
|
|
3389
3396
|
function dn(t) {
|
|
3390
|
-
return Gt(
|
|
3397
|
+
return Gt(ji) || Di();
|
|
3391
3398
|
}
|
|
3392
3399
|
const st = (t) => typeof t?.then == "function", ot = (t) => {
|
|
3393
3400
|
t.status || (t.status = "pending", t.then(
|
|
@@ -3398,7 +3405,7 @@ const st = (t) => typeof t?.then == "function", ot = (t) => {
|
|
|
3398
3405
|
t.status = "rejected", t.reason = e;
|
|
3399
3406
|
}
|
|
3400
3407
|
));
|
|
3401
|
-
},
|
|
3408
|
+
}, Ui = rt.use || // A shim for older React versions
|
|
3402
3409
|
((t) => {
|
|
3403
3410
|
if (t.status === "pending")
|
|
3404
3411
|
throw t;
|
|
@@ -3453,7 +3460,7 @@ function Ge(t, e) {
|
|
|
3453
3460
|
return h(), f;
|
|
3454
3461
|
}, [s, t, n, i]), mn(p), st(p)) {
|
|
3455
3462
|
const f = Ft(p, () => s.get(t));
|
|
3456
|
-
return i && ot(f),
|
|
3463
|
+
return i && ot(f), Ui(f);
|
|
3457
3464
|
}
|
|
3458
3465
|
return p;
|
|
3459
3466
|
}
|
|
@@ -3461,7 +3468,7 @@ function Be(t, e) {
|
|
|
3461
3468
|
const n = dn();
|
|
3462
3469
|
return bn(
|
|
3463
3470
|
(...s) => {
|
|
3464
|
-
if ((
|
|
3471
|
+
if ((Pi ? "production" : void 0) !== "production" && !("write" in t))
|
|
3465
3472
|
throw new Error("not writable atom");
|
|
3466
3473
|
return n.set(t, ...s);
|
|
3467
3474
|
},
|
|
@@ -3469,10 +3476,10 @@ function Be(t, e) {
|
|
|
3469
3476
|
);
|
|
3470
3477
|
}
|
|
3471
3478
|
const ln = Fe([]);
|
|
3472
|
-
function
|
|
3479
|
+
function Ji() {
|
|
3473
3480
|
return Ge(ln);
|
|
3474
3481
|
}
|
|
3475
|
-
function
|
|
3482
|
+
function $i() {
|
|
3476
3483
|
return Be(ln);
|
|
3477
3484
|
}
|
|
3478
3485
|
const We = () => {
|
|
@@ -3481,8 +3488,8 @@ const We = () => {
|
|
|
3481
3488
|
throw new Error("useClient must be used within a TelnyxAIAgentProvider");
|
|
3482
3489
|
return t;
|
|
3483
3490
|
};
|
|
3484
|
-
function
|
|
3485
|
-
const t = We(), e =
|
|
3491
|
+
function Vi() {
|
|
3492
|
+
const t = We(), e = $i();
|
|
3486
3493
|
return ce(() => {
|
|
3487
3494
|
const n = (i) => e((s) => [...s, i]);
|
|
3488
3495
|
return t.addListener("transcript.item", n), () => {
|
|
@@ -3491,14 +3498,14 @@ function $i() {
|
|
|
3491
3498
|
}, [t, e]), null;
|
|
3492
3499
|
}
|
|
3493
3500
|
const un = Fe("connecting");
|
|
3494
|
-
function
|
|
3501
|
+
function Hi() {
|
|
3495
3502
|
return Ge(un);
|
|
3496
3503
|
}
|
|
3497
|
-
function
|
|
3504
|
+
function Fi() {
|
|
3498
3505
|
return Be(un);
|
|
3499
3506
|
}
|
|
3500
|
-
function
|
|
3501
|
-
const t = We(), e =
|
|
3507
|
+
function Gi() {
|
|
3508
|
+
const t = We(), e = Fi();
|
|
3502
3509
|
return ce(() => {
|
|
3503
3510
|
const n = () => e("connected"), i = () => e("disconnected"), s = () => e("error");
|
|
3504
3511
|
return t.addListener("agent.connected", n), t.addListener("agent.disconnected", i), t.addListener("agent.error", s), () => {
|
|
@@ -3507,14 +3514,14 @@ function Fi() {
|
|
|
3507
3514
|
}, [t, e]), null;
|
|
3508
3515
|
}
|
|
3509
3516
|
const hn = Fe(null);
|
|
3510
|
-
function
|
|
3517
|
+
function Ki() {
|
|
3511
3518
|
return Ge(hn);
|
|
3512
3519
|
}
|
|
3513
|
-
function
|
|
3520
|
+
function Bi() {
|
|
3514
3521
|
return Be(hn);
|
|
3515
3522
|
}
|
|
3516
|
-
const
|
|
3517
|
-
const t = We(), e =
|
|
3523
|
+
const Wi = () => {
|
|
3524
|
+
const t = We(), e = Bi();
|
|
3518
3525
|
return ce(() => {
|
|
3519
3526
|
const n = (i) => {
|
|
3520
3527
|
e(i);
|
|
@@ -3524,14 +3531,14 @@ const Bi = () => {
|
|
|
3524
3531
|
};
|
|
3525
3532
|
}, [t, e]), null;
|
|
3526
3533
|
}, pn = Fe("listening");
|
|
3527
|
-
function
|
|
3534
|
+
function Qi() {
|
|
3528
3535
|
return Ge(pn);
|
|
3529
3536
|
}
|
|
3530
|
-
function
|
|
3537
|
+
function qi() {
|
|
3531
3538
|
return Be(pn);
|
|
3532
3539
|
}
|
|
3533
|
-
function
|
|
3534
|
-
const t = We(), e =
|
|
3540
|
+
function Yi() {
|
|
3541
|
+
const t = We(), e = qi();
|
|
3535
3542
|
return ce(() => {
|
|
3536
3543
|
const n = (i) => {
|
|
3537
3544
|
e(i);
|
|
@@ -3541,7 +3548,7 @@ function qi() {
|
|
|
3541
3548
|
};
|
|
3542
3549
|
}, [t, e]), null;
|
|
3543
3550
|
}
|
|
3544
|
-
const fn = Bt(null),
|
|
3551
|
+
const fn = Bt(null), Xi = ({
|
|
3545
3552
|
children: t,
|
|
3546
3553
|
agentId: e,
|
|
3547
3554
|
environment: n,
|
|
@@ -3558,24 +3565,24 @@ const fn = Bt(null), Qi = ({
|
|
|
3558
3565
|
}, [e, s, n, i]), ce(() => {
|
|
3559
3566
|
s?.connect();
|
|
3560
3567
|
}, [s]), /* @__PURE__ */ be.jsxs(fn.Provider, { value: s, children: [
|
|
3561
|
-
/* @__PURE__ */ be.jsx(
|
|
3562
|
-
/* @__PURE__ */ be.jsx(
|
|
3563
|
-
/* @__PURE__ */ be.jsx(
|
|
3564
|
-
/* @__PURE__ */ be.jsx(
|
|
3568
|
+
/* @__PURE__ */ be.jsx(Vi, {}),
|
|
3569
|
+
/* @__PURE__ */ be.jsx(Gi, {}),
|
|
3570
|
+
/* @__PURE__ */ be.jsx(Wi, {}),
|
|
3571
|
+
/* @__PURE__ */ be.jsx(Yi, {}),
|
|
3565
3572
|
t
|
|
3566
3573
|
] });
|
|
3567
3574
|
};
|
|
3568
3575
|
export {
|
|
3569
3576
|
fn as ClientContext,
|
|
3570
3577
|
Ot as TelnyxAIAgent,
|
|
3571
|
-
|
|
3572
|
-
|
|
3578
|
+
Xi as TelnyxAIAgentProvider,
|
|
3579
|
+
Qi as useAgentState,
|
|
3573
3580
|
We as useClient,
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
+
Hi as useConnectionState,
|
|
3582
|
+
Ki as useConversation,
|
|
3583
|
+
qi as useSetAgentState,
|
|
3584
|
+
Fi as useSetConnectionState,
|
|
3585
|
+
Bi as useSetConversation,
|
|
3586
|
+
$i as useSetTranscript,
|
|
3587
|
+
Ji as useTranscript
|
|
3581
3588
|
};
|
package/dist/util.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telnyx/ai-agent-lib",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"jotai": "^2.12.5"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@types/node": "^24.1.0",
|
|
29
28
|
"@eslint/js": "^9.30.1",
|
|
29
|
+
"@types/node": "^24.1.0",
|
|
30
30
|
"@types/react": "^19.1.8",
|
|
31
31
|
"@types/react-dom": "^19.1.6",
|
|
32
32
|
"@vitejs/plugin-react-swc": "^3.10.2",
|
|
@@ -34,6 +34,8 @@
|
|
|
34
34
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
35
35
|
"eslint-plugin-react-refresh": "^0.4.20",
|
|
36
36
|
"globals": "^16.3.0",
|
|
37
|
+
"react": "^19.1.1",
|
|
38
|
+
"react-dom": "^19.1.1",
|
|
37
39
|
"release-it": "^19.0.4",
|
|
38
40
|
"typescript": "~5.8.3",
|
|
39
41
|
"typescript-eslint": "^8.35.1",
|