@apia/ai 4.0.9 → 4.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import { jsx, jsxs, Fragment } from '@apia/theme/jsx-runtime';
2
- import { Box, getVariant, Textarea, Paragraph } from '@apia/theme';
3
- import { useRef, useCallback, useState } from 'react';
4
- import { IconButton, SimpleButton, ApiaUtil, SortableList, SortableListItem } from '@apia/components';
2
+ import { Box, getVariant, useBreakpointIndex, Textarea, Paragraph, Form } from '@apia/theme';
3
+ import { useRef, useCallback, useState, createContext, forwardRef, useEffect } from 'react';
4
+ import { IconButton, SimpleButton, ApiaUtil, FiltersStore, SortableList, SortableListItem } from '@apia/components';
5
5
  import { getLabel, noNaN, AudioRecorder, EventEmitter } from '@apia/util';
6
6
  import { makeObservable, observable, action, toJS, makeAutoObservable } from 'mobx';
7
+ import { observer } from 'mobx-react-lite';
7
8
  import { CollectorField, Collector } from '@apia/validations';
8
9
  import { uniqueId } from '@apia/notifications';
9
10
  import { FileIcon } from '@apia/icons';
10
- import { observer } from 'mobx-react-lite';
11
- import axios from 'axios';
12
11
  import { ApiaApi, makeApiaUrl, parseSuccessfulResponse } from '@apia/api';
12
+ import axios from 'axios';
13
13
 
