@miso.ai/client-sdk-ui 1.11.0-beta.1 → 1.11.0-beta.11

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 (118) hide show
  1. package/dist/cjs/actor/data.js +6 -7
  2. package/dist/cjs/actor/feedback.js +6 -39
  3. package/dist/cjs/actor/fields.js +14 -6
  4. package/dist/cjs/actor/hub.js +1 -2
  5. package/dist/cjs/actor/index.js +0 -7
  6. package/dist/cjs/actor/interactions.js +4 -15
  7. package/dist/cjs/actor/sessions.js +2 -33
  8. package/dist/cjs/actor/tracker.js +25 -26
  9. package/dist/cjs/actor/utils.js +0 -49
  10. package/dist/cjs/actor/view.js +40 -40
  11. package/dist/cjs/actor/views.js +32 -8
  12. package/dist/cjs/asset/svgs.js +18 -8
  13. package/dist/cjs/constants.js +18 -19
  14. package/dist/cjs/defaults/hybrid-search/answer-box.js +19 -3
  15. package/dist/cjs/defaults/hybrid-search/phrases.js +5 -5
  16. package/dist/cjs/defaults/hybrid-search/templates.js +37 -9
  17. package/dist/cjs/element/role/index.js +12 -5
  18. package/dist/cjs/element/role/{miso-hits.js → miso-more.js} +4 -4
  19. package/dist/cjs/element/role/miso-total.js +20 -0
  20. package/dist/cjs/layout/affiliation/affiliation.js +0 -3
  21. package/dist/cjs/layout/banner/banner.js +0 -4
  22. package/dist/cjs/layout/button/more-button.js +73 -0
  23. package/dist/cjs/layout/container/container.js +0 -3
  24. package/dist/cjs/layout/error/error.js +0 -4
  25. package/dist/cjs/layout/index.js +7 -0
  26. package/dist/cjs/layout/input/facets.js +5 -5
  27. package/dist/cjs/layout/input/option-list.js +0 -4
  28. package/dist/cjs/layout/input/search-box.js +35 -17
  29. package/dist/cjs/layout/list/cards.js +0 -3
  30. package/dist/cjs/layout/list/carousel.js +0 -3
  31. package/dist/cjs/layout/list/collection.js +22 -7
  32. package/dist/cjs/layout/list/list.js +0 -3
  33. package/dist/cjs/layout/radio/feedback.js +0 -3
  34. package/dist/cjs/layout/radio/radio.js +0 -4
  35. package/dist/cjs/layout/raf.js +4 -2
  36. package/dist/cjs/layout/text/text.js +0 -4
  37. package/dist/cjs/layout/text/typewriter/index.js +0 -3
  38. package/dist/cjs/layout/triggerable.js +79 -0
  39. package/dist/cjs/util/states.js +0 -15
  40. package/dist/cjs/version.js +1 -1
  41. package/dist/cjs/workflow/answer-based.js +109 -111
  42. package/dist/cjs/workflow/ask.js +35 -27
  43. package/dist/cjs/workflow/asks.js +1 -1
  44. package/dist/cjs/workflow/autocompletable.js +33 -0
  45. package/dist/cjs/workflow/autocomplete.js +122 -0
  46. package/dist/cjs/workflow/base.js +169 -102
  47. package/dist/cjs/workflow/explore.js +26 -19
  48. package/dist/cjs/workflow/hybrid-search-answer.js +99 -0
  49. package/dist/cjs/workflow/hybrid-search-results.js +66 -0
  50. package/dist/cjs/workflow/hybrid-search-views.js +122 -0
  51. package/dist/cjs/workflow/hybrid-search.js +98 -103
  52. package/dist/cjs/workflow/options.js +32 -17
  53. package/dist/cjs/workflow/processors.js +191 -17
  54. package/dist/cjs/workflow/recommendation.js +36 -49
  55. package/dist/cjs/workflow/search-based.js +228 -0
  56. package/dist/cjs/workflow/search.js +21 -68
  57. package/package.json +2 -2
  58. package/src/actor/data.js +2 -4
  59. package/src/actor/feedback.js +6 -23
  60. package/src/actor/fields.js +14 -6
  61. package/src/actor/hub.js +1 -2
  62. package/src/actor/index.js +0 -1
  63. package/src/actor/interactions.js +4 -10
  64. package/src/actor/sessions.js +3 -30
  65. package/src/actor/tracker.js +25 -19
  66. package/src/actor/utils.js +0 -47
  67. package/src/actor/view.js +27 -15
  68. package/src/actor/views.js +36 -8
  69. package/src/asset/svgs.js +19 -7
  70. package/src/constants.js +25 -16
  71. package/src/defaults/hybrid-search/answer-box.js +17 -5
  72. package/src/defaults/hybrid-search/phrases.js +4 -4
  73. package/src/defaults/hybrid-search/templates.js +25 -9
  74. package/src/element/role/index.js +2 -1
  75. package/src/element/role/{miso-hits.js → miso-more.js} +3 -3
  76. package/src/element/role/miso-total.js +16 -0
  77. package/src/layout/affiliation/affiliation.js +1 -5
  78. package/src/layout/banner/banner.js +0 -5
  79. package/src/layout/button/more-button.js +69 -0
  80. package/src/layout/container/container.js +1 -5
  81. package/src/layout/error/error.js +0 -5
  82. package/src/layout/index.js +2 -1
  83. package/src/layout/input/facets.js +5 -6
  84. package/src/layout/input/option-list.js +0 -5
  85. package/src/layout/input/search-box.js +29 -19
  86. package/src/layout/list/cards.js +0 -4
  87. package/src/layout/list/carousel.js +0 -4
  88. package/src/layout/list/collection.js +21 -9
  89. package/src/layout/list/list.js +0 -4
  90. package/src/layout/radio/feedback.js +0 -4
  91. package/src/layout/radio/radio.js +0 -5
  92. package/src/layout/raf.js +2 -2
  93. package/src/layout/text/text.js +0 -5
  94. package/src/layout/text/typewriter/index.js +1 -5
  95. package/src/layout/trackable.js +1 -1
  96. package/src/layout/triggerable.js +76 -0
  97. package/src/util/states.js +0 -14
  98. package/src/version.js +1 -1
  99. package/src/workflow/answer-based.js +101 -77
  100. package/src/workflow/ask.js +33 -25
  101. package/src/workflow/asks.js +1 -1
  102. package/src/workflow/autocompletable.js +29 -0
  103. package/src/workflow/autocomplete.js +113 -0
  104. package/src/workflow/base.js +147 -93
  105. package/src/workflow/explore.js +23 -8
  106. package/src/workflow/hybrid-search-answer.js +92 -0
  107. package/src/workflow/hybrid-search-results.js +62 -0
  108. package/src/workflow/hybrid-search-views.js +124 -0
  109. package/src/workflow/hybrid-search.js +102 -73
  110. package/src/workflow/options.js +26 -11
  111. package/src/workflow/processors.js +169 -14
  112. package/src/workflow/recommendation.js +32 -33
  113. package/src/workflow/search-based.js +222 -0
  114. package/src/workflow/search.js +21 -65
  115. package/dist/cjs/actor/autocomplete.js +0 -160
  116. package/dist/cjs/workflow/utils.js +0 -42
  117. package/src/actor/autocomplete.js +0 -133
  118. package/src/workflow/utils.js +0 -29
