fix(responses): safely initialize reasoning summary array during event accumulation
- [x] I understand that this repository is auto-generated and my pull request may not be merged
Changes being requested
Problem
When processing streaming events in accumulateResponse, accumulating reasoning summary events (response.reasoning_summary_part.added, response.reasoning_summary_part.done, response.reasoning_summary_text.delta, and response.reasoning_summary_text.done) on reasoning output items where summary was omitted or uninitialized (e.g. when an output item of type reasoning is added without a pre-initialized summary array) causes an uncaught JavaScript runtime error: TypeError: Cannot read properties of undefined (reading 'push') or TypeError: Cannot read properties of undefined (reading '0').
Root Cause
ResponseAccumulator.tsattempted to calloutput.summary.push(...)inresponse.reasoning_summary_part.addedwithout checking ifoutput.summarywas defined, unlikeresponse.content_part.addedwhich explicitly initializesoutput.content = []when nullish.response.reasoning_summary_part.done,response.reasoning_summary_text.delta, andresponse.reasoning_summary_text.donepassedoutput.summarydirectly togetContent(output.summary, event.summary_index). Whenoutput.summarywas undefined,getContentaccessedcontent[contentIndex], throwing an unhandledTypeError.
Solution
- Added nullish array initialization (
if (!output.summary) output.summary = [];) toresponse.reasoning_summary_part.added,response.reasoning_summary_part.done,response.reasoning_summary_text.delta, andresponse.reasoning_summary_text.doneinsrc/lib/responses/ResponseAccumulator.ts. - Updated
getContentto check for nullishcontentarrays and throw a clearOpenAIErrorinstead of throwing a raw JavaScriptTypeError.
Regression Coverage
Added a unit test in tests/lib/ResponseAccumulator.test.ts ('handles reasoning summary events on output items with uninitialized summary') verifying that reasoning output items with uninitialized summary arrays safely accumulate summary_text parts and deltas.
Validation
npx jest tests/lib/ResponseAccumulator.test.ts(Passed 8/8)npx jest tests/lib(Passed 16/16 test suites, 400/400 tests)pnpm build(Passed with zero errors)pnpm lint(Passed formatting, ESLint, and TypeScript type checks)git diff --check(Passed cleanly)
Generated Code Impact
None. Changes are strictly confined to manually maintained files under src/lib/responses/ and tests/lib/.