@sprucelabs/spruce-conversation-plugin 56.1.4 → 56.1.6

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.
Files changed (39) hide show
  1. package/build/__tests__/behavioral/TestingAConversation.test.d.ts +4 -0
  2. package/build/__tests__/behavioral/TestingAConversation.test.js +41 -1
  3. package/build/__tests__/implementation/ConversationCoordinator.test.d.ts +2 -1
  4. package/build/__tests__/implementation/ConversationCoordinator.test.js +4 -1
  5. package/build/__tests__/implementation/ScriptTester.test.d.ts +2 -1
  6. package/build/__tests__/implementation/ScriptTester.test.js +15 -12
  7. package/build/__tests__/implementation/TopicScriptPlayer.test.d.ts +2 -1
  8. package/build/__tests__/testDirsAndFiles/skill-with-one-topic/build/.spruce/events/listeners.d.ts +2 -0
  9. package/build/__tests__/testDirsAndFiles/skill-with-one-topic/build/.spruce/events/listeners.js +3 -0
  10. package/build/__tests__/testDirsAndFiles/skill-with-one-topic/build/conversations/bookAppointment.topic.d.ts +3 -0
  11. package/build/__tests__/testDirsAndFiles/skill-with-one-topic/build/conversations/bookAppointment.topic.js +8 -0
  12. package/build/conversations/ConversationCoordinator.d.ts +1 -1
  13. package/build/conversations/ConversationCoordinator.js +1 -0
  14. package/build/esm/__tests__/behavioral/TestingAConversation.test.d.ts +4 -0
  15. package/build/esm/__tests__/behavioral/TestingAConversation.test.js +45 -1
  16. package/build/esm/__tests__/implementation/ConversationCoordinator.test.d.ts +2 -1
  17. package/build/esm/__tests__/implementation/ConversationCoordinator.test.js +4 -1
  18. package/build/esm/__tests__/implementation/ScriptTester.test.d.ts +2 -1
  19. package/build/esm/__tests__/implementation/ScriptTester.test.js +17 -12
  20. package/build/esm/__tests__/implementation/TopicScriptPlayer.test.d.ts +2 -1
  21. package/build/esm/__tests__/testDirsAndFiles/skill-with-one-topic/build/conversations/bookAppointment.topic.d.ts +3 -0
  22. package/build/esm/__tests__/testDirsAndFiles/skill-with-one-topic/build/conversations/bookAppointment.topic.js +6 -0
  23. package/build/esm/conversations/ConversationCoordinator.d.ts +1 -1
  24. package/build/esm/conversations/ConversationCoordinator.js +1 -0
  25. package/build/esm/interfaces/MessageGraphicsInterface.d.ts +1 -1
  26. package/build/esm/interfaces/MessageGraphicsInterface.js +1 -1
  27. package/build/esm/plugins/conversation.plugin.d.ts +1 -0
  28. package/build/esm/plugins/conversation.plugin.js +9 -5
  29. package/build/esm/tests/AbstractGraphicsInterfaceTest.js +1 -1
  30. package/build/esm/tests/ScriptTester.d.ts +14 -8
  31. package/build/esm/tests/ScriptTester.js +15 -4
  32. package/build/interfaces/MessageGraphicsInterface.d.ts +1 -1
  33. package/build/interfaces/MessageGraphicsInterface.js +1 -1
  34. package/build/plugins/conversation.plugin.d.ts +1 -0
  35. package/build/plugins/conversation.plugin.js +9 -5
  36. package/build/tests/AbstractGraphicsInterfaceTest.js +1 -1
  37. package/build/tests/ScriptTester.d.ts +14 -8
  38. package/build/tests/ScriptTester.js +15 -4
  39. package/package.json +9 -9
@@ -1,3 +1,4 @@
1
+ import { SkillContext } from '@sprucelabs/spruce-skill-utils';
1
2
  import AbstractConversationTest from '../../tests/AbstractConversationTest';
2
3
  export default class TestingAConversationTest extends AbstractConversationTest {
3
4
  protected static afterEach(): Promise<void>;
@@ -6,5 +7,8 @@ export default class TestingAConversationTest extends AbstractConversationTest {
6
7
  protected static bootsInTestModeWithProperAction(): Promise<void>;
7
8
  protected static throwsWithBadScript(): Promise<void>;
8
9
  protected static throwsWithThrowsInScript(): Promise<void>;
10
+ protected static scriptTesterGetsContext(context: SkillContext): Promise<void>;
11
+ private static getScriptTester;
9
12
  private static bootAndGetConversationFeature;
13
+ private static getConversationFeature;
10
14
  }
@@ -9,6 +9,7 @@ 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 mercury_client_1 = require("@sprucelabs/mercury-client");
12
13
  const test_utils_1 = require("@sprucelabs/test-utils");
13
14
  const test_utils_2 = require("@sprucelabs/test-utils");
14
15
  const AbstractConversationTest_1 = __importDefault(require("../../tests/AbstractConversationTest"));
@@ -49,11 +50,46 @@ class TestingAConversationTest extends AbstractConversationTest_1.default {
49
50
  const err = await test_utils_1.assert.doesThrowAsync(() => skill.execute());
50
51
  test_utils_2.errorAssert.assertError(err, 'CONVERSATION_ABORTED');
51
52
  }
53
+ static async scriptTesterGetsContext(context) {
54
+ this.cwd = this.resolveTestPath('skill-with-one-topic');
55
+ mercury_client_1.MercuryClientFactory.setIsTestMode(true);
56
+ process.env.ACTION = 'test.conversation';
57
+ process.env.FIRST_MESSAGE = 'hey there!';
58
+ const skill = await this.Skill();
59
+ const getContext = () => context;
60
+ //@ts-ignore
61
+ skill.getContext = getContext;
62
+ void this.bootSkill({ skill });
63
+ await this.wait(100);
64
+ const scriptTester = await this.getScriptTester(skill);
65
+ //@ts-ignore
66
+ scriptTester.writeHandler = () => { };
67
+ //@ts-ignore
68
+ const player = scriptTester.player;
69
+ test_utils_1.assert.isTruthy(player);
70
+ //@ts-ignore
71
+ test_utils_1.assert.isEqualDeep(player.getContext(), context);
72
+ await skill.kill();
73
+ }
74
+ static async getScriptTester(skill) {
75
+ const conversation = this.getConversationFeature(skill);
76
+ //@ts-ignore
77
+ while (!conversation.tester) {
78
+ await this.wait(100);
79
+ }
80
+ //@ts-ignore
81
+ const scriptTester = conversation.tester;
82
+ test_utils_1.assert.isTruthy(scriptTester);
83
+ return scriptTester;
84
+ }
52
85
  static async bootAndGetConversationFeature(options) {
53
86
  const { skill } = await this.bootSkill(options);
54
- const conversation = skill.getFeatureByCode('conversation');
87
+ const conversation = this.getConversationFeature(skill);
55
88
  return conversation;
56
89
  }
90
+ static getConversationFeature(skill) {
91
+ return skill.getFeatureByCode('conversation');
92
+ }
57
93
  }
