@miso.ai/client-sdk-ui 1.11.0-beta.2 → 1.11.0-beta.4

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.
@@ -58,13 +58,12 @@ class DataActor {
58
58
  session
59
59
  } = this._hub.states;
60
60
  const request = _objectWithoutPropertiesLoose(event, _excluded);
61
- if (!event._skipLoading) {
62
- // emit response to update request
63
- this._emitResponse({
64
- session,
65
- request
66
- });
67
- }
61
+
62
+ // emit response to update request
63
+ this._emitResponse({
64
+ session,
65
+ request
66
+ });
68
67
  try {
69
68
  const {
70
69
  signal
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _commons = require("@miso.ai/commons");
8
- var _processors = require("../workflow/processors.js");
9
8
  class Hub {
10
9
  constructor() {
11
10
  (this._events = new _commons.EventEmitter())._injectSubscribeInterface(this);
@@ -20,7 +19,7 @@ class Hub {
20
19
  let {
21
20
  silent = false
22
21
  } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
23
- this._states[name] = Object.freeze((0, _processors.removeDataInstructions)(state));
22
+ this._states[name] = Object.freeze(state);
24
23
  if (!silent) {
25
24
  this._events.emit(name, state);
26
25
  }
@@ -15,16 +15,15 @@ class SessionMaker {
15
15
  (0, _commons.delegateGetters)(hub, this, ['active']);
16
16
  }
17
17
  get active() {
18
- const {
19
- session
20
- } = this._hub.states;
18
+ // TODO: may eliminate active flag?
19
+ const session = this._hub.states[fields.session()];
21
20
  return !!(session && session.active);
22
21
  }
23
22
  new() {
24
23
  let {
25
24
  force = false
26
25
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
27
- const currentSession = this._hub.states.session;
26
+ const currentSession = this._hub.states[fields.session()];
28
27
  if (currentSession && !currentSession.active && !force) {
29
28
  return;
30
29
  }
@@ -32,7 +31,7 @@ class SessionMaker {
32
31
  this._hub.update(fields.session(), session);
33
32
  }
34
33
  start() {
35
- const session = this._hub.states.session || this._create();
34
+ const session = this._hub.states[fields.session()] || this._create();
36
35
  if (session.active) {
37
36
  return;
38
37
  }
@@ -95,6 +95,9 @@ class ViewsActor {
95
95
  updateComponentRole(element, oldRole, newRole) {
96
96
  // TODO
97
97
  }
98
+ containsElement(element) {
99
+ return this._containers.has(element) || this._views[element.role];
100
+ }
98
101
  refreshElement(element) {
99
102
  const view = element.isContainer ? this._containers.get(element) : this._getViewByElement(element);
100
103
  view && view.refresh({
@@ -38,7 +38,7 @@ class AnswerBox {
38
38
  // sync state
39
39
  this._syncWofkflowStatus();
40
40
  this._syncButtonText();
41
- this._unsubscribes = [() => element.removeEventListener('click', callback), workflow.on('loading', () => this.hide()), workflow.on('error', () => this.show()), workflow.on('ready', () => this.show())];
41
+ this._unsubscribes = [() => element.removeEventListener('click', callback), workflow._answer.on('loading', () => this.hide()), workflow._answer.on('error', () => this.show()), workflow._answer.on('ready', () => this.show())];
42
42
  }
43
43
  _handleClick(_ref) {
44
44
  let {
@@ -56,7 +56,7 @@ class AnswerBox {
56
56
  _syncWofkflowStatus() {
57
57
  const {
58
58
  status
59
- } = this._workflow;
59
+ } = this._workflow._answer;
60
60
  switch (status) {
61
61
  case _constants2.STATUS.ERRONEOUS:
62
62
  case _constants2.STATUS.READY:
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = exports.default = '1.11.0-beta.2';
7
+ var _default = exports.default = '1.11.0-beta.4';
@@ -159,13 +159,14 @@ class AnswerBasedWorkflow extends _base.default {
159
159
  // start a new session
160
160
  this.restart();
161
161
 
162
- // keep track of question source on this session
162
+ // TODO: move to ask workflow
163
+ // keep track of question source on this session, for suggested questions interactions
164
+ this._writeQuestionSourceToSession(args);
165
+
166
+ // build payload and trigger request
163
167
  const {
164
168
  session
165
169
  } = this;
166
- session.meta.question_source = args.questionSource || _constants.ORGANIC_QUESTION_SOURCE; // might be null, not undefined
167
-
168
- // build payload and trigger request
169
170
  const payload = this._buildPayload(args);
170
171
  const event = (0, _options.mergeApiOptions)(this._options.resolved.api, {
171
172
  payload,
@@ -173,6 +174,9 @@ class AnswerBasedWorkflow extends _base.default {
173
174
  });
174
175
  this._request(event);
175
176
  }
177
+ _writeQuestionSourceToSession(args) {
178
+ this.session.meta.question_source = args.questionSource || _constants.ORGANIC_QUESTION_SOURCE; // might be null, not undefined
179
+ }
176
180
  _request(event) {
177
181
  this._hub.update(_index.fields.request(), event);
178
182
  }
@@ -193,11 +197,20 @@ class AnswerBasedWorkflow extends _base.default {
193
197
  */
194
198
 
195
199
  // data //
196
- _defaultProcessData(data) {
197
- data = super._defaultProcessData(data);
198
-
200
+ _updateData(data) {
201
+ // if it's the head response, write question id and return
202
+ if (data.value && !data.value.answer_stage) {
203
+ this._handleHeadResponse(data);
204
+ return;
205
+ }
206
+ super._updateData(data);
207
+ }
208
+ _handleHeadResponse(data) {
199
209
  // capture question ID and register at context
200
210
  this._writeQuestionIdFromData(data);
211
+ }
212
+ _defaultProcessData(data) {
213
+ data = super._defaultProcessData(data);
201
214
 
202
215
  // update URL if autoQuery.updateUrl is not false
203
216
  this._updateUrlIfNecessary(data);
@@ -69,6 +69,7 @@ class Ask extends _answerBased.default {
69
69
  if (!previous) {
70
70
  return;
71
71
  }
72
+ // TODO: write question_source from payload._meta, so we don't need to write it to session.meta
72
73
  const values = previous.states[_index.fields.data()].value;
73
74
  const value = values.suggested_followup_questions || values.followup_questions || [];
74
75
  this._hub.update(_index.fields.suggestions(), {
@@ -53,7 +53,8 @@ class Workflow extends _commons.Component {
53
53
  let {
54
54
  context,
55
55
  plugin,
56
- client
56
+ client,
57
+ options
57
58
  } = args;
58
59
  this._context = context;
59
60
  this._plugin = plugin = plugin || context._plugin;
@@ -66,7 +67,7 @@ class Workflow extends _commons.Component {
66
67
  this._roles = args.roles;
67
68
  this._rolesConfig = Object.assign({}, ROLES_CONFIG, args.rolesConfig);
68
69
  this._extensions = plugin._getExtensions(client);
69
- this._options = new _options.WorkflowOptions(context && context._options, mergeDefaults(this, args.defaults));
70
+ this._options = options || new _options.WorkflowOptions(context && context._options, mergeDefaults(this, args.defaults));
70
71
  this._hub = (0, _utils.injectLogger)(new _index.Hub(), function () {
71
72
  return _this._log(...arguments);
72
73
  });
@@ -112,7 +113,7 @@ class Workflow extends _commons.Component {
112
113
  return this.session && this.session.uuid;
113
114
  }
114
115
  get session() {
115
- return this._hub.states.session;
116
+ return this._hub.states[_index.fields.session()];
116
117
  }
117
118
  get active() {
118
119
  const {
@@ -147,9 +148,6 @@ class Workflow extends _commons.Component {
147
148
 
148
149
  // states //
149
150
  updateData(data) {
150
- let {
151
- instructions
152
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
153
151
  if (!data) {
154
152
  throw new Error(`Data is required.`);
155
153
  }
@@ -174,6 +172,10 @@ class Workflow extends _commons.Component {
174
172
  return;
175
173
  }
176
174
  }
175
+ this._updateData(data);
176
+ return this;
177
+ }
178
+ _updateData(data) {
177
179
  this._sessions.start(); // in case session not started yet
178
180
 
179
181
  data = (0, _processors.writeDataStatus)(data);
@@ -181,23 +183,24 @@ class Workflow extends _commons.Component {
181
183
  for (const process of this._options.resolved.dataProcessor) {
182
184
  data = process(data);
183
185
  }
184
-
185
- // write data instructions from function args
186
- data = (0, _processors.addDataInstructions)(data, instructions);
187
- data = this._mergeDataIfNecessary(data);
188
186
  this._hub.update(_index.fields.data(), data);
189
- return this;
190
187
  }
191
188
  _defaultProcessData(data) {
192
189
  return (0, _processors.writeMisoIdToMeta)(data);
193
190
  }
191
+
192
+ /*
194
193
  _mergeDataIfNecessary(data) {
195
194
  if (!data._inst || !data._inst.merge) {
196
195
  return data;
197
196
  }
198
- return Object.assign({}, this._hub.states[_index.fields.data()], data);
197
+ return {
198
+ ...this._hub.states[fields.data()],
199
+ ...data,
200
+ };
199
201
  }
200
- _handleResponseObject() {}
202
+ _handleResponseObject() {}
203
+ */
201
204
 
202
205
  // TODO: notifyViewUpdateAll()
203
206
 
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _answerBased = _interopRequireDefault(require("./answer-based.js"));
8
+ var _constants = require("../constants.js");
9
+ var _processors = require("./processors.js");
10
+ const _excluded = ["q", "qs"];
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
13
+ const ROLES_CONFIG = Object.freeze({
14
+ [_constants.ROLE.QUESTION]: {
15
+ mapping: _constants.ROLE.KEYWORDS
16
+ }
17
+ });
18
+ class HybridSearchAnswer extends _answerBased.default {
19
+ constructor(superworkflow) {
20
+ super({
21
+ name: 'hybrid-search/answer',
22
+ plugin: superworkflow._plugin,
23
+ client: superworkflow._client,
24
+ options: superworkflow._options,
25
+ roles: Object.keys(_answerBased.default.DEFAULT_LAYOUTS),
26
+ rolesConfig: ROLES_CONFIG,
27
+ superworkflow
28
+ });
29
+ this.useInteractions(false);
30
+ }
31
+ _initProperties(args) {
32
+ super._initProperties(args);
33
+ this._superworkflow = args.superworkflow;
34
+ }
35
+ _initReset() {} // no reset here, will manually reset later
36
+
37
+ restart() {
38
+ super.restart();
39
+ // cascade restart to the sibling
40
+ const results = this._superworkflow._results;
41
+ results.restart();
42
+ this._resultsSession = results.session; // keep track of the session
43
+ }
44
+
45
+ // query //
46
+ _buildPayload() {
47
+ let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
48
+ let {
49
+ q,
50
+ qs
51
+ } = _ref,
52
+ payload = _objectWithoutPropertiesLoose(_ref, _excluded);
53
+ return Object.assign({}, payload, {
54
+ q,
55
+ // q, not question
56
+ _meta: Object.assign({}, payload._meta, {
57
+ question_source: qs || _constants.ORGANIC_QUESTION_SOURCE // might be null, not undefined
58
+ })
59
+ });
60
+ }
61
+
62
+ // data //
63
+ _updateData(data) {
64
+ // we want this to be available everywhere
65
+ data = (0, _processors.writeKeywordsToData)(data);
66
+ switch (data.status) {
67
+ case _constants.STATUS.INITIAL:
68
+ case _constants.STATUS.LOADING:
69
+ // share the initial/loading status with its sibling
70
+ this._dispatchDataToSibling(data);
71
+ break;
72
+ }
73
+ super._updateData(data);
74
+ }
75
+ _handleHeadResponse(data) {
76
+ super._handleHeadResponse(data);
77
+ // share the search results with its sibling
78
+ this._dispatchDataToSibling(data);
79
+ }
80
+ _dispatchDataToSibling(data) {
81
+ this._superworkflow._results.updateData(Object.assign({}, data, {
82
+ session: this._resultsSession
83
+ }));
84
+ }
85
+ }
86
+ exports.default = HybridSearchAnswer;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _commons = require("@miso.ai/commons");
8
+ var _base = _interopRequireDefault(require("./base.js"));
9
+ var _index = require("../actor/index.js");
10
+ var _constants = require("../constants.js");
11
+ var _options = require("./options.js");
12
+ var _processors = require("./processors.js");
13
+ const _excluded = ["filters"];
14
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
16
+ const ROLES_CONFIG = Object.freeze({
17
+ [_constants.ROLE.FACETS]: {
18
+ mapping: 'facet_counts'
19
+ }
20
+ });
21
+ class HybridSearchResults extends _base.default {
22
+ constructor(superworkflow) {
23
+ super({
24
+ name: 'hybrid-search/results',
25
+ plugin: superworkflow._plugin,
26
+ client: superworkflow._client,
27
+ options: superworkflow._options,
28
+ roles: [_constants.ROLE.PRODUCTS, _constants.ROLE.KEYWORDS, _constants.ROLE.HITS, _constants.ROLE.FACETS],
29
+ rolesConfig: ROLES_CONFIG,
30
+ superworkflow
31
+ });
32
+ this.useInteractions(false);
33
+ }
34
+ _initProperties(args) {
35
+ super._initProperties(args);
36
+ this._superworkflow = args.superworkflow;
37
+ }
38
+ _initSubscriptions(args) {
39
+ super._initSubscriptions(args);
40
+ this._unsubscribes = [...this._unsubscribes, this._hub.on(_index.fields.filters(), filters => this._refine(filters))];
41
+ }
42
+ _initReset() {} // no reset here, will manually reset later
43
+
44
+ // query //
45
+ _refine(filters) {
46
+ // start a new session
47
+ this.restart();
48
+
49
+ // get stored query from sibling
50
+ const query = this._superworkflow._answer._hub.states[_index.fields.query()];
51
+ const payload = this._buildPayload(Object.assign({}, query, {
52
+ filters,
53
+ answer: false
54
+ }));
55
+ const {
56
+ session
57
+ } = this;
58
+ const event = (0, _options.mergeApiOptions)(this._options.resolved.api, {
59
+ payload,
60
+ session
61
+ });
62
+ this._request(event);
63
+ }
64
+ _buildPayload() {
65
+ let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
66
+ let {
67
+ filters
68
+ } = _ref,
69
+ payload = _objectWithoutPropertiesLoose(_ref, _excluded);
70
+ // borrow the work from the sibling
71
+ payload = this._superworkflow._answer._buildPayload(payload);
72
+ const fq = (0, _processors.composeFq)(filters); // TODO: combine with fq in payload?
73
+ return (0, _commons.trimObj)(Object.assign({}, payload, {
74
+ fq
75
+ }));
76
+ }
77
+ _request(event) {
78
+ this._hub.update(_index.fields.request(), event);
79
+ }
80
+
81
+ // data //
82
+ _defaultProcessData(data) {
83
+ data = super._defaultProcessData(data);
84
+ data = (0, _processors.writeKeywordsToData)(data);
85
+ return data;
86
+ }
87
+ }
88
+ exports.default = HybridSearchResults;