mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
## What changed For enrolled threads with Daybreak propagation enabled, carry the creating turn's explicit access program into automatic continuations of the same model-created goal. Reuse it only while the account, model, and provider still match. Editing the objective preserves the selection, and clearing the goal discards it. ## Testing App-server regression tests check that automatic continuations honor enrollment even after an objective edit, that explicit requests retain their selection regardless of enrollment, and that a replacement goal created after clearing starts without the previous goal's selection. GitOrigin-RevId: 346742f6587f14867b1acc9c570383d1fa405d17
104 lines
3.4 KiB
Rust
104 lines
3.4 KiB
Rust
//! Forward explicit programs while leaving entitlement and model policy to the server.
|
|
|
|
use codex_api::AccessPrograms;
|
|
use codex_features::Feature;
|
|
use codex_login::CodexAuth;
|
|
use codex_protocol::error::CodexErr;
|
|
use codex_protocol::error::Result;
|
|
use codex_protocol::turn_input::CyberAccessProgram;
|
|
use std::sync::Arc;
|
|
|
|
pub use crate::session::turn_context::ContinuationCyberAccessProgram;
|
|
|
|
/// Host requirement for every model request issued by this thread.
|
|
///
|
|
/// Install in thread extension data before startup and reapply on cold resume.
|
|
/// Core snapshots it before extension callbacks; it is not inherited or persisted.
|
|
/// Every request must resolve to one listed program; backend authorization remains authoritative.
|
|
#[derive(Clone, Debug)]
|
|
pub struct RequiredCyberAccessPrograms {
|
|
pub allowed: Vec<CyberAccessProgram>,
|
|
}
|
|
|
|
pub(crate) struct RequiredCyberAccessProgramsSnapshot(pub Arc<RequiredCyberAccessPrograms>);
|
|
|
|
impl RequiredCyberAccessPrograms {
|
|
/// Read Core's startup snapshot, independent of later edits to the public attachment.
|
|
pub fn for_thread(data: &codex_extension_api::ExtensionData) -> Option<Arc<Self>> {
|
|
data.get::<RequiredCyberAccessProgramsSnapshot>()
|
|
.map(|snapshot| Arc::clone(&snapshot.0))
|
|
}
|
|
}
|
|
|
|
/// Configured support for explicit Cyber programs on API-key requests.
|
|
#[derive(Clone, Copy, Debug)]
|
|
pub enum ApiKeyCyberAccessPrograms {
|
|
UnsupportedProvider,
|
|
Disabled,
|
|
Enabled,
|
|
}
|
|
|
|
impl ApiKeyCyberAccessPrograms {
|
|
/// Captures the same provider and feature policy used by ordinary model requests.
|
|
pub fn from_config(config: &crate::config::Config) -> Self {
|
|
Self::for_provider(
|
|
&config.model_provider,
|
|
&config.model_provider_id,
|
|
&config.features,
|
|
)
|
|
}
|
|
|
|
/// Resolves API-key policy for the provider that will receive the request.
|
|
pub fn for_provider(
|
|
provider: &codex_model_provider_info::ModelProviderInfo,
|
|
provider_id: &str,
|
|
features: &codex_features::Features,
|
|
) -> Self {
|
|
if !provider.supports_cyber_access_programs(provider_id) {
|
|
Self::UnsupportedProvider
|
|
} else if features.enabled(Feature::ApiKeyCyberAccessPrograms) {
|
|
Self::Enabled
|
|
} else {
|
|
Self::Disabled
|
|
}
|
|
}
|
|
}
|
|
|
|
pub(crate) fn for_provider(
|
|
config: &crate::config::Config,
|
|
program: Option<CyberAccessProgram>,
|
|
) -> Option<CyberAccessProgram> {
|
|
program.filter(|_| {
|
|
config
|
|
.model_provider
|
|
.supports_cyber_access_programs(&config.model_provider_id)
|
|
})
|
|
}
|
|
|
|
/// Resolves an explicit program using the request's current authentication.
|
|
pub fn for_auth(
|
|
auth: Option<&CodexAuth>,
|
|
program: Option<CyberAccessProgram>,
|
|
policy: ApiKeyCyberAccessPrograms,
|
|
) -> Result<Option<AccessPrograms>> {
|
|
let Some(program) = program else {
|
|
return Ok(None);
|
|
};
|
|
let Some(auth) = auth else {
|
|
return Ok(None);
|
|
};
|
|
if auth.is_chatgpt_auth() || matches!(auth, CodexAuth::Headers(_)) {
|
|
return Ok(Some(program.into()));
|
|
}
|
|
if !auth.is_api_key_auth() {
|
|
return Ok(None);
|
|
}
|
|
match policy {
|
|
ApiKeyCyberAccessPrograms::UnsupportedProvider => Ok(None),
|
|
ApiKeyCyberAccessPrograms::Disabled => Err(CodexErr::InvalidRequest(
|
|
"Cyber access programs are disabled for this API-key session.".to_owned(),
|
|
)),
|
|
ApiKeyCyberAccessPrograms::Enabled => Ok(Some(program.into())),
|
|
}
|
|
}
|