@livekit/agents-plugin-openai 1.4.5 → 1.4.7
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/api_proto.cjs.map +1 -1
- package/dist/realtime/api_proto.d.cts +12 -1
- package/dist/realtime/api_proto.d.ts +12 -1
- package/dist/realtime/api_proto.d.ts.map +1 -1
- package/dist/realtime/api_proto.js.map +1 -1
- package/dist/realtime/realtime_model.cjs +20 -6
- package/dist/realtime/realtime_model.cjs.map +1 -1
- package/dist/realtime/realtime_model.d.cts +2 -0
- package/dist/realtime/realtime_model.d.ts +2 -0
- package/dist/realtime/realtime_model.d.ts.map +1 -1
- package/dist/realtime/realtime_model.js +20 -6
- package/dist/realtime/realtime_model.js.map +1 -1
- package/dist/realtime/realtime_model.test.cjs +16 -0
- package/dist/realtime/realtime_model.test.cjs.map +1 -1
- package/dist/realtime/realtime_model.test.js +16 -0
- package/dist/realtime/realtime_model.test.js.map +1 -1
- package/dist/responses/llm.cjs +11 -0
- package/dist/responses/llm.cjs.map +1 -1
- package/dist/responses/llm.d.ts.map +1 -1
- package/dist/responses/llm.js +11 -0
- package/dist/responses/llm.js.map +1 -1
- package/dist/stt.cjs +3 -1
- package/dist/stt.cjs.map +1 -1
- package/dist/stt.d.cts +9 -6
- package/dist/stt.d.ts +9 -6
- package/dist/stt.d.ts.map +1 -1
- package/dist/stt.js +3 -1
- package/dist/stt.js.map +1 -1
- package/dist/stt.test.cjs +9 -2
- package/dist/stt.test.cjs.map +1 -1
- package/dist/stt.test.js +9 -2
- package/dist/stt.test.js.map +1 -1
- package/dist/ws/llm.cjs +9 -0
- package/dist/ws/llm.cjs.map +1 -1
- package/dist/ws/llm.d.ts.map +1 -1
- package/dist/ws/llm.js +9 -0
- package/dist/ws/llm.js.map +1 -1
- package/dist/ws/types.cjs +1 -1
- package/dist/ws/types.cjs.map +1 -1
- package/dist/ws/types.d.cts +3 -0
- package/dist/ws/types.d.ts +3 -0
- package/dist/ws/types.d.ts.map +1 -1
- package/dist/ws/types.js +1 -1
- package/dist/ws/types.js.map +1 -1
- package/package.json +5 -5
- package/src/realtime/api_proto.ts +14 -0
- package/src/realtime/realtime_model.test.ts +18 -0
- package/src/realtime/realtime_model.ts +33 -8
- package/src/responses/llm.ts +13 -0
- package/src/stt.test.ts +14 -2
- package/src/stt.ts +12 -7
- package/src/ws/llm.ts +9 -0
- package/src/ws/types.ts +1 -1
package/dist/ws/types.js
CHANGED
|
@@ -23,7 +23,7 @@ const wsFunctionCallItemSchema = z.object({
|
|
|
23
23
|
});
|
|
24
24
|
const wsOutputItemSchema = z.discriminatedUnion("type", [
|
|
25
25
|
wsFunctionCallItemSchema,
|
|
26
|
-
z.object({ type: z.literal("message") }).passthrough(),
|
|
26
|
+
z.object({ type: z.literal("message"), phase: z.string().optional() }).passthrough(),
|
|
27
27
|
z.object({ type: z.literal("reasoning") }).passthrough(),
|
|
28
28
|
z.object({ type: z.literal("file") }).passthrough(),
|
|
29
29
|
z.object({ type: z.literal("computer_call") }).passthrough(),
|
package/dist/ws/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ws/types.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { z } from 'zod';\n\n// ============================================================================\n// Client → Server events\n// ============================================================================\n\nexport const wsResponseCreateEventSchema = z\n .object({\n type: z.literal('response.create'),\n model: z.string(),\n input: z.array(z.unknown()),\n tools: z.array(z.unknown()).optional(),\n previous_response_id: z.string().nullable().optional(),\n store: z.boolean().optional(),\n temperature: z.number().optional(),\n metadata: z.record(z.string(), z.string()).optional(),\n })\n .passthrough();\n\nexport type WsResponseCreateEvent = z.infer<typeof wsResponseCreateEventSchema>;\n\n// ============================================================================\n// Server → Client events\n// ============================================================================\n\nexport const wsResponseCreatedEventSchema = z.object({\n type: z.literal('response.created'),\n response: z\n .object({\n id: z.string(),\n })\n .passthrough(),\n});\n\nexport const wsFunctionCallItemSchema = z.object({\n type: z.literal('function_call'),\n call_id: z.string(),\n name: z.string(),\n arguments: z.string(),\n});\n\nexport const wsOutputItemSchema = z.discriminatedUnion('type', [\n wsFunctionCallItemSchema,\n z.object({ type: z.literal('message') }).passthrough(),\n z.object({ type: z.literal('reasoning') }).passthrough(),\n z.object({ type: z.literal('file') }).passthrough(),\n z.object({ type: z.literal('computer_call') }).passthrough(),\n z.object({ type: z.literal('web_search_call') }).passthrough(),\n]);\n\nexport const wsOutputItemDoneEventSchema = z.object({\n type: z.literal('response.output_item.done'),\n item: wsOutputItemSchema,\n});\n\nexport const wsOutputTextDeltaEventSchema = z.object({\n type: z.literal('response.output_text.delta'),\n delta: z.string(),\n});\n\nexport const wsResponseCompletedEventSchema = z.object({\n type: z.literal('response.completed'),\n response: z\n .object({\n id: z.string(),\n service_tier: z.string().nullable().optional(),\n usage: z\n .object({\n output_tokens: z.number(),\n input_tokens: z.number(),\n total_tokens: z.number(),\n input_tokens_details: z\n .object({\n cached_tokens: z.number(),\n })\n .passthrough(),\n })\n .optional(),\n })\n .passthrough(),\n});\n\nexport const wsResponseFailedEventSchema = z.object({\n type: z.literal('response.failed'),\n response: z\n .object({\n id: z.string().optional(),\n error: z\n .object({\n code: z.string().optional(),\n message: z.string().optional(),\n })\n .optional(),\n })\n .passthrough(),\n});\n\nexport const wsErrorEventSchema = z.object({\n type: z.literal('error'),\n status: z.number().optional(),\n error: z\n .object({\n type: z.string().optional(),\n code: z.string().optional(),\n message: z.string().optional(),\n param: z.string().optional(),\n })\n .optional(),\n message: z.string().optional(),\n});\n\nexport const wsServerEventSchema = z.discriminatedUnion('type', [\n wsResponseCreatedEventSchema,\n wsOutputItemDoneEventSchema,\n wsOutputTextDeltaEventSchema,\n wsResponseCompletedEventSchema,\n wsResponseFailedEventSchema,\n wsErrorEventSchema,\n]);\n\nexport type WsResponseCreatedEvent = z.infer<typeof wsResponseCreatedEventSchema>;\nexport type WsFunctionCallItem = z.infer<typeof wsFunctionCallItemSchema>;\nexport type WsOutputItem = z.infer<typeof wsOutputItemSchema>;\nexport type WsOutputItemDoneEvent = z.infer<typeof wsOutputItemDoneEventSchema>;\nexport type WsOutputTextDeltaEvent = z.infer<typeof wsOutputTextDeltaEventSchema>;\nexport type WsResponseCompletedEvent = z.infer<typeof wsResponseCompletedEventSchema>;\nexport type WsResponseFailedEvent = z.infer<typeof wsResponseFailedEventSchema>;\nexport type WsErrorEvent = z.infer<typeof wsErrorEventSchema>;\nexport type WsServerEvent = z.infer<typeof wsServerEventSchema>;\n"],"mappings":"AAGA,SAAS,SAAS;AAMX,MAAM,8BAA8B,EACxC,OAAO;AAAA,EACN,MAAM,EAAE,QAAQ,iBAAiB;AAAA,EACjC,OAAO,EAAE,OAAO;AAAA,EAChB,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC;AAAA,EAC1B,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,SAAS;AAAA,EACrC,sBAAsB,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,EACrD,OAAO,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC5B,aAAa,EAAE,OAAO,EAAE,SAAS;AAAA,EACjC,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,EAAE,SAAS;AACtD,CAAC,EACA,YAAY;AAQR,MAAM,+BAA+B,EAAE,OAAO;AAAA,EACnD,MAAM,EAAE,QAAQ,kBAAkB;AAAA,EAClC,UAAU,EACP,OAAO;AAAA,IACN,IAAI,EAAE,OAAO;AAAA,EACf,CAAC,EACA,YAAY;AACjB,CAAC;AAEM,MAAM,2BAA2B,EAAE,OAAO;AAAA,EAC/C,MAAM,EAAE,QAAQ,eAAe;AAAA,EAC/B,SAAS,EAAE,OAAO;AAAA,EAClB,MAAM,EAAE,OAAO;AAAA,EACf,WAAW,EAAE,OAAO;AACtB,CAAC;AAEM,MAAM,qBAAqB,EAAE,mBAAmB,QAAQ;AAAA,EAC7D;AAAA,EACA,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,SAAS,EAAE,CAAC,EAAE,YAAY;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/ws/types.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { z } from 'zod';\n\n// ============================================================================\n// Client → Server events\n// ============================================================================\n\nexport const wsResponseCreateEventSchema = z\n .object({\n type: z.literal('response.create'),\n model: z.string(),\n input: z.array(z.unknown()),\n tools: z.array(z.unknown()).optional(),\n previous_response_id: z.string().nullable().optional(),\n store: z.boolean().optional(),\n temperature: z.number().optional(),\n metadata: z.record(z.string(), z.string()).optional(),\n })\n .passthrough();\n\nexport type WsResponseCreateEvent = z.infer<typeof wsResponseCreateEventSchema>;\n\n// ============================================================================\n// Server → Client events\n// ============================================================================\n\nexport const wsResponseCreatedEventSchema = z.object({\n type: z.literal('response.created'),\n response: z\n .object({\n id: z.string(),\n })\n .passthrough(),\n});\n\nexport const wsFunctionCallItemSchema = z.object({\n type: z.literal('function_call'),\n call_id: z.string(),\n name: z.string(),\n arguments: z.string(),\n});\n\nexport const wsOutputItemSchema = z.discriminatedUnion('type', [\n wsFunctionCallItemSchema,\n z.object({ type: z.literal('message'), phase: z.string().optional() }).passthrough(),\n z.object({ type: z.literal('reasoning') }).passthrough(),\n z.object({ type: z.literal('file') }).passthrough(),\n z.object({ type: z.literal('computer_call') }).passthrough(),\n z.object({ type: z.literal('web_search_call') }).passthrough(),\n]);\n\nexport const wsOutputItemDoneEventSchema = z.object({\n type: z.literal('response.output_item.done'),\n item: wsOutputItemSchema,\n});\n\nexport const wsOutputTextDeltaEventSchema = z.object({\n type: z.literal('response.output_text.delta'),\n delta: z.string(),\n});\n\nexport const wsResponseCompletedEventSchema = z.object({\n type: z.literal('response.completed'),\n response: z\n .object({\n id: z.string(),\n service_tier: z.string().nullable().optional(),\n usage: z\n .object({\n output_tokens: z.number(),\n input_tokens: z.number(),\n total_tokens: z.number(),\n input_tokens_details: z\n .object({\n cached_tokens: z.number(),\n })\n .passthrough(),\n })\n .optional(),\n })\n .passthrough(),\n});\n\nexport const wsResponseFailedEventSchema = z.object({\n type: z.literal('response.failed'),\n response: z\n .object({\n id: z.string().optional(),\n error: z\n .object({\n code: z.string().optional(),\n message: z.string().optional(),\n })\n .optional(),\n })\n .passthrough(),\n});\n\nexport const wsErrorEventSchema = z.object({\n type: z.literal('error'),\n status: z.number().optional(),\n error: z\n .object({\n type: z.string().optional(),\n code: z.string().optional(),\n message: z.string().optional(),\n param: z.string().optional(),\n })\n .optional(),\n message: z.string().optional(),\n});\n\nexport const wsServerEventSchema = z.discriminatedUnion('type', [\n wsResponseCreatedEventSchema,\n wsOutputItemDoneEventSchema,\n wsOutputTextDeltaEventSchema,\n wsResponseCompletedEventSchema,\n wsResponseFailedEventSchema,\n wsErrorEventSchema,\n]);\n\nexport type WsResponseCreatedEvent = z.infer<typeof wsResponseCreatedEventSchema>;\nexport type WsFunctionCallItem = z.infer<typeof wsFunctionCallItemSchema>;\nexport type WsOutputItem = z.infer<typeof wsOutputItemSchema>;\nexport type WsOutputItemDoneEvent = z.infer<typeof wsOutputItemDoneEventSchema>;\nexport type WsOutputTextDeltaEvent = z.infer<typeof wsOutputTextDeltaEventSchema>;\nexport type WsResponseCompletedEvent = z.infer<typeof wsResponseCompletedEventSchema>;\nexport type WsResponseFailedEvent = z.infer<typeof wsResponseFailedEventSchema>;\nexport type WsErrorEvent = z.infer<typeof wsErrorEventSchema>;\nexport type WsServerEvent = z.infer<typeof wsServerEventSchema>;\n"],"mappings":"AAGA,SAAS,SAAS;AAMX,MAAM,8BAA8B,EACxC,OAAO;AAAA,EACN,MAAM,EAAE,QAAQ,iBAAiB;AAAA,EACjC,OAAO,EAAE,OAAO;AAAA,EAChB,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC;AAA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E,SAAS;AAAA,EAC7B,CAAC,EACA,SAAS;AAAA,EACZ,SAAS,EAAE,OAAO,EAAE,SAAS;AAC/B,CAAC;AAEM,MAAM,sBAAsB,EAAE,mBAAmB,QAAQ;AAAA,EAC9D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livekit/agents-plugin-openai",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.7",
|
|
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.
|
|
34
|
-
"@livekit/agents-plugin-silero": "1.4.
|
|
35
|
-
"@livekit/agents-plugins-test": "1.4.
|
|
33
|
+
"@livekit/agents": "1.4.7",
|
|
34
|
+
"@livekit/agents-plugin-silero": "1.4.7",
|
|
35
|
+
"@livekit/agents-plugins-test": "1.4.7"
|
|
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.
|
|
45
|
+
"@livekit/agents": "1.4.7"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "tsup --onSuccess \"pnpm build:types\"",
|
|
@@ -10,6 +10,18 @@ export const OUT_FRAME_SIZE = 1200; // 50ms
|
|
|
10
10
|
export const BASE_URL = 'wss://api.openai.com/v1';
|
|
11
11
|
|
|
12
12
|
export type Model = 'gpt-4o-realtime-preview-2024-10-01' | string; // Open-ended, for future models
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Models that support the `reasoning` configuration on the Realtime API.
|
|
16
|
+
* Currently only the `gpt-realtime-2` family supports it.
|
|
17
|
+
*
|
|
18
|
+
* Ref: https://developers.openai.com/api/reference/resources/realtime/subresources/calls/methods/accept
|
|
19
|
+
*/
|
|
20
|
+
export type ReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
21
|
+
|
|
22
|
+
export interface Reasoning {
|
|
23
|
+
effort?: ReasoningEffort;
|
|
24
|
+
}
|
|
13
25
|
export type Voice =
|
|
14
26
|
| 'alloy'
|
|
15
27
|
| 'shimmer'
|
|
@@ -268,6 +280,7 @@ export interface ConversationResource {
|
|
|
268
280
|
}
|
|
269
281
|
|
|
270
282
|
export type ResponseStatusDetails =
|
|
283
|
+
| string
|
|
271
284
|
| {
|
|
272
285
|
type: 'incomplete';
|
|
273
286
|
reason: 'max_output_tokens' | 'content_filter' | string;
|
|
@@ -329,6 +342,7 @@ export interface SessionUpdateEvent extends BaseClientEvent {
|
|
|
329
342
|
audio?: RealtimeAudioConfig; // GA: nested audio config
|
|
330
343
|
max_output_tokens?: number | 'inf'; // GA: renamed from max_response_output_tokens
|
|
331
344
|
tracing?: TracingConfig | null; // GA: tracing config
|
|
345
|
+
reasoning?: Reasoning | null; // GA: reasoning config (gpt-realtime-2 only)
|
|
332
346
|
// Common fields
|
|
333
347
|
model: Model;
|
|
334
348
|
instructions: string;
|
|
@@ -119,6 +119,24 @@ describe('RealtimeSession response.done status handling', () => {
|
|
|
119
119
|
message: 'rate limited',
|
|
120
120
|
});
|
|
121
121
|
});
|
|
122
|
+
|
|
123
|
+
it('handles string response.done status details', () => {
|
|
124
|
+
const session = createResponseDoneSession();
|
|
125
|
+
|
|
126
|
+
expect(() =>
|
|
127
|
+
session.handleResponseDone({
|
|
128
|
+
type: 'response.done',
|
|
129
|
+
event_id: 'evt_response_incomplete',
|
|
130
|
+
response: {
|
|
131
|
+
id: 'resp_incomplete',
|
|
132
|
+
object: 'realtime.response',
|
|
133
|
+
status: 'incomplete',
|
|
134
|
+
status_details: 'incomplete',
|
|
135
|
+
output: [],
|
|
136
|
+
},
|
|
137
|
+
}),
|
|
138
|
+
).not.toThrow();
|
|
139
|
+
});
|
|
122
140
|
});
|
|
123
141
|
|
|
124
142
|
describe('RealtimeSession input_audio_transcription delta handling', () => {
|
|
@@ -48,6 +48,7 @@ interface RealtimeOptions {
|
|
|
48
48
|
maxResponseOutputTokens?: number | 'inf';
|
|
49
49
|
speed?: number;
|
|
50
50
|
tracing?: api_proto.TracingConfig | null;
|
|
51
|
+
reasoning?: api_proto.Reasoning;
|
|
51
52
|
apiKey?: string;
|
|
52
53
|
baseURL: string;
|
|
53
54
|
isAzure: boolean;
|
|
@@ -160,6 +161,7 @@ export class RealtimeModel extends llm.RealtimeModel {
|
|
|
160
161
|
constructor(
|
|
161
162
|
options: {
|
|
162
163
|
model?: string;
|
|
164
|
+
reasoning?: api_proto.Reasoning;
|
|
163
165
|
voice?: string;
|
|
164
166
|
/** @deprecated Unused in GA API (v1). Temperature is no longer supported. */
|
|
165
167
|
temperature?: number;
|
|
@@ -516,6 +518,7 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
516
518
|
// GA format (OpenAI or Azure GA)
|
|
517
519
|
const audioFormat: api_proto.AudioFormat = { type: 'audio/pcm', rate: SAMPLE_RATE };
|
|
518
520
|
const modality: Modality = opts.modalities.includes('audio') ? 'audio' : 'text';
|
|
521
|
+
const includeReasoning = opts.reasoning && opts.model.startsWith('gpt-realtime-2');
|
|
519
522
|
return {
|
|
520
523
|
type: 'session.update',
|
|
521
524
|
session: {
|
|
@@ -539,6 +542,7 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
539
542
|
tool_choice: toOaiToolChoice(opts.toolChoice),
|
|
540
543
|
tracing: opts.tracing,
|
|
541
544
|
instructions: this.instructions,
|
|
545
|
+
...(includeReasoning ? { reasoning: opts.reasoning } : {}),
|
|
542
546
|
},
|
|
543
547
|
};
|
|
544
548
|
}
|
|
@@ -674,7 +678,13 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
674
678
|
| api_proto.ConversationItemDeleteEvent
|
|
675
679
|
)[] = [];
|
|
676
680
|
|
|
677
|
-
const
|
|
681
|
+
const remoteCtx = this.chatCtx;
|
|
682
|
+
const remoteIds = new Set(remoteCtx.items.map((item) => item.id));
|
|
683
|
+
newChatCtx.items = newChatCtx.items.filter(
|
|
684
|
+
(item) => item.type !== 'message' || item.content.length > 0 || remoteIds.has(item.id),
|
|
685
|
+
);
|
|
686
|
+
|
|
687
|
+
const diffOps = llm.computeChatCtxDiff(remoteCtx, newChatCtx);
|
|
678
688
|
for (const op of diffOps.toRemove) {
|
|
679
689
|
events.push({
|
|
680
690
|
type: 'conversation.item.delete',
|
|
@@ -707,8 +717,7 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
707
717
|
throw new Error('Tools are missing in the session update event');
|
|
708
718
|
}
|
|
709
719
|
|
|
710
|
-
// TODO(brian): these logics below are noops I think
|
|
711
|
-
// parity with the python but we should remove them later
|
|
720
|
+
// TODO(brian): these logics below are noops I think; remove them later.
|
|
712
721
|
const retainedToolNames = new Set(ev.session.tools.map((tool) => tool.name));
|
|
713
722
|
const retainedTools = Object.fromEntries(
|
|
714
723
|
Object.entries(_tools).filter(
|
|
@@ -886,11 +895,18 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
886
895
|
const hasServerSideAudio = this.audioCapableItemIds.has(_options.messageId);
|
|
887
896
|
|
|
888
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;
|
|
889
905
|
this.sendEvent({
|
|
890
906
|
type: 'conversation.item.truncate',
|
|
891
907
|
content_index: 0,
|
|
892
908
|
item_id: _options.messageId,
|
|
893
|
-
audio_end_ms:
|
|
909
|
+
audio_end_ms: audioEndMs,
|
|
894
910
|
} as api_proto.ConversationItemTruncateEvent);
|
|
895
911
|
} else if (_options.audioTranscript !== undefined) {
|
|
896
912
|
// sync it to the remote chat context
|
|
@@ -1836,7 +1852,10 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
1836
1852
|
|
|
1837
1853
|
const statusDetails = event.response.status_details;
|
|
1838
1854
|
if (event.response.status === 'failed') {
|
|
1839
|
-
const errorBody =
|
|
1855
|
+
const errorBody =
|
|
1856
|
+
typeof statusDetails !== 'string' && statusDetails?.type === 'failed'
|
|
1857
|
+
? statusDetails.error
|
|
1858
|
+
: undefined;
|
|
1840
1859
|
const errorTypeValue = errorBody && 'type' in errorBody ? errorBody.type : undefined;
|
|
1841
1860
|
const errorType = typeof errorTypeValue === 'string' ? errorTypeValue : 'unknown';
|
|
1842
1861
|
|
|
@@ -1848,9 +1867,15 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
1848
1867
|
recoverable: true,
|
|
1849
1868
|
});
|
|
1850
1869
|
} else if (event.response.status === 'cancelled' || event.response.status === 'incomplete') {
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1870
|
+
let statusType: string | undefined;
|
|
1871
|
+
let statusReason: string | undefined;
|
|
1872
|
+
if (typeof statusDetails === 'string') {
|
|
1873
|
+
statusType = statusDetails;
|
|
1874
|
+
} else {
|
|
1875
|
+
statusType = statusDetails?.type;
|
|
1876
|
+
statusReason =
|
|
1877
|
+
statusDetails && 'reason' in statusDetails ? statusDetails.reason : undefined;
|
|
1878
|
+
}
|
|
1854
1879
|
|
|
1855
1880
|
this.#logger.debug(
|
|
1856
1881
|
{
|
package/src/responses/llm.ts
CHANGED
|
@@ -318,6 +318,19 @@ class ResponsesHttpLLMStream extends llm.LLMStream {
|
|
|
318
318
|
],
|
|
319
319
|
},
|
|
320
320
|
};
|
|
321
|
+
} else if (event.item.type === 'message') {
|
|
322
|
+
const phase = (event.item as OpenAI.Responses.ResponseOutputMessage & { phase?: string })
|
|
323
|
+
.phase;
|
|
324
|
+
if (phase === undefined) return undefined;
|
|
325
|
+
|
|
326
|
+
chunk = {
|
|
327
|
+
id: this.responseId,
|
|
328
|
+
delta: {
|
|
329
|
+
role: 'assistant',
|
|
330
|
+
content: undefined,
|
|
331
|
+
extra: { openai: { phase } },
|
|
332
|
+
},
|
|
333
|
+
};
|
|
321
334
|
}
|
|
322
335
|
return chunk;
|
|
323
336
|
}
|
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
|
|
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(
|
|
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
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* `session.update` frame
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
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.
|
|
62
|
+
if (url.hostname !== 'api.openai.com') {
|
|
63
|
+
url.searchParams.set('model', model);
|
|
64
|
+
}
|
|
60
65
|
return url.toString();
|
|
61
66
|
}
|
|
62
67
|
|
package/src/ws/llm.ts
CHANGED
|
@@ -593,6 +593,15 @@ export class WSLLMStream extends llm.LLMStream {
|
|
|
593
593
|
],
|
|
594
594
|
},
|
|
595
595
|
};
|
|
596
|
+
} else if (event.item.type === 'message' && event.item.phase !== undefined) {
|
|
597
|
+
return {
|
|
598
|
+
id: this.#responseId,
|
|
599
|
+
delta: {
|
|
600
|
+
role: 'assistant',
|
|
601
|
+
content: undefined,
|
|
602
|
+
extra: { openai: { phase: event.item.phase } },
|
|
603
|
+
},
|
|
604
|
+
};
|
|
596
605
|
}
|
|
597
606
|
return undefined;
|
|
598
607
|
}
|
package/src/ws/types.ts
CHANGED
|
@@ -44,7 +44,7 @@ export const wsFunctionCallItemSchema = z.object({
|
|
|
44
44
|
|
|
45
45
|
export const wsOutputItemSchema = z.discriminatedUnion('type', [
|
|
46
46
|
wsFunctionCallItemSchema,
|
|
47
|
-
z.object({ type: z.literal('message') }).passthrough(),
|
|
47
|
+
z.object({ type: z.literal('message'), phase: z.string().optional() }).passthrough(),
|
|
48
48
|
z.object({ type: z.literal('reasoning') }).passthrough(),
|
|
49
49
|
z.object({ type: z.literal('file') }).passthrough(),
|
|
50
50
|
z.object({ type: z.literal('computer_call') }).passthrough(),
|