phonic 0.32.9 → 0.32.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 (59) hide show
  1. package/dist/cjs/BaseClient.js +2 -2
  2. package/dist/cjs/Client.d.ts +3 -2
  3. package/dist/cjs/api/resources/agents/client/requests/AgentsCreateRequest.d.ts +2 -0
  4. package/dist/cjs/api/resources/agents/client/requests/UpdateAgentRequest.d.ts +2 -0
  5. package/dist/cjs/api/resources/conversations/client/Client.d.ts +3 -3
  6. package/dist/cjs/api/resources/tools/client/requests/CreateToolRequest.d.ts +12 -0
  7. package/dist/cjs/api/resources/tools/client/requests/CreateToolRequest.js +9 -0
  8. package/dist/cjs/api/resources/tools/client/requests/UpdateToolRequest.d.ts +9 -0
  9. package/dist/cjs/api/resources/tools/client/requests/UpdateToolRequest.js +6 -0
  10. package/dist/cjs/api/types/Agent.d.ts +2 -0
  11. package/dist/cjs/api/types/AudioChunkPayload.d.ts +1 -1
  12. package/dist/cjs/api/types/BuiltInToolConfig.d.ts +16 -0
  13. package/dist/cjs/api/types/BuiltInToolConfig.js +13 -0
  14. package/dist/cjs/api/types/BuiltInToolConfigs.d.ts +5 -0
  15. package/dist/cjs/api/types/BuiltInToolConfigs.js +3 -0
  16. package/dist/cjs/api/types/BuiltInToolDefinition.d.ts +18 -0
  17. package/dist/cjs/api/types/BuiltInToolDefinition.js +12 -0
  18. package/dist/cjs/api/types/ConfigOptions.d.ts +1 -1
  19. package/dist/cjs/api/types/CreateAgentRequest.d.ts +2 -0
  20. package/dist/cjs/api/types/GenerateReplyPayload.d.ts +2 -0
  21. package/dist/cjs/api/types/Tool.d.ts +12 -0
  22. package/dist/cjs/api/types/Tool.js +9 -0
  23. package/dist/cjs/api/types/ToolDefinition.d.ts +1 -1
  24. package/dist/cjs/api/types/index.d.ts +3 -0
  25. package/dist/cjs/api/types/index.js +3 -0
  26. package/dist/cjs/custom/ReconnectableConversationsSocket.d.ts +5 -4
  27. package/dist/cjs/custom/ReconnectableConversationsSocket.js +25 -12
  28. package/dist/cjs/version.d.ts +1 -1
  29. package/dist/cjs/version.js +1 -1
  30. package/dist/esm/BaseClient.mjs +2 -2
  31. package/dist/esm/Client.d.mts +3 -2
  32. package/dist/esm/api/resources/agents/client/requests/AgentsCreateRequest.d.mts +2 -0
  33. package/dist/esm/api/resources/agents/client/requests/UpdateAgentRequest.d.mts +2 -0
  34. package/dist/esm/api/resources/conversations/client/Client.d.mts +3 -3
  35. package/dist/esm/api/resources/tools/client/requests/CreateToolRequest.d.mts +12 -0
  36. package/dist/esm/api/resources/tools/client/requests/CreateToolRequest.mjs +9 -0
  37. package/dist/esm/api/resources/tools/client/requests/UpdateToolRequest.d.mts +9 -0
  38. package/dist/esm/api/resources/tools/client/requests/UpdateToolRequest.mjs +6 -0
  39. package/dist/esm/api/types/Agent.d.mts +2 -0
  40. package/dist/esm/api/types/AudioChunkPayload.d.mts +1 -1
  41. package/dist/esm/api/types/BuiltInToolConfig.d.mts +16 -0
  42. package/dist/esm/api/types/BuiltInToolConfig.mjs +10 -0
  43. package/dist/esm/api/types/BuiltInToolConfigs.d.mts +5 -0
  44. package/dist/esm/api/types/BuiltInToolConfigs.mjs +2 -0
  45. package/dist/esm/api/types/BuiltInToolDefinition.d.mts +18 -0
  46. package/dist/esm/api/types/BuiltInToolDefinition.mjs +9 -0
  47. package/dist/esm/api/types/ConfigOptions.d.mts +1 -1
  48. package/dist/esm/api/types/CreateAgentRequest.d.mts +2 -0
  49. package/dist/esm/api/types/GenerateReplyPayload.d.mts +2 -0
  50. package/dist/esm/api/types/Tool.d.mts +12 -0
  51. package/dist/esm/api/types/Tool.mjs +9 -0
  52. package/dist/esm/api/types/ToolDefinition.d.mts +1 -1
  53. package/dist/esm/api/types/index.d.mts +3 -0
  54. package/dist/esm/api/types/index.mjs +3 -0
  55. package/dist/esm/custom/ReconnectableConversationsSocket.d.mts +5 -4
  56. package/dist/esm/custom/ReconnectableConversationsSocket.mjs +25 -12
  57. package/dist/esm/version.d.mts +1 -1
  58. package/dist/esm/version.mjs +1 -1
  59. package/package.json +1 -1
