feat(acp): scope Toolshim to custom providers (#11414)
This commit is contained in:
@@ -2307,6 +2307,7 @@ fn add_provider() -> anyhow::Result<()> {
|
||||
requires_auth,
|
||||
catalog_provider_id: None,
|
||||
base_path,
|
||||
toolshim: false,
|
||||
preserves_thinking: None,
|
||||
auth,
|
||||
})?;
|
||||
|
||||
@@ -87,7 +87,7 @@ pub fn print_recipe_info(recipe: &Recipe, params: Vec<(String, String)>) {
|
||||
style("Loading recipe:").green().bold(),
|
||||
style(&recipe.title).green()
|
||||
);
|
||||
eprintln!("{} {}", style("Description:").bold(), &recipe.description);
|
||||
eprintln!("{} {}", style("Description:").bold(), recipe.description);
|
||||
|
||||
if !params.is_empty() {
|
||||
eprintln!("{}", style("Parameters used to load this recipe:").bold());
|
||||
|
||||
@@ -647,7 +647,7 @@ impl CliSession {
|
||||
println!(
|
||||
"\n {} {}",
|
||||
console::style("●").red(),
|
||||
console::style(format!("session closed · {}", &self.session_id)).dim()
|
||||
console::style(format!("session closed · {}", self.session_id)).dim()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -184,6 +184,8 @@ pub struct DeclarativeProviderConfig {
|
||||
#[serde(default)]
|
||||
pub setup_steps: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub toolshim: bool,
|
||||
#[serde(default)]
|
||||
pub preserves_thinking: bool,
|
||||
/// Enables Z.AI's `clear_thinking` field, which Anthropic does not support.
|
||||
#[serde(default)]
|
||||
|
||||
@@ -588,6 +588,7 @@ mod tests {
|
||||
skip_canonical_filtering: false,
|
||||
model_doc_link: None,
|
||||
setup_steps: vec![],
|
||||
toolshim: false,
|
||||
preserves_thinking: false,
|
||||
emit_clear_thinking: false,
|
||||
setup: None,
|
||||
|
||||
@@ -1391,6 +1391,7 @@ mod tests {
|
||||
skip_canonical_filtering: false,
|
||||
model_doc_link: None,
|
||||
setup_steps: vec![],
|
||||
toolshim: false,
|
||||
preserves_thinking: false,
|
||||
emit_clear_thinking: false,
|
||||
setup: None,
|
||||
|
||||
@@ -1214,6 +1214,7 @@ pub struct CustomProviderConfigDto {
|
||||
pub catalog_provider_id: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub base_path: Option<String>,
|
||||
pub toolshim: bool,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub api_key_env: Option<String>,
|
||||
pub api_key_set: bool,
|
||||
@@ -1253,6 +1254,7 @@ pub struct CustomProviderUpsertDto {
|
||||
pub struct CustomProviderCreateRequest {
|
||||
#[serde(flatten)]
|
||||
pub provider: CustomProviderUpsertDto,
|
||||
pub toolshim: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema, JsonRpcResponse)]
|
||||
@@ -1293,6 +1295,7 @@ pub struct CustomProviderUpdateRequest {
|
||||
pub provider_id: String,
|
||||
#[serde(flatten)]
|
||||
pub provider: CustomProviderUpsertDto,
|
||||
pub toolshim: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema, JsonRpcResponse)]
|
||||
|
||||
@@ -70,7 +70,7 @@ pub fn record(log_file_path: &String, cmd: &String, cmd_args: &[String]) -> io::
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.inspect_err(|e| eprintln!("Failed to execute command '{}': {}", &cmd, e))?;
|
||||
.inspect_err(|e| eprintln!("Failed to execute command '{}': {}", cmd, e))?;
|
||||
|
||||
let child_stdin = child.stdin.take().unwrap();
|
||||
let child_stdout = child.stdout.take().unwrap();
|
||||
|
||||
@@ -2300,13 +2300,17 @@
|
||||
"boolean",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"toolshim": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"engine",
|
||||
"displayName",
|
||||
"apiUrl",
|
||||
"requiresAuth"
|
||||
"requiresAuth",
|
||||
"toolshim"
|
||||
],
|
||||
"description": "Create a custom provider backed by goose's declarative provider store.",
|
||||
"x-side": "agent",
|
||||
@@ -2483,6 +2487,9 @@
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"toolshim": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"apiKeyEnv": {
|
||||
"type": [
|
||||
"string",
|
||||
@@ -2502,6 +2509,7 @@
|
||||
"displayName",
|
||||
"apiUrl",
|
||||
"requiresAuth",
|
||||
"toolshim",
|
||||
"apiKeySet",
|
||||
"preservesThinking"
|
||||
]
|
||||
@@ -2567,6 +2575,9 @@
|
||||
"boolean",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"toolshim": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -2574,7 +2585,8 @@
|
||||
"engine",
|
||||
"displayName",
|
||||
"apiUrl",
|
||||
"requiresAuth"
|
||||
"requiresAuth",
|
||||
"toolshim"
|
||||
],
|
||||
"description": "Update a custom provider backed by goose's declarative provider store.",
|
||||
"x-side": "agent",
|
||||
|
||||
@@ -22,7 +22,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("\n✅ Authentication successful!");
|
||||
println!(
|
||||
"API Key received: {}...",
|
||||
&api_key.chars().take(10).collect::<String>()
|
||||
api_key.chars().take(10).collect::<String>()
|
||||
);
|
||||
println!("\nYou can now use this API key with the Tetrate provider.");
|
||||
}
|
||||
|
||||
@@ -448,6 +448,7 @@ fn custom_provider_config_to_dto(
|
||||
requires_auth: config.requires_auth,
|
||||
catalog_provider_id: config.catalog_provider_id.clone(),
|
||||
base_path: config.base_path.clone(),
|
||||
toolshim: config.toolshim,
|
||||
api_key_env,
|
||||
api_key_set,
|
||||
preserves_thinking: config.preserves_thinking,
|
||||
@@ -631,6 +632,7 @@ impl GooseAcpAgent {
|
||||
&self,
|
||||
req: CustomProviderCreateRequest,
|
||||
) -> Result<CustomProviderCreateResponse, agent_client_protocol::Error> {
|
||||
let toolshim = req.toolshim;
|
||||
let provider = normalize_custom_provider_upsert(req.provider, true)?;
|
||||
let config = declarative_providers::create_custom_provider(
|
||||
declarative_providers::CreateCustomProviderParams {
|
||||
@@ -648,6 +650,7 @@ impl GooseAcpAgent {
|
||||
requires_auth: provider.requires_auth,
|
||||
catalog_provider_id: provider.catalog_provider_id,
|
||||
base_path: provider.base_path,
|
||||
toolshim,
|
||||
preserves_thinking: provider.preserves_thinking,
|
||||
auth: None,
|
||||
},
|
||||
@@ -726,6 +729,7 @@ impl GooseAcpAgent {
|
||||
requires_auth: provider.requires_auth,
|
||||
catalog_provider_id: provider.catalog_provider_id,
|
||||
base_path: provider.base_path,
|
||||
toolshim: req.toolshim,
|
||||
preserves_thinking: provider.preserves_thinking,
|
||||
// The desktop/ACP form doesn't yet support editing command-based
|
||||
// auth, so carry the existing setting forward unchanged rather
|
||||
@@ -858,6 +862,7 @@ impl GooseAcpAgent {
|
||||
let provider_factory = Arc::clone(&self.provider_factory);
|
||||
let provider_id = refresh_job.provider_id.clone();
|
||||
let identity = refresh_job.identity.clone();
|
||||
let toolshim = refresh_job.toolshim;
|
||||
tokio::spawn(async move {
|
||||
let mut refresh_guard = provider_inventory.refresh_guard(&identity);
|
||||
let provider_result = AssertUnwindSafe(async {
|
||||
@@ -866,28 +871,27 @@ impl GooseAcpAgent {
|
||||
.catch_unwind()
|
||||
.await;
|
||||
|
||||
let fetch_result: Result<Vec<String>> =
|
||||
match provider_result {
|
||||
Ok(Ok(provider)) => {
|
||||
match ensure_refresh_identity_current(&provider_id, &identity).await {
|
||||
Ok(()) => match AssertUnwindSafe(provider.fetch_recommended_models(
|
||||
crate::model_config::global_toolshim(),
|
||||
))
|
||||
.catch_unwind()
|
||||
.await
|
||||
let fetch_result: Result<Vec<String>> = match provider_result {
|
||||
Ok(Ok(provider)) => {
|
||||
match ensure_refresh_identity_current(&provider_id, &identity).await {
|
||||
Ok(()) => {
|
||||
match AssertUnwindSafe(provider.fetch_recommended_models(toolshim))
|
||||
.catch_unwind()
|
||||
.await
|
||||
{
|
||||
Ok(Ok(models)) => Ok(models),
|
||||
Ok(Err(error)) => Err(anyhow::anyhow!(error.to_string())),
|
||||
Err(_) => Err(anyhow::anyhow!(
|
||||
"provider inventory refresh task panicked"
|
||||
)),
|
||||
},
|
||||
Err(error) => Err(error),
|
||||
}
|
||||
}
|
||||
Err(error) => Err(error),
|
||||
}
|
||||
Ok(Err(error)) => Err(error),
|
||||
Err(_) => Err(anyhow::anyhow!("provider inventory refresh task panicked")),
|
||||
};
|
||||
}
|
||||
Ok(Err(error)) => Err(error),
|
||||
Err(_) => Err(anyhow::anyhow!("provider inventory refresh task panicked")),
|
||||
};
|
||||
|
||||
match fetch_result {
|
||||
Ok(models) => match provider_inventory
|
||||
|
||||
@@ -1011,6 +1011,20 @@ impl Agent {
|
||||
.map_err(|e| anyhow!("Could not resolve model config: {e}"))
|
||||
}
|
||||
|
||||
pub(super) async fn effective_model_config_for_session(
|
||||
&self,
|
||||
session_id: &str,
|
||||
) -> Result<goose_providers::model::ModelConfig> {
|
||||
let model_config = self.model_config_for_session(session_id).await?;
|
||||
let provider_name = self.provider().await?.get_name().to_string();
|
||||
match crate::providers::get_from_registry(&provider_name).await {
|
||||
Ok(entry) => Ok(entry
|
||||
.normalize_model_config(model_config.clone())
|
||||
.unwrap_or(model_config)),
|
||||
Err(_) => Ok(model_config),
|
||||
}
|
||||
}
|
||||
|
||||
/// When set, all stdio extensions will be started via `docker exec` in the specified container.
|
||||
pub async fn set_container(&self, container: Option<Container>) {
|
||||
*self.container.lock().await = container.clone();
|
||||
@@ -1938,26 +1952,13 @@ impl Agent {
|
||||
) -> Result<BoxStream<'_, Result<AgentEvent>>> {
|
||||
let session_manager = self.config.session_manager.clone();
|
||||
let session_id = session_config.id.clone();
|
||||
let entry_session = session_manager.get_session(&session_id, false).await?;
|
||||
let provider = self
|
||||
.provider
|
||||
.lock()
|
||||
.await
|
||||
.clone()
|
||||
.ok_or_else(|| anyhow!("Provider not set"))?;
|
||||
let model_config = match entry_session.model_config {
|
||||
Some(model_config) => model_config,
|
||||
None => {
|
||||
let provider_name = Config::global()
|
||||
.get_goose_provider()
|
||||
.map_err(|_| anyhow!("Could not resolve model config: missing provider"))?;
|
||||
let model_name = Config::global()
|
||||
.get_goose_model()
|
||||
.map_err(|_| anyhow!("Could not resolve model config: missing model"))?;
|
||||
crate::model_config::model_config_from_user_config(&provider_name, &model_name)
|
||||
.map_err(|error| anyhow!("Could not resolve model config: {error}"))?
|
||||
}
|
||||
};
|
||||
let model_config = self.effective_model_config_for_session(&session_id).await?;
|
||||
|
||||
let context_limit =
|
||||
crate::context_limit::get_context_limit(provider.as_ref(), &model_config.model_name)
|
||||
@@ -3649,15 +3650,24 @@ impl Agent {
|
||||
session_id: &str,
|
||||
) -> Result<()> {
|
||||
let provider_name = provider.get_name().to_string();
|
||||
let registry_entry = crate::providers::get_from_registry(&provider_name)
|
||||
.await
|
||||
.ok();
|
||||
|
||||
let model_config = match crate::providers::get_from_registry(&provider_name).await {
|
||||
Ok(entry) => entry
|
||||
.normalize_model_config(model_config.clone())
|
||||
.unwrap_or(model_config),
|
||||
Err(_) => model_config,
|
||||
let model_config = if registry_entry.is_some() {
|
||||
crate::model_config::materialize_model_config(&provider_name, model_config.clone())
|
||||
.unwrap_or(model_config)
|
||||
} else {
|
||||
model_config
|
||||
};
|
||||
let effort_support = provider.thinking_effort_support();
|
||||
let model_config = normalize_legacy_provider_thinking_effort(model_config, &effort_support);
|
||||
let effective_model_config = match registry_entry {
|
||||
Some(entry) => entry
|
||||
.normalize_model_config(model_config.clone())
|
||||
.unwrap_or_else(|_| model_config.clone()),
|
||||
None => model_config.clone(),
|
||||
};
|
||||
|
||||
{
|
||||
let mut current_provider = self.provider.lock().await;
|
||||
@@ -3668,7 +3678,10 @@ impl Agent {
|
||||
// own default, so the session's selection has to be pushed to it before
|
||||
// the next config snapshot is built. Failures are not fatal here: the
|
||||
// selection is re-applied at stream time.
|
||||
if let Err(e) = provider.apply_model_selection(&model_config).await {
|
||||
if let Err(e) = provider
|
||||
.apply_model_selection(&effective_model_config)
|
||||
.await
|
||||
{
|
||||
warn!("Failed to apply model selection to provider: {e}");
|
||||
}
|
||||
|
||||
@@ -4783,6 +4796,96 @@ mod tests {
|
||||
assert_eq!(provider.model_selections(), ["mock-model"]);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn provider_toolshim_is_effective_without_being_persisted() {
|
||||
let (agent, session, _data_dir) = tracing_test_agent_and_session().await;
|
||||
let provider_root = TempDir::new().unwrap();
|
||||
let provider_root_path = provider_root.path().display().to_string();
|
||||
let _guard = env_lock::lock_env([
|
||||
("GOOSE_PATH_ROOT", Some(provider_root_path.as_str())),
|
||||
("GOOSE_TOOLSHIM", None),
|
||||
]);
|
||||
|
||||
let config = crate::config::declarative_providers::create_custom_provider(
|
||||
crate::config::declarative_providers::CreateCustomProviderParams {
|
||||
engine: "openai".to_string(),
|
||||
display_name: "Sticky Toolshim".to_string(),
|
||||
api_url: "https://example.invalid/v1".to_string(),
|
||||
api_key: None,
|
||||
models: vec![crate::providers::base::ModelInfo::new("test-model")],
|
||||
supports_streaming: Some(true),
|
||||
headers: None,
|
||||
requires_auth: false,
|
||||
catalog_provider_id: None,
|
||||
base_path: None,
|
||||
toolshim: true,
|
||||
preserves_thinking: None,
|
||||
auth: None,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
crate::providers::refresh_custom_providers().await.unwrap();
|
||||
|
||||
let provider = crate::providers::create(&config.name, Vec::new())
|
||||
.await
|
||||
.unwrap();
|
||||
agent
|
||||
.update_provider(
|
||||
provider,
|
||||
goose_providers::model::ModelConfig::new("test-model"),
|
||||
&session.id,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(
|
||||
!agent
|
||||
.model_config_for_session(&session.id)
|
||||
.await
|
||||
.unwrap()
|
||||
.toolshim
|
||||
);
|
||||
assert!(
|
||||
agent
|
||||
.effective_model_config_for_session(&session.id)
|
||||
.await
|
||||
.unwrap()
|
||||
.toolshim
|
||||
);
|
||||
|
||||
crate::config::declarative_providers::update_custom_provider(
|
||||
crate::config::declarative_providers::UpdateCustomProviderParams {
|
||||
id: config.name.clone(),
|
||||
engine: "openai".to_string(),
|
||||
display_name: config.display_name,
|
||||
api_url: config.base_url,
|
||||
api_key: None,
|
||||
models: config.models,
|
||||
supports_streaming: config.supports_streaming,
|
||||
headers: config.headers,
|
||||
requires_auth: false,
|
||||
catalog_provider_id: None,
|
||||
base_path: None,
|
||||
toolshim: false,
|
||||
preserves_thinking: None,
|
||||
auth: None,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
crate::providers::refresh_custom_providers().await.unwrap();
|
||||
|
||||
assert!(
|
||||
!agent
|
||||
.effective_model_config_for_session(&session.id)
|
||||
.await
|
||||
.unwrap()
|
||||
.toolshim
|
||||
);
|
||||
|
||||
crate::config::declarative_providers::remove_custom_provider(&config.name).unwrap();
|
||||
crate::providers::refresh_custom_providers().await.unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn update_provider_replaces_harness_only_effort_for_legacy_provider() {
|
||||
let _guard = env_lock::lock_env([("GOOSE_THINKING_EFFORT", Some("high"))]);
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
use crate::agents::extension::PlatformExtensionContext;
|
||||
use crate::agents::mcp_client::{Error, McpClientTrait};
|
||||
use crate::agents::reply_parts::coerce_tool_arguments;
|
||||
use crate::agents::reply_parts::{
|
||||
coerce_tool_arguments, prepare_tools_for_provider, toolshim_postprocess,
|
||||
};
|
||||
use crate::agents::tool_execution::ToolCallContext;
|
||||
use crate::config::paths::Paths;
|
||||
use crate::conversation::message::Message;
|
||||
use crate::goose_apps::McpAppResource;
|
||||
use crate::goose_apps::{GooseApp, McpAppCache, WindowProps};
|
||||
use crate::prompt_template::render_template;
|
||||
use crate::providers::base::Provider;
|
||||
use crate::providers::base::{Provider, ProviderUsage};
|
||||
use async_trait::async_trait;
|
||||
use rmcp::model::{
|
||||
CallToolResult, ContentBlock, Implementation, InitializeResult, JsonObject,
|
||||
@@ -23,6 +25,35 @@ use std::path::{Component, Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
async fn complete_app_content(
|
||||
provider: Arc<dyn Provider>,
|
||||
model_config: &goose_providers::model::ModelConfig,
|
||||
session_id: &str,
|
||||
system_prompt: String,
|
||||
messages: &[Message],
|
||||
tools: Vec<McpTool>,
|
||||
) -> Result<(Message, ProviderUsage), String> {
|
||||
let (tools, toolshim_tools, system_prompt) =
|
||||
prepare_tools_for_provider(tools, system_prompt, model_config);
|
||||
|
||||
let (response, usage) = crate::session_context::with_session_id(
|
||||
Some(session_id.to_string()),
|
||||
provider.complete(model_config, &system_prompt, messages, &tools),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| format!("LLM call failed: {e}"))?;
|
||||
|
||||
let response = if model_config.toolshim {
|
||||
toolshim_postprocess(response, &toolshim_tools)
|
||||
.await
|
||||
.map_err(|e| format!("Toolshim failed: {e}"))?
|
||||
} else {
|
||||
response
|
||||
};
|
||||
|
||||
Ok((response, usage))
|
||||
}
|
||||
|
||||
pub static EXTENSION_NAME: &str = "apps";
|
||||
const CLOCK_APP_NAME: &str = "clock";
|
||||
const CLOCK_HTML: &str = include_str!("../../goose_apps/clock.html");
|
||||
@@ -249,6 +280,20 @@ impl AppsManagerClient {
|
||||
Ok(provider)
|
||||
}
|
||||
|
||||
async fn effective_model_config(
|
||||
&self,
|
||||
session_id: &str,
|
||||
provider_name: &str,
|
||||
) -> Result<goose_providers::model::ModelConfig, String> {
|
||||
let model_config = self.context.model_config_for_session(session_id).await?;
|
||||
match crate::providers::get_from_registry(provider_name).await {
|
||||
Ok(entry) => Ok(entry
|
||||
.normalize_model_config(model_config.clone())
|
||||
.unwrap_or(model_config)),
|
||||
Err(_) => Ok(model_config),
|
||||
}
|
||||
}
|
||||
|
||||
fn schema<T: JsonSchema>() -> JsonObject {
|
||||
serde_json::to_value(schema_for!(T))
|
||||
.map(|v| {
|
||||
@@ -298,14 +343,18 @@ impl AppsManagerClient {
|
||||
let messages = vec![Message::user().with_text(&user_prompt)];
|
||||
let tools = vec![Self::create_app_content_tool()];
|
||||
|
||||
let model_config = self.context.model_config_for_session(session_id).await?;
|
||||
|
||||
let (response, usage) = crate::session_context::with_session_id(
|
||||
Some(session_id.to_string()),
|
||||
provider.complete(&model_config, &system_prompt, &messages, &tools),
|
||||
let model_config = self
|
||||
.effective_model_config(session_id, provider.get_name())
|
||||
.await?;
|
||||
let (response, usage) = complete_app_content(
|
||||
provider,
|
||||
&model_config,
|
||||
session_id,
|
||||
system_prompt,
|
||||
&messages,
|
||||
tools,
|
||||
)
|
||||
.await
|
||||
.map_err(|e| format!("LLM call failed: {}", e))?;
|
||||
.await?;
|
||||
|
||||
if let (Some(output), Some(max)) = (usage.usage.output_tokens, model_config.max_tokens) {
|
||||
if output >= max {
|
||||
@@ -343,14 +392,18 @@ impl AppsManagerClient {
|
||||
let messages = vec![Message::user().with_text(&user_prompt)];
|
||||
let tools = vec![Self::update_app_content_tool()];
|
||||
|
||||
let model_config = self.context.model_config_for_session(session_id).await?;
|
||||
|
||||
let (response, usage) = crate::session_context::with_session_id(
|
||||
Some(session_id.to_string()),
|
||||
provider.complete(&model_config, &system_prompt, &messages, &tools),
|
||||
let model_config = self
|
||||
.effective_model_config(session_id, provider.get_name())
|
||||
.await?;
|
||||
let (response, usage) = complete_app_content(
|
||||
provider,
|
||||
&model_config,
|
||||
session_id,
|
||||
system_prompt,
|
||||
&messages,
|
||||
tools,
|
||||
)
|
||||
.await
|
||||
.map_err(|e| format!("LLM call failed: {}", e))?;
|
||||
.await?;
|
||||
|
||||
if let (Some(output), Some(max)) = (usage.usage.output_tokens, model_config.max_tokens) {
|
||||
if output >= max {
|
||||
@@ -741,8 +794,39 @@ fn extract_tool_response<T: serde::de::DeserializeOwned>(
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::agents::reply_parts::{is_tool_visible_to_app, is_tool_visible_to_model};
|
||||
use crate::providers::base::{stream_from_single_message, MessageStream, Usage};
|
||||
use crate::session::SessionManager;
|
||||
use goose_providers::errors::ProviderError;
|
||||
use std::path::Path;
|
||||
use std::sync::Mutex;
|
||||
|
||||
#[derive(Default)]
|
||||
struct AppContentProvider {
|
||||
request: Mutex<Option<(bool, String, usize)>>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Provider for AppContentProvider {
|
||||
fn get_name(&self) -> &str {
|
||||
"app-content-test"
|
||||
}
|
||||
|
||||
async fn stream(
|
||||
&self,
|
||||
model_config: &goose_providers::model::ModelConfig,
|
||||
system: &str,
|
||||
_messages: &[Message],
|
||||
tools: &[McpTool],
|
||||
) -> Result<MessageStream, ProviderError> {
|
||||
*self.request.lock().unwrap() =
|
||||
Some((model_config.toolshim, system.to_string(), tools.len()));
|
||||
let message = Message::assistant().with_text(
|
||||
r#"{"name":"create_app_content","arguments":{"name":"test-app","description":"Test app","html":"<html></html>"}}"#,
|
||||
);
|
||||
let usage = ProviderUsage::new("test-model".to_string(), Usage::default());
|
||||
Ok(stream_from_single_message(message, usage))
|
||||
}
|
||||
}
|
||||
|
||||
fn test_client(apps_dir: PathBuf) -> AppsManagerClient {
|
||||
AppsManagerClient {
|
||||
@@ -776,6 +860,35 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn app_content_completion_uses_toolshim() {
|
||||
let provider = Arc::new(AppContentProvider::default());
|
||||
let model_config =
|
||||
goose_providers::model::ModelConfig::new("test-model").with_toolshim(true);
|
||||
let tool = AppsManagerClient::create_app_content_tool();
|
||||
let tool_schema = AppsManagerClient::schema::<CreateAppContentResponse>();
|
||||
|
||||
let (response, _) = complete_app_content(
|
||||
provider.clone(),
|
||||
&model_config,
|
||||
"session",
|
||||
"Create an app".to_string(),
|
||||
&[Message::user().with_text("A test app")],
|
||||
vec![tool],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let request = provider.request.lock().unwrap().clone().unwrap();
|
||||
assert!(request.0);
|
||||
assert!(request.1.contains("Tool Name: create_app_content"));
|
||||
assert_eq!(request.2, 0);
|
||||
|
||||
let content: CreateAppContentResponse =
|
||||
extract_tool_response(&response, "create_app_content", &tool_schema).unwrap();
|
||||
assert_eq!(content.name, "test-app");
|
||||
}
|
||||
|
||||
fn invalid_app_names(temp_dir: &Path) -> Vec<String> {
|
||||
vec![
|
||||
"../outside".to_string(),
|
||||
|
||||
@@ -169,7 +169,7 @@ impl CodeExecutionClient {
|
||||
.clone()
|
||||
.map(|n| format!("{n}__"))
|
||||
.unwrap_or_default(),
|
||||
&cfg.name
|
||||
cfg.name
|
||||
);
|
||||
let callback = create_tool_callback(
|
||||
ctx.clone(),
|
||||
|
||||
@@ -129,7 +129,7 @@ pub(crate) fn coerce_tool_arguments(
|
||||
Some(coerced)
|
||||
}
|
||||
|
||||
async fn toolshim_postprocess(
|
||||
pub(crate) async fn toolshim_postprocess(
|
||||
response: Message,
|
||||
toolshim_tools: &[Tool],
|
||||
) -> Result<Message, ProviderError> {
|
||||
@@ -217,7 +217,7 @@ impl Agent {
|
||||
.extension_manager
|
||||
.get_extensions_info(working_dir)
|
||||
.await;
|
||||
let model_config = self.model_config_for_session(session_id).await?;
|
||||
let model_config = self.effective_model_config_for_session(session_id).await?;
|
||||
|
||||
let goose_mode = *self.current_goose_mode.lock().await;
|
||||
|
||||
|
||||
@@ -144,6 +144,7 @@ pub struct CreateCustomProviderParams {
|
||||
pub requires_auth: bool,
|
||||
pub catalog_provider_id: Option<String>,
|
||||
pub base_path: Option<String>,
|
||||
pub toolshim: bool,
|
||||
pub preserves_thinking: Option<bool>,
|
||||
/// Alternative to `api_key`; mutually exclusive with it.
|
||||
pub auth: Option<AuthConfig>,
|
||||
@@ -162,6 +163,7 @@ pub struct UpdateCustomProviderParams {
|
||||
pub requires_auth: bool,
|
||||
pub catalog_provider_id: Option<String>,
|
||||
pub base_path: Option<String>,
|
||||
pub toolshim: bool,
|
||||
pub preserves_thinking: Option<bool>,
|
||||
/// Alternative to `api_key`; mutually exclusive with it.
|
||||
pub auth: Option<AuthConfig>,
|
||||
@@ -225,6 +227,7 @@ pub fn create_custom_provider(
|
||||
skip_canonical_filtering: false,
|
||||
model_doc_link: None,
|
||||
setup_steps: vec![],
|
||||
toolshim: params.toolshim,
|
||||
preserves_thinking,
|
||||
emit_clear_thinking: false,
|
||||
setup: None,
|
||||
@@ -343,6 +346,7 @@ pub fn update_custom_provider(params: UpdateCustomProviderParams) -> Result<()>
|
||||
skip_canonical_filtering: existing_config.skip_canonical_filtering,
|
||||
model_doc_link: existing_config.model_doc_link,
|
||||
setup_steps: existing_config.setup_steps,
|
||||
toolshim: params.toolshim,
|
||||
preserves_thinking,
|
||||
emit_clear_thinking: existing_config.emit_clear_thinking,
|
||||
setup: existing_config.setup,
|
||||
@@ -619,12 +623,31 @@ mod tests {
|
||||
skip_canonical_filtering: false,
|
||||
model_doc_link: None,
|
||||
setup_steps: Vec::new(),
|
||||
toolshim: false,
|
||||
preserves_thinking: true,
|
||||
emit_clear_thinking: false,
|
||||
setup: None,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn toolshim_changes_declarative_inventory_identity() {
|
||||
let _guard = env_lock::lock_env([("GOOSE_TOOLSHIM", None::<&str>)]);
|
||||
let mut config = test_huggingface_config();
|
||||
|
||||
let native = declarative_inventory_identity(&config)
|
||||
.unwrap()
|
||||
.into_identity()
|
||||
.unwrap();
|
||||
config.toolshim = true;
|
||||
let toolshim = declarative_inventory_identity(&config)
|
||||
.unwrap()
|
||||
.into_identity()
|
||||
.unwrap();
|
||||
|
||||
assert_ne!(native.inventory_key, toolshim.inventory_key);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn huggingface_inventory_allows_unauthenticated_custom_provider() {
|
||||
let mut config = test_huggingface_config();
|
||||
@@ -770,6 +793,7 @@ mod tests {
|
||||
requires_auth: false,
|
||||
catalog_provider_id: None,
|
||||
base_path: None,
|
||||
toolshim: false,
|
||||
preserves_thinking: None,
|
||||
auth: None,
|
||||
})
|
||||
@@ -787,6 +811,7 @@ mod tests {
|
||||
requires_auth: false,
|
||||
catalog_provider_id: None,
|
||||
base_path: None,
|
||||
toolshim: false,
|
||||
preserves_thinking: None,
|
||||
auth: None,
|
||||
})
|
||||
@@ -904,6 +929,7 @@ mod tests {
|
||||
requires_auth: false,
|
||||
catalog_provider_id: None,
|
||||
base_path: None,
|
||||
toolshim: false,
|
||||
preserves_thinking: None,
|
||||
auth: None,
|
||||
})
|
||||
|
||||
@@ -144,6 +144,7 @@ mod tests {
|
||||
skip_canonical_filtering: false,
|
||||
model_doc_link: None,
|
||||
setup_steps: vec![],
|
||||
toolshim: false,
|
||||
preserves_thinking: false,
|
||||
emit_clear_thinking: false,
|
||||
setup: None,
|
||||
|
||||
@@ -581,6 +581,7 @@ mod tests {
|
||||
skip_canonical_filtering: false,
|
||||
model_doc_link: None,
|
||||
setup_steps: vec![],
|
||||
toolshim: false,
|
||||
preserves_thinking: true,
|
||||
emit_clear_thinking: false,
|
||||
setup: None,
|
||||
|
||||
@@ -162,6 +162,7 @@ pub struct RefreshSkip {
|
||||
pub(crate) struct RefreshJob {
|
||||
pub provider_id: String,
|
||||
pub identity: InventoryIdentity,
|
||||
pub toolshim: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
@@ -271,6 +272,7 @@ struct ProviderDescriptor {
|
||||
config_keys: Vec<ConfigKey>,
|
||||
setup_steps: Vec<String>,
|
||||
supports_refresh: bool,
|
||||
toolshim: bool,
|
||||
static_models: Vec<ModelInfo>,
|
||||
}
|
||||
|
||||
@@ -435,6 +437,7 @@ impl ProviderInventoryService {
|
||||
plan.started.push(RefreshJob {
|
||||
provider_id: descriptor.provider_id,
|
||||
identity: descriptor.identity,
|
||||
toolshim: descriptor.toolshim,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -621,16 +624,15 @@ impl ProviderInventoryService {
|
||||
.find(|job| job.provider_id == provider_id);
|
||||
if let Some(refresh_job) = refresh_job {
|
||||
let mut refresh_guard = self.refresh_guard(&refresh_job.identity);
|
||||
let toolshim = refresh_job.toolshim;
|
||||
let fetch_result: Result<Vec<String>> =
|
||||
match ensure_refresh_identity_current(&provider_id, &refresh_job.identity)
|
||||
.await
|
||||
{
|
||||
Ok(()) => {
|
||||
match AssertUnwindSafe(provider.fetch_recommended_models(
|
||||
crate::model_config::global_toolshim(),
|
||||
))
|
||||
.catch_unwind()
|
||||
.await
|
||||
match AssertUnwindSafe(provider.fetch_recommended_models(toolshim))
|
||||
.catch_unwind()
|
||||
.await
|
||||
{
|
||||
Ok(Ok(models)) => Ok(models),
|
||||
Ok(Err(error)) => Err(anyhow::anyhow!(error.to_string())),
|
||||
@@ -741,6 +743,7 @@ impl ProviderInventoryService {
|
||||
config_keys: metadata.config_keys.clone(),
|
||||
setup_steps: metadata.setup_steps.clone(),
|
||||
supports_refresh: entry.supports_inventory_refresh(),
|
||||
toolshim: entry.toolshim_enabled(crate::model_config::global_toolshim()),
|
||||
static_models: metadata.known_models,
|
||||
}))
|
||||
}
|
||||
@@ -955,6 +958,10 @@ pub fn declarative_inventory_identity(
|
||||
"skip_canonical_filtering".to_string(),
|
||||
config.skip_canonical_filtering.to_string(),
|
||||
);
|
||||
identity.public_inputs.insert(
|
||||
"toolshim".to_string(),
|
||||
(config.toolshim || crate::model_config::global_toolshim()).to_string(),
|
||||
);
|
||||
if !config.models.is_empty() {
|
||||
identity.public_inputs.insert(
|
||||
"models".to_string(),
|
||||
|
||||
@@ -486,6 +486,7 @@ mod tests {
|
||||
skip_canonical_filtering: false,
|
||||
model_doc_link: None,
|
||||
setup_steps: vec![],
|
||||
toolshim: false,
|
||||
preserves_thinking: true,
|
||||
emit_clear_thinking: false,
|
||||
setup: None,
|
||||
|
||||
@@ -32,6 +32,7 @@ pub struct ProviderEntry {
|
||||
provider_type: ProviderType,
|
||||
supports_inventory_refresh: bool,
|
||||
tls_config: Option<TlsConfig>,
|
||||
toolshim: bool,
|
||||
}
|
||||
|
||||
impl ProviderEntry {
|
||||
@@ -55,7 +56,14 @@ impl ProviderEntry {
|
||||
(self.inventory_configured)()
|
||||
}
|
||||
|
||||
pub fn normalize_model_config(&self, model: ModelConfig) -> Result<ModelConfig> {
|
||||
pub(crate) fn toolshim_enabled(&self, fallback: bool) -> bool {
|
||||
self.toolshim || fallback
|
||||
}
|
||||
|
||||
pub fn normalize_model_config(&self, mut model: ModelConfig) -> Result<ModelConfig> {
|
||||
if self.toolshim_enabled(model.toolshim) {
|
||||
model = model.with_toolshim(true);
|
||||
}
|
||||
crate::model_config::materialize_model_config(&self.metadata.name, model)
|
||||
}
|
||||
|
||||
@@ -145,6 +153,7 @@ impl ProviderRegistry {
|
||||
},
|
||||
supports_inventory_refresh: inventory.supports_refresh,
|
||||
tls_config: self.tls_config.clone(),
|
||||
toolshim: false,
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -309,6 +318,7 @@ impl ProviderRegistry {
|
||||
provider_type,
|
||||
supports_inventory_refresh,
|
||||
tls_config: self.tls_config.clone(),
|
||||
toolshim: config.toolshim,
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -379,6 +389,7 @@ mod tests {
|
||||
skip_canonical_filtering: false,
|
||||
model_doc_link: None,
|
||||
setup_steps: vec![],
|
||||
toolshim: false,
|
||||
preserves_thinking: false,
|
||||
emit_clear_thinking: false,
|
||||
setup: None,
|
||||
@@ -403,4 +414,38 @@ mod tests {
|
||||
assert!(entry.metadata().setup.is_none());
|
||||
assert!(entry.metadata().deprecated.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_provider_toolshim_uses_global_setting_as_fallback() {
|
||||
let mut registry = ProviderRegistry::new(None);
|
||||
for (name, toolshim) in [("custom_toolshim", true), ("custom_default", false)] {
|
||||
let mut config = test_config();
|
||||
config.name = name.to_string();
|
||||
config.toolshim = toolshim;
|
||||
registry.register_with_name::<OpenAiProviderDef, _, _>(
|
||||
&config,
|
||||
ProviderType::Custom,
|
||||
false,
|
||||
|_| unreachable!("constructor is not used by this test"),
|
||||
move || Ok(InventoryIdentityInput::new(name, name)),
|
||||
);
|
||||
}
|
||||
|
||||
let toolshim = registry.entries["custom_toolshim"]
|
||||
.normalize_model_config(ModelConfig::new("test-model"))
|
||||
.unwrap();
|
||||
let fallback_enabled = registry.entries["custom_default"]
|
||||
.normalize_model_config(ModelConfig::new("test-model").with_toolshim(true))
|
||||
.unwrap();
|
||||
let fallback_disabled = registry.entries["custom_default"]
|
||||
.normalize_model_config(ModelConfig::new("test-model"))
|
||||
.unwrap();
|
||||
|
||||
assert!(toolshim.toolshim);
|
||||
assert!(fallback_enabled.toolshim);
|
||||
assert!(!fallback_disabled.toolshim);
|
||||
assert!(registry.entries["custom_toolshim"].toolshim_enabled(false));
|
||||
assert!(registry.entries["custom_default"].toolshim_enabled(true));
|
||||
assert!(!registry.entries["custom_default"].toolshim_enabled(false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1416,7 +1416,7 @@ pub async fn run_prompt_model_mismatch<C: Connection>() {
|
||||
// Server starts on gpt-4o; client is configured with TEST_MODEL.
|
||||
// If session_model is seeded from the response, stream() detects the
|
||||
// mismatch and sends set_model(TEST_MODEL) before prompting.
|
||||
let BasicSession { conn: _, .. } = new_basic_session::<C>(config).await;
|
||||
drop(new_basic_session::<C>(config).await);
|
||||
}
|
||||
|
||||
pub async fn run_prompt_skill<C: Connection>() {
|
||||
|
||||
@@ -260,7 +260,8 @@ fn acp_catalog_and_custom_provider_methods_use_core_provider_store() {
|
||||
},
|
||||
"requiresAuth": true,
|
||||
"catalogProviderId": "openai",
|
||||
"basePath": "v1/chat/completions"
|
||||
"basePath": "v1/chat/completions",
|
||||
"toolshim": true
|
||||
}),
|
||||
)
|
||||
.await
|
||||
@@ -305,6 +306,7 @@ fn acp_catalog_and_custom_provider_methods_use_core_provider_store() {
|
||||
assert_eq!(saved_provider.name, provider_id);
|
||||
assert_eq!(saved_provider.display_name, "Stark ACP Provider");
|
||||
assert_eq!(saved_provider.base_url, "https://stark.example/v1");
|
||||
assert!(saved_provider.toolshim);
|
||||
assert!(saved_provider.preserves_thinking);
|
||||
assert_eq!(
|
||||
saved_provider
|
||||
@@ -350,6 +352,7 @@ fn acp_catalog_and_custom_provider_methods_use_core_provider_store() {
|
||||
"requiresAuth": true,
|
||||
"catalogProviderId": "openai",
|
||||
"basePath": "v1/chat/completions",
|
||||
"toolshim": true,
|
||||
"apiKeyEnv": "CUSTOM_STARK_ACP_PROVIDER_API_KEY",
|
||||
"apiKeySet": true,
|
||||
"preservesThinking": true,
|
||||
@@ -386,6 +389,7 @@ fn acp_catalog_and_custom_provider_methods_use_core_provider_store() {
|
||||
"headers": {},
|
||||
"requiresAuth": true,
|
||||
"catalogProviderId": "zai",
|
||||
"toolshim": true,
|
||||
"preservesThinking": false
|
||||
}),
|
||||
)
|
||||
@@ -417,6 +421,7 @@ fn acp_catalog_and_custom_provider_methods_use_core_provider_store() {
|
||||
);
|
||||
assert_eq!(updated_provider.base_path, None);
|
||||
assert_eq!(updated_provider.headers, None);
|
||||
assert!(updated_provider.toolshim);
|
||||
assert!(!updated_provider.preserves_thinking);
|
||||
assert_eq!(
|
||||
updated_provider
|
||||
@@ -440,7 +445,8 @@ fn acp_catalog_and_custom_provider_methods_use_core_provider_store() {
|
||||
"supportsStreaming": false,
|
||||
"headers": {},
|
||||
"requiresAuth": false,
|
||||
"catalogProviderId": "zai"
|
||||
"catalogProviderId": "zai",
|
||||
"toolshim": false
|
||||
}),
|
||||
)
|
||||
.await
|
||||
@@ -458,6 +464,7 @@ fn acp_catalog_and_custom_provider_methods_use_core_provider_store() {
|
||||
.expect("no-auth provider should remain core-compatible");
|
||||
assert!(!no_auth_provider.requires_auth);
|
||||
assert_eq!(no_auth_provider.api_key_env, "");
|
||||
assert!(!no_auth_provider.toolshim);
|
||||
assert!(!no_auth_provider.preserves_thinking);
|
||||
assert!(
|
||||
matches!(
|
||||
@@ -480,7 +487,8 @@ fn acp_catalog_and_custom_provider_methods_use_core_provider_store() {
|
||||
"supportsStreaming": false,
|
||||
"headers": {},
|
||||
"requiresAuth": true,
|
||||
"catalogProviderId": "zai"
|
||||
"catalogProviderId": "zai",
|
||||
"toolshim": false
|
||||
}),
|
||||
)
|
||||
.await
|
||||
@@ -600,7 +608,8 @@ fn acp_catalog_and_custom_provider_methods_use_core_provider_store() {
|
||||
"apiKey": "secret",
|
||||
"models": ["model-a"],
|
||||
"headers": {},
|
||||
"requiresAuth": true
|
||||
"requiresAuth": true,
|
||||
"toolshim": false
|
||||
});
|
||||
let payload_obj = payload.as_object_mut().unwrap();
|
||||
for (key, value) in patch.as_object().unwrap() {
|
||||
@@ -630,7 +639,8 @@ fn acp_catalog_and_custom_provider_methods_use_core_provider_store() {
|
||||
"apiKey": "owned-secret",
|
||||
"models": ["model-a"],
|
||||
"headers": {},
|
||||
"requiresAuth": true
|
||||
"requiresAuth": true,
|
||||
"toolshim": false
|
||||
}),
|
||||
)
|
||||
.await
|
||||
@@ -663,7 +673,8 @@ fn acp_catalog_and_custom_provider_methods_use_core_provider_store() {
|
||||
"apiUrl": "https://api.example.test/v1",
|
||||
"models": ["model-a"],
|
||||
"headers": {},
|
||||
"requiresAuth": false
|
||||
"requiresAuth": false,
|
||||
"toolshim": false
|
||||
}),
|
||||
)
|
||||
.await
|
||||
@@ -685,7 +696,8 @@ fn acp_catalog_and_custom_provider_methods_use_core_provider_store() {
|
||||
"apiKey": "owned-secret",
|
||||
"models": ["model-a"],
|
||||
"headers": {},
|
||||
"requiresAuth": true
|
||||
"requiresAuth": true,
|
||||
"toolshim": false
|
||||
}),
|
||||
)
|
||||
.await
|
||||
|
||||
@@ -35,6 +35,7 @@ fn custom_config_with_auth(base_url: &str, auth: AuthConfig) -> DeclarativeProvi
|
||||
skip_canonical_filtering: false,
|
||||
model_doc_link: None,
|
||||
setup_steps: vec![],
|
||||
toolshim: false,
|
||||
preserves_thinking: false,
|
||||
emit_clear_thinking: false,
|
||||
setup: None,
|
||||
|
||||
@@ -304,7 +304,7 @@ async fn test_replayed_session(
|
||||
|
||||
let mut results_path = replay_file_path.clone();
|
||||
results_path.pop();
|
||||
results_path.push(format!("{}.results.json", &replay_file_name));
|
||||
results_path.push(format!("{}.results.json", replay_file_name));
|
||||
|
||||
match mode {
|
||||
TestMode::Record => {
|
||||
|
||||
@@ -91,6 +91,7 @@ function updateRequestToCreate(
|
||||
requiresAuth: request.requires_auth ?? true,
|
||||
catalogProviderId: request.catalog_provider_id ?? null,
|
||||
basePath: request.base_path ?? null,
|
||||
toolshim: request.toolshim,
|
||||
preservesThinking: request.preserves_thinking ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -298,6 +298,7 @@ function ProviderCards({
|
||||
requires_auth: editingProvider.config.requiresAuth ?? true,
|
||||
headers: editingProvider.config.headers ?? undefined,
|
||||
catalog_provider_id: editingProvider.config.catalogProviderId ?? undefined,
|
||||
toolshim: editingProvider.config.toolshim,
|
||||
};
|
||||
|
||||
const editable = editingProvider ? editingProvider.isEditable : true;
|
||||
|
||||
+1
@@ -185,6 +185,7 @@ describe('CustomProviderForm transitions', () => {
|
||||
models: ['model-a'],
|
||||
supports_streaming: true,
|
||||
requires_auth: true,
|
||||
toolshim: false,
|
||||
}}
|
||||
isEditable
|
||||
onSubmit={onSubmit}
|
||||
|
||||
+32
-12
@@ -144,6 +144,10 @@ const i18n = defineMessages({
|
||||
id: 'customProviderForm.supportsStreaming',
|
||||
defaultMessage: 'Provider supports streaming responses',
|
||||
},
|
||||
alwaysUseToolshim: {
|
||||
id: 'customProviderForm.alwaysUseToolshim',
|
||||
defaultMessage: 'Always use Toolshim for this provider',
|
||||
},
|
||||
customHeaders: {
|
||||
id: 'customProviderForm.customHeaders',
|
||||
defaultMessage: 'Custom Headers',
|
||||
@@ -272,6 +276,7 @@ export default function CustomProviderForm({
|
||||
const [models, setModels] = useState('');
|
||||
const [requiresAuth, setRequiresAuth] = useState(false);
|
||||
const [supportsStreaming, setSupportsStreaming] = useState(true);
|
||||
const [toolshim, setToolshim] = useState(false);
|
||||
const [headers, setHeaders] = useState<{ key: string; value: string }[]>([]);
|
||||
const [newHeaderKey, setNewHeaderKey] = useState('');
|
||||
const [newHeaderValue, setNewHeaderValue] = useState('');
|
||||
@@ -309,6 +314,7 @@ export default function CustomProviderForm({
|
||||
setBasePath(initialData.base_path ?? '');
|
||||
setModels(initialData.models.join(', '));
|
||||
setSupportsStreaming(initialData.supports_streaming ?? true);
|
||||
setToolshim(initialData.toolshim);
|
||||
setRequiresAuth(initialData.requires_auth ?? true);
|
||||
|
||||
if (initialData.headers) {
|
||||
@@ -492,6 +498,7 @@ export default function CustomProviderForm({
|
||||
api_key: apiKey,
|
||||
models: modelList,
|
||||
supports_streaming: supportsStreaming,
|
||||
toolshim,
|
||||
requires_auth: requiresAuth,
|
||||
headers: headersObject,
|
||||
catalog_provider_id:
|
||||
@@ -834,19 +841,32 @@ export default function CustomProviderForm({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Streaming */}
|
||||
{isEditable && (
|
||||
<div className="flex items-center space-x-2 mb-10">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="supports-streaming"
|
||||
checked={supportsStreaming}
|
||||
onChange={(e) => setSupportsStreaming(e.target.checked)}
|
||||
className="rounded border-border-primary"
|
||||
/>
|
||||
<label htmlFor="supports-streaming" className="text-sm text-text-secondary">
|
||||
{intl.formatMessage(i18n.supportsStreaming)}
|
||||
</label>
|
||||
<div className="space-y-3 mb-10">
|
||||
<div className="flex items-center space-x-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="supports-streaming"
|
||||
checked={supportsStreaming}
|
||||
onChange={(e) => setSupportsStreaming(e.target.checked)}
|
||||
className="rounded border-border-primary"
|
||||
/>
|
||||
<label htmlFor="supports-streaming" className="text-sm text-text-secondary">
|
||||
{intl.formatMessage(i18n.supportsStreaming)}
|
||||
</label>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="always-use-toolshim"
|
||||
checked={toolshim}
|
||||
onChange={(e) => setToolshim(e.target.checked)}
|
||||
className="rounded border-border-primary"
|
||||
/>
|
||||
<label htmlFor="always-use-toolshim" className="text-sm text-text-secondary">
|
||||
{intl.formatMessage(i18n.alwaysUseToolshim)}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
@@ -617,6 +617,9 @@
|
||||
"customProviderForm.add": {
|
||||
"defaultMessage": "Hinzufügen"
|
||||
},
|
||||
"customProviderForm.alwaysUseToolshim": {
|
||||
"defaultMessage": "Toolshim für diesen Anbieter immer verwenden"
|
||||
},
|
||||
"customProviderForm.anthropicCompatible": {
|
||||
"defaultMessage": "Anthropic-kompatibel"
|
||||
},
|
||||
|
||||
@@ -638,6 +638,9 @@
|
||||
"customProviderForm.add": {
|
||||
"defaultMessage": "Add"
|
||||
},
|
||||
"customProviderForm.alwaysUseToolshim": {
|
||||
"defaultMessage": "Always use Toolshim for this provider"
|
||||
},
|
||||
"customProviderForm.anthropicCompatible": {
|
||||
"defaultMessage": "Anthropic Compatible"
|
||||
},
|
||||
|
||||
@@ -617,6 +617,9 @@
|
||||
"customProviderForm.add": {
|
||||
"defaultMessage": "Agregar"
|
||||
},
|
||||
"customProviderForm.alwaysUseToolshim": {
|
||||
"defaultMessage": "Usar siempre Toolshim para este proveedor"
|
||||
},
|
||||
"customProviderForm.anthropicCompatible": {
|
||||
"defaultMessage": "Compatible con Anthropic"
|
||||
},
|
||||
|
||||
@@ -617,6 +617,9 @@
|
||||
"customProviderForm.add": {
|
||||
"defaultMessage": "Ajouter"
|
||||
},
|
||||
"customProviderForm.alwaysUseToolshim": {
|
||||
"defaultMessage": "Toujours utiliser Toolshim pour ce fournisseur"
|
||||
},
|
||||
"customProviderForm.anthropicCompatible": {
|
||||
"defaultMessage": "Compatible Anthropic"
|
||||
},
|
||||
|
||||
@@ -617,6 +617,9 @@
|
||||
"customProviderForm.add": {
|
||||
"defaultMessage": "जोड़ें"
|
||||
},
|
||||
"customProviderForm.alwaysUseToolshim": {
|
||||
"defaultMessage": "इस प्रदाता के लिए हमेशा Toolshim का उपयोग करें"
|
||||
},
|
||||
"customProviderForm.anthropicCompatible": {
|
||||
"defaultMessage": "Anthropic संगत"
|
||||
},
|
||||
|
||||
@@ -617,6 +617,9 @@
|
||||
"customProviderForm.add": {
|
||||
"defaultMessage": "Tambah"
|
||||
},
|
||||
"customProviderForm.alwaysUseToolshim": {
|
||||
"defaultMessage": "Selalu gunakan Toolshim untuk penyedia ini"
|
||||
},
|
||||
"customProviderForm.anthropicCompatible": {
|
||||
"defaultMessage": "Kompatibel dengan Anthropic"
|
||||
},
|
||||
|
||||
@@ -617,6 +617,9 @@
|
||||
"customProviderForm.add": {
|
||||
"defaultMessage": "Aggiungi"
|
||||
},
|
||||
"customProviderForm.alwaysUseToolshim": {
|
||||
"defaultMessage": "Usa sempre Toolshim per questo provider"
|
||||
},
|
||||
"customProviderForm.anthropicCompatible": {
|
||||
"defaultMessage": "Compatibile con Anthropic"
|
||||
},
|
||||
|
||||
@@ -617,6 +617,9 @@
|
||||
"customProviderForm.add": {
|
||||
"defaultMessage": "追加"
|
||||
},
|
||||
"customProviderForm.alwaysUseToolshim": {
|
||||
"defaultMessage": "このプロバイダーでは常にToolshimを使用する"
|
||||
},
|
||||
"customProviderForm.anthropicCompatible": {
|
||||
"defaultMessage": "Anthropic互換"
|
||||
},
|
||||
|
||||
@@ -617,6 +617,9 @@
|
||||
"customProviderForm.add": {
|
||||
"defaultMessage": "추가"
|
||||
},
|
||||
"customProviderForm.alwaysUseToolshim": {
|
||||
"defaultMessage": "이 제공업체에 항상 Toolshim 사용"
|
||||
},
|
||||
"customProviderForm.anthropicCompatible": {
|
||||
"defaultMessage": "Anthropic 호환"
|
||||
},
|
||||
|
||||
@@ -617,6 +617,9 @@
|
||||
"customProviderForm.add": {
|
||||
"defaultMessage": "Tambah"
|
||||
},
|
||||
"customProviderForm.alwaysUseToolshim": {
|
||||
"defaultMessage": "Sentiasa gunakan Toolshim untuk pembekal ini"
|
||||
},
|
||||
"customProviderForm.anthropicCompatible": {
|
||||
"defaultMessage": "Serasi Anthropic"
|
||||
},
|
||||
|
||||
@@ -617,6 +617,9 @@
|
||||
"customProviderForm.add": {
|
||||
"defaultMessage": "Adicionar"
|
||||
},
|
||||
"customProviderForm.alwaysUseToolshim": {
|
||||
"defaultMessage": "Usar sempre o Toolshim para este fornecedor"
|
||||
},
|
||||
"customProviderForm.anthropicCompatible": {
|
||||
"defaultMessage": "Compatível com Anthropic"
|
||||
},
|
||||
|
||||
@@ -617,6 +617,9 @@
|
||||
"customProviderForm.add": {
|
||||
"defaultMessage": "Добавить"
|
||||
},
|
||||
"customProviderForm.alwaysUseToolshim": {
|
||||
"defaultMessage": "Всегда использовать Toolshim для этого провайдера"
|
||||
},
|
||||
"customProviderForm.anthropicCompatible": {
|
||||
"defaultMessage": "Совместимо с Anthropic"
|
||||
},
|
||||
|
||||
@@ -617,6 +617,9 @@
|
||||
"customProviderForm.add": {
|
||||
"defaultMessage": "Ekle"
|
||||
},
|
||||
"customProviderForm.alwaysUseToolshim": {
|
||||
"defaultMessage": "Bu sağlayıcı için her zaman Toolshim kullan"
|
||||
},
|
||||
"customProviderForm.anthropicCompatible": {
|
||||
"defaultMessage": "Anthropic Uyumlu"
|
||||
},
|
||||
|
||||
@@ -617,6 +617,9 @@
|
||||
"customProviderForm.add": {
|
||||
"defaultMessage": "Thêm"
|
||||
},
|
||||
"customProviderForm.alwaysUseToolshim": {
|
||||
"defaultMessage": "Luôn sử dụng Toolshim cho nhà cung cấp này"
|
||||
},
|
||||
"customProviderForm.anthropicCompatible": {
|
||||
"defaultMessage": "Tương thích Anthropic"
|
||||
},
|
||||
|
||||
@@ -617,6 +617,9 @@
|
||||
"customProviderForm.add": {
|
||||
"defaultMessage": "添加"
|
||||
},
|
||||
"customProviderForm.alwaysUseToolshim": {
|
||||
"defaultMessage": "始终为此提供商使用 Toolshim"
|
||||
},
|
||||
"customProviderForm.anthropicCompatible": {
|
||||
"defaultMessage": "Anthropic 兼容"
|
||||
},
|
||||
|
||||
@@ -617,6 +617,9 @@
|
||||
"customProviderForm.add": {
|
||||
"defaultMessage": "新增"
|
||||
},
|
||||
"customProviderForm.alwaysUseToolshim": {
|
||||
"defaultMessage": "一律為此供應商使用 Toolshim"
|
||||
},
|
||||
"customProviderForm.anthropicCompatible": {
|
||||
"defaultMessage": "Anthropic 相容"
|
||||
},
|
||||
|
||||
@@ -62,4 +62,5 @@ export type UpdateCustomProviderRequest = {
|
||||
preserves_thinking?: boolean | null;
|
||||
requires_auth?: boolean;
|
||||
supports_streaming?: boolean | null;
|
||||
toolshim: boolean;
|
||||
};
|
||||
|
||||
@@ -1084,6 +1084,7 @@ export type CustomProviderCreateRequest_unstable = {
|
||||
catalogProviderId?: string | null;
|
||||
basePath?: string | null;
|
||||
preservesThinking?: boolean | null;
|
||||
toolshim: boolean;
|
||||
};
|
||||
|
||||
export type CustomProviderCreateResponse_unstable = {
|
||||
@@ -1144,6 +1145,7 @@ export type CustomProviderConfigDto = {
|
||||
requiresAuth: boolean;
|
||||
catalogProviderId?: string | null;
|
||||
basePath?: string | null;
|
||||
toolshim: boolean;
|
||||
apiKeyEnv?: string | null;
|
||||
apiKeySet: boolean;
|
||||
preservesThinking: boolean;
|
||||
@@ -1167,6 +1169,7 @@ export type CustomProviderUpdateRequest_unstable = {
|
||||
catalogProviderId?: string | null;
|
||||
basePath?: string | null;
|
||||
preservesThinking?: boolean | null;
|
||||
toolshim: boolean;
|
||||
};
|
||||
|
||||
export type CustomProviderUpdateResponse_unstable = {
|
||||
|
||||
@@ -746,7 +746,8 @@ export const zCustomProviderCreateRequest_unstable = z.object({
|
||||
requiresAuth: z.boolean(),
|
||||
catalogProviderId: z.string().nullish(),
|
||||
basePath: z.string().nullish(),
|
||||
preservesThinking: z.boolean().nullish()
|
||||
preservesThinking: z.boolean().nullish(),
|
||||
toolshim: z.boolean()
|
||||
});
|
||||
|
||||
export const zProviderConfigStatusDto = z.object({
|
||||
@@ -798,6 +799,7 @@ export const zCustomProviderConfigDto = z.object({
|
||||
requiresAuth: z.boolean(),
|
||||
catalogProviderId: z.string().nullish(),
|
||||
basePath: z.string().nullish(),
|
||||
toolshim: z.boolean(),
|
||||
apiKeyEnv: z.string().nullish(),
|
||||
apiKeySet: z.boolean(),
|
||||
preservesThinking: z.boolean()
|
||||
@@ -824,7 +826,8 @@ export const zCustomProviderUpdateRequest_unstable = z.object({
|
||||
requiresAuth: z.boolean(),
|
||||
catalogProviderId: z.string().nullish(),
|
||||
basePath: z.string().nullish(),
|
||||
preservesThinking: z.boolean().nullish()
|
||||
preservesThinking: z.boolean().nullish(),
|
||||
toolshim: z.boolean()
|
||||
});
|
||||
|
||||
export const zCustomProviderUpdateResponse_unstable = z.object({
|
||||
|
||||
Reference in New Issue
Block a user