File size: 1,218 Bytes
52a9af3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | use crate::function_tool::FunctionCallError;
use crate::session::session::Session;
use crate::session::turn_context::TurnContext;
use codex_protocol::ThreadId;
use codex_protocol::error::CodexErrorDetails;
use std::sync::Arc;
/// Resolves a single tool-facing agent target to a thread id.
pub(crate) async fn resolve_agent_target(
session: &Arc<Session>,
turn: &Arc<TurnContext>,
target: &str,
) -> Result<ThreadId, FunctionCallError> {
register_session_root(session, turn);
if let Ok(thread_id) = ThreadId::from_string(target) {
return Ok(thread_id);
}
session
.services
.agent_control
.resolve_agent_reference(session.thread_id, &turn.session_source, target)
.await
.map_err(|err| match err.details() {
CodexErrorDetails::UnsupportedOperation(message) => {
FunctionCallError::RespondToModel(message.clone())
}
_ => FunctionCallError::RespondToModel(err.to_string()),
})
}
fn register_session_root(session: &Arc<Session>, turn: &Arc<TurnContext>) {
session
.services
.agent_control
.register_session_root(session.thread_id, turn.parent_thread_id);
}
|