14
14
  const AutoscrollContainer = ({ children }) => {
15
15
  const observer = useRef(null);
@@ -30,10 +30,10 @@ const AutoscrollContainer = ({ children }) => {
30
30
  observer.current?.disconnect();
31
31
  unsuscribe.current?.();
32
32
  observer.current = new MutationObserver(([mutation]) => {
33
- if (mutation && mutation.target instanceof HTMLElement && mutation.target === el) {
34
- if (isFullScrolled.current && mutation.target.scrollTop !== mutation.target.scrollHeight - mutation.target.offsetHeight) {
35
- mutation.target.scrollTo({
36
- top: mutation.target.scrollHeight,
33
+ if (mutation && mutation.target instanceof HTMLElement) {
34
+ if (isFullScrolled.current && el.scrollTop !== el.scrollHeight - el.offsetHeight) {
35
+ el.scrollTo({
36
+ top: el.scrollHeight,
37
37
  behavior: "smooth"
38
38
  });
39
39
  }
@@ -193,40 +193,50 @@ function useHandleFileUpload({
193
193
  return { progress, handleFileUpload };
194
194
  }
195
195
 
196
- var __defProp$7 = Object.defineProperty;
197
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
198
- var __publicField$7 = (obj, key, value) => {
199
- __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
196
+ var __defProp$b = Object.defineProperty;
197
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
198
+ var __publicField$b = (obj, key, value) => {
199
+ __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
200
200
  return value;
201
201
  };
202
202
  let maxId = 0;
203
203
  class ChatMessage {
204
- constructor(message = "", messageType = "user", attachments = []) {
204
+ constructor(message = "", messageType = "user", attachments = [], reference = null) {
205
205
  this.message = message;
206
206
  this.messageType = messageType;
207
207
  this.attachments = attachments;
208
- __publicField$7(this, "id");
209
- __publicField$7(this, "copy", () => new ChatMessage(this.message, this.messageType, this.attachments));
210
- __publicField$7(this, "Component", () => {
208
+ this.reference = reference;
209
+ __publicField$b(this, "id");
210
+ __publicField$b(this, "clone", () => new ChatMessage(
211
+ this.message,
212
+ this.messageType,
213
+ this.attachments,
214
+ this.reference
215
+ ));
216
+ __publicField$b(this, "Component", observer(({ className }) => {
211
217
  return /* @__PURE__ */ jsxs(
212
218
  Box,
213
219
  {
214
220
  as: "pre",
215
- className: `history__message ${this.messageType}`,
221
+ className: `history_message ${className || ""} ${this.messageType}`,
216
222
  children: [
217
223
  /* @__PURE__ */ jsx(
218
224
  Box,
219
225
  {
220
- className: "text_wrapper",
226
+ className: "history_message__content",
221
227
  ...typeof this.message === "string" ? { dangerouslySetInnerHTML: { __html: this.message } } : { children: this.message }
222
228
  }
223
229
  ),
224
- /* @__PURE__ */ jsx(Box, { className: "additionalContent_wrapper", children: this.attachments.map((x) => /* @__PURE__ */ jsx(x.Component, {}, x.id)) })
230
+ this.attachments.length > 0 && /* @__PURE__ */ jsx(Box, { className: "history_message__attachments", children: this.attachments.map((x) => {
231
+ const a = x;
232
+ return /* @__PURE__ */ jsx(a.Component, {}, x.id);
233
+ }) }),
234
+ this.reference && /* @__PURE__ */ jsx(Box, { className: "history_message__references", children: this.reference })
225
235
  ]
226
236
  },
227
237
  this.id
228
238
  );
229
- });
239
+ }));
230
240
  this.id = maxId++;
231
241
  if (messageType === "response")
232
242
  this.messageType = "system";
@@ -235,7 +245,8 @@ class ChatMessage {
235
245
  makeObservable(this, {
236
246
  attachments: observable,
237
247
  message: observable,
238
- messageType: observable
248
+ messageType: observable,
249
+ reference: observable
239
250
  });
240
251
  }
241
252
  parseMessage(message) {
@@ -244,20 +255,23 @@ class ChatMessage {
244
255
  result = result.replaceAll("[/strong]", "</strong>");
245
256
  return result;
246
257
  }
258
+ removeAttachment(idx) {
259
+ this.attachments = this.attachments.filter((_, i) => i !== idx);
260
+ }
247
261
  }
248
262
 
249
- var __defProp$6 = Object.defineProperty;
250
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
251
- var __publicField$6 = (obj, key, value) => {
252
- __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
263
+ var __defProp$a = Object.defineProperty;
264
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
265
+ var __publicField$a = (obj, key, value) => {
266
+ __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
253
267
  return value;
254
268
  };
255
269
  class AIContent extends CollectorField {
256
270
  constructor(content) {
257
271
  super(uniqueId(), "");
258
- __publicField$6(this, "type", "aiContent");
259
- __publicField$6(this, "content");
260
- __publicField$6(this, "Component", () => {
272
+ __publicField$a(this, "type", "aiContent");
273
+ __publicField$a(this, "content");
274
+ __publicField$a(this, "Component", () => {
261
275
  return /* @__PURE__ */ jsx(Box, { variant: "layout.common.components.aiMessage.textBox", children: /* @__PURE__ */ jsx(Box, { variant: "layout.common.components.aiMessage.textSnippet", children: this.content }) });
262
276
  });
263
277
  this.content = content;
@@ -292,27 +306,32 @@ var AIMessageRole = /* @__PURE__ */ ((AIMessageRole2) => {
292
306
  return AIMessageRole2;
293
307
  })(AIMessageRole || {});
294
308
 
295
- var __defProp$5 = Object.defineProperty;
296
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
297
- var __publicField$5 = (obj, key, value) => {
298
- __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
309
+ var __defProp$9 = Object.defineProperty;
310
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
311
+ var __publicField$9 = (obj, key, value) => {
312
+ __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
299
313
  return value;
300
314
  };
301
315
  const _AIFileContent = class _AIFileContent extends AIContent {
302
- constructor(fileUrl, fileName, f, error) {
303
- const extension = _AIFileContent.getExtensionFromFileName(fileName);
316
+ constructor(props) {
317
+ if (props.needsControlExtension === null || props.needsControlExtension === void 0) {
318
+ props.needsControlExtension = true;
319
+ }
320
+ const extension = _AIFileContent.getExtensionFromFileName(props.name);
304
321
  super();
305
- __publicField$5(this, "type");
306
- __publicField$5(this, "fileUrl");
307
- __publicField$5(this, "fileName");
308
- __publicField$5(this, "extension");
309
- __publicField$5(this, "__file");
310
- __publicField$5(this, "__error");
311
- __publicField$5(this, "overrideSize");
312
- __publicField$5(this, "inferContent", () => {
322
+ __publicField$9(this, "type");
323
+ __publicField$9(this, "value");
324
+ __publicField$9(this, "name");
325
+ __publicField$9(this, "extension");
326
+ __publicField$9(this, "__file");
327
+ __publicField$9(this, "__error");
328
+ __publicField$9(this, "onClose");
329
+ __publicField$9(this, "overrideSize");
330
+ __publicField$9(this, "id", uniqueId());
331
+ __publicField$9(this, "inferContent", () => {
313
332
  return `You must collect information contained in this ${this.type} as help to build your tool choice.`;
314
333
  });
315
- __publicField$5(this, "inferExtension", (extension) => {
334
+ __publicField$9(this, "inferExtension", (extension) => {
316
335
  switch (extension) {
317
336
  case AIFileContentAllowedExtensions.jpg:
318
337
  case AIFileContentAllowedExtensions.jpeg:
@@ -339,45 +358,64 @@ const _AIFileContent = class _AIFileContent extends AIContent {
339
358
  }
340
359
  });
341
360
  // COMPONENT METHODS
342
- __publicField$5(this, "Component", () => /* @__PURE__ */ jsxs(
343
- Box,
344
- {
345
- sx: {
346
- ...this.overrideSize ? {
347
- ...this.overrideSize,
348
- img: {
349
- width: `${this.overrideSize.width - 20}px`,
350
- height: `${this.overrideSize.height - 61}px`
351
- }
352
- } : {}
353
- },
354
- variant: "layout.common.components.aiMessage.fileBox",
355
- children: [
356
- FileType.IMAGE === this.type ? /* @__PURE__ */ jsx("img", { src: URL.createObjectURL(this.file), alt: this.fileName }) : /* @__PURE__ */ jsx(FileIcon, { iconSize: "lg", docName: this.fileName }),
357
- /* @__PURE__ */ jsx(
358
- Box,
359
- {
360
- as: "p",
361
- variant: "layout.common.components.aiMessage.fileName",
362
- title: this.fileName,
363
- children: this.fileName
364
- }
365
- )
366
- ]
367
- }
368
- ));
369
- this.__error = error;
370
- if (!_AIFileContent.isValidExtension(extension))
361
+ __publicField$9(this, "Component", () => {
362
+ const closeButton = this.onClose ? /* @__PURE__ */ jsx(
363
+ IconButton,
364
+ {
365
+ className: "file_close_button",
366
+ size: "Md",
367
+ icon: "Close",
368
+ onClick: this.onClose,
369
+ title: getLabel("lblDeleteItem").title
370
+ }
371
+ ) : null;
372
+ return /* @__PURE__ */ jsxs(
373
+ Box,
374
+ {
375
+ className: "file_box",
376
+ sx: {
377
+ ...this.overrideSize ? {
378
+ ...this.overrideSize,
379
+ img: {
380
+ width: `${this.overrideSize.width - 20}px`,
381
+ height: `${this.overrideSize.height - 61}px`
382
+ }
383
+ } : {}
384
+ },
385
+ variant: "layout.common.components.aiMessage.fileBox",
386
+ children: [
387
+ closeButton && closeButton,
388
+ FileType.IMAGE === this.type ? /* @__PURE__ */ jsx("img", { src: URL.createObjectURL(this.file), alt: this.name }) : /* @__PURE__ */ jsx(FileIcon, { iconSize: "lg", docName: this.name }),
389
+ /* @__PURE__ */ jsx(
390
+ Box,
391
+ {
392
+ as: "p",
393
+ variant: "layout.common.components.aiMessage.fileName",
394
+ title: this.name,
395
+ children: this.name
396
+ }
397
+ )
398
+ ]
399
+ }
400
+ );
401
+ });
402
+ this.__error = props.error;
403
+ if (props.needsControlExtension && !_AIFileContent.isValidExtension(extension))
371
404
  this.__throwError(
372
405
  new Error(_AIFileContent.__getExtensionErrorMessage(extension)),
373
406
  this.__error?.fileExtension
374
407
  );
375
- this.fileUrl = fileUrl;
408
+ this.value = props.value;
376
409
  this.extension = extension;
377
410
  this.type = this.inferExtension(this.extension);
378
- this.fileName = fileName;
379
- this.__file = f;
411
+ this.name = props.name;
412
+ this.__file = props.f;
380
413
  this.content = this.inferContent();
414
+ this.onClose = props.onClose;
415
+ }
416
+ setOnClose(callback) {
417
+ this.onClose = callback;
418
+ return this;
381
419
  }
382
420
  // PUBLIC METHODS
383
421
  setOverrideSize(overrideSize) {
@@ -390,7 +428,7 @@ const _AIFileContent = class _AIFileContent extends AIContent {
390
428
  return this.__file;
391
429
  }
392
430
  static getExtensionFromFileName(fileName) {
393
- return fileName.split(".", 2).pop();
431
+ return fileName.split(".").pop();
394
432
  }
395
433
  // PRIVATE METHODS
396
434
  static __getExtensionErrorMessage(extension) {
@@ -401,14 +439,17 @@ ${Object.keys(AIFileContentAllowedExtensions)}`;
401
439
  callback && callback();
402
440
  throw e;
403
441
  }
442
+ getId() {
443
+ return this.id;
444
+ }
404
445
  };
405
446
  // STATIC METHODS
406
- __publicField$5(_AIFileContent, "isValidExtension", (extension) => {
447
+ __publicField$9(_AIFileContent, "isValidExtension", (extension) => {
407
448
  return Object.values(
408
449
  AIFileContentAllowedExtensions
409
450
  ).includes(extension);
410
451
  });
411
- __publicField$5(_AIFileContent, "blobToBase64", async (blob) => {
452
+ __publicField$9(_AIFileContent, "blobToBase64", async (blob) => {
412
453
  return await ((blob2) => new Promise((resolve, reject) => {
413
454
  const reader = new FileReader();
414
455
  reader.onloadend = () => {
@@ -419,31 +460,37 @@ __publicField$5(_AIFileContent, "blobToBase64", async (blob) => {
419
460
  reader.readAsDataURL(blob2);
420
461
  }))(blob);
421
462
  });
422
- __publicField$5(_AIFileContent, "fromFile", async (f, error) => {
423
- const fileUrl = await ((f2) => new Promise((resolve, reject) => {
463
+ __publicField$9(_AIFileContent, "fromFile", async (props) => {
464
+ const fileUrl = await ((f) => new Promise((resolve, reject) => {
424
465
  const reader = new FileReader();
425
- reader.readAsDataURL(f2);
466
+ reader.readAsDataURL(f);
426
467
  reader.onload = () => resolve(reader.result);
427
468
  reader.onerror = () => reject();
428
- }))(f);
429
- return new _AIFileContent(fileUrl, f.name, f, error);
469
+ }))(props.f);
470
+ return new _AIFileContent({
471
+ value: fileUrl,
472
+ name: props.f.name,
473
+ f: props.f,
474
+ error: props.error,
475
+ needsControlExtension: props.needsControlExtension
476
+ });
430
477
  });
431
478
  let AIFileContent = _AIFileContent;
432
479
 
433
- var __defProp$4 = Object.defineProperty;
434
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
435
- var __publicField$4 = (obj, key, value) => {
436
- __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
480
+ var __defProp$8 = Object.defineProperty;
481
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
482
+ var __publicField$8 = (obj, key, value) => {
483
+ __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
437
484
  return value;
438
485
  };
439
486
  class AIMessageAttachments {
440
487
  constructor(role, content, close) {
441
488
  this.close = close;
442
- __publicField$4(this, "role");
443
- __publicField$4(this, "content");
444
- __publicField$4(this, "id", uniqueId());
445
- __publicField$4(this, "customDescription", false);
446
- __publicField$4(this, "addDescription", async () => {
489
+ __publicField$8(this, "role");
490
+ __publicField$8(this, "content");
491
+ __publicField$8(this, "id", uniqueId());
492
+ __publicField$8(this, "customDescription", false);
493
+ __publicField$8(this, "addDescription", async () => {
447
494
  const collector = new Collector();
448
495
  const collected = await collector.add(this.content).add(
449
496
  new collector.fields.textarea(
@@ -467,7 +514,7 @@ class AIMessageAttachments {
467
514
  this.customDescription = false;
468
515
  }
469
516
  });
470
- __publicField$4(this, "Component", (props) => /* @__PURE__ */ jsxs(Box, { ...getVariant("layout.common.components.aiMessage"), children: [
517
+ __publicField$8(this, "Component", (props) => /* @__PURE__ */ jsxs(Box, { ...getVariant("layout.common.components.aiMessage"), children: [
471
518
  props.closeButton ? /* @__PURE__ */ jsx(
472
519
  IconButton,
473
520
  {
@@ -492,6 +539,9 @@ class AIMessageAttachments {
492
539
  this.role = role;
493
540
  this.content = content;
494
541
  }
542
+ getId() {
543
+ return this.id;
544
+ }
495
545
  }
496
546
 
497
547
  const handleFileUploadAsMessage = async (fileInputElement, chatController) => {
@@ -527,6 +577,7 @@ const makeTextarea = (chatController) => {
527
577
  preventAppendUserMessages
528
578
  }) => {
529
579
  const [isLoading, setIsLoading] = useState(false);
580
+ const breakpoint = useBreakpointIndex();
530
581
  const submit = useCallback(() => {
531
582
  if (preventAppendUserMessages !== true)
532
583
  chatController.messages.add(chatController.state.current);
@@ -588,6 +639,95 @@ const makeTextarea = (chatController) => {
588
639
  ev.preventDefault();
589
640
  setDragging(true);
590
641
  };
642
+ const additionalButtons = [];
643
+ additionalButtons.push({
644
+ key: "prev",
645
+ children: /* @__PURE__ */ jsx(
646
+ SimpleButton,
647
+ {
648
+ title: getLabel("btnAiPrevious").title,
649
+ variant: "outline",
650
+ type: "button",
651
+ onClick: chatController.history.previous,
652
+ size: "sm",
653
+ children: getLabel("btnAiPrevious").text
654
+ }
655
+ )
656
+ });
657
+ additionalButtons.push({
658
+ key: "next",
659
+ children: /* @__PURE__ */ jsx(
660
+ SimpleButton,
661
+ {
662
+ title: getLabel("btnAiNext").title,
663
+ variant: "outline",
664
+ type: "button",
665
+ onClick: chatController.history.next,
666
+ size: "sm",
667
+ children: getLabel("btnAiNext").text
668
+ }
669
+ )
670
+ });
671
+ if (!hideDeleteButton) {
672
+ additionalButtons.push({
673
+ key: "delete",
674
+ children: /* @__PURE__ */ jsx(
675
+ SimpleButton,
676
+ {
677
+ title: getLabel("btnAiDelete").title,
678
+ variant: "outline",
679
+ type: "button",
680
+ onClick: () => {
681
+ chatController.state.current.message = "";
682
+ chatController.attachments.dropAll();
683
+ chatController.currentHistoryIndex = -1;
684
+ },
685
+ size: "sm",
686
+ children: getLabel("btnAiDelete").text
687
+ }
688
+ )
689
+ });
690
+ additionalButtons.push({
691
+ key: "deleteMessages",
692
+ children: /* @__PURE__ */ jsx(
693
+ SimpleButton,
694
+ {
695
+ title: getLabel("btnAiDeleteMessages").title,
696
+ variant: "outline",
697
+ type: "button",
698
+ onClick: () => chatController.messages.clear(),
699
+ size: "sm",
700
+ children: getLabel("btnAiDeleteMessages").text
701
+ }
702
+ )
703
+ });
704
+ }
705
+ const isPhone = breakpoint < 4;
706
+ let iconButton = /* @__PURE__ */ jsx(Fragment, {});
707
+ if (isPhone) {
708
+ iconButton = /* @__PURE__ */ jsx(
709
+ IconButton,
710
+ {
711
+ ...getVariant("layout.ai.execution.formsAssistant.settingsButton"),
712
+ iconSize: "Md",
713
+ size: "Lg",
714
+ icon: "Ellipsis",
715
+ isLoading: actualIsLoading,
716
+ onClick: () => {
717
+ const util = ApiaUtil.instance;
718
+ const items = [];
719
+ items.push(...additionalButtons);
720
+ if (items.length > 0)
721
+ util.menu.open({
722
+ menuProps: {
723
+ anchorPoint: { x: util.mouse.x, y: util.mouse.y }
724
+ },
725
+ items
726
+ });
727
+ }
728
+ }
729
+ );
730
+ }
591
731
  return /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexDirection: "column", width: "100%" }, children: [
592
732
  /* @__PURE__ */ jsx(
593
733
  Box,
@@ -701,54 +841,9 @@ const makeTextarea = (chatController) => {
701
841
  size: "Lg"
702
842
  }
703
843
  ),
704
- /* @__PURE__ */ jsx(
705
- SimpleButton,
706
- {
707
- title: getLabel("btnAiPrevious").title,
708
- variant: "outline",
709
- type: "button",
710
- onClick: chatController.history.previous,
711
- size: "sm",
712
- children: getLabel("btnAiPrevious").text
713
- }
714
- ),
715
- /* @__PURE__ */ jsx(
716
- SimpleButton,
717
- {
718
- title: getLabel("btnAiNext").title,
719
- variant: "outline",
720
- type: "button",
721
- onClick: chatController.history.next,
722
- size: "sm",
723
- children: getLabel("btnAiNext").text
724
- }
725
- ),
726
- !hideDeleteButton && /* @__PURE__ */ jsxs(Fragment, { children: [
727
- /* @__PURE__ */ jsx(
728
- SimpleButton,
729
- {
730
- title: getLabel("btnAiDelete").title,
731
- variant: "outline",
732
- type: "button",
733
- onClick: () => {
734
- chatController.state.current.message = "";
735
- chatController.attachments.dropAll();
736
- chatController.currentHistoryIndex = -1;
737
- },
738
- size: "sm",
739
- children: getLabel("btnAiDelete").text
740
- }
741
- ),
742
- /* @__PURE__ */ jsx(
743
- SimpleButton,
744
- {
745
- title: getLabel("btnAiDeleteMessages").title,
746
- variant: "outline",
747
- type: "button",
748
- onClick: () => chatController.messages.clear(),
749
- size: "sm",
750
- children: getLabel("btnAiDeleteMessages").text
751
- }
844
+ isPhone ? iconButton : /* @__PURE__ */ jsxs(Fragment, { children: [
845
+ ...additionalButtons.map(
846
+ (x) => x.children
752
847
  )
753
848
  ] }),
754
849
  /* @__PURE__ */ jsx(
@@ -772,10 +867,10 @@ const makeTextarea = (chatController) => {
772
867
  return NewTextarea;
773
868
  };
774
869
 
775
- var __defProp$3 = Object.defineProperty;
776
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
777
- var __publicField$3 = (obj, key, value) => {
778
- __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
870
+ var __defProp$7 = Object.defineProperty;
871
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
872
+ var __publicField$7 = (obj, key, value) => {
873
+ __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
779
874
  return value;
780
875
  };
781
876
  var __accessCheck = (obj, member, msg) => {
@@ -784,7 +879,7 @@ var __accessCheck = (obj, member, msg) => {
784
879
  };
785
880
  var __privateGet = (obj, member, getter) => {
786
881
  __accessCheck(obj, member, "read from private field");
787
- return getter ? getter.call(obj) : member.get(obj);
882
+ return member.get(obj);
788
883
  };
789
884
  var __privateAdd = (obj, member, value) => {
790
885
  if (member.has(obj))
@@ -793,18 +888,18 @@ var __privateAdd = (obj, member, value) => {
793
888
  };
794
889
  var __privateSet = (obj, member, value, setter) => {
795
890
  __accessCheck(obj, member, "write to private field");
796
- setter ? setter.call(obj, value) : member.set(obj, value);
891
+ member.set(obj, value);
797
892
  return value;
798
893
  };
799
894
  var _promptsHistory, _internalAudioRecorder;
800
895
  class ChatController {
801
896
  constructor(id, welcomeMessage) {
802
897
  this.id = id;
803
- __publicField$3(this, "state", {
898
+ __publicField$7(this, "state", {
804
899
  current: new ChatMessage(),
805
900
  messages: []
806
901
  });
807
- __publicField$3(this, "components", {
902
+ __publicField$7(this, "components", {
808
903
  MessageHistory: observer(() => {
809
904
  return /* @__PURE__ */ jsx(
810
905
  Box,
@@ -818,16 +913,16 @@ class ChatController {
818
913
  Textarea: makeTextarea(this)
819
914
  });
820
915
  __privateAdd(this, _promptsHistory, []);
821
- __publicField$3(this, "currentHistoryIndex", -1);
916
+ __publicField$7(this, "currentHistoryIndex", -1);
822
917
  __privateAdd(this, _internalAudioRecorder, new AudioRecorder());
823
- __publicField$3(this, "audioRecorder", {
918
+ __publicField$7(this, "audioRecorder", {
824
919
  start: () => __privateGet(this, _internalAudioRecorder).start().then(async (blob) => {
825
920
  const m = new AIMessageAttachments(
826
921
  AIMessageRole.USER,
827
- new AIFileContent(
828
- await AIFileContent.blobToBase64(blob),
829
- `userRecord_${this.audioRecorder.record++}.wav`
830
- ),
922
+ new AIFileContent({
923
+ value: await AIFileContent.blobToBase64(blob),
924
+ name: `userRecord_${this.audioRecorder.record++}.wav`
925
+ }),
831
926
  () => this.attachments.drop(m)
832
927
  );
833
928
  this.attachments.add(m);
@@ -838,7 +933,7 @@ class ChatController {
838
933
  record: 0,
839
934
  state: __privateGet(this, _internalAudioRecorder).state
840
935
  });
841
- __publicField$3(this, "history", {
936
+ __publicField$7(this, "history", {
842
937
  add: (message) => {
843
938
  this.currentHistoryIndex = -1;
844
939
  if (message === __privateGet(this, _promptsHistory)[__privateGet(this, _promptsHistory).length]) {
@@ -854,7 +949,7 @@ class ChatController {
854
949
  next: () => {
855
950
  let message = new ChatMessage();
856
951
  if (__privateGet(this, _promptsHistory)[this.currentHistoryIndex - 1])
857
- message = __privateGet(this, _promptsHistory)[--this.currentHistoryIndex].copy();
952
+ message = __privateGet(this, _promptsHistory)[--this.currentHistoryIndex].clone();
858
953
  else {
859
954
  this.currentHistoryIndex = -1;
860
955
  }
@@ -863,7 +958,7 @@ class ChatController {
863
958
  previous: () => {
864
959
  if (__privateGet(this, _promptsHistory)[this.currentHistoryIndex + 1]) {
865
960
  this.history.updateState(
866
- __privateGet(this, _promptsHistory)[++this.currentHistoryIndex].copy()
961
+ __privateGet(this, _promptsHistory)[++this.currentHistoryIndex].clone()
867
962
  );
868
963
  }
869
964
  },
@@ -875,7 +970,7 @@ class ChatController {
875
970
  },
876
971
  size: () => this.state.messages.length
877
972
  });
878
- __publicField$3(this, "messages", {
973
+ __publicField$7(this, "messages", {
879
974
  add: (message, idx) => {
880
975
  if (idx !== void 0 && idx !== null) {
881
976
  this.state.messages.splice(idx, 0, message);
@@ -887,19 +982,25 @@ class ChatController {
887
982
  this.state.messages = [];
888
983
  }
889
984
  });
890
- __publicField$3(this, "attachments", {
985
+ __publicField$7(this, "attachments", {
891
986
  add: (...aiMessage) => {
892
- this.state.current.attachments.push(...aiMessage);
987
+ this.state.current.attachments.push(
988
+ ...aiMessage
989
+ );
893
990
  },
894
991
  dropAll: () => void (this.state.current.attachments = []),
895
992
  drop: (el) => {
993
+ const e = el;
896
994
  this.state.current.attachments = this.state.current.attachments.filter(
897
- (c) => c !== el
995
+ (c) => c !== e
898
996
  );
899
997
  if (!this.state.current.message && this.attachments.size() < 1)
900
998
  this.currentHistoryIndex = -1;
901
999
  },
902
- getComponents: () => this.state.current.attachments.map((x) => /* @__PURE__ */ jsx(x.Component, { closeButton: true, canAddDescription: true }, x.id)),
1000
+ getComponents: () => this.state.current.attachments.map((x) => {
1001
+ const c = x;
1002
+ return /* @__PURE__ */ jsx(c.Component, { closeButton: true, canAddDescription: true }, x.id);
1003
+ }),
903
1004
  get: () => this.state.current.attachments,
904
1005
  size: () => this.state.current.attachments.length
905
1006
  });
@@ -940,74 +1041,87 @@ class MultipleChoiceMessage extends ChatMessage {
940
1041
  }
941
1042
  }
942
1043
 
943
- var __defProp$2 = Object.defineProperty;
944
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
945
- var __publicField$2 = (obj, key, value) => {
946
- __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
1044
+ const Component = observer(
1045
+ (props) => {
1046
+ return /* @__PURE__ */ jsxs(Box, { children: [
1047
+ /* @__PURE__ */ jsx("a", { href: props.instance.state.link, children: props.instance.state.title }),
1048
+ /* @__PURE__ */ jsx(Box, { children: props.instance.state.body })
1049
+ ] });
1050
+ }
1051
+ );
1052
+
1053
+ var __defProp$6 = Object.defineProperty;
1054
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1055
+ var __publicField$6 = (obj, key, value) => {
1056
+ __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
947
1057
  return value;
948
1058
  };
949
- class ResponseStream extends EventEmitter {
950
- constructor() {
951
- super(...arguments);
952
- __publicField$2(this, "buffer", "");
953
- __publicField$2(this, "isRunning", false);
954
- __publicField$2(this, "locked", false);
955
- __publicField$2(this, "maxCompletionTime", 2);
956
- // s
957
- __publicField$2(this, "minPartSize", 2);
958
- __publicField$2(this, "partSize", 2);
959
- __publicField$2(this, "timing", 5);
960
- // ms
961
- __publicField$2(this, "waiting", []);
1059
+ class SemanticSearchReference {
1060
+ constructor(props) {
1061
+ __publicField$6(this, "state", { title: "", body: "", link: "" });
1062
+ __publicField$6(this, "Component", () => /* @__PURE__ */ jsxs(Fragment, { children: [
1063
+ "(",
1064
+ /* @__PURE__ */ jsx(Component, { instance: this }),
1065
+ ")"
1066
+ ] }));
1067
+ this.state = props;
1068
+ makeObservable(this, { state: observable });
962
1069
  }
963
- close() {
1070
+ }
1071
+
1072
+ var __defProp$5 = Object.defineProperty;
1073
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1074
+ var __publicField$5 = (obj, key, value) => {
1075
+ __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
1076
+ return value;
1077
+ };
1078
+ const _SearchController = class _SearchController {
1079
+ constructor() {
1080
+ __publicField$5(this, "state", { queryString: "", results: [], isLoading: false, disabled: false });
1081
+ makeObservable(this, { state: observable });
964
1082
  }
965
- calculatePartSize() {
966
- const totalSize = this.buffer.length + this.waiting.reduce((a, b) => a + b.length, 0);
967
- this.partSize = Math.max(
968
- this.minPartSize,
969
- totalSize * this.timing / (this.maxCompletionTime * 1e3)
1083
+ async search(selectedId) {
1084
+ const filters = await FiltersStore.getFiltersById(
1085
+ Number.parseInt(selectedId)
970
1086
  );
971
- }
972
- emit(_, data) {
973
- if (this.locked) {
974
- this.waiting.push(data);
975
- } else {
976
- this.buffer += data;
1087
+ FiltersStore.setFilters(filters, "U");
1088
+ _SearchController.instance.state.isLoading = true;
1089
+ const response = await ApiaApi.post(
1090
+ makeApiaUrl({
1091
+ action: "search",
1092
+ semSearchId: selectedId
1093
+ }),
1094
+ {
1095
+ postData: {
1096
+ q: _SearchController.instance.state.queryString,
1097
+ filters: JSON.stringify(FiltersStore.getFiltersAsFilterValue("U"))
1098
+ },
1099
+ postDataTreatement: "stringify",
1100
+ stringifyOptions: { arrayFormat: "repeat" }
1101
+ }
1102
+ );
1103
+ if (response?.data?.results) {
1104
+ this.setReferences(response.data.results);
977
1105
  }
978
- this.calculatePartSize();
979
- this.run();
1106
+ this.state.isLoading = false;
980
1107
  }
981
- run() {
982
- if (!this.isRunning) {
983
- this.isRunning = true;
984
- const interval = setInterval(() => {
985
- this.locked = true;
986
- const choosedSize = Math.min(this.buffer.length, this.partSize);
987
- const part = this.buffer.slice(0, choosedSize);
988
- this.buffer = this.buffer.slice(choosedSize);
989
- while (this.waiting.length > 0) {
990
- const part2 = this.waiting.shift();
991
- if (part2) {
992
- this.buffer += part2;
993
- }
994
- }
995
- this.locked = false;
996
- if (part) {
997
- super.emit("part", part);
998
- } else {
999
- this.isRunning = false;
1000
- clearInterval(interval);
1001
- }
1002
- }, this.timing);
1108
+ setReferences(results) {
1109
+ if (typeof results === "string" && results) {
1110
+ results = JSON.parse(results);
1003
1111
  }
1112
+ _SearchController.instance.state.results = results.map(
1113
+ (x) => x instanceof SemanticSearchReference ? x : new SemanticSearchReference(x)
1114
+ );
1115
+ _SearchController.instance.state.disabled = false;
1004
1116
  }
1005
- }
1117
+ };
1118
+ __publicField$5(_SearchController, "instance", new _SearchController());
1119
+ let SearchController = _SearchController;
1006
1120
 
1007
- var __defProp$1 = Object.defineProperty;
1008
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1009
- var __publicField$1 = (obj, key, value) => {
1010
- __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
1121
+ var __defProp$4 = Object.defineProperty;
1122
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1123
+ var __publicField$4 = (obj, key, value) => {
1124
+ __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
1011
1125
  return value;
1012
1126
  };
1013
1127
  function isPollProgress(payload) {
@@ -1015,9 +1129,9 @@ function isPollProgress(payload) {
1015
1129
  }
1016
1130
  class RoutinesGeneration {
1017
1131
  constructor() {
1018
- __publicField$1(this, "audioRecorder", new AudioRecorder());
1019
- __publicField$1(this, "routineId", "");
1020
- __publicField$1(this, "state", {
1132
+ __publicField$4(this, "audioRecorder", new AudioRecorder());
1133
+ __publicField$4(this, "routineId", "");
1134
+ __publicField$4(this, "state", {
1021
1135
  isLoading: false,
1022
1136
  progress: 0
1023
1137
  });
@@ -1034,9 +1148,14 @@ class RoutinesGeneration {
1034
1148
  }
1035
1149
  this.state.isLoading = true;
1036
1150
  }
1037
- async pollRoutine(stream) {
1151
+ async pollRoutine(routineId, stream) {
1152
+ this.routineId = routineId;
1153
+ this.state.isLoading = true;
1154
+ return this.internalPollRoutine(stream);
1155
+ }
1156
+ async internalPollRoutine(stream) {
1038
1157
  while (this.state.isLoading) {
1039
- const pollResult = await this.poll(this.routineId);
1158
+ const pollResult = await this.callRoutinePoll(this.routineId);
1040
1159
  if (isPollProgress(pollResult.payload)) {
1041
1160
  try {
1042
1161
  const res = JSON.parse(pollResult.payload.debug);
@@ -1055,43 +1174,33 @@ class RoutinesGeneration {
1055
1174
  } else if (pollResult.status === "FINISHED") {
1056
1175
  this.resetLoading();
1057
1176
  return pollResult.payload;
1177
+ } else if (pollResult.status === "ERROR") {
1178
+ this.resetLoading();
1179
+ throw new Error(pollResult.payload);
1058
1180
  } else {
1181
+ this.resetLoading();
1059
1182
  throw new Error("Wrong poll response");
1060
1183
  }
1061
1184
  }
1062
1185
  return null;
1063
1186
  }
1064
- async executeRoutine(routineName, prompts, images, stream) {
1065
- this.checkCanGenerate();
1066
- try {
1067
- const routineStartResult = await ApiaApi.post(
1068
- makeApiaUrl({
1069
- action: "routineStart",
1070
- routine: routineName
1071
- }),
1072
- {
1073
- postData: {
1074
- images: JSON.stringify(images),
1075
- ...prompts
1076
- },
1077
- stringifyOptions: {
1078
- arrayFormat: "repeat"
1079
- },
1080
- postDataTreatement: "stringify"
1081
- }
1082
- );
1083
- if (routineStartResult?.data?.orchestrator?.routineId !== void 0) {
1084
- this.routineId = routineStartResult?.data?.orchestrator?.routineId;
1085
- return this.pollRoutine(stream);
1086
- } else {
1087
- throw new Error("Cannot get routine id");
1187
+ async callAudioTranscription(audio) {
1188
+ const url = makeApiaUrl({
1189
+ action: "routineStart",
1190
+ routine: "transcription/Transcribe"
1191
+ });
1192
+ const response = await axios.post(url, audio.arrayBuffer(), {
1193
+ headers: {
1194
+ "Content-Type": "application/octet-stream"
1088
1195
  }
1089
- } catch (e) {
1090
- this.resetLoading();
1091
- throw e;
1196
+ });
1197
+ const result = await parseSuccessfulResponse(response, "");
1198
+ if (result?.orchestrator) {
1199
+ return result;
1092
1200
  }
1201
+ return null;
1093
1202
  }
1094
- async poll(routineId) {
1203
+ async callRoutinePoll(routineId) {
1095
1204
  const result = await ApiaApi.post(
1096
1205
  makeApiaUrl({
1097
1206
  action: "routinePoll",
@@ -1104,6 +1213,44 @@ class RoutinesGeneration {
1104
1213
  throw new Error("Poll failed");
1105
1214
  }
1106
1215
  }
1216
+ async callRoutineStart(routineName, parameters, images) {
1217
+ const result = await ApiaApi.post(
1218
+ makeApiaUrl({
1219
+ action: "routineStart",
1220
+ routine: routineName
1221
+ }),
1222
+ {
1223
+ postData: {
1224
+ images: JSON.stringify(images),
1225
+ ...parameters
1226
+ },
1227
+ stringifyOptions: {
1228
+ arrayFormat: "repeat"
1229
+ },
1230
+ postDataTreatement: "stringify"
1231
+ }
1232
+ );
1233
+ return result?.data || null;
1234
+ }
1235
+ async executeRoutine(routineName, parameters, images, stream) {
1236
+ this.checkCanGenerate();
1237
+ try {
1238
+ const result = await this.callRoutineStart(
1239
+ routineName,
1240
+ parameters,
1241
+ images
1242
+ );
1243
+ if (result?.orchestrator?.routineId !== void 0) {
1244
+ this.routineId = result?.orchestrator.routineId;
1245
+ return this.internalPollRoutine(stream);
1246
+ } else {
1247
+ throw new Error("Cannot get routine id");
1248
+ }
1249
+ } catch (e) {
1250
+ this.resetLoading();
1251
+ throw e;
1252
+ }
1253
+ }
1107
1254
  resetLoading() {
1108
1255
  this.state.isLoading = false;
1109
1256
  this.state.progress = 0;
@@ -1126,33 +1273,135 @@ class RoutinesGeneration {
1126
1273
  );
1127
1274
  }
1128
1275
  async transcribeAudio(audio) {
1129
- const arrayBuffer = await audio.arrayBuffer();
1130
- const url = makeApiaUrl({
1131
- action: "routineStart",
1132
- routine: "transcription/Transcribe"
1133
- });
1134
- const response = await axios.post(url, arrayBuffer, {
1135
- headers: {
1136
- "Content-Type": "application/octet-stream"
1137
- }
1138
- });
1139
- if (response.data) {
1140
- const result = await parseSuccessfulResponse(response, url);
1276
+ const result = await this.callAudioTranscription(audio);
1277
+ if (result) {
1141
1278
  this.state.isLoading = true;
1142
1279
  if (result?.orchestrator?.routineId) {
1143
1280
  this.routineId = result?.orchestrator?.routineId;
1144
- return await this.pollRoutine();
1281
+ return await this.internalPollRoutine();
1145
1282
  }
1146
1283
  }
1147
1284
  throw new Error("Something went wrong while transcribing the audio");
1148
1285
  }
1149
1286
  }
1150
1287
 
1151
- async function getImageFromDisk(inputProps) {
1152
- return (await getImagesFromDisk({ ...inputProps, multiple: "false" }))[0] ?? null;
1153
- }
1154
- function getImagesFromDisk(inputProps) {
1155
- return new Promise((resolve) => {
1288
+ class DashboardsRoutinesGeneration extends RoutinesGeneration {
1289
+ constructor(dispatcher) {
1290
+ super();
1291
+ this.dispatcher = dispatcher;
1292
+ }
1293
+ blobToBase64(audio) {
1294
+ return new Promise((resolve, reject) => {
1295
+ const reader = new FileReader();
1296
+ reader.onloadend = () => {
1297
+ if (reader.result && typeof reader.result === "string") {
1298
+ const base64 = reader.result.split(",")[1];
1299
+ resolve(base64);
1300
+ } else {
1301
+ reject(new Error("Could not convert Blob to base64"));
1302
+ }
1303
+ };
1304
+ reader.onerror = reject;
1305
+ reader.readAsDataURL(audio);
1306
+ });
1307
+ }
1308
+ async callAudioTranscription(audio) {
1309
+ const audioBase64 = await this.blobToBase64(audio);
1310
+ const result = await this.dispatcher({
1311
+ action: "transcription",
1312
+ audioBase64
1313
+ });
1314
+ return result?.data || null;
1315
+ }
1316
+ async callRoutinePoll(routineId) {
1317
+ const result = await this.dispatcher({
1318
+ action: "routinePoll",
1319
+ routineId
1320
+ });
1321
+ if (result?.data?.orchestrator) {
1322
+ const parsed = JSON.parse(result.data.orchestrator);
1323
+ return parsed;
1324
+ }
1325
+ throw new Error("Poll failed");
1326
+ }
1327
+ async callRoutineStart(routineName, parameters, images) {
1328
+ const result = await this.dispatcher({
1329
+ action: "routineStart",
1330
+ routine: routineName,
1331
+ ...parameters,
1332
+ images
1333
+ });
1334
+ return result?.data || null;
1335
+ }
1336
+ }
1337
+
1338
+ var __defProp$3 = Object.defineProperty;
1339
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1340
+ var __publicField$3 = (obj, key, value) => {
1341
+ __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
1342
+ return value;
1343
+ };
1344
+ class ResponseStream extends EventEmitter {
1345
+ constructor() {
1346
+ super(...arguments);
1347
+ __publicField$3(this, "buffer", "");
1348
+ __publicField$3(this, "isRunning", false);
1349
+ __publicField$3(this, "locked", false);
1350
+ __publicField$3(this, "maxCompletionTime", 2);
1351
+ // s
1352
+ __publicField$3(this, "minPartSize", 2);
1353
+ __publicField$3(this, "partSize", 2);
1354
+ __publicField$3(this, "timing", 5);
1355
+ // ms
1356
+ __publicField$3(this, "waiting", []);
1357
+ }
1358
+ calculatePartSize() {
1359
+ const totalSize = this.buffer.length + this.waiting.reduce((a, b) => a + b.length, 0);
1360
+ this.partSize = Math.max(
1361
+ this.minPartSize,
1362
+ totalSize * this.timing / (this.maxCompletionTime * 1e3)
1363
+ );
1364
+ }
1365
+ emit(_, data) {
1366
+ if (this.locked) {
1367
+ this.waiting.push(data);
1368
+ } else {
1369
+ this.buffer += data;
1370
+ }
1371
+ this.calculatePartSize();
1372
+ this.run();
1373
+ }
1374
+ run() {
1375
+ if (!this.isRunning) {
1376
+ this.isRunning = true;
1377
+ const interval = setInterval(() => {
1378
+ this.locked = true;
1379
+ const choosedSize = Math.min(this.buffer.length, this.partSize);
1380
+ const part = this.buffer.slice(0, choosedSize);
1381
+ this.buffer = this.buffer.slice(choosedSize);
1382
+ while (this.waiting.length > 0) {
1383
+ const part2 = this.waiting.shift();
1384
+ if (part2) {
1385
+ this.buffer += part2;
1386
+ }
1387
+ }
1388
+ this.locked = false;
1389
+ if (part) {
1390
+ super.emit("part", part);
1391
+ } else {
1392
+ this.isRunning = false;
1393
+ clearInterval(interval);
1394
+ }
1395
+ }, this.timing);
1396
+ }
1397
+ }
1398
+ }
1399
+
1400
+ async function getImageFromDisk(inputProps) {
1401
+ return (await getImagesFromDisk({ ...inputProps, multiple: "false" }))[0] ?? null;
1402
+ }
1403
+ function getImagesFromDisk(inputProps) {
1404
+ return new Promise((resolve) => {
1156
1405
  const input = document.createElement("input");
1157
1406
  input.accept = "image/*";
1158
1407
  input.type = "file";
@@ -1209,17 +1458,17 @@ function getSrcFromBase64(base64) {
1209
1458
  return `data:image/jpg;base64,${base64}`;
1210
1459
  }
1211
1460
 
1212
- var __defProp = Object.defineProperty;
1213
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1214
- var __publicField = (obj, key, value) => {
1215
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1461
+ var __defProp$2 = Object.defineProperty;
1462
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1463
+ var __publicField$2 = (obj, key, value) => {
1464
+ __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
1216
1465
  return value;
1217
1466
  };
1218
1467
  class ImagesStore {
1219
1468
  constructor(images, multiple) {
1220
1469
  this.multiple = multiple;
1221
- __publicField(this, "images", /* @__PURE__ */ new Map());
1222
- __publicField(this, "selectedId", "");
1470
+ __publicField$2(this, "images", /* @__PURE__ */ new Map());
1471
+ __publicField$2(this, "selectedId", "");
1223
1472
  this.images = new Map(
1224
1473
  images.map((c) => {
1225
1474
  const id = uniqueId();
@@ -1345,5 +1594,667 @@ function getImagesWithDescription({
1345
1594
  });
1346
1595
  }
1347
1596
 
1348
- export { AIMessageAttachments, AutoscrollContainer, ChatController, ChatMessage, MultipleChoiceMessage, ResponseStream, RoutinesGeneration, getImageFromDisk, getImagesFromDisk, getImagesWithDescription };
1597
+ const ViewRendererContext = createContext(
1598
+ {}
1599
+ );
1600
+
1601
+ const FileAttachment = observer(
1602
+ ({
1603
+ attachment,
1604
+ onRemove
1605
+ }) => {
1606
+ return /* @__PURE__ */ jsxs(Box, { className: "file_box", children: [
1607
+ /* @__PURE__ */ jsx(FileIcon, { className: "file_box__icon", docName: attachment.name }),
1608
+ /* @__PURE__ */ jsx(Box, { className: "file_box__name", title: attachment.name, children: attachment.name }),
1609
+ onRemove && /* @__PURE__ */ jsx(
1610
+ IconButton,
1611
+ {
1612
+ icon: "Close",
1613
+ className: "file_box__remove",
1614
+ onClick: onRemove,
1615
+ variant: "icon-only"
1616
+ }
1617
+ )
1618
+ ] });
1619
+ }
1620
+ );
1621
+
1622
+ const Attachments = observer(
1623
+ ({
1624
+ attachments,
1625
+ onRemove
1626
+ }) => {
1627
+ if (!attachments.length)
1628
+ return null;
1629
+ return /* @__PURE__ */ jsx(
1630
+ Box,
1631
+ {
1632
+ className: "attachments",
1633
+ ...getVariant("layout.common.chat.attachments"),
1634
+ children: attachments.map((x) => /* @__PURE__ */ jsx(
1635
+ FileAttachment,
1636
+ {
1637
+ attachment: x,
1638
+ onRemove: onRemove ? () => onRemove(x) : void 0
1639
+ },
1640
+ x.id
1641
+ ))
1642
+ }
1643
+ );
1644
+ }
1645
+ );
1646
+
1647
+ const Message = observer(
1648
+ ({
1649
+ className,
1650
+ type,
1651
+ id,
1652
+ message,
1653
+ attachments,
1654
+ reference
1655
+ }) => {
1656
+ return /* @__PURE__ */ jsxs(
1657
+ Box,
1658
+ {
1659
+ as: "pre",
1660
+ className: `history_message ${className || ""} ${type}`,
1661
+ children: [
1662
+ /* @__PURE__ */ jsx(
1663
+ Box,
1664
+ {
1665
+ className: "history_message__content",
1666
+ ...typeof message === "string" ? { dangerouslySetInnerHTML: { __html: message } } : { children: message }
1667
+ }
1668
+ ),
1669
+ attachments.length > 0 && /* @__PURE__ */ jsx(Attachments, { attachments }),
1670
+ reference && /* @__PURE__ */ jsx(Box, { className: "history_message__references", children: reference })
1671
+ ]
1672
+ },
1673
+ id
1674
+ );
1675
+ }
1676
+ );
1677
+
1678
+ const History = observer(({ messages }) => {
1679
+ let currentType = "";
1680
+ return /* @__PURE__ */ jsx(AutoscrollContainer, { children: /* @__PURE__ */ jsx(
1681
+ Box,
1682
+ {
1683
+ ...getVariant("layout.common.chat.history"),
1684
+ className: "chat_history",
1685
+ children: messages.map((current, i) => {
1686
+ let first = false;
1687
+ let last = false;
1688
+ if (currentType !== current.messageType) {
1689
+ currentType = current.messageType;
1690
+ first = true;
1691
+ }
1692
+ if (i === messages.length - 1 || messages[i + 1].messageType !== current.messageType) {
1693
+ last = true;
1694
+ }
1695
+ return /* @__PURE__ */ jsx(
1696
+ Message,
1697
+ {
1698
+ className: first ? "first" : last ? "last" : void 0,
1699
+ type: current.messageType,
1700
+ id: String(current.id),
1701
+ attachments: current.attachments,
1702
+ reference: current.reference,
1703
+ message: current.message
1704
+ }
1705
+ );
1706
+ })
1707
+ }
1708
+ ) });
1709
+ });
1710
+
1711
+ function getBase64FromFile(f) {
1712
+ return ((f2) => new Promise((resolve, reject) => {
1713
+ const reader = new FileReader();
1714
+ reader.readAsDataURL(f2);
1715
+ reader.onload = () => resolve(reader.result);
1716
+ reader.onerror = () => reject();
1717
+ }))(f);
1718
+ }
1719
+ function getBase64FromBlob(b) {
1720
+ return ((blob) => new Promise((resolve, reject) => {
1721
+ const reader = new FileReader();
1722
+ reader.onloadend = () => {
1723
+ const base64String = reader.result;
1724
+ resolve(base64String);
1725
+ };
1726
+ reader.onerror = reject;
1727
+ reader.readAsDataURL(blob);
1728
+ }))(b);
1729
+ }
1730
+
1731
+ const TextArea = observer(
1732
+ ({
1733
+ isLoading,
1734
+ isRecording,
1735
+ onSubmit,
1736
+ onChange,
1737
+ onClearHistory,
1738
+ onClearAttachments,
1739
+ onClearMessage,
1740
+ onAttach,
1741
+ onRecord,
1742
+ onVideoRecord,
1743
+ onPrev,
1744
+ onNext,
1745
+ hideDeleteButton,
1746
+ value,
1747
+ id
1748
+ }) => {
1749
+ const fileInputRef = useRef(null);
1750
+ const searchControlsRef = useRef(null);
1751
+ const recordButton = /* @__PURE__ */ jsx(
1752
+ IconButton,
1753
+ {
1754
+ variant: "icon-only",
1755
+ onClick: onRecord,
1756
+ disabled: isLoading && !isRecording,
1757
+ sx: {
1758
+ color: isRecording ? "red" : void 0
1759
+ },
1760
+ icon: isRecording ? "Stop" : "Microphone",
1761
+ id: "transcribeAudio",
1762
+ iconSize: "Sm",
1763
+ title: getLabel("lblAiRecordAudio").text
1764
+ }
1765
+ );
1766
+ const handleAttachments = async (ev) => {
1767
+ if (ev.target.files) {
1768
+ for await (const f of ev.target.files) {
1769
+ const base64 = await getBase64FromFile(f);
1770
+ onAttach({
1771
+ value: base64,
1772
+ name: f.name,
1773
+ id: f.name
1774
+ });
1775
+ }
1776
+ }
1777
+ };
1778
+ const iconsList = [
1779
+ {
1780
+ icon: "ArrowLeft",
1781
+ children: getLabel("btnAiPrevious").text,
1782
+ title: getLabel("btnAiPrevious").text,
1783
+ onClick: onPrev,
1784
+ key: "0"
1785
+ },
1786
+ {
1787
+ icon: "ArrowRight",
1788
+ children: getLabel("btnAiNext").text,
1789
+ title: getLabel("btnAiNext").text,
1790
+ onClick: onNext,
1791
+ key: "1"
1792
+ },
1793
+ {
1794
+ children: getLabel("btnUpload").text,
1795
+ title: getLabel("btnUpload").text,
1796
+ icon: "File",
1797
+ onClick: () => fileInputRef.current?.click(),
1798
+ key: "2"
1799
+ },
1800
+ {
1801
+ title: getLabel("lblOpenCamera").text,
1802
+ children: getLabel("lblOpenCamera").text,
1803
+ icon: "Camera",
1804
+ onClick: onVideoRecord,
1805
+ key: "3"
1806
+ },
1807
+ {
1808
+ title: getLabel("lblAiRecordAudio").text,
1809
+ children: getLabel("lblAiRecordAudio").text,
1810
+ key: "4",
1811
+ onClick: (event) => onRecord(event),
1812
+ icon: isRecording ? "Stop" : "Microphone"
1813
+ },
1814
+ ...hideDeleteButton ? [] : [
1815
+ {
1816
+ icon: "Trash",
1817
+ onClick: onClearHistory,
1818
+ key: "5",
1819
+ children: getLabel("btnAiDeleteMessages").text,
1820
+ title: getLabel("btnAiDeleteMessages").text
1821
+ },
1822
+ {
1823
+ icon: "Erase",
1824
+ title: getLabel("btnAiDelete").text,
1825
+ children: getLabel("btnAiDelete").text,
1826
+ onClick: () => {
1827
+ onClearMessage();
1828
+ onClearAttachments();
1829
+ },
1830
+ key: "6"
1831
+ }
1832
+ ]
1833
+ ];
1834
+ return /* @__PURE__ */ jsxs(
1835
+ Form,
1836
+ {
1837
+ id,
1838
+ onSubmit: (ev) => {
1839
+ ev.preventDefault();
1840
+ onSubmit();
1841
+ },
1842
+ className: "search_controls",
1843
+ ...getVariant("layout.common.chat.form"),
1844
+ children: [
1845
+ /* @__PURE__ */ jsx(
1846
+ Textarea,
1847
+ {
1848
+ ref: searchControlsRef,
1849
+ "aria-label": (
1850
+ /** TODO: Crear etiqueta para búsqueda */
1851
+ "Frase de b\xFAsqueda"
1852
+ ),
1853
+ value,
1854
+ className: "searchTextArea",
1855
+ onChange: (ev) => onChange(ev.target.value),
1856
+ onKeyDown: (ev) => {
1857
+ if (ev.code === "Enter" && !ev.shiftKey) {
1858
+ ev.preventDefault();
1859
+ ev.target.closest("form").querySelector('[type="submit"]').click();
1860
+ }
1861
+ }
1862
+ }
1863
+ ),
1864
+ isRecording && recordButton,
1865
+ /* @__PURE__ */ jsx(
1866
+ "input",
1867
+ {
1868
+ ref: fileInputRef,
1869
+ id: "invisible__attach__file",
1870
+ type: "file",
1871
+ multiple: true,
1872
+ onChange: handleAttachments,
1873
+ sx: { display: "none" }
1874
+ }
1875
+ ),
1876
+ /* @__PURE__ */ jsx(
1877
+ IconButton,
1878
+ {
1879
+ disabled: isLoading,
1880
+ icon: "Ellipsis",
1881
+ variant: "icon-only",
1882
+ iconSize: "Sm",
1883
+ onClick: (ev) => {
1884
+ ApiaUtil.instance.menu.open({
1885
+ menuProps: {
1886
+ anchorPoint: { x: ev.clientX, y: ev.clientY }
1887
+ },
1888
+ items: iconsList
1889
+ });
1890
+ }
1891
+ }
1892
+ ),
1893
+ /* @__PURE__ */ jsx(
1894
+ IconButton,
1895
+ {
1896
+ className: "SearchButton",
1897
+ isLoading,
1898
+ icon: "ArrowRight",
1899
+ variant: "icon-only",
1900
+ iconSize: "Sm",
1901
+ title: getLabel("btnBus").title,
1902
+ type: "submit"
1903
+ }
1904
+ )
1905
+ ]
1906
+ }
1907
+ );
1908
+ }
1909
+ );
1910
+
1911
+ var __defProp$1 = Object.defineProperty;
1912
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1913
+ var __publicField$1 = (obj, key, value) => {
1914
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
1915
+ return value;
1916
+ };
1917
+ class CameraController {
1918
+ constructor() {
1919
+ __publicField$1(this, "state", {
1920
+ videoStream: null,
1921
+ isOpen: false
1922
+ });
1923
+ __publicField$1(this, "currentCapture", null);
1924
+ __publicField$1(this, "videoElement");
1925
+ __publicField$1(this, "Component", () => {
1926
+ return /* @__PURE__ */ jsx(
1927
+ "video",
1928
+ {
1929
+ ref: (el) => {
1930
+ if (el) {
1931
+ el.srcObject = this.videoElement.srcObject;
1932
+ el.autoplay = true;
1933
+ el.playsInline = true;
1934
+ }
1935
+ },
1936
+ style: { width: "100%", height: "auto" }
1937
+ }
1938
+ );
1939
+ });
1940
+ makeObservable(this, {
1941
+ state: observable,
1942
+ openCamera: action,
1943
+ closeCamera: action
1944
+ });
1945
+ this.videoElement = document.createElement("video");
1946
+ this.videoElement.autoplay = true;
1947
+ this.videoElement.playsInline = true;
1948
+ }
1949
+ async openCamera() {
1950
+ try {
1951
+ const stream = await navigator.mediaDevices.getUserMedia({ video: true });
1952
+ this.state.videoStream = stream;
1953
+ this.videoElement.srcObject = stream;
1954
+ this.state.isOpen = true;
1955
+ ApiaUtil.instance.modals.open({
1956
+ children: /* @__PURE__ */ jsx(this.Component, {}),
1957
+ onConfirm: () => {
1958
+ this.closeCamera();
1959
+ },
1960
+ onClose: () => {
1961
+ this.state.isOpen = false;
1962
+ this.closeCamera();
1963
+ }
1964
+ });
1965
+ } catch (error) {
1966
+ console.error("Error while accessing the camera:", error);
1967
+ this.state.isOpen = false;
1968
+ this.closeCamera();
1969
+ }
1970
+ }
1971
+ async closeCamera() {
1972
+ if (!this.videoElement.srcObject)
1973
+ return null;
1974
+ const canvas = document.createElement("canvas");
1975
+ canvas.width = this.videoElement.videoWidth;
1976
+ canvas.height = this.videoElement.videoHeight;
1977
+ const ctx = canvas.getContext("2d");
1978
+ if (ctx)
1979
+ ctx.drawImage(this.videoElement, 0, 0, canvas.width, canvas.height);
1980
+ this.currentCapture = await new Promise((resolve) => {
1981
+ canvas.toBlob((blob) => {
1982
+ if (blob) {
1983
+ const file = new File([blob], "captured_image.jpg", {
1984
+ type: "image/jpeg"
1985
+ });
1986
+ resolve(file);
1987
+ } else {
1988
+ resolve(null);
1989
+ }
1990
+ }, "image/jpeg");
1991
+ }).finally(() => {
1992
+ this.state.videoStream?.getTracks().forEach((track) => track.stop());
1993
+ this.state.videoStream = null;
1994
+ this.videoElement.srcObject = null;
1995
+ this.state.isOpen = false;
1996
+ });
1997
+ }
1998
+ pop() {
1999
+ const returnFile = this.currentCapture;
2000
+ this.currentCapture = null;
2001
+ return returnFile;
2002
+ }
2003
+ }
2004
+
2005
+ var __defProp = Object.defineProperty;
2006
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2007
+ var __publicField = (obj, key, value) => {
2008
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
2009
+ return value;
2010
+ };
2011
+ class ChatController2 {
2012
+ constructor(props, onMessageSubmit, id) {
2013
+ this.onMessageSubmit = onMessageSubmit;
2014
+ this.id = id;
2015
+ __publicField(this, "currentIndex", 0);
2016
+ __publicField(this, "needsControlExtension", false);
2017
+ __publicField(this, "state", {
2018
+ isVisible: false,
2019
+ isLoading: false,
2020
+ canRecord: true,
2021
+ canAttach: true,
2022
+ canAddSystemMessage: true,
2023
+ hideDeleteButton: false,
2024
+ canAddUserMessage: true,
2025
+ maxAttachmentsSize: 100,
2026
+ messages: [],
2027
+ currentMessage: new ChatMessage("", "user")
2028
+ });
2029
+ __publicField(this, "internalAudioRecorder", new AudioRecorder());
2030
+ __publicField(this, "internalCameraRecorder", new CameraController());
2031
+ __publicField(this, "maxId", 0);
2032
+ __publicField(this, "audioRecorder", {
2033
+ start: () => {
2034
+ this.internalAudioRecorder.start().then(async (blob) => {
2035
+ this.state.currentMessage.attachments.push({
2036
+ id: String(this.maxId++),
2037
+ name: `userRecord_${this.audioRecorder.record++}.wav`,
2038
+ value: await getBase64FromBlob(blob)
2039
+ });
2040
+ });
2041
+ },
2042
+ stop: async () => {
2043
+ this.internalAudioRecorder.stop();
2044
+ },
2045
+ record: 0,
2046
+ state: this.internalAudioRecorder.state
2047
+ });
2048
+ __publicField(this, "History", observer(() => /* @__PURE__ */ jsx(History, { messages: this.state.messages })));
2049
+ __publicField(this, "Attachments", observer(() => /* @__PURE__ */ jsx(
2050
+ Attachments,
2051
+ {
2052
+ attachments: this.state.currentMessage.attachments,
2053
+ onRemove: (a) => {
2054
+ this.removeAttachment(a);
2055
+ }
2056
+ }
2057
+ )));
2058
+ __publicField(this, "TextArea", observer(() => /* @__PURE__ */ jsx(
2059
+ TextArea,
2060
+ {
2061
+ id: this.id,
2062
+ value: this.state.currentMessage.message,
2063
+ isLoading: this.state.isLoading,
2064
+ isRecording: this.internalAudioRecorder.state.recording,
2065
+ onChange: (ev) => {
2066
+ this.state.currentMessage.message = ev;
2067
+ },
2068
+ onSubmit: () => {
2069
+ if (this.state.currentMessage.message || this.state.currentMessage.attachments.length > 0) {
2070
+ this.onMessageSubmit({
2071
+ message: this.state.currentMessage
2072
+ });
2073
+ this.state.currentMessage = new ChatMessage("", "user");
2074
+ }
2075
+ },
2076
+ onClearHistory: () => {
2077
+ this.clearHistory();
2078
+ },
2079
+ onClearAttachments: () => {
2080
+ this.state.currentMessage.attachments = [];
2081
+ },
2082
+ onClearMessage: () => {
2083
+ this.clearMessage();
2084
+ },
2085
+ onAttach: async (ev) => {
2086
+ this.state.currentMessage.attachments.push({
2087
+ ...ev,
2088
+ id: String(this.maxId++)
2089
+ });
2090
+ },
2091
+ onRecord: () => {
2092
+ !this.internalAudioRecorder.state.recording ? this.audioRecorder.start() : this.audioRecorder.stop();
2093
+ },
2094
+ onVideoRecord: async () => {
2095
+ !this.internalCameraRecorder.state.isOpen && await this.internalCameraRecorder.openCamera();
2096
+ await new Promise((resolve, _) => {
2097
+ const checkCapture = async () => {
2098
+ if (!this.internalCameraRecorder.state.isOpen) {
2099
+ const capture = this.internalCameraRecorder.pop();
2100
+ if (capture) {
2101
+ this.state.currentMessage.attachments.push({
2102
+ id: String(this.maxId++),
2103
+ name: capture.name,
2104
+ value: await getBase64FromFile(capture)
2105
+ });
2106
+ return resolve();
2107
+ }
2108
+ } else {
2109
+ requestAnimationFrame(checkCapture);
2110
+ }
2111
+ };
2112
+ checkCapture();
2113
+ });
2114
+ },
2115
+ onPrev: () => {
2116
+ this.prevMessage();
2117
+ },
2118
+ onNext: () => {
2119
+ this.nextMessage();
2120
+ },
2121
+ hideDeleteButton: this.state.hideDeleteButton,
2122
+ attachments: []
2123
+ }
2124
+ )));
2125
+ __publicField(this, "Renderer", () => /* @__PURE__ */ jsxs(
2126
+ Box,
2127
+ {
2128
+ ...getVariant("layout.common.chat.controller"),
2129
+ className: "chat_controller",
2130
+ children: [
2131
+ /* @__PURE__ */ jsx(this.History, {}),
2132
+ /* @__PURE__ */ jsx(this.Attachments, {}),
2133
+ /* @__PURE__ */ jsx(this.TextArea, {})
2134
+ ]
2135
+ }
2136
+ ));
2137
+ this.state = Object.assign({}, this.state, props);
2138
+ makeObservable(this, { state: observable });
2139
+ }
2140
+ removeMessage(idx) {
2141
+ this.state.messages = this.state.messages.filter((_, i) => i !== idx);
2142
+ }
2143
+ addMessage(message) {
2144
+ this.state.messages.push(message);
2145
+ }
2146
+ clearHistory() {
2147
+ this.state.messages = [];
2148
+ }
2149
+ clearMessage() {
2150
+ this.state.currentMessage = new ChatMessage("", "user");
2151
+ }
2152
+ removeAttachment(attachment) {
2153
+ this.state.currentMessage.attachments = this.state.currentMessage.attachments.filter((x) => x !== attachment);
2154
+ }
2155
+ nextMessage() {
2156
+ const n = this.state.messages.length;
2157
+ if (n === 0) {
2158
+ return;
2159
+ }
2160
+ if (this.currentIndex === -1 || this.currentIndex === n - 1) {
2161
+ this.state.currentMessage = this.state.messages[0].clone();
2162
+ this.currentIndex = 0;
2163
+ } else if (this.currentIndex < n - 1) {
2164
+ this.state.currentMessage = this.state.messages[this.currentIndex + 1].clone();
2165
+ this.currentIndex++;
2166
+ }
2167
+ }
2168
+ prevMessage() {
2169
+ const n = this.state.messages.length;
2170
+ if (n === 0) {
2171
+ return;
2172
+ }
2173
+ if (this.currentIndex === -1 || this.currentIndex === 0) {
2174
+ this.state.currentMessage = this.state.messages[n - 1].clone();
2175
+ this.currentIndex = n - 1;
2176
+ } else if (this.currentIndex > 0) {
2177
+ this.state.currentMessage = this.state.messages[this.currentIndex - 1].clone();
2178
+ this.currentIndex--;
2179
+ }
2180
+ }
2181
+ }
2182
+
2183
+ const WindowDragger = forwardRef((props, outerRef) => {
2184
+ const isDragging = useRef(false);
2185
+ const initialPosition = useRef({ mousex: 0, mousey: 0, boxx: 0, boxy: 0 });
2186
+ const ref = useRef(null);
2187
+ useEffect(() => {
2188
+ const handleMouseMove = (ev) => {
2189
+ if (isDragging.current && ref.current) {
2190
+ const newx = ev.clientX;
2191
+ const newy = ev.clientY;
2192
+ const difx = newx - initialPosition.current.mousex;
2193
+ const dify = newy - initialPosition.current.mousey;
2194
+ ref.current.style.left = `${initialPosition.current.boxx + difx}px`;
2195
+ ref.current.style.top = `${initialPosition.current.boxy + dify}px`;
2196
+ ref.current.style.bottom = "auto";
2197
+ ref.current.style.right = "auto";
2198
+ ref.current.style.zIndex = "1200";
2199
+ }
2200
+ };
2201
+ const handleMouseUp = () => {
2202
+ isDragging.current = false;
2203
+ };
2204
+ const handleWindowResize = () => {
2205
+ if (ref.current) {
2206
+ const bounding = ref.current.getBoundingClientRect();
2207
+ if (window.innerWidth < bounding.left + bounding.width) {
2208
+ const newx = window.innerWidth - bounding.width;
2209
+ ref.current.style.left = `${newx}px`;
2210
+ }
2211
+ if (window.innerHeight < bounding.top + bounding.height) {
2212
+ const newy = window.innerHeight - bounding.height;
2213
+ ref.current.style.top = `${newy}px`;
2214
+ }
2215
+ }
2216
+ };
2217
+ document.addEventListener("mousemove", handleMouseMove);
2218
+ document.addEventListener("mouseup", handleMouseUp);
2219
+ window.addEventListener("resize", handleWindowResize);
2220
+ return () => {
2221
+ document.removeEventListener("mousemove", handleMouseMove);
2222
+ document.removeEventListener("mouseup", handleMouseUp);
2223
+ window.removeEventListener("resize", handleWindowResize);
2224
+ };
2225
+ }, []);
2226
+ return /* @__PURE__ */ jsx(
2227
+ Box,
2228
+ {
2229
+ ref,
2230
+ className: "windowDragger",
2231
+ onMouseDown: (ev) => {
2232
+ if (ev.target instanceof Element && (ev.target.nodeName === "TEXTAREA" || ev.target.classList.contains("history__message")))
2233
+ return;
2234
+ const target = ev.target.closest?.(
2235
+ ".windowDragger"
2236
+ );
2237
+ if (target) {
2238
+ const bounding = target.getBoundingClientRect();
2239
+ isDragging.current = true;
2240
+ initialPosition.current = {
2241
+ mousex: ev.clientX,
2242
+ mousey: ev.clientY,
2243
+ boxx: bounding.left,
2244
+ boxy: bounding.top
2245
+ };
2246
+ }
2247
+ },
2248
+ sx: {
2249
+ position: "fixed",
2250
+ bottom: "260px",
2251
+ right: "10px",
2252
+ ...props.style
2253
+ },
2254
+ children: props.children
2255
+ }
2256
+ );
2257
+ });
2258
+
2259
+ export { AIFileContent, AIMessageAttachments, AutoscrollContainer, ChatController, ChatController2, ChatMessage, DashboardsRoutinesGeneration, MultipleChoiceMessage, ResponseStream, RoutinesGeneration, SearchController, SemanticSearchReference as SemanticSearchResult, ViewRendererContext, WindowDragger, getImageFromDisk, getImagesFromDisk, getImagesWithDescription };
1349
2260
  //# sourceMappingURL=index.js.map