@livekit/agents-plugin-openai 1.7.1 → 1.8.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/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/realtime/realtime_model.cjs +4 -1
- package/dist/realtime/realtime_model.cjs.map +1 -1
- package/dist/realtime/realtime_model.d.ts.map +1 -1
- package/dist/realtime/realtime_model.js +4 -1
- package/dist/realtime/realtime_model.js.map +1 -1
- package/dist/realtime/realtime_model.test.cjs +29 -0
- package/dist/realtime/realtime_model.test.cjs.map +1 -1
- package/dist/realtime/realtime_model.test.js +29 -0
- package/dist/realtime/realtime_model.test.js.map +1 -1
- package/dist/responses/llm.cjs +10 -0
- package/dist/responses/llm.cjs.map +1 -1
- package/dist/responses/llm.d.ts.map +1 -1
- package/dist/responses/llm.js +10 -0
- package/dist/responses/llm.js.map +1 -1
- package/dist/responses/llm.test.cjs +51 -0
- package/dist/responses/llm.test.cjs.map +1 -1
- package/dist/responses/llm.test.js +52 -1
- package/dist/responses/llm.test.js.map +1 -1
- package/dist/ws/llm.cjs +25 -7
- package/dist/ws/llm.cjs.map +1 -1
- package/dist/ws/llm.d.cts +2 -2
- package/dist/ws/llm.d.ts +2 -2
- package/dist/ws/llm.d.ts.map +1 -1
- package/dist/ws/llm.js +25 -7
- package/dist/ws/llm.js.map +1 -1
- package/dist/ws/llm.test.cjs +117 -0
- package/dist/ws/llm.test.cjs.map +1 -1
- package/dist/ws/llm.test.js +126 -3
- package/dist/ws/llm.test.js.map +1 -1
- package/dist/ws/types.cjs +12 -0
- package/dist/ws/types.cjs.map +1 -1
- package/dist/ws/types.d.cts +18 -0
- package/dist/ws/types.d.ts +18 -0
- package/dist/ws/types.d.ts.map +1 -1
- package/dist/ws/types.js +11 -0
- package/dist/ws/types.js.map +1 -1
- package/package.json +5 -5
- package/src/realtime/realtime_model.test.ts +32 -0
- package/src/realtime/realtime_model.ts +4 -1
- package/src/responses/llm.test.ts +55 -1
- package/src/responses/llm.ts +10 -0
- package/src/ws/llm.test.ts +141 -5
- package/src/ws/llm.ts +29 -8
- package/src/ws/types.ts +17 -0
package/dist/ws/types.cjs
CHANGED
|
@@ -27,6 +27,7 @@ __export(types_exports, {
|
|
|
27
27
|
wsResponseCreateEventSchema: () => wsResponseCreateEventSchema,
|
|
28
28
|
wsResponseCreatedEventSchema: () => wsResponseCreatedEventSchema,
|
|
29
29
|
wsResponseFailedEventSchema: () => wsResponseFailedEventSchema,
|
|
30
|
+
wsResponseIncompleteEventSchema: () => wsResponseIncompleteEventSchema,
|
|
30
31
|
wsServerEventSchema: () => wsServerEventSchema
|
|
31
32
|
});
|
|
32
33
|
module.exports = __toCommonJS(types_exports);
|
|
@@ -94,6 +95,15 @@ const wsResponseFailedEventSchema = import_zod.z.object({
|
|
|
94
95
|
}).optional()
|
|
95
96
|
}).passthrough()
|
|
96
97
|
});
|
|
98
|
+
const wsResponseIncompleteEventSchema = import_zod.z.object({
|
|
99
|
+
type: import_zod.z.literal("response.incomplete"),
|
|
100
|
+
response: import_zod.z.object({
|
|
101
|
+
id: import_zod.z.string(),
|
|
102
|
+
incomplete_details: import_zod.z.object({
|
|
103
|
+
reason: import_zod.z.string().optional()
|
|
104
|
+
}).nullable().optional()
|
|
105
|
+
}).passthrough()
|
|
106
|
+
});
|
|
97
107
|
const wsErrorEventSchema = import_zod.z.object({
|
|
98
108
|
type: import_zod.z.literal("error"),
|
|
99
109
|
status: import_zod.z.number().optional(),
|
|
@@ -113,6 +123,7 @@ const wsServerEventSchema = import_zod.z.discriminatedUnion("type", [
|
|
|
113
123
|
wsOutputTextDeltaEventSchema,
|
|
114
124
|
wsResponseCompletedEventSchema,
|
|
115
125
|
wsResponseFailedEventSchema,
|
|
126
|
+
wsResponseIncompleteEventSchema,
|
|
116
127
|
wsErrorEventSchema
|
|
117
128
|
]);
|
|
118
129
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -126,6 +137,7 @@ const wsServerEventSchema = import_zod.z.discriminatedUnion("type", [
|
|
|
126
137
|
wsResponseCreateEventSchema,
|
|
127
138
|
wsResponseCreatedEventSchema,
|
|
128
139
|
wsResponseFailedEventSchema,
|
|
140
|
+
wsResponseIncompleteEventSchema,
|
|
129
141
|
wsServerEventSchema
|
|
130
142
|
});
|
|
131
143
|
//# sourceMappingURL=types.cjs.map
|
package/dist/ws/types.cjs.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'), 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 code: z.string().optional(),\n param: z.string().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":";;;;;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EACzC,MAAM,aAAE,QAAQ,OAAO;AAAA,EACvB,QAAQ,aAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,MAAM,aAAE,OAAO,EAAE,SAAS;AAAA,EAC1B,OAAO,aAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,OAAO,aACJ,OAAO;AAAA,IACN,MAAM,aAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,MAAM,aAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,SAAS,aAAE,OAAO,EAAE,SAAS;AAAA,IAC7B,OAAO,aAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,CAAC,EACA,SAAS;AAAA,EACZ,SAAS,aAAE,OAAO,EAAE,SAAS;AAC/B,CAAC;AAEM,MAAM,sBAAsB,aAAE,mBAAmB,QAAQ;AAAA,EAC9D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;","names":[]}
|
|
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 wsResponseIncompleteEventSchema = z.object({\n type: z.literal('response.incomplete'),\n response: z\n .object({\n id: z.string(),\n incomplete_details: z\n .object({\n reason: z.string().optional(),\n })\n .nullable()\n .optional(),\n })\n .passthrough(),\n});\n\nexport const wsErrorEventSchema = z.object({\n type: z.literal('error'),\n status: z.number().optional(),\n code: z.string().optional(),\n param: z.string().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 wsResponseIncompleteEventSchema,\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 WsResponseIncompleteEvent = z.infer<typeof wsResponseIncompleteEventSchema>;\nexport type WsErrorEvent = z.infer<typeof wsErrorEventSchema>;\nexport type WsServerEvent = z.infer<typeof wsServerEventSchema>;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAkB;AAMX,MAAM,8BAA8B,aACxC,OAAO;AAAA,EACN,MAAM,aAAE,QAAQ,iBAAiB;AAAA,EACjC,OAAO,aAAE,OAAO;AAAA,EAChB,OAAO,aAAE,MAAM,aAAE,QAAQ,CAAC;AAAA,EAC1B,OAAO,aAAE,MAAM,aAAE,QAAQ,CAAC,EAAE,SAAS;AAAA,EACrC,sBAAsB,aAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,EACrD,OAAO,aAAE,QAAQ,EAAE,SAAS;AAAA,EAC5B,aAAa,aAAE,OAAO,EAAE,SAAS;AAAA,EACjC,UAAU,aAAE,OAAO,aAAE,OAAO,GAAG,aAAE,OAAO,CAAC,EAAE,SAAS;AACtD,CAAC,EACA,YAAY;AAQR,MAAM,+BAA+B,aAAE,OAAO;AAAA,EACnD,MAAM,aAAE,QAAQ,kBAAkB;AAAA,EAClC,UAAU,aACP,OAAO;AAAA,IACN,IAAI,aAAE,OAAO;AAAA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,EAAE,SAAS;AAC/B,CAAC;AAEM,MAAM,sBAAsB,aAAE,mBAAmB,QAAQ;AAAA,EAC9D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;","names":[]}
|
package/dist/ws/types.d.cts
CHANGED
|
@@ -88,6 +88,15 @@ export declare const wsResponseFailedEventSchema: z.ZodObject<{
|
|
|
88
88
|
}, z.core.$strip>>;
|
|
89
89
|
}, z.core.$loose>;
|
|
90
90
|
}, z.core.$strip>;
|
|
91
|
+
export declare const wsResponseIncompleteEventSchema: z.ZodObject<{
|
|
92
|
+
type: z.ZodLiteral<"response.incomplete">;
|
|
93
|
+
response: z.ZodObject<{
|
|
94
|
+
id: z.ZodString;
|
|
95
|
+
incomplete_details: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
96
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
97
|
+
}, z.core.$strip>>>;
|
|
98
|
+
}, z.core.$loose>;
|
|
99
|
+
}, z.core.$strip>;
|
|
91
100
|
export declare const wsErrorEventSchema: z.ZodObject<{
|
|
92
101
|
type: z.ZodLiteral<"error">;
|
|
93
102
|
status: z.ZodOptional<z.ZodNumber>;
|
|
@@ -151,6 +160,14 @@ export declare const wsServerEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
151
160
|
message: z.ZodOptional<z.ZodString>;
|
|
152
161
|
}, z.core.$strip>>;
|
|
153
162
|
}, z.core.$loose>;
|
|
163
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
164
|
+
type: z.ZodLiteral<"response.incomplete">;
|
|
165
|
+
response: z.ZodObject<{
|
|
166
|
+
id: z.ZodString;
|
|
167
|
+
incomplete_details: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
168
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
169
|
+
}, z.core.$strip>>>;
|
|
170
|
+
}, z.core.$loose>;
|
|
154
171
|
}, z.core.$strip>, z.ZodObject<{
|
|
155
172
|
type: z.ZodLiteral<"error">;
|
|
156
173
|
status: z.ZodOptional<z.ZodNumber>;
|
|
@@ -171,6 +188,7 @@ export type WsOutputItemDoneEvent = z.infer<typeof wsOutputItemDoneEventSchema>;
|
|
|
171
188
|
export type WsOutputTextDeltaEvent = z.infer<typeof wsOutputTextDeltaEventSchema>;
|
|
172
189
|
export type WsResponseCompletedEvent = z.infer<typeof wsResponseCompletedEventSchema>;
|
|
173
190
|
export type WsResponseFailedEvent = z.infer<typeof wsResponseFailedEventSchema>;
|
|
191
|
+
export type WsResponseIncompleteEvent = z.infer<typeof wsResponseIncompleteEventSchema>;
|
|
174
192
|
export type WsErrorEvent = z.infer<typeof wsErrorEventSchema>;
|
|
175
193
|
export type WsServerEvent = z.infer<typeof wsServerEventSchema>;
|
|
176
194
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/ws/types.d.ts
CHANGED
|
@@ -88,6 +88,15 @@ export declare const wsResponseFailedEventSchema: z.ZodObject<{
|
|
|
88
88
|
}, z.core.$strip>>;
|
|
89
89
|
}, z.core.$loose>;
|
|
90
90
|
}, z.core.$strip>;
|
|
91
|
+
export declare const wsResponseIncompleteEventSchema: z.ZodObject<{
|
|
92
|
+
type: z.ZodLiteral<"response.incomplete">;
|
|
93
|
+
response: z.ZodObject<{
|
|
94
|
+
id: z.ZodString;
|
|
95
|
+
incomplete_details: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
96
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
97
|
+
}, z.core.$strip>>>;
|
|
98
|
+
}, z.core.$loose>;
|
|
99
|
+
}, z.core.$strip>;
|
|
91
100
|
export declare const wsErrorEventSchema: z.ZodObject<{
|
|
92
101
|
type: z.ZodLiteral<"error">;
|
|
93
102
|
status: z.ZodOptional<z.ZodNumber>;
|
|
@@ -151,6 +160,14 @@ export declare const wsServerEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
151
160
|
message: z.ZodOptional<z.ZodString>;
|
|
152
161
|
}, z.core.$strip>>;
|
|
153
162
|
}, z.core.$loose>;
|
|
163
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
164
|
+
type: z.ZodLiteral<"response.incomplete">;
|
|
165
|
+
response: z.ZodObject<{
|
|
166
|
+
id: z.ZodString;
|
|
167
|
+
incomplete_details: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
168
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
169
|
+
}, z.core.$strip>>>;
|
|
170
|
+
}, z.core.$loose>;
|
|
154
171
|
}, z.core.$strip>, z.ZodObject<{
|
|
155
172
|
type: z.ZodLiteral<"error">;
|
|
156
173
|
status: z.ZodOptional<z.ZodNumber>;
|
|
@@ -171,6 +188,7 @@ export type WsOutputItemDoneEvent = z.infer<typeof wsOutputItemDoneEventSchema>;
|
|
|
171
188
|
export type WsOutputTextDeltaEvent = z.infer<typeof wsOutputTextDeltaEventSchema>;
|
|
172
189
|
export type WsResponseCompletedEvent = z.infer<typeof wsResponseCompletedEventSchema>;
|
|
173
190
|
export type WsResponseFailedEvent = z.infer<typeof wsResponseFailedEventSchema>;
|
|
191
|
+
export type WsResponseIncompleteEvent = z.infer<typeof wsResponseIncompleteEventSchema>;
|
|
174
192
|
export type WsErrorEvent = z.infer<typeof wsErrorEventSchema>;
|
|
175
193
|
export type WsServerEvent = z.infer<typeof wsServerEventSchema>;
|
|
176
194
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/ws/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/ws/types.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,2BAA2B;;;;;;;;;iBAWxB,CAAC;AAEjB,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAMhF,eAAO,MAAM,4BAA4B;;;;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;;;;;;;;;;;;;;;;;2BAQ9B,CAAC;AAEH,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAClF,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAC1E,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAC9D,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAChF,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAClF,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAC;AACtF,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAChF,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAC;AACxF,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAC9D,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
|
package/dist/ws/types.js
CHANGED
|
@@ -62,6 +62,15 @@ const wsResponseFailedEventSchema = z.object({
|
|
|
62
62
|
}).optional()
|
|
63
63
|
}).passthrough()
|
|
64
64
|
});
|
|
65
|
+
const wsResponseIncompleteEventSchema = z.object({
|
|
66
|
+
type: z.literal("response.incomplete"),
|
|
67
|
+
response: z.object({
|
|
68
|
+
id: z.string(),
|
|
69
|
+
incomplete_details: z.object({
|
|
70
|
+
reason: z.string().optional()
|
|
71
|
+
}).nullable().optional()
|
|
72
|
+
}).passthrough()
|
|
73
|
+
});
|
|
65
74
|
const wsErrorEventSchema = z.object({
|
|
66
75
|
type: z.literal("error"),
|
|
67
76
|
status: z.number().optional(),
|
|
@@ -81,6 +90,7 @@ const wsServerEventSchema = z.discriminatedUnion("type", [
|
|
|
81
90
|
wsOutputTextDeltaEventSchema,
|
|
82
91
|
wsResponseCompletedEventSchema,
|
|
83
92
|
wsResponseFailedEventSchema,
|
|
93
|
+
wsResponseIncompleteEventSchema,
|
|
84
94
|
wsErrorEventSchema
|
|
85
95
|
]);
|
|
86
96
|
export {
|
|
@@ -93,6 +103,7 @@ export {
|
|
|
93
103
|
wsResponseCreateEventSchema,
|
|
94
104
|
wsResponseCreatedEventSchema,
|
|
95
105
|
wsResponseFailedEventSchema,
|
|
106
|
+
wsResponseIncompleteEventSchema,
|
|
96
107
|
wsServerEventSchema
|
|
97
108
|
};
|
|
98
109
|
//# sourceMappingURL=types.js.map
|
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'), 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 code: z.string().optional(),\n param: z.string().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,GAAG,OAA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OAAO;AAAA,MACN,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,MAC1B,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,IAC/B,CAAC,EACA,SAAS;AAAA,EACd,CAAC,EACA,YAAY;AACjB,CAAC;AAEM,MAAM,qBAAqB,EAAE,OAAO;AAAA,EACzC,MAAM,EAAE,QAAQ,OAAO;AAAA,EACvB,QAAQ,EAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,EAC1B,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,OAAO,EACJ,OAAO;AAAA,IACN,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,IAC7B,OAAO,EAAE,OAAO,EAAE,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":[]}
|
|
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 wsResponseIncompleteEventSchema = z.object({\n type: z.literal('response.incomplete'),\n response: z\n .object({\n id: z.string(),\n incomplete_details: z\n .object({\n reason: z.string().optional(),\n })\n .nullable()\n .optional(),\n })\n .passthrough(),\n});\n\nexport const wsErrorEventSchema = z.object({\n type: z.literal('error'),\n status: z.number().optional(),\n code: z.string().optional(),\n param: z.string().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 wsResponseIncompleteEventSchema,\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 WsResponseIncompleteEvent = z.infer<typeof wsResponseIncompleteEventSchema>;\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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B,OAAO,EAAE,OAAO,EAAE,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;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.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "OpenAI plugin for LiveKit Node Agents",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"require": "dist/index.cjs",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"@types/ws": "^8.5.10",
|
|
34
34
|
"tsup": "^8.3.5",
|
|
35
35
|
"typescript": "^5.0.0",
|
|
36
|
-
"@livekit/agents": "1.
|
|
37
|
-
"@livekit/agents-plugin-silero": "1.
|
|
38
|
-
"@livekit/agents-plugins-test": "1.
|
|
36
|
+
"@livekit/agents": "1.8.0",
|
|
37
|
+
"@livekit/agents-plugin-silero": "1.8.0",
|
|
38
|
+
"@livekit/agents-plugins-test": "1.8.0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@livekit/mutex": "^1.1.1",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"@livekit/rtc-node": "^0.13.34",
|
|
47
47
|
"zod": "^3.25.76 || ^4.1.8",
|
|
48
|
-
"@livekit/agents": "1.
|
|
48
|
+
"@livekit/agents": "1.8.0"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "tsup --onSuccess \"pnpm build:types\"",
|
|
@@ -1096,6 +1096,38 @@ describe('RealtimeSession chat context update events', () => {
|
|
|
1096
1096
|
expect((events[0] as api_proto.ConversationItemDeleteEvent).item_id).toBe('item_1');
|
|
1097
1097
|
expect((events[1] as api_proto.ConversationItemCreateEvent).item.id).toBe('item_1');
|
|
1098
1098
|
});
|
|
1099
|
+
|
|
1100
|
+
it('ignores session metadata when creating provider events', async () => {
|
|
1101
|
+
const existingMessage = llm.ChatMessage.create({
|
|
1102
|
+
id: 'item_1',
|
|
1103
|
+
role: 'assistant',
|
|
1104
|
+
content: ['What is two plus two?'],
|
|
1105
|
+
});
|
|
1106
|
+
const session = createChatCtxUpdateSession(existingMessage);
|
|
1107
|
+
|
|
1108
|
+
const events = await session.createChatCtxUpdateEvents(
|
|
1109
|
+
new llm.ChatContext([
|
|
1110
|
+
existingMessage,
|
|
1111
|
+
new llm.AgentConfigUpdate({
|
|
1112
|
+
id: 'item_config',
|
|
1113
|
+
instructions: 'Ask the next math question.',
|
|
1114
|
+
}),
|
|
1115
|
+
new llm.AgentHandoffItem({
|
|
1116
|
+
id: 'item_handoff',
|
|
1117
|
+
oldAgentId: 'agent_1',
|
|
1118
|
+
newAgentId: 'agent_2',
|
|
1119
|
+
}),
|
|
1120
|
+
llm.ChatMessage.create({ id: 'item_2', role: 'user', content: ['four'] }),
|
|
1121
|
+
]),
|
|
1122
|
+
);
|
|
1123
|
+
|
|
1124
|
+
expect(events).toHaveLength(1);
|
|
1125
|
+
expect(events[0]).toMatchObject({
|
|
1126
|
+
type: 'conversation.item.create',
|
|
1127
|
+
previous_item_id: 'item_1',
|
|
1128
|
+
item: { id: 'item_2' },
|
|
1129
|
+
});
|
|
1130
|
+
});
|
|
1099
1131
|
});
|
|
1100
1132
|
|
|
1101
1133
|
describe('RealtimeSession.updateOptions', () => {
|
|
@@ -710,7 +710,10 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
710
710
|
chatCtx: llm.ChatContext,
|
|
711
711
|
addMockAudio: boolean = false,
|
|
712
712
|
): Promise<(api_proto.ConversationItemCreateEvent | api_proto.ConversationItemDeleteEvent)[]> {
|
|
713
|
-
const newChatCtx = chatCtx.copy(
|
|
713
|
+
const newChatCtx = chatCtx.copy({
|
|
714
|
+
excludeHandoff: true,
|
|
715
|
+
excludeConfigUpdate: true,
|
|
716
|
+
});
|
|
714
717
|
if (addMockAudio) {
|
|
715
718
|
newChatCtx.items.push(createMockAudioItem());
|
|
716
719
|
} else {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
import { ChatContext, initializeLogger } from '@livekit/agents';
|
|
4
|
+
import { APIStatusError, ChatContext, initializeLogger } from '@livekit/agents';
|
|
5
5
|
import { llm, llmStrict } from '@livekit/agents-plugins-test';
|
|
6
6
|
import type OpenAI from 'openai';
|
|
7
7
|
import { describe, expect, it } from 'vitest';
|
|
@@ -116,6 +116,60 @@ describe('OpenAI Responses HTTP retry eligibility', () => {
|
|
|
116
116
|
});
|
|
117
117
|
});
|
|
118
118
|
|
|
119
|
+
describe('OpenAI Responses HTTP incomplete handling', () => {
|
|
120
|
+
it.each([
|
|
121
|
+
['max_output_tokens', 'max_output_tokens'],
|
|
122
|
+
[undefined, 'reason unavailable'],
|
|
123
|
+
] as const)('surfaces %s as non-retryable', async (reason, expectedMessage) => {
|
|
124
|
+
let attempts = 0;
|
|
125
|
+
const incomplete = {
|
|
126
|
+
type: 'response.incomplete',
|
|
127
|
+
response: {
|
|
128
|
+
id: 'resp_1',
|
|
129
|
+
...(reason === undefined ? {} : { incomplete_details: { reason } }),
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
const client = {
|
|
133
|
+
responses: {
|
|
134
|
+
create: async () => {
|
|
135
|
+
attempts++;
|
|
136
|
+
return {
|
|
137
|
+
async *[Symbol.asyncIterator]() {
|
|
138
|
+
yield RESPONSE_CREATED;
|
|
139
|
+
yield incomplete;
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
const model = new LLM({
|
|
146
|
+
model: 'gpt-4.1',
|
|
147
|
+
apiKey: 'test-key',
|
|
148
|
+
useWebSocket: false,
|
|
149
|
+
client: client as unknown as OpenAI,
|
|
150
|
+
});
|
|
151
|
+
const errorEvent = new Promise<Error>((resolve) => {
|
|
152
|
+
model.once('error', (event) => resolve(event.error));
|
|
153
|
+
});
|
|
154
|
+
const chatCtx = ChatContext.empty();
|
|
155
|
+
chatCtx.addMessage({ role: 'user', content: 'hi' });
|
|
156
|
+
|
|
157
|
+
const stream = model.chat({
|
|
158
|
+
chatCtx,
|
|
159
|
+
connOptions: { maxRetry: 2, retryIntervalMs: 0, timeoutMs: 5000 },
|
|
160
|
+
});
|
|
161
|
+
for await (const _chunk of stream) void _chunk;
|
|
162
|
+
const error = await errorEvent;
|
|
163
|
+
|
|
164
|
+
expect(error).toBeInstanceOf(APIStatusError);
|
|
165
|
+
expect(error.message).toContain(expectedMessage);
|
|
166
|
+
expect((error as APIStatusError).statusCode).toBe(-1);
|
|
167
|
+
expect((error as APIStatusError).retryable).toBe(false);
|
|
168
|
+
expect(attempts).toBe(1);
|
|
169
|
+
await model.aclose();
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
119
173
|
if (hasOpenAIApiKey) {
|
|
120
174
|
describe('OpenAI Responses', async () => {
|
|
121
175
|
await llm(
|
package/src/responses/llm.ts
CHANGED
|
@@ -247,6 +247,9 @@ class ResponsesHttpLLMStream extends llm.LLMStream {
|
|
|
247
247
|
case 'response.failed':
|
|
248
248
|
this.handleResponseFailed(event);
|
|
249
249
|
break;
|
|
250
|
+
case 'response.incomplete':
|
|
251
|
+
this.handleResponseIncomplete(event);
|
|
252
|
+
break;
|
|
250
253
|
}
|
|
251
254
|
|
|
252
255
|
if (chunk) {
|
|
@@ -303,6 +306,13 @@ class ResponsesHttpLLMStream extends llm.LLMStream {
|
|
|
303
306
|
});
|
|
304
307
|
}
|
|
305
308
|
|
|
309
|
+
private handleResponseIncomplete(event: OpenAI.Responses.ResponseIncompleteEvent): void {
|
|
310
|
+
throw new APIStatusError({
|
|
311
|
+
message: `response incomplete: ${event.response.incomplete_details?.reason ?? 'reason unavailable'}`,
|
|
312
|
+
options: { statusCode: -1, retryable: false },
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
|
|
306
316
|
private handleResponseCreated(event: OpenAI.Responses.ResponseCreatedEvent): void {
|
|
307
317
|
this.responseId = event.response.id;
|
|
308
318
|
}
|
package/src/ws/llm.test.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2025 LiveKit, Inc.
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
APIStatusError,
|
|
6
|
+
ChatContext,
|
|
7
|
+
ConnectionPool,
|
|
8
|
+
initializeLogger,
|
|
9
|
+
stream,
|
|
10
|
+
} from '@livekit/agents';
|
|
5
11
|
import { llm, llmStrict } from '@livekit/agents-plugins-test';
|
|
6
|
-
import {
|
|
12
|
+
import { EventEmitter } from 'node:events';
|
|
13
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
7
14
|
import { LLM } from '../responses/llm.js';
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
15
|
+
import { ResponsesWebSocket, WSLLM, WSLLMStream, buildResponsesWsUrl } from './llm.js';
|
|
16
|
+
import type { WsResponseCreateEvent, WsServerEvent } from './types.js';
|
|
17
|
+
import { wsServerEventSchema } from './types.js';
|
|
11
18
|
|
|
12
19
|
initializeLogger({ level: 'silent', pretty: false });
|
|
13
20
|
|
|
@@ -100,6 +107,65 @@ const TEXT_DELTA: WsServerEvent = {
|
|
|
100
107
|
delta: 'hello',
|
|
101
108
|
};
|
|
102
109
|
|
|
110
|
+
function responseIncomplete(reason?: string): WsServerEvent {
|
|
111
|
+
return {
|
|
112
|
+
type: 'response.incomplete',
|
|
113
|
+
response: {
|
|
114
|
+
id: 'resp_1',
|
|
115
|
+
incomplete_details: reason === undefined ? {} : { reason },
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
describe('OpenAI Responses WS incomplete events', () => {
|
|
121
|
+
it.each(['max_output_tokens', 'content_filter'])('parses the provider reason %s', (reason) => {
|
|
122
|
+
const parsed = wsServerEventSchema.parse(responseIncomplete(reason));
|
|
123
|
+
|
|
124
|
+
expect(parsed.type).toBe('response.incomplete');
|
|
125
|
+
if (parsed.type !== 'response.incomplete') throw new Error('expected incomplete event');
|
|
126
|
+
expect(parsed.response.incomplete_details?.reason).toBe(reason);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('accepts incomplete details without a reason', () => {
|
|
130
|
+
const parsed = wsServerEventSchema.parse({
|
|
131
|
+
type: 'response.incomplete',
|
|
132
|
+
response: { id: 'resp_1', incomplete_details: {} },
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
expect(parsed.type).toBe('response.incomplete');
|
|
136
|
+
if (parsed.type !== 'response.incomplete') throw new Error('expected incomplete event');
|
|
137
|
+
expect(parsed.response.incomplete_details?.reason).toBeUndefined();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('closes the request channel after the terminal frame', async () => {
|
|
141
|
+
class RecordingSocket extends EventEmitter {
|
|
142
|
+
readyState = 1;
|
|
143
|
+
sent: string[] = [];
|
|
144
|
+
|
|
145
|
+
send(data: string): void {
|
|
146
|
+
this.sent.push(data);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
close(): void {}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const socket = new RecordingSocket();
|
|
153
|
+
const transport = new ResponsesWebSocket(socket as never);
|
|
154
|
+
const channel = transport.sendRequest({
|
|
155
|
+
type: 'response.create',
|
|
156
|
+
model: 'gpt-4.1',
|
|
157
|
+
input: [],
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
socket.emit('message', Buffer.from(JSON.stringify(responseIncomplete())));
|
|
161
|
+
const events = [];
|
|
162
|
+
for await (const event of channel.stream()) events.push(event);
|
|
163
|
+
|
|
164
|
+
expect(events).toEqual([responseIncomplete()]);
|
|
165
|
+
expect(socket.sent).toHaveLength(1);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
103
169
|
/** Replays the given frames, then dies the way a socket going quiet does. */
|
|
104
170
|
class StallingConnection {
|
|
105
171
|
attempts = 0;
|
|
@@ -173,6 +239,76 @@ describe('OpenAI Responses WS retry eligibility', () => {
|
|
|
173
239
|
});
|
|
174
240
|
});
|
|
175
241
|
|
|
242
|
+
describe('OpenAI Responses WS incomplete handling', () => {
|
|
243
|
+
it.each([
|
|
244
|
+
['max_output_tokens', 'max_output_tokens'],
|
|
245
|
+
[undefined, 'reason unavailable'],
|
|
246
|
+
] as const)(
|
|
247
|
+
'surfaces %s as non-retryable without updating context',
|
|
248
|
+
async (reason, expectedMessage) => {
|
|
249
|
+
class ReplayConnection {
|
|
250
|
+
attempts = 0;
|
|
251
|
+
payloads: WsResponseCreateEvent[] = [];
|
|
252
|
+
|
|
253
|
+
sendRequest(payload: WsResponseCreateEvent): stream.StreamChannel<WsServerEvent> {
|
|
254
|
+
this.attempts++;
|
|
255
|
+
this.payloads.push(payload);
|
|
256
|
+
const channel = stream.createStreamChannel<WsServerEvent>();
|
|
257
|
+
void (async () => {
|
|
258
|
+
await channel.write(RESPONSE_CREATED);
|
|
259
|
+
await channel.write(responseIncomplete(reason));
|
|
260
|
+
await channel.close();
|
|
261
|
+
})();
|
|
262
|
+
return channel;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
close(): void {}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const model = new WSLLM({ model: 'gpt-4.1', apiKey: 'test-key' });
|
|
269
|
+
const onCompleted = vi.spyOn(model, '_onResponseCompleted');
|
|
270
|
+
const errorEvent = new Promise<Error>((resolve) => {
|
|
271
|
+
model.once('error', (event) => resolve(event.error));
|
|
272
|
+
});
|
|
273
|
+
const conn = new ReplayConnection();
|
|
274
|
+
let connectCalls = 0;
|
|
275
|
+
const pool = new ConnectionPool<ResponsesWebSocket>({
|
|
276
|
+
connectCb: async () => {
|
|
277
|
+
connectCalls++;
|
|
278
|
+
return conn as unknown as ResponsesWebSocket;
|
|
279
|
+
},
|
|
280
|
+
});
|
|
281
|
+
const chatCtx = ChatContext.empty();
|
|
282
|
+
chatCtx.addMessage({ role: 'user', content: 'hi' });
|
|
283
|
+
const llmStream = new WSLLMStream(model, {
|
|
284
|
+
pool,
|
|
285
|
+
model: 'gpt-4.1',
|
|
286
|
+
chatCtx,
|
|
287
|
+
fullChatCtx: chatCtx,
|
|
288
|
+
connOptions: { maxRetry: 2, retryIntervalMs: 0, timeoutMs: 5000 },
|
|
289
|
+
modelOptions: {},
|
|
290
|
+
strictToolSchema: true,
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
for await (const _chunk of llmStream) void _chunk;
|
|
294
|
+
const error = await errorEvent;
|
|
295
|
+
|
|
296
|
+
expect(error).toBeInstanceOf(APIStatusError);
|
|
297
|
+
expect(error.message).toContain(expectedMessage);
|
|
298
|
+
expect((error as APIStatusError).statusCode).toBe(-1);
|
|
299
|
+
expect((error as APIStatusError).retryable).toBe(false);
|
|
300
|
+
expect(conn.attempts).toBe(1);
|
|
301
|
+
expect(onCompleted).not.toHaveBeenCalled();
|
|
302
|
+
|
|
303
|
+
await pool.withConnection(async (pooled) => expect(pooled).toBe(conn));
|
|
304
|
+
expect(connectCalls).toBe(1);
|
|
305
|
+
expect(conn.payloads[0]).not.toHaveProperty('previous_response_id');
|
|
306
|
+
await pool.close();
|
|
307
|
+
await model.aclose();
|
|
308
|
+
},
|
|
309
|
+
);
|
|
310
|
+
});
|
|
311
|
+
|
|
176
312
|
if (hasOpenAIApiKey) {
|
|
177
313
|
describe('OpenAI Responses WS wrapper', async () => {
|
|
178
314
|
await llm(
|