@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.
Files changed (43) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/realtime/index.cjs +0 -19
  4. package/dist/realtime/index.cjs.map +1 -1
  5. package/dist/realtime/index.d.cts +0 -1
  6. package/dist/realtime/index.d.ts +0 -1
  7. package/dist/realtime/index.d.ts.map +1 -1
  8. package/dist/realtime/index.js +0 -4
  9. package/dist/realtime/index.js.map +1 -1
  10. package/dist/realtime/realtime_model.cjs +67 -23
  11. package/dist/realtime/realtime_model.cjs.map +1 -1
  12. package/dist/realtime/realtime_model.d.cts +1 -1
  13. package/dist/realtime/realtime_model.d.ts +1 -1
  14. package/dist/realtime/realtime_model.d.ts.map +1 -1
  15. package/dist/realtime/realtime_model.js +67 -23
  16. package/dist/realtime/realtime_model.js.map +1 -1
  17. package/dist/responses/llm.cjs +3 -1
  18. package/dist/responses/llm.cjs.map +1 -1
  19. package/dist/responses/llm.d.cts +2 -0
  20. package/dist/responses/llm.d.ts +2 -0
  21. package/dist/responses/llm.d.ts.map +1 -1
  22. package/dist/responses/llm.js +3 -1
  23. package/dist/responses/llm.js.map +1 -1
  24. package/dist/ws/llm.cjs +3 -0
  25. package/dist/ws/llm.cjs.map +1 -1
  26. package/dist/ws/llm.d.cts +2 -0
  27. package/dist/ws/llm.d.ts +2 -0
  28. package/dist/ws/llm.d.ts.map +1 -1
  29. package/dist/ws/llm.js +3 -0
  30. package/dist/ws/llm.js.map +1 -1
  31. package/package.json +5 -5
  32. package/src/realtime/index.ts +0 -1
  33. package/src/realtime/realtime_model.ts +89 -30
  34. package/src/responses/llm.ts +6 -1
  35. package/src/ws/llm.ts +6 -0
  36. package/dist/realtime/realtime_model_beta.cjs +0 -1300
  37. package/dist/realtime/realtime_model_beta.cjs.map +0 -1
  38. package/dist/realtime/realtime_model_beta.d.cts +0 -164
  39. package/dist/realtime/realtime_model_beta.d.ts +0 -164
  40. package/dist/realtime/realtime_model_beta.d.ts.map +0 -1
  41. package/dist/realtime/realtime_model_beta.js +0 -1281
  42. package/dist/realtime/realtime_model_beta.js.map +0 -1
  43. package/src/realtime/realtime_model_beta.ts +0 -1663
