Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ version-compare = "0.1"
vte = { git = "https://github.com/warpdotdev/vte.git", rev = "4b399c87b63ba88f45709edaa6383fc519f6c900", default-features = false }
walkdir = "2"
warp-workflows = { git = "https://github.com/warpdotdev/workflows", rev = "793a98ddda6ef19682aed66364faebd2829f0e01" }
warp_multi_agent_api = { git = "https://github.com/warpdotdev/warp-proto-apis.git", rev = "8320a94875bce9e730d9bfc4abda1544279e5db3" }
warp_multi_agent_api = { git = "https://github.com/warpdotdev/warp-proto-apis.git", rev = "1766ae05d1a6" }
wasm-bindgen = "0.2.89"
wasm-bindgen-futures = "0.4.42"
web-sys = { version = "0.3.69", features = [
Expand Down
26 changes: 15 additions & 11 deletions app/src/ai/agent/conversation_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::collections::HashMap;

use ai::api_keys::{ApiKeyManager, CustomEndpointParams, CustomEndpointSchema};
use ai::api_keys::{
ApiKeyManager, CustomEndpointModel, CustomEndpointParams, CustomEndpointSchema,
};
use warp_core::features::FeatureFlag;
use warp_multi_agent_api as api;
use warpui::{App, SingletonEntity};
Expand Down Expand Up @@ -771,11 +773,12 @@ fn update_cost_and_usage_resolves_custom_endpoint_alias_for_footer_usage() {
name: "Endpoint".to_string(),
url: "https://custom.example".to_string(),
api_key: "key".to_string(),
models: vec![(
"raw-model".to_string(),
Some("Friendly alias".to_string()),
Some("config-key".to_string()),
)],
models: vec![CustomEndpointModel {
name: "raw-model".to_string(),
alias: Some("Friendly alias".to_string()),
config_key: "config-key".to_string(),
..Default::default()
}],
schema: CustomEndpointSchema::default(),
},
ctx,
Expand Down Expand Up @@ -1031,11 +1034,12 @@ fn footer_model_token_usage_keeps_custom_endpoint_usage_distinct_from_same_label
name: "Endpoint".to_string(),
url: "https://custom.example".to_string(),
api_key: "key".to_string(),
models: vec![(
"raw-model".to_string(),
Some("Resolved custom".to_string()),
Some("config-key".to_string()),
)],
models: vec![CustomEndpointModel {
name: "raw-model".to_string(),
alias: Some("Resolved custom".to_string()),
config_key: "config-key".to_string(),
..Default::default()
}],
schema: CustomEndpointSchema::default(),
},
ctx,
Expand Down
9 changes: 6 additions & 3 deletions app/src/ai/blocklist/controller_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::sync::{Arc, Mutex};
use std::time::SystemTime;

use ai::api_keys::{
ApiKeyManager, AwsCredentials, AwsCredentialsState, CustomEndpointParams, GeapCredentials,
GeapCredentialsState,
ApiKeyManager, AwsCredentials, AwsCredentialsState, CustomEndpointModel, CustomEndpointParams,
GeapCredentials, GeapCredentialsState,
};
use chrono::Local;
use uuid::Uuid;
Expand Down Expand Up @@ -973,7 +973,10 @@ fn passive_suggestions_request_params_scope_member_byo_credentials_by_the_window
name: "member-endpoint".to_string(),
url: "https://example.com/v1".to_string(),
api_key: "endpoint-key".to_string(),
models: vec![("member-model".to_string(), None, None)],
models: vec![CustomEndpointModel {
name: "member-model".to_string(),
..Default::default()
}],
schema: Default::default(),
},
ctx,
Expand Down
16 changes: 8 additions & 8 deletions app/src/ai/custom_endpoints.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ai::api_keys::{
ApiKeyManager, CustomEndpointDefinition, CustomEndpointDefinitions, CustomEndpointId,
CustomEndpointModel, CustomEndpointParams,
CustomEndpointParams,
};
use settings::Setting;
use uuid::Uuid;
Expand Down Expand Up @@ -151,7 +151,8 @@ pub(crate) fn save(
.id_at(index)
.cloned()
.ok_or_else(|| anyhow::anyhow!("custom endpoint index is out of bounds"))?;
definitions.insert(id.clone(), definition_from_params(params.clone()))?;
let definition = definition_from_params(params.clone());
definitions.insert(id.clone(), definition)?;
let old_key = ApiKeyManager::as_ref(ctx)
.custom_endpoint_key(&id)
.map(ToOwned::to_owned);
Expand Down Expand Up @@ -191,12 +192,11 @@ fn definition_from_params(params: CustomEndpointParams) -> CustomEndpointDefinit
models: params
.models
.into_iter()
.map(|(name, alias, config_key)| CustomEndpointModel {
name,
alias,
config_key: config_key
.filter(|key| !key.trim().is_empty())
.unwrap_or_else(|| Uuid::new_v4().to_string()),
.map(|mut model| {
if model.config_key.trim().is_empty() {
model.config_key = Uuid::new_v4().to_string();
}
model
})
.collect(),
}
Expand Down
36 changes: 35 additions & 1 deletion app/src/ai/custom_endpoints_tests.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,47 @@
use std::cell::Cell;
use std::rc::Rc;

use ai::api_keys::CustomEndpointSchema;
use ai::api_keys::{ComputerUseToolset, CustomEndpointModel, CustomEndpointSchema};
use settings::Setting as _;
use warpui::{App, SingletonEntity as _};
use warpui_extras::secure_storage;

use super::*;
use crate::settings::init_and_register_user_preferences;

#[test]
Comment thread
warp-agent-staging[bot] marked this conversation as resolved.
fn endpoint_params_supply_toolsets_for_existing_and_new_models() {
let edited = definition_from_params(CustomEndpointParams {
name: "Renamed gateway".into(),
url: "https://gateway.example/v1".into(),
api_key: "rotated-key".into(),
schema: CustomEndpointSchema::AnthropicMessages,
models: vec![
CustomEndpointModel {
name: "model".into(),
alias: Some("Alias".into()),
config_key: "pinned-key".into(),
computer_use_toolset: ComputerUseToolset::None,
},
CustomEndpointModel {
name: "new".into(),
computer_use_toolset: ComputerUseToolset::AnthropicComputer20251124,
..Default::default()
},
],
});
assert_eq!(edited.models[0].config_key, "pinned-key");
assert!(!edited.models[1].config_key.is_empty());
assert_eq!(
edited.models[0].computer_use_toolset,
ComputerUseToolset::None
);
assert_eq!(
edited.models[1].computer_use_toolset,
ComputerUseToolset::AnthropicComputer20251124
);
}

struct FailingSecureStorage {
write_attempts: Rc<Cell<usize>>,
}
Expand Down Expand Up @@ -57,6 +90,7 @@ fn removal_succeeds_when_credential_cleanup_fails() {
name: "model".to_owned(),
alias: None,
config_key: "config-key".to_owned(),
computer_use_toolset: Default::default(),
}],
},
)
Expand Down
26 changes: 18 additions & 8 deletions app/src/ai/llms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,19 +1242,29 @@ impl LLMPreferences {
let profile = AIExecutionProfilesModel::as_ref(app).active_profile(terminal_view_id, app);

let available = self.get_computer_use_available(scope.team_uid(), app);
let selected_model = terminal_view_id
.and_then(|id| self.computer_use_llm_for_terminal_view.get(&id))
.map(Option::as_ref)
.unwrap_or_else(|| profile.data().computer_use_model.as_ref());
selected_model
.and_then(|id| available.info_for_id(id))
if let Some(selection) =
terminal_view_id.and_then(|id| self.computer_use_llm_for_terminal_view.get(&id))
{
match selection {
Some(id) => {
if let Some(info) = self.usable_model_info_for_id(available, id, app) {
return info;
}
}
None => return self.get_default_computer_use_model(scope, app),
}
}
profile
.data()
.computer_use_model
.as_ref()
.and_then(|id| self.usable_model_info_for_id(available, id, app))
.unwrap_or_else(|| self.get_default_computer_use_model(scope, app))
}

