@eka-care/medassist-core 1.0.2 → 1.0.4
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/Synapse.d.ts +9 -9
- package/dist/Synapse.d.ts.map +1 -1
- package/dist/Synapse.js +33 -62
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/internal/Error/Error.d.ts +2 -0
- package/dist/internal/Error/Error.d.ts.map +1 -1
- package/dist/internal/Error/Error.js +3 -0
- package/dist/media/audio/Audio.d.ts +2 -3
- package/dist/media/audio/Audio.d.ts.map +1 -1
- package/dist/media/audio/Audio.js +5 -10
- package/dist/media/audio/types.d.ts +0 -9
- package/dist/media/audio/types.d.ts.map +1 -1
- package/dist/media/audio/types.js +12 -8
- package/dist/media/file/File.d.ts +1 -3
- package/dist/media/file/File.d.ts.map +1 -1
- package/dist/media/file/File.js +1 -5
- package/dist/messages/MessageManager.d.ts +6 -10
- package/dist/messages/MessageManager.d.ts.map +1 -1
- package/dist/messages/MessageManager.js +99 -85
- package/dist/messages/types.d.ts +1 -1
- package/dist/messages/types.d.ts.map +1 -1
- package/package.json +6 -3
package/dist/Synapse.d.ts
CHANGED
|
@@ -3,30 +3,26 @@
|
|
|
3
3
|
* Provides a simple interface for managing chat sessions
|
|
4
4
|
*/
|
|
5
5
|
import { ConnectionType } from "./connection/ConnectionFactory";
|
|
6
|
-
import { ConnectionStatus } from "./internal/connection/types";
|
|
7
6
|
import { type Environment } from "./constants";
|
|
8
7
|
import { SYNAPSE_REALTIME_EVENTS } from "./messages/types";
|
|
9
8
|
import { SynapseError } from "./internal/Error/Error";
|
|
10
9
|
import { type SessionResponse } from "./resources/session/types";
|
|
11
|
-
import {
|
|
10
|
+
import { type AudioMetaData } from "./media/audio/types";
|
|
12
11
|
export interface SendMessageOptions {
|
|
13
12
|
message?: string;
|
|
14
13
|
messageId?: string;
|
|
15
14
|
files?: File[];
|
|
16
|
-
|
|
17
|
-
tool_use_params?: Record<string, unknown>;
|
|
18
|
-
hidden?: boolean;
|
|
15
|
+
audio?: AudioMetaData;
|
|
19
16
|
}
|
|
20
17
|
export interface SynapseSDKOverrides {
|
|
21
18
|
prompt?: string;
|
|
22
19
|
firstMessage?: string;
|
|
23
20
|
language?: string;
|
|
21
|
+
primaryColor?: string;
|
|
24
22
|
}
|
|
25
23
|
export type SynapseSDKError = SynapseError | Error;
|
|
26
24
|
export interface SynapseSDKCallbacks {
|
|
27
25
|
onSessionRefreshed?: (sessionResponse: SessionResponse) => void;
|
|
28
|
-
onConnectionStatusChange?: (status: ConnectionStatus) => void;
|
|
29
|
-
onRecordingStatusChange?: (status: AudioRecordingStatus) => void;
|
|
30
26
|
onError?: (error: SynapseSDKError) => void;
|
|
31
27
|
}
|
|
32
28
|
export interface SynapseSDKConfig {
|
|
@@ -61,7 +57,7 @@ export declare class SynapseSDK {
|
|
|
61
57
|
/**
|
|
62
58
|
* Send a message conetnt will be text always
|
|
63
59
|
*/
|
|
64
|
-
sendMessage({ message,
|
|
60
|
+
sendMessage({ message, files, audio, }: SendMessageOptions): Promise<void>;
|
|
65
61
|
/**
|
|
66
62
|
* Register a listener for a specific event
|
|
67
63
|
*/
|
|
@@ -77,11 +73,15 @@ export declare class SynapseSDK {
|
|
|
77
73
|
/**
|
|
78
74
|
* Send audio
|
|
79
75
|
* */
|
|
80
|
-
startRecording(
|
|
76
|
+
startRecording({ onChunks, onError, }: {
|
|
77
|
+
onChunks: (chunks: AudioMetaData) => void;
|
|
78
|
+
onError?: (error: Error) => void;
|
|
79
|
+
}): Promise<void>;
|
|
81
80
|
/**
|
|
82
81
|
* Stop recording audio
|
|
83
82
|
*/
|
|
84
83
|
endRecording(): void;
|
|
84
|
+
isConnected(): boolean;
|
|
85
85
|
/**
|
|
86
86
|
* End the session
|
|
87
87
|
*/
|
package/dist/Synapse.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Synapse.d.ts","sourceRoot":"","sources":["../src/Synapse.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAEL,cAAc,EACf,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"Synapse.d.ts","sourceRoot":"","sources":["../src/Synapse.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAEL,cAAc,EACf,MAAM,gCAAgC,CAAC;AAKxC,OAAO,EAAE,KAAK,WAAW,EAAa,MAAM,aAAa,CAAC;AAI1D,OAAO,EACL,uBAAuB,EAExB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAML,YAAY,EAEb,MAAM,wBAAwB,CAAC;AAShC,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;IACf,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB;AACD,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG,KAAK,CAAC;AACnD,MAAM,WAAW,mBAAmB;IAClC,kBAAkB,CAAC,EAAE,CAAC,eAAe,EAAE,eAAe,KAAK,IAAI,CAAC;IAGhE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;CAC5C;AACD,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,MAAM,CAAC,EAAE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;IAgCjB;;OAEG;IACI,YAAY,IAAI,IAAI;IAmCpB,WAAW,IAAI,OAAO;IAG7B;;OAEG;IACI,UAAU,IAAI,IAAI;IAUzB,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,cAAc;IAYtB;;;OAGG;YACW,oBAAoB;IAwClC;;;OAGG;YACW,aAAa;IA2C3B;;OAEG;YACW,cAAc;IAwB5B;;OAEG;YACW,gBAAgB;IAM9B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAwC1B;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAW/B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAe9B;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAgD/B;;OAEG;YACW,mBAAmB;IAmCjC,OAAO,CAAC,iBAAiB;CAW1B"}
|
package/dist/Synapse.js
CHANGED
|
@@ -6,12 +6,11 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.SynapseSDK = void 0;
|
|
8
8
|
const ConnectionFactory_1 = require("./connection/ConnectionFactory");
|
|
9
|
-
const types_1 = require("./internal/connection/types");
|
|
10
9
|
const constants_1 = require("./constants");
|
|
11
10
|
const resources_1 = require("./resources");
|
|
12
11
|
// import { type AgentConfig } from "./resources/types";
|
|
13
12
|
const MessageManager_1 = require("./messages/MessageManager");
|
|
14
|
-
const
|
|
13
|
+
const types_1 = require("./messages/types");
|
|
15
14
|
const Error_1 = require("./utils/Error");
|
|
16
15
|
const Error_2 = require("./internal/Error/Error");
|
|
17
16
|
const Events_1 = require("./events/Events");
|
|
@@ -64,7 +63,7 @@ class SynapseSDK {
|
|
|
64
63
|
/**
|
|
65
64
|
* Send a message conetnt will be text always
|
|
66
65
|
*/
|
|
67
|
-
async sendMessage({ message,
|
|
66
|
+
async sendMessage({ message, files, audio, }) {
|
|
68
67
|
if (!this.connection) {
|
|
69
68
|
const error = new Error_2.ConnectionError("Connection not established. Session may not be initialized.", {
|
|
70
69
|
context: { stage: "sendChatMessage" },
|
|
@@ -75,14 +74,10 @@ class SynapseSDK {
|
|
|
75
74
|
}
|
|
76
75
|
switch (this.connectionType) {
|
|
77
76
|
case ConnectionFactory_1.ConnectionType.SOCKET:
|
|
78
|
-
this.messageManager.
|
|
77
|
+
this.messageManager.sendSocketMessage({
|
|
79
78
|
message: message,
|
|
80
79
|
files: files,
|
|
81
|
-
|
|
82
|
-
type: Events_1.SOCKET_CONTENT_TYPES.TEXT,
|
|
83
|
-
tool_use_id: tool_use_id,
|
|
84
|
-
tool_use_params: tool_use_params,
|
|
85
|
-
hidden: hidden,
|
|
80
|
+
audio: audio,
|
|
86
81
|
});
|
|
87
82
|
break;
|
|
88
83
|
default:
|
|
@@ -96,46 +91,6 @@ class SynapseSDK {
|
|
|
96
91
|
throw error;
|
|
97
92
|
}
|
|
98
93
|
}
|
|
99
|
-
// /**
|
|
100
|
-
// * upload files
|
|
101
|
-
// */
|
|
102
|
-
// public uploadFiles(
|
|
103
|
-
// files: File[],
|
|
104
|
-
// message?: string,
|
|
105
|
-
// messageId?: string
|
|
106
|
-
// ): void {
|
|
107
|
-
// if (!this.connection) {
|
|
108
|
-
// //TODO: use onError instead of throw error
|
|
109
|
-
// const error = new ConnectionError(
|
|
110
|
-
// "Connection not established. Session may not be initialized.",
|
|
111
|
-
// {
|
|
112
|
-
// context: { stage: "uploadFiles" },
|
|
113
|
-
// hint: "Call startSession() before attempting uploads.",
|
|
114
|
-
// }
|
|
115
|
-
// );
|
|
116
|
-
// this.emitError(error);
|
|
117
|
-
// throw error;
|
|
118
|
-
// }
|
|
119
|
-
// switch (this.connectionType) {
|
|
120
|
-
// case ConnectionType.SOCKET:
|
|
121
|
-
// this.messageManager.sendSocketChatMessage({
|
|
122
|
-
// files,
|
|
123
|
-
// message,
|
|
124
|
-
// messageId: messageId,
|
|
125
|
-
// type: SOCKET_CONTENT_TYPES.FILE,
|
|
126
|
-
// });
|
|
127
|
-
// break;
|
|
128
|
-
// default:
|
|
129
|
-
// const error = new ConnectionError("Unsupported connection type", {
|
|
130
|
-
// context: {
|
|
131
|
-
// stage: "uploadFiles",
|
|
132
|
-
// connectionType: this.connectionType,
|
|
133
|
-
// },
|
|
134
|
-
// });
|
|
135
|
-
// this.emitError(error);
|
|
136
|
-
// throw error;
|
|
137
|
-
// }
|
|
138
|
-
// }
|
|
139
94
|
/**
|
|
140
95
|
* Register a listener for a specific event
|
|
141
96
|
*/
|
|
@@ -166,7 +121,7 @@ class SynapseSDK {
|
|
|
166
121
|
/**
|
|
167
122
|
* Send audio
|
|
168
123
|
* */
|
|
169
|
-
startRecording() {
|
|
124
|
+
async startRecording({ onChunks, onError, }) {
|
|
170
125
|
if (!this.connection) {
|
|
171
126
|
const error = new Error_2.ConnectionError("Connection not established. Session may not be initialized.", {
|
|
172
127
|
context: { stage: "sendAudio" },
|
|
@@ -177,7 +132,15 @@ class SynapseSDK {
|
|
|
177
132
|
}
|
|
178
133
|
switch (this.connectionType) {
|
|
179
134
|
case ConnectionFactory_1.ConnectionType.SOCKET:
|
|
180
|
-
|
|
135
|
+
try {
|
|
136
|
+
await this.messageManager.startRecording({
|
|
137
|
+
onChunks,
|
|
138
|
+
onError,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
181
144
|
break;
|
|
182
145
|
default:
|
|
183
146
|
const error = new Error_2.ConnectionError("Unsupported connection type", {
|
|
@@ -220,6 +183,9 @@ class SynapseSDK {
|
|
|
220
183
|
// public getAgentConfig(): AgentConfig | null {
|
|
221
184
|
// return this.agentConfig;
|
|
222
185
|
// }
|
|
186
|
+
isConnected() {
|
|
187
|
+
return this.connection?.isConnected() ?? false;
|
|
188
|
+
}
|
|
223
189
|
/**
|
|
224
190
|
* End the session
|
|
225
191
|
*/
|
|
@@ -280,11 +246,13 @@ class SynapseSDK {
|
|
|
280
246
|
* function to decide whether to create a new session or refresh the existing session
|
|
281
247
|
*/
|
|
282
248
|
async manageSession(existingSession) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
this.config.callbacks?.onConnectionStatusChange?.(types_1.ConnectionStatus.CONNECTING);
|
|
249
|
+
// this.config.callbacks?.onConnectionStatusChange?.(
|
|
250
|
+
// ConnectionStatus.CONNECTING
|
|
251
|
+
// );
|
|
287
252
|
try {
|
|
253
|
+
if (!existingSession?.session_id) {
|
|
254
|
+
return this.createNewSession();
|
|
255
|
+
}
|
|
288
256
|
const result = await this.resourceManager.validateSession(existingSession.session_id);
|
|
289
257
|
if (result.active) {
|
|
290
258
|
return existingSession;
|
|
@@ -295,7 +263,9 @@ class SynapseSDK {
|
|
|
295
263
|
return this.createNewSession();
|
|
296
264
|
}
|
|
297
265
|
catch (error) {
|
|
298
|
-
this.config.callbacks?.onConnectionStatusChange?.(
|
|
266
|
+
// this.config.callbacks?.onConnectionStatusChange?.(
|
|
267
|
+
// ConnectionStatus.NOT_CONNECTED
|
|
268
|
+
// );
|
|
299
269
|
if (error instanceof Error_2.APIError) {
|
|
300
270
|
const status = error.status;
|
|
301
271
|
if (status === 404 || status === 500) {
|
|
@@ -316,6 +286,8 @@ class SynapseSDK {
|
|
|
316
286
|
}
|
|
317
287
|
catch (error) {
|
|
318
288
|
if (error instanceof Error_2.APIError) {
|
|
289
|
+
// Emit API error via onError callback before handling
|
|
290
|
+
this.emitError(error);
|
|
319
291
|
const status = error.status;
|
|
320
292
|
if (status === 404 || status === 500) {
|
|
321
293
|
return this.createNewSession();
|
|
@@ -350,10 +322,7 @@ class SynapseSDK {
|
|
|
350
322
|
this.connection.onError((error) => {
|
|
351
323
|
this.onSocketConnectionError(error);
|
|
352
324
|
});
|
|
353
|
-
this.connection.
|
|
354
|
-
this.config.callbacks?.onConnectionStatusChange?.(status);
|
|
355
|
-
});
|
|
356
|
-
this.connection.on(types_2.SYNAPSE_REALTIME_RESERVED_EVENTS.SESSION_EXPIRED, () => {
|
|
325
|
+
this.connection.on(types_1.SYNAPSE_REALTIME_RESERVED_EVENTS.SESSION_EXPIRED, () => {
|
|
357
326
|
this.handleSessionExpiry();
|
|
358
327
|
});
|
|
359
328
|
break;
|
|
@@ -376,6 +345,7 @@ class SynapseSDK {
|
|
|
376
345
|
* Handle socket error
|
|
377
346
|
*/
|
|
378
347
|
onSocketConnectionError(error) {
|
|
348
|
+
this.connection?.emit(types_1.SYNAPSE_REALTIME_EVENTS.ERROR, error);
|
|
379
349
|
const connectionError = this.toConnectionError(error, "WebSocket connection error", { stage: "onSocketConnectionError" }, "Verify network connectivity or attempt to reconnect.");
|
|
380
350
|
this.emitError(connectionError);
|
|
381
351
|
}
|
|
@@ -441,7 +411,6 @@ class SynapseSDK {
|
|
|
441
411
|
async handleSessionExpiry() {
|
|
442
412
|
try {
|
|
443
413
|
this.endSession();
|
|
444
|
-
this.config.callbacks?.onConnectionStatusChange?.(types_1.ConnectionStatus.CONNECTING);
|
|
445
414
|
if (!this.sessionId || !this.sessionToken) {
|
|
446
415
|
const error = new Error_2.SessionError("Session ID or token not found", {
|
|
447
416
|
context: { stage: "handleSessionExpiry" },
|
|
@@ -462,7 +431,9 @@ class SynapseSDK {
|
|
|
462
431
|
this.config.callbacks?.onSessionRefreshed?.(refreshed);
|
|
463
432
|
}
|
|
464
433
|
catch (error) {
|
|
465
|
-
this.config.callbacks?.onConnectionStatusChange?.(
|
|
434
|
+
// this.config.callbacks?.onConnectionStatusChange?.(
|
|
435
|
+
// ConnectionStatus.NOT_CONNECTED
|
|
436
|
+
// );
|
|
466
437
|
const sessionError = this.toSessionError(error, "Session expired", {
|
|
467
438
|
stage: "handleSessionExpiry",
|
|
468
439
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export { MessageManager } from "./messages/MessageManager";
|
|
|
17
17
|
export { SYNAPSE_REALTIME_EVENTS, type SynapseRealTimeEventData, type ToolEscalationData, } from "./messages/types";
|
|
18
18
|
export { HttpClient } from "./internal/Api/HttpClient";
|
|
19
19
|
export type { HttpClientConfig } from "./internal/Api/HttpClient";
|
|
20
|
-
export { SynapseError, APIError, APIUserAbortError, APIConnectionTimeoutError, BadRequestError, UnauthorizedError, PermissionDeniedError, NotFoundError, MethodNotAllowedError, RateLimitError, InternalServerError, } from "./internal/Error/Error";
|
|
20
|
+
export { SynapseError, APIError, APIUserAbortError, APIConnectionTimeoutError, BadRequestError, UnauthorizedError, PermissionDeniedError, NotFoundError, MethodNotAllowedError, RateLimitError, InternalServerError, SynapseErrorCode, } from "./internal/Error/Error";
|
|
21
21
|
export { ErrorType } from "./internal/Error/types";
|
|
22
22
|
export type { Environment } from "./constants";
|
|
23
23
|
export { ErrorUtils } from "./utils/Error";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EACL,iBAAiB,EACjB,cAAc,GACf,MAAM,gCAAgC,CAAC;AACxC,YAAY,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AACvE,cAAc,6BAA6B,CAAC;AAG5C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,cAAc,mBAAmB,CAAC;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AACtD,cAAc,2BAA2B,CAAC;AAG1C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EACL,uBAAuB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,kBAAkB,GACxB,MAAM,kBAAkB,CAAC;AAG1B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qBAAqB,EACrB,aAAa,EACb,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,cAAc,qBAAqB,CAAC;AAEpC,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
18
18
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.SYNAPSE_MESSAGE_TYPES = exports.ErrorUtils = exports.ErrorType = exports.InternalServerError = exports.RateLimitError = exports.MethodNotAllowedError = exports.NotFoundError = exports.PermissionDeniedError = exports.UnauthorizedError = exports.BadRequestError = exports.APIConnectionTimeoutError = exports.APIUserAbortError = exports.APIError = exports.SynapseError = exports.HttpClient = exports.SYNAPSE_REALTIME_EVENTS = exports.MessageManager = exports.Session = exports.ResourceManager = exports.ConnectionType = exports.ConnectionFactory = exports.WebSocketConnection = exports.BaseConnection = exports.SynapseSDK = void 0;
|
|
21
|
+
exports.SYNAPSE_MESSAGE_TYPES = exports.ErrorUtils = exports.ErrorType = exports.SynapseErrorCode = exports.InternalServerError = exports.RateLimitError = exports.MethodNotAllowedError = exports.NotFoundError = exports.PermissionDeniedError = exports.UnauthorizedError = exports.BadRequestError = exports.APIConnectionTimeoutError = exports.APIUserAbortError = exports.APIError = exports.SynapseError = exports.HttpClient = exports.SYNAPSE_REALTIME_EVENTS = exports.MessageManager = exports.Session = exports.ResourceManager = exports.ConnectionType = exports.ConnectionFactory = exports.WebSocketConnection = exports.BaseConnection = exports.SynapseSDK = void 0;
|
|
22
22
|
// High-level API (Primary interface for most users)
|
|
23
23
|
var Synapse_1 = require("./Synapse");
|
|
24
24
|
Object.defineProperty(exports, "SynapseSDK", { enumerable: true, get: function () { return Synapse_1.SynapseSDK; } });
|
|
@@ -59,6 +59,7 @@ Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: functio
|
|
|
59
59
|
Object.defineProperty(exports, "MethodNotAllowedError", { enumerable: true, get: function () { return Error_1.MethodNotAllowedError; } });
|
|
60
60
|
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return Error_1.RateLimitError; } });
|
|
61
61
|
Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return Error_1.InternalServerError; } });
|
|
62
|
+
Object.defineProperty(exports, "SynapseErrorCode", { enumerable: true, get: function () { return Error_1.SynapseErrorCode; } });
|
|
62
63
|
var types_2 = require("./internal/Error/types");
|
|
63
64
|
Object.defineProperty(exports, "ErrorType", { enumerable: true, get: function () { return types_2.ErrorType; } });
|
|
64
65
|
// Utilities
|
|
@@ -14,6 +14,7 @@ export declare const SynapseErrorCode: {
|
|
|
14
14
|
export type SynapseErrorCode = (typeof SynapseErrorCode)[keyof typeof SynapseErrorCode];
|
|
15
15
|
export interface SynapseErrorOptions {
|
|
16
16
|
cause?: unknown;
|
|
17
|
+
displayMessage?: string;
|
|
17
18
|
context?: Record<string, unknown>;
|
|
18
19
|
hint?: string;
|
|
19
20
|
}
|
|
@@ -23,6 +24,7 @@ export declare class SynapseError extends Error {
|
|
|
23
24
|
readonly cause?: unknown;
|
|
24
25
|
readonly context?: Record<string, unknown>;
|
|
25
26
|
readonly hint?: string;
|
|
27
|
+
readonly displayMessage?: string;
|
|
26
28
|
constructor(message: string, code?: SynapseErrorCode, options?: SynapseErrorOptions);
|
|
27
29
|
}
|
|
28
30
|
export declare class APIError<TStatus extends number | undefined = number | undefined, THeader extends Headers | undefined = Headers | undefined, TError extends Record<string, unknown> | undefined = Record<string, unknown> | undefined> extends SynapseError {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../../src/internal/Error/Error.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB;;;;;;;;;;;;CAYnB,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAC1B,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC;AAE3D,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,qBAAa,YAAa,SAAQ,KAAK;IACrC,SAAgB,IAAI,EAAE,gBAAgB,CAAC;IACvC,SAAgB,SAAS,EAAE,IAAI,CAAC;IAChC,SAAgB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChC,SAAgB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClD,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../../src/internal/Error/Error.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB;;;;;;;;;;;;CAYnB,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAC1B,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC;AAE3D,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,qBAAa,YAAa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E,mBAAwB;CAI/D;AAED,qBAAa,UAAW,SAAQ,YAAY;gBAC9B,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB;CAI/D;AAED,qBAAa,kBAAmB,SAAQ,YAAY;gBACtC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB;CAI/D;AAED,qBAAa,eAAgB,SAAQ,YAAY;gBACnC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB;CAI/D;AAED,KAAK,gBAAgB,CAAC,CAAC,SAAS,YAAY,IAAI,KAC9C,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,mBAAmB,KAC1B,CAAC,CAAC;AAEP,wBAAgB,cAAc,CAAC,CAAC,SAAS,YAAY,EACnD,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,EACzB,eAAe,EAAE,MAAM,EACvB,OAAO,GAAE,mBAAwB,GAChC,CAAC,CAwBH"}
|
|
@@ -21,6 +21,7 @@ class SynapseError extends Error {
|
|
|
21
21
|
cause;
|
|
22
22
|
context;
|
|
23
23
|
hint;
|
|
24
|
+
displayMessage;
|
|
24
25
|
constructor(message, code = exports.SynapseErrorCode.UNKNOWN, options = {}) {
|
|
25
26
|
super(message);
|
|
26
27
|
this.name = "SynapseError";
|
|
@@ -29,6 +30,7 @@ class SynapseError extends Error {
|
|
|
29
30
|
this.cause = options.cause;
|
|
30
31
|
this.context = options.context;
|
|
31
32
|
this.hint = options.hint;
|
|
33
|
+
this.displayMessage = options.displayMessage || options?.hint || message;
|
|
32
34
|
if (Error.captureStackTrace) {
|
|
33
35
|
Error.captureStackTrace(this, this.constructor);
|
|
34
36
|
}
|
|
@@ -53,6 +55,7 @@ class APIError extends SynapseError {
|
|
|
53
55
|
hint: status && status >= 500
|
|
54
56
|
? "Retry the request or contact support if the issue persists."
|
|
55
57
|
: undefined,
|
|
58
|
+
displayMessage: message || "Something went wrong", //give user friednly message,
|
|
56
59
|
});
|
|
57
60
|
this.name = "APIError";
|
|
58
61
|
this.status = status;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AudioConfig, type AudioDataCallback, type AudioErrorCallback
|
|
1
|
+
import { type AudioConfig, type AudioDataCallback, type AudioErrorCallback } from "./types";
|
|
2
2
|
export declare class AudioManager {
|
|
3
3
|
private mediaRecorder;
|
|
4
4
|
private mediaStream;
|
|
@@ -7,11 +7,10 @@ export declare class AudioManager {
|
|
|
7
7
|
private config;
|
|
8
8
|
private onAudioData;
|
|
9
9
|
private onAudioError;
|
|
10
|
-
private onRecordingStatusChange;
|
|
11
10
|
private suppressCallbacks;
|
|
12
11
|
constructor(config?: Partial<AudioConfig>);
|
|
13
12
|
private checkCurrentPermissionState;
|
|
14
|
-
start(onAudioData: AudioDataCallback,
|
|
13
|
+
start(onAudioData: AudioDataCallback, onAudioError?: AudioErrorCallback): Promise<void>;
|
|
15
14
|
private processAudioChunk;
|
|
16
15
|
private toRecordingError;
|
|
17
16
|
private handleError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Audio.d.ts","sourceRoot":"","sources":["../../../src/media/audio/Audio.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,
|
|
1
|
+
{"version":3,"file":"Audio.d.ts","sourceRoot":"","sources":["../../../src/media/audio/Audio.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EAExB,MAAM,SAAS,CAAC;AAGjB,qBAAa,YAAY;IACvB,OAAO,CAAC,aAAa,CAA8B;IACnD,OAAO,CAAC,WAAW,CAA4B;IAC/C,OAAO,CAAC,kBAAkB,CAAa;IACvC,OAAO,CAAC,cAAc,CAA8C;IAEpE,OAAO,CAAC,MAAM,CAAc;IAE5B,OAAO,CAAC,WAAW,CAAkC;IACrD,OAAO,CAAC,YAAY,CAAmC;IACvD,OAAO,CAAC,iBAAiB,CAAS;gBAEtB,MAAM,GAAE,OAAO,CAAC,WAAW,CAAM;YAU/B,2BAA2B;IAa5B,KAAK,CAChB,WAAW,EAAE,iBAAiB,EAC9B,YAAY,CAAC,EAAE,kBAAkB,GAChC,OAAO,CAAC,IAAI,CAAC;YAoGF,iBAAiB;IAuB/B,OAAO,CAAC,gBAAgB;IA0BxB,OAAO,CAAC,WAAW;IAmBnB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAW3B,OAAO,CAAC,wBAAwB;IAsChC;;OAEG;IACH,OAAO,CAAC,YAAY;IA8BpB;;OAEG;IACH,IAAI,IAAI,IAAI;IA6BZ;;OAEG;IACH,MAAM,IAAI,IAAI;IAgCd,OAAO,IAAI,IAAI;CAiBhB"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AudioManager = void 0;
|
|
4
|
-
const types_1 = require("./types");
|
|
5
4
|
const Error_1 = require("../../internal/Error/Error");
|
|
6
5
|
class AudioManager {
|
|
7
6
|
mediaRecorder = null;
|
|
@@ -11,7 +10,6 @@ class AudioManager {
|
|
|
11
10
|
config;
|
|
12
11
|
onAudioData = null;
|
|
13
12
|
onAudioError = null;
|
|
14
|
-
onRecordingStatusChange = null;
|
|
15
13
|
suppressCallbacks = false; //gurad against late recorder events like ondatavaailable after cancel () or cleanup() is called
|
|
16
14
|
constructor(config = {}) {
|
|
17
15
|
this.config = {
|
|
@@ -34,7 +32,7 @@ class AudioManager {
|
|
|
34
32
|
}
|
|
35
33
|
return permission.state;
|
|
36
34
|
}
|
|
37
|
-
async start(onAudioData,
|
|
35
|
+
async start(onAudioData, onAudioError //Clearly handles the error inside the callback without unhandled rejections
|
|
38
36
|
) {
|
|
39
37
|
try {
|
|
40
38
|
// Check if mediaDevices is available
|
|
@@ -42,6 +40,7 @@ class AudioManager {
|
|
|
42
40
|
throw new Error_1.RecordingError("Media devices API is not available. This usually means the page is not served over HTTPS or there are browser restrictions.", {
|
|
43
41
|
context: { feature: "mediaDevices" },
|
|
44
42
|
hint: "Serve the app over HTTPS and verify browser/device microphone support.",
|
|
43
|
+
displayMessage: "Microphone access is unavailable."
|
|
45
44
|
});
|
|
46
45
|
}
|
|
47
46
|
// Check if MediaRecorder is supported
|
|
@@ -49,6 +48,7 @@ class AudioManager {
|
|
|
49
48
|
throw new Error_1.RecordingError("MediaRecorder is not supported in this browser", {
|
|
50
49
|
context: { feature: "MediaRecorder" },
|
|
51
50
|
hint: "Use a browser that supports the MediaRecorder API.",
|
|
51
|
+
displayMessage: "Microphone access is unavailable."
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
// Check for supported audio formats in order of preference
|
|
@@ -63,6 +63,7 @@ class AudioManager {
|
|
|
63
63
|
throw new Error_1.RecordingError("No supported audio formats found in this browser", {
|
|
64
64
|
context: { requestedTypes: supportedTypes },
|
|
65
65
|
hint: "Verify codec support or adjust the requested MIME types.",
|
|
66
|
+
displayMessage: "Microphone access is unavailable."
|
|
66
67
|
});
|
|
67
68
|
}
|
|
68
69
|
// Update config with best supported mime type
|
|
@@ -70,7 +71,6 @@ class AudioManager {
|
|
|
70
71
|
await this.checkCurrentPermissionState();
|
|
71
72
|
this.onAudioData = onAudioData;
|
|
72
73
|
this.onAudioError = onAudioError ?? null;
|
|
73
|
-
this.onRecordingStatusChange = onRecordingStatusChange ?? null;
|
|
74
74
|
this.suppressCallbacks = false; //reset the guard against late recorder events
|
|
75
75
|
// Get user media
|
|
76
76
|
this.mediaStream = await navigator.mediaDevices.getUserMedia({
|
|
@@ -91,6 +91,7 @@ class AudioManager {
|
|
|
91
91
|
if (this.mediaRecorder.state !== "inactive") {
|
|
92
92
|
throw new Error_1.RecordingError("MediaRecorder is in an invalid state for start()", {
|
|
93
93
|
context: { recorderState: this.mediaRecorder.state },
|
|
94
|
+
displayMessage: "Failed to start recording"
|
|
94
95
|
});
|
|
95
96
|
}
|
|
96
97
|
// Set up event handlers
|
|
@@ -98,7 +99,6 @@ class AudioManager {
|
|
|
98
99
|
// Start recording
|
|
99
100
|
this.mediaRecorder.start();
|
|
100
101
|
this.recordingStartTime = Date.now();
|
|
101
|
-
this.onRecordingStatusChange?.(types_1.AudioRecordingStatus.LISTENING);
|
|
102
102
|
// Set up auto-pause timer if enabled
|
|
103
103
|
if (this.config.autoPauseEnabled) {
|
|
104
104
|
this.setupAutoPauseTimer();
|
|
@@ -112,7 +112,6 @@ class AudioManager {
|
|
|
112
112
|
}
|
|
113
113
|
async processAudioChunk(blob) {
|
|
114
114
|
try {
|
|
115
|
-
this.onRecordingStatusChange?.(types_1.AudioRecordingStatus.PROCESSING);
|
|
116
115
|
const base64Audio = await this.blobToBase64(blob);
|
|
117
116
|
const now = Date.now();
|
|
118
117
|
if (!this.onAudioData) {
|
|
@@ -125,7 +124,6 @@ class AudioManager {
|
|
|
125
124
|
timestamp: this.recordingStartTime > 0 ? this.recordingStartTime : now,
|
|
126
125
|
};
|
|
127
126
|
this.onAudioData(audioData);
|
|
128
|
-
this.onRecordingStatusChange?.(types_1.AudioRecordingStatus.TRANSCRIBING);
|
|
129
127
|
}
|
|
130
128
|
catch (error) {
|
|
131
129
|
this.handleError(error, { stage: "process_audio_chunk" });
|
|
@@ -150,7 +148,6 @@ class AudioManager {
|
|
|
150
148
|
}
|
|
151
149
|
handleError(error, context) {
|
|
152
150
|
const recordingError = this.toRecordingError(error, "Unexpected recording error", context);
|
|
153
|
-
this.onRecordingStatusChange?.(types_1.AudioRecordingStatus.ERROR);
|
|
154
151
|
if (this.onAudioError) {
|
|
155
152
|
try {
|
|
156
153
|
this.onAudioError(recordingError);
|
|
@@ -249,7 +246,6 @@ class AudioManager {
|
|
|
249
246
|
this.mediaStream.getTracks().forEach((track) => track.stop());
|
|
250
247
|
this.mediaStream = null;
|
|
251
248
|
}
|
|
252
|
-
this.onRecordingStatusChange?.(types_1.AudioRecordingStatus.IDLE);
|
|
253
249
|
console.log("Audio recording stopped manually");
|
|
254
250
|
}
|
|
255
251
|
catch (error) {
|
|
@@ -281,7 +277,6 @@ class AudioManager {
|
|
|
281
277
|
this.mediaStream.getTracks().forEach((track) => track.stop());
|
|
282
278
|
this.mediaStream = null;
|
|
283
279
|
}
|
|
284
|
-
this.onRecordingStatusChange?.(types_1.AudioRecordingStatus.IDLE);
|
|
285
280
|
}
|
|
286
281
|
catch (error) {
|
|
287
282
|
throw this.toRecordingError(error, "Failed to cancel audio recording", {
|
|
@@ -13,13 +13,4 @@ export interface AudioConfig {
|
|
|
13
13
|
}
|
|
14
14
|
export type AudioDataCallback = (data: AudioMetaData) => void;
|
|
15
15
|
export type AudioErrorCallback = (error: RecordingError) => void;
|
|
16
|
-
export declare const AudioRecordingStatus: {
|
|
17
|
-
readonly IDLE: "idle";
|
|
18
|
-
readonly LISTENING: "listening";
|
|
19
|
-
readonly ERROR: "error";
|
|
20
|
-
readonly PROCESSING: "processing";
|
|
21
|
-
readonly TRANSCRIBING: "transcribing";
|
|
22
|
-
};
|
|
23
|
-
export type AudioRecordingStatus = (typeof AudioRecordingStatus)[keyof typeof AudioRecordingStatus];
|
|
24
|
-
export type AudioRecordingStatusCallback = (status: AudioRecordingStatus) => void;
|
|
25
16
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/media/audio/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,CAAC;AAC9D,MAAM,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/media/audio/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,CAAC;AAC9D,MAAM,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
// export const AudioRecordingStatus = {
|
|
4
|
+
// IDLE: "idle",
|
|
5
|
+
// LISTENING: "listening",
|
|
6
|
+
// ERROR: "error",
|
|
7
|
+
// PROCESSING: "processing",
|
|
8
|
+
// TRANSCRIBING: "transcribing",
|
|
9
|
+
// } as const;
|
|
10
|
+
// export type AudioRecordingStatus =
|
|
11
|
+
// (typeof AudioRecordingStatus)[keyof typeof AudioRecordingStatus];
|
|
12
|
+
// export type AudioRecordingStatusCallback = (
|
|
13
|
+
// status: AudioRecordingStatus
|
|
14
|
+
// ) => void;
|
|
@@ -2,17 +2,15 @@ export declare class Filemanager {
|
|
|
2
2
|
private pendingFiles;
|
|
3
3
|
private pendingMessage?;
|
|
4
4
|
private pendingFormat;
|
|
5
|
-
private messageId?;
|
|
6
5
|
/**
|
|
7
6
|
* Set the files for upload
|
|
8
7
|
*/
|
|
9
|
-
setFilesForUpload(files: File[],
|
|
8
|
+
setFilesForUpload(files: File[], message?: string): void;
|
|
10
9
|
/**
|
|
11
10
|
* Get the pending file state
|
|
12
11
|
*/
|
|
13
12
|
getPendingFileState(): {
|
|
14
13
|
files: File[];
|
|
15
|
-
messageId: string;
|
|
16
14
|
message: string;
|
|
17
15
|
format: string;
|
|
18
16
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"File.d.ts","sourceRoot":"","sources":["../../../src/media/file/File.ts"],"names":[],"mappings":"AAMA,qBAAa,WAAW;IACtB,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,cAAc,CAAC,CAAc;IACrC,OAAO,CAAC,aAAa,CAAc;
|
|
1
|
+
{"version":3,"file":"File.d.ts","sourceRoot":"","sources":["../../../src/media/file/File.ts"],"names":[],"mappings":"AAMA,qBAAa,WAAW;IACtB,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,cAAc,CAAC,CAAc;IACrC,OAAO,CAAC,aAAa,CAAc;IAEnC;;OAEG;IACI,iBAAiB,CACtB,KAAK,EAAE,IAAI,EAAE,EACb,OAAO,CAAC,EAAE,MAAM,GACf,IAAI;IAYP;;OAEG;IAEI,mBAAmB,IAAI;QAC5B,KAAK,EAAE,IAAI,EAAE,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;KAChB;IAQD;;OAEG;IACU,yBAAyB,CACpC,aAAa,EAAE,MAAM,EAAE,GACtB,OAAO,CAAC,MAAM,CAAC;IA4ElB;;;;;OAKG;IACU,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IActC;;;;;OAKG;IACI,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAIrD;;;;OAIG;IACI,cAAc,IAAI,OAAO;IAIhC;;;;OAIG;IACI,iBAAiB,IAAI,MAAM;IAOlC;;OAEG;IACI,sBAAsB,IAAI,IAAI;CAKtC"}
|
package/dist/media/file/File.js
CHANGED
|
@@ -14,16 +14,14 @@ class Filemanager {
|
|
|
14
14
|
pendingFiles = [];
|
|
15
15
|
pendingMessage = "";
|
|
16
16
|
pendingFormat = "";
|
|
17
|
-
messageId = "";
|
|
18
17
|
/**
|
|
19
18
|
* Set the files for upload
|
|
20
19
|
*/
|
|
21
|
-
setFilesForUpload(files,
|
|
20
|
+
setFilesForUpload(files, message) {
|
|
22
21
|
if (this.pendingFiles.length > 0) {
|
|
23
22
|
this.clearPendingFilesState();
|
|
24
23
|
}
|
|
25
24
|
this.pendingFiles = files;
|
|
26
|
-
this.messageId = messageId || Date.now().toString();
|
|
27
25
|
if (message && message.trim()) {
|
|
28
26
|
this.pendingMessage = message;
|
|
29
27
|
}
|
|
@@ -36,7 +34,6 @@ class Filemanager {
|
|
|
36
34
|
getPendingFileState() {
|
|
37
35
|
return {
|
|
38
36
|
files: this.pendingFiles,
|
|
39
|
-
messageId: this.messageId || "",
|
|
40
37
|
message: this.pendingMessage || "",
|
|
41
38
|
format: this.pendingFormat || "",
|
|
42
39
|
};
|
|
@@ -153,7 +150,6 @@ class Filemanager {
|
|
|
153
150
|
this.pendingFiles = [];
|
|
154
151
|
this.pendingMessage = "";
|
|
155
152
|
this.pendingFormat = "";
|
|
156
|
-
this.messageId = "";
|
|
157
153
|
}
|
|
158
154
|
}
|
|
159
155
|
exports.Filemanager = Filemanager;
|
|
@@ -6,6 +6,7 @@ import { type SynapseSDKCallbacks } from "../Synapse";
|
|
|
6
6
|
import { type IncomingSocketChatMessage, type IncomingSocketStreamMessage, type IncomingSocketErrorMessage, type IncomingSocketEndOfStreamMessage } from "../events/Events";
|
|
7
7
|
import { BaseConnection } from "../internal/connection/BaseConnection";
|
|
8
8
|
import { type SocketChatRequestData } from "./types";
|
|
9
|
+
import { type AudioMetaData } from "../media/audio/types";
|
|
9
10
|
import { type DisconnectionDetails } from "../internal/connection/types";
|
|
10
11
|
export declare class MessageManager {
|
|
11
12
|
private connection;
|
|
@@ -20,7 +21,7 @@ export declare class MessageManager {
|
|
|
20
21
|
/**
|
|
21
22
|
* send chat message through socket
|
|
22
23
|
*/
|
|
23
|
-
|
|
24
|
+
sendSocketMessage({ message, files, audio, url, }: SocketChatRequestData): void;
|
|
24
25
|
/**
|
|
25
26
|
* Handle incoming chat message
|
|
26
27
|
*/
|
|
@@ -46,14 +47,13 @@ export declare class MessageManager {
|
|
|
46
47
|
* send ping message
|
|
47
48
|
*/
|
|
48
49
|
sendSocketPingMessage(): void;
|
|
49
|
-
/**
|
|
50
|
-
* start recording audio
|
|
51
|
-
*/
|
|
52
|
-
private sendSocketStreamMessage;
|
|
53
50
|
/**
|
|
54
51
|
* send audio message
|
|
55
52
|
*/
|
|
56
|
-
|
|
53
|
+
startRecording({ onChunks, onError, }: {
|
|
54
|
+
onChunks: (chunks: AudioMetaData) => void;
|
|
55
|
+
onError?: (error: Error) => void;
|
|
56
|
+
}): Promise<void>;
|
|
57
57
|
/**
|
|
58
58
|
* stop recording audio
|
|
59
59
|
*/
|
|
@@ -67,10 +67,6 @@ export declare class MessageManager {
|
|
|
67
67
|
* Cleanup message service
|
|
68
68
|
*/
|
|
69
69
|
cleanupMessageServerState(): void;
|
|
70
|
-
/**
|
|
71
|
-
* Generate a unique message ID
|
|
72
|
-
*/
|
|
73
|
-
private generateId;
|
|
74
70
|
private emitError;
|
|
75
71
|
private toFileError;
|
|
76
72
|
private toRecordingError;
|
|
@@ -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,
|
|
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;AAEjB,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAS1D,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEzE,qBAAa,cAAc;IACzB,OAAO,CAAC,UAAU,CAA+B;IACjD,OAAO,CAAC,SAAS,CAAoC;IACrD,OAAO,CAAC,WAAW,CAA4B;IAC/C,OAAO,CAAC,YAAY,CAA6B;gBAErC,UAAU,EAAE,cAAc,EAAE,SAAS,CAAC,EAAE,mBAAmB;IAIvE;;OAEG;IACH,OAAO,CAAC,uBAAuB;IA+C/B;;OAEG;IACI,iBAAiB,CAAC,EACvB,OAAO,EACP,KAAK,EACL,KAAK,EACL,GAAG,GACJ,EAAE,qBAAqB,GAAG,IAAI;IA8C/B;;OAEG;IACI,+BAA+B,CACpC,OAAO,EAAE,yBAAyB,GACjC,IAAI;IAmFP;;OAEG;IACI,iCAAiC,CACtC,OAAO,EAAE,2BAA2B,GACnC,IAAI;IAsDA,gBAAgB,CAAC,OAAO,EAAE,oBAAoB,GAAG,IAAI;IAI5D;;OAEG;IACI,sCAAsC,CAC3C,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;IA+CpC;;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"}
|
|
@@ -5,7 +5,6 @@ const Events_1 = require("../events/Events");
|
|
|
5
5
|
const File_1 = require("../media/file/File");
|
|
6
6
|
const types_1 = require("./types");
|
|
7
7
|
const Audio_1 = require("../media/audio/Audio");
|
|
8
|
-
const types_2 = require("../media/audio/types");
|
|
9
8
|
const Error_1 = require("../internal/Error/Error");
|
|
10
9
|
class MessageManager {
|
|
11
10
|
connection = null;
|
|
@@ -19,7 +18,7 @@ class MessageManager {
|
|
|
19
18
|
/**
|
|
20
19
|
* Handle file upload process
|
|
21
20
|
*/
|
|
22
|
-
handleFileUploadProcess({ files,
|
|
21
|
+
handleFileUploadProcess({ files, message, url, }) {
|
|
23
22
|
if (!this.fileManager) {
|
|
24
23
|
this.fileManager = new File_1.Filemanager();
|
|
25
24
|
}
|
|
@@ -27,11 +26,11 @@ class MessageManager {
|
|
|
27
26
|
if (files && files.length > 0) {
|
|
28
27
|
//stage 1. of file upload process
|
|
29
28
|
//--store files temproary in memory
|
|
30
|
-
this.fileManager.setFilesForUpload(files,
|
|
29
|
+
this.fileManager.setFilesForUpload(files, message);
|
|
31
30
|
fileUploadMessage = {
|
|
32
31
|
ev: Events_1.SOCKET_EVENTS.CHAT,
|
|
33
32
|
ct: Events_1.SOCKET_CONTENT_TYPES.FILE,
|
|
34
|
-
_id:
|
|
33
|
+
_id: Date.now().toString(),
|
|
35
34
|
ts: Date.now(),
|
|
36
35
|
data: {
|
|
37
36
|
extension: this.fileManager.getPendingFileState().format,
|
|
@@ -46,7 +45,7 @@ class MessageManager {
|
|
|
46
45
|
fileUploadMessage = {
|
|
47
46
|
ev: Events_1.SOCKET_EVENTS.CHAT,
|
|
48
47
|
ct: Events_1.SOCKET_CONTENT_TYPES.FILE,
|
|
49
|
-
_id:
|
|
48
|
+
_id: Date.now().toString(),
|
|
50
49
|
ts: Date.now(),
|
|
51
50
|
data: {
|
|
52
51
|
url: url,
|
|
@@ -60,43 +59,43 @@ class MessageManager {
|
|
|
60
59
|
/**
|
|
61
60
|
* send chat message through socket
|
|
62
61
|
*/
|
|
63
|
-
|
|
62
|
+
sendSocketMessage({ message, files, audio, url, }) {
|
|
64
63
|
const connection = this.assertConnection("sendSocketChatMessage");
|
|
65
64
|
let outMessage;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
65
|
+
if ((files && files.length > 0) || (url && url.trim() !== "")) {
|
|
66
|
+
outMessage = this.handleFileUploadProcess({
|
|
67
|
+
files,
|
|
68
|
+
message,
|
|
69
|
+
url,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
else if (message) {
|
|
73
|
+
outMessage = {
|
|
74
|
+
ev: Events_1.SOCKET_EVENTS.CHAT,
|
|
75
|
+
ct: Events_1.SOCKET_CONTENT_TYPES.TEXT,
|
|
76
|
+
_id: Date.now().toString(),
|
|
77
|
+
ts: Date.now(),
|
|
78
|
+
data: {
|
|
79
|
+
text: message,
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
else if (audio && audio?.audio && audio?.format) {
|
|
84
|
+
console.log("obj", Object.keys(audio || {}));
|
|
85
|
+
outMessage = {
|
|
86
|
+
ev: Events_1.SOCKET_EVENTS.STREAM,
|
|
87
|
+
ct: Events_1.SOCKET_CONTENT_TYPES.AUDIO,
|
|
88
|
+
_id: Date.now().toString(),
|
|
89
|
+
ts: Date.now(),
|
|
90
|
+
data: {
|
|
91
|
+
audio: audio?.audio,
|
|
92
|
+
format: audio?.format,
|
|
93
|
+
},
|
|
94
|
+
};
|
|
96
95
|
}
|
|
97
96
|
if (!outMessage) {
|
|
98
97
|
const error = new Error_1.MessageError("No message to send", {
|
|
99
|
-
context: { stage: "sendSocketChatMessage"
|
|
98
|
+
context: { stage: "sendSocketChatMessage" },
|
|
100
99
|
});
|
|
101
100
|
this.emitError(error);
|
|
102
101
|
throw error;
|
|
@@ -115,8 +114,7 @@ class MessageManager {
|
|
|
115
114
|
this.fileManager
|
|
116
115
|
?.uploadFilesToPresignedUrl(message.data.urls)
|
|
117
116
|
.then(() => {
|
|
118
|
-
this.
|
|
119
|
-
type: Events_1.SOCKET_CONTENT_TYPES.FILE,
|
|
117
|
+
this.sendSocketMessage({
|
|
120
118
|
url: message.data.urls?.[0],
|
|
121
119
|
});
|
|
122
120
|
})
|
|
@@ -166,7 +164,6 @@ class MessageManager {
|
|
|
166
164
|
timestamp: message.ts,
|
|
167
165
|
};
|
|
168
166
|
connection.emit(types_1.SYNAPSE_REALTIME_EVENTS.INLINE_TEXT, messageData);
|
|
169
|
-
this.callbacks?.onRecordingStatusChange?.(types_2.AudioRecordingStatus.IDLE);
|
|
170
167
|
// this.callbacks?.onChatmessage?.(message.data.text, message.ct);
|
|
171
168
|
}
|
|
172
169
|
break;
|
|
@@ -287,55 +284,72 @@ class MessageManager {
|
|
|
287
284
|
};
|
|
288
285
|
connection.sendMessage(pingMessage);
|
|
289
286
|
}
|
|
290
|
-
/**
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
sendSocketStreamMessage({
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
287
|
+
// /**
|
|
288
|
+
// * start recording audio
|
|
289
|
+
// */
|
|
290
|
+
// private sendSocketStreamMessage({
|
|
291
|
+
// data,
|
|
292
|
+
// type,
|
|
293
|
+
// messageId,
|
|
294
|
+
// timestamp,
|
|
295
|
+
// }: {
|
|
296
|
+
// data: SOCKET_STREAM_DATA;
|
|
297
|
+
// type: SOCKET_CONTENT_TYPES;
|
|
298
|
+
// messageId?: string;
|
|
299
|
+
// timestamp?: number;
|
|
300
|
+
// }): void {
|
|
301
|
+
// const connection = this.assertConnection("sendSocketStreamMessage");
|
|
302
|
+
// switch (type) {
|
|
303
|
+
// case SOCKET_CONTENT_TYPES.AUDIO:
|
|
304
|
+
// const message: Outgoing.StreamSynapseToMatrixMessage = {
|
|
305
|
+
// ev: SOCKET_EVENTS.STREAM,
|
|
306
|
+
// ct: type,
|
|
307
|
+
// _id: messageId || this.generateId(),
|
|
308
|
+
// ts: timestamp || Date.now(),
|
|
309
|
+
// data: {
|
|
310
|
+
// audio: data.audio,
|
|
311
|
+
// format: data.format,
|
|
312
|
+
// },
|
|
313
|
+
// };
|
|
314
|
+
// connection.sendMessage(message);
|
|
315
|
+
// break;
|
|
316
|
+
// default:
|
|
317
|
+
// const error = new MessageError("Unsupported content type", {
|
|
318
|
+
// context: { stage: "sendSocketStreamMessage", contentType: type },
|
|
319
|
+
// });
|
|
320
|
+
// this.emitError(error);
|
|
321
|
+
// throw error;
|
|
322
|
+
// }
|
|
323
|
+
// }
|
|
317
324
|
/**
|
|
318
325
|
* send audio message
|
|
319
326
|
*/
|
|
320
|
-
|
|
327
|
+
async startRecording({ onChunks, onError, }) {
|
|
328
|
+
if (!onChunks) {
|
|
329
|
+
const error = new Error_1.RecordingError("onChunks is required", {
|
|
330
|
+
context: { stage: "startRecording" },
|
|
331
|
+
hint: "onChunks is required",
|
|
332
|
+
});
|
|
333
|
+
this.emitError(error);
|
|
334
|
+
throw error;
|
|
335
|
+
}
|
|
321
336
|
this.assertConnection("startRecording");
|
|
322
337
|
if (!this.audioManager) {
|
|
323
338
|
this.audioManager = new Audio_1.AudioManager();
|
|
324
339
|
}
|
|
325
|
-
|
|
326
|
-
.start((
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
340
|
+
try {
|
|
341
|
+
await this.audioManager.start(onChunks, (error) => {
|
|
342
|
+
const recordingError = this.toRecordingError(error, "Failed to start audio recording", { stage: "startRecording" });
|
|
343
|
+
onError?.(recordingError);
|
|
344
|
+
this.emitError(recordingError);
|
|
330
345
|
});
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
this.emitError(recordingError);
|
|
334
|
-
})
|
|
335
|
-
.catch((error) => {
|
|
346
|
+
}
|
|
347
|
+
catch (error) {
|
|
336
348
|
const recordingError = this.toRecordingError(error, "Failed to start audio recording", { stage: "startRecording" });
|
|
349
|
+
onError?.(recordingError);
|
|
337
350
|
this.emitError(recordingError);
|
|
338
|
-
|
|
351
|
+
throw recordingError;
|
|
352
|
+
}
|
|
339
353
|
}
|
|
340
354
|
/**
|
|
341
355
|
* stop recording audio
|
|
@@ -385,12 +399,12 @@ class MessageManager {
|
|
|
385
399
|
this.audioManager = null;
|
|
386
400
|
}
|
|
387
401
|
}
|
|
388
|
-
/**
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
generateId() {
|
|
392
|
-
|
|
393
|
-
}
|
|
402
|
+
// /**
|
|
403
|
+
// * Generate a unique message ID
|
|
404
|
+
// */
|
|
405
|
+
// private generateId(): string {
|
|
406
|
+
// return `msg_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
|
|
407
|
+
// }
|
|
394
408
|
emitError(error) {
|
|
395
409
|
this.callbacks?.onError?.(error);
|
|
396
410
|
}
|
package/dist/messages/types.d.ts
CHANGED
|
@@ -20,8 +20,8 @@ export type OutgoingMessage = OutgoingSocketMessage;
|
|
|
20
20
|
export interface SocketChatRequestData {
|
|
21
21
|
message?: string;
|
|
22
22
|
messageId?: string;
|
|
23
|
-
type: SOCKET_CONTENT_TYPES;
|
|
24
23
|
files?: File[];
|
|
24
|
+
audio?: AudioMetaData;
|
|
25
25
|
url?: string;
|
|
26
26
|
tool_use_id?: string;
|
|
27
27
|
tool_use_params?: Record<string, unknown>;
|
|
@@ -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,EAC1B,8BAA8B,EAC/B,MAAM,kBAAkB,CAAC;AAC1B,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,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CAAC,MAAM,OAAO,4BAA4B,CAAC,CAAC;AAEnF,eAAO,MAAM,gCAAgC;;CAEnC,CAAC;AAEX,MAAM,MAAM,gCAAgC,GAC1C,CAAC,OAAO,gCAAgC,CAAC,CAAC,MAAM,OAAO,gCAAgC,CAAC,CAAC;AAG3F,MAAM,MAAM,kBAAkB,GAAG,aAAa,CAAC;AAE/C,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,EAAE,kBAAkB,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,oBAAoB,CAAC;AACvD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,iBAAiB,CAAC,EAAE,OAAO,8BAA8B,CAAC;IAC1D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,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.4",
|
|
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",
|
|
@@ -19,10 +19,13 @@
|
|
|
19
19
|
"medical",
|
|
20
20
|
"chatbot",
|
|
21
21
|
"websocket",
|
|
22
|
-
"typescript"
|
|
22
|
+
"typescript",
|
|
23
|
+
"medassist",
|
|
24
|
+
"core",
|
|
25
|
+
"widget"
|
|
23
26
|
],
|
|
24
27
|
"author": "Geethanjali S",
|
|
25
|
-
"homepage": "https://github.com/eka-care/
|
|
28
|
+
"homepage": "https://github.com/eka-care/synapse-sdk/blob/main/README.md",
|
|
26
29
|
"license": "MIT",
|
|
27
30
|
"repository": {
|
|
28
31
|
"type": "git",
|