refactor(provider):拆分type和openai#185
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
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.
变更说明
将
internal/provider/types.go拆分为独立的internal/provider/types/子包,将internal/provider/openai/openai.go单文件按职责拆分为 8 个文件,同时修复 SSE 流消费中的多个 Bug。主要改动
1.
internal/provider/types/子包拆分message.goMessage、ToolCall、ToolSpec结构体及角色常量provider/types.gorequest.goChatRequest、Usage结构体provider/types.goevent.goStreamEvent及全部事件类型、载荷结构、构造函数、访问器provider/types.gotypes_test.goprovider/types_test.go(部分迁移)provider.go的Provider接口改为引用types.ChatRequest和types.StreamEvent。internal/provider/types.go和internal/provider/types_test.go删除。2.
internal/provider/openai/适配器拆分driver.goDriverName常量、Driver()驱动注册、defaultRetryTransport()provider.goProvider结构体、New()构造、Chat()入口、DiscoverModels()request.gobuildRequest()、toOpenAIMessage()、parseError()response.goconsumeStream()SSE 流消费主循环、extractStreamUsage()events.goemitTextDelta/ToolCallStart/ToolCallDelta/MessageDone、emitStreamEvent、flushDataLinestoolcall.gomergeToolCallDelta()工具调用增量合并discovery.gofetchModels()模型发现 HTTP 请求types.gointernal/provider/openai/openai.go删除。sse_reader.go和sse_reader_test.go保持不变。3. Bug 修复
flushDataLines拼接多 data 行产生无效 JSONprocessChunkTestConsumeStream_SSECommentIgnored、TestConsumeStream_MultiLineDataPayload、TestChat_BaseURLTrailingSlashHandleddata: [DONE]与前一行 JSON 拼接导致解码失败consumeStream中遇到[DONE]时立即刷新缓冲并标记结束TestConsumeStream_SSECommentIgnored、TestConsumeStream_FinishReasonAccumulation{"path":"main.go"+,"replace_string":"new"})TestMergeToolCallDelta_MultipleIndices、TestProviderChatConsumesSSEAndMergesToolCalls、TestProviderChatEmitsFullEventStreamTestBuildRequest_EmptyModelReturnsError无法触达 buildRequestNew()的 Validate 校验TestBuildRequest_EmptyModelReturnsErrorTestConsumeStream_FinishReasonAccumulation测试数据 finish_reason 位置错误TestConsumeStream_FinishReasonAccumulation预期收益
types子包按领域对象分组,openai子包按协议阶段分组,新增事件类型或协议字段时只需修改对应文件。Provider接口行为、流式事件协议、OpenAI API 兼容性完全不变,上游runtime/tui仅需调整 import 路径。