@estuary-ai/sdk 0.1.0

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 ADDED
@@ -0,0 +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.
package/README.md ADDED
@@ -0,0 +1,127 @@
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
+ ### Memory & Knowledge Graph
78
+
79
+ ```typescript
80
+ const memories = await client.memory.getMemories({ status: 'active', limit: 50 });
81
+ const facts = await client.memory.getCoreFacts();
82
+ const graph = await client.memory.getGraph({ includeEntities: true });
83
+ const results = await client.memory.search('favorite food');
84
+ ```
85
+
86
+ ## Events
87
+
88
+ ```typescript
89
+ client.on('connected', (session) => { /* authenticated */ });
90
+ client.on('disconnected', (reason) => { /* lost connection */ });
91
+ client.on('botResponse', (response) => { /* streaming text */ });
92
+ client.on('botVoice', (voice) => { /* audio chunk */ });
93
+ client.on('sttResponse', (stt) => { /* speech-to-text */ });
94
+ client.on('interrupt', (data) => { /* response interrupted */ });
95
+ client.on('error', (error) => { /* EstuaryError */ });
96
+ client.on('quotaExceeded', (data) => { /* rate limited */ });
97
+ ```
98
+
99
+ ## Configuration
100
+
101
+ ```typescript
102
+ interface EstuaryConfig {
103
+ serverUrl: string; // Server URL
104
+ apiKey: string; // API key (est_...)
105
+ characterId: string; // Character ID
106
+ playerId: string; // End user ID
107
+ audioSampleRate?: number; // Default: 16000
108
+ autoReconnect?: boolean; // Default: true
109
+ maxReconnectAttempts?: number; // Default: 5
110
+ reconnectDelayMs?: number; // Default: 2000
111
+ debug?: boolean; // Default: false
112
+ voiceTransport?: 'websocket' | 'livekit' | 'auto'; // Default: 'auto'
113
+ }
114
+ ```
115
+
116
+ ## Requirements
117
+
118
+ - Node.js 18+ or modern browser
119
+ - Estuary account with API key and Character ID
120
+
121
+ ## Documentation
122
+
123
+ Full documentation at [docs.estuary-ai.com](https://docs.estuary-ai.com/docs/typescript-sdk/getting-started).
124
+
125
+ ## License
126
+
127
+ MIT
@@ -0,0 +1,291 @@
1
+ interface EstuaryConfig {
2
+ /** Base URL of the Estuary server (e.g., "https://api.estuary-ai.com") */
3
+ serverUrl: string;
4
+ /** API key (starts with "est_") */
5
+ apiKey: string;
6
+ /** Character (agent) ID */
7
+ characterId: string;
8
+ /** Unique identifier for the end user */
9
+ playerId: string;
10
+ /** Audio sample rate in Hz (default: 16000) */
11
+ audioSampleRate?: number;
12
+ /** Auto-reconnect on disconnect (default: true) */
13
+ autoReconnect?: boolean;
14
+ /** Max reconnect attempts (default: 5) */
15
+ maxReconnectAttempts?: number;
16
+ /** Delay between reconnect attempts in ms (default: 2000) */
17
+ reconnectDelayMs?: number;
18
+ /** Enable debug logging (default: false) */
19
+ debug?: boolean;
20
+ /** Voice transport: 'websocket' | 'livekit' | 'auto' (default: 'auto') */
21
+ voiceTransport?: VoiceTransport;
22
+ /** Enable real-time memory extraction after each response (default: false) */
23
+ realtimeMemory?: boolean;
24
+ }
25
+ type VoiceTransport = 'websocket' | 'livekit' | 'auto';
26
+ declare enum ConnectionState {
27
+ Disconnected = "disconnected",
28
+ Connecting = "connecting",
29
+ Connected = "connected",
30
+ Reconnecting = "reconnecting",
31
+ Error = "error"
32
+ }
33
+ interface SessionInfo {
34
+ sessionId: string;
35
+ conversationId: string;
36
+ characterId: string;
37
+ playerId: string;
38
+ }
39
+ interface BotResponse {
40
+ text: string;
41
+ isFinal: boolean;
42
+ partial: string;
43
+ messageId: string;
44
+ chunkIndex: number;
45
+ isInterjection: boolean;
46
+ }
47
+ interface BotVoice {
48
+ audio: string;
49
+ messageId: string;
50
+ chunkIndex: number;
51
+ isFinal: boolean;
52
+ }
53
+ interface SttResponse {
54
+ text: string;
55
+ isFinal: boolean;
56
+ }
57
+ interface InterruptData {
58
+ messageId?: string;
59
+ reason?: string;
60
+ interruptedAt?: string;
61
+ }
62
+ interface QuotaExceededData {
63
+ message: string;
64
+ current: number;
65
+ limit: number;
66
+ remaining: number;
67
+ tier: string;
68
+ }
69
+ interface LiveKitTokenResponse {
70
+ token: string;
71
+ url: string;
72
+ room: string;
73
+ }
74
+ interface CameraCaptureRequest {
75
+ requestId: string;
76
+ text?: string;
77
+ }
78
+ interface MemoryData {
79
+ id: string;
80
+ content: string;
81
+ memoryType: string;
82
+ confidence: number;
83
+ status: string;
84
+ sourceConversationId: string;
85
+ sourceQuote?: string;
86
+ topic?: string;
87
+ createdAt: string;
88
+ }
89
+ interface MemoryUpdatedEvent {
90
+ agentId: string;
91
+ playerId: string;
92
+ memoriesExtracted: number;
93
+ factsExtracted: number;
94
+ conversationId: string;
95
+ newMemories: MemoryData[];
96
+ timestamp: string;
97
+ }
98
+ type EstuaryEventMap = {
99
+ connected: (session: SessionInfo) => void;
100
+ disconnected: (reason: string) => void;
101
+ reconnecting: (attempt: number) => void;
102
+ connectionStateChanged: (state: ConnectionState) => void;
103
+ botResponse: (response: BotResponse) => void;
104
+ botVoice: (voice: BotVoice) => void;
105
+ sttResponse: (response: SttResponse) => void;
106
+ interrupt: (data: InterruptData) => void;
107
+ error: (error: Error) => void;
108
+ authError: (error: string) => void;
109
+ quotaExceeded: (data: QuotaExceededData) => void;
110
+ cameraCaptureRequest: (request: CameraCaptureRequest) => void;
111
+ voiceStarted: () => void;
112
+ voiceStopped: () => void;
113
+ livekitConnected: (room: string) => void;
114
+ livekitDisconnected: () => void;
115
+ audioPlaybackStarted: (messageId: string) => void;
116
+ audioPlaybackComplete: (messageId: string) => void;
117
+ memoryUpdated: (event: MemoryUpdatedEvent) => void;
118
+ };
119
+ interface VoiceManager {
120
+ start(): Promise<void>;
121
+ stop(): Promise<void>;
122
+ toggleMute(): void;
123
+ readonly isMuted: boolean;
124
+ readonly isActive: boolean;
125
+ dispose(): void;
126
+ }
127
+ interface MemoryListOptions {
128
+ memoryType?: string;
129
+ status?: string;
130
+ limit?: number;
131
+ offset?: number;
132
+ sortBy?: 'created_at' | 'confidence' | 'last_accessed_at';
133
+ sortOrder?: 'asc' | 'desc';
134
+ }
135
+ interface MemoryTimelineOptions {
136
+ startDate?: string;
137
+ endDate?: string;
138
+ groupBy?: 'day' | 'week' | 'month';
139
+ }
140
+ interface MemoryGraphOptions {
141
+ includeEntities?: boolean;
142
+ includeCharacterMemories?: boolean;
143
+ }
144
+ interface MemorySearchOptions {
145
+ query: string;
146
+ limit?: number;
147
+ }
148
+ interface MemoryListResponse {
149
+ memories: Record<string, unknown>[];
150
+ total: number;
151
+ limit: number;
152
+ offset: number;
153
+ }
154
+ interface MemoryTimelineResponse {
155
+ timeline: {
156
+ date: string;
157
+ memories: Record<string, unknown>[];
158
+ }[];
159
+ totalMemories: number;
160
+ groupBy: string;
161
+ }
162
+ interface MemoryStatsResponse {
163
+ [key: string]: unknown;
164
+ }
165
+ interface MemoryGraphResponse {
166
+ nodes: Record<string, unknown>[];
167
+ edges: Record<string, unknown>[];
168
+ stats: Record<string, unknown>;
169
+ }
170
+ interface MemorySearchResponse {
171
+ results: {
172
+ memory: Record<string, unknown>;
173
+ score: number;
174
+ similarityScore: number;
175
+ }[];
176
+ query: string;
177
+ total: number;
178
+ }
179
+ interface CoreFactsResponse {
180
+ coreFacts: Record<string, unknown>[];
181
+ }
182
+
183
+ declare class RestClient {
184
+ private baseUrl;
185
+ private apiKey;
186
+ constructor(baseUrl: string, apiKey: string);
187
+ get<T>(path: string, params?: Record<string, string | number | boolean | undefined>): Promise<T>;
188
+ post<T>(path: string, body?: unknown): Promise<T>;
189
+ delete<T>(path: string, params?: Record<string, string | number | boolean | undefined>): Promise<T>;
190
+ dispose(): void;
191
+ private buildUrl;
192
+ private request;
193
+ }
194
+
195
+ declare class MemoryClient {
196
+ private rest;
197
+ private basePath;
198
+ constructor(rest: RestClient, agentId: string, playerId: string);
199
+ getMemories(options?: MemoryListOptions): Promise<MemoryListResponse>;
200
+ getTimeline(options?: MemoryTimelineOptions): Promise<MemoryTimelineResponse>;
201
+ getStats(): Promise<MemoryStatsResponse>;
202
+ getCoreFacts(): Promise<CoreFactsResponse>;
203
+ getGraph(options?: MemoryGraphOptions): Promise<MemoryGraphResponse>;
204
+ search(query: string, limit?: number): Promise<MemorySearchResponse>;
205
+ deleteAll(confirm: boolean): Promise<{
206
+ message: string;
207
+ deletedCount: number;
208
+ }>;
209
+ dispose(): void;
210
+ }
211
+
212
+ declare class TypedEventEmitter<T extends Record<string, unknown>> {
213
+ private listeners;
214
+ private onceListeners;
215
+ on<K extends keyof T>(event: K, listener: T[K]): this;
216
+ off<K extends keyof T>(event: K, listener: T[K]): this;
217
+ once<K extends keyof T>(event: K, listener: T[K]): this;
218
+ protected emit<K extends keyof T>(event: K, ...args: T[K] extends (...a: infer A) => void ? A : never[]): boolean;
219
+ removeAllListeners<K extends keyof T>(event?: K): this;
220
+ listenerCount<K extends keyof T>(event: K): number;
221
+ }
222
+
223
+ declare class EstuaryClient extends TypedEventEmitter<EstuaryEventMap> {
224
+ private config;
225
+ private logger;
226
+ private socketManager;
227
+ private voiceManager;
228
+ private audioPlayer;
229
+ private _memory;
230
+ private _sessionInfo;
231
+ constructor(config: EstuaryConfig);
232
+ /** Memory API client for querying memories, graphs, and facts */
233
+ get memory(): MemoryClient;
234
+ /** Current session info (null if not connected) */
235
+ get session(): SessionInfo | null;
236
+ /** Current connection state */
237
+ get connectionState(): ConnectionState;
238
+ /** Whether the client is connected and authenticated */
239
+ get isConnected(): boolean;
240
+ /** Connect to the Estuary server and authenticate */
241
+ connect(): Promise<SessionInfo>;
242
+ /** Disconnect from the server */
243
+ disconnect(): void;
244
+ /** Send a text message to the character */
245
+ sendText(text: string, textOnly?: boolean): void;
246
+ /** Interrupt the current bot response */
247
+ interrupt(messageId?: string): void;
248
+ /** Send a camera image for vision processing */
249
+ sendCameraImage(imageBase64: string, mimeType: string, requestId?: string, text?: string): void;
250
+ /** Update session preferences */
251
+ updatePreferences(preferences: {
252
+ enableVisionAcknowledgment?: boolean;
253
+ }): void;
254
+ /** Notify server that audio playback completed for a message */
255
+ notifyAudioPlaybackComplete(messageId?: string): void;
256
+ /** Start voice input (requests microphone permission) */
257
+ startVoice(): Promise<void>;
258
+ /** Stop voice input */
259
+ stopVoice(): void;
260
+ /** Toggle microphone mute */
261
+ toggleMute(): void;
262
+ /** Whether the microphone is muted */
263
+ get isMuted(): boolean;
264
+ /** Whether voice is currently active */
265
+ get isVoiceActive(): boolean;
266
+ private ensureConnected;
267
+ private forwardSocketEvents;
268
+ private handleBotVoice;
269
+ }
270
+
271
+ declare enum ErrorCode {
272
+ CONNECTION_FAILED = "CONNECTION_FAILED",
273
+ AUTH_FAILED = "AUTH_FAILED",
274
+ CONNECTION_TIMEOUT = "CONNECTION_TIMEOUT",
275
+ QUOTA_EXCEEDED = "QUOTA_EXCEEDED",
276
+ VOICE_NOT_SUPPORTED = "VOICE_NOT_SUPPORTED",
277
+ VOICE_ALREADY_ACTIVE = "VOICE_ALREADY_ACTIVE",
278
+ VOICE_NOT_ACTIVE = "VOICE_NOT_ACTIVE",
279
+ LIVEKIT_UNAVAILABLE = "LIVEKIT_UNAVAILABLE",
280
+ MICROPHONE_DENIED = "MICROPHONE_DENIED",
281
+ NOT_CONNECTED = "NOT_CONNECTED",
282
+ REST_ERROR = "REST_ERROR",
283
+ UNKNOWN = "UNKNOWN"
284
+ }
285
+ declare class EstuaryError extends Error {
286
+ readonly code: ErrorCode;
287
+ readonly details?: unknown;
288
+ constructor(code: ErrorCode, message: string, details?: unknown);
289
+ }
290
+
291
+ export { type BotResponse, type BotVoice, type CameraCaptureRequest, ConnectionState, type CoreFactsResponse, ErrorCode, EstuaryClient, type EstuaryConfig, EstuaryError, type EstuaryEventMap, type InterruptData, type LiveKitTokenResponse, MemoryClient, type MemoryData, type MemoryGraphOptions, type MemoryGraphResponse, type MemoryListOptions, type MemoryListResponse, type MemorySearchOptions, type MemorySearchResponse, type MemoryStatsResponse, type MemoryTimelineOptions, type MemoryTimelineResponse, type MemoryUpdatedEvent, type QuotaExceededData, type SessionInfo, type SttResponse, type VoiceManager, type VoiceTransport };