Skip to content

feat(provider): move into sub crate#90

Merged
bzp2010 merged 1 commit intomainfrom
bzp/feat-split-llm-crate
May 5, 2026
Merged

feat(provider): move into sub crate#90
bzp2010 merged 1 commit intomainfrom
bzp/feat-split-llm-crate

Conversation

@bzp2010
Copy link
Copy Markdown
Collaborator

@bzp2010 bzp2010 commented May 5, 2026

Summary by CodeRabbit

  • Chores
    • Reorganized workspace dependencies to centralize version management across multiple crates.
    • Extracted gateway functionality into a separate workspace crate for improved modularity.
    • Restructured internal module organization and updated module path references throughout the codebase.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

📝 Walkthrough

Walkthrough

This PR restructures the gateway code into a separate workspace crate (aisix-llm) by establishing a Cargo workspace with centralized dependencies, creating the new crate with re-exported modules, and updating all internal imports to reflect the new module paths while maintaining backward compatibility through re-exports in the main crate.

Changes

Gateway Modularization & Workspace Setup

Layer / File(s) Summary
Workspace & Crate Manifest
Cargo.toml, crates/aisix-llm/Cargo.toml
Root Cargo.toml now defines [workspace], [workspace.package], and [workspace.dependencies] with centralized versions for common crates (tokio, reqwest, axum, serde*, AWS SDK, etc.). New crates/aisix-llm/Cargo.toml created as workspace member, wiring version/edition/rust-version from workspace and declaring all dependencies as workspace = true.
New Crate Public API
crates/aisix-llm/src/lib.rs
Declares public modules (error, formats, provider_instance, providers, session, streams, traits, types) using #[path = ...] attributes pointing to gateway/* source files. Re-exports Gateway type from internal gateway_impl module.
Gateway Module Reorganization
src/gateway/mod.rs, src/lib.rs
src/gateway/mod.rs removes all public submodule exports and the Gateway re-export. src/lib.rs replaces private mod gateway; with public pub mod gateway { pub use aisix_llm::*; } to maintain external API compatibility while sourcing implementations from the new crate.
Import Path Updates (Core Modules)
crates/aisix-llm/src/gateway/*.rs, crates/aisix-llm/src/gateway/formats/*.rs, crates/aisix-llm/src/gateway/traits/*.rs, crates/aisix-llm/src/gateway/types/*.rs
Updated all module-level imports from crate::gateway::{...} to crate::{...} or crate::{ ... } across ~50+ files (gateway.rs, provider_instance.rs, session.rs, response.rs, chat_format.rs, native.rs, provider.rs, and all format/stream modules). These changes reflect the new crate-root module organization.
Import Path Updates (Providers & Macros)
crates/aisix-llm/src/gateway/providers/*.rs, crates/aisix-llm/src/gateway/providers/*/mod.rs, crates/aisix-llm/src/gateway/providers/*/transform.rs, crates/aisix-llm/src/gateway/providers/macros.rs
Updated imports in ~20 provider implementations (anthropic, azure, bedrock, cohere, deepseek, fireworks, gemini, groq, mistral, modelscope, moonshot, openai, openrouter, siliconflow, stepfun, xai, zhipuai) to use crate::{...} instead of crate::gateway::{...}. Updated provider! macro expansion targets from $crate::gateway::traits::* to $crate::traits::*, adjusting generated trait implementations and method signatures.
Test & Error Reference Updates
crates/aisix-llm/src/gateway/**/*.rs (test modules)
Updated all test module imports and assert_matches! patterns in ~25+ files to use crate::types::..., crate::error::..., and crate::traits::... instead of crate::gateway::... equivalents (e.g., GatewayError, ChatStreamState, type annotations for OpenAI/Anthropic/Bedrock messages).

Sequence Diagram(s)

No sequence diagrams generated — the changes are primarily a module restructuring and import path refactoring without introducing new runtime interactions or control flow patterns.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • api7/aisix#19: Main PR adapts widespread use of crate::providers::macros::provider and provider module paths to locations introduced in this PR.
  • api7/aisix#14: Main PR's import/path changes and lib.rs reshaping align with the gateway module/type organization established in that PR.
  • api7/aisix#18: Both PRs modify gateway/formats module surface and re-export structure.

Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 1 warning)

Check name Status Explanation Resolution
Security Check ❌ Error AwsStaticCredentials in crates/aisix-llm/src/gateway/provider_instance.rs (lines 12-17) derives Debug without redacting secrets. Direct logging would expose AWS credentials. Implement custom Debug impl for AwsStaticCredentials that redacts secret fields. Remove Debug from derive, add impl fmt::Debug with redaction pattern like BedrockProviderConfig.
E2e Test Quality Review ⚠️ Warning PR lacks E2E tests. Only unit tests with import path updates exist; no new E2E tests validating the full business flow after moving gateway logic into the aisix-llm subcrate. Add E2E tests covering: (1) Full API → Gateway → Provider flow post-refactor; (2) Major provider types working end-to-end; (3) Re-export compatibility in main crate; (4) Error scenarios (auth, network); (5) Concurrent requests.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately summarizes the main objective: moving the provider logic into a separate sub-crate (aisix-llm), which is evidenced by the creation of crates/aisix-llm/ and reorganization of module exports.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bzp/feat-split-llm-crate

