@miso.ai/client-sdk-ui 1.13.2-beta.0 → 1.14.0-beta.2
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 +15 -4
- package/dist/cjs/combo/ask/index.js +2 -2
- package/dist/cjs/constants.js +118 -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 +169 -0
- package/dist/cjs/element/container/index.js +14 -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-recommendation.js +1 -1
- package/dist/cjs/element/container/miso-search.js +1 -1
- package/dist/cjs/element/context/miso-follow-ups.js +1 -1
- package/dist/cjs/element/role/index.js +42 -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 +130 -0
- package/dist/cjs/layout/button/checkbox.js +115 -0
- package/dist/cjs/layout/button/more-button.js +3 -3
- package/dist/cjs/layout/container/container.js +1 -1
- package/dist/cjs/layout/error/error.js +2 -1
- package/dist/cjs/layout/index.js +28 -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 +42 -9
- 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 +5 -0
- 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 +346 -0
- package/dist/cjs/layout/list/threads.js +257 -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 +70 -0
- package/dist/cjs/layout/text/text.js +2 -1
- package/dist/cjs/layout/text/typewriter/index.js +4 -2
- package/dist/cjs/plugin.js +43 -104
- package/dist/cjs/util/confirm.js +33 -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 +48 -105
- package/src/asset/svgs.js +14 -3
- package/src/combo/ask/index.js +2 -2
- package/src/constants.js +37 -147
- package/src/defaults/ask/controls.js +1 -1
- package/src/defaults/hybrid-search/answer-box.js +2 -2
- package/src/defaults.js +107 -0
- package/src/element/container/index.js +2 -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-recommendation.js +1 -1
- package/src/element/container/miso-search.js +1 -1
- package/src/element/context/miso-follow-ups.js +1 -1
- package/src/element/role/index.js +6 -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 +116 -0
- package/src/layout/button/checkbox.js +91 -0
- package/src/layout/button/more-button.js +3 -3
- package/src/layout/container/container.js +2 -2
- package/src/layout/error/error.js +2 -1
- package/src/layout/index.js +4 -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 +41 -6
- 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 +6 -1
- 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 +318 -0
- package/src/layout/list/threads.js +206 -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 +62 -0
- package/src/layout/text/text.js +2 -1
- package/src/layout/text/typewriter/index.js +5 -3
- package/src/plugin.js +31 -117
- package/src/util/confirm.js +28 -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
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);
|
|
@@ -1,150 +0,0 @@
|
|
|
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 _context = _interopRequireDefault(require("./context.js"));
|
|
9
|
-
var _ask = _interopRequireDefault(require("./ask.js"));
|
|
10
|
-
var _index = require("./options/index.js");
|
|
11
|
-
var _autocompletable = require("./autocompletable.js");
|
|
12
|
-
const _excluded = ["root", "events"];
|
|
13
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
-
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; }
|
|
15
|
-
const DEFAULT_AUTO_NEXT_OPTIONS = {
|
|
16
|
-
event: 'done'
|
|
17
|
-
};
|
|
18
|
-
function autoNextOptionsAsPredicate(options = DEFAULT_AUTO_NEXT_OPTIONS) {
|
|
19
|
-
if (options === true) {
|
|
20
|
-
options = DEFAULT_AUTO_NEXT_OPTIONS;
|
|
21
|
-
}
|
|
22
|
-
if (typeof options === 'string') {
|
|
23
|
-
options = {
|
|
24
|
-
event: options
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
switch (typeof options) {
|
|
28
|
-
case 'object':
|
|
29
|
-
// TODO: support more options
|
|
30
|
-
return event => event && options.event === event._event;
|
|
31
|
-
case 'function':
|
|
32
|
-
return options;
|
|
33
|
-
default:
|
|
34
|
-
return () => false;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
class Asks extends _context.default {
|
|
38
|
-
constructor(plugin, client) {
|
|
39
|
-
super('asks', plugin, client);
|
|
40
|
-
this._initAutocompleteContext(); // must be earlier than root workflow
|
|
41
|
-
this._byQid = new Map();
|
|
42
|
-
this._byPqid = new Map();
|
|
43
|
-
this._root = new _ask.default(this); // initialize with default workflow
|
|
44
|
-
client._events.emit('postworkflow', this._root);
|
|
45
|
-
this._events.on('*', event => this._createNextIfNecessary(event));
|
|
46
|
-
this._events.on('loading', event => this._setActive(event.workflow));
|
|
47
|
-
this._events.on('destroy', () => this._requestEmitAfterDestroy());
|
|
48
|
-
this._events.on('after-destroy', () => this._syncActiveOnAfterDestroy());
|
|
49
|
-
this._autoNextFn = undefined;
|
|
50
|
-
this._active = this._root;
|
|
51
|
-
}
|
|
52
|
-
get root() {
|
|
53
|
-
return this._root;
|
|
54
|
-
}
|
|
55
|
-
get workflows() {
|
|
56
|
-
return [this._root, ...this._byPqid.values()];
|
|
57
|
-
}
|
|
58
|
-
get active() {
|
|
59
|
-
return this._active;
|
|
60
|
-
}
|
|
61
|
-
getByQuestionId(questionId) {
|
|
62
|
-
if (typeof questionId !== 'string') {
|
|
63
|
-
throw new Error(`Required ID to be a string: ${questionId}`);
|
|
64
|
-
}
|
|
65
|
-
return this._byQid.get(questionId);
|
|
66
|
-
}
|
|
67
|
-
getByParentQuestionId(parentQuestionId, {
|
|
68
|
-
autoCreate = false
|
|
69
|
-
} = {}) {
|
|
70
|
-
if (parentQuestionId === undefined) {
|
|
71
|
-
return this._root;
|
|
72
|
-
}
|
|
73
|
-
if (typeof parentQuestionId !== 'string') {
|
|
74
|
-
throw new Error(`Required ID to be a string: ${parentQuestionId}`);
|
|
75
|
-
}
|
|
76
|
-
let workflow = this._byPqid.get(parentQuestionId);
|
|
77
|
-
if (!workflow && autoCreate) {
|
|
78
|
-
workflow = new _ask.default(this, parentQuestionId);
|
|
79
|
-
this._client._events.emit('postworkflow', workflow);
|
|
80
|
-
}
|
|
81
|
-
return workflow;
|
|
82
|
-
}
|
|
83
|
-
reset(_ref = {}) {
|
|
84
|
-
let {
|
|
85
|
-
root = true,
|
|
86
|
-
events
|
|
87
|
-
} = _ref,
|
|
88
|
-
options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
89
|
-
// clear event listeners on context
|
|
90
|
-
if (events === undefined) {
|
|
91
|
-
events = !!root; // events are default to be true only when root = true
|
|
92
|
-
}
|
|
93
|
-
if (events) {
|
|
94
|
-
this._events.clear();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// destroy all follow-up workflows
|
|
98
|
-
for (const workflow of this._byPqid.values()) {
|
|
99
|
-
workflow.destroy(options);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// reset root workflow
|
|
103
|
-
if (root) {
|
|
104
|
-
this._root.restart();
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
autoNext(options) {
|
|
108
|
-
this._autoNextFn = autoNextOptionsAsPredicate(options);
|
|
109
|
-
}
|
|
110
|
-
_createNextIfNecessary(event) {
|
|
111
|
-
if (!this._autoNextFn || !this._autoNextFn(event)) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
const {
|
|
115
|
-
workflow
|
|
116
|
-
} = event;
|
|
117
|
-
workflow && workflow.getOrCreateNext();
|
|
118
|
-
}
|
|
119
|
-
_requestEmitAfterDestroy() {
|
|
120
|
-
if (this._emitAfterDestroyRequested) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
this._emitAfterDestroyRequested = true;
|
|
124
|
-
setTimeout(() => {
|
|
125
|
-
this._emitAfterDestroyRequested = false;
|
|
126
|
-
this._events.emit('after-destroy', {});
|
|
127
|
-
}, 0);
|
|
128
|
-
}
|
|
129
|
-
_syncActiveOnAfterDestroy() {
|
|
130
|
-
if (!this._active.destroyed) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
// find last non-initial workflow or root
|
|
134
|
-
let workflow = this._root;
|
|
135
|
-
for (; workflow.next && workflow.next.status !== _constants.STATUS.INITIAL; workflow = workflow.next) {}
|
|
136
|
-
this._setActive(workflow);
|
|
137
|
-
}
|
|
138
|
-
_setActive(workflow) {
|
|
139
|
-
if (workflow === this._active) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
this._active = workflow;
|
|
143
|
-
this._events.emit('active', {
|
|
144
|
-
workflow
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
exports.default = Asks;
|
|
149
|
-
(0, _index.makeConfigurable)(Asks.prototype, [_constants.WORKFLOW_CONFIGURABLE.TEMPLATES]);
|
|
150
|
-
(0, _autocompletable.makeAutocompletableContext)(Asks.prototype);
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.AutocompletableMixin = exports.AutocompletableContextMixin = void 0;
|
|
7
|
-
exports.makeAutocompletable = makeAutocompletable;
|
|
8
|
-
exports.makeAutocompletableContext = makeAutocompletableContext;
|
|
9
|
-
var _commons = require("@miso.ai/commons");
|
|
10
|
-
var _index = require("../actor/index.js");
|
|
11
|
-
var _autocomplete = _interopRequireDefault(require("./autocomplete.js"));
|
|
12
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
function makeAutocompletable(prototype) {
|
|
14
|
-
(0, _commons.mixin)(prototype, AutocompletableMixin.prototype);
|
|
15
|
-
}
|
|
16
|
-
function makeAutocompletableContext(prototype) {
|
|
17
|
-
(0, _commons.mixin)(prototype, AutocompletableContextMixin.prototype);
|
|
18
|
-
}
|
|
19
|
-
class AutocompletableMixin {
|
|
20
|
-
_initAutocomplete(args) {
|
|
21
|
-
this._autocomplete = new _autocomplete.default(this, {
|
|
22
|
-
defaults: args.defaults.autocomplete
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
get autocomplete() {
|
|
26
|
-
return this._autocomplete;
|
|
27
|
-
}
|
|
28
|
-
updateCompletions(data) {
|
|
29
|
-
this._hub.update(_index.fields.completions(), data);
|
|
30
|
-
return this;
|
|
31
|
-
}
|
|
32
|
-
_destroyAutocomplete() {
|
|
33
|
-
this._autocomplete && this._autocomplete._destroy();
|
|
34
|
-
this._autocomplete = undefined;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.AutocompletableMixin = AutocompletableMixin;
|
|
38
|
-
class AutocompletableContextMixin {
|
|
39
|
-
_initAutocompleteContext() {
|
|
40
|
-
this._autocomplete = new AutocompleteContext(this);
|
|
41
|
-
}
|
|
42
|
-
get autocomplete() {
|
|
43
|
-
return this._autocomplete;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
exports.AutocompletableContextMixin = AutocompletableContextMixin;
|
|
47
|
-
class AutocompleteContext {
|
|
48
|
-
constructor(context) {
|
|
49
|
-
this._context = context;
|
|
50
|
-
this._active = false;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// API //
|
|
54
|
-
get enabled() {
|
|
55
|
-
return this._active;
|
|
56
|
-
}
|
|
57
|
-
enable() {
|
|
58
|
-
this._active = true;
|
|
59
|
-
}
|
|
60
|
-
disable() {
|
|
61
|
-
this._active = false;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
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 (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
14
|
-
const ROLES_OPTIONS = Object.freeze({
|
|
15
|
-
members: []
|
|
16
|
-
});
|
|
17
|
-
function shimDefaults(_ref = {}) {
|
|
18
|
-
let options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
19
|
-
return Object.assign({}, options, {
|
|
20
|
-
layouts: {},
|
|
21
|
-
trackers: {}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
function sameInputValue(a, b) {
|
|
25
|
-
return getInputValue(a) === getInputValue(b);
|
|
26
|
-
}
|
|
27
|
-
function getInputValue(args) {
|
|
28
|
-
return args && args.value && args.value.trim() || undefined;
|
|
29
|
-
}
|
|
30
|
-
class Autocomplete extends _base.default {
|
|
31
|
-
constructor(superworkflow, _ref2 = {}) {
|
|
32
|
-
let {
|
|
33
|
-
defaults
|
|
34
|
-
} = _ref2,
|
|
35
|
-
args = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
36
|
-
super(Object.assign({
|
|
37
|
-
name: 'autocomplete',
|
|
38
|
-
plugin: superworkflow._plugin,
|
|
39
|
-
client: superworkflow._client,
|
|
40
|
-
defaults: shimDefaults(defaults),
|
|
41
|
-
roles: ROLES_OPTIONS,
|
|
42
|
-
superworkflow
|
|
43
|
-
}, args));
|
|
44
|
-
this._autocompleteContext = superworkflow && superworkflow._context && superworkflow._context.autocomplete;
|
|
45
|
-
}
|
|
46
|
-
_initProperties(args) {
|
|
47
|
-
super._initProperties(args);
|
|
48
|
-
this._superworkflow = args.superworkflow;
|
|
49
|
-
this._active = args.defaults.active;
|
|
50
|
-
}
|
|
51
|
-
_initSubscriptions(args) {
|
|
52
|
-
// TODO: how to sync options updates
|
|
53
|
-
super._initSubscriptions(args);
|
|
54
|
-
this._unsubscribes = [...this._unsubscribes, args.superworkflow._hub.on(_index.fields.input(), args => this._query(args))];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// API //
|
|
58
|
-
get enabled() {
|
|
59
|
-
return !!(this._active !== undefined ? this._active : this._autocompleteContext && this._autocompleteContext.enabled);
|
|
60
|
-
}
|
|
61
|
-
enable() {
|
|
62
|
-
this._active = true;
|
|
63
|
-
}
|
|
64
|
-
disable() {
|
|
65
|
-
this._active = false;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// query //
|
|
69
|
-
_query(args) {
|
|
70
|
-
if (!this.enabled || sameInputValue(args, this._args)) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
this._args = args;
|
|
74
|
-
|
|
75
|
-
// start a new session
|
|
76
|
-
this.restart();
|
|
77
|
-
const {
|
|
78
|
-
session
|
|
79
|
-
} = this;
|
|
80
|
-
session.meta.input = args;
|
|
81
|
-
|
|
82
|
-
// if input value is blank, emit empty response
|
|
83
|
-
if (!getInputValue(args)) {
|
|
84
|
-
this._updateCompletions({
|
|
85
|
-
session,
|
|
86
|
-
status: _constants.STATUS.INITIAL
|
|
87
|
-
});
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// payload
|
|
92
|
-
const payload = this._buildPayload(args);
|
|
93
|
-
|
|
94
|
-
// request
|
|
95
|
-
this._request({
|
|
96
|
-
payload
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
_buildPayload(args) {
|
|
100
|
-
return {
|
|
101
|
-
q: getInputValue(args)
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// data //
|
|
106
|
-
_updateDataInHub(data) {
|
|
107
|
-
if (data.value) {
|
|
108
|
-
data = Object.assign({}, data, {
|
|
109
|
-
value: data.value.completions
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
// update completion field in superworkflow hub
|
|
113
|
-
this._updateCompletions(data);
|
|
114
|
-
}
|
|
115
|
-
_updateCompletions(data) {
|
|
116
|
-
// TODO: session is different
|
|
117
|
-
this._superworkflow.updateCompletions(data);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
exports.default = Autocomplete;
|