@deepgram/sdk 3.9.0 → 3.10.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/dist/main/DeepgramClient.d.ts +8 -1
- package/dist/main/DeepgramClient.d.ts.map +1 -1
- package/dist/main/DeepgramClient.js +9 -0
- package/dist/main/DeepgramClient.js.map +1 -1
- package/dist/main/lib/constants.d.ts +2 -0
- package/dist/main/lib/constants.d.ts.map +1 -1
- package/dist/main/lib/constants.js +9 -1
- package/dist/main/lib/constants.js.map +1 -1
- package/dist/main/lib/enums/AgentEvents.d.ts +78 -0
- package/dist/main/lib/enums/AgentEvents.d.ts.map +1 -0
- package/dist/main/lib/enums/AgentEvents.js +82 -0
- package/dist/main/lib/enums/AgentEvents.js.map +1 -0
- package/dist/main/lib/enums/index.d.ts +1 -0
- package/dist/main/lib/enums/index.d.ts.map +1 -1
- package/dist/main/lib/enums/index.js +1 -0
- package/dist/main/lib/enums/index.js.map +1 -1
- package/dist/main/lib/types/AgentLiveSchema.d.ts +119 -0
- package/dist/main/lib/types/AgentLiveSchema.d.ts.map +1 -0
- package/dist/main/lib/types/AgentLiveSchema.js +3 -0
- package/dist/main/lib/types/AgentLiveSchema.js.map +1 -0
- package/dist/main/lib/types/DeepgramClientOptions.d.ts +1 -0
- package/dist/main/lib/types/DeepgramClientOptions.d.ts.map +1 -1
- package/dist/main/lib/types/FunctionCallResponse.d.ts +14 -0
- package/dist/main/lib/types/FunctionCallResponse.d.ts.map +1 -0
- package/dist/main/lib/types/FunctionCallResponse.js +3 -0
- package/dist/main/lib/types/FunctionCallResponse.js.map +1 -0
- package/dist/main/lib/types/LiveTranscriptionEvent.d.ts +1 -0
- package/dist/main/lib/types/LiveTranscriptionEvent.d.ts.map +1 -1
- package/dist/main/lib/types/index.d.ts +2 -0
- package/dist/main/lib/types/index.d.ts.map +1 -1
- package/dist/main/lib/types/index.js +2 -0
- package/dist/main/lib/types/index.js.map +1 -1
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.js +1 -1
- package/dist/main/packages/AbstractLiveClient.js +2 -2
- package/dist/main/packages/AbstractLiveClient.js.map +1 -1
- package/dist/main/packages/AgentLiveClient.d.ts +85 -0
- package/dist/main/packages/AgentLiveClient.d.ts.map +1 -0
- package/dist/main/packages/AgentLiveClient.js +169 -0
- package/dist/main/packages/AgentLiveClient.js.map +1 -0
- package/dist/main/packages/index.d.ts +1 -0
- package/dist/main/packages/index.d.ts.map +1 -1
- package/dist/main/packages/index.js +1 -0
- package/dist/main/packages/index.js.map +1 -1
- package/dist/module/DeepgramClient.d.ts +8 -1
- package/dist/module/DeepgramClient.d.ts.map +1 -1
- package/dist/module/DeepgramClient.js +10 -1
- package/dist/module/DeepgramClient.js.map +1 -1
- package/dist/module/lib/constants.d.ts +2 -0
- package/dist/module/lib/constants.d.ts.map +1 -1
- package/dist/module/lib/constants.js +8 -0
- package/dist/module/lib/constants.js.map +1 -1
- package/dist/module/lib/enums/AgentEvents.d.ts +78 -0
- package/dist/module/lib/enums/AgentEvents.d.ts.map +1 -0
- package/dist/module/lib/enums/AgentEvents.js +79 -0
- package/dist/module/lib/enums/AgentEvents.js.map +1 -0
- package/dist/module/lib/enums/index.d.ts +1 -0
- package/dist/module/lib/enums/index.d.ts.map +1 -1
- package/dist/module/lib/enums/index.js +1 -0
- package/dist/module/lib/enums/index.js.map +1 -1
- package/dist/module/lib/types/AgentLiveSchema.d.ts +119 -0
- package/dist/module/lib/types/AgentLiveSchema.d.ts.map +1 -0
- package/dist/module/lib/types/AgentLiveSchema.js +2 -0
- package/dist/module/lib/types/AgentLiveSchema.js.map +1 -0
- package/dist/module/lib/types/DeepgramClientOptions.d.ts +1 -0
- package/dist/module/lib/types/DeepgramClientOptions.d.ts.map +1 -1
- package/dist/module/lib/types/FunctionCallResponse.d.ts +14 -0
- package/dist/module/lib/types/FunctionCallResponse.d.ts.map +1 -0
- package/dist/module/lib/types/FunctionCallResponse.js +2 -0
- package/dist/module/lib/types/FunctionCallResponse.js.map +1 -0
- package/dist/module/lib/types/LiveTranscriptionEvent.d.ts +1 -0
- package/dist/module/lib/types/LiveTranscriptionEvent.d.ts.map +1 -1
- package/dist/module/lib/types/index.d.ts +2 -0
- package/dist/module/lib/types/index.d.ts.map +1 -1
- package/dist/module/lib/types/index.js +2 -0
- package/dist/module/lib/types/index.js.map +1 -1
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.js +1 -1
- package/dist/module/packages/AbstractLiveClient.js +2 -2
- package/dist/module/packages/AbstractLiveClient.js.map +1 -1
- package/dist/module/packages/AgentLiveClient.d.ts +85 -0
- package/dist/module/packages/AgentLiveClient.d.ts.map +1 -0
- package/dist/module/packages/AgentLiveClient.js +165 -0
- package/dist/module/packages/AgentLiveClient.js.map +1 -0
- package/dist/module/packages/index.d.ts +1 -0
- package/dist/module/packages/index.d.ts.map +1 -1
- package/dist/module/packages/index.js +1 -0
- package/dist/module/packages/index.js.map +1 -1
- package/dist/umd/deepgram.js +1 -1
- package/package.json +1 -1
- package/src/DeepgramClient.ts +11 -0
- package/src/lib/constants.ts +9 -0
- package/src/lib/enums/AgentEvents.ts +78 -0
- package/src/lib/enums/index.ts +1 -0
- package/src/lib/types/AgentLiveSchema.ts +184 -0
- package/src/lib/types/DeepgramClientOptions.ts +1 -0
- package/src/lib/types/FunctionCallResponse.ts +13 -0
- package/src/lib/types/LiveTranscriptionEvent.ts +1 -0
- package/src/lib/types/index.ts +2 -0
- package/src/lib/version.ts +1 -1
- package/src/packages/AbstractLiveClient.ts +2 -2
- package/src/packages/AgentLiveClient.ts +178 -0
- package/src/packages/index.ts +1 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
type AudioFormat =
|
|
2
|
+
| {
|
|
3
|
+
encoding: "linear16";
|
|
4
|
+
container: "wav" | "none";
|
|
5
|
+
sampleRate: 8000 | 16000 | 24000 | 32000 | 48000;
|
|
6
|
+
}
|
|
7
|
+
| {
|
|
8
|
+
encoding: "mulaw";
|
|
9
|
+
container: "wav" | "none";
|
|
10
|
+
sampleRate: 8000 | 16000;
|
|
11
|
+
}
|
|
12
|
+
| {
|
|
13
|
+
encoding: "alaw";
|
|
14
|
+
container: "wav" | "none";
|
|
15
|
+
sampleRate: 8000 | 16000;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type AudioEncoding =
|
|
19
|
+
| "linear16"
|
|
20
|
+
| "flac"
|
|
21
|
+
| "mulaw"
|
|
22
|
+
| "amr-nb"
|
|
23
|
+
| "amr-wb"
|
|
24
|
+
| "Opus"
|
|
25
|
+
| "speex"
|
|
26
|
+
| "g729";
|
|
27
|
+
|
|
28
|
+
type ListenModel =
|
|
29
|
+
| "nova-2"
|
|
30
|
+
| "nova-2-meeting"
|
|
31
|
+
| "nova-2-phonecall"
|
|
32
|
+
| "nova-2-voicemail"
|
|
33
|
+
| "nova-2-finance"
|
|
34
|
+
| "nova-2-conversational"
|
|
35
|
+
| "nova-2-video"
|
|
36
|
+
| "nova-2-medical"
|
|
37
|
+
| "nova-2-drivethru"
|
|
38
|
+
| "nova-2-automotive"
|
|
39
|
+
| "nova-2-atc"
|
|
40
|
+
| "nova"
|
|
41
|
+
| "nova-phonecall"
|
|
42
|
+
| "enhanced"
|
|
43
|
+
| "enhanced-meeting"
|
|
44
|
+
| "enhanced-phonecall"
|
|
45
|
+
| "enhanced-finance"
|
|
46
|
+
| "base"
|
|
47
|
+
| "base-meeting"
|
|
48
|
+
| "base-phonecall"
|
|
49
|
+
| "base-voicemail"
|
|
50
|
+
| "base-finance"
|
|
51
|
+
| "base-conversational"
|
|
52
|
+
| "base-video"
|
|
53
|
+
| "whisper-tiny"
|
|
54
|
+
| "whisper"
|
|
55
|
+
| "whisper-small"
|
|
56
|
+
| "whisper-medium"
|
|
57
|
+
| "whisper-large";
|
|
58
|
+
|
|
59
|
+
type SpeakModel =
|
|
60
|
+
| "aura-asteria-en"
|
|
61
|
+
| "aura-luna-en"
|
|
62
|
+
| "aura-stella-en"
|
|
63
|
+
| "aura-athena-en"
|
|
64
|
+
| "aura-hera-en"
|
|
65
|
+
| "aura-orion-en"
|
|
66
|
+
| "aura-arcas-en"
|
|
67
|
+
| "aura-perseus-en"
|
|
68
|
+
| "aura-angus-en"
|
|
69
|
+
| "aura-orpheus-en"
|
|
70
|
+
| "aura-helios-en"
|
|
71
|
+
| "aura-zeus-en";
|
|
72
|
+
|
|
73
|
+
interface ThinkModelFunction {
|
|
74
|
+
name: string;
|
|
75
|
+
description: string;
|
|
76
|
+
url: string;
|
|
77
|
+
headers: [
|
|
78
|
+
{
|
|
79
|
+
key: "authorization";
|
|
80
|
+
value: string;
|
|
81
|
+
}
|
|
82
|
+
];
|
|
83
|
+
method: "POST";
|
|
84
|
+
parameters: {
|
|
85
|
+
type: string;
|
|
86
|
+
properties: Record<
|
|
87
|
+
string,
|
|
88
|
+
{
|
|
89
|
+
type: string;
|
|
90
|
+
description: string;
|
|
91
|
+
}
|
|
92
|
+
>;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
type ThinkModel =
|
|
97
|
+
| {
|
|
98
|
+
provider: {
|
|
99
|
+
type: "open_ai";
|
|
100
|
+
};
|
|
101
|
+
model: "gpt-4o-mini";
|
|
102
|
+
instructions: string;
|
|
103
|
+
functions: ThinkModelFunction[];
|
|
104
|
+
}
|
|
105
|
+
| {
|
|
106
|
+
provider: {
|
|
107
|
+
type: "anthropic";
|
|
108
|
+
};
|
|
109
|
+
model: "claude-3-haiku-20240307";
|
|
110
|
+
instructions: string;
|
|
111
|
+
functions: ThinkModelFunction[];
|
|
112
|
+
}
|
|
113
|
+
| {
|
|
114
|
+
provider: {
|
|
115
|
+
type: "groq";
|
|
116
|
+
};
|
|
117
|
+
model: "";
|
|
118
|
+
instructions: string;
|
|
119
|
+
functions: ThinkModelFunction[];
|
|
120
|
+
}
|
|
121
|
+
| {
|
|
122
|
+
provider: {
|
|
123
|
+
type: "custom";
|
|
124
|
+
url: string;
|
|
125
|
+
key: string;
|
|
126
|
+
};
|
|
127
|
+
model: string;
|
|
128
|
+
instructions: string;
|
|
129
|
+
functions: ThinkModelFunction[];
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @see https://developers.deepgram.com/reference/voicebot-api-phase-preview#settingsconfiguration
|
|
134
|
+
*/
|
|
135
|
+
interface AgentLiveSchema extends Record<string, unknown> {
|
|
136
|
+
audio: {
|
|
137
|
+
input?: {
|
|
138
|
+
/**
|
|
139
|
+
* @default 1
|
|
140
|
+
*/
|
|
141
|
+
channels: number;
|
|
142
|
+
encoding: AudioEncoding;
|
|
143
|
+
/**
|
|
144
|
+
* @default false
|
|
145
|
+
*/
|
|
146
|
+
multichannel: boolean;
|
|
147
|
+
sampleRate: number;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* @see https://developers.deepgram.com/docs/tts-media-output-settings#audio-format-combinations
|
|
151
|
+
*/
|
|
152
|
+
output?: AudioFormat;
|
|
153
|
+
};
|
|
154
|
+
agent: {
|
|
155
|
+
listen: {
|
|
156
|
+
/**
|
|
157
|
+
* @see https://developers.deepgram.com/docs/model
|
|
158
|
+
*/
|
|
159
|
+
model: ListenModel;
|
|
160
|
+
};
|
|
161
|
+
speak: {
|
|
162
|
+
/**
|
|
163
|
+
* @see https://developers.deepgram.com/docs/tts-models
|
|
164
|
+
*/
|
|
165
|
+
model: SpeakModel;
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* @see https://developers.deepgram.com/reference/voicebot-api-phase-preview#supported-llm-providers-and-models
|
|
169
|
+
*/
|
|
170
|
+
think: ThinkModel;
|
|
171
|
+
};
|
|
172
|
+
context: {
|
|
173
|
+
/**
|
|
174
|
+
* LLM message history (e.g. to restore existing conversation if websocket disconnects)
|
|
175
|
+
*/
|
|
176
|
+
messages: [];
|
|
177
|
+
/**
|
|
178
|
+
* Whether to replay the last message, if it is an assistant message.
|
|
179
|
+
*/
|
|
180
|
+
replay: boolean;
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export type { AgentLiveSchema, SpeakModel };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Respond with this when you receive a `FunctionCallRequest` payload.
|
|
3
|
+
*/
|
|
4
|
+
export interface FunctionCallResponse {
|
|
5
|
+
/**
|
|
6
|
+
* This must be the ID that was received in the request.
|
|
7
|
+
*/
|
|
8
|
+
function_call_id: string;
|
|
9
|
+
/**
|
|
10
|
+
* The result of the function call.
|
|
11
|
+
*/
|
|
12
|
+
output: string;
|
|
13
|
+
}
|
package/src/lib/types/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from "./AgentLiveSchema";
|
|
1
2
|
export * from "./AnalyzeSchema";
|
|
2
3
|
export * from "./AsyncAnalyzeResponse";
|
|
3
4
|
export * from "./AsyncPrerecordedResponse";
|
|
@@ -8,6 +9,7 @@ export * from "./DeepgramClientOptions";
|
|
|
8
9
|
export * from "./DeepgramResponse";
|
|
9
10
|
export * from "./DeepgramSource";
|
|
10
11
|
export * from "./Fetch";
|
|
12
|
+
export * from "./FunctionCallResponse";
|
|
11
13
|
export * from "./GetModelsResponse";
|
|
12
14
|
export * from "./GetModelsSchema";
|
|
13
15
|
export * from "./GetProjectBalancesResponse";
|
package/src/lib/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "3.
|
|
1
|
+
export const version = "3.10.0";
|
|
@@ -245,8 +245,8 @@ export abstract class AbstractLiveClient extends AbstractClient {
|
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
if (typeof data !== "string") {
|
|
248
|
-
if (data
|
|
249
|
-
this.log("warn", "skipping `send` for zero-byte
|
|
248
|
+
if (!data?.byteLength) {
|
|
249
|
+
this.log("warn", "skipping `send` for zero-byte payload", data);
|
|
250
250
|
|
|
251
251
|
return;
|
|
252
252
|
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { DEFAULT_AGENT_URL } from "../lib/constants";
|
|
2
|
+
import { AgentEvents } from "../lib/enums/AgentEvents";
|
|
3
|
+
import type {
|
|
4
|
+
AgentLiveSchema,
|
|
5
|
+
SpeakModel,
|
|
6
|
+
DeepgramClientOptions,
|
|
7
|
+
FunctionCallResponse,
|
|
8
|
+
} from "../lib/types";
|
|
9
|
+
import { AbstractLiveClient } from "./AbstractLiveClient";
|
|
10
|
+
|
|
11
|
+
export class AgentLiveClient extends AbstractLiveClient {
|
|
12
|
+
public namespace: string = "agent";
|
|
13
|
+
|
|
14
|
+
constructor(options: DeepgramClientOptions, endpoint: string = "/agent") {
|
|
15
|
+
super(options);
|
|
16
|
+
this.baseUrl = options.agent?.websocket?.options?.url ?? DEFAULT_AGENT_URL;
|
|
17
|
+
|
|
18
|
+
this.connect({}, endpoint);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Sets up the connection event handlers.
|
|
23
|
+
* This method is responsible for handling the various events that can occur on the WebSocket connection, such as opening, closing, and receiving messages.
|
|
24
|
+
* - When the connection is opened, it emits the `AgentEvents.Open` event.
|
|
25
|
+
* - When the connection is closed, it emits the `AgentEvents.Close` event.
|
|
26
|
+
* - When an error occurs on the connection, it emits the `AgentEvents.Error` event.
|
|
27
|
+
* - When a message is received, it parses the message and emits the appropriate event based on the message type.
|
|
28
|
+
*/
|
|
29
|
+
public setupConnection(): void {
|
|
30
|
+
if (this.conn) {
|
|
31
|
+
this.conn.onopen = () => {
|
|
32
|
+
this.emit(AgentEvents.Open, this);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
this.conn.onclose = (event: any) => {
|
|
36
|
+
this.emit(AgentEvents.Close, event);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
this.conn.onerror = (event: ErrorEvent) => {
|
|
40
|
+
this.emit(AgentEvents.Error, event);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
this.conn.onmessage = (event: MessageEvent) => {
|
|
44
|
+
this.handleMessage(event);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Handles incoming messages from the WebSocket connection.
|
|
51
|
+
* @param event - The MessageEvent object representing the received message.
|
|
52
|
+
*/
|
|
53
|
+
protected handleMessage(event: MessageEvent): void {
|
|
54
|
+
if (typeof event.data === "string") {
|
|
55
|
+
try {
|
|
56
|
+
const data = JSON.parse(event.data);
|
|
57
|
+
this.handleTextMessage(data);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
this.emit(AgentEvents.Error, {
|
|
60
|
+
event,
|
|
61
|
+
message: "Unable to parse `data` as JSON.",
|
|
62
|
+
error,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
} else if (event.data instanceof Blob) {
|
|
66
|
+
event.data.arrayBuffer().then((buffer) => {
|
|
67
|
+
this.handleBinaryMessage(Buffer.from(buffer));
|
|
68
|
+
});
|
|
69
|
+
} else if (event.data instanceof ArrayBuffer) {
|
|
70
|
+
this.handleBinaryMessage(Buffer.from(event.data));
|
|
71
|
+
} else if (Buffer.isBuffer(event.data)) {
|
|
72
|
+
this.handleBinaryMessage(event.data);
|
|
73
|
+
} else {
|
|
74
|
+
console.log("Received unknown data type", event.data);
|
|
75
|
+
this.emit(AgentEvents.Error, {
|
|
76
|
+
event,
|
|
77
|
+
message: "Received unknown data type.",
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Handles binary messages received from the WebSocket connection.
|
|
84
|
+
* @param data - The binary data.
|
|
85
|
+
*/
|
|
86
|
+
protected handleBinaryMessage(data: Buffer): void {
|
|
87
|
+
this.emit(AgentEvents.Audio, data);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Handles text messages received from the WebSocket connection.
|
|
92
|
+
* @param data - The parsed JSON data.
|
|
93
|
+
*/
|
|
94
|
+
protected handleTextMessage(data: any): void {
|
|
95
|
+
if (data.type in AgentEvents) {
|
|
96
|
+
this.emit(data.type, data);
|
|
97
|
+
} else {
|
|
98
|
+
this.emit(AgentEvents.Unhandled, data);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* To be called with your model configuration BEFORE sending
|
|
104
|
+
* any audio data.
|
|
105
|
+
* @param options - The SettingsConfiguration object.
|
|
106
|
+
* @param options.audio.input.encoding - The encoding for your inbound (user) audio.
|
|
107
|
+
* @param options.audio.input.sampleRate - The sample rate for your inbound (user) audio.
|
|
108
|
+
* @param options.audio.output.encoding - The encoding for your outbound (agent) audio.
|
|
109
|
+
* @param options.audio.output.sampleRate - The sample rate for your outbound (agent) audio.
|
|
110
|
+
* @param options.audio.output.bitrate - The bitrate for your outbound (agent) audio.
|
|
111
|
+
* @param options.audio.output.container - The container for your outbound (agent) audio.
|
|
112
|
+
* @param options.agent.listen.model - The STT model to use for processing user audio.
|
|
113
|
+
* @param options.agent.speak.model - The TTS model to use for generating agent audio.
|
|
114
|
+
* @param options.agent.think.provider.type - The LLM provider to use.
|
|
115
|
+
* @param options.agent.think.model - The LLM model to use.
|
|
116
|
+
* @param options.agent.think.instructions - The instructions to provide to the LLM.
|
|
117
|
+
* @param options.agent.think.functions - The functions to provide to the LLM.
|
|
118
|
+
* @param options.context.messages - The message history to provide to the LLM (useful if a websocket connection is lost.)
|
|
119
|
+
* @param options.context.replay - Whether to replay the last message if it was an assistant message.
|
|
120
|
+
*/
|
|
121
|
+
public configure(options: AgentLiveSchema): void {
|
|
122
|
+
// Converting the property names...
|
|
123
|
+
const opts: Record<string, any> = { ...options };
|
|
124
|
+
opts.audio.input["sample_rate"] = options.audio.input?.sampleRate;
|
|
125
|
+
delete opts.audio.input.sampleRate;
|
|
126
|
+
opts.audio.output["sample_rate"] = options.audio.output?.sampleRate;
|
|
127
|
+
delete opts.audio.output.sampleRate;
|
|
128
|
+
this.send(JSON.stringify({ type: "SettingsConfiguration", ...opts }));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Provide new instructions to the LLM.
|
|
133
|
+
* @param instructions - The instructions to provide.
|
|
134
|
+
*/
|
|
135
|
+
public updateInstructions(instructions: string): void {
|
|
136
|
+
this.send(JSON.stringify({ type: "UpdateInstructions", instructions }));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Change the speak model.
|
|
141
|
+
* @param model - The new model to use.
|
|
142
|
+
*/
|
|
143
|
+
public updateSpeak(model: SpeakModel): void {
|
|
144
|
+
this.send(JSON.stringify({ type: "UpdateSpeak", model }));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Immediately trigger an agent message. If this message
|
|
149
|
+
* is sent while the user is speaking, or while the server is in the
|
|
150
|
+
* middle of sending audio, then the request will be ignored and an InjectionRefused
|
|
151
|
+
* event will be emitted.
|
|
152
|
+
* @example "Hold on while I look that up for you."
|
|
153
|
+
* @example "Are you still on the line?"
|
|
154
|
+
* @param message - The message to speak.
|
|
155
|
+
*/
|
|
156
|
+
public injectAgentMessage(message: string): void {
|
|
157
|
+
this.send(JSON.stringify({ type: "InjectAgentMessage", message }));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Respond to a function call request.
|
|
162
|
+
* @param response - The response to the function call request.
|
|
163
|
+
* @param response.function_call_id - The ID that was received in the request (these MUST match).
|
|
164
|
+
* @param response.output - The result of the function call.
|
|
165
|
+
*/
|
|
166
|
+
public functionCallResponse(response: FunctionCallResponse): void {
|
|
167
|
+
this.send(JSON.stringify({ type: "FunctionCallResponse", ...response }));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Send a keepalive to avoid closing the websocket while you
|
|
172
|
+
* are not transmitting audio. This should be sent at least
|
|
173
|
+
* every 8 seconds.
|
|
174
|
+
*/
|
|
175
|
+
public keepAlive(): void {
|
|
176
|
+
this.send(JSON.stringify({ type: "KeepAlive" }));
|
|
177
|
+
}
|
|
178
|
+
}
|
package/src/packages/index.ts
CHANGED