58
94
  __decorate([
59
95
  (0, test_utils_1.test)()
@@ -67,4 +103,8 @@ __decorate([
67
103
  __decorate([
68
104
  (0, test_utils_1.test)()
69
105
  ], TestingAConversationTest, "throwsWithThrowsInScript", null);
106
+ __decorate([
107
+ (0, test_utils_1.test)('can get context 1', { hello: 'world' }),
108
+ (0, test_utils_1.test)('can get context 2', { what: 'the!?' })
109
+ ], TestingAConversationTest, "scriptTesterGetsContext", null);
70
110
  exports.default = TestingAConversationTest;
@@ -1,3 +1,4 @@
1
+ import { SkillContext } from '@sprucelabs/spruce-skill-utils';
1
2
  import AbstractConversationTest from '../../tests/AbstractConversationTest';
2
3
  export default class TopicCoordinatorTest extends AbstractConversationTest {
3
4
  private static coordinator;
@@ -13,5 +14,5 @@ export default class TopicCoordinatorTest extends AbstractConversationTest {
13
14
  protected static playsScriptWhenTopicIsSelected(): Promise<void>;
14
15
  protected static canHandlePromptsInScript(): Promise<void>;
15
16
  protected static canPlaceMixedScriptsUntilTheEndAndStartsOver(): Promise<void>;
16
- protected static passesThroughContextGetter(context: Record<string, any>): Promise<void>;
17
+ protected static passesThroughContextGetter(context: SkillContext): Promise<void>;
17
18
  }
@@ -9,6 +9,7 @@ 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 test_utils_2 = require("@sprucelabs/test-utils");
14
15
  const ConversationCoordinator_1 = require("../../conversations/ConversationCoordinator");
@@ -124,7 +125,9 @@ class TopicCoordinatorTest extends AbstractConversationTest_1.default {
124
125
  }
125
126
  }
126
127
  TopicCoordinatorTest.sentMessages = [];
127
- TopicCoordinatorTest.skillContext = {};
128
+ TopicCoordinatorTest.skillContext = {
129
+ client: spruce_test_fixtures_1.fake.getClient(),
130
+ };
128
131
  __decorate([
129
132
  (0, test_utils_1.test)()
130
133
  ], TopicCoordinatorTest, "canCreateTopicCoordinator", null);
@@ -1,12 +1,12 @@
1
1
  import AbstractConversationTest from '../../tests/AbstractConversationTest';
2
2
  import { Script } from '../../types/conversation.types';
3
3
  export default class ScriptTesterTest extends AbstractConversationTest {
4
+ private static readonly basicBookingScript;
4
5
  protected static throwsWithoutScript(): Promise<void>;
5
6
  protected static acceptsSimpleScript(): Promise<void>;
6
7
  protected static callingGoDoesntCrash(): Promise<void>;
7
8
  protected static cantHandleMessageBeforeStartup(): Promise<void>;
8
9
  protected static selectingBadScriptToStartThrows(): Promise<void>;
9
- private static readonly basicBookingScript;
10
10
  protected static asksWhichScriptYouWantToStartWithWhenThereIsMoreThanOne(): Promise<void>;
11
11
  protected static playsSimpleScript(script: Script): Promise<void>;
12
12
  protected static canSendInputToThePlayer(answer: string): Promise<void>;
@@ -15,4 +15,5 @@ export default class ScriptTesterTest extends AbstractConversationTest {
15
15
  protected static promptsToStartAgainAfterDone(): Promise<void>;
16
16
  protected static messagesAboutTransitionResponseTopicChanger(): Promise<void>;
17
17
  protected static messagesAboutTransitionResponseWithRepairs(): Promise<void>;
18
+ private static Tester;
18
19
  }
@@ -45,7 +45,7 @@ class ScriptTesterTest extends AbstractConversationTest_1.default {
45
45
  });
46
46
  }
47
47
  static async acceptsSimpleScript() {
48
- const tester = await ScriptTester_1.default.Tester({
48
+ const tester = await ScriptTesterTest.Tester({
49
49
  topics: [
50
50
  {
51
51
  utterances: [],
@@ -58,7 +58,7 @@ class ScriptTesterTest extends AbstractConversationTest_1.default {
58
58
  test_utils_1.assert.isTruthy(tester);
59
59
  }
60
60
  static async callingGoDoesntCrash() {
61
- const tester = await ScriptTester_1.default.Tester({
61
+ const tester = await this.Tester({
62
62
  topics: [
63
63
  {
64
64
  utterances: [],
@@ -74,7 +74,7 @@ class ScriptTesterTest extends AbstractConversationTest_1.default {
74
74
  void tester.go();
75
75
  }
76
76
  static async cantHandleMessageBeforeStartup() {
77
- const tester = await ScriptTester_1.default.Tester({
77
+ const tester = await this.Tester({
78
78
  topics: [
79
79
  {
80
80
  utterances: [],
@@ -91,7 +91,7 @@ class ScriptTesterTest extends AbstractConversationTest_1.default {
91
91
  test_utils_2.errorAssert.assertError(err, 'TESTER_NOT_STARTED');
92
92
  }
93
93
  static async selectingBadScriptToStartThrows() {
94
- const tester = await ScriptTester_1.default.Tester({
94
+ const tester = await this.Tester({
95
95
  topics: this.basicBookingScript,
96
96
  selectPromptHandler: async () => {
97
97
  return 'oeuou';
@@ -108,7 +108,7 @@ class ScriptTesterTest extends AbstractConversationTest_1.default {
108
108
  static async asksWhichScriptYouWantToStartWithWhenThereIsMoreThanOne() {
109
109
  let choices;
110
110
  const writes = [];
111
- const tester = await ScriptTester_1.default.Tester({
111
+ const tester = await this.Tester({
112
112
  topics: this.basicBookingScript,
113
113
  selectPromptHandler: async (message) => {
114
114
  var _a;
@@ -136,7 +136,7 @@ class ScriptTesterTest extends AbstractConversationTest_1.default {
136
136
  }
137
137
  static async playsSimpleScript(script) {
138
138
  const writes = [];
139
- const tester = await ScriptTester_1.default.Tester({
139
+ const tester = await this.Tester({
140
140
  shouldPlayReplayAfterFinish: false,
141
141
  lineDelay: 0,
142
142
  topics: [{ key: 'test', label: 'Testing', script, utterances: [] }],
@@ -159,7 +159,7 @@ class ScriptTesterTest extends AbstractConversationTest_1.default {
159
159
  }
160
160
  static async canSendInputToThePlayer(answer) {
161
161
  const writes = [];
162
- const tester = await ScriptTester_1.default.Tester({
162
+ const tester = await this.Tester({
163
163
  shouldPlayReplayAfterFinish: false,
164
164
  topics: [
165
165
  {
@@ -201,7 +201,7 @@ class ScriptTesterTest extends AbstractConversationTest_1.default {
201
201
  const writes = [];
202
202
  const promptWrites = [];
203
203
  let promptResolve;
204
- const tester = await ScriptTester_1.default.Tester({
204
+ const tester = await this.Tester({
205
205
  lineDelay: 0,
206
206
  topics: [
207
207
  {
@@ -238,7 +238,7 @@ class ScriptTesterTest extends AbstractConversationTest_1.default {
238
238
  static async showsConfidenceRatingBasedOnFirstMesageSent() {
239
239
  const writes = [];
240
240
  const promptWrites = [];
241
- const tester = await ScriptTester_1.default.Tester({
241
+ const tester = await this.Tester({
242
242
  lineDelay: 0,
243
243
  topics: [
244
244
  {
@@ -264,7 +264,7 @@ class ScriptTesterTest extends AbstractConversationTest_1.default {
264
264
  static async promptsToStartAgainAfterDone() {
265
265
  const writes = [];
266
266
  let promptHitCount = 0;
267
- const tester = await ScriptTester_1.default.Tester({
267
+ const tester = await this.Tester({
268
268
  lineDelay: 0,
269
269
  topics: [
270
270
  {
@@ -303,7 +303,7 @@ class ScriptTesterTest extends AbstractConversationTest_1.default {
303
303
  static async messagesAboutTransitionResponseTopicChanger() {
304
304
  const writes = [];
305
305
  let promptHitCount = 0;
306
- const tester = await ScriptTester_1.default.Tester({
306
+ const tester = await this.Tester({
307
307
  lineDelay: 0,
308
308
  topics: [
309
309
  {
@@ -353,7 +353,7 @@ class ScriptTesterTest extends AbstractConversationTest_1.default {
353
353
  static async messagesAboutTransitionResponseWithRepairs() {
354
354
  const writes = [];
355
355
  let promptHitCount = 0;
356
- const tester = await ScriptTester_1.default.Tester({
356
+ const tester = await this.Tester({
357
357
  lineDelay: 0,
358
358
  topics: [
359
359
  {
@@ -400,6 +400,9 @@ class ScriptTesterTest extends AbstractConversationTest_1.default {
400
400
  ScriptTester_1.END_OF_LINE,
401
401
  ]);
402
402
  }
403
+ static async Tester(options) {
404
+ return await ScriptTester_1.default.Tester(Object.assign({ getContext: () => ({}), topics: [] }, options));
405
+ }
403
406
  }
404
407
  ScriptTesterTest.basicBookingScript = [
405
408
  {
@@ -1,3 +1,4 @@
1
+ import { SkillContext } from '@sprucelabs/spruce-skill-utils';
1
2
  import AbstractConversationTest from '../../tests/AbstractConversationTest';
2
3
  export default class TopicScriptPlayerTest extends AbstractConversationTest {
3
4
  protected static throwsWhenRequiredOptionsNotSent(): Promise<void>;
@@ -16,7 +17,7 @@ export default class TopicScriptPlayerTest extends AbstractConversationTest {
16
17
  protected static retainsStateBetweenScriptLines(): Promise<void>;
17
18
  protected static retainsStateBetweenMessages(): Promise<void>;
18
19
  protected static alwaysEndsWithRedirectToDiscovery(): Promise<void>;
19
- protected static skillContextAvailableOnScriptLine(context: Record<string, any>): Promise<void>;
20
+ protected static skillContextAvailableOnScriptLine(context: SkillContext): Promise<void>;
20
21
  private static Player;
21
22
  private static sendMessage;
22
23
  }
@@ -0,0 +1,2 @@
1
+ declare const _default: never[];
2
+ export default _default;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = [];
@@ -0,0 +1,3 @@
1
+ import { TopicDefinition } from '../../../../../types/conversation.types';
2
+ declare const topicDefinition: TopicDefinition;
3
+ export default topicDefinition;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const topicDefinition = {
4
+ label: 'book appointment',
5
+ utterances: ['book appointment', 'Can i book my appointment?', 'book'],
6
+ script: ['Sweet, lets book!', 'Lemme find your appointment!'],
7
+ };
8
+ exports.default = topicDefinition;
@@ -29,6 +29,6 @@ export declare class ConversationCoordinator {
29
29
  getContext: GetContext;
30
30
  Class?: new (...args: any[]) => ConversationCoordinator;
31
31
  }): Promise<ConversationCoordinator>;
32
- handleMessage(message: Message, topic?: string): Promise<MessageResponsePayload | void>;
32
+ handleMessage(message: Message, topic?: string): Promise<MessageResponsePayload | null>;
33
33
  }
34
34
  export {};
@@ -78,6 +78,7 @@ class ConversationCoordinator {
78
78
  if (results) {
79
79
  return results;
80
80
  }
81
+ return null;
81
82
  }
82
83
  }
83
84
  exports.ConversationCoordinator = ConversationCoordinator;
@@ -1,3 +1,4 @@
1
+ import { SkillContext } from '@sprucelabs/spruce-skill-utils';
1
2
  import AbstractConversationTest from '../../tests/AbstractConversationTest';
2
3
  export default class TestingAConversationTest extends AbstractConversationTest {
3
4
  protected static afterEach(): Promise<void>;
@@ -6,5 +7,8 @@ export default class TestingAConversationTest extends AbstractConversationTest {
6
7
  protected static bootsInTestModeWithProperAction(): Promise<void>;
7
8
  protected static throwsWithBadScript(): Promise<void>;
8
9
  protected static throwsWithThrowsInScript(): Promise<void>;
10
+ protected static scriptTesterGetsContext(context: SkillContext): Promise<void>;
11
+ private static getScriptTester;
9
12
  private static bootAndGetConversationFeature;
13
+ private static getConversationFeature;
10
14
  }
@@ -13,6 +13,7 @@ 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 { MercuryClientFactory } from '@sprucelabs/mercury-client';
16
17
  import { test, assert } from '@sprucelabs/test-utils';
17
18
  import { errorAssert } from '@sprucelabs/test-utils';
18
19
  import AbstractConversationTest from '../../tests/AbstractConversationTest.js';
@@ -71,13 +72,52 @@ export default class TestingAConversationTest extends AbstractConversationTest {
71
72
  errorAssert.assertError(err, 'CONVERSATION_ABORTED');
72
73
  });
73
74
  }
75
+ static scriptTesterGetsContext(context) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ this.cwd = this.resolveTestPath('skill-with-one-topic');
78
+ MercuryClientFactory.setIsTestMode(true);
79
+ process.env.ACTION = 'test.conversation';
80
+ process.env.FIRST_MESSAGE = 'hey there!';
81
+ const skill = yield this.Skill();
82
+ const getContext = () => context;
83
+ //@ts-ignore
84
+ skill.getContext = getContext;
85
+ void this.bootSkill({ skill });
86
+ yield this.wait(100);
87
+ const scriptTester = yield this.getScriptTester(skill);
88
+ //@ts-ignore
89
+ scriptTester.writeHandler = () => { };
90
+ //@ts-ignore
91
+ const player = scriptTester.player;
92
+ assert.isTruthy(player);
93
+ //@ts-ignore
94
+ assert.isEqualDeep(player.getContext(), context);
95
+ yield skill.kill();
96
+ });
97
+ }
98
+ static getScriptTester(skill) {
99
+ return __awaiter(this, void 0, void 0, function* () {
100
+ const conversation = this.getConversationFeature(skill);
101
+ //@ts-ignore
102
+ while (!conversation.tester) {
103
+ yield this.wait(100);
104
+ }
105
+ //@ts-ignore
106
+ const scriptTester = conversation.tester;
107
+ assert.isTruthy(scriptTester);
108
+ return scriptTester;
109
+ });
110
+ }
74
111
  static bootAndGetConversationFeature(options) {
75
112
  return __awaiter(this, void 0, void 0, function* () {
76
113
  const { skill } = yield this.bootSkill(options);
77
- const conversation = skill.getFeatureByCode('conversation');
114
+ const conversation = this.getConversationFeature(skill);
78
115
  return conversation;
79
116
  });
80
117
  }
118
+ static getConversationFeature(skill) {
119
+ return skill.getFeatureByCode('conversation');
120
+ }
81
121
  }
82
122
  __decorate([
83
123
  test()
@@ -91,3 +131,7 @@ __decorate([
91
131
  __decorate([
92
132
  test()
93
133
  ], TestingAConversationTest, "throwsWithThrowsInScript", null);
134
+ __decorate([
135
+ test('can get context 1', { hello: 'world' }),
136
+ test('can get context 2', { what: 'the!?' })
137
+ ], TestingAConversationTest, "scriptTesterGetsContext", null);
@@ -1,3 +1,4 @@
1
+ import { SkillContext } from '@sprucelabs/spruce-skill-utils';
1
2
  import AbstractConversationTest from '../../tests/AbstractConversationTest';
2
3
  export default class TopicCoordinatorTest extends AbstractConversationTest {
3
4
  private static coordinator;
@@ -13,5 +14,5 @@ export default class TopicCoordinatorTest extends AbstractConversationTest {
13
14
  protected static playsScriptWhenTopicIsSelected(): Promise<void>;
14
15
  protected static canHandlePromptsInScript(): Promise<void>;
15
16
  protected static canPlaceMixedScriptsUntilTheEndAndStartsOver(): Promise<void>;
16
- protected static passesThroughContextGetter(context: Record<string, any>): Promise<void>;
17
+ protected static passesThroughContextGetter(context: SkillContext): Promise<void>;
17
18
  }
@@ -13,6 +13,7 @@ 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 { fake } from '@sprucelabs/spruce-test-fixtures';
16
17
  import { test, assert } from '@sprucelabs/test-utils';
17
18
  import { errorAssert } from '@sprucelabs/test-utils';
18
19
  import { ConversationCoordinator } from '../../conversations/ConversationCoordinator.js';
@@ -153,7 +154,9 @@ class TopicCoordinatorTest extends AbstractConversationTest {
153
154
  }
154
155
  }
155
156
  TopicCoordinatorTest.sentMessages = [];
156
- TopicCoordinatorTest.skillContext = {};
157
+ TopicCoordinatorTest.skillContext = {
158
+ client: fake.getClient(),
159
+ };
157
160
  __decorate([
158
161
  test()
159
162
  ], TopicCoordinatorTest, "canCreateTopicCoordinator", null);
@@ -1,12 +1,12 @@
1
1
  import AbstractConversationTest from '../../tests/AbstractConversationTest';
2
2
  import { Script } from '../../types/conversation.types';
3
3
  export default class ScriptTesterTest extends AbstractConversationTest {
4
+ private static readonly basicBookingScript;
4
5
  protected static throwsWithoutScript(): Promise<void>;
5
6
  protected static acceptsSimpleScript(): Promise<void>;
6
7
  protected static callingGoDoesntCrash(): Promise<void>;
7
8
  protected static cantHandleMessageBeforeStartup(): Promise<void>;
8
9
  protected static selectingBadScriptToStartThrows(): Promise<void>;
9
- private static readonly basicBookingScript;
10
10
  protected static asksWhichScriptYouWantToStartWithWhenThereIsMoreThanOne(): Promise<void>;
11
11
  protected static playsSimpleScript(script: Script): Promise<void>;
12
12
  protected static canSendInputToThePlayer(answer: string): Promise<void>;
@@ -15,4 +15,5 @@ export default class ScriptTesterTest extends AbstractConversationTest {
15
15
  protected static promptsToStartAgainAfterDone(): Promise<void>;
16
16
  protected static messagesAboutTransitionResponseTopicChanger(): Promise<void>;
17
17
  protected static messagesAboutTransitionResponseWithRepairs(): Promise<void>;
18
+ private static Tester;
18
19
  }
@@ -29,7 +29,7 @@ class ScriptTesterTest extends AbstractConversationTest {
29
29
  }
30
30
  static acceptsSimpleScript() {
31
31
  return __awaiter(this, void 0, void 0, function* () {
32
- const tester = yield ScriptTester.Tester({
32
+ const tester = yield ScriptTesterTest.Tester({
33
33
  topics: [
34
34
  {
35
35
  utterances: [],
@@ -44,7 +44,7 @@ class ScriptTesterTest extends AbstractConversationTest {
44
44
  }
45
45
  static callingGoDoesntCrash() {
46
46
  return __awaiter(this, void 0, void 0, function* () {
47
- const tester = yield ScriptTester.Tester({
47
+ const tester = yield this.Tester({
48
48
  topics: [
49
49
  {
50
50
  utterances: [],
@@ -62,7 +62,7 @@ class ScriptTesterTest extends AbstractConversationTest {
62
62
  }
63
63
  static cantHandleMessageBeforeStartup() {
64
64
  return __awaiter(this, void 0, void 0, function* () {
65
- const tester = yield ScriptTester.Tester({
65
+ const tester = yield this.Tester({
66
66
  topics: [
67
67
  {
68
68
  utterances: [],
@@ -81,7 +81,7 @@ class ScriptTesterTest extends AbstractConversationTest {
81
81
  }
82
82
  static selectingBadScriptToStartThrows() {
83
83
  return __awaiter(this, void 0, void 0, function* () {
84
- const tester = yield ScriptTester.Tester({
84
+ const tester = yield this.Tester({
85
85
  topics: this.basicBookingScript,
86
86
  selectPromptHandler: () => __awaiter(this, void 0, void 0, function* () {
87
87
  return 'oeuou';
@@ -100,7 +100,7 @@ class ScriptTesterTest extends AbstractConversationTest {
100
100
  return __awaiter(this, void 0, void 0, function* () {
101
101
  let choices;
102
102
  const writes = [];
103
- const tester = yield ScriptTester.Tester({
103
+ const tester = yield this.Tester({
104
104
  topics: this.basicBookingScript,
105
105
  selectPromptHandler: (message) => __awaiter(this, void 0, void 0, function* () {
106
106
  var _a;
@@ -130,7 +130,7 @@ class ScriptTesterTest extends AbstractConversationTest {
130
130
  static playsSimpleScript(script) {
131
131
  return __awaiter(this, void 0, void 0, function* () {
132
132
  const writes = [];
133
- const tester = yield ScriptTester.Tester({
133
+ const tester = yield this.Tester({
134
134
  shouldPlayReplayAfterFinish: false,
135
135
  lineDelay: 0,
136
136
  topics: [{ key: 'test', label: 'Testing', script, utterances: [] }],
@@ -155,7 +155,7 @@ class ScriptTesterTest extends AbstractConversationTest {
155
155
  static canSendInputToThePlayer(answer) {
156
156
  return __awaiter(this, void 0, void 0, function* () {
157
157
  const writes = [];
158
- const tester = yield ScriptTester.Tester({
158
+ const tester = yield this.Tester({
159
159
  shouldPlayReplayAfterFinish: false,
160
160
  topics: [
161
161
  {
@@ -199,7 +199,7 @@ class ScriptTesterTest extends AbstractConversationTest {
199
199
  const writes = [];
200
200
  const promptWrites = [];
201
201
  let promptResolve;
202
- const tester = yield ScriptTester.Tester({
202
+ const tester = yield this.Tester({
203
203
  lineDelay: 0,
204
204
  topics: [
205
205
  {
@@ -238,7 +238,7 @@ class ScriptTesterTest extends AbstractConversationTest {
238
238
  return __awaiter(this, void 0, void 0, function* () {
239
239
  const writes = [];
240
240
  const promptWrites = [];
241
- const tester = yield ScriptTester.Tester({
241
+ const tester = yield this.Tester({
242
242
  lineDelay: 0,
243
243
  topics: [
244
244
  {
@@ -266,7 +266,7 @@ class ScriptTesterTest extends AbstractConversationTest {
266
266
  return __awaiter(this, void 0, void 0, function* () {
267
267
  const writes = [];
268
268
  let promptHitCount = 0;
269
- const tester = yield ScriptTester.Tester({
269
+ const tester = yield this.Tester({
270
270
  lineDelay: 0,
271
271
  topics: [
272
272
  {
@@ -307,7 +307,7 @@ class ScriptTesterTest extends AbstractConversationTest {
307
307
  return __awaiter(this, void 0, void 0, function* () {
308
308
  const writes = [];
309
309
  let promptHitCount = 0;
310
- const tester = yield ScriptTester.Tester({
310
+ const tester = yield this.Tester({
311
311
  lineDelay: 0,
312
312
  topics: [
313
313
  {
@@ -359,7 +359,7 @@ class ScriptTesterTest extends AbstractConversationTest {
359
359
  return __awaiter(this, void 0, void 0, function* () {
360
360
  const writes = [];
361
361
  let promptHitCount = 0;
362
- const tester = yield ScriptTester.Tester({
362
+ const tester = yield this.Tester({
363
363
  lineDelay: 0,
364
364
  topics: [
365
365
  {
@@ -407,6 +407,11 @@ class ScriptTesterTest extends AbstractConversationTest {
407
407
  ]);
408
408
  });
409
409
  }
410
+ static Tester(options) {
411
+ return __awaiter(this, void 0, void 0, function* () {
412
+ return yield ScriptTester.Tester(Object.assign({ getContext: () => ({}), topics: [] }, options));
413
+ });
414
+ }
410
415
  }
411
416
  ScriptTesterTest.basicBookingScript = [
412
417
  {
@@ -1,3 +1,4 @@
1
+ import { SkillContext } from '@sprucelabs/spruce-skill-utils';
1
2
  import AbstractConversationTest from '../../tests/AbstractConversationTest';
2
3
  export default class TopicScriptPlayerTest extends AbstractConversationTest {
3
4
  protected static throwsWhenRequiredOptionsNotSent(): Promise<void>;
@@ -16,7 +17,7 @@ export default class TopicScriptPlayerTest extends AbstractConversationTest {
16
17
  protected static retainsStateBetweenScriptLines(): Promise<void>;
17
18
  protected static retainsStateBetweenMessages(): Promise<void>;
18
19
  protected static alwaysEndsWithRedirectToDiscovery(): Promise<void>;
19
- protected static skillContextAvailableOnScriptLine(context: Record<string, any>): Promise<void>;
20
+ protected static skillContextAvailableOnScriptLine(context: SkillContext): Promise<void>;
20
21
  private static Player;
21
22
  private static sendMessage;
22
23
  }
@@ -0,0 +1,3 @@
1
+ import { TopicDefinition } from '../../../../../types/conversation.types';
2
+ declare const topicDefinition: TopicDefinition;
3
+ export default topicDefinition;
@@ -0,0 +1,6 @@
1
+ const topicDefinition = {
2
+ label: 'book appointment',
3
+ utterances: ['book appointment', 'Can i book my appointment?', 'book'],
4
+ script: ['Sweet, lets book!', 'Lemme find your appointment!'],
5
+ };
6
+ export default topicDefinition;
@@ -29,6 +29,6 @@ export declare class ConversationCoordinator {
29
29
  getContext: GetContext;
30
30
  Class?: new (...args: any[]) => ConversationCoordinator;
31
31
  }): Promise<ConversationCoordinator>;
32
- handleMessage(message: Message, topic?: string): Promise<MessageResponsePayload | void>;
32
+ handleMessage(message: Message, topic?: string): Promise<MessageResponsePayload | null>;
33
33
  }
34
34
  export {};
@@ -84,6 +84,7 @@ export class ConversationCoordinator {
84
84
  if (results) {
85
85
  return results;
86
86
  }
87
+ return null;
87
88
  });
88
89
  }
89
90
  }
@@ -36,5 +36,5 @@ export default class MessageGraphicsInterface implements GraphicsInterface {
36
36
  protected waitForNextMessage(): Promise<string>;
37
37
  handleMessageBody(body: string): Promise<void>;
38
38
  isWaitingForInput(): boolean;
39
- destory(): void;
39
+ destroy(): void;
40
40
  }
@@ -154,7 +154,7 @@ export default class MessageGraphicsInterface {
154
154
  isWaitingForInput() {
155
155
  return !!this.resolve;
156
156
  }
157
- destory() {
157
+ destroy() {
158
158
  this.isDestroyed = true;
159
159
  }
160
160
  }
@@ -9,6 +9,7 @@ export declare class ConversationFeature implements SkillFeature {
9
9
  private _isTesting;
10
10
  private coordinatorsBySource;
11
11
  private bootHandler?;
12
+ private tester?;
12
13
  constructor(skill: Skill);
13
14
  onBoot(cb: BootCallback): void;
14
15
  execute(): Promise<void>;
@@ -81,14 +81,18 @@ export class ConversationFeature {
81
81
  }
82
82
  startScriptTesterAndNotifyBoot(topics) {
83
83
  return __awaiter(this, void 0, void 0, function* () {
84
- const tester = yield ScriptTester.Tester({ topics });
84
+ this.tester = yield ScriptTester.Tester({
85
+ topics,
86
+ getContext: () => this.skill.getContext(),
87
+ });
85
88
  const promise = new Promise((resolve, reject) => {
86
89
  this.skill.onBoot(() => __awaiter(this, void 0, void 0, function* () {
90
+ var _a;
87
91
  this.log.info(`Found ${topics.length} topic${topics.length ? '' : 's'}. Holding for a second to let your skill finish building...`);
88
92
  this.log.info('Booting conversation tester.');
89
93
  console.clear();
90
94
  try {
91
- yield tester.go(process.env.FIRST_MESSAGE);
95
+ yield ((_a = this.tester) === null || _a === void 0 ? void 0 : _a.go(process.env.FIRST_MESSAGE));
92
96
  resolve();
93
97
  }
94
98
  catch (err) {
@@ -149,10 +153,9 @@ export class ConversationFeature {
149
153
  this.log.info(`Found ${topics.length} conversation topics.`);
150
154
  const client = yield this.connectToApi();
151
155
  this.log.info('Unregistering all past conversation topics.');
152
- const unregisterResults = yield client.emit('unregister-conversation-topics::v2020_12_25', {
156
+ yield client.emitAndFlattenResponses('unregister-conversation-topics::v2020_12_25', {
153
157
  payload: { shouldUnregisterAll: true },
154
158
  });
155
- eventResponseUtil.getFirstResponseOrThrow(unregisterResults);
156
159
  if (topics.length > 0) {
157
160
  this.log.info(`Registering new ${topics.length} topic${topics.length === 1 ? '' : 's'}.`);
158
161
  const results = yield client.emit(`register-conversation-topics::v2020_12_25`, { payload: { topics: topics.map((topic) => ({ key: topic.key })) } });
@@ -209,11 +212,12 @@ export class ConversationFeature {
209
212
  });
210
213
  }
211
214
  destroy() {
212
- var _a;
215
+ var _a, _b;
213
216
  return __awaiter(this, void 0, void 0, function* () {
214
217
  this._isTesting = false;
215
218
  (_a = this.executeResolver) === null || _a === void 0 ? void 0 : _a.call(this);
216
219
  this.executeResolver = undefined;
220
+ (_b = this.tester) === null || _b === void 0 ? void 0 : _b.destroy();
217
221
  while (this.isExecuting) {
218
222
  yield new Promise((resolve) => setTimeout(resolve, 250));
219
223
  }
@@ -31,7 +31,7 @@ export default class AbstractGraphicsInterfaceTest extends AbstractConversationT
31
31
  });
32
32
  return __awaiter(this, void 0, void 0, function* () {
33
33
  yield _super.afterEach.call(this);
34
- this.ui.destory();
34
+ this.ui.destroy();
35
35
  });
36
36
  }
37
37
  static sendMessage(body) {
@@ -1,3 +1,4 @@
1
+ import { SkillContext } from '@sprucelabs/spruce-skill-utils';
1
2
  import { PromptHandler } from '../interfaces/TestGraphicsInterface';
2
3
  import { LoadedTopicDefinition, Message } from '../types/conversation.types';
3
4
  export default class ScriptTester {
@@ -9,23 +10,28 @@ export default class ScriptTester {
9
10
  private lineDelay?;
10
11
  private shouldPlayReplayAfterFinish;
11
12
  private suggester?;
13
+ private getContext;
14
+ private isDestroyed;
12
15
  private constructor();
13
16
  go(firstMessage?: string): Promise<void>;
17
+ destroy(): void;
14
18
  private reportOnConfidence;
15
19
  private promptForDesiredTopic;
16
20
  handleInput(input: string): Promise<import("@sprucelabs/schema").SchemaStaticValues<import("@sprucelabs/mercury-types").SpruceSchemas.Mercury.v2020_12_25.DidMessageResponsePayloadSchema, false, import("@sprucelabs/schema").SchemaOptionalFieldNames<import("@sprucelabs/mercury-types").SpruceSchemas.Mercury.v2020_12_25.DidMessageResponsePayloadSchema>, import("@sprucelabs/schema").StaticSchemaAllValues<import("@sprucelabs/mercury-types").SpruceSchemas.Mercury.v2020_12_25.DidMessageResponsePayloadSchema, false>> | null>;
17
- static Tester(options: {
18
- topics: SimplifiedTopic[];
19
- writeHandler?: WriteHandler;
20
- selectPromptHandler?: SelectHandler;
21
- promptHandler?: PromptHandler;
22
- lineDelay?: number;
23
- shouldPlayReplayAfterFinish?: boolean;
24
- }): Promise<ScriptTester>;
21
+ static Tester(options: ScriptTesterOptions): Promise<ScriptTester>;
25
22
  }
26
23
  export declare function generateTransitionMessage(transitionConversationTo: string): string;
27
24
  type WriteHandler = (message: Pick<Message, 'body' | 'choices'>) => void;
28
25
  type SelectHandler = (message: Pick<Message, 'body' | 'choices'>) => Promise<string>;
29
26
  type SimplifiedTopic = LoadedTopicDefinition;
30
27
  export declare const END_OF_LINE = "END OF LINE \uD83D\uDC7E";
28
+ export interface ScriptTesterOptions {
29
+ topics: SimplifiedTopic[];
30
+ writeHandler?: WriteHandler;
31
+ selectPromptHandler?: SelectHandler;
32
+ promptHandler?: PromptHandler;
33
+ lineDelay?: number;
34
+ shouldPlayReplayAfterFinish?: boolean;
35
+ getContext: () => SkillContext;
36
+ }
31
37
  export {};
@@ -15,8 +15,10 @@ import { TopicScriptPlayer } from '../topics/TopicScriptPlayer.js';
15
15
  import { TopicSuggester } from '../topics/TopicSuggester.js';
16
16
  import randomUtil from '../utilities/random.utility.js';
17
17
  export default class ScriptTester {
18
- constructor(topics, writeHandler, selectPromptHandler, promptHandler, lineDelay, shouldPlayReplayAfterFinish) {
18
+ constructor(topics, getContext, writeHandler, selectPromptHandler, promptHandler, lineDelay, shouldPlayReplayAfterFinish) {
19
+ this.isDestroyed = false;
19
20
  this.writeHandler = writeHandler !== null && writeHandler !== void 0 ? writeHandler : ((message) => console.log(message.body));
21
+ this.getContext = getContext;
20
22
  this.topics = topics;
21
23
  this.selectPromptHandler =
22
24
  selectPromptHandler !== null && selectPromptHandler !== void 0 ? selectPromptHandler : inquirerSelectPromptHandler;
@@ -46,7 +48,7 @@ export default class ScriptTester {
46
48
  sendMessageHandler: (message) => __awaiter(this, void 0, void 0, function* () {
47
49
  return this.writeHandler(message);
48
50
  }),
49
- getContext: () => ({}),
51
+ getContext: this.getContext,
50
52
  });
51
53
  let msg = firstMessage;
52
54
  if (!msg) {
@@ -57,7 +59,13 @@ export default class ScriptTester {
57
59
  yield this.reportOnConfidence(msg);
58
60
  // eslint-disable-next-line no-constant-condition
59
61
  while (true) {
62
+ if (this.isDestroyed) {
63
+ return;
64
+ }
60
65
  const response = yield this.handleInput(msg);
66
+ if (this.isDestroyed) {
67
+ return;
68
+ }
61
69
  if (response === null || response === void 0 ? void 0 : response.transitionConversationTo) {
62
70
  if (response.topicChangers) {
63
71
  this.writeHandler({ body: randomUtil.rand(response.topicChangers) });
@@ -70,13 +78,16 @@ export default class ScriptTester {
70
78
  });
71
79
  }
72
80
  this.writeHandler({ body: END_OF_LINE });
73
- if (!this.shouldPlayReplayAfterFinish) {
81
+ if (!this.shouldPlayReplayAfterFinish || this.isDestroyed) {
74
82
  return;
75
83
  }
76
84
  yield this.promptHandler({ body: 'Enter to start again.' });
77
85
  }
78
86
  });
79
87
  }
88
+ destroy() {
89
+ this.isDestroyed = true;
90
+ }
80
91
  reportOnConfidence(msg) {
81
92
  return __awaiter(this, void 0, void 0, function* () {
82
93
  if (!this.suggester) {
@@ -133,7 +144,7 @@ export default class ScriptTester {
133
144
  if (missing.length > 0) {
134
145
  throw new SchemaError({ code: 'MISSING_PARAMETERS', parameters: missing });
135
146
  }
136
- return new ScriptTester(options.topics, options.writeHandler, options.selectPromptHandler, options.promptHandler, options.lineDelay, options.shouldPlayReplayAfterFinish);
147
+ return new ScriptTester(options.topics, options.getContext, options.writeHandler, options.selectPromptHandler, options.promptHandler, options.lineDelay, options.shouldPlayReplayAfterFinish);
137
148
  });
138
149
  }
139
150
  }
@@ -36,5 +36,5 @@ export default class MessageGraphicsInterface implements GraphicsInterface {
36
36
  protected waitForNextMessage(): Promise<string>;
37
37
  handleMessageBody(body: string): Promise<void>;
38
38
  isWaitingForInput(): boolean;
39
- destory(): void;
39
+ destroy(): void;
40
40
  }
@@ -142,7 +142,7 @@ class MessageGraphicsInterface {
142
142
  isWaitingForInput() {
143
143
  return !!this.resolve;
144
144
  }
145
- destory() {
145
+ destroy() {
146
146
  this.isDestroyed = true;
147
147
  }
148
148
  }
@@ -9,6 +9,7 @@ export declare class ConversationFeature implements SkillFeature {
9
9
  private _isTesting;
10
10
  private coordinatorsBySource;
11
11
  private bootHandler?;
12
+ private tester?;
12
13
  constructor(skill: Skill);
13
14
  onBoot(cb: BootCallback): void;
14
15
  execute(): Promise<void>;
@@ -71,14 +71,18 @@ class ConversationFeature {
71
71
  await ((_a = this.bootHandler) === null || _a === void 0 ? void 0 : _a.call(this));
72
72
  }
73
73
  async startScriptTesterAndNotifyBoot(topics) {
74
- const tester = await ScriptTester_1.default.Tester({ topics });
74
+ this.tester = await ScriptTester_1.default.Tester({
75
+ topics,
76
+ getContext: () => this.skill.getContext(),
77
+ });
75
78
  const promise = new Promise((resolve, reject) => {
76
79
  this.skill.onBoot(async () => {
80
+ var _a;
77
81
  this.log.info(`Found ${topics.length} topic${topics.length ? '' : 's'}. Holding for a second to let your skill finish building...`);
78
82
  this.log.info('Booting conversation tester.');
79
83
  console.clear();
80
84
  try {
81
- await tester.go(process.env.FIRST_MESSAGE);
85
+ await ((_a = this.tester) === null || _a === void 0 ? void 0 : _a.go(process.env.FIRST_MESSAGE));
82
86
  resolve();
83
87
  }
84
88
  catch (err) {
@@ -133,10 +137,9 @@ class ConversationFeature {
133
137
  this.log.info(`Found ${topics.length} conversation topics.`);
134
138
  const client = await this.connectToApi();
135
139
  this.log.info('Unregistering all past conversation topics.');
136
- const unregisterResults = await client.emit('unregister-conversation-topics::v2020_12_25', {
140
+ await client.emitAndFlattenResponses('unregister-conversation-topics::v2020_12_25', {
137
141
  payload: { shouldUnregisterAll: true },
138
142
  });
139
- spruce_event_utils_1.eventResponseUtil.getFirstResponseOrThrow(unregisterResults);
140
143
  if (topics.length > 0) {
141
144
  this.log.info(`Registering new ${topics.length} topic${topics.length === 1 ? '' : 's'}.`);
142
145
  const results = await client.emit(`register-conversation-topics::v2020_12_25`, { payload: { topics: topics.map((topic) => ({ key: topic.key })) } });
@@ -186,10 +189,11 @@ class ConversationFeature {
186
189
  return true;
187
190
  }
188
191
  async destroy() {
189
- var _a;
192
+ var _a, _b;
190
193
  this._isTesting = false;
191
194
  (_a = this.executeResolver) === null || _a === void 0 ? void 0 : _a.call(this);
192
195
  this.executeResolver = undefined;
196
+ (_b = this.tester) === null || _b === void 0 ? void 0 : _b.destroy();
193
197
  while (this.isExecuting) {
194
198
  await new Promise((resolve) => setTimeout(resolve, 250));
195
199
  }
@@ -18,7 +18,7 @@ class AbstractGraphicsInterfaceTest extends AbstractConversationTest_1.default {
18
18
  }
19
19
  static async afterEach() {
20
20
  await super.afterEach();
21
- this.ui.destory();
21
+ this.ui.destroy();
22
22
  }
23
23
  static async sendMessage(body) {
24
24
  await this.ui.handleMessageBody(body);
@@ -1,3 +1,4 @@
1
+ import { SkillContext } from '@sprucelabs/spruce-skill-utils';
1
2
  import { PromptHandler } from '../interfaces/TestGraphicsInterface';
2
3
  import { LoadedTopicDefinition, Message } from '../types/conversation.types';
3
4
  export default class ScriptTester {
@@ -9,23 +10,28 @@ export default class ScriptTester {
9
10
  private lineDelay?;
10
11
  private shouldPlayReplayAfterFinish;
11
12
  private suggester?;
13
+ private getContext;
14
+ private isDestroyed;
12
15
  private constructor();
13
16
  go(firstMessage?: string): Promise<void>;
17
+ destroy(): void;
14
18
  private reportOnConfidence;
15
19
  private promptForDesiredTopic;
16
20
  handleInput(input: string): Promise<import("@sprucelabs/schema").SchemaStaticValues<import("@sprucelabs/mercury-types").SpruceSchemas.Mercury.v2020_12_25.DidMessageResponsePayloadSchema, false, import("@sprucelabs/schema").SchemaOptionalFieldNames<import("@sprucelabs/mercury-types").SpruceSchemas.Mercury.v2020_12_25.DidMessageResponsePayloadSchema>, import("@sprucelabs/schema").StaticSchemaAllValues<import("@sprucelabs/mercury-types").SpruceSchemas.Mercury.v2020_12_25.DidMessageResponsePayloadSchema, false>> | null>;
17
- static Tester(options: {
18
- topics: SimplifiedTopic[];
19
- writeHandler?: WriteHandler;
20
- selectPromptHandler?: SelectHandler;
21
- promptHandler?: PromptHandler;
22
- lineDelay?: number;
23
- shouldPlayReplayAfterFinish?: boolean;
24
- }): Promise<ScriptTester>;
21
+ static Tester(options: ScriptTesterOptions): Promise<ScriptTester>;
25
22
  }
26
23
  export declare function generateTransitionMessage(transitionConversationTo: string): string;
27
24
  type WriteHandler = (message: Pick<Message, 'body' | 'choices'>) => void;
28
25
  type SelectHandler = (message: Pick<Message, 'body' | 'choices'>) => Promise<string>;
29
26
  type SimplifiedTopic = LoadedTopicDefinition;
30
27
  export declare const END_OF_LINE = "END OF LINE \uD83D\uDC7E";
28
+ export interface ScriptTesterOptions {
29
+ topics: SimplifiedTopic[];
30
+ writeHandler?: WriteHandler;
31
+ selectPromptHandler?: SelectHandler;
32
+ promptHandler?: PromptHandler;
33
+ lineDelay?: number;
34
+ shouldPlayReplayAfterFinish?: boolean;
35
+ getContext: () => SkillContext;
36
+ }
31
37
  export {};
@@ -12,8 +12,10 @@ const TopicScriptPlayer_1 = require("../topics/TopicScriptPlayer");
12
12
  const TopicSuggester_1 = require("../topics/TopicSuggester");
13
13
  const random_utility_1 = __importDefault(require("../utilities/random.utility"));
14
14
  class ScriptTester {
15
- constructor(topics, writeHandler, selectPromptHandler, promptHandler, lineDelay, shouldPlayReplayAfterFinish) {
15
+ constructor(topics, getContext, writeHandler, selectPromptHandler, promptHandler, lineDelay, shouldPlayReplayAfterFinish) {
16
+ this.isDestroyed = false;
16
17
  this.writeHandler = writeHandler !== null && writeHandler !== void 0 ? writeHandler : ((message) => console.log(message.body));
18
+ this.getContext = getContext;
17
19
  this.topics = topics;
18
20
  this.selectPromptHandler =
19
21
  selectPromptHandler !== null && selectPromptHandler !== void 0 ? selectPromptHandler : inquirerSelectPromptHandler;
@@ -42,7 +44,7 @@ class ScriptTester {
42
44
  sendMessageHandler: async (message) => {
43
45
  return this.writeHandler(message);
44
46
  },
45
- getContext: () => ({}),
47
+ getContext: this.getContext,
46
48
  });
47
49
  let msg = firstMessage;
48
50
  if (!msg) {
@@ -53,7 +55,13 @@ class ScriptTester {
53
55
  await this.reportOnConfidence(msg);
54
56
  // eslint-disable-next-line no-constant-condition
55
57
  while (true) {
58
+ if (this.isDestroyed) {
59
+ return;
60
+ }
56
61
  const response = await this.handleInput(msg);
62
+ if (this.isDestroyed) {
63
+ return;
64
+ }
57
65
  if (response === null || response === void 0 ? void 0 : response.transitionConversationTo) {
58
66
  if (response.topicChangers) {
59
67
  this.writeHandler({ body: random_utility_1.default.rand(response.topicChangers) });
@@ -66,12 +74,15 @@ class ScriptTester {
66
74
  });
67
75
  }
68
76
  this.writeHandler({ body: exports.END_OF_LINE });
69
- if (!this.shouldPlayReplayAfterFinish) {
77
+ if (!this.shouldPlayReplayAfterFinish || this.isDestroyed) {
70
78
  return;
71
79
  }
72
80
  await this.promptHandler({ body: 'Enter to start again.' });
73
81
  }
74
82
  }
83
+ destroy() {
84
+ this.isDestroyed = true;
85
+ }
75
86
  async reportOnConfidence(msg) {
76
87
  if (!this.suggester) {
77
88
  this.suggester = await TopicSuggester_1.TopicSuggester.Suggester({ topics: this.topics });
@@ -121,7 +132,7 @@ class ScriptTester {
121
132
  if (missing.length > 0) {
122
133
  throw new schema_1.SchemaError({ code: 'MISSING_PARAMETERS', parameters: missing });
123
134
  }
124
- return new ScriptTester(options.topics, options.writeHandler, options.selectPromptHandler, options.promptHandler, options.lineDelay, options.shouldPlayReplayAfterFinish);
135
+ return new ScriptTester(options.topics, options.getContext, options.writeHandler, options.selectPromptHandler, options.promptHandler, options.lineDelay, options.shouldPlayReplayAfterFinish);
125
136
  }
126
137
  }
127
138
  exports.default = ScriptTester;
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "@types/inquirer"
13
13
  ]
14
14
  },
15
- "version": "56.1.4",
15
+ "version": "56.1.6",
16
16
  "files": [
17
17
  "build/**/*",
18
18
  "!build/__tests__",
@@ -65,14 +65,14 @@
65
65
  "@nlpjs/nlu": "^4.26.1",
66
66
  "@sprucelabs/error": "^5.0.592",
67
67
  "@sprucelabs/globby": "^0.0.7",
68
- "@sprucelabs/mercury-core-events": "^18.0.35",
68
+ "@sprucelabs/mercury-core-events": "^18.0.36",
69
69
  "@sprucelabs/schema": "^28.5.155",
70
- "@sprucelabs/spruce-core-schemas": "^37.2.20",
71
- "@sprucelabs/spruce-event-plugin": "^56.1.4",
72
- "@sprucelabs/spruce-event-utils": "^34.0.32",
73
- "@sprucelabs/spruce-skill-booter": "^56.1.4",
70
+ "@sprucelabs/spruce-core-schemas": "^37.2.21",
71
+ "@sprucelabs/spruce-event-plugin": "^56.1.6",
72
+ "@sprucelabs/spruce-event-utils": "^34.0.33",
73
+ "@sprucelabs/spruce-skill-booter": "^56.1.6",
74
74
  "@sprucelabs/spruce-skill-utils": "^28.1.111",
75
- "@sprucelabs/spruce-test-fixtures": "^56.1.4",
75
+ "@sprucelabs/spruce-test-fixtures": "^56.1.6",
76
76
  "fuzzyset": "^1.0.7",
77
77
  "inquirer": "^8.2.4",
78
78
  "node-nlp": "^4.26.1",
@@ -81,7 +81,7 @@
81
81
  "devDependencies": {
82
82
  "@sprucelabs/esm-postbuild": "^3.0.15",
83
83
  "@sprucelabs/jest-json-reporter": "^7.0.13",
84
- "@sprucelabs/mercury-client": "^38.0.33",
84
+ "@sprucelabs/mercury-client": "^38.0.34",
85
85
  "@sprucelabs/resolve-path-aliases": "^1.1.201",
86
86
  "@sprucelabs/semantic-release": "^4.0.8",
87
87
  "@sprucelabs/test": "^7.7.431",
@@ -118,5 +118,5 @@
118
118
  "^#spruce/(.*)$": "<rootDir>/build/.spruce/$1"
119
119
  }
120
120
  },
121
- "gitHead": "12d080d5da6dfd1c18424242ae62867608cb09f6"
121
+ "gitHead": "a05ef3df4e9bde261c0b04628fa7e8b8a55fd065"
122
122
  }