Apply ACP recipe state during session load and fork (#9998)
This commit is contained in:
@@ -183,7 +183,7 @@ async fn update_session_user_recipe_values(
|
||||
message: format!("Failed to get agent: {}", status),
|
||||
status,
|
||||
})?;
|
||||
if let Some(prompt) = apply_recipe_to_agent(&agent, &recipe, false).await {
|
||||
if let Some(prompt) = apply_recipe_to_agent(&agent, &recipe, true).await {
|
||||
agent
|
||||
.extend_system_prompt("recipe".to_string(), prompt)
|
||||
.await;
|
||||
|
||||
@@ -51,12 +51,13 @@ impl GooseAcpAgent {
|
||||
)
|
||||
.await?;
|
||||
|
||||
let (_agent, extension_results) = self
|
||||
.activate_acp_session(cx, &goose_session, HashMap::new())
|
||||
.await?;
|
||||
let (agent, extension_results) = self.prepare_acp_session_agent(cx, &goose_session).await?;
|
||||
self.apply_session_recipe(&agent, &goose_session).await?;
|
||||
self.register_acp_session(goose_session.id.clone(), agent, HashMap::new())
|
||||
.await;
|
||||
|
||||
let acp_session_id = SessionId::new(new_session_id.clone());
|
||||
let mut meta = session_meta(&new_session);
|
||||
let mut meta = session_meta(&goose_session);
|
||||
if let Ok(v) = serde_json::to_value(&extension_results) {
|
||||
meta.insert("extensionResults".to_string(), v);
|
||||
}
|
||||
|
||||
@@ -191,6 +191,7 @@ impl GooseAcpAgent {
|
||||
|
||||
let replay_tool_requests = replay_conversation_to_client(cx, &session)?;
|
||||
let (agent, extension_results) = self.prepare_acp_session_agent(cx, &session).await?;
|
||||
self.apply_session_recipe(&agent, &session).await?;
|
||||
self.register_acp_session(session_id_str.clone(), agent.clone(), replay_tool_requests)
|
||||
.await;
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ use crate::recipe::manifest::{
|
||||
use crate::recipe::validate_recipe::validate_recipe_template_from_content;
|
||||
use crate::recipe::{strip_error_location, Recipe, RecipeParameter};
|
||||
use crate::recipe_deeplink;
|
||||
use crate::session::{Session, SessionType};
|
||||
use crate::slash_commands::recipe_slash_command;
|
||||
|
||||
use self::conversions::recipe_manifest_to_list_entry_dto;
|
||||
@@ -321,6 +322,32 @@ impl GooseAcpAgent {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) async fn apply_session_recipe(
|
||||
&self,
|
||||
agent: &Arc<Agent>,
|
||||
session: &Session,
|
||||
) -> Result<(), agent_client_protocol::Error> {
|
||||
let Some(recipe) = session.recipe.as_ref() else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
if session.session_type == SessionType::Scheduled {
|
||||
self.apply_recipe(agent, recipe).await;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let recipe_dir = get_recipe_library_dir(true);
|
||||
if let Some(rendered) = self.render_recipe(
|
||||
recipe,
|
||||
&recipe_dir,
|
||||
session.user_recipe_values.clone().unwrap_or_default(),
|
||||
)? {
|
||||
self.apply_recipe(agent, &rendered).await;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) async fn render_recipe_for_session(
|
||||
&self,
|
||||
cx: &ConnectionTo<Client>,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { defineMessages, useIntl } from '../i18n';
|
||||
import { AppEvents } from '../constants/events';
|
||||
import { ChatState } from '../types/chatState';
|
||||
|
||||
import { Message, Session, TokenState, updateFromSession } from '../api';
|
||||
import { Message, Session, TokenState } from '../api';
|
||||
|
||||
import { createUserMessage, NotificationEvent, UserInput } from '../types/message';
|
||||
import { errorMessage } from '../utils/conversionUtils';
|
||||
@@ -267,17 +267,6 @@ export function useAcpChatSession({
|
||||
return Promise.reject(new Error('ACP recipe parameters are handled during session creation'));
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (session) {
|
||||
updateFromSession({
|
||||
body: {
|
||||
session_id: session.id,
|
||||
},
|
||||
throwOnError: true,
|
||||
});
|
||||
}
|
||||
}, [session]);
|
||||
|
||||
const stopStreaming = useCallback(() => {
|
||||
acpChatSessionController.stop(sessionId);
|
||||
}, [sessionId]);
|
||||
|
||||
Reference in New Issue
Block a user