Add Meta Muse Code provider (#11765)
This commit is contained in:
@@ -58,6 +58,7 @@ pub fn map_provider_name(provider: &str) -> &str {
|
||||
"opencode_zen" => "opencode",
|
||||
"ollama_cloud" => "ollama-cloud",
|
||||
"kimi_code" => "kimi-code-plan-cn",
|
||||
"muse_code" => "meta",
|
||||
_ => provider,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ impl AnthropicFormatOptions {
|
||||
}
|
||||
}
|
||||
|
||||
fn for_model(self, model_config: &ModelConfig) -> Self {
|
||||
fn for_model(self, provider_name: &str, model_config: &ModelConfig) -> Self {
|
||||
let preserve_thinking_context = model_config
|
||||
.request_param::<bool>("preserve_thinking_context")
|
||||
.unwrap_or(self.preserve_thinking_context);
|
||||
@@ -86,8 +86,11 @@ impl AnthropicFormatOptions {
|
||||
.request_param::<bool>("preserve_unsigned_thinking")
|
||||
.unwrap_or(self.preserve_unsigned_thinking)
|
||||
|| preserve_thinking_context;
|
||||
let thinking_disabled = model_config.reasoning == Some(false)
|
||||
|| model_config.thinking_effort() == Some(ThinkingEffort::Off);
|
||||
let always_on = canonical_thinking_mode(provider_name, &model_config.model_name)
|
||||
== Some(ThinkingMode::AlwaysOnAdaptive);
|
||||
let thinking_disabled = !always_on
|
||||
&& (model_config.reasoning == Some(false)
|
||||
|| model_config.thinking_effort() == Some(ThinkingEffort::Off));
|
||||
let emit_clear_thinking = model_config
|
||||
.request_param::<bool>("emit_clear_thinking")
|
||||
.unwrap_or(self.emit_clear_thinking);
|
||||
@@ -148,7 +151,18 @@ pub fn thinking_block_is_stale(message: &Message, current_model: Option<&str>) -
|
||||
}
|
||||
|
||||
fn canonical_thinking_mode(provider_name: &str, model_name: &str) -> Option<ThinkingMode> {
|
||||
maybe_get_canonical_model(provider_name, model_name).and_then(|model| model.thinking_mode)
|
||||
maybe_get_canonical_model(provider_name, model_name)
|
||||
.and_then(|model| model.thinking_mode)
|
||||
.or_else(|| provider_thinking_mode(provider_name, model_name))
|
||||
}
|
||||
|
||||
/// Models that always reason when the canonical entry has no thinking mode.
|
||||
/// Muse Spark rejects `thinking: disabled` and ignores `budget_tokens`.
|
||||
fn provider_thinking_mode(provider_name: &str, model_name: &str) -> Option<ThinkingMode> {
|
||||
if provider_name == "muse_code" && model_name.starts_with("muse-spark") {
|
||||
return Some(ThinkingMode::AlwaysOnAdaptive);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Adaptive models run adaptive thinking when `thinking` is omitted, so turning
|
||||
@@ -759,6 +773,15 @@ pub fn thinking_effort(model_config: &ModelConfig) -> ThinkingEffort {
|
||||
.unwrap_or(ThinkingEffort::High)
|
||||
}
|
||||
|
||||
fn adaptive_effort_wire(provider_name: &str, model_config: &ModelConfig) -> String {
|
||||
let effort = adaptive_output_effort(model_config);
|
||||
// Meta Messages accepts low, medium, high, and xhigh. goose's max maps to xhigh.
|
||||
if provider_name == "muse_code" && effort == ThinkingEffort::Max {
|
||||
return "xhigh".to_string();
|
||||
}
|
||||
effort.to_string()
|
||||
}
|
||||
|
||||
pub fn adaptive_output_effort(model_config: &ModelConfig) -> ThinkingEffort {
|
||||
match thinking_effort(model_config) {
|
||||
ThinkingEffort::Off => ThinkingEffort::High,
|
||||
@@ -805,7 +828,7 @@ fn apply_thinking_config(
|
||||
match thinking_type_for_provider(provider_name, model_config) {
|
||||
ThinkingType::Adaptive => {
|
||||
obj.insert("thinking".to_string(), json!({"type": "adaptive"}));
|
||||
let effort = adaptive_output_effort(model_config).to_string();
|
||||
let effort = adaptive_effort_wire(provider_name, model_config);
|
||||
obj.insert("output_config".to_string(), json!({"effort": effort}));
|
||||
}
|
||||
ThinkingType::Enabled => {
|
||||
@@ -909,7 +932,7 @@ pub fn create_request_for_model(
|
||||
tools: &[Tool],
|
||||
options: AnthropicFormatOptions,
|
||||
) -> Result<Value> {
|
||||
let options = options.for_model(model_config);
|
||||
let options = options.for_model(provider_name, model_config);
|
||||
let anthropic_messages = format_messages_with_options(messages, &options);
|
||||
let tool_specs = format_tools(tools, &options);
|
||||
let system_spec = format_system(system, &options);
|
||||
|
||||
@@ -17,10 +17,11 @@ use super::api_client::ApiClient;
|
||||
use super::base::{
|
||||
known_models_from_registry, ConfigKey, MessageStream, ModelInfo, Provider, ProviderMetadata,
|
||||
};
|
||||
pub use super::formats::anthropic::AnthropicFormatOptions;
|
||||
use super::formats::anthropic::{
|
||||
block_binding_behavior, create_request_for_model, is_thinking_signature_error,
|
||||
response_to_streaming_message, AnthropicFormatOptions, PrefixMismatchBehavior,
|
||||
ANTHROPIC_PROVIDER_NAME, INPUT_TRANSFORMATIONS_FIELD, THINKING_BINDING_CONTROLS_BETA,
|
||||
response_to_streaming_message, PrefixMismatchBehavior, ANTHROPIC_PROVIDER_NAME,
|
||||
INPUT_TRANSFORMATIONS_FIELD, THINKING_BINDING_CONTROLS_BETA,
|
||||
};
|
||||
use super::openai_compatible::handle_status;
|
||||
use super::retry::ProviderRetry;
|
||||
@@ -153,7 +154,7 @@ impl AnthropicProvider {
|
||||
format_options: AnthropicFormatOptions,
|
||||
) -> Result<Value, ProviderError> {
|
||||
let mut payload = create_request_for_model(
|
||||
ANTHROPIC_PROVIDER_NAME,
|
||||
&self.name,
|
||||
model_config,
|
||||
wire_model,
|
||||
system,
|
||||
|
||||
@@ -317,6 +317,17 @@ impl ApiClient {
|
||||
.read_timeout(timeout)
|
||||
}
|
||||
|
||||
/// Build a reqwest client that honors the same custom CA and client
|
||||
/// certificate settings as provider API clients.
|
||||
pub fn http_client(tls_config: Option<&TlsConfig>) -> Result<Client> {
|
||||
let mut client_builder =
|
||||
Self::client_builder(Duration::from_secs(DEFAULT_PROVIDER_TIMEOUT_SECS));
|
||||
if let Some(tls_config) = tls_config {
|
||||
client_builder = Self::configure_tls(client_builder, tls_config)?;
|
||||
}
|
||||
Ok(client_builder.build()?)
|
||||
}
|
||||
|
||||
fn rebuild_client(&mut self) -> Result<()> {
|
||||
let mut client_builder =
|
||||
Self::client_builder(self.timeout).default_headers(self.default_headers.clone());
|
||||
|
||||
@@ -16,6 +16,42 @@
|
||||
"output_token_cost": 0.00000425,
|
||||
"currency": "USD",
|
||||
"reasoning": true
|
||||
},
|
||||
{
|
||||
"name": "muse-spark-1.2",
|
||||
"context_limit": 1048576,
|
||||
"max_tokens": 131072,
|
||||
"input_token_cost": 0.00000125,
|
||||
"output_token_cost": 0.00000425,
|
||||
"currency": "USD",
|
||||
"reasoning": true
|
||||
},
|
||||
{
|
||||
"name": "muse-spark-1.2-contributor",
|
||||
"context_limit": 1048576,
|
||||
"max_tokens": 131072,
|
||||
"input_token_cost": 0.0000001,
|
||||
"output_token_cost": 0.0000002,
|
||||
"currency": "USD",
|
||||
"reasoning": true
|
||||
},
|
||||
{
|
||||
"name": "muse-spark-1.3",
|
||||
"context_limit": 1048576,
|
||||
"max_tokens": 131072,
|
||||
"input_token_cost": 0.00000125,
|
||||
"output_token_cost": 0.00000425,
|
||||
"currency": "USD",
|
||||
"reasoning": true
|
||||
},
|
||||
{
|
||||
"name": "muse-spark-1.3-contributor",
|
||||
"context_limit": 1048576,
|
||||
"max_tokens": 131072,
|
||||
"input_token_cost": 0.0000001,
|
||||
"output_token_cost": 0.0000002,
|
||||
"currency": "USD",
|
||||
"reasoning": true
|
||||
}
|
||||
],
|
||||
"preserves_thinking": true,
|
||||
|
||||
@@ -42,6 +42,7 @@ use crate::providers::base::ProviderType;
|
||||
use crate::providers::databricks_def::{self, DatabricksProviderDef};
|
||||
use crate::providers::databricks_v2_def::{self, DatabricksV2ProviderDef};
|
||||
use crate::providers::google_def::GoogleProviderDef;
|
||||
use crate::providers::muse_code_def::{MuseCodeProvider, MuseCodeProviderDef};
|
||||
use crate::providers::ollama_def::OllamaProviderDef;
|
||||
use crate::providers::openai_def::OpenAiProviderDef;
|
||||
use crate::providers::openrouter_def::OpenRouterProviderDef;
|
||||
@@ -149,6 +150,10 @@ async fn init_registry() -> RwLock<ProviderRegistry> {
|
||||
);
|
||||
registry
|
||||
.register_with_inventory::<NanoGptProvider>(true, Some(registrations::refresh_only()));
|
||||
registry.register_with_inventory::<MuseCodeProviderDef>(
|
||||
true,
|
||||
Some(registrations::muse_code_inventory()),
|
||||
);
|
||||
registry.register_with_inventory::<OllamaProviderDef>(
|
||||
true,
|
||||
Some(registrations::ollama_inventory()),
|
||||
@@ -198,6 +203,10 @@ async fn init_registry() -> RwLock<ProviderRegistry> {
|
||||
"kimi_code",
|
||||
Arc::new(|| Box::pin(KimiCodeProvider::cleanup())),
|
||||
);
|
||||
registry.set_cleanup(
|
||||
"muse_code",
|
||||
Arc::new(|| Box::pin(MuseCodeProvider::cleanup())),
|
||||
);
|
||||
registry.set_cleanup(
|
||||
"chatgpt_codex",
|
||||
Arc::new(|| Box::pin(ChatGptCodexProvider::cleanup())),
|
||||
@@ -566,6 +575,7 @@ mod tests {
|
||||
"gcp_vertex_ai",
|
||||
"github_copilot",
|
||||
"kimi_code",
|
||||
"muse_code",
|
||||
"nano-gpt",
|
||||
"tetrate",
|
||||
"xai",
|
||||
|
||||
@@ -16,6 +16,7 @@ use crate::providers::google::{GOOGLE_API_HOST, GOOGLE_PROVIDER_NAME};
|
||||
use crate::providers::huggingface::HuggingFaceProvider;
|
||||
use crate::providers::huggingface_auth;
|
||||
use crate::providers::kimicode;
|
||||
use crate::providers::muse_code_def;
|
||||
use crate::providers::ollama::OLLAMA_PROVIDER_NAME;
|
||||
use crate::providers::openai::{OPEN_AI_DEFAULT_BASE_PATH, OPEN_AI_PROVIDER_NAME};
|
||||
use crate::providers::pi_acp::{PI_ACP_BINARY, PI_ACP_PROVIDER_NAME};
|
||||
@@ -199,6 +200,10 @@ pub fn kimi_code_inventory() -> InventoryRegistration {
|
||||
refresh_only().with_configured(kimicode::has_configured_token)
|
||||
}
|
||||
|
||||
pub fn muse_code_inventory() -> InventoryRegistration {
|
||||
refresh_only().with_configured(muse_code_def::has_configured_token)
|
||||
}
|
||||
|
||||
pub fn chatgpt_codex_inventory() -> InventoryRegistration {
|
||||
InventoryRegistration {
|
||||
supports_refresh: false,
|
||||
@@ -351,4 +356,38 @@ mod tests {
|
||||
|
||||
assert!(configured());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial_test::serial]
|
||||
fn muse_code_inventory_configured_uses_token_cache() {
|
||||
let root = tempfile::tempdir().unwrap();
|
||||
let root_path = root.path().to_string_lossy().to_string();
|
||||
let _guard = env_lock::lock_env([
|
||||
("GOOSE_PATH_ROOT", Some(root_path.as_str())),
|
||||
("MUSE_AUTH_PATH", Some("/tmp/goose-missing-muse-auth.json")),
|
||||
("XDG_CONFIG_HOME", Some(root_path.as_str())),
|
||||
]);
|
||||
|
||||
let registration = muse_code_inventory();
|
||||
let configured = registration
|
||||
.configured
|
||||
.expect("Muse Code should define configured resolver");
|
||||
|
||||
assert!(!configured());
|
||||
|
||||
let cache_path = Paths::in_config_dir("muse_code/token.json");
|
||||
std::fs::create_dir_all(cache_path.parent().unwrap()).unwrap();
|
||||
std::fs::write(
|
||||
cache_path,
|
||||
serde_json::to_string(&serde_json::json!({
|
||||
"access_token": "access",
|
||||
"refresh_token": "refresh",
|
||||
"expires_at": (Utc::now() + chrono::Duration::hours(1)).to_rfc3339(),
|
||||
}))
|
||||
.unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert!(configured());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ pub mod kimicode;
|
||||
pub mod litellm;
|
||||
#[cfg(feature = "local-inference")]
|
||||
pub mod local_inference;
|
||||
pub mod muse_code_def;
|
||||
pub mod nanogpt;
|
||||
pub mod oauth;
|
||||
pub mod oauth_device_flow;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -186,6 +186,11 @@ prompt: |
|
||||
5. Run `python3 documentation/automation/gdk-api/generate.py --check` to verify the generated GDK API data is current and publishes `gateway_path` as an optional argument defaulting to `None`.
|
||||
If the source checkout or Rust toolchain is unavailable, mark this validation as skipped rather than failed.
|
||||
|
||||
### Muse Code Provider Validation
|
||||
When running from a goose source checkout:
|
||||
1. Run `cargo test -p goose --features scheduler --lib muse_code` to verify Muse Code metadata, device-code login, key mint, day-long key renewal from the identity token, and CLI-token reuse.
|
||||
If the source checkout or Rust toolchain is unavailable, mark this validation as skipped rather than failed.
|
||||
|
||||
Log results to: {{ workspace_dir }}/phase1_basic_tools.md
|
||||
{% endif %}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user