feat: finalise ticket99 - implémentation agent model configuration v2
- agent/lifecycle.rs: lifecycle management per profile
- agent/provider_catalogue.rs: provider registration with model support
- agent/usecases.rs: usecases for profile-based agent invocation
- agent/mod.rs: expose agent capabilities via AgentManager
- backend/dto.rs: AgentModelConfig, AgentProviderConfig DTOs
- domain/profile.rs: extend Profile avec agent capabilities
- domain/permission.rs: permission checks pour agent access
- infrastructure/assistant/mod.rs: agent integration
- infrastructure/permission/{claude,codex}.rs: permission handlers
- web-server/lib.rs: agent endpoints
- commands.rs: agent commands
- frontend/adapters/{http,profile,mock,domain}.ts: adapters
- frontend/first-run/FirstRunWizard.{test.tsx,tsx}: first-run flow
This commit is contained in:
@ -20,10 +20,7 @@ use domain::ports::{
|
||||
ProfileStore, ProjectStore, PtyPort, RemotePath, SecretStore, SessionPlan, SkillStore,
|
||||
SpawnSpec, StoreError, StructuredProviderLaunchPolicy, SystemPermissionStore,
|
||||
};
|
||||
use domain::profile::{
|
||||
ClaudeProviderConfig, CodexProviderConfig, McpConfigStrategy, OpenCodeProviderConfig,
|
||||
StructuredAdapter,
|
||||
};
|
||||
use domain::profile::{McpConfigStrategy, OpenCodeProviderConfig, StructuredAdapter};
|
||||
use domain::sandbox::{compile_sandbox_plan, SandboxContext, SandboxPlan};
|
||||
use domain::{
|
||||
bound_handoff_summary, Agent, AgentId, AgentManifest, AgentOrigin, AgentProfile,
|
||||
@ -1134,35 +1131,7 @@ fn build_structured_launch_policy(
|
||||
}
|
||||
|
||||
fn projection_model(profile: &AgentProfile) -> Option<&str> {
|
||||
profile
|
||||
.codex_provider
|
||||
.as_ref()
|
||||
.map(|provider| provider.model.as_str())
|
||||
.or_else(|| {
|
||||
profile
|
||||
.claude_provider
|
||||
.as_ref()
|
||||
.map(|provider| provider.model.as_str())
|
||||
})
|
||||
}
|
||||
|
||||
fn projection_model_provider(profile: &AgentProfile) -> Option<&str> {
|
||||
profile
|
||||
.codex_provider
|
||||
.as_ref()
|
||||
.map(|provider| provider.provider_id.as_str())
|
||||
}
|
||||
|
||||
fn projection_model_provider_base_url(profile: &AgentProfile) -> Option<&str> {
|
||||
profile
|
||||
.codex_provider
|
||||
.as_ref()
|
||||
.and_then(|provider| provider.custom.as_ref())
|
||||
.map(|custom| custom.base_url.as_str())
|
||||
}
|
||||
|
||||
fn projection_model_provider_env_key(profile: &AgentProfile) -> Option<&str> {
|
||||
profile.codex_provider.as_ref().map(|_| "OPENAI_API_KEY")
|
||||
profile.model.as_deref()
|
||||
}
|
||||
|
||||
/// Launches an agent: resolve profile + context, prepare the invocation, apply
|
||||
@ -1815,8 +1784,6 @@ impl LaunchAgent {
|
||||
|
||||
self.ensure_local_model_server_for_opencode(&agent, &mut profile)
|
||||
.await?;
|
||||
self.apply_profile_provider_env(&profile, &run_dir, &mut spec)
|
||||
.await?;
|
||||
|
||||
// 5a. ── INJECTION DE LA CONF MCP (cadrage v3, Décision 3) ──
|
||||
// Strictement APRÈS le convention file (étape 5) et AVANT le spawn /
|
||||
@ -2246,9 +2213,6 @@ impl LaunchAgent {
|
||||
project_root: project_root.as_str(),
|
||||
run_dir: run_dir.as_str(),
|
||||
model: projection_model(profile),
|
||||
model_provider: projection_model_provider(profile),
|
||||
model_provider_base_url: projection_model_provider_base_url(profile),
|
||||
model_provider_env_key: projection_model_provider_env_key(profile),
|
||||
};
|
||||
let projection = projector.project(permissions, network, &ctx);
|
||||
|
||||
@ -2483,6 +2447,7 @@ impl LaunchAgent {
|
||||
&declaration,
|
||||
run_dir.as_str(),
|
||||
project_root.as_str(),
|
||||
profile.model.as_deref(),
|
||||
);
|
||||
let _ = self.fs.write(&path, rendered.as_bytes()).await;
|
||||
}
|
||||
@ -2494,6 +2459,7 @@ impl LaunchAgent {
|
||||
&declaration,
|
||||
run_dir.as_str(),
|
||||
project_root.as_str(),
|
||||
profile.model.as_deref(),
|
||||
);
|
||||
let _ = self.fs.write(&path, rendered.as_bytes()).await;
|
||||
}
|
||||
@ -2602,64 +2568,6 @@ impl LaunchAgent {
|
||||
})
|
||||
}
|
||||
|
||||
async fn apply_profile_provider_env(
|
||||
&self,
|
||||
profile: &AgentProfile,
|
||||
run_dir: &ProjectPath,
|
||||
spec: &mut SpawnSpec,
|
||||
) -> Result<(), AppError> {
|
||||
if let Some(provider) = profile.codex_provider.as_ref() {
|
||||
let api_key = self.resolve_codex_provider_api_key(provider).await?;
|
||||
upsert_env(&mut spec.env, "OPENAI_API_KEY", &api_key);
|
||||
upsert_env(&mut spec.env, "CODEX_HOME", &join(run_dir, ".codex"));
|
||||
}
|
||||
if let Some(provider) = profile.claude_provider.as_ref() {
|
||||
let api_key = self.resolve_claude_provider_api_key(provider).await?;
|
||||
upsert_env(&mut spec.env, "ANTHROPIC_API_KEY", &api_key);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn resolve_codex_provider_api_key(
|
||||
&self,
|
||||
provider: &CodexProviderConfig,
|
||||
) -> Result<String, AppError> {
|
||||
let secret_store = self.secret_store.as_ref().ok_or_else(|| {
|
||||
AppError::Invalid("Codex provider profile requires a SecretStore, none injected".into())
|
||||
})?;
|
||||
secret_store
|
||||
.get(&provider.api_key_ref)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
AppError::Invalid(format!(
|
||||
"no secret found for Codex provider `{}` (secret ref `{}`)",
|
||||
provider.provider_id,
|
||||
provider.api_key_ref.as_str()
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
async fn resolve_claude_provider_api_key(
|
||||
&self,
|
||||
provider: &ClaudeProviderConfig,
|
||||
) -> Result<String, AppError> {
|
||||
let secret_store = self.secret_store.as_ref().ok_or_else(|| {
|
||||
AppError::Invalid(
|
||||
"Claude provider profile requires a SecretStore, none injected".into(),
|
||||
)
|
||||
})?;
|
||||
secret_store
|
||||
.get(&provider.api_key_ref)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
AppError::Invalid(format!(
|
||||
"no secret found for Claude provider `{}` (secret ref `{}`)",
|
||||
provider.provider_id,
|
||||
provider.api_key_ref.as_str()
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
async fn ensure_local_model_server_for_opencode(
|
||||
&self,
|
||||
agent: &Agent,
|
||||
@ -3148,6 +3056,11 @@ fn toml_string(s: &str) -> String {
|
||||
format!("\"{}\"", json_escape(s))
|
||||
}
|
||||
|
||||
fn set_top_level_toml_value(input: &str, key: &str, value: &str) -> String {
|
||||
let line = format!("{key} = {}", toml_string(value));
|
||||
set_top_level_toml_line(input, key, &line)
|
||||
}
|
||||
|
||||
/// Renders Codex's `config.toml` **MCP part only** (lot LP3-3 decoupling): merges
|
||||
/// the `[mcp_servers.idea]` table and ensures the run-dir + project-root trust
|
||||
/// entries. The permission part (`sandbox_mode` / `approval_policy` + the
|
||||
@ -3159,8 +3072,12 @@ fn codex_config_toml(
|
||||
mcp_declaration: &str,
|
||||
run_dir: &str,
|
||||
project_root: &str,
|
||||
model: Option<&str>,
|
||||
) -> String {
|
||||
let mut text = existing.unwrap_or_default().to_owned();
|
||||
if let Some(model) = model {
|
||||
text = set_top_level_toml_value(&text, "model", model);
|
||||
}
|
||||
text = replace_toml_table(&text, "mcp_servers.idea", mcp_declaration.trim_end());
|
||||
text = ensure_codex_trust(&text, run_dir);
|
||||
text = ensure_codex_trust(&text, project_root);
|
||||
@ -4585,6 +4502,7 @@ command = "other"
|
||||
"[mcp_servers.idea]\ncommand = \"new\"",
|
||||
"/home/me/proj/.ideai/run/a",
|
||||
"/home/me/proj",
|
||||
Some("gpt-5-codex"),
|
||||
);
|
||||
|
||||
// MCP table + trust entries are the only things this function touches.
|
||||
@ -4593,6 +4511,7 @@ command = "other"
|
||||
assert!(rendered.contains("approval_policy = \"nested\""));
|
||||
assert!(rendered.contains("[mcp_servers.idea]\ncommand = \"new\""));
|
||||
assert!(rendered.contains("[mcp_servers.other]\ncommand = \"other\""));
|
||||
assert!(rendered.contains("model = \"gpt-5-codex\""));
|
||||
assert!(!rendered.contains("command = \"old\""));
|
||||
assert_eq!(rendered.matches("[mcp_servers.idea]").count(), 1);
|
||||
assert_eq!(rendered.matches("[projects.\"/home/me/proj\"]").count(), 1);
|
||||
@ -4607,8 +4526,10 @@ command = "other"
|
||||
"[mcp_servers.idea]\ncommand = \"idea-mcp\"",
|
||||
"/home/me/proj/.ideai/run/a",
|
||||
"/home/me/proj",
|
||||
None,
|
||||
);
|
||||
|
||||
assert!(!rendered.contains("model ="));
|
||||
assert!(!rendered.contains("approval_policy ="));
|
||||
assert!(!rendered.contains("sandbox_mode ="));
|
||||
assert!(rendered.contains("[projects.\"/home/me/proj\"]"));
|
||||
|
||||
@ -40,10 +40,8 @@ pub use lifecycle::{
|
||||
AGENT_MEMORY_RECALL_BUDGET, DEFAULT_OPENCODE_MCP_TIMEOUT_MS, LIVE_STATE_INJECT_MAX,
|
||||
};
|
||||
pub use provider_catalogue::{
|
||||
claude_provider_catalogue, codex_provider_catalogue, opencode_models_cache_path,
|
||||
opencode_provider_catalogue, ClaudeProviderCatalogEntry, CodexProviderCatalogEntry,
|
||||
ListClaudeProviders, ListClaudeProvidersOutput, ListCodexProviders, ListCodexProvidersOutput,
|
||||
ListOpenCodeProviders, ListOpenCodeProvidersOutput, OpenCodeProviderCatalogEntry,
|
||||
opencode_models_cache_path, opencode_provider_catalogue, ListOpenCodeProviders,
|
||||
ListOpenCodeProvidersOutput, OpenCodeProviderCatalogEntry,
|
||||
};
|
||||
pub use resume::{
|
||||
ListResumableAgents, ListResumableAgentsInput, ListResumableAgentsOutput, ResumableAgent,
|
||||
@ -54,8 +52,6 @@ pub use usecases::{
|
||||
ConfigureProfilesOutput, DeleteProfile, DeleteProfileInput, DetectProfiles,
|
||||
DetectProfilesInput, DetectProfilesOutput, FirstRunState, FirstRunStateOutput, ListProfiles,
|
||||
ListProfilesOutput, ProfileAvailability, ReferenceProfiles, ReferenceProfilesOutput,
|
||||
SaveClaudeProviderProfile, SaveClaudeProviderProfileInput, SaveClaudeProviderProfileOutput,
|
||||
SaveCodexProviderProfile, SaveCodexProviderProfileInput, SaveCodexProviderProfileOutput,
|
||||
SaveOpenCodeProviderProfile, SaveOpenCodeProviderProfileInput,
|
||||
SaveOpenCodeProviderProfileOutput, SaveProfile, SaveProfileInput, SaveProfileOutput,
|
||||
};
|
||||
|
||||
@ -41,60 +41,6 @@ pub struct OpenCodeProviderCatalogEntry {
|
||||
pub(crate) model_labels: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
/// One entry of a Codex provider catalogue (ticket #99).
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct CodexProviderCatalogEntry {
|
||||
/// Provider identifier used as Codex's `model_provider`.
|
||||
pub provider_id: String,
|
||||
/// Human-readable label for the picker UI.
|
||||
pub display_name: String,
|
||||
/// Model identifiers this provider serves.
|
||||
pub models: Vec<String>,
|
||||
/// Whether the UI may save this provider with a custom endpoint.
|
||||
pub custom_supported: bool,
|
||||
}
|
||||
|
||||
/// One entry of a Claude provider catalogue (ticket #99).
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct ClaudeProviderCatalogEntry {
|
||||
/// Provider identifier. V1 backend exposes Anthropic.
|
||||
pub provider_id: String,
|
||||
/// Human-readable label for the picker UI.
|
||||
pub display_name: String,
|
||||
/// Model identifiers this provider serves.
|
||||
pub models: Vec<String>,
|
||||
}
|
||||
|
||||
/// Returns the static Codex provider catalogue.
|
||||
#[must_use]
|
||||
pub fn codex_provider_catalogue() -> Vec<CodexProviderCatalogEntry> {
|
||||
vec![CodexProviderCatalogEntry {
|
||||
provider_id: "openai".to_owned(),
|
||||
display_name: "OpenAI".to_owned(),
|
||||
models: vec![
|
||||
"gpt-5".to_owned(),
|
||||
"gpt-5-mini".to_owned(),
|
||||
"gpt-5-codex".to_owned(),
|
||||
"o3".to_owned(),
|
||||
],
|
||||
custom_supported: true,
|
||||
}]
|
||||
}
|
||||
|
||||
/// Returns the static Claude provider catalogue.
|
||||
#[must_use]
|
||||
pub fn claude_provider_catalogue() -> Vec<ClaudeProviderCatalogEntry> {
|
||||
vec![ClaudeProviderCatalogEntry {
|
||||
provider_id: "anthropic".to_owned(),
|
||||
display_name: "Anthropic".to_owned(),
|
||||
models: vec![
|
||||
"claude-sonnet-4-5".to_owned(),
|
||||
"claude-opus-4-1".to_owned(),
|
||||
"claude-haiku-3-5".to_owned(),
|
||||
],
|
||||
}]
|
||||
}
|
||||
|
||||
/// The original lot-B3 catalogue: three well-known providers, used whenever
|
||||
/// the real OpenCode model cache can't be read or parsed.
|
||||
fn static_fallback_catalogue() -> Vec<OpenCodeProviderCatalogEntry> {
|
||||
@ -339,70 +285,6 @@ impl Default for ListOpenCodeProviders {
|
||||
}
|
||||
}
|
||||
|
||||
/// Use case exposing the static Codex provider catalogue.
|
||||
pub struct ListCodexProviders;
|
||||
|
||||
/// Output of [`ListCodexProviders::execute`].
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct ListCodexProvidersOutput {
|
||||
/// The catalogue entries.
|
||||
pub providers: Vec<CodexProviderCatalogEntry>,
|
||||
}
|
||||
|
||||
impl ListCodexProviders {
|
||||
/// Builds the use case (stateless, no ports to inject).
|
||||
#[must_use]
|
||||
pub const fn new() -> Self {
|
||||
Self
|
||||
}
|
||||
|
||||
/// Lists the Codex provider catalogue.
|
||||
#[must_use]
|
||||
pub fn execute(&self) -> ListCodexProvidersOutput {
|
||||
ListCodexProvidersOutput {
|
||||
providers: codex_provider_catalogue(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ListCodexProviders {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
/// Use case exposing the static Claude provider catalogue.
|
||||
pub struct ListClaudeProviders;
|
||||
|
||||
/// Output of [`ListClaudeProviders::execute`].
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct ListClaudeProvidersOutput {
|
||||
/// The catalogue entries.
|
||||
pub providers: Vec<ClaudeProviderCatalogEntry>,
|
||||
}
|
||||
|
||||
impl ListClaudeProviders {
|
||||
/// Builds the use case (stateless, no ports to inject).
|
||||
#[must_use]
|
||||
pub const fn new() -> Self {
|
||||
Self
|
||||
}
|
||||
|
||||
/// Lists the Claude provider catalogue.
|
||||
#[must_use]
|
||||
pub fn execute(&self) -> ListClaudeProvidersOutput {
|
||||
ListClaudeProvidersOutput {
|
||||
providers: claude_provider_catalogue(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ListClaudeProviders {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@ -16,8 +16,7 @@ use std::sync::Arc;
|
||||
use domain::ids::ProfileId;
|
||||
use domain::ports::{AgentRuntime, IdGenerator, ProfileStore, SecretRef, SecretStore};
|
||||
use domain::profile::{
|
||||
AgentProfile, ClaudeProviderConfig, CodexCustomProviderConfig, CodexProviderConfig,
|
||||
CustomProviderConfig, OpenCodeConfig, OpenCodeProviderConfig, StructuredAdapter,
|
||||
AgentProfile, CustomProviderConfig, OpenCodeConfig, OpenCodeProviderConfig, StructuredAdapter,
|
||||
};
|
||||
|
||||
use crate::error::AppError;
|
||||
@ -325,149 +324,6 @@ pub struct SaveOpenCodeProviderProfileOutput {
|
||||
pub profile: AgentProfile,
|
||||
}
|
||||
|
||||
/// Input for [`SaveCodexProviderProfile::execute`].
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct SaveCodexProviderProfileInput {
|
||||
/// The profile to create or replace (by id).
|
||||
pub profile: AgentProfile,
|
||||
/// Provider id used as Codex's `model_provider`.
|
||||
pub provider_id: String,
|
||||
/// Model name served by this provider.
|
||||
pub model: String,
|
||||
/// Literal API key, sealed into the `SecretStore`.
|
||||
pub api_key: String,
|
||||
/// Optional custom-provider endpoint configuration.
|
||||
pub custom: Option<CodexCustomProviderConfig>,
|
||||
}
|
||||
|
||||
/// Output of [`SaveCodexProviderProfile::execute`].
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct SaveCodexProviderProfileOutput {
|
||||
/// The saved profile (echoed back), with `codex_provider` set.
|
||||
pub profile: AgentProfile,
|
||||
}
|
||||
|
||||
/// Persists a Codex profile backed by a provider/model pair (ticket #99).
|
||||
pub struct SaveCodexProviderProfile {
|
||||
profile_store: Arc<dyn ProfileStore>,
|
||||
secret_store: Arc<dyn SecretStore>,
|
||||
ids: Arc<dyn IdGenerator>,
|
||||
}
|
||||
|
||||
impl SaveCodexProviderProfile {
|
||||
/// Builds the use case from the profile store, secret store and id generator
|
||||
/// ports.
|
||||
#[must_use]
|
||||
pub fn new(
|
||||
profile_store: Arc<dyn ProfileStore>,
|
||||
secret_store: Arc<dyn SecretStore>,
|
||||
ids: Arc<dyn IdGenerator>,
|
||||
) -> Self {
|
||||
Self {
|
||||
profile_store,
|
||||
secret_store,
|
||||
ids,
|
||||
}
|
||||
}
|
||||
|
||||
/// Seals `input.api_key` under a [`SecretRef`] and persists the profile with
|
||||
/// `codex_provider` set.
|
||||
///
|
||||
/// # Errors
|
||||
/// [`AppError::Invalid`] if `provider_id`/`model` is empty, [`AppError::Store`]
|
||||
/// on secret or profile persistence failure.
|
||||
pub async fn execute(
|
||||
&self,
|
||||
input: SaveCodexProviderProfileInput,
|
||||
) -> Result<SaveCodexProviderProfileOutput, AppError> {
|
||||
let secret_ref = input
|
||||
.profile
|
||||
.codex_provider
|
||||
.as_ref()
|
||||
.map(|config| config.api_key_ref.clone())
|
||||
.unwrap_or_else(|| SecretRef::new(self.ids.new_uuid().to_string()));
|
||||
self.secret_store.put(&secret_ref, &input.api_key).await?;
|
||||
|
||||
let mut provider = CodexProviderConfig::new(input.provider_id, input.model, secret_ref)
|
||||
.map_err(|e| AppError::Invalid(e.to_string()))?;
|
||||
if let Some(custom) = input.custom {
|
||||
provider = provider.with_custom(custom);
|
||||
}
|
||||
let profile = input.profile.with_codex_provider(provider);
|
||||
self.profile_store.save(&profile).await?;
|
||||
Ok(SaveCodexProviderProfileOutput { profile })
|
||||
}
|
||||
}
|
||||
|
||||
/// Input for [`SaveClaudeProviderProfile::execute`].
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct SaveClaudeProviderProfileInput {
|
||||
/// The profile to create or replace (by id).
|
||||
pub profile: AgentProfile,
|
||||
/// Provider id. V1 backend expects `"anthropic"`.
|
||||
pub provider_id: String,
|
||||
/// Model name served by this provider.
|
||||
pub model: String,
|
||||
/// Literal API key, sealed into the `SecretStore`.
|
||||
pub api_key: String,
|
||||
}
|
||||
|
||||
/// Output of [`SaveClaudeProviderProfile::execute`].
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct SaveClaudeProviderProfileOutput {
|
||||
/// The saved profile (echoed back), with `claude_provider` set.
|
||||
pub profile: AgentProfile,
|
||||
}
|
||||
|
||||
/// Persists a Claude profile backed by a provider/model pair (ticket #99).
|
||||
pub struct SaveClaudeProviderProfile {
|
||||
profile_store: Arc<dyn ProfileStore>,
|
||||
secret_store: Arc<dyn SecretStore>,
|
||||
ids: Arc<dyn IdGenerator>,
|
||||
}
|
||||
|
||||
impl SaveClaudeProviderProfile {
|
||||
/// Builds the use case from the profile store, secret store and id generator
|
||||
/// ports.
|
||||
#[must_use]
|
||||
pub fn new(
|
||||
profile_store: Arc<dyn ProfileStore>,
|
||||
secret_store: Arc<dyn SecretStore>,
|
||||
ids: Arc<dyn IdGenerator>,
|
||||
) -> Self {
|
||||
Self {
|
||||
profile_store,
|
||||
secret_store,
|
||||
ids,
|
||||
}
|
||||
}
|
||||
|
||||
/// Seals `input.api_key` under a [`SecretRef`] and persists the profile with
|
||||
/// `claude_provider` set.
|
||||
///
|
||||
/// # Errors
|
||||
/// [`AppError::Invalid`] if `provider_id`/`model` is empty, [`AppError::Store`]
|
||||
/// on secret or profile persistence failure.
|
||||
pub async fn execute(
|
||||
&self,
|
||||
input: SaveClaudeProviderProfileInput,
|
||||
) -> Result<SaveClaudeProviderProfileOutput, AppError> {
|
||||
let secret_ref = input
|
||||
.profile
|
||||
.claude_provider
|
||||
.as_ref()
|
||||
.map(|config| config.api_key_ref.clone())
|
||||
.unwrap_or_else(|| SecretRef::new(self.ids.new_uuid().to_string()));
|
||||
self.secret_store.put(&secret_ref, &input.api_key).await?;
|
||||
|
||||
let provider = ClaudeProviderConfig::new(input.provider_id, input.model, secret_ref)
|
||||
.map_err(|e| AppError::Invalid(e.to_string()))?;
|
||||
let profile = input.profile.with_claude_provider(provider);
|
||||
self.profile_store.save(&profile).await?;
|
||||
Ok(SaveClaudeProviderProfileOutput { profile })
|
||||
}
|
||||
}
|
||||
|
||||
/// Persists an OpenCode profile backed by a **cloud** provider (ticket #92, lot
|
||||
/// B3), keeping the literal API key out of `profiles.json`: it is sealed into the
|
||||
/// [`SecretStore`] under an opaque [`SecretRef`], and only the ref is persisted on
|
||||
@ -580,12 +436,6 @@ impl DeleteProfile {
|
||||
if let Some(config) = &profile.opencode_provider {
|
||||
self.secret_store.delete(&config.api_key_ref).await?;
|
||||
}
|
||||
if let Some(config) = &profile.codex_provider {
|
||||
self.secret_store.delete(&config.api_key_ref).await?;
|
||||
}
|
||||
if let Some(config) = &profile.claude_provider {
|
||||
self.secret_store.delete(&config.api_key_ref).await?;
|
||||
}
|
||||
}
|
||||
self.store.delete(input.id).await?;
|
||||
Ok(())
|
||||
|
||||
@ -44,26 +44,23 @@ pub use agent::{
|
||||
drain_with_readiness_and_announcements, drain_with_readiness_outcome, reference_profile_id,
|
||||
reference_profiles, selectable_reference_profiles, send_blocking, AgentResumer,
|
||||
AnnouncementPublisher, ChangeAgentProfile, ChangeAgentProfileInput, ChangeAgentProfileOutput,
|
||||
ClaudeProviderCatalogEntry, CloneOpenCodeProfileFromSeed, CloneOpenCodeProfileFromSeedInput,
|
||||
CloneOpenCodeProfileFromSeedOutput, CodexProviderCatalogEntry, ConfigureProfiles,
|
||||
ConfigureProfilesInput, ConfigureProfilesOutput, CreateAgentFromScratch, CreateAgentInput,
|
||||
CreateAgentOutput, DeleteAgent, DeleteAgentInput, DeleteProfile, DeleteProfileInput,
|
||||
DetectProfiles, DetectProfilesInput, DetectProfilesOutput, FirstRunState, FirstRunStateOutput,
|
||||
HandoffProvider, InjectedLiveRow, InspectConversation, InspectConversationInput,
|
||||
InspectConversationOutput, LaunchAgent, LaunchAgentInput, LaunchAgentOutput, ListAgents,
|
||||
ListAgentsInput, ListAgentsOutput, ListClaudeProviders, ListClaudeProvidersOutput,
|
||||
ListCodexProviders, ListCodexProvidersOutput, ListOpenCodeProviders,
|
||||
ListOpenCodeProvidersOutput, ListProfiles, ListProfilesOutput, ListResumableAgents,
|
||||
ListResumableAgentsInput, ListResumableAgentsOutput, LiveStateLeanProvider, McpRuntime,
|
||||
OpenCodeProviderCatalogEntry, PermissionProjectorRegistry, ProfileAvailability,
|
||||
ProviderSessionProvider, ReadAgentContext, ReadAgentContextInput, ReadAgentContextOutput,
|
||||
ReferenceProfiles, ReferenceProfilesOutput, ResumableAgent, SaveClaudeProviderProfile,
|
||||
SaveClaudeProviderProfileInput, SaveClaudeProviderProfileOutput, SaveCodexProviderProfile,
|
||||
SaveCodexProviderProfileInput, SaveCodexProviderProfileOutput, SaveOpenCodeProviderProfile,
|
||||
SaveOpenCodeProviderProfileInput, SaveOpenCodeProviderProfileOutput, SaveProfile,
|
||||
SaveProfileInput, SaveProfileOutput, SessionLimitService, StructuredRoutingMode,
|
||||
StructuredSessionDescriptor, TurnOutcome, UpdateAgentContext, UpdateAgentContextInput,
|
||||
AGENT_MEMORY_RECALL_BUDGET, CODEX_SUBMIT_DELAY_MS, LIVE_STATE_INJECT_MAX, RESUME_PROMPT,
|
||||
CloneOpenCodeProfileFromSeed, CloneOpenCodeProfileFromSeedInput,
|
||||
CloneOpenCodeProfileFromSeedOutput, ConfigureProfiles, ConfigureProfilesInput,
|
||||
ConfigureProfilesOutput, CreateAgentFromScratch, CreateAgentInput, CreateAgentOutput,
|
||||
DeleteAgent, DeleteAgentInput, DeleteProfile, DeleteProfileInput, DetectProfiles,
|
||||
DetectProfilesInput, DetectProfilesOutput, FirstRunState, FirstRunStateOutput, HandoffProvider,
|
||||
InjectedLiveRow, InspectConversation, InspectConversationInput, InspectConversationOutput,
|
||||
LaunchAgent, LaunchAgentInput, LaunchAgentOutput, ListAgents, ListAgentsInput,
|
||||
ListAgentsOutput, ListOpenCodeProviders, ListOpenCodeProvidersOutput, ListProfiles,
|
||||
ListProfilesOutput, ListResumableAgents, ListResumableAgentsInput, ListResumableAgentsOutput,
|
||||
LiveStateLeanProvider, McpRuntime, OpenCodeProviderCatalogEntry, PermissionProjectorRegistry,
|
||||
ProfileAvailability, ProviderSessionProvider, ReadAgentContext, ReadAgentContextInput,
|
||||
ReadAgentContextOutput, ReferenceProfiles, ReferenceProfilesOutput, ResumableAgent,
|
||||
SaveOpenCodeProviderProfile, SaveOpenCodeProviderProfileInput,
|
||||
SaveOpenCodeProviderProfileOutput, SaveProfile, SaveProfileInput, SaveProfileOutput,
|
||||
SessionLimitService, StructuredRoutingMode, StructuredSessionDescriptor, TurnOutcome,
|
||||
UpdateAgentContext, UpdateAgentContextInput, AGENT_MEMORY_RECALL_BUDGET, CODEX_SUBMIT_DELAY_MS,
|
||||
LIVE_STATE_INJECT_MAX, RESUME_PROMPT,
|
||||
};
|
||||
pub use background::{
|
||||
BackgroundCommandArchive, CancelBackgroundTask, CancelBackgroundTaskOutput,
|
||||
|
||||
@ -27,9 +27,8 @@ use application::{
|
||||
reference_profile_id, reference_profiles, CloneOpenCodeProfileFromSeed,
|
||||
CloneOpenCodeProfileFromSeedInput, ConfigureProfiles, ConfigureProfilesInput, DeleteProfile,
|
||||
DeleteProfileInput, DetectProfiles, DetectProfilesInput, FirstRunState, ListProfiles,
|
||||
ReferenceProfiles, SaveClaudeProviderProfile, SaveClaudeProviderProfileInput,
|
||||
SaveCodexProviderProfile, SaveCodexProviderProfileInput, SaveOpenCodeProviderProfile,
|
||||
SaveOpenCodeProviderProfileInput, SaveProfile, SaveProfileInput, CODEX_SUBMIT_DELAY_MS,
|
||||
ReferenceProfiles, SaveOpenCodeProviderProfile, SaveOpenCodeProviderProfileInput, SaveProfile,
|
||||
SaveProfileInput, CODEX_SUBMIT_DELAY_MS,
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@ -602,70 +601,25 @@ async fn delete_profile_with_opencode_provider_purges_its_secret() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn save_codex_provider_profile_seals_key_and_sets_backend_config() {
|
||||
async fn save_profile_persists_codex_claude_model_without_provider_or_secret_surface() {
|
||||
let store = FakeProfileStore::default();
|
||||
let secrets = FakeSecretStore::default();
|
||||
let save = SaveCodexProviderProfile::new(
|
||||
Arc::new(store.clone()),
|
||||
Arc::new(secrets.clone()),
|
||||
Arc::new(SeqIds::new(vec![uuid::Uuid::from_u128(9901)])),
|
||||
);
|
||||
let save = SaveProfile::new(Arc::new(store.clone()));
|
||||
let profile = profile(991, "Codex GPT-5", "codex").with_model("gpt-5-codex");
|
||||
|
||||
let out = save
|
||||
.execute(SaveCodexProviderProfileInput {
|
||||
profile: profile(991, "Codex GPT-5", "codex"),
|
||||
provider_id: "openai".to_owned(),
|
||||
model: "gpt-5".to_owned(),
|
||||
api_key: "sk-openai-literal".to_owned(),
|
||||
custom: None,
|
||||
.execute(SaveProfileInput {
|
||||
profile: profile.clone(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let provider = out.profile.codex_provider.as_ref().unwrap();
|
||||
assert_eq!(provider.provider_id, "openai");
|
||||
assert_eq!(provider.model, "gpt-5");
|
||||
assert_ne!(provider.api_key_ref.as_str(), "sk-openai-literal");
|
||||
assert!(!serde_json::to_string(&out.profile)
|
||||
.unwrap()
|
||||
.contains("sk-openai-literal"));
|
||||
assert_eq!(
|
||||
secrets.get(&provider.api_key_ref).await.unwrap(),
|
||||
Some("sk-openai-literal".to_owned())
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn save_claude_provider_profile_seals_key_and_sets_backend_config() {
|
||||
let store = FakeProfileStore::default();
|
||||
let secrets = FakeSecretStore::default();
|
||||
let save = SaveClaudeProviderProfile::new(
|
||||
Arc::new(store.clone()),
|
||||
Arc::new(secrets.clone()),
|
||||
Arc::new(SeqIds::new(vec![uuid::Uuid::from_u128(9902)])),
|
||||
);
|
||||
|
||||
let out = save
|
||||
.execute(SaveClaudeProviderProfileInput {
|
||||
profile: profile(992, "Claude Sonnet", "claude"),
|
||||
provider_id: "anthropic".to_owned(),
|
||||
model: "claude-sonnet-4-5".to_owned(),
|
||||
api_key: "sk-anthropic-literal".to_owned(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let provider = out.profile.claude_provider.as_ref().unwrap();
|
||||
assert_eq!(provider.provider_id, "anthropic");
|
||||
assert_eq!(provider.model, "claude-sonnet-4-5");
|
||||
assert_ne!(provider.api_key_ref.as_str(), "sk-anthropic-literal");
|
||||
assert!(!serde_json::to_string(&out.profile)
|
||||
.unwrap()
|
||||
.contains("sk-anthropic-literal"));
|
||||
assert_eq!(
|
||||
secrets.get(&provider.api_key_ref).await.unwrap(),
|
||||
Some("sk-anthropic-literal".to_owned())
|
||||
);
|
||||
assert_eq!(out.profile.model.as_deref(), Some("gpt-5-codex"));
|
||||
let json = serde_json::to_string(&out.profile).unwrap();
|
||||
assert!(!json.contains("codexProvider"), "got: {json}");
|
||||
assert!(!json.contains("claudeProvider"), "got: {json}");
|
||||
assert!(!json.contains("apiKey"), "got: {json}");
|
||||
assert!(!json.contains("providerId"), "got: {json}");
|
||||
assert_eq!(store.list().await.unwrap(), vec![profile]);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
Reference in New Issue
Block a user