@apia/ai 4.0.8 → 4.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +266 -18
- package/dist/index.js +1193 -285
- package/dist/index.js.map +1 -1
- package/index.ts/index.d.ts +343 -0
- package/index.ts/index.d.ts.map +1 -0
- package/index.ts/index.js +1898 -0
- package/index.ts/index.js.map +1 -0
- package/package.json +7 -6
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
|
|
34
|
-
if (isFullScrolled.current &&
|
|
35
|
-
|
|
36
|
-
top:
|
|
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$
|
|
197
|
-
var __defNormalProp$
|
|
198
|
-
var __publicField$
|
|
199
|
-
__defNormalProp$
|
|
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
|
-
|
|
209
|
-
__publicField$
|
|
210
|
-
__publicField$
|
|
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: `
|
|
221
|
+
className: `history_message ${className || ""} ${this.messageType}`,
|
|
216
222
|
children: [
|
|
217
223
|
/* @__PURE__ */ jsx(
|
|
218
224
|
Box,
|
|
219
225
|
{
|
|
220
|
-
className: "
|
|
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: "
|
|
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,21 +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$
|
|
250
|
-
var __defNormalProp$
|
|
251
|
-
var __publicField$
|
|
252
|
-
__defNormalProp$
|
|
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$
|
|
259
|
-
__publicField$
|
|
260
|
-
|
|
261
|
-
__publicField$6(this, "Component", () => {
|
|
272
|
+
__publicField$a(this, "type", "aiContent");
|
|
273
|
+
__publicField$a(this, "content");
|
|
274
|
+
__publicField$a(this, "Component", () => {
|
|
262
275
|
return /* @__PURE__ */ jsx(Box, { variant: "layout.common.components.aiMessage.textBox", children: /* @__PURE__ */ jsx(Box, { variant: "layout.common.components.aiMessage.textSnippet", children: this.content }) });
|
|
263
276
|
});
|
|
264
277
|
this.content = content;
|
|
@@ -293,27 +306,32 @@ var AIMessageRole = /* @__PURE__ */ ((AIMessageRole2) => {
|
|
|
293
306
|
return AIMessageRole2;
|
|
294
307
|
})(AIMessageRole || {});
|
|
295
308
|
|
|
296
|
-
var __defProp$
|
|
297
|
-
var __defNormalProp$
|
|
298
|
-
var __publicField$
|
|
299
|
-
__defNormalProp$
|
|
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);
|
|
300
313
|
return value;
|
|
301
314
|
};
|
|
302
315
|
const _AIFileContent = class _AIFileContent extends AIContent {
|
|
303
|
-
constructor(
|
|
304
|
-
|
|
316
|
+
constructor(props) {
|
|
317
|
+
if (props.needsControlExtension === null || props.needsControlExtension === void 0) {
|
|
318
|
+
props.needsControlExtension = true;
|
|
319
|
+
}
|
|
320
|
+
const extension = _AIFileContent.getExtensionFromFileName(props.name);
|
|
305
321
|
super();
|
|
306
|
-
__publicField$
|
|
307
|
-
__publicField$
|
|
308
|
-
__publicField$
|
|
309
|
-
__publicField$
|
|
310
|
-
__publicField$
|
|
311
|
-
__publicField$
|
|
312
|
-
__publicField$
|
|
313
|
-
__publicField$
|
|
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", () => {
|
|
314
332
|
return `You must collect information contained in this ${this.type} as help to build your tool choice.`;
|
|
315
333
|
});
|
|
316
|
-
__publicField$
|
|
334
|
+
__publicField$9(this, "inferExtension", (extension) => {
|
|
317
335
|
switch (extension) {
|
|
318
336
|
case AIFileContentAllowedExtensions.jpg:
|
|
319
337
|
case AIFileContentAllowedExtensions.jpeg:
|
|
@@ -340,45 +358,64 @@ const _AIFileContent = class _AIFileContent extends AIContent {
|
|
|
340
358
|
}
|
|
341
359
|
});
|
|
342
360
|
// COMPONENT METHODS
|
|
343
|
-
__publicField$
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
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))
|
|
372
404
|
this.__throwError(
|
|
373
405
|
new Error(_AIFileContent.__getExtensionErrorMessage(extension)),
|
|
374
406
|
this.__error?.fileExtension
|
|
375
407
|
);
|
|
376
|
-
this.
|
|
408
|
+
this.value = props.value;
|
|
377
409
|
this.extension = extension;
|
|
378
410
|
this.type = this.inferExtension(this.extension);
|
|
379
|
-
this.
|
|
380
|
-
this.__file = f;
|
|
411
|
+
this.name = props.name;
|
|
412
|
+
this.__file = props.f;
|
|
381
413
|
this.content = this.inferContent();
|
|
414
|
+
this.onClose = props.onClose;
|
|
415
|
+
}
|
|
416
|
+
setOnClose(callback) {
|
|
417
|
+
this.onClose = callback;
|
|
418
|
+
return this;
|
|
382
419
|
}
|
|
383
420
|
// PUBLIC METHODS
|
|
384
421
|
setOverrideSize(overrideSize) {
|
|
@@ -391,7 +428,7 @@ const _AIFileContent = class _AIFileContent extends AIContent {
|
|
|
391
428
|
return this.__file;
|
|
392
429
|
}
|
|
393
430
|
static getExtensionFromFileName(fileName) {
|
|
394
|
-
return fileName.split("."
|
|
431
|
+
return fileName.split(".").pop();
|
|
395
432
|
}
|
|
396
433
|
// PRIVATE METHODS
|
|
397
434
|
static __getExtensionErrorMessage(extension) {
|
|
@@ -402,14 +439,17 @@ ${Object.keys(AIFileContentAllowedExtensions)}`;
|
|
|
402
439
|
callback && callback();
|
|
403
440
|
throw e;
|
|
404
441
|
}
|
|
442
|
+
getId() {
|
|
443
|
+
return this.id;
|
|
444
|
+
}
|
|
405
445
|
};
|
|
406
446
|
// STATIC METHODS
|
|
407
|
-
__publicField$
|
|
447
|
+
__publicField$9(_AIFileContent, "isValidExtension", (extension) => {
|
|
408
448
|
return Object.values(
|
|
409
449
|
AIFileContentAllowedExtensions
|
|
410
450
|
).includes(extension);
|
|
411
451
|
});
|
|
412
|
-
__publicField$
|
|
452
|
+
__publicField$9(_AIFileContent, "blobToBase64", async (blob) => {
|
|
413
453
|
return await ((blob2) => new Promise((resolve, reject) => {
|
|
414
454
|
const reader = new FileReader();
|
|
415
455
|
reader.onloadend = () => {
|
|
@@ -420,38 +460,42 @@ __publicField$5(_AIFileContent, "blobToBase64", async (blob) => {
|
|
|
420
460
|
reader.readAsDataURL(blob2);
|
|
421
461
|
}))(blob);
|
|
422
462
|
});
|
|
423
|
-
__publicField$
|
|
424
|
-
const fileUrl = await ((
|
|
463
|
+
__publicField$9(_AIFileContent, "fromFile", async (props) => {
|
|
464
|
+
const fileUrl = await ((f) => new Promise((resolve, reject) => {
|
|
425
465
|
const reader = new FileReader();
|
|
426
|
-
reader.readAsDataURL(
|
|
466
|
+
reader.readAsDataURL(f);
|
|
427
467
|
reader.onload = () => resolve(reader.result);
|
|
428
468
|
reader.onerror = () => reject();
|
|
429
|
-
}))(f);
|
|
430
|
-
return new _AIFileContent(
|
|
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
|
+
});
|
|
431
477
|
});
|
|
432
478
|
let AIFileContent = _AIFileContent;
|
|
433
479
|
|
|
434
|
-
var __defProp$
|
|
435
|
-
var __defNormalProp$
|
|
436
|
-
var __publicField$
|
|
437
|
-
__defNormalProp$
|
|
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);
|
|
438
484
|
return value;
|
|
439
485
|
};
|
|
440
486
|
class AIMessageAttachments {
|
|
441
487
|
constructor(role, content, close) {
|
|
442
488
|
this.close = close;
|
|
443
|
-
__publicField$
|
|
444
|
-
__publicField$
|
|
445
|
-
__publicField$
|
|
446
|
-
__publicField$
|
|
447
|
-
__publicField$
|
|
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 () => {
|
|
448
494
|
const collector = new Collector();
|
|
449
|
-
const collected = await collector.add(
|
|
450
|
-
this.content instanceof AIFileContent ? this.content.setOverrideSize({ height: 320, width: 330 }) : this.content
|
|
451
|
-
).add(
|
|
495
|
+
const collected = await collector.add(this.content).add(
|
|
452
496
|
new collector.fields.textarea(
|
|
453
497
|
"addCommentTextArea",
|
|
454
|
-
getLabel("lblAiAddImageCo").text,
|
|
498
|
+
getLabel("lblAiAddImageCo").text.replace(".", ""),
|
|
455
499
|
{
|
|
456
500
|
initialValue: this.content instanceof AIFileContent && this.content.content !== this.content.inferContent() ? this.content.content : ""
|
|
457
501
|
}
|
|
@@ -470,7 +514,7 @@ class AIMessageAttachments {
|
|
|
470
514
|
this.customDescription = false;
|
|
471
515
|
}
|
|
472
516
|
});
|
|
473
|
-
__publicField$
|
|
517
|
+
__publicField$8(this, "Component", (props) => /* @__PURE__ */ jsxs(Box, { ...getVariant("layout.common.components.aiMessage"), children: [
|
|
474
518
|
props.closeButton ? /* @__PURE__ */ jsx(
|
|
475
519
|
IconButton,
|
|
476
520
|
{
|
|
@@ -495,6 +539,9 @@ class AIMessageAttachments {
|
|
|
495
539
|
this.role = role;
|
|
496
540
|
this.content = content;
|
|
497
541
|
}
|
|
542
|
+
getId() {
|
|
543
|
+
return this.id;
|
|
544
|
+
}
|
|
498
545
|
}
|
|
499
546
|
|
|
500
547
|
const handleFileUploadAsMessage = async (fileInputElement, chatController) => {
|
|
@@ -530,6 +577,7 @@ const makeTextarea = (chatController) => {
|
|
|
530
577
|
preventAppendUserMessages
|
|
531
578
|
}) => {
|
|
532
579
|
const [isLoading, setIsLoading] = useState(false);
|
|
580
|
+
const breakpoint = useBreakpointIndex();
|
|
533
581
|
const submit = useCallback(() => {
|
|
534
582
|
if (preventAppendUserMessages !== true)
|
|
535
583
|
chatController.messages.add(chatController.state.current);
|
|
@@ -591,6 +639,95 @@ const makeTextarea = (chatController) => {
|
|
|
591
639
|
ev.preventDefault();
|
|
592
640
|
setDragging(true);
|
|
593
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
|
+
}
|
|
594
731
|
return /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexDirection: "column", width: "100%" }, children: [
|
|
595
732
|
/* @__PURE__ */ jsx(
|
|
596
733
|
Box,
|
|
@@ -704,54 +841,9 @@ const makeTextarea = (chatController) => {
|
|
|
704
841
|
size: "Lg"
|
|
705
842
|
}
|
|
706
843
|
),
|
|
707
|
-
/* @__PURE__ */
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
title: getLabel("btnAiPrevious").title,
|
|
711
|
-
variant: "outline",
|
|
712
|
-
type: "button",
|
|
713
|
-
onClick: chatController.history.previous,
|
|
714
|
-
size: "sm",
|
|
715
|
-
children: getLabel("btnAiPrevious").text
|
|
716
|
-
}
|
|
717
|
-
),
|
|
718
|
-
/* @__PURE__ */ jsx(
|
|
719
|
-
SimpleButton,
|
|
720
|
-
{
|
|
721
|
-
title: getLabel("btnAiNext").title,
|
|
722
|
-
variant: "outline",
|
|
723
|
-
type: "button",
|
|
724
|
-
onClick: chatController.history.next,
|
|
725
|
-
size: "sm",
|
|
726
|
-
children: getLabel("btnAiNext").text
|
|
727
|
-
}
|
|
728
|
-
),
|
|
729
|
-
!hideDeleteButton && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
730
|
-
/* @__PURE__ */ jsx(
|
|
731
|
-
SimpleButton,
|
|
732
|
-
{
|
|
733
|
-
title: getLabel("btnAiDelete").title,
|
|
734
|
-
variant: "outline",
|
|
735
|
-
type: "button",
|
|
736
|
-
onClick: () => {
|
|
737
|
-
chatController.state.current.message = "";
|
|
738
|
-
chatController.attachments.dropAll();
|
|
739
|
-
chatController.currentHistoryIndex = -1;
|
|
740
|
-
},
|
|
741
|
-
size: "sm",
|
|
742
|
-
children: getLabel("btnAiDelete").text
|
|
743
|
-
}
|
|
744
|
-
),
|
|
745
|
-
/* @__PURE__ */ jsx(
|
|
746
|
-
SimpleButton,
|
|
747
|
-
{
|
|
748
|
-
title: getLabel("btnAiDeleteMessages").title,
|
|
749
|
-
variant: "outline",
|
|
750
|
-
type: "button",
|
|
751
|
-
onClick: () => chatController.messages.clear(),
|
|
752
|
-
size: "sm",
|
|
753
|
-
children: getLabel("btnAiDeleteMessages").text
|
|
754
|
-
}
|
|
844
|
+
isPhone ? iconButton : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
845
|
+
...additionalButtons.map(
|
|
846
|
+
(x) => x.children
|
|
755
847
|
)
|
|
756
848
|
] }),
|
|
757
849
|
/* @__PURE__ */ jsx(
|
|
@@ -775,10 +867,10 @@ const makeTextarea = (chatController) => {
|
|
|
775
867
|
return NewTextarea;
|
|
776
868
|
};
|
|
777
869
|
|
|
778
|
-
var __defProp$
|
|
779
|
-
var __defNormalProp$
|
|
780
|
-
var __publicField$
|
|
781
|
-
__defNormalProp$
|
|
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);
|
|
782
874
|
return value;
|
|
783
875
|
};
|
|
784
876
|
var __accessCheck = (obj, member, msg) => {
|
|
@@ -787,7 +879,7 @@ var __accessCheck = (obj, member, msg) => {
|
|
|
787
879
|
};
|
|
788
880
|
var __privateGet = (obj, member, getter) => {
|
|
789
881
|
__accessCheck(obj, member, "read from private field");
|
|
790
|
-
return
|
|
882
|
+
return member.get(obj);
|
|
791
883
|
};
|
|
792
884
|
var __privateAdd = (obj, member, value) => {
|
|
793
885
|
if (member.has(obj))
|
|
@@ -796,18 +888,18 @@ var __privateAdd = (obj, member, value) => {
|
|
|
796
888
|
};
|
|
797
889
|
var __privateSet = (obj, member, value, setter) => {
|
|
798
890
|
__accessCheck(obj, member, "write to private field");
|
|
799
|
-
|
|
891
|
+
member.set(obj, value);
|
|
800
892
|
return value;
|
|
801
893
|
};
|
|
802
894
|
var _promptsHistory, _internalAudioRecorder;
|
|
803
895
|
class ChatController {
|
|
804
896
|
constructor(id, welcomeMessage) {
|
|
805
897
|
this.id = id;
|
|
806
|
-
__publicField$
|
|
898
|
+
__publicField$7(this, "state", {
|
|
807
899
|
current: new ChatMessage(),
|
|
808
900
|
messages: []
|
|
809
901
|
});
|
|
810
|
-
__publicField$
|
|
902
|
+
__publicField$7(this, "components", {
|
|
811
903
|
MessageHistory: observer(() => {
|
|
812
904
|
return /* @__PURE__ */ jsx(
|
|
813
905
|
Box,
|
|
@@ -821,16 +913,16 @@ class ChatController {
|
|
|
821
913
|
Textarea: makeTextarea(this)
|
|
822
914
|
});
|
|
823
915
|
__privateAdd(this, _promptsHistory, []);
|
|
824
|
-
__publicField$
|
|
916
|
+
__publicField$7(this, "currentHistoryIndex", -1);
|
|
825
917
|
__privateAdd(this, _internalAudioRecorder, new AudioRecorder());
|
|
826
|
-
__publicField$
|
|
918
|
+
__publicField$7(this, "audioRecorder", {
|
|
827
919
|
start: () => __privateGet(this, _internalAudioRecorder).start().then(async (blob) => {
|
|
828
920
|
const m = new AIMessageAttachments(
|
|
829
921
|
AIMessageRole.USER,
|
|
830
|
-
new AIFileContent(
|
|
831
|
-
await AIFileContent.blobToBase64(blob),
|
|
832
|
-
`userRecord_${this.audioRecorder.record++}.wav`
|
|
833
|
-
),
|
|
922
|
+
new AIFileContent({
|
|
923
|
+
value: await AIFileContent.blobToBase64(blob),
|
|
924
|
+
name: `userRecord_${this.audioRecorder.record++}.wav`
|
|
925
|
+
}),
|
|
834
926
|
() => this.attachments.drop(m)
|
|
835
927
|
);
|
|
836
928
|
this.attachments.add(m);
|
|
@@ -841,7 +933,7 @@ class ChatController {
|
|
|
841
933
|
record: 0,
|
|
842
934
|
state: __privateGet(this, _internalAudioRecorder).state
|
|
843
935
|
});
|
|
844
|
-
__publicField$
|
|
936
|
+
__publicField$7(this, "history", {
|
|
845
937
|
add: (message) => {
|
|
846
938
|
this.currentHistoryIndex = -1;
|
|
847
939
|
if (message === __privateGet(this, _promptsHistory)[__privateGet(this, _promptsHistory).length]) {
|
|
@@ -857,7 +949,7 @@ class ChatController {
|
|
|
857
949
|
next: () => {
|
|
858
950
|
let message = new ChatMessage();
|
|
859
951
|
if (__privateGet(this, _promptsHistory)[this.currentHistoryIndex - 1])
|
|
860
|
-
message = __privateGet(this, _promptsHistory)[--this.currentHistoryIndex].
|
|
952
|
+
message = __privateGet(this, _promptsHistory)[--this.currentHistoryIndex].clone();
|
|
861
953
|
else {
|
|
862
954
|
this.currentHistoryIndex = -1;
|
|
863
955
|
}
|
|
@@ -866,7 +958,7 @@ class ChatController {
|
|
|
866
958
|
previous: () => {
|
|
867
959
|
if (__privateGet(this, _promptsHistory)[this.currentHistoryIndex + 1]) {
|
|
868
960
|
this.history.updateState(
|
|
869
|
-
__privateGet(this, _promptsHistory)[++this.currentHistoryIndex].
|
|
961
|
+
__privateGet(this, _promptsHistory)[++this.currentHistoryIndex].clone()
|
|
870
962
|
);
|
|
871
963
|
}
|
|
872
964
|
},
|
|
@@ -878,7 +970,7 @@ class ChatController {
|
|
|
878
970
|
},
|
|
879
971
|
size: () => this.state.messages.length
|
|
880
972
|
});
|
|
881
|
-
__publicField$
|
|
973
|
+
__publicField$7(this, "messages", {
|
|
882
974
|
add: (message, idx) => {
|
|
883
975
|
if (idx !== void 0 && idx !== null) {
|
|
884
976
|
this.state.messages.splice(idx, 0, message);
|
|
@@ -890,19 +982,25 @@ class ChatController {
|
|
|
890
982
|
this.state.messages = [];
|
|
891
983
|
}
|
|
892
984
|
});
|
|
893
|
-
__publicField$
|
|
985
|
+
__publicField$7(this, "attachments", {
|
|
894
986
|
add: (...aiMessage) => {
|
|
895
|
-
this.state.current.attachments.push(
|
|
987
|
+
this.state.current.attachments.push(
|
|
988
|
+
...aiMessage
|
|
989
|
+
);
|
|
896
990
|
},
|
|
897
991
|
dropAll: () => void (this.state.current.attachments = []),
|
|
898
992
|
drop: (el) => {
|
|
993
|
+
const e = el;
|
|
899
994
|
this.state.current.attachments = this.state.current.attachments.filter(
|
|
900
|
-
(c) => c !==
|
|
995
|
+
(c) => c !== e
|
|
901
996
|
);
|
|
902
997
|
if (!this.state.current.message && this.attachments.size() < 1)
|
|
903
998
|
this.currentHistoryIndex = -1;
|
|
904
999
|
},
|
|
905
|
-
getComponents: () => this.state.current.attachments.map((x) =>
|
|
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
|
+
}),
|
|
906
1004
|
get: () => this.state.current.attachments,
|
|
907
1005
|
size: () => this.state.current.attachments.length
|
|
908
1006
|
});
|
|
@@ -943,74 +1041,87 @@ class MultipleChoiceMessage extends ChatMessage {
|
|
|
943
1041
|
}
|
|
944
1042
|
}
|
|
945
1043
|
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
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);
|
|
950
1057
|
return value;
|
|
951
1058
|
};
|
|
952
|
-
class
|
|
953
|
-
constructor() {
|
|
954
|
-
|
|
955
|
-
__publicField$
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
__publicField$2(this, "timing", 5);
|
|
963
|
-
// ms
|
|
964
|
-
__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 });
|
|
965
1069
|
}
|
|
966
|
-
|
|
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 });
|
|
967
1082
|
}
|
|
968
|
-
|
|
969
|
-
const
|
|
970
|
-
|
|
971
|
-
this.minPartSize,
|
|
972
|
-
totalSize * this.timing / (this.maxCompletionTime * 1e3)
|
|
1083
|
+
async search(selectedId) {
|
|
1084
|
+
const filters = await FiltersStore.getFiltersById(
|
|
1085
|
+
Number.parseInt(selectedId)
|
|
973
1086
|
);
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
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);
|
|
980
1105
|
}
|
|
981
|
-
this.
|
|
982
|
-
this.run();
|
|
1106
|
+
this.state.isLoading = false;
|
|
983
1107
|
}
|
|
984
|
-
|
|
985
|
-
if (
|
|
986
|
-
|
|
987
|
-
const interval = setInterval(() => {
|
|
988
|
-
this.locked = true;
|
|
989
|
-
const choosedSize = Math.min(this.buffer.length, this.partSize);
|
|
990
|
-
const part = this.buffer.slice(0, choosedSize);
|
|
991
|
-
this.buffer = this.buffer.slice(choosedSize);
|
|
992
|
-
while (this.waiting.length > 0) {
|
|
993
|
-
const part2 = this.waiting.shift();
|
|
994
|
-
if (part2) {
|
|
995
|
-
this.buffer += part2;
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
this.locked = false;
|
|
999
|
-
if (part) {
|
|
1000
|
-
super.emit("part", part);
|
|
1001
|
-
} else {
|
|
1002
|
-
this.isRunning = false;
|
|
1003
|
-
clearInterval(interval);
|
|
1004
|
-
}
|
|
1005
|
-
}, this.timing);
|
|
1108
|
+
setReferences(results) {
|
|
1109
|
+
if (typeof results === "string" && results) {
|
|
1110
|
+
results = JSON.parse(results);
|
|
1006
1111
|
}
|
|
1112
|
+
_SearchController.instance.state.results = results.map(
|
|
1113
|
+
(x) => x instanceof SemanticSearchReference ? x : new SemanticSearchReference(x)
|
|
1114
|
+
);
|
|
1115
|
+
_SearchController.instance.state.disabled = false;
|
|
1007
1116
|
}
|
|
1008
|
-
}
|
|
1117
|
+
};
|
|
1118
|
+
__publicField$5(_SearchController, "instance", new _SearchController());
|
|
1119
|
+
let SearchController = _SearchController;
|
|
1009
1120
|
|
|
1010
|
-
var __defProp$
|
|
1011
|
-
var __defNormalProp$
|
|
1012
|
-
var __publicField$
|
|
1013
|
-
__defNormalProp$
|
|
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);
|
|
1014
1125
|
return value;
|
|
1015
1126
|
};
|
|
1016
1127
|
function isPollProgress(payload) {
|
|
@@ -1018,9 +1129,9 @@ function isPollProgress(payload) {
|
|
|
1018
1129
|
}
|
|
1019
1130
|
class RoutinesGeneration {
|
|
1020
1131
|
constructor() {
|
|
1021
|
-
__publicField$
|
|
1022
|
-
__publicField$
|
|
1023
|
-
__publicField$
|
|
1132
|
+
__publicField$4(this, "audioRecorder", new AudioRecorder());
|
|
1133
|
+
__publicField$4(this, "routineId", "");
|
|
1134
|
+
__publicField$4(this, "state", {
|
|
1024
1135
|
isLoading: false,
|
|
1025
1136
|
progress: 0
|
|
1026
1137
|
});
|
|
@@ -1037,9 +1148,14 @@ class RoutinesGeneration {
|
|
|
1037
1148
|
}
|
|
1038
1149
|
this.state.isLoading = true;
|
|
1039
1150
|
}
|
|
1040
|
-
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) {
|
|
1041
1157
|
while (this.state.isLoading) {
|
|
1042
|
-
const pollResult = await this.
|
|
1158
|
+
const pollResult = await this.callRoutinePoll(this.routineId);
|
|
1043
1159
|
if (isPollProgress(pollResult.payload)) {
|
|
1044
1160
|
try {
|
|
1045
1161
|
const res = JSON.parse(pollResult.payload.debug);
|
|
@@ -1058,43 +1174,33 @@ class RoutinesGeneration {
|
|
|
1058
1174
|
} else if (pollResult.status === "FINISHED") {
|
|
1059
1175
|
this.resetLoading();
|
|
1060
1176
|
return pollResult.payload;
|
|
1177
|
+
} else if (pollResult.status === "ERROR") {
|
|
1178
|
+
this.resetLoading();
|
|
1179
|
+
throw new Error(pollResult.payload);
|
|
1061
1180
|
} else {
|
|
1181
|
+
this.resetLoading();
|
|
1062
1182
|
throw new Error("Wrong poll response");
|
|
1063
1183
|
}
|
|
1064
1184
|
}
|
|
1065
1185
|
return null;
|
|
1066
1186
|
}
|
|
1067
|
-
async
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
{
|
|
1076
|
-
postData: {
|
|
1077
|
-
images: JSON.stringify(images),
|
|
1078
|
-
...prompts
|
|
1079
|
-
},
|
|
1080
|
-
stringifyOptions: {
|
|
1081
|
-
arrayFormat: "repeat"
|
|
1082
|
-
},
|
|
1083
|
-
postDataTreatement: "stringify"
|
|
1084
|
-
}
|
|
1085
|
-
);
|
|
1086
|
-
if (routineStartResult?.data?.orchestrator?.routineId !== void 0) {
|
|
1087
|
-
this.routineId = routineStartResult?.data?.orchestrator?.routineId;
|
|
1088
|
-
return this.pollRoutine(stream);
|
|
1089
|
-
} else {
|
|
1090
|
-
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"
|
|
1091
1195
|
}
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
|
-
|
|
1196
|
+
});
|
|
1197
|
+
const result = await parseSuccessfulResponse(response, "");
|
|
1198
|
+
if (result?.orchestrator) {
|
|
1199
|
+
return result;
|
|
1095
1200
|
}
|
|
1201
|
+
return null;
|
|
1096
1202
|
}
|
|
1097
|
-
async
|
|
1203
|
+
async callRoutinePoll(routineId) {
|
|
1098
1204
|
const result = await ApiaApi.post(
|
|
1099
1205
|
makeApiaUrl({
|
|
1100
1206
|
action: "routinePoll",
|
|
@@ -1107,6 +1213,44 @@ class RoutinesGeneration {
|
|
|
1107
1213
|
throw new Error("Poll failed");
|
|
1108
1214
|
}
|
|
1109
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
|
+
}
|
|
1110
1254
|
resetLoading() {
|
|
1111
1255
|
this.state.isLoading = false;
|
|
1112
1256
|
this.state.progress = 0;
|
|
@@ -1129,33 +1273,135 @@ class RoutinesGeneration {
|
|
|
1129
1273
|
);
|
|
1130
1274
|
}
|
|
1131
1275
|
async transcribeAudio(audio) {
|
|
1132
|
-
const
|
|
1133
|
-
|
|
1134
|
-
action: "routineStart",
|
|
1135
|
-
routine: "transcription/Transcribe"
|
|
1136
|
-
});
|
|
1137
|
-
const response = await axios.post(url, arrayBuffer, {
|
|
1138
|
-
headers: {
|
|
1139
|
-
"Content-Type": "application/octet-stream"
|
|
1140
|
-
}
|
|
1141
|
-
});
|
|
1142
|
-
if (response.data) {
|
|
1143
|
-
const result = await parseSuccessfulResponse(response, url);
|
|
1276
|
+
const result = await this.callAudioTranscription(audio);
|
|
1277
|
+
if (result) {
|
|
1144
1278
|
this.state.isLoading = true;
|
|
1145
1279
|
if (result?.orchestrator?.routineId) {
|
|
1146
1280
|
this.routineId = result?.orchestrator?.routineId;
|
|
1147
|
-
return await this.
|
|
1281
|
+
return await this.internalPollRoutine();
|
|
1148
1282
|
}
|
|
1149
1283
|
}
|
|
1150
1284
|
throw new Error("Something went wrong while transcribing the audio");
|
|
1151
1285
|
}
|
|
1152
1286
|
}
|
|
1153
1287
|
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
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) => {
|
|
1159
1405
|
const input = document.createElement("input");
|
|
1160
1406
|
input.accept = "image/*";
|
|
1161
1407
|
input.type = "file";
|
|
@@ -1212,17 +1458,17 @@ function getSrcFromBase64(base64) {
|
|
|
1212
1458
|
return `data:image/jpg;base64,${base64}`;
|
|
1213
1459
|
}
|
|
1214
1460
|
|
|
1215
|
-
var __defProp = Object.defineProperty;
|
|
1216
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1217
|
-
var __publicField = (obj, key, value) => {
|
|
1218
|
-
__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);
|
|
1219
1465
|
return value;
|
|
1220
1466
|
};
|
|
1221
1467
|
class ImagesStore {
|
|
1222
1468
|
constructor(images, multiple) {
|
|
1223
1469
|
this.multiple = multiple;
|
|
1224
|
-
__publicField(this, "images", /* @__PURE__ */ new Map());
|
|
1225
|
-
__publicField(this, "selectedId", "");
|
|
1470
|
+
__publicField$2(this, "images", /* @__PURE__ */ new Map());
|
|
1471
|
+
__publicField$2(this, "selectedId", "");
|
|
1226
1472
|
this.images = new Map(
|
|
1227
1473
|
images.map((c) => {
|
|
1228
1474
|
const id = uniqueId();
|
|
@@ -1348,5 +1594,667 @@ function getImagesWithDescription({
|
|
|
1348
1594
|
});
|
|
1349
1595
|
}
|
|
1350
1596
|
|
|
1351
|
-
|
|
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 };
|
|
1352
2260
|
//# sourceMappingURL=index.js.map
|