@sprucelabs/spruce-conversation-plugin 62.0.0 → 62.0.2
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/build/.spruce/errors/conversation/abort.schema.js +1 -1
- package/build/.spruce/errors/conversation/conversationAborted.schema.js +1 -1
- package/build/.spruce/errors/conversation/conversationPluginError.schema.js +1 -1
- package/build/.spruce/errors/conversation/invalidTopic.schema.js +3 -3
- package/build/.spruce/errors/conversation/missingDependencies.schema.js +3 -3
- package/build/.spruce/errors/conversation/testerNotStarted.schema.js +1 -1
- package/build/.spruce/errors/conversation/topicNotFound.schema.js +5 -5
- package/build/.spruce/schemas/fields/fields.types.d.ts +1 -1
- package/build/__tests__/behavioral/KillingASkill.test.js +1 -1
- package/build/__tests__/behavioral/RegisteringConversationsOnBoot.test.js +4 -2
- package/build/__tests__/behavioral/RespondingToMessages.test.js +1 -1
- package/build/__tests__/implementation/ConversationCoordinator.test.js +24 -6
- package/build/__tests__/implementation/MessageGraphicsInterface/EmailField.test.js +3 -1
- package/build/__tests__/implementation/MessageGraphicsInterface/TextField.test.js +3 -1
- package/build/__tests__/implementation/TopicScriptPlayer.test.js +5 -1
- package/build/__tests__/implementation/TopicSuggester.test.js +7 -1
- package/build/__tests__/testDirsAndFiles/good/conversations/cancelAppointment.topic.js +5 -1
- package/build/__tests__/testDirsAndFiles/skill/build/conversations/cancelAppointment.topic.js +5 -1
- package/build/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColor.topic.js +4 -1
- package/build/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColorTopicChanger.topic.js +4 -1
- package/build/__tests__/testDirsAndFiles/skill-with-script-that-throws/build/conversations/cancelAppointment.topic.js +5 -1
- package/build/esm/__tests__/behavioral/KillingASkill.test.js +1 -1
- package/build/esm/__tests__/behavioral/RegisteringConversationsOnBoot.test.js +4 -2
- package/build/esm/__tests__/behavioral/RespondingToMessages.test.js +1 -1
- package/build/esm/__tests__/implementation/ConversationCoordinator.test.js +24 -6
- package/build/esm/__tests__/implementation/MessageGraphicsInterface/EmailField.test.js +3 -1
- package/build/esm/__tests__/implementation/MessageGraphicsInterface/TextField.test.js +3 -1
- package/build/esm/__tests__/implementation/TopicScriptPlayer.test.js +5 -1
- package/build/esm/__tests__/implementation/TopicSuggester.test.js +7 -1
- package/build/esm/__tests__/testDirsAndFiles/good/conversations/cancelAppointment.topic.js +5 -1
- package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/cancelAppointment.topic.js +5 -1
- package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColor.topic.js +4 -1
- package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColorTopicChanger.topic.js +4 -1
- package/build/esm/__tests__/testDirsAndFiles/skill-with-script-that-throws/build/conversations/cancelAppointment.topic.js +5 -1
- package/build/esm/plugins/conversation.plugin.js +25 -20
- package/build/esm/tests/AbstractGraphicsInterfaceTest.js +4 -1
- package/build/esm/tests/ScriptTester.js +19 -7
- package/build/esm/topics/TopicLoader.js +3 -1
- package/build/esm/topics/TopicScriptPlayer.js +2 -1
- package/build/esm/topics/TopicSuggester.js +5 -1
- package/build/esm/types/conversation.types.d.ts +6 -10
- package/build/esm/utilities/suggester.utility.d.ts +2 -2
- package/build/plugins/conversation.plugin.js +25 -20
- package/build/tests/AbstractGraphicsInterfaceTest.js +4 -1
- package/build/tests/ScriptTester.js +19 -7
- package/build/topics/TopicLoader.js +3 -1
- package/build/topics/TopicScriptPlayer.js +2 -1
- package/build/topics/TopicSuggester.js +5 -1
- package/build/types/conversation.types.d.ts +6 -10
- package/build/utilities/suggester.utility.d.ts +2 -2
- package/package.json +20 -20
|
@@ -5,7 +5,7 @@ const conversationAbortedSchema = {
|
|
|
5
5
|
id: 'conversationAborted',
|
|
6
6
|
namespace: 'Conversation',
|
|
7
7
|
name: 'Conversation aborted',
|
|
8
|
-
fields: {}
|
|
8
|
+
fields: {},
|
|
9
9
|
};
|
|
10
10
|
schema_1.SchemaRegistry.getInstance().trackSchema(conversationAbortedSchema);
|
|
11
11
|
exports.default = conversationAbortedSchema;
|
|
@@ -5,7 +5,7 @@ const conversationPluginErrorSchema = {
|
|
|
5
5
|
id: 'conversationPluginError',
|
|
6
6
|
namespace: 'Conversation',
|
|
7
7
|
name: 'Conversation plugin error',
|
|
8
|
-
fields: {}
|
|
8
|
+
fields: {},
|
|
9
9
|
};
|
|
10
10
|
schema_1.SchemaRegistry.getInstance().trackSchema(conversationPluginErrorSchema);
|
|
11
11
|
exports.default = conversationPluginErrorSchema;
|
|
@@ -7,13 +7,13 @@ const invalidTopicSchema = {
|
|
|
7
7
|
name: 'Invalid topic',
|
|
8
8
|
fields: {
|
|
9
9
|
/** . The script that I was attempting to load. Ends in .topic */
|
|
10
|
-
|
|
10
|
+
topicScript: {
|
|
11
11
|
type: 'text',
|
|
12
12
|
isRequired: true,
|
|
13
13
|
hint: 'The script that I was attempting to load. Ends in .topic',
|
|
14
|
-
options: undefined
|
|
14
|
+
options: undefined,
|
|
15
15
|
},
|
|
16
|
-
}
|
|
16
|
+
},
|
|
17
17
|
};
|
|
18
18
|
schema_1.SchemaRegistry.getInstance().trackSchema(invalidTopicSchema);
|
|
19
19
|
exports.default = invalidTopicSchema;
|
|
@@ -7,13 +7,13 @@ const missingDependenciesSchema = {
|
|
|
7
7
|
name: 'Missing dependencies',
|
|
8
8
|
fields: {
|
|
9
9
|
/** . */
|
|
10
|
-
|
|
10
|
+
dependencies: {
|
|
11
11
|
type: 'text',
|
|
12
12
|
isRequired: true,
|
|
13
13
|
isArray: true,
|
|
14
|
-
options: undefined
|
|
14
|
+
options: undefined,
|
|
15
15
|
},
|
|
16
|
-
}
|
|
16
|
+
},
|
|
17
17
|
};
|
|
18
18
|
schema_1.SchemaRegistry.getInstance().trackSchema(missingDependenciesSchema);
|
|
19
19
|
exports.default = missingDependenciesSchema;
|
|
@@ -5,7 +5,7 @@ const testerNotStartedSchema = {
|
|
|
5
5
|
id: 'testerNotStarted',
|
|
6
6
|
namespace: 'Conversation',
|
|
7
7
|
name: 'Tester not started',
|
|
8
|
-
fields: {}
|
|
8
|
+
fields: {},
|
|
9
9
|
};
|
|
10
10
|
schema_1.SchemaRegistry.getInstance().trackSchema(testerNotStartedSchema);
|
|
11
11
|
exports.default = testerNotStartedSchema;
|
|
@@ -7,19 +7,19 @@ const topicNotFoundSchema = {
|
|
|
7
7
|
name: 'Topic not found',
|
|
8
8
|
fields: {
|
|
9
9
|
/** . */
|
|
10
|
-
|
|
10
|
+
suppliedTopic: {
|
|
11
11
|
type: 'text',
|
|
12
12
|
isRequired: true,
|
|
13
|
-
options: undefined
|
|
13
|
+
options: undefined,
|
|
14
14
|
},
|
|
15
15
|
/** . */
|
|
16
|
-
|
|
16
|
+
validTopics: {
|
|
17
17
|
type: 'text',
|
|
18
18
|
isRequired: true,
|
|
19
19
|
isArray: true,
|
|
20
|
-
options: undefined
|
|
20
|
+
options: undefined,
|
|
21
21
|
},
|
|
22
|
-
}
|
|
22
|
+
},
|
|
23
23
|
};
|
|
24
24
|
schema_1.SchemaRegistry.getInstance().trackSchema(topicNotFoundSchema);
|
|
25
25
|
exports.default = topicNotFoundSchema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { FieldDefinitions, FieldDefinitionMap, FieldValueTypeGeneratorMap, FieldMap } from '@sprucelabs/schema';
|
|
1
|
+
export { FieldDefinitions, FieldDefinitionMap, FieldValueTypeGeneratorMap, FieldMap, } from '@sprucelabs/schema';
|
|
@@ -9,9 +9,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
9
9
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const spruce_test_fixtures_1 = require("@sprucelabs/spruce-test-fixtures");
|
|
12
13
|
const test_utils_1 = require("@sprucelabs/test-utils");
|
|
13
14
|
const AbstractConversationTest_1 = __importDefault(require("../../tests/AbstractConversationTest"));
|
|
14
|
-
const spruce_test_fixtures_1 = require("@sprucelabs/spruce-test-fixtures");
|
|
15
15
|
spruce_test_fixtures_1.MercuryFixture.setShouldRequireLocalListeners(false);
|
|
16
16
|
class KillingASkillTest extends AbstractConversationTest_1.default {
|
|
17
17
|
static async killingASkillKillsConversation() {
|
|
@@ -10,11 +10,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const spruce_event_utils_1 = require("@sprucelabs/spruce-event-utils");
|
|
13
|
+
const spruce_test_fixtures_1 = require("@sprucelabs/spruce-test-fixtures");
|
|
13
14
|
const test_utils_1 = require("@sprucelabs/test-utils");
|
|
14
15
|
const test_utils_2 = require("@sprucelabs/test-utils");
|
|
15
16
|
const conversation_plugin_1 = __importDefault(require("../../plugins/conversation.plugin"));
|
|
16
17
|
const AbstractConversationTest_1 = __importDefault(require("../../tests/AbstractConversationTest"));
|
|
17
|
-
const spruce_test_fixtures_1 = require("@sprucelabs/spruce-test-fixtures");
|
|
18
18
|
spruce_test_fixtures_1.MercuryFixture.setShouldRequireLocalListeners(false);
|
|
19
19
|
class RegisteringConversationsOnBootTest extends AbstractConversationTest_1.default {
|
|
20
20
|
static async throwsWhenExecutingIfEventPluginMissing() {
|
|
@@ -35,7 +35,9 @@ class RegisteringConversationsOnBootTest extends AbstractConversationTest_1.defa
|
|
|
35
35
|
this.assertExpectedTopics(topics);
|
|
36
36
|
}
|
|
37
37
|
static async skillShutsDownWhenConvosFailToRegister() {
|
|
38
|
-
const { skill } = await super.bootSkill({
|
|
38
|
+
const { skill } = await super.bootSkill({
|
|
39
|
+
shouldSuppressBootErrors: true,
|
|
40
|
+
});
|
|
39
41
|
test_utils_1.assert.isFalse(skill.isRunning());
|
|
40
42
|
this.clearSkillBootErrors();
|
|
41
43
|
}
|
|
@@ -10,9 +10,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const spruce_event_utils_1 = require("@sprucelabs/spruce-event-utils");
|
|
13
|
+
const spruce_test_fixtures_1 = require("@sprucelabs/spruce-test-fixtures");
|
|
13
14
|
const test_utils_1 = require("@sprucelabs/test-utils");
|
|
14
15
|
const AbstractConversationTest_1 = __importDefault(require("../../tests/AbstractConversationTest"));
|
|
15
|
-
const spruce_test_fixtures_1 = require("@sprucelabs/spruce-test-fixtures");
|
|
16
16
|
spruce_test_fixtures_1.MercuryFixture.setShouldRequireLocalListeners(false);
|
|
17
17
|
class RespondingToMessagesTest extends AbstractConversationTest_1.default {
|
|
18
18
|
static async beforeEach() {
|
|
@@ -41,7 +41,10 @@ class TopicCoordinatorTest extends AbstractConversationTest_1.default {
|
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
static async respondsWithSuggestedTopicsToFirstMessage() {
|
|
44
|
-
const results = await this.coordinator.handleMessage(this.buildMessage({
|
|
44
|
+
const results = await this.coordinator.handleMessage(this.buildMessage({
|
|
45
|
+
body: 'help me book!',
|
|
46
|
+
source: { personId: '1234' },
|
|
47
|
+
}));
|
|
45
48
|
test_utils_1.assert.isArray(results.suggestedTopics);
|
|
46
49
|
test_utils_1.assert.isLength(results.suggestedTopics, 3);
|
|
47
50
|
}
|
|
@@ -51,7 +54,10 @@ class TopicCoordinatorTest extends AbstractConversationTest_1.default {
|
|
|
51
54
|
sendMessageHandler: async () => { },
|
|
52
55
|
getContext: () => this.skillContext,
|
|
53
56
|
});
|
|
54
|
-
const results = await coordinator.handleMessage(this.buildMessage({
|
|
57
|
+
const results = await coordinator.handleMessage(this.buildMessage({
|
|
58
|
+
body: 'help me book!',
|
|
59
|
+
source: { personId: '1234' },
|
|
60
|
+
}));
|
|
55
61
|
test_utils_1.assert.isArray(results.suggestedTopics);
|
|
56
62
|
test_utils_1.assert.isLength(results.suggestedTopics, 0);
|
|
57
63
|
}
|
|
@@ -96,26 +102,38 @@ class TopicCoordinatorTest extends AbstractConversationTest_1.default {
|
|
|
96
102
|
test_utils_1.assert.isEqual((_a = this.sentMessages[0]) === null || _a === void 0 ? void 0 : _a.body, 'string 1');
|
|
97
103
|
test_utils_1.assert.isEqual((_b = this.sentMessages[1]) === null || _b === void 0 ? void 0 : _b.body, 'prompt 1');
|
|
98
104
|
this.sentMessages = [];
|
|
99
|
-
await this.coordinator.handleMessage(this.buildMessage({
|
|
105
|
+
await this.coordinator.handleMessage(this.buildMessage({
|
|
106
|
+
body: 'answer 1',
|
|
107
|
+
source: { personId: '1234' },
|
|
108
|
+
}), 'mixedStringsAndCallbacks');
|
|
100
109
|
await this.wait(100);
|
|
101
110
|
test_utils_1.assert.isLength(this.sentMessages, 3);
|
|
102
111
|
test_utils_1.assert.isEqual((_c = this.sentMessages[0]) === null || _c === void 0 ? void 0 : _c.body, 'answer 1');
|
|
103
112
|
test_utils_1.assert.isEqual((_d = this.sentMessages[1]) === null || _d === void 0 ? void 0 : _d.body, 'string 2');
|
|
104
113
|
test_utils_1.assert.isEqual((_e = this.sentMessages[2]) === null || _e === void 0 ? void 0 : _e.body, 'prompt 2');
|
|
105
114
|
this.sentMessages = [];
|
|
106
|
-
await this.coordinator.handleMessage(this.buildMessage({
|
|
115
|
+
await this.coordinator.handleMessage(this.buildMessage({
|
|
116
|
+
body: 'answer 2',
|
|
117
|
+
source: { personId: '1234' },
|
|
118
|
+
}), 'mixedStringsAndCallbacks');
|
|
107
119
|
test_utils_1.assert.isLength(this.sentMessages, 2);
|
|
108
120
|
test_utils_1.assert.isEqual((_f = this.sentMessages[0]) === null || _f === void 0 ? void 0 : _f.body, 'answer 2');
|
|
109
121
|
test_utils_1.assert.isEqual((_g = this.sentMessages[1]) === null || _g === void 0 ? void 0 : _g.body, 'and done');
|
|
110
122
|
this.sentMessages = [];
|
|
111
|
-
await this.coordinator.handleMessage(this.buildMessage({
|
|
123
|
+
await this.coordinator.handleMessage(this.buildMessage({
|
|
124
|
+
body: 'answer 1',
|
|
125
|
+
source: { personId: '1234' },
|
|
126
|
+
}), 'mixedStringsAndCallbacks');
|
|
112
127
|
await this.wait(100);
|
|
113
128
|
test_utils_1.assert.isLength(this.sentMessages, 2);
|
|
114
129
|
test_utils_1.assert.isEqual((_h = this.sentMessages[0]) === null || _h === void 0 ? void 0 : _h.body, 'string 1');
|
|
115
130
|
test_utils_1.assert.isEqual((_j = this.sentMessages[1]) === null || _j === void 0 ? void 0 : _j.body, 'prompt 1');
|
|
116
131
|
}
|
|
117
132
|
static async passesThroughContextGetter(context) {
|
|
118
|
-
await this.coordinator.handleMessage(this.buildMessage({
|
|
133
|
+
await this.coordinator.handleMessage(this.buildMessage({
|
|
134
|
+
body: 'answer 2',
|
|
135
|
+
source: { personId: '1234' },
|
|
136
|
+
}), 'bookAppointment');
|
|
119
137
|
this.skillContext = context;
|
|
120
138
|
const player = this.coordinator.getPlayer();
|
|
121
139
|
test_utils_1.assert.isTruthy(player);
|
|
@@ -18,7 +18,9 @@ class TextFieldTest extends AbstractGraphicsInterfaceTest_1.default {
|
|
|
18
18
|
type: 'email',
|
|
19
19
|
label: 'Tell me about your life.',
|
|
20
20
|
});
|
|
21
|
-
test_utils_1.assert.doesInclude(this.sentMessages, {
|
|
21
|
+
test_utils_1.assert.doesInclude(this.sentMessages, {
|
|
22
|
+
body: 'Tell me about your life.',
|
|
23
|
+
});
|
|
22
24
|
}
|
|
23
25
|
static async noPromptSendsNoMessage() {
|
|
24
26
|
void this.ui.prompt({
|
|
@@ -17,7 +17,9 @@ class TextFieldTest extends AbstractGraphicsInterfaceTest_1.default {
|
|
|
17
17
|
type: 'text',
|
|
18
18
|
label: 'Tell me about your life.',
|
|
19
19
|
});
|
|
20
|
-
test_utils_1.assert.doesInclude(this.sentMessages, {
|
|
20
|
+
test_utils_1.assert.doesInclude(this.sentMessages, {
|
|
21
|
+
body: 'Tell me about your life.',
|
|
22
|
+
});
|
|
21
23
|
}
|
|
22
24
|
static async noPromptSendsNoMessage() {
|
|
23
25
|
void this.ui.prompt({
|
|
@@ -233,7 +233,11 @@ class TopicScriptPlayerTest extends AbstractConversationTest_1.default {
|
|
|
233
233
|
static async randomOnOptions() {
|
|
234
234
|
const messages = [];
|
|
235
235
|
const remaining = { one: true, two: true, three: true };
|
|
236
|
-
const possibilities = [
|
|
236
|
+
const possibilities = [
|
|
237
|
+
'one',
|
|
238
|
+
'two',
|
|
239
|
+
'three',
|
|
240
|
+
];
|
|
237
241
|
const player = this.Player({
|
|
238
242
|
sendMessageHandler: async (message) => {
|
|
239
243
|
messages.push(message.body);
|
|
@@ -57,7 +57,13 @@ class TopicSuggesterTest extends test_utils_1.default {
|
|
|
57
57
|
{
|
|
58
58
|
key: 'scheduleShft',
|
|
59
59
|
label: 'Shift',
|
|
60
|
-
utterances: [
|
|
60
|
+
utterances: [
|
|
61
|
+
'shift',
|
|
62
|
+
'block my time',
|
|
63
|
+
'break',
|
|
64
|
+
'hours',
|
|
65
|
+
'schedule',
|
|
66
|
+
],
|
|
61
67
|
},
|
|
62
68
|
{
|
|
63
69
|
key: 'bookAppointment',
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const topicDefinition = {
|
|
4
4
|
label: 'Cancel appointment',
|
|
5
|
-
utterances: [
|
|
5
|
+
utterances: [
|
|
6
|
+
'Cancel appointment',
|
|
7
|
+
'Can i cancel my appointment?',
|
|
8
|
+
'cancel',
|
|
9
|
+
],
|
|
6
10
|
script: ['how are you?', 'Lemme find your appointment!'],
|
|
7
11
|
};
|
|
8
12
|
exports.default = topicDefinition;
|
package/build/__tests__/testDirsAndFiles/skill/build/conversations/cancelAppointment.topic.js
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const topicDefinition = {
|
|
4
4
|
label: 'Cancel appointment',
|
|
5
|
-
utterances: [
|
|
5
|
+
utterances: [
|
|
6
|
+
'Cancel appointment',
|
|
7
|
+
'Can i cancel my appointment?',
|
|
8
|
+
'cancel',
|
|
9
|
+
],
|
|
6
10
|
script: ['how are you?', 'Lemme find your appointment!'],
|
|
7
11
|
};
|
|
8
12
|
exports.default = topicDefinition;
|
|
@@ -6,7 +6,10 @@ const topicDefinition = {
|
|
|
6
6
|
script: [
|
|
7
7
|
'what is your favorite color?',
|
|
8
8
|
async (options) => {
|
|
9
|
-
const answer = await options.ui.prompt({
|
|
9
|
+
const answer = await options.ui.prompt({
|
|
10
|
+
type: 'text',
|
|
11
|
+
isRequired: true,
|
|
12
|
+
});
|
|
10
13
|
options.ui.renderLine(answer);
|
|
11
14
|
return {
|
|
12
15
|
transitionConversationTo: 'discovery',
|
|
@@ -6,7 +6,10 @@ const topicDefinition = {
|
|
|
6
6
|
script: [
|
|
7
7
|
'what is your favorite color?',
|
|
8
8
|
async (options) => {
|
|
9
|
-
const answer = await options.ui.prompt({
|
|
9
|
+
const answer = await options.ui.prompt({
|
|
10
|
+
type: 'text',
|
|
11
|
+
isRequired: true,
|
|
12
|
+
});
|
|
10
13
|
options.ui.renderLine(answer);
|
|
11
14
|
return {
|
|
12
15
|
transitionConversationTo: 'discovery',
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const topicDefinition = {
|
|
4
4
|
label: 'Cancel appointment',
|
|
5
|
-
utterances: [
|
|
5
|
+
utterances: [
|
|
6
|
+
'Cancel appointment',
|
|
7
|
+
'Can i cancel my appointment?',
|
|
8
|
+
'cancel',
|
|
9
|
+
],
|
|
6
10
|
script: [
|
|
7
11
|
() => {
|
|
8
12
|
throw new Error('In Script');
|
|
@@ -13,9 +13,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
13
13
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
|
+
import { MercuryFixture } from '@sprucelabs/spruce-test-fixtures';
|
|
16
17
|
import { test, assert } from '@sprucelabs/test-utils';
|
|
17
18
|
import AbstractConversationTest from '../../tests/AbstractConversationTest.js';
|
|
18
|
-
import { MercuryFixture } from '@sprucelabs/spruce-test-fixtures';
|
|
19
19
|
MercuryFixture.setShouldRequireLocalListeners(false);
|
|
20
20
|
export default class KillingASkillTest extends AbstractConversationTest {
|
|
21
21
|
static killingASkillKillsConversation() {
|
|
@@ -14,11 +14,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
16
|
import { eventResponseUtil } from '@sprucelabs/spruce-event-utils';
|
|
17
|
+
import { MercuryFixture } from '@sprucelabs/spruce-test-fixtures';
|
|
17
18
|
import { test, assert, generateId } from '@sprucelabs/test-utils';
|
|
18
19
|
import { errorAssert } from '@sprucelabs/test-utils';
|
|
19
20
|
import plugin from '../../plugins/conversation.plugin.js';
|
|
20
21
|
import AbstractConversationTest from '../../tests/AbstractConversationTest.js';
|
|
21
|
-
import { MercuryFixture } from '@sprucelabs/spruce-test-fixtures';
|
|
22
22
|
MercuryFixture.setShouldRequireLocalListeners(false);
|
|
23
23
|
export default class RegisteringConversationsOnBootTest extends AbstractConversationTest {
|
|
24
24
|
static throwsWhenExecutingIfEventPluginMissing() {
|
|
@@ -49,7 +49,9 @@ export default class RegisteringConversationsOnBootTest extends AbstractConversa
|
|
|
49
49
|
bootSkill: { get: () => super.bootSkill }
|
|
50
50
|
});
|
|
51
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
const { skill } = yield _super.bootSkill.call(this, {
|
|
52
|
+
const { skill } = yield _super.bootSkill.call(this, {
|
|
53
|
+
shouldSuppressBootErrors: true,
|
|
54
|
+
});
|
|
53
55
|
assert.isFalse(skill.isRunning());
|
|
54
56
|
this.clearSkillBootErrors();
|
|
55
57
|
});
|
|
@@ -14,9 +14,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
16
|
import { eventResponseUtil } from '@sprucelabs/spruce-event-utils';
|
|
17
|
+
import { MercuryFixture } from '@sprucelabs/spruce-test-fixtures';
|
|
17
18
|
import { test, assert } from '@sprucelabs/test-utils';
|
|
18
19
|
import AbstractConversationTest from '../../tests/AbstractConversationTest.js';
|
|
19
|
-
import { MercuryFixture } from '@sprucelabs/spruce-test-fixtures';
|
|
20
20
|
MercuryFixture.setShouldRequireLocalListeners(false);
|
|
21
21
|
export default class RespondingToMessagesTest extends AbstractConversationTest {
|
|
22
22
|
static beforeEach() {
|
|
@@ -57,7 +57,10 @@ class TopicCoordinatorTest extends AbstractConversationTest {
|
|
|
57
57
|
}
|
|
58
58
|
static respondsWithSuggestedTopicsToFirstMessage() {
|
|
59
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
const results = yield this.coordinator.handleMessage(this.buildMessage({
|
|
60
|
+
const results = yield this.coordinator.handleMessage(this.buildMessage({
|
|
61
|
+
body: 'help me book!',
|
|
62
|
+
source: { personId: '1234' },
|
|
63
|
+
}));
|
|
61
64
|
assert.isArray(results.suggestedTopics);
|
|
62
65
|
assert.isLength(results.suggestedTopics, 3);
|
|
63
66
|
});
|
|
@@ -69,7 +72,10 @@ class TopicCoordinatorTest extends AbstractConversationTest {
|
|
|
69
72
|
sendMessageHandler: () => __awaiter(this, void 0, void 0, function* () { }),
|
|
70
73
|
getContext: () => this.skillContext,
|
|
71
74
|
});
|
|
72
|
-
const results = yield coordinator.handleMessage(this.buildMessage({
|
|
75
|
+
const results = yield coordinator.handleMessage(this.buildMessage({
|
|
76
|
+
body: 'help me book!',
|
|
77
|
+
source: { personId: '1234' },
|
|
78
|
+
}));
|
|
73
79
|
assert.isArray(results.suggestedTopics);
|
|
74
80
|
assert.isLength(results.suggestedTopics, 0);
|
|
75
81
|
});
|
|
@@ -122,19 +128,28 @@ class TopicCoordinatorTest extends AbstractConversationTest {
|
|
|
122
128
|
assert.isEqual((_a = this.sentMessages[0]) === null || _a === void 0 ? void 0 : _a.body, 'string 1');
|
|
123
129
|
assert.isEqual((_b = this.sentMessages[1]) === null || _b === void 0 ? void 0 : _b.body, 'prompt 1');
|
|
124
130
|
this.sentMessages = [];
|
|
125
|
-
yield this.coordinator.handleMessage(this.buildMessage({
|
|
131
|
+
yield this.coordinator.handleMessage(this.buildMessage({
|
|
132
|
+
body: 'answer 1',
|
|
133
|
+
source: { personId: '1234' },
|
|
134
|
+
}), 'mixedStringsAndCallbacks');
|
|
126
135
|
yield this.wait(100);
|
|
127
136
|
assert.isLength(this.sentMessages, 3);
|
|
128
137
|
assert.isEqual((_c = this.sentMessages[0]) === null || _c === void 0 ? void 0 : _c.body, 'answer 1');
|
|
129
138
|
assert.isEqual((_d = this.sentMessages[1]) === null || _d === void 0 ? void 0 : _d.body, 'string 2');
|
|
130
139
|
assert.isEqual((_e = this.sentMessages[2]) === null || _e === void 0 ? void 0 : _e.body, 'prompt 2');
|
|
131
140
|
this.sentMessages = [];
|
|
132
|
-
yield this.coordinator.handleMessage(this.buildMessage({
|
|
141
|
+
yield this.coordinator.handleMessage(this.buildMessage({
|
|
142
|
+
body: 'answer 2',
|
|
143
|
+
source: { personId: '1234' },
|
|
144
|
+
}), 'mixedStringsAndCallbacks');
|
|
133
145
|
assert.isLength(this.sentMessages, 2);
|
|
134
146
|
assert.isEqual((_f = this.sentMessages[0]) === null || _f === void 0 ? void 0 : _f.body, 'answer 2');
|
|
135
147
|
assert.isEqual((_g = this.sentMessages[1]) === null || _g === void 0 ? void 0 : _g.body, 'and done');
|
|
136
148
|
this.sentMessages = [];
|
|
137
|
-
yield this.coordinator.handleMessage(this.buildMessage({
|
|
149
|
+
yield this.coordinator.handleMessage(this.buildMessage({
|
|
150
|
+
body: 'answer 1',
|
|
151
|
+
source: { personId: '1234' },
|
|
152
|
+
}), 'mixedStringsAndCallbacks');
|
|
138
153
|
yield this.wait(100);
|
|
139
154
|
assert.isLength(this.sentMessages, 2);
|
|
140
155
|
assert.isEqual((_h = this.sentMessages[0]) === null || _h === void 0 ? void 0 : _h.body, 'string 1');
|
|
@@ -143,7 +158,10 @@ class TopicCoordinatorTest extends AbstractConversationTest {
|
|
|
143
158
|
}
|
|
144
159
|
static passesThroughContextGetter(context) {
|
|
145
160
|
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
-
yield this.coordinator.handleMessage(this.buildMessage({
|
|
161
|
+
yield this.coordinator.handleMessage(this.buildMessage({
|
|
162
|
+
body: 'answer 2',
|
|
163
|
+
source: { personId: '1234' },
|
|
164
|
+
}), 'bookAppointment');
|
|
147
165
|
this.skillContext = context;
|
|
148
166
|
const player = this.coordinator.getPlayer();
|
|
149
167
|
assert.isTruthy(player);
|
|
@@ -23,7 +23,9 @@ export default class TextFieldTest extends AbstractGraphicsInterfaceTest {
|
|
|
23
23
|
type: 'email',
|
|
24
24
|
label: 'Tell me about your life.',
|
|
25
25
|
});
|
|
26
|
-
assert.doesInclude(this.sentMessages, {
|
|
26
|
+
assert.doesInclude(this.sentMessages, {
|
|
27
|
+
body: 'Tell me about your life.',
|
|
28
|
+
});
|
|
27
29
|
});
|
|
28
30
|
}
|
|
29
31
|
static noPromptSendsNoMessage() {
|
|
@@ -22,7 +22,9 @@ export default class TextFieldTest extends AbstractGraphicsInterfaceTest {
|
|
|
22
22
|
type: 'text',
|
|
23
23
|
label: 'Tell me about your life.',
|
|
24
24
|
});
|
|
25
|
-
assert.doesInclude(this.sentMessages, {
|
|
25
|
+
assert.doesInclude(this.sentMessages, {
|
|
26
|
+
body: 'Tell me about your life.',
|
|
27
|
+
});
|
|
26
28
|
});
|
|
27
29
|
}
|
|
28
30
|
static noPromptSendsNoMessage() {
|
|
@@ -260,7 +260,11 @@ export default class TopicScriptPlayerTest extends AbstractConversationTest {
|
|
|
260
260
|
return __awaiter(this, void 0, void 0, function* () {
|
|
261
261
|
const messages = [];
|
|
262
262
|
const remaining = { one: true, two: true, three: true };
|
|
263
|
-
const possibilities = [
|
|
263
|
+
const possibilities = [
|
|
264
|
+
'one',
|
|
265
|
+
'two',
|
|
266
|
+
'three',
|
|
267
|
+
];
|
|
264
268
|
const player = this.Player({
|
|
265
269
|
sendMessageHandler: (message) => __awaiter(this, void 0, void 0, function* () {
|
|
266
270
|
messages.push(message.body);
|
|
@@ -46,7 +46,13 @@ export default class TopicSuggesterTest extends AbstractSpruceTest {
|
|
|
46
46
|
{
|
|
47
47
|
key: 'scheduleShft',
|
|
48
48
|
label: 'Shift',
|
|
49
|
-
utterances: [
|
|
49
|
+
utterances: [
|
|
50
|
+
'shift',
|
|
51
|
+
'block my time',
|
|
52
|
+
'break',
|
|
53
|
+
'hours',
|
|
54
|
+
'schedule',
|
|
55
|
+
],
|
|
50
56
|
},
|
|
51
57
|
{
|
|
52
58
|
key: 'bookAppointment',
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
const topicDefinition = {
|
|
2
2
|
label: 'Cancel appointment',
|
|
3
|
-
utterances: [
|
|
3
|
+
utterances: [
|
|
4
|
+
'Cancel appointment',
|
|
5
|
+
'Can i cancel my appointment?',
|
|
6
|
+
'cancel',
|
|
7
|
+
],
|
|
4
8
|
script: ['how are you?', 'Lemme find your appointment!'],
|
|
5
9
|
};
|
|
6
10
|
export default topicDefinition;
|
package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/cancelAppointment.topic.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
const topicDefinition = {
|
|
2
2
|
label: 'Cancel appointment',
|
|
3
|
-
utterances: [
|
|
3
|
+
utterances: [
|
|
4
|
+
'Cancel appointment',
|
|
5
|
+
'Can i cancel my appointment?',
|
|
6
|
+
'cancel',
|
|
7
|
+
],
|
|
4
8
|
script: ['how are you?', 'Lemme find your appointment!'],
|
|
5
9
|
};
|
|
6
10
|
export default topicDefinition;
|
package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColor.topic.js
CHANGED
|
@@ -13,7 +13,10 @@ const topicDefinition = {
|
|
|
13
13
|
script: [
|
|
14
14
|
'what is your favorite color?',
|
|
15
15
|
(options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
const answer = yield options.ui.prompt({
|
|
16
|
+
const answer = yield options.ui.prompt({
|
|
17
|
+
type: 'text',
|
|
18
|
+
isRequired: true,
|
|
19
|
+
});
|
|
17
20
|
options.ui.renderLine(answer);
|
|
18
21
|
return {
|
|
19
22
|
transitionConversationTo: 'discovery',
|
|
@@ -13,7 +13,10 @@ const topicDefinition = {
|
|
|
13
13
|
script: [
|
|
14
14
|
'what is your favorite color?',
|
|
15
15
|
(options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
const answer = yield options.ui.prompt({
|
|
16
|
+
const answer = yield options.ui.prompt({
|
|
17
|
+
type: 'text',
|
|
18
|
+
isRequired: true,
|
|
19
|
+
});
|
|
17
20
|
options.ui.renderLine(answer);
|
|
18
21
|
return {
|
|
19
22
|
transitionConversationTo: 'discovery',
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
const topicDefinition = {
|
|
2
2
|
label: 'Cancel appointment',
|
|
3
|
-
utterances: [
|
|
3
|
+
utterances: [
|
|
4
|
+
'Cancel appointment',
|
|
5
|
+
'Can i cancel my appointment?',
|
|
6
|
+
'cancel',
|
|
7
|
+
],
|
|
4
8
|
script: [
|
|
5
9
|
() => {
|
|
6
10
|
throw new Error('In Script');
|
|
@@ -125,25 +125,26 @@ export class ConversationFeature {
|
|
|
125
125
|
if (this.coordinatorsBySource[sourceId]) {
|
|
126
126
|
return this.coordinatorsBySource[sourceId];
|
|
127
127
|
}
|
|
128
|
-
this.coordinatorsBySource[sourceId] =
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
128
|
+
this.coordinatorsBySource[sourceId] =
|
|
129
|
+
ConversationCoordinator.Coordinator({
|
|
130
|
+
topicLookupPath: this.skill.activeDir,
|
|
131
|
+
getContext: () => this.skill.getContext(),
|
|
132
|
+
sendMessageHandler: (message) => __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
try {
|
|
134
|
+
const { target } = message, values = __rest(message, ["target"]);
|
|
135
|
+
const results = yield client.emit('send-message::v2020_12_25', {
|
|
136
|
+
target,
|
|
137
|
+
payload: {
|
|
138
|
+
message: values,
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
eventResponseUtil.getFirstResponseOrThrow(results);
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
this.log.error(err.message);
|
|
145
|
+
}
|
|
146
|
+
}),
|
|
147
|
+
});
|
|
147
148
|
return this.coordinatorsBySource[sourceId];
|
|
148
149
|
});
|
|
149
150
|
}
|
|
@@ -158,7 +159,11 @@ export class ConversationFeature {
|
|
|
158
159
|
});
|
|
159
160
|
if (topics.length > 0) {
|
|
160
161
|
this.log.info(`Registering new ${topics.length} topic${topics.length === 1 ? '' : 's'}.`);
|
|
161
|
-
const results = yield client.emit(`register-conversation-topics::v2020_12_25`, {
|
|
162
|
+
const results = yield client.emit(`register-conversation-topics::v2020_12_25`, {
|
|
163
|
+
payload: {
|
|
164
|
+
topics: topics.map((topic) => ({ key: topic.key })),
|
|
165
|
+
},
|
|
166
|
+
});
|
|
162
167
|
eventResponseUtil.getFirstResponseOrThrow(results);
|
|
163
168
|
this.log.info('Topics now in sync.');
|
|
164
169
|
}
|
|
@@ -18,7 +18,10 @@ export default class AbstractGraphicsInterfaceTest extends AbstractConversationT
|
|
|
18
18
|
yield _super.beforeEach.call(this);
|
|
19
19
|
this.sentMessages = [];
|
|
20
20
|
this.ui = new MessageGraphicsInterface({
|
|
21
|
-
invalidValueRepairs: [
|
|
21
|
+
invalidValueRepairs: [
|
|
22
|
+
'invalid-value-repair',
|
|
23
|
+
'invalid-value-repair2',
|
|
24
|
+
],
|
|
22
25
|
sendMessageHandler: (message) => __awaiter(this, void 0, void 0, function* () {
|
|
23
26
|
this.sentMessages.push(message);
|
|
24
27
|
}),
|
|
@@ -17,7 +17,8 @@ import randomUtil from '../utilities/random.utility.js';
|
|
|
17
17
|
export default class ScriptTester {
|
|
18
18
|
constructor(topics, getContext, writeHandler, selectPromptHandler, promptHandler, lineDelay, shouldPlayReplayAfterFinish) {
|
|
19
19
|
this.isDestroyed = false;
|
|
20
|
-
this.writeHandler =
|
|
20
|
+
this.writeHandler =
|
|
21
|
+
writeHandler !== null && writeHandler !== void 0 ? writeHandler : ((message) => console.log(message.body));
|
|
21
22
|
this.getContext = getContext;
|
|
22
23
|
this.topics = topics;
|
|
23
24
|
this.selectPromptHandler =
|
|
@@ -57,7 +58,6 @@ export default class ScriptTester {
|
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
60
|
yield this.reportOnConfidence(msg);
|
|
60
|
-
// eslint-disable-next-line no-constant-condition
|
|
61
61
|
while (true) {
|
|
62
62
|
if (this.isDestroyed) {
|
|
63
63
|
return;
|
|
@@ -68,10 +68,14 @@ export default class ScriptTester {
|
|
|
68
68
|
}
|
|
69
69
|
if (response === null || response === void 0 ? void 0 : response.transitionConversationTo) {
|
|
70
70
|
if (response.topicChangers) {
|
|
71
|
-
this.writeHandler({
|
|
71
|
+
this.writeHandler({
|
|
72
|
+
body: randomUtil.rand(response.topicChangers),
|
|
73
|
+
});
|
|
72
74
|
}
|
|
73
75
|
else if (response.repairs) {
|
|
74
|
-
this.writeHandler({
|
|
76
|
+
this.writeHandler({
|
|
77
|
+
body: randomUtil.rand(response.repairs),
|
|
78
|
+
});
|
|
75
79
|
}
|
|
76
80
|
this.writeHandler({
|
|
77
81
|
body: generateTransitionMessage(response.transitionConversationTo),
|
|
@@ -91,7 +95,9 @@ export default class ScriptTester {
|
|
|
91
95
|
reportOnConfidence(msg) {
|
|
92
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
93
97
|
if (!this.suggester) {
|
|
94
|
-
this.suggester = yield TopicSuggester.Suggester({
|
|
98
|
+
this.suggester = yield TopicSuggester.Suggester({
|
|
99
|
+
topics: this.topics,
|
|
100
|
+
});
|
|
95
101
|
}
|
|
96
102
|
const suggestions = yield this.suggester.suggest(msg);
|
|
97
103
|
if (suggestions.length > 0) {
|
|
@@ -142,7 +148,10 @@ export default class ScriptTester {
|
|
|
142
148
|
missing.push('script');
|
|
143
149
|
}
|
|
144
150
|
if (missing.length > 0) {
|
|
145
|
-
throw new SchemaError({
|
|
151
|
+
throw new SchemaError({
|
|
152
|
+
code: 'MISSING_PARAMETERS',
|
|
153
|
+
parameters: missing,
|
|
154
|
+
});
|
|
146
155
|
}
|
|
147
156
|
return new ScriptTester(options.topics, options.getContext, options.writeHandler, options.selectPromptHandler, options.promptHandler, options.lineDelay, options.shouldPlayReplayAfterFinish);
|
|
148
157
|
});
|
|
@@ -157,7 +166,10 @@ const inquirerSelectPromptHandler = (message) => __awaiter(void 0, void 0, void
|
|
|
157
166
|
type: 'list',
|
|
158
167
|
name: 'select',
|
|
159
168
|
message: message.body,
|
|
160
|
-
choices: (_a = message.choices) === null || _a === void 0 ? void 0 : _a.map((c) => ({
|
|
169
|
+
choices: (_a = message.choices) === null || _a === void 0 ? void 0 : _a.map((c) => ({
|
|
170
|
+
name: c.label,
|
|
171
|
+
value: c.value,
|
|
172
|
+
})),
|
|
161
173
|
});
|
|
162
174
|
return answer.select;
|
|
163
175
|
});
|
|
@@ -29,7 +29,9 @@ export default class TopicLoader {
|
|
|
29
29
|
}
|
|
30
30
|
static loadTopic(match) {
|
|
31
31
|
const imported = require(match);
|
|
32
|
-
const file = pathUtil
|
|
32
|
+
const file = pathUtil
|
|
33
|
+
.basename(match)
|
|
34
|
+
.replace(pathUtil.extname(match), '');
|
|
33
35
|
const key = file.split('.')[0];
|
|
34
36
|
if (!imported || !imported.default) {
|
|
35
37
|
throw new SpruceError({
|
|
@@ -117,7 +117,8 @@ export class TopicScriptPlayer {
|
|
|
117
117
|
do {
|
|
118
118
|
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
119
119
|
done =
|
|
120
|
-
((_a = this.runningLine) === null || _a === void 0 ? void 0 : _a.isDone) ||
|
|
120
|
+
((_a = this.runningLine) === null || _a === void 0 ? void 0 : _a.isDone) ||
|
|
121
|
+
this.graphicsInterface.isWaitingForInput();
|
|
121
122
|
} while (!done);
|
|
122
123
|
}
|
|
123
124
|
if (this.runningLine.isDone) {
|
|
@@ -23,7 +23,11 @@ export class TopicSuggester {
|
|
|
23
23
|
const container = containerBootstrap();
|
|
24
24
|
container.use(LangEn);
|
|
25
25
|
container.use(NluNeural);
|
|
26
|
-
const manager = new NluManager({
|
|
26
|
+
const manager = new NluManager({
|
|
27
|
+
container,
|
|
28
|
+
locales: ['en'],
|
|
29
|
+
log: false,
|
|
30
|
+
});
|
|
27
31
|
for (const topic of options.topics) {
|
|
28
32
|
manager.assignDomain('en', topic.key, topic.key);
|
|
29
33
|
for (const utterance of topic.utterances) {
|
|
@@ -10,17 +10,15 @@ export type SendMessage = SpruceSchemas.Spruce.v2020_07_22.SendMessage;
|
|
|
10
10
|
export type SendMessageHandler = (message: SendMessage) => Promise<void>;
|
|
11
11
|
export type DidMessageResponsePayloadSchema = SkillEventContract['eventSignatures']['did-message::v2020_12_25']['responsePayloadSchema'];
|
|
12
12
|
export type DidMessageResponsePayload = SchemaValues<DidMessageResponsePayloadSchema>;
|
|
13
|
-
export
|
|
13
|
+
export interface ScriptLineCallbackOptions {
|
|
14
14
|
ui: GraphicsInterface;
|
|
15
15
|
state: Record<string, any>;
|
|
16
16
|
rand<T>(possibilities: T[]): T;
|
|
17
17
|
message: Message;
|
|
18
18
|
context: SkillContext;
|
|
19
|
-
};
|
|
20
|
-
export type ScriptLine = string | ScriptLineCallback | string[];
|
|
21
|
-
export interface ScriptLineCallback {
|
|
22
|
-
(options: ScriptLineCallbackOptions): Promise<void | DidMessageResponsePayload>;
|
|
23
19
|
}
|
|
20
|
+
export type ScriptLine = string | ScriptLineCallback | string[];
|
|
21
|
+
export type ScriptLineCallback = (options: ScriptLineCallbackOptions) => Promise<void | DidMessageResponsePayload>;
|
|
24
22
|
export type Script = ScriptLine[];
|
|
25
23
|
export interface ScriptPlayerOptions {
|
|
26
24
|
script: Script;
|
|
@@ -30,10 +28,10 @@ export interface ScriptPlayerOptions {
|
|
|
30
28
|
graphicsInterface?: MessageGraphicsInterface;
|
|
31
29
|
getContext: () => SkillContext;
|
|
32
30
|
}
|
|
33
|
-
export
|
|
31
|
+
export interface ScriptPlayerSendMessage {
|
|
34
32
|
body: string;
|
|
35
33
|
choices?: Message['choices'];
|
|
36
|
-
}
|
|
34
|
+
}
|
|
37
35
|
export declare const suggestedConversationTopicSchema: {
|
|
38
36
|
id: string;
|
|
39
37
|
fields: {
|
|
@@ -78,6 +76,4 @@ export interface FieldHandlerOptions<D extends FieldDefinitions = FieldDefinitio
|
|
|
78
76
|
waitForNextMessageHandler: () => Promise<string>;
|
|
79
77
|
definition: D;
|
|
80
78
|
}
|
|
81
|
-
export
|
|
82
|
-
(options: FieldHandlerOptions<F>): Promise<any>;
|
|
83
|
-
}
|
|
79
|
+
export type FieldHandler<F extends FieldDefinitions = FieldDefinitions> = (options: FieldHandlerOptions<F>) => Promise<any>;
|
|
@@ -111,25 +111,26 @@ class ConversationFeature {
|
|
|
111
111
|
if (this.coordinatorsBySource[sourceId]) {
|
|
112
112
|
return this.coordinatorsBySource[sourceId];
|
|
113
113
|
}
|
|
114
|
-
this.coordinatorsBySource[sourceId] =
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
114
|
+
this.coordinatorsBySource[sourceId] =
|
|
115
|
+
ConversationCoordinator_1.ConversationCoordinator.Coordinator({
|
|
116
|
+
topicLookupPath: this.skill.activeDir,
|
|
117
|
+
getContext: () => this.skill.getContext(),
|
|
118
|
+
sendMessageHandler: async (message) => {
|
|
119
|
+
try {
|
|
120
|
+
const { target } = message, values = __rest(message, ["target"]);
|
|
121
|
+
const results = await client.emit('send-message::v2020_12_25', {
|
|
122
|
+
target,
|
|
123
|
+
payload: {
|
|
124
|
+
message: values,
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
spruce_event_utils_1.eventResponseUtil.getFirstResponseOrThrow(results);
|
|
128
|
+
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
this.log.error(err.message);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
});
|
|
133
134
|
return this.coordinatorsBySource[sourceId];
|
|
134
135
|
}
|
|
135
136
|
async syncTopics() {
|
|
@@ -142,7 +143,11 @@ class ConversationFeature {
|
|
|
142
143
|
});
|
|
143
144
|
if (topics.length > 0) {
|
|
144
145
|
this.log.info(`Registering new ${topics.length} topic${topics.length === 1 ? '' : 's'}.`);
|
|
145
|
-
const results = await client.emit(`register-conversation-topics::v2020_12_25`, {
|
|
146
|
+
const results = await client.emit(`register-conversation-topics::v2020_12_25`, {
|
|
147
|
+
payload: {
|
|
148
|
+
topics: topics.map((topic) => ({ key: topic.key })),
|
|
149
|
+
},
|
|
150
|
+
});
|
|
146
151
|
spruce_event_utils_1.eventResponseUtil.getFirstResponseOrThrow(results);
|
|
147
152
|
this.log.info('Topics now in sync.');
|
|
148
153
|
}
|
|
@@ -10,7 +10,10 @@ class AbstractGraphicsInterfaceTest extends AbstractConversationTest_1.default {
|
|
|
10
10
|
await super.beforeEach();
|
|
11
11
|
this.sentMessages = [];
|
|
12
12
|
this.ui = new MessageGraphicsInterface_1.default({
|
|
13
|
-
invalidValueRepairs: [
|
|
13
|
+
invalidValueRepairs: [
|
|
14
|
+
'invalid-value-repair',
|
|
15
|
+
'invalid-value-repair2',
|
|
16
|
+
],
|
|
14
17
|
sendMessageHandler: async (message) => {
|
|
15
18
|
this.sentMessages.push(message);
|
|
16
19
|
},
|
|
@@ -14,7 +14,8 @@ const random_utility_1 = __importDefault(require("../utilities/random.utility"))
|
|
|
14
14
|
class ScriptTester {
|
|
15
15
|
constructor(topics, getContext, writeHandler, selectPromptHandler, promptHandler, lineDelay, shouldPlayReplayAfterFinish) {
|
|
16
16
|
this.isDestroyed = false;
|
|
17
|
-
this.writeHandler =
|
|
17
|
+
this.writeHandler =
|
|
18
|
+
writeHandler !== null && writeHandler !== void 0 ? writeHandler : ((message) => console.log(message.body));
|
|
18
19
|
this.getContext = getContext;
|
|
19
20
|
this.topics = topics;
|
|
20
21
|
this.selectPromptHandler =
|
|
@@ -53,7 +54,6 @@ class ScriptTester {
|
|
|
53
54
|
});
|
|
54
55
|
}
|
|
55
56
|
await this.reportOnConfidence(msg);
|
|
56
|
-
// eslint-disable-next-line no-constant-condition
|
|
57
57
|
while (true) {
|
|
58
58
|
if (this.isDestroyed) {
|
|
59
59
|
return;
|
|
@@ -64,10 +64,14 @@ class ScriptTester {
|
|
|
64
64
|
}
|
|
65
65
|
if (response === null || response === void 0 ? void 0 : response.transitionConversationTo) {
|
|
66
66
|
if (response.topicChangers) {
|
|
67
|
-
this.writeHandler({
|
|
67
|
+
this.writeHandler({
|
|
68
|
+
body: random_utility_1.default.rand(response.topicChangers),
|
|
69
|
+
});
|
|
68
70
|
}
|
|
69
71
|
else if (response.repairs) {
|
|
70
|
-
this.writeHandler({
|
|
72
|
+
this.writeHandler({
|
|
73
|
+
body: random_utility_1.default.rand(response.repairs),
|
|
74
|
+
});
|
|
71
75
|
}
|
|
72
76
|
this.writeHandler({
|
|
73
77
|
body: generateTransitionMessage(response.transitionConversationTo),
|
|
@@ -85,7 +89,9 @@ class ScriptTester {
|
|
|
85
89
|
}
|
|
86
90
|
async reportOnConfidence(msg) {
|
|
87
91
|
if (!this.suggester) {
|
|
88
|
-
this.suggester = await TopicSuggester_1.TopicSuggester.Suggester({
|
|
92
|
+
this.suggester = await TopicSuggester_1.TopicSuggester.Suggester({
|
|
93
|
+
topics: this.topics,
|
|
94
|
+
});
|
|
89
95
|
}
|
|
90
96
|
const suggestions = await this.suggester.suggest(msg);
|
|
91
97
|
if (suggestions.length > 0) {
|
|
@@ -130,7 +136,10 @@ class ScriptTester {
|
|
|
130
136
|
missing.push('script');
|
|
131
137
|
}
|
|
132
138
|
if (missing.length > 0) {
|
|
133
|
-
throw new schema_1.SchemaError({
|
|
139
|
+
throw new schema_1.SchemaError({
|
|
140
|
+
code: 'MISSING_PARAMETERS',
|
|
141
|
+
parameters: missing,
|
|
142
|
+
});
|
|
134
143
|
}
|
|
135
144
|
return new ScriptTester(options.topics, options.getContext, options.writeHandler, options.selectPromptHandler, options.promptHandler, options.lineDelay, options.shouldPlayReplayAfterFinish);
|
|
136
145
|
}
|
|
@@ -146,7 +155,10 @@ const inquirerSelectPromptHandler = async (message) => {
|
|
|
146
155
|
type: 'list',
|
|
147
156
|
name: 'select',
|
|
148
157
|
message: message.body,
|
|
149
|
-
choices: (_a = message.choices) === null || _a === void 0 ? void 0 : _a.map((c) => ({
|
|
158
|
+
choices: (_a = message.choices) === null || _a === void 0 ? void 0 : _a.map((c) => ({
|
|
159
|
+
name: c.label,
|
|
160
|
+
value: c.value,
|
|
161
|
+
})),
|
|
150
162
|
});
|
|
151
163
|
return answer.select;
|
|
152
164
|
};
|
|
@@ -23,7 +23,9 @@ class TopicLoader {
|
|
|
23
23
|
}
|
|
24
24
|
static loadTopic(match) {
|
|
25
25
|
const imported = require(match);
|
|
26
|
-
const file = path_1.default
|
|
26
|
+
const file = path_1.default
|
|
27
|
+
.basename(match)
|
|
28
|
+
.replace(path_1.default.extname(match), '');
|
|
27
29
|
const key = file.split('.')[0];
|
|
28
30
|
if (!imported || !imported.default) {
|
|
29
31
|
throw new SpruceError_1.default({
|
|
@@ -105,7 +105,8 @@ class TopicScriptPlayer {
|
|
|
105
105
|
do {
|
|
106
106
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
107
107
|
done =
|
|
108
|
-
((_a = this.runningLine) === null || _a === void 0 ? void 0 : _a.isDone) ||
|
|
108
|
+
((_a = this.runningLine) === null || _a === void 0 ? void 0 : _a.isDone) ||
|
|
109
|
+
this.graphicsInterface.isWaitingForInput();
|
|
109
110
|
} while (!done);
|
|
110
111
|
}
|
|
111
112
|
if (this.runningLine.isDone) {
|
|
@@ -16,7 +16,11 @@ class TopicSuggester {
|
|
|
16
16
|
const container = (0, core_1.containerBootstrap)();
|
|
17
17
|
container.use(lang_en_1.LangEn);
|
|
18
18
|
container.use(nlu_1.NluNeural);
|
|
19
|
-
const manager = new nlu_1.NluManager({
|
|
19
|
+
const manager = new nlu_1.NluManager({
|
|
20
|
+
container,
|
|
21
|
+
locales: ['en'],
|
|
22
|
+
log: false,
|
|
23
|
+
});
|
|
20
24
|
for (const topic of options.topics) {
|
|
21
25
|
manager.assignDomain('en', topic.key, topic.key);
|
|
22
26
|
for (const utterance of topic.utterances) {
|
|
@@ -10,17 +10,15 @@ export type SendMessage = SpruceSchemas.Spruce.v2020_07_22.SendMessage;
|
|
|
10
10
|
export type SendMessageHandler = (message: SendMessage) => Promise<void>;
|
|
11
11
|
export type DidMessageResponsePayloadSchema = SkillEventContract['eventSignatures']['did-message::v2020_12_25']['responsePayloadSchema'];
|
|
12
12
|
export type DidMessageResponsePayload = SchemaValues<DidMessageResponsePayloadSchema>;
|
|
13
|
-
export
|
|
13
|
+
export interface ScriptLineCallbackOptions {
|
|
14
14
|
ui: GraphicsInterface;
|
|
15
15
|
state: Record<string, any>;
|
|
16
16
|
rand<T>(possibilities: T[]): T;
|
|
17
17
|
message: Message;
|
|
18
18
|
context: SkillContext;
|
|
19
|
-
};
|
|
20
|
-
export type ScriptLine = string | ScriptLineCallback | string[];
|
|
21
|
-
export interface ScriptLineCallback {
|
|
22
|
-
(options: ScriptLineCallbackOptions): Promise<void | DidMessageResponsePayload>;
|
|
23
19
|
}
|
|
20
|
+
export type ScriptLine = string | ScriptLineCallback | string[];
|
|
21
|
+
export type ScriptLineCallback = (options: ScriptLineCallbackOptions) => Promise<void | DidMessageResponsePayload>;
|
|
24
22
|
export type Script = ScriptLine[];
|
|
25
23
|
export interface ScriptPlayerOptions {
|
|
26
24
|
script: Script;
|
|
@@ -30,10 +28,10 @@ export interface ScriptPlayerOptions {
|
|
|
30
28
|
graphicsInterface?: MessageGraphicsInterface;
|
|
31
29
|
getContext: () => SkillContext;
|
|
32
30
|
}
|
|
33
|
-
export
|
|
31
|
+
export interface ScriptPlayerSendMessage {
|
|
34
32
|
body: string;
|
|
35
33
|
choices?: Message['choices'];
|
|
36
|
-
}
|
|
34
|
+
}
|
|
37
35
|
export declare const suggestedConversationTopicSchema: {
|
|
38
36
|
id: string;
|
|
39
37
|
fields: {
|
|
@@ -78,6 +76,4 @@ export interface FieldHandlerOptions<D extends FieldDefinitions = FieldDefinitio
|
|
|
78
76
|
waitForNextMessageHandler: () => Promise<string>;
|
|
79
77
|
definition: D;
|
|
80
78
|
}
|
|
81
|
-
export
|
|
82
|
-
(options: FieldHandlerOptions<F>): Promise<any>;
|
|
83
|
-
}
|
|
79
|
+
export type FieldHandler<F extends FieldDefinitions = FieldDefinitions> = (options: FieldHandlerOptions<F>) => Promise<any>;
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"@types/inquirer"
|
|
13
13
|
]
|
|
14
14
|
},
|
|
15
|
-
"version": "62.0.
|
|
15
|
+
"version": "62.0.2",
|
|
16
16
|
"files": [
|
|
17
17
|
"build/**/*",
|
|
18
18
|
"!build/__tests__",
|
|
@@ -66,36 +66,36 @@
|
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"@nlpjs/nlu": "^4.27.0",
|
|
69
|
-
"@sprucelabs/error": "^6.0.
|
|
70
|
-
"@sprucelabs/globby": "^2.0.
|
|
71
|
-
"@sprucelabs/mercury-core-events": "^24.0.
|
|
72
|
-
"@sprucelabs/schema": "^30.0.
|
|
73
|
-
"@sprucelabs/spruce-core-schemas": "^40.0.
|
|
74
|
-
"@sprucelabs/spruce-event-plugin": "^62.0.
|
|
75
|
-
"@sprucelabs/spruce-event-utils": "^40.0.
|
|
76
|
-
"@sprucelabs/spruce-skill-booter": "^62.0.
|
|
77
|
-
"@sprucelabs/spruce-skill-utils": "^31.0.
|
|
78
|
-
"@sprucelabs/spruce-test-fixtures": "^62.0.
|
|
69
|
+
"@sprucelabs/error": "^6.0.4",
|
|
70
|
+
"@sprucelabs/globby": "^2.0.4",
|
|
71
|
+
"@sprucelabs/mercury-core-events": "^24.0.3",
|
|
72
|
+
"@sprucelabs/schema": "^30.0.5",
|
|
73
|
+
"@sprucelabs/spruce-core-schemas": "^40.0.4",
|
|
74
|
+
"@sprucelabs/spruce-event-plugin": "^62.0.2",
|
|
75
|
+
"@sprucelabs/spruce-event-utils": "^40.0.3",
|
|
76
|
+
"@sprucelabs/spruce-skill-booter": "^62.0.2",
|
|
77
|
+
"@sprucelabs/spruce-skill-utils": "^31.0.6",
|
|
78
|
+
"@sprucelabs/spruce-test-fixtures": "^62.0.2",
|
|
79
79
|
"fuzzyset": "^1.0.7",
|
|
80
80
|
"inquirer": "^8.2.4",
|
|
81
81
|
"node-nlp": "^4.27.0",
|
|
82
82
|
"random": "^4.1.0"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
|
-
"@sprucelabs/esm-postbuild": "^6.0.
|
|
86
|
-
"@sprucelabs/jest-json-reporter": "^8.0.
|
|
87
|
-
"@sprucelabs/mercury-client": "^42.0.
|
|
88
|
-
"@sprucelabs/resolve-path-aliases": "^2.0.
|
|
85
|
+
"@sprucelabs/esm-postbuild": "^6.0.5",
|
|
86
|
+
"@sprucelabs/jest-json-reporter": "^8.0.3",
|
|
87
|
+
"@sprucelabs/mercury-client": "^42.0.4",
|
|
88
|
+
"@sprucelabs/resolve-path-aliases": "^2.0.7",
|
|
89
89
|
"@sprucelabs/semantic-release": "^5.0.1",
|
|
90
|
-
"@sprucelabs/test": "^9.0.
|
|
91
|
-
"@sprucelabs/test-utils": "^5.0.
|
|
90
|
+
"@sprucelabs/test": "^9.0.5",
|
|
91
|
+
"@sprucelabs/test-utils": "^5.0.4",
|
|
92
92
|
"@types/fuzzyset": "^1.0.7",
|
|
93
93
|
"@types/inquirer": "^8.2.1",
|
|
94
94
|
"@types/node": "17.0.5",
|
|
95
95
|
"chokidar-cli": "^3.0.0",
|
|
96
96
|
"concurrently": "^8.2.2",
|
|
97
|
-
"eslint": "^9.
|
|
98
|
-
"eslint-config-spruce": "^11.2.
|
|
97
|
+
"eslint": "^9.1.1",
|
|
98
|
+
"eslint-config-spruce": "^11.2.12",
|
|
99
99
|
"jest": "^29.7.0",
|
|
100
100
|
"jest-circus": "^29.7.0",
|
|
101
101
|
"prettier": "^3.2.5",
|
|
@@ -121,5 +121,5 @@
|
|
|
121
121
|
"^#spruce/(.*)$": "<rootDir>/build/.spruce/$1"
|
|
122
122
|
}
|
|
123
123
|
},
|
|
124
|
-
"gitHead": "
|
|
124
|
+
"gitHead": "9fdbb199e8aa7838697547d6abd709e6c642d4ec"
|
|
125
125
|
}
|