@eka-care/medassist-core 1.0.0

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 (98) hide show
  1. package/README.md +32 -0
  2. package/dist/Synapse.d.ts +131 -0
  3. package/dist/Synapse.d.ts.map +1 -0
  4. package/dist/Synapse.js +479 -0
  5. package/dist/connection/ConnectionFactory.d.ts +17 -0
  6. package/dist/connection/ConnectionFactory.d.ts.map +1 -0
  7. package/dist/connection/ConnectionFactory.js +28 -0
  8. package/dist/connection/Websocket.d.ts +61 -0
  9. package/dist/connection/Websocket.d.ts.map +1 -0
  10. package/dist/connection/Websocket.js +184 -0
  11. package/dist/constants/index.d.ts +17 -0
  12. package/dist/constants/index.d.ts.map +1 -0
  13. package/dist/constants/index.js +28 -0
  14. package/dist/constants/types.d.ts +2 -0
  15. package/dist/constants/types.d.ts.map +1 -0
  16. package/dist/constants/types.js +2 -0
  17. package/dist/events/Events.d.ts +47 -0
  18. package/dist/events/Events.d.ts.map +1 -0
  19. package/dist/events/Events.js +46 -0
  20. package/dist/events/Incoming.d.ts +2 -0
  21. package/dist/events/Incoming.d.ts.map +1 -0
  22. package/dist/events/Incoming.js +2 -0
  23. package/dist/events/Outgoing.d.ts +2 -0
  24. package/dist/events/Outgoing.d.ts.map +1 -0
  25. package/dist/events/Outgoing.js +2 -0
  26. package/dist/events/index.d.ts +3 -0
  27. package/dist/events/index.d.ts.map +1 -0
  28. package/dist/events/index.js +38 -0
  29. package/dist/events/types.d.ts +86 -0
  30. package/dist/events/types.d.ts.map +1 -0
  31. package/dist/events/types.js +6 -0
  32. package/dist/index.d.ts +27 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +69 -0
  35. package/dist/internal/Api/BaseResource.d.ts +35 -0
  36. package/dist/internal/Api/BaseResource.d.ts.map +1 -0
  37. package/dist/internal/Api/BaseResource.js +54 -0
  38. package/dist/internal/Api/HttpClient.d.ts +25 -0
  39. package/dist/internal/Api/HttpClient.d.ts.map +1 -0
  40. package/dist/internal/Api/HttpClient.js +131 -0
  41. package/dist/internal/Api/types.d.ts +7 -0
  42. package/dist/internal/Api/types.d.ts.map +1 -0
  43. package/dist/internal/Api/types.js +2 -0
  44. package/dist/internal/Error/Error.d.ts +97 -0
  45. package/dist/internal/Error/Error.d.ts.map +1 -0
  46. package/dist/internal/Error/Error.js +243 -0
  47. package/dist/internal/Error/types.d.ts +17 -0
  48. package/dist/internal/Error/types.d.ts.map +1 -0
  49. package/dist/internal/Error/types.js +12 -0
  50. package/dist/internal/connection/BaseConnection.d.ts +100 -0
  51. package/dist/internal/connection/BaseConnection.d.ts.map +1 -0
  52. package/dist/internal/connection/BaseConnection.js +138 -0
  53. package/dist/internal/connection/types.d.ts +43 -0
  54. package/dist/internal/connection/types.d.ts.map +1 -0
  55. package/dist/internal/connection/types.js +20 -0
  56. package/dist/internal/events/EventEmitter.d.ts +7 -0
  57. package/dist/internal/events/EventEmitter.d.ts.map +1 -0
  58. package/dist/internal/events/EventEmitter.js +27 -0
  59. package/dist/internal/store/index.d.ts +10 -0
  60. package/dist/internal/store/index.d.ts.map +1 -0
  61. package/dist/internal/store/index.js +9 -0
  62. package/dist/media/audio/Audio.d.ts +37 -0
  63. package/dist/media/audio/Audio.d.ts.map +1 -0
  64. package/dist/media/audio/Audio.js +310 -0
  65. package/dist/media/audio/types.d.ts +25 -0
  66. package/dist/media/audio/types.d.ts.map +1 -0
  67. package/dist/media/audio/types.js +10 -0
  68. package/dist/media/file/File.d.ts +54 -0
  69. package/dist/media/file/File.d.ts.map +1 -0
  70. package/dist/media/file/File.js +159 -0
  71. package/dist/messages/MessageManager.d.ts +79 -0
  72. package/dist/messages/MessageManager.d.ts.map +1 -0
  73. package/dist/messages/MessageManager.js +420 -0
  74. package/dist/messages/types.d.ts +74 -0
  75. package/dist/messages/types.d.ts.map +1 -0
  76. package/dist/messages/types.js +34 -0
  77. package/dist/resources/config/Config.d.ts +5 -0
  78. package/dist/resources/config/Config.d.ts.map +1 -0
  79. package/dist/resources/config/Config.js +5 -0
  80. package/dist/resources/index.d.ts +34 -0
  81. package/dist/resources/index.d.ts.map +1 -0
  82. package/dist/resources/index.js +108 -0
  83. package/dist/resources/session/Session.d.ts +21 -0
  84. package/dist/resources/session/Session.d.ts.map +1 -0
  85. package/dist/resources/session/Session.js +39 -0
  86. package/dist/resources/session/types.d.ts +17 -0
  87. package/dist/resources/session/types.d.ts.map +1 -0
  88. package/dist/resources/session/types.js +8 -0
  89. package/dist/resources/types.d.ts +22 -0
  90. package/dist/resources/types.d.ts.map +1 -0
  91. package/dist/resources/types.js +5 -0
  92. package/dist/types/index.d.ts +8 -0
  93. package/dist/types/index.d.ts.map +1 -0
  94. package/dist/types/index.js +24 -0
  95. package/dist/utils/Error.d.ts +45 -0
  96. package/dist/utils/Error.d.ts.map +1 -0
  97. package/dist/utils/Error.js +114 -0
  98. package/package.json +41 -0
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ /**
3
+ * Init class to fetch agent configuration from the platform
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ResourceManager = void 0;
7
+ const HttpClient_1 = require("../internal/Api/HttpClient");
8
+ const Session_1 = require("./session/Session");
9
+ const Error_1 = require("../internal/Error/Error");
10
+ class ResourceManager {
11
+ resourceConfig;
12
+ httpClient;
13
+ session;
14
+ constructor(config) {
15
+ this.resourceConfig = config;
16
+ // Set up HTTP client with agentId header for all requests
17
+ this.httpClient = new HttpClient_1.HttpClient({
18
+ baseUrl: this.resourceConfig.serverUrl,
19
+ headers: {
20
+ "X-agent-id": this.resourceConfig.agentId, // This will be included in ALL requests
21
+ },
22
+ // authorization: config.authorization,
23
+ });
24
+ // Initialize sessions resource with the configured client
25
+ this.session = new Session_1.Session(this.httpClient);
26
+ }
27
+ /**
28
+ * Fetch agent configuration and create session
29
+ */
30
+ async createSession(userId) {
31
+ try {
32
+ // Use SessionsResource to start a session
33
+ // The X-agent-id header is automatically included from httpClient config
34
+ const sessionData = await this.session.create(userId);
35
+ if (!sessionData?.session_id || !sessionData?.session_token) {
36
+ throw new Error_1.APIError("Failed to start session.", 500, undefined, undefined);
37
+ }
38
+ return sessionData;
39
+ }
40
+ catch (error) {
41
+ if (error instanceof Error_1.APIError) {
42
+ throw error;
43
+ }
44
+ throw new Error_1.APIError("Failed to start session.", 500, undefined, undefined);
45
+ }
46
+ }
47
+ /**
48
+ * Validate a session if it's still active or not
49
+ * GET /med-assist/session/:sessionId
50
+ */
51
+ async validateSession(sessionId) {
52
+ try {
53
+ const sessionData = await this.session.retrieve(sessionId);
54
+ if (sessionData.msg && sessionData.msg === "Session Active") {
55
+ return {
56
+ expired: false,
57
+ active: true,
58
+ };
59
+ }
60
+ return {
61
+ expired: true,
62
+ active: false,
63
+ };
64
+ }
65
+ catch (error) {
66
+ if (error instanceof Error_1.APIError) {
67
+ switch (error.status) {
68
+ case 404:
69
+ return {
70
+ expired: false,
71
+ active: false,
72
+ };
73
+ case 500:
74
+ return {
75
+ expired: false,
76
+ active: false,
77
+ };
78
+ case 401:
79
+ return {
80
+ expired: true,
81
+ active: false,
82
+ };
83
+ default:
84
+ return {
85
+ expired: false,
86
+ active: false,
87
+ };
88
+ }
89
+ }
90
+ throw new Error_1.APIError("Failed to validate session.", 500, undefined, undefined);
91
+ }
92
+ }
93
+ /**
94
+ * Refresh a session
95
+ * POST /med-assist/session/:sessionId/refresh
96
+ */
97
+ async refreshSession(sessionId, sessionToken) {
98
+ return await this.session.refresh(sessionId, sessionToken);
99
+ }
100
+ /**
101
+ * Feedback on a message
102
+ * PATCH /med-assist/session/:sessionId/:messageId
103
+ */
104
+ async sendFeedback(sessionId, messageId, feedback, feedbackReason) {
105
+ return await this.session.feedback(sessionId, messageId, feedback, feedbackReason);
106
+ }
107
+ }
108
+ exports.ResourceManager = ResourceManager;
@@ -0,0 +1,21 @@
1
+ import { BaseResource } from "../../internal/Api/BaseResource";
2
+ import { type SessionResponse, USER_FEEDBACK } from "./types";
3
+ /**
4
+ * SessionsResource class for managing sessions-related api calls
5
+ */
6
+ export declare class Session extends BaseResource {
7
+ /**
8
+ * create a new session
9
+ * POST /med-assist/session
10
+ */
11
+ private basePath;
12
+ create(userId: string): Promise<SessionResponse>;
13
+ retrieve(sessionId: string): Promise<SessionResponse>;
14
+ /**
15
+ * refresh a session
16
+ * POST /med-assist/session/refresh
17
+ */
18
+ refresh(sessionId: string, sessionToken: string): Promise<SessionResponse>;
19
+ feedback(sessionId: string, messageId: string, feedback: USER_FEEDBACK, feedback_reason?: string): Promise<void>;
20
+ }
21
+ //# sourceMappingURL=Session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Session.d.ts","sourceRoot":"","sources":["../../../src/resources/session/Session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,KAAK,eAAe,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE9D;;GAEG;AACH,qBAAa,OAAQ,SAAQ,YAAY;IAEvC;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAyB;IAC5B,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAIhD,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAIlE;;;OAGG;IACU,OAAO,CAClB,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,eAAe,CAAC;IAYd,QAAQ,CACnB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,aAAa,EACvB,eAAe,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,IAAI,CAAC;CAMjB"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Session = void 0;
4
+ const BaseResource_1 = require("../../internal/Api/BaseResource");
5
+ /**
6
+ * SessionsResource class for managing sessions-related api calls
7
+ */
8
+ class Session extends BaseResource_1.BaseResource {
9
+ //Ts implicitly calls super() here
10
+ /**
11
+ * create a new session
12
+ * POST /med-assist/session
13
+ */
14
+ basePath = "/med-assist/session";
15
+ async create(userId) {
16
+ return this.post(this.basePath, { user_id: userId });
17
+ }
18
+ async retrieve(sessionId) {
19
+ return this.get(`${this.basePath}/${sessionId}`);
20
+ }
21
+ /**
22
+ * refresh a session
23
+ * POST /med-assist/session/refresh
24
+ */
25
+ async refresh(sessionId, sessionToken) {
26
+ return this.get(`${this.basePath}/${sessionId}/refresh`, undefined, {
27
+ headers: {
28
+ "x-sess-token": sessionToken,
29
+ },
30
+ });
31
+ }
32
+ async feedback(sessionId, messageId, feedback, feedback_reason) {
33
+ return this.patch(`${this.basePath}/${sessionId}/${messageId}`, {
34
+ feedback,
35
+ feedback_reason,
36
+ });
37
+ }
38
+ }
39
+ exports.Session = Session;
@@ -0,0 +1,17 @@
1
+ export declare const USER_FEEDBACK: {
2
+ readonly LIKE: "LIKE";
3
+ readonly DISLIKE: "DISLIKE";
4
+ readonly NONE: "NONE";
5
+ };
6
+ export type USER_FEEDBACK = (typeof USER_FEEDBACK)[keyof typeof USER_FEEDBACK];
7
+ export interface SessionResponse {
8
+ session_id: string;
9
+ session_token?: string;
10
+ session_validity_s?: string;
11
+ msg?: string;
12
+ error?: {
13
+ code: string;
14
+ msg: string;
15
+ };
16
+ }
17
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/resources/session/types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa;;;;CAIhB,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC;AAE/E,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;CACH"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USER_FEEDBACK = void 0;
4
+ exports.USER_FEEDBACK = {
5
+ LIKE: "LIKE",
6
+ DISLIKE: "DISLIKE",
7
+ NONE: "NONE",
8
+ };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Types for agent configuration initialization
3
+ */
4
+ export interface AgentConfig {
5
+ agentId: string;
6
+ name: string;
7
+ prompt: string;
8
+ firstMessage: string;
9
+ language: string;
10
+ theme?: {
11
+ primaryColor?: string;
12
+ backgroundColor?: string;
13
+ fontFamily?: string;
14
+ };
15
+ metadata?: Record<string, unknown>;
16
+ }
17
+ export interface ResourceConfig {
18
+ agentId: string;
19
+ serverUrl: string;
20
+ authorization?: string;
21
+ }
22
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/resources/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE;QACN,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ /**
3
+ * Types for agent configuration initialization
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Shared types across the SDK
3
+ */
4
+ export * from '../internal/connection/types';
5
+ export * from '../internal/Error/types';
6
+ export * from '../messages/types';
7
+ export * from '../resources/session/types';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /**
3
+ * Shared types across the SDK
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ // Re-export common types from other modules
21
+ __exportStar(require("../internal/connection/types"), exports);
22
+ __exportStar(require("../internal/Error/types"), exports);
23
+ __exportStar(require("../messages/types"), exports);
24
+ __exportStar(require("../resources/session/types"), exports);
@@ -0,0 +1,45 @@
1
+ import { APIError, SynapseErrorCode } from "../internal/Error/Error";
2
+ export declare class ErrorUtils {
3
+ /**
4
+ * Check if an error is a specific API error type
5
+ */
6
+ static isAPIError(error: unknown): error is APIError<number, Headers, Record<string, unknown>>;
7
+ /**
8
+ * Check if an error is a network-related error
9
+ */
10
+ static isNetworkError(error: unknown): boolean;
11
+ /**
12
+ * Check if an error is a timeout error
13
+ */
14
+ static isTimeoutError(error: unknown): boolean;
15
+ /**
16
+ * Check if an error is an authentication error
17
+ */
18
+ static isAuthError(error: unknown): boolean;
19
+ /**
20
+ * Check if an error is a client error (4xx)
21
+ */
22
+ static isClientError(error: unknown): boolean;
23
+ /**
24
+ * Check if an error is a server error (5xx)
25
+ */
26
+ static isServerError(error: unknown): boolean;
27
+ /**
28
+ * Get user-friendly error message
29
+ */
30
+ static getUserFriendlyMessage(error: unknown): string;
31
+ /**
32
+ * Extract error details for logging
33
+ */
34
+ static getErrorDetails(error: unknown): {
35
+ type: string;
36
+ message: string;
37
+ code?: SynapseErrorCode | string;
38
+ status?: number;
39
+ timestamp?: Date;
40
+ stack?: string;
41
+ context?: Record<string, unknown>;
42
+ hint?: string;
43
+ };
44
+ }
45
+ //# sourceMappingURL=Error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../src/utils/Error.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAGR,gBAAgB,EAEjB,MAAM,yBAAyB,CAAC;AAGjC,qBAAa,UAAU;IACrB;;OAEG;IACH,MAAM,CAAC,UAAU,CACf,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAI9D;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAO9C;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAI9C;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAO3C;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAS7C;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAQ7C;;OAEG;IACH,MAAM,CAAC,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM;IA4BrD;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG;QACtC,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAAC;QACjC,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,IAAI,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAClC,IAAI,CAAC,EAAE,MAAM,CAAC;KACf;CAuCF"}
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErrorUtils = void 0;
4
+ const Error_1 = require("../internal/Error/Error");
5
+ // Utility functions for error handling
6
+ class ErrorUtils {
7
+ /**
8
+ * Check if an error is a specific API error type
9
+ */
10
+ static isAPIError(error) {
11
+ return error instanceof Error_1.APIError;
12
+ }
13
+ /**
14
+ * Check if an error is a network-related error
15
+ */
16
+ static isNetworkError(error) {
17
+ return (error instanceof Error_1.APIError &&
18
+ (error.status === 0 || error.status === undefined));
19
+ }
20
+ /**
21
+ * Check if an error is a timeout error
22
+ */
23
+ static isTimeoutError(error) {
24
+ return error instanceof Error_1.APIConnectionTimeoutError;
25
+ }
26
+ /**
27
+ * Check if an error is an authentication error
28
+ */
29
+ static isAuthError(error) {
30
+ return (error instanceof Error_1.UnauthorizedError ||
31
+ error instanceof Error_1.PermissionDeniedError);
32
+ }
33
+ /**
34
+ * Check if an error is a client error (4xx)
35
+ */
36
+ static isClientError(error) {
37
+ return (error instanceof Error_1.APIError &&
38
+ error.status !== undefined &&
39
+ error.status >= 400 &&
40
+ error.status < 500);
41
+ }
42
+ /**
43
+ * Check if an error is a server error (5xx)
44
+ */
45
+ static isServerError(error) {
46
+ return (error instanceof Error_1.APIError &&
47
+ error.status !== undefined &&
48
+ error.status >= 500);
49
+ }
50
+ /**
51
+ * Get user-friendly error message
52
+ */
53
+ static getUserFriendlyMessage(error) {
54
+ if (ErrorUtils.isNetworkError(error)) {
55
+ return "Unable to connect to the server. Please check your internet connection.";
56
+ }
57
+ if (ErrorUtils.isTimeoutError(error)) {
58
+ return "Request timed out. Please try again.";
59
+ }
60
+ if (ErrorUtils.isAuthError(error)) {
61
+ return "Authentication failed. Please log in again.";
62
+ }
63
+ if (ErrorUtils.isServerError(error)) {
64
+ return "Server error occurred. Please try again later.";
65
+ }
66
+ if (ErrorUtils.isAPIError(error)) {
67
+ return error.message;
68
+ }
69
+ if (error instanceof Error) {
70
+ return error.message;
71
+ }
72
+ return "An unexpected error occurred.";
73
+ }
74
+ /**
75
+ * Extract error details for logging
76
+ */
77
+ static getErrorDetails(error) {
78
+ if (ErrorUtils.isAPIError(error)) {
79
+ return {
80
+ type: error.name,
81
+ message: error.message,
82
+ code: error.code,
83
+ status: error.status,
84
+ timestamp: error.timestamp,
85
+ stack: error.stack,
86
+ context: error.context,
87
+ hint: error.hint,
88
+ };
89
+ }
90
+ if (error instanceof Error_1.SynapseError) {
91
+ return {
92
+ type: error.name,
93
+ message: error.message,
94
+ code: error.code,
95
+ timestamp: error.timestamp,
96
+ stack: error.stack,
97
+ context: error.context,
98
+ hint: error.hint,
99
+ };
100
+ }
101
+ if (error instanceof Error) {
102
+ return {
103
+ type: error.name,
104
+ message: error.message,
105
+ stack: error.stack,
106
+ };
107
+ }
108
+ return {
109
+ type: "Unknown",
110
+ message: String(error),
111
+ };
112
+ }
113
+ }
114
+ exports.ErrorUtils = ErrorUtils;
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@eka-care/medassist-core",
3
+ "version": "1.0.0",
4
+ "description": "TypeScript SDK for real-time medical chatbot experiences with session management, WebSocket connectivity, and media handling",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "README.md"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc --project tsconfig.build.json",
13
+ "prepublishOnly": "npm run build",
14
+ "clean": "rm -rf dist"
15
+ },
16
+ "keywords": [
17
+ "synapse",
18
+ "sdk",
19
+ "medical",
20
+ "chatbot",
21
+ "websocket",
22
+ "typescript"
23
+ ],
24
+ "author": "Geethanjali S",
25
+ "license": "MIT",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/eka-care/synapse-sdk.git"
29
+ },
30
+ "homepage": "https://github.com/eka-care/synapse-sdk/blob/main/README.md",
31
+ "dependencies": {
32
+ "jszip": "^3.10.1"
33
+ },
34
+ "devDependencies": {
35
+ "typescript": "^5.0.0"
36
+ },
37
+ "peerDependencies": {},
38
+ "publishConfig": {
39
+ "access": "public"
40
+ }
41
+ }