Skip to content

Unable to type events, potentially due to duplicate exports #739

@jonjomckay

Description

@jonjomckay

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions