@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.
Files changed (226) hide show
  1. package/dist/cjs/asset/svgs.js +17 -4
  2. package/dist/cjs/combo/ask/index.js +2 -2
  3. package/dist/cjs/constants.js +120 -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 +259 -0
  7. package/dist/cjs/element/container/index.js +28 -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-message-item.js +91 -0
  14. package/dist/cjs/element/container/miso-recommendation.js +1 -1
  15. package/dist/cjs/element/container/miso-search.js +1 -1
  16. package/dist/cjs/element/container/miso-thread-item.js +91 -0
  17. package/dist/cjs/element/context/miso-follow-ups.js +1 -1
  18. package/dist/cjs/element/role/index.js +49 -0
  19. package/dist/cjs/element/role/miso-delete.js +20 -0
  20. package/dist/cjs/element/role/miso-messages.js +20 -0
  21. package/dist/cjs/element/role/miso-new-thread.js +20 -0
  22. package/dist/cjs/element/role/miso-rename.js +20 -0
  23. package/dist/cjs/element/role/miso-subscription.js +20 -0
  24. package/dist/cjs/element/role/miso-threads.js +20 -0
  25. package/dist/cjs/element/role/miso-title.js +20 -0
  26. package/dist/cjs/layout/affiliation/affiliation.js +1 -1
  27. package/dist/cjs/layout/banner/banner.js +2 -1
  28. package/dist/cjs/layout/button/button.js +170 -0
  29. package/dist/cjs/layout/button/checkbox.js +116 -0
  30. package/dist/cjs/layout/button/more-button.js +3 -3
  31. package/dist/cjs/layout/container/container.js +1 -1
  32. package/dist/cjs/layout/container/item-container.js +99 -0
  33. package/dist/cjs/layout/error/error.js +2 -1
  34. package/dist/cjs/layout/index.js +42 -0
  35. package/dist/cjs/layout/input/facets.js +4 -3
  36. package/dist/cjs/layout/input/option-list.js +3 -2
  37. package/dist/cjs/layout/input/search-box.js +50 -12
  38. package/dist/cjs/layout/input/select.js +2 -1
  39. package/dist/cjs/layout/list/cards.js +2 -1
  40. package/dist/cjs/layout/list/carousel.js +2 -1
  41. package/dist/cjs/layout/list/collection.js +13 -1
  42. package/dist/cjs/layout/list/gallery.js +2 -1
  43. package/dist/cjs/layout/list/horizontal.js +2 -1
  44. package/dist/cjs/layout/list/list.js +2 -1
  45. package/dist/cjs/layout/list/messages.js +359 -0
  46. package/dist/cjs/layout/list/threads.js +199 -0
  47. package/dist/cjs/layout/mixin/trackable.js +4 -5
  48. package/dist/cjs/layout/mixin/triggerable.js +2 -2
  49. package/dist/cjs/layout/radio/feedback.js +4 -3
  50. package/dist/cjs/layout/templates.js +97 -0
  51. package/dist/cjs/layout/text/question.js +71 -0
  52. package/dist/cjs/layout/text/text.js +2 -1
  53. package/dist/cjs/layout/text/typewriter/index.js +18 -23
  54. package/dist/cjs/plugin.js +43 -104
  55. package/dist/cjs/util/confirm.js +33 -0
  56. package/dist/cjs/util/dom.js +21 -0
  57. package/dist/cjs/util/modal.js +48 -0
  58. package/dist/cjs/util/prompt.js +47 -0
  59. package/dist/cjs/version.js +1 -1
  60. package/package.json +5 -4
  61. package/src/CLAUDE.md +51 -104
  62. package/src/asset/svgs.js +16 -3
  63. package/src/combo/ask/index.js +2 -2
  64. package/src/constants.js +39 -147
  65. package/src/defaults/ask/controls.js +1 -1
  66. package/src/defaults/hybrid-search/answer-box.js +2 -2
  67. package/src/defaults.js +174 -0
  68. package/src/element/container/index.js +4 -0
  69. package/src/element/container/miso-ask.js +3 -3
  70. package/src/element/container/miso-conversation.js +19 -0
  71. package/src/element/container/miso-explore.js +1 -1
  72. package/src/element/container/miso-history.js +19 -0
  73. package/src/element/container/miso-hybrid-search.js +1 -1
  74. package/src/element/container/miso-message-item.js +94 -0
  75. package/src/element/container/miso-recommendation.js +1 -1
  76. package/src/element/container/miso-search.js +1 -1
  77. package/src/element/container/miso-thread-item.js +94 -0
  78. package/src/element/context/miso-follow-ups.js +1 -1
  79. package/src/element/role/index.js +7 -0
  80. package/src/element/role/miso-delete.js +16 -0
  81. package/src/element/role/miso-messages.js +16 -0
  82. package/src/element/role/miso-new-thread.js +16 -0
  83. package/src/element/role/miso-rename.js +16 -0
  84. package/src/element/role/miso-subscription.js +16 -0
  85. package/src/element/role/miso-threads.js +16 -0
  86. package/src/element/role/miso-title.js +16 -0
  87. package/src/layout/affiliation/affiliation.js +2 -2
  88. package/src/layout/banner/banner.js +2 -1
  89. package/src/layout/button/button.js +152 -0
  90. package/src/layout/button/checkbox.js +92 -0
  91. package/src/layout/button/more-button.js +3 -3
  92. package/src/layout/container/container.js +2 -2
  93. package/src/layout/container/item-container.js +99 -0
  94. package/src/layout/error/error.js +2 -1
  95. package/src/layout/index.js +6 -0
  96. package/src/layout/input/facets.js +3 -2
  97. package/src/layout/input/option-list.js +3 -2
  98. package/src/layout/input/search-box.js +45 -8
  99. package/src/layout/input/select.js +2 -1
  100. package/src/layout/list/cards.js +2 -1
  101. package/src/layout/list/carousel.js +2 -1
  102. package/src/layout/list/collection.js +15 -2
  103. package/src/layout/list/gallery.js +2 -1
  104. package/src/layout/list/horizontal.js +2 -1
  105. package/src/layout/list/list.js +2 -1
  106. package/src/layout/list/messages.js +316 -0
  107. package/src/layout/list/threads.js +166 -0
  108. package/src/layout/mixin/trackable.js +2 -3
  109. package/src/layout/mixin/triggerable.js +1 -1
  110. package/src/layout/radio/feedback.js +3 -2
  111. package/src/layout/templates.js +97 -0
  112. package/src/layout/text/question.js +58 -0
  113. package/src/layout/text/text.js +2 -1
  114. package/src/layout/text/typewriter/index.js +15 -18
  115. package/src/plugin.js +31 -117
  116. package/src/util/confirm.js +28 -0
  117. package/src/util/dom.js +16 -0
  118. package/src/util/modal.js +49 -0
  119. package/src/util/prompt.js +42 -0
  120. package/src/version.js +1 -1
  121. package/dist/cjs/actor/data.js +0 -132
  122. package/dist/cjs/actor/feedback.js +0 -29
  123. package/dist/cjs/actor/fields.js +0 -57
  124. package/dist/cjs/actor/filters.js +0 -161
  125. package/dist/cjs/actor/hub.js +0 -57
  126. package/dist/cjs/actor/index.js +0 -73
  127. package/dist/cjs/actor/interactions.js +0 -36
  128. package/dist/cjs/actor/sessions.js +0 -25
  129. package/dist/cjs/actor/tracker-states.js +0 -61
  130. package/dist/cjs/actor/tracker.js +0 -109
  131. package/dist/cjs/actor/trackers.js +0 -52
  132. package/dist/cjs/actor/utils.js +0 -15
  133. package/dist/cjs/actor/view.js +0 -294
  134. package/dist/cjs/actor/views.js +0 -209
  135. package/dist/cjs/source.js +0 -27
  136. package/dist/cjs/util/proxy.js +0 -88
  137. package/dist/cjs/util/trackers.js +0 -88
  138. package/dist/cjs/workflow/affiliations.js +0 -140
  139. package/dist/cjs/workflow/answer-based.js +0 -337
  140. package/dist/cjs/workflow/ask.js +0 -319
  141. package/dist/cjs/workflow/asks.js +0 -150
  142. package/dist/cjs/workflow/autocompletable.js +0 -63
  143. package/dist/cjs/workflow/autocomplete.js +0 -120
  144. package/dist/cjs/workflow/base.js +0 -418
  145. package/dist/cjs/workflow/context.js +0 -19
  146. package/dist/cjs/workflow/explore.js +0 -210
  147. package/dist/cjs/workflow/explores.js +0 -21
  148. package/dist/cjs/workflow/hybrid-search-answer.js +0 -88
  149. package/dist/cjs/workflow/hybrid-search-views.js +0 -109
  150. package/dist/cjs/workflow/hybrid-search.js +0 -213
  151. package/dist/cjs/workflow/index.js +0 -41
  152. package/dist/cjs/workflow/options/api.js +0 -41
  153. package/dist/cjs/workflow/options/auto-query.js +0 -97
  154. package/dist/cjs/workflow/options/configurable.js +0 -45
  155. package/dist/cjs/workflow/options/data-processor.js +0 -20
  156. package/dist/cjs/workflow/options/filters.js +0 -15
  157. package/dist/cjs/workflow/options/index.js +0 -126
  158. package/dist/cjs/workflow/options/interactions.js +0 -41
  159. package/dist/cjs/workflow/options/layouts.js +0 -79
  160. package/dist/cjs/workflow/options/options.js +0 -156
  161. package/dist/cjs/workflow/options/pagination.js +0 -25
  162. package/dist/cjs/workflow/options/roles.js +0 -15
  163. package/dist/cjs/workflow/options/templates.js +0 -30
  164. package/dist/cjs/workflow/options/trackers.js +0 -83
  165. package/dist/cjs/workflow/options/utils.js +0 -33
  166. package/dist/cjs/workflow/processors.js +0 -607
  167. package/dist/cjs/workflow/recommendation.js +0 -57
  168. package/dist/cjs/workflow/recommendations.js +0 -18
  169. package/dist/cjs/workflow/search-based.js +0 -337
  170. package/dist/cjs/workflow/search.js +0 -64
  171. package/dist/cjs/workflow/unit.js +0 -57
  172. package/dist/cjs/workflow/units.js +0 -42
  173. package/dist/cjs/workflow/use-link.js +0 -49
  174. package/src/actor/data.js +0 -106
  175. package/src/actor/feedback.js +0 -28
  176. package/src/actor/fields.js +0 -51
  177. package/src/actor/filters.js +0 -149
  178. package/src/actor/hub.js +0 -47
  179. package/src/actor/index.js +0 -10
  180. package/src/actor/interactions.js +0 -32
  181. package/src/actor/sessions.js +0 -21
  182. package/src/actor/tracker-states.js +0 -57
  183. package/src/actor/tracker.js +0 -104
  184. package/src/actor/trackers.js +0 -45
  185. package/src/actor/utils.js +0 -7
  186. package/src/actor/view.js +0 -272
  187. package/src/actor/views.js +0 -224
  188. package/src/source.js +0 -17
  189. package/src/util/proxy.js +0 -81
  190. package/src/util/trackers.js +0 -84
  191. package/src/workflow/affiliations.js +0 -121
  192. package/src/workflow/answer-based.js +0 -312
  193. package/src/workflow/ask.js +0 -284
  194. package/src/workflow/asks.js +0 -143
  195. package/src/workflow/autocompletable.js +0 -67
  196. package/src/workflow/autocomplete.js +0 -114
  197. package/src/workflow/base.js +0 -396
  198. package/src/workflow/context.js +0 -16
  199. package/src/workflow/explore.js +0 -194
  200. package/src/workflow/explores.js +0 -18
  201. package/src/workflow/hybrid-search-answer.js +0 -73
  202. package/src/workflow/hybrid-search-views.js +0 -116
  203. package/src/workflow/hybrid-search.js +0 -230
  204. package/src/workflow/index.js +0 -5
  205. package/src/workflow/options/api.js +0 -31
  206. package/src/workflow/options/auto-query.js +0 -70
  207. package/src/workflow/options/configurable.js +0 -48
  208. package/src/workflow/options/data-processor.js +0 -15
  209. package/src/workflow/options/filters.js +0 -10
  210. package/src/workflow/options/index.js +0 -11
  211. package/src/workflow/options/interactions.js +0 -36
  212. package/src/workflow/options/layouts.js +0 -73
  213. package/src/workflow/options/options.js +0 -175
  214. package/src/workflow/options/pagination.js +0 -18
  215. package/src/workflow/options/roles.js +0 -12
  216. package/src/workflow/options/templates.js +0 -27
  217. package/src/workflow/options/trackers.js +0 -80
  218. package/src/workflow/options/utils.js +0 -26
  219. package/src/workflow/processors.js +0 -490
  220. package/src/workflow/recommendation.js +0 -63
  221. package/src/workflow/recommendations.js +0 -14
  222. package/src/workflow/search-based.js +0 -329
  223. package/src/workflow/search.js +0 -73
  224. package/src/workflow/unit.js +0 -51
  225. package/src/workflow/units.js +0 -43
  226. package/src/workflow/use-link.js +0 -41
