Skip to content

refactor: move the xAI files to the upstream layout - #313

Merged
eric8810 merged 14 commits into
masterfrom
refactor/move-the-xai-files-to-the-upstream-layout
Oct 27, 2026
Merged

eric8810 merged 14 commits into
masterfrom
refactor/move-the-xai-files-to-the-upstream-layout

Conversation

@cunninghamcard-bit

@cunninghamcard-bit cunninghamcard-bit commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

把 xAI 的源文件按 @ai-sdk/xai@5.0.12 一个文件对一个文件拆开(RFC-0046 §4.2),老的四个 tests/xai_*_test.rs 并进厂商测试目录 src/xai/tests/(RFC-0046 §5 的新布局)。只搬不改:函数体只改了模块路径,测试数量、模块路径和函数名前后一致。叠在测试 PR #312 上。

已经测试分支 bf71fda9 合上 master b69137eb,冲突按 master 的改动搬到新位置解决(responses/convert.rs 的四处改动落到 responses/{responses_language_model_options, responses_prepare_tools, convert_to_responses_input}.rs,JSON 解析错误的 cause 落到 error.rs,老测试里四处错误模式改成结构体变体);测试数前后仍相等(xAI 338 个,测试分支 lib 262 个加老测试程序 76 个,名字多重集相同)。

