@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,73 +1,55 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import * as guava from "../src/index.js";
|
|
11
2
|
import { getConsoleLogger } from "../src/logging.js";
|
|
12
3
|
import { IntentRecognizer } from "../src/helpers/openai.js";
|
|
13
4
|
class ThaiPalaceCallController extends guava.CallController {
|
|
5
|
+
choices = ["restaurant waitlist", "anything else"];
|
|
6
|
+
intentRecognizer;
|
|
14
7
|
constructor(logger) {
|
|
15
8
|
super(logger);
|
|
16
|
-
this.choices = ["restaurant waitlist", "anything else"];
|
|
17
9
|
this.intentRecognizer = new IntentRecognizer(this.choices, logger);
|
|
18
10
|
this.setPersona({
|
|
19
11
|
organizationName: "Thai Palace",
|
|
20
12
|
});
|
|
21
13
|
}
|
|
22
|
-
onIncomingCall(from_number) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
yield _super.onIncomingCall.call(this, from_number);
|
|
28
|
-
this.acceptCall();
|
|
29
|
-
this.setThaiPalaceTask();
|
|
30
|
-
});
|
|
14
|
+
async onIncomingCall(from_number) {
|
|
15
|
+
await super.onIncomingCall(from_number);
|
|
16
|
+
this.acceptCall();
|
|
17
|
+
this.setThaiPalaceTask();
|
|
31
18
|
}
|
|
32
19
|
setThaiPalaceTask() {
|
|
33
20
|
this.setTask({
|
|
34
21
|
objective: `You are a virtual assistant for a restaurant called Thai Palace.
|
|
35
22
|
Your job is to add callers to the waitlist.`,
|
|
36
23
|
checklist: [
|
|
37
|
-
{
|
|
38
|
-
item_type: "field",
|
|
24
|
+
guava.Field({
|
|
39
25
|
key: "caller_name",
|
|
40
|
-
|
|
26
|
+
fieldType: "text",
|
|
41
27
|
description: "The name to be added to the waitlist",
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
item_type: "field",
|
|
28
|
+
}),
|
|
29
|
+
guava.Field({
|
|
45
30
|
key: "party_size",
|
|
46
|
-
|
|
31
|
+
fieldType: "integer",
|
|
47
32
|
description: "The number of people attending",
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
item_type: "field",
|
|
33
|
+
}),
|
|
34
|
+
guava.Field({
|
|
51
35
|
key: "phone_number",
|
|
52
|
-
|
|
36
|
+
fieldType: "text",
|
|
53
37
|
description: "phone number to text when table is ready",
|
|
54
|
-
},
|
|
38
|
+
}),
|
|
55
39
|
"Read the phone number back to the caller to make sure you got it right",
|
|
56
40
|
],
|
|
57
41
|
}, () => this.hangup());
|
|
58
42
|
}
|
|
59
|
-
onIntent(intent) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
});
|
|
43
|
+
async onIntent(intent) {
|
|
44
|
+
const choice = await this.intentRecognizer.classify(intent);
|
|
45
|
+
this.logger.info(`Chosen intent: ${choice}`);
|
|
46
|
+
if (choice === "restaurant waitlist") {
|
|
47
|
+
this.setThaiPalaceTask();
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
return "Tell them we only handle waitlist additions at this number.";
|
|
52
|
+
}
|
|
71
53
|
}
|
|
72
54
|
}
|
|
73
55
|
export function run(_args) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thai-palace.js","sourceRoot":"","sources":["../../examples/thai-palace.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"thai-palace.js","sourceRoot":"","sources":["../../examples/thai-palace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAe,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,MAAM,wBAAyB,SAAQ,KAAK,CAAC,cAAc;IACjD,OAAO,GAAG,CAAC,qBAAqB,EAAE,eAAe,CAAU,CAAC;IAC5D,gBAAgB,CAAwC;IAChE,YAAY,MAAc;QACxB,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,gBAAgB,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACnE,IAAI,CAAC,UAAU,CAAC;YACd,gBAAgB,EAAE,aAAa;SAChC,CAAC,CAAC;IACL,CAAC;IAEQ,KAAK,CAAC,cAAc,CAAC,WAAoB;QAChD,MAAM,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;QACxC,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC3B,CAAC;IAED,iBAAiB;QACf,IAAI,CAAC,OAAO,CACV;YACE,SAAS,EAAE;6CAC0B;YACrC,SAAS,EAAE;gBACT,KAAK,CAA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
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guava-ai/guava-sdk",
|
|
3
|
-
"
|
|
3
|
+
"description": "The official TypeScript SDK for building Guava voice agents.",
|
|
4
|
+
"homepage": "https://docs.goguava.ai/typescript-sdk/",
|
|
5
|
+
"version": "0.4.1",
|
|
4
6
|
"type": "module",
|
|
5
7
|
"main": "dist/src/index.js",
|
|
6
8
|
"types": "dist/src/index.d.ts",
|
|
@@ -8,6 +10,7 @@
|
|
|
8
10
|
"@biomejs/biome": "2.3.11",
|
|
9
11
|
"@types/node": "^25.0.7",
|
|
10
12
|
"@types/ws": "^8.18.1",
|
|
13
|
+
"tsx": "^4.21.0",
|
|
11
14
|
"typescript": "^5.9.3"
|
|
12
15
|
},
|
|
13
16
|
"bin": {
|
|
@@ -20,10 +23,11 @@
|
|
|
20
23
|
},
|
|
21
24
|
"scripts": {
|
|
22
25
|
"typecheck": "tsc --noEmit",
|
|
23
|
-
"lint": "biome lint",
|
|
24
|
-
"
|
|
25
|
-
"format
|
|
26
|
-
"
|
|
26
|
+
"lint": "biome lint --max-diagnostics=none",
|
|
27
|
+
"lint-fix": "biome lint --max-diagnostics=none --write",
|
|
28
|
+
"check-format": "biome format ./src ./examples",
|
|
29
|
+
"format": "biome format --write ./src ./examples",
|
|
30
|
+
"check": "npm run typecheck && npm audit && npm run lint && npm run check-format",
|
|
27
31
|
"clean": "rm -rf ./dist",
|
|
28
32
|
"build": "tsc",
|
|
29
33
|
"prepublishOnly": "npm run clean && npm run build"
|
|
@@ -1,34 +1,47 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
|
-
export declare const
|
|
3
|
-
export type FieldItemType = z.input<typeof
|
|
4
|
-
export
|
|
2
|
+
export declare const FieldItemType: z.ZodUnion<z.ZodLiteral<"text" | "integer" | "date" | "datetime" | "multiple_choice" | "calendar_slot">[]>;
|
|
3
|
+
export type FieldItemType = z.input<typeof FieldItemType>;
|
|
4
|
+
export type ChoiceGenerator = (query: string) => Promise<[string[], string[]]>;
|
|
5
|
+
export declare const FieldItem: z.ZodObject<{
|
|
5
6
|
item_type: z.ZodLiteral<"field">;
|
|
6
7
|
key: z.ZodString;
|
|
7
8
|
description: z.ZodString;
|
|
8
|
-
field_type: z.ZodUnion<z.ZodLiteral<"text" | "integer" | "date" | "datetime" | "multiple_choice">[]>;
|
|
9
|
+
field_type: z.ZodUnion<z.ZodLiteral<"text" | "integer" | "date" | "datetime" | "multiple_choice" | "calendar_slot">[]>;
|
|
9
10
|
required: z.ZodDefault<z.ZodBoolean>;
|
|
10
11
|
choices: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
12
|
+
choiceGenerator: z.ZodOptional<z.ZodCustom<ChoiceGenerator, ChoiceGenerator>>;
|
|
11
13
|
}, z.core.$strip>;
|
|
12
|
-
export type
|
|
13
|
-
export declare const
|
|
14
|
+
export type FieldItem = z.input<typeof FieldItem>;
|
|
15
|
+
export declare const SerializableFieldItem: z.ZodObject<{
|
|
16
|
+
item_type: z.ZodLiteral<"field">;
|
|
17
|
+
key: z.ZodString;
|
|
18
|
+
description: z.ZodString;
|
|
19
|
+
field_type: z.ZodUnion<z.ZodLiteral<"text" | "integer" | "date" | "datetime" | "multiple_choice" | "calendar_slot">[]>;
|
|
20
|
+
required: z.ZodDefault<z.ZodBoolean>;
|
|
21
|
+
choices: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
22
|
+
is_search_field: z.ZodDefault<z.ZodBoolean>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
export type SerializableFieldItem = z.input<typeof SerializableFieldItem>;
|
|
25
|
+
export declare const SayItem: z.ZodObject<{
|
|
14
26
|
item_type: z.ZodLiteral<"say">;
|
|
15
27
|
statement: z.ZodString;
|
|
16
28
|
key: z.ZodDefault<z.ZodString>;
|
|
17
29
|
}, z.core.$strip>;
|
|
18
|
-
export type
|
|
19
|
-
export declare const
|
|
30
|
+
export type SayItem = z.input<typeof SayItem>;
|
|
31
|
+
export declare const TodoItem: z.ZodObject<{
|
|
20
32
|
item_type: z.ZodLiteral<"todo">;
|
|
21
33
|
description: z.ZodString;
|
|
22
34
|
key: z.ZodDefault<z.ZodString>;
|
|
23
35
|
}, z.core.$strip>;
|
|
24
|
-
export type
|
|
25
|
-
export declare const
|
|
36
|
+
export type TodoItem = z.input<typeof TodoItem>;
|
|
37
|
+
export declare const ActionItem: z.ZodUnion<readonly [z.ZodObject<{
|
|
26
38
|
item_type: z.ZodLiteral<"field">;
|
|
27
39
|
key: z.ZodString;
|
|
28
40
|
description: z.ZodString;
|
|
29
|
-
field_type: z.ZodUnion<z.ZodLiteral<"text" | "integer" | "date" | "datetime" | "multiple_choice">[]>;
|
|
41
|
+
field_type: z.ZodUnion<z.ZodLiteral<"text" | "integer" | "date" | "datetime" | "multiple_choice" | "calendar_slot">[]>;
|
|
30
42
|
required: z.ZodDefault<z.ZodBoolean>;
|
|
31
43
|
choices: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
44
|
+
is_search_field: z.ZodDefault<z.ZodBoolean>;
|
|
32
45
|
}, z.core.$strip>, z.ZodObject<{
|
|
33
46
|
item_type: z.ZodLiteral<"say">;
|
|
34
47
|
statement: z.ZodString;
|
|
@@ -38,4 +51,13 @@ export declare const actionItem: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
38
51
|
description: z.ZodString;
|
|
39
52
|
key: z.ZodDefault<z.ZodString>;
|
|
40
53
|
}, z.core.$strip>]>;
|
|
41
|
-
export type ActionItem = z.input<typeof
|
|
54
|
+
export type ActionItem = z.input<typeof ActionItem>;
|
|
55
|
+
export declare function Field(options: {
|
|
56
|
+
key: string;
|
|
57
|
+
description: string;
|
|
58
|
+
fieldType: FieldItemType;
|
|
59
|
+
required?: boolean;
|
|
60
|
+
choices?: string[];
|
|
61
|
+
choiceGenerator?: ChoiceGenerator;
|
|
62
|
+
}): FieldItem;
|
|
63
|
+
export declare function Say(statement: string): SayItem;
|
package/dist/src/action_item.js
CHANGED
|
@@ -1,29 +1,56 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
|
-
export const
|
|
3
|
-
export const
|
|
2
|
+
export const FieldItemType = z.union(["text", "date", "datetime", "integer", "multiple_choice", "calendar_slot"].map((val) => z.literal(val)));
|
|
3
|
+
export const FieldItem = z
|
|
4
4
|
.object({
|
|
5
5
|
item_type: z.literal("field"),
|
|
6
6
|
key: z.string(),
|
|
7
7
|
description: z.string(),
|
|
8
|
-
field_type:
|
|
8
|
+
field_type: FieldItemType,
|
|
9
9
|
required: z.boolean().default(true),
|
|
10
10
|
choices: z.array(z.string()).default([]),
|
|
11
|
+
choiceGenerator: z.custom((val) => typeof val === "function").optional(),
|
|
11
12
|
})
|
|
12
13
|
.refine((field) => {
|
|
13
|
-
if (field.field_type
|
|
14
|
+
if (field.field_type === "multiple_choice" && field.choices.length > 10) {
|
|
14
15
|
process.emitWarning("Performance degrades with large number of choices for multiple choice field.", "ACTION_ITEM");
|
|
15
16
|
}
|
|
16
17
|
return true;
|
|
17
18
|
});
|
|
18
|
-
export const
|
|
19
|
+
export const SerializableFieldItem = z.object({
|
|
20
|
+
item_type: z.literal("field"),
|
|
21
|
+
key: z.string(),
|
|
22
|
+
description: z.string(),
|
|
23
|
+
field_type: FieldItemType,
|
|
24
|
+
required: z.boolean().default(true),
|
|
25
|
+
choices: z.array(z.string()).default([]),
|
|
26
|
+
is_search_field: z.boolean().default(false),
|
|
27
|
+
});
|
|
28
|
+
export const SayItem = z.object({
|
|
19
29
|
item_type: z.literal("say"),
|
|
20
30
|
statement: z.string(),
|
|
21
31
|
key: z.string().default(() => Math.random().toString(16).substring(2, 6)),
|
|
22
32
|
});
|
|
23
|
-
export const
|
|
33
|
+
export const TodoItem = z.object({
|
|
24
34
|
item_type: z.literal("todo"),
|
|
25
35
|
description: z.string(),
|
|
26
36
|
key: z.string().default(() => Math.random().toString(16).substring(2, 6)),
|
|
27
37
|
});
|
|
28
|
-
export const
|
|
38
|
+
export const ActionItem = z.union([SerializableFieldItem, SayItem, TodoItem]);
|
|
39
|
+
export function Field(options) {
|
|
40
|
+
return FieldItem.parse({
|
|
41
|
+
item_type: "field",
|
|
42
|
+
key: options.key,
|
|
43
|
+
description: options.description,
|
|
44
|
+
field_type: options.fieldType,
|
|
45
|
+
required: options.required,
|
|
46
|
+
choices: options.choices,
|
|
47
|
+
choiceGenerator: options.choiceGenerator,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
export function Say(statement) {
|
|
51
|
+
return SayItem.parse({
|
|
52
|
+
item_type: "say",
|
|
53
|
+
statement: statement,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
29
56
|
//# sourceMappingURL=action_item.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action_item.js","sourceRoot":"","sources":["../../src/action_item.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CACjC,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,iBAAiB,CAAW,CAAC,GAAG,
|
|
1
|
+
{"version":3,"file":"action_item.js","sourceRoot":"","sources":["../../src/action_item.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CACjC,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,iBAAiB,EAAE,eAAe,CAAW,CAAC,GAAG,CACxF,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CACxB,CACF,CAAC;AAKF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC;KACvB,MAAM,CAAC;IACN,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;IAC7B,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,WAAW,EAAE,CAAC,CAAC,MAAM,E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|
|
1
|
+
import { type Logger } from "./logging.ts";
|
|
2
|
+
import { type Command } from "./commands.ts";
|
|
3
|
+
import type { GuavaEvent, CallerSpeechEvent, AgentSpeechEvent } from "./events.ts";
|
|
4
|
+
import { type FieldItem, type SayItem } from "./action_item.ts";
|
|
5
|
+
export type TaskObjective = {
|
|
6
|
+
objective: string;
|
|
7
|
+
} | {
|
|
8
|
+
objective?: string;
|
|
9
|
+
checklist: (FieldItem | SayItem | string)[];
|
|
10
|
+
};
|
|
11
|
+
export type ReachPersonOutcome = {
|
|
12
|
+
key: string;
|
|
13
|
+
onOutcome: () => void;
|
|
14
|
+
description?: string;
|
|
15
|
+
nextActionPreview?: string;
|
|
16
|
+
};
|
|
17
|
+
type ReachPersonOptions = {
|
|
18
|
+
onSuccess: () => void;
|
|
19
|
+
onFailure: () => void;
|
|
20
|
+
greeting?: string;
|
|
21
|
+
} | {
|
|
22
|
+
outcomes: ReachPersonOutcome[];
|
|
23
|
+
greeting?: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Interface between Guava services and user-supplied code
|
|
27
|
+
*/
|
|
28
|
+
export declare class CallController {
|
|
29
|
+
private _commandQueue;
|
|
30
|
+
private _on_complete_current_task?;
|
|
31
|
+
private _current_task_id?;
|
|
32
|
+
/**
|
|
33
|
+
* @protected
|
|
34
|
+
* @description logger used to emit diagnostics
|
|
35
|
+
*/
|
|
36
|
+
protected logger: Logger;
|
|
37
|
+
private _drain?;
|
|
38
|
+
private _fieldValues;
|
|
39
|
+
private _searchFunctionsByKey;
|
|
40
|
+
constructor(logger?: Logger);
|
|
41
|
+
/**
|
|
42
|
+
* @description Supply a function used to consume commands from the internal command queue.
|
|
43
|
+
*
|
|
44
|
+
* The function is expected to remove from the argument array commands that it has handled (iterating
|
|
45
|
+
* through the result of `Array.splice(0)` is sufficient)
|
|
46
|
+
*/
|
|
47
|
+
setDrain(newDrain: (_: Command[]) => Promise<void>): void;
|
|
48
|
+
/**
|
|
49
|
+
* @description [inbound] receive a call, and process further.
|
|
50
|
+
*/
|
|
51
|
+
protected acceptCall(): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* @description read a span of text verbatim
|
|
54
|
+
*/
|
|
55
|
+
protected readScript(script: string): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* @description [inbound] reject a call
|
|
58
|
+
*/
|
|
59
|
+
protected rejectCall(): Promise<void>;
|
|
60
|
+
protected addInfo(_info: string): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* @description read a span of text non-verbatim
|
|
63
|
+
*/
|
|
64
|
+
protected sendInstruction(instruction: string): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* @description provide identifiers the agent will use to identify the virtual agent
|
|
67
|
+
*/
|
|
68
|
+
protected setPersona(args: {
|
|
69
|
+
organizationName?: string;
|
|
70
|
+
agentName?: string;
|
|
71
|
+
agentPurpose?: string;
|
|
72
|
+
voice?: string;
|
|
73
|
+
}): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* @description direct the agent to collect information
|
|
76
|
+
* @param goal {} an objective string and/or a checklist of information to collect
|
|
77
|
+
* @param on_complete {} a callback to call once the information is available from the agent
|
|
78
|
+
* @param args {} arguments to pass through to the `on_complete` callback
|
|
79
|
+
*/
|
|
80
|
+
protected setTask(goal: TaskObjective, on_complete?: (...c: any[]) => void, ...args: any[]): void;
|
|
81
|
+
/**
|
|
82
|
+
* @description direct the agent to collect information, continuing execution once the agent has collected the information
|
|
83
|
+
* @param goal {} an objective string and/or a checklist of information to collect
|
|
84
|
+
*/
|
|
85
|
+
protected awaitTask(goal: TaskObjective): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* @description retrieve a piece of information that the agent has collected
|
|
88
|
+
* @param key {string} key of the field checklist item
|
|
89
|
+
*/
|
|
90
|
+
protected getField(key: string): unknown;
|
|
91
|
+
/**
|
|
92
|
+
* @description [inbound] hang up an accepted call
|
|
93
|
+
*/
|
|
94
|
+
protected hangup(final_instructions?: string): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* @description helper for reaching a specific contact on an outbound call and recording their availability.
|
|
97
|
+
*/
|
|
98
|
+
protected reachPerson(contactFullName: string, options: ReachPersonOptions): void;
|
|
99
|
+
/**
|
|
100
|
+
* @description transfer an accepted call
|
|
101
|
+
*/
|
|
102
|
+
protected transfer(to_number: string, transfer_message?: string): void;
|
|
103
|
+
private sendCommand;
|
|
104
|
+
private flush;
|
|
105
|
+
onEvent(event: GuavaEvent): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* @description called when an inbound call is received. The overriding function must start
|
|
108
|
+
* with `await super.onIncomingCall(from_number)`
|
|
109
|
+
*/
|
|
110
|
+
onIncomingCall(from_number?: string): Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* @description called when a call is connected by the API, whether inbound or outbound
|
|
113
|
+
*/
|
|
114
|
+
onCallStart(): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* @description called when the caller speaks to the agent.
|
|
117
|
+
*/
|
|
118
|
+
onCallerSpeech(event: CallerSpeechEvent): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* @description called when the agent speaks to the caller.
|
|
121
|
+
*/
|
|
122
|
+
onAgentSpeech(event: AgentSpeechEvent): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* @description called when the caller expresses a task they wish to execute
|
|
125
|
+
*/
|
|
126
|
+
onIntent(intent: string): Promise<string | null>;
|
|
127
|
+
/**
|
|
128
|
+
* @description called when the agent needs to respond to a question that it doesn't know
|
|
129
|
+
* the answer to.
|
|
130
|
+
*/
|
|
131
|
+
onQuestion(question: string): Promise<string>;
|
|
132
|
+
/**
|
|
133
|
+
* @description called when the bot session has ended.
|
|
134
|
+
*/
|
|
135
|
+
onSessionDone(): void;
|
|
136
|
+
}
|
|
137
|
+
export {};
|