feat(agent): UI hot-swap de profil (A2) — commande Tauri + sélecteur + dialog
- Tauri : commande change_agent_profile + ChangeAgentProfileRequestDto/Dto (camelCase, relaunchedSession omis si None), câblage state.rs par composition. - Front : gateway changeAgentProfile (adapters Tauri+mock), sélecteur de profil par agent, dialog de confirmation FR (« Changer le moteur abandonne l'historique de conversation… »), refresh sur event agentProfileChanged. Tests : app-tauri dto 5/5 ; vitest 314/314 (mapping, payload, dialog gating, libellé FR, refresh). 0 régression. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -9,8 +9,9 @@ use tauri::State;
|
||||
|
||||
use crate::dto::DismissEmbedderSuggestionRequestDto;
|
||||
use application::{
|
||||
AppError, AssignSkillToAgentInput, CloseProjectInput, CreateAgentInput, CreateLayoutInput,
|
||||
CreateMemoryInput, CreateSkillInput, DeleteAgentInput, DeleteEmbedderProfileInput,
|
||||
AppError, AssignSkillToAgentInput, ChangeAgentProfileInput, CloseProjectInput, CreateAgentInput,
|
||||
CreateLayoutInput, CreateMemoryInput, CreateSkillInput, DeleteAgentInput,
|
||||
DeleteEmbedderProfileInput,
|
||||
DeleteLayoutInput, DeleteMemoryInput, DeleteSkillInput, DeleteTemplateInput,
|
||||
DetectAgentDriftInput, GetMemoryInput, GitBranchesInput, GitCheckoutInput, GitCommitInput,
|
||||
GitGraphInput, GitInitInput, GitLogInput, GitStagePathInput, GitStatusInput,
|
||||
@ -27,7 +28,8 @@ use crate::dto::{
|
||||
parse_agent_id, parse_close_terminal, parse_delete_profile, parse_layout_id, parse_memory_slug,
|
||||
parse_node_id, parse_profile_id, parse_project_id, parse_session_id, parse_skill_id,
|
||||
parse_template_id, AgentDriftListDto, AgentDto, AgentListDto, AssignSkillRequestDto,
|
||||
AttachLiveAgentRequestDto, ConfigureProfilesRequestDto, ConversationDetailsDto,
|
||||
AttachLiveAgentRequestDto, ChangeAgentProfileDto, ChangeAgentProfileRequestDto,
|
||||
ConfigureProfilesRequestDto, ConversationDetailsDto,
|
||||
CreateAgentFromTemplateRequestDto, CreateAgentRequestDto, CreateLayoutRequestDto,
|
||||
CreateLayoutResultDto, CreateMemoryRequestDto, CreateProjectRequestDto, CreateSkillRequestDto,
|
||||
CreateTemplateRequestDto, DeleteLayoutRequestDto, DeleteLayoutResultDto,
|
||||
@ -1037,6 +1039,42 @@ pub async fn launch_agent(
|
||||
Ok(TerminalSessionDto::from(output))
|
||||
}
|
||||
|
||||
/// `change_agent_profile` — hot-swap an agent's runtime profile (§15.1).
|
||||
///
|
||||
/// Mutates the profile in the manifest, clears the now-foreign conversation id on
|
||||
/// every persisted layout cell hosting the agent, and — if the agent is live —
|
||||
/// kills its PTY and relaunches the session in the same cell with the new engine.
|
||||
/// Announces [`DomainEvent::AgentProfileChanged`].
|
||||
///
|
||||
/// Returns the mutated [`AgentDto`] and the relaunched [`TerminalSessionDto`] when
|
||||
/// a live session was hot-swapped (absent otherwise).
|
||||
///
|
||||
/// # Errors
|
||||
/// Returns an [`ErrorDto`] (`INVALID` for malformed ids, `NOT_FOUND` if the
|
||||
/// project, agent or target profile is unknown, `STORE`/`FILESYSTEM`/`PROCESS` on
|
||||
/// the respective port failures).
|
||||
#[tauri::command]
|
||||
pub async fn change_agent_profile(
|
||||
request: ChangeAgentProfileRequestDto,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<ChangeAgentProfileDto, ErrorDto> {
|
||||
let project = resolve_project(&request.project_id, &state).await?;
|
||||
let agent_id = parse_agent_id(&request.agent_id)?;
|
||||
let profile_id = parse_profile_id(&request.profile_id)?;
|
||||
state
|
||||
.change_agent_profile
|
||||
.execute(ChangeAgentProfileInput {
|
||||
project,
|
||||
agent_id,
|
||||
profile_id,
|
||||
rows: request.rows,
|
||||
cols: request.cols,
|
||||
})
|
||||
.await
|
||||
.map(ChangeAgentProfileDto::from)
|
||||
.map_err(ErrorDto::from)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Templates & sync (L7)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@ -1032,10 +1032,10 @@ pub fn parse_profile_id(raw: &str) -> Result<ProfileId, ErrorDto> {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
use application::{
|
||||
CreateAgentOutput, InspectConversationOutput, LaunchAgentOutput, ListAgentsOutput,
|
||||
ReadAgentContextOutput,
|
||||
ChangeAgentProfileOutput, CreateAgentOutput, InspectConversationOutput, LaunchAgentOutput,
|
||||
ListAgentsOutput, ReadAgentContextOutput,
|
||||
};
|
||||
use domain::Agent;
|
||||
use domain::{Agent, TerminalSession};
|
||||
|
||||
/// An agent crossing the wire. [`Agent`] already serialises camelCase
|
||||
/// (`id`, `name`, `contextPath`, `profileId`, `origin` tagged, `synchronized`),
|
||||
@ -1154,6 +1154,56 @@ impl From<LaunchAgentOutput> for TerminalSessionDto {
|
||||
}
|
||||
}
|
||||
|
||||
/// Request DTO for `change_agent_profile` (§15.1): hot-swap an agent's runtime
|
||||
/// profile, optionally relaunching its live session in place.
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ChangeAgentProfileRequestDto {
|
||||
/// Id of the owning project.
|
||||
pub project_id: String,
|
||||
/// Id of the agent whose runtime profile to change.
|
||||
pub agent_id: String,
|
||||
/// Id of the new runtime profile.
|
||||
pub profile_id: String,
|
||||
/// Terminal height in rows for a possible hot relaunch.
|
||||
pub rows: u16,
|
||||
/// Terminal width in columns for a possible hot relaunch.
|
||||
pub cols: u16,
|
||||
}
|
||||
|
||||
/// Response DTO for `change_agent_profile`: the mutated agent plus the freshly
|
||||
/// relaunched session when a live session was hot-swapped (absent otherwise).
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ChangeAgentProfileDto {
|
||||
/// The agent now carrying the new profile.
|
||||
pub agent: AgentDto,
|
||||
/// The relaunched session, present only when a live session was swapped.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub relaunched_session: Option<TerminalSessionDto>,
|
||||
}
|
||||
|
||||
impl From<ChangeAgentProfileOutput> for ChangeAgentProfileDto {
|
||||
fn from(out: ChangeAgentProfileOutput) -> Self {
|
||||
Self {
|
||||
agent: AgentDto(out.agent),
|
||||
relaunched_session: out.relaunched.map(TerminalSessionDto::from),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TerminalSession> for TerminalSessionDto {
|
||||
fn from(s: TerminalSession) -> Self {
|
||||
Self {
|
||||
session_id: s.id.to_string(),
|
||||
cwd: s.cwd.as_str().to_owned(),
|
||||
rows: s.pty_size.rows,
|
||||
cols: s.pty_size.cols,
|
||||
assigned_conversation_id: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Request DTO for `inspect_conversation` (T7).
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
|
||||
@ -126,6 +126,7 @@ pub fn run() {
|
||||
commands::update_agent_context,
|
||||
commands::delete_agent,
|
||||
commands::launch_agent,
|
||||
commands::change_agent_profile,
|
||||
commands::inspect_conversation,
|
||||
commands::create_template,
|
||||
commands::update_template,
|
||||
|
||||
@ -10,7 +10,8 @@ use std::path::PathBuf;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use application::{
|
||||
AssignSkillToAgent, CheckEmbedderSuggestion, CloseProject, CloseTab, CloseTerminal,
|
||||
AssignSkillToAgent, ChangeAgentProfile, CheckEmbedderSuggestion, CloseProject, CloseTab,
|
||||
CloseTerminal,
|
||||
ConfigureProfiles, CreateAgentFromScratch, CreateAgentFromTemplate, CreateLayout, CreateMemory,
|
||||
CreateProject, CreateSkill, CreateTemplate, DeleteAgent, DeleteEmbedderProfile, DeleteLayout,
|
||||
DeleteMemory, DeleteProfile, DeleteSkill, DeleteTemplate, DescribeEmbedderEngines,
|
||||
@ -128,6 +129,8 @@ pub struct AppState {
|
||||
pub delete_agent: Arc<DeleteAgent>,
|
||||
/// Launch an agent (spawn PTY, apply injection strategy).
|
||||
pub launch_agent: Arc<LaunchAgent>,
|
||||
/// Hot-swap an agent's runtime profile, relaunching its live session in place (§15.1).
|
||||
pub change_agent_profile: Arc<ChangeAgentProfile>,
|
||||
/// Best-effort inspection of a conversation (last topic + token indicator)
|
||||
/// for the resume popup (T7). Optional/extensible: backed by a `Vec` of
|
||||
/// [`domain::ports::SessionInspector`]s; an empty/missing match yields empty
|
||||
@ -514,6 +517,20 @@ impl AppState {
|
||||
Some(Arc::clone(&check_embedder_suggestion)),
|
||||
));
|
||||
|
||||
// Hot-swap an agent's runtime profile (§15.1). Reuses the shared context/
|
||||
// profile/project/fs stores, the live-session registry and PTY port, and
|
||||
// *composes* the launcher above for the in-place relaunch (no duplication).
|
||||
let change_agent_profile = Arc::new(ChangeAgentProfile::new(
|
||||
Arc::clone(&contexts_port),
|
||||
Arc::clone(&profile_store_port),
|
||||
Arc::clone(&store_port),
|
||||
Arc::clone(&fs_port),
|
||||
Arc::clone(&terminal_sessions),
|
||||
Arc::clone(&pty_port),
|
||||
Arc::clone(&launch_agent),
|
||||
Arc::clone(&events_port),
|
||||
));
|
||||
|
||||
// --- Conversation inspection (T7) ---
|
||||
// Best-effort, optional, extensible: a `Vec` of SessionInspectors routed
|
||||
// by profile. Adding an inspectable CLI = pushing one more adapter here.
|
||||
@ -699,6 +716,7 @@ impl AppState {
|
||||
update_agent_context,
|
||||
delete_agent,
|
||||
launch_agent,
|
||||
change_agent_profile,
|
||||
inspect_conversation,
|
||||
project_store,
|
||||
create_template,
|
||||
|
||||
Reference in New Issue
Block a user