@apia/ai 4.0.43 → 4.0.45
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 +280 -17
- package/dist/index.js +1271 -63
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { makeObservable, observable, action, toJS, makeAutoObservable } from 'mobx';
|
|
2
2
|
import { jsxs, jsx, Fragment } from '@apia/theme/jsx-runtime';
|
|
3
|
-
import { Box, getVariant,
|
|
3
|
+
import { Box, Label, getVariant, Form, spacing, Paragraph, Textarea } from '@apia/theme';
|
|
4
4
|
import { observer } from 'mobx-react-lite';
|
|
5
5
|
import { ApiaApi, makeApiaUrl, parseSuccessfulResponse } from '@apia/api';
|
|
6
|
-
import { FiltersStore,
|
|
6
|
+
import { FiltersStore, ApiaUtil, FileCard, importComponent, MDRenderer, AutogrowTextarea, IconButton, SimpleButton, SortableList, SortableListItem } from '@apia/components';
|
|
7
7
|
import axios from 'axios';
|
|
8
|
-
import { AudioRecorder, EventEmitter } from '@apia/util';
|
|
9
|
-
import { createContext } from 'react';
|
|
8
|
+
import { findScrollContainer, getLabel, decodeBase64ToUtf8, AudioRecorder, EventEmitter } from '@apia/util';
|
|
9
|
+
import { useRef, useEffect, memo, Suspense, useState, createContext } from 'react';
|
|
10
10
|
import { uniqueId } from '@apia/notifications';
|
|
11
|
+
import { Collector } from '@apia/validations';
|
|
11
12
|
|
|
12
13
|
const Component = observer(
|
|
13
14
|
(props) => {
|
|
@@ -18,16 +19,16 @@ const Component = observer(
|
|
|
18
19
|
}
|
|
19
20
|
);
|
|
20
21
|
|
|
21
|
-
var __defProp$
|
|
22
|
-
var __defNormalProp$
|
|
23
|
-
var __publicField$
|
|
24
|
-
__defNormalProp$
|
|
22
|
+
var __defProp$a = Object.defineProperty;
|
|
23
|
+
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
24
|
+
var __publicField$a = (obj, key, value) => {
|
|
25
|
+
__defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
25
26
|
return value;
|
|
26
27
|
};
|
|
27
28
|
class SemanticSearchReference {
|
|
28
29
|
constructor(props) {
|
|
29
|
-
__publicField$
|
|
30
|
-
__publicField$
|
|
30
|
+
__publicField$a(this, "state", { title: "", body: "", link: "" });
|
|
31
|
+
__publicField$a(this, "Component", () => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
31
32
|
"(",
|
|
32
33
|
/* @__PURE__ */ jsx(Component, { instance: this }),
|
|
33
34
|
")"
|
|
@@ -37,15 +38,15 @@ class SemanticSearchReference {
|
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
var __defProp$
|
|
41
|
-
var __defNormalProp$
|
|
42
|
-
var __publicField$
|
|
43
|
-
__defNormalProp$
|
|
41
|
+
var __defProp$9 = Object.defineProperty;
|
|
42
|
+
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
43
|
+
var __publicField$9 = (obj, key, value) => {
|
|
44
|
+
__defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
44
45
|
return value;
|
|
45
46
|
};
|
|
46
47
|
const _SearchController = class _SearchController {
|
|
47
48
|
constructor() {
|
|
48
|
-
__publicField$
|
|
49
|
+
__publicField$9(this, "state", { queryString: "", results: [], isLoading: false, disabled: false });
|
|
49
50
|
makeObservable(this, { state: observable });
|
|
50
51
|
}
|
|
51
52
|
async search(selectedId) {
|
|
@@ -83,13 +84,1198 @@ const _SearchController = class _SearchController {
|
|
|
83
84
|
_SearchController.instance.state.disabled = false;
|
|
84
85
|
}
|
|
85
86
|
};
|
|
86
|
-
__publicField$
|
|
87
|
+
__publicField$9(_SearchController, "instance", new _SearchController());
|
|
87
88
|
let SearchController = _SearchController;
|
|
88
89
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
const AutoscrollContainer = ({ children, threshold = 150, className }) => {
|
|
91
|
+
const wrapperRef = useRef(null);
|
|
92
|
+
const autoScrollEnabled = useRef(true);
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
const wrapper = wrapperRef.current;
|
|
95
|
+
if (!wrapper)
|
|
96
|
+
return;
|
|
97
|
+
const scrollEl = findScrollContainer(wrapper);
|
|
98
|
+
const isNearBottom = () => scrollEl.scrollHeight - (scrollEl.scrollTop + scrollEl.clientHeight) <= threshold;
|
|
99
|
+
const onWheel = (e) => {
|
|
100
|
+
if (e.deltaY < 0) {
|
|
101
|
+
autoScrollEnabled.current = false;
|
|
102
|
+
} else if (e.deltaY > 0 && isNearBottom()) {
|
|
103
|
+
autoScrollEnabled.current = true;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const onScroll = () => {
|
|
107
|
+
if (isNearBottom()) {
|
|
108
|
+
autoScrollEnabled.current = true;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
function enable() {
|
|
112
|
+
autoScrollEnabled.current = true;
|
|
113
|
+
}
|
|
114
|
+
scrollEl.addEventListener("wheel", onWheel, { passive: true });
|
|
115
|
+
scrollEl.addEventListener("scroll", onScroll, { passive: true });
|
|
116
|
+
document.addEventListener("enableAutoScroll", enable);
|
|
117
|
+
scrollEl.scrollTo({ top: scrollEl.scrollHeight, behavior: "smooth" });
|
|
118
|
+
const mo = new MutationObserver(() => {
|
|
119
|
+
if (autoScrollEnabled.current) {
|
|
120
|
+
scrollEl.scrollTo({ top: scrollEl.scrollHeight, behavior: "smooth" });
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
mo.observe(wrapper, { childList: true, subtree: true });
|
|
124
|
+
return () => {
|
|
125
|
+
scrollEl.removeEventListener("wheel", onWheel);
|
|
126
|
+
scrollEl.removeEventListener("enableAutoScroll", enable);
|
|
127
|
+
scrollEl.removeEventListener("scroll", onScroll);
|
|
128
|
+
mo.disconnect();
|
|
129
|
+
};
|
|
130
|
+
}, [threshold]);
|
|
131
|
+
return /* @__PURE__ */ jsx("div", { ref: wrapperRef, className: `${className || ""} autoscrollContainer`, children });
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
var __defProp$8 = Object.defineProperty;
|
|
135
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
136
|
+
var __publicField$8 = (obj, key, value) => {
|
|
137
|
+
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
138
|
+
return value;
|
|
139
|
+
};
|
|
140
|
+
let maxId = 0;
|
|
141
|
+
class ChatMessage {
|
|
142
|
+
constructor(message = "", messageType = "user", attachments = [], reference = null) {
|
|
143
|
+
__publicField$8(this, "id");
|
|
144
|
+
__publicField$8(this, "state");
|
|
145
|
+
__publicField$8(this, "clone", () => new ChatMessage(
|
|
146
|
+
this.message,
|
|
147
|
+
this.messageType,
|
|
148
|
+
this.attachments.map((x) => {
|
|
149
|
+
return { ...x };
|
|
150
|
+
}),
|
|
151
|
+
this.reference
|
|
152
|
+
));
|
|
153
|
+
this.state = { message, messageType, attachments, reference };
|
|
154
|
+
this.id = maxId++;
|
|
155
|
+
if (messageType === "response")
|
|
156
|
+
this.messageType = "system";
|
|
157
|
+
if (typeof message === "string")
|
|
158
|
+
this.message = message;
|
|
159
|
+
makeObservable(this, {
|
|
160
|
+
state: observable
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
get message() {
|
|
164
|
+
return this.state.message;
|
|
165
|
+
}
|
|
166
|
+
get messageType() {
|
|
167
|
+
return this.state.messageType;
|
|
168
|
+
}
|
|
169
|
+
get attachments() {
|
|
170
|
+
return this.state.attachments;
|
|
171
|
+
}
|
|
172
|
+
get reference() {
|
|
173
|
+
return this.state.reference;
|
|
174
|
+
}
|
|
175
|
+
set message(value) {
|
|
176
|
+
this.state.message = value;
|
|
177
|
+
}
|
|
178
|
+
set messageType(value) {
|
|
179
|
+
this.state.messageType = value;
|
|
180
|
+
}
|
|
181
|
+
set attachments(value) {
|
|
182
|
+
this.state.attachments = value;
|
|
183
|
+
}
|
|
184
|
+
set reference(value) {
|
|
185
|
+
this.state.reference = value;
|
|
186
|
+
}
|
|
187
|
+
removeAttachment(attachment) {
|
|
188
|
+
this.attachments = this.attachments.filter(
|
|
189
|
+
(current) => current !== attachment
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
addAttachmentDescription(attachment, description) {
|
|
193
|
+
const a = this.attachments.find((current) => current === attachment);
|
|
194
|
+
if (a) {
|
|
195
|
+
a.description = description;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
setMessageType(type) {
|
|
199
|
+
this.messageType = type;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const FileAttachment = observer(
|
|
204
|
+
({
|
|
205
|
+
attachment,
|
|
206
|
+
onAddDescription,
|
|
207
|
+
onRemove
|
|
208
|
+
}) => {
|
|
209
|
+
const { ref } = ApiaUtil.instance.tooltips.useHover({
|
|
210
|
+
preferredOrientationX: "left",
|
|
211
|
+
preferredOrientationY: "top",
|
|
212
|
+
minSize: {
|
|
213
|
+
width: 200,
|
|
214
|
+
height: 400
|
|
215
|
+
},
|
|
216
|
+
attachToMousePosition: true,
|
|
217
|
+
closeOnMouseLeaveAttachedElement: true,
|
|
218
|
+
children: /* @__PURE__ */ jsxs(
|
|
219
|
+
Box,
|
|
220
|
+
{
|
|
221
|
+
sx: {
|
|
222
|
+
display: "flex",
|
|
223
|
+
alignItems: "center",
|
|
224
|
+
flexDirection: "column"
|
|
225
|
+
},
|
|
226
|
+
children: [
|
|
227
|
+
/* @__PURE__ */ jsx("h1", { children: attachment.name }),
|
|
228
|
+
/* @__PURE__ */ jsx("img", { src: attachment.base64 }),
|
|
229
|
+
attachment.description && /* @__PURE__ */ jsx(Label, { children: attachment.description })
|
|
230
|
+
]
|
|
231
|
+
}
|
|
232
|
+
)
|
|
233
|
+
});
|
|
234
|
+
return /* @__PURE__ */ jsx(
|
|
235
|
+
FileCard,
|
|
236
|
+
{
|
|
237
|
+
ref,
|
|
238
|
+
name: attachment.name,
|
|
239
|
+
handleClose: onRemove,
|
|
240
|
+
additionalButtons: onAddDescription ? [
|
|
241
|
+
{
|
|
242
|
+
icon: "Pencil",
|
|
243
|
+
onClick: () => {
|
|
244
|
+
const collector = new Collector();
|
|
245
|
+
collector.add(
|
|
246
|
+
new collector.fields.textarea(
|
|
247
|
+
"desc",
|
|
248
|
+
getLabel("lblDes").text,
|
|
249
|
+
{ initialValue: attachment.description }
|
|
250
|
+
)
|
|
251
|
+
);
|
|
252
|
+
collector.show({
|
|
253
|
+
onConfirm: (ev) => {
|
|
254
|
+
if (ev) {
|
|
255
|
+
onAddDescription(attachment, ev.desc);
|
|
256
|
+
}
|
|
257
|
+
return true;
|
|
258
|
+
},
|
|
259
|
+
title: getLabel("btnAddComment").text
|
|
260
|
+
});
|
|
261
|
+
},
|
|
262
|
+
variant: "icon-only"
|
|
263
|
+
}
|
|
264
|
+
] : []
|
|
265
|
+
}
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
const Attachments = observer(
|
|
271
|
+
({
|
|
272
|
+
attachments,
|
|
273
|
+
onRemove,
|
|
274
|
+
onAddDescription,
|
|
275
|
+
className
|
|
276
|
+
}) => {
|
|
277
|
+
if (!attachments.length)
|
|
278
|
+
return null;
|
|
279
|
+
return /* @__PURE__ */ jsx(
|
|
280
|
+
Box,
|
|
281
|
+
{
|
|
282
|
+
className: `attachments ${className}`,
|
|
283
|
+
...getVariant("layout.common.chat.attachments"),
|
|
284
|
+
children: attachments.map((x) => /* @__PURE__ */ jsx(
|
|
285
|
+
FileAttachment,
|
|
286
|
+
{
|
|
287
|
+
attachment: x,
|
|
288
|
+
onRemove: onRemove ? () => onRemove(x) : void 0,
|
|
289
|
+
onAddDescription
|
|
290
|
+
},
|
|
291
|
+
x.id
|
|
292
|
+
))
|
|
293
|
+
}
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
const MessageBlock = memo(
|
|
299
|
+
({ componentData }) => {
|
|
300
|
+
if (typeof componentData.args === "string") {
|
|
301
|
+
componentData.args = JSON.parse(componentData.args);
|
|
302
|
+
}
|
|
303
|
+
const Component = importComponent(componentData.path);
|
|
304
|
+
return /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(Component, { ...componentData.args }) });
|
|
305
|
+
}
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
const MessageBlocks = observer(
|
|
309
|
+
({ streamParts }) => {
|
|
310
|
+
const parts = streamParts.map((p, i) => {
|
|
311
|
+
if (p.blockType === "describer") {
|
|
312
|
+
return /* @__PURE__ */ jsx(
|
|
313
|
+
Box,
|
|
314
|
+
{
|
|
315
|
+
variant: "layout.common.ai.semanticSearch.execution.streamBlocks",
|
|
316
|
+
className: "sem_search__stream_blocks",
|
|
317
|
+
as: "ul",
|
|
318
|
+
children: /* @__PURE__ */ jsx(
|
|
319
|
+
Box,
|
|
320
|
+
{
|
|
321
|
+
variant: "layout.common.ai.semanticSearch.execution.streamBlocks",
|
|
322
|
+
as: "li",
|
|
323
|
+
className: `sem_search__stream_block ${p.describer.type}`,
|
|
324
|
+
children: p.describer.content
|
|
325
|
+
},
|
|
326
|
+
i
|
|
327
|
+
)
|
|
328
|
+
}
|
|
329
|
+
);
|
|
330
|
+
} else if (p.blockType === "text") {
|
|
331
|
+
return p.str.split(/(!!\[[^]+])/g).map((c) => {
|
|
332
|
+
if (c.match(/^!!\[[^]+]$/)) {
|
|
333
|
+
const definition = JSON.parse(
|
|
334
|
+
decodeBase64ToUtf8(
|
|
335
|
+
(c.match(/^!!\[([^]+)]$/) ?? [void 0, void 0])[1] ?? ""
|
|
336
|
+
)
|
|
337
|
+
);
|
|
338
|
+
return /* @__PURE__ */ jsx(MessageBlock, { componentData: definition }, i);
|
|
339
|
+
} else {
|
|
340
|
+
return /* @__PURE__ */ jsx(MDRenderer, { str: c }, i);
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
return parts;
|
|
346
|
+
}
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
const Message = observer(
|
|
350
|
+
({
|
|
351
|
+
className,
|
|
352
|
+
type,
|
|
353
|
+
id,
|
|
354
|
+
message,
|
|
355
|
+
attachments,
|
|
356
|
+
reference
|
|
357
|
+
}) => {
|
|
358
|
+
return /* @__PURE__ */ jsxs(
|
|
359
|
+
Box,
|
|
360
|
+
{
|
|
361
|
+
as: "pre",
|
|
362
|
+
className: `history_message ${className || ""} ${type}`,
|
|
363
|
+
children: [
|
|
364
|
+
/* @__PURE__ */ jsx(
|
|
365
|
+
Box,
|
|
366
|
+
{
|
|
367
|
+
className: "history_message__content",
|
|
368
|
+
...typeof message === "string" ? {
|
|
369
|
+
children: /* @__PURE__ */ jsx(
|
|
370
|
+
MessageBlocks,
|
|
371
|
+
{
|
|
372
|
+
streamParts: [{ blockType: "text", str: message }]
|
|
373
|
+
}
|
|
374
|
+
)
|
|
375
|
+
} : { children: message }
|
|
376
|
+
}
|
|
377
|
+
),
|
|
378
|
+
attachments.length > 0 && /* @__PURE__ */ jsx(Attachments, { attachments }),
|
|
379
|
+
reference && /* @__PURE__ */ jsx(Box, { className: "history_message__references", children: reference })
|
|
380
|
+
]
|
|
381
|
+
},
|
|
382
|
+
id
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
const History = observer(
|
|
388
|
+
({
|
|
389
|
+
messages,
|
|
390
|
+
className
|
|
391
|
+
}) => {
|
|
392
|
+
let currentType = "";
|
|
393
|
+
return /* @__PURE__ */ jsx(AutoscrollContainer, { className, children: /* @__PURE__ */ jsx(
|
|
394
|
+
Box,
|
|
395
|
+
{
|
|
396
|
+
...getVariant("layout.common.chat.history"),
|
|
397
|
+
className: "chat_history",
|
|
398
|
+
children: messages.map((current, i) => {
|
|
399
|
+
let first = false;
|
|
400
|
+
let last = false;
|
|
401
|
+
if (currentType !== current.messageType) {
|
|
402
|
+
currentType = current.messageType;
|
|
403
|
+
first = true;
|
|
404
|
+
}
|
|
405
|
+
if (i === messages.length - 1 || messages[i + 1].messageType !== current.messageType) {
|
|
406
|
+
last = true;
|
|
407
|
+
}
|
|
408
|
+
return /* @__PURE__ */ jsx(
|
|
409
|
+
Message,
|
|
410
|
+
{
|
|
411
|
+
className: first ? "first" : last ? "last" : void 0,
|
|
412
|
+
type: current.messageType,
|
|
413
|
+
id: String(current.id),
|
|
414
|
+
attachments: current.attachments,
|
|
415
|
+
reference: current.reference,
|
|
416
|
+
message: current.message
|
|
417
|
+
}
|
|
418
|
+
);
|
|
419
|
+
})
|
|
420
|
+
}
|
|
421
|
+
) });
|
|
422
|
+
}
|
|
423
|
+
);
|
|
424
|
+
|
|
425
|
+
function getBase64FromFile(f) {
|
|
426
|
+
return ((f2) => new Promise((resolve, reject) => {
|
|
427
|
+
const reader = new FileReader();
|
|
428
|
+
reader.readAsDataURL(f2);
|
|
429
|
+
reader.onload = () => resolve(reader.result);
|
|
430
|
+
reader.onerror = () => reject();
|
|
431
|
+
}))(f);
|
|
432
|
+
}
|
|
433
|
+
function getBase64FromBlob(b) {
|
|
434
|
+
return ((blob) => new Promise((resolve, reject) => {
|
|
435
|
+
const reader = new FileReader();
|
|
436
|
+
reader.onloadend = () => {
|
|
437
|
+
const base64String = reader.result;
|
|
438
|
+
resolve(base64String);
|
|
439
|
+
};
|
|
440
|
+
reader.onerror = reject;
|
|
441
|
+
reader.readAsDataURL(blob);
|
|
442
|
+
}))(b);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const TextArea = observer(
|
|
446
|
+
({
|
|
447
|
+
additionalOptions = [],
|
|
448
|
+
isLoading,
|
|
449
|
+
isRecording,
|
|
450
|
+
disablePrevButton,
|
|
451
|
+
disableNextButton,
|
|
452
|
+
onSubmit,
|
|
453
|
+
onChange,
|
|
454
|
+
onClearHistory,
|
|
455
|
+
onAttach,
|
|
456
|
+
onRecord,
|
|
457
|
+
onRecordCancel,
|
|
458
|
+
onVideoRecord,
|
|
459
|
+
onPrev,
|
|
460
|
+
onNext,
|
|
461
|
+
value,
|
|
462
|
+
attachments,
|
|
463
|
+
className
|
|
464
|
+
}) => {
|
|
465
|
+
const fileInputRef = useRef(null);
|
|
466
|
+
const searchControlsRef = useRef(null);
|
|
467
|
+
const [dragging, setDragging] = useState(false);
|
|
468
|
+
const handleAttachments = async (ev) => {
|
|
469
|
+
if (ev.target.files) {
|
|
470
|
+
for await (const f of ev.target.files) {
|
|
471
|
+
const base64 = await getBase64FromFile(f);
|
|
472
|
+
onAttach({
|
|
473
|
+
base64,
|
|
474
|
+
name: f.name,
|
|
475
|
+
id: f.name
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
ev.target.value = "";
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
const menuItemsList = [
|
|
482
|
+
...additionalOptions.length > 0 ? [...additionalOptions, "separator"] : [],
|
|
483
|
+
{
|
|
484
|
+
children: getLabel("btnUpload").text,
|
|
485
|
+
title: getLabel("btnUpload").text,
|
|
486
|
+
icon: "File",
|
|
487
|
+
onClick: () => fileInputRef.current?.click(),
|
|
488
|
+
key: "2"
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
title: getLabel("lblOpenCamera").text,
|
|
492
|
+
children: getLabel("lblOpenCamera").text,
|
|
493
|
+
icon: "Camera",
|
|
494
|
+
onClick: onVideoRecord,
|
|
495
|
+
key: "3"
|
|
496
|
+
},
|
|
497
|
+
"separator",
|
|
498
|
+
{
|
|
499
|
+
icon: "ArrowLeft",
|
|
500
|
+
children: getLabel("btnAiPrevious").text,
|
|
501
|
+
title: getLabel("btnAiPrevious").text,
|
|
502
|
+
onClick: onPrev,
|
|
503
|
+
disabled: disablePrevButton,
|
|
504
|
+
key: "0"
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
icon: "ArrowRight",
|
|
508
|
+
children: getLabel("btnAiNext").text,
|
|
509
|
+
title: getLabel("btnAiNext").text,
|
|
510
|
+
onClick: onNext,
|
|
511
|
+
disabled: disableNextButton,
|
|
512
|
+
key: "1"
|
|
513
|
+
},
|
|
514
|
+
"separator",
|
|
515
|
+
{
|
|
516
|
+
icon: "Trash",
|
|
517
|
+
onClick: onClearHistory,
|
|
518
|
+
key: "5",
|
|
519
|
+
children: getLabel("btnAiDeleteMessages").text,
|
|
520
|
+
title: getLabel("btnAiDeleteMessages").text
|
|
521
|
+
}
|
|
522
|
+
];
|
|
523
|
+
const handleDragLeave = (ev) => {
|
|
524
|
+
ev.preventDefault();
|
|
525
|
+
setDragging(false);
|
|
526
|
+
};
|
|
527
|
+
const handleDrop = (ev) => {
|
|
528
|
+
ev.preventDefault();
|
|
529
|
+
setDragging(false);
|
|
530
|
+
const fileElement = document.getElementById(
|
|
531
|
+
`invisible__attach__file`
|
|
532
|
+
);
|
|
533
|
+
(fileInputRef.current ?? fileElement).files = ev.dataTransfer.files;
|
|
534
|
+
const event = new Event("change", { bubbles: true });
|
|
535
|
+
fileElement.dispatchEvent(event);
|
|
536
|
+
};
|
|
537
|
+
const handleDragOver = (ev) => {
|
|
538
|
+
ev.preventDefault();
|
|
539
|
+
};
|
|
540
|
+
const handleDragEnter = (ev) => {
|
|
541
|
+
ev.preventDefault();
|
|
542
|
+
setDragging(true);
|
|
543
|
+
};
|
|
544
|
+
return /* @__PURE__ */ jsxs(
|
|
545
|
+
Form,
|
|
546
|
+
{
|
|
547
|
+
onDrop: handleDrop,
|
|
548
|
+
onDragOver: handleDragOver,
|
|
549
|
+
onDragEnter: handleDragEnter,
|
|
550
|
+
onDragLeave: handleDragLeave,
|
|
551
|
+
onSubmit: (ev) => {
|
|
552
|
+
ev.preventDefault();
|
|
553
|
+
onSubmit();
|
|
554
|
+
},
|
|
555
|
+
className: `search_controls ${className}`,
|
|
556
|
+
...getVariant("layout.common.chat.form"),
|
|
557
|
+
children: [
|
|
558
|
+
dragging ? /* @__PURE__ */ jsx(
|
|
559
|
+
Box,
|
|
560
|
+
{
|
|
561
|
+
sx: {
|
|
562
|
+
height: "150px",
|
|
563
|
+
border: "3px dashed #aaa",
|
|
564
|
+
width: "100%",
|
|
565
|
+
display: "flex",
|
|
566
|
+
alignItems: "center",
|
|
567
|
+
justifyContent: "center"
|
|
568
|
+
},
|
|
569
|
+
children: getLabel("msgAiDragAndDrop").text
|
|
570
|
+
}
|
|
571
|
+
) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
572
|
+
/* @__PURE__ */ jsx(
|
|
573
|
+
AutogrowTextarea,
|
|
574
|
+
{
|
|
575
|
+
ref: searchControlsRef,
|
|
576
|
+
"aria-label": (
|
|
577
|
+
/** TODO: Crear etiqueta para búsqueda */
|
|
578
|
+
"Frase de b\xFAsqueda"
|
|
579
|
+
),
|
|
580
|
+
value,
|
|
581
|
+
className: "searchTextArea",
|
|
582
|
+
onChange: (ev) => onChange(ev.target.value),
|
|
583
|
+
onKeyDown: (ev) => {
|
|
584
|
+
if ((ev.code === "Enter" || ev.code === "NumpadEnter") && !ev.shiftKey) {
|
|
585
|
+
ev.preventDefault();
|
|
586
|
+
ev.target.closest("form").querySelector('[type="submit"]').click();
|
|
587
|
+
}
|
|
588
|
+
},
|
|
589
|
+
sx: {
|
|
590
|
+
resize: "none",
|
|
591
|
+
px: spacing(4),
|
|
592
|
+
background: "transparent",
|
|
593
|
+
border: "none",
|
|
594
|
+
alignContent: "center"
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
),
|
|
598
|
+
/* @__PURE__ */ jsxs(Box, { className: "chatButtons", children: [
|
|
599
|
+
/* @__PURE__ */ jsx(
|
|
600
|
+
IconButton,
|
|
601
|
+
{
|
|
602
|
+
className: "ChatBarButton",
|
|
603
|
+
icon: isRecording ? "Trash" : "Ellipsis",
|
|
604
|
+
variant: "icon-only",
|
|
605
|
+
iconSize: "Sm",
|
|
606
|
+
onClick: isRecording ? onRecordCancel : (ev) => {
|
|
607
|
+
ApiaUtil.instance.menu.open({
|
|
608
|
+
menuProps: {
|
|
609
|
+
anchorPoint: { x: ev.clientX, y: ev.clientY }
|
|
610
|
+
},
|
|
611
|
+
items: menuItemsList
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
),
|
|
616
|
+
value === "" && attachments.length === 0 || isRecording ? /* @__PURE__ */ jsx(
|
|
617
|
+
IconButton,
|
|
618
|
+
{
|
|
619
|
+
className: `ChatBarButton ${isRecording ? "isRecording" : ""}`,
|
|
620
|
+
icon: isRecording ? "Stop" : "Microphone",
|
|
621
|
+
variant: "icon-only",
|
|
622
|
+
iconSize: "Sm",
|
|
623
|
+
title: getLabel("lblAiRecordAudio").text,
|
|
624
|
+
onClick: onRecord,
|
|
625
|
+
isLoading,
|
|
626
|
+
disabled: isLoading && !isRecording,
|
|
627
|
+
sx: {
|
|
628
|
+
color: isRecording ? "red" : void 0
|
|
629
|
+
},
|
|
630
|
+
id: "transcribeAudio"
|
|
631
|
+
}
|
|
632
|
+
) : /* @__PURE__ */ jsx(
|
|
633
|
+
IconButton,
|
|
634
|
+
{
|
|
635
|
+
className: "ChatBarButton",
|
|
636
|
+
isLoading,
|
|
637
|
+
icon: "ArrowRight",
|
|
638
|
+
variant: "icon-only",
|
|
639
|
+
iconSize: "Sm",
|
|
640
|
+
title: getLabel("btnBus").title,
|
|
641
|
+
type: "submit"
|
|
642
|
+
}
|
|
643
|
+
)
|
|
644
|
+
] })
|
|
645
|
+
] }),
|
|
646
|
+
/* @__PURE__ */ jsx(
|
|
647
|
+
"input",
|
|
648
|
+
{
|
|
649
|
+
ref: fileInputRef,
|
|
650
|
+
id: "invisible__attach__file",
|
|
651
|
+
type: "file",
|
|
652
|
+
multiple: true,
|
|
653
|
+
onChange: handleAttachments,
|
|
654
|
+
sx: { display: "none" }
|
|
655
|
+
}
|
|
656
|
+
)
|
|
657
|
+
]
|
|
658
|
+
}
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
);
|
|
662
|
+
|
|
663
|
+
var __defProp$7 = Object.defineProperty;
|
|
664
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
665
|
+
var __publicField$7 = (obj, key, value) => {
|
|
666
|
+
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
667
|
+
return value;
|
|
668
|
+
};
|
|
669
|
+
class CameraController {
|
|
670
|
+
constructor() {
|
|
671
|
+
__publicField$7(this, "state", {
|
|
672
|
+
videoStream: null,
|
|
673
|
+
isOpen: false
|
|
674
|
+
});
|
|
675
|
+
__publicField$7(this, "currentCapture", null);
|
|
676
|
+
__publicField$7(this, "videoElement");
|
|
677
|
+
__publicField$7(this, "Component", () => {
|
|
678
|
+
return /* @__PURE__ */ jsx(
|
|
679
|
+
"video",
|
|
680
|
+
{
|
|
681
|
+
ref: (el) => {
|
|
682
|
+
if (el) {
|
|
683
|
+
el.srcObject = this.videoElement.srcObject;
|
|
684
|
+
el.autoplay = true;
|
|
685
|
+
el.playsInline = true;
|
|
686
|
+
}
|
|
687
|
+
},
|
|
688
|
+
style: { width: "100%", height: "auto" }
|
|
689
|
+
}
|
|
690
|
+
);
|
|
691
|
+
});
|
|
692
|
+
makeObservable(this, {
|
|
693
|
+
state: observable,
|
|
694
|
+
openCamera: action,
|
|
695
|
+
closeCamera: action
|
|
696
|
+
});
|
|
697
|
+
this.videoElement = document.createElement("video");
|
|
698
|
+
this.videoElement.autoplay = true;
|
|
699
|
+
this.videoElement.playsInline = true;
|
|
700
|
+
}
|
|
701
|
+
async openCamera() {
|
|
702
|
+
try {
|
|
703
|
+
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
|
|
704
|
+
this.state.videoStream = stream;
|
|
705
|
+
this.videoElement.srcObject = stream;
|
|
706
|
+
this.state.isOpen = true;
|
|
707
|
+
ApiaUtil.instance.modals.open({
|
|
708
|
+
children: /* @__PURE__ */ jsx(this.Component, {}),
|
|
709
|
+
onConfirm: () => {
|
|
710
|
+
this.closeCamera();
|
|
711
|
+
},
|
|
712
|
+
onClose: () => {
|
|
713
|
+
this.closeCamera();
|
|
714
|
+
}
|
|
715
|
+
});
|
|
716
|
+
} catch (error) {
|
|
717
|
+
console.error("Error while accessing the camera:", error);
|
|
718
|
+
this.state.isOpen = false;
|
|
719
|
+
this.closeCamera();
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
async closeCamera() {
|
|
723
|
+
if (!this.videoElement.srcObject)
|
|
724
|
+
return;
|
|
725
|
+
const canvas = document.createElement("canvas");
|
|
726
|
+
canvas.width = this.videoElement.videoWidth;
|
|
727
|
+
canvas.height = this.videoElement.videoHeight;
|
|
728
|
+
const ctx = canvas.getContext("2d");
|
|
729
|
+
if (ctx)
|
|
730
|
+
ctx.drawImage(this.videoElement, 0, 0, canvas.width, canvas.height);
|
|
731
|
+
this.currentCapture = await new Promise((resolve) => {
|
|
732
|
+
canvas.toBlob((blob) => {
|
|
733
|
+
if (blob) {
|
|
734
|
+
const file = new File([blob], "captured_image.jpg", {
|
|
735
|
+
type: "image/jpeg"
|
|
736
|
+
});
|
|
737
|
+
resolve(file);
|
|
738
|
+
} else {
|
|
739
|
+
this.closeCamera();
|
|
740
|
+
}
|
|
741
|
+
}, "image/jpeg");
|
|
742
|
+
}).finally(() => {
|
|
743
|
+
this.state.videoStream?.getTracks().forEach((track) => track.stop());
|
|
744
|
+
this.state.videoStream = null;
|
|
745
|
+
this.videoElement.srcObject = null;
|
|
746
|
+
this.state.isOpen = false;
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
pop() {
|
|
750
|
+
const returnFile = this.currentCapture;
|
|
751
|
+
this.currentCapture = null;
|
|
752
|
+
return returnFile;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
var __defProp$6 = Object.defineProperty;
|
|
757
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
758
|
+
var __publicField$6 = (obj, key, value) => {
|
|
759
|
+
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
760
|
+
return value;
|
|
761
|
+
};
|
|
762
|
+
class ChatController {
|
|
763
|
+
constructor(props, onMessageSubmit, onClearHistory, additionalOptions, classNames) {
|
|
764
|
+
this.onMessageSubmit = onMessageSubmit;
|
|
765
|
+
this.onClearHistory = onClearHistory;
|
|
766
|
+
this.additionalOptions = additionalOptions;
|
|
767
|
+
this.classNames = classNames;
|
|
768
|
+
__publicField$6(this, "currentIndex", 0);
|
|
769
|
+
__publicField$6(this, "state", {
|
|
770
|
+
isLoading: false,
|
|
771
|
+
canRecord: true,
|
|
772
|
+
canAttach: true,
|
|
773
|
+
maxAttachmentsSize: 100,
|
|
774
|
+
messages: [],
|
|
775
|
+
currentMessage: new ChatMessage("", "user")
|
|
776
|
+
});
|
|
777
|
+
__publicField$6(this, "internalAudioRecorder", new AudioRecorder());
|
|
778
|
+
__publicField$6(this, "internalCameraRecorder", new CameraController());
|
|
779
|
+
__publicField$6(this, "maxId", 0);
|
|
780
|
+
__publicField$6(this, "audioRecorder", {
|
|
781
|
+
cancelOnStop: false,
|
|
782
|
+
start: () => {
|
|
783
|
+
this.state.isLoading = true;
|
|
784
|
+
this.internalAudioRecorder.start().then(async (blob) => {
|
|
785
|
+
if (this.audioRecorder.cancelOnStop) {
|
|
786
|
+
this.audioRecorder.cancelOnStop = false;
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
this.state.currentMessage.attachments.push({
|
|
790
|
+
id: String(this.maxId++),
|
|
791
|
+
name: `userRecord_${this.audioRecorder.record++}.wav`,
|
|
792
|
+
base64: await getBase64FromBlob(blob)
|
|
793
|
+
});
|
|
794
|
+
const currentMessage = new ChatMessage(
|
|
795
|
+
this.state.currentMessage.message,
|
|
796
|
+
"user"
|
|
797
|
+
);
|
|
798
|
+
this.state.currentMessage.message = "";
|
|
799
|
+
const submitMessage = this.state.currentMessage;
|
|
800
|
+
this.state.currentMessage = currentMessage;
|
|
801
|
+
await this.handleSubmit({
|
|
802
|
+
message: submitMessage,
|
|
803
|
+
eraseCurrentMessage: false
|
|
804
|
+
});
|
|
805
|
+
}).finally(() => {
|
|
806
|
+
this.state.isLoading = false;
|
|
807
|
+
});
|
|
808
|
+
},
|
|
809
|
+
stop: async () => {
|
|
810
|
+
this.internalAudioRecorder.stop();
|
|
811
|
+
},
|
|
812
|
+
record: 0,
|
|
813
|
+
state: this.internalAudioRecorder.state
|
|
814
|
+
});
|
|
815
|
+
__publicField$6(this, "handleSubmit", async (props) => {
|
|
816
|
+
if (!this.audioRecorder.state.recording) {
|
|
817
|
+
const currentMessage = props?.message || this.state.currentMessage;
|
|
818
|
+
if (currentMessage.message || currentMessage.attachments.length > 0) {
|
|
819
|
+
this.state.isLoading = true;
|
|
820
|
+
if (props?.eraseCurrentMessage !== false) {
|
|
821
|
+
this.state.currentMessage = new ChatMessage("", "user");
|
|
822
|
+
}
|
|
823
|
+
await this.onMessageSubmit({
|
|
824
|
+
message: currentMessage,
|
|
825
|
+
...this.getAdditionalProps()
|
|
826
|
+
});
|
|
827
|
+
this.state.isLoading = false;
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
});
|
|
831
|
+
__publicField$6(this, "History", observer(() => /* @__PURE__ */ jsx(
|
|
832
|
+
History,
|
|
833
|
+
{
|
|
834
|
+
messages: this.state.messages,
|
|
835
|
+
className: this.classNames?.history
|
|
836
|
+
}
|
|
837
|
+
)));
|
|
838
|
+
__publicField$6(this, "Attachments", observer(() => /* @__PURE__ */ jsx(
|
|
839
|
+
Attachments,
|
|
840
|
+
{
|
|
841
|
+
attachments: this.state.currentMessage.attachments,
|
|
842
|
+
onRemove: (a) => {
|
|
843
|
+
this.removeAttachment(a);
|
|
844
|
+
},
|
|
845
|
+
className: this.classNames?.attachments,
|
|
846
|
+
onAddDescription: (a, ev) => this.state.currentMessage.addAttachmentDescription(a, ev)
|
|
847
|
+
}
|
|
848
|
+
)));
|
|
849
|
+
__publicField$6(this, "TextArea", observer(() => /* @__PURE__ */ jsx(
|
|
850
|
+
TextArea,
|
|
851
|
+
{
|
|
852
|
+
additionalOptions: this.additionalOptions,
|
|
853
|
+
className: this.classNames?.textarea,
|
|
854
|
+
value: this.state.currentMessage.message,
|
|
855
|
+
isLoading: this.state.isLoading,
|
|
856
|
+
isRecording: this.internalAudioRecorder.state.recording,
|
|
857
|
+
disablePrevButton: !this.canGoPrev(),
|
|
858
|
+
disableNextButton: !this.canGoNext(),
|
|
859
|
+
onChange: (ev) => {
|
|
860
|
+
this.state.currentMessage.message = ev;
|
|
861
|
+
},
|
|
862
|
+
onSubmit: () => this.handleSubmit(),
|
|
863
|
+
onClearHistory: () => {
|
|
864
|
+
this.clearHistory();
|
|
865
|
+
},
|
|
866
|
+
onAttach: async (ev) => {
|
|
867
|
+
this.state.currentMessage.attachments.push({
|
|
868
|
+
...ev,
|
|
869
|
+
id: String(this.maxId++)
|
|
870
|
+
});
|
|
871
|
+
},
|
|
872
|
+
onRecord: () => {
|
|
873
|
+
!this.internalAudioRecorder.state.recording ? this.audioRecorder.start() : this.audioRecorder.stop();
|
|
874
|
+
},
|
|
875
|
+
onRecordCancel: async () => {
|
|
876
|
+
if (this.internalAudioRecorder.state.recording) {
|
|
877
|
+
this.audioRecorder.cancelOnStop = true;
|
|
878
|
+
await this.audioRecorder.stop();
|
|
879
|
+
}
|
|
880
|
+
},
|
|
881
|
+
onVideoRecord: async () => {
|
|
882
|
+
!this.internalCameraRecorder.state.isOpen && await this.internalCameraRecorder.openCamera();
|
|
883
|
+
await new Promise((resolve, _) => {
|
|
884
|
+
const checkCapture = async () => {
|
|
885
|
+
if (!this.internalCameraRecorder.state.isOpen) {
|
|
886
|
+
const capture = this.internalCameraRecorder.pop();
|
|
887
|
+
if (capture) {
|
|
888
|
+
this.state.currentMessage.attachments.push({
|
|
889
|
+
id: String(this.maxId++),
|
|
890
|
+
name: capture.name,
|
|
891
|
+
base64: await getBase64FromFile(capture)
|
|
892
|
+
});
|
|
893
|
+
return resolve();
|
|
894
|
+
}
|
|
895
|
+
} else {
|
|
896
|
+
requestAnimationFrame(checkCapture);
|
|
897
|
+
}
|
|
898
|
+
};
|
|
899
|
+
checkCapture();
|
|
900
|
+
});
|
|
901
|
+
},
|
|
902
|
+
onPrev: () => {
|
|
903
|
+
this.prevMessage();
|
|
904
|
+
},
|
|
905
|
+
onNext: () => {
|
|
906
|
+
this.nextMessage();
|
|
907
|
+
},
|
|
908
|
+
attachments: this.state.currentMessage.attachments
|
|
909
|
+
}
|
|
910
|
+
)));
|
|
911
|
+
__publicField$6(this, "Renderer", () => /* @__PURE__ */ jsxs(
|
|
912
|
+
Box,
|
|
913
|
+
{
|
|
914
|
+
...getVariant("layout.common.chat.controller"),
|
|
915
|
+
className: "chat_controller",
|
|
916
|
+
children: [
|
|
917
|
+
/* @__PURE__ */ jsx(this.History, {}),
|
|
918
|
+
/* @__PURE__ */ jsx(this.Attachments, {}),
|
|
919
|
+
/* @__PURE__ */ jsx(this.TextArea, {})
|
|
920
|
+
]
|
|
921
|
+
}
|
|
922
|
+
));
|
|
923
|
+
this.state = Object.assign({}, this.state, props);
|
|
924
|
+
makeObservable(this, { state: observable });
|
|
925
|
+
}
|
|
926
|
+
removeMessage(idx) {
|
|
927
|
+
this.state.messages = this.state.messages.filter((_, i) => i !== idx);
|
|
928
|
+
}
|
|
929
|
+
addMessage(message) {
|
|
930
|
+
this.state.messages.push(message);
|
|
931
|
+
this.currentIndex = this.state.messages.length;
|
|
932
|
+
}
|
|
933
|
+
clearHistory() {
|
|
934
|
+
this.state.messages = [];
|
|
935
|
+
this.onClearHistory && this.onClearHistory();
|
|
936
|
+
}
|
|
937
|
+
clearMessage() {
|
|
938
|
+
this.state.currentMessage = new ChatMessage("", "user");
|
|
939
|
+
}
|
|
940
|
+
removeAttachment(attachment) {
|
|
941
|
+
this.state.currentMessage.removeAttachment(attachment);
|
|
942
|
+
}
|
|
943
|
+
isForHistory(message) {
|
|
944
|
+
return message && message.messageType === "user";
|
|
945
|
+
}
|
|
946
|
+
canGoNext() {
|
|
947
|
+
let condition = false;
|
|
948
|
+
const slice = this.state.messages.slice(
|
|
949
|
+
this.currentIndex,
|
|
950
|
+
this.state.messages.length
|
|
951
|
+
);
|
|
952
|
+
const n = slice.length;
|
|
953
|
+
if (this.currentIndex + 1 > n) {
|
|
954
|
+
return condition;
|
|
955
|
+
}
|
|
956
|
+
for (let i = 0; i < n && !condition; i++) {
|
|
957
|
+
const current = slice[i];
|
|
958
|
+
condition = current.messageType === "user";
|
|
959
|
+
}
|
|
960
|
+
return condition;
|
|
961
|
+
}
|
|
962
|
+
canGoPrev() {
|
|
963
|
+
let condition = false;
|
|
964
|
+
if (this.currentIndex - 1 === -1) {
|
|
965
|
+
return condition;
|
|
966
|
+
}
|
|
967
|
+
for (let i = this.state.messages.slice(0, this.currentIndex).length - 1; i >= 0 && !condition; i--) {
|
|
968
|
+
const current = this.state.messages[i];
|
|
969
|
+
condition = current.messageType === "user";
|
|
970
|
+
}
|
|
971
|
+
return condition;
|
|
972
|
+
}
|
|
973
|
+
nextMessage() {
|
|
974
|
+
let newCurrentMessage = void 0;
|
|
975
|
+
let i = this.currentIndex;
|
|
976
|
+
const n = this.state.messages.length;
|
|
977
|
+
if (n === 0 || n - 1 === i) {
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
while (!newCurrentMessage && i < n - 1) {
|
|
981
|
+
newCurrentMessage = this.state.messages[i + 1];
|
|
982
|
+
i++;
|
|
983
|
+
if (this.isForHistory(newCurrentMessage)) {
|
|
984
|
+
this.state.currentMessage = newCurrentMessage.clone();
|
|
985
|
+
break;
|
|
986
|
+
} else {
|
|
987
|
+
newCurrentMessage = void 0;
|
|
988
|
+
}
|
|
989
|
+
if (i === this.currentIndex) {
|
|
990
|
+
break;
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
this.currentIndex = i;
|
|
994
|
+
}
|
|
995
|
+
prevMessage() {
|
|
996
|
+
let newCurrentMessage = void 0;
|
|
997
|
+
let i = this.currentIndex;
|
|
998
|
+
const n = this.state.messages.length;
|
|
999
|
+
if (n === 0 || i === 0) {
|
|
1000
|
+
return;
|
|
1001
|
+
}
|
|
1002
|
+
while (!newCurrentMessage && i > 0) {
|
|
1003
|
+
newCurrentMessage = this.state.messages[i - 1];
|
|
1004
|
+
i--;
|
|
1005
|
+
if (this.isForHistory(newCurrentMessage)) {
|
|
1006
|
+
this.state.currentMessage = newCurrentMessage.clone();
|
|
1007
|
+
break;
|
|
1008
|
+
} else {
|
|
1009
|
+
newCurrentMessage = void 0;
|
|
1010
|
+
}
|
|
1011
|
+
if (i === this.currentIndex) {
|
|
1012
|
+
break;
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
this.currentIndex = i;
|
|
1016
|
+
}
|
|
1017
|
+
getAdditionalProps() {
|
|
1018
|
+
return {};
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
var __defProp$5 = Object.defineProperty;
|
|
1023
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1024
|
+
var __publicField$5 = (obj, key, value) => {
|
|
1025
|
+
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1026
|
+
return value;
|
|
1027
|
+
};
|
|
1028
|
+
class FloatingChatController extends ChatController {
|
|
1029
|
+
constructor(props) {
|
|
1030
|
+
super(
|
|
1031
|
+
{ isWindowOpen: false, ...props },
|
|
1032
|
+
props.onMessageSubmit,
|
|
1033
|
+
props.onClearHistory,
|
|
1034
|
+
props.additionalOptions,
|
|
1035
|
+
props.classNames
|
|
1036
|
+
);
|
|
1037
|
+
__publicField$5(this, "modalTitle");
|
|
1038
|
+
__publicField$5(this, "Window", observer(() => {
|
|
1039
|
+
return this.state.isWindowOpen ? null : /* @__PURE__ */ jsx(
|
|
1040
|
+
IconButton,
|
|
1041
|
+
{
|
|
1042
|
+
className: "chat_controller__open",
|
|
1043
|
+
icon: "Magic",
|
|
1044
|
+
size: "Md",
|
|
1045
|
+
variant: "icon-outline",
|
|
1046
|
+
onClick: () => {
|
|
1047
|
+
this.open();
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
);
|
|
1051
|
+
}));
|
|
1052
|
+
this.modalTitle = props.modalTitle;
|
|
1053
|
+
makeObservable({ open: action });
|
|
1054
|
+
if (props.props.isWindowOpen) {
|
|
1055
|
+
this.state.isWindowOpen = false;
|
|
1056
|
+
this.open();
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
getModalTitle() {
|
|
1060
|
+
return this.modalTitle;
|
|
1061
|
+
}
|
|
1062
|
+
setModalTitle(title) {
|
|
1063
|
+
this.modalTitle = title;
|
|
1064
|
+
}
|
|
1065
|
+
open() {
|
|
1066
|
+
if (!this.state.isWindowOpen) {
|
|
1067
|
+
this.state.isWindowOpen = true;
|
|
1068
|
+
ApiaUtil.instance.modals.open({
|
|
1069
|
+
variant: "layout.common.chat.assistant.floatingAssistant",
|
|
1070
|
+
defaultPosition: {
|
|
1071
|
+
bottom: "10px",
|
|
1072
|
+
right: "10px"
|
|
1073
|
+
},
|
|
1074
|
+
id: "floatingAssistant",
|
|
1075
|
+
draggable: true,
|
|
1076
|
+
dragBounded: true,
|
|
1077
|
+
children: /* @__PURE__ */ jsx(this.Renderer, {}),
|
|
1078
|
+
onClose: () => {
|
|
1079
|
+
this.state.isWindowOpen = false;
|
|
1080
|
+
},
|
|
1081
|
+
title: this.modalTitle
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
var __defProp$4 = Object.defineProperty;
|
|
1088
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1089
|
+
var __publicField$4 = (obj, key, value) => {
|
|
1090
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1091
|
+
return value;
|
|
1092
|
+
};
|
|
1093
|
+
class StreamMessage {
|
|
1094
|
+
constructor() {
|
|
1095
|
+
__publicField$4(this, "blocks", []);
|
|
1096
|
+
__publicField$4(this, "references", []);
|
|
1097
|
+
__publicField$4(this, "tables", {});
|
|
1098
|
+
__publicField$4(this, "charts", {});
|
|
1099
|
+
makeObservable(this, {
|
|
1100
|
+
references: observable,
|
|
1101
|
+
blocks: observable,
|
|
1102
|
+
tables: observable,
|
|
1103
|
+
charts: observable
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
addPart(part, afterAddPart) {
|
|
1107
|
+
if (this.blocks.length > 0 && this.blocks[this.blocks.length - 1].blockType === "text" && part.blockType === "text") {
|
|
1108
|
+
const aux = this.blocks[this.blocks.length - 1];
|
|
1109
|
+
if (aux !== part) {
|
|
1110
|
+
aux.str += part.str;
|
|
1111
|
+
}
|
|
1112
|
+
} else {
|
|
1113
|
+
this.blocks.push(part);
|
|
1114
|
+
}
|
|
1115
|
+
afterAddPart && afterAddPart(part);
|
|
1116
|
+
}
|
|
1117
|
+
getLastBlock() {
|
|
1118
|
+
return this.blocks[this.blocks.length - 1];
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
const Ellipsis = () => {
|
|
1123
|
+
const [e, setE] = useState(0);
|
|
1124
|
+
let dots = ".";
|
|
1125
|
+
for (let i = 0; i < e; i++) {
|
|
1126
|
+
dots += ".";
|
|
1127
|
+
}
|
|
1128
|
+
const interval = useRef(0);
|
|
1129
|
+
useEffect(() => {
|
|
1130
|
+
interval.current = setInterval(() => {
|
|
1131
|
+
setE((e2) => e2 === 2 ? 0 : e2 + 1);
|
|
1132
|
+
}, 500);
|
|
1133
|
+
return () => {
|
|
1134
|
+
clearInterval(interval.current);
|
|
1135
|
+
};
|
|
1136
|
+
});
|
|
1137
|
+
return /* @__PURE__ */ jsx("div", { className: "ellipsis", children: dots });
|
|
1138
|
+
};
|
|
1139
|
+
|
|
1140
|
+
const Header = observer(
|
|
1141
|
+
({ childComponent }) => {
|
|
1142
|
+
return /* @__PURE__ */ jsx(Box, { className: "search_header_container", children: childComponent });
|
|
1143
|
+
}
|
|
1144
|
+
);
|
|
1145
|
+
|
|
1146
|
+
async function rate(el, how, query) {
|
|
1147
|
+
return new Promise((resolve) => {
|
|
1148
|
+
const collector = new Collector();
|
|
1149
|
+
collector.add(
|
|
1150
|
+
new collector.fields.textarea("comment", "Comment", {
|
|
1151
|
+
validationRules: { required: true },
|
|
1152
|
+
properties: { autoFocus: true }
|
|
1153
|
+
})
|
|
1154
|
+
);
|
|
1155
|
+
const tooltip = ApiaUtil.instance.tooltips.open({
|
|
1156
|
+
attachToElement: { current: el },
|
|
1157
|
+
children: /* @__PURE__ */ jsx(
|
|
1158
|
+
collector.Render,
|
|
1159
|
+
{
|
|
1160
|
+
sx: {
|
|
1161
|
+
width: "300px",
|
|
1162
|
+
minWidth: "unset",
|
|
1163
|
+
".collector__buttons button": {
|
|
1164
|
+
fontSize: 14,
|
|
1165
|
+
py: 2,
|
|
1166
|
+
px: 3
|
|
1167
|
+
}
|
|
1168
|
+
},
|
|
1169
|
+
resolve: (w) => {
|
|
1170
|
+
(async () => {
|
|
1171
|
+
const result = await ApiaApi.post(
|
|
1172
|
+
makeApiaUrl({ action: "giveFeedback" }),
|
|
1173
|
+
{
|
|
1174
|
+
postData: {
|
|
1175
|
+
query,
|
|
1176
|
+
feedback: w.comment,
|
|
1177
|
+
positive: how === "up"
|
|
1178
|
+
},
|
|
1179
|
+
postDataTreatement: "stringify"
|
|
1180
|
+
}
|
|
1181
|
+
);
|
|
1182
|
+
tooltip.close();
|
|
1183
|
+
resolve(!result?.hasError && !result?.hasMessages);
|
|
1184
|
+
})();
|
|
1185
|
+
return true;
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
),
|
|
1189
|
+
minSize: {
|
|
1190
|
+
width: 300,
|
|
1191
|
+
height: 220
|
|
1192
|
+
},
|
|
1193
|
+
preferredOrientationX: "right",
|
|
1194
|
+
preferredOrientationY: "top",
|
|
1195
|
+
closeOnMouseLeaveAttachedElement: false,
|
|
1196
|
+
closeOnMouseLeaveTooltip: false,
|
|
1197
|
+
closeOnClickOut: true,
|
|
1198
|
+
closeOnClick: false,
|
|
1199
|
+
closeOnEscape: true,
|
|
1200
|
+
closeOnScrollOut: true,
|
|
1201
|
+
closeOthers: true,
|
|
1202
|
+
attachToElementAnchorPoint: "topRight"
|
|
1203
|
+
});
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
const MessageBody = observer(
|
|
1208
|
+
({
|
|
1209
|
+
onRate,
|
|
1210
|
+
store
|
|
1211
|
+
}) => {
|
|
1212
|
+
const [thumb, setThumb] = useState(void 0);
|
|
1213
|
+
const hasText = store.blocks.find((x) => x.blockType === "text");
|
|
1214
|
+
return /* @__PURE__ */ jsxs(Box, { className: "sem_search__system_message", children: [
|
|
1215
|
+
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1216
|
+
/* @__PURE__ */ jsx(Box, { className: "message__body markdown", children: /* @__PURE__ */ jsx(MessageBlocks, { streamParts: store.blocks }) }),
|
|
1217
|
+
onRate && hasText ? /* @__PURE__ */ jsxs(Box, { className: "sem_search__thumbs", children: [
|
|
1218
|
+
/* @__PURE__ */ jsx(
|
|
1219
|
+
IconButton,
|
|
1220
|
+
{
|
|
1221
|
+
variant: "icon-only",
|
|
1222
|
+
icon: "ThumbsUp",
|
|
1223
|
+
className: thumb === "up" ? "selected" : thumb === "down" ? "unselected" : "no_feedback",
|
|
1224
|
+
onClick: (ev) => onRate(ev.target, "up").then((res) => {
|
|
1225
|
+
if (res) {
|
|
1226
|
+
setThumb("up");
|
|
1227
|
+
}
|
|
1228
|
+
})
|
|
1229
|
+
}
|
|
1230
|
+
),
|
|
1231
|
+
/* @__PURE__ */ jsx(
|
|
1232
|
+
IconButton,
|
|
1233
|
+
{
|
|
1234
|
+
variant: "icon-only",
|
|
1235
|
+
icon: "ThumbsDown",
|
|
1236
|
+
className: thumb === "down" ? "selected" : thumb === "up" ? "unselected" : "no_feedback",
|
|
1237
|
+
onClick: (ev) => onRate(ev.target, "down").then((res) => {
|
|
1238
|
+
if (res) {
|
|
1239
|
+
setThumb("down");
|
|
1240
|
+
}
|
|
1241
|
+
})
|
|
1242
|
+
}
|
|
1243
|
+
)
|
|
1244
|
+
] }) : /* @__PURE__ */ jsx(Fragment, {})
|
|
1245
|
+
] }),
|
|
1246
|
+
!hasText && /* @__PURE__ */ jsx(Ellipsis, {})
|
|
1247
|
+
] });
|
|
1248
|
+
}
|
|
1249
|
+
);
|
|
1250
|
+
|
|
1251
|
+
class MultipleChoiceMessage extends ChatMessage {
|
|
1252
|
+
constructor(question, options, Renderer) {
|
|
1253
|
+
super(
|
|
1254
|
+
Renderer ? /* @__PURE__ */ jsxs(Box, { className: "multipleChoiceMessage customRenderer", children: [
|
|
1255
|
+
/* @__PURE__ */ jsx(Paragraph, { children: question }),
|
|
1256
|
+
options.map((item) => /* @__PURE__ */ jsx(Renderer, { item }, item.url))
|
|
1257
|
+
] }) : /* @__PURE__ */ jsxs(Box, { className: "multipleChoiceMessage", children: [
|
|
1258
|
+
/* @__PURE__ */ jsx(Paragraph, { children: question }),
|
|
1259
|
+
/* @__PURE__ */ jsx(Box, { as: "ul", children: options.map((current) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(
|
|
1260
|
+
SimpleButton,
|
|
1261
|
+
{
|
|
1262
|
+
className: "multipleChoice__option",
|
|
1263
|
+
onClick: () => {
|
|
1264
|
+
ApiaUtil.instance.tabs.openTab(current.label, current.url);
|
|
1265
|
+
},
|
|
1266
|
+
children: current.label
|
|
1267
|
+
}
|
|
1268
|
+
) }, current.label)) })
|
|
1269
|
+
] }),
|
|
1270
|
+
"multipleChoice"
|
|
1271
|
+
);
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
var __defProp$3 = Object.defineProperty;
|
|
1276
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1277
|
+
var __publicField$3 = (obj, key, value) => {
|
|
1278
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
93
1279
|
return value;
|
|
94
1280
|
};
|
|
95
1281
|
function isPollProgress(payload) {
|
|
@@ -97,9 +1283,9 @@ function isPollProgress(payload) {
|
|
|
97
1283
|
}
|
|
98
1284
|
class RoutinesGeneration {
|
|
99
1285
|
constructor() {
|
|
100
|
-
__publicField$
|
|
101
|
-
__publicField$
|
|
102
|
-
__publicField$
|
|
1286
|
+
__publicField$3(this, "audioRecorder", new AudioRecorder());
|
|
1287
|
+
__publicField$3(this, "routineId", "");
|
|
1288
|
+
__publicField$3(this, "state", {
|
|
103
1289
|
isLoading: false,
|
|
104
1290
|
progress: 0
|
|
105
1291
|
});
|
|
@@ -303,25 +1489,25 @@ class DashboardsRoutinesGeneration extends RoutinesGeneration {
|
|
|
303
1489
|
}
|
|
304
1490
|
}
|
|
305
1491
|
|
|
306
|
-
var __defProp$
|
|
307
|
-
var __defNormalProp$
|
|
308
|
-
var __publicField$
|
|
309
|
-
__defNormalProp$
|
|
1492
|
+
var __defProp$2 = Object.defineProperty;
|
|
1493
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1494
|
+
var __publicField$2 = (obj, key, value) => {
|
|
1495
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
310
1496
|
return value;
|
|
311
1497
|
};
|
|
312
1498
|
class ResponseStream extends EventEmitter {
|
|
313
1499
|
constructor() {
|
|
314
1500
|
super(...arguments);
|
|
315
|
-
__publicField$
|
|
316
|
-
__publicField$
|
|
317
|
-
__publicField$
|
|
318
|
-
__publicField$
|
|
1501
|
+
__publicField$2(this, "buffer", "");
|
|
1502
|
+
__publicField$2(this, "isRunning", false);
|
|
1503
|
+
__publicField$2(this, "locked", false);
|
|
1504
|
+
__publicField$2(this, "maxCompletionTime", 150);
|
|
319
1505
|
// ms
|
|
320
|
-
__publicField$
|
|
321
|
-
__publicField$
|
|
322
|
-
__publicField$
|
|
1506
|
+
__publicField$2(this, "minPartSize", 2);
|
|
1507
|
+
__publicField$2(this, "partSize", 2);
|
|
1508
|
+
__publicField$2(this, "timing", 5);
|
|
323
1509
|
// ms
|
|
324
|
-
__publicField$
|
|
1510
|
+
__publicField$2(this, "waiting", []);
|
|
325
1511
|
}
|
|
326
1512
|
calculatePartSize() {
|
|
327
1513
|
const totalSize = this.buffer.length + this.waiting.reduce((a, b) => a + b.length, 0);
|
|
@@ -438,17 +1624,17 @@ function getSrcFromBase64(base64) {
|
|
|
438
1624
|
return `data:image/jpg;base64,${base64}`;
|
|
439
1625
|
}
|
|
440
1626
|
|
|
441
|
-
var __defProp = Object.defineProperty;
|
|
442
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
443
|
-
var __publicField = (obj, key, value) => {
|
|
444
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1627
|
+
var __defProp$1 = Object.defineProperty;
|
|
1628
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1629
|
+
var __publicField$1 = (obj, key, value) => {
|
|
1630
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
445
1631
|
return value;
|
|
446
1632
|
};
|
|
447
1633
|
class ImagesStore {
|
|
448
1634
|
constructor(images, multiple) {
|
|
449
1635
|
this.multiple = multiple;
|
|
450
|
-
__publicField(this, "images", /* @__PURE__ */ new Map());
|
|
451
|
-
__publicField(this, "selectedId", "");
|
|
1636
|
+
__publicField$1(this, "images", /* @__PURE__ */ new Map());
|
|
1637
|
+
__publicField$1(this, "selectedId", "");
|
|
452
1638
|
this.images = new Map(
|
|
453
1639
|
images.map((c) => {
|
|
454
1640
|
const id = uniqueId();
|
|
@@ -578,29 +1764,51 @@ const ViewRendererContext = createContext(
|
|
|
578
1764
|
{}
|
|
579
1765
|
);
|
|
580
1766
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
1767
|
+
var __defProp = Object.defineProperty;
|
|
1768
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1769
|
+
var __publicField = (obj, key, value) => {
|
|
1770
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1771
|
+
return value;
|
|
1772
|
+
};
|
|
1773
|
+
class StreamServicePoller {
|
|
1774
|
+
constructor() {
|
|
1775
|
+
__publicField(this, "closed", true);
|
|
1776
|
+
__publicField(this, "stream", new ResponseStream());
|
|
1777
|
+
}
|
|
1778
|
+
on(ev, cb) {
|
|
1779
|
+
return this.stream.on(ev, cb);
|
|
1780
|
+
}
|
|
1781
|
+
async start(token) {
|
|
1782
|
+
this.closed = false;
|
|
1783
|
+
try {
|
|
1784
|
+
while (!this.closed) {
|
|
1785
|
+
const res = await ApiaApi.post(
|
|
1786
|
+
makeApiaUrl({
|
|
1787
|
+
ajaxUrl: "apia.execution.StreamAction.run",
|
|
1788
|
+
action: "poll",
|
|
1789
|
+
streamToken: token
|
|
1790
|
+
})
|
|
1791
|
+
);
|
|
1792
|
+
if (!res) {
|
|
1793
|
+
this.closed = true;
|
|
1794
|
+
this.stream.emit("error", null);
|
|
1795
|
+
}
|
|
1796
|
+
if (res?.data?.part) {
|
|
1797
|
+
this.stream.emit("part", decodeBase64ToUtf8(res.data.part));
|
|
1798
|
+
}
|
|
1799
|
+
if (res?.data?.closed === "true") {
|
|
1800
|
+
this.closed = true;
|
|
1801
|
+
this.stream.emit("close", null);
|
|
1802
|
+
}
|
|
1803
|
+
if (res?.data?.failed === "true") {
|
|
1804
|
+
this.stream.emit("error", null);
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
} finally {
|
|
1808
|
+
this.closed = true;
|
|
1809
|
+
}
|
|
602
1810
|
}
|
|
603
1811
|
}
|
|
604
1812
|
|
|
605
|
-
export { DashboardsRoutinesGeneration, MultipleChoiceMessage, ResponseStream, RoutinesGeneration, SearchController, SemanticSearchReference as SemanticSearchResult, ViewRendererContext, getImageFromDisk, getImagesFromDisk, getImagesWithDescription };
|
|
1813
|
+
export { Attachments, AutoscrollContainer, CameraController, ChatController, ChatMessage, DashboardsRoutinesGeneration, Ellipsis, FloatingChatController, Header, History, Message, MessageBlock, MessageBlocks, MessageBody, MultipleChoiceMessage, ResponseStream, RoutinesGeneration, SearchController, SemanticSearchReference as SemanticSearchResult, StreamMessage, StreamServicePoller, TextArea, ViewRendererContext, getImageFromDisk, getImagesFromDisk, getImagesWithDescription, rate };
|
|
606
1814
|
//# sourceMappingURL=index.js.map
|