@miso.ai/client-sdk-ui 1.10.3-beta.0 → 1.10.4-beta.0
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/dist/cjs/actor/autocomplete.js +4 -1
- package/dist/cjs/actor/data.js +15 -6
- package/dist/cjs/actor/fields.js +10 -10
- package/dist/cjs/actor/filters.js +114 -0
- package/dist/cjs/actor/hub.js +2 -1
- package/dist/cjs/actor/sessions.js +3 -5
- package/dist/cjs/actor/view.js +19 -6
- package/dist/cjs/actor/views.js +32 -19
- package/dist/cjs/constants.js +9 -2
- package/dist/cjs/defaults/ask/constants.js +3 -2
- package/dist/cjs/defaults/ask/templates.js +112 -219
- package/dist/cjs/defaults/common/templates.js +234 -0
- package/dist/cjs/defaults/hybrid-search/answer-box.js +115 -0
- package/dist/cjs/defaults/hybrid-search/constants.js +8 -0
- package/dist/cjs/defaults/hybrid-search/controls.js +17 -0
- package/dist/cjs/defaults/hybrid-search/index.js +31 -0
- package/dist/cjs/defaults/hybrid-search/phrases.js +27 -0
- package/dist/cjs/defaults/hybrid-search/templates.js +127 -0
- package/dist/cjs/defaults/index.js +4 -2
- package/dist/cjs/element/container/index.js +7 -0
- package/dist/cjs/element/container/miso-hybrid-search.js +21 -0
- package/dist/cjs/element/role/index.js +21 -0
- package/dist/cjs/element/role/miso-facets.js +20 -0
- package/dist/cjs/element/role/miso-hits.js +20 -0
- package/dist/cjs/element/role/miso-keywords.js +20 -0
- package/dist/cjs/layout/index.js +7 -0
- package/dist/cjs/layout/input/facets.js +294 -0
- package/dist/cjs/layout/input/option-list.js +4 -4
- package/dist/cjs/layout/input/search-box.js +6 -8
- package/dist/cjs/layout/list/collection.js +1 -2
- package/dist/cjs/layout/raf.js +1 -0
- package/dist/cjs/layout/template.js +3 -1
- package/dist/cjs/layout/templates.js +15 -0
- package/dist/cjs/layout/text/text.js +38 -5
- package/dist/cjs/layout/trackable.js +2 -16
- package/dist/cjs/plugin.js +4 -1
- package/dist/cjs/{source/index.js → source.js} +7 -4
- package/dist/cjs/util/bindings.js +3 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/workflow/answer-based.js +335 -0
- package/dist/cjs/workflow/ask.js +98 -271
- package/dist/cjs/workflow/base.js +69 -35
- package/dist/cjs/workflow/explore.js +10 -0
- package/dist/cjs/workflow/hybrid-search.js +140 -0
- package/dist/cjs/workflow/index.js +7 -0
- package/dist/cjs/workflow/processors.js +113 -0
- package/dist/cjs/workflow/recommendation.js +12 -3
- package/dist/cjs/workflow/search.js +34 -12
- package/package.json +2 -2
- package/src/actor/autocomplete.js +4 -2
- package/src/actor/data.js +8 -2
- package/src/actor/fields.js +10 -10
- package/src/actor/filters.js +103 -0
- package/src/actor/hub.js +2 -1
- package/src/actor/sessions.js +3 -4
- package/src/actor/view.js +19 -2
- package/src/actor/views.js +30 -16
- package/src/constants.js +10 -0
- package/src/defaults/ask/constants.js +1 -0
- package/src/defaults/ask/templates.js +70 -179
- package/src/defaults/common/templates.js +173 -0
- package/src/defaults/hybrid-search/answer-box.js +118 -0
- package/src/defaults/hybrid-search/constants.js +2 -0
- package/src/defaults/hybrid-search/controls.js +11 -0
- package/src/defaults/hybrid-search/index.js +9 -0
- package/src/defaults/hybrid-search/phrases.js +22 -0
- package/src/defaults/hybrid-search/templates.js +83 -0
- package/src/defaults/index.js +2 -0
- package/src/element/container/index.js +1 -0
- package/src/element/container/miso-hybrid-search.js +19 -0
- package/src/element/role/index.js +3 -0
- package/src/element/role/miso-facets.js +16 -0
- package/src/element/role/miso-hits.js +16 -0
- package/src/element/role/miso-keywords.js +16 -0
- package/src/layout/index.js +1 -0
- package/src/layout/input/facets.js +242 -0
- package/src/layout/input/option-list.js +3 -4
- package/src/layout/input/search-box.js +6 -7
- package/src/layout/list/collection.js +1 -2
- package/src/layout/raf.js +1 -0
- package/src/layout/template.js +2 -1
- package/src/layout/templates.js +15 -0
- package/src/layout/text/text.js +28 -3
- package/src/layout/trackable.js +2 -15
- package/src/plugin.js +6 -2
- package/src/{source/index.js → source.js} +7 -4
- package/src/util/bindings.js +4 -0
- package/src/version.js +1 -1
- package/src/workflow/answer-based.js +280 -0
- package/src/workflow/ask.js +82 -204
- package/src/workflow/base.js +64 -27
- package/src/workflow/explore.js +10 -1
- package/src/workflow/hybrid-search.js +125 -0
- package/src/workflow/index.js +1 -0
- package/src/workflow/processors.js +95 -0
- package/src/workflow/recommendation.js +9 -2
- package/src/workflow/search.js +35 -7
- package/dist/cjs/source/api.js +0 -23
- package/src/source/api.js +0 -12
package/dist/cjs/workflow/ask.js
CHANGED
|
@@ -5,112 +5,94 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _commons = require("@miso.ai/commons");
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var sources = _interopRequireWildcard(require("../source/index.js"));
|
|
11
|
-
var _index2 = require("../actor/index.js");
|
|
8
|
+
var _answerBased = _interopRequireDefault(require("./answer-based.js"));
|
|
9
|
+
var _index = require("../actor/index.js");
|
|
12
10
|
var _constants = require("../constants.js");
|
|
13
|
-
var
|
|
14
|
-
var _index4 = require("../affiliation/index.js");
|
|
11
|
+
var _index2 = require("../layout/index.js");
|
|
15
12
|
const _excluded = ["q", "qs"];
|
|
16
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
17
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
18
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
function _objectDestructuringEmpty(t) { if (null == t) throw new TypeError("Cannot destructure " + t); }
|
|
19
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; }
|
|
20
|
-
const DEFAULT_API_OPTIONS = Object.freeze({
|
|
21
|
-
group: _commons.API.GROUP.ASK,
|
|
16
|
+
const DEFAULT_API_OPTIONS = Object.freeze(Object.assign({}, _answerBased.default.DEFAULT_API_OPTIONS, {
|
|
22
17
|
name: _commons.API.NAME.QUESTIONS,
|
|
23
|
-
payload: {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
const DEFAULT_AUTOCOMPLETE_OPTIONS = Object.freeze({
|
|
32
|
-
actor: false,
|
|
33
|
-
api: {
|
|
34
|
-
group: _commons.API.GROUP.ASK,
|
|
35
|
-
name: _commons.API.NAME.AUTOCOMPLETE
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
const DEFAULT_LAYOUTS = Object.freeze({
|
|
39
|
-
[_constants.ROLE.QUERY]: [_index3.SearchBoxLayout.type, {
|
|
40
|
-
placeholder: 'Ask a question'
|
|
41
|
-
}],
|
|
42
|
-
[_constants.ROLE.QUESTION]: [_index3.TextLayout.type, {
|
|
43
|
-
tag: 'h2'
|
|
44
|
-
}],
|
|
45
|
-
[_constants.ROLE.ANSWER]: _index3.TypewriterLayout.type,
|
|
46
|
-
[_constants.ROLE.FEEDBACK]: _index3.FeedbackLayout.type,
|
|
47
|
-
[_constants.ROLE.SOURCES]: [_index3.ListLayout.type, {
|
|
48
|
-
incremental: true,
|
|
49
|
-
itemType: 'article',
|
|
50
|
-
templates: {
|
|
51
|
-
ordered: true
|
|
52
|
-
}
|
|
53
|
-
}],
|
|
54
|
-
[_constants.ROLE.RELATED_RESOURCES]: [_index3.ListLayout.type, {
|
|
18
|
+
payload: Object.assign({}, _answerBased.default.DEFAULT_API_OPTIONS.payload, {
|
|
19
|
+
related_resource_fl: ['cover_image', 'url', 'created_at', 'updated_at', 'published_at']
|
|
20
|
+
})
|
|
21
|
+
}));
|
|
22
|
+
const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _answerBased.default.DEFAULT_LAYOUTS, {
|
|
23
|
+
[_constants.ROLE.RELATED_RESOURCES]: [_index2.ListLayout.type, {
|
|
55
24
|
incremental: true,
|
|
56
25
|
itemType: 'article'
|
|
57
26
|
}],
|
|
58
|
-
[_constants.ROLE.QUERY_SUGGESTIONS]:
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
itemType: 'affiliation',
|
|
62
|
-
link: {
|
|
63
|
-
rel: 'noopener nofollow'
|
|
64
|
-
}
|
|
65
|
-
}]
|
|
66
|
-
});
|
|
67
|
-
const DEFAULT_TRACKERS = Object.freeze({
|
|
68
|
-
[_constants.ROLE.SOURCES]: {},
|
|
27
|
+
[_constants.ROLE.QUERY_SUGGESTIONS]: _index2.OptionListLayout.type
|
|
28
|
+
}));
|
|
29
|
+
const DEFAULT_TRACKERS = Object.freeze(Object.assign({}, _answerBased.default.DEFAULT_TRACKERS, {
|
|
69
30
|
[_constants.ROLE.RELATED_RESOURCES]: {},
|
|
70
|
-
[_constants.ROLE.AFFILIATION]: {},
|
|
71
31
|
[_constants.ROLE.QUERY_SUGGESTIONS]: {
|
|
72
32
|
click: {
|
|
73
33
|
validate: event => event.button === 0 // left click only
|
|
74
34
|
}
|
|
75
35
|
}
|
|
76
|
-
});
|
|
77
|
-
const DEFAULT_OPTIONS = Object.freeze({
|
|
36
|
+
}));
|
|
37
|
+
const DEFAULT_OPTIONS = Object.freeze(Object.assign({}, _answerBased.default.DEFAULT_OPTIONS, {
|
|
78
38
|
api: DEFAULT_API_OPTIONS,
|
|
79
|
-
autocomplete: DEFAULT_AUTOCOMPLETE_OPTIONS,
|
|
80
39
|
layouts: DEFAULT_LAYOUTS,
|
|
81
40
|
trackers: DEFAULT_TRACKERS
|
|
82
|
-
});
|
|
83
|
-
class Ask extends
|
|
41
|
+
}));
|
|
42
|
+
class Ask extends _answerBased.default {
|
|
84
43
|
constructor(context, parentQuestionId) {
|
|
85
44
|
super({
|
|
86
45
|
name: 'ask',
|
|
87
46
|
context,
|
|
88
47
|
roles: Object.keys(DEFAULT_LAYOUTS),
|
|
89
|
-
defaults: DEFAULT_OPTIONS
|
|
48
|
+
defaults: DEFAULT_OPTIONS,
|
|
49
|
+
parentQuestionId
|
|
90
50
|
});
|
|
91
|
-
|
|
92
|
-
|
|
51
|
+
}
|
|
52
|
+
_initProperties(args) {
|
|
53
|
+
super._initProperties(args);
|
|
54
|
+
const {
|
|
55
|
+
parentQuestionId
|
|
56
|
+
} = args;
|
|
93
57
|
(0, _commons.defineValues)(this, {
|
|
94
58
|
parentQuestionId
|
|
95
59
|
});
|
|
96
|
-
|
|
60
|
+
}
|
|
61
|
+
_initSubscriptions(args) {
|
|
97
62
|
this._setSuggestedQuestions();
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
63
|
+
super._initSubscriptions(args);
|
|
64
|
+
}
|
|
65
|
+
_setSuggestedQuestions() {
|
|
66
|
+
const {
|
|
67
|
+
previous
|
|
68
|
+
} = this;
|
|
69
|
+
if (!previous) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const values = previous.states[_index.fields.data()].value;
|
|
73
|
+
const value = values.suggested_followup_questions || values.followup_questions || [];
|
|
74
|
+
this._hub.update(_index.fields.suggestions(), {
|
|
75
|
+
value: value.map(text => ({
|
|
76
|
+
text
|
|
77
|
+
}))
|
|
103
78
|
});
|
|
104
|
-
*/
|
|
105
|
-
|
|
106
|
-
this._unsubscribes = [...this._unsubscribes, this._hub.on(_index2.fields.query(), payload => this.query(payload)), this._hub.on(_index2.fields.view(_constants.ROLE.ANSWER), data => this._onAnswerViewUpdate(data)), this._views.get(_constants.ROLE.ANSWER).on('citation-click', event => this._onCitationClick(event))];
|
|
107
|
-
parentQuestionId && context._byPqid.set(parentQuestionId, this);
|
|
108
|
-
context._events.emit('create', this);
|
|
109
|
-
this.reset(); // create a session so query suggestions can be tracked
|
|
110
79
|
}
|
|
111
|
-
|
|
112
|
-
|
|
80
|
+
_initReset(args) {
|
|
81
|
+
// register at context
|
|
82
|
+
args.parentQuestionId && this._context._byPqid.set(args.parentQuestionId, this);
|
|
83
|
+
this._context._events.emit('create', this);
|
|
84
|
+
super._initReset(args);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// lifecycle //
|
|
88
|
+
restart() {
|
|
89
|
+
if (this._questionId) {
|
|
90
|
+
this._context._byQid.delete(this._questionId);
|
|
91
|
+
}
|
|
92
|
+
super.restart();
|
|
113
93
|
}
|
|
94
|
+
|
|
95
|
+
// properties //
|
|
114
96
|
get rootQuestionId() {
|
|
115
97
|
return this._context.root.questionId;
|
|
116
98
|
}
|
|
@@ -135,227 +117,73 @@ class Ask extends _base.default {
|
|
|
135
117
|
}) : undefined;
|
|
136
118
|
}
|
|
137
119
|
|
|
138
|
-
//
|
|
139
|
-
|
|
140
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
141
|
-
const {
|
|
142
|
-
setValue = true,
|
|
143
|
-
focus = true
|
|
144
|
-
} = this._autoQuery = options;
|
|
145
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
146
|
-
const q = searchParams.get('q');
|
|
147
|
-
const qs = searchParams.get('qs');
|
|
148
|
-
const {
|
|
149
|
-
layout
|
|
150
|
-
} = this._views.get(_constants.ROLE.QUERY);
|
|
151
|
-
if (layout) {
|
|
152
|
-
if (q && setValue) {
|
|
153
|
-
layout.value = q;
|
|
154
|
-
}
|
|
155
|
-
if (!q && focus) {
|
|
156
|
-
layout.focus();
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (q) {
|
|
160
|
-
this.query({
|
|
161
|
-
q,
|
|
162
|
-
qs
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
query() {
|
|
120
|
+
// query //
|
|
121
|
+
_buildPayload() {
|
|
167
122
|
let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
168
123
|
let {
|
|
169
|
-
q
|
|
170
|
-
qs
|
|
124
|
+
q,
|
|
125
|
+
qs
|
|
171
126
|
} = _ref,
|
|
172
127
|
payload = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
173
|
-
payload = Object.assign({}, payload, {
|
|
174
|
-
question
|
|
175
|
-
});
|
|
176
|
-
questionSource = questionSource || _constants.ORGANIC_QUESTION_SOURCE;
|
|
177
|
-
if (this.parentQuestionId) {
|
|
178
|
-
payload.parent_question_id = this.parentQuestionId;
|
|
179
|
-
}
|
|
180
|
-
(payload._meta || (payload._meta = {})).question_source = questionSource;
|
|
181
|
-
|
|
182
|
-
// clear question id from previous session
|
|
183
|
-
if (this._questionId) {
|
|
184
|
-
this._context._byQid.delete(this._questionId);
|
|
185
|
-
this._questionId = undefined;
|
|
186
|
-
}
|
|
187
|
-
this.restart();
|
|
188
128
|
const {
|
|
189
|
-
|
|
129
|
+
parentQuestionId
|
|
190
130
|
} = this;
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
131
|
+
return (0, _commons.trimObj)(Object.assign({}, payload, {
|
|
132
|
+
question: q,
|
|
133
|
+
// question, not q
|
|
134
|
+
parent_question_id: parentQuestionId,
|
|
135
|
+
_meta: Object.assign({}, payload._meta, {
|
|
136
|
+
question_source: qs || _constants.ORGANIC_QUESTION_SOURCE // might be null, not undefined
|
|
137
|
+
})
|
|
195
138
|
}));
|
|
196
|
-
return this;
|
|
197
|
-
}
|
|
198
|
-
restart() {
|
|
199
|
-
// TODO: move to workflow base
|
|
200
|
-
const {
|
|
201
|
-
session,
|
|
202
|
-
status,
|
|
203
|
-
ongoing
|
|
204
|
-
} = this._hub.states[_index2.fields.view(_constants.ROLE.ANSWER)] || {};
|
|
205
|
-
if (session && status !== _constants.STATUS.INITIAL && (status !== _constants.STATUS.READY || ongoing)) {
|
|
206
|
-
// it's interrupted by a new question
|
|
207
|
-
const state = Object.freeze({
|
|
208
|
-
session,
|
|
209
|
-
status,
|
|
210
|
-
ongoing
|
|
211
|
-
});
|
|
212
|
-
this._emit('interrupt', state);
|
|
213
|
-
this._emit('finally', state);
|
|
214
|
-
}
|
|
215
|
-
super.restart();
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/*
|
|
219
|
-
updateCompletions(event) {
|
|
220
|
-
// TODO: verify
|
|
221
|
-
this._hub.update(fields.completions(), {
|
|
222
|
-
...event,
|
|
223
|
-
source: 'manual',
|
|
224
|
-
});
|
|
225
|
-
return this;
|
|
226
139
|
}
|
|
227
|
-
*/
|
|
228
|
-
|
|
229
|
-
_defaultProcessData(data) {
|
|
230
|
-
data = super._defaultProcessData(data);
|
|
231
|
-
const {
|
|
232
|
-
value,
|
|
233
|
-
request
|
|
234
|
-
} = data;
|
|
235
|
-
if (!value) {
|
|
236
|
-
return data;
|
|
237
|
-
}
|
|
238
|
-
const {
|
|
239
|
-
question_id: questionId,
|
|
240
|
-
question
|
|
241
|
-
} = value;
|
|
242
|
-
const organic = request && request.payload && request.payload._meta && request.payload._meta.question_source === _constants.ORGANIC_QUESTION_SOURCE;
|
|
243
|
-
|
|
244
|
-
// capture question ID and register at context
|
|
245
|
-
if (!this._questionId && questionId) {
|
|
246
|
-
this._questionId = questionId;
|
|
247
|
-
this._context._byQid.set(questionId, this);
|
|
248
|
-
}
|
|
249
140
|
|
|
250
|
-
|
|
251
|
-
if (this._autoQuery && this._autoQuery.updateUrl !== false) {
|
|
252
|
-
const url = new URL(window.location);
|
|
253
|
-
const currentQuestion = url.searchParams.get('q');
|
|
254
|
-
// TODO: review this, handle &s=
|
|
255
|
-
if (question !== currentQuestion && (!organic || this._autoQuery.updateUrl === true)) {
|
|
256
|
-
url.searchParams.set('q', question);
|
|
257
|
-
window.history.replaceState({}, '', url);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
// affiliation
|
|
262
|
-
data = (0, _index4.processData)(data);
|
|
263
|
-
|
|
264
|
-
// 1. put answer_stage to meta
|
|
265
|
-
// 2. mark ongoing flag
|
|
266
|
-
return Object.assign({}, data, {
|
|
267
|
-
ongoing: !value.finished,
|
|
268
|
-
meta: Object.assign({}, data.meta, {
|
|
269
|
-
answer_stage: value.answer_stage
|
|
270
|
-
})
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
_onAnswerViewUpdate(_ref2) {
|
|
274
|
-
let {
|
|
275
|
-
session,
|
|
276
|
-
status,
|
|
277
|
-
ongoing
|
|
278
|
-
} = _ref2;
|
|
279
|
-
if (status === _constants.STATUS.INITIAL) {
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
const done = status === _constants.STATUS.READY && !ongoing;
|
|
283
|
-
const erroneous = status === _constants.STATUS.ERRONEOUS;
|
|
284
|
-
const eventName = done ? 'done' : erroneous ? 'error' : status;
|
|
285
|
-
const state = Object.freeze({
|
|
286
|
-
session,
|
|
287
|
-
status,
|
|
288
|
-
ongoing
|
|
289
|
-
});
|
|
290
|
-
this._emit(eventName, state);
|
|
291
|
-
if (done || erroneous) {
|
|
292
|
-
this._emit('finally', state);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
_setSuggestedQuestions() {
|
|
296
|
-
const {
|
|
297
|
-
previous
|
|
298
|
-
} = this;
|
|
299
|
-
if (!previous) {
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
const values = previous.states[_index2.fields.data()].value;
|
|
303
|
-
const value = values.suggested_followup_questions || values.followup_questions || [];
|
|
304
|
-
this._hub.update(_index2.fields.suggestions(), {
|
|
305
|
-
value: value.map(text => ({
|
|
306
|
-
text
|
|
307
|
-
}))
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
_onCitationClick(_ref3) {
|
|
311
|
-
let {
|
|
312
|
-
index
|
|
313
|
-
} = _ref3;
|
|
314
|
-
const {
|
|
315
|
-
value
|
|
316
|
-
} = this.states[_index2.fields.data()] || {};
|
|
317
|
-
const {
|
|
318
|
-
sources
|
|
319
|
-
} = value || {};
|
|
320
|
-
// index is 1-based
|
|
321
|
-
const source = sources && sources[index - 1];
|
|
322
|
-
if (!source || !source.product_id) {
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
// TODO: should we track impression as well?
|
|
326
|
-
this._trackers.sources.click([source.product_id], {
|
|
327
|
-
manual: false
|
|
328
|
-
});
|
|
329
|
-
}
|
|
141
|
+
// interactions //
|
|
330
142
|
_preprocessInteraction(payload) {
|
|
331
143
|
payload = super._preprocessInteraction(payload) || {};
|
|
332
144
|
const {
|
|
333
145
|
context = {}
|
|
334
146
|
} = payload;
|
|
335
|
-
const {
|
|
336
|
-
custom_context = {}
|
|
337
|
-
} = context;
|
|
147
|
+
const _ref2 = context.custom_context || {},
|
|
148
|
+
custom_context = Object.assign({}, (_objectDestructuringEmpty(_ref2), _ref2));
|
|
338
149
|
let {
|
|
339
150
|
rootQuestionId,
|
|
340
151
|
parentQuestionId,
|
|
341
152
|
questionId
|
|
342
153
|
} = this;
|
|
343
|
-
// when we track suggested questions, we are actually tracking the suggested_followup_questions of the previous workflow
|
|
344
154
|
if (custom_context.property === _constants.ROLE.QUERY_SUGGESTIONS) {
|
|
345
155
|
questionId = parentQuestionId;
|
|
346
156
|
parentQuestionId = this.previous && this.previous.parentQuestionId;
|
|
347
157
|
custom_context.property = 'suggested_followup_questions';
|
|
348
158
|
custom_context.question_source = this.previous && this.previous.session.meta.question_source;
|
|
349
159
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
160
|
+
custom_context.question_id = questionId;
|
|
161
|
+
custom_context.root_question_id = rootQuestionId;
|
|
162
|
+
custom_context.parent_question_id = parentQuestionId;
|
|
163
|
+
return Object.assign({}, payload, {
|
|
164
|
+
context: Object.assign({}, context, {
|
|
165
|
+
custom_context: (0, _commons.trimObj)(custom_context)
|
|
166
|
+
})
|
|
356
167
|
});
|
|
357
|
-
return payload;
|
|
358
168
|
}
|
|
169
|
+
|
|
170
|
+
// helpers //
|
|
171
|
+
_writeQuestionId(questionId) {
|
|
172
|
+
// capture question ID and register at context
|
|
173
|
+
if (!this._questionId && questionId) {
|
|
174
|
+
this._questionId = questionId;
|
|
175
|
+
this._context._byQid.set(questionId, this);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
_clearQuestionId() {
|
|
179
|
+
// clear question id from previous session
|
|
180
|
+
if (this._questionId) {
|
|
181
|
+
this._context._byQid.delete(this._questionId);
|
|
182
|
+
this._questionId = undefined;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// destroy //
|
|
359
187
|
_destroy(options) {
|
|
360
188
|
const {
|
|
361
189
|
parentQuestionId,
|
|
@@ -367,7 +195,6 @@ class Ask extends _base.default {
|
|
|
367
195
|
if (questionId) {
|
|
368
196
|
this._context._byQid.delete(questionId);
|
|
369
197
|
}
|
|
370
|
-
this._feedback._destroy();
|
|
371
198
|
super._destroy(options);
|
|
372
199
|
}
|
|
373
200
|
}
|
|
@@ -6,11 +6,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _commons = require("@miso.ai/commons");
|
|
8
8
|
var _index = require("../actor/index.js");
|
|
9
|
-
var sources = _interopRequireWildcard(require("../source
|
|
9
|
+
var sources = _interopRequireWildcard(require("../source.js"));
|
|
10
10
|
var _constants = require("../constants.js");
|
|
11
|
-
var
|
|
11
|
+
var _index2 = require("../layout/index.js");
|
|
12
12
|
var _utils = require("./utils.js");
|
|
13
13
|
var _options = require("./options.js");
|
|
14
|
+
var _processors = require("./processors.js");
|
|
14
15
|
const _excluded = ["layouts", "interactions"],
|
|
15
16
|
_excluded2 = ["custom_context"],
|
|
16
17
|
_excluded3 = ["context"];
|
|
@@ -18,8 +19,13 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
|
|
|
18
19
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
19
20
|
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; }
|
|
20
21
|
const DEFAULT_LAYOUTS = Object.freeze({
|
|
21
|
-
[_constants.ROLE.CONTAINER]:
|
|
22
|
-
[_constants.ROLE.ERROR]:
|
|
22
|
+
[_constants.ROLE.CONTAINER]: _index2.ContainerLayout.type,
|
|
23
|
+
[_constants.ROLE.ERROR]: _index2.ErrorLayout.type
|
|
24
|
+
});
|
|
25
|
+
const ROLES_CONFIG = Object.freeze({
|
|
26
|
+
[_constants.ROLE.ERROR]: {
|
|
27
|
+
mapping: data => data.error
|
|
28
|
+
}
|
|
23
29
|
});
|
|
24
30
|
function mergeDefaults(workflow) {
|
|
25
31
|
let _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
@@ -40,29 +46,44 @@ function getRevision(data) {
|
|
|
40
46
|
return data && data.value && data.value.revision;
|
|
41
47
|
}
|
|
42
48
|
class Workflow extends _commons.Component {
|
|
43
|
-
constructor(
|
|
49
|
+
constructor(args) {
|
|
44
50
|
var _this;
|
|
51
|
+
super(args.name || 'workflow', args.plugin);
|
|
52
|
+
_this = this;
|
|
45
53
|
let {
|
|
46
|
-
name,
|
|
47
54
|
context,
|
|
48
55
|
plugin,
|
|
49
|
-
client
|
|
50
|
-
|
|
51
|
-
defaults
|
|
52
|
-
} = _ref2;
|
|
53
|
-
super(name || 'workflow', plugin);
|
|
54
|
-
_this = this;
|
|
56
|
+
client
|
|
57
|
+
} = args;
|
|
55
58
|
this._context = context;
|
|
56
59
|
this._plugin = plugin = plugin || context._plugin;
|
|
57
60
|
this._client = client = client || context._client;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
args = Object.freeze(Object.assign({}, args, {
|
|
62
|
+
plugin,
|
|
63
|
+
client
|
|
64
|
+
}));
|
|
65
|
+
this._name = args.name;
|
|
66
|
+
this._roles = args.roles;
|
|
67
|
+
this._rolesConfig = Object.assign({}, ROLES_CONFIG, args.rolesConfig);
|
|
68
|
+
this._extensions = plugin._getExtensions(client);
|
|
69
|
+
this._options = new _options.WorkflowOptions(context && context._options, mergeDefaults(this, args.defaults));
|
|
70
|
+
this._hub = (0, _utils.injectLogger)(new _index.Hub(), function () {
|
|
63
71
|
return _this._log(...arguments);
|
|
64
72
|
});
|
|
65
|
-
|
|
73
|
+
this._initProperties(args);
|
|
74
|
+
this._initActors(args);
|
|
75
|
+
this._initSubscriptions(args);
|
|
76
|
+
this._initReset(args);
|
|
77
|
+
}
|
|
78
|
+
_initProperties() {}
|
|
79
|
+
_initActors() {
|
|
80
|
+
const hub = this._hub;
|
|
81
|
+
const client = this._client;
|
|
82
|
+
const roles = this._roles;
|
|
83
|
+
const rolesConfig = this._rolesConfig;
|
|
84
|
+
const options = this._options;
|
|
85
|
+
const extensions = this._extensions;
|
|
86
|
+
const layouts = this._plugin.layouts;
|
|
66
87
|
this._sessions = new _index.SessionMaker(hub);
|
|
67
88
|
this._data = new _index.DataActor(hub, {
|
|
68
89
|
source: sources.api(client),
|
|
@@ -72,15 +93,21 @@ class Workflow extends _commons.Component {
|
|
|
72
93
|
extensions,
|
|
73
94
|
layouts,
|
|
74
95
|
roles,
|
|
96
|
+
rolesConfig,
|
|
75
97
|
options,
|
|
76
|
-
workflow:
|
|
98
|
+
workflow: this._name
|
|
77
99
|
});
|
|
78
100
|
this._interactions = new _index.InteractionsActor(hub, {
|
|
79
101
|
client,
|
|
80
102
|
options
|
|
81
103
|
});
|
|
104
|
+
}
|
|
105
|
+
_initSubscriptions() {
|
|
82
106
|
this._unsubscribes = [this._hub.on(_index.fields.response(), data => this.updateData(data))];
|
|
83
107
|
}
|
|
108
|
+
_initReset() {
|
|
109
|
+
this.reset();
|
|
110
|
+
}
|
|
84
111
|
get uuid() {
|
|
85
112
|
return this.session && this.session.uuid;
|
|
86
113
|
}
|
|
@@ -96,6 +123,10 @@ class Workflow extends _commons.Component {
|
|
|
96
123
|
get states() {
|
|
97
124
|
return this._hub.states;
|
|
98
125
|
}
|
|
126
|
+
get status() {
|
|
127
|
+
const data = this._hub.states[_index.fields.data()];
|
|
128
|
+
return data && data.status;
|
|
129
|
+
}
|
|
99
130
|
get views() {
|
|
100
131
|
return this._views.interface;
|
|
101
132
|
}
|
|
@@ -110,13 +141,15 @@ class Workflow extends _commons.Component {
|
|
|
110
141
|
return this;
|
|
111
142
|
}
|
|
112
143
|
restart() {
|
|
113
|
-
this.
|
|
114
|
-
this.start();
|
|
144
|
+
this._sessions.restart();
|
|
115
145
|
return this;
|
|
116
146
|
}
|
|
117
147
|
|
|
118
148
|
// states //
|
|
119
149
|
updateData(data) {
|
|
150
|
+
let {
|
|
151
|
+
instructions
|
|
152
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
120
153
|
if (!data) {
|
|
121
154
|
throw new Error(`Data is required.`);
|
|
122
155
|
}
|
|
@@ -143,27 +176,28 @@ class Workflow extends _commons.Component {
|
|
|
143
176
|
}
|
|
144
177
|
this._sessions.start(); // in case session not started yet
|
|
145
178
|
|
|
179
|
+
data = (0, _processors.writeDataStatus)(data);
|
|
146
180
|
data = this._defaultProcessData(data);
|
|
147
181
|
for (const process of this._options.resolved.dataProcessor) {
|
|
148
182
|
data = process(data);
|
|
149
183
|
}
|
|
184
|
+
|
|
185
|
+
// write data instructions from function args
|
|
186
|
+
data = (0, _processors.addDataInstructions)(data, instructions);
|
|
187
|
+
data = this._mergeDataIfNecessary(data);
|
|
150
188
|
this._hub.update(_index.fields.data(), data);
|
|
151
189
|
return this;
|
|
152
190
|
}
|
|
153
191
|
_defaultProcessData(data) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (!value || !value.miso_id) {
|
|
192
|
+
return (0, _processors.writeMisoIdToMeta)(data);
|
|
193
|
+
}
|
|
194
|
+
_mergeDataIfNecessary(data) {
|
|
195
|
+
if (!data._inst || !data._inst.merge) {
|
|
159
196
|
return data;
|
|
160
197
|
}
|
|
161
|
-
return Object.assign({}, data,
|
|
162
|
-
meta: Object.assign({}, data.meta, {
|
|
163
|
-
miso_id: value.miso_id
|
|
164
|
-
})
|
|
165
|
-
});
|
|
198
|
+
return Object.assign({}, this._hub.states[_index.fields.data()], data);
|
|
166
199
|
}
|
|
200
|
+
_handleResponseObject() {}
|
|
167
201
|
|
|
168
202
|
// TODO: notifyViewUpdateAll()
|
|
169
203
|
|
|
@@ -182,14 +216,14 @@ class Workflow extends _commons.Component {
|
|
|
182
216
|
return this._views.trackers;
|
|
183
217
|
}
|
|
184
218
|
_preprocessInteraction() {
|
|
185
|
-
let
|
|
219
|
+
let _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
186
220
|
let {
|
|
187
221
|
context: {
|
|
188
222
|
custom_context
|
|
189
223
|
} = {}
|
|
190
|
-
} =
|
|
191
|
-
context = _objectWithoutPropertiesLoose(
|
|
192
|
-
payload = _objectWithoutPropertiesLoose(
|
|
224
|
+
} = _ref2,
|
|
225
|
+
context = _objectWithoutPropertiesLoose(_ref2.context, _excluded2),
|
|
226
|
+
payload = _objectWithoutPropertiesLoose(_ref2, _excluded3);
|
|
193
227
|
const {
|
|
194
228
|
group: api_group,
|
|
195
229
|
name: api_name
|
|
@@ -49,10 +49,18 @@ class Explore extends _base.default {
|
|
|
49
49
|
roles: Object.keys(DEFAULT_LAYOUTS),
|
|
50
50
|
defaults: DEFAULT_OPTIONS
|
|
51
51
|
});
|
|
52
|
+
}
|
|
53
|
+
_initProperties(args) {
|
|
54
|
+
super._initProperties(args);
|
|
52
55
|
this._productId = undefined;
|
|
53
56
|
this._linkFn = undefined;
|
|
57
|
+
}
|
|
58
|
+
_initSubscriptions(args) {
|
|
59
|
+
super._initSubscriptions(args);
|
|
54
60
|
this._unsubscribes = [...this._unsubscribes, this._views.get(_constants.ROLE.RELATED_QUESTIONS).on('click', event => this._handleRelatedQuestionClick(event)), this._hub.on(_index.fields.query(), payload => this.query(payload))];
|
|
55
61
|
}
|
|
62
|
+
|
|
63
|
+
// configuration //
|
|
56
64
|
set productId(value) {
|
|
57
65
|
console.warning('DEPRECATED: use useApi() instead');
|
|
58
66
|
this.useApi({
|
|
@@ -95,8 +103,10 @@ class Explore extends _base.default {
|
|
|
95
103
|
session
|
|
96
104
|
}));
|
|
97
105
|
} else {
|
|
106
|
+
// TODO: ad-hoc
|
|
98
107
|
this.updateData({
|
|
99
108
|
session,
|
|
109
|
+
request: {},
|
|
100
110
|
value: {
|
|
101
111
|
related_questions: []
|
|
102
112
|
}
|