openai-node
openai-node copied to clipboard
fix(responses): correct error message in finalResponse and safely accumulate string deltas
- [x] I understand that this repository is auto-generated and my pull request may not be merged
Changes being requested
- Fix error message thrown by
ResponseStream.finalResponse()when a stream ends prematurely without producing a response (stream ended without producing a Responseinstead ofstream ended without producing a ChatCompletion). - Fix typo in
ResponseStream.finalResponse()docstring (REsponse->Response). - Safely handle nullish initial values when accumulating string deltas in
ResponseAccumulator.tsacrossoutput_text,refusal,function_call_arguments,reasoning_text,reasoning_summary_text,custom_tool_call_input, andmcp_call_argumentsevents using(target ?? '') + event.delta. - Add unit tests for
finalResponse()error message andResponseAccumulatorstring delta accumulation.
Additional context & links
Problem
ResponseStreambelongs to the Responses API. WhenfinalResponse()is called on a stream that ended prematurely without producing aResponse, it previously threwOpenAIError('stream ended without producing a ChatCompletion').- When stream delta events (
response.function_call_arguments.delta,response.refusal.delta, etc.) arrive on uninitialized string properties,+= event.deltaresulted in"undefined"prefixing the delta content.
Root cause
- Copy-paste typo from
ChatCompletionStream.tsinResponseStream.ts. - Missing nullish fallback
(str ?? '')on string property delta accumulation inResponseAccumulator.ts.
Verification
pnpm test tests/lib/ResponseStream.test.ts(Pass)pnpm build(Pass)pnpm lint(Pass)