mirror of
https://github.com/openai/codex.git
synced 2026-05-22 03:54:18 +00:00
feat: async approval contrib (#23690)
This commit is contained in:
@@ -134,18 +134,15 @@ pub trait ToolLifecycleContributor: Send + Sync {
|
||||
}
|
||||
}
|
||||
|
||||
/// Future returned by one claimed approval-review contribution.
|
||||
pub type ApprovalReviewFuture<'a> =
|
||||
std::pin::Pin<Box<dyn Future<Output = ReviewDecision> + Send + 'a>>;
|
||||
|
||||
/// Extension contribution that can claim rendered approval-review prompts.
|
||||
#[async_trait::async_trait]
|
||||
pub trait ApprovalReviewContributor: Send + Sync {
|
||||
fn contribute<'a>(
|
||||
&'a self,
|
||||
session_store: &'a ExtensionData,
|
||||
thread_store: &'a ExtensionData,
|
||||
prompt: &'a str,
|
||||
) -> Option<ApprovalReviewFuture<'a>>;
|
||||
async fn contribute(
|
||||
&self,
|
||||
session_store: &ExtensionData,
|
||||
thread_store: &ExtensionData,
|
||||
prompt: &str,
|
||||
) -> Option<ReviewDecision>;
|
||||
}
|
||||
|
||||
/// Future returned by one ordered turn-item contribution.
|
||||
|
||||
@@ -18,7 +18,6 @@ pub use codex_tools::ToolPayload;
|
||||
pub use codex_tools::ToolSpec;
|
||||
pub use codex_tools::parse_tool_input_schema;
|
||||
pub use contributors::ApprovalReviewContributor;
|
||||
pub use contributors::ApprovalReviewFuture;
|
||||
pub use contributors::ConfigContributor;
|
||||
pub use contributors::ContextContributor;
|
||||
pub use contributors::PromptFragment;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use codex_protocol::protocol::ReviewDecision;
|
||||
|
||||
use crate::ApprovalReviewContributor;
|
||||
use crate::ApprovalReviewFuture;
|
||||
use crate::ConfigContributor;
|
||||
use crate::ContextContributor;
|
||||
use crate::ExtensionData;
|
||||
@@ -171,15 +172,22 @@ impl<C: Sync> ExtensionRegistry<C> {
|
||||
|
||||
/// Claims the first rendered approval-review prompt accepted by an
|
||||
/// installed contributor.
|
||||
pub fn approval_review<'a>(
|
||||
&'a self,
|
||||
session_store: &'a ExtensionData,
|
||||
thread_store: &'a ExtensionData,
|
||||
prompt: &'a str,
|
||||
) -> Option<ApprovalReviewFuture<'a>> {
|
||||
self.approval_review_contributors
|
||||
.iter()
|
||||
.find_map(|contributor| contributor.contribute(session_store, thread_store, prompt))
|
||||
pub async fn approval_review(
|
||||
&self,
|
||||
session_store: &ExtensionData,
|
||||
thread_store: &ExtensionData,
|
||||
prompt: &str,
|
||||
) -> Option<ReviewDecision> {
|
||||
for contributor in &self.approval_review_contributors {
|
||||
if let Some(decision) = contributor
|
||||
.contribute(session_store, thread_store, prompt)
|
||||
.await
|
||||
{
|
||||
return Some(decision);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
/// Returns the registered prompt contributors.
|
||||
|
||||
Reference in New Issue
Block a user