mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
Simplify goal extension plumbing
This commit is contained in:
@@ -11,7 +11,6 @@ use codex_extension_api::AgentSpawnFuture;
|
||||
use codex_extension_api::AgentSpawner;
|
||||
use codex_extension_api::ExtensionEvent;
|
||||
use codex_extension_api::ExtensionEventFuture;
|
||||
use codex_extension_api::ExtensionEventMsg;
|
||||
use codex_extension_api::ExtensionEventSink;
|
||||
use codex_extension_api::ExtensionRegistry;
|
||||
use codex_extension_api::ExtensionRegistryBuilder;
|
||||
@@ -60,8 +59,8 @@ struct AppServerExtensionEventSink {
|
||||
impl ExtensionEventSink for AppServerExtensionEventSink {
|
||||
fn emit<'a>(&'a self, event: ExtensionEvent) -> ExtensionEventFuture<'a> {
|
||||
Box::pin(async move {
|
||||
match event.msg {
|
||||
ExtensionEventMsg::ThreadGoalUpdated(thread_goal_event) => {
|
||||
match event {
|
||||
ExtensionEvent::ThreadGoalUpdated(thread_goal_event) => {
|
||||
let notification =
|
||||
ServerNotification::ThreadGoalUpdated(ThreadGoalUpdatedNotification {
|
||||
thread_id: thread_goal_event.thread_id.to_string(),
|
||||
@@ -182,23 +181,20 @@ mod tests {
|
||||
objective: &str,
|
||||
turn_id: &str,
|
||||
) -> ExtensionEvent {
|
||||
ExtensionEvent {
|
||||
id: "call-1".to_string(),
|
||||
msg: ExtensionEventMsg::ThreadGoalUpdated(ThreadGoalUpdatedEvent {
|
||||
ExtensionEvent::ThreadGoalUpdated(ThreadGoalUpdatedEvent {
|
||||
thread_id,
|
||||
turn_id: Some(turn_id.to_string()),
|
||||
goal: ThreadGoal {
|
||||
thread_id,
|
||||
turn_id: Some(turn_id.to_string()),
|
||||
goal: ThreadGoal {
|
||||
thread_id,
|
||||
objective: objective.to_string(),
|
||||
status: ThreadGoalStatus::Active,
|
||||
token_budget: Some(123),
|
||||
tokens_used: 45,
|
||||
time_used_seconds: 6,
|
||||
created_at: 7,
|
||||
updated_at: 8,
|
||||
},
|
||||
}),
|
||||
}
|
||||
objective: objective.to_string(),
|
||||
status: ThreadGoalStatus::Active,
|
||||
token_budget: Some(123),
|
||||
tokens_used: 45,
|
||||
time_used_seconds: 6,
|
||||
created_at: 7,
|
||||
updated_at: 8,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
fn app_server_goal_update(
|
||||
|
||||
@@ -143,67 +143,42 @@ impl ThreadGoalRequestProcessor {
|
||||
.get_thread_goal(thread_id)
|
||||
.await
|
||||
.map_err(|err| invalid_request(err.to_string()))?;
|
||||
let (goal, previous_goal) = match (objective, existing_goal) {
|
||||
(Some(objective), Some(existing_goal)) => {
|
||||
let goal = state_db
|
||||
.thread_goals()
|
||||
.update_thread_goal(
|
||||
thread_id,
|
||||
codex_state::GoalUpdate {
|
||||
objective: Some(objective.to_string()),
|
||||
status,
|
||||
token_budget: params.token_budget,
|
||||
expected_goal_id: Some(existing_goal.goal_id.clone()),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map_err(|err| invalid_request(err.to_string()))?
|
||||
.ok_or_else(|| {
|
||||
invalid_request(format!(
|
||||
"cannot update goal for thread {thread_id}: no goal exists"
|
||||
))
|
||||
})?;
|
||||
(goal, Some(existing_goal))
|
||||
}
|
||||
(Some(objective), None) => {
|
||||
let goal = state_db
|
||||
.thread_goals()
|
||||
.replace_thread_goal(
|
||||
thread_id,
|
||||
objective,
|
||||
status.unwrap_or(codex_state::ThreadGoalStatus::Active),
|
||||
params.token_budget.flatten(),
|
||||
)
|
||||
.await
|
||||
.map_err(|err| invalid_request(err.to_string()))?;
|
||||
(goal, None)
|
||||
}
|
||||
(None, Some(existing_goal)) => {
|
||||
let goal = state_db
|
||||
.thread_goals()
|
||||
.update_thread_goal(
|
||||
thread_id,
|
||||
codex_state::GoalUpdate {
|
||||
objective: None,
|
||||
status,
|
||||
token_budget: params.token_budget,
|
||||
expected_goal_id: Some(existing_goal.goal_id.clone()),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map_err(|err| invalid_request(err.to_string()))?
|
||||
.ok_or_else(|| {
|
||||
invalid_request(format!(
|
||||
"cannot update goal for thread {thread_id}: no goal exists"
|
||||
))
|
||||
})?;
|
||||
(goal, Some(existing_goal))
|
||||
}
|
||||
(None, None) => {
|
||||
return Err(invalid_request(format!(
|
||||
"cannot update goal for thread {thread_id}: no goal exists"
|
||||
)));
|
||||
}
|
||||
let no_goal_error = || {
|
||||
invalid_request(format!(
|
||||
"cannot update goal for thread {thread_id}: no goal exists"
|
||||
))
|
||||
};
|
||||
let (goal, previous_goal) = if let Some(existing_goal) = existing_goal {
|
||||
let goal = state_db
|
||||
.thread_goals()
|
||||
.update_thread_goal(
|
||||
thread_id,
|
||||
codex_state::GoalUpdate {
|
||||
objective: objective.map(str::to_string),
|
||||
status,
|
||||
token_budget: params.token_budget,
|
||||
expected_goal_id: Some(existing_goal.goal_id.clone()),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map_err(|err| invalid_request(err.to_string()))?
|
||||
.ok_or_else(no_goal_error)?;
|
||||
(goal, Some(existing_goal))
|
||||
} else {
|
||||
let Some(objective) = objective else {
|
||||
return Err(no_goal_error());
|
||||
};
|
||||
let goal = state_db
|
||||
.thread_goals()
|
||||
.replace_thread_goal(
|
||||
thread_id,
|
||||
objective,
|
||||
status.unwrap_or(codex_state::ThreadGoalStatus::Active),
|
||||
params.token_budget.flatten(),
|
||||
)
|
||||
.await
|
||||
.map_err(|err| invalid_request(err.to_string()))?;
|
||||
(goal, None)
|
||||
};
|
||||
if should_set_thread_preview
|
||||
&& let Err(err) = state_db
|
||||
|
||||
Reference in New Issue
Block a user