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
1 change: 1 addition & 0 deletions src-tauri/src/provider/claude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ fn migrate_v1(v1: ClaudeV1Settings) -> Vec<CustomProvider> {
label: slug.clone(),
slug,
effort_levels: Vec::new(),
..Default::default()
})
.collect(),
..Default::default()
Expand Down
41 changes: 40 additions & 1 deletion src-tauri/src/provider/codex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
//! never touches `~/.codex/config.toml`. Each provider is its own catalog id
//! (`codex:<id>`) since Codex binds the provider at thread start (no mid-thread switch).

use super::types::{is_enabled, CustomProvider, CustomProviderModel};
use super::types::{
is_enabled, CustomProvider, CustomProviderModel, InterleavedConfig, ModelCost,
ModelLimit, ModelModalities, ModelStatus,
};
use super::CustomProviderBackend;

const SETTINGS_KEY: &str = "app.codex_custom_providers";
Expand Down Expand Up @@ -192,6 +195,41 @@ pub(super) fn parse_models_response(
slug: slug.to_string(),
label,
effort_levels: Vec::new(),
reasoning: item.get("reasoning").and_then(serde_json::Value::as_bool),
tool_call: item.get("tool_call").and_then(serde_json::Value::as_bool),
temperature: item.get("temperature").and_then(serde_json::Value::as_bool),
attachment: item.get("attachment").and_then(serde_json::Value::as_bool),
limit: item
.get("limit")
.and_then(|v| serde_json::from_value::<ModelLimit>(v.clone()).ok()),
modalities: item
.get("modalities")
.and_then(|v| serde_json::from_value::<ModelModalities>(v.clone()).ok()),
cost: item
.get("cost")
.and_then(|v| serde_json::from_value::<ModelCost>(v.clone()).ok()),
family: item
.get("family")
.and_then(serde_json::Value::as_str)
.map(str::to_string),
release_date: item
.get("release_date")
.and_then(serde_json::Value::as_str)
.map(str::to_string),
status: item
.get("status")
.and_then(|v| serde_json::from_value::<ModelStatus>(v.clone()).ok()),
interleaved: item
.get("interleaved")
.and_then(|v| serde_json::from_value::<InterleavedConfig>(v.clone()).ok()),
variants: item.get("variants").and_then(|v| {
let obj = v.as_object()?;
let map: std::collections::BTreeMap<String, serde_json::Value> = obj
.iter()
.map(|(k, v)| (k.clone(), v.clone()))
.collect();
Some(map)
}),
});
}
Ok(out)
Expand Down Expand Up @@ -231,6 +269,7 @@ mod tests {
slug: slug.to_string(),
label: slug.to_uppercase(),
effort_levels: Vec::new(),
..Default::default()
}
}

Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/provider/kimi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ fn read_custom_providers() -> Result<Vec<CustomProvider>> {
slug,
label,
effort_levels: Vec::new(),
..Default::default()
});
}
}
Expand Down Expand Up @@ -512,6 +513,7 @@ keep = true
slug: "deepseek-v4-pro".into(),
label: "DeepSeek V4 Pro".into(),
effort_levels: Vec::new(),
..Default::default()
}],
..Default::default()
}
Expand Down
104 changes: 102 additions & 2 deletions src-tauri/src/provider/opencode.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! OpenCode custom-provider backend. File-backed; list/upsert/remove
//! delegate to `opencode_config`. Written models always carry `reasoning: true`.
//! delegate to `opencode_config`.