@@ -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.32.9",
47
- "User-Agent": "phonic/0.32.9",
46
+ "X-Fern-SDK-Version": "0.32.11",
47
+ "User-Agent": "phonic/0.32.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);
@@ -15,8 +15,9 @@ import * as core from "./core/index.js";
15
15
  export declare namespace PhonicClient {
16
16
  type Options = BaseClientOptions & {
17
17
  /**
18
- * When `true`, conversation WebSockets automatically reconnect after an
19
- * abnormal disconnect (WebSocket close code 1006) using `reconnect_conv_id`.
18
+ * **Experimental.** When `true`, conversation WebSockets automatically
19
+ * reconnect and resume after a non-deliberate disconnect (WebSocket close
20
+ * codes 1006, 1012, or 1001/"restarting") using `reconnect_conv_id`.
20
21
  * Defaults to `false` until the behavior is broadly validated in production;
21
22
  * set to `true` to opt in early.
22
23
  */
@@ -83,6 +83,8 @@ export interface AgentsCreateRequest {
83
83
  template_variables?: Record<string, Phonic.CreateAgentRequest.TemplateVariables.Value>;
84
84
  /** Array of built-in or custom tool names to use. */
85
85
  tools?: Phonic.CreateAgentRequest.Tools.Item[];
86
+ /** Configuration overrides for built-in tools, keyed by built-in tool ID. Built-in tools not listed here use their default configuration. */
87
+ built_in_tool_configs?: Phonic.BuiltInToolConfigs;
86
88
  /** Array of task objects with `name` and `description` fields. */
87
89
  tasks?: Phonic.Task[];
88
90
  /** Whether to have the no-input poke text be generated by AI. */
@@ -83,6 +83,8 @@ export interface UpdateAgentRequest {
83
83
  template_variables?: Record<string, UpdateAgentRequest.TemplateVariables.Value>;
84
84
  /** Array of built-in or custom tool names to use. */
85
85
  tools?: UpdateAgentRequest.Tools.Item[];
86
+ /** Configuration overrides for built-in tools, keyed by built-in tool ID. Built-in tools not listed here use their default configuration. */
87
+ built_in_tool_configs?: Phonic.BuiltInToolConfigs;
86
88
  /** Array of task objects with `name` and `description` fields. */
87
89
  tasks?: Phonic.Task[];
88
90
  /** Whether to have the no-input poke text be generated by AI. */
@@ -6,9 +6,9 @@ import { ConversationsSocket } from "./Socket.js";
6
6
  export declare namespace ConversationsClient {
7
7
  type Options = BaseClientOptions & {
8
8
  /**
9
- * When `true`, `connect()` uses session-aware reconnection on abnormal
10
- * disconnect (1006). Set via `PhonicClient` options as
11
- * `reconnectConversationOnAbnormalDisconnect`.
9
+ * **Experimental.** When `true`, `connect()` uses session-aware reconnection
10
+ * on a non-deliberate disconnect (close codes 1006, 1012, or 1001/"restarting").
11
+ * Set via `PhonicClient` options as `reconnectConversationOnAbnormalDisconnect`.
12
12
  */
13
13
  reconnectConversationOnAbnormalDisconnect?: boolean;
14
14
  };
@@ -141,6 +141,8 @@ export interface CreateToolRequest {
141
141
  agents_to_transfer_to?: string[];
142
142
  /** When true, forces the agent to speak before executing the tool. */
143
143
  require_speech_before_tool_call?: boolean;
144
+ /** For built_in_natural_conversation_ending and built_in_keypad_input tools. Whether the agent must speak before calling the tool ("required"), the model decides ("optional"), or the agent must stay silent ("suppressed"). Not used by other tool types. */
145
+ speech_before_tool_call?: CreateToolRequest.SpeechBeforeToolCall;
144
146
  /** If true, the agent will wait to finish speaking before executing the tool. This is only available for custom_webhook and custom_websocket tools. */
145
147
  wait_for_speech_before_tool_call?: boolean;
146
148
  /** When true, forbids the agent from speaking after executing the tool. Available for custom_context, custom_webhook and custom_websocket tools. */
@@ -160,6 +162,9 @@ export declare namespace CreateToolRequest {
160
162
  readonly CustomWebsocket: "custom_websocket";
161
163
  readonly BuiltInTransferToPhoneNumber: "built_in_transfer_to_phone_number";
162
164
  readonly BuiltInTransferToAgent: "built_in_transfer_to_agent";
165
+ readonly BuiltInNaturalConversationEnding: "built_in_natural_conversation_ending";
166
+ readonly BuiltInKeypadInput: "built_in_keypad_input";
167
+ readonly BuiltInChooseNotToRespond: "built_in_choose_not_to_respond";
163
168
  };
164
169
  type Type = (typeof Type)[keyof typeof Type];
165
170
  /** Mode of operation. */
@@ -174,4 +179,11 @@ export declare namespace CreateToolRequest {
174
179
  readonly Post: "POST";
175
180
  };
176
181
  type EndpointMethod = (typeof EndpointMethod)[keyof typeof EndpointMethod];
182
+ /** For built_in_natural_conversation_ending and built_in_keypad_input tools. Whether the agent must speak before calling the tool ("required"), the model decides ("optional"), or the agent must stay silent ("suppressed"). Not used by other tool types. */
183
+ const SpeechBeforeToolCall: {
184
+ readonly Required: "required";
185
+ readonly Optional: "optional";
186
+ readonly Suppressed: "suppressed";
187
+ };
188
+ type SpeechBeforeToolCall = (typeof SpeechBeforeToolCall)[keyof typeof SpeechBeforeToolCall];
177
189
  }
@@ -11,6 +11,9 @@ var CreateToolRequest;
11
11
  CustomWebsocket: "custom_websocket",
12
12
  BuiltInTransferToPhoneNumber: "built_in_transfer_to_phone_number",
13
13
  BuiltInTransferToAgent: "built_in_transfer_to_agent",
14
+ BuiltInNaturalConversationEnding: "built_in_natural_conversation_ending",
15
+ BuiltInKeypadInput: "built_in_keypad_input",
16
+ BuiltInChooseNotToRespond: "built_in_choose_not_to_respond",
14
17
  };
15
18
  /** Mode of operation. */
16
19
  CreateToolRequest.ExecutionMode = {
@@ -22,4 +25,10 @@ var CreateToolRequest;
22
25
  Get: "GET",
23
26
  Post: "POST",
24
27
  };
28
+ /** For built_in_natural_conversation_ending and built_in_keypad_input tools. Whether the agent must speak before calling the tool ("required"), the model decides ("optional"), or the agent must stay silent ("suppressed"). Not used by other tool types. */
29
+ CreateToolRequest.SpeechBeforeToolCall = {
30
+ Required: "required",
31
+ Optional: "optional",
32
+ Suppressed: "suppressed",
33
+ };
25
34
  })(CreateToolRequest || (exports.CreateToolRequest = CreateToolRequest = {}));
@@ -49,6 +49,8 @@ export interface UpdateToolRequest {
49
49
  agents_to_transfer_to?: string[];
50
50
  /** When true, forces the agent to speak before executing the tool. */
51
51
  require_speech_before_tool_call?: boolean;
52
+ /** For built_in_natural_conversation_ending and built_in_keypad_input tools. Whether the agent must speak before calling the tool ("required"), the model decides ("optional"), or the agent must stay silent ("suppressed"). Not used by other tool types. */
53
+ speech_before_tool_call?: UpdateToolRequest.SpeechBeforeToolCall;
52
54
  /** If true, the agent will wait to finish speaking before executing the tool. This is only available for custom_webhook and custom_websocket tools. */
53
55
  wait_for_speech_before_tool_call?: boolean;
54
56
  /** When true, forbids the agent from speaking after executing the tool. Available for custom_context, custom_webhook and custom_websocket tools. */
@@ -71,4 +73,11 @@ export declare namespace UpdateToolRequest {
71
73
  readonly Post: "POST";
72
74
  };
73
75
  type EndpointMethod = (typeof EndpointMethod)[keyof typeof EndpointMethod];
76
+ /** For built_in_natural_conversation_ending and built_in_keypad_input tools. Whether the agent must speak before calling the tool ("required"), the model decides ("optional"), or the agent must stay silent ("suppressed"). Not used by other tool types. */
77
+ const SpeechBeforeToolCall: {
78
+ readonly Required: "required";
79
+ readonly Optional: "optional";
80
+ readonly Suppressed: "suppressed";
81
+ };
82
+ type SpeechBeforeToolCall = (typeof SpeechBeforeToolCall)[keyof typeof SpeechBeforeToolCall];
74
83
  }
@@ -14,4 +14,10 @@ var UpdateToolRequest;
14
14
  Get: "GET",
15
15
  Post: "POST",
16
16
  };
17
+ /** For built_in_natural_conversation_ending and built_in_keypad_input tools. Whether the agent must speak before calling the tool ("required"), the model decides ("optional"), or the agent must stay silent ("suppressed"). Not used by other tool types. */
18
+ UpdateToolRequest.SpeechBeforeToolCall = {
19
+ Required: "required",
20
+ Optional: "optional",
21
+ Suppressed: "suppressed",
22
+ };
17
23
  })(UpdateToolRequest || (exports.UpdateToolRequest = UpdateToolRequest = {}));
