@livekit/agents-plugin-openai 1.2.6 → 1.2.8
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/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/realtime/index.cjs +0 -19
- package/dist/realtime/index.cjs.map +1 -1
- package/dist/realtime/index.d.cts +0 -1
- package/dist/realtime/index.d.ts +0 -1
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js +0 -4
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime/realtime_model.cjs +67 -23
- package/dist/realtime/realtime_model.cjs.map +1 -1
- package/dist/realtime/realtime_model.d.cts +1 -1
- package/dist/realtime/realtime_model.d.ts +1 -1
- package/dist/realtime/realtime_model.d.ts.map +1 -1
- package/dist/realtime/realtime_model.js +67 -23
- package/dist/realtime/realtime_model.js.map +1 -1
- package/dist/responses/llm.cjs +3 -1
- package/dist/responses/llm.cjs.map +1 -1
- package/dist/responses/llm.d.cts +2 -0
- package/dist/responses/llm.d.ts +2 -0
- package/dist/responses/llm.d.ts.map +1 -1
- package/dist/responses/llm.js +3 -1
- package/dist/responses/llm.js.map +1 -1
- package/dist/ws/llm.cjs +3 -0
- package/dist/ws/llm.cjs.map +1 -1
- package/dist/ws/llm.d.cts +2 -0
- package/dist/ws/llm.d.ts +2 -0
- package/dist/ws/llm.d.ts.map +1 -1
- package/dist/ws/llm.js +3 -0
- package/dist/ws/llm.js.map +1 -1
- package/package.json +5 -5
- package/src/realtime/index.ts +0 -1
- package/src/realtime/realtime_model.ts +89 -30
- package/src/responses/llm.ts +6 -1
- package/src/ws/llm.ts +6 -0
- package/dist/realtime/realtime_model_beta.cjs +0 -1300
- package/dist/realtime/realtime_model_beta.cjs.map +0 -1
- package/dist/realtime/realtime_model_beta.d.cts +0 -164
- package/dist/realtime/realtime_model_beta.d.ts +0 -164
- package/dist/realtime/realtime_model_beta.d.ts.map +0 -1
- package/dist/realtime/realtime_model_beta.js +0 -1281
- package/dist/realtime/realtime_model_beta.js.map +0 -1
- package/src/realtime/realtime_model_beta.ts +0 -1663
|
@@ -138,7 +138,7 @@ class RealtimeModel extends llm.RealtimeModel {
|
|
|
138
138
|
*
|
|
139
139
|
* @param azureDeployment - The name of your Azure OpenAI deployment.
|
|
140
140
|
* @param azureEndpoint - The endpoint URL for your Azure OpenAI resource. If undefined, will attempt to read from the environment variable AZURE_OPENAI_ENDPOINT.
|
|
141
|
-
* @param apiVersion - API version
|
|
141
|
+
* @param apiVersion - **Deprecated.** API version for legacy Azure OpenAI preview models. Will be removed on April 30, 2026. Omit for GA models.
|
|
142
142
|
* @param apiKey - Azure OpenAI API key. If undefined, will attempt to read from the environment variable AZURE_OPENAI_API_KEY.
|
|
143
143
|
* @param entraToken - Azure Entra authentication token. Required if not using API key authentication.
|
|
144
144
|
* @param baseURL - Base URL for the API endpoint. If undefined, constructed from the azure_endpoint.
|
|
@@ -176,9 +176,9 @@ class RealtimeModel extends llm.RealtimeModel {
|
|
|
176
176
|
);
|
|
177
177
|
}
|
|
178
178
|
apiVersion = apiVersion || process.env.OPENAI_API_VERSION;
|
|
179
|
-
if (
|
|
180
|
-
|
|
181
|
-
"
|
|
179
|
+
if (apiVersion) {
|
|
180
|
+
log().warn(
|
|
181
|
+
"The `apiVersion` parameter for Azure OpenAI Realtime is deprecated and will be removed on April 30, 2026. Please use the newer Azure OpenAI Realtime API without specifying an API version."
|
|
182
182
|
);
|
|
183
183
|
}
|
|
184
184
|
if (!baseURL) {
|
|
@@ -211,6 +211,17 @@ class RealtimeModel extends llm.RealtimeModel {
|
|
|
211
211
|
return;
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
|
+
function normalizeAzureClientEvent(event) {
|
|
215
|
+
const item = event["item"];
|
|
216
|
+
if (!item) return;
|
|
217
|
+
const content = item["content"];
|
|
218
|
+
if (!content) return;
|
|
219
|
+
for (const contentPart of content) {
|
|
220
|
+
if (contentPart["type"] === "output_text") {
|
|
221
|
+
contentPart["type"] = "text";
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
214
225
|
function processBaseURL({
|
|
215
226
|
baseURL,
|
|
216
227
|
model,
|
|
@@ -218,7 +229,8 @@ function processBaseURL({
|
|
|
218
229
|
azureDeployment,
|
|
219
230
|
apiVersion
|
|
220
231
|
}) {
|
|
221
|
-
const
|
|
232
|
+
const realtimePath = isAzure && !apiVersion ? "v1/realtime" : "realtime";
|
|
233
|
+
const url = new URL([baseURL, realtimePath].join("/"));
|
|
222
234
|
if (url.protocol === "https:") {
|
|
223
235
|
url.protocol = "wss:";
|
|
224
236
|
}
|
|
@@ -228,13 +240,15 @@ function processBaseURL({
|
|
|
228
240
|
url.pathname = url.pathname.replace(/\/$/, "");
|
|
229
241
|
}
|
|
230
242
|
const queryParams = {};
|
|
231
|
-
if (isAzure) {
|
|
232
|
-
|
|
233
|
-
queryParams["api-version"] = apiVersion;
|
|
234
|
-
}
|
|
243
|
+
if (isAzure && apiVersion) {
|
|
244
|
+
queryParams["api-version"] = apiVersion;
|
|
235
245
|
if (azureDeployment) {
|
|
236
246
|
queryParams["deployment"] = azureDeployment;
|
|
237
247
|
}
|
|
248
|
+
} else if (isAzure) {
|
|
249
|
+
if (azureDeployment) {
|
|
250
|
+
queryParams["model"] = azureDeployment;
|
|
251
|
+
}
|
|
238
252
|
} else {
|
|
239
253
|
queryParams["model"] = model;
|
|
240
254
|
}
|
|
@@ -279,30 +293,51 @@ class RealtimeSession extends llm.RealtimeSession {
|
|
|
279
293
|
this.messageChannel.put(command);
|
|
280
294
|
}
|
|
281
295
|
createSessionUpdateEvent() {
|
|
296
|
+
const opts = this.oaiRealtimeModel._options;
|
|
297
|
+
const maxOutputTokens = opts.maxResponseOutputTokens === Infinity ? "inf" : opts.maxResponseOutputTokens;
|
|
298
|
+
if (opts.isAzure && opts.apiVersion) {
|
|
299
|
+
const modalities = opts.modalities.includes("audio") ? ["text", "audio"] : ["text"];
|
|
300
|
+
return {
|
|
301
|
+
type: "session.update",
|
|
302
|
+
session: {
|
|
303
|
+
model: opts.model,
|
|
304
|
+
voice: opts.voice,
|
|
305
|
+
input_audio_format: "pcm16",
|
|
306
|
+
output_audio_format: "pcm16",
|
|
307
|
+
modalities,
|
|
308
|
+
turn_detection: opts.turnDetection,
|
|
309
|
+
input_audio_transcription: opts.inputAudioTranscription,
|
|
310
|
+
tool_choice: toOaiToolChoice(opts.toolChoice),
|
|
311
|
+
max_response_output_tokens: maxOutputTokens,
|
|
312
|
+
speed: opts.speed,
|
|
313
|
+
instructions: this.instructions
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
}
|
|
282
317
|
const audioFormat = { type: "audio/pcm", rate: SAMPLE_RATE };
|
|
283
|
-
const modality =
|
|
318
|
+
const modality = opts.modalities.includes("audio") ? "audio" : "text";
|
|
284
319
|
return {
|
|
285
320
|
type: "session.update",
|
|
286
321
|
session: {
|
|
287
322
|
type: "realtime",
|
|
288
|
-
model:
|
|
323
|
+
model: opts.model,
|
|
289
324
|
output_modalities: [modality],
|
|
290
325
|
audio: {
|
|
291
326
|
input: {
|
|
292
327
|
format: audioFormat,
|
|
293
|
-
noise_reduction:
|
|
294
|
-
transcription:
|
|
295
|
-
turn_detection:
|
|
328
|
+
noise_reduction: opts.inputAudioNoiseReduction,
|
|
329
|
+
transcription: opts.inputAudioTranscription,
|
|
330
|
+
turn_detection: opts.turnDetection
|
|
296
331
|
},
|
|
297
332
|
output: {
|
|
298
333
|
format: audioFormat,
|
|
299
|
-
speed:
|
|
300
|
-
voice:
|
|
334
|
+
speed: opts.speed,
|
|
335
|
+
voice: opts.voice
|
|
301
336
|
}
|
|
302
337
|
},
|
|
303
|
-
max_output_tokens:
|
|
304
|
-
tool_choice: toOaiToolChoice(
|
|
305
|
-
tracing:
|
|
338
|
+
max_output_tokens: maxOutputTokens,
|
|
339
|
+
tool_choice: toOaiToolChoice(opts.toolChoice),
|
|
340
|
+
tracing: opts.tracing,
|
|
306
341
|
instructions: this.instructions
|
|
307
342
|
}
|
|
308
343
|
};
|
|
@@ -475,10 +510,11 @@ class RealtimeSession extends llm.RealtimeSession {
|
|
|
475
510
|
continue;
|
|
476
511
|
}
|
|
477
512
|
}
|
|
513
|
+
const isLegacyAzure = this.oaiRealtimeModel._options.isAzure && !!this.oaiRealtimeModel._options.apiVersion;
|
|
478
514
|
return {
|
|
479
515
|
type: "session.update",
|
|
480
516
|
session: {
|
|
481
|
-
type: "realtime",
|
|
517
|
+
...!isLegacyAzure && { type: "realtime" },
|
|
482
518
|
model: this.oaiRealtimeModel._options.model,
|
|
483
519
|
tools: oaiTools
|
|
484
520
|
},
|
|
@@ -486,11 +522,12 @@ class RealtimeSession extends llm.RealtimeSession {
|
|
|
486
522
|
};
|
|
487
523
|
}
|
|
488
524
|
async updateInstructions(_instructions) {
|
|
525
|
+
const isLegacyAzure = this.oaiRealtimeModel._options.isAzure && !!this.oaiRealtimeModel._options.apiVersion;
|
|
489
526
|
const eventId = shortuuid("instructions_update_");
|
|
490
527
|
this.sendEvent({
|
|
491
528
|
type: "session.update",
|
|
492
529
|
session: {
|
|
493
|
-
type: "realtime",
|
|
530
|
+
...!isLegacyAzure && { type: "realtime" },
|
|
494
531
|
instructions: _instructions
|
|
495
532
|
},
|
|
496
533
|
event_id: eventId
|
|
@@ -504,8 +541,9 @@ class RealtimeSession extends llm.RealtimeSession {
|
|
|
504
541
|
this.oaiRealtimeModel._options.toolChoice = toolChoice;
|
|
505
542
|
return;
|
|
506
543
|
}
|
|
544
|
+
const isLegacyAzure = this.oaiRealtimeModel._options.isAzure && !!this.oaiRealtimeModel._options.apiVersion;
|
|
507
545
|
const options = {
|
|
508
|
-
type: "realtime"
|
|
546
|
+
...!isLegacyAzure && { type: "realtime" }
|
|
509
547
|
};
|
|
510
548
|
this.oaiRealtimeModel._options.toolChoice = toolChoice;
|
|
511
549
|
options.tool_choice = toOaiToolChoice(toolChoice);
|
|
@@ -691,6 +729,9 @@ class RealtimeSession extends llm.RealtimeSession {
|
|
|
691
729
|
try {
|
|
692
730
|
for (const ev of events) {
|
|
693
731
|
this.emit("openai_client_event_queued", ev);
|
|
732
|
+
if (this.oaiRealtimeModel._options.isAzure && this.oaiRealtimeModel._options.apiVersion) {
|
|
733
|
+
normalizeAzureClientEvent(ev);
|
|
734
|
+
}
|
|
694
735
|
wsConn.send(JSON.stringify(ev));
|
|
695
736
|
}
|
|
696
737
|
} catch (error) {
|
|
@@ -764,6 +805,9 @@ class RealtimeSession extends llm.RealtimeSession {
|
|
|
764
805
|
this.#logger.debug(this.loggableEvent(event), `(client) -> ${event.type}`);
|
|
765
806
|
}
|
|
766
807
|
this.emit("openai_client_event_queued", event);
|
|
808
|
+
if (this.oaiRealtimeModel._options.isAzure && this.oaiRealtimeModel._options.apiVersion) {
|
|
809
|
+
normalizeAzureClientEvent(event);
|
|
810
|
+
}
|
|
767
811
|
wsConn.send(JSON.stringify(event));
|
|
768
812
|
} catch (error) {
|
|
769
813
|
break;
|
|
@@ -1400,7 +1444,7 @@ function openAIItemToLivekitItem(item) {
|
|
|
1400
1444
|
const content = [];
|
|
1401
1445
|
const contents = Array.isArray(item.content) ? item.content : [item.content];
|
|
1402
1446
|
for (const c of contents) {
|
|
1403
|
-
if (c.type === "text" || c.type === "input_text") {
|
|
1447
|
+
if (c.type === "text" || c.type === "input_text" || c.type === "output_text") {
|
|
1404
1448
|
content.push(c.text);
|
|
1405
1449
|
} else if (c.type === "input_image" && c.image_url) {
|
|
1406
1450
|
content.push(
|