/// Returns the effective default computer use model as a fallback: the
/// server default when usable, else the first usable choice, else the
/// (possibly disabled) server default. No custom-endpoint fallback here:
/// custom models aren't offered for computer use.
/// (possibly disabled) server default. Custom endpoints are only used when explicitly selected.
pub fn get_default_computer_use_model<'a>(
&'a self,
scope: &(impl TeamScope + ?Sized),
Expand Down
57 changes: 45 additions & 12 deletions app/src/ai/llms_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ fn model(name: &str, alias: Option<&str>, config_key: &str) -> CustomEndpointMod
name: name.into(),
alias: alias.map(|s| s.into()),
config_key: config_key.into(),
computer_use_toolset: Default::default(),
}
}

Expand Down Expand Up @@ -634,11 +635,11 @@ fn active_models_fall_back_to_usable_choice_or_custom_endpoint_when_default_disa
name: "local".to_string(),
url: "https://example.com/v1".to_string(),
api_key: "test-key".to_string(),
models: vec![(
"custom-model".to_string(),
None,
Some(custom_model_id.to_string()),
)],
models: vec![CustomEndpointModel {
name: "custom-model".to_string(),
config_key: custom_model_id.to_string(),
..Default::default()
}],
schema: ai::api_keys::CustomEndpointSchema::default(),
},
ctx,
Expand Down Expand Up @@ -819,11 +820,12 @@ fn reconcile_preserves_custom_models_saved_on_execution_profile() {
name: "local".to_string(),
url: "https://example.com/v1".to_string(),
api_key: "test-key".to_string(),
models: vec![(
"custom-model".to_string(),
Some("Custom Model".to_string()),
Some(custom_model_id.to_string()),
)],
models: vec![CustomEndpointModel {
name: "custom-model".to_string(),
alias: Some("Custom Model".to_string()),
config_key: custom_model_id.to_string(),
..Default::default()
}],
schema: ai::api_keys::CustomEndpointSchema::default(),
},
ctx,
Expand Down Expand Up @@ -1398,6 +1400,30 @@ fn resetting_profiles_clears_session_computer_use() {
});
}

