@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.
Files changed (214) hide show
  1. package/dist/cjs/asset/svgs.js +15 -4
  2. package/dist/cjs/combo/ask/index.js +2 -2
  3. package/dist/cjs/constants.js +118 -98
  4. package/dist/cjs/defaults/ask/controls.js +1 -1
  5. package/dist/cjs/defaults/hybrid-search/answer-box.js +4 -4
  6. package/dist/cjs/defaults.js +169 -0
  7. package/dist/cjs/element/container/index.js +14 -0
  8. package/dist/cjs/element/container/miso-ask.js +3 -3
  9. package/dist/cjs/element/container/miso-conversation.js +21 -0
  10. package/dist/cjs/element/container/miso-explore.js +1 -1
  11. package/dist/cjs/element/container/miso-history.js +21 -0
  12. package/dist/cjs/element/container/miso-hybrid-search.js +1 -1
  13. package/dist/cjs/element/container/miso-recommendation.js +1 -1
  14. package/dist/cjs/element/container/miso-search.js +1 -1
  15. package/dist/cjs/element/context/miso-follow-ups.js +1 -1
  16. package/dist/cjs/element/role/index.js +42 -0
  17. package/dist/cjs/element/role/miso-messages.js +20 -0
  18. package/dist/cjs/element/role/miso-new-thread.js +20 -0
  19. package/dist/cjs/element/role/miso-rename.js +20 -0
  20. package/dist/cjs/element/role/miso-subscription.js +20 -0
  21. package/dist/cjs/element/role/miso-threads.js +20 -0
  22. package/dist/cjs/element/role/miso-title.js +20 -0
  23. package/dist/cjs/layout/affiliation/affiliation.js +1 -1
  24. package/dist/cjs/layout/banner/banner.js +2 -1
  25. package/dist/cjs/layout/button/button.js +130 -0
  26. package/dist/cjs/layout/button/checkbox.js +115 -0
  27. package/dist/cjs/layout/button/more-button.js +3 -3
  28. package/dist/cjs/layout/container/container.js +1 -1
  29. package/dist/cjs/layout/error/error.js +2 -1
  30. package/dist/cjs/layout/index.js +28 -0
  31. package/dist/cjs/layout/input/facets.js +4 -3
  32. package/dist/cjs/layout/input/option-list.js +3 -2
  33. package/dist/cjs/layout/input/search-box.js +42 -9
  34. package/dist/cjs/layout/input/select.js +2 -1
  35. package/dist/cjs/layout/list/cards.js +2 -1
  36. package/dist/cjs/layout/list/carousel.js +2 -1
  37. package/dist/cjs/layout/list/collection.js +5 -0
  38. package/dist/cjs/layout/list/gallery.js +2 -1
  39. package/dist/cjs/layout/list/horizontal.js +2 -1
  40. package/dist/cjs/layout/list/list.js +2 -1
  41. package/dist/cjs/layout/list/messages.js +346 -0
  42. package/dist/cjs/layout/list/threads.js +257 -0
  43. package/dist/cjs/layout/mixin/trackable.js +4 -5
  44. package/dist/cjs/layout/mixin/triggerable.js +2 -2
  45. package/dist/cjs/layout/radio/feedback.js +4 -3
  46. package/dist/cjs/layout/templates.js +70 -0
  47. package/dist/cjs/layout/text/text.js +2 -1
  48. package/dist/cjs/layout/text/typewriter/index.js +4 -2
  49. package/dist/cjs/plugin.js +43 -104
  50. package/dist/cjs/util/confirm.js +33 -0
  51. package/dist/cjs/util/modal.js +48 -0
  52. package/dist/cjs/util/prompt.js +47 -0
  53. package/dist/cjs/version.js +1 -1
  54. package/package.json +5 -4
  55. package/src/CLAUDE.md +48 -105
  56. package/src/asset/svgs.js +14 -3
  57. package/src/combo/ask/index.js +2 -2
  58. package/src/constants.js +37 -147
  59. package/src/defaults/ask/controls.js +1 -1
  60. package/src/defaults/hybrid-search/answer-box.js +2 -2
  61. package/src/defaults.js +107 -0
  62. package/src/element/container/index.js +2 -0
  63. package/src/element/container/miso-ask.js +3 -3
  64. package/src/element/container/miso-conversation.js +19 -0
  65. package/src/element/container/miso-explore.js +1 -1
  66. package/src/element/container/miso-history.js +19 -0
  67. package/src/element/container/miso-hybrid-search.js +1 -1
  68. package/src/element/container/miso-recommendation.js +1 -1
  69. package/src/element/container/miso-search.js +1 -1
  70. package/src/element/context/miso-follow-ups.js +1 -1
  71. package/src/element/role/index.js +6 -0
  72. package/src/element/role/miso-messages.js +16 -0
  73. package/src/element/role/miso-new-thread.js +16 -0
  74. package/src/element/role/miso-rename.js +16 -0
  75. package/src/element/role/miso-subscription.js +16 -0
  76. package/src/element/role/miso-threads.js +16 -0
  77. package/src/element/role/miso-title.js +16 -0
  78. package/src/layout/affiliation/affiliation.js +2 -2
  79. package/src/layout/banner/banner.js +2 -1
  80. package/src/layout/button/button.js +116 -0
  81. package/src/layout/button/checkbox.js +91 -0
  82. package/src/layout/button/more-button.js +3 -3
  83. package/src/layout/container/container.js +2 -2
  84. package/src/layout/error/error.js +2 -1
  85. package/src/layout/index.js +4 -0
  86. package/src/layout/input/facets.js +3 -2
  87. package/src/layout/input/option-list.js +3 -2
  88. package/src/layout/input/search-box.js +41 -6
  89. package/src/layout/input/select.js +2 -1
  90. package/src/layout/list/cards.js +2 -1
  91. package/src/layout/list/carousel.js +2 -1
  92. package/src/layout/list/collection.js +6 -1
  93. package/src/layout/list/gallery.js +2 -1
  94. package/src/layout/list/horizontal.js +2 -1
  95. package/src/layout/list/list.js +2 -1
  96. package/src/layout/list/messages.js +318 -0
  97. package/src/layout/list/threads.js +206 -0
  98. package/src/layout/mixin/trackable.js +2 -3
  99. package/src/layout/mixin/triggerable.js +1 -1
  100. package/src/layout/radio/feedback.js +3 -2
  101. package/src/layout/templates.js +62 -0
  102. package/src/layout/text/text.js +2 -1
  103. package/src/layout/text/typewriter/index.js +5 -3
  104. package/src/plugin.js +31 -117
  105. package/src/util/confirm.js +28 -0
  106. package/src/util/modal.js +49 -0
  107. package/src/util/prompt.js +42 -0
  108. package/src/version.js +1 -1
  109. package/dist/cjs/actor/data.js +0 -132
  110. package/dist/cjs/actor/feedback.js +0 -29
  111. package/dist/cjs/actor/fields.js +0 -57
  112. package/dist/cjs/actor/filters.js +0 -161
  113. package/dist/cjs/actor/hub.js +0 -57
  114. package/dist/cjs/actor/index.js +0 -73
  115. package/dist/cjs/actor/interactions.js +0 -36
  116. package/dist/cjs/actor/sessions.js +0 -25
  117. package/dist/cjs/actor/tracker-states.js +0 -61
  118. package/dist/cjs/actor/tracker.js +0 -109
  119. package/dist/cjs/actor/trackers.js +0 -52
  120. package/dist/cjs/actor/utils.js +0 -15
  121. package/dist/cjs/actor/view.js +0 -294
  122. package/dist/cjs/actor/views.js +0 -209
  123. package/dist/cjs/source.js +0 -27
  124. package/dist/cjs/util/proxy.js +0 -88
  125. package/dist/cjs/util/trackers.js +0 -88
  126. package/dist/cjs/workflow/affiliations.js +0 -140
  127. package/dist/cjs/workflow/answer-based.js +0 -337
  128. package/dist/cjs/workflow/ask.js +0 -319
  129. package/dist/cjs/workflow/asks.js +0 -150
  130. package/dist/cjs/workflow/autocompletable.js +0 -63
  131. package/dist/cjs/workflow/autocomplete.js +0 -120
  132. package/dist/cjs/workflow/base.js +0 -418
  133. package/dist/cjs/workflow/context.js +0 -19
  134. package/dist/cjs/workflow/explore.js +0 -210
  135. package/dist/cjs/workflow/explores.js +0 -21
  136. package/dist/cjs/workflow/hybrid-search-answer.js +0 -88
  137. package/dist/cjs/workflow/hybrid-search-views.js +0 -109
  138. package/dist/cjs/workflow/hybrid-search.js +0 -213
  139. package/dist/cjs/workflow/index.js +0 -41
  140. package/dist/cjs/workflow/options/api.js +0 -41
  141. package/dist/cjs/workflow/options/auto-query.js +0 -97
  142. package/dist/cjs/workflow/options/configurable.js +0 -45
  143. package/dist/cjs/workflow/options/data-processor.js +0 -20
  144. package/dist/cjs/workflow/options/filters.js +0 -15
  145. package/dist/cjs/workflow/options/index.js +0 -126
  146. package/dist/cjs/workflow/options/interactions.js +0 -41
  147. package/dist/cjs/workflow/options/layouts.js +0 -79
  148. package/dist/cjs/workflow/options/options.js +0 -156
  149. package/dist/cjs/workflow/options/pagination.js +0 -25
  150. package/dist/cjs/workflow/options/roles.js +0 -15
  151. package/dist/cjs/workflow/options/templates.js +0 -30
  152. package/dist/cjs/workflow/options/trackers.js +0 -83
  153. package/dist/cjs/workflow/options/utils.js +0 -33
  154. package/dist/cjs/workflow/processors.js +0 -607
  155. package/dist/cjs/workflow/recommendation.js +0 -57
  156. package/dist/cjs/workflow/recommendations.js +0 -18
  157. package/dist/cjs/workflow/search-based.js +0 -337
  158. package/dist/cjs/workflow/search.js +0 -64
  159. package/dist/cjs/workflow/unit.js +0 -57
  160. package/dist/cjs/workflow/units.js +0 -42
  161. package/dist/cjs/workflow/use-link.js +0 -49
  162. package/src/actor/data.js +0 -106
  163. package/src/actor/feedback.js +0 -28
  164. package/src/actor/fields.js +0 -51
  165. package/src/actor/filters.js +0 -149
  166. package/src/actor/hub.js +0 -47
  167. package/src/actor/index.js +0 -10
  168. package/src/actor/interactions.js +0 -32
  169. package/src/actor/sessions.js +0 -21
  170. package/src/actor/tracker-states.js +0 -57
  171. package/src/actor/tracker.js +0 -104
  172. package/src/actor/trackers.js +0 -45
  173. package/src/actor/utils.js +0 -7
  174. package/src/actor/view.js +0 -272
  175. package/src/actor/views.js +0 -224
  176. package/src/source.js +0 -17
  177. package/src/util/proxy.js +0 -81
  178. package/src/util/trackers.js +0 -84
  179. package/src/workflow/affiliations.js +0 -121
  180. package/src/workflow/answer-based.js +0 -312
  181. package/src/workflow/ask.js +0 -284
  182. package/src/workflow/asks.js +0 -143
  183. package/src/workflow/autocompletable.js +0 -67
  184. package/src/workflow/autocomplete.js +0 -114
  185. package/src/workflow/base.js +0 -396
  186. package/src/workflow/context.js +0 -16
  187. package/src/workflow/explore.js +0 -194
  188. package/src/workflow/explores.js +0 -18
  189. package/src/workflow/hybrid-search-answer.js +0 -73
  190. package/src/workflow/hybrid-search-views.js +0 -116
  191. package/src/workflow/hybrid-search.js +0 -230
  192. package/src/workflow/index.js +0 -5
  193. package/src/workflow/options/api.js +0 -31
  194. package/src/workflow/options/auto-query.js +0 -70
  195. package/src/workflow/options/configurable.js +0 -48
  196. package/src/workflow/options/data-processor.js +0 -15
  197. package/src/workflow/options/filters.js +0 -10
  198. package/src/workflow/options/index.js +0 -11
  199. package/src/workflow/options/interactions.js +0 -36
  200. package/src/workflow/options/layouts.js +0 -73
  201. package/src/workflow/options/options.js +0 -175
  202. package/src/workflow/options/pagination.js +0 -18
  203. package/src/workflow/options/roles.js +0 -12
  204. package/src/workflow/options/templates.js +0 -27
  205. package/src/workflow/options/trackers.js +0 -80
  206. package/src/workflow/options/utils.js +0 -26
  207. package/src/workflow/processors.js +0 -490
  208. package/src/workflow/recommendation.js +0 -63
  209. package/src/workflow/recommendations.js +0 -14
  210. package/src/workflow/search-based.js +0 -329
  211. package/src/workflow/search.js +0 -73
  212. package/src/workflow/unit.js +0 -51
  213. package/src/workflow/units.js +0 -43
  214. package/src/workflow/use-link.js +0 -41