@@ -36,6 +36,8 @@ export interface Agent {
36
36
  template_variables: Record<string, Agent.TemplateVariables.Value>;
37
37
  /** List of tools available to the agent. */
38
38
  tools: Agent.Tools.Item[];
39
+ /** Configuration overrides for built-in tools, keyed by built-in tool ID. */
40
+ built_in_tool_configs: Phonic.BuiltInToolConfigs;
39
41
  /** Tasks for the agent to complete during the conversation. */
40
42
  tasks: Phonic.Task[];
41
43
  /** Whether to have the no-input poke text be generated by AI. */
@@ -1,6 +1,6 @@
1
1
  export interface AudioChunkPayload {
2
2
  type: "audio_chunk";
3
- /** Base64-encoded audio data (Int16Array for PCM, Uint8Array for mulaw) */
3
+ /** Base64-encoded audio data (Int16Array for PCM, Uint8Array for mulaw). Each chunk may contain at most 40 ms of audio — longer chunks are rejected with an error. Batch ~20 ms frames for headroom. */
4
4
  audio: string;
5
5
  /** ISO 8601 timestamp (required for first chunk only) */
6
6
  iso_date_time?: string | undefined;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Configuration for a simple built-in tool (`keypad_input`, `natural_conversation_ending`, or `choose_not_to_respond`).
3
+ */
4
+ export interface BuiltInToolConfig {
5
+ /** Controls whether the assistant speaks before the tool is called. `required`: the assistant must speak first. `optional`: the model decides. `suppressed`: the assistant is strongly instructed to stay silent before the call (best effort). */
6
+ speech_before_tool_call: BuiltInToolConfig.SpeechBeforeToolCall;
7
+ }
8
+ export declare namespace BuiltInToolConfig {
9
+ /** Controls whether the assistant speaks before the tool is called. `required`: the assistant must speak first. `optional`: the model decides. `suppressed`: the assistant is strongly instructed to stay silent before the call (best effort). */
10
+ const SpeechBeforeToolCall: {
11
+ readonly Required: "required";
12
+ readonly Optional: "optional";
13
+ readonly Suppressed: "suppressed";
14
+ };
15
+ type SpeechBeforeToolCall = (typeof SpeechBeforeToolCall)[keyof typeof SpeechBeforeToolCall];
16
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ // This file was auto-generated by Fern from our API Definition.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.BuiltInToolConfig = void 0;
5
+ var BuiltInToolConfig;
6
+ (function (BuiltInToolConfig) {
7
+ /** Controls whether the assistant speaks before the tool is called. `required`: the assistant must speak first. `optional`: the model decides. `suppressed`: the assistant is strongly instructed to stay silent before the call (best effort). */
8
+ BuiltInToolConfig.SpeechBeforeToolCall = {
9
+ Required: "required",
10
+ Optional: "optional",
11
+ Suppressed: "suppressed",
12
+ };
13
+ })(BuiltInToolConfig || (exports.BuiltInToolConfig = BuiltInToolConfig = {}));
@@ -0,0 +1,5 @@
1
+ import type * as Phonic from "../index.js";
2
+ /**
3
+ * Per-tool configuration overrides for built-in tools, keyed by built-in tool ID (e.g. `tool_natural_conversation_ending`). A built-in tool referenced in `tools` but absent from this map uses its default configuration.
4
+ */
5
+ export type BuiltInToolConfigs = Record<string, Phonic.BuiltInToolConfig>;
@@ -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 });
@@ -0,0 +1,18 @@
1
+ import type * as Phonic from "../index.js";
2
+ /**
3
+ * A built-in tool with an explicit configuration, as an alternative to referencing it by bare name (which uses the tool's default configuration). Only `keypad_input` and `natural_conversation_ending` accept configuration this way.
4
+ */
5
+ export interface BuiltInToolDefinition {
6
+ type: "built_in";
7
+ /** The name of the built-in tool. */
8
+ name: BuiltInToolDefinition.Name;
9
+ tool_config: Phonic.BuiltInToolConfig;
10
+ }
11
+ export declare namespace BuiltInToolDefinition {
12
+ /** The name of the built-in tool. */
13
+ const Name: {
14
+ readonly KeypadInput: "keypad_input";
15
+ readonly NaturalConversationEnding: "natural_conversation_ending";
16
+ };
17
+ type Name = (typeof Name)[keyof typeof Name];
18
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ // This file was auto-generated by Fern from our API Definition.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.BuiltInToolDefinition = void 0;
5
+ var BuiltInToolDefinition;
6
+ (function (BuiltInToolDefinition) {
7
+ /** The name of the built-in tool. */
8
+ BuiltInToolDefinition.Name = {
9
+ KeypadInput: "keypad_input",
10
+ NaturalConversationEnding: "natural_conversation_ending",
11
+ };
12
+ })(BuiltInToolDefinition || (exports.BuiltInToolDefinition = BuiltInToolDefinition = {}));
@@ -65,7 +65,7 @@ export interface ConfigOptions {
65
65
  boosted_keywords?: string[] | undefined;
66
66
  /** Array of `{ word, pronunciation }` entries. Words must be unique. */
67
67
  pronunciation_dictionary?: ConfigOptions.PronunciationDictionary.Item[] | undefined;
68
- /** Tools available to the assistant. Use a string to reference a pre-defined tool by name, or define an inline WebSocket tool for this conversation. */
68
+ /** Tools available to the assistant. Use a string to reference a pre-defined tool by name, provide a built-in tool object to override its default configuration, or define an inline WebSocket tool for this conversation. */
69
69
  tools?: Phonic.ToolDefinition[] | undefined;
70
70
  /** Template variables for system prompt and welcome message */
71
71
  template_variables?: Record<string, string> | undefined;
@@ -36,6 +36,8 @@ export interface CreateAgentRequest {
36
36
  template_variables?: Record<string, CreateAgentRequest.TemplateVariables.Value> | undefined;
37
37
  /** Array of built-in or custom tool names to use. */
38
38
  tools?: CreateAgentRequest.Tools.Item[] | undefined;
39
+ /** Configuration overrides for built-in tools, keyed by built-in tool ID. Built-in tools not listed here use their default configuration. */
40
+ built_in_tool_configs?: Phonic.BuiltInToolConfigs | undefined;
39
41
  /** Array of task objects with `name` and `description` fields. */
40
42
  tasks?: Phonic.Task[] | undefined;
41
43
  /** Whether to have the no-input poke text be generated by AI. */
@@ -2,4 +2,6 @@ export interface GenerateReplyPayload {
2
2
  type: "generate_reply";
3
3
  /** Optional system message to guide the assistant's reply */
4
4
  system_message?: (string | null) | undefined;
5
+ /** Optional user message for the assistant to reply to */
6
+ user_message?: (string | null) | undefined;
5
7
  }
@@ -37,6 +37,8 @@ export interface Tool {
37
37
  agents_to_transfer_to?: string[] | undefined;
38
38
  /** When true, forces the agent to speak before executing the tool. */
39
39
  require_speech_before_tool_call?: boolean | undefined;
40
+ /** For built_in_natural_conversation_ending and built_in_keypad_input tools. Whether the agent must speak before calling the tool ("required"), the model decides ("optional"), or the agent must stay silent ("suppressed"). Not used by other tool types. */
41
+ speech_before_tool_call?: Tool.SpeechBeforeToolCall | undefined;
40
42
  /** If true, the agent will wait to finish speaking before executing the tool. This is only available for custom_webhook and custom_websocket tools. */
41
43
  wait_for_speech_before_tool_call?: boolean | undefined;
42
44
  /** When true, forbids the agent from speaking after executing the tool. Available for custom_context, custom_webhook and custom_websocket tools. */
@@ -60,6 +62,9 @@ export declare namespace Tool {
60
62
  readonly CustomWebsocket: "custom_websocket";
61
63
  readonly BuiltInTransferToPhoneNumber: "built_in_transfer_to_phone_number";
62
64
  readonly BuiltInTransferToAgent: "built_in_transfer_to_agent";
65
+ readonly BuiltInNaturalConversationEnding: "built_in_natural_conversation_ending";
66
+ readonly BuiltInKeypadInput: "built_in_keypad_input";
67
+ readonly BuiltInChooseNotToRespond: "built_in_choose_not_to_respond";
63
68
  };
64
69
  type Type = (typeof Type)[keyof typeof Type];
65
70
  /** Mode of operation - sync waits for response, async continues without waiting. */
@@ -74,4 +79,11 @@ export declare namespace Tool {
74
79
  readonly Post: "POST";
75
80
  };
76
81
  type EndpointMethod = (typeof EndpointMethod)[keyof typeof EndpointMethod];
82
+ /** For built_in_natural_conversation_ending and built_in_keypad_input tools. Whether the agent must speak before calling the tool ("required"), the model decides ("optional"), or the agent must stay silent ("suppressed"). Not used by other tool types. */
83
+ const SpeechBeforeToolCall: {
84
+ readonly Required: "required";
85
+ readonly Optional: "optional";
86
+ readonly Suppressed: "suppressed";
87
+ };
88
+ type SpeechBeforeToolCall = (typeof SpeechBeforeToolCall)[keyof typeof SpeechBeforeToolCall];
77
89
  }
@@ -11,6 +11,9 @@ var Tool;
11
11
  CustomWebsocket: "custom_websocket",
12
12
  BuiltInTransferToPhoneNumber: "built_in_transfer_to_phone_number",
13
13
  BuiltInTransferToAgent: "built_in_transfer_to_agent",
14
+ BuiltInNaturalConversationEnding: "built_in_natural_conversation_ending",
15
+ BuiltInKeypadInput: "built_in_keypad_input",
16
+ BuiltInChooseNotToRespond: "built_in_choose_not_to_respond",
14
17
  };
15
18
  /** Mode of operation - sync waits for response, async continues without waiting. */
16
19
  Tool.ExecutionMode = {
@@ -22,4 +25,10 @@ var Tool;
22
25
  Get: "GET",
23
26
  Post: "POST",
24
27
  };
28
+ /** For built_in_natural_conversation_ending and built_in_keypad_input tools. Whether the agent must speak before calling the tool ("required"), the model decides ("optional"), or the agent must stay silent ("suppressed"). Not used by other tool types. */
29
+ Tool.SpeechBeforeToolCall = {
30
+ Required: "required",
31
+ Optional: "optional",
32
+ Suppressed: "suppressed",
33
+ };
25
34
  })(Tool || (exports.Tool = Tool = {}));
@@ -1,2 +1,2 @@
1
1
  import type * as Phonic from "../index.js";
2
- export type ToolDefinition = Phonic.ToolName | Phonic.InlineWebSocketTool;
2
+ export type ToolDefinition = Phonic.ToolName | Phonic.BuiltInToolDefinition | Phonic.InlineWebSocketTool;
@@ -10,6 +10,9 @@ export * from "./AudioChunkPayload.js";
10
10
  export * from "./AudioChunkResponsePayload.js";
11
11
  export * from "./BadRequestErrorBody.js";
12
12
  export * from "./BasicError.js";
13
+ export * from "./BuiltInToolConfig.js";
14
+ export * from "./BuiltInToolConfigs.js";
15
+ export * from "./BuiltInToolDefinition.js";
13
16
  export * from "./ConfigOptions.js";
14
17
  export * from "./ConfigPayload.js";
15
18
  export * from "./Conversation.js";
@@ -26,6 +26,9 @@ __exportStar(require("./AudioChunkPayload.js"), exports);
26
26
  __exportStar(require("./AudioChunkResponsePayload.js"), exports);
27
27
  __exportStar(require("./BadRequestErrorBody.js"), exports);
28
28
  __exportStar(require("./BasicError.js"), exports);
29
+ __exportStar(require("./BuiltInToolConfig.js"), exports);
30
+ __exportStar(require("./BuiltInToolConfigs.js"), exports);
31
+ __exportStar(require("./BuiltInToolDefinition.js"), exports);
29
32
  __exportStar(require("./ConfigOptions.js"), exports);
30
33
  __exportStar(require("./ConfigPayload.js"), exports);
31
34
  __exportStar(require("./Conversation.js"), exports);
@@ -2,7 +2,7 @@ import * as core from "../core/index.js";
2
2
  import type * as Phonic from "../api/index.js";
3
3
  import { ConversationsSocket } from "../api/resources/conversations/client/Socket.js";
4
4
  export interface ReconnectableConversationsSocketArgs {
5
- /** Called on 1006 to create a new socket with reconnect_conv_id. May be async (e.g. fresh auth). */
5
+ /** Called on a reconnectable close to create a new socket with reconnect_conv_id. May be async (e.g. fresh auth). */
6
6
  createReconnectSocket: (conversationId: string) => core.ReconnectingWebSocket | Promise<core.ReconnectingWebSocket>;
7
7
  /** Initial socket for the first connection. */
8
8
  socket: core.ReconnectingWebSocket;
@@ -16,9 +16,10 @@ type EventHandlers = {
16
16
  error?: (error: Error) => void;
17
17
  };
18
18
  /**
19
- * Wraps ConversationsSocket with automatic reconnection on 1006.
19
+ * Wraps ConversationsSocket with automatic reconnection on a reconnectable
20
+ * close (1006, 1012, or 1001/"restarting" — see isReconnectableClose).
20
21
  *
21
- * On abnormal closure, creates a brand new ReconnectingWebSocket (via the
22
+ * On such a close, creates a brand new ReconnectingWebSocket (via the
22
23
  * createReconnectSocket factory) and wraps it in a fresh ConversationsSocket,
23
24
  * forwarding all events to user-registered handlers.
24
25
  *
@@ -60,7 +61,7 @@ export declare class ReconnectableConversationsSocket {
60
61
  sendMute(message: Phonic.MutePayload): void;
61
62
  sendUnmute(message: Phonic.UnmutePayload): void;
62
63
  /**
63
- * Not supported — reconnection after 1006 is handled automatically.
64
+ * Not supported — reconnection after a dropped connection is handled automatically.
64
65
  * To start a new conversation, create a new socket via client.conversations.connect().
65
66
  */
66
67
  connect(): never;
@@ -46,20 +46,33 @@ exports.ReconnectableConversationsSocket = void 0;
46
46
  const core = __importStar(require("../core/index.js"));
47
47
  const Socket_js_1 = require("../api/resources/conversations/client/Socket.js");
48
48
  const json_js_1 = require("../core/json.js");
49
- /** 1006 is the only close code that indicates an unexpected disconnect
50
- * worth reconnecting for. All other codes (1000, 4000, 4800, etc.)
51
- * are intentional server-side closes. */
52
49
  const ABNORMAL_CLOSURE = 1006;
50
+ const SERVICE_RESTART = 1012;
51
+ const GOING_AWAY = 1001;
52
+ /** Whether a close means the disconnect was NOT a deliberate end of the
53
+ * conversation, so the SDK should transparently reconnect and resume it:
54
+ * - 1006 abnormal closure (socket died with no close frame)
55
+ * - 1012 service restart — an edge proxy/load-balancer restart closes the
56
+ * client with 1012/"restarting"; the conversation is still alive
57
+ * server-side within the grace window
58
+ * - 1001 "going away" ONLY when the reason is "restarting" — a proxy drain
59
+ * can surface to the client as 1001/"restarting" instead of 1012. A bare
60
+ * 1001 (empty/other reason) is a deliberate close (the caller ended the
61
+ * conversation, tab closed/suspended) and must NOT reconnect.
62
+ * Matches the server's reconnect policy. All other codes (1000, 4000,
63
+ * 4800, ...) are intentional closes. */
64
+ const isReconnectableClose = (code, reason) => code === ABNORMAL_CLOSURE || code === SERVICE_RESTART || (code === GOING_AWAY && reason === "restarting");
53
65
  const BASE_RECONNECT_DELAY_MS = 500;
54
66
  const MAX_RECONNECT_DELAY_MS = 5000;
55
67
  /** Safety cap: stop retrying if the server is completely unreachable.
56
68
  * In normal operation the server's terminal codes (4800/4801) stop
57
- * retries much sooner (within the 10s grace period). */
69
+ * retries much sooner (within the 30s grace period). */
58
70
  const MAX_RECONNECT_ATTEMPTS = 10;
59
71
  /**
60
- * Wraps ConversationsSocket with automatic reconnection on 1006.
72
+ * Wraps ConversationsSocket with automatic reconnection on a reconnectable
73
+ * close (1006, 1012, or 1001/"restarting" — see isReconnectableClose).
61
74
  *
62
- * On abnormal closure, creates a brand new ReconnectingWebSocket (via the
75
+ * On such a close, creates a brand new ReconnectingWebSocket (via the
63
76
  * createReconnectSocket factory) and wraps it in a fresh ConversationsSocket,
64
77
  * forwarding all events to user-registered handlers.
65
78
  *
@@ -141,12 +154,12 @@ class ReconnectableConversationsSocket {
141
154
  this._safeSend((inner) => inner.sendUnmute(message));
142
155
  }
143
156
  /**
144
- * Not supported — reconnection after 1006 is handled automatically.
157
+ * Not supported — reconnection after a dropped connection is handled automatically.
145
158
  * To start a new conversation, create a new socket via client.conversations.connect().
146
159
  */
147
160
  connect() {
148
161
  throw new Error("connect() is not supported on ReconnectableConversationsSocket. "
149
- + "Reconnection after 1006 is automatic. To start a new conversation, "
162
+ + "Reconnection after an abnormal close is automatic. To start a new conversation, "
150
163
  + "call client.conversations.connect() again.");
151
164
  }
152
165
  close() {
@@ -225,7 +238,7 @@ class ReconnectableConversationsSocket {
225
238
  catch (_d) {
226
239
  this._pendingReplacement = false;
227
240
  // Connection failed — schedule another attempt.
228
- // The server's grace period (10s) is the natural limit;
241
+ // The server's grace period (30s) is the natural limit;
229
242
  // once it expires, the next attempt will get 4800 and stop.
230
243
  this._scheduleReconnect();
231
244
  }
@@ -265,7 +278,7 @@ class ReconnectableConversationsSocket {
265
278
  if (this._isClosed) {
266
279
  return;
267
280
  }
268
- if (event.code === ABNORMAL_CLOSURE && this._conversationId !== null) {
281
+ if (isReconnectableClose(event.code, event.reason) && this._conversationId !== null) {
269
282
  // We have a conversation to resume — cancel RWS's built-in
270
283
  // auto-reconnect and handle it ourselves with reconnect_conv_id.
271
284
  // _handleClose calls _connect() before notifying listeners,
@@ -275,8 +288,8 @@ class ReconnectableConversationsSocket {
275
288
  rawSocket.close();
276
289
  this._scheduleReconnect();
277
290
  }
278
- // 1006 without conversationId: let RWS handle transport-level
279
- // reconnect normally (starts a fresh conversation).
291
+ // Reconnectable close without conversationId: let RWS handle
292
+ // transport-level reconnect normally (starts a fresh conversation).
280
293
  };
281
294
  rawSocket.addEventListener("message", onMessage);
282
295
  rawSocket.addEventListener("close", onClose);
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.32.9";
1
+ export declare const SDK_VERSION = "0.32.11";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = "0.32.9";
4
+ exports.SDK_VERSION = "0.32.11";
@@ -6,8 +6,8 @@ export function normalizeClientOptions(options) {
6
6
  const headers = mergeHeaders({
7
7
  "X-Fern-Language": "JavaScript",
8
8
  "X-Fern-SDK-Name": "phonic",
9
- "X-Fern-SDK-Version": "0.32.9",
10
- "User-Agent": "phonic/0.32.9",
9
+ "X-Fern-SDK-Version": "0.32.11",
10
+ "User-Agent": "phonic/0.32.11",
11
11
  "X-Fern-Runtime": core.RUNTIME.type,
12
12
  "X-Fern-Runtime-Version": core.RUNTIME.version,
13
13
  }, options === null || options === void 0 ? void 0 : options.headers);
@@ -15,8 +15,9 @@ import * as core from "./core/index.mjs";
15
15
  export declare namespace PhonicClient {
16
16
  type Options = BaseClientOptions & {
17
17
  /**
18
- * When `true`, conversation WebSockets automatically reconnect after an
19
- * abnormal disconnect (WebSocket close code 1006) using `reconnect_conv_id`.
18
+ * **Experimental.** When `true`, conversation WebSockets automatically
19
+ * reconnect and resume after a non-deliberate disconnect (WebSocket close
20
+ * codes 1006, 1012, or 1001/"restarting") using `reconnect_conv_id`.
20
21
  * Defaults to `false` until the behavior is broadly validated in production;
21
22
  * set to `true` to opt in early.
22
23
  */
@@ -83,6 +83,8 @@ export interface AgentsCreateRequest {
83
83
  template_variables?: Record<string, Phonic.CreateAgentRequest.TemplateVariables.Value>;
84
84
  /** Array of built-in or custom tool names to use. */
85
85
  tools?: Phonic.CreateAgentRequest.Tools.Item[];
86
+ /** Configuration overrides for built-in tools, keyed by built-in tool ID. Built-in tools not listed here use their default configuration. */
87
+ built_in_tool_configs?: Phonic.BuiltInToolConfigs;
86
88
  /** Array of task objects with `name` and `description` fields. */
87
89
  tasks?: Phonic.Task[];
88
90
  /** Whether to have the no-input poke text be generated by AI. */
@@ -83,6 +83,8 @@ export interface UpdateAgentRequest {
83
83
  template_variables?: Record<string, UpdateAgentRequest.TemplateVariables.Value>;
84
84
  /** Array of built-in or custom tool names to use. */
85
85
  tools?: UpdateAgentRequest.Tools.Item[];
86
+ /** Configuration overrides for built-in tools, keyed by built-in tool ID. Built-in tools not listed here use their default configuration. */
87
+ built_in_tool_configs?: Phonic.BuiltInToolConfigs;
86
88
  /** Array of task objects with `name` and `description` fields. */
87
89
  tasks?: Phonic.Task[];
88
90
  /** Whether to have the no-input poke text be generated by AI. */
@@ -6,9 +6,9 @@ import { ConversationsSocket } from "./Socket.mjs";
6
6
  export declare namespace ConversationsClient {
7
7
  type Options = BaseClientOptions & {
8
8
  /**
9
- * When `true`, `connect()` uses session-aware reconnection on abnormal
10
- * disconnect (1006). Set via `PhonicClient` options as
11
- * `reconnectConversationOnAbnormalDisconnect`.
9
+ * **Experimental.** When `true`, `connect()` uses session-aware reconnection
10
+ * on a non-deliberate disconnect (close codes 1006, 1012, or 1001/"restarting").
11
+ * Set via `PhonicClient` options as `reconnectConversationOnAbnormalDisconnect`.
12
12
  */
13
13
  reconnectConversationOnAbnormalDisconnect?: boolean;
14
14
  };
@@ -141,6 +141,8 @@ export interface CreateToolRequest {
141
141
  agents_to_transfer_to?: string[];
142
142
  /** When true, forces the agent to speak before executing the tool. */
143
143
  require_speech_before_tool_call?: boolean;
144
+ /** For built_in_natural_conversation_ending and built_in_keypad_input tools. Whether the agent must speak before calling the tool ("required"), the model decides ("optional"), or the agent must stay silent ("suppressed"). Not used by other tool types. */
145
+ speech_before_tool_call?: CreateToolRequest.SpeechBeforeToolCall;
144
146
  /** If true, the agent will wait to finish speaking before executing the tool. This is only available for custom_webhook and custom_websocket tools. */
145
147
  wait_for_speech_before_tool_call?: boolean;
146
148
  /** When true, forbids the agent from speaking after executing the tool. Available for custom_context, custom_webhook and custom_websocket tools. */
@@ -160,6 +162,9 @@ export declare namespace CreateToolRequest {
160
162
  readonly CustomWebsocket: "custom_websocket";
161
163
  readonly BuiltInTransferToPhoneNumber: "built_in_transfer_to_phone_number";
162
164
  readonly BuiltInTransferToAgent: "built_in_transfer_to_agent";
165
+ readonly BuiltInNaturalConversationEnding: "built_in_natural_conversation_ending";
166
+ readonly BuiltInKeypadInput: "built_in_keypad_input";
167
+ readonly BuiltInChooseNotToRespond: "built_in_choose_not_to_respond";
163
168
  };
164
169
  type Type = (typeof Type)[keyof typeof Type];
165
170
  /** Mode of operation. */
@@ -174,4 +179,11 @@ export declare namespace CreateToolRequest {
174
179
  readonly Post: "POST";
175
180
  };
176
181
  type EndpointMethod = (typeof EndpointMethod)[keyof typeof EndpointMethod];
182
+ /** For built_in_natural_conversation_ending and built_in_keypad_input tools. Whether the agent must speak before calling the tool ("required"), the model decides ("optional"), or the agent must stay silent ("suppressed"). Not used by other tool types. */
183
+ const SpeechBeforeToolCall: {
184
+ readonly Required: "required";
185
+ readonly Optional: "optional";
186
+ readonly Suppressed: "suppressed";
187
+ };
188
+ type SpeechBeforeToolCall = (typeof SpeechBeforeToolCall)[keyof typeof SpeechBeforeToolCall];
177
189
  }
@@ -8,6 +8,9 @@ export var CreateToolRequest;
8
8
  CustomWebsocket: "custom_websocket",
9
9
  BuiltInTransferToPhoneNumber: "built_in_transfer_to_phone_number",
10
10
  BuiltInTransferToAgent: "built_in_transfer_to_agent",
11
+ BuiltInNaturalConversationEnding: "built_in_natural_conversation_ending",
12
+ BuiltInKeypadInput: "built_in_keypad_input",
13
+ BuiltInChooseNotToRespond: "built_in_choose_not_to_respond",
11
14
  };
12
15
  /** Mode of operation. */
13
16
  CreateToolRequest.ExecutionMode = {
@@ -19,4 +22,10 @@ export var CreateToolRequest;
19
22
  Get: "GET",
20
23
  Post: "POST",
21
24
  };
25
+ /** For built_in_natural_conversation_ending and built_in_keypad_input tools. Whether the agent must speak before calling the tool ("required"), the model decides ("optional"), or the agent must stay silent ("suppressed"). Not used by other tool types. */
26
+ CreateToolRequest.SpeechBeforeToolCall = {
27
+ Required: "required",
28
+ Optional: "optional",
29
+ Suppressed: "suppressed",
30
+ };
22
31
  })(CreateToolRequest || (CreateToolRequest = {}));
@@ -49,6 +49,8 @@ export interface UpdateToolRequest {
49
49
  agents_to_transfer_to?: string[];
50
50
  /** When true, forces the agent to speak before executing the tool. */
51
51
  require_speech_before_tool_call?: boolean;
52
+ /** For built_in_natural_conversation_ending and built_in_keypad_input tools. Whether the agent must speak before calling the tool ("required"), the model decides ("optional"), or the agent must stay silent ("suppressed"). Not used by other tool types. */
53
+ speech_before_tool_call?: UpdateToolRequest.SpeechBeforeToolCall;
52
54
  /** If true, the agent will wait to finish speaking before executing the tool. This is only available for custom_webhook and custom_websocket tools. */
53
55
  wait_for_speech_before_tool_call?: boolean;
54
56
  /** When true, forbids the agent from speaking after executing the tool. Available for custom_context, custom_webhook and custom_websocket tools. */
@@ -71,4 +73,11 @@ export declare namespace UpdateToolRequest {
71
73
  readonly Post: "POST";
72
74
  };
73
75
  type EndpointMethod = (typeof EndpointMethod)[keyof typeof EndpointMethod];
76
+ /** For built_in_natural_conversation_ending and built_in_keypad_input tools. Whether the agent must speak before calling the tool ("required"), the model decides ("optional"), or the agent must stay silent ("suppressed"). Not used by other tool types. */
77
+ const SpeechBeforeToolCall: {
78
+ readonly Required: "required";
79
+ readonly Optional: "optional";
80
+ readonly Suppressed: "suppressed";
81
+ };
82
+ type SpeechBeforeToolCall = (typeof SpeechBeforeToolCall)[keyof typeof SpeechBeforeToolCall];
74
83
  }
@@ -11,4 +11,10 @@ export var UpdateToolRequest;
11
11
  Get: "GET",
12
12
  Post: "POST",
13
13
  };
14
+ /** For built_in_natural_conversation_ending and built_in_keypad_input tools. Whether the agent must speak before calling the tool ("required"), the model decides ("optional"), or the agent must stay silent ("suppressed"). Not used by other tool types. */
15
+ UpdateToolRequest.SpeechBeforeToolCall = {
16
+ Required: "required",
17
+ Optional: "optional",
18
+ Suppressed: "suppressed",
19
+ };
14
20
  })(UpdateToolRequest || (UpdateToolRequest = {}));
@@ -36,6 +36,8 @@ export interface Agent {
36
36
  template_variables: Record<string, Agent.TemplateVariables.Value>;
37
37
  /** List of tools available to the agent. */
38
38
  tools: Agent.Tools.Item[];
39
+ /** Configuration overrides for built-in tools, keyed by built-in tool ID. */
40
+ built_in_tool_configs: Phonic.BuiltInToolConfigs;
39
41
  /** Tasks for the agent to complete during the conversation. */
40
42
  tasks: Phonic.Task[];
41
43
  /** Whether to have the no-input poke text be generated by AI. */
@@ -1,6 +1,6 @@
1
1
  export interface AudioChunkPayload {
2
2
  type: "audio_chunk";
3
- /** Base64-encoded audio data (Int16Array for PCM, Uint8Array for mulaw) */
3
+ /** Base64-encoded audio data (Int16Array for PCM, Uint8Array for mulaw). Each chunk may contain at most 40 ms of audio — longer chunks are rejected with an error. Batch ~20 ms frames for headroom. */
4
4
  audio: string;
5
5
  /** ISO 8601 timestamp (required for first chunk only) */
6
6
  iso_date_time?: string | undefined;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Configuration for a simple built-in tool (`keypad_input`, `natural_conversation_ending`, or `choose_not_to_respond`).
3
+ */
4
+ export interface BuiltInToolConfig {
5
+ /** Controls whether the assistant speaks before the tool is called. `required`: the assistant must speak first. `optional`: the model decides. `suppressed`: the assistant is strongly instructed to stay silent before the call (best effort). */
6
+ speech_before_tool_call: BuiltInToolConfig.SpeechBeforeToolCall;
7
+ }
8
+ export declare namespace BuiltInToolConfig {
9
+ /** Controls whether the assistant speaks before the tool is called. `required`: the assistant must speak first. `optional`: the model decides. `suppressed`: the assistant is strongly instructed to stay silent before the call (best effort). */
10
+ const SpeechBeforeToolCall: {
11
+ readonly Required: "required";
12
+ readonly Optional: "optional";
13
+ readonly Suppressed: "suppressed";
14
+ };
15
+ type SpeechBeforeToolCall = (typeof SpeechBeforeToolCall)[keyof typeof SpeechBeforeToolCall];
16
+ }
@@ -0,0 +1,10 @@
1
+ // This file was auto-generated by Fern from our API Definition.
2
+ export var BuiltInToolConfig;
3
+ (function (BuiltInToolConfig) {
4
+ /** Controls whether the assistant speaks before the tool is called. `required`: the assistant must speak first. `optional`: the model decides. `suppressed`: the assistant is strongly instructed to stay silent before the call (best effort). */
5
+ BuiltInToolConfig.SpeechBeforeToolCall = {
6
+ Required: "required",
7
+ Optional: "optional",
8
+ Suppressed: "suppressed",
9
+ };
10
+ })(BuiltInToolConfig || (BuiltInToolConfig = {}));
@@ -0,0 +1,5 @@
1
+ import type * as Phonic from "../index.mjs";
2
+ /**
3
+ * Per-tool configuration overrides for built-in tools, keyed by built-in tool ID (e.g. `tool_natural_conversation_ending`). A built-in tool referenced in `tools` but absent from this map uses its default configuration.
4
+ */
5
+ export type BuiltInToolConfigs = Record<string, Phonic.BuiltInToolConfig>;
@@ -0,0 +1,2 @@
1
+ // This file was auto-generated by Fern from our API Definition.
2
+ export {};
@@ -0,0 +1,18 @@
1
+ import type * as Phonic from "../index.mjs";
2
+ /**
3
+ * A built-in tool with an explicit configuration, as an alternative to referencing it by bare name (which uses the tool's default configuration). Only `keypad_input` and `natural_conversation_ending` accept configuration this way.
4
+ */
5
+ export interface BuiltInToolDefinition {
6
+ type: "built_in";
7
+ /** The name of the built-in tool. */
8
+ name: BuiltInToolDefinition.Name;
9
+ tool_config: Phonic.BuiltInToolConfig;
10
+ }
11
+ export declare namespace BuiltInToolDefinition {
12
+ /** The name of the built-in tool. */
13
+ const Name: {
14
+ readonly KeypadInput: "keypad_input";
15
+ readonly NaturalConversationEnding: "natural_conversation_ending";
16
+ };
17
+ type Name = (typeof Name)[keyof typeof Name];
18
+ }
@@ -0,0 +1,9 @@
1
+ // This file was auto-generated by Fern from our API Definition.
2
+ export var BuiltInToolDefinition;
3
+ (function (BuiltInToolDefinition) {
4
+ /** The name of the built-in tool. */
5
+ BuiltInToolDefinition.Name = {
6
+ KeypadInput: "keypad_input",
7
+ NaturalConversationEnding: "natural_conversation_ending",
8
+ };
9
+ })(BuiltInToolDefinition || (BuiltInToolDefinition = {}));
@@ -65,7 +65,7 @@ export interface ConfigOptions {
65
65
  boosted_keywords?: string[] | undefined;
66
66
  /** Array of `{ word, pronunciation }` entries. Words must be unique. */
67
67
  pronunciation_dictionary?: ConfigOptions.PronunciationDictionary.Item[] | undefined;
68
- /** Tools available to the assistant. Use a string to reference a pre-defined tool by name, or define an inline WebSocket tool for this conversation. */
68
+ /** Tools available to the assistant. Use a string to reference a pre-defined tool by name, provide a built-in tool object to override its default configuration, or define an inline WebSocket tool for this conversation. */
69
69
  tools?: Phonic.ToolDefinition[] | undefined;
70
70
  /** Template variables for system prompt and welcome message */
71
71
  template_variables?: Record<string, string> | undefined;
@@ -36,6 +36,8 @@ export interface CreateAgentRequest {
36
36
  template_variables?: Record<string, CreateAgentRequest.TemplateVariables.Value> | undefined;
37
37
  /** Array of built-in or custom tool names to use. */
38
38
  tools?: CreateAgentRequest.Tools.Item[] | undefined;
39
+ /** Configuration overrides for built-in tools, keyed by built-in tool ID. Built-in tools not listed here use their default configuration. */
40
+ built_in_tool_configs?: Phonic.BuiltInToolConfigs | undefined;
39
41
  /** Array of task objects with `name` and `description` fields. */
40
42
  tasks?: Phonic.Task[] | undefined;
41
43
  /** Whether to have the no-input poke text be generated by AI. */
@@ -2,4 +2,6 @@ export interface GenerateReplyPayload {
2
2
  type: "generate_reply";
3
3
  /** Optional system message to guide the assistant's reply */
4
4
  system_message?: (string | null) | undefined;
5
+ /** Optional user message for the assistant to reply to */
6
+ user_message?: (string | null) | undefined;
5
7
  }
@@ -37,6 +37,8 @@ export interface Tool {
37
37
  agents_to_transfer_to?: string[] | undefined;
38
38
  /** When true, forces the agent to speak before executing the tool. */
39
39
  require_speech_before_tool_call?: boolean | undefined;
40
+ /** For built_in_natural_conversation_ending and built_in_keypad_input tools. Whether the agent must speak before calling the tool ("required"), the model decides ("optional"), or the agent must stay silent ("suppressed"). Not used by other tool types. */
41
+ speech_before_tool_call?: Tool.SpeechBeforeToolCall | undefined;
40
42
  /** If true, the agent will wait to finish speaking before executing the tool. This is only available for custom_webhook and custom_websocket tools. */
41
43
  wait_for_speech_before_tool_call?: boolean | undefined;
42
44
  /** When true, forbids the agent from speaking after executing the tool. Available for custom_context, custom_webhook and custom_websocket tools. */
@@ -60,6 +62,9 @@ export declare namespace Tool {
60
62
  readonly CustomWebsocket: "custom_websocket";
61
63
  readonly BuiltInTransferToPhoneNumber: "built_in_transfer_to_phone_number";
62
64
  readonly BuiltInTransferToAgent: "built_in_transfer_to_agent";
65
+ readonly BuiltInNaturalConversationEnding: "built_in_natural_conversation_ending";
66
+ readonly BuiltInKeypadInput: "built_in_keypad_input";
67
+ readonly BuiltInChooseNotToRespond: "built_in_choose_not_to_respond";
63
68
  };
64
69
  type Type = (typeof Type)[keyof typeof Type];
65
70
  /** Mode of operation - sync waits for response, async continues without waiting. */
@@ -74,4 +79,11 @@ export declare namespace Tool {
74
79
  readonly Post: "POST";
75
80
  };
76
81
  type EndpointMethod = (typeof EndpointMethod)[keyof typeof EndpointMethod];
82
+ /** For built_in_natural_conversation_ending and built_in_keypad_input tools. Whether the agent must speak before calling the tool ("required"), the model decides ("optional"), or the agent must stay silent ("suppressed"). Not used by other tool types. */
83
+ const SpeechBeforeToolCall: {
84
+ readonly Required: "required";
85
+ readonly Optional: "optional";
86
+ readonly Suppressed: "suppressed";
87
+ };
88
+ type SpeechBeforeToolCall = (typeof SpeechBeforeToolCall)[keyof typeof SpeechBeforeToolCall];
77
89
  }
@@ -8,6 +8,9 @@ export var Tool;
8
8
  CustomWebsocket: "custom_websocket",
9
9
  BuiltInTransferToPhoneNumber: "built_in_transfer_to_phone_number",
10
10
  BuiltInTransferToAgent: "built_in_transfer_to_agent",
11
+ BuiltInNaturalConversationEnding: "built_in_natural_conversation_ending",
12
+ BuiltInKeypadInput: "built_in_keypad_input",
13
+ BuiltInChooseNotToRespond: "built_in_choose_not_to_respond",
11
14
  };
12
15
  /** Mode of operation - sync waits for response, async continues without waiting. */
13
16
  Tool.ExecutionMode = {
@@ -19,4 +22,10 @@ export var Tool;
19
22
  Get: "GET",
20
23
  Post: "POST",
21
24
  };
25
+ /** For built_in_natural_conversation_ending and built_in_keypad_input tools. Whether the agent must speak before calling the tool ("required"), the model decides ("optional"), or the agent must stay silent ("suppressed"). Not used by other tool types. */
26
+ Tool.SpeechBeforeToolCall = {
27
+ Required: "required",
28
+ Optional: "optional",
29
+ Suppressed: "suppressed",
30
+ };
22
31
  })(Tool || (Tool = {}));
@@ -1,2 +1,2 @@
1
1
  import type * as Phonic from "../index.mjs";
2
- export type ToolDefinition = Phonic.ToolName | Phonic.InlineWebSocketTool;
2
+ export type ToolDefinition = Phonic.ToolName | Phonic.BuiltInToolDefinition | Phonic.InlineWebSocketTool;
@@ -10,6 +10,9 @@ export * from "./AudioChunkPayload.mjs";
10
10
  export * from "./AudioChunkResponsePayload.mjs";
11
11
  export * from "./BadRequestErrorBody.mjs";
12
12
  export * from "./BasicError.mjs";
13
+ export * from "./BuiltInToolConfig.mjs";
14
+ export * from "./BuiltInToolConfigs.mjs";
15
+ export * from "./BuiltInToolDefinition.mjs";
13
16
  export * from "./ConfigOptions.mjs";
14
17
  export * from "./ConfigPayload.mjs";
15
18
  export * from "./Conversation.mjs";
@@ -10,6 +10,9 @@ export * from "./AudioChunkPayload.mjs";
10
10
  export * from "./AudioChunkResponsePayload.mjs";
11
11
  export * from "./BadRequestErrorBody.mjs";
12
12
  export * from "./BasicError.mjs";
13
+ export * from "./BuiltInToolConfig.mjs";
14
+ export * from "./BuiltInToolConfigs.mjs";
15
+ export * from "./BuiltInToolDefinition.mjs";
13
16
  export * from "./ConfigOptions.mjs";
14
17
  export * from "./ConfigPayload.mjs";
15
18
  export * from "./Conversation.mjs";
@@ -2,7 +2,7 @@ import * as core from "../core/index.mjs";
2
2
  import type * as Phonic from "../api/index.mjs";
3
3
  import { ConversationsSocket } from "../api/resources/conversations/client/Socket.mjs";
4
4
  export interface ReconnectableConversationsSocketArgs {
5
- /** Called on 1006 to create a new socket with reconnect_conv_id. May be async (e.g. fresh auth). */
5
+ /** Called on a reconnectable close to create a new socket with reconnect_conv_id. May be async (e.g. fresh auth). */
6
6
  createReconnectSocket: (conversationId: string) => core.ReconnectingWebSocket | Promise<core.ReconnectingWebSocket>;
7
7
  /** Initial socket for the first connection. */
8
8
  socket: core.ReconnectingWebSocket;
@@ -16,9 +16,10 @@ type EventHandlers = {
16
16
  error?: (error: Error) => void;
17
17
  };
18
18
  /**
19
- * Wraps ConversationsSocket with automatic reconnection on 1006.
19
+ * Wraps ConversationsSocket with automatic reconnection on a reconnectable
20
+ * close (1006, 1012, or 1001/"restarting" — see isReconnectableClose).
20
21
  *
21
- * On abnormal closure, creates a brand new ReconnectingWebSocket (via the
22
+ * On such a close, creates a brand new ReconnectingWebSocket (via the
22
23
  * createReconnectSocket factory) and wraps it in a fresh ConversationsSocket,
23
24
  * forwarding all events to user-registered handlers.
24
25
  *
@@ -60,7 +61,7 @@ export declare class ReconnectableConversationsSocket {
60
61
  sendMute(message: Phonic.MutePayload): void;
61
62
  sendUnmute(message: Phonic.UnmutePayload): void;
62
63
  /**
63
- * Not supported — reconnection after 1006 is handled automatically.
64
+ * Not supported — reconnection after a dropped connection is handled automatically.
64
65
  * To start a new conversation, create a new socket via client.conversations.connect().
65
66
  */
66
67
  connect(): never;
@@ -10,20 +10,33 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import * as core from "../core/index.mjs";
11
11
  import { ConversationsSocket } from "../api/resources/conversations/client/Socket.mjs";
12
12
  import { fromJson } from "../core/json.mjs";
13
- /** 1006 is the only close code that indicates an unexpected disconnect
14
- * worth reconnecting for. All other codes (1000, 4000, 4800, etc.)
15
- * are intentional server-side closes. */
16
13
  const ABNORMAL_CLOSURE = 1006;
14
+ const SERVICE_RESTART = 1012;
15
+ const GOING_AWAY = 1001;
16
+ /** Whether a close means the disconnect was NOT a deliberate end of the
17
+ * conversation, so the SDK should transparently reconnect and resume it:
18
+ * - 1006 abnormal closure (socket died with no close frame)
19
+ * - 1012 service restart — an edge proxy/load-balancer restart closes the
20
+ * client with 1012/"restarting"; the conversation is still alive
21
+ * server-side within the grace window
22
+ * - 1001 "going away" ONLY when the reason is "restarting" — a proxy drain
23
+ * can surface to the client as 1001/"restarting" instead of 1012. A bare
24
+ * 1001 (empty/other reason) is a deliberate close (the caller ended the
25
+ * conversation, tab closed/suspended) and must NOT reconnect.
26
+ * Matches the server's reconnect policy. All other codes (1000, 4000,
27
+ * 4800, ...) are intentional closes. */
28
+ const isReconnectableClose = (code, reason) => code === ABNORMAL_CLOSURE || code === SERVICE_RESTART || (code === GOING_AWAY && reason === "restarting");
17
29
  const BASE_RECONNECT_DELAY_MS = 500;
18
30
  const MAX_RECONNECT_DELAY_MS = 5000;
19
31
  /** Safety cap: stop retrying if the server is completely unreachable.
20
32
  * In normal operation the server's terminal codes (4800/4801) stop
21
- * retries much sooner (within the 10s grace period). */
33
+ * retries much sooner (within the 30s grace period). */
22
34
  const MAX_RECONNECT_ATTEMPTS = 10;
23
35
  /**
24
- * Wraps ConversationsSocket with automatic reconnection on 1006.
36
+ * Wraps ConversationsSocket with automatic reconnection on a reconnectable
37
+ * close (1006, 1012, or 1001/"restarting" — see isReconnectableClose).
25
38
  *
26
- * On abnormal closure, creates a brand new ReconnectingWebSocket (via the
39
+ * On such a close, creates a brand new ReconnectingWebSocket (via the
27
40
  * createReconnectSocket factory) and wraps it in a fresh ConversationsSocket,
28
41
  * forwarding all events to user-registered handlers.
29
42
  *
@@ -105,12 +118,12 @@ export class ReconnectableConversationsSocket {
105
118
  this._safeSend((inner) => inner.sendUnmute(message));
106
119
  }
107
120
  /**
108
- * Not supported — reconnection after 1006 is handled automatically.
121
+ * Not supported — reconnection after a dropped connection is handled automatically.
109
122
  * To start a new conversation, create a new socket via client.conversations.connect().
110
123
  */
111
124
  connect() {
112
125
  throw new Error("connect() is not supported on ReconnectableConversationsSocket. "
113
- + "Reconnection after 1006 is automatic. To start a new conversation, "
126
+ + "Reconnection after an abnormal close is automatic. To start a new conversation, "
114
127
  + "call client.conversations.connect() again.");
115
128
  }
116
129
  close() {
@@ -189,7 +202,7 @@ export class ReconnectableConversationsSocket {
189
202
  catch (_d) {
190
203
  this._pendingReplacement = false;
191
204
  // Connection failed — schedule another attempt.
192
- // The server's grace period (10s) is the natural limit;
205
+ // The server's grace period (30s) is the natural limit;
193
206
  // once it expires, the next attempt will get 4800 and stop.
194
207
  this._scheduleReconnect();
195
208
  }
@@ -229,7 +242,7 @@ export class ReconnectableConversationsSocket {
229
242
  if (this._isClosed) {
230
243
  return;
231
244
  }
232
- if (event.code === ABNORMAL_CLOSURE && this._conversationId !== null) {
245
+ if (isReconnectableClose(event.code, event.reason) && this._conversationId !== null) {
233
246
  // We have a conversation to resume — cancel RWS's built-in
234
247
  // auto-reconnect and handle it ourselves with reconnect_conv_id.
235
248
  // _handleClose calls _connect() before notifying listeners,
@@ -239,8 +252,8 @@ export class ReconnectableConversationsSocket {
239
252
  rawSocket.close();
240
253
  this._scheduleReconnect();
241
254
  }
242
- // 1006 without conversationId: let RWS handle transport-level
243
- // reconnect normally (starts a fresh conversation).
255
+ // Reconnectable close without conversationId: let RWS handle
256
+ // transport-level reconnect normally (starts a fresh conversation).
244
257
  };
245
258
  rawSocket.addEventListener("message", onMessage);
246
259
  rawSocket.addEventListener("close", onClose);
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.32.9";
1
+ export declare const SDK_VERSION = "0.32.11";
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.32.9";
1
+ export const SDK_VERSION = "0.32.11";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phonic",
3
- "version": "0.32.9",
3
+ "version": "0.32.11",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",