Patch Changes
-
225154e: fix(cohere): tolerate partial citations and usage in non-streaming responses
Cohere citations and usage fields are optional in the API specification, but the
response schema requiredstart,end,text, every sourcedocumentwith
textandtitle, and usage token counts. Responses with untitled documents
(documents passed without a filename), with tool-sourced citations, or without
token counts failed with anAI_TypeValidationErrorand discarded the whole
response.These fields are now validated loosely: citation fields and source
type/id
are nullish,documentis a loose object with optionalid/text/title, tool
sources are accepted, andusageplus its token counts are nullish. Document
citations without a title fall back to"Document". Tool-only citations are
skipped because they have no document to point at; their data stays in the
response body.convertCohereUsageno longer falls back tobilled_units, which are a
different measure thantokens(e.g. 12 billed vs 507 input tokens in a single
response) and would go negative when cached tokens are subtracted. A response
withouttokensnow reports undefined token counts instead of unrelated
numbers. This usage conversion is shared with streaming. -
024df7d: fix(cohere): read the response id from v2 chat responses
The non-streaming response schema read
generation_id, which Cohere's v2 chat
response does not return. As a result,generateText().response.idwas a locally
generated fallback instead of the provider's id, whilestreamTextreturned the
id from themessage-startevent.doGeneratenow readsidand keeps
generation_id(the v1 field) only for compatibility with proxies and mocks that
still return it. -
225154e: fix(cohere): emit
sourcestream parts for citationsstreamTextdid not produce sources for Cohere RAG responses becausecitation-startstream events were ignored, whilegenerateTextmappedmessage.citationsto document sources. Streaming now maps each cited document to the samesourcepart as the non-streaming path. Citations that only reference tool output are not emitted as sources, andcitation-startevents without citations are ignored.