package/src/util/dom.js CHANGED
@@ -1,3 +1,19 @@
1
+ // data-* attributes of an element as a JSON string, for click interactions
2
+ export function dumpElementAttributes(element) {
3
+ const { attributes } = element;
4
+ const attrs = {};
5
+ for (const { name, value } of attributes) {
6
+ if (name.startsWith('data-')) {
7
+ attrs[name] = value;
8
+ }
9
+ }
10
+ try {
11
+ return JSON.stringify(attrs);
12
+ } catch (e) {
13
+ return '{}';
14
+ }
15
+ }
16
+
1
17
  export function setOrRemoveAttribute(element, name, value) {
2
18
  if (value === undefined) {
3
19
  element.removeAttribute(name);
@@ -0,0 +1,49 @@
1
+ import { escapeHtml } from '@miso.ai/commons';
2
+
3
+ /**
4
+ * The shared modal dialog core of confirm() and prompt(): a native <dialog>
5
+ * with title, message, an optional body, and cancel/confirm actions. Resolves
6
+ * with `result(dialog)` when confirmed; the cancel button, a backdrop click,
7
+ * and the Escape key all resolve with `cancelValue`.
8
+ */
9
+ export function openModal({
10
+ className,
11
+ title,
12
+ message,
13
+ body = '',
14
+ confirmText = 'Confirm',
15
+ cancelText = 'Cancel',
16
+ danger = false,
17
+ onOpen,
18
+ result = () => true,
19
+ cancelValue,
20
+ } = {}) {
21
+ return new Promise((resolve) => {
22
+ const dialog = document.createElement('dialog');
23
+ dialog.className = className;
24
+ dialog.innerHTML = [
25
+ title ? `<div class="${className}__title">${escapeHtml(title)}</div>` : '',
26
+ message ? `<div class="${className}__message">${escapeHtml(message)}</div>` : '',
27
+ body,
28
+ `<div class="${className}__actions">`,
29
+ `<button type="button" class="${className}__button ${className}__cancel-button" data-role="cancel">${escapeHtml(cancelText)}</button>`,
30
+ `<button type="button" class="${className}__button ${className}__confirm-button${danger ? ` ${className}__confirm-button--danger` : ''}" data-role="confirm">${escapeHtml(confirmText)}</button>`,
31
+ `</div>`,
32
+ ].join('');
33
+ dialog.addEventListener('click', (event) => {
34
+ if (event.target.closest('[data-role="confirm"]')) {
35
+ dialog.close('confirm');
36
+ } else if (event.target.closest('[data-role="cancel"]') || event.target === dialog) {
37
+ dialog.close(); // cancel button or backdrop click
38
+ }
39
+ });
40
+ dialog.addEventListener('close', () => {
41
+ const value = dialog.returnValue === 'confirm' ? result(dialog) : cancelValue;
42
+ dialog.remove();
43
+ resolve(value);
44
+ }, { once: true });
45
+ document.body.appendChild(dialog);
46
+ dialog.showModal();
47
+ onOpen && onOpen(dialog);
48
+ });
49
+ }
@@ -0,0 +1,42 @@
1
+ import { escapeHtml } from '@miso.ai/commons';
2
+ import { openModal } from './modal.js';
3
+
4
+ const DEFAULT_CLASSNAME = 'miso-prompt';
5
+
6
+ /**
7
+ * Show a modal input dialog (a native <dialog>), resolving to the entered
8
+ * (trimmed) text when confirmed. Cancel button, backdrop click, and the
9
+ * Escape key all resolve to undefined. The Enter key confirms. Exposed as
10
+ * `MisoClient.ui.prompt()`.
11
+ */
12
+ export default function prompt({
13
+ title,
14
+ message,
15
+ value = '',
16
+ placeholder,
17
+ confirmText = 'Confirm',
18
+ cancelText = 'Cancel',
19
+ className = DEFAULT_CLASSNAME,
20
+ } = {}) {
21
+ return openModal({
22
+ className,
23
+ title,
24
+ message,
25
+ body: `<input class="${className}__input" type="text" data-role="input" value="${escapeHtml(value)}"${placeholder ? ` placeholder="${escapeHtml(placeholder)}"` : ''}>`,
26
+ confirmText,
27
+ cancelText,
28
+ onOpen: (dialog) => {
29
+ const input = dialog.querySelector('[data-role="input"]');
30
+ input.addEventListener('keydown', (event) => {
31
+ if (event.key === 'Enter') {
32
+ event.preventDefault();
33
+ dialog.close('confirm');
34
+ }
35
+ });
36
+ input.focus();
37
+ input.select();
38
+ },
39
+ result: dialog => dialog.querySelector('[data-role="input"]').value.trim(),
40
+ cancelValue: undefined,
41
+ });
42
+ }
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '1.13.2-beta.1';
1
+ export default '1.14.0-beta.3';
@@ -1,132 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var fields = _interopRequireWildcard(require("./fields.js"));
8
- var _utils = require("./utils.js");
9
- const _excluded = ["session"];
10
- 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); }
11
- 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; }
12
- class DataActor {
13
- constructor(hub, {
14
- source,
15
- options,
16
- polling = true
17
- }) {
18
- this._hub = hub;
19
- this._source = source;
20
- this._options = options;
21
- this._polling = polling;
22
- this._unsubscribes = [hub.on(fields.session(), session => this._handleSession(session)), hub.on(fields.request(), event => this._handleRequest(event))];
23
- }
24
- get active() {
25
- return this._options.resolved.api.actor !== false;
26
- }
27
- get source() {
28
- return this._source;
29
- }
30
- _handleSession(session) {
31
- // this is mandatory in any case
32
- /*
33
- if (!this.active) {
34
- return;
35
- }
36
- */
37
- // abort ongoing data fetch if any
38
- if (!this._session || session.index !== this._session.index) {
39
- // new session, abort preview data fetch if necessary
40
- this._ac && this._ac.abort({
41
- type: 'new-session',
42
- message: 'A new session is created, discarding the old one.'
43
- });
44
- this._ac = new AbortController();
45
- }
46
- this._session = session;
47
- }
48
- async _handleRequest(event) {
49
- // protocol: inactive -> no reaction
50
- if (!this.active) {
51
- return;
52
- }
53
- const {
54
- session
55
- } = event,
56
- request = _objectWithoutPropertiesLoose(event, _excluded);
57
- try {
58
- const {
59
- signal
60
- } = this._ac || {};
61
- const options = Object.assign({}, event.options, {
62
- signal
63
- });
64
- const response = await this._source(Object.assign({
65
- session
66
- }, request, {
67
- options
68
- }));
69
- // takes an iterable, either sync or async
70
- if (response && response[Symbol.asyncIterator]) {
71
- // also emit reponse of the head request, if available
72
- if (response._response) {
73
- this._emitResponseWithSessionCheck({
74
- session,
75
- request,
76
- value: response._response
77
- });
78
- }
79
- if (this._polling) {
80
- let value;
81
- for await (value of response) {
82
- // A new session invalidates ongoing data fetch for the old session, terminating the loop
83
- if (!(0, _utils.isCurrentSession)(this._hub, session)) {
84
- break;
85
- }
86
- this._emitResponse({
87
- session,
88
- request,
89
- value
90
- });
91
- }
92
- }
93
- } else {
94
- this._emitResponseWithSessionCheck({
95
- session,
96
- request,
97
- value: response
98
- });
99
- }
100
- } catch (error) {
101
- this._error(error);
102
- this._emitResponseWithSessionCheck({
103
- session,
104
- request,
105
- error
106
- });
107
- }
108
- }
109
- _emitResponseWithSessionCheck(response) {
110
- // A new session invalidates ongoing data fetch
111
- (0, _utils.isCurrentSession)(this._hub, response.session) && this._emitResponse(response);
112
- }
113
- _emitResponse(response) {
114
- this._hub.update(fields.response(), response);
115
- }
116
- _error(error) {
117
- // TODO
118
- console.error(error);
119
- }
120
- _destroy() {
121
- // abort ongoing data fetch if any
122
- this._ac && this._ac.abort({
123
- type: 'data-actor-destroy',
124
- message: 'Data actor is destroyed.'
125
- });
126
- for (const unsubscribe of this._unsubscribes) {
127
- unsubscribe();
128
- }
129
- this._unsubscribes = [];
130
- }
131
- }
132
- exports.default = DataActor;
@@ -1,29 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var fields = _interopRequireWildcard(require("./fields.js"));
8
- var _constants = require("../constants.js");
9
- 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); }
10
- class FeedbackActor {
11
- constructor(hub) {
12
- this._hub = hub;
13
- this._unsubscribes = [hub.on(fields.feedback(), state => this._trigger(state))];
14
- }
15
- _trigger(state) {
16
- this._hub.trigger(fields.tracker(), {
17
- type: _constants.EVENT_TYPE.FEEDBACK,
18
- result_type: 'answer',
19
- value: state.unselected ? 'unselected' : state.value
20
- });
21
- }
22
- _destroy() {
23
- for (const unsubscribe of this._unsubscribes) {
24
- unsubscribe();
25
- }
26
- this._unsubscribes = [];
27
- }
28
- }
29
- exports.default = FeedbackActor;
@@ -1,57 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.completions = completions;
7
- exports.data = data;
8
- exports.feedback = feedback;
9
- exports.filters = filters;
10
- exports.input = input;
11
- exports.interaction = interaction;
12
- exports.more = more;
13
- exports.query = query;
14
- exports.request = request;
15
- exports.response = response;
16
- exports.session = session;
17
- exports.tracker = tracker;
18
- exports.view = view;
19
- function session() {
20
- return 'session';
21
- }
22
- function completions() {
23
- return 'completions';
24
- }
25
- function filters() {
26
- return 'filters';
27
- }
28
- function query() {
29
- return 'query';
30
- }
31
- function request() {
32
- return 'request';
33
- }
34
- function response() {
35
- return 'response';
36
- }
37
- function data() {
38
- return 'data';
39
- }
40
- function view(role) {
41
- return role ? `view:${role}` : 'view';
42
- }
43
- function tracker() {
44
- return 'tracker';
45
- }
46
- function interaction() {
47
- return 'interaction';
48
- }
49
- function feedback() {
50
- return 'feedback';
51
- }
52
- function input() {
53
- return 'input';
54
- }
55
- function more() {
56
- return 'more';
57
- }
@@ -1,161 +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 fields = _interopRequireWildcard(require("./fields.js"));
9
- 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); }
10
- function mergeState(state = {}, update = {}) {
11
- return Object.freeze((0, _commons.trimObj)(Object.assign({}, state, update, {
12
- facets: Object.freeze((0, _commons.trimObj)(Object.assign({}, state.facets, update.facets)))
13
- })));
14
- }
15
- function optionsToState({
16
- sort
17
- } = {}) {
18
- // TODO: facets
19
- return (0, _commons.trimObj)({
20
- facets: Object.freeze({}),
21
- sort: sortOptionsToState(sort)
22
- });
23
- }
24
- function sortOptionsToState(sort) {
25
- if (!sort) {
26
- return undefined;
27
- }
28
- const {
29
- options = []
30
- } = sort;
31
- for (const option of options) {
32
- if (option.default) {
33
- return Object.freeze(option);
34
- }
35
- }
36
- return Object.freeze(options[0]);
37
- }
38
- class Filters {
39
- constructor(views, {
40
- facets: facetsOptions
41
- } = {}) {
42
- this._views = views;
43
- this._hub = views._hub;
44
- const error = this._error = this._error.bind(this);
45
- this._events = new _commons.EventEmitter({
46
- target: this,
47
- error
48
- });
49
- (0, _commons.defineValues)(this, {
50
- facets: new Facets(this, facetsOptions)
51
- });
52
- this._unsubscribes = [views._options.on('filters', () => this._syncOptions())];
53
- this._syncOptions();
54
- this._states = undefined;
55
- }
56
- _syncOptions() {
57
- const options = this._views._options.resolved.filters;
58
- this._initialStates = optionsToState(options);
59
- this.apply({
60
- silent: true
61
- });
62
- }
63
- _getStates() {
64
- return this._states || this._initialStates;
65
- }
66
- update(updates) {
67
- const oldStates = this._getStates();
68
- this._states = mergeState(Object.assign({}, oldStates, updates));
69
- const states = this._getStates();
70
- this._events.emit('update', {
71
- updates,
72
- states,
73
- oldStates
74
- });
75
- }
76
- reset({
77
- silent = false
78
- } = {}) {
79
- // TODO: review this
80
- const oldStates = this._states;
81
- this._states = undefined;
82
- const states = this._getStates();
83
- this._hub.update(fields.filters(), states, {
84
- silent
85
- });
86
- this._events.emit('reset', {
87
- states,
88
- oldStates
89
- });
90
- }
91
- apply({
92
- silent = false
93
- } = {}) {
94
- const states = this._getStates();
95
- this._hub.update(fields.filters(), states, {
96
- silent
97
- });
98
- !silent && this._events.emit('apply');
99
- }
100
- _error(error) {
101
- this._views._error(error);
102
- }
103
- _destroy() {
104
- for (const unsubscribe of this._unsubscribes) {
105
- unsubscribe();
106
- }
107
- this._unsubscribes = [];
108
- }
109
- }
110
- exports.default = Filters;
111
- class Facets {
112
- constructor(filters, options = {}) {
113
- this._filters = filters;
114
- this._options = options;
115
- }
116
- isSelected(field, value) {
117
- return this._getFieldValues(field).includes(value);
118
- }
119
- select(field, value) {
120
- if (this.isSelected(field, value)) {
121
- return;
122
- }
123
- this._select(field, value);
124
- }
125
- unselect(field, value) {
126
- if (!this.isSelected(field, value)) {
127
- return;
128
- }
129
- this._unselect(field, value);
130
- }
131
- toggle(field, value) {
132
- if (this.isSelected(field, value)) {
133
- this._unselect(field, value);
134
- } else {
135
- this._select(field, value);
136
- }
137
- }
138
- _getFieldValues(field) {
139
- return this._filters._getStates().facets[field] || [];
140
- }
141
- _select(field, value) {
142
- const values = this._options.multivalued ? [...this._getFieldValues(field), value] : [value];
143
- values.sort();
144
- this._filters.update({
145
- facets: {
146
- [field]: values
147
- }
148
- });
149
- }
150
- _unselect(field, value) {
151
- let values = this._getFieldValues(field).filter(v => v !== value);
152
- if (values.length === 0) {
153
- values = undefined;
154
- }
155
- this._filters.update({
156
- facets: {
157
- [field]: values
158
- }
159
- });
160
- }
161
- }
@@ -1,57 +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
- class Hub {
9
- constructor(options = {}) {
10
- (this._events = new _commons.EventEmitter())._injectSubscribeInterface(this);
11
- this._options = options;
12
- this._states = {};
13
- (0, _commons.defineValues)(this, {
14
- states: new Proxy(this._states, {
15
- set() {}
16
- })
17
- });
18
- }
19
- update(name, state, options = {}) {
20
- this._states[name] = Object.freeze(state);
21
- const event = Object.freeze(Object.assign({
22
- action: 'update',
23
- name,
24
- state
25
- }, options));
26
- // callback after update, before emit
27
- if (typeof this._options.onUpdate === 'function') {
28
- this._options.onUpdate(event);
29
- }
30
- // emit
31
- if (!options.silent) {
32
- this._events.emit(name, state);
33
- }
34
- // callback after emit
35
- if (typeof this._options.onEmit === 'function') {
36
- this._options.onEmit(event);
37
- }
38
- }
39
- trigger(name, state) {
40
- const event = Object.freeze({
41
- action: 'trigger',
42
- name,
43
- state
44
- });
45
- // callback before emit
46
- if (typeof this._options.onUpdate === 'function') {
47
- this._options.onUpdate(event);
48
- }
49
- // emit
50
- this._events.emit(name, state);
51
- // callback after emit
52
- if (typeof this._options.onEmit === 'function') {
53
- this._options.onEmit(event);
54
- }
55
- }
56
- }
57
- exports.default = Hub;
@@ -1,73 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {
7
- fields: true,
8
- Hub: true,
9
- SessionMaker: true,
10
- DataActor: true,
11
- ViewsActor: true,
12
- FeedbackActor: true,
13
- InteractionsActor: true
14
- };
15
- Object.defineProperty(exports, "DataActor", {
16
- enumerable: true,
17
- get: function () {
18
- return _data.default;
19
- }
20
- });
21
- Object.defineProperty(exports, "FeedbackActor", {
22
- enumerable: true,
23
- get: function () {
24
- return _feedback.default;
25
- }
26
- });
27
- Object.defineProperty(exports, "Hub", {
28
- enumerable: true,
29
- get: function () {
30
- return _hub.default;
31
- }
32
- });
33
- Object.defineProperty(exports, "InteractionsActor", {
34
- enumerable: true,
35
- get: function () {
36
- return _interactions.default;
37
- }
38
- });
39
- Object.defineProperty(exports, "SessionMaker", {
40
- enumerable: true,
41
- get: function () {
42
- return _sessions.default;
43
- }
44
- });
45
- Object.defineProperty(exports, "ViewsActor", {
46
- enumerable: true,
47
- get: function () {
48
- return _views.default;
49
- }
50
- });
51
- exports.fields = void 0;
52
- var fields = _interopRequireWildcard(require("./fields.js"));
53
- exports.fields = fields;
54
- var _hub = _interopRequireDefault(require("./hub.js"));
55
- var _sessions = _interopRequireDefault(require("./sessions.js"));
56
- var _data = _interopRequireDefault(require("./data.js"));
57
- var _views = _interopRequireDefault(require("./views.js"));
58
- var _feedback = _interopRequireDefault(require("./feedback.js"));
59
- var _interactions = _interopRequireDefault(require("./interactions.js"));
60
- var _trackers = require("./trackers.js");
61
- Object.keys(_trackers).forEach(function (key) {
62
- if (key === "default" || key === "__esModule") return;
63
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
64
- if (key in exports && exports[key] === _trackers[key]) return;
65
- Object.defineProperty(exports, key, {
66
- enumerable: true,
67
- get: function () {
68
- return _trackers[key];
69
- }
70
- });
71
- });
72
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
73
- 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); }
@@ -1,36 +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 fields = _interopRequireWildcard(require("./fields.js"));
9
- 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); }
10
- class InteractionsActor {
11
- constructor(hub, {
12
- client,
13
- options
14
- }) {
15
- this._client = client;
16
- this._options = options;
17
- this._unsubscribes = [hub.on(fields.interaction(), payload => this._handle(payload))];
18
- }
19
- _handle(payload) {
20
- // TODO: omit when option == false
21
- payload = (0, _commons.asArray)(payload);
22
- if (payload.length === 0) {
23
- return;
24
- }
25
- this._client.api.interactions.upload(payload, {
26
- merge: true
27
- });
28
- }
29
- destroy() {
30
- for (const unsubscribe of this._unsubscribes) {
31
- unsubscribe();
32
- }
33
- this._unsubscribes = [];
34
- }
35
- }
36
- exports.default = InteractionsActor;
@@ -1,25 +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 fields = _interopRequireWildcard(require("./fields.js"));
9
- 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); }
10
- class SessionMaker {
11
- constructor(hub) {
12
- this._hub = hub;
13
- this._sessionIndex = 0;
14
- }
15
- restart() {
16
- const session = Object.freeze({
17
- uuid: (0, _commons.uuidv4)(),
18
- index: this._sessionIndex++,
19
- startAt: Date.now(),
20
- meta: {}
21
- });
22
- this._hub.update(fields.session(), session);
23
- }
24
- }
25
- exports.default = SessionMaker;