@livekit/agents-plugin-openai 1.4.5 → 1.4.6
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 +18 -5
- 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 +18 -5
- 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/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 +24 -5
- package/src/responses/llm.ts +13 -0
- package/src/ws/llm.ts +9 -0
- package/src/ws/types.ts +1 -1
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":"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","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.6",
|
|
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.6",
|
|
34
|
+
"@livekit/agents-plugin-silero": "1.4.6",
|
|
35
|
+
"@livekit/agents-plugins-test": "1.4.6"
|
|
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.6"
|
|
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',
|
|
@@ -1836,7 +1846,10 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
1836
1846
|
|
|
1837
1847
|
const statusDetails = event.response.status_details;
|
|
1838
1848
|
if (event.response.status === 'failed') {
|
|
1839
|
-
const errorBody =
|
|
1849
|
+
const errorBody =
|
|
1850
|
+
typeof statusDetails !== 'string' && statusDetails?.type === 'failed'
|
|
1851
|
+
? statusDetails.error
|
|
1852
|
+
: undefined;
|
|
1840
1853
|
const errorTypeValue = errorBody && 'type' in errorBody ? errorBody.type : undefined;
|
|
1841
1854
|
const errorType = typeof errorTypeValue === 'string' ? errorTypeValue : 'unknown';
|
|
1842
1855
|
|
|
@@ -1848,9 +1861,15 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
1848
1861
|
recoverable: true,
|
|
1849
1862
|
});
|
|
1850
1863
|
} else if (event.response.status === 'cancelled' || event.response.status === 'incomplete') {
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1864
|
+
let statusType: string | undefined;
|
|
1865
|
+
let statusReason: string | undefined;
|
|
1866
|
+
if (typeof statusDetails === 'string') {
|
|
1867
|
+
statusType = statusDetails;
|
|
1868
|
+
} else {
|
|
1869
|
+
statusType = statusDetails?.type;
|
|
1870
|
+
statusReason =
|
|
1871
|
+
statusDetails && 'reason' in statusDetails ? statusDetails.reason : undefined;
|
|
1872
|
+
}
|
|
1854
1873
|
|
|
1855
1874
|
this.#logger.debug(
|
|
1856
1875
|
{
|
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/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(),
|