use super::opencode_config::{self, OpencodeCustomModel, OpencodeCustomProvider};
use super::types::{CustomProvider, CustomProviderModel};
Expand Down Expand Up @@ -37,6 +37,18 @@ fn to_custom(p: OpencodeCustomProvider) -> CustomProvider {
slug: m.id,
label: m.name,
effort_levels: Vec::new(),
reasoning: Some(m.reasoning),
tool_call: Some(m.tool_call),
temperature: Some(m.temperature),
attachment: Some(m.attachment),
limit: m.limit,
modalities: m.modalities,
cost: m.cost,
family: m.family,
release_date: m.release_date,
status: m.status,
interleaved: m.interleaved,
variants: m.variants,
})
.collect(),
enabled_model_ids: None,
Expand All @@ -63,7 +75,19 @@ fn to_opencode(p: CustomProvider) -> OpencodeCustomProvider {
.map(|m| OpencodeCustomModel {
id: m.slug,
name: m.label,
reasoning: true,

reasoning: m.reasoning.unwrap_or(true),
tool_call: m.tool_call.unwrap_or(false),
temperature: m.temperature.unwrap_or(false),
attachment: m.attachment.unwrap_or(false),
family: m.family,
release_date: m.release_date,
status: m.status,
cost: m.cost,
interleaved: m.interleaved,
variants: m.variants,
limit: m.limit,
modalities: m.modalities,
})
.collect(),
}
Expand Down Expand Up @@ -117,6 +141,7 @@ mod tests {
slug: "m".to_string(),
label: "M".to_string(),
effort_levels: Vec::new(),
..Default::default()
}],
enabled_model_ids: None,
..Default::default()
Expand All @@ -128,6 +153,10 @@ mod tests {
assert_eq!(back.api_style.as_deref(), Some("responses"));
assert_eq!(back.preset_key, None);
assert_eq!(back.models[0].slug, "m");
assert_eq!(back.models[0].reasoning, Some(true));
assert_eq!(back.models[0].tool_call, Some(false));
assert_eq!(back.models[0].temperature, Some(false));
assert_eq!(back.models[0].attachment, Some(false));
}

#[test]
Expand Down Expand Up @@ -160,4 +189,75 @@ mod tests {
};
assert_eq!(to_custom(oc).preset_key, None);
}

#[test]
fn api_silent_fields_fall_back_to_defaults() {
let custom = CustomProvider {
id: "sparse".to_string(),
name: "Sparse".to_string(),
preset_key: None,
base_url: "https://sparse.example.com/v1".to_string(),
api_key: "sk-test".to_string(),
api_style: Some("chat".to_string()),
headers: None,
models: vec![CustomProviderModel {
slug: "m".to_string(),
label: "M".to_string(),
effort_levels: Vec::new(),
..Default::default()
}],
enabled_model_ids: None,
};
let oc = to_opencode(custom);
let m = &oc.models[0];
assert!(m.reasoning);
assert!(!m.tool_call);
assert!(!m.temperature);
assert!(!m.attachment);
assert!(m.limit.is_none());
assert!(m.modalities.is_none());
assert!(m.cost.is_none());
}

#[test]
fn api_fields_override_defaults() {
use crate::provider::types::{ModelLimit, ModelModalities};

let custom = CustomProvider {
id: "rich".to_string(),
name: "Rich".to_string(),
preset_key: None,
base_url: "https://rich.example.com/v1".to_string(),
api_key: "sk-test".to_string(),
api_style: Some("chat".to_string()),
headers: None,
models: vec![CustomProviderModel {
slug: "m".to_string(),
label: "M".to_string(),
effort_levels: Vec::new(),
reasoning: Some(false),
tool_call: Some(true),
temperature: Some(true),
attachment: Some(true),
limit: Some(ModelLimit {
context: 1_000_000,
output: 384_000,
}),
modalities: Some(ModelModalities {
input: vec!["text".to_string(), "image".to_string()],
output: vec!["text".to_string()],
}),
..Default::default()
}],
enabled_model_ids: None,
};
let oc = to_opencode(custom);
let m = &oc.models[0];
assert!(!m.reasoning);
assert!(m.tool_call);
assert!(m.temperature);
assert!(m.attachment);
assert_eq!(m.limit.as_ref().unwrap().context, 1_000_000);
assert_eq!(m.modalities.as_ref().unwrap().input, vec!["text", "image"]);
}
}
Loading
Loading