Comment @coderabbitai help to get the list of available commands and usage tips.

@bzp2010 bzp2010 marked this pull request as ready for review May 5, 2026 05:02
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/aisix-llm/src/gateway/providers/siliconflow.rs (1)

21-29: ⚠️ Potential issue | 🔴 Critical

Fix broken import paths: modules are in crate::gateway::*, not at crate root.

The import statements reference modules at the crate root (crate::error, crate::provider_instance, crate::traits, crate::types), but these modules still reside in the gateway subdirectory. Update all imports to use crate::gateway::* instead, or move the modules to the crate root if that was the intended restructuring.

Current broken paths:

crate::error::{GatewayError, Result}
crate::provider_instance::ProviderAuth
crate::traits::{ChatTransform, EmbedTransform, ProviderCapabilities, ProviderMeta}
crate::types::{...}

Actual locations:

crate::gateway::error
crate::gateway::provider_instance
crate::gateway::traits (location needs verification)
crate::gateway::types (location needs verification)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/aisix-llm/src/gateway/providers/siliconflow.rs` around lines 21 - 29,
Update the broken imports in siliconflow.rs to point to the gateway module:
replace references to crate::error::{GatewayError, Result},
crate::provider_instance::ProviderAuth, crate::traits::{ChatTransform,
EmbedTransform, ProviderCapabilities, ProviderMeta}, and
crate::types::{embed::{EmbedRequestBody, EmbeddingRequest},
openai::ChatCompletionRequest} with their correct paths under crate::gateway
(e.g. crate::gateway::error::GatewayError/Result,
crate::gateway::provider_instance::ProviderAuth,
crate::gateway::traits::ChatTransform/EmbedTransform/ProviderCapabilities/ProviderMeta,
and crate::gateway::types::embed::EmbedRequestBody/EmbeddingRequest and
crate::gateway::types::openai::ChatCompletionRequest) so the compiler can
resolve the symbols.
🧹 Nitpick comments (1)
crates/aisix-llm/src/lib.rs (1)

1-21: ⚡ Quick win

Add /// docs for crate-root public exports.

The crate’s public modules and Gateway re-export are undocumented in this new public surface.

💡 Proposed patch
+/// Error types and result aliases for gateway operations.
 #[path = "gateway/error.rs"]
 pub mod error;
+/// Format adapters and bridge implementations.
 #[path = "gateway/formats/mod.rs"]
 pub mod formats;
+/// Provider authentication and instance configuration types.
 #[path = "gateway/provider_instance.rs"]
 pub mod provider_instance;
+/// Built-in provider implementations.
 #[path = "gateway/providers/mod.rs"]
 pub mod providers;
+/// Session lifecycle and request-scoped context.
 #[path = "gateway/session.rs"]
 pub mod session;
+/// Streaming readers and stream utilities.
 #[path = "gateway/streams/mod.rs"]
 pub mod streams;
+/// Core gateway traits and contracts.
 #[path = "gateway/traits/mod.rs"]
 pub mod traits;
+/// Shared request/response model types.
 #[path = "gateway/types/mod.rs"]
 pub mod types;
 
 #[path = "gateway/gateway.rs"]
 mod gateway_impl;
 
+/// Main gateway entry point.
 pub use gateway_impl::Gateway;

As per coding guidelines, "Use /// for doc comments on public items in Rust".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/aisix-llm/src/lib.rs` around lines 1 - 21, Add triple-slash
documentation comments for each public module export and the public re-export to
document the crate root: add concise /// doc comments above pub mod error, pub
mod formats, pub mod provider_instance, pub mod providers, pub mod session, pub
mod streams, pub mod traits, pub mod types and above pub use
gateway_impl::Gateway describing the module’s purpose and intended public API
surface (one-line summary plus optional short example or pointer to more docs),
keeping comments idiomatic Rust doc style and brief.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@crates/aisix-llm/src/gateway/providers/siliconflow.rs`:
- Around line 21-29: Update the broken imports in siliconflow.rs to point to the
gateway module: replace references to crate::error::{GatewayError, Result},
crate::provider_instance::ProviderAuth, crate::traits::{ChatTransform,
EmbedTransform, ProviderCapabilities, ProviderMeta}, and
crate::types::{embed::{EmbedRequestBody, EmbeddingRequest},
openai::ChatCompletionRequest} with their correct paths under crate::gateway
(e.g. crate::gateway::error::GatewayError/Result,
crate::gateway::provider_instance::ProviderAuth,
crate::gateway::traits::ChatTransform/EmbedTransform/ProviderCapabilities/ProviderMeta,
and crate::gateway::types::embed::EmbedRequestBody/EmbeddingRequest and
crate::gateway::types::openai::ChatCompletionRequest) so the compiler can
resolve the symbols.

---

Nitpick comments:
In `@crates/aisix-llm/src/lib.rs`:
- Around line 1-21: Add triple-slash documentation comments for each public
module export and the public re-export to document the crate root: add concise
/// doc comments above pub mod error, pub mod formats, pub mod
provider_instance, pub mod providers, pub mod session, pub mod streams, pub mod
traits, pub mod types and above pub use gateway_impl::Gateway describing the
module’s purpose and intended public API surface (one-line summary plus optional
short example or pointer to more docs), keeping comments idiomatic Rust doc
style and brief.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6741a596-d2f6-4638-9ccb-35ae4a09c2ef

📥 Commits

Reviewing files that changed from the base of the PR and between 7b2d7c9 and ac792b7.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (53)
  • Cargo.toml
  • crates/aisix-llm/Cargo.toml
  • crates/aisix-llm/src/gateway/error.rs
  • crates/aisix-llm/src/gateway/formats/anthropic_messages.rs
  • crates/aisix-llm/src/gateway/formats/mod.rs
  • crates/aisix-llm/src/gateway/formats/openai/mod.rs
  • crates/aisix-llm/src/gateway/formats/openai/responses.rs
  • crates/aisix-llm/src/gateway/gateway.rs
  • crates/aisix-llm/src/gateway/provider_instance.rs
  • crates/aisix-llm/src/gateway/providers/anthropic/mod.rs
  • crates/aisix-llm/src/gateway/providers/anthropic/transform.rs
  • crates/aisix-llm/src/gateway/providers/azure.rs
  • crates/aisix-llm/src/gateway/providers/bedrock.rs
  • crates/aisix-llm/src/gateway/providers/bedrock/transform.rs
  • crates/aisix-llm/src/gateway/providers/cohere.rs
  • crates/aisix-llm/src/gateway/providers/deepseek.rs
  • crates/aisix-llm/src/gateway/providers/fireworks.rs
  • crates/aisix-llm/src/gateway/providers/gemini.rs
  • crates/aisix-llm/src/gateway/providers/groq.rs
  • crates/aisix-llm/src/gateway/providers/macros.rs
  • crates/aisix-llm/src/gateway/providers/mistral.rs
  • crates/aisix-llm/src/gateway/providers/mod.rs
  • crates/aisix-llm/src/gateway/providers/modelscope.rs
  • crates/aisix-llm/src/gateway/providers/moonshot.rs
  • crates/aisix-llm/src/gateway/providers/openai.rs
  • crates/aisix-llm/src/gateway/providers/openrouter.rs
  • crates/aisix-llm/src/gateway/providers/siliconflow.rs
  • crates/aisix-llm/src/gateway/providers/stepfun.rs
  • crates/aisix-llm/src/gateway/providers/xai.rs
  • crates/aisix-llm/src/gateway/providers/zhipuai.rs
  • crates/aisix-llm/src/gateway/session.rs
  • crates/aisix-llm/src/gateway/streams/bridged.rs
  • crates/aisix-llm/src/gateway/streams/hub.rs
  • crates/aisix-llm/src/gateway/streams/mod.rs
  • crates/aisix-llm/src/gateway/streams/native.rs
  • crates/aisix-llm/src/gateway/streams/reader/aws_event_stream.rs
  • crates/aisix-llm/src/gateway/streams/reader/mod.rs
  • crates/aisix-llm/src/gateway/streams/reader/sse.rs
  • crates/aisix-llm/src/gateway/traits/chat_format.rs
  • crates/aisix-llm/src/gateway/traits/mod.rs
  • crates/aisix-llm/src/gateway/traits/native.rs
  • crates/aisix-llm/src/gateway/traits/provider.rs
  • crates/aisix-llm/src/gateway/types/anthropic.rs
  • crates/aisix-llm/src/gateway/types/bedrock.rs
  • crates/aisix-llm/src/gateway/types/common.rs
  • crates/aisix-llm/src/gateway/types/embed.rs
  • crates/aisix-llm/src/gateway/types/mod.rs
  • crates/aisix-llm/src/gateway/types/openai/mod.rs
  • crates/aisix-llm/src/gateway/types/openai/responses.rs
  • crates/aisix-llm/src/gateway/types/response.rs
  • crates/aisix-llm/src/lib.rs
  • src/gateway/mod.rs
  • src/lib.rs
💤 Files with no reviewable changes (1)
  • src/gateway/mod.rs

@bzp2010 bzp2010 merged commit 8167359 into main May 5, 2026
3 checks passed
@bzp2010 bzp2010 deleted the bzp/feat-split-llm-crate branch May 5, 2026 05:30
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.

1 participant