@apia/ai 4.0.13 → 4.0.15
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 +11 -2
- package/dist/index.js +724 -685
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -193,10 +193,10 @@ 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$c = Object.defineProperty;
|
|
197
|
+
var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
198
|
+
var __publicField$c = (obj, key, value) => {
|
|
199
|
+
__defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
200
200
|
return value;
|
|
201
201
|
};
|
|
202
202
|
let maxId = 0;
|
|
@@ -206,14 +206,14 @@ class ChatMessage {
|
|
|
206
206
|
this.messageType = messageType;
|
|
207
207
|
this.attachments = attachments;
|
|
208
208
|
this.reference = reference;
|
|
209
|
-
__publicField$
|
|
210
|
-
__publicField$
|
|
209
|
+
__publicField$c(this, "id");
|
|
210
|
+
__publicField$c(this, "clone", () => new ChatMessage(
|
|
211
211
|
this.message,
|
|
212
212
|
this.messageType,
|
|
213
|
-
this.attachments,
|
|
213
|
+
[...this.attachments],
|
|
214
214
|
this.reference
|
|
215
215
|
));
|
|
216
|
-
__publicField$
|
|
216
|
+
__publicField$c(this, "Component", observer(({ className }) => {
|
|
217
217
|
return /* @__PURE__ */ jsxs(
|
|
218
218
|
Box,
|
|
219
219
|
{
|
|
@@ -260,18 +260,18 @@ class ChatMessage {
|
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
-
var __defProp$
|
|
264
|
-
var __defNormalProp$
|
|
265
|
-
var __publicField$
|
|
266
|
-
__defNormalProp$
|
|
263
|
+
var __defProp$b = Object.defineProperty;
|
|
264
|
+
var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
265
|
+
var __publicField$b = (obj, key, value) => {
|
|
266
|
+
__defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
267
267
|
return value;
|
|
268
268
|
};
|
|
269
269
|
class AIContent extends CollectorField {
|
|
270
270
|
constructor(content) {
|
|
271
271
|
super(uniqueId(), "");
|
|
272
|
-
__publicField$
|
|
273
|
-
__publicField$
|
|
274
|
-
__publicField$
|
|
272
|
+
__publicField$b(this, "type", "aiContent");
|
|
273
|
+
__publicField$b(this, "content");
|
|
274
|
+
__publicField$b(this, "Component", () => {
|
|
275
275
|
return /* @__PURE__ */ jsx(Box, { variant: "layout.common.components.aiMessage.textBox", children: /* @__PURE__ */ jsx(Box, { variant: "layout.common.components.aiMessage.textSnippet", children: this.content }) });
|
|
276
276
|
});
|
|
277
277
|
this.content = content;
|
|
@@ -306,10 +306,10 @@ var AIMessageRole = /* @__PURE__ */ ((AIMessageRole2) => {
|
|
|
306
306
|
return AIMessageRole2;
|
|
307
307
|
})(AIMessageRole || {});
|
|
308
308
|
|
|
309
|
-
var __defProp$
|
|
310
|
-
var __defNormalProp$
|
|
311
|
-
var __publicField$
|
|
312
|
-
__defNormalProp$
|
|
309
|
+
var __defProp$a = Object.defineProperty;
|
|
310
|
+
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
311
|
+
var __publicField$a = (obj, key, value) => {
|
|
312
|
+
__defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
313
313
|
return value;
|
|
314
314
|
};
|
|
315
315
|
const _AIFileContent = class _AIFileContent extends AIContent {
|
|
@@ -319,19 +319,19 @@ const _AIFileContent = class _AIFileContent extends AIContent {
|
|
|
319
319
|
}
|
|
320
320
|
const extension = _AIFileContent.getExtensionFromFileName(props.name);
|
|
321
321
|
super();
|
|
322
|
-
__publicField$
|
|
323
|
-
__publicField$
|
|
324
|
-
__publicField$
|
|
325
|
-
__publicField$
|
|
326
|
-
__publicField$
|
|
327
|
-
__publicField$
|
|
328
|
-
__publicField$
|
|
329
|
-
__publicField$
|
|
330
|
-
__publicField$
|
|
331
|
-
__publicField$
|
|
322
|
+
__publicField$a(this, "type");
|
|
323
|
+
__publicField$a(this, "value");
|
|
324
|
+
__publicField$a(this, "name");
|
|
325
|
+
__publicField$a(this, "extension");
|
|
326
|
+
__publicField$a(this, "__file");
|
|
327
|
+
__publicField$a(this, "__error");
|
|
328
|
+
__publicField$a(this, "onClose");
|
|
329
|
+
__publicField$a(this, "overrideSize");
|
|
330
|
+
__publicField$a(this, "id", uniqueId());
|
|
331
|
+
__publicField$a(this, "inferContent", () => {
|
|
332
332
|
return `You must collect information contained in this ${this.type} as help to build your tool choice.`;
|
|
333
333
|
});
|
|
334
|
-
__publicField$
|
|
334
|
+
__publicField$a(this, "inferExtension", (extension) => {
|
|
335
335
|
switch (extension) {
|
|
336
336
|
case AIFileContentAllowedExtensions.jpg:
|
|
337
337
|
case AIFileContentAllowedExtensions.jpeg:
|
|
@@ -358,7 +358,7 @@ const _AIFileContent = class _AIFileContent extends AIContent {
|
|
|
358
358
|
}
|
|
359
359
|
});
|
|
360
360
|
// COMPONENT METHODS
|
|
361
|
-
__publicField$
|
|
361
|
+
__publicField$a(this, "Component", () => {
|
|
362
362
|
const closeButton = this.onClose ? /* @__PURE__ */ jsx(
|
|
363
363
|
IconButton,
|
|
364
364
|
{
|
|
@@ -444,12 +444,12 @@ ${Object.keys(AIFileContentAllowedExtensions)}`;
|
|
|
444
444
|
}
|
|
445
445
|
};
|
|
446
446
|
// STATIC METHODS
|
|
447
|
-
__publicField$
|
|
447
|
+
__publicField$a(_AIFileContent, "isValidExtension", (extension) => {
|
|
448
448
|
return Object.values(
|
|
449
449
|
AIFileContentAllowedExtensions
|
|
450
450
|
).includes(extension);
|
|
451
451
|
});
|
|
452
|
-
__publicField$
|
|
452
|
+
__publicField$a(_AIFileContent, "blobToBase64", async (blob) => {
|
|
453
453
|
return await ((blob2) => new Promise((resolve, reject) => {
|
|
454
454
|
const reader = new FileReader();
|
|
455
455
|
reader.onloadend = () => {
|
|
@@ -460,7 +460,7 @@ __publicField$9(_AIFileContent, "blobToBase64", async (blob) => {
|
|
|
460
460
|
reader.readAsDataURL(blob2);
|
|
461
461
|
}))(blob);
|
|
462
462
|
});
|
|
463
|
-
__publicField$
|
|
463
|
+
__publicField$a(_AIFileContent, "fromFile", async (props) => {
|
|
464
464
|
const fileUrl = await ((f) => new Promise((resolve, reject) => {
|
|
465
465
|
const reader = new FileReader();
|
|
466
466
|
reader.readAsDataURL(f);
|
|
@@ -477,20 +477,20 @@ __publicField$9(_AIFileContent, "fromFile", async (props) => {
|
|
|
477
477
|
});
|
|
478
478
|
let AIFileContent = _AIFileContent;
|
|
479
479
|
|
|
480
|
-
var __defProp$
|
|
481
|
-
var __defNormalProp$
|
|
482
|
-
var __publicField$
|
|
483
|
-
__defNormalProp$
|
|
480
|
+
var __defProp$9 = Object.defineProperty;
|
|
481
|
+
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
482
|
+
var __publicField$9 = (obj, key, value) => {
|
|
483
|
+
__defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
484
484
|
return value;
|
|
485
485
|
};
|
|
486
486
|
class AIMessageAttachments {
|
|
487
487
|
constructor(role, content, close) {
|
|
488
488
|
this.close = close;
|
|
489
|
-
__publicField$
|
|
490
|
-
__publicField$
|
|
491
|
-
__publicField$
|
|
492
|
-
__publicField$
|
|
493
|
-
__publicField$
|
|
489
|
+
__publicField$9(this, "role");
|
|
490
|
+
__publicField$9(this, "content");
|
|
491
|
+
__publicField$9(this, "id", uniqueId());
|
|
492
|
+
__publicField$9(this, "customDescription", false);
|
|
493
|
+
__publicField$9(this, "addDescription", async () => {
|
|
494
494
|
const collector = new Collector();
|
|
495
495
|
const collected = await collector.add(this.content).add(
|
|
496
496
|
new collector.fields.textarea(
|
|
@@ -514,7 +514,7 @@ class AIMessageAttachments {
|
|
|
514
514
|
this.customDescription = false;
|
|
515
515
|
}
|
|
516
516
|
});
|
|
517
|
-
__publicField$
|
|
517
|
+
__publicField$9(this, "Component", (props) => /* @__PURE__ */ jsxs(Box, { ...getVariant("layout.common.components.aiMessage"), children: [
|
|
518
518
|
props.closeButton ? /* @__PURE__ */ jsx(
|
|
519
519
|
IconButton,
|
|
520
520
|
{
|
|
@@ -867,10 +867,10 @@ const makeTextarea = (chatController) => {
|
|
|
867
867
|
return NewTextarea;
|
|
868
868
|
};
|
|
869
869
|
|
|
870
|
-
var __defProp$
|
|
871
|
-
var __defNormalProp$
|
|
872
|
-
var __publicField$
|
|
873
|
-
__defNormalProp$
|
|
870
|
+
var __defProp$8 = Object.defineProperty;
|
|
871
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
872
|
+
var __publicField$8 = (obj, key, value) => {
|
|
873
|
+
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
874
874
|
return value;
|
|
875
875
|
};
|
|
876
876
|
var __accessCheck = (obj, member, msg) => {
|
|
@@ -895,11 +895,11 @@ var _promptsHistory, _internalAudioRecorder;
|
|
|
895
895
|
class ChatController {
|
|
896
896
|
constructor(id, welcomeMessage) {
|
|
897
897
|
this.id = id;
|
|
898
|
-
__publicField$
|
|
898
|
+
__publicField$8(this, "state", {
|
|
899
899
|
current: new ChatMessage(),
|
|
900
900
|
messages: []
|
|
901
901
|
});
|
|
902
|
-
__publicField$
|
|
902
|
+
__publicField$8(this, "components", {
|
|
903
903
|
MessageHistory: observer(() => {
|
|
904
904
|
return /* @__PURE__ */ jsx(
|
|
905
905
|
Box,
|
|
@@ -913,9 +913,9 @@ class ChatController {
|
|
|
913
913
|
Textarea: makeTextarea(this)
|
|
914
914
|
});
|
|
915
915
|
__privateAdd(this, _promptsHistory, []);
|
|
916
|
-
__publicField$
|
|
916
|
+
__publicField$8(this, "currentHistoryIndex", -1);
|
|
917
917
|
__privateAdd(this, _internalAudioRecorder, new AudioRecorder());
|
|
918
|
-
__publicField$
|
|
918
|
+
__publicField$8(this, "audioRecorder", {
|
|
919
919
|
start: () => __privateGet(this, _internalAudioRecorder).start().then(async (blob) => {
|
|
920
920
|
const m = new AIMessageAttachments(
|
|
921
921
|
AIMessageRole.USER,
|
|
@@ -933,7 +933,7 @@ class ChatController {
|
|
|
933
933
|
record: 0,
|
|
934
934
|
state: __privateGet(this, _internalAudioRecorder).state
|
|
935
935
|
});
|
|
936
|
-
__publicField$
|
|
936
|
+
__publicField$8(this, "history", {
|
|
937
937
|
add: (message) => {
|
|
938
938
|
this.currentHistoryIndex = -1;
|
|
939
939
|
if (message === __privateGet(this, _promptsHistory)[__privateGet(this, _promptsHistory).length]) {
|
|
@@ -970,7 +970,7 @@ class ChatController {
|
|
|
970
970
|
},
|
|
971
971
|
size: () => this.state.messages.length
|
|
972
972
|
});
|
|
973
|
-
__publicField$
|
|
973
|
+
__publicField$8(this, "messages", {
|
|
974
974
|
add: (message, idx) => {
|
|
975
975
|
if (idx !== void 0 && idx !== null) {
|
|
976
976
|
this.state.messages.splice(idx, 0, message);
|
|
@@ -982,7 +982,7 @@ class ChatController {
|
|
|
982
982
|
this.state.messages = [];
|
|
983
983
|
}
|
|
984
984
|
});
|
|
985
|
-
__publicField$
|
|
985
|
+
__publicField$8(this, "attachments", {
|
|
986
986
|
add: (...aiMessage) => {
|
|
987
987
|
this.state.current.attachments.push(
|
|
988
988
|
...aiMessage
|
|
@@ -1050,16 +1050,16 @@ const Component = observer(
|
|
|
1050
1050
|
}
|
|
1051
1051
|
);
|
|
1052
1052
|
|
|
1053
|
-
var __defProp$
|
|
1054
|
-
var __defNormalProp$
|
|
1055
|
-
var __publicField$
|
|
1056
|
-
__defNormalProp$
|
|
1053
|
+
var __defProp$7 = Object.defineProperty;
|
|
1054
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1055
|
+
var __publicField$7 = (obj, key, value) => {
|
|
1056
|
+
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1057
1057
|
return value;
|
|
1058
1058
|
};
|
|
1059
1059
|
class SemanticSearchReference {
|
|
1060
1060
|
constructor(props) {
|
|
1061
|
-
__publicField$
|
|
1062
|
-
__publicField$
|
|
1061
|
+
__publicField$7(this, "state", { title: "", body: "", link: "" });
|
|
1062
|
+
__publicField$7(this, "Component", () => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1063
1063
|
"(",
|
|
1064
1064
|
/* @__PURE__ */ jsx(Component, { instance: this }),
|
|
1065
1065
|
")"
|
|
@@ -1069,15 +1069,15 @@ class SemanticSearchReference {
|
|
|
1069
1069
|
}
|
|
1070
1070
|
}
|
|
1071
1071
|
|
|
1072
|
-
var __defProp$
|
|
1073
|
-
var __defNormalProp$
|
|
1074
|
-
var __publicField$
|
|
1075
|
-
__defNormalProp$
|
|
1072
|
+
var __defProp$6 = Object.defineProperty;
|
|
1073
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1074
|
+
var __publicField$6 = (obj, key, value) => {
|
|
1075
|
+
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1076
1076
|
return value;
|
|
1077
1077
|
};
|
|
1078
1078
|
const _SearchController = class _SearchController {
|
|
1079
1079
|
constructor() {
|
|
1080
|
-
__publicField$
|
|
1080
|
+
__publicField$6(this, "state", { queryString: "", results: [], isLoading: false, disabled: false });
|
|
1081
1081
|
makeObservable(this, { state: observable });
|
|
1082
1082
|
}
|
|
1083
1083
|
async search(selectedId) {
|
|
@@ -1115,617 +1115,137 @@ const _SearchController = class _SearchController {
|
|
|
1115
1115
|
_SearchController.instance.state.disabled = false;
|
|
1116
1116
|
}
|
|
1117
1117
|
};
|
|
1118
|
-
__publicField$
|
|
1118
|
+
__publicField$6(_SearchController, "instance", new _SearchController());
|
|
1119
1119
|
let SearchController = _SearchController;
|
|
1120
1120
|
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
progress: 0
|
|
1137
|
-
});
|
|
1138
|
-
makeObservable(this, {
|
|
1139
|
-
completion: action,
|
|
1140
|
-
state: observable,
|
|
1141
|
-
stop: action,
|
|
1142
|
-
transcribeAudio: action
|
|
1143
|
-
});
|
|
1144
|
-
}
|
|
1145
|
-
checkCanGenerate() {
|
|
1146
|
-
if (this.state.isLoading) {
|
|
1147
|
-
throw new Error("Cannot queue two simultaneous generations");
|
|
1148
|
-
}
|
|
1149
|
-
this.state.isLoading = true;
|
|
1150
|
-
}
|
|
1151
|
-
async pollRoutine(routineId, stream) {
|
|
1152
|
-
this.routineId = routineId;
|
|
1153
|
-
this.state.isLoading = true;
|
|
1154
|
-
return this.internalPollRoutine(stream);
|
|
1155
|
-
}
|
|
1156
|
-
async internalPollRoutine(stream) {
|
|
1157
|
-
while (this.state.isLoading) {
|
|
1158
|
-
const pollResult = await this.callRoutinePoll(this.routineId);
|
|
1159
|
-
if (isPollProgress(pollResult.payload)) {
|
|
1160
|
-
try {
|
|
1161
|
-
const res = JSON.parse(pollResult.payload.debug);
|
|
1162
|
-
if (res.length > 0) {
|
|
1163
|
-
res.forEach((c) => {
|
|
1164
|
-
console.log(JSON.parse(c));
|
|
1165
|
-
});
|
|
1166
|
-
}
|
|
1167
|
-
if (pollResult.payload.streamPart && stream) {
|
|
1168
|
-
stream.emit("part", pollResult.payload.streamPart);
|
|
1169
|
-
}
|
|
1170
|
-
this.state.progress = pollResult.payload.progress;
|
|
1171
|
-
} catch (e) {
|
|
1172
|
-
console.error(e);
|
|
1121
|
+
const FileAttachment = observer(
|
|
1122
|
+
({
|
|
1123
|
+
attachment,
|
|
1124
|
+
onRemove
|
|
1125
|
+
}) => {
|
|
1126
|
+
return /* @__PURE__ */ jsxs(Box, { className: "file_box", children: [
|
|
1127
|
+
/* @__PURE__ */ jsx(FileIcon, { className: "file_box__icon", docName: attachment.name }),
|
|
1128
|
+
/* @__PURE__ */ jsx(Box, { className: "file_box__name", title: attachment.name, children: attachment.name }),
|
|
1129
|
+
onRemove && /* @__PURE__ */ jsx(
|
|
1130
|
+
IconButton,
|
|
1131
|
+
{
|
|
1132
|
+
icon: "Close",
|
|
1133
|
+
className: "file_box__remove",
|
|
1134
|
+
onClick: onRemove,
|
|
1135
|
+
variant: "icon-only"
|
|
1173
1136
|
}
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
return pollResult.payload;
|
|
1177
|
-
} else if (pollResult.status === "ERROR") {
|
|
1178
|
-
this.resetLoading();
|
|
1179
|
-
throw new Error(pollResult.payload);
|
|
1180
|
-
} else {
|
|
1181
|
-
this.resetLoading();
|
|
1182
|
-
throw new Error("Wrong poll response");
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
return null;
|
|
1137
|
+
)
|
|
1138
|
+
] });
|
|
1186
1139
|
}
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1140
|
+
);
|
|
1141
|
+
|
|
1142
|
+
const Attachments = observer(
|
|
1143
|
+
({
|
|
1144
|
+
attachments,
|
|
1145
|
+
onRemove
|
|
1146
|
+
}) => {
|
|
1147
|
+
if (!attachments.length)
|
|
1148
|
+
return null;
|
|
1149
|
+
return /* @__PURE__ */ jsx(
|
|
1150
|
+
Box,
|
|
1151
|
+
{
|
|
1152
|
+
className: "attachments",
|
|
1153
|
+
...getVariant("layout.common.chat.attachments"),
|
|
1154
|
+
children: attachments.map((x) => /* @__PURE__ */ jsx(
|
|
1155
|
+
FileAttachment,
|
|
1156
|
+
{
|
|
1157
|
+
attachment: x,
|
|
1158
|
+
onRemove: onRemove ? () => onRemove(x) : void 0
|
|
1159
|
+
},
|
|
1160
|
+
x.id
|
|
1161
|
+
))
|
|
1195
1162
|
}
|
|
1196
|
-
});
|
|
1197
|
-
const result = await parseSuccessfulResponse(response, "");
|
|
1198
|
-
if (result?.orchestrator) {
|
|
1199
|
-
return result;
|
|
1200
|
-
}
|
|
1201
|
-
return null;
|
|
1202
|
-
}
|
|
1203
|
-
async callRoutinePoll(routineId) {
|
|
1204
|
-
const result = await ApiaApi.post(
|
|
1205
|
-
makeApiaUrl({
|
|
1206
|
-
action: "routinePoll",
|
|
1207
|
-
routineId
|
|
1208
|
-
})
|
|
1209
1163
|
);
|
|
1210
|
-
if (result?.data?.orchestrator) {
|
|
1211
|
-
return JSON.parse(result.data.orchestrator);
|
|
1212
|
-
} else {
|
|
1213
|
-
throw new Error("Poll failed");
|
|
1214
|
-
}
|
|
1215
1164
|
}
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1165
|
+
);
|
|
1166
|
+
|
|
1167
|
+
const Message = observer(
|
|
1168
|
+
({
|
|
1169
|
+
className,
|
|
1170
|
+
type,
|
|
1171
|
+
id,
|
|
1172
|
+
message,
|
|
1173
|
+
attachments,
|
|
1174
|
+
reference
|
|
1175
|
+
}) => {
|
|
1176
|
+
return /* @__PURE__ */ jsxs(
|
|
1177
|
+
Box,
|
|
1222
1178
|
{
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1179
|
+
as: "pre",
|
|
1180
|
+
className: `history_message ${className || ""} ${type}`,
|
|
1181
|
+
children: [
|
|
1182
|
+
/* @__PURE__ */ jsx(
|
|
1183
|
+
Box,
|
|
1184
|
+
{
|
|
1185
|
+
className: "history_message__content",
|
|
1186
|
+
...typeof message === "string" ? { dangerouslySetInnerHTML: { __html: message } } : { children: message }
|
|
1187
|
+
}
|
|
1188
|
+
),
|
|
1189
|
+
attachments.length > 0 && /* @__PURE__ */ jsx(Attachments, { attachments }),
|
|
1190
|
+
reference && /* @__PURE__ */ jsx(Box, { className: "history_message__references", children: reference })
|
|
1191
|
+
]
|
|
1192
|
+
},
|
|
1193
|
+
id
|
|
1232
1194
|
);
|
|
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
|
-
}
|
|
1254
|
-
resetLoading() {
|
|
1255
|
-
this.state.isLoading = false;
|
|
1256
|
-
this.state.progress = 0;
|
|
1257
1195
|
}
|
|
1258
|
-
|
|
1259
|
-
return this.executeRoutine(
|
|
1260
|
-
params.routineName,
|
|
1261
|
-
params.parameters ?? {},
|
|
1262
|
-
params.images ?? [],
|
|
1263
|
-
params.stream
|
|
1264
|
-
);
|
|
1265
|
-
}
|
|
1266
|
-
stop() {
|
|
1267
|
-
this.resetLoading();
|
|
1268
|
-
ApiaApi.get(
|
|
1269
|
-
makeApiaUrl({
|
|
1270
|
-
action: "routineStop",
|
|
1271
|
-
routineId: this.routineId
|
|
1272
|
-
})
|
|
1273
|
-
);
|
|
1274
|
-
}
|
|
1275
|
-
async transcribeAudio(audio) {
|
|
1276
|
-
const result = await this.callAudioTranscription(audio);
|
|
1277
|
-
if (result) {
|
|
1278
|
-
this.state.isLoading = true;
|
|
1279
|
-
if (result?.orchestrator?.routineId) {
|
|
1280
|
-
this.routineId = result?.orchestrator?.routineId;
|
|
1281
|
-
return await this.internalPollRoutine();
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
throw new Error("Something went wrong while transcribing the audio");
|
|
1285
|
-
}
|
|
1286
|
-
}
|
|
1287
|
-
|
|
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
|
-
}
|
|
1196
|
+
);
|
|
1337
1197
|
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
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
|
-
}
|
|
1198
|
+
const History = observer(({ messages }) => {
|
|
1199
|
+
let currentType = "";
|
|
1200
|
+
return /* @__PURE__ */ jsx(AutoscrollContainer, { children: /* @__PURE__ */ jsx(
|
|
1201
|
+
Box,
|
|
1202
|
+
{
|
|
1203
|
+
...getVariant("layout.common.chat.history"),
|
|
1204
|
+
className: "chat_history",
|
|
1205
|
+
children: messages.map((current, i) => {
|
|
1206
|
+
let first = false;
|
|
1207
|
+
let last = false;
|
|
1208
|
+
if (currentType !== current.messageType) {
|
|
1209
|
+
currentType = current.messageType;
|
|
1210
|
+
first = true;
|
|
1387
1211
|
}
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
super.emit("part", part);
|
|
1391
|
-
} else {
|
|
1392
|
-
this.isRunning = false;
|
|
1393
|
-
clearInterval(interval);
|
|
1212
|
+
if (i === messages.length - 1 || messages[i + 1].messageType !== current.messageType) {
|
|
1213
|
+
last = true;
|
|
1394
1214
|
}
|
|
1395
|
-
|
|
1215
|
+
return /* @__PURE__ */ jsx(
|
|
1216
|
+
Message,
|
|
1217
|
+
{
|
|
1218
|
+
className: first ? "first" : last ? "last" : void 0,
|
|
1219
|
+
type: current.messageType,
|
|
1220
|
+
id: String(current.id),
|
|
1221
|
+
attachments: current.attachments,
|
|
1222
|
+
reference: current.reference,
|
|
1223
|
+
message: current.message
|
|
1224
|
+
}
|
|
1225
|
+
);
|
|
1226
|
+
})
|
|
1396
1227
|
}
|
|
1397
|
-
}
|
|
1398
|
-
}
|
|
1228
|
+
) });
|
|
1229
|
+
});
|
|
1399
1230
|
|
|
1400
|
-
|
|
1401
|
-
return (
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
input.type = "file";
|
|
1408
|
-
input.style.display = "none";
|
|
1409
|
-
Object.assign(input, inputProps);
|
|
1410
|
-
document.body.append(input);
|
|
1411
|
-
input.addEventListener("change", (event) => {
|
|
1412
|
-
const target = event?.target;
|
|
1413
|
-
if (!target?.files)
|
|
1414
|
-
return;
|
|
1415
|
-
const retrievedImages = [];
|
|
1416
|
-
const sources = [...target.files ?? []];
|
|
1417
|
-
const checkResolve = () => {
|
|
1418
|
-
if (sources.length === retrievedImages.length) {
|
|
1419
|
-
resolve(retrievedImages.filter((c) => !!c));
|
|
1420
|
-
}
|
|
1421
|
-
};
|
|
1422
|
-
sources.forEach((file) => {
|
|
1423
|
-
if (file) {
|
|
1424
|
-
const reader = new FileReader();
|
|
1425
|
-
reader.onload = function(e) {
|
|
1426
|
-
const binary = e.target?.result?.split(",")[1];
|
|
1427
|
-
input.remove();
|
|
1428
|
-
retrievedImages.push({
|
|
1429
|
-
base64: binary,
|
|
1430
|
-
path: file.name
|
|
1431
|
-
});
|
|
1432
|
-
checkResolve();
|
|
1433
|
-
};
|
|
1434
|
-
reader.readAsDataURL(file);
|
|
1435
|
-
} else {
|
|
1436
|
-
retrievedImages.push(null);
|
|
1437
|
-
}
|
|
1438
|
-
checkResolve();
|
|
1439
|
-
});
|
|
1440
|
-
});
|
|
1441
|
-
input.click();
|
|
1442
|
-
});
|
|
1231
|
+
function getBase64FromFile(f) {
|
|
1232
|
+
return ((f2) => new Promise((resolve, reject) => {
|
|
1233
|
+
const reader = new FileReader();
|
|
1234
|
+
reader.readAsDataURL(f2);
|
|
1235
|
+
reader.onload = () => resolve(reader.result);
|
|
1236
|
+
reader.onerror = () => reject();
|
|
1237
|
+
}))(f);
|
|
1443
1238
|
}
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
] });
|
|
1455
|
-
};
|
|
1456
|
-
|
|
1457
|
-
function getSrcFromBase64(base64) {
|
|
1458
|
-
return `data:image/jpg;base64,${base64}`;
|
|
1459
|
-
}
|
|
1460
|
-
|
|
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);
|
|
1465
|
-
return value;
|
|
1466
|
-
};
|
|
1467
|
-
class ImagesStore {
|
|
1468
|
-
constructor(images, multiple) {
|
|
1469
|
-
this.multiple = multiple;
|
|
1470
|
-
__publicField$2(this, "images", /* @__PURE__ */ new Map());
|
|
1471
|
-
__publicField$2(this, "selectedId", "");
|
|
1472
|
-
this.images = new Map(
|
|
1473
|
-
images.map((c) => {
|
|
1474
|
-
const id = uniqueId();
|
|
1475
|
-
return [id, { ...c, id }];
|
|
1476
|
-
})
|
|
1477
|
-
);
|
|
1478
|
-
this.selectedId = this.images.values().next().value.id;
|
|
1479
|
-
makeAutoObservable(this);
|
|
1480
|
-
}
|
|
1481
|
-
}
|
|
1482
|
-
const GetImagesDescription = observer(({ store }) => {
|
|
1483
|
-
return /* @__PURE__ */ jsxs(
|
|
1484
|
-
Box,
|
|
1485
|
-
{
|
|
1486
|
-
className: "images_description_generator",
|
|
1487
|
-
...getVariant("layout.design.projectAnalysis.imagesLoader"),
|
|
1488
|
-
children: [
|
|
1489
|
-
/* @__PURE__ */ jsx(Box, { className: "images_sort_wrapper", children: /* @__PURE__ */ jsx(
|
|
1490
|
-
SortableList,
|
|
1491
|
-
{
|
|
1492
|
-
onSortChange: (ev) => {
|
|
1493
|
-
store.images = new Map(
|
|
1494
|
-
ev.map((c) => [
|
|
1495
|
-
c.props.id,
|
|
1496
|
-
c.props.additionalProps
|
|
1497
|
-
])
|
|
1498
|
-
);
|
|
1499
|
-
},
|
|
1500
|
-
children: [...store.images].map(([k, c]) => /* @__PURE__ */ jsx(SortableListItem, { additionalProps: c, id: c.id, children: /* @__PURE__ */ jsx(
|
|
1501
|
-
ImageIcon,
|
|
1502
|
-
{
|
|
1503
|
-
deletable: store.multiple,
|
|
1504
|
-
onClick: () => {
|
|
1505
|
-
store.selectedId = c.id;
|
|
1506
|
-
},
|
|
1507
|
-
onRemove: () => {
|
|
1508
|
-
store.images.delete(k);
|
|
1509
|
-
},
|
|
1510
|
-
src: getSrcFromBase64(c.base64 ?? "")
|
|
1511
|
-
}
|
|
1512
|
-
) }, c.id))
|
|
1513
|
-
}
|
|
1514
|
-
) }),
|
|
1515
|
-
/* @__PURE__ */ jsxs(Box, { className: "image_editor", children: [
|
|
1516
|
-
/* @__PURE__ */ jsx(Box, { className: "image_preview", children: store.images.get(store.selectedId) && /* @__PURE__ */ jsx(
|
|
1517
|
-
"img",
|
|
1518
|
-
{
|
|
1519
|
-
src: getSrcFromBase64(
|
|
1520
|
-
store.images.get(store.selectedId).base64 ?? ""
|
|
1521
|
-
)
|
|
1522
|
-
}
|
|
1523
|
-
) }),
|
|
1524
|
-
/* @__PURE__ */ jsxs(Box, { className: "image_description", children: [
|
|
1525
|
-
/* @__PURE__ */ jsx(
|
|
1526
|
-
Textarea,
|
|
1527
|
-
{
|
|
1528
|
-
autoFocus: true,
|
|
1529
|
-
disabled: !store.images.get(store.selectedId),
|
|
1530
|
-
onChange: (ev) => {
|
|
1531
|
-
const image = store.images.get(store.selectedId);
|
|
1532
|
-
if (image)
|
|
1533
|
-
image.description = ev.target.value;
|
|
1534
|
-
},
|
|
1535
|
-
value: store.images.get(store.selectedId)?.description
|
|
1536
|
-
}
|
|
1537
|
-
),
|
|
1538
|
-
store.multiple && /* @__PURE__ */ jsx(
|
|
1539
|
-
IconButton,
|
|
1540
|
-
{
|
|
1541
|
-
icon: "Attach",
|
|
1542
|
-
onClick: () => {
|
|
1543
|
-
getImagesFromDisk({ multiple: "true" }).then((res) => {
|
|
1544
|
-
res.forEach((c) => {
|
|
1545
|
-
const id = uniqueId();
|
|
1546
|
-
store.images.set(id, {
|
|
1547
|
-
base64: c.base64,
|
|
1548
|
-
description: "",
|
|
1549
|
-
id
|
|
1550
|
-
});
|
|
1551
|
-
});
|
|
1552
|
-
});
|
|
1553
|
-
},
|
|
1554
|
-
size: "Md",
|
|
1555
|
-
iconSize: "Sm",
|
|
1556
|
-
variant: "icon-only"
|
|
1557
|
-
}
|
|
1558
|
-
)
|
|
1559
|
-
] })
|
|
1560
|
-
] })
|
|
1561
|
-
]
|
|
1562
|
-
}
|
|
1563
|
-
);
|
|
1564
|
-
});
|
|
1565
|
-
function getImagesWithDescription({
|
|
1566
|
-
multiple
|
|
1567
|
-
}) {
|
|
1568
|
-
return new Promise((resolve) => {
|
|
1569
|
-
getImagesFromDisk({ multiple: multiple ? "true" : void 0 }).then(
|
|
1570
|
-
(images) => {
|
|
1571
|
-
const store = new ImagesStore(
|
|
1572
|
-
images.map((c) => ({
|
|
1573
|
-
base64: c.base64,
|
|
1574
|
-
description: ""
|
|
1575
|
-
})),
|
|
1576
|
-
multiple || false
|
|
1577
|
-
);
|
|
1578
|
-
ApiaUtil.instance.modals.open({
|
|
1579
|
-
children: /* @__PURE__ */ jsx(GetImagesDescription, { store }),
|
|
1580
|
-
initialFocusGetter(modalInnerRef) {
|
|
1581
|
-
return modalInnerRef.querySelector("textarea");
|
|
1582
|
-
},
|
|
1583
|
-
onConfirm: () => {
|
|
1584
|
-
resolve([...toJS(store.images).values()]);
|
|
1585
|
-
},
|
|
1586
|
-
onCancel() {
|
|
1587
|
-
resolve([]);
|
|
1588
|
-
},
|
|
1589
|
-
size: "xxxl-fixed",
|
|
1590
|
-
noHeader: true
|
|
1591
|
-
});
|
|
1592
|
-
}
|
|
1593
|
-
);
|
|
1594
|
-
});
|
|
1595
|
-
}
|
|
1596
|
-
|
|
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);
|
|
1239
|
+
function getBase64FromBlob(b) {
|
|
1240
|
+
return ((blob) => new Promise((resolve, reject) => {
|
|
1241
|
+
const reader = new FileReader();
|
|
1242
|
+
reader.onloadend = () => {
|
|
1243
|
+
const base64String = reader.result;
|
|
1244
|
+
resolve(base64String);
|
|
1245
|
+
};
|
|
1246
|
+
reader.onerror = reject;
|
|
1247
|
+
reader.readAsDataURL(blob);
|
|
1248
|
+
}))(b);
|
|
1729
1249
|
}
|
|
1730
1250
|
|
|
1731
1251
|
const TextArea = observer(
|
|
@@ -1908,21 +1428,21 @@ const TextArea = observer(
|
|
|
1908
1428
|
}
|
|
1909
1429
|
);
|
|
1910
1430
|
|
|
1911
|
-
var __defProp$
|
|
1912
|
-
var __defNormalProp$
|
|
1913
|
-
var __publicField$
|
|
1914
|
-
__defNormalProp$
|
|
1431
|
+
var __defProp$5 = Object.defineProperty;
|
|
1432
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1433
|
+
var __publicField$5 = (obj, key, value) => {
|
|
1434
|
+
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1915
1435
|
return value;
|
|
1916
1436
|
};
|
|
1917
1437
|
class CameraController {
|
|
1918
1438
|
constructor() {
|
|
1919
|
-
__publicField$
|
|
1439
|
+
__publicField$5(this, "state", {
|
|
1920
1440
|
videoStream: null,
|
|
1921
1441
|
isOpen: false
|
|
1922
1442
|
});
|
|
1923
|
-
__publicField$
|
|
1924
|
-
__publicField$
|
|
1925
|
-
__publicField$
|
|
1443
|
+
__publicField$5(this, "currentCapture", null);
|
|
1444
|
+
__publicField$5(this, "videoElement");
|
|
1445
|
+
__publicField$5(this, "Component", () => {
|
|
1926
1446
|
return /* @__PURE__ */ jsx(
|
|
1927
1447
|
"video",
|
|
1928
1448
|
{
|
|
@@ -2002,19 +1522,18 @@ class CameraController {
|
|
|
2002
1522
|
}
|
|
2003
1523
|
}
|
|
2004
1524
|
|
|
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);
|
|
1525
|
+
var __defProp$4 = Object.defineProperty;
|
|
1526
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1527
|
+
var __publicField$4 = (obj, key, value) => {
|
|
1528
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2009
1529
|
return value;
|
|
2010
1530
|
};
|
|
2011
1531
|
class ChatController2 {
|
|
2012
1532
|
constructor(props, onMessageSubmit, id) {
|
|
2013
1533
|
this.onMessageSubmit = onMessageSubmit;
|
|
2014
1534
|
this.id = id;
|
|
2015
|
-
__publicField(this, "currentIndex", 0);
|
|
2016
|
-
__publicField(this, "
|
|
2017
|
-
__publicField(this, "state", {
|
|
1535
|
+
__publicField$4(this, "currentIndex", 0);
|
|
1536
|
+
__publicField$4(this, "state", {
|
|
2018
1537
|
isVisible: false,
|
|
2019
1538
|
isLoading: false,
|
|
2020
1539
|
canRecord: true,
|
|
@@ -2026,10 +1545,10 @@ class ChatController2 {
|
|
|
2026
1545
|
messages: [],
|
|
2027
1546
|
currentMessage: new ChatMessage("", "user")
|
|
2028
1547
|
});
|
|
2029
|
-
__publicField(this, "internalAudioRecorder", new AudioRecorder());
|
|
2030
|
-
__publicField(this, "internalCameraRecorder", new CameraController());
|
|
2031
|
-
__publicField(this, "maxId", 0);
|
|
2032
|
-
__publicField(this, "audioRecorder", {
|
|
1548
|
+
__publicField$4(this, "internalAudioRecorder", new AudioRecorder());
|
|
1549
|
+
__publicField$4(this, "internalCameraRecorder", new CameraController());
|
|
1550
|
+
__publicField$4(this, "maxId", 0);
|
|
1551
|
+
__publicField$4(this, "audioRecorder", {
|
|
2033
1552
|
start: () => {
|
|
2034
1553
|
this.internalAudioRecorder.start().then(async (blob) => {
|
|
2035
1554
|
this.state.currentMessage.attachments.push({
|
|
@@ -2045,8 +1564,8 @@ class ChatController2 {
|
|
|
2045
1564
|
record: 0,
|
|
2046
1565
|
state: this.internalAudioRecorder.state
|
|
2047
1566
|
});
|
|
2048
|
-
__publicField(this, "History", observer(() => /* @__PURE__ */ jsx(History, { messages: this.state.messages })));
|
|
2049
|
-
__publicField(this, "Attachments", observer(() => /* @__PURE__ */ jsx(
|
|
1567
|
+
__publicField$4(this, "History", observer(() => /* @__PURE__ */ jsx(History, { messages: this.state.messages })));
|
|
1568
|
+
__publicField$4(this, "Attachments", observer(() => /* @__PURE__ */ jsx(
|
|
2050
1569
|
Attachments,
|
|
2051
1570
|
{
|
|
2052
1571
|
attachments: this.state.currentMessage.attachments,
|
|
@@ -2055,7 +1574,7 @@ class ChatController2 {
|
|
|
2055
1574
|
}
|
|
2056
1575
|
}
|
|
2057
1576
|
)));
|
|
2058
|
-
__publicField(this, "TextArea", observer(() => /* @__PURE__ */ jsx(
|
|
1577
|
+
__publicField$4(this, "TextArea", observer(() => /* @__PURE__ */ jsx(
|
|
2059
1578
|
TextArea,
|
|
2060
1579
|
{
|
|
2061
1580
|
id: this.id,
|
|
@@ -2122,7 +1641,7 @@ class ChatController2 {
|
|
|
2122
1641
|
attachments: []
|
|
2123
1642
|
}
|
|
2124
1643
|
)));
|
|
2125
|
-
__publicField(this, "Renderer", () => /* @__PURE__ */ jsxs(
|
|
1644
|
+
__publicField$4(this, "Renderer", () => /* @__PURE__ */ jsxs(
|
|
2126
1645
|
Box,
|
|
2127
1646
|
{
|
|
2128
1647
|
...getVariant("layout.common.chat.controller"),
|
|
@@ -2180,6 +1699,526 @@ class ChatController2 {
|
|
|
2180
1699
|
}
|
|
2181
1700
|
}
|
|
2182
1701
|
|
|
1702
|
+
var __defProp$3 = Object.defineProperty;
|
|
1703
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1704
|
+
var __publicField$3 = (obj, key, value) => {
|
|
1705
|
+
__defNormalProp$3(obj, key + "" , value);
|
|
1706
|
+
return value;
|
|
1707
|
+
};
|
|
1708
|
+
class FloatingChatController extends ChatController2 {
|
|
1709
|
+
constructor(props, onMessageSubmit, id) {
|
|
1710
|
+
super(props, onMessageSubmit, id);
|
|
1711
|
+
__publicField$3(this, "Window", observer(() => /* @__PURE__ */ jsx(
|
|
1712
|
+
IconButton,
|
|
1713
|
+
{
|
|
1714
|
+
icon: "Magic",
|
|
1715
|
+
size: "Md",
|
|
1716
|
+
variant: "icon-outline",
|
|
1717
|
+
onClick: () => {
|
|
1718
|
+
this.state.isVisible = true;
|
|
1719
|
+
this.open();
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
)));
|
|
1723
|
+
this.state = Object.assign({}, this.state, props);
|
|
1724
|
+
makeObservable(this, { state: observable });
|
|
1725
|
+
}
|
|
1726
|
+
open() {
|
|
1727
|
+
ApiaUtil.instance.modals.open({
|
|
1728
|
+
variant: "layout.common.chat.assistant.floatingAssistant",
|
|
1729
|
+
defaultPosition: {
|
|
1730
|
+
bottom: "10px",
|
|
1731
|
+
right: "50px"
|
|
1732
|
+
},
|
|
1733
|
+
draggable: true,
|
|
1734
|
+
children: /* @__PURE__ */ jsx(this.Renderer, {}),
|
|
1735
|
+
onClose: () => {
|
|
1736
|
+
this.state.isVisible = false;
|
|
1737
|
+
}
|
|
1738
|
+
});
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
var __defProp$2 = Object.defineProperty;
|
|
1743
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1744
|
+
var __publicField$2 = (obj, key, value) => {
|
|
1745
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1746
|
+
return value;
|
|
1747
|
+
};
|
|
1748
|
+
function isPollProgress(payload) {
|
|
1749
|
+
return payload?.progress !== void 0;
|
|
1750
|
+
}
|
|
1751
|
+
class RoutinesGeneration {
|
|
1752
|
+
constructor() {
|
|
1753
|
+
__publicField$2(this, "audioRecorder", new AudioRecorder());
|
|
1754
|
+
__publicField$2(this, "routineId", "");
|
|
1755
|
+
__publicField$2(this, "state", {
|
|
1756
|
+
isLoading: false,
|
|
1757
|
+
progress: 0
|
|
1758
|
+
});
|
|
1759
|
+
makeObservable(this, {
|
|
1760
|
+
completion: action,
|
|
1761
|
+
state: observable,
|
|
1762
|
+
stop: action,
|
|
1763
|
+
transcribeAudio: action
|
|
1764
|
+
});
|
|
1765
|
+
}
|
|
1766
|
+
checkCanGenerate() {
|
|
1767
|
+
if (this.state.isLoading) {
|
|
1768
|
+
throw new Error("Cannot queue two simultaneous generations");
|
|
1769
|
+
}
|
|
1770
|
+
this.state.isLoading = true;
|
|
1771
|
+
}
|
|
1772
|
+
async pollRoutine(routineId, stream) {
|
|
1773
|
+
this.routineId = routineId;
|
|
1774
|
+
this.state.isLoading = true;
|
|
1775
|
+
return this.internalPollRoutine(stream);
|
|
1776
|
+
}
|
|
1777
|
+
async internalPollRoutine(stream) {
|
|
1778
|
+
while (this.state.isLoading) {
|
|
1779
|
+
const pollResult = await this.callRoutinePoll(this.routineId);
|
|
1780
|
+
if (isPollProgress(pollResult.payload)) {
|
|
1781
|
+
try {
|
|
1782
|
+
const res = JSON.parse(pollResult.payload.debug);
|
|
1783
|
+
if (res.length > 0) {
|
|
1784
|
+
res.forEach((c) => {
|
|
1785
|
+
console.log(JSON.parse(c));
|
|
1786
|
+
});
|
|
1787
|
+
}
|
|
1788
|
+
if (pollResult.payload.streamPart && stream) {
|
|
1789
|
+
stream.emit("part", pollResult.payload.streamPart);
|
|
1790
|
+
}
|
|
1791
|
+
this.state.progress = pollResult.payload.progress;
|
|
1792
|
+
} catch (e) {
|
|
1793
|
+
console.error(e);
|
|
1794
|
+
}
|
|
1795
|
+
} else if (pollResult.status === "FINISHED") {
|
|
1796
|
+
this.resetLoading();
|
|
1797
|
+
return pollResult.payload;
|
|
1798
|
+
} else if (pollResult.status === "ERROR") {
|
|
1799
|
+
this.resetLoading();
|
|
1800
|
+
throw new Error(pollResult.payload);
|
|
1801
|
+
} else {
|
|
1802
|
+
this.resetLoading();
|
|
1803
|
+
throw new Error("Wrong poll response");
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
return null;
|
|
1807
|
+
}
|
|
1808
|
+
async callAudioTranscription(audio) {
|
|
1809
|
+
const url = makeApiaUrl({
|
|
1810
|
+
action: "routineStart",
|
|
1811
|
+
routine: "transcription/Transcribe"
|
|
1812
|
+
});
|
|
1813
|
+
const response = await axios.post(url, audio.arrayBuffer(), {
|
|
1814
|
+
headers: {
|
|
1815
|
+
"Content-Type": "application/octet-stream"
|
|
1816
|
+
}
|
|
1817
|
+
});
|
|
1818
|
+
const result = await parseSuccessfulResponse(response, "");
|
|
1819
|
+
if (result?.orchestrator) {
|
|
1820
|
+
return result;
|
|
1821
|
+
}
|
|
1822
|
+
return null;
|
|
1823
|
+
}
|
|
1824
|
+
async callRoutinePoll(routineId) {
|
|
1825
|
+
const result = await ApiaApi.post(
|
|
1826
|
+
makeApiaUrl({
|
|
1827
|
+
action: "routinePoll",
|
|
1828
|
+
routineId
|
|
1829
|
+
})
|
|
1830
|
+
);
|
|
1831
|
+
if (result?.data?.orchestrator) {
|
|
1832
|
+
return JSON.parse(result.data.orchestrator);
|
|
1833
|
+
} else {
|
|
1834
|
+
throw new Error("Poll failed");
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
async callRoutineStart(routineName, parameters, images) {
|
|
1838
|
+
const result = await ApiaApi.post(
|
|
1839
|
+
makeApiaUrl({
|
|
1840
|
+
action: "routineStart",
|
|
1841
|
+
routine: routineName
|
|
1842
|
+
}),
|
|
1843
|
+
{
|
|
1844
|
+
postData: {
|
|
1845
|
+
images: JSON.stringify(images),
|
|
1846
|
+
...parameters
|
|
1847
|
+
},
|
|
1848
|
+
stringifyOptions: {
|
|
1849
|
+
arrayFormat: "repeat"
|
|
1850
|
+
},
|
|
1851
|
+
postDataTreatement: "stringify"
|
|
1852
|
+
}
|
|
1853
|
+
);
|
|
1854
|
+
return result?.data || null;
|
|
1855
|
+
}
|
|
1856
|
+
async executeRoutine(routineName, parameters, images, stream) {
|
|
1857
|
+
this.checkCanGenerate();
|
|
1858
|
+
try {
|
|
1859
|
+
const result = await this.callRoutineStart(
|
|
1860
|
+
routineName,
|
|
1861
|
+
parameters,
|
|
1862
|
+
images
|
|
1863
|
+
);
|
|
1864
|
+
if (result?.orchestrator?.routineId !== void 0) {
|
|
1865
|
+
this.routineId = result?.orchestrator.routineId;
|
|
1866
|
+
return this.internalPollRoutine(stream);
|
|
1867
|
+
} else {
|
|
1868
|
+
throw new Error("Cannot get routine id");
|
|
1869
|
+
}
|
|
1870
|
+
} catch (e) {
|
|
1871
|
+
this.resetLoading();
|
|
1872
|
+
throw e;
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
resetLoading() {
|
|
1876
|
+
this.state.isLoading = false;
|
|
1877
|
+
this.state.progress = 0;
|
|
1878
|
+
}
|
|
1879
|
+
async completion(params) {
|
|
1880
|
+
return this.executeRoutine(
|
|
1881
|
+
params.routineName,
|
|
1882
|
+
params.parameters ?? {},
|
|
1883
|
+
params.images ?? [],
|
|
1884
|
+
params.stream
|
|
1885
|
+
);
|
|
1886
|
+
}
|
|
1887
|
+
stop() {
|
|
1888
|
+
this.resetLoading();
|
|
1889
|
+
ApiaApi.get(
|
|
1890
|
+
makeApiaUrl({
|
|
1891
|
+
action: "routineStop",
|
|
1892
|
+
routineId: this.routineId
|
|
1893
|
+
})
|
|
1894
|
+
);
|
|
1895
|
+
}
|
|
1896
|
+
async transcribeAudio(audio) {
|
|
1897
|
+
const result = await this.callAudioTranscription(audio);
|
|
1898
|
+
if (result) {
|
|
1899
|
+
this.state.isLoading = true;
|
|
1900
|
+
if (result?.orchestrator?.routineId) {
|
|
1901
|
+
this.routineId = result?.orchestrator?.routineId;
|
|
1902
|
+
return await this.internalPollRoutine();
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
throw new Error("Something went wrong while transcribing the audio");
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1909
|
+
class DashboardsRoutinesGeneration extends RoutinesGeneration {
|
|
1910
|
+
constructor(dispatcher) {
|
|
1911
|
+
super();
|
|
1912
|
+
this.dispatcher = dispatcher;
|
|
1913
|
+
}
|
|
1914
|
+
blobToBase64(audio) {
|
|
1915
|
+
return new Promise((resolve, reject) => {
|
|
1916
|
+
const reader = new FileReader();
|
|
1917
|
+
reader.onloadend = () => {
|
|
1918
|
+
if (reader.result && typeof reader.result === "string") {
|
|
1919
|
+
const base64 = reader.result.split(",")[1];
|
|
1920
|
+
resolve(base64);
|
|
1921
|
+
} else {
|
|
1922
|
+
reject(new Error("Could not convert Blob to base64"));
|
|
1923
|
+
}
|
|
1924
|
+
};
|
|
1925
|
+
reader.onerror = reject;
|
|
1926
|
+
reader.readAsDataURL(audio);
|
|
1927
|
+
});
|
|
1928
|
+
}
|
|
1929
|
+
async callAudioTranscription(audio) {
|
|
1930
|
+
const audioBase64 = await this.blobToBase64(audio);
|
|
1931
|
+
const result = await this.dispatcher({
|
|
1932
|
+
action: "transcription",
|
|
1933
|
+
audioBase64
|
|
1934
|
+
});
|
|
1935
|
+
return result?.data || null;
|
|
1936
|
+
}
|
|
1937
|
+
async callRoutinePoll(routineId) {
|
|
1938
|
+
const result = await this.dispatcher({
|
|
1939
|
+
action: "routinePoll",
|
|
1940
|
+
routineId
|
|
1941
|
+
});
|
|
1942
|
+
if (result?.data?.orchestrator) {
|
|
1943
|
+
const parsed = JSON.parse(result.data.orchestrator);
|
|
1944
|
+
return parsed;
|
|
1945
|
+
}
|
|
1946
|
+
throw new Error("Poll failed");
|
|
1947
|
+
}
|
|
1948
|
+
async callRoutineStart(routineName, parameters, images) {
|
|
1949
|
+
const result = await this.dispatcher({
|
|
1950
|
+
action: "routineStart",
|
|
1951
|
+
routine: routineName,
|
|
1952
|
+
...parameters,
|
|
1953
|
+
images
|
|
1954
|
+
});
|
|
1955
|
+
return result?.data || null;
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
var __defProp$1 = Object.defineProperty;
|
|
1960
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1961
|
+
var __publicField$1 = (obj, key, value) => {
|
|
1962
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1963
|
+
return value;
|
|
1964
|
+
};
|
|
1965
|
+
class ResponseStream extends EventEmitter {
|
|
1966
|
+
constructor() {
|
|
1967
|
+
super(...arguments);
|
|
1968
|
+
__publicField$1(this, "buffer", "");
|
|
1969
|
+
__publicField$1(this, "isRunning", false);
|
|
1970
|
+
__publicField$1(this, "locked", false);
|
|
1971
|
+
__publicField$1(this, "maxCompletionTime", 2);
|
|
1972
|
+
// s
|
|
1973
|
+
__publicField$1(this, "minPartSize", 2);
|
|
1974
|
+
__publicField$1(this, "partSize", 2);
|
|
1975
|
+
__publicField$1(this, "timing", 5);
|
|
1976
|
+
// ms
|
|
1977
|
+
__publicField$1(this, "waiting", []);
|
|
1978
|
+
}
|
|
1979
|
+
calculatePartSize() {
|
|
1980
|
+
const totalSize = this.buffer.length + this.waiting.reduce((a, b) => a + b.length, 0);
|
|
1981
|
+
this.partSize = Math.max(
|
|
1982
|
+
this.minPartSize,
|
|
1983
|
+
totalSize * this.timing / (this.maxCompletionTime * 1e3)
|
|
1984
|
+
);
|
|
1985
|
+
}
|
|
1986
|
+
emit(_, data) {
|
|
1987
|
+
if (this.locked) {
|
|
1988
|
+
this.waiting.push(data);
|
|
1989
|
+
} else {
|
|
1990
|
+
this.buffer += data;
|
|
1991
|
+
}
|
|
1992
|
+
this.calculatePartSize();
|
|
1993
|
+
this.run();
|
|
1994
|
+
}
|
|
1995
|
+
run() {
|
|
1996
|
+
if (!this.isRunning) {
|
|
1997
|
+
this.isRunning = true;
|
|
1998
|
+
const interval = setInterval(() => {
|
|
1999
|
+
this.locked = true;
|
|
2000
|
+
const choosedSize = Math.min(this.buffer.length, this.partSize);
|
|
2001
|
+
const part = this.buffer.slice(0, choosedSize);
|
|
2002
|
+
this.buffer = this.buffer.slice(choosedSize);
|
|
2003
|
+
while (this.waiting.length > 0) {
|
|
2004
|
+
const part2 = this.waiting.shift();
|
|
2005
|
+
if (part2) {
|
|
2006
|
+
this.buffer += part2;
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
this.locked = false;
|
|
2010
|
+
if (part) {
|
|
2011
|
+
super.emit("part", part);
|
|
2012
|
+
} else {
|
|
2013
|
+
this.isRunning = false;
|
|
2014
|
+
clearInterval(interval);
|
|
2015
|
+
}
|
|
2016
|
+
}, this.timing);
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
|
|
2021
|
+
async function getImageFromDisk(inputProps) {
|
|
2022
|
+
return (await getImagesFromDisk({ ...inputProps, multiple: "false" }))[0] ?? null;
|
|
2023
|
+
}
|
|
2024
|
+
function getImagesFromDisk(inputProps) {
|
|
2025
|
+
return new Promise((resolve) => {
|
|
2026
|
+
const input = document.createElement("input");
|
|
2027
|
+
input.accept = "image/*";
|
|
2028
|
+
input.type = "file";
|
|
2029
|
+
input.style.display = "none";
|
|
2030
|
+
Object.assign(input, inputProps);
|
|
2031
|
+
document.body.append(input);
|
|
2032
|
+
input.addEventListener("change", (event) => {
|
|
2033
|
+
const target = event?.target;
|
|
2034
|
+
if (!target?.files)
|
|
2035
|
+
return;
|
|
2036
|
+
const retrievedImages = [];
|
|
2037
|
+
const sources = [...target.files ?? []];
|
|
2038
|
+
const checkResolve = () => {
|
|
2039
|
+
if (sources.length === retrievedImages.length) {
|
|
2040
|
+
resolve(retrievedImages.filter((c) => !!c));
|
|
2041
|
+
}
|
|
2042
|
+
};
|
|
2043
|
+
sources.forEach((file) => {
|
|
2044
|
+
if (file) {
|
|
2045
|
+
const reader = new FileReader();
|
|
2046
|
+
reader.onload = function(e) {
|
|
2047
|
+
const binary = e.target?.result?.split(",")[1];
|
|
2048
|
+
input.remove();
|
|
2049
|
+
retrievedImages.push({
|
|
2050
|
+
base64: binary,
|
|
2051
|
+
path: file.name
|
|
2052
|
+
});
|
|
2053
|
+
checkResolve();
|
|
2054
|
+
};
|
|
2055
|
+
reader.readAsDataURL(file);
|
|
2056
|
+
} else {
|
|
2057
|
+
retrievedImages.push(null);
|
|
2058
|
+
}
|
|
2059
|
+
checkResolve();
|
|
2060
|
+
});
|
|
2061
|
+
});
|
|
2062
|
+
input.click();
|
|
2063
|
+
});
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2066
|
+
const ImageIcon = ({
|
|
2067
|
+
deletable,
|
|
2068
|
+
onClick,
|
|
2069
|
+
onRemove,
|
|
2070
|
+
src
|
|
2071
|
+
}) => {
|
|
2072
|
+
return /* @__PURE__ */ jsxs(Box, { className: "image_preview", children: [
|
|
2073
|
+
deletable && /* @__PURE__ */ jsx(IconButton, { icon: "Close", size: "Xs", iconSize: "Xs", onClick: onRemove }),
|
|
2074
|
+
/* @__PURE__ */ jsx("img", { src, onClick })
|
|
2075
|
+
] });
|
|
2076
|
+
};
|
|
2077
|
+
|
|
2078
|
+
function getSrcFromBase64(base64) {
|
|
2079
|
+
return `data:image/jpg;base64,${base64}`;
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
var __defProp = Object.defineProperty;
|
|
2083
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2084
|
+
var __publicField = (obj, key, value) => {
|
|
2085
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2086
|
+
return value;
|
|
2087
|
+
};
|
|
2088
|
+
class ImagesStore {
|
|
2089
|
+
constructor(images, multiple) {
|
|
2090
|
+
this.multiple = multiple;
|
|
2091
|
+
__publicField(this, "images", /* @__PURE__ */ new Map());
|
|
2092
|
+
__publicField(this, "selectedId", "");
|
|
2093
|
+
this.images = new Map(
|
|
2094
|
+
images.map((c) => {
|
|
2095
|
+
const id = uniqueId();
|
|
2096
|
+
return [id, { ...c, id }];
|
|
2097
|
+
})
|
|
2098
|
+
);
|
|
2099
|
+
this.selectedId = this.images.values().next().value.id;
|
|
2100
|
+
makeAutoObservable(this);
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
const GetImagesDescription = observer(({ store }) => {
|
|
2104
|
+
return /* @__PURE__ */ jsxs(
|
|
2105
|
+
Box,
|
|
2106
|
+
{
|
|
2107
|
+
className: "images_description_generator",
|
|
2108
|
+
...getVariant("layout.design.projectAnalysis.imagesLoader"),
|
|
2109
|
+
children: [
|
|
2110
|
+
/* @__PURE__ */ jsx(Box, { className: "images_sort_wrapper", children: /* @__PURE__ */ jsx(
|
|
2111
|
+
SortableList,
|
|
2112
|
+
{
|
|
2113
|
+
onSortChange: (ev) => {
|
|
2114
|
+
store.images = new Map(
|
|
2115
|
+
ev.map((c) => [
|
|
2116
|
+
c.props.id,
|
|
2117
|
+
c.props.additionalProps
|
|
2118
|
+
])
|
|
2119
|
+
);
|
|
2120
|
+
},
|
|
2121
|
+
children: [...store.images].map(([k, c]) => /* @__PURE__ */ jsx(SortableListItem, { additionalProps: c, id: c.id, children: /* @__PURE__ */ jsx(
|
|
2122
|
+
ImageIcon,
|
|
2123
|
+
{
|
|
2124
|
+
deletable: store.multiple,
|
|
2125
|
+
onClick: () => {
|
|
2126
|
+
store.selectedId = c.id;
|
|
2127
|
+
},
|
|
2128
|
+
onRemove: () => {
|
|
2129
|
+
store.images.delete(k);
|
|
2130
|
+
},
|
|
2131
|
+
src: getSrcFromBase64(c.base64 ?? "")
|
|
2132
|
+
}
|
|
2133
|
+
) }, c.id))
|
|
2134
|
+
}
|
|
2135
|
+
) }),
|
|
2136
|
+
/* @__PURE__ */ jsxs(Box, { className: "image_editor", children: [
|
|
2137
|
+
/* @__PURE__ */ jsx(Box, { className: "image_preview", children: store.images.get(store.selectedId) && /* @__PURE__ */ jsx(
|
|
2138
|
+
"img",
|
|
2139
|
+
{
|
|
2140
|
+
src: getSrcFromBase64(
|
|
2141
|
+
store.images.get(store.selectedId).base64 ?? ""
|
|
2142
|
+
)
|
|
2143
|
+
}
|
|
2144
|
+
) }),
|
|
2145
|
+
/* @__PURE__ */ jsxs(Box, { className: "image_description", children: [
|
|
2146
|
+
/* @__PURE__ */ jsx(
|
|
2147
|
+
Textarea,
|
|
2148
|
+
{
|
|
2149
|
+
autoFocus: true,
|
|
2150
|
+
disabled: !store.images.get(store.selectedId),
|
|
2151
|
+
onChange: (ev) => {
|
|
2152
|
+
const image = store.images.get(store.selectedId);
|
|
2153
|
+
if (image)
|
|
2154
|
+
image.description = ev.target.value;
|
|
2155
|
+
},
|
|
2156
|
+
value: store.images.get(store.selectedId)?.description
|
|
2157
|
+
}
|
|
2158
|
+
),
|
|
2159
|
+
store.multiple && /* @__PURE__ */ jsx(
|
|
2160
|
+
IconButton,
|
|
2161
|
+
{
|
|
2162
|
+
icon: "Attach",
|
|
2163
|
+
onClick: () => {
|
|
2164
|
+
getImagesFromDisk({ multiple: "true" }).then((res) => {
|
|
2165
|
+
res.forEach((c) => {
|
|
2166
|
+
const id = uniqueId();
|
|
2167
|
+
store.images.set(id, {
|
|
2168
|
+
base64: c.base64,
|
|
2169
|
+
description: "",
|
|
2170
|
+
id
|
|
2171
|
+
});
|
|
2172
|
+
});
|
|
2173
|
+
});
|
|
2174
|
+
},
|
|
2175
|
+
size: "Md",
|
|
2176
|
+
iconSize: "Sm",
|
|
2177
|
+
variant: "icon-only"
|
|
2178
|
+
}
|
|
2179
|
+
)
|
|
2180
|
+
] })
|
|
2181
|
+
] })
|
|
2182
|
+
]
|
|
2183
|
+
}
|
|
2184
|
+
);
|
|
2185
|
+
});
|
|
2186
|
+
function getImagesWithDescription({
|
|
2187
|
+
multiple
|
|
2188
|
+
}) {
|
|
2189
|
+
return new Promise((resolve) => {
|
|
2190
|
+
getImagesFromDisk({ multiple: multiple ? "true" : void 0 }).then(
|
|
2191
|
+
(images) => {
|
|
2192
|
+
const store = new ImagesStore(
|
|
2193
|
+
images.map((c) => ({
|
|
2194
|
+
base64: c.base64,
|
|
2195
|
+
description: ""
|
|
2196
|
+
})),
|
|
2197
|
+
multiple || false
|
|
2198
|
+
);
|
|
2199
|
+
ApiaUtil.instance.modals.open({
|
|
2200
|
+
children: /* @__PURE__ */ jsx(GetImagesDescription, { store }),
|
|
2201
|
+
initialFocusGetter(modalInnerRef) {
|
|
2202
|
+
return modalInnerRef.querySelector("textarea");
|
|
2203
|
+
},
|
|
2204
|
+
onConfirm: () => {
|
|
2205
|
+
resolve([...toJS(store.images).values()]);
|
|
2206
|
+
},
|
|
2207
|
+
onCancel() {
|
|
2208
|
+
resolve([]);
|
|
2209
|
+
},
|
|
2210
|
+
size: "xxxl-fixed",
|
|
2211
|
+
noHeader: true
|
|
2212
|
+
});
|
|
2213
|
+
}
|
|
2214
|
+
);
|
|
2215
|
+
});
|
|
2216
|
+
}
|
|
2217
|
+
|
|
2218
|
+
const ViewRendererContext = createContext(
|
|
2219
|
+
{}
|
|
2220
|
+
);
|
|
2221
|
+
|
|
2183
2222
|
const WindowDragger = forwardRef((props, outerRef) => {
|
|
2184
2223
|
const isDragging = useRef(false);
|
|
2185
2224
|
const initialPosition = useRef({ mousex: 0, mousey: 0, boxx: 0, boxy: 0 });
|
|
@@ -2256,5 +2295,5 @@ const WindowDragger = forwardRef((props, outerRef) => {
|
|
|
2256
2295
|
);
|
|
2257
2296
|
});
|
|
2258
2297
|
|
|
2259
|
-
export { AIFileContent, AIMessageAttachments, AutoscrollContainer, ChatController, ChatController2, ChatMessage, DashboardsRoutinesGeneration, MultipleChoiceMessage, ResponseStream, RoutinesGeneration, SearchController, SemanticSearchReference as SemanticSearchResult, ViewRendererContext, WindowDragger, getImageFromDisk, getImagesFromDisk, getImagesWithDescription };
|
|
2298
|
+
export { AIFileContent, AIMessageAttachments, AutoscrollContainer, ChatController, ChatController2, ChatMessage, DashboardsRoutinesGeneration, FloatingChatController, MultipleChoiceMessage, ResponseStream, RoutinesGeneration, SearchController, SemanticSearchReference as SemanticSearchResult, ViewRendererContext, WindowDragger, getImageFromDisk, getImagesFromDisk, getImagesWithDescription };
|
|
2260
2299
|
//# sourceMappingURL=index.js.map
|