Fix/sparse stream block index#46
Merged
CrazyBoyM merged 2 commits intoshareAI-lab:mainfrom Mar 29, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
修复
Agent.runStep()对稀疏 streamed block index 的处理问题,并将OpenAIProvider.stream()的 block index 规范化为连续且互不冲突的本地索引。Motivation / Context
Agent.runStep()会直接按chunk.index写入assistantBlocks[chunk.index]。当 provider 输出稀疏 index 时,会生成稀疏数组,后续传入splitThinkBlocksIfNeeded()时可能触发:TypeError: Cannot read properties of undefined (reading 'type')本 PR 一方面在core层修复该运行时问题,另一方面同步修正OpenAIProvider.stream()当前已知的稀疏 / 冲突 index 行为。Type of Change
Scope / Modules
Public API
src/index.tsBreaking Changes
Testing
npm run test:unit(required)npm run test:integration(if needed)npm run test:e2e(if needed)Impact / Risk
风险较低。
本次行为调整包括:
Agent在 streamed assistant blocks 进入后处理前,先压缩为稠密数组。splitThinkBlocksIfNeeded()增加对空值的防御处理。OpenAIProvider.stream()改为对 text、reasoning、tool_use 分配本地连续索引,避免稀疏数组和 index 冲突。
兼容性说明:
Checklist
tests/README.mdstructuredocs/en+docs/zh-CNformat rulesdist/changes (unless release)