@layercode/js-sdk 1.0.26 → 2.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.
- package/README.md +1 -1
- package/dist/layercode-js-sdk.esm.js +187 -101
- package/dist/layercode-js-sdk.esm.js.map +1 -1
- package/dist/layercode-js-sdk.min.js +187 -101
- package/dist/layercode-js-sdk.min.js.map +1 -1
- package/dist/types/index.d.ts +26 -11
- package/package.json +2 -2
package/dist/types/index.d.ts
CHANGED
|
@@ -11,16 +11,16 @@ interface ILayercodeClient {
|
|
|
11
11
|
readonly status: string;
|
|
12
12
|
readonly userAudioAmplitude: number;
|
|
13
13
|
readonly agentAudioAmplitude: number;
|
|
14
|
-
readonly
|
|
14
|
+
readonly conversationId: string | null;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Interface for LayercodeClient constructor options
|
|
18
18
|
*/
|
|
19
19
|
interface LayercodeClientOptions {
|
|
20
|
-
/** The ID of the Layercode
|
|
21
|
-
|
|
22
|
-
/** The ID of the
|
|
23
|
-
|
|
20
|
+
/** The ID of the Layercode agent to connect to */
|
|
21
|
+
agentId: string;
|
|
22
|
+
/** The ID of the conversation to connect to */
|
|
23
|
+
conversationId?: string | null;
|
|
24
24
|
/** The endpoint URL for the audio agent API */
|
|
25
25
|
authorizeSessionEndpoint: string;
|
|
26
26
|
/** Metadata to send with webhooks */
|
|
@@ -28,13 +28,15 @@ interface LayercodeClientOptions {
|
|
|
28
28
|
/** Milliseconds before resuming assistant audio after temporary pause due to user interruption (which was actually a false interruption) */
|
|
29
29
|
vadResumeDelay?: number;
|
|
30
30
|
/** Callback when connection is established */
|
|
31
|
-
onConnect?: ({
|
|
32
|
-
|
|
31
|
+
onConnect?: ({ conversationId }: {
|
|
32
|
+
conversationId: string | null;
|
|
33
33
|
}) => void;
|
|
34
34
|
/** Callback when connection is closed */
|
|
35
35
|
onDisconnect?: () => void;
|
|
36
36
|
/** Callback when an error occurs */
|
|
37
37
|
onError?: (error: Error) => void;
|
|
38
|
+
/** Callback when a device is switched */
|
|
39
|
+
onDeviceSwitched?: (deviceId: string) => void;
|
|
38
40
|
/** Callback for data messages */
|
|
39
41
|
onDataMessage?: (message: any) => void;
|
|
40
42
|
/** Callback for user audio amplitude changes */
|
|
@@ -48,7 +50,7 @@ interface LayercodeClientOptions {
|
|
|
48
50
|
}
|
|
49
51
|
/**
|
|
50
52
|
* @class LayercodeClient
|
|
51
|
-
* @classdesc Core client for Layercode audio
|
|
53
|
+
* @classdesc Core client for Layercode audio agent that manages audio recording, WebSocket communication, and speech processing.
|
|
52
54
|
*/
|
|
53
55
|
declare class LayercodeClient implements ILayercodeClient {
|
|
54
56
|
private options;
|
|
@@ -65,17 +67,18 @@ declare class LayercodeClient implements ILayercodeClient {
|
|
|
65
67
|
private readySent;
|
|
66
68
|
private currentTurnId;
|
|
67
69
|
private audioBuffer;
|
|
70
|
+
private vadConfig;
|
|
71
|
+
private deviceId;
|
|
68
72
|
_websocketUrl: string;
|
|
69
73
|
status: string;
|
|
70
74
|
userAudioAmplitude: number;
|
|
71
75
|
agentAudioAmplitude: number;
|
|
72
|
-
|
|
76
|
+
conversationId: string | null;
|
|
73
77
|
/**
|
|
74
78
|
* Creates an instance of LayercodeClient.
|
|
75
79
|
* @param {Object} options - Configuration options
|
|
76
80
|
*/
|
|
77
81
|
constructor(options: LayercodeClientOptions);
|
|
78
|
-
private _setupAmplitudeBasedVAD;
|
|
79
82
|
private _initializeVAD;
|
|
80
83
|
/**
|
|
81
84
|
* Updates the connection status and triggers the callback
|
|
@@ -109,7 +112,7 @@ declare class LayercodeClient implements ILayercodeClient {
|
|
|
109
112
|
*/
|
|
110
113
|
private _setupAmplitudeMonitoring;
|
|
111
114
|
/**
|
|
112
|
-
* Connects to the Layercode
|
|
115
|
+
* Connects to the Layercode agent and starts the audio conversation
|
|
113
116
|
* @async
|
|
114
117
|
* @returns {Promise<void>}
|
|
115
118
|
*/
|
|
@@ -126,6 +129,18 @@ declare class LayercodeClient implements ILayercodeClient {
|
|
|
126
129
|
* @param {string} deviceId - The deviceId of the new microphone
|
|
127
130
|
*/
|
|
128
131
|
setInputDevice(deviceId: string): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Restarts audio recording after a device switch to ensure audio is captured from the new device
|
|
134
|
+
*/
|
|
135
|
+
private _restartAudioRecording;
|
|
136
|
+
/**
|
|
137
|
+
* Reinitializes VAD with a new stream (used after device switching)
|
|
138
|
+
*/
|
|
139
|
+
private _reinitializeVAD;
|
|
140
|
+
/**
|
|
141
|
+
* Sets up the device change event listener
|
|
142
|
+
*/
|
|
143
|
+
private _setupDeviceChangeListener;
|
|
129
144
|
}
|
|
130
145
|
export default LayercodeClient;
|
|
131
146
|
export type { ILayercodeClient, LayercodeClientOptions };
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"author": "Layercode",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "@layercode/js-sdk",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "2.0.0",
|
|
6
6
|
"description": "Layercode JavaScript SDK for browser usage",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/layercode-js-sdk.esm.js",
|
|
@@ -48,4 +48,4 @@
|
|
|
48
48
|
"@ricky0123/vad-web": "^0.0.24",
|
|
49
49
|
"onnxruntime-web": "^1.21.1"
|
|
50
50
|
}
|
|
51
|
-
}
|
|
51
|
+
}
|