From 980448167334ab380e291f421095ed6b9f939c11 Mon Sep 17 00:00:00 2001 From: Aiden Cline Date: Wed, 2 Sep 2026 20:33:42 -0500 Subject: [PATCH] chore(ai): clean up responses item id comments --- packages/ai/src/protocols/open-responses.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/ai/src/protocols/open-responses.ts b/packages/ai/src/protocols/open-responses.ts index 8a17f703513e..d0499c49dd23 100644 --- a/packages/ai/src/protocols/open-responses.ts +++ b/packages/ai/src/protocols/open-responses.ts @@ -934,15 +934,15 @@ const ITEM_ID_PREFIX: Readonly> = { compaction: "cmp", } -// Mirror Codex: an item that arrives without an id adopts the id of the item -// already open in its output slot, otherwise it gets a locally minted one. -const hasID = (item: StreamItem): item is OutputItem => item.id !== undefined - -const resolveItem = (state: ParserState, item: StreamItem, index: number | undefined): OutputItem => { - if (hasID(item)) return item - const slot = index === undefined ? undefined : state.outputItems[index] - return { ...item, id: slot ?? `${ITEM_ID_PREFIX[item.type] ?? "item"}_${crypto.randomUUID().replaceAll("-", "")}` } -} +// An item without an id adopts the id already open in its output slot, +// otherwise it gets a locally minted one. +const resolveItem = (state: ParserState, item: StreamItem, index: number | undefined): OutputItem => ({ + ...item, + id: + item.id ?? + (index === undefined ? undefined : state.outputItems[index]) ?? + `${ITEM_ID_PREFIX[item.type] ?? "item"}_${crypto.randomUUID().replaceAll("-", "")}`, +}) // Registered output slots are authoritative for `item_id` routing, and items // are resolved here so everything downstream can rely on `item.id`.