@@ -1,133 +0,0 @@
1
- import { STATUS, DATA_ASPECT } from '../constants.js';
2
- import * as fields from './fields.js';
3
-
4
- export default class AutocompleteActor {
5
-
6
- constructor(hub, { source, options }) {
7
- this._hub = hub;
8
- this._source = source;
9
- this._options = options;
10
- this._index = -1;
11
-
12
- // TODO: listen to request:input instead
13
- this._unsubscribes = [
14
- hub.on(fields.input(), () => this._sync()),
15
- options.on('autocomplete', () => this._syncOptions()),
16
- ];
17
-
18
- // sync right away
19
- this._sync(true);
20
- }
21
-
22
- get active() {
23
- return this._options.resolved.autocomplete.actor !== false;
24
- }
25
-
26
- get source() {
27
- return this._source;
28
- }
29
-
30
- _syncOptions() {
31
- // TODO: explore scenarios where options.actor true -> false
32
- this._sync(true);
33
- }
34
-
35
- async _sync(force = false) {
36
- // protocol: inactive -> no reaction
37
- if (!this.active) {
38
- return;
39
- }
40
-
41
- const { input } = this._hub.states;
42
- const value = input && input.value && input.value.trim() || undefined;
43
-
44
- if (sameInput(this._input, input) && !force) {
45
- return;
46
- }
47
- this._input = input;
48
- const index = ++this._index;
49
-
50
- // new input, abort previous data fetch if any
51
- this._clearTimeout();
52
- this._abortPendingRequest({
53
- type: 'new-input',
54
- message: 'A new input renders previous autocomplete request obsolete.',
55
- });
56
-
57
- // emit loading/initial state
58
- this._emitCompletions({ index, input, status: value ? STATUS.LOADING : STATUS.INITIAL });
59
-
60
- if (!value) {
61
- return;
62
- }
63
-
64
- try {
65
- const response = await this._fetchCompletions(input);
66
- if (this._index !== index) {
67
- return; // new results loading, discard this one
68
- }
69
- this._emitCompletions({ index, input, status: STATUS.READY, value: response.completions });
70
- } catch (error) {
71
- this._error(error);
72
- if (this._index !== index) {
73
- return; // ignore
74
- }
75
- this._emitCompletions({ index, input, status: STATUS.ERRONEOUS, error });
76
- }
77
- }
78
-
79
- async _getCompletions(input) {
80
- // TODO: cache
81
- return await this._fetchCompletions(input);
82
- }
83
-
84
- async _fetchCompletions({ value }) {
85
- // TODO: other options?
86
- const { api } = this._options.resolved.autocomplete;
87
- const { group, name } = api;
88
- const { signal } = this._ac || {};
89
- const options = { ...api.options, signal };
90
- const payload = { ...api.payload, q: value };
91
- return await this._source({ group, name, payload, options });
92
- }
93
-
94
- _clearTimeout() {
95
- if (this._timeoutId) {
96
- clearTimeout(this._timeoutId);
97
- this._timeoutId = undefined;
98
- }
99
- }
100
-
101
- _abortPendingRequest(info) {
102
- this._ac && this._ac.abort(info);
103
- this._ac = new AbortController();
104
- }
105
-
106
- _emitCompletions(event) {
107
- event.source = 'actor';
108
- // TDOO: update response:autocomplete instead
109
- this._hub.update(fields.data(DATA_ASPECT.AUTOCOMPLETE), event);
110
- }
111
-
112
- _error(error) {
113
- // TODO
114
- console.error(error);
115
- }
116
-
117
- _destroy() {
118
- // abort ongoing data fetch if any
119
- this._ac && this._ac.abort({
120
- type: 'autocomplete-actor-destroy',
121
- message: 'Autocomplete actor is destroyed.',
122
- });
123
- for (const unsubscribe of this._unsubscribes) {
124
- unsubscribe();
125
- }
126
- this._unsubscribes = [];
127
- }
128
-
129
- }
130
-
131
- function sameInput(a, b) {
132
- return (!a && !b) || (a && b && a.value === b.value);
133
- }
@@ -1,29 +0,0 @@
1
- export function mergeInteractionsOptions(base = {}, overrides = {}) {
2
- if (overrides === false) {
3
- return false;
4
- }
5
- return Object.freeze({
6
- ...base,
7
- ...overrides,
8
- preprocess: concatFunctions(base.preprocess, overrides.preprocess),
9
- });
10
- }
11
-
12
- export function injectLogger(hub, callback) {
13
- const { update, trigger } = hub;
14
- hub.update = (name, state, options) => {
15
- if (!options || !options.silent) {
16
- callback('update', name, state, options);
17
- }
18
- return update.call(hub, name, state, options);
19
- }
20
- hub.trigger = (...args) => {
21
- callback('trigger', ...args);
22
- return trigger.apply(hub, args);
23
- }
24
- return hub;
25
- }
26
-
27
- function concatFunctions(fn0, fn1) {
28
- return fn0 ? fn1 ? (...args) => fn1(fn0(...args)) : fn0 : fn1;
29
- }