@miso.ai/client-sdk-ui 1.13.2-beta.1 → 1.14.0-beta.3
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/asset/svgs.js +17 -4
- package/dist/cjs/combo/ask/index.js +2 -2
- package/dist/cjs/constants.js +120 -98
- package/dist/cjs/defaults/ask/controls.js +1 -1
- package/dist/cjs/defaults/hybrid-search/answer-box.js +4 -4
- package/dist/cjs/defaults.js +259 -0
- package/dist/cjs/element/container/index.js +28 -0
- package/dist/cjs/element/container/miso-ask.js +3 -3
- package/dist/cjs/element/container/miso-conversation.js +21 -0
- package/dist/cjs/element/container/miso-explore.js +1 -1
- package/dist/cjs/element/container/miso-history.js +21 -0
- package/dist/cjs/element/container/miso-hybrid-search.js +1 -1
- package/dist/cjs/element/container/miso-message-item.js +91 -0
- package/dist/cjs/element/container/miso-recommendation.js +1 -1
- package/dist/cjs/element/container/miso-search.js +1 -1
- package/dist/cjs/element/container/miso-thread-item.js +91 -0
- package/dist/cjs/element/context/miso-follow-ups.js +1 -1
- package/dist/cjs/element/role/index.js +49 -0
- package/dist/cjs/element/role/miso-delete.js +20 -0
- package/dist/cjs/element/role/miso-messages.js +20 -0
- package/dist/cjs/element/role/miso-new-thread.js +20 -0
- package/dist/cjs/element/role/miso-rename.js +20 -0
- package/dist/cjs/element/role/miso-subscription.js +20 -0
- package/dist/cjs/element/role/miso-threads.js +20 -0
- package/dist/cjs/element/role/miso-title.js +20 -0
- package/dist/cjs/layout/affiliation/affiliation.js +1 -1
- package/dist/cjs/layout/banner/banner.js +2 -1
- package/dist/cjs/layout/button/button.js +170 -0
- package/dist/cjs/layout/button/checkbox.js +116 -0
- package/dist/cjs/layout/button/more-button.js +3 -3
- package/dist/cjs/layout/container/container.js +1 -1
- package/dist/cjs/layout/container/item-container.js +99 -0
- package/dist/cjs/layout/error/error.js +2 -1
- package/dist/cjs/layout/index.js +42 -0
- package/dist/cjs/layout/input/facets.js +4 -3
- package/dist/cjs/layout/input/option-list.js +3 -2
- package/dist/cjs/layout/input/search-box.js +50 -12
- package/dist/cjs/layout/input/select.js +2 -1
- package/dist/cjs/layout/list/cards.js +2 -1
- package/dist/cjs/layout/list/carousel.js +2 -1
- package/dist/cjs/layout/list/collection.js +13 -1
- package/dist/cjs/layout/list/gallery.js +2 -1
- package/dist/cjs/layout/list/horizontal.js +2 -1
- package/dist/cjs/layout/list/list.js +2 -1
- package/dist/cjs/layout/list/messages.js +359 -0
- package/dist/cjs/layout/list/threads.js +199 -0
- package/dist/cjs/layout/mixin/trackable.js +4 -5
- package/dist/cjs/layout/mixin/triggerable.js +2 -2
- package/dist/cjs/layout/radio/feedback.js +4 -3
- package/dist/cjs/layout/templates.js +97 -0
- package/dist/cjs/layout/text/question.js +71 -0
- package/dist/cjs/layout/text/text.js +2 -1
- package/dist/cjs/layout/text/typewriter/index.js +18 -23
- package/dist/cjs/plugin.js +43 -104
- package/dist/cjs/util/confirm.js +33 -0
- package/dist/cjs/util/dom.js +21 -0
- package/dist/cjs/util/modal.js +48 -0
- package/dist/cjs/util/prompt.js +47 -0
- package/dist/cjs/version.js +1 -1
- package/package.json +5 -4
- package/src/CLAUDE.md +51 -104
- package/src/asset/svgs.js +16 -3
- package/src/combo/ask/index.js +2 -2
- package/src/constants.js +39 -147
- package/src/defaults/ask/controls.js +1 -1
- package/src/defaults/hybrid-search/answer-box.js +2 -2
- package/src/defaults.js +174 -0
- package/src/element/container/index.js +4 -0
- package/src/element/container/miso-ask.js +3 -3
- package/src/element/container/miso-conversation.js +19 -0
- package/src/element/container/miso-explore.js +1 -1
- package/src/element/container/miso-history.js +19 -0
- package/src/element/container/miso-hybrid-search.js +1 -1
- package/src/element/container/miso-message-item.js +94 -0
- package/src/element/container/miso-recommendation.js +1 -1
- package/src/element/container/miso-search.js +1 -1
- package/src/element/container/miso-thread-item.js +94 -0
- package/src/element/context/miso-follow-ups.js +1 -1
- package/src/element/role/index.js +7 -0
- package/src/element/role/miso-delete.js +16 -0
- package/src/element/role/miso-messages.js +16 -0
- package/src/element/role/miso-new-thread.js +16 -0
- package/src/element/role/miso-rename.js +16 -0
- package/src/element/role/miso-subscription.js +16 -0
- package/src/element/role/miso-threads.js +16 -0
- package/src/element/role/miso-title.js +16 -0
- package/src/layout/affiliation/affiliation.js +2 -2
- package/src/layout/banner/banner.js +2 -1
- package/src/layout/button/button.js +152 -0
- package/src/layout/button/checkbox.js +92 -0
- package/src/layout/button/more-button.js +3 -3
- package/src/layout/container/container.js +2 -2
- package/src/layout/container/item-container.js +99 -0
- package/src/layout/error/error.js +2 -1
- package/src/layout/index.js +6 -0
- package/src/layout/input/facets.js +3 -2
- package/src/layout/input/option-list.js +3 -2
- package/src/layout/input/search-box.js +45 -8
- package/src/layout/input/select.js +2 -1
- package/src/layout/list/cards.js +2 -1
- package/src/layout/list/carousel.js +2 -1
- package/src/layout/list/collection.js +15 -2
- package/src/layout/list/gallery.js +2 -1
- package/src/layout/list/horizontal.js +2 -1
- package/src/layout/list/list.js +2 -1
- package/src/layout/list/messages.js +316 -0
- package/src/layout/list/threads.js +166 -0
- package/src/layout/mixin/trackable.js +2 -3
- package/src/layout/mixin/triggerable.js +1 -1
- package/src/layout/radio/feedback.js +3 -2
- package/src/layout/templates.js +97 -0
- package/src/layout/text/question.js +58 -0
- package/src/layout/text/text.js +2 -1
- package/src/layout/text/typewriter/index.js +15 -18
- package/src/plugin.js +31 -117
- package/src/util/confirm.js +28 -0
- package/src/util/dom.js +16 -0
- package/src/util/modal.js +49 -0
- package/src/util/prompt.js +42 -0
- package/src/version.js +1 -1
- package/dist/cjs/actor/data.js +0 -132
- package/dist/cjs/actor/feedback.js +0 -29
- package/dist/cjs/actor/fields.js +0 -57
- package/dist/cjs/actor/filters.js +0 -161
- package/dist/cjs/actor/hub.js +0 -57
- package/dist/cjs/actor/index.js +0 -73
- package/dist/cjs/actor/interactions.js +0 -36
- package/dist/cjs/actor/sessions.js +0 -25
- package/dist/cjs/actor/tracker-states.js +0 -61
- package/dist/cjs/actor/tracker.js +0 -109
- package/dist/cjs/actor/trackers.js +0 -52
- package/dist/cjs/actor/utils.js +0 -15
- package/dist/cjs/actor/view.js +0 -294
- package/dist/cjs/actor/views.js +0 -209
- package/dist/cjs/source.js +0 -27
- package/dist/cjs/util/proxy.js +0 -88
- package/dist/cjs/util/trackers.js +0 -88
- package/dist/cjs/workflow/affiliations.js +0 -140
- package/dist/cjs/workflow/answer-based.js +0 -337
- package/dist/cjs/workflow/ask.js +0 -319
- package/dist/cjs/workflow/asks.js +0 -150
- package/dist/cjs/workflow/autocompletable.js +0 -63
- package/dist/cjs/workflow/autocomplete.js +0 -120
- package/dist/cjs/workflow/base.js +0 -418
- package/dist/cjs/workflow/context.js +0 -19
- package/dist/cjs/workflow/explore.js +0 -210
- package/dist/cjs/workflow/explores.js +0 -21
- package/dist/cjs/workflow/hybrid-search-answer.js +0 -88
- package/dist/cjs/workflow/hybrid-search-views.js +0 -109
- package/dist/cjs/workflow/hybrid-search.js +0 -213
- package/dist/cjs/workflow/index.js +0 -41
- package/dist/cjs/workflow/options/api.js +0 -41
- package/dist/cjs/workflow/options/auto-query.js +0 -97
- package/dist/cjs/workflow/options/configurable.js +0 -45
- package/dist/cjs/workflow/options/data-processor.js +0 -20
- package/dist/cjs/workflow/options/filters.js +0 -15
- package/dist/cjs/workflow/options/index.js +0 -126
- package/dist/cjs/workflow/options/interactions.js +0 -41
- package/dist/cjs/workflow/options/layouts.js +0 -79
- package/dist/cjs/workflow/options/options.js +0 -156
- package/dist/cjs/workflow/options/pagination.js +0 -25
- package/dist/cjs/workflow/options/roles.js +0 -15
- package/dist/cjs/workflow/options/templates.js +0 -30
- package/dist/cjs/workflow/options/trackers.js +0 -83
- package/dist/cjs/workflow/options/utils.js +0 -33
- package/dist/cjs/workflow/processors.js +0 -607
- package/dist/cjs/workflow/recommendation.js +0 -57
- package/dist/cjs/workflow/recommendations.js +0 -18
- package/dist/cjs/workflow/search-based.js +0 -337
- package/dist/cjs/workflow/search.js +0 -64
- package/dist/cjs/workflow/unit.js +0 -57
- package/dist/cjs/workflow/units.js +0 -42
- package/dist/cjs/workflow/use-link.js +0 -49
- package/src/actor/data.js +0 -106
- package/src/actor/feedback.js +0 -28
- package/src/actor/fields.js +0 -51
- package/src/actor/filters.js +0 -149
- package/src/actor/hub.js +0 -47
- package/src/actor/index.js +0 -10
- package/src/actor/interactions.js +0 -32
- package/src/actor/sessions.js +0 -21
- package/src/actor/tracker-states.js +0 -57
- package/src/actor/tracker.js +0 -104
- package/src/actor/trackers.js +0 -45
- package/src/actor/utils.js +0 -7
- package/src/actor/view.js +0 -272
- package/src/actor/views.js +0 -224
- package/src/source.js +0 -17
- package/src/util/proxy.js +0 -81
- package/src/util/trackers.js +0 -84
- package/src/workflow/affiliations.js +0 -121
- package/src/workflow/answer-based.js +0 -312
- package/src/workflow/ask.js +0 -284
- package/src/workflow/asks.js +0 -143
- package/src/workflow/autocompletable.js +0 -67
- package/src/workflow/autocomplete.js +0 -114
- package/src/workflow/base.js +0 -396
- package/src/workflow/context.js +0 -16
- package/src/workflow/explore.js +0 -194
- package/src/workflow/explores.js +0 -18
- package/src/workflow/hybrid-search-answer.js +0 -73
- package/src/workflow/hybrid-search-views.js +0 -116
- package/src/workflow/hybrid-search.js +0 -230
- package/src/workflow/index.js +0 -5
- package/src/workflow/options/api.js +0 -31
- package/src/workflow/options/auto-query.js +0 -70
- package/src/workflow/options/configurable.js +0 -48
- package/src/workflow/options/data-processor.js +0 -15
- package/src/workflow/options/filters.js +0 -10
- package/src/workflow/options/index.js +0 -11
- package/src/workflow/options/interactions.js +0 -36
- package/src/workflow/options/layouts.js +0 -73
- package/src/workflow/options/options.js +0 -175
- package/src/workflow/options/pagination.js +0 -18
- package/src/workflow/options/roles.js +0 -12
- package/src/workflow/options/templates.js +0 -27
- package/src/workflow/options/trackers.js +0 -80
- package/src/workflow/options/utils.js +0 -26
- package/src/workflow/processors.js +0 -490
- package/src/workflow/recommendation.js +0 -63
- package/src/workflow/recommendations.js +0 -14
- package/src/workflow/search-based.js +0 -329
- package/src/workflow/search.js +0 -73
- package/src/workflow/unit.js +0 -51
- package/src/workflow/units.js +0 -43
- package/src/workflow/use-link.js +0 -41
|
@@ -1,337 +0,0 @@
|
|
|
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 _index2 = require("../layout/index.js");
|
|
12
|
-
var _affiliations = require("./affiliations.js");
|
|
13
|
-
var _index3 = require("./options/index.js");
|
|
14
|
-
var _processors = require("./processors.js");
|
|
15
|
-
var _useLink = require("./use-link.js");
|
|
16
|
-
var _trackers = require("../util/trackers.js");
|
|
17
|
-
const _excluded = ["event"];
|
|
18
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
20
|
-
const DEFAULT_API_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_API_OPTIONS, {
|
|
21
|
-
group: _commons.API.GROUP.ASK,
|
|
22
|
-
payload: Object.assign({}, _base.default.DEFAULT_API_OPTIONS.payload, {
|
|
23
|
-
source_fl: ['cover_image', 'url', 'created_at', 'updated_at', 'published_at'],
|
|
24
|
-
cite_link: 1,
|
|
25
|
-
cite_start: '[',
|
|
26
|
-
cite_end: ']'
|
|
27
|
-
})
|
|
28
|
-
}));
|
|
29
|
-
const DEFAULT_AUTOCOMPLETE_OPTIONS = Object.freeze({
|
|
30
|
-
actor: false,
|
|
31
|
-
api: {
|
|
32
|
-
group: _commons.API.GROUP.ASK,
|
|
33
|
-
name: _commons.API.NAME.AUTOCOMPLETE
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _base.default.DEFAULT_LAYOUTS, {
|
|
37
|
-
[_constants.ROLE.QUERY]: [_index2.SearchBoxLayout.type, {
|
|
38
|
-
placeholder: 'Ask a question'
|
|
39
|
-
}],
|
|
40
|
-
[_constants.ROLE.QUESTION]: [_index2.TextLayout.type, {
|
|
41
|
-
tag: 'h2'
|
|
42
|
-
}],
|
|
43
|
-
[_constants.ROLE.ANSWER]: _index2.TypewriterLayout.type,
|
|
44
|
-
[_constants.ROLE.FEEDBACK]: _index2.FeedbackLayout.type,
|
|
45
|
-
[_constants.ROLE.IMAGES]: [_index2.GalleryLayout.type, {
|
|
46
|
-
incremental: true,
|
|
47
|
-
itemType: 'image'
|
|
48
|
-
}],
|
|
49
|
-
[_constants.ROLE.SOURCES]: [_index2.ListLayout.type, {
|
|
50
|
-
incremental: true,
|
|
51
|
-
itemType: 'article',
|
|
52
|
-
templates: {
|
|
53
|
-
ordered: true
|
|
54
|
-
}
|
|
55
|
-
}],
|
|
56
|
-
[_constants.ROLE.AFFILIATION]: [_index2.AffiliationLayout.type, {
|
|
57
|
-
incremental: true,
|
|
58
|
-
itemType: 'affiliation',
|
|
59
|
-
link: {
|
|
60
|
-
rel: 'noopener nofollow'
|
|
61
|
-
}
|
|
62
|
-
}]
|
|
63
|
-
}));
|
|
64
|
-
const DEFAULT_TRACKERS = Object.freeze(Object.assign({}, _base.default.DEFAULT_TRACKERS, {
|
|
65
|
-
[_constants.ROLE.ANSWER]: {
|
|
66
|
-
active: true,
|
|
67
|
-
itemless: true,
|
|
68
|
-
deduplicated: false,
|
|
69
|
-
click: _index3.DEFAULT_TRACKER_OPTIONS.click // click only
|
|
70
|
-
},
|
|
71
|
-
[_constants.ROLE.IMAGES]: _index3.DEFAULT_TRACKER_OPTIONS,
|
|
72
|
-
[_constants.ROLE.SOURCES]: _index3.DEFAULT_TRACKER_OPTIONS,
|
|
73
|
-
[_constants.ROLE.AFFILIATION]: _index3.DEFAULT_TRACKER_OPTIONS,
|
|
74
|
-
[_constants.ROLE.PRODUCTS]: _index3.DEFAULT_TRACKER_OPTIONS
|
|
75
|
-
}));
|
|
76
|
-
const DEFAULT_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_OPTIONS, {
|
|
77
|
-
api: DEFAULT_API_OPTIONS,
|
|
78
|
-
autocomplete: DEFAULT_AUTOCOMPLETE_OPTIONS,
|
|
79
|
-
layouts: DEFAULT_LAYOUTS,
|
|
80
|
-
trackers: DEFAULT_TRACKERS
|
|
81
|
-
}));
|
|
82
|
-
const ROLES_OPTIONS = (0, _index3.mergeRolesOptions)(_base.default.ROLES_OPTIONS, {
|
|
83
|
-
main: _constants.ROLE.ANSWER,
|
|
84
|
-
members: Object.keys(DEFAULT_LAYOUTS),
|
|
85
|
-
mappings: {
|
|
86
|
-
[_constants.ROLE.ANSWER]: _processors.mappingAnswerData,
|
|
87
|
-
[_constants.ROLE.REASONING]: _processors.mappingReasoningData
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
class AnswerBasedWorkflow extends _base.default {
|
|
91
|
-
// constructor //
|
|
92
|
-
_initProperties(args) {
|
|
93
|
-
super._initProperties(args);
|
|
94
|
-
this._questionId = undefined;
|
|
95
|
-
this._autoQuery = false;
|
|
96
|
-
}
|
|
97
|
-
_initActors(args) {
|
|
98
|
-
super._initActors(args);
|
|
99
|
-
this._feedback = new _index.FeedbackActor(this._hub);
|
|
100
|
-
}
|
|
101
|
-
_initSubscriptions(args) {
|
|
102
|
-
super._initSubscriptions(args);
|
|
103
|
-
this._unsubscribes = [...this._unsubscribes, this._hub.on(_index.fields.query(), args => this._query(args)), this._views.on(_constants.ROLE.ANSWER, 'citation-click', event => this._onCitationClick(event)), this._views.on(_constants.ROLE.ANSWER, 'link-click', event => this._onAnswerLinkClick(event))];
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// lifecycle //
|
|
107
|
-
restart() {
|
|
108
|
-
// clear question id from previous session
|
|
109
|
-
if (this._questionId) {
|
|
110
|
-
this._questionId = undefined;
|
|
111
|
-
}
|
|
112
|
-
// restart
|
|
113
|
-
super.restart();
|
|
114
|
-
}
|
|
115
|
-
_shallEmitLifecycleEvent(name, event) {
|
|
116
|
-
return name === 'answer-stage' || super._shallEmitLifecycleEvent(name, event);
|
|
117
|
-
}
|
|
118
|
-
_emitInterruptEventIfNecessary() {
|
|
119
|
-
const state = this._hub.states[_index.fields.view(this._roles.main)] || {};
|
|
120
|
-
if (state.session && state.status !== _constants.STATUS.INITIAL && (state.status !== _constants.STATUS.READY || state.ongoing)) {
|
|
121
|
-
// it's interrupted by a new question
|
|
122
|
-
this._emitLifecycleEvent('interrupt', state);
|
|
123
|
-
this._emitLifecycleEvent('finally', state);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
_onMainViewUpdate(state) {
|
|
127
|
-
const {
|
|
128
|
-
status,
|
|
129
|
-
session
|
|
130
|
-
} = state;
|
|
131
|
-
const done = status === _constants.STATUS.READY && !state.ongoing;
|
|
132
|
-
const erroneous = status === _constants.STATUS.ERRONEOUS;
|
|
133
|
-
const eventName = done ? 'done' : erroneous ? 'error' : status;
|
|
134
|
-
|
|
135
|
-
// answer-stage
|
|
136
|
-
const context = this._getSessionContext(session);
|
|
137
|
-
const oldAnswerStage = context.answerStage;
|
|
138
|
-
const newAnswerStage = state.meta && state.meta.answer_stage;
|
|
139
|
-
if (newAnswerStage && newAnswerStage !== oldAnswerStage) {
|
|
140
|
-
this._emitLifecycleEvent('answer-stage', Object.freeze(Object.assign({}, state, {
|
|
141
|
-
answer_stage: newAnswerStage
|
|
142
|
-
})));
|
|
143
|
-
context.answerStage = newAnswerStage;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// blocked reason
|
|
147
|
-
const data = this._hub.states[_index.fields.data()] || {};
|
|
148
|
-
const {
|
|
149
|
-
value
|
|
150
|
-
} = data;
|
|
151
|
-
if (value) {
|
|
152
|
-
const {
|
|
153
|
-
blocked_reason
|
|
154
|
-
} = value;
|
|
155
|
-
if (blocked_reason) {
|
|
156
|
-
this._emitLifecycleEvent('blocked', Object.assign({}, state, {
|
|
157
|
-
blockedReason: blocked_reason
|
|
158
|
-
}));
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// ready, done, or error
|
|
163
|
-
this._emitLifecycleEvent(eventName, state);
|
|
164
|
-
if (done || erroneous) {
|
|
165
|
-
// finally
|
|
166
|
-
this._emitLifecycleEvent('finally', state);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// properties //
|
|
171
|
-
get questionId() {
|
|
172
|
-
return this._questionId;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// query //
|
|
176
|
-
autoQuery(options = {}) {
|
|
177
|
-
_index3.autoQuery.call(this, options);
|
|
178
|
-
}
|
|
179
|
-
query(args) {
|
|
180
|
-
// TODO: also accept "question", "questionSource"?
|
|
181
|
-
if (!args.q && !args.questionId) {
|
|
182
|
-
throw new Error(`q is required in query() call`);
|
|
183
|
-
}
|
|
184
|
-
this._hub.update(_index.fields.query(), args);
|
|
185
|
-
}
|
|
186
|
-
_query(args = {}) {
|
|
187
|
-
if (this._linkFn) {
|
|
188
|
-
this._submitToPage(args);
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
// start a new session
|
|
192
|
-
this.restart();
|
|
193
|
-
|
|
194
|
-
// keep track of question source on this session, for suggested questions interactions
|
|
195
|
-
this._writeQuestionSourceToSession(args);
|
|
196
|
-
|
|
197
|
-
// build payload and trigger request
|
|
198
|
-
const payload = this._buildPayload(args);
|
|
199
|
-
this._request({
|
|
200
|
-
payload
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
_writeQuestionSourceToSession(args) {
|
|
204
|
-
this.session.meta.question_source = args.qs || _constants.QUESTION_SOURCE.ORGANIC; // might be null, not undefined
|
|
205
|
-
}
|
|
206
|
-
_buildPayload() {
|
|
207
|
-
throw new Error(`Not implemented`);
|
|
208
|
-
}
|
|
209
|
-
_writeWikiLinkTemplateToPayload(payload) {
|
|
210
|
-
if (!this._autoQuery || !this._autoQuery.param || this._autoQuery.param === _index3.DEFAULT_AUTO_QUERY_PARAM) {
|
|
211
|
-
return payload;
|
|
212
|
-
}
|
|
213
|
-
return Object.assign({}, payload, {
|
|
214
|
-
wiki_link_template: `?${this._autoQuery.param}=%s`
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// data //
|
|
219
|
-
_updateData(data) {
|
|
220
|
-
// capture question ID and register at context
|
|
221
|
-
this._writeQuestionIdFromData(data);
|
|
222
|
-
|
|
223
|
-
// if it's the head response, write question id and return
|
|
224
|
-
if (data.value && !data.value.answer_stage) {
|
|
225
|
-
this._handleHeadResponse(data);
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
super._updateData(data);
|
|
229
|
-
|
|
230
|
-
// update URL if autoQuery.updateUrl is not false
|
|
231
|
-
_index3.updateQueryParametersInUrl.call(this, data);
|
|
232
|
-
}
|
|
233
|
-
_handleHeadResponse(data) {}
|
|
234
|
-
_defaultProcessData(data, oldData) {
|
|
235
|
-
data = super._defaultProcessData(data, oldData);
|
|
236
|
-
data = (0, _affiliations.processAffiliationData)(data);
|
|
237
|
-
data = (0, _processors.writeAnswerStageToMeta)(data);
|
|
238
|
-
return data;
|
|
239
|
-
}
|
|
240
|
-
_writeQuestionIdFromData({
|
|
241
|
-
value
|
|
242
|
-
}) {
|
|
243
|
-
value && this._writeQuestionId(value.question_id);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// interactions //
|
|
247
|
-
_defaultProcessInteraction(payload, args) {
|
|
248
|
-
payload = super._defaultProcessInteraction(payload, args);
|
|
249
|
-
payload = (0, _processors.writeAnswerInfoToInteraction)(payload, args);
|
|
250
|
-
return payload;
|
|
251
|
-
}
|
|
252
|
-
_getQuestionSourceFromViewState(args) {
|
|
253
|
-
const {
|
|
254
|
-
request
|
|
255
|
-
} = this._hub.states[_index.fields.view(args.role)] || {};
|
|
256
|
-
const {
|
|
257
|
-
payload
|
|
258
|
-
} = request || {};
|
|
259
|
-
return payload && payload.metadata && payload.metadata.question_source || undefined;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// handlers //
|
|
263
|
-
_onCitationClick({
|
|
264
|
-
index,
|
|
265
|
-
event
|
|
266
|
-
}) {
|
|
267
|
-
if (event.button !== 0) {
|
|
268
|
-
return; // only left click
|
|
269
|
-
}
|
|
270
|
-
if ((0, _trackers.isTracked)(event)) {
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
const {
|
|
274
|
-
value
|
|
275
|
-
} = this._hub.states[_index.fields.data()] || {};
|
|
276
|
-
const {
|
|
277
|
-
sources
|
|
278
|
-
} = value || {};
|
|
279
|
-
// index is 1-based
|
|
280
|
-
const source = sources && sources[index - 1];
|
|
281
|
-
if (!source || !source.product_id) {
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
// TODO: should we track impression as well?
|
|
285
|
-
(0, _trackers.markAsTracked)(event);
|
|
286
|
-
// distinguish from regular sources element click
|
|
287
|
-
this._views.trackers.sources.click([source.product_id], {
|
|
288
|
-
event_target: 'citation-link'
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
_onAnswerLinkClick(_ref) {
|
|
292
|
-
let {
|
|
293
|
-
event
|
|
294
|
-
} = _ref,
|
|
295
|
-
item = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
296
|
-
if (event.button !== 0) {
|
|
297
|
-
return; // only left click
|
|
298
|
-
}
|
|
299
|
-
if ((0, _trackers.isTracked)(event)) {
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
(0, _trackers.markAsTracked)(event);
|
|
303
|
-
// put everything into args and let _defaultProcessInteraction() handles it
|
|
304
|
-
// for it's hard to make it a standard item
|
|
305
|
-
this._views.trackers.answer.click([], {
|
|
306
|
-
items: [item]
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
// helpers //
|
|
311
|
-
_writeQuestionId(questionId) {
|
|
312
|
-
if (!this._questionId && questionId) {
|
|
313
|
-
this._questionId = questionId;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
_clearQuestionId() {
|
|
317
|
-
// clear question id from previous session
|
|
318
|
-
this._questionId = undefined;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// destroy //
|
|
322
|
-
_destroy(options) {
|
|
323
|
-
this._feedback._destroy();
|
|
324
|
-
// this._autocomplete._destroy();
|
|
325
|
-
super._destroy(options);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
exports.default = AnswerBasedWorkflow;
|
|
329
|
-
(0, _useLink.enableUseLink)(AnswerBasedWorkflow.prototype);
|
|
330
|
-
Object.assign(AnswerBasedWorkflow, {
|
|
331
|
-
DEFAULT_API_OPTIONS,
|
|
332
|
-
DEFAULT_AUTOCOMPLETE_OPTIONS,
|
|
333
|
-
DEFAULT_LAYOUTS,
|
|
334
|
-
DEFAULT_TRACKERS,
|
|
335
|
-
DEFAULT_OPTIONS,
|
|
336
|
-
ROLES_OPTIONS
|
|
337
|
-
});
|
package/dist/cjs/workflow/ask.js
DELETED
|
@@ -1,319 +0,0 @@
|
|
|
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 _answerBased = _interopRequireDefault(require("./answer-based.js"));
|
|
9
|
-
var _index = require("../actor/index.js");
|
|
10
|
-
var _constants = require("../constants.js");
|
|
11
|
-
var _index2 = require("../layout/index.js");
|
|
12
|
-
var _index3 = require("./options/index.js");
|
|
13
|
-
var _processors = require("./processors.js");
|
|
14
|
-
var _templates = require("../defaults/ask/templates.js");
|
|
15
|
-
var _autocompletable = require("./autocompletable.js");
|
|
16
|
-
const _excluded = ["q", "qs", "questionId"];
|
|
17
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
19
|
-
const DEFAULT_API_OPTIONS = Object.freeze(Object.assign({}, _answerBased.default.DEFAULT_API_OPTIONS, {
|
|
20
|
-
name: _commons.API.NAME.QUESTIONS,
|
|
21
|
-
payload: Object.assign({}, _answerBased.default.DEFAULT_API_OPTIONS.payload, {
|
|
22
|
-
related_resource_fl: ['cover_image', 'url', 'created_at', 'updated_at', 'published_at']
|
|
23
|
-
})
|
|
24
|
-
}));
|
|
25
|
-
const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _answerBased.default.DEFAULT_LAYOUTS, {
|
|
26
|
-
[_constants.ROLE.QUERY]: [_index2.SearchBoxLayout.type, {
|
|
27
|
-
templates: {
|
|
28
|
-
buttonIcon: 'send'
|
|
29
|
-
}
|
|
30
|
-
}],
|
|
31
|
-
[_constants.ROLE.REASONING]: _index2.TypewriterLayout.type,
|
|
32
|
-
[_constants.ROLE.RELATED_RESOURCES]: [_index2.ListLayout.type, {
|
|
33
|
-
incremental: true,
|
|
34
|
-
itemType: 'article'
|
|
35
|
-
}],
|
|
36
|
-
[_constants.ROLE.QUERY_SUGGESTIONS]: _index2.OptionListLayout.type,
|
|
37
|
-
[_constants.ROLE.FOLLOW_UP_QUESTIONS]: _index2.OptionListLayout.type
|
|
38
|
-
}));
|
|
39
|
-
const DEFAULT_TRACKERS = Object.freeze(Object.assign({}, _answerBased.default.DEFAULT_TRACKERS, {
|
|
40
|
-
[_constants.ROLE.RELATED_RESOURCES]: _index3.DEFAULT_TRACKER_OPTIONS,
|
|
41
|
-
[_constants.ROLE.QUERY_SUGGESTIONS]: Object.assign({}, _index3.DEFAULT_TRACKER_OPTIONS, {
|
|
42
|
-
click: Object.assign({}, _index3.DEFAULT_TRACKER_OPTIONS.click, {
|
|
43
|
-
validate: event => event.button === 0 // loosen criteria, for it's not a hyperlink
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
}));
|
|
47
|
-
const DEFAULT_TEMPLATES = Object.freeze({
|
|
48
|
-
followUp: _templates.followUp
|
|
49
|
-
});
|
|
50
|
-
const DEFAULT_AUTOCOMPLETE_OPTIONS = Object.freeze({
|
|
51
|
-
api: {
|
|
52
|
-
group: _commons.API.GROUP.ASK,
|
|
53
|
-
name: _commons.API.NAME.AUTOCOMPLETE
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
const DEFAULT_OPTIONS = Object.freeze(Object.assign({}, _answerBased.default.DEFAULT_OPTIONS, {
|
|
57
|
-
api: DEFAULT_API_OPTIONS,
|
|
58
|
-
layouts: DEFAULT_LAYOUTS,
|
|
59
|
-
trackers: DEFAULT_TRACKERS,
|
|
60
|
-
templates: DEFAULT_TEMPLATES,
|
|
61
|
-
autocomplete: DEFAULT_AUTOCOMPLETE_OPTIONS
|
|
62
|
-
}));
|
|
63
|
-
const ROLES_OPTIONS = (0, _index3.mergeRolesOptions)(_answerBased.default.ROLES_OPTIONS, {
|
|
64
|
-
members: Object.keys(DEFAULT_LAYOUTS),
|
|
65
|
-
mappings: {
|
|
66
|
-
[_constants.ROLE.QUERY_SUGGESTIONS]: _processors.mappingSuggestionsData,
|
|
67
|
-
[_constants.ROLE.FOLLOW_UP_QUESTIONS]: _processors.mappingFollowUpQuestionsData
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
class Ask extends _answerBased.default {
|
|
71
|
-
constructor(context, parentQuestionId) {
|
|
72
|
-
super({
|
|
73
|
-
name: 'ask',
|
|
74
|
-
context,
|
|
75
|
-
roles: ROLES_OPTIONS,
|
|
76
|
-
defaults: DEFAULT_OPTIONS,
|
|
77
|
-
parentQuestionId
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
_initProperties(args) {
|
|
81
|
-
super._initProperties(args);
|
|
82
|
-
this._initAutocomplete(args);
|
|
83
|
-
const {
|
|
84
|
-
parentQuestionId
|
|
85
|
-
} = args;
|
|
86
|
-
(0, _commons.defineValues)(this, {
|
|
87
|
-
parentQuestionId
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
_initSubscriptions(args) {
|
|
91
|
-
super._initSubscriptions(args);
|
|
92
|
-
this._unsubscribes = [...this._unsubscribes, this._hub.on(_index.fields.view(_constants.ROLE.REASONING), state => this._onReasoningViewUpdate(state)), this._views.on(_constants.ROLE.ANSWER, 'follow-up-click', event => this._onFollowUpClick(event)), this._views.on(_constants.ROLE.FOLLOW_UP_QUESTIONS, 'select', event => this._onFollowUpQuestionSelect(event)), this._views.on(_constants.ROLE.QUERY_SUGGESTIONS, 'select', event => this._onQuerySuggestionSelect(event))];
|
|
93
|
-
}
|
|
94
|
-
_initSession(args) {
|
|
95
|
-
// register at context
|
|
96
|
-
args.parentQuestionId && this._context._byPqid.set(args.parentQuestionId, this);
|
|
97
|
-
this._context._events.emit('create', this);
|
|
98
|
-
super._initSession(args);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// lifecycle //
|
|
102
|
-
restart() {
|
|
103
|
-
const {
|
|
104
|
-
next
|
|
105
|
-
} = this;
|
|
106
|
-
next && next.destroy();
|
|
107
|
-
if (this._questionId) {
|
|
108
|
-
this._context._byQid.delete(this._questionId);
|
|
109
|
-
}
|
|
110
|
-
super.restart();
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// properties //
|
|
114
|
-
get rootQuestionId() {
|
|
115
|
-
return this._context.root.questionId;
|
|
116
|
-
}
|
|
117
|
-
get previous() {
|
|
118
|
-
const {
|
|
119
|
-
parentQuestionId
|
|
120
|
-
} = this;
|
|
121
|
-
return parentQuestionId ? this._context.getByQuestionId(parentQuestionId) : undefined;
|
|
122
|
-
}
|
|
123
|
-
get next() {
|
|
124
|
-
const {
|
|
125
|
-
questionId
|
|
126
|
-
} = this;
|
|
127
|
-
return questionId ? this._context.getByParentQuestionId(questionId) : undefined;
|
|
128
|
-
}
|
|
129
|
-
getOrCreateNext() {
|
|
130
|
-
const {
|
|
131
|
-
questionId
|
|
132
|
-
} = this;
|
|
133
|
-
return questionId ? this._context.getByParentQuestionId(questionId, {
|
|
134
|
-
autoCreate: true
|
|
135
|
-
}) : undefined;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// query //
|
|
139
|
-
_buildPayload(_ref = {}) {
|
|
140
|
-
let {
|
|
141
|
-
q,
|
|
142
|
-
qs,
|
|
143
|
-
questionId
|
|
144
|
-
} = _ref,
|
|
145
|
-
options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
146
|
-
if (questionId) {
|
|
147
|
-
return (0, _commons.trimObj)(Object.assign({}, options, {
|
|
148
|
-
question_id: questionId
|
|
149
|
-
// TODO: specify this is a replayed session
|
|
150
|
-
}));
|
|
151
|
-
}
|
|
152
|
-
const {
|
|
153
|
-
parentQuestionId
|
|
154
|
-
} = this;
|
|
155
|
-
let payload = (0, _commons.trimObj)(Object.assign({}, options, {
|
|
156
|
-
question: q,
|
|
157
|
-
// question, not q
|
|
158
|
-
parent_question_id: parentQuestionId
|
|
159
|
-
}));
|
|
160
|
-
payload = (0, _processors.writeQuestionSourceToPayload)(Object.assign({}, payload, {
|
|
161
|
-
qs
|
|
162
|
-
}));
|
|
163
|
-
payload = this._writeWikiLinkTemplateToPayload(payload);
|
|
164
|
-
return payload;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// data //
|
|
168
|
-
_updateData(data) {
|
|
169
|
-
super._updateData(data);
|
|
170
|
-
this._triggerSuggestionsRefreshIfNecessary();
|
|
171
|
-
}
|
|
172
|
-
_triggerSuggestionsRefreshIfNecessary() {
|
|
173
|
-
const {
|
|
174
|
-
next
|
|
175
|
-
} = this;
|
|
176
|
-
if (!next) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
for (const view of next._views.getAll(_constants.ROLE.QUERY_SUGGESTIONS)) {
|
|
180
|
-
view.refresh();
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// view //
|
|
185
|
-
_onReasoningViewUpdate({
|
|
186
|
-
status,
|
|
187
|
-
ongoing
|
|
188
|
-
}) {
|
|
189
|
-
if (status !== _constants.STATUS.READY || ongoing) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
for (const view of this._views.getAll(_constants.ROLE.REASONING)) {
|
|
193
|
-
const element = view.element && view.element.closest('[data-role="reasoning-box"]');
|
|
194
|
-
element && element.classList.add('done');
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// interactions //
|
|
199
|
-
_defaultProcessInteraction(payload, args) {
|
|
200
|
-
payload = super._defaultProcessInteraction(payload, args);
|
|
201
|
-
payload = this._writeAdditionalAskPropertiesToInteraction(payload, args);
|
|
202
|
-
return payload;
|
|
203
|
-
}
|
|
204
|
-
_writeAdditionalAskPropertiesToInteraction(payload, args) {
|
|
205
|
-
const root_question_id = this.rootQuestionId;
|
|
206
|
-
let {
|
|
207
|
-
property
|
|
208
|
-
} = payload.context && payload.context.custom_context || {};
|
|
209
|
-
let question_id, parent_question_id, question_source;
|
|
210
|
-
if (args.role === _constants.ROLE.FOLLOW_UP_QUESTIONS || args.role === _constants.ROLE.QUERY_SUGGESTIONS) {
|
|
211
|
-
property = 'suggested_followup_questions';
|
|
212
|
-
}
|
|
213
|
-
if (args.role === _constants.ROLE.QUERY_SUGGESTIONS) {
|
|
214
|
-
parent_question_id = this.previous && this.previous.parentQuestionId;
|
|
215
|
-
question_id = this.parentQuestionId;
|
|
216
|
-
question_source = this.previous && this.previous.session.meta.question_source;
|
|
217
|
-
} else {
|
|
218
|
-
parent_question_id = this.parentQuestionId;
|
|
219
|
-
}
|
|
220
|
-
return (0, _commons.mergeInteractions)(payload, {
|
|
221
|
-
context: {
|
|
222
|
-
custom_context: (0, _commons.trimObj)({
|
|
223
|
-
// question_id, question_source can be undefined
|
|
224
|
-
property,
|
|
225
|
-
root_question_id,
|
|
226
|
-
parent_question_id,
|
|
227
|
-
question_id,
|
|
228
|
-
question_source
|
|
229
|
-
})
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// handlers //
|
|
235
|
-
_onFollowUpClick({
|
|
236
|
-
q,
|
|
237
|
-
event
|
|
238
|
-
} = {}) {
|
|
239
|
-
if (event.button !== 0) {
|
|
240
|
-
return; // only left click
|
|
241
|
-
}
|
|
242
|
-
this._submitFollowUpQuestion({
|
|
243
|
-
q,
|
|
244
|
-
qs: _constants.QUESTION_SOURCE.INLINE_QUESTION_LINK
|
|
245
|
-
});
|
|
246
|
-
// TODO: track click?
|
|
247
|
-
}
|
|
248
|
-
_onFollowUpQuestionSelect({
|
|
249
|
-
value: q
|
|
250
|
-
}) {
|
|
251
|
-
this._submitFollowUpQuestion({
|
|
252
|
-
q,
|
|
253
|
-
qs: _constants.QUESTION_SOURCE.SUGGESTED_QUESTIONS
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
_submitFollowUpQuestion({
|
|
257
|
-
q = '',
|
|
258
|
-
qs
|
|
259
|
-
} = {}) {
|
|
260
|
-
q = q.trim();
|
|
261
|
-
if (!q) {
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
const next = this.getOrCreateNext();
|
|
265
|
-
next.query({
|
|
266
|
-
q,
|
|
267
|
-
qs
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
_onQuerySuggestionSelect({
|
|
271
|
-
value: q
|
|
272
|
-
}) {
|
|
273
|
-
if (!q) {
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
// backward compatible: query on current workflow
|
|
277
|
-
this.query({
|
|
278
|
-
q,
|
|
279
|
-
qs: _constants.QUESTION_SOURCE.SUGGESTED_QUESTIONS
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// helpers //
|
|
284
|
-
_writeQuestionId(questionId) {
|
|
285
|
-
// capture question ID and register at context
|
|
286
|
-
if (!this._questionId && questionId) {
|
|
287
|
-
this._questionId = questionId;
|
|
288
|
-
this._context._byQid.set(questionId, this);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
_clearQuestionId() {
|
|
292
|
-
// clear question id from previous session
|
|
293
|
-
if (this._questionId) {
|
|
294
|
-
this._context._byQid.delete(this._questionId);
|
|
295
|
-
this._questionId = undefined;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
// destroy //
|
|
300
|
-
_destroy(options) {
|
|
301
|
-
const {
|
|
302
|
-
next,
|
|
303
|
-
parentQuestionId,
|
|
304
|
-
questionId
|
|
305
|
-
} = this;
|
|
306
|
-
if (next) {
|
|
307
|
-
next.destroy(options);
|
|
308
|
-
}
|
|
309
|
-
if (parentQuestionId) {
|
|
310
|
-
this._context._byPqid.delete(parentQuestionId);
|
|
311
|
-
}
|
|
312
|
-
if (questionId) {
|
|
313
|
-
this._context._byQid.delete(questionId);
|
|
314
|
-
}
|
|
315
|
-
super._destroy(options);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
exports.default = Ask;
|
|
319
|
-
(0, _autocompletable.makeAutocompletable)(Ask.prototype);
|