@livekit/agents-plugin-openai 1.4.6 → 1.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livekit/agents-plugin-openai",
3
- "version": "1.4.6",
3
+ "version": "1.4.8",
4
4
  "description": "OpenAI plugin for LiveKit Node Agents",
5
5
  "main": "dist/index.js",
6
6
  "require": "dist/index.cjs",
@@ -30,9 +30,9 @@
30
30
  "@types/ws": "^8.5.10",
31
31
  "tsup": "^8.3.5",
32
32
  "typescript": "^5.0.0",
33
- "@livekit/agents": "1.4.6",
34
- "@livekit/agents-plugin-silero": "1.4.6",
35
- "@livekit/agents-plugins-test": "1.4.6"
33
+ "@livekit/agents": "1.4.8",
34
+ "@livekit/agents-plugin-silero": "1.4.8",
35
+ "@livekit/agents-plugins-test": "1.4.8"
36
36
  },
37
37
  "dependencies": {
38
38
  "@livekit/mutex": "^1.1.1",
@@ -42,7 +42,7 @@
42
42
  "peerDependencies": {
43
43
  "@livekit/rtc-node": "^0.13.29",
44
44
  "zod": "^3.25.76 || ^4.1.8",
45
- "@livekit/agents": "1.4.6"
45
+ "@livekit/agents": "1.4.8"
46
46
  },
47
47
  "scripts": {
48
48
  "build": "tsup --onSuccess \"pnpm build:types\"",
@@ -717,8 +717,7 @@ export class RealtimeSession extends llm.RealtimeSession {
717
717
  throw new Error('Tools are missing in the session update event');
718
718
  }
719
719
 
720
- // TODO(brian): these logics below are noops I think, leaving it here to keep
721
- // parity with the python but we should remove them later
720
+ // TODO(brian): these logics below are noops I think; remove them later.
722
721
  const retainedToolNames = new Set(ev.session.tools.map((tool) => tool.name));
723
722
  const retainedTools = Object.fromEntries(
724
723
  Object.entries(_tools).filter(
@@ -896,11 +895,18 @@ export class RealtimeSession extends llm.RealtimeSession {
896
895
  const hasServerSideAudio = this.audioCapableItemIds.has(_options.messageId);
897
896
 
898
897
  if (hasAudioModality && hasServerSideAudio) {
898
+ // Guard against a non-finite audioEndMs (e.g. NaN from an unreported avatar
899
+ // playback position): JSON.stringify would serialize it as `null`, which the
900
+ // Realtime API rejects with an `invalid_type` error. Clamp to a valid
901
+ // non-negative integer (ms).
902
+ const audioEndMs = Number.isFinite(_options.audioEndMs)
903
+ ? Math.max(0, Math.floor(_options.audioEndMs))
904
+ : 0;
899
905
  this.sendEvent({
900
906
  type: 'conversation.item.truncate',
901
907
  content_index: 0,
902
908
  item_id: _options.messageId,
903
- audio_end_ms: _options.audioEndMs,
909
+ audio_end_ms: audioEndMs,
904
910
  } as api_proto.ConversationItemTruncateEvent);
905
911
  } else if (_options.audioTranscript !== undefined) {
906
912
  // sync it to the remote chat context
package/src/stt.test.ts CHANGED
@@ -74,14 +74,26 @@ describe('OpenAI STT options', () => {
74
74
  });
75
75
 
76
76
  describe('buildRealtimeSttUrl', () => {
77
- it('points at OpenAI realtime with intent and model when no baseURL is set', () => {
77
+ it('points at OpenAI realtime with intent but omits model on the native endpoint', () => {
78
+ // OpenAI's native /realtime endpoint rejects `?model=` with
79
+ // invalid_request_error.invalid_model when intent=transcription, so the
80
+ // model is conveyed via the subsequent session.update instead.
78
81
  const url = new URL(buildRealtimeSttUrl(undefined, 'gpt-realtime-whisper'));
79
82
 
80
83
  expect(url.protocol).toBe('wss:');
81
84
  expect(url.host).toBe('api.openai.com');
82
85
  expect(url.pathname).toBe('/v1/realtime');
83
86
  expect(url.searchParams.get('intent')).toBe('transcription');
84
- expect(url.searchParams.get('model')).toBe('gpt-realtime-whisper');
87
+ expect(url.searchParams.get('model')).toBe(null);
88
+ });
89
+
90
+ it('omits the model when an explicit baseURL still points at api.openai.com', () => {
91
+ const url = new URL(buildRealtimeSttUrl('https://api.openai.com/v1', 'gpt-4o-mini-transcribe'));
92
+
93
+ expect(url.host).toBe('api.openai.com');
94
+ expect(url.pathname).toBe('/v1/realtime');
95
+ expect(url.searchParams.get('intent')).toBe('transcription');
96
+ expect(url.searchParams.get('model')).toBe(null);
85
97
  });
86
98
 
87
99
  it('upgrades https baseURL to wss and appends /realtime when path is /v1', () => {
package/src/stt.ts CHANGED
@@ -28,12 +28,15 @@ const DEFAULT_REALTIME_MODEL = 'gpt-realtime-whisper';
28
28
  /**
29
29
  * Build the realtime transcription WebSocket URL.
30
30
  *
31
- * Includes the model on the upgrade URL so OpenAI-compatible gateways
32
- * (which can only see the URL at the WebSocket upgrade, not the subsequent
33
- * `session.update` frame) can route by model. Mirrors the existing
34
- * convention in `realtime/realtime_model.ts` for the conversational
35
- * Realtime API. OpenAI's native endpoint accepts and ignores the
36
- * parameter, so this is a no-op for direct connections.
31
+ * For OpenAI-compatible gateways (LiteLLM, Cloudflare AI Gateway, etc.) the
32
+ * model is included on the upgrade URL so the gateway can route by model
33
+ * before the subsequent `session.update` frame arrives. OpenAI's own
34
+ * `wss://api.openai.com/.../realtime` endpoint, on the other hand, treats a
35
+ * `?model=` query param as selecting a conversation session and rejects the
36
+ * subsequent transcription-mode `session.update` with
37
+ * `error.invalid_request_error.invalid_model`, so the model is intentionally
38
+ * omitted for native OpenAI connections — the model is conveyed via
39
+ * `session.update → audio.input.transcription.model` instead.
37
40
  *
38
41
  * The scheme of `baseURL` is respected: `http://` maps to `ws://`
39
42
  * and `https://` maps to `wss://`.
@@ -56,7 +59,9 @@ export function buildRealtimeSttUrl(baseURL: string | undefined, model: string):
56
59
  }
57
60
 
58
61
  url.searchParams.set('intent', 'transcription');
59
- url.searchParams.set('model', model);
62
+ if (url.hostname !== 'api.openai.com') {
63
+ url.searchParams.set('model', model);
64
+ }
60
65
  return url.toString();
61
66
  }
62
67