Skip to content

refactor(providers): extract ProviderDef trait and OpenAiCompatibleProvider#6832

Merged
codefromthecrypt merged 5 commits intomainfrom
provider-factory
Feb 2, 2026
Merged

refactor(providers): extract ProviderDef trait and OpenAiCompatibleProvider#6832
codefromthecrypt merged 5 commits intomainfrom
provider-factory

Conversation

@codefromthecrypt
Copy link
Collaborator

@codefromthecrypt codefromthecrypt commented Jan 30, 2026

Summary

Separate provider construction from runtime behavior to reduce boilerplate and prepare for ACP-backed providers.

ProviderDef: new trait with metadata() and from_env(), split from Provider. Simplifies registration from a closure-based call to a single type parameter:

-        registry.register::<XaiProvider, _>(|m| Box::pin(XaiProvider::from_env(m)), false);
+        registry.register::<XaiProvider>(false);

The name follows Rust conventions (FromStr, Default) rather than OOP "factory" terminology. The implementing structs are zero-sized types used purely as type-level descriptors, with an associated type that ensures compile-time verification that the constructed provider implements Provider.

OpenAiCompatibleProvider: reusable struct that implements Provider for any OpenAI-compatible API. Providers like xAI and Azure go from ~200 lines (full Provider impl with duplicated HTTP/streaming logic) to ~70 lines (just metadata + client setup). Applied initially to "xai" and "azure" to prove the concept; others can follow.

This is vital for ACP-backed providers, as there could be over a dozen and differ only on aspects such as permission and mode mappings.

Type of Change

  • Refactor / Code quality

AI Assistance

  • This PR was created or reviewed with AI assistance

Testing

Ran the normal tests.

Related Issues

Last major refactor needed to reduce the huge diff in ACP provider PR #6605

@codefromthecrypt codefromthecrypt marked this pull request as ready for review January 30, 2026 06:45
Copilot AI review requested due to automatic review settings January 30, 2026 06:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the provider system by separating provider construction (ProviderFactory trait) from runtime behavior (Provider trait), reducing boilerplate for OpenAI-compatible providers.

Changes:

  • Introduces ProviderFactory trait with metadata() and from_env() methods, previously part of Provider
  • Adds OpenAiCompatibleProvider implementation to consolidate shared OpenAI-compatible logic
  • Simplifies provider registration from registry.register::<XaiProvider, _>(|m| Box::pin(XaiProvider::from_env(m)), false) to registry.register::<XaiProvider>(false)

Reviewed changes

