@miso.ai/client-sdk-ui 1.9.10 → 1.10.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/actor/autocomplete.js +157 -0
- package/dist/cjs/actor/data.js +3 -11
- package/dist/cjs/actor/fields.js +8 -0
- package/dist/cjs/actor/index.js +7 -0
- package/dist/cjs/actor/utils.js +10 -0
- package/dist/cjs/defaults/ask/templates.js +21 -0
- package/dist/cjs/layout/input/search-box.js +213 -127
- package/dist/cjs/layout/list/collection.js +6 -1
- package/dist/cjs/layout/templates.js +50 -35
- package/dist/cjs/layout/text/typewriter/index.js +8 -53
- package/dist/cjs/source/index.js +20 -8
- package/dist/cjs/styles.js +4 -83
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/workflow/ask.js +48 -16
- package/dist/cjs/workflow/base.js +1 -2
- package/dist/cjs/workflow/explore.js +4 -1
- package/dist/cjs/workflow/options.js +54 -13
- package/dist/cjs/workflow/search.js +35 -7
- package/package.json +2 -2
- package/src/actor/autocomplete.js +131 -0
- package/src/actor/data.js +3 -10
- package/src/actor/fields.js +8 -0
- package/src/actor/index.js +1 -0
- package/src/actor/utils.js +8 -0
- package/src/defaults/ask/templates.js +21 -0
- package/src/layout/input/search-box.js +186 -94
- package/src/layout/list/collection.js +6 -1
- package/src/layout/templates.js +31 -25
- package/src/layout/text/typewriter/index.js +6 -46
- package/src/source/index.js +14 -1
- package/src/styles.js +4 -86
- package/src/version.js +1 -1
- package/src/workflow/ask.js +31 -1
- package/src/workflow/base.js +1 -2
- package/src/workflow/explore.js +1 -1
- package/src/workflow/options.js +49 -12
- package/src/workflow/search.js +33 -1
|
@@ -0,0 +1,157 @@
|
|
|
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 fields = _interopRequireWildcard(require("./fields.js"));
|
|
9
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
|
+
class AutocompleteActor {
|
|
12
|
+
constructor(hub, _ref) {
|
|
13
|
+
let {
|
|
14
|
+
source,
|
|
15
|
+
options
|
|
16
|
+
} = _ref;
|
|
17
|
+
this._hub = hub;
|
|
18
|
+
this._source = source;
|
|
19
|
+
this._options = options;
|
|
20
|
+
this._index = -1;
|
|
21
|
+
this._unsubscribes = [hub.on(fields.input(), () => this._sync()), options.on('autocomplete', () => this._syncOptions())];
|
|
22
|
+
|
|
23
|
+
// sync right away
|
|
24
|
+
this._sync(true);
|
|
25
|
+
}
|
|
26
|
+
get active() {
|
|
27
|
+
return this._options.resolved.autocomplete.actor !== false;
|
|
28
|
+
}
|
|
29
|
+
get source() {
|
|
30
|
+
return this._source;
|
|
31
|
+
}
|
|
32
|
+
_syncOptions() {
|
|
33
|
+
// TODO: explore scenarios where options.actor true -> false
|
|
34
|
+
this._sync(true);
|
|
35
|
+
}
|
|
36
|
+
async _sync() {
|
|
37
|
+
let force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
38
|
+
// protocol: inactive -> no reaction
|
|
39
|
+
if (!this.active) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const {
|
|
43
|
+
input
|
|
44
|
+
} = this._hub.states;
|
|
45
|
+
const value = input && input.value && input.value.trim() || undefined;
|
|
46
|
+
if (sameInput(this._input, input) && !force) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
this._input = input;
|
|
50
|
+
const index = ++this._index;
|
|
51
|
+
|
|
52
|
+
// new input, abort previous data fetch if any
|
|
53
|
+
this._clearTimeout();
|
|
54
|
+
this._abortPendingRequest({
|
|
55
|
+
type: 'new-input',
|
|
56
|
+
message: 'A new input renders previous autocomplete request obsolete.'
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// emit loading/initial state
|
|
60
|
+
this._emitCompletions({
|
|
61
|
+
index,
|
|
62
|
+
input,
|
|
63
|
+
status: value ? _constants.STATUS.LOADING : _constants.STATUS.INITIAL
|
|
64
|
+
});
|
|
65
|
+
if (!value) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
const response = await this._fetchCompletions(input);
|
|
70
|
+
if (this._index !== index) {
|
|
71
|
+
return; // new results loading, discard this one
|
|
72
|
+
}
|
|
73
|
+
this._emitCompletions({
|
|
74
|
+
index,
|
|
75
|
+
input,
|
|
76
|
+
status: _constants.STATUS.READY,
|
|
77
|
+
value: response.completions
|
|
78
|
+
});
|
|
79
|
+
} catch (error) {
|
|
80
|
+
this._error(error);
|
|
81
|
+
if (this._index !== index) {
|
|
82
|
+
return; // ignore
|
|
83
|
+
}
|
|
84
|
+
this._emitCompletions({
|
|
85
|
+
index,
|
|
86
|
+
input,
|
|
87
|
+
status: _constants.STATUS.ERRONEOUS,
|
|
88
|
+
error
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async _getCompletions(input) {
|
|
93
|
+
// TODO: cache
|
|
94
|
+
return await this._fetchCompletions(input);
|
|
95
|
+
}
|
|
96
|
+
async _fetchCompletions(_ref2) {
|
|
97
|
+
let {
|
|
98
|
+
value
|
|
99
|
+
} = _ref2;
|
|
100
|
+
// TODO: other options?
|
|
101
|
+
const {
|
|
102
|
+
api
|
|
103
|
+
} = this._options.resolved.autocomplete;
|
|
104
|
+
const {
|
|
105
|
+
group,
|
|
106
|
+
name
|
|
107
|
+
} = api;
|
|
108
|
+
const {
|
|
109
|
+
signal
|
|
110
|
+
} = this._ac || {};
|
|
111
|
+
const options = Object.assign({}, api.options, {
|
|
112
|
+
signal
|
|
113
|
+
});
|
|
114
|
+
const payload = Object.assign({}, api.payload, {
|
|
115
|
+
q: value
|
|
116
|
+
});
|
|
117
|
+
return await this._source({
|
|
118
|
+
group,
|
|
119
|
+
name,
|
|
120
|
+
payload,
|
|
121
|
+
options
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
_clearTimeout() {
|
|
125
|
+
if (this._timeoutId) {
|
|
126
|
+
clearTimeout(this._timeoutId);
|
|
127
|
+
this._timeoutId = undefined;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
_abortPendingRequest(info) {
|
|
131
|
+
this._ac && this._ac.abort(info);
|
|
132
|
+
this._ac = new AbortController();
|
|
133
|
+
}
|
|
134
|
+
_emitCompletions(event) {
|
|
135
|
+
event.source = 'actor';
|
|
136
|
+
this._hub.update(fields.completions(), event);
|
|
137
|
+
}
|
|
138
|
+
_error(error) {
|
|
139
|
+
// TODO
|
|
140
|
+
console.error(error);
|
|
141
|
+
}
|
|
142
|
+
_destroy() {
|
|
143
|
+
// abort ongoing data fetch if any
|
|
144
|
+
this._ac && this._ac.abort({
|
|
145
|
+
type: 'autocomplete-actor-destroy',
|
|
146
|
+
message: 'Autocomplete actor is destroyed.'
|
|
147
|
+
});
|
|
148
|
+
for (const unsubscribe of this._unsubscribes) {
|
|
149
|
+
unsubscribe();
|
|
150
|
+
}
|
|
151
|
+
this._unsubscribes = [];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.default = AutocompleteActor;
|
|
155
|
+
function sameInput(a, b) {
|
|
156
|
+
return !a && !b || a && b && a.value === b.value;
|
|
157
|
+
}
|
package/dist/cjs/actor/data.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var fields = _interopRequireWildcard(require("./fields.js"));
|
|
8
|
+
var _utils = require("./utils.js");
|
|
8
9
|
const _excluded = ["session"];
|
|
9
10
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
11
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -80,7 +81,7 @@ class DataActor {
|
|
|
80
81
|
let value;
|
|
81
82
|
for await (value of response) {
|
|
82
83
|
// A new session invalidates ongoing data fetch for the old session, terminating the loop
|
|
83
|
-
if (!this.
|
|
84
|
+
if (!(0, _utils.isCurrentSession)(this._hub, session)) {
|
|
84
85
|
break;
|
|
85
86
|
}
|
|
86
87
|
this._emitResponse({
|
|
@@ -107,16 +108,7 @@ class DataActor {
|
|
|
107
108
|
}
|
|
108
109
|
_emitResponseWithSessionCheck(response) {
|
|
109
110
|
// A new session invalidates ongoing data fetch
|
|
110
|
-
this.
|
|
111
|
-
}
|
|
112
|
-
_isCurrentSession(session) {
|
|
113
|
-
if (!session) {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
const {
|
|
117
|
-
session: currentSession
|
|
118
|
-
} = this._hub.states;
|
|
119
|
-
return currentSession && currentSession.index === session.index;
|
|
111
|
+
(0, _utils.isCurrentSession)(this._hub, response.session) && this._emitResponse(response);
|
|
120
112
|
}
|
|
121
113
|
_emitResponse(response) {
|
|
122
114
|
this._hub.update(fields.response(), response);
|
package/dist/cjs/actor/fields.js
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.completions = completions;
|
|
6
7
|
exports.data = data;
|
|
7
8
|
exports.event = event;
|
|
8
9
|
exports.feedback = feedback;
|
|
10
|
+
exports.input = input;
|
|
9
11
|
exports.interaction = interaction;
|
|
10
12
|
exports.query = query;
|
|
11
13
|
exports.request = request;
|
|
@@ -42,4 +44,10 @@ function interaction() {
|
|
|
42
44
|
}
|
|
43
45
|
function feedback() {
|
|
44
46
|
return 'feedback';
|
|
47
|
+
}
|
|
48
|
+
function input() {
|
|
49
|
+
return 'input';
|
|
50
|
+
}
|
|
51
|
+
function completions() {
|
|
52
|
+
return 'completions';
|
|
45
53
|
}
|
package/dist/cjs/actor/index.js
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "AutocompleteActor", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _autocomplete.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "DataActor", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function () {
|
|
@@ -54,6 +60,7 @@ var _data = _interopRequireDefault(require("./data.js"));
|
|
|
54
60
|
var _views = _interopRequireDefault(require("./views.js"));
|
|
55
61
|
var _trackers = _interopRequireDefault(require("./trackers.js"));
|
|
56
62
|
var _feedback = _interopRequireDefault(require("./feedback.js"));
|
|
63
|
+
var _autocomplete = _interopRequireDefault(require("./autocomplete.js"));
|
|
57
64
|
var _interactions = _interopRequireDefault(require("./interactions.js"));
|
|
58
65
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
59
66
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
package/dist/cjs/actor/utils.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.isCurrentSession = isCurrentSession;
|
|
6
7
|
exports.isProduct = isProduct;
|
|
7
8
|
exports.toInteraction = toInteraction;
|
|
8
9
|
var _commons = require("@miso.ai/commons");
|
|
@@ -50,4 +51,13 @@ function toInteraction(_ref, _ref2) {
|
|
|
50
51
|
}
|
|
51
52
|
});
|
|
52
53
|
return payload;
|
|
54
|
+
}
|
|
55
|
+
function isCurrentSession(hub, session) {
|
|
56
|
+
if (!session) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
const {
|
|
60
|
+
session: currentSession
|
|
61
|
+
} = hub.states;
|
|
62
|
+
return currentSession && currentSession.index === session.index;
|
|
53
63
|
}
|
|
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.followUp = followUp;
|
|
7
|
+
exports.helpers = void 0;
|
|
7
8
|
exports.root = root;
|
|
9
|
+
exports.sections = void 0;
|
|
8
10
|
var _commons = require("@miso.ai/commons");
|
|
9
11
|
var _constants = require("./constants.js");
|
|
10
12
|
var DEFAULT_PHRASES = _interopRequireWildcard(require("./phrases.js"));
|
|
@@ -39,6 +41,25 @@ function followUp() {
|
|
|
39
41
|
}, '<miso-query></miso-query>'), ...answerGroup(options)]);
|
|
40
42
|
}
|
|
41
43
|
;
|
|
44
|
+
const sections = exports.sections = Object.freeze({
|
|
45
|
+
followUps,
|
|
46
|
+
relatedResources,
|
|
47
|
+
querySuggestions,
|
|
48
|
+
answerGroup,
|
|
49
|
+
answer,
|
|
50
|
+
sources
|
|
51
|
+
});
|
|
52
|
+
const helpers = exports.helpers = Object.freeze({
|
|
53
|
+
normalizeOptions,
|
|
54
|
+
normalizePhraseOptions,
|
|
55
|
+
normalizePhraseOptionKey,
|
|
56
|
+
phrase,
|
|
57
|
+
phraseText,
|
|
58
|
+
section,
|
|
59
|
+
container,
|
|
60
|
+
element,
|
|
61
|
+
attrs
|
|
62
|
+
});
|
|
42
63
|
|
|
43
64
|
// options //
|
|
44
65
|
function normalizeOptions() {
|