First attempt to add ACP support

This commit is contained in:
Ryan Ward
2026-07-31 11:09:32 -05:00
parent 1a0aac51b6
commit 7f4891ec7c
25 changed files with 1051 additions and 138 deletions
+39 -6
View File
@@ -274,7 +274,7 @@ fn acp_backend_model_id(backend: &AgentBackend) -> Option<LLMId> {
match backend {
AgentBackend::Provider => None,
AgentBackend::Acp(acp) => {
Some(format!("acp:{}", acp.agent_id.trim().to_ascii_lowercase()).into())
Some(crate::ai::acp::acp_selection_identity(&acp.agent_id, &acp.config_values).into())
}
}
}
@@ -3826,14 +3826,47 @@ impl BlocklistAIController {
};
let history_model = BlocklistAIHistoryModel::handle(ctx);
let Some(conversation) = history_model.as_ref(ctx).conversation(&conversation_id)
let Some((agent_id, new_exchange_ids, exchanges)) = history_model
.as_ref(ctx)
.conversation(&conversation_id)
.map(|conversation| {
(
match conversation.agent_backend() {
AgentBackend::Acp(acp) => Some(acp.agent_id.clone()),
AgentBackend::Provider => None,
},
conversation
.new_exchange_ids_for_response(&stream_id)
.collect::<Vec<_>>(),
conversation.clone(),
)
})
else {
log::warn!("Conversation not found.");
return;
};
let new_exchange_ids: Vec<_> = conversation
.new_exchange_ids_for_response(&stream_id)
.collect();
#[cfg(not(target_family = "wasm"))]
if let Some(metadata) = response_stream.as_ref(ctx).acp_session_metadata() {
if !metadata.config_options.is_empty() {
if let Some(agent_id) = &agent_id {
crate::settings::AISettings::handle(ctx).update(
ctx,
|settings, ctx| {
if let Err(error) =
crate::ai::acp::AcpRuntimeModel::persist_runtime_options(
settings,
agent_id,
&metadata.config_options,
ctx,
)
{
log::warn!("Failed to persist ACP runtime config: {error}");
}
},
);
}
}
}
log::info!(
"[bedrock-debug] AfterStreamFinished: stream_id={:?}, conversation_id={:?}, new_exchange_ids count={}",
stream_id, conversation_id, new_exchange_ids.len()
@@ -3843,7 +3876,7 @@ impl BlocklistAIController {
let mut actions_to_queue = vec![];
for new_exchange_id in new_exchange_ids {
let Some(exchange) = conversation.exchange_with_id(new_exchange_id) else {
let Some(exchange) = exchanges.exchange_with_id(new_exchange_id) else {
log::warn!("Exchange not found.");
return;
};
+5 -1
View File
@@ -67,8 +67,12 @@ fn acp_backend_model_identity_does_not_claim_a_provider_model() {
agent_id: " Codex ".to_owned(),
launch_fingerprint: "launch-123".to_owned(),
session_id: None,
config_values: std::collections::BTreeMap::from([(
"model".to_owned(),
serde_json::json!("fast"),
)]),
})),
Some(LLMId::from("acp:codex"))
Some(LLMId::from("acp:codex:model=\"fast\""))
);
}
+12 -9
View File
@@ -39,6 +39,8 @@ use crate::ai::agent::{
};
use crate::ai::artifacts::Artifact;
use crate::ai::document::ai_document_model::AIDocumentModel;
#[cfg(not(target_family = "wasm"))]
use crate::ai::llms::LLMPreferences;
use crate::input_suggestions::HistoryOrder;
use crate::persistence::model::{
AcpConversationData, AgentBackend, AgentConversation, AgentConversationData,
@@ -1225,15 +1227,16 @@ impl BlocklistAIHistoryModel {
.value()
.iter()
.find(|agent| agent.id.eq_ignore_ascii_case(agent_id))
.and_then(|agent| {
agent
.config_options
.iter()
.find(|option| option.category.as_deref() == Some("model"))
})
.map(|option| {
std::iter::once((option.id.clone(), option.current_value.clone()))
.collect()
.map(|agent| {
#[cfg(not(target_family = "wasm"))]
if let Some(selection) = LLMPreferences::as_ref(ctx)
.selected_acp_config_for_agent(&agent.name, ctx)
{
return selection;
}
crate::ai::acp::AcpRuntimeModel::current_config_values(
&agent.config_options,
)
})
.unwrap_or_default(),
})
@@ -81,6 +81,7 @@ fn acp_enabled_with_empty_command_selects_codex_backend() {
agent_id: "codex".to_string(),
launch_fingerprint: crate::ai::acp::acp_launch_fingerprint("codex", "", &[]),
session_id: None,
config_values: Default::default(),
})
);
});