@layercode/js-sdk 2.3.0 → 2.3.1
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.
|
@@ -3614,7 +3614,7 @@ function arrayBufferToBase64(arrayBuffer) {
|
|
|
3614
3614
|
const NOOP = () => { };
|
|
3615
3615
|
const DEFAULT_WS_URL = 'wss://api.layercode.com/v1/agents/web/websocket';
|
|
3616
3616
|
// SDK version - updated when publishing
|
|
3617
|
-
const SDK_VERSION = '2.2.
|
|
3617
|
+
const SDK_VERSION = '2.2.1';
|
|
3618
3618
|
/**
|
|
3619
3619
|
* @class LayercodeClient
|
|
3620
3620
|
* @classdesc Core client for Layercode audio agent that manages audio recording, WebSocket communication, and speech processing.
|
|
@@ -3631,6 +3631,7 @@ class LayercodeClient {
|
|
|
3631
3631
|
agentId: options.agentId,
|
|
3632
3632
|
conversationId: (_a = options.conversationId) !== null && _a !== void 0 ? _a : null,
|
|
3633
3633
|
authorizeSessionEndpoint: options.authorizeSessionEndpoint,
|
|
3634
|
+
authorizeSessionRequest: options.authorizeSessionRequest,
|
|
3634
3635
|
metadata: (_b = options.metadata) !== null && _b !== void 0 ? _b : {},
|
|
3635
3636
|
vadResumeDelay: (_c = options.vadResumeDelay) !== null && _c !== void 0 ? _c : 500,
|
|
3636
3637
|
onConnect: (_d = options.onConnect) !== null && _d !== void 0 ? _d : NOOP,
|
|
@@ -3991,7 +3992,7 @@ class LayercodeClient {
|
|
|
3991
3992
|
this._resetTurnTracking();
|
|
3992
3993
|
this._stopAmplitudeMonitoring();
|
|
3993
3994
|
// Get conversation key from server
|
|
3994
|
-
|
|
3995
|
+
const authorizeSessionRequestBody = {
|
|
3995
3996
|
agent_id: this.options.agentId,
|
|
3996
3997
|
metadata: this.options.metadata,
|
|
3997
3998
|
sdk_version: SDK_VERSION,
|
|
@@ -4000,13 +4001,22 @@ class LayercodeClient {
|
|
|
4000
4001
|
if (this.options.conversationId) {
|
|
4001
4002
|
authorizeSessionRequestBody.conversation_id = this.options.conversationId;
|
|
4002
4003
|
}
|
|
4003
|
-
const
|
|
4004
|
+
const defaultRequestInit = {
|
|
4004
4005
|
method: 'POST',
|
|
4005
4006
|
headers: {
|
|
4006
4007
|
'Content-Type': 'application/json',
|
|
4007
4008
|
},
|
|
4008
4009
|
body: JSON.stringify(authorizeSessionRequestBody),
|
|
4009
|
-
}
|
|
4010
|
+
};
|
|
4011
|
+
const authorizeSessionResponse = this.options.authorizeSessionRequest
|
|
4012
|
+
? await this.options.authorizeSessionRequest({
|
|
4013
|
+
url: this.options.authorizeSessionEndpoint,
|
|
4014
|
+
body: authorizeSessionRequestBody,
|
|
4015
|
+
})
|
|
4016
|
+
: await fetch(this.options.authorizeSessionEndpoint, defaultRequestInit);
|
|
4017
|
+
if (!authorizeSessionResponse) {
|
|
4018
|
+
throw new Error('authorizeSessionRequest did not return a response');
|
|
4019
|
+
}
|
|
4010
4020
|
if (!authorizeSessionResponse.ok) {
|
|
4011
4021
|
throw new Error(`Failed to authorize conversation: ${authorizeSessionResponse.statusText}`);
|
|
4012
4022
|
}
|
|
@@ -4120,7 +4130,7 @@ class LayercodeClient {
|
|
|
4120
4130
|
const newStream = this.wavRecorder.getStream();
|
|
4121
4131
|
await this._reinitializeVAD(newStream);
|
|
4122
4132
|
}
|
|
4123
|
-
const reportedDeviceId = (_c = (_b = this.lastReportedDeviceId) !== null && _b !== void 0 ? _b : this.activeDeviceId) !== null && _c !== void 0 ? _c : (this.useSystemDefaultDevice ? 'default' : normalizedDeviceId !== null && normalizedDeviceId !== void 0 ? normalizedDeviceId : 'default');
|
|
4133
|
+
const reportedDeviceId = (_c = (_b = this.lastReportedDeviceId) !== null && _b !== void 0 ? _b : this.activeDeviceId) !== null && _c !== void 0 ? _c : (this.useSystemDefaultDevice ? 'default' : (normalizedDeviceId !== null && normalizedDeviceId !== void 0 ? normalizedDeviceId : 'default'));
|
|
4124
4134
|
console.debug(`Successfully switched to input device: ${reportedDeviceId}`);
|
|
4125
4135
|
}
|
|
4126
4136
|
catch (error) {
|
|
@@ -4157,7 +4167,7 @@ class LayercodeClient {
|
|
|
4157
4167
|
this.recorderStarted = true;
|
|
4158
4168
|
this._sendReadyIfNeeded();
|
|
4159
4169
|
}
|
|
4160
|
-
const reportedDeviceId = (_a = this.activeDeviceId) !== null && _a !== void 0 ? _a : (this.useSystemDefaultDevice ? 'default' : (_b = this.deviceId) !== null && _b !== void 0 ? _b : 'default');
|
|
4170
|
+
const reportedDeviceId = (_a = this.activeDeviceId) !== null && _a !== void 0 ? _a : (this.useSystemDefaultDevice ? 'default' : ((_b = this.deviceId) !== null && _b !== void 0 ? _b : 'default'));
|
|
4161
4171
|
if (reportedDeviceId !== previousReportedDeviceId) {
|
|
4162
4172
|
this.lastReportedDeviceId = reportedDeviceId;
|
|
4163
4173
|
if (this.options.onDeviceSwitched) {
|