@guava-ai/guava-sdk 0.3.0 → 0.4.1
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.internal.md +13 -0
- package/README.md +50 -8
- package/bin/example-runner.js +16 -7
- package/dist/examples/credit-card-activation.js +94 -112
- package/dist/examples/credit-card-activation.js.map +1 -1
- package/dist/examples/property-insurance.js +12 -26
- package/dist/examples/property-insurance.js.map +1 -1
- package/dist/examples/scheduling-outbound.d.ts +1 -0
- package/dist/examples/scheduling-outbound.js +77 -0
- package/dist/examples/scheduling-outbound.js.map +1 -0
- package/dist/examples/thai-palace.js +25 -43
- package/dist/examples/thai-palace.js.map +1 -1
- package/dist/package.json +9 -5
- package/dist/src/action_item.d.ts +34 -12
- package/dist/src/action_item.js +34 -7
- package/dist/src/action_item.js.map +1 -1
- package/dist/src/call-controller.d.ts +137 -0
- package/dist/src/call-controller.js +433 -0
- package/dist/src/call-controller.js.map +1 -0
- package/dist/src/commands.d.ts +67 -27
- package/dist/src/commands.js +41 -27
- package/dist/src/commands.js.map +1 -1
- package/dist/src/events.d.ts +47 -30
- package/dist/src/events.js +42 -36
- package/dist/src/events.js.map +1 -1
- package/dist/src/example_data.d.ts +1 -0
- package/dist/src/example_data.js +33 -0
- package/dist/src/example_data.js.map +1 -1
- package/dist/src/helpers/openai.d.ts +12 -1
- package/dist/src/helpers/openai.js +168 -68
- package/dist/src/helpers/openai.js.map +1 -1
- package/dist/src/index.d.ts +6 -121
- package/dist/src/index.js +249 -483
- package/dist/src/index.js.map +1 -1
- package/dist/src/logging.d.ts +2 -1
- package/dist/src/logging.js +32 -7
- package/dist/src/logging.js.map +1 -1
- package/dist/src/telemetry.d.ts +23 -0
- package/dist/src/telemetry.js +98 -0
- package/dist/src/telemetry.js.map +1 -0
- package/dist/src/utils.d.ts +3 -0
- package/dist/src/utils.js +28 -0
- package/dist/src/utils.js.map +1 -0
- package/examples/biome.json +5 -0
- package/examples/credit-card-activation.ts +20 -26
- package/examples/property-insurance.ts +6 -16
- package/examples/scheduling-outbound.ts +97 -0
- package/examples/thai-palace.ts +10 -13
- package/package.json +9 -5
- package/src/action_item.ts +53 -13
- package/src/call-controller.ts +451 -0
- package/src/commands.ts +58 -42
- package/src/events.ts +66 -51
- package/src/example_data.ts +42 -0
- package/src/helpers/openai.ts +73 -18
- package/src/index.ts +81 -403
- package/src/logging.ts +39 -7
- package/src/telemetry.ts +125 -0
- package/src/utils.ts +32 -0
|
@@ -1,26 +1,46 @@
|
|
|
1
|
-
var
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
2
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
3
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
4
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
6
|
+
var _, done = false;
|
|
7
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
8
|
+
var context = {};
|
|
9
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
10
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
11
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
12
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
13
|
+
if (kind === "accessor") {
|
|
14
|
+
if (result === void 0) continue;
|
|
15
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
16
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
17
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
18
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
19
|
+
}
|
|
20
|
+
else if (_ = accept(result)) {
|
|
21
|
+
if (kind === "field") initializers.unshift(_);
|
|
22
|
+
else descriptor[key] = _;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
26
|
+
done = true;
|
|
9
27
|
};
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
28
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
29
|
+
var useValue = arguments.length > 2;
|
|
30
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
31
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
32
|
+
}
|
|
33
|
+
return useValue ? value : void 0;
|
|
16
34
|
};
|
|
17
35
|
import OpenAI, { toFile } from "openai";
|
|
36
|
+
import { zodTextFormat } from "openai/helpers/zod";
|
|
37
|
+
import { getDefaultLogger } from "../logging.js";
|
|
18
38
|
import * as z from "zod";
|
|
39
|
+
import { telemetryClient } from "../telemetry.js";
|
|
19
40
|
// from beta.py
|
|
20
41
|
// TODO: Remove after beta
|
|
21
42
|
function beta_create_openai_client(logger) {
|
|
22
|
-
|
|
23
|
-
const baseUrl = (_a = process.env.GUAVA_BASE_URL) !== null && _a !== void 0 ? _a : "https://guava-dev.gridspace.com/";
|
|
43
|
+
const baseUrl = process.env.GUAVA_BASE_URL ?? "https://guava-dev.gridspace.com/";
|
|
24
44
|
// to get it working with OpenAI TS/JS client
|
|
25
45
|
const basedUrl = new URL("openai/v1/", baseUrl);
|
|
26
46
|
logger.info(`Creating beta OpenAI client`);
|
|
@@ -29,15 +49,30 @@ function beta_create_openai_client(logger) {
|
|
|
29
49
|
apiKey: process.env.GUAVA_API_KEY,
|
|
30
50
|
});
|
|
31
51
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
52
|
+
let IntentRecognizer = (() => {
|
|
53
|
+
let _classDecorators = [telemetryClient.trackClass()];
|
|
54
|
+
let _classDescriptor;
|
|
55
|
+
let _classExtraInitializers = [];
|
|
56
|
+
let _classThis;
|
|
57
|
+
var IntentRecognizer = class {
|
|
58
|
+
static { _classThis = this; }
|
|
59
|
+
static {
|
|
60
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
61
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
62
|
+
IntentRecognizer = _classThis = _classDescriptor.value;
|
|
63
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
64
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
65
|
+
}
|
|
66
|
+
client;
|
|
67
|
+
intentChoices;
|
|
68
|
+
choiceModel;
|
|
69
|
+
constructor(choices, logger, client) {
|
|
70
|
+
this.intentChoices = choices;
|
|
71
|
+
this.client = client ?? beta_create_openai_client(logger);
|
|
72
|
+
this.choiceModel = z.union(choices.map((s) => z.literal(s)));
|
|
73
|
+
}
|
|
74
|
+
async classify(intent) {
|
|
75
|
+
const response = await this.client.responses.parse({
|
|
41
76
|
model: "gpt-5-mini",
|
|
42
77
|
input: `
|
|
43
78
|
Pick the choice in the list of choices that best reflects the given intent.
|
|
@@ -50,47 +85,51 @@ Possible Choices: ${this.intentChoices}.
|
|
|
50
85
|
});
|
|
51
86
|
const parsed_output = this.choiceModel.parse(response.output_text);
|
|
52
87
|
return parsed_output;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
return IntentRecognizer = _classThis;
|
|
91
|
+
})();
|
|
92
|
+
export { IntentRecognizer };
|
|
93
|
+
let DocumentQA = (() => {
|
|
94
|
+
let _classDecorators = [telemetryClient.trackClass()];
|
|
95
|
+
let _classDescriptor;
|
|
96
|
+
let _classExtraInitializers = [];
|
|
97
|
+
let _classThis;
|
|
98
|
+
var DocumentQA = class {
|
|
99
|
+
static { _classThis = this; }
|
|
100
|
+
static {
|
|
101
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
102
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
103
|
+
DocumentQA = _classThis = _classDescriptor.value;
|
|
104
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
105
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
106
|
+
}
|
|
107
|
+
client;
|
|
108
|
+
vector_store;
|
|
109
|
+
logger;
|
|
110
|
+
constructor(vector_store_name, document, logger = getDefaultLogger(), client) {
|
|
111
|
+
this.client = client ?? beta_create_openai_client(logger);
|
|
112
|
+
this.vector_store = this.getOrCreateVectorStore(vector_store_name, document);
|
|
113
|
+
this.logger = logger;
|
|
114
|
+
}
|
|
115
|
+
async getOrCreateVectorStore(vector_store_name, document) {
|
|
65
116
|
const encoder = new TextEncoder();
|
|
66
117
|
const document_buffer = encoder.encode(document);
|
|
67
|
-
const document_hash_buffer =
|
|
118
|
+
const document_hash_buffer = await crypto.subtle.digest("SHA-256", document_buffer);
|
|
68
119
|
const u8view = new Uint8Array(document_hash_buffer);
|
|
69
120
|
const document_hash = Array.from(u8view)
|
|
70
121
|
.map((b) => b.toString(16).padStart(2, "0"))
|
|
71
122
|
.join("");
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
vs.metadata &&
|
|
79
|
-
vs.metadata["document_hash"] == document_hash) {
|
|
80
|
-
this.logger.info("Re-using existing vector store...");
|
|
81
|
-
return vs;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
86
|
-
finally {
|
|
87
|
-
try {
|
|
88
|
-
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
|
123
|
+
for await (const vs of this.client.vectorStores.list()) {
|
|
124
|
+
if (vs.name === vector_store_name &&
|
|
125
|
+
vs.metadata &&
|
|
126
|
+
vs.metadata.document_hash === document_hash) {
|
|
127
|
+
this.logger.info("Re-using existing vector store...");
|
|
128
|
+
return vs;
|
|
89
129
|
}
|
|
90
|
-
finally { if (e_1) throw e_1.error; }
|
|
91
130
|
}
|
|
92
131
|
this.logger.info("Creating vector store...");
|
|
93
|
-
const vector_store =
|
|
132
|
+
const vector_store = await this.client.vectorStores.create({
|
|
94
133
|
name: vector_store_name,
|
|
95
134
|
expires_after: {
|
|
96
135
|
anchor: "last_active_at",
|
|
@@ -98,26 +137,24 @@ export class DocumentQA {
|
|
|
98
137
|
},
|
|
99
138
|
});
|
|
100
139
|
this.logger.info("Uploading file...");
|
|
101
|
-
|
|
140
|
+
await this.client.vectorStores.files.uploadAndPoll(vector_store.id, await toFile(new Blob([document], { type: "text/plain" }), "document.txt"));
|
|
102
141
|
this.logger.info("Updating vector store metadata...");
|
|
103
|
-
|
|
142
|
+
await this.client.vectorStores.update(vector_store.id, {
|
|
104
143
|
metadata: {
|
|
105
144
|
document_hash,
|
|
106
145
|
},
|
|
107
146
|
});
|
|
108
147
|
return vector_store;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
-
const response = yield this.client.responses.create({
|
|
148
|
+
}
|
|
149
|
+
async ask(question) {
|
|
150
|
+
const response = await this.client.responses.create({
|
|
114
151
|
model: "gpt-5-mini",
|
|
115
152
|
instructions: "You are a virtual contact center agent. Your task is to answer questions using the provided supporting document. Just answer the question - do not offer any follow-ups.",
|
|
116
153
|
input: question,
|
|
117
154
|
tools: [
|
|
118
155
|
{
|
|
119
156
|
type: "file_search",
|
|
120
|
-
vector_store_ids: [(
|
|
157
|
+
vector_store_ids: [(await this.vector_store).id],
|
|
121
158
|
},
|
|
122
159
|
],
|
|
123
160
|
reasoning: {
|
|
@@ -125,7 +162,70 @@ export class DocumentQA {
|
|
|
125
162
|
},
|
|
126
163
|
});
|
|
127
164
|
return response.output_text;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
return DocumentQA = _classThis;
|
|
168
|
+
})();
|
|
169
|
+
export { DocumentQA };
|
|
170
|
+
const filterSchema = z.object({
|
|
171
|
+
matchingAppointments: z.array(z.string()).describe("List of datetimes matching the query."),
|
|
172
|
+
otherAppointments: z
|
|
173
|
+
.array(z.string())
|
|
174
|
+
.describe("If no datetimes match the query, list of datetimes to suggest."),
|
|
175
|
+
});
|
|
176
|
+
let DatetimeFilter = (() => {
|
|
177
|
+
let _classDecorators = [telemetryClient.trackClass()];
|
|
178
|
+
let _classDescriptor;
|
|
179
|
+
let _classExtraInitializers = [];
|
|
180
|
+
let _classThis;
|
|
181
|
+
var DatetimeFilter = class {
|
|
182
|
+
static { _classThis = this; }
|
|
183
|
+
static {
|
|
184
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
185
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
186
|
+
DatetimeFilter = _classThis = _classDescriptor.value;
|
|
187
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
188
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
189
|
+
}
|
|
190
|
+
client;
|
|
191
|
+
sourceList;
|
|
192
|
+
constructor({ sourceList, client }, logger = getDefaultLogger()) {
|
|
193
|
+
this.sourceList = sourceList;
|
|
194
|
+
this.client = client ?? beta_create_openai_client(logger);
|
|
195
|
+
}
|
|
196
|
+
async filter(query, { maxResults = 5 } = {}) {
|
|
197
|
+
const appointmentTimesStr = this.sourceList.join("\n");
|
|
198
|
+
const today = new Date().toLocaleDateString("en-US", {
|
|
199
|
+
month: "long",
|
|
200
|
+
day: "numeric",
|
|
201
|
+
year: "numeric",
|
|
202
|
+
});
|
|
203
|
+
const prompt = `\
|
|
204
|
+
Return a few datetimes in the list matching the query. If no datetimes match the query, return a few other datetimes from the list that can be used as close suggestions.
|
|
205
|
+
NEVER HALLUCINATE DATETIMES THAT ARE NOT IN THE LIST.
|
|
206
|
+
Query: ${query}
|
|
207
|
+
Today's Date: ${today}
|
|
208
|
+
Appointment Times:
|
|
209
|
+
${appointmentTimesStr}
|
|
210
|
+
==================
|
|
211
|
+
You must return at most ${maxResults} options per list.`;
|
|
212
|
+
const response = await this.client.responses.parse({
|
|
213
|
+
model: "gpt-5-mini",
|
|
214
|
+
input: [{ role: "system", content: prompt }],
|
|
215
|
+
text: { format: zodTextFormat(filterSchema, "filter") },
|
|
216
|
+
reasoning: { effort: "medium" },
|
|
217
|
+
});
|
|
218
|
+
const output = response.output_parsed;
|
|
219
|
+
if (!output) {
|
|
220
|
+
throw new Error("Failed to produce parseable output.");
|
|
221
|
+
}
|
|
222
|
+
return [
|
|
223
|
+
output.matchingAppointments.slice(0, maxResults),
|
|
224
|
+
output.otherAppointments.slice(0, maxResults),
|
|
225
|
+
];
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
return DatetimeFilter = _classThis;
|
|
229
|
+
})();
|
|
230
|
+
export { DatetimeFilter };
|
|
131
231
|
//# sourceMappingURL=openai.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../../src/helpers/openai.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../../src/helpers/openai.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAe,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,eAAe;AACf,0BAA0B;AAC1B,SAAS,yBAAyB,CAAC,MAAc;IAC/C,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,kCAAkC,CAAC;IACjF,6CAA6C;IAC7C,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAChD,MAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;IAC3C,OAAO,IAAI,MAAM,CAAC;QAChB,OAAO,EAAE,QAAQ,CAAC,QAAQ,EAAE;QAC5B,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa;KAClC,CAAC,CAAC;AACL,CAAC;IAGY,gBAAgB;4BAD5B,eAAe,CAAC,UAAU,EAAE;;;;;;;;YAC7B,6KAyBC;;;YAzBY,uDAAgB;;QACnB,MAAM,CAAS;QACf,aAAa,CAAU;QACvB,WAAW,CAA6B;QAChD,YAAY,OAAgB,EAAE,MAAc,EAAE,MAAe;YAC3D,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC;YAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,yBAAyB,CAA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J,CAAC;;;;SAjDU,cAAc"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,127 +1,13 @@
|
|
|
1
1
|
import WebSocket from "ws";
|
|
2
2
|
import { type Logger } from "./logging.ts";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Interface between Guava services and user-supplied code
|
|
8
|
-
*/
|
|
9
|
-
export declare class CallController {
|
|
10
|
-
private _commandQueue;
|
|
11
|
-
private _on_complete_current_task?;
|
|
12
|
-
private _current_task_id?;
|
|
13
|
-
/**
|
|
14
|
-
* @protected
|
|
15
|
-
* @description logger used to emit diagnostics
|
|
16
|
-
*/
|
|
17
|
-
protected logger: Logger;
|
|
18
|
-
private _drain?;
|
|
19
|
-
private _fieldValues;
|
|
20
|
-
constructor(logger: Logger);
|
|
21
|
-
/**
|
|
22
|
-
* @description Supply a function used to consume commands from the internal command queue.
|
|
23
|
-
*
|
|
24
|
-
* The function is expected to remove from the argument array commands that it has handled (iterating
|
|
25
|
-
* through the result of `Array.splice(0)` is sufficient)
|
|
26
|
-
*/
|
|
27
|
-
setDrain(newDrain: (_: Command[]) => Promise<void>): void;
|
|
28
|
-
/**
|
|
29
|
-
* @description [inbound] receive a call, and process further.
|
|
30
|
-
*/
|
|
31
|
-
protected acceptCall(): Promise<void>;
|
|
32
|
-
/**
|
|
33
|
-
* @description read a span of text verbatim
|
|
34
|
-
*/
|
|
35
|
-
protected readScript(script: string): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
* @description [inbound] reject a call
|
|
38
|
-
*/
|
|
39
|
-
protected rejectCall(): Promise<void>;
|
|
40
|
-
protected addInfo(_info: string): Promise<void>;
|
|
41
|
-
/**
|
|
42
|
-
* @description read a span of text non-verbatim
|
|
43
|
-
*/
|
|
44
|
-
protected sendInstruction(instruction: string): Promise<void>;
|
|
45
|
-
/**
|
|
46
|
-
* @description provide identifiers the agent will use to identify the virtual agent
|
|
47
|
-
*/
|
|
48
|
-
protected setPersona(args: {
|
|
49
|
-
organizationName?: string;
|
|
50
|
-
agentName?: string;
|
|
51
|
-
agentPurpose?: string;
|
|
52
|
-
}): Promise<void>;
|
|
53
|
-
/**
|
|
54
|
-
* @description direct the agent to collect information
|
|
55
|
-
* @param goal {} an objective string and/or a checklist of information to collect
|
|
56
|
-
* @param on_complete {} a callback to call once the information is available from the agent
|
|
57
|
-
* @param args {} arguments to pass through to the `on_complete` callback
|
|
58
|
-
*/
|
|
59
|
-
protected setTask(goal: TaskObjective, on_complete?: (...c: any[]) => void, ...args: any[]): void;
|
|
60
|
-
/**
|
|
61
|
-
* @description direct the agent to collect information, continuing execution once the agent has collected the information
|
|
62
|
-
* @param goal {} an objective string and/or a checklist of information to collect
|
|
63
|
-
*/
|
|
64
|
-
protected awaitTask(goal: TaskObjective): Promise<void>;
|
|
65
|
-
/**
|
|
66
|
-
* @description retrieve a piece of information that the agent has collected
|
|
67
|
-
* @param key {string} key of the field checklist item
|
|
68
|
-
*/
|
|
69
|
-
protected getField(key: string): unknown;
|
|
70
|
-
/**
|
|
71
|
-
* @description [inbound] hang up an accepted call
|
|
72
|
-
*/
|
|
73
|
-
protected hangup(final_instructions?: string): Promise<void>;
|
|
74
|
-
/**
|
|
75
|
-
* @description transfer an accepted call
|
|
76
|
-
*/
|
|
77
|
-
protected transfer(to_number: string, transfer_message?: string): void;
|
|
78
|
-
private sendCommand;
|
|
79
|
-
private flush;
|
|
80
|
-
onEvent(event: GuavaEvent): Promise<void>;
|
|
81
|
-
/**
|
|
82
|
-
* @abstract
|
|
83
|
-
* @description called when an inbound call is received. The overriding function must start
|
|
84
|
-
* with `await super.onIncomingCall(from_number)`
|
|
85
|
-
*/
|
|
86
|
-
onIncomingCall(from_number?: string): Promise<void>;
|
|
87
|
-
/**
|
|
88
|
-
* @abstract
|
|
89
|
-
* @description called when a call is connected by the API, whether inbound or outbound
|
|
90
|
-
*/
|
|
91
|
-
onCallStart(): Promise<void>;
|
|
92
|
-
/**
|
|
93
|
-
* @abstract
|
|
94
|
-
* @description called when the caller speaks to the agent.
|
|
95
|
-
*/
|
|
96
|
-
onCallerSpeech(event: CallerSpeechEvent): Promise<void>;
|
|
97
|
-
/**
|
|
98
|
-
* @abstract
|
|
99
|
-
* @description called when the agent speaks to the caller.
|
|
100
|
-
*/
|
|
101
|
-
onAgentSpeech(event: AgentSpeechEvent): Promise<void>;
|
|
102
|
-
/**
|
|
103
|
-
* @abstract
|
|
104
|
-
* @description called when the caller expresses a task they wish to execute
|
|
105
|
-
*/
|
|
106
|
-
onIntent(intent: string): Promise<string | null>;
|
|
107
|
-
/**
|
|
108
|
-
* @abstract
|
|
109
|
-
* @description called when the agent needs to respond to a question that it doesn't know
|
|
110
|
-
* the answer to.
|
|
111
|
-
*/
|
|
112
|
-
onQuestion(question: string): Promise<string>;
|
|
113
|
-
}
|
|
3
|
+
import type { CallController } from "./call-controller.ts";
|
|
4
|
+
export { CallController, type TaskObjective } from "./call-controller.ts";
|
|
5
|
+
export { Say, Field } from "./action_item.ts";
|
|
114
6
|
export type InboundConnection = {
|
|
115
7
|
agent_number: string;
|
|
116
8
|
} | {
|
|
117
9
|
webrtc_code: string;
|
|
118
10
|
};
|
|
119
|
-
export type TaskObjective = {
|
|
120
|
-
objective: string;
|
|
121
|
-
} | {
|
|
122
|
-
objective?: string;
|
|
123
|
-
checklist: (Field | Say | string)[];
|
|
124
|
-
};
|
|
125
11
|
export declare class Client {
|
|
126
12
|
private _apiKey;
|
|
127
13
|
private _baseUrl;
|
|
@@ -129,18 +15,18 @@ export declare class Client {
|
|
|
129
15
|
private _ws?;
|
|
130
16
|
private _controller?;
|
|
131
17
|
private messageHandler?;
|
|
132
|
-
constructor(apiKey?: string, baseUrl?: string, logger?: Logger);
|
|
18
|
+
constructor(apiKey?: string, baseUrl?: string, logger?: Logger, captureWarnings?: boolean);
|
|
133
19
|
private getWebsocketBase;
|
|
134
20
|
private getHttpBase;
|
|
135
21
|
private headers;
|
|
22
|
+
private _checkSdkDeprecation;
|
|
136
23
|
/**
|
|
137
24
|
* @description use the Guava API to call out to a number
|
|
138
25
|
*/
|
|
139
|
-
createOutbound(fromNumber: string | undefined, toNumber: string,
|
|
26
|
+
createOutbound(fromNumber: string | undefined, toNumber: string, callController: CallController): void;
|
|
140
27
|
private replaceHandler;
|
|
141
28
|
private uninitializedOutbound;
|
|
142
29
|
private initializedOutbound;
|
|
143
|
-
setInboundHandler(agent_number: string, public_url: string, inbound_token: string): Promise<void>;
|
|
144
30
|
/**
|
|
145
31
|
* @description use the Guava API to receive calls at a given number
|
|
146
32
|
*/
|
|
@@ -151,4 +37,3 @@ declare class InboundListener {
|
|
|
151
37
|
constructor(ws: WebSocket);
|
|
152
38
|
close(): void;
|
|
153
39
|
}
|
|
154
|
-
export {};
|