mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
d2f6d23c6c
## Why
Extension contributors are registered behind `dyn Trait` objects, so
native `async fn`/RPITIT methods would make these traits
non-object-safe. Spell out the boxed, `Send` future contract directly so
`extension-api` no longer needs `async-trait` while retaining the
existing runtime model.
## What changed
- add a shared `ExtensionFuture` alias and use it for asynchronous
contributor methods
- migrate production and test implementations to return `Box::pin(async
move { ... })`
- remove `async-trait` dependencies where they are no longer used,
keeping it dev-only where unrelated test executors still require it
## Behavior
No behavior change is intended. Contributor futures remain boxed,
`Send`, dynamically dispatched, and lazily executed; cancellation and
callback ordering stay unchanged.
## Testing
- `just test -p codex-extension-api` (11 passed)
- affected extension crates (64 passed)
- targeted `codex-core` contributor tests (14 passed)
- `just fmt`
- `just bazel-lock-update`
- `just bazel-lock-check`
A broad local `codex-core` run compiled successfully but encountered
unrelated sandbox and missing test-binary fixture failures; CI will run
the full checks.
67 lines
2.1 KiB
Rust
67 lines
2.1 KiB
Rust
use super::*;
|
|
use codex_extension_api::ExtensionData;
|
|
use codex_extension_api::TurnItemContributor;
|
|
use codex_protocol::items::AgentMessageContent;
|
|
use pretty_assertions::assert_eq;
|
|
use std::sync::Arc;
|
|
|
|
struct RewriteAgentMessageContributor;
|
|
|
|
impl TurnItemContributor for RewriteAgentMessageContributor {
|
|
fn contribute<'a>(
|
|
&'a self,
|
|
_thread_store: &'a ExtensionData,
|
|
_turn_store: &'a ExtensionData,
|
|
item: &'a mut TurnItem,
|
|
) -> codex_extension_api::ExtensionFuture<'a, Result<(), String>> {
|
|
Box::pin(async move {
|
|
if let TurnItem::AgentMessage(agent_message) = item {
|
|
agent_message.content = vec![AgentMessageContent::Text {
|
|
text: "plan contributed assistant text".to_string(),
|
|
}];
|
|
}
|
|
Ok(())
|
|
})
|
|
}
|
|
}
|
|
|
|
fn assistant_output_text(text: &str) -> ResponseItem {
|
|
ResponseItem::Message {
|
|
id: Some("msg-1".to_string()),
|
|
role: "assistant".to_string(),
|
|
content: vec![ContentItem::OutputText {
|
|
text: text.to_string(),
|
|
}],
|
|
phase: None,
|
|
}
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn plan_mode_uses_contributed_turn_item_for_last_agent_message() {
|
|
let (mut session, turn_context) = crate::session::tests::make_session_and_context().await;
|
|
let mut builder = codex_extension_api::ExtensionRegistryBuilder::new();
|
|
builder.turn_item_contributor(Arc::new(RewriteAgentMessageContributor));
|
|
session.services.extensions = Arc::new(builder.build());
|
|
let turn_store = ExtensionData::new(turn_context.sub_id.clone());
|
|
let mut state = PlanModeStreamState::new(&turn_context.sub_id);
|
|
let mut last_agent_message = None;
|
|
let item = assistant_output_text("original assistant text");
|
|
|
|
let handled = handle_assistant_item_done_in_plan_mode(
|
|
&session,
|
|
&turn_context,
|
|
&turn_store,
|
|
&item,
|
|
&mut state,
|
|
/*previously_active_item*/ None,
|
|
&mut last_agent_message,
|
|
)
|
|
.await;
|
|
|
|
assert!(handled);
|
|
assert_eq!(
|
|
last_agent_message.as_deref(),
|
|
Some("plan contributed assistant text")
|
|
);
|
|
}
|