@@ -1,109 +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 _constants = require("../constants.js");
9
- var fields = _interopRequireWildcard(require("./fields.js"));
10
- var _trackerStates = _interopRequireDefault(require("./tracker-states.js"));
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
13
- // a dummy item array for manipulating deduplication
14
- const ITEMLESS_DUMMY_ITEMS = [Symbol('itemless')];
15
- class Tracker {
16
- constructor({
17
- hub,
18
- role,
19
- options
20
- }) {
21
- this._hub = hub;
22
- this._role = role;
23
- this._options = options;
24
- // TODO: know item type
25
-
26
- this._states = new _trackerStates.default(this._getSessionId());
27
- }
28
- get options() {
29
- return typeof this._options === 'function' ? this._options() : this._options;
30
- }
31
- getState(item) {
32
- return this._states.getFullState(item);
33
- }
34
- _trigger(type, items, meta) {
35
- (0, _constants.validateEventType)(type);
36
- const {
37
- options
38
- } = this;
39
- if (!options || options.active === false) {
40
- return;
41
- }
42
- this._syncSession();
43
- const {
44
- deduplicated = true,
45
- itemless = false
46
- } = options;
47
- if (deduplicated) {
48
- if (itemless) {
49
- items = ITEMLESS_DUMMY_ITEMS;
50
- }
51
- items = this._states.untriggered((0, _commons.asArray)(items), type);
52
- if (items.length === 0) {
53
- return;
54
- }
55
- this._states.set(items, type, _constants.TRACKING_STATUS.TRIGGERED);
56
- }
57
- this._sendToHub(Object.assign({
58
- type,
59
- items: itemless ? undefined : items
60
- }, meta));
61
- }
62
- _sendToHub(args) {
63
- this._hub.trigger(fields.tracker(), Object.freeze((0, _commons.trimObj)(Object.assign({
64
- role: this._role
65
- }, args))));
66
- }
67
- _syncSession() {
68
- const sessionId = this._getSessionId();
69
- if (!sessionId) {
70
- return;
71
- }
72
- if (!this._states || sessionId !== this._states.sessionId) {
73
- this._states = new _trackerStates.default(sessionId);
74
- }
75
- }
76
- _getSessionId() {
77
- const {
78
- session
79
- } = this._getViewState() || {};
80
- return session && session.uuid;
81
- }
82
- _getMisoId() {
83
- const state = this._getViewState();
84
- return state && state.meta && state.meta.miso_id || undefined;
85
- }
86
- _getRequestPayload() {
87
- const {
88
- request
89
- } = this._getViewState() || {};
90
- return request && request.payload;
91
- }
92
- _getViewState() {
93
- return this._hub.states[fields.view(this._role)];
94
- }
95
- }
96
- exports.default = Tracker;
97
- for (const type of _constants.PERFORMANCE_EVENT_TYPES) {
98
- Tracker.prototype[(0, _commons.snakeToLowerCamel)(type)] = function (items, meta) {
99
- this._trigger(type, items, meta);
100
- };
101
- }
102
- for (const type of _constants.DIRECT_TRACKING_EVENT_TYPES) {
103
- Tracker.prototype[(0, _commons.snakeToLowerCamel)(type)] = function (args) {
104
- this._syncSession();
105
- this._sendToHub(Object.assign({}, args, {
106
- type
107
- }));
108
- };
109
- }
@@ -1,52 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.TrackersActor = void 0;
7
- exports.proxyTrackers = proxyTrackers;
8
- var _constants = require("../constants.js");
9
- var _tracker = _interopRequireDefault(require("./tracker.js"));
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- class TrackersActor {
12
- constructor(hub, {
13
- roles,
14
- options
15
- }) {
16
- this._hub = hub;
17
- this._roles = roles;
18
- this._options = options;
19
- this._trackers = {};
20
- }
21
- get(role) {
22
- if (!this._roles.members.includes(role)) {
23
- throw new Error(`Role "${role}" is not a member of this workflow.`);
24
- }
25
- if (!this._trackers[role]) {
26
- this._trackers[role] = new _tracker.default({
27
- hub: this._hub,
28
- role,
29
- itemless: role === _constants.ROLE.CONTAINER,
30
- options: () => this._getTrackerOptions(role)
31
- });
32
- }
33
- return this._trackers[role];
34
- }
35
- _getTrackerOptions(role) {
36
- const allTrackerOptions = this._options.resolved.trackers;
37
- return allTrackerOptions && allTrackerOptions[role] || {
38
- active: false
39
- };
40
- }
41
- }
42
- exports.TrackersActor = TrackersActor;
43
- function proxyTrackers(trackers) {
44
- return new Proxy(trackers, {
45
- get: (target, prop) => {
46
- try {
47
- return target.get(prop);
48
- } catch (_) {}
49
- return undefined;
50
- }
51
- });
52
- }
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isCurrentSession = isCurrentSession;
7
- function isCurrentSession(hub, session) {
8
- if (!session) {
9
- return false;
10
- }
11
- const {
12
- session: currentSession
13
- } = hub.states;
14
- return currentSession && currentSession.index === session.index;
15
- }
@@ -1,294 +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 _constants = require("../constants.js");
9
- var fields = _interopRequireWildcard(require("./fields.js"));
10
- var _proxy = _interopRequireDefault(require("../util/proxy.js"));
11
- const _excluded = ["value", "error", "status", "meta"];
12
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
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
- // TODO: browser dependency on syncSize
16
-
17
- function statesEqual(a, b) {
18
- return a === b || a && b && a.status === b.status && a.error === b.error && a.value === b.value &&
19
- // skip deep equals
20
- a.ongoing === b.ongoing && stateEmptyness(a) === stateEmptyness(b) &&
21
- // TODO: ad-hoc
22
- sessionEquals(a.session, b.session);
23
- }
24
- function sessionEquals(a, b) {
25
- return a === b || a && b && a.uuid === b.uuid;
26
- }
27
- function stateEmptyness(data) {
28
- return data && data.meta && data.meta.empty;
29
- }
30
- class ViewActor {
31
- constructor(views, role) {
32
- this._events = new _commons.EventEmitter({
33
- target: this
34
- });
35
- this._views = views;
36
- // TODO: we should pull this up to views, for the results are also used in judging container emptyness
37
- this._mapping = asMappingFunction((views._roles.mappings || {})[role] || role);
38
- (0, _commons.defineValues)(this, {
39
- role,
40
- interface: new View(this)
41
- });
42
- }
43
- get hub() {
44
- return this._views._hub;
45
- }
46
- get element() {
47
- return this._element;
48
- }
49
- set element(element) {
50
- if (element === this._element) {
51
- return;
52
- }
53
- if (this._element) {
54
- this._safeApplyOnLayout('unrender', this._element);
55
- }
56
- this._element = element;
57
- this._proxyElement && this._proxyElement.sync();
58
- this._events.emit('element', element);
59
- this.refresh({
60
- force: true
61
- });
62
- }
63
- get proxyElement() {
64
- if (!this._proxyElement) {
65
- this._proxyElement = new _proxy.default(() => this.element);
66
- }
67
- return this._proxyElement;
68
- }
69
- get layout() {
70
- return this._layout;
71
- }
72
- set layout(layout) {
73
- if (layout === this._layout) {
74
- return;
75
- }
76
- if (layout && typeof layout.render !== 'function') {
77
- throw new Error(`Render function is mandatory in a layout.`);
78
- }
79
-
80
- // clean up old layout
81
- const {
82
- element
83
- } = this;
84
- element && this._safeApplyOnLayout('unrender', element);
85
- this._safeApplyOnLayout('destroy');
86
- this._layout = layout;
87
-
88
- // initialize new layout
89
- if (layout) {
90
- layout._view = this;
91
- // don't use _safeApplyOnLayout, for any error should be thrown
92
- if (typeof layout.initialize === 'function') {
93
- layout.initialize(this);
94
- }
95
- }
96
-
97
- // in case the data is already there
98
- this.refresh({
99
- force: true
100
- });
101
- }
102
- get tracker() {
103
- return this._views.trackers[this.role];
104
- }
105
- get workflow() {
106
- return this._views._workflow;
107
- }
108
- get workflowOptions() {
109
- return this._views._options.resolved;
110
- }
111
- get trackerOptions() {
112
- return this._views._getTrackerOptions(this.role);
113
- }
114
- get filters() {
115
- return this._views.filters;
116
- }
117
- async refresh({
118
- force = false,
119
- data
120
- } = {}) {
121
- // protocol: no reaction when layout is absent
122
- if (!this._layout) {
123
- return;
124
- }
125
-
126
- // nothing to do when element is absent
127
- const {
128
- element
129
- } = this;
130
- if (!element) {
131
- return;
132
- }
133
-
134
- // sync data
135
- const previousData = this._data;
136
- this._data = data = this._sliceData(data || this._views._getData());
137
-
138
- // if data is unchanged, skip unless forced
139
- if (!force && statesEqual(data, previousData)) {
140
- return;
141
- }
142
- const {
143
- session,
144
- status,
145
- ongoing,
146
- request,
147
- meta,
148
- value
149
- } = data;
150
- const baseState = Object.assign({
151
- session,
152
- status,
153
- ongoing,
154
- request,
155
- meta,
156
- data: value
157
- }, getDataEmptyness(this.role, data));
158
-
159
- // render
160
- const notifyUpdate = (state = {}, options) => {
161
- state !== false && this.updateState(Object.assign({}, baseState, state), options);
162
- };
163
- try {
164
- await this._layout.render(element, data, {
165
- notifyUpdate
166
- });
167
- } catch (error) {
168
- this._error(error);
169
- notifyUpdate({
170
- error
171
- });
172
- }
173
- }
174
- updateState(state, {
175
- silent = false
176
- } = {}) {
177
- // there might be error from notifyUpdate() call
178
- const status = state.error ? _constants.STATUS.ERRONEOUS : state.status;
179
- state = this._state = Object.freeze((0, _commons.trimObj)(Object.assign({}, state, {
180
- status
181
- })));
182
- const {
183
- role
184
- } = this;
185
- this.hub.update(fields.view(role), state, {
186
- silent
187
- });
188
- }
189
- _sliceData(data) {
190
- const {
191
- value,
192
- status,
193
- meta
194
- } = data,
195
- rest = _objectWithoutPropertiesLoose(data, _excluded);
196
- const sliced = Object.assign({
197
- value: this._mapping(data, this),
198
- status,
199
- data: value,
200
- meta
201
- }, rest);
202
- if (this.role === _constants.ROLE.CONTAINER) {
203
- // pass empty/nonempty information
204
- sliced.meta = Object.assign({}, meta, {
205
- empty: this._isContainerEmpty(data)
206
- });
207
- }
208
- return (0, _commons.trimObj)(sliced);
209
- }
210
-
211
- // TODO: move this to workflow
212
- _isContainerEmpty(data) {
213
- const {
214
- element
215
- } = this;
216
- if (!element) {
217
- return false;
218
- }
219
- // iterate over all member components' roles
220
- for (const {
221
- role
222
- } of element.components) {
223
- // not a data role -> irrelevant
224
- if (!(0, _constants.isDataRole)(role)) {
225
- continue;
226
- }
227
- // respect data mapping
228
- const mapping = asMappingFunction((this._views._roles.mappings || {})[role] || role);
229
- const sliced = mapping(data, this); // TODO: the view passed in should be the view of the role, not container role
230
- if (!isDateValueEmpty(role, sliced)) {
231
- return false;
232
- }
233
- }
234
- return true;
235
- }
236
- _syncSize() {
237
- this._element && this._safeApplyOnLayout('syncSize', this._element);
238
- }
239
- _safeApplyOnLayout(method, ...args) {
240
- if (!this._layout || typeof this._layout[method] !== 'function') {
241
- return;
242
- }
243
- try {
244
- this._layout[method](...args);
245
- } catch (e) {
246
- this._error(e);
247
- }
248
- }
249
- _emit(name, data) {
250
- this._events.emit(name, data);
251
- this._views._events.emit(`${this.role}:${name}`, data);
252
- }
253
- _error(e) {
254
- this._views._error(e);
255
- }
256
- _destroy() {
257
- this._safeApplyOnLayout('destroy');
258
- this._proxyElement && this._proxyElement.destroy();
259
- }
260
- }
261
- exports.default = ViewActor;
262
- class View {
263
- constructor(actor) {
264
- (0, _commons.delegateGetters)(this, actor, ['role', 'layout', 'element', 'proxyElement', 'refresh', 'on', 'tracker']);
265
- }
266
- }
267
- function asMappingFunction(fn) {
268
- switch (typeof fn) {
269
- case 'function':
270
- return fn;
271
- case 'string':
272
- return data => data.value && data.value[fn];
273
- default:
274
- throw new Error(`Invalid mapping function: ${fn}`);
275
- }
276
- }
277
- function getDataEmptyness(role, data) {
278
- return isDataStatusRelevantToEmptyness(data) ? {
279
- empty: !!isDateValueEmpty(role, data && data.value)
280
- } : {};
281
- }
282
- function isDataStatusRelevantToEmptyness(data) {
283
- return data.status === _constants.STATUS.READY && !data.ongoing;
284
- }
285
- function isDateValueEmpty(role, value) {
286
- // TODO: ad-hoc
287
- switch (role) {
288
- case _constants.ROLE.ANSWER:
289
- case _constants.ROLE.REASONING:
290
- return !value || !value.value;
291
- default:
292
- return value === undefined || (Array.isArray(value) || typeof value === 'string') && !value.length;
293
- }
294
- }
@@ -1,209 +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 _constants = require("../constants.js");
9
- var fields = _interopRequireWildcard(require("./fields.js"));
10
- var _view = _interopRequireDefault(require("./view.js"));
11
- var _filters = _interopRequireDefault(require("./filters.js"));
12
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
14
- class ViewsActor {
15
- constructor(hub, {
16
- workflow,
17
- extensions,
18
- layouts,
19
- roles,
20
- options
21
- }) {
22
- this._hub = hub;
23
- this._workflow = workflow;
24
- this._workflowName = workflow._name;
25
- this._extensions = extensions;
26
- this._layoutFactory = layouts;
27
- this._options = options;
28
- this._roles = roles;
29
- this._containers = new Map();
30
- this._components = new Map();
31
- this._filters = new _filters.default(this);
32
- this._events = new _commons.EventEmitter();
33
- (0, _commons.defineValues)(this, {
34
- interface: new Views(this)
35
- });
36
- this._unsubscribes = [onResize(this.syncSize.bind(this)), hub.on(fields.data(), data => this.refresh({
37
- data
38
- })), options.on('layouts', () => this._syncLayouts())];
39
- this._syncLayouts();
40
- }
41
- get filters() {
42
- return this._filters;
43
- }
44
- get trackers() {
45
- return this._workflow.trackers;
46
- }
47
- on(role, name, fn) {
48
- return this._events.on(`${role}:${name}`, fn);
49
- }
50
-
51
- // elements //
52
- addContainer(element) {
53
- if (this._containers.has(element)) {
54
- return;
55
- }
56
- const view = this._createView(element);
57
- this._containers.set(element, view);
58
- const {
59
- components
60
- } = element;
61
- for (const component of components) {
62
- this.addComponent(component);
63
- }
64
- }
65
- removeContainer(element) {
66
- const view = this._containers.get(element);
67
- if (!view) {
68
- return;
69
- }
70
- const {
71
- components
72
- } = element;
73
- for (const component of components) {
74
- this.removeComponent(component);
75
- }
76
- view._destroy();
77
- this._containers.delete(element);
78
- }
79
- addComponent(element) {
80
- if (this._components.has(element)) {
81
- return;
82
- }
83
- const view = this._createView(element);
84
- this._components.set(element, view);
85
- }
86
- removeComponent(element) {
87
- const view = this._components.get(element);
88
- if (!view) {
89
- return;
90
- }
91
- view._destroy();
92
- this._components.delete(element);
93
- }
94
- updateComponentRole(element, oldRole, newRole) {
95
- // TODO
96
- }
97
- containsElement(element) {
98
- return this._containers.has(element) || this._components.has(element);
99
- }
100
- refreshElement(element) {
101
- const view = element.isContainer ? this._containers.get(element) : this._components.get(element);
102
- view && view.refresh({
103
- force: true
104
- });
105
- }
106
- _createView(element) {
107
- const view = new _view.default(this, element.role);
108
- view.layout = this._createLayout(element.role);
109
- view.element = element;
110
- return view;
111
- }
112
- _syncLayouts() {
113
- // TODO: put a debug event here
114
- const {
115
- layouts
116
- } = this._options.resolved;
117
- if (layouts === false) {
118
- for (const view of [...this._containers.values(), ...this._components.values()]) {
119
- view.layout = undefined;
120
- }
121
- } else {
122
- for (const view of [...this._containers.values(), ...this._components.values()]) {
123
- view.layout = this._createLayout(view.role);
124
- }
125
- }
126
- }
127
- _createLayout(role) {
128
- const args = this._options.resolved.layouts[role];
129
- if (!args) {
130
- return undefined;
131
- }
132
- const [name, options] = args;
133
- return this._layoutFactory.create(name, Object.assign({}, options, {
134
- role,
135
- workflow: this._workflowName
136
- }));
137
- }
138
- get(role) {
139
- return this.getAll(role)[0];
140
- }
141
- getAll(role) {
142
- return role === _constants.ROLE.CONTAINER ? this._containers.values() : this._components.values().filter(view => view.role === role);
143
- }
144
- get views() {
145
- return this._getViews(true);
146
- }
147
- _getViews(containerFirst = true) {
148
- return containerFirst ? [...this._containers.values(), ...this._components.values()] : [...this._components.values(), ...this._containers.values()];
149
- }
150
- syncSize() {
151
- // TODO: containers?
152
- for (const view of this._components.values()) {
153
- view._syncSize();
154
- }
155
- }
156
- async refresh({
157
- force,
158
- data
159
- } = {}) {
160
- data = this._getData(data);
161
- // container first
162
- let views = this._getViews(true);
163
- await Promise.all(views.map(view => view.refresh({
164
- force,
165
- data
166
- })));
167
- }
168
- _getData(data) {
169
- return data || this._hub.states[fields.data()];
170
- }
171
- _error(e) {
172
- // TODO: hub trigger error event
173
- console.error(e);
174
- }
175
- _destroy({
176
- dom
177
- } = {}) {
178
- // destroy components, and then containers
179
- for (const view of this._getViews(false)) {
180
- // TODO: handle dom option
181
- view._destroy();
182
- }
183
- for (const unsubscribe of this._unsubscribes) {
184
- unsubscribe();
185
- }
186
- this._unsubscribes = [];
187
- this._filters._destroy();
188
- }
189
- }
190
- exports.default = ViewsActor;
191
- class Views {
192
- constructor(actor) {
193
- this._actor = actor;
194
- (0, _commons.delegateGetters)(this, actor, ['syncSize', 'refresh', 'trackers', 'filters']);
195
- }
196
- get(role) {
197
- return this._actor.get(role).interface;
198
- }
199
- get all() {
200
- return this._actor.views.map(view => view.interface);
201
- }
202
- }
203
- function onResize(callback) {
204
- if (typeof window === 'undefined') {
205
- return () => {};
206
- }
207
- window.addEventListener('resize', callback);
208
- return () => window.removeEventListener('resize', callback);
209
- }
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.api = api;
7
- var _commons = require("@miso.ai/commons");
8
- function api(client) {
9
- // TODO: send uuid & unit id
10
- return async ({
11
- group,
12
- name,
13
- payload,
14
- options
15
- }) => {
16
- if (group === _commons.API.GROUP.ASK) {
17
- switch (name) {
18
- case _commons.API.NAME.QUESTIONS:
19
- return client.api.ask.questions(payload, options);
20
- case _commons.API.NAME.SEARCH:
21
- return client.api.ask.search(payload, options);
22
- }
23
- }
24
- // because name is in snake case
25
- return client.api[group]._run(name, payload, options);
26
- };
27
- }