Copilot reviewed 37 out of 37 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/goose/src/providers/base.rs Adds ProviderFactory trait, removes metadata() from Provider trait
crates/goose/src/providers/openai_compatible.rs New file containing shared OpenAI-compatible provider implementation and utility functions moved from utils.rs
crates/goose/src/providers/xai.rs Refactored to use OpenAiCompatibleProvider, significantly reducing boilerplate
crates/goose/src/providers/azure.rs Refactored to use OpenAiCompatibleProvider, removing duplicate implementation
crates/goose/src/providers/provider_registry.rs Simplified registration using ProviderFactory trait
crates/goose/src/providers/factory.rs Updated all provider registrations to use simplified syntax
crates/goose/src/providers/utils.rs Removed OpenAI-compat utility functions (moved to openai_compatible.rs)
crates/goose/src/providers/openai.rs Updated to use get_secrets() for better secret handling, implements ProviderFactory
crates/goose/src/providers/*.rs All providers updated to implement ProviderFactory separately from Provider
crates/goose/tests/*.rs Test mocks updated to implement ProviderFactory, removed metadata() from mock Provider impls
crates/goose-mcp/.gooseignore Standard goose ignore file added for MCP crate
crates/goose-acp/tests/fixtures/mod.rs Added recursion limit directive for consistency
clippy-baselines/too_many_lines.txt Added build_canonical_models to allowed long functions

Copilot AI review requested due to automatic review settings February 2, 2026 00:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 36 out of 36 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings February 2, 2026 04:51
@codefromthecrypt codefromthecrypt changed the title refactor(providers): extract ProviderFactory trait and OpenAiCompatibleProvider refactor(providers): extract ProviderDef trait and OpenAiCompatibleProvider Feb 2, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 36 out of 36 changed files in this pull request and generated 1 comment.

…leProvider

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Signed-off-by: Adrian Cole <adrian@tetrate.io>
Signed-off-by: Adrian Cole <adrian@tetrate.io>
Signed-off-by: Adrian Cole <adrian@tetrate.io>
Copilot AI review requested due to automatic review settings February 2, 2026 05:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 37 out of 37 changed files in this pull request and generated no new comments.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Copy link
Collaborator

@michaelneale michaelneale left a comment

Choose a reason for hiding this comment

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

I think this is ok - main concern was azure shift to streaming and missing methods for loading models @codefromthecrypt

@codefromthecrypt codefromthecrypt added this pull request to the merge queue Feb 2, 2026
Merged via the queue into main with commit 1ad81e3 Feb 2, 2026
18 checks passed
@codefromthecrypt codefromthecrypt deleted the provider-factory branch February 2, 2026 22:52
katzdave added a commit that referenced this pull request Feb 3, 2026
…ntext

* 'main' of github.com:block/goose:
  refactor(providers): extract ProviderDef trait and OpenAiCompatibleProvider (#6832)
  feat: ask ai discord bot (#6842)
  chore(maintenance): make GitHub repo configurable for auto-updater and publisher (#6828)
  fix: make apps work in built copies of goose (#6901)
  Remove dependency on goose-mcp from goose crate (#6637)
  Clean up build canonical warnings (#6880)
  Sync desktop_prompt with UI (#6898)
kuccello pushed a commit to kuccello/goose that referenced this pull request Feb 3, 2026
- Merged upstream changes including PR block#6832 (OpenAiCompatibleProvider)
- Refactored Ollama XML tool call parsing to use new architecture:
  - Added stream_ollama() function in openai_compatible.rs
  - Updated ollama.rs to use ProviderDef trait and new imports
  - Cleaned up single-line comments in formats/ollama.rs
- Fixed reqwest multipart feature flag for api_client.rs
- Fixed clippy warnings in utils.rs

Signed-off-by: Keith Uccello <kuccello@gmail.com>
stebbins pushed a commit to stebbins/goose that referenced this pull request Feb 4, 2026
…ovider (block#6832)

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Signed-off-by: Harrison <hcstebbins@gmail.com>
kuccello pushed a commit to kuccello/goose that referenced this pull request Feb 7, 2026
…ovider (block#6832)

Signed-off-by: Adrian Cole <adrian@tetrate.io>
kuccello added a commit to kuccello/goose that referenced this pull request Feb 7, 2026
- Merged upstream changes including PR block#6832 (OpenAiCompatibleProvider)
- Refactored Ollama XML tool call parsing to use new architecture:
  - Added stream_ollama() function in openai_compatible.rs
  - Updated ollama.rs to use ProviderDef trait and new imports
  - Cleaned up single-line comments in formats/ollama.rs
- Fixed reqwest multipart feature flag for api_client.rs
- Fixed clippy warnings in utils.rs

Signed-off-by: Keith Uccello <kuccello@gmail.com>

Signed-off-by: kuccello <kuccello@users.noreply.github.com>
Tyler-Hardin pushed a commit to Tyler-Hardin/goose that referenced this pull request Feb 11, 2026
…ovider (block#6832)

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Tyler-Hardin pushed a commit to Tyler-Hardin/goose that referenced this pull request Feb 11, 2026
…ovider (block#6832)

Signed-off-by: Adrian Cole <adrian@tetrate.io>
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.

2 participants