@miso.ai/client-sdk-ui 1.12.3 → 1.12.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.
- package/dist/cjs/actor/data.js +15 -11
- package/dist/cjs/defaults/ask/controls.js +3 -6
- package/dist/cjs/defaults/ask/templates.js +1 -0
- package/dist/cjs/defaults/common/templates.js +4 -2
- package/dist/cjs/element/container/miso-ask.js +48 -6
- package/dist/cjs/element/container/miso-container.js +2 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/workflow/answer-based.js +2 -88
- package/dist/cjs/workflow/ask.js +13 -9
- package/dist/cjs/workflow/asks.js +36 -1
- package/dist/cjs/workflow/base.js +14 -9
- package/dist/cjs/workflow/hybrid-search-answer.js +40 -68
- package/dist/cjs/workflow/hybrid-search-views.js +12 -11
- package/dist/cjs/workflow/hybrid-search.js +99 -46
- package/dist/cjs/workflow/options/auto-query.js +31 -0
- package/dist/cjs/workflow/processors.js +107 -0
- package/dist/cjs/workflow/search-based.js +16 -30
- package/package.json +2 -2
- package/src/actor/data.js +10 -7
- package/src/defaults/ask/controls.js +3 -6
- package/src/defaults/ask/templates.js +1 -1
- package/src/defaults/common/templates.js +2 -2
- package/src/element/container/miso-ask.js +53 -5
- package/src/element/container/miso-container.js +3 -0
- package/src/version.js +1 -1
- package/src/workflow/answer-based.js +4 -83
- package/src/workflow/ask.js +11 -10
- package/src/workflow/asks.js +39 -2
- package/src/workflow/base.js +13 -9
- package/src/workflow/hybrid-search-answer.js +25 -62
- package/src/workflow/hybrid-search-views.js +14 -12
- package/src/workflow/hybrid-search.js +93 -47
- package/src/workflow/options/auto-query.js +36 -2
- package/src/workflow/processors.js +86 -2
- package/src/workflow/search-based.js +14 -27
- package/dist/cjs/workflow/hybrid-search-results.js +0 -87
- package/src/workflow/hybrid-search-results.js +0 -91
|
@@ -2,9 +2,11 @@ import MisoContainerElement from './miso-container.js';
|
|
|
2
2
|
|
|
3
3
|
const TAG_NAME = 'miso-ask';
|
|
4
4
|
|
|
5
|
+
const ATTR_WORKFLOW = 'workflow';
|
|
5
6
|
const ATTR_PARENT_QUESTION_ID = 'parent-question-id';
|
|
6
7
|
const OBSERVED_ATTRIBUTES = Object.freeze([
|
|
7
8
|
...MisoContainerElement.observedAttributes,
|
|
9
|
+
ATTR_WORKFLOW,
|
|
8
10
|
ATTR_PARENT_QUESTION_ID,
|
|
9
11
|
]);
|
|
10
12
|
|
|
@@ -19,6 +21,9 @@ export default class MisoAskElement extends MisoContainerElement {
|
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
_getWorkflow(client) {
|
|
24
|
+
if (this.boundToActiveWorkflow) {
|
|
25
|
+
return client.ui.asks.active;
|
|
26
|
+
}
|
|
22
27
|
return this._getWorkflowByParentQuestionId(client, this.parentQuestionId);
|
|
23
28
|
}
|
|
24
29
|
|
|
@@ -43,26 +48,69 @@ export default class MisoAskElement extends MisoContainerElement {
|
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
|
|
46
|
-
get
|
|
47
|
-
return this.
|
|
51
|
+
get boundToActiveWorkflow() {
|
|
52
|
+
return this.getAttribute(ATTR_WORKFLOW) === 'active';
|
|
48
53
|
}
|
|
49
54
|
|
|
50
|
-
|
|
51
|
-
this.
|
|
52
|
-
|
|
55
|
+
_setWorkflow(workflow) {
|
|
56
|
+
if (this._workflow === workflow) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
super._setWorkflow(workflow);
|
|
60
|
+
if (workflow) {
|
|
61
|
+
this.parentQuestionId = workflow.parentQuestionId;
|
|
62
|
+
}
|
|
53
63
|
}
|
|
54
64
|
|
|
55
65
|
// lifecycle //
|
|
66
|
+
async connectedCallback() {
|
|
67
|
+
await super.connectedCallback();
|
|
68
|
+
if (document.body.contains(this)) { // in case already disconnected
|
|
69
|
+
const context = this._client.ui.asks;
|
|
70
|
+
this._unsubscribes = [
|
|
71
|
+
...(this._unsubscribes || []),
|
|
72
|
+
context.on('active', (event) => {
|
|
73
|
+
if (!this.boundToActiveWorkflow) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
this.workflow = event.workflow;
|
|
77
|
+
}),
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
disconnectedCallback() {
|
|
83
|
+
for (const unsubscribe of (this._unsubscribes || [])) {
|
|
84
|
+
unsubscribe();
|
|
85
|
+
}
|
|
86
|
+
this._unsubscribes = [];
|
|
87
|
+
super.disconnectedCallback();
|
|
88
|
+
}
|
|
89
|
+
|
|
56
90
|
attributeChangedCallback(attr, oldValue, newValue) {
|
|
57
91
|
switch (attr) {
|
|
58
92
|
case ATTR_PARENT_QUESTION_ID:
|
|
59
93
|
this._handleParentQuestionIdUpdate(oldValue, newValue);
|
|
60
94
|
break;
|
|
95
|
+
case ATTR_WORKFLOW:
|
|
96
|
+
this._handleQuestionUpdate(oldValue, newValue);
|
|
97
|
+
break;
|
|
61
98
|
default:
|
|
62
99
|
super.attributeChangedCallback(attr, oldValue, newValue);
|
|
63
100
|
}
|
|
64
101
|
}
|
|
65
102
|
|
|
103
|
+
_handleQuestionUpdate(oldValue, newValue) {
|
|
104
|
+
oldValue = oldValue || undefined; // null -> undefined
|
|
105
|
+
newValue = newValue || undefined;
|
|
106
|
+
if (oldValue === newValue || !this._client) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (newValue === ATTR_VALUE_ACTIVE) {
|
|
110
|
+
this._setWorkflow(this._getWorkflow(this._client));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
66
114
|
_handleParentQuestionIdUpdate(oldId, newId) {
|
|
67
115
|
oldId = oldId || undefined; // null -> undefined
|
|
68
116
|
newId = newId || undefined;
|
|
@@ -82,6 +82,7 @@ export default class MisoContainerElement extends MisoStubElement {
|
|
|
82
82
|
const client = this._client = await getClient(MisoContainerElement);
|
|
83
83
|
if (document.body.contains(this)) { // in case already disconnected
|
|
84
84
|
this._setWorkflow(this._getWorkflow(client));
|
|
85
|
+
this._onConnected(client);
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
|
|
@@ -90,6 +91,8 @@ export default class MisoContainerElement extends MisoStubElement {
|
|
|
90
91
|
super.disconnectedCallback();
|
|
91
92
|
}
|
|
92
93
|
|
|
94
|
+
_onConnected(client) {}
|
|
95
|
+
|
|
93
96
|
_getWorkflow(client) {
|
|
94
97
|
throw new Error('Unimplemented');
|
|
95
98
|
}
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.12.
|
|
1
|
+
export default '1.12.4';
|
|
@@ -4,8 +4,8 @@ import { fields, FeedbackActor } from '../actor/index.js';
|
|
|
4
4
|
import { ROLE, STATUS, QUESTION_SOURCE } from '../constants.js';
|
|
5
5
|
import { SearchBoxLayout, TextLayout, ListLayout, GalleryLayout, TypewriterLayout, FeedbackLayout, AffiliationLayout } from '../layout/index.js';
|
|
6
6
|
import { processData as processAffiliationData } from '../affiliation/index.js';
|
|
7
|
-
import { mergeRolesOptions, autoQuery as autoQueryFn, DEFAULT_AUTO_QUERY_PARAM, DEFAULT_TRACKER_OPTIONS } from './options/index.js';
|
|
8
|
-
import { mappingAnswerData, mappingReasoningData, writeAnswerStageToMeta,
|
|
7
|
+
import { mergeRolesOptions, autoQuery as autoQueryFn, updateQueryParametersInUrl, DEFAULT_AUTO_QUERY_PARAM, DEFAULT_TRACKER_OPTIONS } from './options/index.js';
|
|
8
|
+
import { mappingAnswerData, mappingReasoningData, writeAnswerStageToMeta, writeAnswerInfoToInteraction } from './processors.js';
|
|
9
9
|
import { enableUseLink } from './use-link.js';
|
|
10
10
|
import { isTracked, markAsTracked } from '../util/trackers.js';
|
|
11
11
|
|
|
@@ -204,7 +204,7 @@ export default class AnswerBasedWorkflow extends Workflow {
|
|
|
204
204
|
super._updateData(data);
|
|
205
205
|
|
|
206
206
|
// update URL if autoQuery.updateUrl is not false
|
|
207
|
-
|
|
207
|
+
updateQueryParametersInUrl.call(this, data);
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
_handleHeadResponse(data) {}
|
|
@@ -220,92 +220,13 @@ export default class AnswerBasedWorkflow extends Workflow {
|
|
|
220
220
|
value && this._writeQuestionId(value.question_id);
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
-
_updateUrlIfNecessary({ value, request }) {
|
|
224
|
-
if (!this._autoQuery || !this._autoQuery.updateUrl) {
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
const { param, sourceParam } = this._autoQuery;
|
|
228
|
-
const question = (value && value.question) || (request && request.payload && request.payload.question);
|
|
229
|
-
const questionSource = request && request.payload && request.payload.metadata && request.payload.metadata.question_source;
|
|
230
|
-
|
|
231
|
-
if (!question) {
|
|
232
|
-
return; // at initial phase
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
const url = new URL(window.location);
|
|
236
|
-
const currentQuestion = url.searchParams.get(param);
|
|
237
|
-
const currentQuestionSource = url.searchParams.get(sourceParam) || QUESTION_SOURCE.ORGANIC;
|
|
238
|
-
if (question === currentQuestion && questionSource === currentQuestionSource) {
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
url.searchParams.set(param, question);
|
|
242
|
-
if (questionSource === QUESTION_SOURCE.ORGANIC) {
|
|
243
|
-
url.searchParams.delete(sourceParam);
|
|
244
|
-
} else {
|
|
245
|
-
url.searchParams.set(sourceParam, questionSource);
|
|
246
|
-
}
|
|
247
|
-
window.history.replaceState({}, '', url);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
223
|
// interactions //
|
|
251
224
|
_defaultProcessInteraction(payload, args) {
|
|
252
225
|
payload = super._defaultProcessInteraction(payload, args);
|
|
253
|
-
payload =
|
|
254
|
-
payload = this._writeAnswerClickInteraction(payload, args);
|
|
255
|
-
payload = writeEventTargetToInteraction(payload, args);
|
|
226
|
+
payload = writeAnswerInfoToInteraction(payload, args);
|
|
256
227
|
return payload;
|
|
257
228
|
}
|
|
258
229
|
|
|
259
|
-
_writeRequestInfoToInteraction(payload, args) {
|
|
260
|
-
const { data } = args;
|
|
261
|
-
if (!data) {
|
|
262
|
-
return payload;
|
|
263
|
-
}
|
|
264
|
-
const requestPayload = data.request && data.request.payload;
|
|
265
|
-
if (!requestPayload) {
|
|
266
|
-
return payload;
|
|
267
|
-
}
|
|
268
|
-
const { question, fq } = requestPayload;
|
|
269
|
-
return mergeInteractions(payload, {
|
|
270
|
-
context: {
|
|
271
|
-
custom_context: {
|
|
272
|
-
question,
|
|
273
|
-
fq,
|
|
274
|
-
},
|
|
275
|
-
},
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
_writeAskPropertiesToInteraction(payload = {}, args) {
|
|
280
|
-
const question_source = this._getQuestionSourceFromViewState(args);
|
|
281
|
-
const question_id = this.questionId;
|
|
282
|
-
return mergeInteractions(payload, {
|
|
283
|
-
context: {
|
|
284
|
-
custom_context: {
|
|
285
|
-
question_source,
|
|
286
|
-
question_id,
|
|
287
|
-
},
|
|
288
|
-
},
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
_writeAnswerClickInteraction(payload, args) {
|
|
293
|
-
if (args.role !== ROLE.ANSWER) {
|
|
294
|
-
return payload;
|
|
295
|
-
}
|
|
296
|
-
const { items = [] } = args;
|
|
297
|
-
return mergeInteractions(payload, {
|
|
298
|
-
context: {
|
|
299
|
-
custom_context: {
|
|
300
|
-
urls: items.map(item => item.url),
|
|
301
|
-
texts: items.map(item => item.text),
|
|
302
|
-
class_names: items.map(item => item.className),
|
|
303
|
-
attributes: items.map(item => item.attributes),
|
|
304
|
-
},
|
|
305
|
-
},
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
|
|
309
230
|
_getQuestionSourceFromViewState(args) {
|
|
310
231
|
const { request } = this._hub.states[fields.view(args.role)] || {};
|
|
311
232
|
const { payload } = request || {};
|
package/src/workflow/ask.js
CHANGED
|
@@ -4,7 +4,7 @@ import { fields } from '../actor/index.js';
|
|
|
4
4
|
import { ROLE, STATUS, QUESTION_SOURCE } from '../constants.js';
|
|
5
5
|
import { OptionListLayout, ListLayout, SearchBoxLayout, TypewriterLayout } from '../layout/index.js';
|
|
6
6
|
import { mergeRolesOptions, DEFAULT_TRACKER_OPTIONS } from './options/index.js';
|
|
7
|
-
import { mappingSuggestionsData, mappingFollowUpQuestionsData } from './processors.js';
|
|
7
|
+
import { writeQuestionSourceToPayload, mappingSuggestionsData, mappingFollowUpQuestionsData } from './processors.js';
|
|
8
8
|
import { followUp as followUpTemplate } from '../defaults/ask/templates.js';
|
|
9
9
|
|
|
10
10
|
const DEFAULT_API_OPTIONS = Object.freeze({
|
|
@@ -137,11 +137,8 @@ export default class Ask extends AnswerBasedWorkflow {
|
|
|
137
137
|
...options,
|
|
138
138
|
question: q, // question, not q
|
|
139
139
|
parent_question_id: parentQuestionId,
|
|
140
|
-
metadata: {
|
|
141
|
-
...options.metadata,
|
|
142
|
-
question_source: qs || QUESTION_SOURCE.ORGANIC, // might be null, not undefined
|
|
143
|
-
},
|
|
144
140
|
});
|
|
141
|
+
payload = writeQuestionSourceToPayload({ ...payload, qs });
|
|
145
142
|
payload = this._writeWikiLinkTemplateToPayload(payload);
|
|
146
143
|
return payload;
|
|
147
144
|
}
|
|
@@ -171,7 +168,13 @@ export default class Ask extends AnswerBasedWorkflow {
|
|
|
171
168
|
}
|
|
172
169
|
|
|
173
170
|
// interactions //
|
|
174
|
-
|
|
171
|
+
_defaultProcessInteraction(payload, args) {
|
|
172
|
+
payload = super._defaultProcessInteraction(payload, args);
|
|
173
|
+
payload = this._writeAdditionalAskPropertiesToInteraction(payload, args);
|
|
174
|
+
return payload;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
_writeAdditionalAskPropertiesToInteraction(payload, args) {
|
|
175
178
|
const root_question_id = this.rootQuestionId;
|
|
176
179
|
let { property } = (payload.context && payload.context.custom_context) || {};
|
|
177
180
|
let question_id, parent_question_id, question_source;
|
|
@@ -186,19 +189,17 @@ export default class Ask extends AnswerBasedWorkflow {
|
|
|
186
189
|
question_source = this.previous && this.previous.session.meta.question_source;
|
|
187
190
|
} else {
|
|
188
191
|
parent_question_id = this.parentQuestionId;
|
|
189
|
-
question_id = this.questionId;
|
|
190
|
-
question_source = this._getQuestionSourceFromViewState(args);
|
|
191
192
|
}
|
|
192
193
|
|
|
193
194
|
return mergeInteractions(payload, {
|
|
194
195
|
context: {
|
|
195
|
-
custom_context: {
|
|
196
|
+
custom_context: trimObj({ // question_id, question_source can be undefined
|
|
196
197
|
property,
|
|
197
198
|
root_question_id,
|
|
198
199
|
parent_question_id,
|
|
199
200
|
question_id,
|
|
200
201
|
question_source,
|
|
201
|
-
},
|
|
202
|
+
}),
|
|
202
203
|
}
|
|
203
204
|
});
|
|
204
205
|
}
|
package/src/workflow/asks.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WORKFLOW_CONFIGURABLE } from '../constants.js';
|
|
1
|
+
import { WORKFLOW_CONFIGURABLE, STATUS } from '../constants.js';
|
|
2
2
|
import WorkflowContext from './context.js';
|
|
3
3
|
import Ask from './ask.js';
|
|
4
4
|
import { makeConfigurable } from './options/index.js';
|
|
@@ -15,7 +15,7 @@ function autoNextOptionsAsPredicate(options = DEFAULT_AUTO_NEXT_OPTIONS) {
|
|
|
15
15
|
switch (typeof options) {
|
|
16
16
|
case 'object':
|
|
17
17
|
// TODO: support more options
|
|
18
|
-
return event => options.event === event._event;
|
|
18
|
+
return event => event && options.event === event._event;
|
|
19
19
|
case 'function':
|
|
20
20
|
return options;
|
|
21
21
|
default:
|
|
@@ -31,7 +31,11 @@ export default class Asks extends WorkflowContext {
|
|
|
31
31
|
this._byPqid = new Map();
|
|
32
32
|
this._root = new Ask(this); // initialize with default workflow
|
|
33
33
|
this._events.on('*', event => this._createNextIfNecessary(event));
|
|
34
|
+
this._events.on('loading', event => this._setActive(event.workflow));
|
|
35
|
+
this._events.on('destroy', () => this._requestEmitAfterDestroy());
|
|
36
|
+
this._events.on('after-destroy', () => this._syncActiveOnAfterDestroy());
|
|
34
37
|
this._autoNextFn = undefined;
|
|
38
|
+
this._active = this._root;
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
get root() {
|
|
@@ -42,6 +46,10 @@ export default class Asks extends WorkflowContext {
|
|
|
42
46
|
return [this._root, ...this._byPqid.values()];
|
|
43
47
|
}
|
|
44
48
|
|
|
49
|
+
get active() {
|
|
50
|
+
return this._active;
|
|
51
|
+
}
|
|
52
|
+
|
|
45
53
|
getByQuestionId(questionId) {
|
|
46
54
|
if (typeof questionId !== 'string') {
|
|
47
55
|
throw new Error(`Required ID to be a string: ${questionId}`);
|
|
@@ -95,6 +103,35 @@ export default class Asks extends WorkflowContext {
|
|
|
95
103
|
workflow && workflow.getOrCreateNext();
|
|
96
104
|
}
|
|
97
105
|
|
|
106
|
+
_requestEmitAfterDestroy() {
|
|
107
|
+
if (this._emitAfterDestroyRequested) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
this._emitAfterDestroyRequested = true;
|
|
111
|
+
setTimeout(() => {
|
|
112
|
+
this._emitAfterDestroyRequested = false;
|
|
113
|
+
this._events.emit('after-destroy', {});
|
|
114
|
+
}, 0);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
_syncActiveOnAfterDestroy() {
|
|
118
|
+
if (!this._active.destroyed) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
// find last non-initial workflow or root
|
|
122
|
+
let workflow = this._root;
|
|
123
|
+
for (; workflow.next && workflow.next.status !== STATUS.INITIAL; workflow = workflow.next) {}
|
|
124
|
+
this._setActive(workflow);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
_setActive(workflow) {
|
|
128
|
+
if (workflow === this._active) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
this._active = workflow;
|
|
132
|
+
this._events.emit('active', { workflow });
|
|
133
|
+
}
|
|
134
|
+
|
|
98
135
|
}
|
|
99
136
|
|
|
100
137
|
makeConfigurable(Asks.prototype, [WORKFLOW_CONFIGURABLE.TEMPLATES]);
|
package/src/workflow/base.js
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
writeDataStatus,
|
|
11
11
|
writeMisoIdToMeta,
|
|
12
12
|
buildBaseInteraction,
|
|
13
|
+
writeRequestInfoToInteraction,
|
|
13
14
|
writeRequestMetadataToInteraction,
|
|
14
15
|
writeAffiliationInfoToInteraction,
|
|
15
16
|
} from './processors.js';
|
|
@@ -40,7 +41,7 @@ export default class Workflow extends Component {
|
|
|
40
41
|
constructor(args) {
|
|
41
42
|
super(args.name || 'workflow', args.plugin);
|
|
42
43
|
|
|
43
|
-
let { context, plugin, client, defaults, options } = args;
|
|
44
|
+
let { context, plugin, client, defaults, options, extraOptions } = args;
|
|
44
45
|
this._context = context;
|
|
45
46
|
this._plugin = plugin = plugin || context._plugin;
|
|
46
47
|
this._client = client = client || context._client;
|
|
@@ -52,6 +53,7 @@ export default class Workflow extends Component {
|
|
|
52
53
|
this._extensions = plugin._getExtensions(client);
|
|
53
54
|
this._defaults = defaults;
|
|
54
55
|
this._options = options || new WorkflowOptions(context && context._options, defaults);
|
|
56
|
+
this._extraOptions = extraOptions || {};
|
|
55
57
|
this._hub = new Hub({
|
|
56
58
|
onUpdate: event => this._onHubUpdate(event),
|
|
57
59
|
onEmit: event => this._onHubEmit(event),
|
|
@@ -76,7 +78,7 @@ export default class Workflow extends Component {
|
|
|
76
78
|
const layouts = this._plugin.layouts;
|
|
77
79
|
|
|
78
80
|
this._sessions = new SessionMaker(hub);
|
|
79
|
-
this._data = new DataActor(hub, { source: sources.api(client), options });
|
|
81
|
+
this._data = new DataActor(hub, { source: sources.api(client), options, ...this._extraOptions.api });
|
|
80
82
|
this._views = new ViewsActor(hub, { extensions, layouts, roles, options, workflow: this });
|
|
81
83
|
//this._trackers = new TrackersActor(hub, { options });
|
|
82
84
|
this._interactions = new InteractionsActor(hub, { client, options });
|
|
@@ -274,8 +276,9 @@ export default class Workflow extends Component {
|
|
|
274
276
|
}
|
|
275
277
|
|
|
276
278
|
_onTracker(args) {
|
|
279
|
+
const workflow = this;
|
|
277
280
|
const data = this._hub.states[fields.data()];
|
|
278
|
-
const payload = this._buildInteraction({ ...args, data });
|
|
281
|
+
const payload = this._buildInteraction({ ...args, data, workflow });
|
|
279
282
|
this._sendInteraction(payload);
|
|
280
283
|
}
|
|
281
284
|
|
|
@@ -290,10 +293,10 @@ export default class Workflow extends Component {
|
|
|
290
293
|
}
|
|
291
294
|
|
|
292
295
|
_defaultProcessInteraction(payload, args) {
|
|
293
|
-
payload = writeRequestMetadataToInteraction(payload, args);
|
|
294
296
|
payload = this._writeApiInfoToInteraction(payload, args);
|
|
295
|
-
payload = this._writeRequestInfoToInteraction(payload, args);
|
|
296
297
|
payload = this._writeMisoIdToInteraction(payload, args);
|
|
298
|
+
payload = writeRequestInfoToInteraction(payload, args);
|
|
299
|
+
payload = writeRequestMetadataToInteraction(payload, args);
|
|
297
300
|
payload = writeAffiliationInfoToInteraction(payload, args);
|
|
298
301
|
return payload;
|
|
299
302
|
}
|
|
@@ -310,10 +313,6 @@ export default class Workflow extends Component {
|
|
|
310
313
|
});
|
|
311
314
|
}
|
|
312
315
|
|
|
313
|
-
_writeRequestInfoToInteraction(payload, args) {
|
|
314
|
-
return payload;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
316
|
_writeMisoIdToInteraction(payload, args) {
|
|
318
317
|
// TODO: ad-hoc, try to pass info from tracker
|
|
319
318
|
const state = this._hub.states[fields.view(args.role)] || {};
|
|
@@ -336,6 +335,10 @@ export default class Workflow extends Component {
|
|
|
336
335
|
this._destroy(options);
|
|
337
336
|
}
|
|
338
337
|
|
|
338
|
+
get destroyed() {
|
|
339
|
+
return !!this._destroyed;
|
|
340
|
+
}
|
|
341
|
+
|
|
339
342
|
_destroy({ dom } = {}) {
|
|
340
343
|
for (const unsubscribe of this._unsubscribes || []) {
|
|
341
344
|
unsubscribe();
|
|
@@ -344,6 +347,7 @@ export default class Workflow extends Component {
|
|
|
344
347
|
|
|
345
348
|
this._views._destroy({ dom });
|
|
346
349
|
this._data._destroy();
|
|
350
|
+
this._destroyed = true;
|
|
347
351
|
}
|
|
348
352
|
|
|
349
353
|
// helper //
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import { mergeApiPayloads } from '@miso.ai/commons';
|
|
2
1
|
import AnswerBasedWorkflow from './answer-based.js';
|
|
3
|
-
import {
|
|
4
|
-
import { mergeRolesOptions } from './options/index.js';
|
|
2
|
+
import { fields } from '../actor/index.js';
|
|
5
3
|
import { writeKeywordsToData, writeMisoIdToSession, writeMisoIdFromSession, writeUnanswerableToMeta } from './processors.js';
|
|
6
|
-
import { makeAutocompletable } from './autocompletable.js';
|
|
7
4
|
|
|
8
|
-
const ROLES_OPTIONS =
|
|
9
|
-
mappings: {
|
|
10
|
-
[ROLE.QUESTION]: ROLE.KEYWORDS,
|
|
11
|
-
},
|
|
12
|
-
});
|
|
5
|
+
const ROLES_OPTIONS = AnswerBasedWorkflow.ROLES_OPTIONS;
|
|
13
6
|
|
|
14
7
|
export default class HybridSearchAnswer extends AnswerBasedWorkflow {
|
|
15
8
|
|
|
@@ -27,35 +20,34 @@ export default class HybridSearchAnswer extends AnswerBasedWorkflow {
|
|
|
27
20
|
|
|
28
21
|
_initProperties(args) {
|
|
29
22
|
super._initProperties(args);
|
|
30
|
-
this._initAutocomplete(args);
|
|
31
23
|
this._superworkflow = args.superworkflow;
|
|
32
24
|
}
|
|
33
25
|
|
|
34
26
|
_initSession() {} // no reset here, will manually reset later
|
|
35
27
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const results = this._superworkflow._results;
|
|
40
|
-
results._views.filters.reset({ silent: true });
|
|
41
|
-
results.restart();
|
|
42
|
-
this._resultsSession = results.session; // keep track of the session
|
|
28
|
+
_doLoading(data) {
|
|
29
|
+
const { session } = this;
|
|
30
|
+
this.updateData({ ...data, session });
|
|
43
31
|
}
|
|
44
32
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
33
|
+
_queryWithQuestionId(data) {
|
|
34
|
+
const { session } = this;
|
|
35
|
+
const { request, value } = data;
|
|
36
|
+
this.updateData({ ...data, session });
|
|
37
|
+
// start query with question_id
|
|
38
|
+
const { question_id } = value;
|
|
39
|
+
if (!question_id) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
// forge the request
|
|
43
|
+
const payload = {
|
|
44
|
+
...request.payload,
|
|
45
|
+
question_id,
|
|
46
|
+
};
|
|
47
|
+
if (payload.metadata.page !== undefined) {
|
|
48
|
+
delete payload.metadata.page;
|
|
49
|
+
}
|
|
50
|
+
this._hub.update(fields.request(), { ...request, payload, session });
|
|
59
51
|
}
|
|
60
52
|
|
|
61
53
|
// data //
|
|
@@ -67,44 +59,15 @@ export default class HybridSearchAnswer extends AnswerBasedWorkflow {
|
|
|
67
59
|
return data;
|
|
68
60
|
}
|
|
69
61
|
|
|
70
|
-
_updateDataInHub(data) {
|
|
71
|
-
switch (data.status) {
|
|
72
|
-
case STATUS.INITIAL:
|
|
73
|
-
case STATUS.LOADING:
|
|
74
|
-
// share the initial/loading status with its sibling
|
|
75
|
-
this._dispatchDataToSibling(data);
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
super._updateDataInHub(data);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
62
|
_handleHeadResponse(data) {
|
|
82
63
|
super._handleHeadResponse(data);
|
|
83
64
|
// keep track of miso_id in session
|
|
84
65
|
writeMisoIdToSession(data);
|
|
85
|
-
// share the search results with its sibling
|
|
86
|
-
this._dispatchDataToSibling(data);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
_dispatchDataToSibling(data) {
|
|
90
|
-
this._resultsSession && this._superworkflow._results.updateData({ ...data, session: this._resultsSession });
|
|
91
66
|
}
|
|
92
67
|
|
|
93
68
|
// interactions //
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
_defaultProcessInteraction0(payload, args) {
|
|
99
|
-
return super._defaultProcessInteraction(payload, args);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// destroy //
|
|
103
|
-
_destroy(options) {
|
|
104
|
-
this._destroyAutocomplete();
|
|
105
|
-
super._destroy(options);
|
|
69
|
+
_onTracker(args) {
|
|
70
|
+
this._superworkflow._onTracker(args);
|
|
106
71
|
}
|
|
107
72
|
|
|
108
73
|
}
|
|
109
|
-
|
|
110
|
-
makeAutocompletable(HybridSearchAnswer.prototype);
|
|
@@ -1,17 +1,23 @@
|
|
|
1
|
-
import
|
|
1
|
+
import SearchBasedWorkflow from './search-based.js';
|
|
2
|
+
|
|
3
|
+
const RESULTS_ROLE_MEMBERS = SearchBasedWorkflow.ROLES_OPTIONS.members;
|
|
2
4
|
|
|
3
5
|
function getSubworkflowByRole(role) {
|
|
4
6
|
// TODO: ROLE.ERROR
|
|
5
|
-
return
|
|
7
|
+
return RESULTS_ROLE_MEMBERS.includes(role) ? 'results' : 'answer';
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
export default class HybridSearchViewsActor {
|
|
9
11
|
|
|
10
|
-
constructor(
|
|
11
|
-
this.
|
|
12
|
+
constructor(subviews) {
|
|
13
|
+
this._subviews = subviews;
|
|
12
14
|
this._containers = new Set();
|
|
13
15
|
}
|
|
14
16
|
|
|
17
|
+
get filters() {
|
|
18
|
+
return this._subviews.results.filters;
|
|
19
|
+
}
|
|
20
|
+
|
|
15
21
|
get(role) {
|
|
16
22
|
return this._getSubviews(role).get(role);
|
|
17
23
|
}
|
|
@@ -29,8 +35,8 @@ export default class HybridSearchViewsActor {
|
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
removeContainer(element) {
|
|
32
|
-
for (const
|
|
33
|
-
|
|
38
|
+
for (const subviews of this._getAllSubviews()) {
|
|
39
|
+
subviews.removeContainer(element);
|
|
34
40
|
}
|
|
35
41
|
this._containers.delete(element);
|
|
36
42
|
}
|
|
@@ -55,16 +61,12 @@ export default class HybridSearchViewsActor {
|
|
|
55
61
|
}
|
|
56
62
|
|
|
57
63
|
// helpers //
|
|
58
|
-
_getSubworkflow(role) {
|
|
59
|
-
return this._workflow._getSubworkflow(getSubworkflowByRole(role));
|
|
60
|
-
}
|
|
61
|
-
|
|
62
64
|
_getAllSubviews() {
|
|
63
|
-
return
|
|
65
|
+
return Object.values(this._subviews);
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
_getSubviews(role) {
|
|
67
|
-
return this.
|
|
69
|
+
return this._subviews[getSubworkflowByRole(role)];
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
_getViewByElement(element) {
|