@estuary-ai/sdk 0.1.20 → 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/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @estuary-ai/sdk
2
2
 
3
+ [![npm](https://img.shields.io/npm/v/@estuary-ai/sdk)](https://www.npmjs.com/package/@estuary-ai/sdk)
4
+
3
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.
4
6
 
5
7
  ## Installation
@@ -274,6 +276,40 @@ import type {
274
276
  } from '@estuary-ai/sdk';
275
277
  ```
276
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
+
277
313
  ## Requirements
278
314
 
279
315
  - Node.js 18+ or modern browser
@@ -1,9 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
1
  // src/errors.ts
8
2
  var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
9
3
  ErrorCode2["CONNECTION_FAILED"] = "CONNECTION_FAILED";
@@ -31,6 +25,6 @@ var EstuaryError = class extends Error {
31
25
  }
32
26
  };
33
27
 
34
- export { ErrorCode, EstuaryError, __export };
35
- //# sourceMappingURL=chunk-ZROWZRQD.mjs.map
36
- //# sourceMappingURL=chunk-ZROWZRQD.mjs.map
28
+ export { ErrorCode, EstuaryError };
29
+ //# sourceMappingURL=chunk-6M5LSBMK.mjs.map
30
+ //# sourceMappingURL=chunk-6M5LSBMK.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts"],"names":["ErrorCode"],"mappings":";AAAO,IAAK,SAAA,qBAAAA,UAAAA,KAAL;AACL,EAAAA,WAAA,mBAAA,CAAA,GAAoB,mBAAA;AACpB,EAAAA,WAAA,aAAA,CAAA,GAAc,aAAA;AACd,EAAAA,WAAA,oBAAA,CAAA,GAAqB,oBAAA;AACrB,EAAAA,WAAA,gBAAA,CAAA,GAAiB,gBAAA;AACjB,EAAAA,WAAA,qBAAA,CAAA,GAAsB,qBAAA;AACtB,EAAAA,WAAA,sBAAA,CAAA,GAAuB,sBAAA;AACvB,EAAAA,WAAA,kBAAA,CAAA,GAAmB,kBAAA;AACnB,EAAAA,WAAA,qBAAA,CAAA,GAAsB,qBAAA;AACtB,EAAAA,WAAA,mBAAA,CAAA,GAAoB,mBAAA;AACpB,EAAAA,WAAA,eAAA,CAAA,GAAgB,eAAA;AAChB,EAAAA,WAAA,YAAA,CAAA,GAAa,YAAA;AACb,EAAAA,WAAA,SAAA,CAAA,GAAU,SAAA;AAZA,EAAA,OAAAA,UAAAA;AAAA,CAAA,EAAA,SAAA,IAAA,EAAA;AAeL,IAAM,YAAA,GAAN,cAA2B,KAAA,CAAM;AAAA,EAC7B,IAAA;AAAA,EACA,OAAA;AAAA,EAET,WAAA,CAAY,IAAA,EAAiB,OAAA,EAAiB,OAAA,EAAmB;AAC/D,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,cAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AAAA,EACjB;AACF","file":"chunk-6M5LSBMK.mjs","sourcesContent":["export enum ErrorCode {\r\n CONNECTION_FAILED = 'CONNECTION_FAILED',\r\n AUTH_FAILED = 'AUTH_FAILED',\r\n CONNECTION_TIMEOUT = 'CONNECTION_TIMEOUT',\r\n QUOTA_EXCEEDED = 'QUOTA_EXCEEDED',\r\n VOICE_NOT_SUPPORTED = 'VOICE_NOT_SUPPORTED',\r\n VOICE_ALREADY_ACTIVE = 'VOICE_ALREADY_ACTIVE',\r\n VOICE_NOT_ACTIVE = 'VOICE_NOT_ACTIVE',\r\n LIVEKIT_UNAVAILABLE = 'LIVEKIT_UNAVAILABLE',\r\n MICROPHONE_DENIED = 'MICROPHONE_DENIED',\r\n NOT_CONNECTED = 'NOT_CONNECTED',\r\n REST_ERROR = 'REST_ERROR',\r\n UNKNOWN = 'UNKNOWN',\r\n}\r\n\r\nexport class EstuaryError extends Error {\r\n readonly code: ErrorCode;\r\n readonly details?: unknown;\r\n\r\n constructor(code: ErrorCode, message: string, details?: unknown) {\r\n super(message);\r\n this.name = 'EstuaryError';\r\n this.code = code;\r\n this.details = details;\r\n }\r\n}\r\n"]}
@@ -0,0 +1,331 @@
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
+ /** Suppress mic during TTS playback (software AEC fallback, disables barge-in). Default: false */
25
+ suppressMicDuringPlayback?: boolean;
26
+ /** Proactively interrupt bot audio when user starts speaking (default: true) */
27
+ autoInterruptOnSpeech?: boolean;
28
+ }
29
+ type VoiceTransport = 'websocket' | 'livekit' | 'auto';
30
+ declare enum ConnectionState {
31
+ Disconnected = "disconnected",
32
+ Connecting = "connecting",
33
+ Connected = "connected",
34
+ Reconnecting = "reconnecting",
35
+ Error = "error"
36
+ }
37
+ interface SessionInfo {
38
+ sessionId: string;
39
+ conversationId: string;
40
+ characterId: string;
41
+ playerId: string;
42
+ }
43
+ interface BotResponse {
44
+ text: string;
45
+ isFinal: boolean;
46
+ partial: string;
47
+ messageId: string;
48
+ chunkIndex: number;
49
+ isInterjection: boolean;
50
+ tokenStream?: boolean;
51
+ }
52
+ interface BotVoice {
53
+ audio: string;
54
+ messageId: string;
55
+ chunkIndex: number;
56
+ isFinal: boolean;
57
+ }
58
+ interface SttResponse {
59
+ text: string;
60
+ isFinal: boolean;
61
+ }
62
+ interface InterruptData {
63
+ messageId?: string;
64
+ reason?: string;
65
+ interruptedAt?: string;
66
+ }
67
+ interface QuotaExceededData {
68
+ message: string;
69
+ current: number;
70
+ limit: number;
71
+ remaining: number;
72
+ tier: string;
73
+ }
74
+ interface LiveKitTokenResponse {
75
+ token: string;
76
+ url: string;
77
+ room: string;
78
+ }
79
+ interface CameraCaptureRequest {
80
+ requestId: string;
81
+ text?: string;
82
+ }
83
+ interface MemoryData {
84
+ id: string;
85
+ content: string;
86
+ memoryType: string;
87
+ confidence: number;
88
+ status: string;
89
+ sourceConversationId: string;
90
+ sourceQuote?: string;
91
+ topic?: string;
92
+ createdAt: string;
93
+ }
94
+ interface MemoryUpdatedEvent {
95
+ agentId: string;
96
+ playerId: string;
97
+ memoriesExtracted: number;
98
+ factsExtracted: number;
99
+ conversationId: string;
100
+ newMemories: MemoryData[];
101
+ timestamp: string;
102
+ }
103
+ interface CharacterAction {
104
+ /** Action name (e.g., "follow_user", "sit", "look_at") */
105
+ name: string;
106
+ /** Action parameters as key-value pairs */
107
+ params: Record<string, string>;
108
+ /** Message ID of the bot response that contained this action */
109
+ messageId: string;
110
+ }
111
+ type EstuaryEventMap = {
112
+ connected: (session: SessionInfo) => void;
113
+ disconnected: (reason: string) => void;
114
+ reconnecting: (attempt: number) => void;
115
+ connectionStateChanged: (state: ConnectionState) => void;
116
+ botResponse: (response: BotResponse) => void;
117
+ botVoice: (voice: BotVoice) => void;
118
+ sttResponse: (response: SttResponse) => void;
119
+ interrupt: (data: InterruptData) => void;
120
+ error: (error: Error) => void;
121
+ authError: (error: string) => void;
122
+ quotaExceeded: (data: QuotaExceededData) => void;
123
+ cameraCaptureRequest: (request: CameraCaptureRequest) => void;
124
+ characterAction: (action: CharacterAction) => void;
125
+ voiceStarted: () => void;
126
+ voiceStopped: () => void;
127
+ livekitConnected: (room: string) => void;
128
+ livekitDisconnected: () => void;
129
+ audioPlaybackStarted: (messageId: string) => void;
130
+ audioPlaybackComplete: (messageId: string) => void;
131
+ memoryUpdated: (event: MemoryUpdatedEvent) => void;
132
+ };
133
+ interface VoiceManager {
134
+ start(): Promise<void>;
135
+ stop(): Promise<void>;
136
+ toggleMute(): void;
137
+ /** Suppress audio sending (software AEC). No-op if not supported. */
138
+ setSuppressed?(suppressed: boolean): void;
139
+ readonly isMuted: boolean;
140
+ readonly isActive: boolean;
141
+ dispose(): void;
142
+ }
143
+ interface MemoryListOptions {
144
+ memoryType?: string;
145
+ status?: string;
146
+ limit?: number;
147
+ offset?: number;
148
+ sortBy?: 'created_at' | 'confidence' | 'last_accessed_at';
149
+ sortOrder?: 'asc' | 'desc';
150
+ }
151
+ interface MemoryTimelineOptions {
152
+ startDate?: string;
153
+ endDate?: string;
154
+ groupBy?: 'day' | 'week' | 'month';
155
+ }
156
+ interface MemoryGraphOptions {
157
+ includeEntities?: boolean;
158
+ includeCharacterMemories?: boolean;
159
+ }
160
+ interface MemorySearchOptions {
161
+ query: string;
162
+ limit?: number;
163
+ }
164
+ interface MemoryListResponse {
165
+ memories: Record<string, unknown>[];
166
+ total: number;
167
+ limit: number;
168
+ offset: number;
169
+ }
170
+ interface MemoryTimelineResponse {
171
+ timeline: {
172
+ date: string;
173
+ memories: Record<string, unknown>[];
174
+ }[];
175
+ totalMemories: number;
176
+ groupBy: string;
177
+ }
178
+ interface MemoryStatsResponse {
179
+ [key: string]: unknown;
180
+ }
181
+ interface MemoryGraphResponse {
182
+ nodes: Record<string, unknown>[];
183
+ edges: Record<string, unknown>[];
184
+ stats: Record<string, unknown>;
185
+ }
186
+ interface MemorySearchResponse {
187
+ results: {
188
+ memory: Record<string, unknown>;
189
+ score: number;
190
+ similarityScore: number;
191
+ }[];
192
+ query: string;
193
+ total: number;
194
+ }
195
+ interface CoreFactsResponse {
196
+ coreFacts: Record<string, unknown>[];
197
+ }
198
+
199
+ declare class RestClient {
200
+ private baseUrl;
201
+ private apiKey;
202
+ constructor(baseUrl: string, apiKey: string);
203
+ get<T>(path: string, params?: Record<string, string | number | boolean | undefined>): Promise<T>;
204
+ post<T>(path: string, body?: unknown): Promise<T>;
205
+ delete<T>(path: string, params?: Record<string, string | number | boolean | undefined>): Promise<T>;
206
+ dispose(): void;
207
+ private buildUrl;
208
+ private request;
209
+ }
210
+
211
+ declare class MemoryClient {
212
+ private rest;
213
+ private basePath;
214
+ constructor(rest: RestClient, agentId: string, playerId: string);
215
+ getMemories(options?: MemoryListOptions): Promise<MemoryListResponse>;
216
+ getTimeline(options?: MemoryTimelineOptions): Promise<MemoryTimelineResponse>;
217
+ getStats(): Promise<MemoryStatsResponse>;
218
+ getCoreFacts(): Promise<CoreFactsResponse>;
219
+ getGraph(options?: MemoryGraphOptions): Promise<MemoryGraphResponse>;
220
+ search(query: string, limit?: number): Promise<MemorySearchResponse>;
221
+ deleteAll(confirm: boolean): Promise<{
222
+ message: string;
223
+ deletedCount: number;
224
+ }>;
225
+ dispose(): void;
226
+ }
227
+
228
+ declare class TypedEventEmitter<T extends Record<string, unknown>> {
229
+ private listeners;
230
+ private onceListeners;
231
+ on<K extends keyof T>(event: K, listener: T[K]): this;
232
+ off<K extends keyof T>(event: K, listener: T[K]): this;
233
+ once<K extends keyof T>(event: K, listener: T[K]): this;
234
+ protected emit<K extends keyof T>(event: K, ...args: T[K] extends (...a: infer A) => void ? A : never[]): boolean;
235
+ removeAllListeners<K extends keyof T>(event?: K): this;
236
+ listenerCount<K extends keyof T>(event: K): number;
237
+ }
238
+
239
+ declare class EstuaryClient extends TypedEventEmitter<EstuaryEventMap> {
240
+ private config;
241
+ private logger;
242
+ private socketManager;
243
+ private voiceManager;
244
+ private audioPlayer;
245
+ private _memory;
246
+ private _sessionInfo;
247
+ private actionParsers;
248
+ private _hasAutoInterrupted;
249
+ private _autoInterruptGraceTimer;
250
+ constructor(config: EstuaryConfig);
251
+ /** Memory API client for querying memories, graphs, and facts */
252
+ get memory(): MemoryClient;
253
+ /** Current session info (null if not connected) */
254
+ get session(): SessionInfo | null;
255
+ /** Current connection state */
256
+ get connectionState(): ConnectionState;
257
+ /** Whether the client is connected and authenticated */
258
+ get isConnected(): boolean;
259
+ /** Connect to the Estuary server and authenticate */
260
+ connect(): Promise<SessionInfo>;
261
+ /** Disconnect from the server */
262
+ disconnect(): void;
263
+ /** Send a text message to the character */
264
+ sendText(text: string, textOnly?: boolean): void;
265
+ /** Interrupt the current bot response */
266
+ interrupt(messageId?: string): void;
267
+ /** Send a camera image for vision processing */
268
+ sendCameraImage(imageBase64: string, mimeType: string, requestId?: string, text?: string): void;
269
+ /** Update session preferences */
270
+ updatePreferences(preferences: {
271
+ enableVisionAcknowledgment?: boolean;
272
+ }): void;
273
+ /** Notify server that audio playback completed for a message */
274
+ notifyAudioPlaybackComplete(messageId?: string): void;
275
+ /** Start voice input (requests microphone permission) */
276
+ startVoice(): Promise<void>;
277
+ /** Stop voice input */
278
+ stopVoice(): void;
279
+ /** Toggle microphone mute */
280
+ toggleMute(): void;
281
+ /** Whether the microphone is muted */
282
+ get isMuted(): boolean;
283
+ /** Whether voice is currently active */
284
+ get isVoiceActive(): boolean;
285
+ private ensureConnected;
286
+ private forwardSocketEvents;
287
+ private handleBotResponse;
288
+ private handleBotVoice;
289
+ private maybeAutoInterrupt;
290
+ }
291
+
292
+ declare enum ErrorCode {
293
+ CONNECTION_FAILED = "CONNECTION_FAILED",
294
+ AUTH_FAILED = "AUTH_FAILED",
295
+ CONNECTION_TIMEOUT = "CONNECTION_TIMEOUT",
296
+ QUOTA_EXCEEDED = "QUOTA_EXCEEDED",
297
+ VOICE_NOT_SUPPORTED = "VOICE_NOT_SUPPORTED",
298
+ VOICE_ALREADY_ACTIVE = "VOICE_ALREADY_ACTIVE",
299
+ VOICE_NOT_ACTIVE = "VOICE_NOT_ACTIVE",
300
+ LIVEKIT_UNAVAILABLE = "LIVEKIT_UNAVAILABLE",
301
+ MICROPHONE_DENIED = "MICROPHONE_DENIED",
302
+ NOT_CONNECTED = "NOT_CONNECTED",
303
+ REST_ERROR = "REST_ERROR",
304
+ UNKNOWN = "UNKNOWN"
305
+ }
306
+ declare class EstuaryError extends Error {
307
+ readonly code: ErrorCode;
308
+ readonly details?: unknown;
309
+ constructor(code: ErrorCode, message: string, details?: unknown);
310
+ }
311
+
312
+ /**
313
+ * Parses `<action name="..." .../>` XML tags from bot response text.
314
+ *
315
+ * Designed for streaming: call `parse()` with the accumulated text on each
316
+ * chunk and it returns only newly-discovered actions since the last call.
317
+ */
318
+ interface ParsedAction {
319
+ name: string;
320
+ params: Record<string, string>;
321
+ }
322
+ /**
323
+ * One-shot parse: extract all actions and return clean text.
324
+ * Useful for non-streaming contexts.
325
+ */
326
+ declare function parseActions(text: string): {
327
+ actions: ParsedAction[];
328
+ cleanText: string;
329
+ };
330
+
331
+ export { type BotResponse, type BotVoice, type CameraCaptureRequest, type CharacterAction, 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 ParsedAction, type QuotaExceededData, type SessionInfo, type SttResponse, type VoiceManager, type VoiceTransport, parseActions };