@sprucelabs/spruce-conversation-plugin 62.3.44 → 62.3.45

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.
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
@@ -32,7 +21,7 @@ class ConversationCoordinator {
32
21
  const { Class, topicLookupPath, sendMessageHandler, lineDelay, getContext, } = options;
33
22
  const topics = await TopicLoader_1.default.loadTopics(topicLookupPath);
34
23
  const suggester = await TopicSuggester_1.TopicSuggester.Suggester({ topics });
35
- return new (Class !== null && Class !== void 0 ? Class : ConversationCoordinator)({
24
+ return new (Class ?? ConversationCoordinator)({
36
25
  suggester,
37
26
  sendMessageHandler,
38
27
  topics,
@@ -62,7 +51,7 @@ class ConversationCoordinator {
62
51
  validTopics: this.topics.map((t) => t.key),
63
52
  });
64
53
  }
65
- const target = __rest(message.source, []);
54
+ const { ...target } = message.source;
66
55
  delete target.isCore;
67
56
  if (!this.player || this.lastTopic !== matchedTopic.key) {
68
57
  this.lastTopic = matchedTopic.key;
@@ -9,7 +9,7 @@ class SpruceError extends error_1.default {
9
9
  friendlyMessage() {
10
10
  const { options } = this;
11
11
  let message;
12
- switch (options === null || options === void 0 ? void 0 : options.code) {
12
+ switch (options?.code) {
13
13
  case 'INVALID_TOPIC':
14
14
  message = `The conversation topic defined in ${options.topicScript} is not valid.`;
15
15
  break;
@@ -12,11 +12,10 @@ const TextFieldHandler_1 = __importDefault(require("./fieldHandlers/TextFieldHan
12
12
  const sentiment = new node_nlp_1.SentimentAnalyzer({ language: 'en' });
13
13
  class MessageGraphicsInterface {
14
14
  constructor(options) {
15
- var _a;
16
15
  this.invalidValueRepairIdx = 0;
17
16
  this.isDestroyed = false;
18
17
  this.sendMessageHandler = options.sendMessageHandler;
19
- this.invalidValueRepairs = (_a = options.invalidValueRepairs) !== null && _a !== void 0 ? _a : [
18
+ this.invalidValueRepairs = options.invalidValueRepairs ?? [
20
19
  "Oh geezy, I'm sorry, a don't understand.",
21
20
  ];
22
21
  }
@@ -137,7 +136,7 @@ class MessageGraphicsInterface {
137
136
  async handleMessageBody(body) {
138
137
  const resolve = this.resolve;
139
138
  this.resolve = undefined;
140
- resolve === null || resolve === void 0 ? void 0 : resolve(body);
139
+ resolve?.(body);
141
140
  }
142
141
  isWaitingForInput() {
143
142
  return !!this.resolve;
@@ -40,23 +40,20 @@ class MockMessageInterface extends MessageGraphicsInterface_1.default {
40
40
  });
41
41
  }
42
42
  answerPrompt(value) {
43
- var _a;
44
43
  this.isPrompting = false;
45
44
  this.clearLastPrompt();
46
- (_a = this.promptResolve) === null || _a === void 0 ? void 0 : _a.call(this, value);
45
+ this.promptResolve?.(value);
47
46
  }
48
47
  assertJustPromptedFor(type, options) {
49
- var _a, _b;
50
- test_utils_1.assert.isEqual((_a = this.lastPrompt) === null || _a === void 0 ? void 0 : _a.type, type, `You did not prompt for a '${type}'!`);
48
+ test_utils_1.assert.isEqual(this.lastPrompt?.type, type, `You did not prompt for a '${type}'!`);
51
49
  if (options) {
52
50
  if (!this.assertValidChoices(options)) {
53
- test_utils_1.assert.doesInclude((_b = this.lastPrompt) === null || _b === void 0 ? void 0 : _b.options, options, `Your prompt options are not what I expected!`);
51
+ test_utils_1.assert.doesInclude(this.lastPrompt?.options, options, `Your prompt options are not what I expected!`);
54
52
  }
55
53
  }
56
54
  }
57
55
  assertValidChoices(options) {
58
- var _a, _b;
59
- const choices = (_b = (_a = this.lastPrompt) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.choices;
56
+ const choices = this.lastPrompt?.options?.choices;
60
57
  if (choices) {
61
58
  schema_1.selectAssert.assertSelectChoicesMatch(choices, options.choices.map((c) => c.value));
62
59
  return true;
@@ -24,7 +24,13 @@ class EmailFieldHandler {
24
24
  const errs = emailField.validate(value);
25
25
  if (errs.length > 0) {
26
26
  if (attempt === 0) {
27
- return this.go(Object.assign(Object.assign({}, options), { definition: Object.assign(Object.assign({}, options.definition), { label: random_utility_1.default.rand(this.repairs) }) }), attempt + 1);
27
+ return this.go({
28
+ ...options,
29
+ definition: {
30
+ ...options.definition,
31
+ label: random_utility_1.default.rand(this.repairs),
32
+ },
33
+ }, attempt + 1);
28
34
  }
29
35
  else {
30
36
  throw new SpruceError_1.default({ code: 'ABORT' });
@@ -17,18 +17,17 @@ class SelectFieldHandler {
17
17
  }
18
18
  _a = SelectFieldHandler;
19
19
  SelectFieldHandler.handle = async (options) => {
20
- var _b, _c, _d, _e;
21
20
  const { sendMessageHandler, definition, waitForNextMessageHandler } = options;
22
21
  let value;
23
22
  definition.label &&
24
23
  sendMessageHandler({
25
24
  body: definition.label,
26
25
  //@ts-ignore
27
- choices: (_b = definition.options) === null || _b === void 0 ? void 0 : _b.choices,
26
+ choices: definition.options?.choices,
28
27
  });
29
28
  const response = await waitForNextMessageHandler();
30
29
  if (isNumeric(response)) {
31
- value = (_e = (_d = (_c = definition.options) === null || _c === void 0 ? void 0 : _c.choices) === null || _d === void 0 ? void 0 : _d[parseInt(response) - 1]) === null || _e === void 0 ? void 0 : _e.value;
30
+ value = definition.options?.choices?.[parseInt(response) - 1]?.value;
32
31
  if (!value) {
33
32
  return response;
34
33
  }
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
@@ -65,10 +54,9 @@ class ConversationFeature {
65
54
  return topics;
66
55
  }
67
56
  async notifyBooted() {
68
- var _a;
69
57
  this.isExecuting = false;
70
58
  this._isBooted = true;
71
- await ((_a = this.bootHandler) === null || _a === void 0 ? void 0 : _a.call(this));
59
+ await this.bootHandler?.();
72
60
  }
73
61
  async startScriptTesterAndNotifyBoot(topics) {
74
62
  this.tester = await ScriptTester_1.default.Tester({
@@ -77,12 +65,11 @@ class ConversationFeature {
77
65
  });
78
66
  const promise = new Promise((resolve, reject) => {
79
67
  this.skill.onBoot(async () => {
80
- var _a;
81
68
  this.log.info(`Found ${topics.length} topic${topics.length ? '' : 's'}. Holding for a second to let your skill finish building...`);
82
69
  this.log.info('Booting conversation tester.');
83
70
  console.clear();
84
71
  try {
85
- await ((_a = this.tester) === null || _a === void 0 ? void 0 : _a.go(process.env.FIRST_MESSAGE));
72
+ await this.tester?.go(process.env.FIRST_MESSAGE);
86
73
  resolve();
87
74
  }
88
75
  catch (err) {
@@ -101,9 +88,8 @@ class ConversationFeature {
101
88
  }
102
89
  async startConversationCoordinator(client) {
103
90
  await client.on('did-message::v2020_12_25', async (targetAndPayload) => {
104
- var _a;
105
91
  const { message, topic } = targetAndPayload.payload;
106
- const coordinator = await this.getCoordinatorForPerson(client, (_a = message.source.personId) !== null && _a !== void 0 ? _a : '***missing***');
92
+ const coordinator = await this.getCoordinatorForPerson(client, message.source.personId ?? '***missing***');
107
93
  return coordinator.handleMessage(message, topic);
108
94
  });
109
95
  }
@@ -117,7 +103,7 @@ class ConversationFeature {
117
103
  getContext: () => this.skill.getContext(),
118
104
  sendMessageHandler: async (message) => {
119
105
  try {
120
- const { target } = message, values = __rest(message, ["target"]);
106
+ const { target, ...values } = message;
121
107
  const results = await client.emit('send-message::v2020_12_25', {
122
108
  target,
123
109
  payload: {
@@ -183,7 +169,7 @@ class ConversationFeature {
183
169
  try {
184
170
  this.skill.getFeatureByCode('event');
185
171
  }
186
- catch (_a) {
172
+ catch {
187
173
  throw new SpruceError_1.default({
188
174
  code: 'MISSING_DEPENDENCIES',
189
175
  dependencies: ['event.plugin'],
@@ -194,11 +180,10 @@ class ConversationFeature {
194
180
  return true;
195
181
  }
196
182
  async destroy() {
197
- var _a, _b;
198
183
  this._isTesting = false;
199
- (_a = this.executeResolver) === null || _a === void 0 ? void 0 : _a.call(this);
184
+ this.executeResolver?.();
200
185
  this.executeResolver = undefined;
201
- (_b = this.tester) === null || _b === void 0 ? void 0 : _b.destroy();
186
+ this.tester?.destroy();
202
187
  while (this.isExecuting) {
203
188
  await new Promise((resolve) => setTimeout(resolve, 250));
204
189
  }
@@ -26,8 +26,11 @@ class AbstractConversationTest extends spruce_test_fixtures_1.AbstractSpruceFixt
26
26
  delete process.env.FIRST_MESSAGE;
27
27
  }
28
28
  static async Skill(options) {
29
- const { plugins = [spruce_event_plugin_1.plugin, conversation_plugin_1.default] } = options !== null && options !== void 0 ? options : {};
30
- return super.Skill(Object.assign({ plugins }, options));
29
+ const { plugins = [spruce_event_plugin_1.plugin, conversation_plugin_1.default] } = options ?? {};
30
+ return super.Skill({
31
+ plugins,
32
+ ...options,
33
+ });
31
34
  }
32
35
  static resolveTestPath(...pathAfterTestDirsAndFiles) {
33
36
  return this.resolvePath(__dirname, '..', '__tests__', 'testDirsAndFiles', ...pathAfterTestDirsAndFiles);
@@ -16,14 +16,14 @@ class ScriptTester {
16
16
  constructor(topics, getContext, writeHandler, selectPromptHandler, promptHandler, lineDelay, shouldPlayReplayAfterFinish) {
17
17
  this.isDestroyed = false;
18
18
  this.writeHandler =
19
- writeHandler !== null && writeHandler !== void 0 ? writeHandler : ((message) => console.log(message.body));
19
+ writeHandler ?? ((message) => console.log(message.body));
20
20
  this.getContext = getContext;
21
21
  this.topics = topics;
22
22
  this.selectPromptHandler =
23
- selectPromptHandler !== null && selectPromptHandler !== void 0 ? selectPromptHandler : inquirerSelectPromptHandler;
24
- this.promptHandler = promptHandler !== null && promptHandler !== void 0 ? promptHandler : inquirerPromptHandler;
23
+ selectPromptHandler ?? inquirerSelectPromptHandler;
24
+ this.promptHandler = promptHandler ?? inquirerPromptHandler;
25
25
  this.lineDelay = lineDelay;
26
- this.shouldPlayReplayAfterFinish = shouldPlayReplayAfterFinish !== null && shouldPlayReplayAfterFinish !== void 0 ? shouldPlayReplayAfterFinish : true;
26
+ this.shouldPlayReplayAfterFinish = shouldPlayReplayAfterFinish ?? true;
27
27
  }
28
28
  async go(firstMessage) {
29
29
  let match;
@@ -63,7 +63,7 @@ class ScriptTester {
63
63
  if (this.isDestroyed) {
64
64
  return;
65
65
  }
66
- if (response === null || response === void 0 ? void 0 : response.transitionConversationTo) {
66
+ if (response?.transitionConversationTo) {
67
67
  if (response.topicChangers) {
68
68
  this.writeHandler({
69
69
  body: random_utility_1.default.rand(response.topicChangers),
@@ -124,16 +124,15 @@ class ScriptTester {
124
124
  return match;
125
125
  }
126
126
  async handleInput(input) {
127
- var _a;
128
127
  if (!this.player) {
129
128
  throw new SpruceError_1.default({ code: 'TESTER_NOT_STARTED' });
130
129
  }
131
130
  //@ts-ignore
132
- return (_a = this.player) === null || _a === void 0 ? void 0 : _a.handleMessage({ body: input });
131
+ return this.player?.handleMessage({ body: input });
133
132
  }
134
133
  static async Tester(options) {
135
134
  const missing = [];
136
- if (!(options === null || options === void 0 ? void 0 : options.topics)) {
135
+ if (!options?.topics) {
137
136
  missing.push('script');
138
137
  }
139
138
  if (missing.length > 0) {
@@ -150,12 +149,11 @@ function generateTransitionMessage(transitionConversationTo) {
150
149
  return `Conversation exited. Transitioning to ${transitionConversationTo}.`;
151
150
  }
152
151
  const inquirerSelectPromptHandler = async (message) => {
153
- var _a;
154
152
  const answer = await inquirer_1.default.prompt({
155
153
  type: 'list',
156
154
  name: 'select',
157
155
  message: message.body,
158
- choices: (_a = message.choices) === null || _a === void 0 ? void 0 : _a.map((c) => ({
156
+ choices: message.choices?.map((c) => ({
159
157
  name: c.label,
160
158
  value: c.value,
161
159
  })),
@@ -2,7 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const messageTestUtility = {
4
4
  buildMessage(values) {
5
- return Object.assign({ id: '1234', dateCreated: new Date().getTime(), target: {}, source: {}, classification: 'incoming' }, values);
5
+ return {
6
+ id: '1234',
7
+ dateCreated: new Date().getTime(),
8
+ target: {},
9
+ source: {},
10
+ classification: 'incoming',
11
+ ...values,
12
+ };
6
13
  },
7
14
  };
8
15
  exports.default = messageTestUtility;
@@ -9,7 +9,6 @@ const MessageGraphicsInterface_1 = __importDefault(require("../interfaces/Messag
9
9
  const random_utility_1 = __importDefault(require("../utilities/random.utility"));
10
10
  class TopicScriptPlayer {
11
11
  constructor(options) {
12
- var _a;
13
12
  this.scriptState = {};
14
13
  this.scriptLineIndex = -1;
15
14
  const { script, target, sendMessageHandler, lineDelay, getContext } = (0, schema_1.assertOptions)(options, [
@@ -21,12 +20,13 @@ class TopicScriptPlayer {
21
20
  this.script = script;
22
21
  this.target = target;
23
22
  this.sendMessageHandler = sendMessageHandler;
24
- this.lineDelay = lineDelay !== null && lineDelay !== void 0 ? lineDelay : 2000;
23
+ this.lineDelay = lineDelay ?? 2000;
25
24
  this.getContext = getContext;
26
25
  this.graphicsInterface =
27
- (_a = options.graphicsInterface) !== null && _a !== void 0 ? _a : new MessageGraphicsInterface_1.default({
28
- sendMessageHandler: this.sendMessage.bind(this),
29
- });
26
+ options.graphicsInterface ??
27
+ new MessageGraphicsInterface_1.default({
28
+ sendMessageHandler: this.sendMessage.bind(this),
29
+ });
30
30
  }
31
31
  async handleMessage(message) {
32
32
  let results;
@@ -99,13 +99,12 @@ class TopicScriptPlayer {
99
99
  return this.waitForRunningLineToResolveOrMoveOn();
100
100
  }
101
101
  async waitForRunningLineToResolveOrMoveOn() {
102
- var _a;
103
102
  if (this.runningLine) {
104
103
  let done = false;
105
104
  do {
106
105
  await new Promise((resolve) => setTimeout(resolve, 10));
107
106
  done =
108
- ((_a = this.runningLine) === null || _a === void 0 ? void 0 : _a.isDone) ||
107
+ this.runningLine?.isDone ||
109
108
  this.graphicsInterface.isWaitingForInput();
110
109
  } while (!done);
111
110
  }
@@ -129,7 +128,11 @@ class TopicScriptPlayer {
129
128
  return random_utility_1.default.rand(line);
130
129
  }
131
130
  async sendMessage(message) {
132
- await this.sendMessageHandler(Object.assign(Object.assign({}, message), { target: this.target, classification: 'transactional' }));
131
+ await this.sendMessageHandler({
132
+ ...message,
133
+ target: this.target,
134
+ classification: 'transactional',
135
+ });
133
136
  }
134
137
  }
135
138
  exports.TopicScriptPlayer = TopicScriptPlayer;
@@ -22,11 +22,11 @@ const suggesterUtil = {
22
22
  return suggestions;
23
23
  },
24
24
  async doesMatch(phrases, utterance) {
25
- var _a;
26
25
  //@ts-ignore
27
26
  const f = new fuzzyset_1.default(phrases);
28
27
  const matches = f.get(utterance);
29
- return ((_a = (matches && matches.filter((m) => m[0] > 0.4).length > 0)) !== null && _a !== void 0 ? _a : false);
28
+ return ((matches && matches.filter((m) => m[0] > 0.4).length > 0) ??
29
+ false);
30
30
  },
31
31
  };
32
32
  exports.default = suggesterUtil;
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "@types/inquirer"
13
13
  ]
14
14
  },
15
- "version": "62.3.44",
15
+ "version": "62.3.45",
16
16
  "files": [
17
17
  "build/**/*",
18
18
  "!build/__tests__",
@@ -65,29 +65,29 @@
65
65
  },
66
66
  "dependencies": {
67
67
  "@nlpjs/nlu": "^4.27.0",
68
- "@sprucelabs/error": "^6.0.477",
69
- "@sprucelabs/globby": "^2.0.438",
70
- "@sprucelabs/mercury-core-events": "^24.3.289",
71
- "@sprucelabs/schema": "^30.0.486",
72
- "@sprucelabs/spruce-core-schemas": "^40.1.472",
73
- "@sprucelabs/spruce-event-plugin": "^62.3.44",
74
- "@sprucelabs/spruce-event-utils": "^40.1.248",
75
- "@sprucelabs/spruce-skill-booter": "^62.3.44",
76
- "@sprucelabs/spruce-skill-utils": "^31.0.545",
77
- "@sprucelabs/spruce-test-fixtures": "^62.3.44",
68
+ "@sprucelabs/error": "^6.0.479",
69
+ "@sprucelabs/globby": "^2.0.441",
70
+ "@sprucelabs/mercury-core-events": "^24.3.290",
71
+ "@sprucelabs/schema": "^30.0.488",
72
+ "@sprucelabs/spruce-core-schemas": "^40.1.473",
73
+ "@sprucelabs/spruce-event-plugin": "^62.3.45",
74
+ "@sprucelabs/spruce-event-utils": "^40.1.249",
75
+ "@sprucelabs/spruce-skill-booter": "^62.3.45",
76
+ "@sprucelabs/spruce-skill-utils": "^31.0.547",
77
+ "@sprucelabs/spruce-test-fixtures": "^62.3.45",
78
78
  "fuzzyset": "^1.0.7",
79
79
  "inquirer": "^8.2.4",
80
80
  "node-nlp": "^4.27.0",
81
81
  "random": "^5.1.1"
82
82
  },
83
83
  "devDependencies": {
84
- "@sprucelabs/esm-postbuild": "^6.0.461",
85
- "@sprucelabs/jest-json-reporter": "^8.0.477",
86
- "@sprucelabs/mercury-client": "^42.0.527",
87
- "@sprucelabs/resolve-path-aliases": "^2.0.456",
84
+ "@sprucelabs/esm-postbuild": "^6.0.462",
85
+ "@sprucelabs/jest-json-reporter": "^8.0.480",
86
+ "@sprucelabs/mercury-client": "^42.0.528",
87
+ "@sprucelabs/resolve-path-aliases": "^2.0.457",
88
88
  "@sprucelabs/semantic-release": "^5.0.2",
89
- "@sprucelabs/test": "^9.0.50",
90
- "@sprucelabs/test-utils": "^5.1.427",
89
+ "@sprucelabs/test": "^9.0.51",
90
+ "@sprucelabs/test-utils": "^5.1.432",
91
91
  "@types/fuzzyset": "^1.0.7",
92
92
  "@types/inquirer": "^8.2.1",
93
93
  "@types/node": "17.0.5",
@@ -119,5 +119,5 @@
119
119
  "^#spruce/(.*)$": "<rootDir>/build/.spruce/$1"
120
120
  }
121
121
  },
122
- "gitHead": "c7972277d178a6c6bac75519fff5814ae846ce30"
122
+ "gitHead": "59b913c0b16c2e83a7506abd5618082abfcd1f65"
123
123
  }
package/tsconfig.json CHANGED
@@ -3,10 +3,9 @@
3
3
  "skipLibCheck": true,
4
4
  "module": "commonjs",
5
5
  "esModuleInterop": true,
6
- "target": "ES2017",
6
+ "target": "ES2020",
7
7
  "lib": [
8
8
  "DOM",
9
- "es2017",
10
9
  "ES2020"
11
10
  ],
12
11
  "declaration": true,