package/dist/index.cjs CHANGED
@@ -51,7 +51,7 @@ class OpenAIPlugin extends import_agents.Plugin {
51
51
  constructor() {
52
52
  super({
53
53
  title: "openai",
54
- version: "1.2.6",
54
+ version: "1.2.8",
55
55
  package: "@livekit/agents-plugin-openai"
56
56
  });
57
57
  }
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ class OpenAIPlugin extends Plugin {
10
10
  constructor() {
11
11
  super({
12
12
  title: "openai",
13
- version: "1.2.6",
13
+ version: "1.2.8",
14
14
  package: "@livekit/agents-plugin-openai"
15
15
  });
16
16
  }
@@ -1,14 +1,8 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
6
  var __copyProps = (to, from, except, desc) => {
13
7
  if (from && typeof from === "object" || typeof from === "function") {
14
8
  for (let key of __getOwnPropNames(from))
@@ -18,26 +12,13 @@ var __copyProps = (to, from, except, desc) => {
18
12
  return to;
19
13
  };
20
14
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
15
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
16
  var realtime_exports = {};
31
- __export(realtime_exports, {
32
- beta: () => beta
33
- });
34
17
  module.exports = __toCommonJS(realtime_exports);
35
18
  __reExport(realtime_exports, require("./api_proto.cjs"), module.exports);
36
19
  __reExport(realtime_exports, require("./realtime_model.cjs"), module.exports);
37
- var beta = __toESM(require("./realtime_model_beta.cjs"), 1);
38
20
  // Annotate the CommonJS export names for ESM import in node:
39
21
  0 && (module.exports = {
40
- beta,
41
22
  ...require("./api_proto.cjs"),
42
23
  ...require("./realtime_model.cjs")
43
24
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/realtime/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nexport * from './api_proto.js';\nexport * from './realtime_model.js';\nexport * as beta from './realtime_model_beta.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,6BAAc,2BAHd;AAIA,6BAAc,gCAJd;AAKA,WAAsB;","names":[]}
1
+ {"version":3,"sources":["../../src/realtime/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nexport * from './api_proto.js';\nexport * from './realtime_model.js';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAGA,6BAAc,2BAHd;AAIA,6BAAc,gCAJd;","names":[]}
@@ -1,4 +1,3 @@
1
1
  export * from './api_proto.js';
2
2
  export * from './realtime_model.js';
3
- export * as beta from './realtime_model_beta.js';
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,3 @@
1
1
  export * from './api_proto.js';
2
2
  export * from './realtime_model.js';
3
- export * as beta from './realtime_model_beta.js';
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/realtime/index.ts"],"names":[],"mappings":"AAGA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,OAAO,KAAK,IAAI,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/realtime/index.ts"],"names":[],"mappings":"AAGA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC"}
@@ -1,7 +1,3 @@
1
1
  export * from "./api_proto.js";
2
2
  export * from "./realtime_model.js";
3
- import * as beta from "./realtime_model_beta.js";
4
- export {
5
- beta
6
- };
7
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/realtime/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nexport * from './api_proto.js';\nexport * from './realtime_model.js';\nexport * as beta from './realtime_model_beta.js';\n"],"mappings":"AAGA,cAAc;AACd,cAAc;AACd,YAAY,UAAU;","names":[]}
1
+ {"version":3,"sources":["../../src/realtime/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nexport * from './api_proto.js';\nexport * from './realtime_model.js';\n"],"mappings":"AAGA,cAAc;AACd,cAAc;","names":[]}
@@ -157,7 +157,7 @@ class RealtimeModel extends import_agents.llm.RealtimeModel {
157
157
  *
158
158
  * @param azureDeployment - The name of your Azure OpenAI deployment.
159
159
  * @param azureEndpoint - The endpoint URL for your Azure OpenAI resource. If undefined, will attempt to read from the environment variable AZURE_OPENAI_ENDPOINT.
160
- * @param apiVersion - API version to use with Azure OpenAI Service. If undefined, will attempt to read from the environment variable OPENAI_API_VERSION.
160
+ * @param apiVersion - **Deprecated.** API version for legacy Azure OpenAI preview models. Will be removed on April 30, 2026. Omit for GA models.
161
161
  * @param apiKey - Azure OpenAI API key. If undefined, will attempt to read from the environment variable AZURE_OPENAI_API_KEY.
162
162
  * @param entraToken - Azure Entra authentication token. Required if not using API key authentication.
163
163
  * @param baseURL - Base URL for the API endpoint. If undefined, constructed from the azure_endpoint.
@@ -195,9 +195,9 @@ class RealtimeModel extends import_agents.llm.RealtimeModel {
195
195
  );
196
196
  }
197
197
  apiVersion = apiVersion || process.env.OPENAI_API_VERSION;
198
- if (!apiVersion) {
199
- throw new Error(
200
- "Must provide either the `apiVersion` argument or the `OPENAI_API_VERSION` environment variable"
198
+ if (apiVersion) {
199
+ (0, import_agents.log)().warn(
200
+ "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."
201
201
  );
202
202
  }
203
203
  if (!baseURL) {
@@ -230,6 +230,17 @@ class RealtimeModel extends import_agents.llm.RealtimeModel {
230
230
  return;
231
231
  }
232
232
  }
233
+ function normalizeAzureClientEvent(event) {
234
+ const item = event["item"];
235
+ if (!item) return;
236
+ const content = item["content"];
237
+ if (!content) return;
238
+ for (const contentPart of content) {
239
+ if (contentPart["type"] === "output_text") {
240
+ contentPart["type"] = "text";
241
+ }
242
+ }
243
+ }
233
244
  function processBaseURL({
234
245
  baseURL,
235
246
  model,
@@ -237,7 +248,8 @@ function processBaseURL({
237
248
  azureDeployment,
238
249
  apiVersion
239
250
  }) {
240
- const url = new URL([baseURL, "realtime"].join("/"));
251
+ const realtimePath = isAzure && !apiVersion ? "v1/realtime" : "realtime";
252
+ const url = new URL([baseURL, realtimePath].join("/"));
241
253
  if (url.protocol === "https:") {
242
254
  url.protocol = "wss:";
243
255
  }
@@ -247,13 +259,15 @@ function processBaseURL({
247
259
  url.pathname = url.pathname.replace(/\/$/, "");
248
260
  }
249
261
  const queryParams = {};
250
- if (isAzure) {
251
- if (apiVersion) {
252
- queryParams["api-version"] = apiVersion;
253
- }
262
+ if (isAzure && apiVersion) {
263
+ queryParams["api-version"] = apiVersion;
254
264
  if (azureDeployment) {
255
265
  queryParams["deployment"] = azureDeployment;
256
266
  }
267
+ } else if (isAzure) {
268
+ if (azureDeployment) {
269
+ queryParams["model"] = azureDeployment;
270
+ }
257
271
  } else {
258
272
  queryParams["model"] = model;
259
273
  }
@@ -298,30 +312,51 @@ class RealtimeSession extends import_agents.llm.RealtimeSession {
298
312
  this.messageChannel.put(command);
299
313
  }
300
314
  createSessionUpdateEvent() {
315
+ const opts = this.oaiRealtimeModel._options;
316
+ const maxOutputTokens = opts.maxResponseOutputTokens === Infinity ? "inf" : opts.maxResponseOutputTokens;
317
+ if (opts.isAzure && opts.apiVersion) {
318
+ const modalities = opts.modalities.includes("audio") ? ["text", "audio"] : ["text"];
319
+ return {
320
+ type: "session.update",
321
+ session: {
322
+ model: opts.model,
323
+ voice: opts.voice,
324
+ input_audio_format: "pcm16",
325
+ output_audio_format: "pcm16",
326
+ modalities,
327
+ turn_detection: opts.turnDetection,
328
+ input_audio_transcription: opts.inputAudioTranscription,
329
+ tool_choice: toOaiToolChoice(opts.toolChoice),
330
+ max_response_output_tokens: maxOutputTokens,
331
+ speed: opts.speed,
332
+ instructions: this.instructions
333
+ }
334
+ };
335
+ }
301
336
  const audioFormat = { type: "audio/pcm", rate: SAMPLE_RATE };
302
- const modality = this.oaiRealtimeModel._options.modalities.includes("audio") ? "audio" : "text";
337
+ const modality = opts.modalities.includes("audio") ? "audio" : "text";
303
338
  return {
304
339
  type: "session.update",
305
340
  session: {
306
341
  type: "realtime",
307
- model: this.oaiRealtimeModel._options.model,
342
+ model: opts.model,
308
343
  output_modalities: [modality],
309
344
  audio: {
310
345
  input: {
311
346
  format: audioFormat,
312
- noise_reduction: this.oaiRealtimeModel._options.inputAudioNoiseReduction,
313
- transcription: this.oaiRealtimeModel._options.inputAudioTranscription,
314
- turn_detection: this.oaiRealtimeModel._options.turnDetection
347
+ noise_reduction: opts.inputAudioNoiseReduction,
348
+ transcription: opts.inputAudioTranscription,
349
+ turn_detection: opts.turnDetection
315
350
  },
316
351
  output: {
317
352
  format: audioFormat,
318
- speed: this.oaiRealtimeModel._options.speed,
319
- voice: this.oaiRealtimeModel._options.voice
353
+ speed: opts.speed,
354
+ voice: opts.voice
320
355
  }
321
356
  },
322
- max_output_tokens: this.oaiRealtimeModel._options.maxResponseOutputTokens === Infinity ? "inf" : this.oaiRealtimeModel._options.maxResponseOutputTokens,
323
- tool_choice: toOaiToolChoice(this.oaiRealtimeModel._options.toolChoice),
324
- tracing: this.oaiRealtimeModel._options.tracing,
357
+ max_output_tokens: maxOutputTokens,
358
+ tool_choice: toOaiToolChoice(opts.toolChoice),
359
+ tracing: opts.tracing,
325
360
  instructions: this.instructions
326
361
  }
327
362
  };
@@ -494,10 +529,11 @@ class RealtimeSession extends import_agents.llm.RealtimeSession {
494
529
  continue;
495
530
  }
496
531
  }
532
+ const isLegacyAzure = this.oaiRealtimeModel._options.isAzure && !!this.oaiRealtimeModel._options.apiVersion;
497
533
  return {
498
534
  type: "session.update",
499
535
  session: {
500
- type: "realtime",
536
+ ...!isLegacyAzure && { type: "realtime" },
501
537
  model: this.oaiRealtimeModel._options.model,
502
538
  tools: oaiTools
503
539
  },
@@ -505,11 +541,12 @@ class RealtimeSession extends import_agents.llm.RealtimeSession {
505
541
  };
506
542
  }
507
543
  async updateInstructions(_instructions) {
544
+ const isLegacyAzure = this.oaiRealtimeModel._options.isAzure && !!this.oaiRealtimeModel._options.apiVersion;
508
545
  const eventId = (0, import_agents.shortuuid)("instructions_update_");
509
546
  this.sendEvent({
510
547
  type: "session.update",
511
548
  session: {
512
- type: "realtime",
549
+ ...!isLegacyAzure && { type: "realtime" },
513
550
  instructions: _instructions
514
551
  },
515
552
  event_id: eventId
@@ -523,8 +560,9 @@ class RealtimeSession extends import_agents.llm.RealtimeSession {
523
560
  this.oaiRealtimeModel._options.toolChoice = toolChoice;
524
561
  return;
525
562
  }
563
+ const isLegacyAzure = this.oaiRealtimeModel._options.isAzure && !!this.oaiRealtimeModel._options.apiVersion;
526
564
  const options = {
527
- type: "realtime"
565
+ ...!isLegacyAzure && { type: "realtime" }
528
566
  };
529
567
  this.oaiRealtimeModel._options.toolChoice = toolChoice;
530
568
  options.tool_choice = toOaiToolChoice(toolChoice);
@@ -710,6 +748,9 @@ class RealtimeSession extends import_agents.llm.RealtimeSession {
710
748
  try {
711
749
  for (const ev of events) {
712
750
  this.emit("openai_client_event_queued", ev);
751
+ if (this.oaiRealtimeModel._options.isAzure && this.oaiRealtimeModel._options.apiVersion) {
752
+ normalizeAzureClientEvent(ev);
753
+ }
713
754
  wsConn.send(JSON.stringify(ev));
714
755
  }
715
756
  } catch (error) {
@@ -783,6 +824,9 @@ class RealtimeSession extends import_agents.llm.RealtimeSession {
783
824
  this.#logger.debug(this.loggableEvent(event), `(client) -> ${event.type}`);
784
825
  }
785
826
  this.emit("openai_client_event_queued", event);
827
+ if (this.oaiRealtimeModel._options.isAzure && this.oaiRealtimeModel._options.apiVersion) {
828
+ normalizeAzureClientEvent(event);
829
+ }
786
830
  wsConn.send(JSON.stringify(event));
787
831
  } catch (error) {
788
832
  break;
@@ -1419,7 +1463,7 @@ function openAIItemToLivekitItem(item) {
1419
1463
  const content = [];
1420
1464
  const contents = Array.isArray(item.content) ? item.content : [item.content];
1421
1465
  for (const c of contents) {
1422
- if (c.type === "text" || c.type === "input_text") {
1466
+ if (c.type === "text" || c.type === "input_text" || c.type === "output_text") {
1423
1467
  content.push(c.text);
1424
1468
  } else if (c.type === "input_image" && c.image_url) {
1425
1469
  content.push(