@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.
|
@@ -3620,7 +3620,7 @@ registerProcessor('audio_processor', AudioProcessor);
|
|
|
3620
3620
|
const NOOP = () => { };
|
|
3621
3621
|
const DEFAULT_WS_URL = 'wss://api.layercode.com/v1/agents/web/websocket';
|
|
3622
3622
|
// SDK version - updated when publishing
|
|
3623
|
-
const SDK_VERSION = '2.2.
|
|
3623
|
+
const SDK_VERSION = '2.2.1';
|
|
3624
3624
|
/**
|
|
3625
3625
|
* @class LayercodeClient
|
|
3626
3626
|
* @classdesc Core client for Layercode audio agent that manages audio recording, WebSocket communication, and speech processing.
|
|
@@ -3637,6 +3637,7 @@ registerProcessor('audio_processor', AudioProcessor);
|
|
|
3637
3637
|
agentId: options.agentId,
|
|
3638
3638
|
conversationId: (_a = options.conversationId) !== null && _a !== void 0 ? _a : null,
|
|
3639
3639
|
authorizeSessionEndpoint: options.authorizeSessionEndpoint,
|
|
3640
|
+
authorizeSessionRequest: options.authorizeSessionRequest,
|
|
3640
3641
|
metadata: (_b = options.metadata) !== null && _b !== void 0 ? _b : {},
|
|
3641
3642
|
vadResumeDelay: (_c = options.vadResumeDelay) !== null && _c !== void 0 ? _c : 500,
|
|
3642
3643
|
onConnect: (_d = options.onConnect) !== null && _d !== void 0 ? _d : NOOP,
|
|
@@ -3997,7 +3998,7 @@ registerProcessor('audio_processor', AudioProcessor);
|
|
|
3997
3998
|
this._resetTurnTracking();
|
|
3998
3999
|
this._stopAmplitudeMonitoring();
|
|
3999
4000
|
// Get conversation key from server
|
|
4000
|
-
|
|
4001
|
+
const authorizeSessionRequestBody = {
|
|
4001
4002
|
agent_id: this.options.agentId,
|
|
4002
4003
|
metadata: this.options.metadata,
|
|
4003
4004
|
sdk_version: SDK_VERSION,
|
|
@@ -4006,13 +4007,22 @@ registerProcessor('audio_processor', AudioProcessor);
|
|
|
4006
4007
|
if (this.options.conversationId) {
|
|
4007
4008
|
authorizeSessionRequestBody.conversation_id = this.options.conversationId;
|
|
4008
4009
|
}
|
|
4009
|
-
const
|
|
4010
|
+
const defaultRequestInit = {
|
|
4010
4011
|
method: 'POST',
|
|
4011
4012
|
headers: {
|
|
4012
4013
|
'Content-Type': 'application/json',
|
|
4013
4014
|
},
|
|
4014
4015
|
body: JSON.stringify(authorizeSessionRequestBody),
|
|
4015
|
-
}
|
|
4016
|
+
};
|
|
4017
|
+
const authorizeSessionResponse = this.options.authorizeSessionRequest
|
|
4018
|
+
? await this.options.authorizeSessionRequest({
|
|
4019
|
+
url: this.options.authorizeSessionEndpoint,
|
|
4020
|
+
body: authorizeSessionRequestBody,
|
|
4021
|
+
})
|
|
4022
|
+
: await fetch(this.options.authorizeSessionEndpoint, defaultRequestInit);
|
|
4023
|
+
if (!authorizeSessionResponse) {
|
|
4024
|
+
throw new Error('authorizeSessionRequest did not return a response');
|
|
4025
|
+
}
|
|
4016
4026
|
if (!authorizeSessionResponse.ok) {
|
|
4017
4027
|
throw new Error(`Failed to authorize conversation: ${authorizeSessionResponse.statusText}`);
|
|
4018
4028
|
}
|
|
@@ -4126,7 +4136,7 @@ registerProcessor('audio_processor', AudioProcessor);
|
|
|
4126
4136
|
const newStream = this.wavRecorder.getStream();
|
|
4127
4137
|
await this._reinitializeVAD(newStream);
|
|
4128
4138
|
}
|
|
4129
|
-
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');
|
|
4139
|
+
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'));
|
|
4130
4140
|
console.debug(`Successfully switched to input device: ${reportedDeviceId}`);
|
|
4131
4141
|
}
|
|
4132
4142
|
catch (error) {
|
|
@@ -4163,7 +4173,7 @@ registerProcessor('audio_processor', AudioProcessor);
|
|
|
4163
4173
|
this.recorderStarted = true;
|
|
4164
4174
|
this._sendReadyIfNeeded();
|
|
4165
4175
|
}
|
|
4166
|
-
const reportedDeviceId = (_a = this.activeDeviceId) !== null && _a !== void 0 ? _a : (this.useSystemDefaultDevice ? 'default' : (_b = this.deviceId) !== null && _b !== void 0 ? _b : 'default');
|
|
4176
|
+
const reportedDeviceId = (_a = this.activeDeviceId) !== null && _a !== void 0 ? _a : (this.useSystemDefaultDevice ? 'default' : ((_b = this.deviceId) !== null && _b !== void 0 ? _b : 'default'));
|
|
4167
4177
|
if (reportedDeviceId !== previousReportedDeviceId) {
|
|
4168
4178
|
this.lastReportedDeviceId = reportedDeviceId;
|
|
4169
4179
|
if (this.options.onDeviceSwitched) {
|