-
Notifications
You must be signed in to change notification settings - Fork 540
Open
Description
Describe the bug
I'm trying to handle streamed events in my project, but the rawItem field is always coming through as unknown, even when I type it explicitly.
import type { RunToolCallItem } from '@openai/agents-core';
import type { ToolCallItem } from '@openai/agents-core/types';
const result: ReadableStream<RunStreamEvent>;
for await (const event of result) {
if (event.type === 'run_item_stream_event') {
if (event.name === 'tool_called' && event.item.type === 'tool_call_item') {
const item = event.item as RunToolCallItem;
// item.rawItem is "unknown" here, though it should be "protocol.ToolCallItem"
const rawItem = event.item.rawItem as ToolCallItem;
// rawItem is "unknown" here, despite casting it to "ToolCallItem"
}
}
}I think this is happening due to duplicate exports in protocol.ts - one for the Zod schema, and one for the type inferred from the Zod schema:
export const ToolCallItem = z.discriminatedUnion('type', [
ComputerUseCallItem,
ShellCallItem,
ApplyPatchCallItem,
FunctionCallItem,
HostedToolCallItem,
]);
export type ToolCallItem = z.infer<typeof ToolCallItem>;
Debug information
- Agents SDK version: (e.g.
v0.3.4) - Runtime environment (e.g.
Node.js 22.19.0)
Repro steps
See above.
Expected behavior
Either event.item and event.rawItem are typed correctly automatically through type inference, or using an explicit type should not come through as unknown.