一、体系现状(概览,测试 PR #312 头 8c30faea)

aimux_providers::create_xai                          src/xai/mod.rs:319
 └ XAIProvider::language_model → responses           src/xai/mod.rs:429 → :385
   └ XaiResponsesModel::do_generate                  src/xai/responses/mod.rs:216
     └ build_responses_request_body                  src/xai/responses/convert.rs:717
       ├ validate_response_options                   src/xai/responses/convert.rs:312
       ├ convert_to_xai_responses_input              src/xai/responses/convert.rs:425
       ├ prepare_responses_tools                     src/xai/responses/convert.rs:99
       └ supports_reasoning_effort                   src/xai/convert.rs:37
     └ post_json_to_api(xai_failed_response_handler) src/xai/mod.rs:53
     └ convert_xai_responses_usage / map_xai_responses_finish_reason
                                                     src/xai/responses/convert.rs:43 / :30
     └ resolve_tool_name                             src/xai/responses/convert.rs:941
   └ do_stream → XaiResponsesStream, xai_stream_error
                                                     src/xai/responses/mod.rs:506 / :560, src/xai/mod.rs:83
 └ speech / transcription / video                    src/xai/speech.rs:148, transcription.rs:125, video.rs:686

上游同一条路:createXai(xai-provider.ts)→ XaiResponsesLanguageModel.doGenerate(responses/xai-responses-language-model.ts)→ convertToXaiResponsesInput、prepareResponsesTools、convertXaiResponsesUsage、mapXaiResponsesFinishReason、supportsReasoningEffort 各在自己的文件,错误处理在 xai-error.ts。aimux 把工厂、错误处理和 index.ts 放在一个 470 行的 mod.rs 里,5 个上游 responses 文件放在一个 1,013 行的 responses/convert.rs 里。

测试:#312 的新用例在 src/xai/tests/,老用例还在四个独立测试程序里(xai_speech_test 17 个、xai_transcription_test 20 个、xai_video_test 34 个、xai_upstream_e2e_test 5 个)。

二、本 PR 改动(细节)

aimux_providers::create_xai                          src/xai/provider.rs:76                     ← xai-provider.ts
 └ XAIProvider::language_model → responses           src/xai/provider.rs:186 → :142
   └ XaiResponsesModel::do_generate                  src/xai/responses/responses_language_model.rs:219
     └ build_responses_request_body                  src/xai/responses/responses_language_model.rs:1240
       ├ validate_response_options                   src/xai/responses/responses_language_model_options.rs:35
       ├ convert_to_xai_responses_input              src/xai/responses/convert_to_responses_input.rs:24
       ├ prepare_responses_tools                     src/xai/responses/responses_prepare_tools.rs:22
       └ supports_reasoning_effort                   src/xai/supports_reasoning_effort.rs:23
     └ post_json_to_api(xai_failed_response_handler) src/xai/error.rs:9                         ← xai-error.ts
     └ convert_xai_responses_usage                   src/xai/responses/convert_responses_usage.rs:6
     └ map_xai_responses_finish_reason               src/xai/responses/map_responses_finish_reason.rs:6
     └ resolve_tool_name                             src/xai/responses/responses_language_model.rs:1464
   └ do_stream → XaiResponsesStream, xai_stream_error
                                                     src/xai/responses/responses_language_model.rs:509 / :563, src/xai/error.rs:39
 └ speech / transcription / video                    src/xai/speech_model.rs:148, transcription_model.rs:125, video_model.rs:686
现在 搬到 上游
mod.rs 模块文档、导出 xai/mod.rs(只有模块声明和 pub use) index.ts
mod.rs 设置、工厂、默认实例、XAIProvider xai/provider.rs xai-provider.ts
mod.rs 四个响应/错误处理器 xai/error.rs xai-error.ts
convert.rs xai/supports_reasoning_effort.rs supports-reasoning-effort.ts
speech.rs、transcription.rs、video.rs speech_model.rs、transcription_model.rs、video_model.rs xai-*-model.ts(选项解析在模型文件里,*-model-options.ts 也指向它)
responses/mod.rs 模型和流;responses/convert.rs 请求体、工具名帮手 responses/responses_language_model.rs xai-responses-language-model.ts(get-response-metadata.ts 内联在里面)
responses/convert.rs 输入转换、convert.rs 的 provider reference 和媒体类型帮手 responses/convert_to_responses_input.rs convert-to-xai-responses-input.ts、xai-file-part-options.ts
responses/convert.rs 工具准备、provider tool 参数校验 responses/responses_prepare_tools.rs xai-responses-prepare-tools.ts
responses/convert.rs providerOptions.xai 校验 responses/responses_language_model_options.rs xai-responses-language-model-options.ts
responses/convert.rs 用量、finish reason responses/convert_responses_usage.rs、responses/map_responses_finish_reason.rs 同名两个文件
responses/types.rs responses/responses_api.rs xai-responses-api.ts
  • 公开路径:原 xai::responses::convert::*、xai::responses::types::* 的公开项由 responses/mod.rs 再导出为 xai::responses::*;xai::convert::supports_reasoning_effort 变成 xai::supports_reasoning_effort。crate 外没有用这些路径的地方。
  • 跨文件调用的四个私有函数改成 pub(super)(xai_option、validate_value、string_array、validate_response_options);super::xai_*_handler 改成 crate::xai::error:: / super::error::,模型里用 use super::responses_api as types; 保持 types:: 不变,函数体不动。options.rs 不动(包内的选项帮手,命名空间键只写在这里),边界脚本不用改。
  • 测试:四个老测试按 describe 并进同名文件:xai_speech_test → tests/speech_model.rs,xai_transcription_test → tests/transcription_model.rs,xai_video_test → tests/video_model.rs,xai_upstream_e2e_test → tests/responses/responses_language_model.rs。老 wiremock 帮手放在各文件的「wiremock harness」一节,和 test: port the upstream xAI tests #312 帮手同名的改加 wiremock_ 前缀(speech_model、xai_options、default_body、stream_options、start、completed),内容相同的直接去重(AUDIO 和视频的 7 个常量/帮手);aimux_providers:: 改成 crate::。
  • layout.toml 的 rust 字段改到新路径;openai/responses/responses_convert.rs 一处指向旧文件的注释改到新文件。

CHANGELOG

CHANGELOG Unreleased 的 Breaking 加了一条,列出本家变了的公开子模块路径和替代入口(RFC-0046 §4.5 第 2 条)。

验证

  • cargo test -p aimux-providers --lib 加原四个 --test xai_*:前后都是 338 个测试(262 + 76),模块路径(去掉文件前缀后)和函数名完全相同;xAI 的 338 个全过。
  • 非测试源码逐行比对:去掉 use 和注释后,只有可见性和模块路径的差别。
  • cargo +1.99 clippy -p aimux-providers --lib --tests -- -D warnings、cargo doc -D warnings、cargo fmt --check、scripts/check_provider_boundaries.sh 通过。

Type of change

  • Refactor (no behavior change)

Checklist

  • Tests pass locally
  • Commit messages follow Conventional Commits

共享进程状态:测试原来各自是单独的测试程序,现在并进 lib 的同一个测试程序。9 个测试带 #[serial];SOURCE_ID_COUNTER(xai/responses/responses_language_model.rs:47)只有 xAI 用,搬进来后不和别家共享;没有固定临时路径(RFC-0046 §5)。


Generated by Claude Code

One Rust file per @ai-sdk/xai source file (RFC-0046 §4.2): mod.rs keeps
only the module list (index.ts), with the provider in provider.rs and the
error and response handlers in error.rs; convert.rs becomes
supports_reasoning_effort.rs; speech, transcription and video become
*_model.rs. responses/mod.rs becomes responses_language_model.rs (with
the request body and tool-name helpers), types.rs becomes responses_api.rs,
and responses/convert.rs splits into convert_to_responses_input.rs,
convert_responses_usage.rs, map_responses_finish_reason.rs,
responses_prepare_tools.rs and responses_language_model_options.rs.

The four tests/xai_*_test.rs binaries join their files in
src/xai/tests/. Move only: the test count (338) and the test names are
unchanged; function bodies change only in module paths.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
RFC-0046 §4.5 item 2: the vendor move PR lists the old public sub-module
paths and the replacement entry under Unreleased > Breaking.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
@cunninghamcard-bit
cunninghamcard-bit marked this pull request as ready for review October 24, 2026 11:29

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xAI layout refactor:test multiset 338→338,80/80 functions 归一化后一致;公开路径删除已在 CHANGELOG 登记。Approve。

claude added 11 commits October 25, 2026 08:43
The new xai_transcription_test.rs case (dropping an unpolled stream closes
the socket) moves into src/xai/tests/transcription_model.rs with the other
transcription cases; its stream_options helper is wiremock_stream_options
there.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…' into refactor/move-the-xai-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…' into refactor/move-the-xai-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…' into refactor/move-the-xai-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…' into refactor/move-the-xai-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…' into refactor/move-the-xai-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…' into refactor/move-the-xai-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…' into refactor/move-the-xai-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…' into refactor/move-the-xai-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…' into refactor/move-the-xai-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
@eric8810
eric8810 changed the base branch from test/port-the-upstream-xai-tests to master October 27, 2026 16:33
@eric8810
eric8810 merged commit c165778 into master Oct 27, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants