@sprucelabs/spruce-conversation-plugin 62.0.1 → 62.0.3
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/errors.types.d.ts +8 -8
- package/build/.spruce/errors/options.types.d.ts +2 -2
- 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/ScriptTester.test.js +3 -4
- 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/.spruce/errors/errors.types.d.ts +8 -8
- package/build/esm/.spruce/errors/options.types.d.ts +2 -2
- 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/ScriptTester.test.js +1 -2
- 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 -22
|
@@ -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.3",
|
|
16
16
|
"files": [
|
|
17
17
|
"build/**/*",
|
|
18
18
|
"!build/__tests__",
|
|
@@ -59,43 +59,41 @@
|
|
|
59
59
|
"post.watch.build": "yarn run build.copy-files && yarn run build.resolve-paths",
|
|
60
60
|
"spruce.upgrade": "spruce upgrade",
|
|
61
61
|
"watch.build.dev": "tsc-watch --sourceMap --onCompilationComplete 'yarn post.watch.build'",
|
|
62
|
-
"watch.lint": "concurrently 'yarn run lint' \"chokidar 'src/**/*' -c 'yarn run lint.tsc'\"",
|
|
63
62
|
"watch.rebuild": "yarn run clean.all && yarn install && yarn run watch.build.dev",
|
|
64
63
|
"watch.tsc": "tsc -w",
|
|
65
64
|
"lint.tsc": "tsc -p . --noEmit"
|
|
66
65
|
},
|
|
67
66
|
"dependencies": {
|
|
68
67
|
"@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.
|
|
68
|
+
"@sprucelabs/error": "^6.0.13",
|
|
69
|
+
"@sprucelabs/globby": "^2.0.11",
|
|
70
|
+
"@sprucelabs/mercury-core-events": "^24.0.8",
|
|
71
|
+
"@sprucelabs/schema": "^30.0.17",
|
|
72
|
+
"@sprucelabs/spruce-core-schemas": "^40.0.13",
|
|
73
|
+
"@sprucelabs/spruce-event-plugin": "^62.0.3",
|
|
74
|
+
"@sprucelabs/spruce-event-utils": "^40.0.13",
|
|
75
|
+
"@sprucelabs/spruce-skill-booter": "^62.0.3",
|
|
76
|
+
"@sprucelabs/spruce-skill-utils": "^31.0.17",
|
|
77
|
+
"@sprucelabs/spruce-test-fixtures": "^62.0.3",
|
|
79
78
|
"fuzzyset": "^1.0.7",
|
|
80
79
|
"inquirer": "^8.2.4",
|
|
81
80
|
"node-nlp": "^4.27.0",
|
|
82
81
|
"random": "^4.1.0"
|
|
83
82
|
},
|
|
84
83
|
"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.
|
|
84
|
+
"@sprucelabs/esm-postbuild": "^6.0.12",
|
|
85
|
+
"@sprucelabs/jest-json-reporter": "^8.0.15",
|
|
86
|
+
"@sprucelabs/mercury-client": "^42.0.13",
|
|
87
|
+
"@sprucelabs/resolve-path-aliases": "^2.0.14",
|
|
89
88
|
"@sprucelabs/semantic-release": "^5.0.1",
|
|
90
|
-
"@sprucelabs/test": "^9.0.
|
|
91
|
-
"@sprucelabs/test-utils": "^5.0.
|
|
89
|
+
"@sprucelabs/test": "^9.0.10",
|
|
90
|
+
"@sprucelabs/test-utils": "^5.0.12",
|
|
92
91
|
"@types/fuzzyset": "^1.0.7",
|
|
93
92
|
"@types/inquirer": "^8.2.1",
|
|
94
93
|
"@types/node": "17.0.5",
|
|
95
94
|
"chokidar-cli": "^3.0.0",
|
|
96
|
-
"
|
|
97
|
-
"eslint": "^
|
|
98
|
-
"eslint-config-spruce": "^11.2.7",
|
|
95
|
+
"eslint": "^9.1.1",
|
|
96
|
+
"eslint-config-spruce": "^11.2.14",
|
|
99
97
|
"jest": "^29.7.0",
|
|
100
98
|
"jest-circus": "^29.7.0",
|
|
101
99
|
"prettier": "^3.2.5",
|
|
@@ -121,5 +119,5 @@
|
|
|
121
119
|
"^#spruce/(.*)$": "<rootDir>/build/.spruce/$1"
|
|
122
120
|
}
|
|
123
121
|
},
|
|
124
|
-
"gitHead": "
|
|
122
|
+
"gitHead": "cd2ddfd22a6c237cb6b20f085967f5df56623e78"
|
|
125
123
|
}
|