phonic 0.30.0-rc2 → 0.30.0-rc4

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.
@@ -50,8 +50,8 @@ class PhonicClient {
50
50
  this._options = Object.assign(Object.assign({}, _options), { headers: (0, headers_js_1.mergeHeaders)({
51
51
  "X-Fern-Language": "JavaScript",
52
52
  "X-Fern-SDK-Name": "phonic",
53
- "X-Fern-SDK-Version": "0.30.0rc1",
54
- "User-Agent": "phonic/0.30.0rc1",
53
+ "X-Fern-SDK-Version": "0.30.0-rc3",
54
+ "User-Agent": "phonic/0.30.0-rc3",
55
55
  "X-Fern-Runtime": core.RUNTIME.type,
56
56
  "X-Fern-Runtime-Version": core.RUNTIME.version,
57
57
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
@@ -29,7 +29,6 @@ export declare namespace Conversations {
29
29
  }
30
30
  interface ConnectArgs {
31
31
  downstream_websocket_url?: string | undefined;
32
- Authorization: string;
33
32
  /** Arbitrary headers to send with the websocket connect request. */
34
33
  headers?: Record<string, string>;
35
34
  /** Enable debug mode on the websocket. Defaults to false. */
@@ -232,6 +231,6 @@ export declare class Conversations {
232
231
  */
233
232
  sipOutboundCall(request: Phonic.ConversationsSipOutboundCallRequest, requestOptions?: Conversations.RequestOptions): core.HttpResponsePromise<Phonic.ConversationsSipOutboundCallResponse>;
234
233
  private __sipOutboundCall;
235
- connect(args: Conversations.ConnectArgs): Promise<ConversationsSocket>;
234
+ connect(args?: Conversations.ConnectArgs): Promise<ConversationsSocket>;
236
235
  protected _getAuthorizationHeader(): Promise<string>;
237
236
  }
@@ -858,8 +858,8 @@ class Conversations {
858
858
  }
859
859
  });
860
860
  }
861
- connect(args) {
862
- return __awaiter(this, void 0, void 0, function* () {
861
+ connect() {
862
+ return __awaiter(this, arguments, void 0, function* (args = {}) {
863
863
  var _a, _b;
864
864
  const { downstream_websocket_url, headers, debug, reconnectAttempts } = args;
865
865
  const _queryParams = {};
@@ -867,9 +867,6 @@ class Conversations {
867
867
  _queryParams["downstream_websocket_url"] = downstream_websocket_url;
868
868
  }
869
869
  let _headers = Object.assign({}, headers);
870
- if (args["Authorization"] != null) {
871
- _headers["Authorization"] = args["Authorization"];
872
- }
873
870
  const socket = new core.ReconnectingWebSocket({
874
871
  url: 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)
875
872
  .production, "/v1/sts/ws"),
@@ -18,6 +18,7 @@ export declare namespace ConversationsSocket {
18
18
  export declare class ConversationsSocket {
19
19
  readonly socket: core.ReconnectingWebSocket;
20
20
  protected readonly eventHandlers: ConversationsSocket.EventHandlers;
21
+ private messageBuffer;
21
22
  private handleOpen;
22
23
  private handleMessage;
23
24
  private handleClose;
@@ -50,6 +51,12 @@ export declare class ConversationsSocket {
50
51
  waitForOpen(): Promise<core.ReconnectingWebSocket>;
51
52
  /** Asserts that the websocket is open. */
52
53
  private assertSocketIsOpen;
54
+ /** Send a message with buffering - if socket is not open, buffer the message. */
55
+ private sendWithBuffering;
56
+ /** Flush all buffered messages when the socket opens. */
57
+ private flushMessageBuffer;
58
+ /** Clear all buffered messages. */
59
+ private clearMessageBuffer;
53
60
  /** Send a binary payload to the websocket. */
54
61
  protected sendBinary(payload: ArrayBufferLike | Blob | ArrayBufferView): void;
55
62
  /** Send a JSON payload to the websocket. */
@@ -51,8 +51,10 @@ const json_js_1 = require("../../../../core/json.js");
51
51
  class ConversationsSocket {
52
52
  constructor(args) {
53
53
  this.eventHandlers = {};
54
+ this.messageBuffer = [];
54
55
  this.handleOpen = () => {
55
56
  var _a, _b;
57
+ this.flushMessageBuffer();
56
58
  (_b = (_a = this.eventHandlers).open) === null || _b === void 0 ? void 0 : _b.call(_a);
57
59
  };
58
60
  this.handleMessage = (event) => {
@@ -93,28 +95,22 @@ class ConversationsSocket {
93
95
  this.eventHandlers[event] = callback;
94
96
  }
95
97
  sendConfig(message) {
96
- this.assertSocketIsOpen();
97
- this.sendJson(message);
98
+ this.sendWithBuffering(() => this.sendJson(message));
98
99
  }
99
100
  sendAudioChunk(message) {
100
- this.assertSocketIsOpen();
101
- this.sendJson(message);
101
+ this.sendWithBuffering(() => this.sendJson(message));
102
102
  }
103
103
  sendUpdateSystemPrompt(message) {
104
- this.assertSocketIsOpen();
105
- this.sendJson(message);
104
+ this.sendWithBuffering(() => this.sendJson(message));
106
105
  }
107
106
  sendSetExternalId(message) {
108
- this.assertSocketIsOpen();
109
- this.sendJson(message);
107
+ this.sendWithBuffering(() => this.sendJson(message));
110
108
  }
111
109
  sendSetTwilioCallSid(message) {
112
- this.assertSocketIsOpen();
113
- this.sendJson(message);
110
+ this.sendWithBuffering(() => this.sendJson(message));
114
111
  }
115
112
  sendToolCallOutput(message) {
116
- this.assertSocketIsOpen();
117
- this.sendJson(message);
113
+ this.sendWithBuffering(() => this.sendJson(message));
118
114
  }
119
115
  /** Connect to the websocket and register event handlers. */
120
116
  connect() {
@@ -129,6 +125,7 @@ class ConversationsSocket {
129
125
  close() {
130
126
  this.socket.close();
131
127
  this.handleClose({ code: 1000 });
128
+ this.clearMessageBuffer();
132
129
  this.socket.removeEventListener("open", this.handleOpen);
133
130
  this.socket.removeEventListener("message", this.handleMessage);
134
131
  this.socket.removeEventListener("close", this.handleClose);
@@ -159,6 +156,33 @@ class ConversationsSocket {
159
156
  throw new Error("Socket is not open.");
160
157
  }
161
158
  }
159
+ /** Send a message with buffering - if socket is not open, buffer the message. */
160
+ sendWithBuffering(sendFn) {
161
+ if (this.socket.readyState === core.ReconnectingWebSocket.OPEN) {
162
+ sendFn();
163
+ }
164
+ else {
165
+ this.messageBuffer.push(sendFn);
166
+ }
167
+ }
168
+ /** Flush all buffered messages when the socket opens. */
169
+ flushMessageBuffer() {
170
+ while (this.messageBuffer.length > 0) {
171
+ const sendFn = this.messageBuffer.shift();
172
+ if (sendFn) {
173
+ try {
174
+ sendFn();
175
+ }
176
+ catch (error) {
177
+ console.error("Error sending buffered message:", error);
178
+ }
179
+ }
180
+ }
181
+ }
182
+ /** Clear all buffered messages. */
183
+ clearMessageBuffer() {
184
+ this.messageBuffer = [];
185
+ }
162
186
  /** Send a binary payload to the websocket. */
163
187
  sendBinary(payload) {
164
188
  this.socket.send(payload);
@@ -1,4 +1,6 @@
1
+ import type { Conversation } from "./Conversation";
1
2
  type PhonicTool = "send_dtmf_tone" | "end_conversation" | (string & {});
3
+ type ISODateTime = `${string}Z`;
2
4
  export type PhonicConfigurationEndpointRequestPayload = {
3
5
  project: {
4
6
  name: string;
@@ -20,4 +22,29 @@ export type PhonicConfigurationEndpointResponsePayload = {
20
22
  tools?: Array<PhonicTool>;
21
23
  boosted_keywords?: string[];
22
24
  };
25
+ export type ConversationEndedWebhookPayload = {
26
+ event_type: "conversation.ended";
27
+ created_at: ISODateTime;
28
+ data: {
29
+ conversation: Conversation;
30
+ call_info: {
31
+ from_phone_number: string;
32
+ to_phone_number: string;
33
+ } | null;
34
+ };
35
+ };
36
+ export type ConversationAnalysisWebhookPayload = {
37
+ event_type: "conversation.analysis";
38
+ created_at: ISODateTime;
39
+ data: {
40
+ conversation: {
41
+ latencies_ms: number[];
42
+ interruptions_count: number;
43
+ };
44
+ call_info: {
45
+ from_phone_number: string;
46
+ to_phone_number: string;
47
+ } | null;
48
+ };
49
+ };
23
50
  export {};
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.30.0rc1";
1
+ export declare const SDK_VERSION = "0.30.0-rc3";
@@ -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.30.0rc1";
4
+ exports.SDK_VERSION = "0.30.0-rc3";
@@ -14,8 +14,8 @@ export class PhonicClient {
14
14
  this._options = Object.assign(Object.assign({}, _options), { headers: mergeHeaders({
15
15
  "X-Fern-Language": "JavaScript",
16
16
  "X-Fern-SDK-Name": "phonic",
17
- "X-Fern-SDK-Version": "0.30.0rc1",
18
- "User-Agent": "phonic/0.30.0rc1",
17
+ "X-Fern-SDK-Version": "0.30.0-rc3",
18
+ "User-Agent": "phonic/0.30.0-rc3",
19
19
  "X-Fern-Runtime": core.RUNTIME.type,
20
20
  "X-Fern-Runtime-Version": core.RUNTIME.version,
21
21
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
@@ -29,7 +29,6 @@ export declare namespace Conversations {
29
29
  }
30
30
  interface ConnectArgs {
31
31
  downstream_websocket_url?: string | undefined;
32
- Authorization: string;
33
32
  /** Arbitrary headers to send with the websocket connect request. */
34
33
  headers?: Record<string, string>;
35
34
  /** Enable debug mode on the websocket. Defaults to false. */
@@ -232,6 +231,6 @@ export declare class Conversations {
232
231
  */
233
232
  sipOutboundCall(request: Phonic.ConversationsSipOutboundCallRequest, requestOptions?: Conversations.RequestOptions): core.HttpResponsePromise<Phonic.ConversationsSipOutboundCallResponse>;
234
233
  private __sipOutboundCall;
235
- connect(args: Conversations.ConnectArgs): Promise<ConversationsSocket>;
234
+ connect(args?: Conversations.ConnectArgs): Promise<ConversationsSocket>;
236
235
  protected _getAuthorizationHeader(): Promise<string>;
237
236
  }
@@ -822,8 +822,8 @@ export class Conversations {
822
822
  }
823
823
  });
824
824
  }
825
- connect(args) {
826
- return __awaiter(this, void 0, void 0, function* () {
825
+ connect() {
826
+ return __awaiter(this, arguments, void 0, function* (args = {}) {
827
827
  var _a, _b;
828
828
  const { downstream_websocket_url, headers, debug, reconnectAttempts } = args;
829
829
  const _queryParams = {};
@@ -831,9 +831,6 @@ export class Conversations {
831
831
  _queryParams["downstream_websocket_url"] = downstream_websocket_url;
832
832
  }
833
833
  let _headers = Object.assign({}, headers);
834
- if (args["Authorization"] != null) {
835
- _headers["Authorization"] = args["Authorization"];
836
- }
837
834
  const socket = new core.ReconnectingWebSocket({
838
835
  url: 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)
839
836
  .production, "/v1/sts/ws"),
@@ -18,6 +18,7 @@ export declare namespace ConversationsSocket {
18
18
  export declare class ConversationsSocket {
19
19
  readonly socket: core.ReconnectingWebSocket;
20
20
  protected readonly eventHandlers: ConversationsSocket.EventHandlers;
21
+ private messageBuffer;
21
22
  private handleOpen;
22
23
  private handleMessage;
23
24
  private handleClose;
@@ -50,6 +51,12 @@ export declare class ConversationsSocket {
50
51
  waitForOpen(): Promise<core.ReconnectingWebSocket>;
51
52
  /** Asserts that the websocket is open. */
52
53
  private assertSocketIsOpen;
54
+ /** Send a message with buffering - if socket is not open, buffer the message. */
55
+ private sendWithBuffering;
56
+ /** Flush all buffered messages when the socket opens. */
57
+ private flushMessageBuffer;
58
+ /** Clear all buffered messages. */
59
+ private clearMessageBuffer;
53
60
  /** Send a binary payload to the websocket. */
54
61
  protected sendBinary(payload: ArrayBufferLike | Blob | ArrayBufferView): void;
55
62
  /** Send a JSON payload to the websocket. */
@@ -15,8 +15,10 @@ import { fromJson, toJson } from "../../../../core/json.mjs";
15
15
  export class ConversationsSocket {
16
16
  constructor(args) {
17
17
  this.eventHandlers = {};
18
+ this.messageBuffer = [];
18
19
  this.handleOpen = () => {
19
20
  var _a, _b;
21
+ this.flushMessageBuffer();
20
22
  (_b = (_a = this.eventHandlers).open) === null || _b === void 0 ? void 0 : _b.call(_a);
21
23
  };
22
24
  this.handleMessage = (event) => {
@@ -57,28 +59,22 @@ export class ConversationsSocket {
57
59
  this.eventHandlers[event] = callback;
58
60
  }
59
61
  sendConfig(message) {
60
- this.assertSocketIsOpen();
61
- this.sendJson(message);
62
+ this.sendWithBuffering(() => this.sendJson(message));
62
63
  }
63
64
  sendAudioChunk(message) {
64
- this.assertSocketIsOpen();
65
- this.sendJson(message);
65
+ this.sendWithBuffering(() => this.sendJson(message));
66
66
  }
67
67
  sendUpdateSystemPrompt(message) {
68
- this.assertSocketIsOpen();
69
- this.sendJson(message);
68
+ this.sendWithBuffering(() => this.sendJson(message));
70
69
  }
71
70
  sendSetExternalId(message) {
72
- this.assertSocketIsOpen();
73
- this.sendJson(message);
71
+ this.sendWithBuffering(() => this.sendJson(message));
74
72
  }
75
73
  sendSetTwilioCallSid(message) {
76
- this.assertSocketIsOpen();
77
- this.sendJson(message);
74
+ this.sendWithBuffering(() => this.sendJson(message));
78
75
  }
79
76
  sendToolCallOutput(message) {
80
- this.assertSocketIsOpen();
81
- this.sendJson(message);
77
+ this.sendWithBuffering(() => this.sendJson(message));
82
78
  }
83
79
  /** Connect to the websocket and register event handlers. */
84
80
  connect() {
@@ -93,6 +89,7 @@ export class ConversationsSocket {
93
89
  close() {
94
90
  this.socket.close();
95
91
  this.handleClose({ code: 1000 });
92
+ this.clearMessageBuffer();
96
93
  this.socket.removeEventListener("open", this.handleOpen);
97
94
  this.socket.removeEventListener("message", this.handleMessage);
98
95
  this.socket.removeEventListener("close", this.handleClose);
@@ -123,6 +120,33 @@ export class ConversationsSocket {
123
120
  throw new Error("Socket is not open.");
124
121
  }
125
122
  }
123
+ /** Send a message with buffering - if socket is not open, buffer the message. */
124
+ sendWithBuffering(sendFn) {
125
+ if (this.socket.readyState === core.ReconnectingWebSocket.OPEN) {
126
+ sendFn();
127
+ }
128
+ else {
129
+ this.messageBuffer.push(sendFn);
130
+ }
131
+ }
132
+ /** Flush all buffered messages when the socket opens. */
133
+ flushMessageBuffer() {
134
+ while (this.messageBuffer.length > 0) {
135
+ const sendFn = this.messageBuffer.shift();
136
+ if (sendFn) {
137
+ try {
138
+ sendFn();
139
+ }
140
+ catch (error) {
141
+ console.error("Error sending buffered message:", error);
142
+ }
143
+ }
144
+ }
145
+ }
146
+ /** Clear all buffered messages. */
147
+ clearMessageBuffer() {
148
+ this.messageBuffer = [];
149
+ }
126
150
  /** Send a binary payload to the websocket. */
127
151
  sendBinary(payload) {
128
152
  this.socket.send(payload);
@@ -1,4 +1,6 @@
1
+ import type { Conversation } from "./Conversation";
1
2
  type PhonicTool = "send_dtmf_tone" | "end_conversation" | (string & {});
3
+ type ISODateTime = `${string}Z`;
2
4
  export type PhonicConfigurationEndpointRequestPayload = {
3
5
  project: {
4
6
  name: string;
@@ -20,4 +22,29 @@ export type PhonicConfigurationEndpointResponsePayload = {
20
22
  tools?: Array<PhonicTool>;
21
23
  boosted_keywords?: string[];
22
24
  };
25
+ export type ConversationEndedWebhookPayload = {
26
+ event_type: "conversation.ended";
27
+ created_at: ISODateTime;
28
+ data: {
29
+ conversation: Conversation;
30
+ call_info: {
31
+ from_phone_number: string;
32
+ to_phone_number: string;
33
+ } | null;
34
+ };
35
+ };
36
+ export type ConversationAnalysisWebhookPayload = {
37
+ event_type: "conversation.analysis";
38
+ created_at: ISODateTime;
39
+ data: {
40
+ conversation: {
41
+ latencies_ms: number[];
42
+ interruptions_count: number;
43
+ };
44
+ call_info: {
45
+ from_phone_number: string;
46
+ to_phone_number: string;
47
+ } | null;
48
+ };
49
+ };
23
50
  export {};
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.30.0rc1";
1
+ export declare const SDK_VERSION = "0.30.0-rc3";
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.30.0rc1";
1
+ export const SDK_VERSION = "0.30.0-rc3";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phonic",
3
- "version": "0.30.0-rc2",
3
+ "version": "0.30.0-rc4",
4
4
  "private": false,
5
5
  "repository": "github:fern-demo/phonic-ts-sdk",
6
6
  "type": "commonjs",