@apia/ai 4.0.14 → 4.0.16
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 +21 -5
- package/dist/index.js +789 -703
- 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) => {
|
|
@@ -879,7 +879,7 @@ var __accessCheck = (obj, member, msg) => {
|
|
|
879
879
|
};
|
|
880
880
|
var __privateGet = (obj, member, getter) => {
|
|
881
881
|
__accessCheck(obj, member, "read from private field");
|
|
882
|
-
return member.get(obj);
|
|
882
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
883
883
|
};
|
|
884
884
|
var __privateAdd = (obj, member, value) => {
|
|
885
885
|
if (member.has(obj))
|
|
@@ -888,18 +888,18 @@ var __privateAdd = (obj, member, value) => {
|
|
|
888
888
|
};
|
|
889
889
|
var __privateSet = (obj, member, value, setter) => {
|
|
890
890
|
__accessCheck(obj, member, "write to private field");
|
|
891
|
-
member.set(obj, value);
|
|
891
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
892
892
|
return value;
|
|
893
893
|
};
|
|
894
894
|
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,138 @@ 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
|
+
var SearchController$1 = SearchController;
|
|
1120
1121
|
|
|
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);
|
|
1122
|
+
const FileAttachment = observer(
|
|
1123
|
+
({
|
|
1124
|
+
attachment,
|
|
1125
|
+
onRemove
|
|
1126
|
+
}) => {
|
|
1127
|
+
return /* @__PURE__ */ jsxs(Box, { className: "file_box", children: [
|
|
1128
|
+
/* @__PURE__ */ jsx(FileIcon, { className: "file_box__icon", docName: attachment.name }),
|
|
1129
|
+
/* @__PURE__ */ jsx(Box, { className: "file_box__name", title: attachment.name, children: attachment.name }),
|
|
1130
|
+
onRemove && /* @__PURE__ */ jsx(
|
|
1131
|
+
IconButton,
|
|
1132
|
+
{
|
|
1133
|
+
icon: "Close",
|
|
1134
|
+
className: "file_box__remove",
|
|
1135
|
+
onClick: onRemove,
|
|
1136
|
+
variant: "icon-only"
|
|
1173
1137
|
}
|
|
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;
|
|
1138
|
+
)
|
|
1139
|
+
] });
|
|
1186
1140
|
}
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1141
|
+
);
|
|
1142
|
+
|
|
1143
|
+
const Attachments = observer(
|
|
1144
|
+
({
|
|
1145
|
+
attachments,
|
|
1146
|
+
onRemove
|
|
1147
|
+
}) => {
|
|
1148
|
+
if (!attachments.length)
|
|
1149
|
+
return null;
|
|
1150
|
+
return /* @__PURE__ */ jsx(
|
|
1151
|
+
Box,
|
|
1152
|
+
{
|
|
1153
|
+
className: "attachments",
|
|
1154
|
+
...getVariant("layout.common.chat.attachments"),
|
|
1155
|
+
children: attachments.map((x) => /* @__PURE__ */ jsx(
|
|
1156
|
+
FileAttachment,
|
|
1157
|
+
{
|
|
1158
|
+
attachment: x,
|
|
1159
|
+
onRemove: onRemove ? () => onRemove(x) : void 0
|
|
1160
|
+
},
|
|
1161
|
+
x.id
|
|
1162
|
+
))
|
|
1195
1163
|
}
|
|
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
1164
|
);
|
|
1210
|
-
if (result?.data?.orchestrator) {
|
|
1211
|
-
return JSON.parse(result.data.orchestrator);
|
|
1212
|
-
} else {
|
|
1213
|
-
throw new Error("Poll failed");
|
|
1214
|
-
}
|
|
1215
1165
|
}
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1166
|
+
);
|
|
1167
|
+
|
|
1168
|
+
const Message = observer(
|
|
1169
|
+
({
|
|
1170
|
+
className,
|
|
1171
|
+
type,
|
|
1172
|
+
id,
|
|
1173
|
+
message,
|
|
1174
|
+
attachments,
|
|
1175
|
+
reference
|
|
1176
|
+
}) => {
|
|
1177
|
+
return /* @__PURE__ */ jsxs(
|
|
1178
|
+
Box,
|
|
1222
1179
|
{
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1180
|
+
as: "pre",
|
|
1181
|
+
className: `history_message ${className || ""} ${type}`,
|
|
1182
|
+
children: [
|
|
1183
|
+
/* @__PURE__ */ jsx(
|
|
1184
|
+
Box,
|
|
1185
|
+
{
|
|
1186
|
+
className: "history_message__content",
|
|
1187
|
+
...typeof message === "string" ? { dangerouslySetInnerHTML: { __html: message } } : { children: message }
|
|
1188
|
+
}
|
|
1189
|
+
),
|
|
1190
|
+
attachments.length > 0 && /* @__PURE__ */ jsx(Attachments, { attachments }),
|
|
1191
|
+
reference && /* @__PURE__ */ jsx(Box, { className: "history_message__references", children: reference })
|
|
1192
|
+
]
|
|
1193
|
+
},
|
|
1194
|
+
id
|
|
1232
1195
|
);
|
|
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
1196
|
}
|
|
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
|
-
}
|
|
1197
|
+
);
|
|
1337
1198
|
|
|
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
|
-
}
|
|
1199
|
+
const History = observer(({ messages }) => {
|
|
1200
|
+
let currentType = "";
|
|
1201
|
+
return /* @__PURE__ */ jsx(AutoscrollContainer, { children: /* @__PURE__ */ jsx(
|
|
1202
|
+
Box,
|
|
1203
|
+
{
|
|
1204
|
+
...getVariant("layout.common.chat.history"),
|
|
1205
|
+
className: "chat_history",
|
|
1206
|
+
children: messages.map((current, i) => {
|
|
1207
|
+
let first = false;
|
|
1208
|
+
let last = false;
|
|
1209
|
+
if (currentType !== current.messageType) {
|
|
1210
|
+
currentType = current.messageType;
|
|
1211
|
+
first = true;
|
|
1387
1212
|
}
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
super.emit("part", part);
|
|
1391
|
-
} else {
|
|
1392
|
-
this.isRunning = false;
|
|
1393
|
-
clearInterval(interval);
|
|
1213
|
+
if (i === messages.length - 1 || messages[i + 1].messageType !== current.messageType) {
|
|
1214
|
+
last = true;
|
|
1394
1215
|
}
|
|
1395
|
-
|
|
1216
|
+
return /* @__PURE__ */ jsx(
|
|
1217
|
+
Message,
|
|
1218
|
+
{
|
|
1219
|
+
className: first ? "first" : last ? "last" : void 0,
|
|
1220
|
+
type: current.messageType,
|
|
1221
|
+
id: String(current.id),
|
|
1222
|
+
attachments: current.attachments,
|
|
1223
|
+
reference: current.reference,
|
|
1224
|
+
message: current.message
|
|
1225
|
+
}
|
|
1226
|
+
);
|
|
1227
|
+
})
|
|
1396
1228
|
}
|
|
1397
|
-
}
|
|
1398
|
-
}
|
|
1229
|
+
) });
|
|
1230
|
+
});
|
|
1399
1231
|
|
|
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
|
-
});
|
|
1232
|
+
function getBase64FromFile(f) {
|
|
1233
|
+
return ((f2) => new Promise((resolve, reject) => {
|
|
1234
|
+
const reader = new FileReader();
|
|
1235
|
+
reader.readAsDataURL(f2);
|
|
1236
|
+
reader.onload = () => resolve(reader.result);
|
|
1237
|
+
reader.onerror = () => reject();
|
|
1238
|
+
}))(f);
|
|
1443
1239
|
}
|
|
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);
|
|
1240
|
+
function getBase64FromBlob(b) {
|
|
1241
|
+
return ((blob) => new Promise((resolve, reject) => {
|
|
1242
|
+
const reader = new FileReader();
|
|
1243
|
+
reader.onloadend = () => {
|
|
1244
|
+
const base64String = reader.result;
|
|
1245
|
+
resolve(base64String);
|
|
1246
|
+
};
|
|
1247
|
+
reader.onerror = reject;
|
|
1248
|
+
reader.readAsDataURL(blob);
|
|
1249
|
+
}))(b);
|
|
1729
1250
|
}
|
|
1730
1251
|
|
|
1731
1252
|
const TextArea = observer(
|
|
@@ -1908,21 +1429,21 @@ const TextArea = observer(
|
|
|
1908
1429
|
}
|
|
1909
1430
|
);
|
|
1910
1431
|
|
|
1911
|
-
var __defProp$
|
|
1912
|
-
var __defNormalProp$
|
|
1913
|
-
var __publicField$
|
|
1914
|
-
__defNormalProp$
|
|
1432
|
+
var __defProp$5 = Object.defineProperty;
|
|
1433
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1434
|
+
var __publicField$5 = (obj, key, value) => {
|
|
1435
|
+
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1915
1436
|
return value;
|
|
1916
1437
|
};
|
|
1917
1438
|
class CameraController {
|
|
1918
1439
|
constructor() {
|
|
1919
|
-
__publicField$
|
|
1440
|
+
__publicField$5(this, "state", {
|
|
1920
1441
|
videoStream: null,
|
|
1921
1442
|
isOpen: false
|
|
1922
1443
|
});
|
|
1923
|
-
__publicField$
|
|
1924
|
-
__publicField$
|
|
1925
|
-
__publicField$
|
|
1444
|
+
__publicField$5(this, "currentCapture", null);
|
|
1445
|
+
__publicField$5(this, "videoElement");
|
|
1446
|
+
__publicField$5(this, "Component", () => {
|
|
1926
1447
|
return /* @__PURE__ */ jsx(
|
|
1927
1448
|
"video",
|
|
1928
1449
|
{
|
|
@@ -2002,34 +1523,36 @@ class CameraController {
|
|
|
2002
1523
|
}
|
|
2003
1524
|
}
|
|
2004
1525
|
|
|
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);
|
|
1526
|
+
var __defProp$4 = Object.defineProperty;
|
|
1527
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1528
|
+
var __publicField$4 = (obj, key, value) => {
|
|
1529
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2009
1530
|
return value;
|
|
2010
1531
|
};
|
|
2011
1532
|
class ChatController2 {
|
|
2012
|
-
constructor(props, onMessageSubmit, id) {
|
|
1533
|
+
constructor(props, onMessageSubmit, id, onMessageResponse) {
|
|
2013
1534
|
this.onMessageSubmit = onMessageSubmit;
|
|
2014
1535
|
this.id = id;
|
|
2015
|
-
|
|
2016
|
-
__publicField(this, "
|
|
2017
|
-
__publicField(this, "state", {
|
|
1536
|
+
this.onMessageResponse = onMessageResponse;
|
|
1537
|
+
__publicField$4(this, "currentIndex", 0);
|
|
1538
|
+
__publicField$4(this, "state", {
|
|
2018
1539
|
isVisible: false,
|
|
2019
1540
|
isLoading: false,
|
|
2020
1541
|
canRecord: true,
|
|
2021
1542
|
canAttach: true,
|
|
2022
1543
|
canAddSystemMessage: true,
|
|
2023
|
-
hideDeleteButton: false,
|
|
2024
1544
|
canAddUserMessage: true,
|
|
1545
|
+
canShowSystemMessage: true,
|
|
1546
|
+
canShowUserMessage: true,
|
|
1547
|
+
hideDeleteButton: false,
|
|
2025
1548
|
maxAttachmentsSize: 100,
|
|
2026
1549
|
messages: [],
|
|
2027
1550
|
currentMessage: new ChatMessage("", "user")
|
|
2028
1551
|
});
|
|
2029
|
-
__publicField(this, "internalAudioRecorder", new AudioRecorder());
|
|
2030
|
-
__publicField(this, "internalCameraRecorder", new CameraController());
|
|
2031
|
-
__publicField(this, "maxId", 0);
|
|
2032
|
-
__publicField(this, "audioRecorder", {
|
|
1552
|
+
__publicField$4(this, "internalAudioRecorder", new AudioRecorder());
|
|
1553
|
+
__publicField$4(this, "internalCameraRecorder", new CameraController());
|
|
1554
|
+
__publicField$4(this, "maxId", 0);
|
|
1555
|
+
__publicField$4(this, "audioRecorder", {
|
|
2033
1556
|
start: () => {
|
|
2034
1557
|
this.internalAudioRecorder.start().then(async (blob) => {
|
|
2035
1558
|
this.state.currentMessage.attachments.push({
|
|
@@ -2045,8 +1568,8 @@ class ChatController2 {
|
|
|
2045
1568
|
record: 0,
|
|
2046
1569
|
state: this.internalAudioRecorder.state
|
|
2047
1570
|
});
|
|
2048
|
-
__publicField(this, "History", observer(() => /* @__PURE__ */ jsx(History, { messages: this.state.messages })));
|
|
2049
|
-
__publicField(this, "Attachments", observer(() => /* @__PURE__ */ jsx(
|
|
1571
|
+
__publicField$4(this, "History", observer(() => /* @__PURE__ */ jsx(History, { messages: this.state.messages })));
|
|
1572
|
+
__publicField$4(this, "Attachments", observer(() => /* @__PURE__ */ jsx(
|
|
2050
1573
|
Attachments,
|
|
2051
1574
|
{
|
|
2052
1575
|
attachments: this.state.currentMessage.attachments,
|
|
@@ -2055,7 +1578,7 @@ class ChatController2 {
|
|
|
2055
1578
|
}
|
|
2056
1579
|
}
|
|
2057
1580
|
)));
|
|
2058
|
-
__publicField(this, "TextArea", observer(() => /* @__PURE__ */ jsx(
|
|
1581
|
+
__publicField$4(this, "TextArea", observer(() => /* @__PURE__ */ jsx(
|
|
2059
1582
|
TextArea,
|
|
2060
1583
|
{
|
|
2061
1584
|
id: this.id,
|
|
@@ -2065,11 +1588,22 @@ class ChatController2 {
|
|
|
2065
1588
|
onChange: (ev) => {
|
|
2066
1589
|
this.state.currentMessage.message = ev;
|
|
2067
1590
|
},
|
|
2068
|
-
onSubmit: () => {
|
|
1591
|
+
onSubmit: async () => {
|
|
2069
1592
|
if (this.state.currentMessage.message || this.state.currentMessage.attachments.length > 0) {
|
|
2070
|
-
this.
|
|
1593
|
+
this.state.isLoading = true;
|
|
1594
|
+
if (this.state.canAddUserMessage) {
|
|
1595
|
+
this.addMessage(this.state.currentMessage);
|
|
1596
|
+
}
|
|
1597
|
+
const response = await this.onMessageSubmit({
|
|
2071
1598
|
message: this.state.currentMessage
|
|
2072
1599
|
});
|
|
1600
|
+
if (this.onMessageResponse) {
|
|
1601
|
+
await this.onMessageResponse(response);
|
|
1602
|
+
}
|
|
1603
|
+
this.state.isLoading = false;
|
|
1604
|
+
if (this.state.canAddSystemMessage && response.responseMessage) {
|
|
1605
|
+
this.addMessage(response.responseMessage);
|
|
1606
|
+
}
|
|
2073
1607
|
this.state.currentMessage = new ChatMessage("", "user");
|
|
2074
1608
|
}
|
|
2075
1609
|
},
|
|
@@ -2122,7 +1656,7 @@ class ChatController2 {
|
|
|
2122
1656
|
attachments: []
|
|
2123
1657
|
}
|
|
2124
1658
|
)));
|
|
2125
|
-
__publicField(this, "Renderer", () => /* @__PURE__ */ jsxs(
|
|
1659
|
+
__publicField$4(this, "Renderer", () => /* @__PURE__ */ jsxs(
|
|
2126
1660
|
Box,
|
|
2127
1661
|
{
|
|
2128
1662
|
...getVariant("layout.common.chat.controller"),
|
|
@@ -2152,34 +1686,586 @@ class ChatController2 {
|
|
|
2152
1686
|
removeAttachment(attachment) {
|
|
2153
1687
|
this.state.currentMessage.attachments = this.state.currentMessage.attachments.filter((x) => x !== attachment);
|
|
2154
1688
|
}
|
|
1689
|
+
isValidToShow(message) {
|
|
1690
|
+
return message && (message.messageType === "system" && this.state.canShowSystemMessage || message.messageType === "user" && this.state.canShowUserMessage);
|
|
1691
|
+
}
|
|
2155
1692
|
nextMessage() {
|
|
1693
|
+
let newCurrentMessage = void 0;
|
|
1694
|
+
let i = this.currentIndex;
|
|
2156
1695
|
const n = this.state.messages.length;
|
|
2157
1696
|
if (n === 0) {
|
|
2158
1697
|
return;
|
|
2159
1698
|
}
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
1699
|
+
while (!newCurrentMessage) {
|
|
1700
|
+
if (i === -1 || i === n - 1) {
|
|
1701
|
+
newCurrentMessage = this.state.messages[0];
|
|
1702
|
+
i = 0;
|
|
1703
|
+
} else if (i < n - 1) {
|
|
1704
|
+
newCurrentMessage = this.state.messages[i + 1];
|
|
1705
|
+
i++;
|
|
1706
|
+
}
|
|
1707
|
+
if (this.isValidToShow(newCurrentMessage)) {
|
|
1708
|
+
this.state.currentMessage = newCurrentMessage.clone();
|
|
1709
|
+
break;
|
|
1710
|
+
} else {
|
|
1711
|
+
newCurrentMessage = void 0;
|
|
1712
|
+
}
|
|
1713
|
+
if (i === this.currentIndex) {
|
|
1714
|
+
break;
|
|
1715
|
+
}
|
|
2166
1716
|
}
|
|
1717
|
+
this.currentIndex = i;
|
|
2167
1718
|
}
|
|
2168
1719
|
prevMessage() {
|
|
1720
|
+
let newCurrentMessage = void 0;
|
|
1721
|
+
let i = this.currentIndex;
|
|
2169
1722
|
const n = this.state.messages.length;
|
|
2170
1723
|
if (n === 0) {
|
|
2171
1724
|
return;
|
|
2172
1725
|
}
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
1726
|
+
while (!newCurrentMessage) {
|
|
1727
|
+
if (i === -1 || i === 0) {
|
|
1728
|
+
newCurrentMessage = this.state.messages[n - 1];
|
|
1729
|
+
i = n - 1;
|
|
1730
|
+
} else if (i > 0) {
|
|
1731
|
+
newCurrentMessage = this.state.messages[i - 1];
|
|
1732
|
+
i--;
|
|
1733
|
+
}
|
|
1734
|
+
if (this.isValidToShow(newCurrentMessage)) {
|
|
1735
|
+
this.state.currentMessage = newCurrentMessage.clone();
|
|
1736
|
+
break;
|
|
1737
|
+
} else {
|
|
1738
|
+
newCurrentMessage = void 0;
|
|
1739
|
+
}
|
|
1740
|
+
if (i === this.currentIndex) {
|
|
1741
|
+
break;
|
|
1742
|
+
}
|
|
2179
1743
|
}
|
|
1744
|
+
this.currentIndex = i;
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
var __defProp$3 = Object.defineProperty;
|
|
1749
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1750
|
+
var __publicField$3 = (obj, key, value) => {
|
|
1751
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1752
|
+
return value;
|
|
1753
|
+
};
|
|
1754
|
+
class FloatingChatController extends ChatController2 {
|
|
1755
|
+
constructor(props, onMessageSubmit, id, onMessageResponse) {
|
|
1756
|
+
super(props, onMessageSubmit, id, onMessageResponse);
|
|
1757
|
+
__publicField$3(this, "Window", observer(() => {
|
|
1758
|
+
return /* @__PURE__ */ jsx(
|
|
1759
|
+
IconButton,
|
|
1760
|
+
{
|
|
1761
|
+
icon: "Magic",
|
|
1762
|
+
size: "Md",
|
|
1763
|
+
variant: "icon-outline",
|
|
1764
|
+
onClick: () => {
|
|
1765
|
+
this.state.isVisible = true;
|
|
1766
|
+
this.open();
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
);
|
|
1770
|
+
}));
|
|
1771
|
+
makeObservable({ open: action });
|
|
1772
|
+
}
|
|
1773
|
+
open() {
|
|
1774
|
+
ApiaUtil.instance.modals.open({
|
|
1775
|
+
variant: "layout.common.chat.assistant.floatingAssistant",
|
|
1776
|
+
defaultPosition: {
|
|
1777
|
+
bottom: "10px",
|
|
1778
|
+
right: "50px"
|
|
1779
|
+
},
|
|
1780
|
+
draggable: true,
|
|
1781
|
+
children: /* @__PURE__ */ jsx(this.Renderer, {}),
|
|
1782
|
+
onClose: () => {
|
|
1783
|
+
this.state.isVisible = false;
|
|
1784
|
+
}
|
|
1785
|
+
});
|
|
2180
1786
|
}
|
|
2181
1787
|
}
|
|
2182
1788
|
|
|
1789
|
+
var __defProp$2 = Object.defineProperty;
|
|
1790
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1791
|
+
var __publicField$2 = (obj, key, value) => {
|
|
1792
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1793
|
+
return value;
|
|
1794
|
+
};
|
|
1795
|
+
function isPollProgress(payload) {
|
|
1796
|
+
return payload?.progress !== void 0;
|
|
1797
|
+
}
|
|
1798
|
+
class RoutinesGeneration {
|
|
1799
|
+
constructor() {
|
|
1800
|
+
__publicField$2(this, "audioRecorder", new AudioRecorder());
|
|
1801
|
+
__publicField$2(this, "routineId", "");
|
|
1802
|
+
__publicField$2(this, "state", {
|
|
1803
|
+
isLoading: false,
|
|
1804
|
+
progress: 0
|
|
1805
|
+
});
|
|
1806
|
+
makeObservable(this, {
|
|
1807
|
+
completion: action,
|
|
1808
|
+
state: observable,
|
|
1809
|
+
stop: action,
|
|
1810
|
+
transcribeAudio: action
|
|
1811
|
+
});
|
|
1812
|
+
}
|
|
1813
|
+
checkCanGenerate() {
|
|
1814
|
+
if (this.state.isLoading) {
|
|
1815
|
+
throw new Error("Cannot queue two simultaneous generations");
|
|
1816
|
+
}
|
|
1817
|
+
this.state.isLoading = true;
|
|
1818
|
+
}
|
|
1819
|
+
async pollRoutine(routineId, stream) {
|
|
1820
|
+
this.routineId = routineId;
|
|
1821
|
+
this.state.isLoading = true;
|
|
1822
|
+
return this.internalPollRoutine(stream);
|
|
1823
|
+
}
|
|
1824
|
+
async internalPollRoutine(stream) {
|
|
1825
|
+
while (this.state.isLoading) {
|
|
1826
|
+
const pollResult = await this.callRoutinePoll(this.routineId);
|
|
1827
|
+
if (isPollProgress(pollResult.payload)) {
|
|
1828
|
+
try {
|
|
1829
|
+
const res = JSON.parse(pollResult.payload.debug);
|
|
1830
|
+
if (res.length > 0) {
|
|
1831
|
+
res.forEach((c) => {
|
|
1832
|
+
console.log(JSON.parse(c));
|
|
1833
|
+
});
|
|
1834
|
+
}
|
|
1835
|
+
if (pollResult.payload.streamPart && stream) {
|
|
1836
|
+
stream.emit("part", pollResult.payload.streamPart);
|
|
1837
|
+
}
|
|
1838
|
+
this.state.progress = pollResult.payload.progress;
|
|
1839
|
+
} catch (e) {
|
|
1840
|
+
console.error(e);
|
|
1841
|
+
}
|
|
1842
|
+
} else if (pollResult.status === "FINISHED") {
|
|
1843
|
+
this.resetLoading();
|
|
1844
|
+
return pollResult.payload;
|
|
1845
|
+
} else if (pollResult.status === "ERROR") {
|
|
1846
|
+
this.resetLoading();
|
|
1847
|
+
throw new Error(pollResult.payload);
|
|
1848
|
+
} else {
|
|
1849
|
+
this.resetLoading();
|
|
1850
|
+
throw new Error("Wrong poll response");
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
return null;
|
|
1854
|
+
}
|
|
1855
|
+
async callAudioTranscription(audio) {
|
|
1856
|
+
const url = makeApiaUrl({
|
|
1857
|
+
action: "routineStart",
|
|
1858
|
+
routine: "transcription/Transcribe"
|
|
1859
|
+
});
|
|
1860
|
+
const response = await axios.post(url, audio.arrayBuffer(), {
|
|
1861
|
+
headers: {
|
|
1862
|
+
"Content-Type": "application/octet-stream"
|
|
1863
|
+
}
|
|
1864
|
+
});
|
|
1865
|
+
const result = await parseSuccessfulResponse(response, "");
|
|
1866
|
+
if (result?.orchestrator) {
|
|
1867
|
+
return result;
|
|
1868
|
+
}
|
|
1869
|
+
return null;
|
|
1870
|
+
}
|
|
1871
|
+
async callRoutinePoll(routineId) {
|
|
1872
|
+
const result = await ApiaApi.post(
|
|
1873
|
+
makeApiaUrl({
|
|
1874
|
+
action: "routinePoll",
|
|
1875
|
+
routineId
|
|
1876
|
+
})
|
|
1877
|
+
);
|
|
1878
|
+
if (result?.data?.orchestrator) {
|
|
1879
|
+
return JSON.parse(result.data.orchestrator);
|
|
1880
|
+
} else {
|
|
1881
|
+
throw new Error("Poll failed");
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
async callRoutineStart(routineName, parameters, images) {
|
|
1885
|
+
const result = await ApiaApi.post(
|
|
1886
|
+
makeApiaUrl({
|
|
1887
|
+
action: "routineStart",
|
|
1888
|
+
routine: routineName
|
|
1889
|
+
}),
|
|
1890
|
+
{
|
|
1891
|
+
postData: {
|
|
1892
|
+
images: JSON.stringify(images),
|
|
1893
|
+
...parameters
|
|
1894
|
+
},
|
|
1895
|
+
stringifyOptions: {
|
|
1896
|
+
arrayFormat: "repeat"
|
|
1897
|
+
},
|
|
1898
|
+
postDataTreatement: "stringify"
|
|
1899
|
+
}
|
|
1900
|
+
);
|
|
1901
|
+
return result?.data || null;
|
|
1902
|
+
}
|
|
1903
|
+
async executeRoutine(routineName, parameters, images, stream) {
|
|
1904
|
+
this.checkCanGenerate();
|
|
1905
|
+
try {
|
|
1906
|
+
const result = await this.callRoutineStart(
|
|
1907
|
+
routineName,
|
|
1908
|
+
parameters,
|
|
1909
|
+
images
|
|
1910
|
+
);
|
|
1911
|
+
if (result?.orchestrator?.routineId !== void 0) {
|
|
1912
|
+
this.routineId = result?.orchestrator.routineId;
|
|
1913
|
+
return this.internalPollRoutine(stream);
|
|
1914
|
+
} else {
|
|
1915
|
+
throw new Error("Cannot get routine id");
|
|
1916
|
+
}
|
|
1917
|
+
} catch (e) {
|
|
1918
|
+
this.resetLoading();
|
|
1919
|
+
throw e;
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
resetLoading() {
|
|
1923
|
+
this.state.isLoading = false;
|
|
1924
|
+
this.state.progress = 0;
|
|
1925
|
+
}
|
|
1926
|
+
async completion(params) {
|
|
1927
|
+
return this.executeRoutine(
|
|
1928
|
+
params.routineName,
|
|
1929
|
+
params.parameters ?? {},
|
|
1930
|
+
params.images ?? [],
|
|
1931
|
+
params.stream
|
|
1932
|
+
);
|
|
1933
|
+
}
|
|
1934
|
+
stop() {
|
|
1935
|
+
this.resetLoading();
|
|
1936
|
+
ApiaApi.get(
|
|
1937
|
+
makeApiaUrl({
|
|
1938
|
+
action: "routineStop",
|
|
1939
|
+
routineId: this.routineId
|
|
1940
|
+
})
|
|
1941
|
+
);
|
|
1942
|
+
}
|
|
1943
|
+
async transcribeAudio(audio) {
|
|
1944
|
+
const result = await this.callAudioTranscription(audio);
|
|
1945
|
+
if (result) {
|
|
1946
|
+
this.state.isLoading = true;
|
|
1947
|
+
if (result?.orchestrator?.routineId) {
|
|
1948
|
+
this.routineId = result?.orchestrator?.routineId;
|
|
1949
|
+
return await this.internalPollRoutine();
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
throw new Error("Something went wrong while transcribing the audio");
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
class DashboardsRoutinesGeneration extends RoutinesGeneration {
|
|
1957
|
+
constructor(dispatcher) {
|
|
1958
|
+
super();
|
|
1959
|
+
this.dispatcher = dispatcher;
|
|
1960
|
+
}
|
|
1961
|
+
blobToBase64(audio) {
|
|
1962
|
+
return new Promise((resolve, reject) => {
|
|
1963
|
+
const reader = new FileReader();
|
|
1964
|
+
reader.onloadend = () => {
|
|
1965
|
+
if (reader.result && typeof reader.result === "string") {
|
|
1966
|
+
const base64 = reader.result.split(",")[1];
|
|
1967
|
+
resolve(base64);
|
|
1968
|
+
} else {
|
|
1969
|
+
reject(new Error("Could not convert Blob to base64"));
|
|
1970
|
+
}
|
|
1971
|
+
};
|
|
1972
|
+
reader.onerror = reject;
|
|
1973
|
+
reader.readAsDataURL(audio);
|
|
1974
|
+
});
|
|
1975
|
+
}
|
|
1976
|
+
async callAudioTranscription(audio) {
|
|
1977
|
+
const audioBase64 = await this.blobToBase64(audio);
|
|
1978
|
+
const result = await this.dispatcher({
|
|
1979
|
+
action: "transcription",
|
|
1980
|
+
audioBase64
|
|
1981
|
+
});
|
|
1982
|
+
return result?.data || null;
|
|
1983
|
+
}
|
|
1984
|
+
async callRoutinePoll(routineId) {
|
|
1985
|
+
const result = await this.dispatcher({
|
|
1986
|
+
action: "routinePoll",
|
|
1987
|
+
routineId
|
|
1988
|
+
});
|
|
1989
|
+
if (result?.data?.orchestrator) {
|
|
1990
|
+
const parsed = JSON.parse(result.data.orchestrator);
|
|
1991
|
+
return parsed;
|
|
1992
|
+
}
|
|
1993
|
+
throw new Error("Poll failed");
|
|
1994
|
+
}
|
|
1995
|
+
async callRoutineStart(routineName, parameters, images) {
|
|
1996
|
+
const result = await this.dispatcher({
|
|
1997
|
+
action: "routineStart",
|
|
1998
|
+
routine: routineName,
|
|
1999
|
+
...parameters,
|
|
2000
|
+
images
|
|
2001
|
+
});
|
|
2002
|
+
return result?.data || null;
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
|
|
2006
|
+
var __defProp$1 = Object.defineProperty;
|
|
2007
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2008
|
+
var __publicField$1 = (obj, key, value) => {
|
|
2009
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2010
|
+
return value;
|
|
2011
|
+
};
|
|
2012
|
+
class ResponseStream extends EventEmitter {
|
|
2013
|
+
constructor() {
|
|
2014
|
+
super(...arguments);
|
|
2015
|
+
__publicField$1(this, "buffer", "");
|
|
2016
|
+
__publicField$1(this, "isRunning", false);
|
|
2017
|
+
__publicField$1(this, "locked", false);
|
|
2018
|
+
__publicField$1(this, "maxCompletionTime", 2);
|
|
2019
|
+
// s
|
|
2020
|
+
__publicField$1(this, "minPartSize", 2);
|
|
2021
|
+
__publicField$1(this, "partSize", 2);
|
|
2022
|
+
__publicField$1(this, "timing", 5);
|
|
2023
|
+
// ms
|
|
2024
|
+
__publicField$1(this, "waiting", []);
|
|
2025
|
+
}
|
|
2026
|
+
calculatePartSize() {
|
|
2027
|
+
const totalSize = this.buffer.length + this.waiting.reduce((a, b) => a + b.length, 0);
|
|
2028
|
+
this.partSize = Math.max(
|
|
2029
|
+
this.minPartSize,
|
|
2030
|
+
totalSize * this.timing / (this.maxCompletionTime * 1e3)
|
|
2031
|
+
);
|
|
2032
|
+
}
|
|
2033
|
+
emit(_, data) {
|
|
2034
|
+
if (this.locked) {
|
|
2035
|
+
this.waiting.push(data);
|
|
2036
|
+
} else {
|
|
2037
|
+
this.buffer += data;
|
|
2038
|
+
}
|
|
2039
|
+
this.calculatePartSize();
|
|
2040
|
+
this.run();
|
|
2041
|
+
}
|
|
2042
|
+
run() {
|
|
2043
|
+
if (!this.isRunning) {
|
|
2044
|
+
this.isRunning = true;
|
|
2045
|
+
const interval = setInterval(() => {
|
|
2046
|
+
this.locked = true;
|
|
2047
|
+
const choosedSize = Math.min(this.buffer.length, this.partSize);
|
|
2048
|
+
const part = this.buffer.slice(0, choosedSize);
|
|
2049
|
+
this.buffer = this.buffer.slice(choosedSize);
|
|
2050
|
+
while (this.waiting.length > 0) {
|
|
2051
|
+
const part2 = this.waiting.shift();
|
|
2052
|
+
if (part2) {
|
|
2053
|
+
this.buffer += part2;
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
this.locked = false;
|
|
2057
|
+
if (part) {
|
|
2058
|
+
super.emit("part", part);
|
|
2059
|
+
} else {
|
|
2060
|
+
this.isRunning = false;
|
|
2061
|
+
clearInterval(interval);
|
|
2062
|
+
}
|
|
2063
|
+
}, this.timing);
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
async function getImageFromDisk(inputProps) {
|
|
2069
|
+
return (await getImagesFromDisk({ ...inputProps, multiple: "false" }))[0] ?? null;
|
|
2070
|
+
}
|
|
2071
|
+
function getImagesFromDisk(inputProps) {
|
|
2072
|
+
return new Promise((resolve) => {
|
|
2073
|
+
const input = document.createElement("input");
|
|
2074
|
+
input.accept = "image/*";
|
|
2075
|
+
input.type = "file";
|
|
2076
|
+
input.style.display = "none";
|
|
2077
|
+
Object.assign(input, inputProps);
|
|
2078
|
+
document.body.append(input);
|
|
2079
|
+
input.addEventListener("change", (event) => {
|
|
2080
|
+
const target = event?.target;
|
|
2081
|
+
if (!target?.files)
|
|
2082
|
+
return;
|
|
2083
|
+
const retrievedImages = [];
|
|
2084
|
+
const sources = [...target.files ?? []];
|
|
2085
|
+
const checkResolve = () => {
|
|
2086
|
+
if (sources.length === retrievedImages.length) {
|
|
2087
|
+
resolve(retrievedImages.filter((c) => !!c));
|
|
2088
|
+
}
|
|
2089
|
+
};
|
|
2090
|
+
sources.forEach((file) => {
|
|
2091
|
+
if (file) {
|
|
2092
|
+
const reader = new FileReader();
|
|
2093
|
+
reader.onload = function(e) {
|
|
2094
|
+
const binary = e.target?.result?.split(",")[1];
|
|
2095
|
+
input.remove();
|
|
2096
|
+
retrievedImages.push({
|
|
2097
|
+
base64: binary,
|
|
2098
|
+
path: file.name
|
|
2099
|
+
});
|
|
2100
|
+
checkResolve();
|
|
2101
|
+
};
|
|
2102
|
+
reader.readAsDataURL(file);
|
|
2103
|
+
} else {
|
|
2104
|
+
retrievedImages.push(null);
|
|
2105
|
+
}
|
|
2106
|
+
checkResolve();
|
|
2107
|
+
});
|
|
2108
|
+
});
|
|
2109
|
+
input.click();
|
|
2110
|
+
});
|
|
2111
|
+
}
|
|
2112
|
+
|
|
2113
|
+
const ImageIcon = ({
|
|
2114
|
+
deletable,
|
|
2115
|
+
onClick,
|
|
2116
|
+
onRemove,
|
|
2117
|
+
src
|
|
2118
|
+
}) => {
|
|
2119
|
+
return /* @__PURE__ */ jsxs(Box, { className: "image_preview", children: [
|
|
2120
|
+
deletable && /* @__PURE__ */ jsx(IconButton, { icon: "Close", size: "Xs", iconSize: "Xs", onClick: onRemove }),
|
|
2121
|
+
/* @__PURE__ */ jsx("img", { src, onClick })
|
|
2122
|
+
] });
|
|
2123
|
+
};
|
|
2124
|
+
|
|
2125
|
+
function getSrcFromBase64(base64) {
|
|
2126
|
+
return `data:image/jpg;base64,${base64}`;
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2129
|
+
var __defProp = Object.defineProperty;
|
|
2130
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2131
|
+
var __publicField = (obj, key, value) => {
|
|
2132
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2133
|
+
return value;
|
|
2134
|
+
};
|
|
2135
|
+
class ImagesStore {
|
|
2136
|
+
constructor(images, multiple) {
|
|
2137
|
+
this.multiple = multiple;
|
|
2138
|
+
__publicField(this, "images", /* @__PURE__ */ new Map());
|
|
2139
|
+
__publicField(this, "selectedId", "");
|
|
2140
|
+
this.images = new Map(
|
|
2141
|
+
images.map((c) => {
|
|
2142
|
+
const id = uniqueId();
|
|
2143
|
+
return [id, { ...c, id }];
|
|
2144
|
+
})
|
|
2145
|
+
);
|
|
2146
|
+
this.selectedId = this.images.values().next().value.id;
|
|
2147
|
+
makeAutoObservable(this);
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
const GetImagesDescription = observer(({ store }) => {
|
|
2151
|
+
return /* @__PURE__ */ jsxs(
|
|
2152
|
+
Box,
|
|
2153
|
+
{
|
|
2154
|
+
className: "images_description_generator",
|
|
2155
|
+
...getVariant("layout.design.projectAnalysis.imagesLoader"),
|
|
2156
|
+
children: [
|
|
2157
|
+
/* @__PURE__ */ jsx(Box, { className: "images_sort_wrapper", children: /* @__PURE__ */ jsx(
|
|
2158
|
+
SortableList,
|
|
2159
|
+
{
|
|
2160
|
+
onSortChange: (ev) => {
|
|
2161
|
+
store.images = new Map(
|
|
2162
|
+
ev.map((c) => [
|
|
2163
|
+
c.props.id,
|
|
2164
|
+
c.props.additionalProps
|
|
2165
|
+
])
|
|
2166
|
+
);
|
|
2167
|
+
},
|
|
2168
|
+
children: [...store.images].map(([k, c]) => /* @__PURE__ */ jsx(SortableListItem, { additionalProps: c, id: c.id, children: /* @__PURE__ */ jsx(
|
|
2169
|
+
ImageIcon,
|
|
2170
|
+
{
|
|
2171
|
+
deletable: store.multiple,
|
|
2172
|
+
onClick: () => {
|
|
2173
|
+
store.selectedId = c.id;
|
|
2174
|
+
},
|
|
2175
|
+
onRemove: () => {
|
|
2176
|
+
store.images.delete(k);
|
|
2177
|
+
},
|
|
2178
|
+
src: getSrcFromBase64(c.base64 ?? "")
|
|
2179
|
+
}
|
|
2180
|
+
) }, c.id))
|
|
2181
|
+
}
|
|
2182
|
+
) }),
|
|
2183
|
+
/* @__PURE__ */ jsxs(Box, { className: "image_editor", children: [
|
|
2184
|
+
/* @__PURE__ */ jsx(Box, { className: "image_preview", children: store.images.get(store.selectedId) && /* @__PURE__ */ jsx(
|
|
2185
|
+
"img",
|
|
2186
|
+
{
|
|
2187
|
+
src: getSrcFromBase64(
|
|
2188
|
+
store.images.get(store.selectedId).base64 ?? ""
|
|
2189
|
+
)
|
|
2190
|
+
}
|
|
2191
|
+
) }),
|
|
2192
|
+
/* @__PURE__ */ jsxs(Box, { className: "image_description", children: [
|
|
2193
|
+
/* @__PURE__ */ jsx(
|
|
2194
|
+
Textarea,
|
|
2195
|
+
{
|
|
2196
|
+
autoFocus: true,
|
|
2197
|
+
disabled: !store.images.get(store.selectedId),
|
|
2198
|
+
onChange: (ev) => {
|
|
2199
|
+
const image = store.images.get(store.selectedId);
|
|
2200
|
+
if (image)
|
|
2201
|
+
image.description = ev.target.value;
|
|
2202
|
+
},
|
|
2203
|
+
value: store.images.get(store.selectedId)?.description
|
|
2204
|
+
}
|
|
2205
|
+
),
|
|
2206
|
+
store.multiple && /* @__PURE__ */ jsx(
|
|
2207
|
+
IconButton,
|
|
2208
|
+
{
|
|
2209
|
+
icon: "Attach",
|
|
2210
|
+
onClick: () => {
|
|
2211
|
+
getImagesFromDisk({ multiple: "true" }).then((res) => {
|
|
2212
|
+
res.forEach((c) => {
|
|
2213
|
+
const id = uniqueId();
|
|
2214
|
+
store.images.set(id, {
|
|
2215
|
+
base64: c.base64,
|
|
2216
|
+
description: "",
|
|
2217
|
+
id
|
|
2218
|
+
});
|
|
2219
|
+
});
|
|
2220
|
+
});
|
|
2221
|
+
},
|
|
2222
|
+
size: "Md",
|
|
2223
|
+
iconSize: "Sm",
|
|
2224
|
+
variant: "icon-only"
|
|
2225
|
+
}
|
|
2226
|
+
)
|
|
2227
|
+
] })
|
|
2228
|
+
] })
|
|
2229
|
+
]
|
|
2230
|
+
}
|
|
2231
|
+
);
|
|
2232
|
+
});
|
|
2233
|
+
function getImagesWithDescription({
|
|
2234
|
+
multiple
|
|
2235
|
+
}) {
|
|
2236
|
+
return new Promise((resolve) => {
|
|
2237
|
+
getImagesFromDisk({ multiple: multiple ? "true" : void 0 }).then(
|
|
2238
|
+
(images) => {
|
|
2239
|
+
const store = new ImagesStore(
|
|
2240
|
+
images.map((c) => ({
|
|
2241
|
+
base64: c.base64,
|
|
2242
|
+
description: ""
|
|
2243
|
+
})),
|
|
2244
|
+
multiple || false
|
|
2245
|
+
);
|
|
2246
|
+
ApiaUtil.instance.modals.open({
|
|
2247
|
+
children: /* @__PURE__ */ jsx(GetImagesDescription, { store }),
|
|
2248
|
+
initialFocusGetter(modalInnerRef) {
|
|
2249
|
+
return modalInnerRef.querySelector("textarea");
|
|
2250
|
+
},
|
|
2251
|
+
onConfirm: () => {
|
|
2252
|
+
resolve([...toJS(store.images).values()]);
|
|
2253
|
+
},
|
|
2254
|
+
onCancel() {
|
|
2255
|
+
resolve([]);
|
|
2256
|
+
},
|
|
2257
|
+
size: "xxxl-fixed",
|
|
2258
|
+
noHeader: true
|
|
2259
|
+
});
|
|
2260
|
+
}
|
|
2261
|
+
);
|
|
2262
|
+
});
|
|
2263
|
+
}
|
|
2264
|
+
|
|
2265
|
+
const ViewRendererContext = createContext(
|
|
2266
|
+
{}
|
|
2267
|
+
);
|
|
2268
|
+
|
|
2183
2269
|
const WindowDragger = forwardRef((props, outerRef) => {
|
|
2184
2270
|
const isDragging = useRef(false);
|
|
2185
2271
|
const initialPosition = useRef({ mousex: 0, mousey: 0, boxx: 0, boxy: 0 });
|
|
@@ -2256,5 +2342,5 @@ const WindowDragger = forwardRef((props, outerRef) => {
|
|
|
2256
2342
|
);
|
|
2257
2343
|
});
|
|
2258
2344
|
|
|
2259
|
-
export { AIFileContent, AIMessageAttachments, AutoscrollContainer, ChatController, ChatController2, ChatMessage, DashboardsRoutinesGeneration, MultipleChoiceMessage, ResponseStream, RoutinesGeneration, SearchController, SemanticSearchReference as SemanticSearchResult, ViewRendererContext, WindowDragger, getImageFromDisk, getImagesFromDisk, getImagesWithDescription };
|
|
2345
|
+
export { AIFileContent, AIMessageAttachments, AutoscrollContainer, ChatController, ChatController2, ChatMessage, DashboardsRoutinesGeneration, FloatingChatController, MultipleChoiceMessage, ResponseStream, RoutinesGeneration, SearchController$1 as SearchController, SemanticSearchReference as SemanticSearchResult, ViewRendererContext, WindowDragger, getImageFromDisk, getImagesFromDisk, getImagesWithDescription };
|
|
2260
2346
|
//# sourceMappingURL=index.js.map
|