@apia/ai 3.0.18 → 3.0.21
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.d.ts +23 -15
- package/dist/index.js +247 -194
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from '@apia/theme/jsx-runtime';
|
|
2
|
-
import { Box, getVariant,
|
|
2
|
+
import { Box, getVariant, spacing, Close, Form, Paragraph, Textarea } from '@apia/theme';
|
|
3
3
|
import { useRef, useCallback, useState } from 'react';
|
|
4
|
-
import { IconButton,
|
|
4
|
+
import { IconButton, AutogrowTextarea, ApiaUtil, SimpleButton, 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
7
|
import { CollectorField, Collector } from '@apia/validations';
|
|
@@ -208,11 +208,13 @@ class ChatMessage {
|
|
|
208
208
|
__publicField$7(this, "id");
|
|
209
209
|
__publicField$7(this, "copy", () => new ChatMessage(this.message, this.messageType, this.attachments));
|
|
210
210
|
__publicField$7(this, "Component", () => {
|
|
211
|
+
const gapAmount = this.attachments.length > 0 && this.message ? "12px" : "0";
|
|
211
212
|
return /* @__PURE__ */ jsxs(
|
|
212
213
|
Box,
|
|
213
214
|
{
|
|
214
215
|
as: "pre",
|
|
215
216
|
className: `history__message ${this.messageType}`,
|
|
217
|
+
sx: { gap: gapAmount },
|
|
216
218
|
children: [
|
|
217
219
|
/* @__PURE__ */ jsx(
|
|
218
220
|
Box,
|
|
@@ -221,7 +223,7 @@ class ChatMessage {
|
|
|
221
223
|
...typeof this.message === "string" ? { dangerouslySetInnerHTML: { __html: this.message } } : { children: this.message }
|
|
222
224
|
}
|
|
223
225
|
),
|
|
224
|
-
/* @__PURE__ */ jsx(Box, { className: "additionalContent_wrapper", children: this.attachments.map((x) => /* @__PURE__ */ jsx(x.Component, {}, x.
|
|
226
|
+
/* @__PURE__ */ jsx(Box, { className: "additionalContent_wrapper", children: this.attachments.map((x) => /* @__PURE__ */ jsx(x.Component, {}, x.getId())) })
|
|
225
227
|
]
|
|
226
228
|
},
|
|
227
229
|
this.id
|
|
@@ -257,7 +259,8 @@ class AIContent extends CollectorField {
|
|
|
257
259
|
super(uniqueId(), "");
|
|
258
260
|
__publicField$6(this, "type", "aiContent");
|
|
259
261
|
__publicField$6(this, "content");
|
|
260
|
-
|
|
262
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
263
|
+
__publicField$6(this, "Component", (props) => {
|
|
261
264
|
return /* @__PURE__ */ jsx(Box, { variant: "layout.common.components.aiMessage.textBox", children: /* @__PURE__ */ jsx(Box, { variant: "layout.common.components.aiMessage.textSnippet", children: this.content }) });
|
|
262
265
|
});
|
|
263
266
|
this.content = content;
|
|
@@ -269,6 +272,7 @@ const AIFileContentAllowedExtensions = {
|
|
|
269
272
|
png: "png",
|
|
270
273
|
jpg: "jpg",
|
|
271
274
|
jpeg: "jpeg",
|
|
275
|
+
webp: "webp",
|
|
272
276
|
txt: "txt",
|
|
273
277
|
doc: "doc",
|
|
274
278
|
pdf: "pdf",
|
|
@@ -309,6 +313,8 @@ const _AIFileContent = class _AIFileContent extends AIContent {
|
|
|
309
313
|
__publicField$5(this, "__file");
|
|
310
314
|
__publicField$5(this, "__error");
|
|
311
315
|
__publicField$5(this, "overrideSize");
|
|
316
|
+
__publicField$5(this, "id", uniqueId());
|
|
317
|
+
__publicField$5(this, "getId", () => this.id);
|
|
312
318
|
__publicField$5(this, "inferContent", () => {
|
|
313
319
|
return `You must collect information contained in this ${this.type} as help to build your tool choice.`;
|
|
314
320
|
});
|
|
@@ -318,6 +324,7 @@ const _AIFileContent = class _AIFileContent extends AIContent {
|
|
|
318
324
|
case AIFileContentAllowedExtensions.jpeg:
|
|
319
325
|
case AIFileContentAllowedExtensions.png:
|
|
320
326
|
case AIFileContentAllowedExtensions.svg:
|
|
327
|
+
case AIFileContentAllowedExtensions.webp:
|
|
321
328
|
return FileType.IMAGE;
|
|
322
329
|
case AIFileContentAllowedExtensions.txt:
|
|
323
330
|
case AIFileContentAllowedExtensions.doc:
|
|
@@ -339,33 +346,80 @@ const _AIFileContent = class _AIFileContent extends AIContent {
|
|
|
339
346
|
}
|
|
340
347
|
});
|
|
341
348
|
// COMPONENT METHODS
|
|
342
|
-
__publicField$5(this, "Component", () =>
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
...this.overrideSize
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
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(
|
|
349
|
+
__publicField$5(this, "Component", (props) => {
|
|
350
|
+
return /* @__PURE__ */ jsx(
|
|
351
|
+
Box,
|
|
352
|
+
{
|
|
353
|
+
sx: {
|
|
354
|
+
...this.overrideSize ? {
|
|
355
|
+
...this.overrideSize,
|
|
356
|
+
img: {
|
|
357
|
+
width: `${this.overrideSize.width - 20}px`,
|
|
358
|
+
height: `${this.overrideSize.height - 61}px`
|
|
359
|
+
}
|
|
360
|
+
} : {}
|
|
361
|
+
},
|
|
362
|
+
children: /* @__PURE__ */ jsxs(
|
|
358
363
|
Box,
|
|
359
364
|
{
|
|
360
|
-
|
|
361
|
-
variant: "layout.common.components.aiMessage.fileName",
|
|
365
|
+
...props,
|
|
362
366
|
title: this.fileName,
|
|
363
|
-
|
|
367
|
+
className: `labelBox ${props?.className ?? ""}`,
|
|
368
|
+
variant: "layout.common.boxes.labelBox",
|
|
369
|
+
children: [
|
|
370
|
+
/* @__PURE__ */ jsxs(Box, { className: "labelAndIcon", as: "span", children: [
|
|
371
|
+
FileType.IMAGE === this.type ? /* @__PURE__ */ jsx(
|
|
372
|
+
"img",
|
|
373
|
+
{
|
|
374
|
+
src: URL.createObjectURL(this.file),
|
|
375
|
+
alt: this.fileName,
|
|
376
|
+
style: {
|
|
377
|
+
maxWidth: "20px",
|
|
378
|
+
maxHeight: "20px",
|
|
379
|
+
height: "auto",
|
|
380
|
+
width: "auto"
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
) : /* @__PURE__ */ jsx(FileIcon, { iconSize: "sm", docName: this.fileName }),
|
|
384
|
+
this.fileName
|
|
385
|
+
] }),
|
|
386
|
+
/* @__PURE__ */ jsxs(Box, { sx: { display: "flex", gap: spacing(2) }, children: [
|
|
387
|
+
props?.onEdit !== void 0 ? /* @__PURE__ */ jsx(
|
|
388
|
+
IconButton,
|
|
389
|
+
{
|
|
390
|
+
icon: "Edit",
|
|
391
|
+
variant: "icon-outline",
|
|
392
|
+
size: "Md",
|
|
393
|
+
onClick: props.onEdit
|
|
394
|
+
}
|
|
395
|
+
) : null,
|
|
396
|
+
props?.onClose !== void 0 ? /* @__PURE__ */ jsx(
|
|
397
|
+
Close,
|
|
398
|
+
{
|
|
399
|
+
type: "button",
|
|
400
|
+
className: "closeButton",
|
|
401
|
+
size: "Sm",
|
|
402
|
+
onClick: props.onClose,
|
|
403
|
+
disabled: !props.onClose,
|
|
404
|
+
title: getLabel("lblDeleteItem").text,
|
|
405
|
+
variant: "icon-outline-danger",
|
|
406
|
+
sx: {
|
|
407
|
+
"&.closeButton": {
|
|
408
|
+
position: "inherit",
|
|
409
|
+
fontSize: "22px",
|
|
410
|
+
height: "22px",
|
|
411
|
+
width: "22px"
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
) : null
|
|
416
|
+
] })
|
|
417
|
+
]
|
|
364
418
|
}
|
|
365
419
|
)
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
)
|
|
420
|
+
}
|
|
421
|
+
);
|
|
422
|
+
});
|
|
369
423
|
this.__error = error;
|
|
370
424
|
if (!_AIFileContent.isValidExtension(extension))
|
|
371
425
|
this.__throwError(
|
|
@@ -443,6 +497,7 @@ class AIMessageAttachments {
|
|
|
443
497
|
__publicField$4(this, "content");
|
|
444
498
|
__publicField$4(this, "id", uniqueId());
|
|
445
499
|
__publicField$4(this, "customDescription", false);
|
|
500
|
+
__publicField$4(this, "getId", () => this.id);
|
|
446
501
|
__publicField$4(this, "addDescription", async () => {
|
|
447
502
|
const collector = new Collector();
|
|
448
503
|
const collected = await collector.add(this.content).add(
|
|
@@ -467,28 +522,13 @@ class AIMessageAttachments {
|
|
|
467
522
|
this.customDescription = false;
|
|
468
523
|
}
|
|
469
524
|
});
|
|
470
|
-
__publicField$4(this, "Component", (props) => /* @__PURE__ */
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
onClick: this.close,
|
|
478
|
-
title: getLabel("lblDeleteItem").title
|
|
479
|
-
}
|
|
480
|
-
) : /* @__PURE__ */ jsx(Fragment, {}),
|
|
481
|
-
props?.canAddDescription ? /* @__PURE__ */ jsx(
|
|
482
|
-
IconButton,
|
|
483
|
-
{
|
|
484
|
-
className: "descriptionButton",
|
|
485
|
-
size: "Md",
|
|
486
|
-
icon: "Magic",
|
|
487
|
-
onClick: this.addDescription
|
|
488
|
-
}
|
|
489
|
-
) : /* @__PURE__ */ jsx(Fragment, {}),
|
|
490
|
-
/* @__PURE__ */ jsx(this.content.Component, {})
|
|
491
|
-
] }));
|
|
525
|
+
__publicField$4(this, "Component", (props) => /* @__PURE__ */ jsx(Box, { ...getVariant("layout.common.components.aiMessage"), children: /* @__PURE__ */ jsx(
|
|
526
|
+
this.content.Component,
|
|
527
|
+
{
|
|
528
|
+
onClose: props.closeButton ? this.close : void 0,
|
|
529
|
+
onEdit: props?.canAddDescription ? this.addDescription : void 0
|
|
530
|
+
}
|
|
531
|
+
) }));
|
|
492
532
|
this.role = role;
|
|
493
533
|
this.content = content;
|
|
494
534
|
}
|
|
@@ -518,6 +558,9 @@ const handleFileUploadAsMessage = async (fileInputElement, chatController) => {
|
|
|
518
558
|
}
|
|
519
559
|
};
|
|
520
560
|
|
|
561
|
+
function isMobile() {
|
|
562
|
+
return /Mobi|Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
|
|
563
|
+
}
|
|
521
564
|
const makeTextarea = (chatController) => {
|
|
522
565
|
const NewTextarea = observer(
|
|
523
566
|
({
|
|
@@ -527,7 +570,6 @@ const makeTextarea = (chatController) => {
|
|
|
527
570
|
preventAppendUserMessages
|
|
528
571
|
}) => {
|
|
529
572
|
const [isLoading, setIsLoading] = useState(false);
|
|
530
|
-
const breakpoint = useBreakpointIndex();
|
|
531
573
|
const submit = useCallback(() => {
|
|
532
574
|
if (preventAppendUserMessages !== true)
|
|
533
575
|
chatController.messages.add(chatController.state.current);
|
|
@@ -537,8 +579,14 @@ const makeTextarea = (chatController) => {
|
|
|
537
579
|
chatController.state.current = new ChatMessage();
|
|
538
580
|
});
|
|
539
581
|
}, [onSubmit, preventAppendUserMessages]);
|
|
582
|
+
const recordingAttachHandler = async () => {
|
|
583
|
+
if (chatController.audioRecorder.state.recording) {
|
|
584
|
+
chatController.audioRecorder.stop();
|
|
585
|
+
await chatController.audioRecorder.attach();
|
|
586
|
+
}
|
|
587
|
+
};
|
|
540
588
|
const handleSubmit = useCallback(
|
|
541
|
-
(ev) => {
|
|
589
|
+
async (ev) => {
|
|
542
590
|
ev.preventDefault();
|
|
543
591
|
if (chatController.state.current.message || chatController.attachments.size() > 0) {
|
|
544
592
|
setIsLoading(true);
|
|
@@ -554,7 +602,7 @@ const makeTextarea = (chatController) => {
|
|
|
554
602
|
const onKeyDown = useCallback((ev) => {
|
|
555
603
|
if (ev.target.readOnly)
|
|
556
604
|
return;
|
|
557
|
-
if (
|
|
605
|
+
if (["NumpadEnter", "Enter"].includes(ev.code) && !ev.shiftKey) {
|
|
558
606
|
ev.preventDefault();
|
|
559
607
|
ev.target.closest("form")?.querySelector('button[type="submit"]')?.click();
|
|
560
608
|
}
|
|
@@ -592,91 +640,44 @@ const makeTextarea = (chatController) => {
|
|
|
592
640
|
const additionalButtons = [];
|
|
593
641
|
additionalButtons.push({
|
|
594
642
|
key: "prev",
|
|
595
|
-
children:
|
|
596
|
-
|
|
597
|
-
{
|
|
598
|
-
title: getLabel("btnAiPrevious").title,
|
|
599
|
-
variant: "outline",
|
|
600
|
-
type: "button",
|
|
601
|
-
onClick: chatController.history.previous,
|
|
602
|
-
size: "sm",
|
|
603
|
-
children: getLabel("btnAiPrevious").text
|
|
604
|
-
}
|
|
605
|
-
)
|
|
643
|
+
children: getLabel("btnAiPrevious").text,
|
|
644
|
+
onClick: chatController.history.previous
|
|
606
645
|
});
|
|
607
646
|
additionalButtons.push({
|
|
608
647
|
key: "next",
|
|
609
|
-
children:
|
|
610
|
-
|
|
611
|
-
{
|
|
612
|
-
title: getLabel("btnAiNext").title,
|
|
613
|
-
variant: "outline",
|
|
614
|
-
type: "button",
|
|
615
|
-
onClick: chatController.history.next,
|
|
616
|
-
size: "sm",
|
|
617
|
-
children: getLabel("btnAiNext").text
|
|
618
|
-
}
|
|
619
|
-
)
|
|
648
|
+
children: getLabel("btnAiNext").text,
|
|
649
|
+
onClick: chatController.history.next
|
|
620
650
|
});
|
|
621
651
|
if (!hideDeleteButton) {
|
|
622
652
|
additionalButtons.push({
|
|
623
653
|
key: "delete",
|
|
624
|
-
children:
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
chatController.state.current.message = "";
|
|
632
|
-
chatController.attachments.dropAll();
|
|
633
|
-
chatController.currentHistoryIndex = -1;
|
|
634
|
-
},
|
|
635
|
-
size: "sm",
|
|
636
|
-
children: getLabel("btnAiDelete").text
|
|
637
|
-
}
|
|
638
|
-
)
|
|
654
|
+
children: getLabel("btnAiDelete").text,
|
|
655
|
+
onClick: () => {
|
|
656
|
+
chatController.state.current.message = "";
|
|
657
|
+
chatController.audioRecorder.stop();
|
|
658
|
+
chatController.attachments.dropAll();
|
|
659
|
+
chatController.currentHistoryIndex = -1;
|
|
660
|
+
}
|
|
639
661
|
});
|
|
640
662
|
additionalButtons.push({
|
|
641
663
|
key: "deleteMessages",
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
{
|
|
645
|
-
title: getLabel("btnAiDeleteMessages").title,
|
|
646
|
-
variant: "outline",
|
|
647
|
-
type: "button",
|
|
648
|
-
onClick: () => chatController.messages.clear(),
|
|
649
|
-
size: "sm",
|
|
650
|
-
children: getLabel("btnAiDeleteMessages").text
|
|
651
|
-
}
|
|
652
|
-
)
|
|
664
|
+
onClick: () => chatController.messages.clear(),
|
|
665
|
+
children: getLabel("btnAiDeleteMessages").text
|
|
653
666
|
});
|
|
654
667
|
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
isLoading: actualIsLoading,
|
|
666
|
-
onClick: () => {
|
|
667
|
-
const util = ApiaUtil.instance;
|
|
668
|
-
const items = [];
|
|
669
|
-
items.push(...additionalButtons);
|
|
670
|
-
if (items.length > 0)
|
|
671
|
-
util.menu.open({
|
|
672
|
-
menuProps: {
|
|
673
|
-
anchorPoint: { x: util.mouse.x, y: util.mouse.y }
|
|
674
|
-
},
|
|
675
|
-
items
|
|
676
|
-
});
|
|
668
|
+
if (isMobile()) {
|
|
669
|
+
additionalButtons.push({
|
|
670
|
+
key: "camera",
|
|
671
|
+
children: getLabel("btnOpenMobileCamera").text,
|
|
672
|
+
onClick: () => {
|
|
673
|
+
const gptUploadFile = document.getElementById(
|
|
674
|
+
`gptUploadFile__${chatController.id}`
|
|
675
|
+
);
|
|
676
|
+
if (gptUploadFile) {
|
|
677
|
+
gptUploadFile.click();
|
|
677
678
|
}
|
|
678
679
|
}
|
|
679
|
-
);
|
|
680
|
+
});
|
|
680
681
|
}
|
|
681
682
|
return /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexDirection: "column", width: "100%" }, children: [
|
|
682
683
|
/* @__PURE__ */ jsx(
|
|
@@ -688,21 +689,27 @@ const makeTextarea = (chatController) => {
|
|
|
688
689
|
maxHeight: "280px",
|
|
689
690
|
overflowY: "auto",
|
|
690
691
|
paddingTop: "6px",
|
|
691
|
-
paddingBottom: "6px"
|
|
692
|
+
paddingBottom: "6px",
|
|
693
|
+
gap: spacing(3)
|
|
692
694
|
},
|
|
693
695
|
children: chatController.attachments.getComponents()
|
|
694
696
|
}
|
|
695
697
|
),
|
|
696
698
|
/* @__PURE__ */ jsxs(
|
|
697
|
-
|
|
699
|
+
Form,
|
|
698
700
|
{
|
|
699
701
|
onDrop: handleDrop,
|
|
700
702
|
onDragOver: handleDragOver,
|
|
701
703
|
onDragEnter: handleDragEnter,
|
|
702
704
|
onDragLeave: handleDragLeave,
|
|
703
|
-
onSubmit:
|
|
705
|
+
onSubmit: async (e) => {
|
|
706
|
+
e.preventDefault();
|
|
707
|
+
await recordingAttachHandler();
|
|
708
|
+
handleSubmit(e);
|
|
709
|
+
},
|
|
704
710
|
className: "gpt__form",
|
|
705
711
|
action: "",
|
|
712
|
+
...getVariant("layout.common.chat.form"),
|
|
706
713
|
children: [
|
|
707
714
|
dragging ? /* @__PURE__ */ jsx(
|
|
708
715
|
Box,
|
|
@@ -717,96 +724,143 @@ const makeTextarea = (chatController) => {
|
|
|
717
724
|
},
|
|
718
725
|
children: getLabel("msgAiDragAndDrop").text
|
|
719
726
|
}
|
|
720
|
-
) : /* @__PURE__ */ jsx(
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
onKeyDown,
|
|
724
|
-
id: `GPTMessage${chatController.id}`,
|
|
725
|
-
readOnly: actualIsLoading,
|
|
726
|
-
value: chatController.state.current.message,
|
|
727
|
-
onChange: (ev) => {
|
|
728
|
-
chatController.state.current.message = ev.target.value;
|
|
729
|
-
if (!chatController.state.current.message && chatController.attachments.size() < 1)
|
|
730
|
-
chatController.currentHistoryIndex = -1;
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
),
|
|
734
|
-
/* @__PURE__ */ jsxs(Box, { className: "gpt__buttonsContainer", children: [
|
|
735
|
-
/* @__PURE__ */ jsx(Box, { sx: { display: "none" }, children: /* @__PURE__ */ jsx(
|
|
736
|
-
"input",
|
|
727
|
+
) : /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(Box, { className: "search_controls", children: [
|
|
728
|
+
/* @__PURE__ */ jsx(
|
|
729
|
+
AutogrowTextarea,
|
|
737
730
|
{
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
731
|
+
onKeyDown,
|
|
732
|
+
id: `GPTMessage${chatController.id}`,
|
|
733
|
+
readOnly: actualIsLoading,
|
|
734
|
+
value: chatController.state.current.message,
|
|
742
735
|
onChange: (ev) => {
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
);
|
|
753
|
-
} else {
|
|
754
|
-
throw e;
|
|
755
|
-
}
|
|
756
|
-
});
|
|
757
|
-
else {
|
|
758
|
-
handleFileUploadAsMessage(ev.target, chatController);
|
|
759
|
-
}
|
|
760
|
-
ev.target.value = "";
|
|
736
|
+
chatController.state.current.message = ev.target.value;
|
|
737
|
+
if (!chatController.state.current.message && chatController.attachments.size() < 1)
|
|
738
|
+
chatController.currentHistoryIndex = -1;
|
|
739
|
+
},
|
|
740
|
+
sx: {
|
|
741
|
+
resize: "none",
|
|
742
|
+
px: spacing(4),
|
|
743
|
+
background: "transparent",
|
|
744
|
+
border: "none"
|
|
761
745
|
}
|
|
762
746
|
}
|
|
763
|
-
)
|
|
747
|
+
),
|
|
764
748
|
/* @__PURE__ */ jsx(
|
|
765
749
|
IconButton,
|
|
766
750
|
{
|
|
751
|
+
...getVariant(
|
|
752
|
+
"layout.ai.execution.formsAssistant.settingsButton"
|
|
753
|
+
),
|
|
767
754
|
variant: "icon-outline",
|
|
768
|
-
|
|
755
|
+
iconSize: "Sm",
|
|
756
|
+
className: "SearchButton",
|
|
757
|
+
icon: "Ellipsis",
|
|
758
|
+
isLoading: actualIsLoading,
|
|
759
|
+
onClick: () => {
|
|
760
|
+
const util = ApiaUtil.instance;
|
|
761
|
+
const items = [];
|
|
762
|
+
items.push(...additionalButtons);
|
|
763
|
+
if (items.length > 0)
|
|
764
|
+
util.menu.open({
|
|
765
|
+
menuProps: {
|
|
766
|
+
anchorPoint: { x: util.mouse.x, y: util.mouse.y }
|
|
767
|
+
},
|
|
768
|
+
items
|
|
769
|
+
});
|
|
770
|
+
},
|
|
771
|
+
sx: { display: actualIsLoading ? "none" : "flex" }
|
|
772
|
+
}
|
|
773
|
+
),
|
|
774
|
+
/* @__PURE__ */ jsx(
|
|
775
|
+
IconButton,
|
|
776
|
+
{
|
|
777
|
+
isLoading: actualIsLoading,
|
|
778
|
+
onClick: async (ev) => {
|
|
779
|
+
if (!chatController.audioRecorder.state.recording) {
|
|
780
|
+
chatController.audioRecorder.start();
|
|
781
|
+
} else {
|
|
782
|
+
chatController.audioRecorder.stop();
|
|
783
|
+
await chatController.audioRecorder.attach();
|
|
784
|
+
handleSubmit(
|
|
785
|
+
ev
|
|
786
|
+
);
|
|
787
|
+
}
|
|
788
|
+
},
|
|
769
789
|
disabled: actualIsLoading && !chatController.audioRecorder.state.recording,
|
|
770
790
|
sx: {
|
|
771
|
-
color: chatController.audioRecorder.state.recording ? "red" : void 0
|
|
791
|
+
color: chatController.audioRecorder.state.recording ? "red" : void 0,
|
|
792
|
+
display: actualIsLoading ? "none" : "flex"
|
|
772
793
|
},
|
|
773
794
|
icon: chatController.audioRecorder.state.recording ? "Stop" : "Microphone",
|
|
774
795
|
id: "transcribeAudio",
|
|
775
|
-
|
|
796
|
+
variant: "icon-outline",
|
|
797
|
+
iconSize: "Sm",
|
|
798
|
+
className: "SearchButton",
|
|
776
799
|
title: getLabel("lblAiRecordAudio").text
|
|
777
800
|
}
|
|
778
801
|
),
|
|
779
802
|
/* @__PURE__ */ jsx(
|
|
780
803
|
IconButton,
|
|
781
804
|
{
|
|
782
|
-
title: getLabel("btnUploadFile").text,
|
|
783
|
-
icon: "File",
|
|
784
805
|
variant: "icon-outline",
|
|
785
|
-
|
|
806
|
+
isLoading: actualIsLoading,
|
|
786
807
|
onClick: () => {
|
|
787
808
|
document.getElementById(
|
|
788
809
|
`gptUploadFile__${chatController.id}`
|
|
789
810
|
).click();
|
|
790
811
|
},
|
|
791
|
-
|
|
812
|
+
icon: "Attach",
|
|
813
|
+
id: "fileUpload",
|
|
814
|
+
iconSize: "Sm",
|
|
815
|
+
className: "SearchButton",
|
|
816
|
+
sx: { display: actualIsLoading ? "none" : "flex" },
|
|
817
|
+
title: getLabel("btnUploadFile").text
|
|
792
818
|
}
|
|
793
819
|
),
|
|
794
|
-
isPhone ? iconButton : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
795
|
-
...additionalButtons.map(
|
|
796
|
-
(x) => x.children
|
|
797
|
-
)
|
|
798
|
-
] }),
|
|
799
820
|
/* @__PURE__ */ jsx(
|
|
800
|
-
|
|
821
|
+
IconButton,
|
|
801
822
|
{
|
|
802
823
|
title: getLabel("btnAiSend").title,
|
|
803
824
|
isLoading: actualIsLoading,
|
|
804
825
|
type: "submit",
|
|
805
|
-
size: "
|
|
806
|
-
|
|
826
|
+
size: "Lg",
|
|
827
|
+
icon: "ArrowRight",
|
|
828
|
+
variant: "icon-outline",
|
|
829
|
+
iconSize: "Sm",
|
|
830
|
+
className: "SearchButton"
|
|
807
831
|
}
|
|
808
832
|
)
|
|
809
|
-
] })
|
|
833
|
+
] }) }),
|
|
834
|
+
/* @__PURE__ */ jsx(Box, { className: "gpt__buttonsContainer", children: /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
|
|
835
|
+
"input",
|
|
836
|
+
{
|
|
837
|
+
type: "file",
|
|
838
|
+
className: "gptUploadFile",
|
|
839
|
+
multiple: true,
|
|
840
|
+
capture: isMobile() ? "environment" : void 0,
|
|
841
|
+
id: `gptUploadFile__${chatController.id}`,
|
|
842
|
+
onChange: (ev) => {
|
|
843
|
+
if (1 == noNaN("a"))
|
|
844
|
+
handleFileUpload(ev).catch((e) => {
|
|
845
|
+
if (e instanceof WrongFormatError) {
|
|
846
|
+
setIsLoading(false);
|
|
847
|
+
chatController.messages.add(
|
|
848
|
+
new ChatMessage(
|
|
849
|
+
getLabel("msgAiFileExtensionError").text,
|
|
850
|
+
"error"
|
|
851
|
+
)
|
|
852
|
+
);
|
|
853
|
+
} else {
|
|
854
|
+
throw e;
|
|
855
|
+
}
|
|
856
|
+
});
|
|
857
|
+
else {
|
|
858
|
+
handleFileUploadAsMessage(ev.target, chatController);
|
|
859
|
+
}
|
|
860
|
+
ev.target.value = "";
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
) }) })
|
|
810
864
|
]
|
|
811
865
|
}
|
|
812
866
|
)
|
|
@@ -851,22 +905,24 @@ class ChatController {
|
|
|
851
905
|
});
|
|
852
906
|
__publicField$3(this, "components", {
|
|
853
907
|
MessageHistory: observer(() => {
|
|
854
|
-
return /* @__PURE__ */ jsx(
|
|
855
|
-
Box,
|
|
856
|
-
{
|
|
857
|
-
...getVariant("layout.common.components.chat"),
|
|
858
|
-
className: "history",
|
|
859
|
-
children: /* @__PURE__ */ jsx(AutoscrollContainer, { children: this.state.messages.map((current) => /* @__PURE__ */ jsx(current.Component, {}, current.id)) })
|
|
860
|
-
}
|
|
861
|
-
);
|
|
908
|
+
return /* @__PURE__ */ jsx(Box, { ...getVariant("layout.common.chat.history"), className: "history", children: /* @__PURE__ */ jsx(AutoscrollContainer, { children: this.state.messages.map((current) => /* @__PURE__ */ jsx(current.Component, {}, current.id)) }) });
|
|
862
909
|
}),
|
|
863
910
|
Textarea: makeTextarea(this)
|
|
864
911
|
});
|
|
865
912
|
__privateAdd(this, _promptsHistory, []);
|
|
866
913
|
__publicField$3(this, "currentHistoryIndex", -1);
|
|
867
914
|
__privateAdd(this, _internalAudioRecorder, new AudioRecorder());
|
|
915
|
+
__publicField$3(this, "audioBlob", new Promise(() => {
|
|
916
|
+
}));
|
|
868
917
|
__publicField$3(this, "audioRecorder", {
|
|
869
|
-
start: () =>
|
|
918
|
+
start: () => {
|
|
919
|
+
this.audioBlob = __privateGet(this, _internalAudioRecorder).start();
|
|
920
|
+
},
|
|
921
|
+
stop: async () => {
|
|
922
|
+
__privateGet(this, _internalAudioRecorder).stop();
|
|
923
|
+
},
|
|
924
|
+
attach: async () => {
|
|
925
|
+
const blob = await this.audioBlob;
|
|
870
926
|
const m = new AIMessageAttachments(
|
|
871
927
|
AIMessageRole.USER,
|
|
872
928
|
new AIFileContent(
|
|
@@ -876,9 +932,6 @@ class ChatController {
|
|
|
876
932
|
() => this.attachments.drop(m)
|
|
877
933
|
);
|
|
878
934
|
this.attachments.add(m);
|
|
879
|
-
}),
|
|
880
|
-
stop: async () => {
|
|
881
|
-
__privateGet(this, _internalAudioRecorder).stop();
|
|
882
935
|
},
|
|
883
936
|
record: 0,
|
|
884
937
|
state: __privateGet(this, _internalAudioRecorder).state
|
|
@@ -944,7 +997,7 @@ class ChatController {
|
|
|
944
997
|
if (!this.state.current.message && this.attachments.size() < 1)
|
|
945
998
|
this.currentHistoryIndex = -1;
|
|
946
999
|
},
|
|
947
|
-
getComponents: () => this.state.current.attachments.map((x) => /* @__PURE__ */ jsx(x.Component, { closeButton: true, canAddDescription: true }, x.
|
|
1000
|
+
getComponents: () => this.state.current.attachments.map((x) => /* @__PURE__ */ jsx(x.Component, { closeButton: true, canAddDescription: true }, x.getId())),
|
|
948
1001
|
get: () => this.state.current.attachments,
|
|
949
1002
|
size: () => this.state.current.attachments.length
|
|
950
1003
|
});
|