@sme.up/ketchup 9.5.0 → 9.5.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 (132) hide show
  1. package/dist/cjs/{f-button-033ed6d4.js → f-button-357a3dff.js} +1 -1
  2. package/dist/cjs/{f-cell-ef276797.js → f-cell-1de0ea69.js} +5 -5
  3. package/dist/cjs/{f-chip-d4e26a2b.js → f-chip-bd5882a0.js} +2 -2
  4. package/dist/cjs/{f-image-33be7baf.js → f-image-30531fd0.js} +1 -1
  5. package/dist/cjs/{f-paginator-utils-5a18cc19.js → f-paginator-utils-ad8a4635.js} +2 -2
  6. package/dist/cjs/{f-text-field-f03e97f8.js → f-text-field-be758970.js} +1 -1
  7. package/dist/cjs/index.cjs.js +1 -1
  8. package/dist/cjs/ketchup.cjs.js +1 -1
  9. package/dist/cjs/kup-accordion.cjs.entry.js +2 -2
  10. package/dist/cjs/kup-autocomplete_27.cjs.entry.js +125 -20
  11. package/dist/cjs/kup-box.cjs.entry.js +7 -7
  12. package/dist/cjs/kup-calendar.cjs.entry.js +4 -4
  13. package/dist/cjs/kup-card-list.cjs.entry.js +1 -1
  14. package/dist/cjs/kup-cell.cjs.entry.js +6 -6
  15. package/dist/cjs/kup-dashboard.cjs.entry.js +4 -4
  16. package/dist/cjs/kup-drawer.cjs.entry.js +1 -1
  17. package/dist/cjs/kup-echart.cjs.entry.js +1 -1
  18. package/dist/cjs/kup-family-tree.cjs.entry.js +3 -3
  19. package/dist/cjs/kup-grid.cjs.entry.js +1 -1
  20. package/dist/cjs/kup-iframe.cjs.entry.js +1 -1
  21. package/dist/cjs/kup-image-list.cjs.entry.js +6 -6
  22. package/dist/cjs/kup-lazy.cjs.entry.js +1 -1
  23. package/dist/cjs/kup-magic-box.cjs.entry.js +2 -2
  24. package/dist/cjs/{kup-manager-f90f1b6d.js → kup-manager-cefb1999.js} +492 -365
  25. package/dist/cjs/kup-nav-bar.cjs.entry.js +1 -1
  26. package/dist/cjs/kup-numeric-picker.cjs.entry.js +2 -2
  27. package/dist/cjs/kup-photo-frame.cjs.entry.js +1 -1
  28. package/dist/cjs/kup-planner.cjs.entry.js +2 -2
  29. package/dist/cjs/kup-probe.cjs.entry.js +1 -1
  30. package/dist/cjs/kup-qlik.cjs.entry.js +1 -1
  31. package/dist/cjs/kup-snackbar.cjs.entry.js +3 -3
  32. package/dist/cjs/loader.cjs.js +1 -1
  33. package/dist/collection/assets/card.js +46 -0
  34. package/dist/collection/collection-manifest.json +0 -1
  35. package/dist/collection/components/kup-card/built-in/kup-card-built-in.js +9 -0
  36. package/dist/collection/components/kup-card/built-in/kup-card-openai.js +74 -0
  37. package/dist/collection/components/kup-card/kup-card-declarations.js +1 -0
  38. package/dist/collection/components/kup-card/kup-card.css +86 -0
  39. package/dist/collection/components/kup-card/kup-card.js +6 -0
  40. package/dist/collection/components/kup-data-table/kup-data-table.js +2 -3
  41. package/dist/collection/components/kup-dialog/kup-dialog.css +3 -3
  42. package/dist/collection/components/kup-dialog/kup-dialog.js +19 -5
  43. package/dist/collection/managers/kup-manager/kup-manager.js +6 -123
  44. package/dist/collection/managers/kup-openai/kup-openai-declarations.js +1 -0
  45. package/dist/collection/managers/kup-openai/kup-openai.js +247 -0
  46. package/dist/components/kup-autocomplete2.js +776 -546
  47. package/dist/components/kup-manager.js +492 -365
  48. package/dist/esm/{f-button-ccde4447.js → f-button-856a189a.js} +1 -1
  49. package/dist/esm/{f-cell-2ad41d52.js → f-cell-6324d838.js} +5 -5
  50. package/dist/esm/{f-chip-3df1c255.js → f-chip-e15fba8a.js} +2 -2
  51. package/dist/esm/{f-image-5434b351.js → f-image-26b1bc14.js} +1 -1
  52. package/dist/esm/{f-paginator-utils-b90cdd2b.js → f-paginator-utils-e8f62783.js} +2 -2
  53. package/dist/esm/{f-text-field-f0b81f8b.js → f-text-field-bbe1f236.js} +1 -1
  54. package/dist/esm/index.js +1 -1
  55. package/dist/esm/ketchup.js +1 -1
  56. package/dist/esm/kup-accordion.entry.js +2 -2
  57. package/dist/esm/kup-autocomplete_27.entry.js +125 -20
  58. package/dist/esm/kup-box.entry.js +7 -7
  59. package/dist/esm/kup-calendar.entry.js +4 -4
  60. package/dist/esm/kup-card-list.entry.js +1 -1
  61. package/dist/esm/kup-cell.entry.js +6 -6
  62. package/dist/esm/kup-dashboard.entry.js +4 -4
  63. package/dist/esm/kup-drawer.entry.js +1 -1
  64. package/dist/esm/kup-echart.entry.js +1 -1
  65. package/dist/esm/kup-family-tree.entry.js +3 -3
  66. package/dist/esm/kup-grid.entry.js +1 -1
  67. package/dist/esm/kup-iframe.entry.js +1 -1
  68. package/dist/esm/kup-image-list.entry.js +6 -6
  69. package/dist/esm/kup-lazy.entry.js +1 -1
  70. package/dist/esm/kup-magic-box.entry.js +2 -2
  71. package/dist/esm/{kup-manager-e33d8d8c.js → kup-manager-8d1df189.js} +492 -365
  72. package/dist/esm/kup-nav-bar.entry.js +1 -1
  73. package/dist/esm/kup-numeric-picker.entry.js +2 -2
  74. package/dist/esm/kup-photo-frame.entry.js +1 -1
  75. package/dist/esm/kup-planner.entry.js +2 -2
  76. package/dist/esm/kup-probe.entry.js +1 -1
  77. package/dist/esm/kup-qlik.entry.js +1 -1
  78. package/dist/esm/kup-snackbar.entry.js +3 -3
  79. package/dist/esm/loader.js +1 -1
  80. package/dist/ketchup/index.esm.js +1 -1
  81. package/dist/ketchup/ketchup.esm.js +1 -1
  82. package/dist/ketchup/{p-f81d7218.entry.js → p-07bed934.entry.js} +1 -1
  83. package/dist/ketchup/{p-5b3d8636.entry.js → p-0c124f99.entry.js} +1 -1
  84. package/dist/ketchup/{p-58798e2d.entry.js → p-0f6cb6e4.entry.js} +1 -1
  85. package/dist/ketchup/p-177f8008.entry.js +9 -0
  86. package/dist/ketchup/{p-f0e4e190.js → p-269a9af8.js} +1 -1
  87. package/dist/ketchup/p-2ab02da0.entry.js +1 -0
  88. package/dist/ketchup/{p-1a594e06.entry.js → p-3f028a71.entry.js} +1 -1
  89. package/dist/ketchup/{p-6a8fcb02.entry.js → p-4a18db68.entry.js} +1 -1
  90. package/dist/ketchup/{p-01aaf3e4.entry.js → p-4eb6d4e8.entry.js} +1 -1
  91. package/dist/ketchup/{p-eea1ee1b.js → p-63031c77.js} +1 -1
  92. package/dist/ketchup/{p-4725191c.entry.js → p-753f30d8.entry.js} +1 -1
  93. package/dist/ketchup/{p-a5229d3d.entry.js → p-8042dcd5.entry.js} +1 -1
  94. package/dist/ketchup/{p-1dbfcab5.entry.js → p-81c1d557.entry.js} +1 -1
  95. package/dist/ketchup/p-937a322f.js +29 -0
  96. package/dist/ketchup/{p-4afe8662.js → p-9ba8f169.js} +1 -1
  97. package/dist/ketchup/{p-645d881d.entry.js → p-a2d3aec9.entry.js} +1 -1
  98. package/dist/ketchup/{p-2940b559.entry.js → p-b115e1ec.entry.js} +1 -1
  99. package/dist/ketchup/{p-11e7be94.js → p-b396d0f8.js} +1 -1
  100. package/dist/ketchup/{p-7e5d8532.entry.js → p-c12a9759.entry.js} +1 -1
  101. package/dist/ketchup/{p-190d0bc5.entry.js → p-cadeb53d.entry.js} +1 -1
  102. package/dist/ketchup/{p-9df95b9f.js → p-caeed3c3.js} +1 -1
  103. package/dist/ketchup/{p-b104afb6.entry.js → p-d300948a.entry.js} +1 -1
  104. package/dist/ketchup/{p-95b31ede.js → p-d76cd8d6.js} +1 -1
  105. package/dist/ketchup/{p-b857aab2.entry.js → p-d9a1e5a4.entry.js} +1 -1
  106. package/dist/ketchup/{p-788da2d9.entry.js → p-dc370227.entry.js} +1 -1
  107. package/dist/ketchup/{p-5fa089cd.entry.js → p-f1cae1e1.entry.js} +1 -1
  108. package/dist/ketchup/{p-269a1dfe.entry.js → p-f417e794.entry.js} +1 -1
  109. package/dist/ketchup/{p-c0c65349.entry.js → p-f753c13f.entry.js} +1 -1
  110. package/dist/ketchup/{p-ddd25869.entry.js → p-f7980061.entry.js} +1 -1
  111. package/dist/types/components/kup-card/built-in/kup-card-built-in.d.ts +6 -0
  112. package/dist/types/components/kup-card/built-in/kup-card-openai.d.ts +3 -0
  113. package/dist/types/components/kup-card/kup-card-declarations.d.ts +20 -1
  114. package/dist/types/components.d.ts +0 -86
  115. package/dist/types/managers/kup-manager/kup-manager-declarations.d.ts +2 -14
  116. package/dist/types/managers/kup-manager/kup-manager.d.ts +3 -17
  117. package/dist/types/managers/kup-openai/kup-openai-declarations.d.ts +4 -0
  118. package/dist/types/managers/kup-openai/kup-openai.d.ts +29 -0
  119. package/package.json +1 -1
  120. package/dist/cjs/kup-openai-interface.cjs.entry.js +0 -146
  121. package/dist/collection/components/kup-openai-interface/kup-openai-interface-declarations.js +0 -11
  122. package/dist/collection/components/kup-openai-interface/kup-openai-interface.css +0 -64
  123. package/dist/collection/components/kup-openai-interface/kup-openai-interface.js +0 -340
  124. package/dist/components/kup-openai-interface.d.ts +0 -11
  125. package/dist/components/kup-openai-interface.js +0 -301
  126. package/dist/esm/kup-openai-interface.entry.js +0 -142
  127. package/dist/ketchup/p-23e4caa1.entry.js +0 -9
  128. package/dist/ketchup/p-2681d3a2.entry.js +0 -1
  129. package/dist/ketchup/p-39ba3355.js +0 -29
  130. package/dist/ketchup/p-6f108540.entry.js +0 -1
  131. package/dist/types/components/kup-openai-interface/kup-openai-interface-declarations.d.ts +0 -10
  132. package/dist/types/components/kup-openai-interface/kup-openai-interface.d.ts +0 -59
