phonic 0.31.9 → 0.31.11

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.
Files changed (48) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/BaseClient.js +2 -2
  3. package/dist/cjs/Client.d.ts +9 -1
  4. package/dist/cjs/Client.js +1 -1
  5. package/dist/cjs/api/resources/conversations/client/Client.d.ts +8 -1
  6. package/dist/cjs/api/resources/conversations/client/Client.js +37 -3
  7. package/dist/cjs/api/resources/conversations/client/Socket.d.ts +2 -1
  8. package/dist/cjs/api/resources/conversations/client/Socket.js +4 -0
  9. package/dist/cjs/api/types/ConfigOptions.d.ts +94 -0
  10. package/dist/cjs/api/types/ConfigOptions.js +32 -0
  11. package/dist/cjs/api/types/ConfigPayload.d.ts +2 -90
  12. package/dist/cjs/api/types/ConfigPayload.js +0 -29
  13. package/dist/cjs/api/types/ResetPayload.d.ts +5 -0
  14. package/dist/cjs/api/types/ResetPayload.js +3 -0
  15. package/dist/cjs/api/types/index.d.ts +2 -0
  16. package/dist/cjs/api/types/index.js +2 -0
  17. package/dist/cjs/custom/ReconnectableConversationsSocket.d.ts +74 -0
  18. package/dist/cjs/custom/ReconnectableConversationsSocket.js +283 -0
  19. package/dist/cjs/custom/index.d.ts +1 -0
  20. package/dist/cjs/custom/index.js +5 -0
  21. package/dist/cjs/index.d.ts +1 -0
  22. package/dist/cjs/index.js +3 -1
  23. package/dist/cjs/version.d.ts +1 -1
  24. package/dist/cjs/version.js +1 -1
  25. package/dist/esm/BaseClient.mjs +2 -2
  26. package/dist/esm/Client.d.mts +9 -1
  27. package/dist/esm/Client.mjs +1 -1
  28. package/dist/esm/api/resources/conversations/client/Client.d.mts +8 -1
  29. package/dist/esm/api/resources/conversations/client/Client.mjs +37 -3
  30. package/dist/esm/api/resources/conversations/client/Socket.d.mts +2 -1
  31. package/dist/esm/api/resources/conversations/client/Socket.mjs +4 -0
  32. package/dist/esm/api/types/ConfigOptions.d.mts +94 -0
  33. package/dist/esm/api/types/ConfigOptions.mjs +29 -0
  34. package/dist/esm/api/types/ConfigPayload.d.mts +2 -90
  35. package/dist/esm/api/types/ConfigPayload.mjs +1 -28
  36. package/dist/esm/api/types/ResetPayload.d.mts +5 -0
  37. package/dist/esm/api/types/ResetPayload.mjs +2 -0
  38. package/dist/esm/api/types/index.d.mts +2 -0
  39. package/dist/esm/api/types/index.mjs +2 -0
  40. package/dist/esm/custom/ReconnectableConversationsSocket.d.mts +74 -0
  41. package/dist/esm/custom/ReconnectableConversationsSocket.mjs +246 -0
  42. package/dist/esm/custom/index.d.mts +1 -0
  43. package/dist/esm/custom/index.mjs +1 -0
  44. package/dist/esm/index.d.mts +1 -0
  45. package/dist/esm/index.mjs +1 -0
  46. package/dist/esm/version.d.mts +1 -1
  47. package/dist/esm/version.mjs +1 -1
  48. package/package.json +2 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Phonic.
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.
@@ -43,8 +43,8 @@ function normalizeClientOptions(options) {
43
43
  const headers = (0, headers_js_1.mergeHeaders)({
44
44
  "X-Fern-Language": "JavaScript",
45
45
  "X-Fern-SDK-Name": "phonic",
46
- "X-Fern-SDK-Version": "0.31.9",
47
- "User-Agent": "phonic/0.31.9",
46
+ "X-Fern-SDK-Version": "0.31.11",
47
+ "User-Agent": "phonic/0.31.11",
48
48
  "X-Fern-Runtime": core.RUNTIME.type,
49
49
  "X-Fern-Runtime-Version": core.RUNTIME.version,
50
50
  }, options === null || options === void 0 ? void 0 : options.headers);
@@ -9,7 +9,15 @@ import type { BaseClientOptions, BaseRequestOptions } from "./BaseClient.js";
9
9
  import { type NormalizedClientOptionsWithAuth } from "./BaseClient.js";
10
10
  import * as core from "./core/index.js";
11
11
  export declare namespace PhonicClient {
12
- type Options = BaseClientOptions;
12
+ type Options = BaseClientOptions & {
13
+ /**
14
+ * When `true`, conversation WebSockets automatically reconnect after an
15
+ * abnormal disconnect (WebSocket close code 1006) using `reconnect_conv_id`.
16
+ * Defaults to `false` until the behavior is broadly validated in production;
17
+ * set to `true` to opt in early.
18
+ */
19
+ reconnectConversationOnAbnormalDisconnect?: boolean;
20
+ };
13
21
  interface RequestOptions extends BaseRequestOptions {
14
22
  }
15
23
  }
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // This file was auto-generated by Fern from our API Definition.
2
+ // Maintained manually (listed in .fernignore). Fern does not overwrite this file.
3
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
4
  if (k2 === undefined) k2 = k;
5
5
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -4,7 +4,14 @@ import * as core from "../../../../core/index.js";
4
4
  import * as Phonic from "../../../index.js";
5
5
  import { ConversationsSocket } from "./Socket.js";
6
6
  export declare namespace ConversationsClient {
7
- type Options = BaseClientOptions;
7
+ type Options = BaseClientOptions & {
8
+ /**
9
+ * When `true`, `connect()` uses session-aware reconnection on abnormal
10
+ * disconnect (1006). Set via `PhonicClient` options as
11
+ * `reconnectConversationOnAbnormalDisconnect`.
12
+ */
13
+ reconnectConversationOnAbnormalDisconnect?: boolean;
14
+ };
8
15
  interface RequestOptions extends BaseRequestOptions {
9
16
  }
10
17
  interface ConnectArgs {
@@ -62,6 +62,7 @@ const environments = __importStar(require("../../../../environments.js"));
62
62
  const handleNonStatusCodeError_js_1 = require("../../../../errors/handleNonStatusCodeError.js");
63
63
  const errors = __importStar(require("../../../../errors/index.js"));
64
64
  const Phonic = __importStar(require("../../../index.js"));
65
+ const ReconnectableConversationsSocket_js_1 = require("../../../../custom/ReconnectableConversationsSocket.js");
65
66
  const Socket_js_1 = require("./Socket.js");
66
67
  class ConversationsClient {
67
68
  constructor(options = {}) {
@@ -750,11 +751,44 @@ class ConversationsClient {
750
751
  const _queryParams = {
751
752
  downstream_websocket_url: downstreamWebsocketUrl,
752
753
  };
754
+ const baseWsUrl = core.url.join((_a = (yield core.Supplier.get(this._options.baseUrl))) !== null && _a !== void 0 ? _a : ((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.PhonicEnvironment.Default)
755
+ .production, "/v1/sts/ws");
756
+ if (this._options.reconnectConversationOnAbnormalDisconnect) {
757
+ const connectionTimeoutMs = connectionTimeoutInSeconds != null ? connectionTimeoutInSeconds * 1000 : undefined;
758
+ const createSocket = (reconnectConvId) => __awaiter(this, void 0, void 0, function* () {
759
+ var _a, _b, _c;
760
+ const freshAuth = yield this._options.authProvider.getAuthRequest();
761
+ const mergedHeaders = Object.assign(Object.assign(Object.assign({}, ((_a = freshAuth.headers) !== null && _a !== void 0 ? _a : {})), ((_c = (_b = this._options) === null || _b === void 0 ? void 0 : _b.headers) !== null && _c !== void 0 ? _c : {})), headers);
762
+ const isSessionReconnect = reconnectConvId != null;
763
+ return new core.ReconnectingWebSocket({
764
+ url: baseWsUrl,
765
+ protocols: protocols !== null && protocols !== void 0 ? protocols : [],
766
+ queryParameters: Object.assign(Object.assign(Object.assign({}, _queryParams), queryParams), (reconnectConvId ? { reconnect_conv_id: reconnectConvId } : {})),
767
+ headers: mergedHeaders,
768
+ options: {
769
+ debug: debug !== null && debug !== void 0 ? debug : false,
770
+ // Initial connection keeps transport retries; replacement sockets use 0 so only
771
+ // ReconnectableConversationsSocket performs session-level reconnect.
772
+ maxRetries: isSessionReconnect ? 0 : reconnectAttempts !== null && reconnectAttempts !== void 0 ? reconnectAttempts : 30,
773
+ connectionTimeout: connectionTimeoutMs,
774
+ },
775
+ // Only pass abortSignal to the initial socket. Reconnect sockets
776
+ // don't get it — each would register a new listener on the signal
777
+ // that's never removed, leaking memory over many reconnects.
778
+ abortSignal: isSessionReconnect ? undefined : abortSignal,
779
+ });
780
+ });
781
+ const initialSocket = yield createSocket();
782
+ return new ReconnectableConversationsSocket_js_1.ReconnectableConversationsSocket({
783
+ socket: initialSocket,
784
+ createReconnectSocket: (conversationId) => createSocket(conversationId),
785
+ abortSignal,
786
+ });
787
+ }
753
788
  const _authRequest = yield this._options.authProvider.getAuthRequest();
754
- const _headers = Object.assign(Object.assign(Object.assign({}, ((_a = _authRequest.headers) !== null && _a !== void 0 ? _a : {})), ((_c = (_b = this._options) === null || _b === void 0 ? void 0 : _b.headers) !== null && _c !== void 0 ? _c : {})), headers);
789
+ const _headers = Object.assign(Object.assign(Object.assign({}, ((_c = _authRequest.headers) !== null && _c !== void 0 ? _c : {})), ((_e = (_d = this._options) === null || _d === void 0 ? void 0 : _d.headers) !== null && _e !== void 0 ? _e : {})), headers);
755
790
  const socket = new core.ReconnectingWebSocket({
756
- url: core.url.join((_d = (yield core.Supplier.get(this._options.baseUrl))) !== null && _d !== void 0 ? _d : ((_e = (yield core.Supplier.get(this._options.environment))) !== null && _e !== void 0 ? _e : environments.PhonicEnvironment.Default)
757
- .production, "/v1/sts/ws"),
791
+ url: baseWsUrl,
758
792
  protocols: protocols !== null && protocols !== void 0 ? protocols : [],
759
793
  queryParameters: Object.assign(Object.assign({}, _queryParams), queryParams),
760
794
  headers: _headers,
@@ -41,6 +41,7 @@ export declare class ConversationsSocket {
41
41
  sendToolCallOutput(message: Phonic.ToolCallOutputPayload): void;
42
42
  sendGenerateReply(message: Phonic.GenerateReplyPayload): void;
43
43
  sendSay(message: Phonic.SayPayload): void;
44
+ sendReset(message: Phonic.ResetPayload): void;
44
45
  /** Connect to the websocket and register event handlers. */
45
46
  connect(): ConversationsSocket;
46
47
  /** Close the websocket and unregister event handlers. */
@@ -52,5 +53,5 @@ export declare class ConversationsSocket {
52
53
  /** Send a binary payload to the websocket. */
53
54
  protected sendBinary(payload: ArrayBuffer | Blob | ArrayBufferView): void;
54
55
  /** Send a JSON payload to the websocket. */
55
- protected sendJson(payload: Phonic.ConfigPayload | Phonic.AudioChunkPayload | Phonic.UpdateSystemPromptPayload | Phonic.AddSystemMessagePayload | Phonic.SetExternalIdPayload | Phonic.ToolCallOutputPayload | Phonic.GenerateReplyPayload | Phonic.SayPayload): void;
56
+ protected sendJson(payload: Phonic.ConfigPayload | Phonic.AudioChunkPayload | Phonic.UpdateSystemPromptPayload | Phonic.AddSystemMessagePayload | Phonic.SetExternalIdPayload | Phonic.ToolCallOutputPayload | Phonic.GenerateReplyPayload | Phonic.SayPayload | Phonic.ResetPayload): void;
56
57
  }
@@ -122,6 +122,10 @@ class ConversationsSocket {
122
122
  this.assertSocketIsOpen();
123
123
  this.sendJson(message);
124
124
  }
125
+ sendReset(message) {
126
+ this.assertSocketIsOpen();
127
+ this.sendJson(message);
128
+ }
125
129
  /** Connect to the websocket and register event handlers. */
126
130
  connect() {
127
131
  this.socket.reconnect();
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Configuration fields for the initial `config` message.
3
+ */
4
+ export interface ConfigOptions {
5
+ /** Agent name to use for conversation */
6
+ agent?: string | undefined;
7
+ /** Project name */
8
+ project?: string | undefined;
9
+ /** STS model to use */
10
+ model?: "merritt" | undefined;
11
+ /** System prompt for AI assistant */
12
+ system_prompt?: string | undefined;
13
+ /** Audio playback speed */
14
+ audio_speed?: number | undefined;
15
+ /** Background noise level for the conversation */
16
+ background_noise_level?: number | undefined;
17
+ /** Background noise type for the conversation */
18
+ background_noise?: (ConfigOptions.BackgroundNoise | null) | undefined;
19
+ /** When `true`, the welcome message will be automatically generated and the `welcome_message` field will be ignored. */
20
+ generate_welcome_message?: boolean | undefined;
21
+ /** Message to play when conversation starts. Ignored when `generate_welcome_message` is `true`. */
22
+ welcome_message?: (string | null) | undefined;
23
+ /** Voice ID to use for speech synthesis */
24
+ voice_id?: string | undefined;
25
+ /** Audio input format */
26
+ input_format?: ConfigOptions.InputFormat | undefined;
27
+ /** Audio output format */
28
+ output_format?: ConfigOptions.OutputFormat | undefined;
29
+ /** Voice activity detection prebuffer duration */
30
+ vad_prebuffer_duration_ms?: number | undefined;
31
+ /** Minimum speech duration for VAD */
32
+ vad_min_speech_duration_ms?: number | undefined;
33
+ /** Minimum silence duration for VAD */
34
+ vad_min_silence_duration_ms?: number | undefined;
35
+ /** Voice activity detection threshold */
36
+ vad_threshold?: number | undefined;
37
+ /** Minimum number of words required to interrupt the assistant. */
38
+ min_words_to_interrupt?: number | undefined;
39
+ /** Whether to have the no-input poke text be generated by AI */
40
+ generate_no_input_poke_text?: boolean | undefined;
41
+ /** Seconds of silence before poke message */
42
+ no_input_poke_sec?: (number | null) | undefined;
43
+ /** Poke message text. Ignored when generate_no_input_poke_text is true. */
44
+ no_input_poke_text?: string | undefined;
45
+ /** Seconds of silence before ending conversation */
46
+ no_input_end_conversation_sec?: number | undefined;
47
+ /** ISO 639-1 language code that sets the agent's default language to recognize and speak. Welcome message and no input poke text should be in this language. */
48
+ default_language?: string | undefined;
49
+ /** Array of additional ISO 639-1 language codes that the agent should be able to recognize and speak. Should not include `default_language`. */
50
+ additional_languages?: string[] | undefined;
51
+ /** If `"auto"`, each user audio is automatically identified for the language to respond in. If `"request"`, user must request to change language (recommended). */
52
+ multilingual_mode?: ConfigOptions.MultilingualMode | undefined;
53
+ /** Keywords to boost in speech recognition */
54
+ boosted_keywords?: string[] | undefined;
55
+ /** Names of tools available to the assistant. */
56
+ tools?: ConfigOptions.Tools.Item[] | undefined;
57
+ /** Template variables for system prompt and welcome message */
58
+ template_variables?: Record<string, string> | undefined;
59
+ }
60
+ export declare namespace ConfigOptions {
61
+ /** Background noise type for the conversation */
62
+ const BackgroundNoise: {
63
+ readonly Office: "office";
64
+ readonly CallCenter: "call-center";
65
+ readonly CoffeeShop: "coffee-shop";
66
+ };
67
+ type BackgroundNoise = (typeof BackgroundNoise)[keyof typeof BackgroundNoise];
68
+ /** Audio input format */
69
+ const InputFormat: {
70
+ readonly Pcm44100: "pcm_44100";
71
+ readonly Pcm16000: "pcm_16000";
72
+ readonly Pcm8000: "pcm_8000";
73
+ readonly Mulaw8000: "mulaw_8000";
74
+ };
75
+ type InputFormat = (typeof InputFormat)[keyof typeof InputFormat];
76
+ /** Audio output format */
77
+ const OutputFormat: {
78
+ readonly Pcm44100: "pcm_44100";
79
+ readonly Pcm16000: "pcm_16000";
80
+ readonly Pcm8000: "pcm_8000";
81
+ readonly Mulaw8000: "mulaw_8000";
82
+ };
83
+ type OutputFormat = (typeof OutputFormat)[keyof typeof OutputFormat];
84
+ /** If `"auto"`, each user audio is automatically identified for the language to respond in. If `"request"`, user must request to change language (recommended). */
85
+ const MultilingualMode: {
86
+ readonly Auto: "auto";
87
+ readonly Request: "request";
88
+ };
89
+ type MultilingualMode = (typeof MultilingualMode)[keyof typeof MultilingualMode];
90
+ type Tools = Tools.Item[];
91
+ namespace Tools {
92
+ type Item = string | Record<string, unknown>;
93
+ }
94
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ // This file was auto-generated by Fern from our API Definition.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ConfigOptions = void 0;
5
+ var ConfigOptions;
6
+ (function (ConfigOptions) {
7
+ /** Background noise type for the conversation */
8
+ ConfigOptions.BackgroundNoise = {
9
+ Office: "office",
10
+ CallCenter: "call-center",
11
+ CoffeeShop: "coffee-shop",
12
+ };
13
+ /** Audio input format */
14
+ ConfigOptions.InputFormat = {
15
+ Pcm44100: "pcm_44100",
16
+ Pcm16000: "pcm_16000",
17
+ Pcm8000: "pcm_8000",
18
+ Mulaw8000: "mulaw_8000",
19
+ };
20
+ /** Audio output format */
21
+ ConfigOptions.OutputFormat = {
22
+ Pcm44100: "pcm_44100",
23
+ Pcm16000: "pcm_16000",
24
+ Pcm8000: "pcm_8000",
25
+ Mulaw8000: "mulaw_8000",
26
+ };
27
+ /** If `"auto"`, each user audio is automatically identified for the language to respond in. If `"request"`, user must request to change language (recommended). */
28
+ ConfigOptions.MultilingualMode = {
29
+ Auto: "auto",
30
+ Request: "request",
31
+ };
32
+ })(ConfigOptions || (exports.ConfigOptions = ConfigOptions = {}));
@@ -1,92 +1,4 @@
1
- export interface ConfigPayload {
1
+ import type * as Phonic from "../index.js";
2
+ export interface ConfigPayload extends Phonic.ConfigOptions {
2
3
  type: "config";
3
- /** Agent name to use for conversation */
4
- agent?: string | undefined;
5
- /** Project name */
6
- project?: string | undefined;
7
- /** STS model to use */
8
- model?: "merritt" | undefined;
9
- /** System prompt for AI assistant */
10
- system_prompt?: string | undefined;
11
- /** Audio playback speed */
12
- audio_speed?: number | undefined;
13
- /** Background noise level for the conversation */
14
- background_noise_level?: number | undefined;
15
- /** Background noise type for the conversation */
16
- background_noise?: (ConfigPayload.BackgroundNoise | null) | undefined;
17
- /** When `true`, the welcome message will be automatically generated and the `welcome_message` field will be ignored. */
18
- generate_welcome_message?: boolean | undefined;
19
- /** Message to play when conversation starts. Ignored when `generate_welcome_message` is `true`. */
20
- welcome_message?: (string | null) | undefined;
21
- /** Voice ID to use for speech synthesis */
22
- voice_id?: string | undefined;
23
- /** Audio input format */
24
- input_format?: ConfigPayload.InputFormat | undefined;
25
- /** Audio output format */
26
- output_format?: ConfigPayload.OutputFormat | undefined;
27
- /** Voice activity detection prebuffer duration */
28
- vad_prebuffer_duration_ms?: number | undefined;
29
- /** Minimum speech duration for VAD */
30
- vad_min_speech_duration_ms?: number | undefined;
31
- /** Minimum silence duration for VAD */
32
- vad_min_silence_duration_ms?: number | undefined;
33
- /** Voice activity detection threshold */
34
- vad_threshold?: number | undefined;
35
- /** Minimum number of words required to interrupt the assistant. */
36
- min_words_to_interrupt?: number | undefined;
37
- /** Whether to have the no-input poke text be generated by AI */
38
- generate_no_input_poke_text?: boolean | undefined;
39
- /** Seconds of silence before poke message */
40
- no_input_poke_sec?: (number | null) | undefined;
41
- /** Poke message text. Ignored when generate_no_input_poke_text is true. */
42
- no_input_poke_text?: string | undefined;
43
- /** Seconds of silence before ending conversation */
44
- no_input_end_conversation_sec?: number | undefined;
45
- /** ISO 639-1 language code that sets the agent's default language to recognize and speak. Welcome message and no input poke text should be in this language. */
46
- default_language?: string | undefined;
47
- /** Array of additional ISO 639-1 language codes that the agent should be able to recognize and speak. Should not include `default_language`. */
48
- additional_languages?: string[] | undefined;
49
- /** If `"auto"`, each user audio is automatically identified for the language to respond in. If `"request"`, user must request to change language (recommended). */
50
- multilingual_mode?: ConfigPayload.MultilingualMode | undefined;
51
- /** Keywords to boost in speech recognition */
52
- boosted_keywords?: string[] | undefined;
53
- /** Names of tools available to the assistant. */
54
- tools?: ConfigPayload.Tools.Item[] | undefined;
55
- /** Template variables for system prompt and welcome message */
56
- template_variables?: Record<string, string> | undefined;
57
- }
58
- export declare namespace ConfigPayload {
59
- /** Background noise type for the conversation */
60
- const BackgroundNoise: {
61
- readonly Office: "office";
62
- readonly CallCenter: "call-center";
63
- readonly CoffeeShop: "coffee-shop";
64
- };
65
- type BackgroundNoise = (typeof BackgroundNoise)[keyof typeof BackgroundNoise];
66
- /** Audio input format */
67
- const InputFormat: {
68
- readonly Pcm44100: "pcm_44100";
69
- readonly Pcm16000: "pcm_16000";
70
- readonly Pcm8000: "pcm_8000";
71
- readonly Mulaw8000: "mulaw_8000";
72
- };
73
- type InputFormat = (typeof InputFormat)[keyof typeof InputFormat];
74
- /** Audio output format */
75
- const OutputFormat: {
76
- readonly Pcm44100: "pcm_44100";
77
- readonly Pcm16000: "pcm_16000";
78
- readonly Pcm8000: "pcm_8000";
79
- readonly Mulaw8000: "mulaw_8000";
80
- };
81
- type OutputFormat = (typeof OutputFormat)[keyof typeof OutputFormat];
82
- /** If `"auto"`, each user audio is automatically identified for the language to respond in. If `"request"`, user must request to change language (recommended). */
83
- const MultilingualMode: {
84
- readonly Auto: "auto";
85
- readonly Request: "request";
86
- };
87
- type MultilingualMode = (typeof MultilingualMode)[keyof typeof MultilingualMode];
88
- type Tools = Tools.Item[];
89
- namespace Tools {
90
- type Item = string | Record<string, unknown>;
91
- }
92
4
  }
@@ -1,32 +1,3 @@
1
1
  "use strict";
2
2
  // This file was auto-generated by Fern from our API Definition.
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.ConfigPayload = void 0;
5
- var ConfigPayload;
6
- (function (ConfigPayload) {
7
- /** Background noise type for the conversation */
8
- ConfigPayload.BackgroundNoise = {
9
- Office: "office",
10
- CallCenter: "call-center",
11
- CoffeeShop: "coffee-shop",
12
- };
13
- /** Audio input format */
14
- ConfigPayload.InputFormat = {
15
- Pcm44100: "pcm_44100",
16
- Pcm16000: "pcm_16000",
17
- Pcm8000: "pcm_8000",
18
- Mulaw8000: "mulaw_8000",
19
- };
20
- /** Audio output format */
21
- ConfigPayload.OutputFormat = {
22
- Pcm44100: "pcm_44100",
23
- Pcm16000: "pcm_16000",
24
- Pcm8000: "pcm_8000",
25
- Mulaw8000: "mulaw_8000",
26
- };
27
- /** If `"auto"`, each user audio is automatically identified for the language to respond in. If `"request"`, user must request to change language (recommended). */
28
- ConfigPayload.MultilingualMode = {
29
- Auto: "auto",
30
- Request: "request",
31
- };
32
- })(ConfigPayload || (exports.ConfigPayload = ConfigPayload = {}));
@@ -0,0 +1,5 @@
1
+ import type * as Phonic from "../index.js";
2
+ export interface ResetPayload {
3
+ type: "reset";
4
+ config: Phonic.ConfigOptions;
5
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // This file was auto-generated by Fern from our API Definition.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -8,6 +8,7 @@ export * from "./AudioChunkPayload.js";
8
8
  export * from "./AudioChunkResponsePayload.js";
9
9
  export * from "./BadRequestErrorBody.js";
10
10
  export * from "./BasicError.js";
11
+ export * from "./ConfigOptions.js";
11
12
  export * from "./ConfigPayload.js";
12
13
  export * from "./Conversation.js";
13
14
  export * from "./ConversationAnalysis.js";
@@ -33,6 +34,7 @@ export * from "./OutboundCallInitiatedResponse.js";
33
34
  export * from "./OutboundDryRunResponse.js";
34
35
  export * from "./Project.js";
35
36
  export * from "./ReadyToStartConversationPayload.js";
37
+ export * from "./ResetPayload.js";
36
38
  export * from "./SayPayload.js";
37
39
  export * from "./SetExternalIdPayload.js";
38
40
  export * from "./SipOutboundCallInitiatedResponse.js";
@@ -24,6 +24,7 @@ __exportStar(require("./AudioChunkPayload.js"), exports);
24
24
  __exportStar(require("./AudioChunkResponsePayload.js"), exports);
25
25
  __exportStar(require("./BadRequestErrorBody.js"), exports);
26
26
  __exportStar(require("./BasicError.js"), exports);
27
+ __exportStar(require("./ConfigOptions.js"), exports);
27
28
  __exportStar(require("./ConfigPayload.js"), exports);
28
29
  __exportStar(require("./Conversation.js"), exports);
29
30
  __exportStar(require("./ConversationAnalysis.js"), exports);
@@ -49,6 +50,7 @@ __exportStar(require("./OutboundCallInitiatedResponse.js"), exports);
49
50
  __exportStar(require("./OutboundDryRunResponse.js"), exports);
50
51
  __exportStar(require("./Project.js"), exports);
51
52
  __exportStar(require("./ReadyToStartConversationPayload.js"), exports);
53
+ __exportStar(require("./ResetPayload.js"), exports);
52
54
  __exportStar(require("./SayPayload.js"), exports);
53
55
  __exportStar(require("./SetExternalIdPayload.js"), exports);
54
56
  __exportStar(require("./SipOutboundCallInitiatedResponse.js"), exports);
@@ -0,0 +1,74 @@
1
+ import * as core from "../core/index.js";
2
+ import type * as Phonic from "../api/index.js";
3
+ import { ConversationsSocket } from "../api/resources/conversations/client/Socket.js";
4
+ export interface ReconnectableConversationsSocketArgs {
5
+ /** Called on 1006 to create a new socket with reconnect_conv_id. May be async (e.g. fresh auth). */
6
+ createReconnectSocket: (conversationId: string) => core.ReconnectingWebSocket | Promise<core.ReconnectingWebSocket>;
7
+ /** Initial socket for the first connection. */
8
+ socket: core.ReconnectingWebSocket;
9
+ /** If provided, reconnection stops when the signal is aborted. */
10
+ abortSignal?: AbortSignal;
11
+ }
12
+ type EventHandlers = {
13
+ open?: () => void;
14
+ message?: (message: ConversationsSocket.Response) => void;
15
+ close?: (event: core.CloseEvent) => void;
16
+ error?: (error: Error) => void;
17
+ };
18
+ /**
19
+ * Wraps ConversationsSocket with automatic reconnection on 1006.
20
+ *
21
+ * On abnormal closure, creates a brand new ReconnectingWebSocket (via the
22
+ * createReconnectSocket factory) and wraps it in a fresh ConversationsSocket,
23
+ * forwarding all events to user-registered handlers.
24
+ *
25
+ * Retries reconnection with exponential backoff until the server responds
26
+ * with a terminal close code (4800 session expired, 4801 invalid state),
27
+ * the safety cap is reached, or the user calls close().
28
+ *
29
+ * Uses composition rather than inheritance to avoid coupling to the parent's
30
+ * private event handler registration or ReconnectingWebSocket internals.
31
+ */
32
+ export declare class ReconnectableConversationsSocket {
33
+ private _conversationId;
34
+ private _inner;
35
+ private readonly _createReconnectSocket;
36
+ private readonly _handlers;
37
+ private _reconnectAttempts;
38
+ private _isClosed;
39
+ private readonly _abortSignal;
40
+ private _cleanupWireListeners;
41
+ private _pendingReconnect;
42
+ private _pendingReplacement;
43
+ constructor(args: ReconnectableConversationsSocketArgs);
44
+ /** The conversation ID captured from the server's conversation_created message. */
45
+ get conversationId(): string | null;
46
+ get socket(): core.ReconnectingWebSocket;
47
+ get readyState(): number;
48
+ on<T extends keyof EventHandlers>(event: T, callback: EventHandlers[T]): void;
49
+ /** Drop outbound sends when we cannot talk to a live socket (no queue). */
50
+ private _safeSend;
51
+ sendConfig(message: Phonic.ConfigPayload): void;
52
+ sendAudioChunk(message: Phonic.AudioChunkPayload): void;
53
+ sendToolCallOutput(message: Phonic.ToolCallOutputPayload): void;
54
+ sendUpdateSystemPrompt(message: Phonic.UpdateSystemPromptPayload): void;
55
+ sendAddSystemMessage(message: Phonic.AddSystemMessagePayload): void;
56
+ sendSetExternalId(message: Phonic.SetExternalIdPayload): void;
57
+ sendGenerateReply(message: Phonic.GenerateReplyPayload): void;
58
+ sendSay(message: Phonic.SayPayload): void;
59
+ sendReset(message: Phonic.ResetPayload): void;
60
+ /**
61
+ * Not supported — reconnection after 1006 is handled automatically.
62
+ * To start a new conversation, create a new socket via client.conversations.connect().
63
+ */
64
+ connect(): never;
65
+ close(): void;
66
+ waitForOpen(): Promise<core.ReconnectingWebSocket>;
67
+ private _getReconnectDelay;
68
+ /** Schedule a reconnection attempt after backoff delay. */
69
+ private _scheduleReconnect;
70
+ /** Perform the actual reconnection attempt. */
71
+ private _doReconnect;
72
+ private _wireInner;
73
+ }
74
+ export {};