mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
06afd63f4a
## Why Codex needs to manage Amazon Bedrock API key credentials through the existing auth lifecycle instead of introducing a separate auth manager or provider-specific credential file. Treating Bedrock API key login as a primary auth mode gives it the same persistence, keyring, reload, and logout behavior as the existing OpenAI API key and ChatGPT modes. The credential is valid only for the `amazon-bedrock` model provider. OpenAI-compatible providers must reject this auth mode rather than treating the Bedrock key as an OpenAI bearer token. ## What changed - Added `bedrockApiKey` as an app-server `AuthMode` and `CodexAuth::BedrockApiKey` as a primary `AuthManager` mode. - Added `BedrockApiKeyAuth`, containing the API key and AWS region, to the existing `AuthDotJson` payload stored in `$CODEX_HOME/auth.json` or the configured keyring backend. - Added `login_with_bedrock_api_key(...)`, parallel to `login_with_api_key(...)`, which replaces the current stored login with Bedrock credentials. - Reused generic auth reload and logout behavior instead of adding a Bedrock-specific auth manager or logout path. - Updated login restrictions, status reporting, diagnostics, telemetry classification, generated app-server schemas, and auth fixtures for the new mode. - Added explicit errors when Bedrock API key auth is selected with an OpenAI-compatible model provider. This PR establishes managed storage and auth-mode behavior. Routing the managed key and region into Amazon Bedrock requests will be in follow-up PRs.
80 lines
2.9 KiB
Rust
80 lines
2.9 KiB
Rust
pub(crate) mod config;
|
|
mod events;
|
|
pub(crate) mod metrics;
|
|
pub(crate) mod provider;
|
|
pub(crate) mod trace_context;
|
|
|
|
mod otlp;
|
|
mod targets;
|
|
|
|
use crate::metrics::Result as MetricsResult;
|
|
use serde::Serialize;
|
|
use strum_macros::Display;
|
|
|
|
pub use crate::config::OtelExporter;
|
|
pub use crate::config::OtelHttpProtocol;
|
|
pub use crate::config::OtelSettings;
|
|
pub use crate::config::OtelTlsConfig;
|
|
pub use crate::config::StatsigMetricsSettings;
|
|
pub use crate::config::validate_span_attributes;
|
|
pub use crate::events::session_telemetry::AuthEnvTelemetryMetadata;
|
|
pub use crate::events::session_telemetry::SessionTelemetry;
|
|
pub use crate::events::session_telemetry::SessionTelemetryMetadata;
|
|
pub use crate::metrics::runtime_metrics::RuntimeMetricTotals;
|
|
pub use crate::metrics::runtime_metrics::RuntimeMetricsSummary;
|
|
pub use crate::metrics::timer::Timer;
|
|
pub use crate::metrics::*;
|
|
pub use crate::provider::OtelProvider;
|
|
pub use crate::trace_context::context_from_w3c_trace_context;
|
|
pub use crate::trace_context::current_span_trace_id;
|
|
pub use crate::trace_context::current_span_w3c_trace_context;
|
|
pub use crate::trace_context::set_parent_from_context;
|
|
pub use crate::trace_context::set_parent_from_w3c_trace_context;
|
|
pub use crate::trace_context::span_w3c_trace_context;
|
|
pub use crate::trace_context::traceparent_context_from_env;
|
|
pub use crate::trace_context::validate_tracestate_entries;
|
|
pub use crate::trace_context::validate_tracestate_member;
|
|
pub use codex_utils_string::sanitize_metric_tag_value;
|
|
|
|
#[derive(Debug, Clone, Serialize, Display)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum ToolDecisionSource {
|
|
AutomatedReviewer,
|
|
Config,
|
|
User,
|
|
}
|
|
|
|
/// Maps to API/auth `AuthMode` to avoid a circular dependency on codex-core.
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Display)]
|
|
pub enum TelemetryAuthMode {
|
|
ApiKey,
|
|
Chatgpt,
|
|
}
|
|
|
|
impl From<codex_app_server_protocol::AuthMode> for TelemetryAuthMode {
|
|
fn from(mode: codex_app_server_protocol::AuthMode) -> Self {
|
|
match mode {
|
|
codex_app_server_protocol::AuthMode::ApiKey
|
|
| codex_app_server_protocol::AuthMode::BedrockApiKey => Self::ApiKey,
|
|
codex_app_server_protocol::AuthMode::Chatgpt
|
|
| codex_app_server_protocol::AuthMode::ChatgptAuthTokens
|
|
| codex_app_server_protocol::AuthMode::AgentIdentity
|
|
| codex_app_server_protocol::AuthMode::PersonalAccessToken => Self::Chatgpt,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Start a metrics timer using the globally installed metrics client.
|
|
pub fn start_global_timer(name: &str, tags: &[(&str, &str)]) -> MetricsResult<Timer> {
|
|
let Some(metrics) = crate::metrics::global() else {
|
|
return Err(MetricsError::ExporterDisabled);
|
|
};
|
|
metrics.start_timer(name, tags)
|
|
}
|
|
|
|
/// Returns the resolved Statsig metrics settings for the globally installed
|
|
/// OTEL metrics client, if the active metrics exporter is Statsig.
|
|
pub fn global_statsig_metrics_settings() -> Option<StatsigMetricsSettings> {
|
|
crate::metrics::global_statsig_settings()
|
|
}
|