@@ -1099,12 +1099,11 @@ export class KupDataTable {
1099
1099
  ' Magic Box ' +
1100
1100
  '(' +
1101
1101
  __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").language.translate(KupLanguageGeneric.EXPERIMENTAL_FEAT) +
1102
- ')', icon: "auto-fix", "onkup-button-click": () => __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").toggleMagicBox() }), __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").openAIInterface &&
1103
- __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").openAIInterface.url ? (h("kup-button", { title: __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").language.translate(KupLanguageGeneric.TOGGLE) +
1102
+ ')', icon: "auto-fix", "onkup-button-click": () => __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").toggleMagicBox() }), __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").openAI && __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").openAI.url ? (h("kup-button", { title: __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").language.translate(KupLanguageGeneric.TOGGLE) +
1104
1103
  ' Open AI ' +
1105
1104
  '(' +
1106
1105
  __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").language.translate(KupLanguageGeneric.EXPERIMENTAL_FEAT) +
1107
- ')', icon: "open-ai", "onkup-button-click": () => __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").toggleOpenAI(this.data) })) : null), totalsMatrix));
1106
+ ')', icon: "open-ai", "onkup-button-click": () => __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").openAI.show(this.data) })) : null), totalsMatrix));
1108
1107
  }
1109
1108
  render() {
1110
1109
  __classPrivateFieldSet(this, _KupDataTable_thRefs, [], "f");
@@ -20,11 +20,11 @@
20
20
  width: 100%;
21
21
  }
