feat(providers): 引入 LLM seam 骨架——统一入口 llm.stream() 与协议适配器注册表 - #594
Open
AlphaCatMeow wants to merge 2 commits into
Open
feat(providers): 引入 LLM seam 骨架——统一入口 llm.stream() 与协议适配器注册表#594AlphaCatMeow wants to merge 2 commits into
AlphaCatMeow wants to merge 2 commits into
Conversation
为 LLM seam 改造提供行为等价判定基准: - wire-payload-golden:anthropic-messages / openai-completions / openai-responses / google-generative-ai / deepseek-responses 五协议 固定输入下的完整请求体逐字段锁定(thinking 档位、工具、缓存断点、 text-only 双形态),走真实 pi-ai stream() 与全部 payload 中间件, onPayload 链尾截获后中断,零网络。 - transport-golden:prepareProviderRequest 完整输出快照(反代 URL、 全量头集、base64 覆盖包解码断言、鉴权头排除、full URL 模式、 useSystemProxy 开关),并锁定 failover 逐候选传输配置独立性 (主选走代理+备选直连互不泄漏,双向拓扑)。 零生产代码改动。
将 streamByApi.ts 的五协议 switch 原样搬移为 service/ 下的双适配器 (piAiAdapter 承接 4 条 pi-ai 协议,deepSeekAdapter 承接 deepseek 原生), 经 api→adapter 注册表分发;新增统一流式入口 llm.stream(),携带仅 dev 构建生效的请求信封冻结与一次性分发不变量。streamByApi.ts 收缩为保留 原签名的兼容壳(分发针孔),agentRunner 与 textOnlyRuntime 共 5 处调用 换用统一入口。行为严格等价:PR-0 两个 golden 套件(13 用例)零修改 通过;新增 seam 单测 8 用例覆盖注册表分发、错误文案逐字等价、dev 冻结开关与双入口 wire payload 等价。零 Rust 改动、零镜像文件改动。
StackCairn
marked this pull request as draft
August 22, 2026 08:06
Contributor
|
PR governance checks passed. Awaiting human review. |
AlphaCatMeow
marked this pull request as ready for review
August 22, 2026 08:18
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.
Closes #593
改动说明
在 PR-0 golden 基线(#590)保护下引入 LLM seam 骨架,行为严格等价:
crates/agent-gui/src/lib/providers/service/types.ts:LlmAdapter接口(必需stream();resolveModel()/retryPolicy()为后续 PR 预留的可选签名)与LlmStreamRequest请求信封registry.ts:api→adapter 注册表;未注册协议错误文案与重构前逐字一致(Unsupported model API: ...)piAiAdapter.ts:原样搬移 streamByApi.ts 的 anthropic-messages / openai-completions / openai-responses / google-generative-ai 四分支(含各分支 withStreamRetry 包装位置、toolChoice 映射、thinking runtime 解析与注释)deepSeekAdapter.ts:原样搬移 deepseek-responses 分支llmService.ts:统一入口llm.stream(request)——一次性分发(同一信封重复分发抛错)+ 仅 dev 构建生效的请求信封冻结(生产零开销)streamByApi.ts收缩为兼容壳:保留streamSimpleByApi原签名,内部走注册表路由;该模块同时是 seam 的公开可观测针孔(传输 golden 与 failover 测试按此路径 mock 截获全部出站流)llm.stream(),参数三元组不变;failover 逐候选传输独立与 buffer-until-commit 语义逐行保持x-liveagent-*头、useSystemProxy 派生头)对 seam 不透明透传:不读取、不判断、不缓存零 Rust 改动(diff 不含
src-tauri/**)、零镜像文件改动、无依赖变更。验证结果
test/providers/llm-service-seam.test.mjs8 用例:注册表五协议分发、未知协议错误文案逐字等价、重复注册抛错、一次性分发、dev 冻结/生产不冻结/自动探测降级、兼容壳与llm.stream()双入口 wire payload 等价(openai-completions 与 deepseek 原生各一)pnpm --dir crates/agent-gui buildpnpm --dir crates/agent-gui test:frontend(268 个测试文件,exit 0)git diff --checknode scripts/check-ui-boundaries.mjs报 3 个文件(agent-gui settings/index.ts、gateway web settings/index.ts、gateway web uiMessages.ts)——已核验三者内容与 upstream/main 完全一致且不在本 PR 改动集,属既有基线问题pnpm lint在 Windows checkout 上有 310+ 既有 CRLF/格式错误(基线问题,与本改动无关)未运行项
人工验收
已在 Windows Tauri 调试客户端(本分支 HEAD 构建)人工验证通过:带工具多轮对话、会话标题生成、手动压缩、断网重试提示、failover 切换。
Screenshots / preview
Stack
Depends-On: #590
Stack-Root: #590