@estuary-ai/sdk 0.1.19 → 0.1.21

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 estuary.ai
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 estuary.ai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,288 +1,324 @@
1
- # @estuary-ai/sdk
2
-
3
- TypeScript SDK for the [Estuary](https://www.estuary-ai.com) real-time AI conversation platform. Build applications with persistent AI characters that remember, hear, and see.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install @estuary-ai/sdk
9
- ```
10
-
11
- For LiveKit voice (optional, lower latency):
12
-
13
- ```bash
14
- npm install @estuary-ai/sdk livekit-client
15
- ```
16
-
17
- ## Quick Start
18
-
19
- ```typescript
20
- import { EstuaryClient } from '@estuary-ai/sdk';
21
-
22
- const client = new EstuaryClient({
23
- serverUrl: 'https://api.estuary-ai.com',
24
- apiKey: 'est_your_api_key',
25
- characterId: 'your-character-id',
26
- playerId: 'user-123',
27
- });
28
-
29
- client.on('botResponse', (response) => {
30
- process.stdout.write(response.text);
31
- if (response.isFinal) console.log();
32
- });
33
-
34
- await client.connect();
35
- client.sendText('Hello!');
36
- ```
37
-
38
- ## Features
39
-
40
- ### Text Chat
41
-
42
- ```typescript
43
- client.sendText('What do you remember about me?');
44
- client.sendText('Just respond in text', true); // textOnly mode
45
- ```
46
-
47
- ### Voice (WebSocket)
48
-
49
- ```typescript
50
- const client = new EstuaryClient({
51
- serverUrl: 'https://api.estuary-ai.com',
52
- apiKey: 'est_...',
53
- characterId: '...',
54
- playerId: '...',
55
- voiceTransport: 'websocket',
56
- });
57
-
58
- await client.connect();
59
- await client.startVoice(); // Requests mic permission
60
- // ... speak, receive audio responses
61
- client.stopVoice();
62
- ```
63
-
64
- ### Voice (LiveKit)
65
-
66
- ```typescript
67
- const client = new EstuaryClient({
68
- // ...
69
- voiceTransport: 'livekit', // or 'auto' to prefer LiveKit
70
- });
71
-
72
- await client.connect();
73
- await client.startVoice();
74
- client.toggleMute();
75
- ```
76
-
77
- ### Interrupts
78
-
79
- Interrupt the bot's current response (stops audio playback and generation):
80
-
81
- ```typescript
82
- client.interrupt(); // interrupt current response
83
- client.interrupt('msg_abc123'); // interrupt a specific message
84
- ```
85
-
86
- ### Vision / Camera
87
-
88
- Send images for vision processing. The server may also request captures via the `cameraCaptureRequest` event.
89
-
90
- ```typescript
91
- // Send a camera image proactively
92
- client.sendCameraImage(base64Image, 'image/jpeg');
93
-
94
- // Respond to a server-initiated capture request
95
- client.on('cameraCaptureRequest', (request) => {
96
- const image = captureFrame(); // your capture logic
97
- client.sendCameraImage(image, 'image/jpeg', request.requestId, request.text);
98
- });
99
- ```
100
-
101
- ### Character Actions
102
-
103
- Bot responses can include inline action tags (e.g., `<action name="wave" target="user"/>`). The SDK automatically parses these, strips them from `botResponse.text`, and emits `characterAction` events:
104
-
105
- ```typescript
106
- client.on('characterAction', (action) => {
107
- console.log(action.name); // e.g., "wave"
108
- console.log(action.params); // e.g., { target: "user" }
109
- console.log(action.messageId); // originating message
110
- });
111
- ```
112
-
113
- For non-streaming contexts, use the `parseActions` utility:
114
-
115
- ```typescript
116
- import { parseActions } from '@estuary-ai/sdk';
117
-
118
- const { actions, cleanText } = parseActions(rawBotText);
119
- ```
120
-
121
- ### Memory & Knowledge Graph
122
-
123
- ```typescript
124
- const memories = await client.memory.getMemories({ status: 'active', limit: 50 });
125
- const facts = await client.memory.getCoreFacts();
126
- const graph = await client.memory.getGraph({ includeEntities: true });
127
- const results = await client.memory.search('favorite food');
128
- const timeline = await client.memory.getTimeline({ groupBy: 'week' });
129
- const stats = await client.memory.getStats();
130
- await client.memory.deleteAll(true); // pass true to confirm
131
- ```
132
-
133
- ### Real-Time Memory Extraction
134
-
135
- Enable `realtimeMemory` to receive live notifications when the server extracts memories from conversation:
136
-
137
- ```typescript
138
- const client = new EstuaryClient({
139
- serverUrl: 'https://api.estuary-ai.com',
140
- apiKey: 'est_...',
141
- characterId: '...',
142
- playerId: '...',
143
- realtimeMemory: true,
144
- });
145
-
146
- client.on('memoryUpdated', (event) => {
147
- console.log(`Extracted ${event.memoriesExtracted} memories, ${event.factsExtracted} facts`);
148
- for (const mem of event.newMemories) {
149
- console.log(` [${mem.memoryType}] ${mem.content} (confidence: ${mem.confidence})`);
150
- }
151
- });
152
-
153
- await client.connect();
154
- ```
155
-
156
- ## Events
157
-
158
- ```typescript
159
- // Connection
160
- client.on('connected', (session) => { /* authenticated */ });
161
- client.on('disconnected', (reason) => { /* lost connection */ });
162
- client.on('reconnecting', (attempt) => { /* reconnect attempt number */ });
163
- client.on('connectionStateChanged', (state) => { /* ConnectionState enum */ });
164
- client.on('authError', (error) => { /* authentication failed */ });
165
-
166
- // Conversation
167
- client.on('botResponse', (response) => { /* streaming text (actions auto-stripped) */ });
168
- client.on('botVoice', (voice) => { /* audio chunk */ });
169
- client.on('sttResponse', (stt) => { /* speech-to-text transcript */ });
170
- client.on('interrupt', (data) => { /* response interrupted */ });
171
- client.on('characterAction', (action) => { /* parsed action from bot response */ });
172
- client.on('cameraCaptureRequest', (request) => { /* server requests a camera image */ });
173
-
174
- // Voice
175
- client.on('voiceStarted', () => { /* voice session began */ });
176
- client.on('voiceStopped', () => { /* voice session ended */ });
177
- client.on('livekitConnected', (room) => { /* joined LiveKit room */ });
178
- client.on('livekitDisconnected', () => { /* left LiveKit room */ });
179
-
180
- // Audio playback
181
- client.on('audioPlaybackStarted', (messageId) => { /* bot audio started playing */ });
182
- client.on('audioPlaybackComplete', (messageId) => { /* bot audio finished playing */ });
183
-
184
- // Memory
185
- client.on('memoryUpdated', (event) => { /* real-time memory extraction */ });
186
-
187
- // Errors & limits
188
- client.on('error', (error) => { /* EstuaryError */ });
189
- client.on('quotaExceeded', (data) => { /* rate limited */ });
190
- ```
191
-
192
- ## Error Handling
193
-
194
- Errors are instances of `EstuaryError` with a typed `code` field:
195
-
196
- ```typescript
197
- import { EstuaryError, ErrorCode } from '@estuary-ai/sdk';
198
-
199
- client.on('error', (error) => {
200
- if (error instanceof EstuaryError) {
201
- switch (error.code) {
202
- case ErrorCode.NOT_CONNECTED:
203
- case ErrorCode.CONNECTION_FAILED:
204
- case ErrorCode.CONNECTION_TIMEOUT:
205
- // connection issues
206
- break;
207
- case ErrorCode.AUTH_FAILED:
208
- // bad API key or character ID
209
- break;
210
- case ErrorCode.MICROPHONE_DENIED:
211
- // user denied mic permission
212
- break;
213
- }
214
- }
215
- });
216
-
217
- client.on('authError', (message) => {
218
- console.error('Authentication failed:', message);
219
- });
220
- ```
221
-
222
- ## Configuration
223
-
224
- ```typescript
225
- interface EstuaryConfig {
226
- serverUrl: string; // Server URL
227
- apiKey: string; // API key (est_...)
228
- characterId: string; // Character ID
229
- playerId: string; // End user ID
230
- audioSampleRate?: number; // Default: 16000
231
- autoReconnect?: boolean; // Default: true
232
- maxReconnectAttempts?: number; // Default: 5
233
- reconnectDelayMs?: number; // Default: 2000
234
- debug?: boolean; // Default: false
235
- voiceTransport?: 'websocket' | 'livekit' | 'auto'; // Default: 'auto'
236
- realtimeMemory?: boolean; // Enable real-time memory extraction events. Default: false
237
- suppressMicDuringPlayback?: boolean; // Mute mic while bot audio plays (software AEC). Default: false
238
- }
239
- ```
240
-
241
- ## Exports
242
-
243
- Key exports for TypeScript users:
244
-
245
- ```typescript
246
- // Client
247
- import { EstuaryClient } from '@estuary-ai/sdk';
248
-
249
- // Errors
250
- import { EstuaryError, ErrorCode } from '@estuary-ai/sdk';
251
-
252
- // Enums
253
- import { ConnectionState } from '@estuary-ai/sdk';
254
-
255
- // Utilities
256
- import { parseActions } from '@estuary-ai/sdk';
257
-
258
- // Types (import type)
259
- import type {
260
- EstuaryConfig,
261
- SessionInfo,
262
- BotResponse,
263
- BotVoice,
264
- SttResponse,
265
- InterruptData,
266
- CameraCaptureRequest,
267
- CharacterAction,
268
- QuotaExceededData,
269
- MemoryData,
270
- MemoryUpdatedEvent,
271
- EstuaryEventMap,
272
- ParsedAction,
273
- MemoryClient,
274
- } from '@estuary-ai/sdk';
275
- ```
276
-
277
- ## Requirements
278
-
279
- - Node.js 18+ or modern browser
280
- - Estuary account with API key and Character ID
281
-
282
- ## Documentation
283
-
284
- Full documentation at [docs.estuary-ai.com](https://docs.estuary-ai.com/docs/typescript-sdk/getting-started).
285
-
286
- ## License
287
-
288
- MIT
1
+ # @estuary-ai/sdk
2
+
3
+ [![npm](https://img.shields.io/npm/v/@estuary-ai/sdk)](https://www.npmjs.com/package/@estuary-ai/sdk)
4
+
5
+ TypeScript SDK for the [Estuary](https://www.estuary-ai.com) real-time AI conversation platform. Build applications with persistent AI characters that remember, hear, and see.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @estuary-ai/sdk
11
+ ```
12
+
13
+ For LiveKit voice (optional, lower latency):
14
+
15
+ ```bash
16
+ npm install @estuary-ai/sdk livekit-client
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ ```typescript
22
+ import { EstuaryClient } from '@estuary-ai/sdk';
23
+
24
+ const client = new EstuaryClient({
25
+ serverUrl: 'https://api.estuary-ai.com',
26
+ apiKey: 'est_your_api_key',
27
+ characterId: 'your-character-id',
28
+ playerId: 'user-123',
29
+ });
30
+
31
+ client.on('botResponse', (response) => {
32
+ process.stdout.write(response.text);
33
+ if (response.isFinal) console.log();
34
+ });
35
+
36
+ await client.connect();
37
+ client.sendText('Hello!');
38
+ ```
39
+
40
+ ## Features
41
+
42
+ ### Text Chat
43
+
44
+ ```typescript
45
+ client.sendText('What do you remember about me?');
46
+ client.sendText('Just respond in text', true); // textOnly mode
47
+ ```
48
+
49
+ ### Voice (WebSocket)
50
+
51
+ ```typescript
52
+ const client = new EstuaryClient({
53
+ serverUrl: 'https://api.estuary-ai.com',
54
+ apiKey: 'est_...',
55
+ characterId: '...',
56
+ playerId: '...',
57
+ voiceTransport: 'websocket',
58
+ });
59
+
60
+ await client.connect();
61
+ await client.startVoice(); // Requests mic permission
62
+ // ... speak, receive audio responses
63
+ client.stopVoice();
64
+ ```
65
+
66
+ ### Voice (LiveKit)
67
+
68
+ ```typescript
69
+ const client = new EstuaryClient({
70
+ // ...
71
+ voiceTransport: 'livekit', // or 'auto' to prefer LiveKit
72
+ });
73
+
74
+ await client.connect();
75
+ await client.startVoice();
76
+ client.toggleMute();
77
+ ```
78
+
79
+ ### Interrupts
80
+
81
+ Interrupt the bot's current response (stops audio playback and generation):
82
+
83
+ ```typescript
84
+ client.interrupt(); // interrupt current response
85
+ client.interrupt('msg_abc123'); // interrupt a specific message
86
+ ```
87
+
88
+ ### Vision / Camera
89
+
90
+ Send images for vision processing. The server may also request captures via the `cameraCaptureRequest` event.
91
+
92
+ ```typescript
93
+ // Send a camera image proactively
94
+ client.sendCameraImage(base64Image, 'image/jpeg');
95
+
96
+ // Respond to a server-initiated capture request
97
+ client.on('cameraCaptureRequest', (request) => {
98
+ const image = captureFrame(); // your capture logic
99
+ client.sendCameraImage(image, 'image/jpeg', request.requestId, request.text);
100
+ });
101
+ ```
102
+
103
+ ### Character Actions
104
+
105
+ Bot responses can include inline action tags (e.g., `<action name="wave" target="user"/>`). The SDK automatically parses these, strips them from `botResponse.text`, and emits `characterAction` events:
106
+
107
+ ```typescript
108
+ client.on('characterAction', (action) => {
109
+ console.log(action.name); // e.g., "wave"
110
+ console.log(action.params); // e.g., { target: "user" }
111
+ console.log(action.messageId); // originating message
112
+ });
113
+ ```
114
+
115
+ For non-streaming contexts, use the `parseActions` utility:
116
+
117
+ ```typescript
118
+ import { parseActions } from '@estuary-ai/sdk';
119
+
120
+ const { actions, cleanText } = parseActions(rawBotText);
121
+ ```
122
+
123
+ ### Memory & Knowledge Graph
124
+
125
+ ```typescript
126
+ const memories = await client.memory.getMemories({ status: 'active', limit: 50 });
127
+ const facts = await client.memory.getCoreFacts();
128
+ const graph = await client.memory.getGraph({ includeEntities: true });
129
+ const results = await client.memory.search('favorite food');
130
+ const timeline = await client.memory.getTimeline({ groupBy: 'week' });
131
+ const stats = await client.memory.getStats();
132
+ await client.memory.deleteAll(true); // pass true to confirm
133
+ ```
134
+
135
+ ### Real-Time Memory Extraction
136
+
137
+ Enable `realtimeMemory` to receive live notifications when the server extracts memories from conversation:
138
+
139
+ ```typescript
140
+ const client = new EstuaryClient({
141
+ serverUrl: 'https://api.estuary-ai.com',
142
+ apiKey: 'est_...',
143
+ characterId: '...',
144
+ playerId: '...',
145
+ realtimeMemory: true,
146
+ });
147
+
148
+ client.on('memoryUpdated', (event) => {
149
+ console.log(`Extracted ${event.memoriesExtracted} memories, ${event.factsExtracted} facts`);
150
+ for (const mem of event.newMemories) {
151
+ console.log(` [${mem.memoryType}] ${mem.content} (confidence: ${mem.confidence})`);
152
+ }
153
+ });
154
+
155
+ await client.connect();
156
+ ```
157
+
158
+ ## Events
159
+
160
+ ```typescript
161
+ // Connection
162
+ client.on('connected', (session) => { /* authenticated */ });
163
+ client.on('disconnected', (reason) => { /* lost connection */ });
164
+ client.on('reconnecting', (attempt) => { /* reconnect attempt number */ });
165
+ client.on('connectionStateChanged', (state) => { /* ConnectionState enum */ });
166
+ client.on('authError', (error) => { /* authentication failed */ });
167
+
168
+ // Conversation
169
+ client.on('botResponse', (response) => { /* streaming text (actions auto-stripped) */ });
170
+ client.on('botVoice', (voice) => { /* audio chunk */ });
171
+ client.on('sttResponse', (stt) => { /* speech-to-text transcript */ });
172
+ client.on('interrupt', (data) => { /* response interrupted */ });
173
+ client.on('characterAction', (action) => { /* parsed action from bot response */ });
174
+ client.on('cameraCaptureRequest', (request) => { /* server requests a camera image */ });
175
+
176
+ // Voice
177
+ client.on('voiceStarted', () => { /* voice session began */ });
178
+ client.on('voiceStopped', () => { /* voice session ended */ });
179
+ client.on('livekitConnected', (room) => { /* joined LiveKit room */ });
180
+ client.on('livekitDisconnected', () => { /* left LiveKit room */ });
181
+
182
+ // Audio playback
183
+ client.on('audioPlaybackStarted', (messageId) => { /* bot audio started playing */ });
184
+ client.on('audioPlaybackComplete', (messageId) => { /* bot audio finished playing */ });
185
+
186
+ // Memory
187
+ client.on('memoryUpdated', (event) => { /* real-time memory extraction */ });
188
+
189
+ // Errors & limits
190
+ client.on('error', (error) => { /* EstuaryError */ });
191
+ client.on('quotaExceeded', (data) => { /* rate limited */ });
192
+ ```
193
+
194
+ ## Error Handling
195
+
196
+ Errors are instances of `EstuaryError` with a typed `code` field:
197
+
198
+ ```typescript
199
+ import { EstuaryError, ErrorCode } from '@estuary-ai/sdk';
200
+
201
+ client.on('error', (error) => {
202
+ if (error instanceof EstuaryError) {
203
+ switch (error.code) {
204
+ case ErrorCode.NOT_CONNECTED:
205
+ case ErrorCode.CONNECTION_FAILED:
206
+ case ErrorCode.CONNECTION_TIMEOUT:
207
+ // connection issues
208
+ break;
209
+ case ErrorCode.AUTH_FAILED:
210
+ // bad API key or character ID
211
+ break;
212
+ case ErrorCode.MICROPHONE_DENIED:
213
+ // user denied mic permission
214
+ break;
215
+ }
216
+ }
217
+ });
218
+
219
+ client.on('authError', (message) => {
220
+ console.error('Authentication failed:', message);
221
+ });
222
+ ```
223
+
224
+ ## Configuration
225
+
226
+ ```typescript
227
+ interface EstuaryConfig {
228
+ serverUrl: string; // Server URL
229
+ apiKey: string; // API key (est_...)
230
+ characterId: string; // Character ID
231
+ playerId: string; // End user ID
232
+ audioSampleRate?: number; // Default: 16000
233
+ autoReconnect?: boolean; // Default: true
234
+ maxReconnectAttempts?: number; // Default: 5
235
+ reconnectDelayMs?: number; // Default: 2000
236
+ debug?: boolean; // Default: false
237
+ voiceTransport?: 'websocket' | 'livekit' | 'auto'; // Default: 'auto'
238
+ realtimeMemory?: boolean; // Enable real-time memory extraction events. Default: false
239
+ suppressMicDuringPlayback?: boolean; // Mute mic while bot audio plays (software AEC). Default: false
240
+ }
241
+ ```
242
+
243
+ ## Exports
244
+
245
+ Key exports for TypeScript users:
246
+
247
+ ```typescript
248
+ // Client
249
+ import { EstuaryClient } from '@estuary-ai/sdk';
250
+
251
+ // Errors
252
+ import { EstuaryError, ErrorCode } from '@estuary-ai/sdk';
253
+
254
+ // Enums
255
+ import { ConnectionState } from '@estuary-ai/sdk';
256
+
257
+ // Utilities
258
+ import { parseActions } from '@estuary-ai/sdk';
259
+
260
+ // Types (import type)
261
+ import type {
262
+ EstuaryConfig,
263
+ SessionInfo,
264
+ BotResponse,
265
+ BotVoice,
266
+ SttResponse,
267
+ InterruptData,
268
+ CameraCaptureRequest,
269
+ CharacterAction,
270
+ QuotaExceededData,
271
+ MemoryData,
272
+ MemoryUpdatedEvent,
273
+ EstuaryEventMap,
274
+ ParsedAction,
275
+ MemoryClient,
276
+ } from '@estuary-ai/sdk';
277
+ ```
278
+
279
+ ## React / Next.js
280
+
281
+ The SDK uses browser APIs, so it must be used in client components. In Next.js App Router:
282
+
283
+ ```tsx
284
+ "use client";
285
+
286
+ import { useEffect, useRef } from 'react';
287
+ import { EstuaryClient } from '@estuary-ai/sdk';
288
+
289
+ export default function Chat() {
290
+ const clientRef = useRef<EstuaryClient | null>(null);
291
+
292
+ useEffect(() => {
293
+ const client = new EstuaryClient({
294
+ serverUrl: 'https://api.estuary-ai.com',
295
+ apiKey: 'est_...',
296
+ characterId: '...',
297
+ playerId: 'user-123',
298
+ });
299
+ clientRef.current = client;
300
+ client.connect();
301
+
302
+ return () => {
303
+ client.disconnect();
304
+ };
305
+ }, []);
306
+
307
+ return <div>...</div>;
308
+ }
309
+ ```
310
+
311
+ If using `next/dynamic` with `ssr: false`, the importing page must also be a client component in Next.js 16+.
312
+
313
+ ## Requirements
314
+
315
+ - Node.js 18+ or modern browser
316
+ - Estuary account with API key and Character ID
317
+
318
+ ## Documentation
319
+
320
+ Full documentation at [docs.estuary-ai.com](https://docs.estuary-ai.com/docs/typescript-sdk/getting-started).
321
+
322
+ ## License
323
+
324
+ MIT