22
22
 
23
- [fade-in] {
23
+ :host([fade-in]) {
24
24
  opacity: 0;
25
25
  }
26
- [fade-in] ::slotted {
27
- display: none;
26
+ :host([fade-in]) ::slotted {
27
+ opacity: 0;
28
28
  }
29
29
 
30
30
  .header {
@@ -14,13 +14,14 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
14
14
  throw new TypeError("Cannot write private member to an object whose class did not declare it");
15
15
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
16
  };
17
- var _KupDialog_header, _KupDialog_kupManager;
17
+ var _KupDialog_header, _KupDialog_kupManager, _KupDialog_recalcSafeguard;
18
18
  import { forceUpdate, h, Host, } from "@stencil/core";
19
19
  import { FImage } from "../../f-components/f-image/f-image";
20
20
  import { kupManagerInstance } from "../../managers/kup-manager/kup-manager";
21
21
  import { getProps, setProps } from "../../utils/utils";
22
22
  import { componentWrapperId } from "../../variables/GenericVariables";
23
23
  import { KupDialogProps, } from "./kup-dialog-declarations";
24
+ import { KupDebugCategory } from "../../managers/kup-debug/kup-debug-declarations";
24
25
  export class KupDialog {
25
26
  constructor() {
26
27
  /*-------------------------------------------------*/
@@ -28,6 +29,7 @@ export class KupDialog {
28
29
  /*-------------------------------------------------*/
29
30
  _KupDialog_header.set(this, null);
30
31
  _KupDialog_kupManager.set(this, kupManagerInstance());
32
+ _KupDialog_recalcSafeguard.set(this, 0);
31
33
  this.autoCenter = { onReady: true };
32
34
  this.customStyle = '';
33
35
  this.header = { icons: { close: true } };
@@ -61,11 +63,25 @@ export class KupDialog {
61
63
  * Places the dialog at the center of the screen.
62
64
  */
63
65
  async recalcPosition() {
66
+ var _a;
64
67
  const rect = this.rootElement.getBoundingClientRect();
68
+ if (!rect.x && !rect.y) {
69
+ __classPrivateFieldGet(this, _KupDialog_kupManager, "f").debug.logMessage(this, `recalcPosition() ran before the component finished being drawn. Running again (attempt #${__classPrivateFieldGet(this, _KupDialog_recalcSafeguard, "f")}).`, KupDebugCategory.INFO);
70
+ if (__classPrivateFieldGet(this, _KupDialog_recalcSafeguard, "f") < 50) {
71
+ __classPrivateFieldSet(this, _KupDialog_recalcSafeguard, (_a = __classPrivateFieldGet(this, _KupDialog_recalcSafeguard, "f"), _a++, _a), "f");
72
+ setTimeout(async () => this.recalcPosition(), 50);
73
+ return;
74
+ }
75
+ else {
76
+ __classPrivateFieldGet(this, _KupDialog_kupManager, "f").debug.logMessage(this, `Too many attempts centering the dialog.`, KupDebugCategory.WARNING);
77
+ }
78
+ }
79
+ __classPrivateFieldSet(this, _KupDialog_recalcSafeguard, 0, "f");
65
80
  const left = window.innerWidth / 2 - rect.width / 2;
66
81
  const top = window.innerHeight / 2 - rect.height / 2;
67
82
  this.rootElement.style.setProperty('--kup_dialog_left', left + 'px');
68
83
  this.rootElement.style.setProperty('--kup_dialog_top', top + 'px');
84
+ this.rootElement.removeAttribute('fade-in');
69
85
  }
70
86
  /**
71
87
  * This method is used to trigger a new render of the component.
@@ -91,9 +107,7 @@ export class KupDialog {
91
107
  var _a;
92
108
  __classPrivateFieldGet(this, _KupDialog_kupManager, "f").interact.dialogify(this.rootElement, __classPrivateFieldGet(this, _KupDialog_header, "f") ? __classPrivateFieldGet(this, _KupDialog_header, "f") : null, !this.resizable);
93
109
  if ((_a = this.autoCenter) === null || _a === void 0 ? void 0 : _a.onReady) {
94
- this.recalcPosition().then(() => {
95
- this.rootElement.removeAttribute('fade-in');
96
- });
110
+ this.recalcPosition();
97
111
  }
98
112
  else {
99
113
  this.rootElement.removeAttribute('fade-in');
@@ -476,4 +490,4 @@ export class KupDialog {
476
490
  }
477
491
  static get elementRef() { return "rootElement"; }
478
492
  }
479
- _KupDialog_header = new WeakMap(), _KupDialog_kupManager = new WeakMap();
493
+ _KupDialog_header = new WeakMap(), _KupDialog_kupManager = new WeakMap(), _KupDialog_recalcSafeguard = new WeakMap();
@@ -18,6 +18,7 @@ import { KupMath } from "../kup-math/kup-math";
18
18
  import { KupTooltip } from "../kup-tooltip/kup-tooltip";
19
19
  import { setAssetPath } from "@stencil/core";
20
20
  import html2canvas from "html2canvas";
21
+ import { KupOpenAI } from "../kup-openai/kup-openai";
21
22
  const dom = document.documentElement;
22
23
  /**
23
24
  * This class controls every other Ketchup utility suite.
@@ -30,7 +31,7 @@ export class KupManager {
30
31
  constructor(overrides) {
31
32
  let datesLocale = null, debugActive = null, debugAutoprint = null, debugLogLimit = null, dialogRestrictContainer = null, dialogZIndex = null, languageList = null, languageName = null, objectsList = null, scrollOnHoverDelay = null, scrollOnHoverStep = null, themeList = null, themeName = null, tooltipDelay = null, tooltipFCellCallbacks = null;
32
33
  /** POI VIA */
33
- this.openAIInterface = { url: 'https://kokosstaging.smeup.com' };
34
+ let openAIUrl = 'https://kokosstaging.smeup.com';
34
35
  if (overrides) {
35
36
  const assetsPath = overrides.assetsPath;
36
37
  const dates = overrides.dates;
@@ -41,7 +42,9 @@ export class KupManager {
41
42
  const scrollOnHover = overrides.scrollOnHover;
42
43
  const theme = overrides.theme;
43
44
  const tooltip = overrides.tooltip;
44
- const openAIUrl = overrides.openAIUrl;
45
+ if (overrides.openAIUrl) {
46
+ openAIUrl = overrides.openAIUrl;
47
+ }
45
48
  if (assetsPath) {
46
49
  setAssetPath(assetsPath);
47
50
  }
@@ -84,9 +87,6 @@ export class KupManager {
84
87
  ? tooltip.fCellCallbacks
85
88
  : null;
86
89
  }
87
- if (openAIUrl) {
88
- this.openAIInterface = { url: openAIUrl };
89
- }
90
90
  }
91
91
  this.data = new KupData();
92
92
  this.dates = new KupDates(datesLocale);
@@ -95,7 +95,7 @@ export class KupManager {
95
95
  this.interact = new KupInteract(dialogZIndex, dialogRestrictContainer);
96
96
  this.language = new KupLanguage(languageList, languageName);
97
97
  this.magicBox = null;
98
- this.openAI = null;
98
+ this.openAI = new KupOpenAI(openAIUrl);
99
99
  this.math = new KupMath();
100
100
  this.overrides = overrides ? overrides : null;
101
101
  this.objects = new KupObjects(objectsList);
@@ -208,123 +208,6 @@ export class KupManager {
208
208
  this.hideMagicBox();
209
209
  }
210
210
  }
211
- /**
212
- * Creates OpenAI component interface.
213
- */
214
- async showOpenAI(data) {
215
- if (!this.openAIInterface || !this.openAIInterface.url) {
216
- return;
217
- }
218
- if (this.openAI) {
219
- return;
220
- }
221
- const response = await fetch(this.openAIInterface.url + '/api/init', {
222
- method: 'POST',
223
- headers: {
224
- 'Content-Type': 'application/json',
225
- },
226
- body: JSON.stringify({ data: data }),
227
- });
228
- console.log('kup-manager.showOpenAI() response', response);
229
- if (response) {
230
- if (response.status != 200) {
231
- this.debug.logMessage(this, await response.text(), KupDebugCategory.ERROR);
232
- return;
233
- }
234
- const responseJson = await response.json();
235
- this.openAIInterface.sessionInfo = {
236
- fileId: responseJson.fileId,
237
- threadId: responseJson.threadId,
238
- };
239
- }
240
- this.openAI = document.createElement('kup-openai-interface');
241
- this.openAI.id = 'kup-openai-interface';
242
- this.openAI.style.position = 'fixed';
243
- this.openAI.style.left = 'calc(50% - 250px)';
244
- this.openAI.style.top = 'calc(50% - 85px)';
245
- this.openAI.data = data;
246
- document.body.appendChild(this.openAI);
247
- }
248
- /**
249
- * Removes OpenAI component interface.
250
- */
251
- async hideOpenAI() {
252
- if (!this.openAI) {
253
- return;
254
- }
255
- this.openAI.remove();
256
- this.openAI = null;
257
- if (!this.openAIInterface || !this.openAIInterface.url) {
258
- return;
259
- }
260
- if (!this.openAIInterface.sessionInfo) {
261
- return;
262
- }
263
- const response = await fetch(this.openAIInterface.url + '/api/finalize', {
264
- method: 'POST',
265
- headers: {
266
- 'Content-Type': 'application/json',
267
- },
268
- body: JSON.stringify({
269
- fileId: this.openAIInterface.sessionInfo.fileId,
270
- threadId: this.openAIInterface.sessionInfo.threadId,
271
- }),
272
- });
273
- console.log('kup-manager.hideOpenAI() response', response);
274
- if (response) {
275
- if (response.status != 200) {
276
- this.debug.logMessage(this, await response.text(), KupDebugCategory.ERROR);
277
- return;
278
- }
279
- this.openAIInterface.sessionInfo = null;
280
- }
281
- }
282
- /**
283
- * Creates or removes OpenAI component interface depending on its existence.
284
- */
285
- toggleOpenAI(data) {
286
- if (!this.openAI) {
287
- this.showOpenAI(data);
288
- }
289
- else {
290
- this.hideOpenAI();
291
- }
292
- }
293
- async interactOpenAI(question) {
294
- if (!this.openAI) {
295
- return;
296
- }
297
- if (!this.openAIInterface || !this.openAIInterface.url) {
298
- return;
299
- }
300
- if (!this.openAIInterface.sessionInfo) {
301
- return;
302
- }
303
- const responseArray = [];
304
- const response = await fetch(this.openAIInterface.url + '/api/chat', {
305
- method: 'POST',
306
- headers: {
307
- 'Content-Type': 'application/json',
308
- },
309
- body: JSON.stringify({
310
- fileId: this.openAIInterface.sessionInfo.fileId,
311
- threadId: this.openAIInterface.sessionInfo.threadId,
312
- question: question,
313
- }),
314
- });
315
- console.log('kup-manager.interactOpenAI() response', response);
316
- if (response) {
317
- if (response.status != 200) {
318
- this.debug.logMessage(this, await response.text(), KupDebugCategory.ERROR);
319
- return;
320
- }
321
- const responseJson = await response.json();
322
- if (responseJson && responseJson.messages) {
323
- responseArray.push(...responseJson.messages);
324
- }
325
- }
326
- return responseArray;
327
- }
328
211
  /**
329
212
  * Sets both locale and language library-wide.
330
213
  * @param {KupDatesLocales} locale - The supported locale.
@@ -0,0 +1,247 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f)
3
+ throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
5
+ throw new TypeError("Cannot read private member from an object whose class did not declare it");
6
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
7
+ };
8
+ var _KupOpenAI_instances, _KupOpenAI_setError, _KupOpenAI_invalidPassword, _KupOpenAI_create, _KupOpenAI_connect, _KupOpenAI_disconnect;
9
+ import { KupCardFamily } from "../../components/kup-card/kup-card-declarations";
10
+ import { KupDebugCategory } from "../kup-debug/kup-debug-declarations";
11
+ const dom = document.documentElement;
12
+ export class KupOpenAI {
13
+ /**
14
+ * Initializes KupOpenAI.
15
+ */
16
+ constructor(url) {
17
+ _KupOpenAI_instances.add(this);
18
+ this.card = null;
19
+ this.data = null;
20
+ this.dialog = null;
21
+ this.sessionInfo = null;
22
+ this.url = null;
23
+ this.container = document.createElement('div');
24
+ this.container.setAttribute('kup-openai', '');
25
+ document.body.appendChild(this.container);
26
+ this.url = url;
27
+ }
28
+ getCardOptions() {
29
+ if (!this.card.data) {
30
+ this.card.data = {};
31
+ }
32
+ if (!this.card.data.options) {
33
+ this.card.data.options = {
34
+ submitCb: this.chat,
35
+ authCb: this.auth,
36
+ };
37
+ }
38
+ return this.card.data.options;
39
+ }
40
+ /**
41
+ * Shows the component
42
+ * @param data
43
+ * @param options
44
+ */
45
+ show(data) {
46
+ this.data = data;
47
+ // Creates the card or updates it with new options
48
+ __classPrivateFieldGet(this, _KupOpenAI_instances, "m", _KupOpenAI_create).call(this);
49
+ }
50
+ /**
51
+ * Hides the component.
52
+ */
53
+ hide() {
54
+ this.card.remove();
55
+ this.card = null;
56
+ this.dialog.remove();
57
+ this.dialog = null;
58
+ __classPrivateFieldGet(this, _KupOpenAI_instances, "m", _KupOpenAI_disconnect).call(this);
59
+ }
60
+ async auth(event) {
61
+ const openAI = dom.ketchup.openAI;
62
+ if (!openAI.url) {
63
+ return;
64
+ }
65
+ const pwd = await event.detail.comp.getValue();
66
+ let response = null;
67
+ try {
68
+ response = await fetch(openAI.url + '/api/auth', {
69
+ method: 'POST',
70
+ headers: {
71
+ 'Content-Type': 'application/json',
72
+ },
73
+ body: JSON.stringify({ data: pwd }),
74
+ });
75
+ }
76
+ catch (e) {
77
+ __classPrivateFieldGet(openAI, _KupOpenAI_instances, "m", _KupOpenAI_setError).call(openAI, e.message, openAI);
78
+ return;
79
+ }
80
+ if (response) {
81
+ if (response.status != 200) {
82
+ __classPrivateFieldGet(openAI, _KupOpenAI_instances, "m", _KupOpenAI_invalidPassword).call(openAI, event);
83
+ //this.#setError(await response.text());
84
+ return;
85
+ }
86
+ const responseJson = await response.json();
87
+ if (responseJson.status == 'ok') {
88
+ openAI.getCardOptions().state = 'connecting';
89
+ openAI.card.refresh();
90
+ __classPrivateFieldGet(openAI, _KupOpenAI_instances, "m", _KupOpenAI_connect).call(openAI);
91
+ return;
92
+ }
93
+ }
94
+ openAI.getCardOptions().state = 'error';
95
+ openAI.card.refresh();
96
+ }
97
+ async chat(disableInteractivity, inputArea) {
98
+ const communicate = async (question) => {
99
+ if (!openAI.url) {
100
+ return;
101
+ }
102
+ if (!openAI.sessionInfo) {
103
+ return;
104
+ }
105
+ const responseMessages = [];
106
+ let response = null;
107
+ try {
108
+ response = await fetch(openAI.url + '/api/chat', {
109
+ method: 'POST',
110
+ headers: {
111
+ 'Content-Type': 'application/json',
112
+ },
113
+ body: JSON.stringify({
114
+ fileId: openAI.sessionInfo.fileId,
115
+ threadId: openAI.sessionInfo.threadId,
116
+ question: question,
117
+ }),
118
+ });
119
+ }
120
+ catch (e) {
121
+ __classPrivateFieldGet(this, _KupOpenAI_instances, "m", _KupOpenAI_setError).call(this, e.message, openAI);
122
+ }
123
+ if (response) {
124
+ if (response.status != 200) {
125
+ __classPrivateFieldGet(this, _KupOpenAI_instances, "m", _KupOpenAI_setError).call(this, await response.text(), openAI);
126
+ return;
127
+ }
128
+ const responseJson = await response.json();
129
+ if (responseJson && responseJson.messages) {
130
+ responseMessages.push(...responseJson.messages);
131
+ }
132
+ }
133
+ return responseMessages;
134
+ };
135
+ const openAI = dom.ketchup.openAI;
136
+ if (!openAI.card) {
137
+ return;
138
+ }
139
+ disableInteractivity(true);
140
+ openAI.getCardOptions().messages = await communicate(await inputArea.getValue());
141
+ openAI.card.refresh();
142
+ disableInteractivity(false);
143
+ }
144
+ }
145
+ _KupOpenAI_instances = new WeakSet(), _KupOpenAI_setError = function _KupOpenAI_setError(message, _this, dontRefreshCard) {
146
+ if (!_this) {
147
+ _this = this;
148
+ }
149
+ dom.ketchup.debug.logMessage(_this, message, KupDebugCategory.ERROR);
150
+ if (dontRefreshCard) {
151
+ return;
152
+ }
153
+ _this.getCardOptions().state = 'error';
154
+ _this.card.refresh();
155
+ }, _KupOpenAI_invalidPassword = function _KupOpenAI_invalidPassword(event) {
156
+ const field = event.detail.comp;
157
+ field.helper = 'Invalid password.';
158
+ field.rootElement.classList.add('kup-danger');
159
+ field.refresh();
160
+ }, _KupOpenAI_create = function _KupOpenAI_create() {
161
+ this.card = document.createElement('kup-card');
162
+ this.card.layoutFamily = KupCardFamily.BUILT_IN;
163
+ this.card.layoutNumber = 7;
164
+ this.card.sizeX = '100%';
165
+ this.card.sizeY = '100%';
166
+ this.dialog = document.createElement('kup-dialog');
167
+ this.dialog.header = {
168
+ title: 'Chat with Data',
169
+ icons: { close: true },
170
+ };
171
+ this.dialog.id = 'openai';
172
+ this.dialog.modal = { closeOnBackdropClick: false };
173
+ this.dialog.sizeX = '50vw';
174
+ this.dialog.sizeY = '50vh';
175
+ this.dialog.addEventListener('kup-dialog-close', () => this.hide());
176
+ this.dialog.appendChild(this.card);
177
+ this.container.appendChild(this.dialog);
178
+ if (!this.url) {
179
+ this.getCardOptions().state = 'error';
180
+ }
181
+ else {
182
+ this.getCardOptions().state = 'authentication';
183
+ }
184
+ }, _KupOpenAI_connect = async function _KupOpenAI_connect() {
185
+ if (!this.url) {
186
+ return;
187
+ }
188
+ let response = null;
189
+ try {
190
+ response = await fetch(this.url + '/api/init', {
191
+ method: 'POST',
192
+ headers: {
193
+ 'Content-Type': 'application/json',
194
+ },
195
+ body: JSON.stringify({ data: this.data }),
196
+ });
197
+ }
198
+ catch (e) {
199
+ __classPrivateFieldGet(this, _KupOpenAI_instances, "m", _KupOpenAI_setError).call(this, e.message);
200
+ return;
201
+ }
202
+ if (response) {
203
+ if (response.status != 200) {
204
+ __classPrivateFieldGet(this, _KupOpenAI_instances, "m", _KupOpenAI_setError).call(this, await response.text());
205
+ return;
206
+ }
207
+ const responseJson = await response.json();
208
+ this.sessionInfo = {
209
+ fileId: responseJson.fileId,
210
+ threadId: responseJson.threadId,
211
+ };
212
+ this.getCardOptions().state = 'ready';
213
+ this.card.refresh();
214
+ return;
215
+ }
216
+ this.getCardOptions().state = 'error';
217
+ this.card.refresh();
218
+ }, _KupOpenAI_disconnect = async function _KupOpenAI_disconnect() {
219
+ if (!this.url) {
220
+ return;
221
+ }
222
+ if (!this.sessionInfo) {
223
+ return;
224
+ }
225
+ let response = null;
226
+ try {
227
+ response = await fetch(this.url + '/api/finalize', {
228
+ method: 'POST',
229
+ headers: {
230
+ 'Content-Type': 'application/json',
231
+ },
232
+ body: JSON.stringify({
233
+ fileId: this.sessionInfo.fileId,
234
+ threadId: this.sessionInfo.threadId,
235
+ }),
236
+ });
237
+ }
238
+ catch (e) {
239
+ __classPrivateFieldGet(this, _KupOpenAI_instances, "m", _KupOpenAI_setError).call(this, e.message, undefined, true);
240
+ }
241
+ this.sessionInfo = null;
242
+ if (response) {
243
+ if (response.status != 200) {
244
+ __classPrivateFieldGet(this, _KupOpenAI_instances, "m", _KupOpenAI_setError).call(this, await response.text(), undefined, true);
245
+ }
246
+ }
247
+ };