@eka-care/medassist-core 1.0.70 → 1.0.73

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.
Files changed (93) hide show
  1. package/dist/messages/types.d.ts +1 -0
  2. package/dist/resources/session/types.d.ts +1 -0
  3. package/package.json +1 -1
  4. package/dist/Synapse.d.ts.map +0 -1
  5. package/dist/connection/ConnectionFactory.d.ts.map +0 -1
  6. package/dist/connection/SSE.d.ts.map +0 -1
  7. package/dist/connection/Websocket.d.ts.map +0 -1
  8. package/dist/constants/index.d.ts.map +0 -1
  9. package/dist/constants/types.d.ts.map +0 -1
  10. package/dist/conversation.d.ts.map +0 -1
  11. package/dist/esm/Synapse.js +0 -612
  12. package/dist/esm/connection/ConnectionFactory.js +0 -27
  13. package/dist/esm/connection/SSE.js +0 -212
  14. package/dist/esm/connection/Websocket.js +0 -178
  15. package/dist/esm/constants/index.js +0 -25
  16. package/dist/esm/constants/types.js +0 -1
  17. package/dist/esm/conversation.js +0 -7
  18. package/dist/esm/events/Events.js +0 -41
  19. package/dist/esm/events/Incoming.js +0 -1
  20. package/dist/esm/events/Outgoing.js +0 -1
  21. package/dist/esm/events/index.js +0 -2
  22. package/dist/esm/events/types.js +0 -5
  23. package/dist/esm/index.js +0 -34
  24. package/dist/esm/internal/Api/BaseResource.js +0 -50
  25. package/dist/esm/internal/Api/HttpClient.js +0 -131
  26. package/dist/esm/internal/Api/types.js +0 -1
  27. package/dist/esm/internal/Error/Error.js +0 -229
  28. package/dist/esm/internal/Error/types.js +0 -9
  29. package/dist/esm/internal/connection/BaseConnection.js +0 -134
  30. package/dist/esm/internal/connection/types.js +0 -17
  31. package/dist/esm/internal/events/EventEmitter.js +0 -26
  32. package/dist/esm/internal/store/index.js +0 -5
  33. package/dist/esm/media/audio/Audio.copy.js +0 -363
  34. package/dist/esm/media/audio/Audio.js +0 -310
  35. package/dist/esm/media/audio/types.js +0 -13
  36. package/dist/esm/media/file/File.js +0 -159
  37. package/dist/esm/messages/MessageManager.js +0 -476
  38. package/dist/esm/messages/types.js +0 -35
  39. package/dist/esm/resources/config/Config.js +0 -11
  40. package/dist/esm/resources/feedback/Feedback.js +0 -9
  41. package/dist/esm/resources/feedback/types.js +0 -7
  42. package/dist/esm/resources/index.js +0 -152
  43. package/dist/esm/resources/session/Session.js +0 -44
  44. package/dist/esm/resources/session/types.js +0 -5
  45. package/dist/esm/resources/toolCall/ToolCall.js +0 -12
  46. package/dist/esm/resources/toolCall/types.js +0 -34
  47. package/dist/esm/resources/types.js +0 -4
  48. package/dist/esm/resources/voice/VoiceResource.js +0 -14
  49. package/dist/esm/resources/voice/types.js +0 -1
  50. package/dist/esm/types/index.js +0 -8
  51. package/dist/esm/utils/Error.js +0 -110
  52. package/dist/esm/voice/VoiceAgent.js +0 -305
  53. package/dist/esm/voice/VoiceAudioAnalyser.js +0 -32
  54. package/dist/esm/voice/index.js +0 -1
  55. package/dist/esm/voice/types.js +0 -15
  56. package/dist/events/Events.d.ts.map +0 -1
  57. package/dist/events/Incoming.d.ts.map +0 -1
  58. package/dist/events/Outgoing.d.ts.map +0 -1
  59. package/dist/events/index.d.ts.map +0 -1
  60. package/dist/events/types.d.ts.map +0 -1
  61. package/dist/index.d.ts.map +0 -1
  62. package/dist/internal/Api/BaseResource.d.ts.map +0 -1
  63. package/dist/internal/Api/HttpClient.d.ts.map +0 -1
  64. package/dist/internal/Api/types.d.ts.map +0 -1
  65. package/dist/internal/Error/Error.d.ts.map +0 -1
  66. package/dist/internal/Error/types.d.ts.map +0 -1
  67. package/dist/internal/connection/BaseConnection.d.ts.map +0 -1
  68. package/dist/internal/connection/types.d.ts.map +0 -1
  69. package/dist/internal/events/EventEmitter.d.ts.map +0 -1
  70. package/dist/internal/store/index.d.ts.map +0 -1
  71. package/dist/media/audio/Audio.copy.d.ts.map +0 -1
  72. package/dist/media/audio/Audio.d.ts.map +0 -1
  73. package/dist/media/audio/types.d.ts.map +0 -1
  74. package/dist/media/file/File.d.ts.map +0 -1
  75. package/dist/messages/MessageManager.d.ts.map +0 -1
  76. package/dist/messages/types.d.ts.map +0 -1
  77. package/dist/resources/config/Config.d.ts.map +0 -1
  78. package/dist/resources/feedback/Feedback.d.ts.map +0 -1
  79. package/dist/resources/feedback/types.d.ts.map +0 -1
  80. package/dist/resources/index.d.ts.map +0 -1
  81. package/dist/resources/session/Session.d.ts.map +0 -1
  82. package/dist/resources/session/types.d.ts.map +0 -1
  83. package/dist/resources/toolCall/ToolCall.d.ts.map +0 -1
  84. package/dist/resources/toolCall/types.d.ts.map +0 -1
  85. package/dist/resources/types.d.ts.map +0 -1
  86. package/dist/resources/voice/VoiceResource.d.ts.map +0 -1
  87. package/dist/resources/voice/types.d.ts.map +0 -1
  88. package/dist/types/index.d.ts.map +0 -1
  89. package/dist/utils/Error.d.ts.map +0 -1
  90. package/dist/voice/VoiceAgent.d.ts.map +0 -1
  91. package/dist/voice/VoiceAudioAnalyser.d.ts.map +0 -1
  92. package/dist/voice/index.d.ts.map +0 -1
  93. package/dist/voice/types.d.ts.map +0 -1
