@eka-care/medassist-core 1.0.53 → 1.0.55
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 +1 -0
- package/dist/Synapse.d.ts.map +1 -1
- package/dist/Synapse.js +32 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/internal/Api/HttpClient.d.ts.map +1 -1
- package/dist/internal/Api/HttpClient.js +6 -2
- package/dist/resources/index.d.ts +4 -0
- package/dist/resources/index.d.ts.map +1 -1
- package/dist/resources/index.js +9 -1
- package/dist/resources/types.d.ts +1 -1
- package/dist/resources/types.d.ts.map +1 -1
- package/dist/resources/voice/VoiceResource.d.ts +9 -0
- package/dist/resources/voice/VoiceResource.d.ts.map +1 -0
- package/dist/resources/voice/VoiceResource.js +18 -0
- package/dist/resources/voice/types.d.ts +19 -0
- package/dist/resources/voice/types.d.ts.map +1 -0
- package/dist/resources/voice/types.js +2 -0
- package/dist/types/index.d.ts +21 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/voice/VoiceAgent.d.ts +6 -7
- package/dist/voice/VoiceAgent.d.ts.map +1 -1
- package/dist/voice/VoiceAgent.js +70 -62
- package/dist/voice/index.d.ts +0 -1
- package/dist/voice/index.d.ts.map +1 -1
- package/dist/voice/index.js +0 -3
- package/package.json +1 -1
package/dist/Synapse.d.ts
CHANGED
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;AAgBH,OAAO,EACL,uBAAuB,EAExB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"Synapse.d.ts","sourceRoot":"","sources":["../src/Synapse.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAgBH,OAAO,EACL,uBAAuB,EAExB,MAAM,kBAAkB,CAAC;AAuB1B,OAA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
|
68
68
|
const sessionError = this.toSessionError(error, userFriendlyMessage || "Failed to start session", {
|
|
69
69
|
stage: "startSession",
|
|
70
70
|
details: errorDetails,
|
|
71
|
-
}, "Check network connectivity or
|
|
71
|
+
}, "Check network connectivity or recheck credentials before retrying.");
|
|
72
72
|
this.emitError(sessionError);
|
|
73
73
|
throw sessionError;
|
|
74
74
|
}
|
|
@@ -182,8 +182,8 @@ class SynapseSDK {
|
|
|
182
182
|
case ConnectionFactory_1.ConnectionType.SOCKET:
|
|
183
183
|
try {
|
|
184
184
|
const response = await this.resourceManager.callTool(this.sessionConfig.session_id, tool_id, message_id, this.sessionConfig.session_token, params);
|
|
185
|
-
if (response.
|
|
186
|
-
throw new Error_2.APIError(response.
|
|
185
|
+
if (response.error) {
|
|
186
|
+
throw new Error_2.APIError(response.error.msg, 500, response.error);
|
|
187
187
|
}
|
|
188
188
|
let cleanedResponse = {
|
|
189
189
|
data: { ...response.data },
|
|
@@ -278,9 +278,12 @@ class SynapseSDK {
|
|
|
278
278
|
}
|
|
279
279
|
get voice() {
|
|
280
280
|
if (!this._voice) {
|
|
281
|
-
this._voice = new VoiceAgent_1.VoiceAgent(this.buildVoiceConfig(), () => {
|
|
282
|
-
const
|
|
283
|
-
return {
|
|
281
|
+
this._voice = new VoiceAgent_1.VoiceAgent(this.buildVoiceConfig(), this.resourceManager, async () => {
|
|
282
|
+
const session = await this.resourceManager.createSession();
|
|
283
|
+
return {
|
|
284
|
+
sessionId: session.session_id,
|
|
285
|
+
sessionToken: session.session_token,
|
|
286
|
+
};
|
|
284
287
|
});
|
|
285
288
|
}
|
|
286
289
|
return this._voice;
|
|
@@ -305,8 +308,30 @@ class SynapseSDK {
|
|
|
305
308
|
},
|
|
306
309
|
};
|
|
307
310
|
}
|
|
311
|
+
toClientError(error) {
|
|
312
|
+
if (error instanceof Error_2.APIError) {
|
|
313
|
+
return {
|
|
314
|
+
message: (error.error?.msg) || error.message,
|
|
315
|
+
error: error.error,
|
|
316
|
+
code: error.code,
|
|
317
|
+
status: error.status,
|
|
318
|
+
context: error.context,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
if (error instanceof Error_2.SynapseError) {
|
|
322
|
+
return {
|
|
323
|
+
message: error.displayMessage || error.message,
|
|
324
|
+
code: error.code,
|
|
325
|
+
context: error.context,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
if (error instanceof Error) {
|
|
329
|
+
return { message: error.message };
|
|
330
|
+
}
|
|
331
|
+
return { message: "An unexpected error occurred" };
|
|
332
|
+
}
|
|
308
333
|
emitError(error) {
|
|
309
|
-
this.config.callbacks?.onError?.(error);
|
|
334
|
+
this.config.callbacks?.onError?.(this.toClientError(error));
|
|
310
335
|
}
|
|
311
336
|
toSessionError(error, fallbackMessage, context, hint) {
|
|
312
337
|
return (0, Error_2.normalizeError)(error, Error_2.SessionError, fallbackMessage, {
|
package/dist/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export { ErrorType } from "./internal/Error/types";
|
|
|
25
25
|
export { type Environment } from "./constants";
|
|
26
26
|
export { ErrorUtils } from "./utils/Error";
|
|
27
27
|
export * from "./media/audio/types";
|
|
28
|
-
export type { SendMessageOptions } from "./types";
|
|
28
|
+
export type { SendMessageOptions, TSynapseError } from "./types";
|
|
29
29
|
export { SYNAPSE_MESSAGE_TYPES } from "./messages/types";
|
|
30
30
|
export * from "./conversation";
|
|
31
31
|
export * from "./voice";
|
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,SAAS,CAAC;AAGjB,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AACtE,OAAO,EAAE,mBAAmB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AC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;IAI7D,KAAK,CAAC,CAAC,EACX,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,CAAC,CAAC;IAIb,OAAO,CAAC,QAAQ;YAUF,WAAW;CAyB1B"}
|
|
@@ -117,9 +117,13 @@ class HttpClient {
|
|
|
117
117
|
let errorData;
|
|
118
118
|
try {
|
|
119
119
|
errorData = await response.json();
|
|
120
|
+
const body = errorData;
|
|
121
|
+
const nestedError = body?.error;
|
|
120
122
|
errorMessage =
|
|
121
|
-
|
|
122
|
-
|
|
123
|
+
body?.message ||
|
|
124
|
+
body?.msg ||
|
|
125
|
+
nestedError?.msg ||
|
|
126
|
+
nestedError?.message ||
|
|
123
127
|
response.statusText;
|
|
124
128
|
}
|
|
125
129
|
catch (error) {
|
|
@@ -5,11 +5,13 @@ import { type ResourceConfig } from "./types";
|
|
|
5
5
|
import { type SessionResponse, type USER_FEEDBACK } from "./session/types";
|
|
6
6
|
import type { ToolCallResponse } from "./toolCall/types";
|
|
7
7
|
import type { AgentConfigResponse, TContext } from "../types";
|
|
8
|
+
import type { IceServersResponse, VoiceOfferRequest, VoiceOfferResponse } from "./voice/types";
|
|
8
9
|
export declare class ResourceManager {
|
|
9
10
|
private resourceConfig;
|
|
10
11
|
private httpClient;
|
|
11
12
|
private session;
|
|
12
13
|
private config;
|
|
14
|
+
private voiceResource;
|
|
13
15
|
constructor(config: ResourceConfig);
|
|
14
16
|
/**
|
|
15
17
|
* Fetch agent configuration and create session
|
|
@@ -39,5 +41,7 @@ export declare class ResourceManager {
|
|
|
39
41
|
* POST /med-assist/api-call-tool
|
|
40
42
|
*/
|
|
41
43
|
callTool(sessionId: string, toolId: string, message_id: string, session_token: string, toolParams?: Record<string, unknown>): Promise<ToolCallResponse>;
|
|
44
|
+
getVoiceIceServers(sessionId: string, sessionToken: string): Promise<IceServersResponse>;
|
|
45
|
+
sendVoiceOffer(body: VoiceOfferRequest): Promise<VoiceOfferResponse>;
|
|
42
46
|
}
|
|
43
47
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resources/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAG9C,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAwB,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGpF,qBAAa,eAAe;IAC1B,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,MAAM,CAAS;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resources/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAG9C,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAwB,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGpF,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAE/F,qBAAa,eAAe;IAC1B,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,aAAa,CAAgB;gBAEzB,MAAM,EAAE,cAAc;IAmBlC;;OAEG;IACU,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,eAAe,CAAC;IAsC5E,cAAc,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAU3D;;;OAGG;IACU,eAAe,CAC1B,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC;IA+CjD;;;OAGG;IACU,cAAc,CACzB,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,eAAe,CAAC;IAI3B;;;OAGG;IACU,YAAY,CACvB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,aAAa,EACvB,cAAc,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,IAAI,CAAC;IAShB;;;OAGG;IACU,QAAQ,CACnB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,EACrB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACnC,OAAO,CAAC,gBAAgB,CAAC;IAIf,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAIxF,cAAc,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAGlF"}
|
package/dist/resources/index.js
CHANGED
|
@@ -8,11 +8,13 @@ const HttpClient_1 = require("../internal/Api/HttpClient");
|
|
|
8
8
|
const Session_1 = require("./session/Session");
|
|
9
9
|
const Error_1 = require("../internal/Error/Error");
|
|
10
10
|
const Config_1 = require("./config/Config");
|
|
11
|
+
const VoiceResource_1 = require("./voice/VoiceResource");
|
|
11
12
|
class ResourceManager {
|
|
12
13
|
resourceConfig;
|
|
13
14
|
httpClient;
|
|
14
15
|
session;
|
|
15
16
|
config;
|
|
17
|
+
voiceResource;
|
|
16
18
|
constructor(config) {
|
|
17
19
|
this.resourceConfig = config;
|
|
18
20
|
// Set up HTTP client with agentId header for all requests
|
|
@@ -26,8 +28,8 @@ class ResourceManager {
|
|
|
26
28
|
// authorization: config.authorization,
|
|
27
29
|
});
|
|
28
30
|
this.config = new Config_1.Config(this.httpClient);
|
|
29
|
-
// Initialize sessions resource with the configured client
|
|
30
31
|
this.session = new Session_1.Session(this.httpClient);
|
|
32
|
+
this.voiceResource = new VoiceResource_1.VoiceResource(this.httpClient);
|
|
31
33
|
}
|
|
32
34
|
/**
|
|
33
35
|
* Fetch agent configuration and create session
|
|
@@ -144,5 +146,11 @@ class ResourceManager {
|
|
|
144
146
|
async callTool(sessionId, toolId, message_id, session_token, toolParams) {
|
|
145
147
|
return await this.session.callTool(sessionId, toolId, message_id, session_token, toolParams);
|
|
146
148
|
}
|
|
149
|
+
async getVoiceIceServers(sessionId, sessionToken) {
|
|
150
|
+
return await this.voiceResource.getIceServers(sessionId, sessionToken);
|
|
151
|
+
}
|
|
152
|
+
async sendVoiceOffer(body) {
|
|
153
|
+
return await this.voiceResource.sendOffer(body);
|
|
154
|
+
}
|
|
147
155
|
}
|
|
148
156
|
exports.ResourceManager = ResourceManager;
|
|
@@ -1 +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;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,
|
|
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;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,EAAE,MAAM,CAAC;KACb,CAAA;CACF,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseResource } from "../../internal/Api/BaseResource";
|
|
2
|
+
import type { IceServersResponse, VoiceOfferRequest, VoiceOfferResponse } from "./types";
|
|
3
|
+
export declare class VoiceResource extends BaseResource {
|
|
4
|
+
private static readonly ICE_SERVERS_PATH;
|
|
5
|
+
private static readonly OFFER_PATH;
|
|
6
|
+
getIceServers(sessionId: string, sessionToken: string): Promise<IceServersResponse>;
|
|
7
|
+
sendOffer(body: VoiceOfferRequest): Promise<VoiceOfferResponse>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=VoiceResource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VoiceResource.d.ts","sourceRoot":"","sources":["../../../src/resources/voice/VoiceResource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAEzF,qBAAa,aAAc,SAAQ,YAAY;IAC7C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAmC;IAC3E,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAA6B;IAEzD,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAOnF,SAAS,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAGtE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VoiceResource = void 0;
|
|
4
|
+
const BaseResource_1 = require("../../internal/Api/BaseResource");
|
|
5
|
+
class VoiceResource extends BaseResource_1.BaseResource {
|
|
6
|
+
static ICE_SERVERS_PATH = "/med-assist/voice/ice-servers";
|
|
7
|
+
static OFFER_PATH = "/med-assist/voice/offer";
|
|
8
|
+
async getIceServers(sessionId, sessionToken) {
|
|
9
|
+
return this.get(VoiceResource.ICE_SERVERS_PATH, {
|
|
10
|
+
session_id: sessionId,
|
|
11
|
+
token: sessionToken,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
async sendOffer(body) {
|
|
15
|
+
return this.post(VoiceResource.OFFER_PATH, body);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.VoiceResource = VoiceResource;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ResourceResponse } from "../types";
|
|
2
|
+
export interface IceServersResponse {
|
|
3
|
+
ice_servers: RTCIceServer[];
|
|
4
|
+
}
|
|
5
|
+
export interface VoiceOfferRequest {
|
|
6
|
+
sdp: string;
|
|
7
|
+
type: string;
|
|
8
|
+
pc_id: string | null;
|
|
9
|
+
request_data: {
|
|
10
|
+
session_id: string;
|
|
11
|
+
token: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface VoiceOfferResponse extends ResourceResponse {
|
|
15
|
+
sdp: string;
|
|
16
|
+
type: string;
|
|
17
|
+
pc_id: string;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/resources/voice/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,YAAY,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,YAAY,EAAE;QACZ,UAAU,EAAE,MAAM,CAAC;QACnB,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;CACH;AAED,MAAM,WAAW,kBAAmB,SAAQ,gBAAgB;IAC1D,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -30,9 +30,29 @@ export interface SynapseSDKOverrides {
|
|
|
30
30
|
primaryColor?: string;
|
|
31
31
|
}
|
|
32
32
|
export type SynapseSDKError = SynapseError | Error;
|
|
33
|
+
/**
|
|
34
|
+
* Unified error shape exposed to SDK consumers.
|
|
35
|
+
* All internal errors (APIError, SessionError, ConnectionError, etc.)
|
|
36
|
+
* are normalized to this before reaching the client.
|
|
37
|
+
*/
|
|
38
|
+
export interface TSynapseError {
|
|
39
|
+
/** Human-readable message suitable for display */
|
|
40
|
+
message: string;
|
|
41
|
+
/** Parsed API error body, when the error originated from an HTTP response */
|
|
42
|
+
error?: {
|
|
43
|
+
code?: string;
|
|
44
|
+
msg?: string;
|
|
45
|
+
} & Record<string, unknown>;
|
|
46
|
+
/** Internal error classification (e.g. "SESSION_ERROR", "CONNECTION_ERROR") */
|
|
47
|
+
code?: string;
|
|
48
|
+
/** HTTP status code, when applicable */
|
|
49
|
+
status?: number;
|
|
50
|
+
/** Extra context set by the SDK (stage, sessionId, etc.) */
|
|
51
|
+
context?: Record<string, unknown>;
|
|
52
|
+
}
|
|
33
53
|
export interface SynapseSDKCallbacks {
|
|
34
54
|
onSessionRefreshed?: (sessionResponse: SessionResponse) => void;
|
|
35
|
-
onError?: (error:
|
|
55
|
+
onError?: (error: TSynapseError) => void;
|
|
36
56
|
}
|
|
37
57
|
export interface SynapseSDKConfig {
|
|
38
58
|
agentId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7F,OAAO,KAAK,EAAE,aAA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MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,mBAAmB;IAClC,kBAAkB,CAAC,EAAE,CAAC,eAAe,EAAE,eAAe,KAAK,IAAI,CAAC;IAChE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;CAC1C;AACD,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,SAAS,CAAC,EAAE,mBAAmB,CAAC;IAChC,SAAS,CAAC,EAAE,mBAAmB,CAAC;IAChC,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;AACD,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { VOICE_AGENT_STATE, type VoiceAgentConfig, type VoiceSessionCredentials } from "./types";
|
|
2
|
+
import type { ResourceManager } from "../resources";
|
|
2
3
|
export declare class VoiceAgent {
|
|
3
4
|
private config;
|
|
5
|
+
private resourceManager;
|
|
4
6
|
private getCredentials;
|
|
5
7
|
private emitter;
|
|
6
8
|
private remoteAnalyser;
|
|
@@ -14,11 +16,11 @@ export declare class VoiceAgent {
|
|
|
14
16
|
private _isMuted;
|
|
15
17
|
private manuallyDisconnected;
|
|
16
18
|
private _hasConnectionFailureNotified;
|
|
17
|
-
/** true while local mic audio is above the speaking threshold */
|
|
18
19
|
private _userSpeaking;
|
|
19
|
-
/** debounce timer: fires THINKING after user goes silent */
|
|
20
20
|
private _silenceTimer;
|
|
21
|
-
|
|
21
|
+
private _cachedIceServers;
|
|
22
|
+
private _iceServersCachedAt;
|
|
23
|
+
constructor(config: VoiceAgentConfig, resourceManager: ResourceManager, getCredentials: () => Promise<VoiceSessionCredentials>);
|
|
22
24
|
get state(): VOICE_AGENT_STATE;
|
|
23
25
|
get isMuted(): boolean;
|
|
24
26
|
on(event: string, listener: (...args: unknown[]) => void): void;
|
|
@@ -28,14 +30,11 @@ export declare class VoiceAgent {
|
|
|
28
30
|
toggleMute(): void;
|
|
29
31
|
reset(): void;
|
|
30
32
|
destroy(): void;
|
|
33
|
+
private fetchIceServers;
|
|
31
34
|
private setState;
|
|
32
35
|
private clearSilenceTimer;
|
|
33
36
|
private handleConnectionFailure;
|
|
34
37
|
private releaseResources;
|
|
35
|
-
/**
|
|
36
|
-
* Analyse the local microphone stream to detect when the user
|
|
37
|
-
* stops talking → transition LISTENING → THINKING.
|
|
38
|
-
*/
|
|
39
38
|
private startLocalAudioAnalysis;
|
|
40
39
|
private handleRemoteTrack;
|
|
41
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VoiceAgent.d.ts","sourceRoot":"","sources":["../../src/voice/VoiceAgent.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,iBAAiB,EAEjB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAE7B,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"VoiceAgent.d.ts","sourceRoot":"","sources":["../../src/voice/VoiceAgent.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,iBAAiB,EAEjB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAE7B,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC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AAiB;IAOzB,OAAO,CAAC,uBAAuB;IAY/B,OAAO,CAAC,gBAAgB;IAkCxB,OAAO,CAAC,uBAAuB;IA6B/B,OAAO,CAAC,iBAAiB;CAsB1B"}
|
package/dist/voice/VoiceAgent.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VoiceAgent = void 0;
|
|
4
|
-
const constants_1 = require("../constants");
|
|
5
4
|
const EventEmitter_1 = require("../internal/events/EventEmitter");
|
|
6
5
|
const VoiceAudioAnalyser_1 = require("./VoiceAudioAnalyser");
|
|
6
|
+
const Error_1 = require("../internal/Error/Error");
|
|
7
7
|
const types_1 = require("./types");
|
|
8
|
-
const DEFAULT_ICE_SERVERS = [
|
|
9
|
-
{ urls: "stun:stun.l.google.com:19302" },
|
|
10
|
-
];
|
|
11
8
|
const DEFAULT_ICE_GATHERING_TIMEOUT_MS = 3000;
|
|
12
9
|
const DEFAULT_SPEAKING_THRESHOLD = 8;
|
|
13
|
-
const
|
|
10
|
+
const ICE_SERVERS_CACHE_TTL_MS = 60 * 60 * 1000; // 60 minutes
|
|
14
11
|
const USER_SILENCE_DEBOUNCE_MS = 600;
|
|
15
12
|
function waitForIceGathering(pc, timeoutMs) {
|
|
16
13
|
return new Promise((resolve) => {
|
|
@@ -29,6 +26,7 @@ function waitForIceGathering(pc, timeoutMs) {
|
|
|
29
26
|
}
|
|
30
27
|
class VoiceAgent {
|
|
31
28
|
config;
|
|
29
|
+
resourceManager;
|
|
32
30
|
getCredentials;
|
|
33
31
|
emitter = new EventEmitter_1.EventEmitter();
|
|
34
32
|
remoteAnalyser = new VoiceAudioAnalyser_1.VoiceAudioAnalyser();
|
|
@@ -42,12 +40,13 @@ class VoiceAgent {
|
|
|
42
40
|
_isMuted = false;
|
|
43
41
|
manuallyDisconnected = false;
|
|
44
42
|
_hasConnectionFailureNotified = false;
|
|
45
|
-
/** true while local mic audio is above the speaking threshold */
|
|
46
43
|
_userSpeaking = false;
|
|
47
|
-
/** debounce timer: fires THINKING after user goes silent */
|
|
48
44
|
_silenceTimer = null;
|
|
49
|
-
|
|
45
|
+
_cachedIceServers = null;
|
|
46
|
+
_iceServersCachedAt = 0;
|
|
47
|
+
constructor(config, resourceManager, getCredentials) {
|
|
50
48
|
this.config = config;
|
|
49
|
+
this.resourceManager = resourceManager;
|
|
51
50
|
this.getCredentials = getCredentials;
|
|
52
51
|
}
|
|
53
52
|
get state() {
|
|
@@ -63,7 +62,7 @@ class VoiceAgent {
|
|
|
63
62
|
this.emitter.off(event, listener);
|
|
64
63
|
}
|
|
65
64
|
async connect() {
|
|
66
|
-
const credentials = this.getCredentials();
|
|
65
|
+
const credentials = await this.getCredentials();
|
|
67
66
|
this.setState(types_1.VOICE_AGENT_STATE.CONNECTING);
|
|
68
67
|
this._hasConnectionFailureNotified = false;
|
|
69
68
|
try {
|
|
@@ -81,21 +80,15 @@ class VoiceAgent {
|
|
|
81
80
|
video: false,
|
|
82
81
|
});
|
|
83
82
|
this.localStream = stream;
|
|
84
|
-
const iceServers = this.
|
|
85
|
-
const pc = new RTCPeerConnection({ iceServers });
|
|
83
|
+
const iceServers = await this.fetchIceServers(credentials);
|
|
84
|
+
const pc = new RTCPeerConnection({ iceServers, iceTransportPolicy: "all" });
|
|
86
85
|
this.pc = pc;
|
|
87
86
|
// Data channel required by SmallWebRTCTransport — without it the server
|
|
88
87
|
// connects ICE but drops queued greeting/audio.
|
|
89
|
-
this.dataChannel = pc.createDataChannel("pipecat-events", {
|
|
90
|
-
ordered: true,
|
|
91
|
-
});
|
|
88
|
+
this.dataChannel = pc.createDataChannel("pipecat-events", { ordered: true });
|
|
92
89
|
this.dataChannel.onopen = () => console.log("data channel open");
|
|
93
|
-
this.dataChannel.onclose = () =>
|
|
94
|
-
|
|
95
|
-
};
|
|
96
|
-
this.dataChannel.onerror = () => {
|
|
97
|
-
this.handleConnectionFailure(new Error("Data channel error"), "Voice connection failed");
|
|
98
|
-
};
|
|
90
|
+
this.dataChannel.onclose = () => this.handleConnectionFailure(new Error("Data channel closed"), "Voice connection failed");
|
|
91
|
+
this.dataChannel.onerror = () => this.handleConnectionFailure(new Error("Data channel error"), "Voice connection failed");
|
|
99
92
|
stream.getAudioTracks().forEach((track) => pc.addTrack(track, stream));
|
|
100
93
|
pc.ontrack = (event) => this.handleRemoteTrack(event);
|
|
101
94
|
pc.onconnectionstatechange = () => {
|
|
@@ -103,15 +96,13 @@ class VoiceAgent {
|
|
|
103
96
|
this.setState(types_1.VOICE_AGENT_STATE.LISTENING);
|
|
104
97
|
this.startLocalAudioAnalysis(stream);
|
|
105
98
|
}
|
|
106
|
-
else if (pc.connectionState === "failed" ||
|
|
107
|
-
pc.connectionState === "closed") {
|
|
99
|
+
else if (pc.connectionState === "failed" || pc.connectionState === "closed") {
|
|
108
100
|
this.releaseResources();
|
|
109
101
|
this.setState(types_1.VOICE_AGENT_STATE.IDLE);
|
|
110
102
|
}
|
|
111
103
|
};
|
|
112
104
|
pc.oniceconnectionstatechange = () => {
|
|
113
|
-
if ((pc.iceConnectionState === "connected" ||
|
|
114
|
-
pc.iceConnectionState === "completed") &&
|
|
105
|
+
if ((pc.iceConnectionState === "connected" || pc.iceConnectionState === "completed") &&
|
|
115
106
|
this._state === types_1.VOICE_AGENT_STATE.CONNECTING) {
|
|
116
107
|
this.setState(types_1.VOICE_AGENT_STATE.LISTENING);
|
|
117
108
|
this.startLocalAudioAnalysis(stream);
|
|
@@ -125,33 +116,33 @@ class VoiceAgent {
|
|
|
125
116
|
await pc.setLocalDescription(offer);
|
|
126
117
|
const timeoutMs = this.config.iceGatheringTimeoutMs ?? DEFAULT_ICE_GATHERING_TIMEOUT_MS;
|
|
127
118
|
await waitForIceGathering(pc, timeoutMs);
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
pc_id: this.pcId,
|
|
137
|
-
request_data: {
|
|
138
|
-
session_id: sessionCredentials.sessionId,
|
|
139
|
-
token: sessionCredentials.sessionToken,
|
|
140
|
-
},
|
|
141
|
-
}),
|
|
119
|
+
const buildOfferBody = (creds) => ({
|
|
120
|
+
sdp: pc.localDescription.sdp,
|
|
121
|
+
type: pc.localDescription.type,
|
|
122
|
+
pc_id: this.pcId,
|
|
123
|
+
request_data: {
|
|
124
|
+
session_id: creds.sessionId,
|
|
125
|
+
token: creds.sessionToken,
|
|
126
|
+
},
|
|
142
127
|
});
|
|
143
|
-
let
|
|
144
|
-
|
|
145
|
-
await this.
|
|
146
|
-
const refreshedCredentials = this.getCredentials();
|
|
147
|
-
response = await createOfferRequest(refreshedCredentials);
|
|
128
|
+
let answer;
|
|
129
|
+
try {
|
|
130
|
+
answer = await this.resourceManager.sendVoiceOffer(buildOfferBody(credentials));
|
|
148
131
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
132
|
+
catch (err) {
|
|
133
|
+
if (err instanceof Error_1.APIError && err.status === 401 && this.config.handleRefresh) {
|
|
134
|
+
await this.config.handleRefresh();
|
|
135
|
+
const refreshed = await this.getCredentials();
|
|
136
|
+
// If the retry also fails, let it propagate to the outer catch → handleConnectionFailure
|
|
137
|
+
answer = await this.resourceManager.sendVoiceOffer(buildOfferBody(refreshed));
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
throw err;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (!answer) {
|
|
144
|
+
throw new Error("No answer received from voice offer");
|
|
153
145
|
}
|
|
154
|
-
const answer = await response.json();
|
|
155
146
|
this.pcId = answer.pc_id;
|
|
156
147
|
if (pc.signalingState === "closed")
|
|
157
148
|
return;
|
|
@@ -174,9 +165,7 @@ class VoiceAgent {
|
|
|
174
165
|
if (!track)
|
|
175
166
|
return;
|
|
176
167
|
const wasEnabled = track.enabled;
|
|
177
|
-
this.localStream.getAudioTracks().forEach((t) => {
|
|
178
|
-
t.enabled = !wasEnabled;
|
|
179
|
-
});
|
|
168
|
+
this.localStream.getAudioTracks().forEach((t) => { t.enabled = !wasEnabled; });
|
|
180
169
|
this._isMuted = wasEnabled;
|
|
181
170
|
this.clearSilenceTimer();
|
|
182
171
|
this._userSpeaking = false;
|
|
@@ -191,6 +180,35 @@ class VoiceAgent {
|
|
|
191
180
|
this._state = types_1.VOICE_AGENT_STATE.IDLE;
|
|
192
181
|
}
|
|
193
182
|
// ──────────────────────────── private ────────────────────────────
|
|
183
|
+
async fetchIceServers(credentials) {
|
|
184
|
+
if (this.config.iceServers)
|
|
185
|
+
return this.config.iceServers;
|
|
186
|
+
const now = Date.now();
|
|
187
|
+
if (this._cachedIceServers && now - this._iceServersCachedAt < ICE_SERVERS_CACHE_TTL_MS) {
|
|
188
|
+
return this._cachedIceServers;
|
|
189
|
+
}
|
|
190
|
+
let resp;
|
|
191
|
+
try {
|
|
192
|
+
resp = await this.resourceManager.getVoiceIceServers(credentials.sessionId, credentials.sessionToken);
|
|
193
|
+
}
|
|
194
|
+
catch (err) {
|
|
195
|
+
if (err instanceof Error_1.APIError && err.status === 401 && this.config.handleRefresh) {
|
|
196
|
+
await this.config.handleRefresh();
|
|
197
|
+
const refreshed = await this.getCredentials();
|
|
198
|
+
// If the retry also fails, propagate — caller's outer catch → handleConnectionFailure
|
|
199
|
+
resp = await this.resourceManager.getVoiceIceServers(refreshed.sessionId, refreshed.sessionToken);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
throw err;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (!Array.isArray(resp?.ice_servers) || resp.ice_servers.length === 0) {
|
|
206
|
+
throw new Error("ICE servers response is empty");
|
|
207
|
+
}
|
|
208
|
+
this._cachedIceServers = resp.ice_servers;
|
|
209
|
+
this._iceServersCachedAt = Date.now();
|
|
210
|
+
return this._cachedIceServers;
|
|
211
|
+
}
|
|
194
212
|
setState(next) {
|
|
195
213
|
this._state = next;
|
|
196
214
|
this.emitter.emit(types_1.VOICE_AGENT_EVENTS.STATE_CHANGED, next);
|
|
@@ -241,14 +259,9 @@ class VoiceAgent {
|
|
|
241
259
|
this.remoteAudio.srcObject = null;
|
|
242
260
|
}
|
|
243
261
|
}
|
|
244
|
-
/**
|
|
245
|
-
* Analyse the local microphone stream to detect when the user
|
|
246
|
-
* stops talking → transition LISTENING → THINKING.
|
|
247
|
-
*/
|
|
248
262
|
startLocalAudioAnalysis(stream) {
|
|
249
263
|
const threshold = this.config.speakingThreshold ?? DEFAULT_SPEAKING_THRESHOLD;
|
|
250
264
|
this.localAnalyser.start(stream, threshold, (isUserSpeaking) => {
|
|
251
|
-
// Only act when the connection is live and not muted / agent speaking
|
|
252
265
|
if (this._state !== types_1.VOICE_AGENT_STATE.LISTENING &&
|
|
253
266
|
this._state !== types_1.VOICE_AGENT_STATE.THINKING) {
|
|
254
267
|
return;
|
|
@@ -256,17 +269,14 @@ class VoiceAgent {
|
|
|
256
269
|
if (isUserSpeaking) {
|
|
257
270
|
this._userSpeaking = true;
|
|
258
271
|
this.clearSilenceTimer();
|
|
259
|
-
// If we had already moved to THINKING, go back to LISTENING
|
|
260
272
|
if (this._state === types_1.VOICE_AGENT_STATE.THINKING) {
|
|
261
273
|
this.setState(types_1.VOICE_AGENT_STATE.LISTENING);
|
|
262
274
|
}
|
|
263
275
|
}
|
|
264
276
|
else if (this._userSpeaking && this._silenceTimer === null) {
|
|
265
|
-
// User just went silent — debounce before entering THINKING
|
|
266
277
|
this._silenceTimer = setTimeout(() => {
|
|
267
278
|
this._silenceTimer = null;
|
|
268
|
-
if (this._userSpeaking &&
|
|
269
|
-
this._state === types_1.VOICE_AGENT_STATE.LISTENING) {
|
|
279
|
+
if (this._userSpeaking && this._state === types_1.VOICE_AGENT_STATE.LISTENING) {
|
|
270
280
|
this._userSpeaking = false;
|
|
271
281
|
this.setState(types_1.VOICE_AGENT_STATE.THINKING);
|
|
272
282
|
}
|
|
@@ -284,7 +294,6 @@ class VoiceAgent {
|
|
|
284
294
|
const threshold = this.config.speakingThreshold ?? DEFAULT_SPEAKING_THRESHOLD;
|
|
285
295
|
this.remoteAnalyser.start(remoteStream, threshold, (isSpeaking) => {
|
|
286
296
|
if (isSpeaking) {
|
|
287
|
-
// Agent started speaking — cancel any pending silence timer
|
|
288
297
|
this.clearSilenceTimer();
|
|
289
298
|
this._userSpeaking = false;
|
|
290
299
|
if (this._state !== types_1.VOICE_AGENT_STATE.SPEAKING) {
|
|
@@ -292,7 +301,6 @@ class VoiceAgent {
|
|
|
292
301
|
}
|
|
293
302
|
}
|
|
294
303
|
else if (this._state === types_1.VOICE_AGENT_STATE.SPEAKING) {
|
|
295
|
-
// Agent stopped — go back to listening
|
|
296
304
|
this.setState(types_1.VOICE_AGENT_STATE.LISTENING);
|
|
297
305
|
}
|
|
298
306
|
});
|
package/dist/voice/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/voice/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/voice/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
|
package/dist/voice/index.js
CHANGED
|
@@ -14,7 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.VoiceAgent = void 0;
|
|
18
|
-
var VoiceAgent_1 = require("./VoiceAgent");
|
|
19
|
-
Object.defineProperty(exports, "VoiceAgent", { enumerable: true, get: function () { return VoiceAgent_1.VoiceAgent; } });
|
|
20
17
|
__exportStar(require("./types"), exports);
|
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.55",
|
|
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",
|