phonic 0.31.8 → 0.31.10
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 +1 -0
- package/dist/cjs/BaseClient.js +2 -2
- package/dist/cjs/Client.d.ts +9 -1
- package/dist/cjs/Client.js +1 -1
- package/dist/cjs/api/resources/agents/client/Client.d.ts +3 -0
- package/dist/cjs/api/resources/agents/client/Client.js +3 -0
- package/dist/cjs/api/resources/agents/client/requests/AgentsCreateRequest.d.ts +3 -0
- package/dist/cjs/api/resources/agents/client/requests/UpdateAgentRequest.d.ts +3 -0
- package/dist/cjs/api/resources/agents/client/requests/UpsertAgentRequest.d.ts +1 -0
- package/dist/cjs/api/resources/conversations/client/Client.d.ts +8 -1
- package/dist/cjs/api/resources/conversations/client/Client.js +37 -3
- package/dist/cjs/api/resources/conversations/client/Socket.d.ts +2 -1
- package/dist/cjs/api/resources/conversations/client/Socket.js +4 -0
- package/dist/cjs/api/resources/conversations/client/requests/ConversationsSipOutboundCallRequest.d.ts +2 -0
- package/dist/cjs/api/resources/conversations/client/requests/OutboundCallRequest.d.ts +5 -1
- package/dist/cjs/api/resources/conversations/types/ConversationsOutboundCallResponse.d.ts +2 -4
- package/dist/cjs/api/resources/conversations/types/ConversationsSipOutboundCallResponse.d.ts +2 -6
- package/dist/cjs/api/types/Agent.d.ts +2 -0
- package/dist/cjs/api/types/ConfigOptions.d.ts +94 -0
- package/dist/cjs/api/types/ConfigOptions.js +32 -0
- package/dist/cjs/api/types/ConfigPayload.d.ts +2 -88
- package/dist/cjs/api/types/ConfigPayload.js +0 -29
- package/dist/cjs/api/types/Conversation.d.ts +2 -0
- package/dist/cjs/api/types/CreateAgentRequest.d.ts +2 -0
- package/dist/cjs/api/types/OutboundCallConfig.d.ts +2 -0
- package/dist/cjs/api/types/OutboundCallInitiatedResponse.d.ts +6 -0
- package/dist/cjs/api/types/{InterruptedResponsePayload.js → OutboundCallInitiatedResponse.js} +1 -3
- package/dist/cjs/api/types/OutboundDryRunResponse.d.ts +6 -0
- package/dist/cjs/api/{resources/agents/client/requests/AgentsRemoveCustomPhoneNumberRequest.js → types/OutboundDryRunResponse.js} +1 -3
- package/dist/cjs/api/types/ResetPayload.d.ts +5 -0
- package/dist/cjs/api/types/{AudioFinishedPayload.js → ResetPayload.js} +1 -3
- package/dist/cjs/api/types/SipOutboundCallInitiatedResponse.d.ts +8 -0
- package/dist/cjs/api/{resources/agents/types/AgentsRemoveCustomPhoneNumberResponse.js → types/SipOutboundCallInitiatedResponse.js} +1 -3
- package/dist/cjs/api/types/SipOutboundDryRunResponse.d.ts +8 -0
- package/dist/cjs/api/types/SipOutboundDryRunResponse.js +3 -0
- package/dist/cjs/api/types/index.d.ts +6 -0
- package/dist/cjs/api/types/index.js +6 -0
- package/dist/cjs/custom/ReconnectableConversationsSocket.d.ts +74 -0
- package/dist/cjs/custom/ReconnectableConversationsSocket.js +283 -0
- package/dist/cjs/custom/index.d.ts +1 -0
- package/dist/cjs/custom/index.js +5 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.mjs +2 -2
- package/dist/esm/Client.d.mts +9 -1
- package/dist/esm/Client.mjs +1 -1
- package/dist/esm/api/resources/agents/client/Client.d.mts +3 -0
- package/dist/esm/api/resources/agents/client/Client.mjs +3 -0
- package/dist/esm/api/resources/agents/client/requests/AgentsCreateRequest.d.mts +3 -0
- package/dist/esm/api/resources/agents/client/requests/UpdateAgentRequest.d.mts +3 -0
- package/dist/esm/api/resources/agents/client/requests/UpsertAgentRequest.d.mts +1 -0
- package/dist/esm/api/resources/conversations/client/Client.d.mts +8 -1
- package/dist/esm/api/resources/conversations/client/Client.mjs +37 -3
- package/dist/esm/api/resources/conversations/client/Socket.d.mts +2 -1
- package/dist/esm/api/resources/conversations/client/Socket.mjs +4 -0
- package/dist/esm/api/resources/conversations/client/requests/ConversationsSipOutboundCallRequest.d.mts +2 -0
- package/dist/esm/api/resources/conversations/client/requests/OutboundCallRequest.d.mts +5 -1
- package/dist/esm/api/resources/conversations/types/ConversationsOutboundCallResponse.d.mts +2 -4
- package/dist/esm/api/resources/conversations/types/ConversationsSipOutboundCallResponse.d.mts +2 -6
- package/dist/esm/api/types/Agent.d.mts +2 -0
- package/dist/esm/api/types/ConfigOptions.d.mts +94 -0
- package/dist/esm/api/types/ConfigOptions.mjs +29 -0
- package/dist/esm/api/types/ConfigPayload.d.mts +2 -88
- package/dist/esm/api/types/ConfigPayload.mjs +1 -28
- package/dist/esm/api/types/Conversation.d.mts +2 -0
- package/dist/esm/api/types/CreateAgentRequest.d.mts +2 -0
- package/dist/esm/api/types/OutboundCallConfig.d.mts +2 -0
- package/dist/esm/api/types/OutboundCallInitiatedResponse.d.mts +6 -0
- package/dist/esm/api/types/OutboundCallInitiatedResponse.mjs +2 -0
- package/dist/esm/api/types/OutboundDryRunResponse.d.mts +6 -0
- package/dist/esm/api/types/OutboundDryRunResponse.mjs +2 -0
- package/dist/esm/api/types/ResetPayload.d.mts +5 -0
- package/dist/esm/api/types/ResetPayload.mjs +2 -0
- package/dist/esm/api/types/SipOutboundCallInitiatedResponse.d.mts +8 -0
- package/dist/esm/api/types/SipOutboundCallInitiatedResponse.mjs +2 -0
- package/dist/esm/api/types/SipOutboundDryRunResponse.d.mts +8 -0
- package/dist/esm/api/types/SipOutboundDryRunResponse.mjs +2 -0
- package/dist/esm/api/types/index.d.mts +6 -0
- package/dist/esm/api/types/index.mjs +6 -0
- package/dist/esm/custom/ReconnectableConversationsSocket.d.mts +74 -0
- package/dist/esm/custom/ReconnectableConversationsSocket.mjs +246 -0
- package/dist/esm/custom/index.d.mts +1 -0
- package/dist/esm/custom/index.mjs +1 -0
- package/dist/esm/index.d.mts +1 -0
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +1 -1
- package/reference.md +6 -1
- package/dist/cjs/api/resources/agents/client/requests/AgentsRemoveCustomPhoneNumberRequest.d.ts +0 -16
- package/dist/cjs/api/resources/agents/types/AgentsRemoveCustomPhoneNumberResponse.d.ts +0 -6
- package/dist/cjs/api/types/AudioFinishedPayload.d.ts +0 -6
- package/dist/cjs/api/types/InterruptedResponsePayload.d.ts +0 -8
- package/dist/cjs/api/types/IsUserSpeakingPayload.d.ts +0 -8
- package/dist/cjs/api/types/IsUserSpeakingPayload.js +0 -5
- package/dist/cjs/api/types/SetTwilioCallSidPayload.d.ts +0 -8
- package/dist/cjs/api/types/SetTwilioCallSidPayload.js +0 -5
- package/dist/cjs/core/fetcher/ResponseWithBody.d.ts +0 -4
- package/dist/cjs/core/fetcher/ResponseWithBody.js +0 -6
- package/dist/esm/api/resources/agents/client/requests/AgentsRemoveCustomPhoneNumberRequest.d.mts +0 -16
- package/dist/esm/api/resources/agents/client/requests/AgentsRemoveCustomPhoneNumberRequest.mjs +0 -4
- package/dist/esm/api/resources/agents/types/AgentsRemoveCustomPhoneNumberResponse.d.mts +0 -6
- package/dist/esm/api/resources/agents/types/AgentsRemoveCustomPhoneNumberResponse.mjs +0 -4
- package/dist/esm/api/types/AudioFinishedPayload.d.mts +0 -6
- package/dist/esm/api/types/AudioFinishedPayload.mjs +0 -4
- package/dist/esm/api/types/InterruptedResponsePayload.d.mts +0 -8
- package/dist/esm/api/types/InterruptedResponsePayload.mjs +0 -4
- package/dist/esm/api/types/IsUserSpeakingPayload.d.mts +0 -8
- package/dist/esm/api/types/IsUserSpeakingPayload.mjs +0 -4
- package/dist/esm/api/types/SetTwilioCallSidPayload.d.mts +0 -8
- package/dist/esm/api/types/SetTwilioCallSidPayload.mjs +0 -4
- package/dist/esm/core/fetcher/ResponseWithBody.d.mts +0 -4
- package/dist/esm/core/fetcher/ResponseWithBody.mjs +0 -3
- package/dist/index.d.mts +0 -686
- package/dist/index.d.ts +0 -686
- package/dist/index.js +0 -643
- package/dist/index.mjs +0 -606
|
@@ -26,6 +26,7 @@ import * as environments from "../../../../environments.mjs";
|
|
|
26
26
|
import { handleNonStatusCodeError } from "../../../../errors/handleNonStatusCodeError.mjs";
|
|
27
27
|
import * as errors from "../../../../errors/index.mjs";
|
|
28
28
|
import * as Phonic from "../../../index.mjs";
|
|
29
|
+
import { ReconnectableConversationsSocket } from "../../../../custom/ReconnectableConversationsSocket.mjs";
|
|
29
30
|
import { ConversationsSocket } from "./Socket.mjs";
|
|
30
31
|
export class ConversationsClient {
|
|
31
32
|
constructor(options = {}) {
|
|
@@ -714,11 +715,44 @@ export class ConversationsClient {
|
|
|
714
715
|
const _queryParams = {
|
|
715
716
|
downstream_websocket_url: downstreamWebsocketUrl,
|
|
716
717
|
};
|
|
718
|
+
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)
|
|
719
|
+
.production, "/v1/sts/ws");
|
|
720
|
+
if (this._options.reconnectConversationOnAbnormalDisconnect) {
|
|
721
|
+
const connectionTimeoutMs = connectionTimeoutInSeconds != null ? connectionTimeoutInSeconds * 1000 : undefined;
|
|
722
|
+
const createSocket = (reconnectConvId) => __awaiter(this, void 0, void 0, function* () {
|
|
723
|
+
var _a, _b, _c;
|
|
724
|
+
const freshAuth = yield this._options.authProvider.getAuthRequest();
|
|
725
|
+
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);
|
|
726
|
+
const isSessionReconnect = reconnectConvId != null;
|
|
727
|
+
return new core.ReconnectingWebSocket({
|
|
728
|
+
url: baseWsUrl,
|
|
729
|
+
protocols: protocols !== null && protocols !== void 0 ? protocols : [],
|
|
730
|
+
queryParameters: Object.assign(Object.assign(Object.assign({}, _queryParams), queryParams), (reconnectConvId ? { reconnect_conv_id: reconnectConvId } : {})),
|
|
731
|
+
headers: mergedHeaders,
|
|
732
|
+
options: {
|
|
733
|
+
debug: debug !== null && debug !== void 0 ? debug : false,
|
|
734
|
+
// Initial connection keeps transport retries; replacement sockets use 0 so only
|
|
735
|
+
// ReconnectableConversationsSocket performs session-level reconnect.
|
|
736
|
+
maxRetries: isSessionReconnect ? 0 : reconnectAttempts !== null && reconnectAttempts !== void 0 ? reconnectAttempts : 30,
|
|
737
|
+
connectionTimeout: connectionTimeoutMs,
|
|
738
|
+
},
|
|
739
|
+
// Only pass abortSignal to the initial socket. Reconnect sockets
|
|
740
|
+
// don't get it — each would register a new listener on the signal
|
|
741
|
+
// that's never removed, leaking memory over many reconnects.
|
|
742
|
+
abortSignal: isSessionReconnect ? undefined : abortSignal,
|
|
743
|
+
});
|
|
744
|
+
});
|
|
745
|
+
const initialSocket = yield createSocket();
|
|
746
|
+
return new ReconnectableConversationsSocket({
|
|
747
|
+
socket: initialSocket,
|
|
748
|
+
createReconnectSocket: (conversationId) => createSocket(conversationId),
|
|
749
|
+
abortSignal,
|
|
750
|
+
});
|
|
751
|
+
}
|
|
717
752
|
const _authRequest = yield this._options.authProvider.getAuthRequest();
|
|
718
|
-
const _headers = Object.assign(Object.assign(Object.assign({}, ((
|
|
753
|
+
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);
|
|
719
754
|
const socket = new core.ReconnectingWebSocket({
|
|
720
|
-
url:
|
|
721
|
-
.production, "/v1/sts/ws"),
|
|
755
|
+
url: baseWsUrl,
|
|
722
756
|
protocols: protocols !== null && protocols !== void 0 ? protocols : [],
|
|
723
757
|
queryParameters: Object.assign(Object.assign({}, _queryParams), queryParams),
|
|
724
758
|
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
|
}
|
|
@@ -86,6 +86,10 @@ export class ConversationsSocket {
|
|
|
86
86
|
this.assertSocketIsOpen();
|
|
87
87
|
this.sendJson(message);
|
|
88
88
|
}
|
|
89
|
+
sendReset(message) {
|
|
90
|
+
this.assertSocketIsOpen();
|
|
91
|
+
this.sendJson(message);
|
|
92
|
+
}
|
|
89
93
|
/** Connect to the websocket and register event handlers. */
|
|
90
94
|
connect() {
|
|
91
95
|
this.socket.reconnect();
|
|
@@ -19,4 +19,6 @@ export interface ConversationsSipOutboundCallRequest {
|
|
|
19
19
|
/** Destination phone number in E.164 format. */
|
|
20
20
|
to_phone_number: string;
|
|
21
21
|
config?: Phonic.OutboundCallConfig;
|
|
22
|
+
/** If true, validates the outbound call setup without placing a call. Returns HTTP 200 with `conversation_id` and `twilio_call_sid` set to null. */
|
|
23
|
+
dry_run?: boolean;
|
|
22
24
|
}
|
|
@@ -20,12 +20,16 @@ import type * as Phonic from "../../../../index.mjs";
|
|
|
20
20
|
* additional_languages: ["es"],
|
|
21
21
|
* multilingual_mode: "request",
|
|
22
22
|
* boosted_keywords: ["Load ID", "dispatch"],
|
|
23
|
+
* min_words_to_interrupt: 1,
|
|
23
24
|
* tools: ["keypad_input"]
|
|
24
|
-
* }
|
|
25
|
+
* },
|
|
26
|
+
* dry_run: false
|
|
25
27
|
* }
|
|
26
28
|
*/
|
|
27
29
|
export interface OutboundCallRequest {
|
|
28
30
|
/** The phone number to call in E.164 format. */
|
|
29
31
|
to_phone_number: string;
|
|
30
32
|
config?: Phonic.OutboundCallConfig;
|
|
33
|
+
/** If true, validates the outbound call setup without placing a call. Returns HTTP 200 with `conversation_id` set to null. */
|
|
34
|
+
dry_run?: boolean;
|
|
31
35
|
}
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
conversation_id: string;
|
|
4
|
-
}
|
|
1
|
+
import type * as Phonic from "../../../index.mjs";
|
|
2
|
+
export type ConversationsOutboundCallResponse = Phonic.OutboundDryRunResponse | Phonic.OutboundCallInitiatedResponse;
|
package/dist/esm/api/resources/conversations/types/ConversationsSipOutboundCallResponse.d.mts
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
conversation_id: string;
|
|
4
|
-
/** The Twilio Call SID. */
|
|
5
|
-
twilio_call_sid: string;
|
|
6
|
-
}
|
|
1
|
+
import type * as Phonic from "../../../index.mjs";
|
|
2
|
+
export type ConversationsSipOutboundCallResponse = Phonic.SipOutboundDryRunResponse | Phonic.SipOutboundCallInitiatedResponse;
|
|
@@ -52,6 +52,8 @@ export interface Agent {
|
|
|
52
52
|
multilingual_mode: Agent.MultilingualMode;
|
|
53
53
|
/** These words, or short phrases, will be more accurately recognized by the agent. */
|
|
54
54
|
boosted_keywords: string[];
|
|
55
|
+
/** Minimum number of words required to interrupt the assistant. */
|
|
56
|
+
min_words_to_interrupt: number;
|
|
55
57
|
/** When not `null`, the agent will call this endpoint to get configuration options. */
|
|
56
58
|
configuration_endpoint: Agent.ConfigurationEndpoint | null;
|
|
57
59
|
/** Float between 0.0 and 1.0 representing the percentage of inbound calls handled by Agent. Requires `phone_number` to be set when less than 1.0. */
|
|
@@ -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,29 @@
|
|
|
1
|
+
// This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
export var ConfigOptions;
|
|
3
|
+
(function (ConfigOptions) {
|
|
4
|
+
/** Background noise type for the conversation */
|
|
5
|
+
ConfigOptions.BackgroundNoise = {
|
|
6
|
+
Office: "office",
|
|
7
|
+
CallCenter: "call-center",
|
|
8
|
+
CoffeeShop: "coffee-shop",
|
|
9
|
+
};
|
|
10
|
+
/** Audio input format */
|
|
11
|
+
ConfigOptions.InputFormat = {
|
|
12
|
+
Pcm44100: "pcm_44100",
|
|
13
|
+
Pcm16000: "pcm_16000",
|
|
14
|
+
Pcm8000: "pcm_8000",
|
|
15
|
+
Mulaw8000: "mulaw_8000",
|
|
16
|
+
};
|
|
17
|
+
/** Audio output format */
|
|
18
|
+
ConfigOptions.OutputFormat = {
|
|
19
|
+
Pcm44100: "pcm_44100",
|
|
20
|
+
Pcm16000: "pcm_16000",
|
|
21
|
+
Pcm8000: "pcm_8000",
|
|
22
|
+
Mulaw8000: "mulaw_8000",
|
|
23
|
+
};
|
|
24
|
+
/** If `"auto"`, each user audio is automatically identified for the language to respond in. If `"request"`, user must request to change language (recommended). */
|
|
25
|
+
ConfigOptions.MultilingualMode = {
|
|
26
|
+
Auto: "auto",
|
|
27
|
+
Request: "request",
|
|
28
|
+
};
|
|
29
|
+
})(ConfigOptions || (ConfigOptions = {}));
|
|
@@ -1,90 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import type * as Phonic from "../index.mjs";
|
|
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
|
-
/** Whether to have the no-input poke text be generated by AI */
|
|
36
|
-
generate_no_input_poke_text?: boolean | undefined;
|
|
37
|
-
/** Seconds of silence before poke message */
|
|
38
|
-
no_input_poke_sec?: (number | null) | undefined;
|
|
39
|
-
/** Poke message text. Ignored when generate_no_input_poke_text is true. */
|
|
40
|
-
no_input_poke_text?: string | undefined;
|
|
41
|
-
/** Seconds of silence before ending conversation */
|
|
42
|
-
no_input_end_conversation_sec?: number | undefined;
|
|
43
|
-
/** 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. */
|
|
44
|
-
default_language?: string | undefined;
|
|
45
|
-
/** Array of additional ISO 639-1 language codes that the agent should be able to recognize and speak. Should not include `default_language`. */
|
|
46
|
-
additional_languages?: string[] | undefined;
|
|
47
|
-
/** If `"auto"`, each user audio is automatically identified for the language to respond in. If `"request"`, user must request to change language (recommended). */
|
|
48
|
-
multilingual_mode?: ConfigPayload.MultilingualMode | undefined;
|
|
49
|
-
/** Keywords to boost in speech recognition */
|
|
50
|
-
boosted_keywords?: string[] | undefined;
|
|
51
|
-
/** Names of tools available to the assistant. */
|
|
52
|
-
tools?: ConfigPayload.Tools.Item[] | undefined;
|
|
53
|
-
/** Template variables for system prompt and welcome message */
|
|
54
|
-
template_variables?: Record<string, string> | undefined;
|
|
55
|
-
}
|
|
56
|
-
export declare namespace ConfigPayload {
|
|
57
|
-
/** Background noise type for the conversation */
|
|
58
|
-
const BackgroundNoise: {
|
|
59
|
-
readonly Office: "office";
|
|
60
|
-
readonly CallCenter: "call-center";
|
|
61
|
-
readonly CoffeeShop: "coffee-shop";
|
|
62
|
-
};
|
|
63
|
-
type BackgroundNoise = (typeof BackgroundNoise)[keyof typeof BackgroundNoise];
|
|
64
|
-
/** Audio input format */
|
|
65
|
-
const InputFormat: {
|
|
66
|
-
readonly Pcm44100: "pcm_44100";
|
|
67
|
-
readonly Pcm16000: "pcm_16000";
|
|
68
|
-
readonly Pcm8000: "pcm_8000";
|
|
69
|
-
readonly Mulaw8000: "mulaw_8000";
|
|
70
|
-
};
|
|
71
|
-
type InputFormat = (typeof InputFormat)[keyof typeof InputFormat];
|
|
72
|
-
/** Audio output format */
|
|
73
|
-
const OutputFormat: {
|
|
74
|
-
readonly Pcm44100: "pcm_44100";
|
|
75
|
-
readonly Pcm16000: "pcm_16000";
|
|
76
|
-
readonly Pcm8000: "pcm_8000";
|
|
77
|
-
readonly Mulaw8000: "mulaw_8000";
|
|
78
|
-
};
|
|
79
|
-
type OutputFormat = (typeof OutputFormat)[keyof typeof OutputFormat];
|
|
80
|
-
/** If `"auto"`, each user audio is automatically identified for the language to respond in. If `"request"`, user must request to change language (recommended). */
|
|
81
|
-
const MultilingualMode: {
|
|
82
|
-
readonly Auto: "auto";
|
|
83
|
-
readonly Request: "request";
|
|
84
|
-
};
|
|
85
|
-
type MultilingualMode = (typeof MultilingualMode)[keyof typeof MultilingualMode];
|
|
86
|
-
type Tools = Tools.Item[];
|
|
87
|
-
namespace Tools {
|
|
88
|
-
type Item = string | Record<string, unknown>;
|
|
89
|
-
}
|
|
90
4
|
}
|
|
@@ -1,29 +1,2 @@
|
|
|
1
1
|
// This file was auto-generated by Fern from our API Definition.
|
|
2
|
-
export
|
|
3
|
-
(function (ConfigPayload) {
|
|
4
|
-
/** Background noise type for the conversation */
|
|
5
|
-
ConfigPayload.BackgroundNoise = {
|
|
6
|
-
Office: "office",
|
|
7
|
-
CallCenter: "call-center",
|
|
8
|
-
CoffeeShop: "coffee-shop",
|
|
9
|
-
};
|
|
10
|
-
/** Audio input format */
|
|
11
|
-
ConfigPayload.InputFormat = {
|
|
12
|
-
Pcm44100: "pcm_44100",
|
|
13
|
-
Pcm16000: "pcm_16000",
|
|
14
|
-
Pcm8000: "pcm_8000",
|
|
15
|
-
Mulaw8000: "mulaw_8000",
|
|
16
|
-
};
|
|
17
|
-
/** Audio output format */
|
|
18
|
-
ConfigPayload.OutputFormat = {
|
|
19
|
-
Pcm44100: "pcm_44100",
|
|
20
|
-
Pcm16000: "pcm_16000",
|
|
21
|
-
Pcm8000: "pcm_8000",
|
|
22
|
-
Mulaw8000: "mulaw_8000",
|
|
23
|
-
};
|
|
24
|
-
/** If `"auto"`, each user audio is automatically identified for the language to respond in. If `"request"`, user must request to change language (recommended). */
|
|
25
|
-
ConfigPayload.MultilingualMode = {
|
|
26
|
-
Auto: "auto",
|
|
27
|
-
Request: "request",
|
|
28
|
-
};
|
|
29
|
-
})(ConfigPayload || (ConfigPayload = {}));
|
|
2
|
+
export {};
|
|
@@ -46,6 +46,8 @@ export interface Conversation {
|
|
|
46
46
|
ended_by: Conversation.EndedBy | null;
|
|
47
47
|
/** These words, or short phrases, are more accurately recognized by the model. */
|
|
48
48
|
boosted_keywords: string[] | null;
|
|
49
|
+
/** Minimum number of words required to interrupt the assistant. */
|
|
50
|
+
min_words_to_interrupt: number;
|
|
49
51
|
/** 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. */
|
|
50
52
|
default_language: string;
|
|
51
53
|
/** Array of additional ISO 639-1 language codes that the agent should be able to recognize and speak. Should not include `default_language`. */
|
|
@@ -50,6 +50,8 @@ export interface CreateAgentRequest {
|
|
|
50
50
|
multilingual_mode?: CreateAgentRequest.MultilingualMode | undefined;
|
|
51
51
|
/** These words, or short phrases, will be more accurately recognized by the agent. */
|
|
52
52
|
boosted_keywords?: string[] | undefined;
|
|
53
|
+
/** Minimum number of words required to interrupt the assistant. */
|
|
54
|
+
min_words_to_interrupt?: number | undefined;
|
|
53
55
|
/** When not `null`, at the beginning of the conversation the agent will make a POST request to this endpoint to get configuration options. */
|
|
54
56
|
configuration_endpoint?: (CreateAgentRequest.ConfigurationEndpoint | null) | undefined;
|
|
55
57
|
/** Float between 0.0 and 1.0 representing the percentage of inbound calls handled by Agent. Defaults to `1.0`. Requires `phone_number` to be set when less than 1.0. */
|
|
@@ -33,6 +33,8 @@ export interface OutboundCallConfig {
|
|
|
33
33
|
multilingual_mode?: OutboundCallConfig.MultilingualMode | undefined;
|
|
34
34
|
/** These words, or short phrases, will be more accurately recognized by the agent. */
|
|
35
35
|
boosted_keywords?: string[] | undefined;
|
|
36
|
+
/** Minimum number of words required to interrupt the assistant. */
|
|
37
|
+
min_words_to_interrupt?: number | undefined;
|
|
36
38
|
/** Array of built-in or custom tool names to use. */
|
|
37
39
|
tools?: OutboundCallConfig.Tools.Item[] | undefined;
|
|
38
40
|
}
|
|
@@ -8,6 +8,7 @@ export * from "./AudioChunkPayload.mjs";
|
|
|
8
8
|
export * from "./AudioChunkResponsePayload.mjs";
|
|
9
9
|
export * from "./BadRequestErrorBody.mjs";
|
|
10
10
|
export * from "./BasicError.mjs";
|
|
11
|
+
export * from "./ConfigOptions.mjs";
|
|
11
12
|
export * from "./ConfigPayload.mjs";
|
|
12
13
|
export * from "./Conversation.mjs";
|
|
13
14
|
export * from "./ConversationAnalysis.mjs";
|
|
@@ -29,10 +30,15 @@ export * from "./InputCancelledPayload.mjs";
|
|
|
29
30
|
export * from "./InputTextPayload.mjs";
|
|
30
31
|
export * from "./LanguageCode.mjs";
|
|
31
32
|
export * from "./OutboundCallConfig.mjs";
|
|
33
|
+
export * from "./OutboundCallInitiatedResponse.mjs";
|
|
34
|
+
export * from "./OutboundDryRunResponse.mjs";
|
|
32
35
|
export * from "./Project.mjs";
|
|
33
36
|
export * from "./ReadyToStartConversationPayload.mjs";
|
|
37
|
+
export * from "./ResetPayload.mjs";
|
|
34
38
|
export * from "./SayPayload.mjs";
|
|
35
39
|
export * from "./SetExternalIdPayload.mjs";
|
|
40
|
+
export * from "./SipOutboundCallInitiatedResponse.mjs";
|
|
41
|
+
export * from "./SipOutboundDryRunResponse.mjs";
|
|
36
42
|
export * from "./Task.mjs";
|
|
37
43
|
export * from "./Tool.mjs";
|
|
38
44
|
export * from "./ToolCallInterruptedPayload.mjs";
|
|
@@ -8,6 +8,7 @@ export * from "./AudioChunkPayload.mjs";
|
|
|
8
8
|
export * from "./AudioChunkResponsePayload.mjs";
|
|
9
9
|
export * from "./BadRequestErrorBody.mjs";
|
|
10
10
|
export * from "./BasicError.mjs";
|
|
11
|
+
export * from "./ConfigOptions.mjs";
|
|
11
12
|
export * from "./ConfigPayload.mjs";
|
|
12
13
|
export * from "./Conversation.mjs";
|
|
13
14
|
export * from "./ConversationAnalysis.mjs";
|
|
@@ -29,10 +30,15 @@ export * from "./InputCancelledPayload.mjs";
|
|
|
29
30
|
export * from "./InputTextPayload.mjs";
|
|
30
31
|
export * from "./LanguageCode.mjs";
|
|
31
32
|
export * from "./OutboundCallConfig.mjs";
|
|
33
|
+
export * from "./OutboundCallInitiatedResponse.mjs";
|
|
34
|
+
export * from "./OutboundDryRunResponse.mjs";
|
|
32
35
|
export * from "./Project.mjs";
|
|
33
36
|
export * from "./ReadyToStartConversationPayload.mjs";
|
|
37
|
+
export * from "./ResetPayload.mjs";
|
|
34
38
|
export * from "./SayPayload.mjs";
|
|
35
39
|
export * from "./SetExternalIdPayload.mjs";
|
|
40
|
+
export * from "./SipOutboundCallInitiatedResponse.mjs";
|
|
41
|
+
export * from "./SipOutboundDryRunResponse.mjs";
|
|
36
42
|
export * from "./Task.mjs";
|
|
37
43
|
export * from "./Tool.mjs";
|
|
38
44
|
export * from "./ToolCallInterruptedPayload.mjs";
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as core from "../core/index.mjs";
|
|
2
|
+
import type * as Phonic from "../api/index.mjs";
|
|
3
|
+
import { ConversationsSocket } from "../api/resources/conversations/client/Socket.mjs";
|
|
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 {};
|