@amigo-ai/platform-sdk 0.78.0 → 0.79.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/README.md CHANGED
@@ -446,6 +446,8 @@ const parent = await client.tokens.exchangeClientCredentials({
446
446
  ### Agents
447
447
 
448
448
  ```typescript
449
+ import type { VoiceSessionProvider } from '@amigo-ai/platform-sdk'
450
+
449
451
  // Create an agent
450
452
  const agent = await client.agents.create({
451
453
  name: 'Patient Intake Agent',
@@ -467,6 +469,10 @@ const version = await client.agents.createVersion(agent.id, {
467
469
  thought_visibility: 'private',
468
470
  },
469
471
  },
472
+ voice_config: {
473
+ voice_id: 'voice-abc123',
474
+ session_provider: 'inhouse' satisfies VoiceSessionProvider,
475
+ },
470
476
  })
471
477
 
472
478
  // Get the latest version
@@ -506,9 +512,18 @@ console.log(result.result, result.duration_ms)
506
512
  Services wire together an agent + context graph + phone channel.
507
513
 
508
514
  ```typescript
515
+ import type { VoiceSessionProvider } from '@amigo-ai/platform-sdk'
516
+
509
517
  const { items: services } = await client.services.list()
510
518
  const service = await client.services.get('service-id')
511
519
  console.log(service.agent_name, service.channel_type, service.version_sets)
520
+
521
+ await client.services.update(service.id, {
522
+ voice_config: {
523
+ ...(service.voice_config ?? {}),
524
+ session_provider: 'inhouse' satisfies VoiceSessionProvider,
525
+ },
526
+ })
512
527
  ```
513
528
 
514
529
  ### World Model
@@ -723,9 +738,16 @@ console.log(source.source_type, source.health_status, source.last_sync_at)
723
738
  ### Settings
724
739
 
725
740
  ```typescript
741
+ import type { SttProvider, TtsProvider } from '@amigo-ai/platform-sdk'
742
+
726
743
  // Voice
727
744
  const voice = await client.settings.voice.get()
728
- await client.settings.voice.update({ voice_id: 'new-voice-id', speed: 1.1 })
745
+ await client.settings.voice.update({
746
+ voice_id: 'new-voice-id',
747
+ speed: 1.1,
748
+ stt_provider: 'deepgram' satisfies SttProvider,
749
+ tts_provider: 'cartesia' satisfies TtsProvider,
750
+ })
729
751
 
730
752
  // Retention
731
753
  const retention = await client.settings.retention.get()
package/api.md CHANGED
@@ -53,6 +53,8 @@ Notes:
53
53
  - Pagination and response helpers: `paginate`, `buildLastResponse`, `extractRequestId`
54
54
  - Conversation helpers: `sessionConnectAuthProtocols`, `textStreamAuthProtocols`
55
55
  - Conversation types: `ConversationDetail`, `ConversationListResponse`, `ConversationSummary`, `ConversationTurn`, `ConversationTurnAvailableAction`, `ConversationTurnStateTransition`, `CreateConversationRequest`, `ListConversationsParams`, `SessionConnectUrlParams`, `TextStreamAuthProtocols` (WebSocket constructor subprotocol tuple), `TextStreamUrlParams`, `TurnDoneEvent`, `TurnErrorEvent`, `TurnMessageEvent`, `TurnRequest`, `TurnResponse`, `TurnConversationSnapshot`, `TurnStreamEvent`, `TurnThinkingEvent`, `TurnTokenEvent`, `TurnToolCallCompletedEvent`, `TurnToolCallStartedEvent`
56
+ - Voice provider constants: `STT_PROVIDERS`, `TTS_PROVIDERS`, `VOICE_SESSION_PROVIDERS`
57
+ - Voice provider types: `AgentVoiceConfig`, `ServiceVoiceConfigInput`, `ServiceVoiceConfigOutput`, `SttProvider`, `TtsProvider`, `VoiceSessionProvider`, `VoiceSettingsRequest`, `VoiceSettingsResponse`
56
58
  - Response and hook types: `PaginatedList`, `ListParams`, `LastResponseInfo`, `ResponseMetadata`, `WithResponseMetadata`, `AmigoResponse`, `RetryOptions`, `RateLimitInfo`, `ClientHooks`, `RequestHookContext`, `ResponseHookContext`, `ErrorHookContext`
57
59
  - Generated OpenAPI types: `paths`, `components`, `operations`
58
60
  - Generated API types are produced with `npm run gen-types` from the committed `openapi.json` snapshot.
@@ -6,11 +6,13 @@
6
6
  * lifecycle requirements:
7
7
  *
8
8
  * * Resume on transient drops with exponential backoff + full jitter
9
- * * Treat 4001 (client error) and 4403 (auth) close codes as terminal
10
- * * Treat 4029 (rate limit / cap) as terminal-but-retryable on a slow timer
9
+ * * Treat permanent-rejection close codes (1008 / 3003 / 4001 / 4003 /
10
+ * 4004 / 4100 / 4403) as terminal fail fast, do not loop
11
+ * * Treat 4029 / 1013 (rate limit / cap) as reconnectable on a slow floor,
12
+ * surfacing a ``rate_limited`` reconnect reason
11
13
  * * Watchdog the connection: if no message arrives within an idle window,
12
14
  * the upstream is dead even if the TCP socket has not closed; force a
13
- * reconnect
15
+ * reconnect (with a NON-terminal close code so the loop actually rebuilds)
14
16
  * * Surface every typed message through ``onMessage`` and every state
15
17
  * transition through ``onStateChange``
16
18
  *
@@ -43,16 +45,31 @@ export class ReconnectingWebSocketError extends Error {
43
45
  * Close codes that should NEVER be retried. The server is telling us the
44
46
  * connection cannot succeed regardless of how many times we try.
45
47
  *
46
- * 1008 (policy violation), 4001 (client error / bad params), 4003
47
- * (forbidden), 4100 (auth / not authenticated, used by some platform
48
+ * 1008 (policy violation), 3003 (workspace mismatch the call/session does
49
+ * not belong to the authenticated workspace; retrying replays the same
50
+ * mismatch), 4001 (client error / bad params), 4003 (forbidden), 4004 (call
51
+ * / session not found — the target no longer exists, every retry 404s the
52
+ * same way), 4100 (auth / not authenticated, used by some platform
48
53
  * endpoints), 4403 (forbidden — used by platform-api session-connect for
49
54
  * auth and origin rejection).
50
55
  */
51
- const TERMINAL_CLOSE_CODES = new Set([1008, 4001, 4003, 4100, 4403]);
56
+ const TERMINAL_CLOSE_CODES = new Set([1008, 3003, 4001, 4003, 4004, 4100, 4403]);
52
57
  /**
53
- * Close codes that are terminal-but-rate-limited. The reconnect loop honors
54
- * a longer floor (``RATE_LIMITED_FLOOR_MS``) before retrying so the client
55
- * does not amplify the problem it just hit.
58
+ * Dedicated NON-terminal close code the idle watchdog uses to force-close a
59
+ * stalled socket. It is deliberately OUTSIDE {@link TERMINAL_CLOSE_CODES}
60
+ * the watchdog's entire purpose is to FORCE a reconnect, so closing with a
61
+ * terminal code (the original bug) made the loop give up instead. Picked in
62
+ * the application-private 4000–4999 range, clear of the platform's assigned
63
+ * 40xx codes.
64
+ */
65
+ const WATCHDOG_CLOSE_CODE = 4099;
66
+ /**
67
+ * Close codes that are reconnectable-but-rate-limited. The reconnect loop
68
+ * still retries these (they are NOT terminal) but honors a longer floor
69
+ * (``RATE_LIMITED_FLOOR_MS``) before doing so, and surfaces a ``rate_limited``
70
+ * reason on ``onReconnect`` so consumers can message "too many connections —
71
+ * retrying…" instead of a generic banner. If the retries exhaust the budget,
72
+ * the terminal ``onError`` carries the originating 4029 / 1013 close code.
56
73
  *
57
74
  * 4029 (custom platform code for "too many connections / burst exceeded").
58
75
  * 1013 (try again later, RFC 6455 standard hint).
@@ -74,9 +91,16 @@ const DEFAULT_IDLE_TIMEOUT_MS = 45_000;
74
91
  * ```ts
75
92
  * const handle = createReconnectingWebSocket({
76
93
  * url: client.conversations.sessionConnectUrl({ serviceId, entityId }),
77
- * protocols: sessionConnectAuthProtocols(apiKey),
94
+ * // Re-mint the auth subprotocols on EACH (re)connect so a token that
95
+ * // expires mid-stream is refreshed before the retry — falls back to the
96
+ * // static `protocols` option when omitted.
97
+ * getProtocols: async () => sessionConnectAuthProtocols(await freshToken()),
78
98
  * onMessage: (e) => console.log('frame', e.data),
79
99
  * onStateChange: (s) => console.log('state', s),
100
+ * onReconnect: ({ reason, delayMs }) => {
101
+ * if (reason === 'rate_limited') showBanner('Too many connections — retrying…');
102
+ * else if (reason === 'idle_watchdog') showBanner('Connection went quiet — reconnecting…');
103
+ * },
80
104
  * onError: (err) => console.error('terminal:', err.reason, err.closeCode),
81
105
  * });
82
106
  *
@@ -165,16 +189,39 @@ export function createReconnectingWebSocket(options) {
165
189
  });
166
190
  return handle;
167
191
  }
192
+ /**
193
+ * Internal sentinel marking a pre-connect failure that the reconnect loop
194
+ * should RETRY (not treat as terminal). Currently only a {@link
195
+ * ReconnectingWebSocketOptions.getProtocols} rejection — a transient
196
+ * token-refresh hiccup — qualifies. Synchronous factory throws (bad URL, no
197
+ * global WebSocket) are NOT wrapped and remain terminal ``open_failed``.
198
+ */
199
+ class RetryableOpenError extends Error {
200
+ constructor(message, cause) {
201
+ super(message, { cause });
202
+ this.name = 'RetryableOpenError';
203
+ }
204
+ }
168
205
  async function runLoop(args) {
169
206
  const { options, signal, setState, reportError, setSocket } = args;
170
207
  let attempt = 0;
171
208
  let delayMs = args.initialDelayMs;
209
+ // Carried from the close that ENDED the previous connection so the
210
+ // ``onReconnect`` callback can report the originating close code and a
211
+ // coarse reason ("idle_watchdog" / "rate_limited" / "transient"). Seeded
212
+ // for the very first connection (attempt 0), where neither applies.
213
+ let pendingReconnect = { closeCode: undefined, reason: 'transient' };
172
214
  while (!signal.aborted) {
173
215
  if (attempt > 0) {
174
216
  setState('reconnecting');
175
217
  const sleepMs = jitter(delayMs);
176
218
  try {
177
- options.onReconnect?.({ attempt, delayMs: sleepMs, closeCode: undefined });
219
+ options.onReconnect?.({
220
+ attempt,
221
+ delayMs: sleepMs,
222
+ closeCode: pendingReconnect.closeCode,
223
+ reason: pendingReconnect.reason,
224
+ });
178
225
  }
179
226
  catch {
180
227
  // ignore
@@ -184,27 +231,51 @@ async function runLoop(args) {
184
231
  break;
185
232
  delayMs = Math.min(delayMs * 2, args.maxDelayMs);
186
233
  }
187
- setState(attempt === 0 ? 'connecting' : 'connecting');
234
+ setState('connecting');
188
235
  let outcome;
189
236
  try {
190
237
  outcome = await runOneConnection(args);
191
238
  }
192
239
  catch (err) {
193
- // Synchronous open failure (e.g., factory threw, invalid URL).
240
+ // A getProtocols() rejection is a TRANSIENT pre-connect failure (e.g. a
241
+ // token-refresh hiccup): retry it up to the reconnect budget rather
242
+ // than killing a long-lived stream over one bad refresh. A synchronous
243
+ // factory throw (invalid URL, no global WebSocket) is genuinely
244
+ // terminal — there is nothing to retry — so it fails fast as before.
245
+ if (err instanceof RetryableOpenError && attempt < args.maxReconnects) {
246
+ pendingReconnect = { closeCode: undefined, reason: 'transient' };
247
+ attempt += 1;
248
+ continue;
249
+ }
194
250
  reportError(new ReconnectingWebSocketError(err instanceof Error ? err.message : 'Failed to open WebSocket', 'open_failed', undefined, undefined, attempt));
195
251
  return;
196
252
  }
197
253
  finally {
198
254
  setSocket(null);
199
255
  }
200
- // Terminal close codes are reported BEFORE the abort check because the
201
- // close arrived from the wire the consumer's subsequent ``close()``
202
- // call (which flips signal.aborted true) must not suppress the diagnostic.
203
- if (outcome.closeCode !== undefined && TERMINAL_CLOSE_CODES.has(outcome.closeCode)) {
204
- reportError(new ReconnectingWebSocketError(`Server closed with terminal code ${outcome.closeCode}: ${outcome.closeReason ?? ''}`, outcome.closeCode === 4403 ? 'auth' : 'client_error', outcome.closeCode, outcome.closeReason, attempt));
205
- return;
256
+ // The idle watchdog forces a close purely to PROVOKE a reconnect — its
257
+ // synthetic close code must never be mistaken for a server-sent terminal
258
+ // rejection. Check ``watchdogTriggered`` first so that even if the
259
+ // watchdog code ever overlapped the terminal set, the loop still
260
+ // reconnects (defense-in-depth; the dedicated WATCHDOG_CLOSE_CODE 4099 is
261
+ // already outside TERMINAL_CLOSE_CODES).
262
+ if (!outcome.watchdogTriggered) {
263
+ // Terminal close codes are reported BEFORE the abort check because the
264
+ // close arrived from the wire — the consumer's subsequent ``close()``
265
+ // call (which flips signal.aborted true) must not suppress the
266
+ // diagnostic.
267
+ if (outcome.closeCode !== undefined && TERMINAL_CLOSE_CODES.has(outcome.closeCode)) {
268
+ reportError(new ReconnectingWebSocketError(`Server closed with terminal code ${outcome.closeCode}: ${outcome.closeReason ?? ''}`, terminalReasonForCode(outcome.closeCode), outcome.closeCode, outcome.closeReason, attempt));
269
+ return;
270
+ }
271
+ if (outcome.aborted || signal.aborted) {
272
+ setState('closed');
273
+ return;
274
+ }
206
275
  }
207
- if (outcome.aborted || signal.aborted) {
276
+ else if (signal.aborted) {
277
+ // Watchdog fired but the consumer also aborted in the same tick — honor
278
+ // the abort and stop, do not reconnect into a torn-down stream.
208
279
  setState('closed');
209
280
  return;
210
281
  }
@@ -212,21 +283,57 @@ async function runLoop(args) {
212
283
  reportError(new ReconnectingWebSocketError(`Reconnect budget exhausted (${args.maxReconnects} attempts)`, 'reconnect_budget_exhausted', outcome.closeCode, outcome.closeReason, attempt));
213
284
  return;
214
285
  }
215
- if (outcome.closeCode !== undefined && RATE_LIMITED_CLOSE_CODES.has(outcome.closeCode)) {
286
+ const isRateLimited = outcome.closeCode !== undefined && RATE_LIMITED_CLOSE_CODES.has(outcome.closeCode);
287
+ if (isRateLimited) {
216
288
  // Pin the floor up so we do not hammer the server we just got
217
289
  // throttled by. Honor whichever is larger between the current
218
290
  // exponential delay and the rate-limited floor.
219
291
  delayMs = Math.max(delayMs, RATE_LIMITED_FLOOR_MS);
220
292
  }
293
+ pendingReconnect = {
294
+ closeCode: outcome.closeCode,
295
+ reason: outcome.watchdogTriggered
296
+ ? 'idle_watchdog'
297
+ : isRateLimited
298
+ ? 'rate_limited'
299
+ : 'transient',
300
+ };
221
301
  attempt += 1;
222
302
  }
223
303
  setState('closed');
224
304
  }
305
+ /**
306
+ * Map a terminal close code to the {@link ReconnectingWebSocketErrorReason}
307
+ * surfaced on ``onError``. 4403 / 4100 are auth rejections; everything else
308
+ * in the terminal set is a client-side / target-not-found error.
309
+ */
310
+ function terminalReasonForCode(code) {
311
+ if (code === 4403 || code === 4100)
312
+ return 'auth';
313
+ return 'client_error';
314
+ }
225
315
  async function runOneConnection(args) {
226
316
  const { options, factory, signal, setState, setSocket, idleTimeoutMs } = args;
317
+ // Resolve subprotocols freshly per (re)connect when a provider is given so
318
+ // an expired bearer token is replaced before each attempt; otherwise reuse
319
+ // the static value frozen at subscribe time (backward compatible). A
320
+ // provider rejection is wrapped as a RetryableOpenError so the loop treats
321
+ // a transient token-refresh hiccup as reconnectable rather than terminal.
322
+ let protocols;
323
+ if (options.getProtocols) {
324
+ try {
325
+ protocols = await options.getProtocols();
326
+ }
327
+ catch (err) {
328
+ throw new RetryableOpenError(err instanceof Error ? err.message : 'getProtocols failed', err);
329
+ }
330
+ }
331
+ else {
332
+ protocols = options.protocols;
333
+ }
227
334
  let socket;
228
335
  try {
229
- socket = factory(options.url, options.protocols);
336
+ socket = factory(options.url, protocols);
230
337
  }
231
338
  catch (err) {
232
339
  throw err instanceof Error ? err : new Error(String(err));
@@ -248,18 +355,24 @@ async function runOneConnection(args) {
248
355
  watchdogTimer = setTimeout(() => {
249
356
  if (resolved)
250
357
  return;
251
- try {
252
- socket.close(4001, 'idle timeout');
253
- }
254
- catch {
255
- // already closed
256
- }
358
+ // Finalize FIRST (flips ``resolved`` and detaches the ``close``
359
+ // listener) so that a runtime which dispatches the ``close`` event
360
+ // synchronously from ``socket.close()`` cannot re-enter ``onClose``
361
+ // and overwrite the outcome with ``watchdogTriggered: false``. The
362
+ // outcome must record the watchdog as the cause so the loop reconnects
363
+ // with the ``idle_watchdog`` reason rather than misclassifying it.
257
364
  finalize({
258
- closeCode: 4001,
365
+ closeCode: WATCHDOG_CLOSE_CODE,
259
366
  closeReason: 'idle timeout',
260
367
  watchdogTriggered: true,
261
368
  aborted: false,
262
369
  });
370
+ try {
371
+ socket.close(WATCHDOG_CLOSE_CODE, 'idle timeout');
372
+ }
373
+ catch {
374
+ // already closed
375
+ }
263
376
  }, idleTimeoutMs);
264
377
  }
265
378
  function finalize(outcome) {
@@ -1 +1 @@
1
- {"version":3,"file":"reconnecting-websocket.js","sourceRoot":"","sources":["../../src/core/reconnecting-websocket.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAuBH,uDAAuD;AACvD,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IAC1C,MAAM,CAAkC;IACxC,SAAS,CAAoB;IAC7B,WAAW,CAAoB;IAC/B,QAAQ,CAAQ;IAEzB,YACE,OAAe,EACf,MAAwC,EACxC,SAA6B,EAC7B,WAA+B,EAC/B,QAAgB;QAEhB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAA;QACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,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CAAA;YAC5C,OAAO,CAAC,KAAK,CAAC,CAAA;QAChB,CAAC,CAAA;QACD,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;IAC3D,CAAC,CAAC,CAAA;AACJ,CAAC"}
package/dist/index.cjs CHANGED
@@ -55,11 +55,14 @@ __export(index_exports, {
55
55
  ReconnectingWebSocketError: () => ReconnectingWebSocketError,
56
56
  RefreshTokenExpiredError: () => RefreshTokenExpiredError,
57
57
  RequestTimeoutError: () => RequestTimeoutError,
58
+ STT_PROVIDERS: () => STT_PROVIDERS,
58
59
  ServerError: () => ServerError,
59
60
  ServiceUnavailableError: () => ServiceUnavailableError,
60
61
  SesSetupResource: () => SesSetupResource,
62
+ TTS_PROVIDERS: () => TTS_PROVIDERS,
61
63
  TokenManager: () => TokenManager,
62
64
  TokensResource: () => TokensResource,
65
+ VOICE_SESSION_PROVIDERS: () => VOICE_SESSION_PROVIDERS,
63
66
  ValidationError: () => ValidationError,
64
67
  WebhookVerificationError: () => WebhookVerificationError,
65
68
  WorkspaceEventStreamError: () => WorkspaceEventStreamError,
@@ -4257,7 +4260,8 @@ var ReconnectingWebSocketError = class extends Error {
4257
4260
  this.attempts = attempts;
4258
4261
  }
4259
4262
  };
4260
- var TERMINAL_CLOSE_CODES = /* @__PURE__ */ new Set([1008, 4001, 4003, 4100, 4403]);
4263
+ var TERMINAL_CLOSE_CODES = /* @__PURE__ */ new Set([1008, 3003, 4001, 4003, 4004, 4100, 4403]);
4264
+ var WATCHDOG_CLOSE_CODE = 4099;
4261
4265
  var RATE_LIMITED_CLOSE_CODES = /* @__PURE__ */ new Set([1013, 4029]);
4262
4266
  var RATE_LIMITED_FLOOR_MS = 5e3;
4263
4267
  var DEFAULT_INITIAL_DELAY_MS2 = 1e3;
@@ -4336,27 +4340,44 @@ function createReconnectingWebSocket(options) {
4336
4340
  });
4337
4341
  return handle;
4338
4342
  }
4343
+ var RetryableOpenError = class extends Error {
4344
+ constructor(message, cause) {
4345
+ super(message, { cause });
4346
+ this.name = "RetryableOpenError";
4347
+ }
4348
+ };
4339
4349
  async function runLoop(args) {
4340
4350
  const { options, signal, setState, reportError, setSocket } = args;
4341
4351
  let attempt = 0;
4342
4352
  let delayMs = args.initialDelayMs;
4353
+ let pendingReconnect = { closeCode: void 0, reason: "transient" };
4343
4354
  while (!signal.aborted) {
4344
4355
  if (attempt > 0) {
4345
4356
  setState("reconnecting");
4346
4357
  const sleepMs = jitter2(delayMs);
4347
4358
  try {
4348
- options.onReconnect?.({ attempt, delayMs: sleepMs, closeCode: void 0 });
4359
+ options.onReconnect?.({
4360
+ attempt,
4361
+ delayMs: sleepMs,
4362
+ closeCode: pendingReconnect.closeCode,
4363
+ reason: pendingReconnect.reason
4364
+ });
4349
4365
  } catch {
4350
4366
  }
4351
4367
  const slept = await abortableSleep2(sleepMs, signal);
4352
4368
  if (!slept) break;
4353
4369
  delayMs = Math.min(delayMs * 2, args.maxDelayMs);
4354
4370
  }
4355
- setState(attempt === 0 ? "connecting" : "connecting");
4371
+ setState("connecting");
4356
4372
  let outcome;
4357
4373
  try {
4358
4374
  outcome = await runOneConnection2(args);
4359
4375
  } catch (err) {
4376
+ if (err instanceof RetryableOpenError && attempt < args.maxReconnects) {
4377
+ pendingReconnect = { closeCode: void 0, reason: "transient" };
4378
+ attempt += 1;
4379
+ continue;
4380
+ }
4360
4381
  reportError(
4361
4382
  new ReconnectingWebSocketError(
4362
4383
  err instanceof Error ? err.message : "Failed to open WebSocket",
@@ -4370,19 +4391,24 @@ async function runLoop(args) {
4370
4391
  } finally {
4371
4392
  setSocket(null);
4372
4393
  }
4373
- if (outcome.closeCode !== void 0 && TERMINAL_CLOSE_CODES.has(outcome.closeCode)) {
4374
- reportError(
4375
- new ReconnectingWebSocketError(
4376
- `Server closed with terminal code ${outcome.closeCode}: ${outcome.closeReason ?? ""}`,
4377
- outcome.closeCode === 4403 ? "auth" : "client_error",
4378
- outcome.closeCode,
4379
- outcome.closeReason,
4380
- attempt
4381
- )
4382
- );
4383
- return;
4384
- }
4385
- if (outcome.aborted || signal.aborted) {
4394
+ if (!outcome.watchdogTriggered) {
4395
+ if (outcome.closeCode !== void 0 && TERMINAL_CLOSE_CODES.has(outcome.closeCode)) {
4396
+ reportError(
4397
+ new ReconnectingWebSocketError(
4398
+ `Server closed with terminal code ${outcome.closeCode}: ${outcome.closeReason ?? ""}`,
4399
+ terminalReasonForCode(outcome.closeCode),
4400
+ outcome.closeCode,
4401
+ outcome.closeReason,
4402
+ attempt
4403
+ )
4404
+ );
4405
+ return;
4406
+ }
4407
+ if (outcome.aborted || signal.aborted) {
4408
+ setState("closed");
4409
+ return;
4410
+ }
4411
+ } else if (signal.aborted) {
4386
4412
  setState("closed");
4387
4413
  return;
4388
4414
  }
@@ -4398,18 +4424,37 @@ async function runLoop(args) {
4398
4424
  );
4399
4425
  return;
4400
4426
  }
4401
- if (outcome.closeCode !== void 0 && RATE_LIMITED_CLOSE_CODES.has(outcome.closeCode)) {
4427
+ const isRateLimited = outcome.closeCode !== void 0 && RATE_LIMITED_CLOSE_CODES.has(outcome.closeCode);
4428
+ if (isRateLimited) {
4402
4429
  delayMs = Math.max(delayMs, RATE_LIMITED_FLOOR_MS);
4403
4430
  }
4431
+ pendingReconnect = {
4432
+ closeCode: outcome.closeCode,
4433
+ reason: outcome.watchdogTriggered ? "idle_watchdog" : isRateLimited ? "rate_limited" : "transient"
4434
+ };
4404
4435
  attempt += 1;
4405
4436
  }
4406
4437
  setState("closed");
4407
4438
  }
4439
+ function terminalReasonForCode(code) {
4440
+ if (code === 4403 || code === 4100) return "auth";
4441
+ return "client_error";
4442
+ }
4408
4443
  async function runOneConnection2(args) {
4409
4444
  const { options, factory, signal, setState, setSocket, idleTimeoutMs } = args;
4445
+ let protocols;
4446
+ if (options.getProtocols) {
4447
+ try {
4448
+ protocols = await options.getProtocols();
4449
+ } catch (err) {
4450
+ throw new RetryableOpenError(err instanceof Error ? err.message : "getProtocols failed", err);
4451
+ }
4452
+ } else {
4453
+ protocols = options.protocols;
4454
+ }
4410
4455
  let socket;
4411
4456
  try {
4412
- socket = factory(options.url, options.protocols);
4457
+ socket = factory(options.url, protocols);
4413
4458
  } catch (err) {
4414
4459
  throw err instanceof Error ? err : new Error(String(err));
4415
4460
  }
@@ -4428,16 +4473,16 @@ async function runOneConnection2(args) {
4428
4473
  clearWatchdog();
4429
4474
  watchdogTimer = setTimeout(() => {
4430
4475
  if (resolved) return;
4431
- try {
4432
- socket.close(4001, "idle timeout");
4433
- } catch {
4434
- }
4435
4476
  finalize({
4436
- closeCode: 4001,
4477
+ closeCode: WATCHDOG_CLOSE_CODE,
4437
4478
  closeReason: "idle timeout",
4438
4479
  watchdogTriggered: true,
4439
4480
  aborted: false
4440
4481
  });
4482
+ try {
4483
+ socket.close(WATCHDOG_CLOSE_CODE, "idle timeout");
4484
+ } catch {
4485
+ }
4441
4486
  }, idleTimeoutMs);
4442
4487
  }
4443
4488
  function finalize(outcome) {
@@ -5635,6 +5680,18 @@ function toCryptoBuffer(bytes) {
5635
5680
  return copy.buffer;
5636
5681
  }
5637
5682
 
5683
+ // src/resources/voice.ts
5684
+ var voiceSessionProviders = [
5685
+ "inhouse",
5686
+ "openai_realtime",
5687
+ "atlas"
5688
+ ];
5689
+ var VOICE_SESSION_PROVIDERS = voiceSessionProviders;
5690
+ var sttProviders = ["deepgram", "openai", "cartesia"];
5691
+ var STT_PROVIDERS = sttProviders;
5692
+ var ttsProviders = ["cartesia", "elevenlabs", "groq"];
5693
+ var TTS_PROVIDERS = ttsProviders;
5694
+
5638
5695
  // src/core/device-code.ts
5639
5696
  var DeviceCodeExpiredError = class extends AmigoError {
5640
5697
  constructor(message = "Device code expired. Please restart the login flow.") {