@miso.ai/client-sdk-ui 1.11.0-beta.8 → 1.11.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/feedback.js +6 -39
- package/dist/cjs/actor/fields.js +14 -6
- package/dist/cjs/actor/index.js +0 -7
- package/dist/cjs/actor/interactions.js +4 -15
- package/dist/cjs/actor/sessions.js +2 -32
- package/dist/cjs/actor/tracker.js +25 -26
- package/dist/cjs/actor/utils.js +0 -49
- package/dist/cjs/actor/view.js +40 -40
- package/dist/cjs/actor/views.js +29 -8
- package/dist/cjs/constants.js +18 -19
- package/dist/cjs/defaults/hybrid-search/phrases.js +3 -3
- package/dist/cjs/defaults/hybrid-search/templates.js +28 -9
- package/dist/cjs/element/role/index.js +12 -5
- package/dist/cjs/element/role/{miso-hits.js → miso-more.js} +4 -4
- package/dist/cjs/element/role/miso-total.js +20 -0
- package/dist/cjs/layout/affiliation/affiliation.js +0 -3
- package/dist/cjs/layout/banner/banner.js +0 -4
- package/dist/cjs/layout/button/more-button.js +73 -0
- package/dist/cjs/layout/container/container.js +0 -3
- package/dist/cjs/layout/error/error.js +0 -4
- package/dist/cjs/layout/index.js +7 -0
- package/dist/cjs/layout/input/facets.js +0 -4
- package/dist/cjs/layout/input/option-list.js +0 -4
- package/dist/cjs/layout/input/search-box.js +13 -12
- package/dist/cjs/layout/list/cards.js +0 -3
- package/dist/cjs/layout/list/carousel.js +0 -3
- package/dist/cjs/layout/list/collection.js +22 -7
- package/dist/cjs/layout/list/list.js +0 -3
- package/dist/cjs/layout/radio/feedback.js +0 -3
- package/dist/cjs/layout/radio/radio.js +0 -4
- package/dist/cjs/layout/raf.js +4 -2
- package/dist/cjs/layout/text/text.js +0 -4
- package/dist/cjs/layout/text/typewriter/index.js +0 -3
- package/dist/cjs/layout/triggerable.js +79 -0
- package/dist/cjs/util/states.js +0 -15
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/workflow/answer-based.js +70 -105
- package/dist/cjs/workflow/ask.js +29 -27
- package/dist/cjs/workflow/asks.js +1 -1
- package/dist/cjs/workflow/autocompletable.js +33 -0
- package/dist/cjs/workflow/autocomplete.js +122 -0
- package/dist/cjs/workflow/base.js +156 -98
- package/dist/cjs/workflow/explore.js +48 -46
- package/dist/cjs/workflow/hybrid-search-answer.js +17 -7
- package/dist/cjs/workflow/hybrid-search-results.js +17 -87
- package/dist/cjs/workflow/hybrid-search-views.js +122 -0
- package/dist/cjs/workflow/hybrid-search.js +47 -168
- package/dist/cjs/workflow/options.js +32 -17
- package/dist/cjs/workflow/processors.js +166 -2
- package/dist/cjs/workflow/recommendation.js +36 -49
- package/dist/cjs/workflow/search-based.js +228 -0
- package/dist/cjs/workflow/search.js +21 -68
- package/dist/cjs/workflow/use-link.js +44 -0
- package/package.json +2 -2
- package/src/actor/feedback.js +6 -23
- package/src/actor/fields.js +14 -6
- package/src/actor/index.js +0 -1
- package/src/actor/interactions.js +4 -10
- package/src/actor/sessions.js +3 -31
- package/src/actor/tracker.js +25 -19
- package/src/actor/utils.js +0 -47
- package/src/actor/view.js +27 -15
- package/src/actor/views.js +32 -8
- package/src/constants.js +25 -16
- package/src/defaults/hybrid-search/phrases.js +2 -2
- package/src/defaults/hybrid-search/templates.js +20 -9
- package/src/element/role/index.js +2 -1
- package/src/element/role/{miso-hits.js → miso-more.js} +3 -3
- package/src/element/role/miso-total.js +16 -0
- package/src/layout/affiliation/affiliation.js +1 -5
- package/src/layout/banner/banner.js +0 -5
- package/src/layout/button/more-button.js +69 -0
- package/src/layout/container/container.js +1 -5
- package/src/layout/error/error.js +0 -5
- package/src/layout/index.js +2 -1
- package/src/layout/input/facets.js +0 -5
- package/src/layout/input/option-list.js +0 -5
- package/src/layout/input/search-box.js +11 -14
- package/src/layout/list/cards.js +0 -4
- package/src/layout/list/carousel.js +0 -4
- package/src/layout/list/collection.js +21 -9
- package/src/layout/list/list.js +0 -4
- package/src/layout/radio/feedback.js +0 -4
- package/src/layout/radio/radio.js +0 -5
- package/src/layout/raf.js +2 -2
- package/src/layout/text/text.js +0 -5
- package/src/layout/text/typewriter/index.js +1 -5
- package/src/layout/triggerable.js +76 -0
- package/src/util/states.js +0 -14
- package/src/version.js +1 -1
- package/src/workflow/answer-based.js +61 -72
- package/src/workflow/ask.js +30 -24
- package/src/workflow/asks.js +1 -1
- package/src/workflow/autocompletable.js +29 -0
- package/src/workflow/autocomplete.js +113 -0
- package/src/workflow/base.js +133 -87
- package/src/workflow/explore.js +38 -30
- package/src/workflow/hybrid-search-answer.js +17 -6
- package/src/workflow/hybrid-search-results.js +17 -77
- package/src/workflow/hybrid-search-views.js +124 -0
- package/src/workflow/hybrid-search.js +47 -157
- package/src/workflow/options.js +26 -11
- package/src/workflow/processors.js +151 -3
- package/src/workflow/recommendation.js +32 -33
- package/src/workflow/search-based.js +222 -0
- package/src/workflow/search.js +21 -65
- package/src/workflow/use-link.js +40 -0
- package/dist/cjs/actor/autocomplete.js +0 -160
- package/dist/cjs/workflow/utils.js +0 -42
- package/src/actor/autocomplete.js +0 -133
- package/src/workflow/utils.js +0 -29
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.TriggerableMixin = void 0;
|
|
7
|
+
exports.makeTriggerable = makeTriggerable;
|
|
8
|
+
var _commons = require("@miso.ai/commons");
|
|
9
|
+
var _constants = require("../constants.js");
|
|
10
|
+
var _index = require("../actor/index.js");
|
|
11
|
+
function makeTriggerable(prototype) {
|
|
12
|
+
(0, _commons.mixin)(prototype, TriggerableMixin.prototype);
|
|
13
|
+
}
|
|
14
|
+
class TriggerableMixin {
|
|
15
|
+
_initTriggerable() {
|
|
16
|
+
this._trigger = undefined;
|
|
17
|
+
}
|
|
18
|
+
_syncTrigger(element, state) {
|
|
19
|
+
if (!this.options.infiniteScroll) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const workflowPaginationOptions = this.workflowOptions.pagination;
|
|
23
|
+
if (!workflowPaginationOptions.active || workflowPaginationOptions.mode !== 'infiniteScroll') {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// only track trigger when ready
|
|
27
|
+
if (state.status === _constants.STATUS.READY) {
|
|
28
|
+
this._trackTrigger(element);
|
|
29
|
+
} else {
|
|
30
|
+
this._untrackTrigger();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async _trackTrigger(element) {
|
|
34
|
+
if (this._trigger) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const triggerElement = element.querySelector('[data-role="trigger"]');
|
|
38
|
+
if (!triggerElement) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const ac = new AbortController();
|
|
42
|
+
this._trigger = Object.freeze({
|
|
43
|
+
element: triggerElement,
|
|
44
|
+
ac
|
|
45
|
+
});
|
|
46
|
+
let result = false;
|
|
47
|
+
try {
|
|
48
|
+
await (0, _commons.viewable)(triggerElement, {
|
|
49
|
+
area: 1,
|
|
50
|
+
duration: 0,
|
|
51
|
+
signal: ac.signal
|
|
52
|
+
});
|
|
53
|
+
result = true;
|
|
54
|
+
} catch (e) {
|
|
55
|
+
if (e.name !== 'AbortError') {
|
|
56
|
+
throw e;
|
|
57
|
+
}
|
|
58
|
+
} finally {
|
|
59
|
+
this._trigger = undefined;
|
|
60
|
+
}
|
|
61
|
+
if (result) {
|
|
62
|
+
this._onTrigger();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
_onTrigger() {
|
|
66
|
+
this._view.hub.trigger(_index.fields.more());
|
|
67
|
+
}
|
|
68
|
+
_untrackTrigger() {
|
|
69
|
+
if (!this._trigger) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this._trigger.ac && this._trigger.ac.abort();
|
|
73
|
+
this._trigger = undefined;
|
|
74
|
+
}
|
|
75
|
+
_destroyTriggerable() {
|
|
76
|
+
this._untrackTrigger();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.TriggerableMixin = TriggerableMixin;
|
package/dist/cjs/util/states.js
CHANGED
|
@@ -15,21 +15,6 @@ const {
|
|
|
15
15
|
UNTRACKED,
|
|
16
16
|
TRIGGERED
|
|
17
17
|
} = _constants.TRACKING_STATUS;
|
|
18
|
-
|
|
19
|
-
/*
|
|
20
|
-
const STATES = {
|
|
21
|
-
NEW: Object.freeze({
|
|
22
|
-
[IMPRESSION]: UNTRACKED,
|
|
23
|
-
[VIEWABLE]: UNTRACKED,
|
|
24
|
-
}),
|
|
25
|
-
UNTRACKED: Object.freeze({
|
|
26
|
-
[IMPRESSION]: UNTRACKED,
|
|
27
|
-
[VIEWABLE]: UNTRACKED,
|
|
28
|
-
[CLICK]: UNTRACKED,
|
|
29
|
-
}),
|
|
30
|
-
};
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
18
|
const UNTRACKED_STATES = Object.freeze({
|
|
34
19
|
[IMPRESSION]: UNTRACKED,
|
|
35
20
|
[VIEWABLE]: UNTRACKED,
|
package/dist/cjs/version.js
CHANGED
|
@@ -6,24 +6,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _commons = require("@miso.ai/commons");
|
|
8
8
|
var _base = _interopRequireDefault(require("./base.js"));
|
|
9
|
-
var _options = require("./options.js");
|
|
10
9
|
var _index = require("../actor/index.js");
|
|
11
10
|
var _constants = require("../constants.js");
|
|
12
11
|
var _index2 = require("../layout/index.js");
|
|
13
12
|
var _index3 = require("../affiliation/index.js");
|
|
13
|
+
var _options = require("./options.js");
|
|
14
14
|
var _processors = require("./processors.js");
|
|
15
|
+
var _useLink = require("./use-link.js");
|
|
15
16
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const DEFAULT_API_OPTIONS = Object.freeze({
|
|
17
|
+
const DEFAULT_API_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_API_OPTIONS, {
|
|
19
18
|
group: _commons.API.GROUP.ASK,
|
|
20
|
-
payload: {
|
|
19
|
+
payload: Object.assign({}, _base.default.DEFAULT_API_OPTIONS.payload, {
|
|
21
20
|
source_fl: ['cover_image', 'url', 'created_at', 'updated_at', 'published_at'],
|
|
22
21
|
cite_link: 1,
|
|
23
22
|
cite_start: '[',
|
|
24
23
|
cite_end: ']'
|
|
25
|
-
}
|
|
26
|
-
});
|
|
24
|
+
})
|
|
25
|
+
}));
|
|
27
26
|
const DEFAULT_AUTOCOMPLETE_OPTIONS = Object.freeze({
|
|
28
27
|
actor: false,
|
|
29
28
|
api: {
|
|
@@ -31,7 +30,7 @@ const DEFAULT_AUTOCOMPLETE_OPTIONS = Object.freeze({
|
|
|
31
30
|
name: _commons.API.NAME.AUTOCOMPLETE
|
|
32
31
|
}
|
|
33
32
|
});
|
|
34
|
-
const DEFAULT_LAYOUTS = Object.freeze({
|
|
33
|
+
const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _base.default.DEFAULT_LAYOUTS, {
|
|
35
34
|
[_constants.ROLE.QUERY]: [_index2.SearchBoxLayout.type, {
|
|
36
35
|
placeholder: 'Ask a question'
|
|
37
36
|
}],
|
|
@@ -54,17 +53,21 @@ const DEFAULT_LAYOUTS = Object.freeze({
|
|
|
54
53
|
rel: 'noopener nofollow'
|
|
55
54
|
}
|
|
56
55
|
}]
|
|
57
|
-
});
|
|
58
|
-
const DEFAULT_TRACKERS = Object.freeze({
|
|
56
|
+
}));
|
|
57
|
+
const DEFAULT_TRACKERS = Object.freeze(Object.assign({}, _base.default.DEFAULT_TRACKERS, {
|
|
59
58
|
[_constants.ROLE.SOURCES]: {},
|
|
60
59
|
[_constants.ROLE.AFFILIATION]: {},
|
|
61
60
|
[_constants.ROLE.PRODUCTS]: {}
|
|
62
|
-
});
|
|
63
|
-
const DEFAULT_OPTIONS = Object.freeze({
|
|
61
|
+
}));
|
|
62
|
+
const DEFAULT_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_OPTIONS, {
|
|
64
63
|
api: DEFAULT_API_OPTIONS,
|
|
65
64
|
autocomplete: DEFAULT_AUTOCOMPLETE_OPTIONS,
|
|
66
65
|
layouts: DEFAULT_LAYOUTS,
|
|
67
66
|
trackers: DEFAULT_TRACKERS
|
|
67
|
+
}));
|
|
68
|
+
const ROLES_OPTIONS = (0, _options.mergeRolesOptions)(_base.default.ROLES_OPTIONS, {
|
|
69
|
+
main: _constants.ROLE.ANSWER,
|
|
70
|
+
members: Object.keys(DEFAULT_LAYOUTS)
|
|
68
71
|
});
|
|
69
72
|
class AnswerBasedWorkflow extends _base.default {
|
|
70
73
|
// constructor //
|
|
@@ -76,16 +79,10 @@ class AnswerBasedWorkflow extends _base.default {
|
|
|
76
79
|
_initActors(args) {
|
|
77
80
|
super._initActors(args);
|
|
78
81
|
this._feedback = new _index.FeedbackActor(this._hub);
|
|
79
|
-
/*
|
|
80
|
-
this._autocomplete = new AutocompleteActor(this._hub, {
|
|
81
|
-
source: sources.api(this._client),
|
|
82
|
-
options: this._options,
|
|
83
|
-
});
|
|
84
|
-
*/
|
|
85
82
|
}
|
|
86
83
|
_initSubscriptions(args) {
|
|
87
84
|
super._initSubscriptions(args);
|
|
88
|
-
this._unsubscribes = [...this._unsubscribes, this._hub.on(_index.fields.query(), args => this._query(args)), this.
|
|
85
|
+
this._unsubscribes = [...this._unsubscribes, this._hub.on(_index.fields.query(), args => this._query(args)), this._views.get(_constants.ROLE.ANSWER).on('citation-click', event => this._onCitationClick(event))];
|
|
89
86
|
}
|
|
90
87
|
|
|
91
88
|
// lifecycle //
|
|
@@ -94,26 +91,29 @@ class AnswerBasedWorkflow extends _base.default {
|
|
|
94
91
|
if (this._questionId) {
|
|
95
92
|
this._questionId = undefined;
|
|
96
93
|
}
|
|
97
|
-
// interrupt event
|
|
98
|
-
// TODO: move to workflow base
|
|
99
|
-
const {
|
|
100
|
-
session,
|
|
101
|
-
status,
|
|
102
|
-
ongoing
|
|
103
|
-
} = this._hub.states[_index.fields.view(_constants.ROLE.ANSWER)] || {};
|
|
104
|
-
if (session && status !== _constants.STATUS.INITIAL && (status !== _constants.STATUS.READY || ongoing)) {
|
|
105
|
-
// it's interrupted by a new question
|
|
106
|
-
const state = Object.freeze({
|
|
107
|
-
session,
|
|
108
|
-
status,
|
|
109
|
-
ongoing
|
|
110
|
-
});
|
|
111
|
-
this._emit('interrupt', state);
|
|
112
|
-
this._emit('finally', state);
|
|
113
|
-
}
|
|
114
94
|
// restart
|
|
115
95
|
super.restart();
|
|
116
96
|
}
|
|
97
|
+
_emitInterruptEventIfNecessary() {
|
|
98
|
+
const state = this._hub.states[_index.fields.view(this._roles.main)] || {};
|
|
99
|
+
if (state.session && state.status !== _constants.STATUS.INITIAL && (state.status !== _constants.STATUS.READY || state.ongoing)) {
|
|
100
|
+
// it's interrupted by a new question
|
|
101
|
+
this._emitLifecycleEvent('interrupt', state);
|
|
102
|
+
this._emitLifecycleEvent('finally', state);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
_onMainViewUpdate(state) {
|
|
106
|
+
const {
|
|
107
|
+
status
|
|
108
|
+
} = state;
|
|
109
|
+
const done = status === _constants.STATUS.READY && !state.ongoing;
|
|
110
|
+
const erroneous = status === _constants.STATUS.ERRONEOUS;
|
|
111
|
+
const eventName = done ? 'done' : erroneous ? 'error' : status;
|
|
112
|
+
this._emitLifecycleEvent(eventName, state);
|
|
113
|
+
if (done || erroneous) {
|
|
114
|
+
this._emitLifecycleEvent('finally', state);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
117
|
|
|
118
118
|
// properties //
|
|
119
119
|
get questionId() {
|
|
@@ -157,46 +157,29 @@ class AnswerBasedWorkflow extends _base.default {
|
|
|
157
157
|
}
|
|
158
158
|
_query() {
|
|
159
159
|
let args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
160
|
+
if (this._linkFn) {
|
|
161
|
+
this._submitToPage(args);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
160
164
|
// start a new session
|
|
161
165
|
this.restart();
|
|
162
166
|
|
|
163
|
-
// TODO: move to ask workflow
|
|
164
167
|
// keep track of question source on this session, for suggested questions interactions
|
|
165
168
|
this._writeQuestionSourceToSession(args);
|
|
166
169
|
|
|
167
170
|
// build payload and trigger request
|
|
168
|
-
const {
|
|
169
|
-
session
|
|
170
|
-
} = this;
|
|
171
171
|
const payload = this._buildPayload(args);
|
|
172
|
-
|
|
173
|
-
payload
|
|
174
|
-
session
|
|
172
|
+
this._request({
|
|
173
|
+
payload
|
|
175
174
|
});
|
|
176
|
-
this._request(event);
|
|
177
175
|
}
|
|
178
176
|
_writeQuestionSourceToSession(args) {
|
|
179
|
-
this.session.meta.question_source = args.
|
|
180
|
-
}
|
|
181
|
-
_request(event) {
|
|
182
|
-
this._hub.update(_index.fields.request(), event);
|
|
177
|
+
this.session.meta.question_source = args.qs || _constants.ORGANIC_QUESTION_SOURCE; // might be null, not undefined
|
|
183
178
|
}
|
|
184
179
|
_buildPayload() {
|
|
185
180
|
throw new Error(`Not implemented`);
|
|
186
181
|
}
|
|
187
182
|
|
|
188
|
-
// autocomplete //
|
|
189
|
-
/*
|
|
190
|
-
updateCompletions(event) {
|
|
191
|
-
// TODO: verify
|
|
192
|
-
this._hub.update(fields.data(DATA_ASPECT.AUTOCOMPLETE), {
|
|
193
|
-
...event,
|
|
194
|
-
source: 'manual',
|
|
195
|
-
});
|
|
196
|
-
return this;
|
|
197
|
-
}
|
|
198
|
-
*/
|
|
199
|
-
|
|
200
183
|
// data //
|
|
201
184
|
_updateData(data) {
|
|
202
185
|
// if it's the head response, write question id and return
|
|
@@ -254,58 +237,40 @@ class AnswerBasedWorkflow extends _base.default {
|
|
|
254
237
|
}
|
|
255
238
|
|
|
256
239
|
// interactions //
|
|
257
|
-
|
|
258
|
-
payload = super.
|
|
259
|
-
payload = this.
|
|
240
|
+
_defaultProcessInteraction(payload, args) {
|
|
241
|
+
payload = super._defaultProcessInteraction(payload, args);
|
|
242
|
+
payload = this._writeAskPropertiesToInteraction(payload, args);
|
|
260
243
|
return payload;
|
|
261
244
|
}
|
|
262
|
-
|
|
245
|
+
_writeAskPropertiesToInteraction() {
|
|
263
246
|
let payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
247
|
+
let args = arguments.length > 1 ? arguments[1] : undefined;
|
|
248
|
+
const question_source = this._getQuestionSourceFromViewState(args);
|
|
249
|
+
const question_id = this.questionId;
|
|
250
|
+
return (0, _processors.mergeInteraction)(payload, {
|
|
251
|
+
context: {
|
|
252
|
+
custom_context: {
|
|
253
|
+
question_source,
|
|
254
|
+
question_id
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
_getQuestionSourceFromViewState(args) {
|
|
264
260
|
const {
|
|
265
|
-
|
|
266
|
-
} =
|
|
261
|
+
request
|
|
262
|
+
} = this._hub.states[_index.fields.view(args.role)] || {};
|
|
267
263
|
const {
|
|
268
|
-
|
|
269
|
-
} =
|
|
270
|
-
|
|
271
|
-
questionId
|
|
272
|
-
} = this;
|
|
273
|
-
return Object.assign({}, payload, {
|
|
274
|
-
context: Object.assign({}, context, {
|
|
275
|
-
custom_context: (0, _commons.trimObj)(Object.assign({
|
|
276
|
-
question_id: questionId
|
|
277
|
-
}, custom_context))
|
|
278
|
-
})
|
|
279
|
-
});
|
|
264
|
+
payload
|
|
265
|
+
} = request || {};
|
|
266
|
+
return payload && payload._meta && payload._meta.question_source || undefined;
|
|
280
267
|
}
|
|
281
268
|
|
|
282
269
|
// handlers //
|
|
283
|
-
|
|
284
|
-
let {
|
|
285
|
-
session,
|
|
286
|
-
status,
|
|
287
|
-
ongoing
|
|
288
|
-
} = _ref3;
|
|
289
|
-
if (status === _constants.STATUS.INITIAL) {
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
const done = status === _constants.STATUS.READY && !ongoing;
|
|
293
|
-
const erroneous = status === _constants.STATUS.ERRONEOUS;
|
|
294
|
-
const eventName = done ? 'done' : erroneous ? 'error' : status;
|
|
295
|
-
const state = Object.freeze({
|
|
296
|
-
session,
|
|
297
|
-
status,
|
|
298
|
-
ongoing
|
|
299
|
-
});
|
|
300
|
-
this._emit(eventName, state);
|
|
301
|
-
if (done || erroneous) {
|
|
302
|
-
this._emit('finally', state);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
_onCitationClick(_ref4) {
|
|
270
|
+
_onCitationClick(_ref3) {
|
|
306
271
|
let {
|
|
307
272
|
index
|
|
308
|
-
} =
|
|
273
|
+
} = _ref3;
|
|
309
274
|
const {
|
|
310
275
|
value
|
|
311
276
|
} = this.states[_index.fields.data()] || {};
|
|
@@ -341,13 +306,13 @@ class AnswerBasedWorkflow extends _base.default {
|
|
|
341
306
|
super._destroy(options);
|
|
342
307
|
}
|
|
343
308
|
}
|
|
344
|
-
|
|
345
|
-
// makeConfigurable(AnswerBasedWorkflow.prototype, ['autocomplete']);
|
|
346
309
|
exports.default = AnswerBasedWorkflow;
|
|
310
|
+
(0, _useLink.enableUseLink)(AnswerBasedWorkflow.prototype);
|
|
347
311
|
Object.assign(AnswerBasedWorkflow, {
|
|
348
312
|
DEFAULT_API_OPTIONS,
|
|
349
313
|
DEFAULT_AUTOCOMPLETE_OPTIONS,
|
|
350
314
|
DEFAULT_LAYOUTS,
|
|
351
315
|
DEFAULT_TRACKERS,
|
|
352
|
-
DEFAULT_OPTIONS
|
|
316
|
+
DEFAULT_OPTIONS,
|
|
317
|
+
ROLES_OPTIONS
|
|
353
318
|
});
|
package/dist/cjs/workflow/ask.js
CHANGED
|
@@ -9,9 +9,9 @@ var _answerBased = _interopRequireDefault(require("./answer-based.js"));
|
|
|
9
9
|
var _index = require("../actor/index.js");
|
|
10
10
|
var _constants = require("../constants.js");
|
|
11
11
|
var _index2 = require("../layout/index.js");
|
|
12
|
+
var _processors = require("./processors.js");
|
|
12
13
|
const _excluded = ["q", "qs"];
|
|
13
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
-
function _objectDestructuringEmpty(t) { if (null == t) throw new TypeError("Cannot destructure " + t); }
|
|
15
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
16
|
const DEFAULT_API_OPTIONS = Object.freeze(Object.assign({}, _answerBased.default.DEFAULT_API_OPTIONS, {
|
|
17
17
|
name: _commons.API.NAME.QUESTIONS,
|
|
@@ -44,12 +44,13 @@ const DEFAULT_OPTIONS = Object.freeze(Object.assign({}, _answerBased.default.DEF
|
|
|
44
44
|
layouts: DEFAULT_LAYOUTS,
|
|
45
45
|
trackers: DEFAULT_TRACKERS
|
|
46
46
|
}));
|
|
47
|
+
const ROLES_OPTIONS = _answerBased.default.ROLES_OPTIONS;
|
|
47
48
|
class Ask extends _answerBased.default {
|
|
48
49
|
constructor(context, parentQuestionId) {
|
|
49
50
|
super({
|
|
50
51
|
name: 'ask',
|
|
51
52
|
context,
|
|
52
|
-
roles:
|
|
53
|
+
roles: ROLES_OPTIONS,
|
|
53
54
|
defaults: DEFAULT_OPTIONS,
|
|
54
55
|
parentQuestionId
|
|
55
56
|
});
|
|
@@ -83,11 +84,11 @@ class Ask extends _answerBased.default {
|
|
|
83
84
|
}))
|
|
84
85
|
});
|
|
85
86
|
}
|
|
86
|
-
|
|
87
|
+
_initSession(args) {
|
|
87
88
|
// register at context
|
|
88
89
|
args.parentQuestionId && this._context._byPqid.set(args.parentQuestionId, this);
|
|
89
90
|
this._context._events.emit('create', this);
|
|
90
|
-
super.
|
|
91
|
+
super._initSession(args);
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
// lifecycle //
|
|
@@ -145,31 +146,32 @@ class Ask extends _answerBased.default {
|
|
|
145
146
|
}
|
|
146
147
|
|
|
147
148
|
// interactions //
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const {
|
|
151
|
-
context = {}
|
|
152
|
-
} = payload;
|
|
153
|
-
const _ref2 = context.custom_context || {},
|
|
154
|
-
custom_context = Object.assign({}, (_objectDestructuringEmpty(_ref2), _ref2));
|
|
149
|
+
_writeAskPropertiesToInteraction(payload, args) {
|
|
150
|
+
const root_question_id = this.rootQuestionId;
|
|
155
151
|
let {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
152
|
+
property
|
|
153
|
+
} = payload.context && payload.context.custom_context || {};
|
|
154
|
+
let question_id, parent_question_id, question_source;
|
|
155
|
+
if (args.role === _constants.ROLE.QUERY_SUGGESTIONS) {
|
|
156
|
+
property = 'suggested_followup_questions';
|
|
157
|
+
parent_question_id = this.previous && this.previous.parentQuestionId;
|
|
158
|
+
question_id = this.parentQuestionId;
|
|
159
|
+
question_source = this.previous && this.previous.session.meta.question_source;
|
|
160
|
+
} else {
|
|
161
|
+
parent_question_id = this.parentQuestionId;
|
|
162
|
+
question_id = this.questionId;
|
|
163
|
+
question_source = this._getQuestionSourceFromViewState(args);
|
|
165
164
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
165
|
+
return (0, _processors.mergeInteraction)(payload, {
|
|
166
|
+
context: {
|
|
167
|
+
custom_context: {
|
|
168
|
+
property,
|
|
169
|
+
root_question_id,
|
|
170
|
+
parent_question_id,
|
|
171
|
+
question_id,
|
|
172
|
+
question_source
|
|
173
|
+
}
|
|
174
|
+
}
|
|
173
175
|
});
|
|
174
176
|
}
|
|
175
177
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AutocompletableMixin = void 0;
|
|
7
|
+
exports.makeAutocompletable = makeAutocompletable;
|
|
8
|
+
var _commons = require("@miso.ai/commons");
|
|
9
|
+
var _index = require("../actor/index.js");
|
|
10
|
+
var _autocomplete = _interopRequireDefault(require("./autocomplete.js"));
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
function makeAutocompletable(prototype) {
|
|
13
|
+
(0, _commons.mixin)(prototype, AutocompletableMixin.prototype);
|
|
14
|
+
}
|
|
15
|
+
class AutocompletableMixin {
|
|
16
|
+
_initAutocomplete(args) {
|
|
17
|
+
this._autocomplete = new _autocomplete.default(this, {
|
|
18
|
+
defaults: args.defaults.autocomplete
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
get autocomplete() {
|
|
22
|
+
return this._autocomplete;
|
|
23
|
+
}
|
|
24
|
+
updateCompletions(data) {
|
|
25
|
+
this._hub.update(_index.fields.completions(), data);
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
_destroyAutocomplete() {
|
|
29
|
+
this._autocomplete && this._autocomplete._destroy();
|
|
30
|
+
this._autocomplete = undefined;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.AutocompletableMixin = AutocompletableMixin;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _constants = require("../constants.js");
|
|
8
|
+
var _index = require("../actor/index.js");
|
|
9
|
+
var _base = _interopRequireDefault(require("./base.js"));
|
|
10
|
+
const _excluded = ["layouts", "trackers"],
|
|
11
|
+
_excluded2 = ["defaults"];
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
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; }
|
|
14
|
+
const ROLES_OPTIONS = Object.freeze({
|
|
15
|
+
members: []
|
|
16
|
+
});
|
|
17
|
+
function shimDefaults() {
|
|
18
|
+
let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
19
|
+
let options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
20
|
+
return Object.assign({
|
|
21
|
+
active: false
|
|
22
|
+
}, options, {
|
|
23
|
+
layouts: {},
|
|
24
|
+
trackers: {}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function sameInputValue(a, b) {
|
|
28
|
+
return getInputValue(a) === getInputValue(b);
|
|
29
|
+
}
|
|
30
|
+
function getInputValue(args) {
|
|
31
|
+
return args && args.value && args.value.trim() || undefined;
|
|
32
|
+
}
|
|
33
|
+
class Autocomplete extends _base.default {
|
|
34
|
+
constructor(superworkflow) {
|
|
35
|
+
let _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
36
|
+
let {
|
|
37
|
+
defaults
|
|
38
|
+
} = _ref2,
|
|
39
|
+
args = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
40
|
+
super(Object.assign({
|
|
41
|
+
name: 'autocomplete',
|
|
42
|
+
plugin: superworkflow._plugin,
|
|
43
|
+
client: superworkflow._client,
|
|
44
|
+
defaults: shimDefaults(defaults),
|
|
45
|
+
roles: ROLES_OPTIONS,
|
|
46
|
+
superworkflow
|
|
47
|
+
}, args));
|
|
48
|
+
}
|
|
49
|
+
_initProperties(args) {
|
|
50
|
+
super._initProperties(args);
|
|
51
|
+
this._superworkflow = args.superworkflow;
|
|
52
|
+
this._active = args.defaults.active;
|
|
53
|
+
}
|
|
54
|
+
_initSubscriptions(args) {
|
|
55
|
+
// TODO: how to sync options updates
|
|
56
|
+
super._initSubscriptions(args);
|
|
57
|
+
this._unsubscribes = [...this._unsubscribes, args.superworkflow._hub.on(_index.fields.input(), args => this._query(args))];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// API //
|
|
61
|
+
get enabled() {
|
|
62
|
+
return this._active;
|
|
63
|
+
}
|
|
64
|
+
enable() {
|
|
65
|
+
this._active = true;
|
|
66
|
+
}
|
|
67
|
+
disable() {
|
|
68
|
+
this._active = false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// query //
|
|
72
|
+
_query(args) {
|
|
73
|
+
if (!this._active || sameInputValue(args, this._args)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
this._args = args;
|
|
77
|
+
|
|
78
|
+
// start a new session
|
|
79
|
+
this.restart();
|
|
80
|
+
const {
|
|
81
|
+
session
|
|
82
|
+
} = this;
|
|
83
|
+
session.meta.input = args;
|
|
84
|
+
|
|
85
|
+
// if input value is blank, emit empty response
|
|
86
|
+
if (!getInputValue(args)) {
|
|
87
|
+
this._updateCompletions({
|
|
88
|
+
session,
|
|
89
|
+
status: _constants.STATUS.INITIAL
|
|
90
|
+
});
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// payload
|
|
95
|
+
const payload = this._buildPayload(args);
|
|
96
|
+
|
|
97
|
+
// request
|
|
98
|
+
this._request({
|
|
99
|
+
payload
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
_buildPayload(args) {
|
|
103
|
+
return {
|
|
104
|
+
q: getInputValue(args)
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// data //
|
|
109
|
+
_updateDataInHub(data) {
|
|
110
|
+
if (data.value) {
|
|
111
|
+
data = Object.assign({}, data, {
|
|
112
|
+
value: data.value.completions
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
// update completion field in superworkflow hub
|
|
116
|
+
this._updateCompletions(data);
|
|
117
|
+
}
|
|
118
|
+
_updateCompletions(data) {
|
|
119
|
+
this._superworkflow.updateCompletions(data);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.default = Autocomplete;
|