@@ -1,7 +0,0 @@
1
- "use strict";
2
- // export type FeedbackRequest = {
3
- // messageId: string;
4
- // sessionId: string;
5
- // feedback: USER_FEEDBACK;
6
- // feedbackReason?: string;
7
- // }
@@ -1,152 +0,0 @@
1
- /**
2
- * Init class to fetch agent configuration from the platform
3
- */
4
- import { HttpClient } from "../internal/Api/HttpClient";
5
- import { Session } from "./session/Session";
6
- import { APIError } from "../internal/Error/Error";
7
- import { Config } from "./config/Config";
8
- import { VoiceResource } from "./voice/VoiceResource";
9
- export class ResourceManager {
10
- resourceConfig;
11
- httpClient;
12
- session;
13
- config;
14
- voiceResource;
15
- constructor(config) {
16
- this.resourceConfig = config;
17
- // Set up HTTP client with agentId header for all requests
18
- this.httpClient = new HttpClient({
19
- baseUrl: this.resourceConfig.serverUrl,
20
- headers: {
21
- "X-agent-id": this.resourceConfig.agentId, // This will be included in ALL requests
22
- "ngrok-skip-browser-warning": "69420",
23
- ...(this.resourceConfig.authorization && { Authorization: this.resourceConfig.authorization }),
24
- },
25
- // authorization: config.authorization,
26
- });
27
- this.config = new Config(this.httpClient);
28
- this.session = new Session(this.httpClient);
29
- this.voiceResource = new VoiceResource(this.httpClient);
30
- }
31
- /**
32
- * Fetch agent configuration and create session
33
- */
34
- async createSession(userId, context) {
35
- try {
36
- // Use SessionsResource to start a session
37
- // The X-agent-id header is automatically included from httpClient config
38
- const { profile, intent, user_location, referer, ...extraContext } = context || {};
39
- const sessionRequest = {
40
- ...(userId && { user_id: userId }),
41
- ...(profile && { user_context: profile }),
42
- ...((intent || Object.keys(extraContext).length > 0) && {
43
- session_context: {
44
- ...(intent && { intent }),
45
- ...(user_location && { user_location }),
46
- ...extraContext, // Include any extra properties from context
47
- }
48
- }),
49
- ...(referer && { referer }),
50
- };
51
- const sessionData = await this.session.create(sessionRequest, this.resourceConfig.authToken);
52
- if (!sessionData?.session_id || !sessionData?.session_token) {
53
- throw new APIError("Failed to start session.", 500, undefined, undefined);
54
- }
55
- return sessionData;
56
- }
57
- catch (error) {
58
- if (error instanceof APIError) {
59
- throw error;
60
- }
61
- throw new APIError("Failed to start session.", 500, undefined, undefined);
62
- }
63
- }
64
- async getAgentConfig() {
65
- if (!this.config) {
66
- this.config = new Config(this.httpClient);
67
- }
68
- try {
69
- return await this.config.retrieve(this.resourceConfig.agentId);
70
- }
71
- catch (error) {
72
- throw new APIError("Failed to get agent config.", 500, undefined, undefined);
73
- }
74
- }
75
- /**
76
- * Validate a session if it's still active or not
77
- * GET /med-assist/session/:sessionId
78
- */
79
- async validateSession(sessionId) {
80
- try {
81
- const sessionData = await this.session.retrieve(sessionId);
82
- if (sessionData.msg && sessionData.msg === "Session Active") {
83
- return {
84
- expired: false,
85
- active: true,
86
- };
87
- }
88
- return {
89
- expired: true,
90
- active: false,
91
- };
92
- }
93
- catch (error) {
94
- if (error instanceof APIError) {
95
- switch (error.status) {
96
- // case 404:
97
- // return {
98
- // expired: false,
99
- // active: false,
100
- // };
101
- // case 500:
102
- // return {
103
- // expired: false,
104
- // active: false,
105
- // };
106
- case 401:
107
- // if (!!error.error?.msg) {
108
- // return {
109
- // expired: true,
110
- // active: false,
111
- // };
112
- // }
113
- // throw new APIError(error.error?.msg || "Failed to authenticate user", 401, undefined, undefined);
114
- return {
115
- expired: true,
116
- active: false,
117
- };
118
- default:
119
- throw error;
120
- }
121
- }
122
- throw error;
123
- }
124
- }
125
- /**
126
- * Refresh a session
127
- * POST /med-assist/session/:sessionId/refresh
128
- */
129
- async refreshSession(sessionId, sessionToken) {
130
- return await this.session.refresh(sessionId, sessionToken);
131
- }
132
- /**
133
- * Feedback on a message
134
- * PATCH /med-assist/session/:sessionId/:messageId
135
- */
136
- async sendFeedback(sessionId, messageId, feedback, feedbackReason) {
137
- return await this.session.feedback(sessionId, messageId, feedback, feedbackReason);
138
- }
139
- /**
140
- * Call a tool
141
- * POST /med-assist/api-call-tool
142
- */
143
- async callTool(sessionId, toolId, message_id, session_token, toolParams) {
144
- return await this.session.callTool(sessionId, toolId, message_id, session_token, toolParams);
145
- }
146
- async getVoiceIceServers(sessionId, sessionToken) {
147
- return await this.voiceResource.getIceServers(sessionId, sessionToken);
148
- }
149
- async sendVoiceOffer(body) {
150
- return await this.voiceResource.sendOffer(body);
151
- }
152
- }
@@ -1,44 +0,0 @@
1
- import { BaseResource } from "../../internal/Api/BaseResource";
2
- /**
3
- * SessionsResource class for managing sessions-related api calls
4
- */
5
- export class Session extends BaseResource {
6
- //Ts implicitly calls super() here
7
- /**
8
- * create a new session
9
- * POST /med-assist/session
10
- */
11
- basePath = "/med-assist/session";
12
- async create(sessionRequest, authToken) {
13
- return this.post(this.basePath, sessionRequest, authToken
14
- ? { headers: { "x-auth-token": authToken } }
15
- : undefined);
16
- }
17
- async retrieve(sessionId) {
18
- return this.get(`${this.basePath}/${sessionId}`);
19
- }
20
- /**
21
- * refresh a session
22
- * POST /med-assist/session/refresh
23
- */
24
- async refresh(sessionId, sessionToken) {
25
- return this.get(`${this.basePath}/${sessionId}/refresh`, undefined, {
26
- headers: {
27
- "x-sess-token": sessionToken,
28
- },
29
- });
30
- }
31
- async feedback(sessionId, messageId, feedback, feedback_reason) {
32
- return this.put(`${this.basePath}/${sessionId}/messages/${messageId}/feedback`, {
33
- feedback,
34
- feedback_reason,
35
- });
36
- }
37
- async callTool(sessionId, toolId, messageId, sessionToken, toolParams) {
38
- return this.post(`${this.basePath}/${sessionId}/messages/${messageId}/tools/${toolId}`, { tool_params: toolParams }, {
39
- headers: {
40
- "x-sess-token": sessionToken,
41
- },
42
- });
43
- }
44
- }
@@ -1,5 +0,0 @@
1
- export const USER_FEEDBACK = {
2
- LIKE: "LIKE",
3
- DISLIKE: "DISLIKE",
4
- NONE: "NONE",
5
- };
@@ -1,12 +0,0 @@
1
- import { BaseResource } from "../../internal/Api/BaseResource";
2
- export class ToolCall extends BaseResource {
3
- basePath = "/med-assist/api-call-tool";
4
- async callTool(sessionId, toolName, toolParams) {
5
- // if (toolName === SYNAPSE_TOOL_NAME.GET_LOCATION) {
6
- // return this.requestLocation() as Promise<R>;
7
- // }
8
- return this.post(`${this.basePath}?session_id=${sessionId}&tool_name=${toolName}`, {
9
- tool_params: toolParams,
10
- });
11
- }
12
- }
@@ -1,34 +0,0 @@
1
- export var SYNAPSE_TOOL_NAME;
2
- (function (SYNAPSE_TOOL_NAME) {
3
- SYNAPSE_TOOL_NAME["MOBILE_VERIFICATION"] = "mobile_verification";
4
- SYNAPSE_TOOL_NAME["AVAILABILITY_DATES"] = "availability_dates";
5
- SYNAPSE_TOOL_NAME["AVAILABILITY_SLOTS"] = "availability_slots";
6
- SYNAPSE_TOOL_NAME["DOCTOR_AVAILABILITY"] = "doctor_availability";
7
- SYNAPSE_TOOL_NAME["DOCTOR_DETAILS"] = "doctor_details";
8
- SYNAPSE_TOOL_NAME["GET_LOCATION"] = "get_location";
9
- })(SYNAPSE_TOOL_NAME || (SYNAPSE_TOOL_NAME = {}));
10
- export var SYNAPSE_COMPONENTS;
11
- (function (SYNAPSE_COMPONENTS) {
12
- SYNAPSE_COMPONENTS["MOBILE"] = "mobile_number";
13
- SYNAPSE_COMPONENTS["OTP"] = "otp";
14
- SYNAPSE_COMPONENTS["EMAIL"] = "email_address";
15
- SYNAPSE_COMPONENTS["PILL"] = "pills";
16
- SYNAPSE_COMPONENTS["MULTI"] = "multi";
17
- SYNAPSE_COMPONENTS["DOCTOR_CARD"] = "doctor_card";
18
- SYNAPSE_COMPONENTS["CARD"] = "card";
19
- SYNAPSE_COMPONENTS["MEDIA_CARD"] = "media_card";
20
- })(SYNAPSE_COMPONENTS || (SYNAPSE_COMPONENTS = {}));
21
- export var SYNAPSE_TOOL_CALLBACK_NAME;
22
- (function (SYNAPSE_TOOL_CALLBACK_NAME) {
23
- SYNAPSE_TOOL_CALLBACK_NAME["DOCTOR_AVAILABILITY"] = "get_doctor_availability";
24
- SYNAPSE_TOOL_CALLBACK_NAME["AVAILABILITY_DATES"] = "get_available_dates";
25
- SYNAPSE_TOOL_CALLBACK_NAME["AVAILABILITY_SLOTS"] = "get_available_slots";
26
- SYNAPSE_TOOL_CALLBACK_NAME["MOBILE_VERIFICATION"] = "verify_mobile_number";
27
- SYNAPSE_TOOL_CALLBACK_NAME["DOCTOR_DETAILS"] = "get_doctor_details";
28
- })(SYNAPSE_TOOL_CALLBACK_NAME || (SYNAPSE_TOOL_CALLBACK_NAME = {}));
29
- export var SYNAPSE_EICITATION_STATUS;
30
- (function (SYNAPSE_EICITATION_STATUS) {
31
- SYNAPSE_EICITATION_STATUS["PROGRESS"] = "progress";
32
- SYNAPSE_EICITATION_STATUS["SUCCESS"] = "success";
33
- SYNAPSE_EICITATION_STATUS["FAILURE"] = "failure";
34
- })(SYNAPSE_EICITATION_STATUS || (SYNAPSE_EICITATION_STATUS = {}));
@@ -1,4 +0,0 @@
1
- /**
2
- * Types for agent configuration initialization
3
- */
4
- export {};
@@ -1,14 +0,0 @@
1
- import { BaseResource } from "../../internal/Api/BaseResource";
2
- export class VoiceResource extends BaseResource {
3
- static ICE_SERVERS_PATH = "/med-assist/voice/ice-servers";
4
- static OFFER_PATH = "/med-assist/voice/offer";
5
- async getIceServers(sessionId, sessionToken) {
6
- return this.get(VoiceResource.ICE_SERVERS_PATH, {
7
- session_id: sessionId,
8
- token: sessionToken,
9
- });
10
- }
11
- async sendOffer(body) {
12
- return this.post(VoiceResource.OFFER_PATH, body);
13
- }
14
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,8 +0,0 @@
1
- /**
2
- * Shared types across the SDK
3
- */
4
- // Re-export common types from other modules
5
- export * from '../internal/connection/types';
6
- export * from '../internal/Error/types';
7
- export * from '../messages/types';
8
- export * from '../resources/session/types';
@@ -1,110 +0,0 @@
1
- import { APIConnectionTimeoutError, APIError, PermissionDeniedError, SynapseError, UnauthorizedError, } from "../internal/Error/Error";
2
- // Utility functions for error handling
3
- export class ErrorUtils {
4
- /**
5
- * Check if an error is a specific API error type
6
- */
7
- static isAPIError(error) {
8
- return error instanceof APIError;
9
- }
10
- /**
11
- * Check if an error is a network-related error
12
- */
13
- static isNetworkError(error) {
14
- return (error instanceof APIError &&
15
- (error.status === 0 || error.status === undefined));
16
- }
17
- /**
18
- * Check if an error is a timeout error
19
- */
20
- static isTimeoutError(error) {
21
- return error instanceof APIConnectionTimeoutError;
22
- }
23
- /**
24
- * Check if an error is an authentication error
25
- */
26
- static isAuthError(error) {
27
- return (error instanceof UnauthorizedError ||
28
- error instanceof PermissionDeniedError);
29
- }
30
- /**
31
- * Check if an error is a client error (4xx)
32
- */
33
- static isClientError(error) {
34
- return (error instanceof APIError &&
35
- error.status !== undefined &&
36
- error.status >= 400 &&
37
- error.status < 500);
38
- }
39
- /**
40
- * Check if an error is a server error (5xx)
41
- */
42
- static isServerError(error) {
43
- return (error instanceof APIError &&
44
- error.status !== undefined &&
45
- error.status >= 500);
46
- }
47
- /**
48
- * Get user-friendly error message
49
- */
50
- static getUserFriendlyMessage(error) {
51
- if (ErrorUtils.isNetworkError(error)) {
52
- return "Unable to connect to the server. Please check your internet connection.";
53
- }
54
- if (ErrorUtils.isTimeoutError(error)) {
55
- return "Request timed out. Please try again.";
56
- }
57
- if (ErrorUtils.isAuthError(error)) {
58
- return "Authentication failed. Please log in again.";
59
- }
60
- if (ErrorUtils.isServerError(error)) {
61
- return "Server error occurred. Please try again later.";
62
- }
63
- if (ErrorUtils.isAPIError(error)) {
64
- return error.message;
65
- }
66
- if (error instanceof Error) {
67
- return error.message;
68
- }
69
- return "An unexpected error occurred.";
70
- }
71
- /**
72
- * Extract error details for logging
73
- */
74
- static getErrorDetails(error) {
75
- if (ErrorUtils.isAPIError(error)) {
76
- return {
77
- type: error.name,
78
- message: error.message,
79
- code: error.code,
80
- status: error.status,
81
- timestamp: error.timestamp,
82
- stack: error.stack,
83
- context: error.context,
84
- hint: error.hint,
85
- };
86
- }
87
- if (error instanceof SynapseError) {
88
- return {
89
- type: error.name,
90
- message: error.message,
91
- code: error.code,
92
- timestamp: error.timestamp,
93
- stack: error.stack,
94
- context: error.context,
95
- hint: error.hint,
96
- };
97
- }
98
- if (error instanceof Error) {
99
- return {
100
- type: error.name,
101
- message: error.message,
102
- stack: error.stack,
103
- };
104
- }
105
- return {
106
- type: "Unknown",
107
- message: String(error),
108
- };
109
- }
110
- }