@guava-ai/guava-sdk 0.11.0 → 0.13.0
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 +2 -30
- package/dist/examples/help-desk.js +1 -1
- package/dist/examples/help-desk.js.map +1 -1
- package/dist/examples/property-insurance.js +1 -1
- package/dist/examples/property-insurance.js.map +1 -1
- package/dist/examples/restaurant-waitlist.js +1 -1
- package/dist/examples/restaurant-waitlist.js.map +1 -1
- package/dist/examples/scheduling-outbound.js +1 -1
- package/dist/examples/scheduling-outbound.js.map +1 -1
- package/dist/src/agent.d.ts +5 -1
- package/dist/src/agent.js +11 -2
- package/dist/src/agent.js.map +1 -1
- package/dist/src/client.d.ts +45 -0
- package/dist/src/client.js +344 -0
- package/dist/src/client.js.map +1 -0
- package/dist/src/helpers/openai.js +1 -1
- package/dist/src/helpers/openai.js.map +1 -1
- package/dist/src/index.d.ts +1 -44
- package/dist/src/index.js +6 -347
- package/dist/src/index.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/examples/README.md +4 -4
- package/examples/help-desk.ts +1 -1
- package/examples/property-insurance.ts +1 -1
- package/examples/restaurant-waitlist.ts +1 -1
- package/examples/scheduling-outbound.ts +1 -1
- package/package.json +1 -1
- package/src/agent.ts +17 -2
- package/src/client.ts +304 -0
- package/src/helpers/openai.ts +1 -1
- package/src/index.ts +1 -307
- package/src/version.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../../src/helpers/openai.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAwC;AACxC,4CAAmD;AACnD,8CAA8D;AAC9D,uCAAyB;AACzB,kDAAkD;AAClD,0CAAyC;AAEzC,eAAe;AACf,0BAA0B;AAC1B,SAAS,yBAAyB,CAAC,MAA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2
|
-
import { type Logger } from "./logging.ts";
|
|
3
|
-
import type { CallController } from "./call-controller.ts";
|
|
1
|
+
export { Client, type InboundConnection } from "./client.ts";
|
|
4
2
|
export { CallController, type TaskObjective } from "./call-controller.ts";
|
|
5
3
|
export { Say, Field } from "./action-item.ts";
|
|
6
4
|
export { Logger, getConsoleLogger, getDefaultLogger } from "./logging.ts";
|
|
7
5
|
export { Agent, CallInfo } from "./agent.ts";
|
|
8
6
|
export { Call } from "./call.ts";
|
|
9
|
-
export type InboundConnection = {
|
|
10
|
-
agent_number: string;
|
|
11
|
-
} | {
|
|
12
|
-
webrtc_code: string;
|
|
13
|
-
};
|
|
14
|
-
export declare class Client {
|
|
15
|
-
private _apiKey;
|
|
16
|
-
private _baseUrl;
|
|
17
|
-
private _logger;
|
|
18
|
-
private _ws?;
|
|
19
|
-
private _controller?;
|
|
20
|
-
private messageHandler?;
|
|
21
|
-
constructor(apiKey?: string, baseUrl?: string, logger?: Logger, captureWarnings?: boolean);
|
|
22
|
-
getWebsocketBase(): string;
|
|
23
|
-
getHttpBase(): string;
|
|
24
|
-
headers(): {
|
|
25
|
-
Authorization: string;
|
|
26
|
-
"x-guava-platform": NodeJS.Platform;
|
|
27
|
-
"x-guava-runtime": string;
|
|
28
|
-
"x-guava-runtime-version": string;
|
|
29
|
-
"x-guava-sdk": string;
|
|
30
|
-
"x-guava-sdk-version": string;
|
|
31
|
-
};
|
|
32
|
-
private _checkSdkDeprecation;
|
|
33
|
-
/**
|
|
34
|
-
* @description use the Guava API to call out to a number
|
|
35
|
-
*/
|
|
36
|
-
createOutbound(fromNumber: string | undefined, toNumber: string, callController: CallController): void;
|
|
37
|
-
private replaceHandler;
|
|
38
|
-
private uninitializedOutbound;
|
|
39
|
-
private initializedOutbound;
|
|
40
|
-
/**
|
|
41
|
-
* @description use the Guava API to receive calls at a given number
|
|
42
|
-
*/
|
|
43
|
-
listenInbound<U extends CallController>(conn: InboundConnection, controllerClassFactory: (logger: Logger) => U): InboundListener;
|
|
44
|
-
}
|
|
45
|
-
declare class InboundListener {
|
|
46
|
-
private ws;
|
|
47
|
-
constructor(ws: WebSocket);
|
|
48
|
-
close(): void;
|
|
49
|
-
}
|
package/dist/src/index.js
CHANGED
|
@@ -1,359 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
19
|
-
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
20
|
-
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
21
|
-
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
22
|
-
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
23
|
-
var _, done = false;
|
|
24
|
-
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
25
|
-
var context = {};
|
|
26
|
-
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
27
|
-
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
28
|
-
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
29
|
-
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
30
|
-
if (kind === "accessor") {
|
|
31
|
-
if (result === void 0) continue;
|
|
32
|
-
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
33
|
-
if (_ = accept(result.get)) descriptor.get = _;
|
|
34
|
-
if (_ = accept(result.set)) descriptor.set = _;
|
|
35
|
-
if (_ = accept(result.init)) initializers.unshift(_);
|
|
36
|
-
}
|
|
37
|
-
else if (_ = accept(result)) {
|
|
38
|
-
if (kind === "field") initializers.unshift(_);
|
|
39
|
-
else descriptor[key] = _;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
43
|
-
done = true;
|
|
44
|
-
};
|
|
45
|
-
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
46
|
-
var useValue = arguments.length > 2;
|
|
47
|
-
for (var i = 0; i < initializers.length; i++) {
|
|
48
|
-
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
49
|
-
}
|
|
50
|
-
return useValue ? value : void 0;
|
|
51
|
-
};
|
|
52
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
53
|
-
var ownKeys = function(o) {
|
|
54
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
55
|
-
var ar = [];
|
|
56
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
57
|
-
return ar;
|
|
58
|
-
};
|
|
59
|
-
return ownKeys(o);
|
|
60
|
-
};
|
|
61
|
-
return function (mod) {
|
|
62
|
-
if (mod && mod.__esModule) return mod;
|
|
63
|
-
var result = {};
|
|
64
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
65
|
-
__setModuleDefault(result, mod);
|
|
66
|
-
return result;
|
|
67
|
-
};
|
|
68
|
-
})();
|
|
69
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
70
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
71
|
-
};
|
|
72
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
73
|
-
exports.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const commands_ts_1 = require("./commands.js");
|
|
77
|
-
const z = __importStar(require("zod"));
|
|
78
|
-
const events_ts_1 = require("./events.js");
|
|
79
|
-
const version_ts_1 = require("./version.js");
|
|
80
|
-
const node_os_1 = __importDefault(require("node:os"));
|
|
81
|
-
const utils_ts_1 = require("./utils.js");
|
|
82
|
-
const telemetry_ts_1 = require("./telemetry.js");
|
|
3
|
+
exports.Call = exports.Agent = exports.getDefaultLogger = exports.getConsoleLogger = exports.Field = exports.Say = exports.CallController = exports.Client = void 0;
|
|
4
|
+
var client_ts_1 = require("./client.js");
|
|
5
|
+
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_ts_1.Client; } });
|
|
83
6
|
var call_controller_ts_1 = require("./call-controller.js");
|
|
84
7
|
Object.defineProperty(exports, "CallController", { enumerable: true, get: function () { return call_controller_ts_1.CallController; } });
|
|
85
8
|
var action_item_ts_1 = require("./action-item.js");
|
|
86
9
|
Object.defineProperty(exports, "Say", { enumerable: true, get: function () { return action_item_ts_1.Say; } });
|
|
87
10
|
Object.defineProperty(exports, "Field", { enumerable: true, get: function () { return action_item_ts_1.Field; } });
|
|
88
|
-
var
|
|
89
|
-
Object.defineProperty(exports, "getConsoleLogger", { enumerable: true, get: function () { return
|
|
90
|
-
Object.defineProperty(exports, "getDefaultLogger", { enumerable: true, get: function () { return
|
|
11
|
+
var logging_ts_1 = require("./logging.js");
|
|
12
|
+
Object.defineProperty(exports, "getConsoleLogger", { enumerable: true, get: function () { return logging_ts_1.getConsoleLogger; } });
|
|
13
|
+
Object.defineProperty(exports, "getDefaultLogger", { enumerable: true, get: function () { return logging_ts_1.getDefaultLogger; } });
|
|
91
14
|
var agent_ts_1 = require("./agent.js");
|
|
92
15
|
Object.defineProperty(exports, "Agent", { enumerable: true, get: function () { return agent_ts_1.Agent; } });
|
|
93
16
|
var call_ts_1 = require("./call.js");
|
|
94
17
|
Object.defineProperty(exports, "Call", { enumerable: true, get: function () { return call_ts_1.Call; } });
|
|
95
|
-
const SDK_NAME = "typescript-sdk";
|
|
96
|
-
let firstClient = false;
|
|
97
|
-
/**
|
|
98
|
-
* @description convenience function for stringifying data according to a schema
|
|
99
|
-
*/
|
|
100
|
-
function stringifyZod(schema, data) {
|
|
101
|
-
return JSON.stringify(schema.parse(data));
|
|
102
|
-
}
|
|
103
|
-
const http_start = /^http:\/\//;
|
|
104
|
-
const https_start = /^https:\/\//;
|
|
105
|
-
let Client = (() => {
|
|
106
|
-
let _classDecorators = [telemetry_ts_1.telemetryClient.trackClass()];
|
|
107
|
-
let _classDescriptor;
|
|
108
|
-
let _classExtraInitializers = [];
|
|
109
|
-
let _classThis;
|
|
110
|
-
var Client = class {
|
|
111
|
-
static { _classThis = this; }
|
|
112
|
-
static {
|
|
113
|
-
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
114
|
-
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
115
|
-
Client = _classThis = _classDescriptor.value;
|
|
116
|
-
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
117
|
-
__runInitializers(_classThis, _classExtraInitializers);
|
|
118
|
-
}
|
|
119
|
-
_apiKey;
|
|
120
|
-
_baseUrl;
|
|
121
|
-
_logger;
|
|
122
|
-
_ws;
|
|
123
|
-
_controller;
|
|
124
|
-
messageHandler;
|
|
125
|
-
constructor(apiKey, baseUrl, logger, captureWarnings = true) {
|
|
126
|
-
// Set up the default logger.
|
|
127
|
-
if (logger) {
|
|
128
|
-
this._logger = logger;
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
this._logger = (0, logging_ts_1.getDefaultLogger)();
|
|
132
|
-
}
|
|
133
|
-
// Resolve the API base URL.
|
|
134
|
-
if (baseUrl) {
|
|
135
|
-
this._baseUrl = baseUrl;
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
this._baseUrl = (0, utils_ts_1.getBaseUrl)();
|
|
139
|
-
}
|
|
140
|
-
// Resolve the API key.
|
|
141
|
-
if (apiKey) {
|
|
142
|
-
this._apiKey = apiKey;
|
|
143
|
-
}
|
|
144
|
-
else if (process.env.GUAVA_API_KEY) {
|
|
145
|
-
this._apiKey = process.env.GUAVA_API_KEY;
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
throw new Error("Guava API key must be provided either as argument to client constructor, or in environment variable GUAVA_API_KEY.");
|
|
149
|
-
}
|
|
150
|
-
if (!firstClient) {
|
|
151
|
-
firstClient = true;
|
|
152
|
-
if (captureWarnings) {
|
|
153
|
-
process.on("warning", (warning) => {
|
|
154
|
-
this._logger.warn(warning.toString());
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
telemetry_ts_1.telemetryClient.setSdkHeaders(this.headers());
|
|
158
|
-
this._checkSdkDeprecation();
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
getWebsocketBase() {
|
|
162
|
-
if (http_start.test(this._baseUrl)) {
|
|
163
|
-
return `ws://${this._baseUrl.substring("ws://".length)}`;
|
|
164
|
-
}
|
|
165
|
-
else if (https_start.test(this._baseUrl)) {
|
|
166
|
-
return `wss://${this._baseUrl.substring("wss://".length)}`;
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
throw new Error(`Invalid base URL: ${this._baseUrl}}`);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
getHttpBase() {
|
|
173
|
-
return this._baseUrl;
|
|
174
|
-
}
|
|
175
|
-
headers() {
|
|
176
|
-
return {
|
|
177
|
-
Authorization: `Bearer ${this._apiKey}`,
|
|
178
|
-
"x-guava-platform": node_os_1.default.platform(),
|
|
179
|
-
"x-guava-runtime": process.release.name,
|
|
180
|
-
"x-guava-runtime-version": process.version,
|
|
181
|
-
"x-guava-sdk": SDK_NAME,
|
|
182
|
-
"x-guava-sdk-version": version_ts_1.SDK_VERSION,
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
async _checkSdkDeprecation() {
|
|
186
|
-
this._logger.debug(`Checking deprecation for SDK ${SDK_NAME}, ${version_ts_1.SDK_VERSION}.`);
|
|
187
|
-
try {
|
|
188
|
-
const url = new URL("v1/check-sdk-deprecation", this.getHttpBase());
|
|
189
|
-
url.searchParams.set("sdk_name", SDK_NAME);
|
|
190
|
-
url.searchParams.set("sdk_version", version_ts_1.SDK_VERSION);
|
|
191
|
-
const response = await (0, utils_ts_1.fetchOrThrow)(url, {
|
|
192
|
-
method: "POST",
|
|
193
|
-
headers: this.headers(),
|
|
194
|
-
});
|
|
195
|
-
const body = (await response.json());
|
|
196
|
-
if (body.deprecation_status === "supported") {
|
|
197
|
-
this._logger.info("SDK version still supported.");
|
|
198
|
-
}
|
|
199
|
-
else if (body.deprecation_status === "deprecated") {
|
|
200
|
-
process.emitWarning("This SDK version is deprecated. Please update to a newer version of the SDK.");
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
this._logger.warn("SDK deprecation status unknown.");
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
catch (e) {
|
|
207
|
-
this._logger.error("Encountered issue while checking for deprecation.");
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* @description use the Guava API to call out to a number
|
|
212
|
-
*/
|
|
213
|
-
createOutbound(fromNumber, toNumber, callController) {
|
|
214
|
-
const url = new URL("v1/create-outbound", this.getWebsocketBase());
|
|
215
|
-
const ws = new ws_1.default(url, {
|
|
216
|
-
headers: this.headers(),
|
|
217
|
-
});
|
|
218
|
-
ws.addEventListener("open", async (_ev) => {
|
|
219
|
-
ws.send(stringifyZod(commands_ts_1.StartOutboundCallCommand, {
|
|
220
|
-
command_type: "start-outbound",
|
|
221
|
-
to_number: toNumber,
|
|
222
|
-
from_number: fromNumber,
|
|
223
|
-
}));
|
|
224
|
-
// set the callController drain function to send all commands
|
|
225
|
-
// through the now open websocket
|
|
226
|
-
callController.setDrain(async (commands) => {
|
|
227
|
-
for (const command of commands.splice(0)) {
|
|
228
|
-
this._logger.debug(`Sending command ${JSON.stringify(command)}`);
|
|
229
|
-
ws.send(JSON.stringify(command));
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
await callController.onCallStart();
|
|
233
|
-
});
|
|
234
|
-
ws.addEventListener("close", (_ev) => {
|
|
235
|
-
// we are closing the socket, so don't trigger any other listeners
|
|
236
|
-
ws.removeAllListeners();
|
|
237
|
-
this._ws = undefined;
|
|
238
|
-
this._controller = undefined;
|
|
239
|
-
});
|
|
240
|
-
this._ws = ws;
|
|
241
|
-
this._controller = callController;
|
|
242
|
-
this.replaceHandler(this.uninitializedOutbound.bind(this));
|
|
243
|
-
}
|
|
244
|
-
replaceHandler(newHandler) {
|
|
245
|
-
if (this.messageHandler) {
|
|
246
|
-
this._ws?.removeEventListener("message", this.messageHandler);
|
|
247
|
-
}
|
|
248
|
-
if (newHandler) {
|
|
249
|
-
this._ws?.addEventListener("message", newHandler);
|
|
250
|
-
}
|
|
251
|
-
this.messageHandler = newHandler;
|
|
252
|
-
}
|
|
253
|
-
// eventlistener handlers for server events
|
|
254
|
-
// (a state machine in functions)
|
|
255
|
-
uninitializedOutbound(ev) {
|
|
256
|
-
// for correctness (and type correctness)
|
|
257
|
-
if (!this._ws) {
|
|
258
|
-
throw new Error("[internal] Uninitialized WebSocket");
|
|
259
|
-
}
|
|
260
|
-
const session_started = z
|
|
261
|
-
.union([events_ts_1.SessionStartedEvent, events_ts_1.ErrorEvent])
|
|
262
|
-
.parse(JSON.parse(ev.data.toString("utf8")));
|
|
263
|
-
if (session_started.event_type === "error") {
|
|
264
|
-
throw new Error(`Outbound call failed: ${session_started.content}`);
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
this._logger.info(`Started session with ID: ${session_started.session_id}`);
|
|
268
|
-
// move to next state
|
|
269
|
-
this.replaceHandler(this.initializedOutbound.bind(this));
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
async initializedOutbound(ev) {
|
|
273
|
-
// for correctness (and type correctness)
|
|
274
|
-
if (!this._ws) {
|
|
275
|
-
throw new Error("[internal] Uninitialized WebSocket");
|
|
276
|
-
}
|
|
277
|
-
// handle the received event
|
|
278
|
-
const event = (0, events_ts_1.decodeEvent)(ev.data);
|
|
279
|
-
if (event) {
|
|
280
|
-
if (this._controller) {
|
|
281
|
-
await this._controller.onEvent(event);
|
|
282
|
-
}
|
|
283
|
-
if (event.event_type === "outbound-call-failed" || event.event_type === "bot-session-ended") {
|
|
284
|
-
// shutdown the websocket
|
|
285
|
-
this._ws.close();
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* @description use the Guava API to receive calls at a given number
|
|
291
|
-
*/
|
|
292
|
-
listenInbound(conn, controllerClassFactory) {
|
|
293
|
-
const callControllers = {};
|
|
294
|
-
// return a way to *stop* listening
|
|
295
|
-
const url = new URL("v1/listen-inbound", this.getWebsocketBase());
|
|
296
|
-
const ws = new ws_1.default(url, {
|
|
297
|
-
headers: this.headers(),
|
|
298
|
-
});
|
|
299
|
-
let agent_number;
|
|
300
|
-
let webrtc_code;
|
|
301
|
-
if ("agent_number" in conn) {
|
|
302
|
-
agent_number = conn.agent_number;
|
|
303
|
-
}
|
|
304
|
-
else {
|
|
305
|
-
webrtc_code = conn.webrtc_code;
|
|
306
|
-
}
|
|
307
|
-
this._logger.info(`Listening for calls to ${agent_number ?? webrtc_code}`);
|
|
308
|
-
if (webrtc_code) {
|
|
309
|
-
const debugurl = new URL(`debug-webrtc?webrtc_code=${webrtc_code}`, this.getHttpBase());
|
|
310
|
-
this._logger.debug(`WebRTC DebugURL: ${debugurl}`);
|
|
311
|
-
}
|
|
312
|
-
ws.addEventListener("open", (_ev) => {
|
|
313
|
-
ws.send(stringifyZod(commands_ts_1.ListenInboundCommand, {
|
|
314
|
-
command_type: "listen-inbound",
|
|
315
|
-
agent_number: agent_number,
|
|
316
|
-
webrtc_code: webrtc_code,
|
|
317
|
-
}));
|
|
318
|
-
});
|
|
319
|
-
ws.addEventListener("close", (_ev) => {
|
|
320
|
-
ws.removeAllListeners();
|
|
321
|
-
});
|
|
322
|
-
ws.addEventListener("message", (ev) => {
|
|
323
|
-
const tunnel_event = events_ts_1.InboundTunnelEvent.parse(JSON.parse(ev.data.toString("utf8")));
|
|
324
|
-
if (!(tunnel_event.call_id in callControllers)) {
|
|
325
|
-
this._logger.info(`Received tunnel event for new call ID: ${tunnel_event.call_id}. Creating call controller.`);
|
|
326
|
-
const newController = controllerClassFactory(this._logger);
|
|
327
|
-
newController.setDrain(async (commands) => {
|
|
328
|
-
for (const command of commands.splice(0)) {
|
|
329
|
-
this._logger.debug(`Sending command: ${JSON.stringify(command)} for call ID: ${tunnel_event.call_id}`);
|
|
330
|
-
ws.send(stringifyZod(commands_ts_1.InboundTunnelCommand, {
|
|
331
|
-
call_id: tunnel_event.call_id,
|
|
332
|
-
command,
|
|
333
|
-
}));
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
callControllers[tunnel_event.call_id] = newController;
|
|
337
|
-
newController.onEvent(tunnel_event.event);
|
|
338
|
-
}
|
|
339
|
-
else {
|
|
340
|
-
// no threading, so manually forward to onEvent!
|
|
341
|
-
callControllers[tunnel_event.call_id].onEvent(tunnel_event.event);
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
return new InboundListener(ws);
|
|
345
|
-
}
|
|
346
|
-
};
|
|
347
|
-
return Client = _classThis;
|
|
348
|
-
})();
|
|
349
|
-
exports.Client = Client;
|
|
350
|
-
class InboundListener {
|
|
351
|
-
ws;
|
|
352
|
-
constructor(ws) {
|
|
353
|
-
this.ws = ws;
|
|
354
|
-
}
|
|
355
|
-
close() {
|
|
356
|
-
this.ws.close();
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
18
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAA6D;AAApD,mGAAA,MAAM,OAAA;AACf,2DAA0E;AAAjE,oHAAA,cAAc,OAAA;AACvB,mDAA8C;AAArC,qGAAA,GAAG,OAAA;AAAE,uGAAA,KAAK,OAAA;AACnB,2CAA0E;AAAzD,8GAAA,gBAAgB,OAAA;AAAE,8GAAA,gBAAgB,OAAA;AACnD,uCAA6C;AAApC,iGAAA,KAAK,OAAA;AACd,qCAAiC;AAAxB,+FAAA,IAAI,OAAA"}
|
package/dist/src/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.
|
|
1
|
+
export declare const SDK_VERSION = "0.13.0";
|
package/dist/src/version.js
CHANGED
package/examples/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Examples
|
|
2
2
|
|
|
3
|
-
- ./property-insurance.ts - A simple inbound phone call example demonstrating use of RAG and the `DocumentQA` class to answer
|
|
4
|
-
- ./
|
|
5
|
-
- ./
|
|
6
|
-
- ./scheduling-outbound.ts - An outbound phone call example
|
|
3
|
+
- [property-insurance.ts](./property-insurance.ts) - A simple inbound phone call example demonstrating use of RAG and the `DocumentQA` class to answer caller questions about a property insurance policy.
|
|
4
|
+
- [restaurant-waitlist.ts](./restaurant-waitlist.ts) - An inbound phone call example where the agent collects caller name, party size, and phone number to add the caller to a restaurant waitlist, then hangs up after confirming the details.
|
|
5
|
+
- [help-desk.ts](./help-desk.ts) - An inbound phone call example for a furniture retailer that uses `DocumentQA` to answer product questions and `IntentRecognizer` to classify caller intent, then transfers the caller to the appropriate department (sales, delivery and returns, account management, or general support).
|
|
6
|
+
- [scheduling-outbound.ts](./scheduling-outbound.ts) - An outbound phone call example where the agent calls a dental patient, verifies they are available, and schedules a cleaning appointment by searching available calendar slots using a `DatetimeFilter`.
|
package/examples/help-desk.ts
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@guava-ai/guava-sdk",
|
|
3
3
|
"description": "The official TypeScript SDK for building Guava voice agents.",
|
|
4
4
|
"homepage": "https://docs.goguava.ai/typescript-sdk/",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.13.0",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"main": "dist/src/index.js",
|
|
8
8
|
"types": "dist/src/index.d.ts",
|
package/src/agent.ts
CHANGED
|
@@ -158,7 +158,7 @@ export class Agent {
|
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
|
|
161
|
+
listenPhone(phoneNumber: string): InboundListener {
|
|
162
162
|
return this._listenInbound({
|
|
163
163
|
agent_number: phoneNumber,
|
|
164
164
|
});
|
|
@@ -367,7 +367,7 @@ export class Agent {
|
|
|
367
367
|
/**
|
|
368
368
|
* @description use the Guava API to call out to a number
|
|
369
369
|
*/
|
|
370
|
-
async
|
|
370
|
+
async callPhone(
|
|
371
371
|
fromNumber: string | undefined,
|
|
372
372
|
toNumber: string,
|
|
373
373
|
variables: Record<string, any> = {},
|
|
@@ -425,6 +425,21 @@ export class Agent {
|
|
|
425
425
|
ws.removeAllListeners();
|
|
426
426
|
});
|
|
427
427
|
}
|
|
428
|
+
|
|
429
|
+
/* ===== Aliases to be removed at some point. ===== */
|
|
430
|
+
/** @deprecated Use {@link listenPhone} instead. */
|
|
431
|
+
inboundPhone(phoneNumber: string): InboundListener {
|
|
432
|
+
return this.listenPhone(phoneNumber);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/** @deprecated Use {@link callPhone} instead. */
|
|
436
|
+
async outboundPhone(
|
|
437
|
+
fromNumber: string | undefined,
|
|
438
|
+
toNumber: string,
|
|
439
|
+
variables: Record<string, any> = {},
|
|
440
|
+
) {
|
|
441
|
+
return this.callPhone(fromNumber, toNumber, variables);
|
|
442
|
+
}
|
|
428
443
|
}
|
|
429
444
|
|
|
430
445
|
class InboundListener {
|