#[cfg(not(target_family = "wasm"))]
#[test]
fn computer_use_model_falls_back_when_the_profile_is_unavailable() {
with_computer_use_test_context(|app| {
AIExecutionProfilesModel::handle(app).update(app, |profiles, ctx| {
profiles.set_computer_use_model(
&profiles.default_profile_id(),
Some("unknown-model".into()),
ctx,
);
});

LLMPreferences::handle(app).read(app, |preferences, ctx| {
assert_eq!(
preferences
.get_active_computer_use_model(&TeamlessScopeForTest, ctx, None)
.id
.as_str(),
"computer-use-agent-auto"
);
});
});
}

#[cfg(not(target_family = "wasm"))]
#[test]
fn computer_use_model_override_takes_precedence_over_the_profile() {
Expand Down Expand Up @@ -1541,10 +1567,17 @@ fn clearing_computer_use_model_override_restores_the_profile_model() {

#[cfg(not(target_family = "wasm"))]
#[test]
fn computer_use_model_override_falls_back_to_default_for_an_unknown_model() {
fn computer_use_model_falls_back_when_the_override_is_unavailable() {
with_computer_use_test_context(|app| {
let preferences = LLMPreferences::handle(app);
let terminal_view_id = EntityId::new();
AIExecutionProfilesModel::handle(app).update(app, |profiles, ctx| {
profiles.set_computer_use_model(
&profiles.default_profile_id(),
Some("profile-model".into()),
ctx,
);
});

preferences.update(app, |preferences, _| {
preferences
Expand All @@ -1561,7 +1594,7 @@ fn computer_use_model_override_falls_back_to_default_for_an_unknown_model() {
)
.id
.as_str(),
"computer-use-agent-auto"
"profile-model"
);
});
});
Expand Down
Loading
Loading