retell-sdk 1.15.16 → 1.15.18

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.
@@ -40,7 +40,7 @@ var CallStatus;
40
40
  CallStatus["Ongoing"] = "ongoing";
41
41
  CallStatus["Ended"] = "ended";
42
42
  CallStatus["Error"] = "error";
43
- })(CallStatus = exports.CallStatus || (exports.CallStatus = {}));
43
+ })(CallStatus || (exports.CallStatus = CallStatus = {}));
44
44
  /**
45
45
  * Web call or phone call.
46
46
  */
@@ -49,7 +49,7 @@ var CallType;
49
49
  CallType["InboundPhoneCall"] = "inbound_phone_call";
50
50
  CallType["OutboundPhoneCall"] = "outbound_phone_call";
51
51
  CallType["WebCall"] = "web_call";
52
- })(CallType = exports.CallType || (exports.CallType = {}));
52
+ })(CallType || (exports.CallType = CallType = {}));
53
53
  var CallDetail = /** @class */ (function (_super) {
54
54
  __extends(CallDetail, _super);
55
55
  function CallDetail() {
@@ -103,7 +103,7 @@ var CallStatus;
103
103
  CallStatus["Ongoing"] = "ongoing";
104
104
  CallStatus["Ended"] = "ended";
105
105
  CallStatus["Error"] = "error";
106
- })(CallStatus = exports.CallStatus || (exports.CallStatus = {}));
106
+ })(CallStatus || (exports.CallStatus = CallStatus = {}));
107
107
  /**
108
108
  * Web call or phone call.
109
109
  */
@@ -112,7 +112,7 @@ var CreatePhoneCallCallType;
112
112
  CreatePhoneCallCallType["InboundPhoneCall"] = "inbound_phone_call";
113
113
  CreatePhoneCallCallType["OutboundPhoneCall"] = "outbound_phone_call";
114
114
  CreatePhoneCallCallType["WebCall"] = "web_call";
115
- })(CreatePhoneCallCallType = exports.CreatePhoneCallCallType || (exports.CreatePhoneCallCallType = {}));
115
+ })(CreatePhoneCallCallType || (exports.CreatePhoneCallCallType = CreatePhoneCallCallType = {}));
116
116
  /**
117
117
  * Successfully retrieved an agent.
118
118
  */
@@ -58,7 +58,7 @@ var CallType;
58
58
  CallType["InboundPhoneCall"] = "inbound_phone_call";
59
59
  CallType["OutboundPhoneCall"] = "outbound_phone_call";
60
60
  CallType["WebCall"] = "web_call";
