@eka-care/medassist-core 1.0.8 → 1.0.9
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/constants/index.js +2 -2
- package/dist/events/types.d.ts +7 -3
- package/dist/events/types.d.ts.map +1 -1
- package/dist/media/file/File.d.ts +6 -23
- package/dist/media/file/File.d.ts.map +1 -1
- package/dist/media/file/File.js +67 -84
- package/dist/messages/MessageManager.d.ts +1 -1
- package/dist/messages/MessageManager.d.ts.map +1 -1
- package/dist/messages/MessageManager.js +16 -9
- package/dist/messages/types.d.ts +1 -1
- package/dist/messages/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/constants/index.js
CHANGED
|
@@ -6,8 +6,8 @@ const PRODUCTION_CONFIG = {
|
|
|
6
6
|
BASE_API_URL: "https://matrix.eka.care/reloaded",
|
|
7
7
|
};
|
|
8
8
|
// const PRODUCTION_CONFIG = {
|
|
9
|
-
// WEBSOCKET_URL: "ws://
|
|
10
|
-
// BASE_API_URL: "https://
|
|
9
|
+
// WEBSOCKET_URL: "ws://87677104b49f.ngrok-free.app/reloaded",
|
|
10
|
+
// BASE_API_URL: "https://87677104b49f.ngrok-free.app/reloaded",
|
|
11
11
|
// }
|
|
12
12
|
const DEVELOPMENT_CONFIG = {
|
|
13
13
|
// can be used for local development
|
package/dist/events/types.d.ts
CHANGED
|
@@ -33,11 +33,11 @@ export interface ChatSynapseToMatrixMessage extends BaseMessage {
|
|
|
33
33
|
ev: (typeof SOCKET_EVENTS)["CHAT"];
|
|
34
34
|
ct: (typeof SOCKET_CONTENT_TYPES)["TEXT"] | (typeof SOCKET_CONTENT_TYPES)["FILE"] | (typeof SOCKET_CONTENT_TYPES)["TOOL_CALL"] | (typeof SOCKET_CONTENT_TYPES)["AUDIO"];
|
|
35
35
|
data?: {
|
|
36
|
-
|
|
36
|
+
urls?: string[];
|
|
37
37
|
text?: string;
|
|
38
38
|
tool_id?: string;
|
|
39
39
|
hidden?: boolean;
|
|
40
|
-
|
|
40
|
+
extensions?: string[];
|
|
41
41
|
tool_use_params?: any;
|
|
42
42
|
audio?: string;
|
|
43
43
|
format?: string;
|
|
@@ -66,11 +66,15 @@ export type ToolCallData = {
|
|
|
66
66
|
details?: ToolDetails;
|
|
67
67
|
_meta?: Record<string, unknown>;
|
|
68
68
|
};
|
|
69
|
+
export interface presignedUrls {
|
|
70
|
+
id: string;
|
|
71
|
+
url: string;
|
|
72
|
+
}
|
|
69
73
|
export interface ChatMatrixToSynapseMessage extends BaseMessage {
|
|
70
74
|
ev: (typeof SOCKET_EVENTS)["CHAT"];
|
|
71
75
|
ct: Exclude<SOCKET_CONTENT_TYPES, (typeof SOCKET_CONTENT_TYPES)["AUDIO"]>;
|
|
72
76
|
data: {
|
|
73
|
-
urls?:
|
|
77
|
+
urls?: presignedUrls[];
|
|
74
78
|
exp?: number;
|
|
75
79
|
text?: string;
|
|
76
80
|
tips?: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/events/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,WAAW,EACjB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE/D,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,aAAa,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;CACZ;AACD,MAAM,WAAW,WAAY,SAAQ,WAAW;IAC9C,EAAE,EAAE,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,WAAY,SAAQ,WAAW;IAC9C,EAAE,EAAE,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,EAAE,EAAE,C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,EAAE,CAAC;KACjB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CAC3B;AAED,MAAM,WAAW,4BAA6B,SAAQ,WAAW;IAC/D,EAAE,EAAE,CAAC,OAAO,aAAa,CAAC,CAAC,QAAQ,CAAC,CAAC;IACrC,EAAE,EACE,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,GACrC,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,GACrC,CAAC,OAAO,oBAAoB,CAAC,CAAC,WAAW,CAAC,GAC1C,CAAC,OAAO,oBAAoB,CAAC,CAAC,YAAY,CAAC,GAC3C,CAAC,OAAO,oBAAoB,CAAC,CAAC,UAAU,CAAC,CAAA;IAC7C,IAAI,EAAE;QACJ,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;KACjB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CAC3B;AAED,MAAM,WAAW,iCAAkC,SAAQ,WAAW;IACpE,EAAE,EAAE,CAAC,OAAO,aAAa,CAAC,CAAC,eAAe,CAAC,CAAC;IAC5C,EAAE,EAAE,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;CAC3C"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { type presignedUrls } from "../../events/types";
|
|
2
|
+
export declare const MAX_FILE_SIZE: number;
|
|
1
3
|
export declare class Filemanager {
|
|
2
4
|
private pendingFiles;
|
|
3
5
|
private pendingMessage?;
|
|
4
|
-
private
|
|
6
|
+
private pendingFormats;
|
|
5
7
|
/**
|
|
6
8
|
* Set the files for upload
|
|
7
9
|
*/
|
|
@@ -12,19 +14,12 @@ export declare class Filemanager {
|
|
|
12
14
|
getPendingFileState(): {
|
|
13
15
|
files: File[];
|
|
14
16
|
message: string;
|
|
15
|
-
|
|
17
|
+
formats: string[];
|
|
16
18
|
};
|
|
17
19
|
/**
|
|
18
20
|
* Upload files to presigned URLs
|
|
19
21
|
*/
|
|
20
|
-
uploadFilesToPresignedUrl(presignedUrls:
|
|
21
|
-
/**
|
|
22
|
-
* Zips multiple files into a single zip file
|
|
23
|
-
* @param files Array of files to zip
|
|
24
|
-
* @param zipFileName Name for the zip file (without extension)
|
|
25
|
-
* @returns Promise<Blob> - The zipped file as a blob
|
|
26
|
-
*/
|
|
27
|
-
zipFiles(): Promise<Blob>;
|
|
22
|
+
uploadFilesToPresignedUrl(presignedUrls: presignedUrls[]): Promise<string[]>;
|
|
28
23
|
/**
|
|
29
24
|
* Creates a File object from a blob with a specific name
|
|
30
25
|
* @param blob The blob to convert
|
|
@@ -32,24 +27,12 @@ export declare class Filemanager {
|
|
|
32
27
|
* @returns File object
|
|
33
28
|
*/
|
|
34
29
|
blobToFile(blob: Blob, fileName: string): File;
|
|
35
|
-
/**
|
|
36
|
-
* Checks if multiple files should be zipped
|
|
37
|
-
* @param files Array of files
|
|
38
|
-
* @returns boolean - true if files should be zipped
|
|
39
|
-
*/
|
|
40
|
-
shouldZipFiles(): boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Gets the appropriate file name for upload (either zip or single file)
|
|
43
|
-
* @param files Array of files
|
|
44
|
-
* @returns string - the file name to use for upload
|
|
45
|
-
*/
|
|
46
|
-
getUploadFileName(): string;
|
|
47
30
|
/**
|
|
48
31
|
* Validate file types
|
|
49
32
|
* @param file The file to validate
|
|
50
33
|
* @returns boolean - true if file type is supported
|
|
51
34
|
*/
|
|
52
|
-
|
|
35
|
+
validateFile(file: File): boolean;
|
|
53
36
|
/**
|
|
54
37
|
* Clears the pending files
|
|
55
38
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"File.d.ts","sourceRoot":"","sources":["../../../src/media/file/File.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"File.d.ts","sourceRoot":"","sources":["../../../src/media/file/File.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,eAAO,MAAM,aAAa,QAAkB,CAAC;AAC7C,qBAAa,WAAW;IACtB,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,cAAc,CAAC,CAAc;IACrC,OAAO,CAAC,cAAc,CAAgB;IAEtC;;OAEG;IACI,iBAAiB,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAkB/D;;OAEG;IAEI,mBAAmB,IAAI;QAC5B,KAAK,EAAE,IAAI,EAAE,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,MAAM,EAAE,CAAC;KACnB;IAQD;;OAEG;IACU,yBAAyB,CACpC,aAAa,EAAE,aAAa,EAAE,GAC7B,OAAO,CAAC,MAAM,EAAE,CAAC;IAgFpB;;;;;OAKG;IACI,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAyBrD;;;;OAIG;IACI,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAgBxC;;OAEG;IACI,sBAAsB,IAAI,IAAI;CAKtC"}
|
package/dist/media/file/File.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Filemanager = void 0;
|
|
3
|
+
exports.Filemanager = exports.MAX_FILE_SIZE = void 0;
|
|
7
4
|
/**
|
|
8
5
|
* Class to store file states
|
|
9
6
|
* Helpers: Zipping, uploading to presigned url, etc.
|
|
10
7
|
*/
|
|
11
|
-
const jszip_1 = __importDefault(require("jszip"));
|
|
12
8
|
const Error_1 = require("../../internal/Error/Error");
|
|
9
|
+
exports.MAX_FILE_SIZE = 3 * 1024 * 1024; // 3MB
|
|
13
10
|
class Filemanager {
|
|
14
11
|
pendingFiles = [];
|
|
15
12
|
pendingMessage = "";
|
|
16
|
-
|
|
13
|
+
pendingFormats = [];
|
|
17
14
|
/**
|
|
18
15
|
* Set the files for upload
|
|
19
16
|
*/
|
|
@@ -21,9 +18,9 @@ class Filemanager {
|
|
|
21
18
|
if (this.pendingFiles.length > 0) {
|
|
22
19
|
this.clearPendingFilesState();
|
|
23
20
|
}
|
|
24
|
-
const validFiles = files.filter((file) => this.
|
|
21
|
+
const validFiles = files.filter((file) => this.validateFile(file));
|
|
25
22
|
if (validFiles.length === 0) {
|
|
26
|
-
throw new Error_1.FileError("
|
|
23
|
+
throw new Error_1.FileError("File not supported", {
|
|
27
24
|
context: { stage: "setFilesForUpload" },
|
|
28
25
|
});
|
|
29
26
|
}
|
|
@@ -31,8 +28,8 @@ class Filemanager {
|
|
|
31
28
|
if (message && message.trim()) {
|
|
32
29
|
this.pendingMessage = message;
|
|
33
30
|
}
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
console.log("validFiles", validFiles);
|
|
32
|
+
this.pendingFormats = validFiles.map(file => file.type);
|
|
36
33
|
}
|
|
37
34
|
/**
|
|
38
35
|
* Get the pending file state
|
|
@@ -41,86 +38,72 @@ class Filemanager {
|
|
|
41
38
|
return {
|
|
42
39
|
files: this.pendingFiles,
|
|
43
40
|
message: this.pendingMessage || "",
|
|
44
|
-
|
|
41
|
+
formats: this.pendingFormats || [],
|
|
45
42
|
};
|
|
46
43
|
}
|
|
47
44
|
/**
|
|
48
45
|
* Upload files to presigned URLs
|
|
49
46
|
*/
|
|
50
47
|
async uploadFilesToPresignedUrl(presignedUrls) {
|
|
51
|
-
let
|
|
48
|
+
let successIds = [];
|
|
52
49
|
// Filter out invalid URLs
|
|
53
|
-
const validUrls = presignedUrls.filter((url) => url && url.trim());
|
|
50
|
+
const validUrls = presignedUrls.filter((url) => url.url && url.url.trim());
|
|
54
51
|
try {
|
|
55
52
|
if (validUrls.length === 0) {
|
|
56
53
|
throw new Error_1.FileError("No valid presigned URLs provided", {
|
|
57
54
|
context: { stage: "uploadFilesToPresignedUrl" },
|
|
58
55
|
});
|
|
59
56
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const zipBlob = await this.zipFiles();
|
|
65
|
-
const zipFileName = this.getUploadFileName();
|
|
66
|
-
fileToUpload = this.blobToFile(zipBlob, zipFileName);
|
|
67
|
-
contentType = "application/zip";
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
// Single file, upload as is
|
|
71
|
-
fileToUpload = this.pendingFiles?.[0];
|
|
72
|
-
contentType = fileToUpload.type;
|
|
57
|
+
if (!this.pendingFiles.length) {
|
|
58
|
+
throw new Error_1.FileError("No files to upload", {
|
|
59
|
+
context: { stage: "uploadFilesToPresignedUrl" },
|
|
60
|
+
});
|
|
73
61
|
}
|
|
74
|
-
// Upload to all presigned URLs
|
|
75
62
|
for (let i = 0; i < validUrls.length; i++) {
|
|
76
|
-
const url = validUrls[i];
|
|
63
|
+
const url = validUrls[i].url;
|
|
77
64
|
const response = await fetch(url, {
|
|
78
65
|
method: "PUT",
|
|
79
|
-
body:
|
|
66
|
+
body: this.pendingFiles[i],
|
|
80
67
|
headers: {
|
|
81
|
-
"Content-Type":
|
|
68
|
+
"Content-Type": this.pendingFiles[i].type,
|
|
82
69
|
"x-ms-blob-type": "BlockBlob",
|
|
83
70
|
},
|
|
84
71
|
});
|
|
85
72
|
if (!response.ok) {
|
|
86
|
-
throw new Error_1.FileError(`Failed to upload ${
|
|
87
|
-
context: {
|
|
88
|
-
stage: "uploadFilesToPresignedUrl",
|
|
89
|
-
status: response.status,
|
|
90
|
-
url,
|
|
91
|
-
},
|
|
73
|
+
throw new Error_1.FileError(`Failed to upload ${this.pendingFiles[i].name} to URL ${i + 1}: ${response.status} ${response.statusText}`, {
|
|
74
|
+
context: { stage: "uploadFilesToPresignedUrl" },
|
|
92
75
|
});
|
|
93
76
|
}
|
|
94
|
-
|
|
77
|
+
successIds.push(validUrls[i].id);
|
|
95
78
|
}
|
|
96
79
|
// Call sendFileUploadComplete only once with the first presigned URL
|
|
97
80
|
// this.sendFileUploadComplete(validUrls[0]);
|
|
98
|
-
return
|
|
81
|
+
return successIds;
|
|
99
82
|
}
|
|
100
83
|
catch (error) {
|
|
101
|
-
if (
|
|
84
|
+
if (successIds.length > 0) {
|
|
102
85
|
// this.sendFileUploadComplete(validUrls[0]);
|
|
103
|
-
return
|
|
86
|
+
return successIds;
|
|
104
87
|
}
|
|
105
88
|
throw (0, Error_1.normalizeError)(error, Error_1.FileError, "Failed to upload files to presigned URL", { context: { stage: "uploadFilesToPresignedUrl" } });
|
|
106
89
|
}
|
|
107
90
|
}
|
|
108
|
-
/**
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
async zipFiles() {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
91
|
+
// /**
|
|
92
|
+
// * Zips multiple files into a single zip file
|
|
93
|
+
// * @param files Array of files to zip
|
|
94
|
+
// * @param zipFileName Name for the zip file (without extension)
|
|
95
|
+
// * @returns Promise<Blob> - The zipped file as a blob
|
|
96
|
+
// */
|
|
97
|
+
// public async zipFiles(): Promise<Blob> {
|
|
98
|
+
// const zip = new JSZip();
|
|
99
|
+
// // Add each file to the zip
|
|
100
|
+
// this.pendingFiles.forEach((file) => {
|
|
101
|
+
// zip.file(file.name, file);
|
|
102
|
+
// });
|
|
103
|
+
// // Generate the zip file as a blob
|
|
104
|
+
// const zipBlob = await zip.generateAsync({ type: "blob" });
|
|
105
|
+
// return zipBlob;
|
|
106
|
+
// }
|
|
124
107
|
/**
|
|
125
108
|
* Creates a File object from a blob with a specific name
|
|
126
109
|
* @param blob The blob to convert
|
|
@@ -130,44 +113,44 @@ class Filemanager {
|
|
|
130
113
|
blobToFile(blob, fileName) {
|
|
131
114
|
return new File([blob], fileName, { type: blob.type });
|
|
132
115
|
}
|
|
133
|
-
/**
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
shouldZipFiles() {
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
getUploadFileName() {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
116
|
+
// /**
|
|
117
|
+
// * Checks if multiple files should be zipped
|
|
118
|
+
// * @param files Array of files
|
|
119
|
+
// * @returns boolean - true if files should be zipped
|
|
120
|
+
// */
|
|
121
|
+
// public shouldZipFiles(): boolean {
|
|
122
|
+
// return this.pendingFiles.length > 1;
|
|
123
|
+
// }
|
|
124
|
+
// /**
|
|
125
|
+
// * Gets the appropriate file name for upload (either zip or single file)
|
|
126
|
+
// * @param files Array of files
|
|
127
|
+
// * @returns string - the file name to use for upload
|
|
128
|
+
// */
|
|
129
|
+
// public getUploadFileName(): string {
|
|
130
|
+
// if (this.shouldZipFiles()) {
|
|
131
|
+
// return `uploaded_files_${Date.now()}.zip`;
|
|
132
|
+
// }
|
|
133
|
+
// return this.pendingFiles[0]?.name || "file";
|
|
134
|
+
// }
|
|
152
135
|
/**
|
|
153
136
|
* Validate file types
|
|
154
137
|
* @param file The file to validate
|
|
155
138
|
* @returns boolean - true if file type is supported
|
|
156
139
|
*/
|
|
157
|
-
|
|
140
|
+
validateFile(file) {
|
|
158
141
|
const validFormats = [
|
|
159
142
|
"application/pdf",
|
|
160
143
|
"image/jpeg",
|
|
161
144
|
"image/png",
|
|
162
145
|
"image/jpg",
|
|
163
|
-
"image/tiff",
|
|
164
|
-
"text/plain",
|
|
165
|
-
"text/markdown",
|
|
166
|
-
"image/heif",
|
|
167
|
-
"image/heic",
|
|
168
|
-
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
146
|
+
// "image/tiff",
|
|
147
|
+
// "text/plain",
|
|
148
|
+
// "text/markdown",
|
|
149
|
+
// "image/heif",
|
|
150
|
+
// "image/heic",
|
|
151
|
+
// "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
169
152
|
];
|
|
170
|
-
return validFormats.includes(file.type);
|
|
153
|
+
return validFormats.includes(file.type) && file.size < exports.MAX_FILE_SIZE;
|
|
171
154
|
}
|
|
172
155
|
/**
|
|
173
156
|
* Clears the pending files
|
|
@@ -175,7 +158,7 @@ class Filemanager {
|
|
|
175
158
|
clearPendingFilesState() {
|
|
176
159
|
this.pendingFiles = [];
|
|
177
160
|
this.pendingMessage = "";
|
|
178
|
-
this.
|
|
161
|
+
this.pendingFormats = [];
|
|
179
162
|
}
|
|
180
163
|
}
|
|
181
164
|
exports.Filemanager = Filemanager;
|
|
@@ -21,7 +21,7 @@ export declare class MessageManager {
|
|
|
21
21
|
/**
|
|
22
22
|
* send chat message through socket
|
|
23
23
|
*/
|
|
24
|
-
sendSocketMessage({ message, files, audio,
|
|
24
|
+
sendSocketMessage({ message, files, audio, urls, tool_declined, tool_id, initial_prompts }: SocketChatRequestData): void;
|
|
25
25
|
/**
|
|
26
26
|
* Handle incoming chat message
|
|
27
27
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageManager.d.ts","sourceRoot":"","sources":["../../src/messages/MessageManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,OAAO,EAGL,KAAK,yBAAyB,EAC9B,KAAK,2BAA2B,EAChC,KAAK,0BAA0B,EAC/B,KAAK,gCAAgC,EACtC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAEvE,OAAO,EAEL,KAAK,qBAAqB,EAI3B,MAAM,SAAS,CAAC;A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AC3C,QAAQ,EAAE,gCAAgC,GACzC,IAAI;IAOP;;OAEG;IACI,gCAAgC,CACrC,OAAO,EAAE,0BAA0B,GAClC,IAAI;IAoBP;;OAEG;IACI,qBAAqB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;IAWxD;;OAEG;IACI,qBAAqB,IAAI,IAAI;IAUpC;;OAEG;IACU,cAAc,CAAC,EAC1B,QAAQ,EACR,OAAO,GACR,EAAE;QACD,QAAQ,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC;QAC1C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;KAClC,GAAG,OAAO,CAAC,IAAI,CAAC;IAmCjB;;OAEG;IACI,sBAAsB,IAAI,IAAI;IAsBrC;;OAEG;IACI,qBAAqB,IAAI,IAAI;IAU7B,2BAA2B,IAAI,IAAI;IAM1C;;OAEG;IACI,yBAAyB,IAAI,IAAI;IAkBxC,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,gBAAgB;IAYxB,OAAO,CAAC,gBAAgB;CAsCzB"}
|
|
@@ -18,7 +18,7 @@ class MessageManager {
|
|
|
18
18
|
/**
|
|
19
19
|
* Handle file upload process
|
|
20
20
|
*/
|
|
21
|
-
handleFileUploadProcess({ files, message,
|
|
21
|
+
handleFileUploadProcess({ files, message, urls, }) {
|
|
22
22
|
if (!this.fileManager) {
|
|
23
23
|
this.fileManager = new File_1.Filemanager();
|
|
24
24
|
}
|
|
@@ -33,11 +33,11 @@ class MessageManager {
|
|
|
33
33
|
_id: Date.now().toString(),
|
|
34
34
|
ts: Date.now(),
|
|
35
35
|
data: {
|
|
36
|
-
|
|
36
|
+
extensions: this.fileManager.getPendingFileState().formats,
|
|
37
37
|
},
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
-
else if (
|
|
40
|
+
else if (urls && urls.length > 0) {
|
|
41
41
|
//--stage 3. of file upload process
|
|
42
42
|
//--only requirement is url
|
|
43
43
|
//--send file upload acknowledgement to client
|
|
@@ -48,7 +48,7 @@ class MessageManager {
|
|
|
48
48
|
_id: Date.now().toString(),
|
|
49
49
|
ts: Date.now(),
|
|
50
50
|
data: {
|
|
51
|
-
|
|
51
|
+
urls: urls,
|
|
52
52
|
...(text && { text }),
|
|
53
53
|
},
|
|
54
54
|
};
|
|
@@ -59,14 +59,21 @@ class MessageManager {
|
|
|
59
59
|
/**
|
|
60
60
|
* send chat message through socket
|
|
61
61
|
*/
|
|
62
|
-
sendSocketMessage({ message, files, audio,
|
|
62
|
+
sendSocketMessage({ message, files, audio, urls, tool_declined, tool_id, initial_prompts }) {
|
|
63
63
|
const connection = this.assertConnection("sendSocketChatMessage");
|
|
64
64
|
let outMessage;
|
|
65
|
-
if ((files && files.length > 0) || (
|
|
65
|
+
if ((files && files.length > 0) || (urls && urls.length > 0)) {
|
|
66
|
+
if (files && files.length > 3) {
|
|
67
|
+
const error = new Error_1.MessageError("Maximum 3 files are allowed to be sent at a time", {
|
|
68
|
+
context: { stage: "sendSocketChatMessage" },
|
|
69
|
+
});
|
|
70
|
+
this.emitError(error);
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
66
73
|
outMessage = this.handleFileUploadProcess({
|
|
67
74
|
files,
|
|
68
75
|
message,
|
|
69
|
-
|
|
76
|
+
urls,
|
|
70
77
|
});
|
|
71
78
|
}
|
|
72
79
|
else if (message) {
|
|
@@ -116,9 +123,9 @@ class MessageManager {
|
|
|
116
123
|
//stage 2. of file upload process
|
|
117
124
|
this.fileManager
|
|
118
125
|
?.uploadFilesToPresignedUrl(message.data.urls)
|
|
119
|
-
.then(() => {
|
|
126
|
+
.then((validUrls) => {
|
|
120
127
|
this.sendSocketMessage({
|
|
121
|
-
|
|
128
|
+
urls: validUrls,
|
|
122
129
|
});
|
|
123
130
|
})
|
|
124
131
|
.catch((error) => {
|
package/dist/messages/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/messages/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,oBAAoB,EACpB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,eAAO,MAAM,qBAAqB;;;;;;;;;CAAuB,CAAC;AAE1D,MAAM,MAAM,WAAW,GAAG,oBAAoB,CAAC;AAE/C,MAAM,MAAM,eAAe,GAAG,qBAAqB,CAAC;AACpD,MAAM,MAAM,eAAe,GAAG,qBAAqB,CAAC;AAEpD,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;IACf,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/messages/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,oBAAoB,EACpB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,eAAO,MAAM,qBAAqB;;;;;;;;;CAAuB,CAAC;AAE1D,MAAM,MAAM,WAAW,GAAG,oBAAoB,CAAC;AAE/C,MAAM,MAAM,eAAe,GAAG,qBAAqB,CAAC;AACpD,MAAM,MAAM,eAAe,GAAG,qBAAqB,CAAC;AAEpD,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAA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AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,CAAC,WAAW,EAAE,MAAM,GAAG;QACrB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,aAAa,CAAC,EAAE,WAAW,EAAE,CAAC;KAC/B,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,YAAY,CAAC,EAAE,aAAa,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,oBAAoB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eka-care/medassist-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "TypeScript SDK for real-time medical chatbot experiences with session management, WebSocket connectivity, and media handling",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|