61
- })(CallType = exports.CallType || (exports.CallType = {}));
61
+ })(CallType || (exports.CallType = CallType = {}));
62
62
  var FilterCriteria = /** @class */ (function (_super) {
63
63
  __extends(FilterCriteria, _super);
64
64
  function FilterCriteria() {
@@ -98,7 +98,7 @@ var SortOrder;
98
98
  (function (SortOrder) {
99
99
  SortOrder["Ascending"] = "ascending";
100
100
  SortOrder["Descending"] = "descending";
101
- })(SortOrder = exports.SortOrder || (exports.SortOrder = {}));
101
+ })(SortOrder || (exports.SortOrder = SortOrder = {}));
102
102
  var ListCallsRequest = /** @class */ (function (_super) {
103
103
  __extends(ListCallsRequest, _super);
104
104
  function ListCallsRequest() {
package/dist/sdk/sdk.d.ts CHANGED
@@ -1,7 +1,10 @@
1
+ /// <reference types="node" />
1
2
  import * as utils from "../internal/utils";
2
3
  import * as components from "../models/components";
3
4
  import * as operations from "../models/operations";
5
+ import { WebSocket } from "isomorphic-ws";
4
6
  import { AxiosInstance, AxiosRequestConfig } from "axios";
7
+ import { EventEmitter } from "events";
5
8
  /**
6
9
  * Contains the list of servers available to the SDK
7
10
  */
@@ -40,6 +43,19 @@ export declare class SDKConfiguration {
40
43
  retryConfig?: utils.RetryConfig;
41
44
  constructor(init?: Partial<SDKConfiguration>);
42
45
  }
46
+ interface PromptParam {
47
+ name: string;
48
+ value: string;
49
+ }
50
+ export declare class LiveClient extends EventEmitter {
51
+ ws: WebSocket;
52
+ constructor(apiKey: string, agentId: string, sampleRate: number, agentPromptParams: PromptParam[], baseEndpoint: string);
53
+ waitForReady(): Promise<void>;
54
+ send(audio: Uint8Array): void;
55
+ close(): void;
56
+ }
57
+ export declare function convertPCM16ToFloat32(array: Uint8Array): Float32Array;
58
+ export declare function convertFloat32ToPCM16(array: Float32Array): Uint8Array;
43
59
  export declare class RetellClient {
44
60
  private sdkConfiguration;
45
61
  constructor(props?: SDKProps);
@@ -96,3 +112,4 @@ export declare class RetellClient {
96
112
  */
97
113
  updatePhoneAgent(requestBody: operations.UpdatePhoneAgentRequestBody, phoneNumber: string, config?: AxiosRequestConfig): Promise<operations.UpdatePhoneAgentResponse>;
98
114
  }
115
+ export {};
package/dist/sdk/sdk.js CHANGED
@@ -2,6 +2,21 @@
2
2
  /*
3
3
  * Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
4
4
  */
5
+ var __extends = (this && this.__extends) || (function () {
6
+ var extendStatics = function (d, b) {
7
+ extendStatics = Object.setPrototypeOf ||
8
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
9
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
10
+ return extendStatics(d, b);
11
+ };
12
+ return function (d, b) {
13
+ if (typeof b !== "function" && b !== null)
14
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
15
+ extendStatics(d, b);
16
+ function __() { this.constructor = d; }
17
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
18
+ };
19
+ })();
5
20
  var __assign = (this && this.__assign) || function () {
6
21
  __assign = Object.assign || function(t) {
7
22
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -72,6 +87,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
72
87
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
73
88
  }
74
89
  };
90
+ var __values = (this && this.__values) || function(o) {
91
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
92
+ if (m) return m.call(o);
93
+ if (o && typeof o.length === "number") return {
94
+ next: function () {
95
+ if (o && i >= o.length) o = void 0;
96
+ return { value: o && o[i++], done: !o };
97
+ }
98
+ };
99
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
100
+ };
75
101
  var __read = (this && this.__read) || function (o, n) {
76
102
  var m = typeof Symbol === "function" && o[Symbol.iterator];
77
103
  if (!m) return o;
@@ -92,12 +118,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
92
118
  return (mod && mod.__esModule) ? mod : { "default": mod };
93
119
  };
94
120
  Object.defineProperty(exports, "__esModule", { value: true });
95
- exports.RetellClient = exports.SDKConfiguration = exports.ServerList = void 0;
121
+ exports.RetellClient = exports.convertFloat32ToPCM16 = exports.convertPCM16ToFloat32 = exports.LiveClient = exports.SDKConfiguration = exports.ServerList = void 0;
96
122
  var utils = __importStar(require("../internal/utils"));
97
123
  var components = __importStar(require("../models/components"));
98
124
  var errors = __importStar(require("../models/errors"));
99
125
  var operations = __importStar(require("../models/operations"));
100
126
  var axios_1 = __importDefault(require("axios"));
127
+ var isomorphic_ws_1 = require("isomorphic-ws");
128
+ var events_1 = require("events");
101
129
  /**
102
130
  * Contains the list of servers available to the SDK
103
131
  */
@@ -118,6 +146,104 @@ var SDKConfiguration = /** @class */ (function () {
118
146
  return SDKConfiguration;
119
147
  }());
120
148
  exports.SDKConfiguration = SDKConfiguration;
149
+ var LiveClient = /** @class */ (function (_super) {
150
+ __extends(LiveClient, _super);
151
+ function LiveClient(apiKey, agentId, sampleRate, agentPromptParams, baseEndpoint) {
152
+ var e_1, _a;
153
+ var _this = _super.call(this) || this;
154
+ var endpoint = baseEndpoint +
155
+ "/create-web-call?api_key=" +
156
+ apiKey +
157
+ "&agent_id=" +
158
+ agentId +
159
+ "&sample_rate=" +
160
+ sampleRate;
161
+ try {
162
+ for (var agentPromptParams_1 = __values(agentPromptParams), agentPromptParams_1_1 = agentPromptParams_1.next(); !agentPromptParams_1_1.done; agentPromptParams_1_1 = agentPromptParams_1.next()) {
163
+ var param = agentPromptParams_1_1.value;
164
+ endpoint += "&agent_prompt_params=" + JSON.stringify(param);
165
+ }
166
+ }
167
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
168
+ finally {
169
+ try {
170
+ if (agentPromptParams_1_1 && !agentPromptParams_1_1.done && (_a = agentPromptParams_1.return)) _a.call(agentPromptParams_1);
171
+ }
172
+ finally { if (e_1) throw e_1.error; }
173
+ }
174
+ _this.ws = new isomorphic_ws_1.WebSocket(endpoint);
175
+ _this.ws.binaryType = "arraybuffer";
176
+ return _this;
177
+ }
178
+ LiveClient.prototype.waitForReady = function () {
179
+ var _this = this;
180
+ return new Promise(function (resolve, reject) {
181
+ var onError = function (error) {
182
+ reject(error); // Reject on error
183
+ };
184
+ _this.ws.onerror = onError;
185
+ var onClose = function () {
186
+ reject("websocket closed before ready.");
187
+ };
188
+ _this.ws.onclose = onClose;
189
+ var onMessage = function (event) {
190
+ try {
191
+ var data = JSON.parse(event.data);
192
+ if (data.status === "ready") {
193
+ // Remove all registered listeners for cleaner future processing.
194
+ _this.ws.removeEventListener("error", onError);
195
+ _this.ws.removeEventListener("close", onClose);
196
+ _this.ws.removeEventListener("message", onMessage);
197
+ // Emit audio
198
+ _this.ws.onmessage = function (event) {
199
+ var audio = event.data;
200
+ _this.emit("audio", new Uint8Array(audio));
201
+ };
202
+ _this.ws.onclose = function (event) {
203
+ _this.emit("close", event);
204
+ };
205
+ resolve(); // Resolve when the ready message is received
206
+ }
207
+ }
208
+ catch (error) {
209
+ // Handle JSON parsing error
210
+ reject("malformed ready event.");
211
+ }
212
+ };
213
+ _this.ws.onmessage = onMessage;
214
+ });
215
+ };
216
+ LiveClient.prototype.send = function (audio) {
217
+ if (this.ws.readyState === 1)
218
+ this.ws.send(audio);
219
+ };
220
+ LiveClient.prototype.close = function () {
221
+ this.ws.close();
222
+ };
223
+ return LiveClient;
224
+ }(events_1.EventEmitter));
225
+ exports.LiveClient = LiveClient;
226
+ function convertPCM16ToFloat32(array) {
227
+ var targetArray = new Float32Array(array.byteLength / 2);
228
+ // A DataView is used to read our 16-bit little-endian samples out of the Uint8Array buffer
229
+ var sourceDataView = new DataView(array.buffer);
230
+ // Loop through, get values, and divide by 32,768
231
+ for (var i = 0; i < targetArray.length; i++) {
232
+ targetArray[i] = sourceDataView.getInt16(i * 2, true) / Math.pow(2, 16 - 1);
233
+ }
234
+ return targetArray;
235
+ }
236
+ exports.convertPCM16ToFloat32 = convertPCM16ToFloat32;
237
+ function convertFloat32ToPCM16(array) {
238
+ var buffer = new ArrayBuffer(array.length * 2);
239
+ var view = new DataView(buffer);
240
+ for (var i = 0; i < array.length; i++) {
241
+ var value = array[i] * 32768;
242
+ view.setInt16(i * 2, value, true); // true for little-endian
243
+ }
244
+ return new Uint8Array(buffer);
245
+ }
246
+ exports.convertFloat32ToPCM16 = convertFloat32ToPCM16;
121
247
  var RetellClient = /** @class */ (function () {
122
248
  function RetellClient(props) {
123
249
  var _a, _b;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "retell-sdk",
3
- "version": "1.15.16",
3
+ "version": "1.15.18",
4
4
  "author": "Retell",
5
5
  "scripts": {
6
6
  "prepare": "tsc --build",
@@ -9,19 +9,23 @@
9
9
  "check": "npm run check:tsc && npm run check:eslint"
10
10
  },
11
11
  "dependencies": {
12
+ "@types/node": "^20.10.6",
12
13
  "axios": "^1.1.3",
13
- "jsonpath": "^1.1.1",
14
14
  "class-transformer": "^0.5.1",
15
15
  "form-data": "^4.0.0",
16
- "reflect-metadata": "^0.1.13"
16
+ "isomorphic-ws": "^5.0.0",
17
+ "jsonpath": "^1.1.1",
18
+ "reflect-metadata": "^0.1.13",
19
+ "websocket": "^1.0.34",
20
+ "ws": "^8.16.0"
17
21
  },
18
22
  "devDependencies": {
19
23
  "@types/jsonpath": "^0.2.0",
20
- "@types/node": "^18.11.5",
21
- "typescript": "^4.8.4",
24
+ "@types/ws": "^8.5.10",
22
25
  "@typescript-eslint/eslint-plugin": "^5.56.0",
23
26
  "@typescript-eslint/parser": "^5.56.0",
24
- "eslint": "^8.36.0"
27
+ "eslint": "^8.36.0",
28
+ "typescript": "^4.8.4"
25
29
  },
26
30
  "main": "dist/index.js",
27
31
  "files": [