aKode fase 2b-2: rimosso login ChatGPT e tutti i sottosistemi solo-ChatGPT
- Login: resta solo chiave API (+ header, Bedrock). Rimossi OAuth/browser, device code, refresh/revoke su auth.openai.com, PAT, agent/workload identity, runtime agent instance, backend-client e openapi-models, workspace routing. - Rimossi: generazione immagini (ext + skill imagegen), history notes, plugin remoti (catalogo, sync, share), cyber access program, daybreak, cloud config e requirements (config_server ora fail-closed), attestation, frozen cloud skills, EMA MCP auth, Codex Apps/connettori, ricerca ospitata, header/zstd/ routing/cookie del backend Codex, fallback OPENAI_API_KEY del realtime. - Messaggi d'errore senza link a chatgpt.com. - Chiavi di config legacy accettate e ignorate; feature rimosse = Stage::Removed. - Test: cancellati solo quelli del codice rimosso; test di sicurezza (sandbox estensioni, permessi, redazione, auth storage, requirements) adattati. Restano solo fallimenti d'ambiente (code-mode-host/V8, ~/.agents). - Istruzioni di sistema invariate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -103,7 +103,6 @@
|
||||
"permissions": null,
|
||||
"token_budget": {
|
||||
"enabled": false,
|
||||
"use_history_notes_extension": false,
|
||||
"reminder_threshold_tokens": 6144,
|
||||
"reminder_message_template": "<context_window_reminder>\nYour current context window is nearly exhausted; only {n_remaining} tokens remain. Before starting a new context window, save concise progress notes with the `notes` tool with the goal, decisions, progress, learnings, next steps, and the window ID and item ID of every relevant user request still being solved, as well as important actions/tool calls for future reference. Note that every non-assistant item, such as user, developer, tool response, has an item id `[id: ...]` that is immediately after its item content. You should write or append notes in a way to best help you recover in a new context window. It is also a good idea to clean up your old notes if they become obsolete or irrelevant. Future context windows will not automatically include the current conversation. After saving your state, call `functions.new_context` to continue in a fresh context window.\n</context_window_reminder>",
|
||||
"guidance_message": "For tasks that may span context windows, use `notes` to maintain a concise checkpoint of the goal, decisions, progress, learnings and next steps. Include the window ID and item ID for every relevant user request you are currently solving as well as important actions/tool calls. You can use `history` tool to look up details with the references later. Note that every non-assistant item, such as user, developer, tool response, has an item id `[id: ...]` that is immediately after its item content. Relative note paths belong to the current thread; absolute paths may read other threads' notes, but writes are limited to the current thread.\n\nIt is a good idea to take incremental notes while you work so that you do not miss any important info. You can also use `get_context_remaining` tool to find the remaining token budget for better planning. Once the token budget is exhausted, you will lose access to the current window and continue in a fresh context window and you can only recover through `notes` and `history` tools. So be careful not to over-run the context window without any documentation.\n\nIf Previous context window id is present in `<context_window>`, it means a context reset occurred and this is a new window. After a reset, read the checkpoint and use the read-only `history` tool to recover any missing details. When a window ID and item ID are known, prefer `read_item` directly; when they are missing or uncertain, use `list_items`, or `search_contents` to locate the item first.\n\nTreat notes and history as internal bookkeeping. Do not mention them in user-facing messages.\n",
|
||||
@@ -277,7 +276,6 @@
|
||||
"permissions": null,
|
||||
"token_budget": {
|
||||
"enabled": false,
|
||||
"use_history_notes_extension": false,
|
||||
"reminder_threshold_tokens": 6144,
|
||||
"reminder_message_template": "<context_window_reminder>\nYour current context window is nearly exhausted; only {n_remaining} tokens remain. Before starting a new context window, save concise progress notes with the `notes` tool with the goal, decisions, progress, learnings, next steps, and the window ID and item ID of every relevant user request still being solved, as well as important actions/tool calls for future reference. Note that every non-assistant item, such as user, developer, tool response, has an item id `[id: ...]` that is immediately after its item content. You should write or append notes in a way to best help you recover in a new context window. It is also a good idea to clean up your old notes if they become obsolete or irrelevant. Future context windows will not automatically include the current conversation. After saving your state, call `functions.new_context` to continue in a fresh context window.\n</context_window_reminder>",
|
||||
"guidance_message": "For tasks that may span context windows, use `notes` to maintain a concise checkpoint of the goal, decisions, progress, learnings and next steps. Include the window ID and item ID for every relevant user request you are currently solving as well as important actions/tool calls. You can use `history` tool to look up details with the references later. Note that every non-assistant item, such as user, developer, tool response, has an item id `[id: ...]` that is immediately after its item content. Relative note paths belong to the current thread; absolute paths may read other threads' notes, but writes are limited to the current thread.\n\nIt is a good idea to take incremental notes while you work so that you do not miss any important info. You can also use `get_context_remaining` tool to find the remaining token budget for better planning. Once the token budget is exhausted, you will lose access to the current window and continue in a fresh context window and you can only recover through `notes` and `history` tools. So be careful not to over-run the context window without any documentation.\n\nIf Previous context window id is present in `<context_window>`, it means a context reset occurred and this is a new window. After a reset, read the checkpoint and use the read-only `history` tool to recover any missing details. When a window ID and item ID are known, prefer `read_item` directly; when they are missing or uncertain, use `list_items`, or `search_contents` to locate the item first.\n\nTreat notes and history as internal bookkeeping. Do not mention them in user-facing messages.\n",
|
||||
@@ -450,7 +448,6 @@
|
||||
},
|
||||
"token_budget": {
|
||||
"enabled": false,
|
||||
"use_history_notes_extension": false,
|
||||
"reminder_threshold_tokens": 6144,
|
||||
"reminder_message_template": "<context_window_reminder>\nYour current context window is nearly exhausted; only {n_remaining} tokens remain. Before starting a new context window, save concise progress notes with the `notes` tool with the goal, decisions, progress, learnings, next steps, and the window ID and item ID of every relevant user request still being solved, as well as important actions/tool calls for future reference. Note that every non-assistant item, such as user, developer, tool response, has an item id `[id: ...]` that is immediately after its item content. You should write or append notes in a way to best help you recover in a new context window. It is also a good idea to clean up your old notes if they become obsolete or irrelevant. Future context windows will not automatically include the current conversation. After saving your state, call `functions.new_context` to continue in a fresh context window.\n</context_window_reminder>",
|
||||
"guidance_message": "For tasks that may span context windows, use `notes` to maintain a concise checkpoint of the goal, decisions, progress, learnings and next steps. Include the window ID and item ID for every relevant user request you are currently solving as well as important actions/tool calls. You can use `history` tool to look up details with the references later. Note that every non-assistant item, such as user, developer, tool response, has an item id `[id: ...]` that is immediately after its item content. Relative note paths belong to the current thread; absolute paths may read other threads' notes, but writes are limited to the current thread.\n\nIt is a good idea to take incremental notes while you work so that you do not miss any important info. You can also use `get_context_remaining` tool to find the remaining token budget for better planning. Once the token budget is exhausted, you will lose access to the current window and continue in a fresh context window and you can only recover through `notes` and `history` tools. So be careful not to over-run the context window without any documentation.\n\nIf Previous context window id is present in `<context_window>`, it means a context reset occurred and this is a new window. After a reset, read the checkpoint and use the read-only `history` tool to recover any missing details. When a window ID and item ID are known, prefer `read_item` directly; when they are missing or uncertain, use `list_items`, or `search_contents` to locate the item first.\n\nTreat notes and history as internal bookkeeping. Do not mention them in user-facing messages.\n",
|
||||
@@ -627,7 +624,6 @@
|
||||
"permissions": null,
|
||||
"token_budget": {
|
||||
"enabled": false,
|
||||
"use_history_notes_extension": false,
|
||||
"reminder_threshold_tokens": 6144,
|
||||
"reminder_message_template": "<context_window_reminder>\nYour current context window is nearly exhausted; only {n_remaining} tokens remain. Before starting a new context window, save concise progress notes with the `notes` tool with the goal, decisions, progress, learnings, next steps, and the window ID and item ID of every relevant user request still being solved, as well as important actions/tool calls for future reference. Note that every non-assistant item, such as user, developer, tool response, has an item id `[id: ...]` that is immediately after its item content. You should write or append notes in a way to best help you recover in a new context window. It is also a good idea to clean up your old notes if they become obsolete or irrelevant. Future context windows will not automatically include the current conversation. After saving your state, call `functions.new_context` to continue in a fresh context window.\n</context_window_reminder>",
|
||||
"guidance_message": "For tasks that may span context windows, use `notes` to maintain a concise checkpoint of the goal, decisions, progress, learnings and next steps. Include the window ID and item ID for every relevant user request you are currently solving as well as important actions/tool calls. You can use `history` tool to look up details with the references later. Note that every non-assistant item, such as user, developer, tool response, has an item id `[id: ...]` that is immediately after its item content. Relative note paths belong to the current thread; absolute paths may read other threads' notes, but writes are limited to the current thread.\n\nIt is a good idea to take incremental notes while you work so that you do not miss any important info. You can also use `get_context_remaining` tool to find the remaining token budget for better planning. Once the token budget is exhausted, you will lose access to the current window and continue in a fresh context window and you can only recover through `notes` and `history` tools. So be careful not to over-run the context window without any documentation.\n\nIf Previous context window id is present in `<context_window>`, it means a context reset occurred and this is a new window. After a reset, read the checkpoint and use the read-only `history` tool to recover any missing details. When a window ID and item ID are known, prefer `read_item` directly; when they are missing or uncertain, use `list_items`, or `search_contents` to locate the item first.\n\nTreat notes and history as internal bookkeeping. Do not mention them in user-facing messages.\n",
|
||||
@@ -794,7 +790,6 @@
|
||||
"permissions": null,
|
||||
"token_budget": {
|
||||
"enabled": false,
|
||||
"use_history_notes_extension": false,
|
||||
"reminder_threshold_tokens": 6144,
|
||||
"reminder_message_template": "<context_window_reminder>\nYour current context window is nearly exhausted; only {n_remaining} tokens remain. Before starting a new context window, save concise progress notes with the `notes` tool with the goal, decisions, progress, learnings, next steps, and the window ID and item ID of every relevant user request still being solved, as well as important actions/tool calls for future reference. Note that every non-assistant item, such as user, developer, tool response, has an item id `[id: ...]` that is immediately after its item content. You should write or append notes in a way to best help you recover in a new context window. It is also a good idea to clean up your old notes if they become obsolete or irrelevant. Future context windows will not automatically include the current conversation. After saving your state, call `functions.new_context` to continue in a fresh context window.\n</context_window_reminder>",
|
||||
"guidance_message": "For tasks that may span context windows, use `notes` to maintain a concise checkpoint of the goal, decisions, progress, learnings and next steps. Include the window ID and item ID for every relevant user request you are currently solving as well as important actions/tool calls. You can use `history` tool to look up details with the references later. Note that every non-assistant item, such as user, developer, tool response, has an item id `[id: ...]` that is immediately after its item content. Relative note paths belong to the current thread; absolute paths may read other threads' notes, but writes are limited to the current thread.\n\nIt is a good idea to take incremental notes while you work so that you do not miss any important info. You can also use `get_context_remaining` tool to find the remaining token budget for better planning. Once the token budget is exhausted, you will lose access to the current window and continue in a fresh context window and you can only recover through `notes` and `history` tools. So be careful not to over-run the context window without any documentation.\n\nIf Previous context window id is present in `<context_window>`, it means a context reset occurred and this is a new window. After a reset, read the checkpoint and use the read-only `history` tool to recover any missing details. When a window ID and item ID are known, prefer `read_item` directly; when they are missing or uncertain, use `list_items`, or `search_contents` to locate the item first.\n\nTreat notes and history as internal bookkeeping. Do not mention them in user-facing messages.\n",
|
||||
@@ -950,7 +945,6 @@
|
||||
"permissions": null,
|
||||
"token_budget": {
|
||||
"enabled": false,
|
||||
"use_history_notes_extension": false,
|
||||
"reminder_threshold_tokens": 6144,
|
||||
"reminder_message_template": "<context_window_reminder>\nYour current context window is nearly exhausted; only {n_remaining} tokens remain. Before starting a new context window, save concise progress notes with the `notes` tool with the goal, decisions, progress, learnings, next steps, and the window ID and item ID of every relevant user request still being solved, as well as important actions/tool calls for future reference. Note that every non-assistant item, such as user, developer, tool response, has an item id `[id: ...]` that is immediately after its item content. You should write or append notes in a way to best help you recover in a new context window. It is also a good idea to clean up your old notes if they become obsolete or irrelevant. Future context windows will not automatically include the current conversation. After saving your state, call `functions.new_context` to continue in a fresh context window.\n</context_window_reminder>",
|
||||
"guidance_message": "For tasks that may span context windows, use `notes` to maintain a concise checkpoint of the goal, decisions, progress, learnings and next steps. Include the window ID and item ID for every relevant user request you are currently solving as well as important actions/tool calls. You can use `history` tool to look up details with the references later. Note that every non-assistant item, such as user, developer, tool response, has an item id `[id: ...]` that is immediately after its item content. Relative note paths belong to the current thread; absolute paths may read other threads' notes, but writes are limited to the current thread.\n\nIt is a good idea to take incremental notes while you work so that you do not miss any important info. You can also use `get_context_remaining` tool to find the remaining token budget for better planning. Once the token budget is exhausted, you will lose access to the current window and continue in a fresh context window and you can only recover through `notes` and `history` tools. So be careful not to over-run the context window without any documentation.\n\nIf Previous context window id is present in `<context_window>`, it means a context reset occurred and this is a new window. After a reset, read the checkpoint and use the read-only `history` tool to recover any missing details. When a window ID and item ID are known, prefer `read_item` directly; when they are missing or uncertain, use `list_items`, or `search_contents` to locate the item first.\n\nTreat notes and history as internal bookkeeping. Do not mention them in user-facing messages.\n",
|
||||
@@ -1091,7 +1085,6 @@
|
||||
"permissions": null,
|
||||
"token_budget": {
|
||||
"enabled": false,
|
||||
"use_history_notes_extension": false,
|
||||
"reminder_threshold_tokens": 6144,
|
||||
"reminder_message_template": "<context_window_reminder>\nYour current context window is nearly exhausted; only {n_remaining} tokens remain. Before starting a new context window, save concise progress notes with the `notes` tool with the goal, decisions, progress, learnings, next steps, and the window ID and item ID of every relevant user request still being solved, as well as important actions/tool calls for future reference. Note that every non-assistant item, such as user, developer, tool response, has an item id `[id: ...]` that is immediately after its item content. You should write or append notes in a way to best help you recover in a new context window. It is also a good idea to clean up your old notes if they become obsolete or irrelevant. Future context windows will not automatically include the current conversation. After saving your state, call `functions.new_context` to continue in a fresh context window.\n</context_window_reminder>",
|
||||
"guidance_message": "For tasks that may span context windows, use `notes` to maintain a concise checkpoint of the goal, decisions, progress, learnings and next steps. Include the window ID and item ID for every relevant user request you are currently solving as well as important actions/tool calls. You can use `history` tool to look up details with the references later. Note that every non-assistant item, such as user, developer, tool response, has an item id `[id: ...]` that is immediately after its item content. Relative note paths belong to the current thread; absolute paths may read other threads' notes, but writes are limited to the current thread.\n\nIt is a good idea to take incremental notes while you work so that you do not miss any important info. You can also use `get_context_remaining` tool to find the remaining token budget for better planning. Once the token budget is exhausted, you will lose access to the current window and continue in a fresh context window and you can only recover through `notes` and `history` tools. So be careful not to over-run the context window without any documentation.\n\nIf Previous context window id is present in `<context_window>`, it means a context reset occurred and this is a new window. After a reset, read the checkpoint and use the read-only `history` tool to recover any missing details. When a window ID and item ID are known, prefer `read_item` directly; when they are missing or uncertain, use `list_items`, or `search_contents` to locate the item first.\n\nTreat notes and history as internal bookkeeping. Do not mention them in user-facing messages.\n",
|
||||
@@ -1232,7 +1225,6 @@
|
||||
"permissions": null,
|
||||
"token_budget": {
|
||||
"enabled": false,
|
||||
"use_history_notes_extension": false,
|
||||
"reminder_threshold_tokens": 6144,
|
||||
"reminder_message_template": "<context_window_reminder>\nYour current context window is nearly exhausted; only {n_remaining} tokens remain. Before starting a new context window, save concise progress notes with the `notes` tool with the goal, decisions, progress, learnings, next steps, and the window ID and item ID of every relevant user request still being solved, as well as important actions/tool calls for future reference. Note that every non-assistant item, such as user, developer, tool response, has an item id `[id: ...]` that is immediately after its item content. You should write or append notes in a way to best help you recover in a new context window. It is also a good idea to clean up your old notes if they become obsolete or irrelevant. Future context windows will not automatically include the current conversation. After saving your state, call `functions.new_context` to continue in a fresh context window.\n</context_window_reminder>",
|
||||
"guidance_message": "For tasks that may span context windows, use `notes` to maintain a concise checkpoint of the goal, decisions, progress, learnings and next steps. Include the window ID and item ID for every relevant user request you are currently solving as well as important actions/tool calls. You can use `history` tool to look up details with the references later. Note that every non-assistant item, such as user, developer, tool response, has an item id `[id: ...]` that is immediately after its item content. Relative note paths belong to the current thread; absolute paths may read other threads' notes, but writes are limited to the current thread.\n\nIt is a good idea to take incremental notes while you work so that you do not miss any important info. You can also use `get_context_remaining` tool to find the remaining token budget for better planning. Once the token budget is exhausted, you will lose access to the current window and continue in a fresh context window and you can only recover through `notes` and `history` tools. So be careful not to over-run the context window without any documentation.\n\nIf Previous context window id is present in `<context_window>`, it means a context reset occurred and this is a new window. After a reset, read the checkpoint and use the read-only `history` tool to recover any missing details. When a window ID and item ID are known, prefer `read_item` directly; when they are missing or uncertain, use `list_items`, or `search_contents` to locate the item first.\n\nTreat notes and history as internal bookkeeping. Do not mention them in user-facing messages.\n",
|
||||
|
||||
@@ -19,10 +19,11 @@ async fn mismatched_and_legacy_cache_entries_fetch_the_current_catalog() {
|
||||
let manager = OpenAiModelsManager::new_with_cache(
|
||||
cache.clone(),
|
||||
endpoint.clone(),
|
||||
Some(AuthManager::from_auth_for_testing(
|
||||
CodexAuth::create_dummy_chatgpt_auth_for_testing(),
|
||||
)),
|
||||
Some(AuthManager::from_auth_for_testing(CodexAuth::from_api_key(
|
||||
"test-api-key",
|
||||
))),
|
||||
);
|
||||
manager.set_api_key_model_discovery_enabled(/*enabled*/ true);
|
||||
manager
|
||||
.ensure_initialized(DEFAULT_HTTP_CLIENT_FACTORY)
|
||||
.await;
|
||||
|
||||
@@ -12,8 +12,7 @@ async fn catalog_origins_survive_reload_and_auth_change() {
|
||||
] {
|
||||
let home = tempdir().unwrap();
|
||||
let model = remote_model_with_visibility(slug, "Gateway", /*priority*/ 0, "hide");
|
||||
let auth =
|
||||
AuthManager::from_auth_for_testing(CodexAuth::create_dummy_chatgpt_auth_for_testing());
|
||||
let auth = AuthManager::from_auth_for_testing(CodexAuth::from_api_key("test-api-key"));
|
||||
let endpoint =
|
||||
TestAuthAwareModelsEndpoint::new(Some(auth.clone()), vec![vec![model.clone()]]);
|
||||
let manager =
|
||||
@@ -151,12 +150,14 @@ async fn refreshing_retained_originators_keeps_catalog_notifications_isolated()
|
||||
let work_model = remote_model("work-model", "Work", /*priority*/ 0);
|
||||
let root_endpoint = TestModelsEndpoint::new(vec![vec![root_model.clone()]]);
|
||||
let work_endpoint = TestModelsEndpoint::new(vec![vec![work_model.clone()]]);
|
||||
let root =
|
||||
OpenAiModelsManager::new_without_cache(root_endpoint.clone(), /*auth_manager*/ None);
|
||||
let auth = AuthManager::from_auth_for_testing(CodexAuth::from_api_key("test-api-key"));
|
||||
let root = OpenAiModelsManager::new_without_cache(root_endpoint.clone(), Some(auth.clone()));
|
||||
root.set_api_key_model_discovery_enabled(/*enabled*/ true);
|
||||
let work = Arc::new(OpenAiModelsManager::new_without_cache(
|
||||
work_endpoint.clone(),
|
||||
/*auth_manager*/ None,
|
||||
Some(auth),
|
||||
));
|
||||
work.set_api_key_model_discovery_enabled(/*enabled*/ true);
|
||||
root.list_models(RefreshStrategy::Online, DEFAULT_HTTP_CLIENT_FACTORY)
|
||||
.await;
|
||||
let root_updates = root.model_catalog_updates().unwrap();
|
||||
|
||||
@@ -65,9 +65,6 @@ pub trait ModelsEndpointClient: fmt::Debug + Send + Sync {
|
||||
/// Returns whether this provider can authenticate command-scoped requests.
|
||||
fn has_command_auth(&self) -> bool;
|
||||
|
||||
/// Returns whether the currently resolved auth can use Codex backend-only models.
|
||||
fn uses_codex_backend(&self) -> ModelsEndpointFuture<'_, bool>;
|
||||
|
||||
/// Returns whether this provider supports an authoritative catalog with OpenAI API keys.
|
||||
fn supports_api_key_models(&self) -> bool {
|
||||
false
|
||||
@@ -255,10 +252,7 @@ pub trait ModelsManager: fmt::Debug + Send + Sync {
|
||||
remote_models.sort_by_key(|model| model.priority);
|
||||
|
||||
let mut presets: Vec<ModelPreset> = remote_models.into_iter().map(Into::into).collect();
|
||||
let uses_codex_backend = self
|
||||
.auth_manager()
|
||||
.is_some_and(AuthManager::current_auth_uses_codex_backend);
|
||||
presets = ModelPreset::filter_by_auth(presets, uses_codex_backend);
|
||||
presets = ModelPreset::filter_by_auth(presets, /*chatgpt_mode*/ false);
|
||||
|
||||
ModelPreset::mark_default_by_picker_visibility(&mut presets);
|
||||
|
||||
@@ -944,11 +938,27 @@ impl OpenAiModelsManager {
|
||||
}
|
||||
|
||||
async fn should_refresh_models(&self) -> bool {
|
||||
self.endpoint_client.uses_codex_backend().await
|
||||
|| self.endpoint_client.has_command_auth()
|
||||
// Resolve lazy command credentials so identity checks observe the current token.
|
||||
// Catalog startup has its own deadline; let rotating credentials finish saving even
|
||||
// when that caller stops waiting.
|
||||
if let Some(auth_manager) = self.auth_manager.clone()
|
||||
&& let Err(error) = tokio::spawn(async move { auth_manager.auth().await }).await
|
||||
{
|
||||
tracing::warn!(?error, "model catalog authentication task failed");
|
||||
}
|
||||
self.endpoint_client.has_command_auth()
|
||||
|| self.uses_host_header_auth()
|
||||
|| self.supports_api_key_discovery()
|
||||
}
|
||||
|
||||
/// Host-supplied header credentials authenticate catalog requests like command auth:
|
||||
/// the provider catalog is merged over the bundled one.
|
||||
fn uses_host_header_auth(&self) -> bool {
|
||||
self.auth_manager
|
||||
.as_ref()
|
||||
.is_some_and(|auth_manager| auth_manager.auth_mode() == Some(AuthMode::Headers))
|
||||
}
|
||||
|
||||
/// Publish only while the request identity still matches, including after async storage.
|
||||
fn apply_remote_models(
|
||||
&self,
|
||||
@@ -969,12 +979,7 @@ impl OpenAiModelsManager {
|
||||
.models
|
||||
.iter()
|
||||
.any(|model| model.visibility == ModelVisibility::List)
|
||||
&& (self.supports_api_key_discovery()
|
||||
|| self.auth_manager.as_ref().is_some_and(|auth_manager| {
|
||||
auth_manager
|
||||
.auth_mode()
|
||||
.is_some_and(AuthMode::has_chatgpt_account)
|
||||
}));
|
||||
&& self.supports_api_key_discovery();
|
||||
if !remote_only && let Some(mut models) = self.catalog_source.fallback_models() {
|
||||
for model in std::mem::take(&mut entry.models) {
|
||||
if let Some(index) = models
|
||||
|
||||
@@ -8,19 +8,13 @@ use crate::cache::ModelsCacheFuture;
|
||||
use chrono::Utc;
|
||||
use codex_http_client::HttpClientFactory;
|
||||
use codex_http_client::OutboundProxyPolicy;
|
||||
use codex_login::AuthCredentialsStoreMode;
|
||||
use codex_login::AuthKeyringBackendKind;
|
||||
use codex_login::AuthManager;
|
||||
use codex_login::CodexAuth;
|
||||
use codex_login::ExternalAuth;
|
||||
use codex_login::ExternalAuthRefreshContext;
|
||||
use codex_login::TokenData;
|
||||
use codex_protocol::auth::AuthMode;
|
||||
use codex_protocol::error::CodexErr;
|
||||
use codex_protocol::openai_models::ModelAccessPrograms;
|
||||
use codex_protocol::openai_models::ModelOrigin;
|
||||
use codex_protocol::openai_models::ModelsResponse;
|
||||
use codex_protocol::turn_input::CyberAccessProgram;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
use std::collections::VecDeque;
|
||||
@@ -99,7 +93,6 @@ fn assert_models_contain(actual: &[ModelInfo], expected: &[ModelInfo]) {
|
||||
#[derive(Debug, Default)]
|
||||
struct TestModelsEndpoint {
|
||||
has_command_auth: bool,
|
||||
uses_codex_backend: bool,
|
||||
responses: Mutex<VecDeque<CoreResult<Vec<ModelInfo>>>>,
|
||||
etag: Option<String>,
|
||||
fetch_count: AtomicUsize,
|
||||
@@ -201,7 +194,6 @@ impl ModelsCache for TestModelsCache {
|
||||
impl TestModelsEndpoint {
|
||||
fn new(responses: Vec<Vec<ModelInfo>>) -> Arc<Self> {
|
||||
Arc::new(Self {
|
||||
uses_codex_backend: true,
|
||||
responses: Mutex::new(responses.into_iter().map(Ok).collect()),
|
||||
..Self::default()
|
||||
})
|
||||
@@ -294,10 +286,6 @@ impl ModelsEndpointClient for TestModelsEndpoint {
|
||||
self.has_command_auth
|
||||
}
|
||||
|
||||
fn uses_codex_backend(&self) -> ModelsEndpointFuture<'_, bool> {
|
||||
Box::pin(async { self.uses_codex_backend })
|
||||
}
|
||||
|
||||
fn list_models<'a>(
|
||||
&'a self,
|
||||
_client_version: &'a str,
|
||||
@@ -318,13 +306,17 @@ fn openai_manager_for_tests(
|
||||
codex_home: std::path::PathBuf,
|
||||
endpoint_client: Arc<dyn ModelsEndpointClient>,
|
||||
) -> OpenAiModelsManager {
|
||||
openai_manager_for_tests_with_auth(
|
||||
let manager = openai_manager_for_tests_with_auth(
|
||||
codex_home,
|
||||
endpoint_client,
|
||||
Some(AuthManager::from_auth_for_testing(
|
||||
CodexAuth::create_dummy_chatgpt_auth_for_testing(),
|
||||
)),
|
||||
)
|
||||
Some(AuthManager::from_auth_for_testing(api_key_auth_for_tests())),
|
||||
);
|
||||
manager.set_api_key_model_discovery_enabled(/*enabled*/ true);
|
||||
manager
|
||||
}
|
||||
|
||||
fn api_key_auth_for_tests() -> CodexAuth {
|
||||
CodexAuth::from_api_key("test-api-key")
|
||||
}
|
||||
|
||||
fn openai_manager_for_tests_with_auth(
|
||||
@@ -371,15 +363,11 @@ async fn file_cache_implements_models_cache_contract() {
|
||||
fetched_at: Utc::now(),
|
||||
etag: Some("file-etag".to_string()),
|
||||
client_version: Some(client_version.clone()),
|
||||
models: vec![ModelInfo {
|
||||
available_access_programs: Some(ModelAccessPrograms {
|
||||
cyber: vec![
|
||||
CyberAccessProgram::Standard,
|
||||
CyberAccessProgram::DaybreakBlue,
|
||||
],
|
||||
}),
|
||||
..remote_model("file-cached", "File Cached", /*priority*/ 0)
|
||||
}],
|
||||
models: vec![remote_model(
|
||||
"file-cached",
|
||||
"File Cached",
|
||||
/*priority*/ 0,
|
||||
)],
|
||||
};
|
||||
|
||||
cache.store(&entry).await.expect("cache store succeeds");
|
||||
@@ -450,10 +438,9 @@ async fn manager_without_cache_fetches_on_every_refresh() {
|
||||
let endpoint = TestModelsEndpoint::new(vec![remote_models.clone(), remote_models.clone()]);
|
||||
let manager = OpenAiModelsManager::new_without_cache(
|
||||
endpoint.clone(),
|
||||
Some(AuthManager::from_auth_for_testing(
|
||||
CodexAuth::create_dummy_chatgpt_auth_for_testing(),
|
||||
)),
|
||||
Some(AuthManager::from_auth_for_testing(api_key_auth_for_tests())),
|
||||
);
|
||||
manager.set_api_key_model_discovery_enabled(/*enabled*/ true);
|
||||
|
||||
let catalog = manager
|
||||
.raw_model_catalog(
|
||||
@@ -490,10 +477,9 @@ async fn injected_cache_hit_avoids_remote_fetch() {
|
||||
let manager = OpenAiModelsManager::new_with_cache(
|
||||
cache,
|
||||
endpoint.clone(),
|
||||
Some(AuthManager::from_auth_for_testing(
|
||||
CodexAuth::create_dummy_chatgpt_auth_for_testing(),
|
||||
)),
|
||||
Some(AuthManager::from_auth_for_testing(api_key_auth_for_tests())),
|
||||
);
|
||||
manager.set_api_key_model_discovery_enabled(/*enabled*/ true);
|
||||
|
||||
let catalog = manager
|
||||
.raw_model_catalog(
|
||||
@@ -514,10 +500,9 @@ async fn injected_cache_read_error_falls_back_and_persists_remote_models() {
|
||||
let manager = OpenAiModelsManager::new_with_cache(
|
||||
cache.clone(),
|
||||
endpoint.clone(),
|
||||
Some(AuthManager::from_auth_for_testing(
|
||||
CodexAuth::create_dummy_chatgpt_auth_for_testing(),
|
||||
)),
|
||||
Some(AuthManager::from_auth_for_testing(api_key_auth_for_tests())),
|
||||
);
|
||||
manager.set_api_key_model_discovery_enabled(/*enabled*/ true);
|
||||
|
||||
let catalog = manager
|
||||
.raw_model_catalog(
|
||||
@@ -556,10 +541,9 @@ async fn injected_cache_write_error_does_not_fail_remote_refresh() {
|
||||
let manager = OpenAiModelsManager::new_with_cache(
|
||||
cache,
|
||||
endpoint.clone(),
|
||||
Some(AuthManager::from_auth_for_testing(
|
||||
CodexAuth::create_dummy_chatgpt_auth_for_testing(),
|
||||
)),
|
||||
Some(AuthManager::from_auth_for_testing(api_key_auth_for_tests())),
|
||||
);
|
||||
manager.set_api_key_model_discovery_enabled(/*enabled*/ true);
|
||||
|
||||
let catalog = manager
|
||||
.raw_model_catalog(RefreshStrategy::Online, DEFAULT_HTTP_CLIENT_FACTORY)
|
||||
@@ -591,9 +575,12 @@ async fn initialization_retains_loaded_catalogs_including_empty_responses() {
|
||||
vec![remote_model("remote", "Remote", /*priority*/ 0)],
|
||||
] {
|
||||
let endpoint = TestModelsEndpoint::new(vec![models.clone()]);
|
||||
let manager =
|
||||
OpenAiModelsManager::new_without_cache(endpoint.clone(), /*auth_manager*/ None)
|
||||
.with_provider_catalog();
|
||||
let manager = OpenAiModelsManager::new_without_cache(
|
||||
endpoint.clone(),
|
||||
Some(AuthManager::from_auth_for_testing(api_key_auth_for_tests())),
|
||||
)
|
||||
.with_provider_catalog();
|
||||
manager.set_api_key_model_discovery_enabled(/*enabled*/ true);
|
||||
manager
|
||||
.ensure_initialized(DEFAULT_HTTP_CLIENT_FACTORY)
|
||||
.await;
|
||||
@@ -646,48 +633,6 @@ async fn injected_cache_ttl_refresh_preserves_cached_payload() {
|
||||
assert_eq!(stored_entries[0].models, cached_models);
|
||||
}
|
||||
|
||||
async fn chatgpt_auth_tokens_for_tests(codex_home: &Path) -> CodexAuth {
|
||||
let auth_dot_json = codex_login::AuthDotJson {
|
||||
auth_mode: Some(AuthMode::ChatgptAuthTokens),
|
||||
openai_api_key: None,
|
||||
tokens: Some(TokenData {
|
||||
id_token: codex_login::token_data::parse_chatgpt_jwt_claims(
|
||||
"eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.\
|
||||
eyJlbWFpbCI6InVzZXJAZXhhbXBsZS5jb20iLCJodHRwczovL2FwaS5vcGVuYWkuY29tL2F1dGgiOnsiY2hhdGdwdF9wbGFuX3R5cGUiOiJwcm8iLCJjaGF0Z3B0X3VzZXJfaWQiOiJ1c2VyLWlkIiwiY2hhdGdwdF9hY2NvdW50X2lkIjoiYWNjb3VudC1pZCJ9fQ.\
|
||||
c2ln",
|
||||
)
|
||||
.expect("fake id token should parse"),
|
||||
access_token: "Access Token".to_string(),
|
||||
refresh_token: "test".to_string(),
|
||||
oauth_provenance: None,
|
||||
login_owner_id: None,
|
||||
account_id: Some("account_id".to_string()),
|
||||
}),
|
||||
last_refresh: Some(Utc::now()),
|
||||
agent_identity: None,
|
||||
personal_access_token: None,
|
||||
bedrock_api_key: None,
|
||||
bedrock_access_keys: None,
|
||||
};
|
||||
std::fs::create_dir_all(codex_home).expect("codex home should be created");
|
||||
std::fs::write(
|
||||
codex_home.join("auth.json"),
|
||||
serde_json::to_string(&auth_dot_json).expect("auth should serialize"),
|
||||
)
|
||||
.expect("auth.json should be written");
|
||||
|
||||
CodexAuth::from_auth_storage(
|
||||
codex_home,
|
||||
AuthCredentialsStoreMode::File,
|
||||
/*chatgpt_base_url*/ None,
|
||||
AuthKeyringBackendKind::default(),
|
||||
&codex_login::test_support::transport_default_auth_route_config(),
|
||||
)
|
||||
.await
|
||||
.expect("auth should load")
|
||||
.expect("auth should be present")
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn static_manager_preserves_supported_requested_model_when_fallback_is_allowed() {
|
||||
let manager = static_manager_for_tests(ModelsResponse {
|
||||
@@ -1413,31 +1358,25 @@ async fn refresh_available_models_uses_cache_when_fresh() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn online_refresh_updates_access_programs_with_unchanged_etag() {
|
||||
async fn online_refresh_updates_metadata_with_unchanged_etag() {
|
||||
let codex_home = tempdir().expect("temp dir");
|
||||
let granted_model = ModelInfo {
|
||||
available_access_programs: Some(ModelAccessPrograms {
|
||||
cyber: vec![
|
||||
CyberAccessProgram::Standard,
|
||||
CyberAccessProgram::DaybreakBlue,
|
||||
],
|
||||
}),
|
||||
..remote_model("access-programs", "Access Programs", /*priority*/ 0)
|
||||
description: Some("granted".to_string()),
|
||||
..remote_model("caller-metadata", "Caller Metadata", /*priority*/ 0)
|
||||
};
|
||||
let revoked_model = ModelInfo {
|
||||
available_access_programs: Some(ModelAccessPrograms { cyber: Vec::new() }),
|
||||
description: Some("revoked".to_string()),
|
||||
..granted_model.clone()
|
||||
};
|
||||
let responses = vec![vec![granted_model.clone()], vec![revoked_model.clone()]];
|
||||
let endpoint = Arc::new(TestModelsEndpoint {
|
||||
uses_codex_backend: true,
|
||||
responses: Mutex::new(responses.into_iter().map(Ok).collect()),
|
||||
etag: Some("stable-catalog-etag".to_string()),
|
||||
..TestModelsEndpoint::default()
|
||||
});
|
||||
let manager = openai_manager_for_tests(codex_home.path().to_path_buf(), endpoint.clone());
|
||||
|
||||
// Caller-specific access can change without changing the catalog ETag.
|
||||
// Caller-specific metadata can change without changing the catalog ETag.
|
||||
for model in [granted_model, revoked_model] {
|
||||
let mut expected = ModelPreset::from(model.clone());
|
||||
expected.is_default = true;
|
||||
@@ -1453,7 +1392,7 @@ async fn online_refresh_updates_access_programs_with_unchanged_etag() {
|
||||
Some("stable-catalog-etag")
|
||||
);
|
||||
|
||||
// A new manager must read the latest access metadata from the disk cache.
|
||||
// A new manager must read the latest metadata from the disk cache.
|
||||
let cache_endpoint = TestModelsEndpoint::new(Vec::new());
|
||||
let cache_manager =
|
||||
openai_manager_for_tests(codex_home.path().to_path_buf(), cache_endpoint.clone());
|
||||
@@ -1575,10 +1514,9 @@ async fn refresh_available_models_drops_removed_remote_models() {
|
||||
Duration::ZERO,
|
||||
)),
|
||||
endpoint.clone(),
|
||||
Some(AuthManager::from_auth_for_testing(
|
||||
CodexAuth::create_dummy_chatgpt_auth_for_testing(),
|
||||
)),
|
||||
Some(AuthManager::from_auth_for_testing(api_key_auth_for_tests())),
|
||||
);
|
||||
manager.set_api_key_model_discovery_enabled(/*enabled*/ true);
|
||||
|
||||
manager
|
||||
.refresh_available_models(
|
||||
@@ -1667,17 +1605,6 @@ impl TestAuthAwareModelsEndpoint {
|
||||
self.fetch_count.load(Ordering::SeqCst)
|
||||
}
|
||||
|
||||
async fn uses_codex_backend(&self) -> bool {
|
||||
match self.auth_manager.as_ref() {
|
||||
Some(auth_manager) => auth_manager
|
||||
.auth()
|
||||
.await
|
||||
.as_ref()
|
||||
.is_some_and(CodexAuth::uses_codex_backend),
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
||||
async fn list_models(&self) -> CoreResult<ModelsEndpointResponse> {
|
||||
self.fetch_count.fetch_add(1, Ordering::SeqCst);
|
||||
let models = self
|
||||
@@ -1700,20 +1627,18 @@ impl ModelsEndpointClient for TestAuthAwareModelsEndpoint {
|
||||
}
|
||||
|
||||
fn identity(&self) -> Option<String> {
|
||||
// Production identities include the request credentials, so a replaced key is a new
|
||||
// identity even when the credential kind is unchanged.
|
||||
self.auth_manager
|
||||
.as_ref()
|
||||
.and_then(|manager| manager.auth_mode())
|
||||
.map(|mode| format!("{mode:?}"))
|
||||
.and_then(|manager| manager.auth_cached())
|
||||
.map(|auth| format!("{:?}:{:?}", auth.auth_mode(), auth.get_token().ok()))
|
||||
}
|
||||
|
||||
fn has_command_auth(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn uses_codex_backend(&self) -> ModelsEndpointFuture<'_, bool> {
|
||||
Box::pin(TestAuthAwareModelsEndpoint::uses_codex_backend(self))
|
||||
}
|
||||
|
||||
fn list_models<'a>(
|
||||
&'a self,
|
||||
_client_version: &'a str,
|
||||
@@ -1724,11 +1649,10 @@ impl ModelsEndpointClient for TestAuthAwareModelsEndpoint {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn refresh_available_models_fetches_when_external_api_key_overrides_chatgpt_auth() {
|
||||
async fn refresh_available_models_fetches_when_external_api_key_overrides_stored_auth() {
|
||||
let dynamic_slug = "dynamic-model-only-for-test-external-api-key";
|
||||
let codex_home = tempdir().expect("temp dir");
|
||||
let auth_manager =
|
||||
AuthManager::from_auth_for_testing(CodexAuth::create_dummy_chatgpt_auth_for_testing());
|
||||
let auth_manager = AuthManager::from_auth_for_testing(api_key_auth_for_tests());
|
||||
auth_manager
|
||||
.set_external_auth(Arc::new(TestExternalApiKeyAuth))
|
||||
.await
|
||||
@@ -1766,11 +1690,10 @@ async fn refresh_available_models_fetches_when_external_api_key_overrides_chatgp
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn refresh_available_models_uses_cached_chatgpt_when_external_api_key_is_unresolved() {
|
||||
async fn refresh_available_models_uses_cached_auth_when_external_api_key_is_unresolved() {
|
||||
let dynamic_slug = "dynamic-model-only-for-test-unresolved-external-api-key";
|
||||
let codex_home = tempdir().expect("temp dir");
|
||||
let auth_manager =
|
||||
AuthManager::from_auth_for_testing(CodexAuth::create_dummy_chatgpt_auth_for_testing());
|
||||
let auth_manager = AuthManager::from_auth_for_testing(api_key_auth_for_tests());
|
||||
auth_manager
|
||||
.set_external_auth(Arc::new(TestUnresolvedExternalApiKeyAuth))
|
||||
.await
|
||||
@@ -1793,7 +1716,7 @@ async fn refresh_available_models_uses_cached_chatgpt_when_external_api_key_is_u
|
||||
manager
|
||||
.refresh_available_models(RefreshStrategy::Online, &DEFAULT_HTTP_CLIENT_FACTORY)
|
||||
.await
|
||||
.expect("refresh should fall back to cached ChatGPT auth");
|
||||
.expect("refresh should fall back to cached API key auth");
|
||||
|
||||
assert!(
|
||||
manager
|
||||
@@ -1801,48 +1724,12 @@ async fn refresh_available_models_uses_cached_chatgpt_when_external_api_key_is_u
|
||||
.await
|
||||
.iter()
|
||||
.any(|candidate| candidate.slug == dynamic_slug),
|
||||
"remote refresh should include models fetched with cached ChatGPT auth"
|
||||
"remote refresh should include models fetched with cached API key auth"
|
||||
);
|
||||
assert_eq!(
|
||||
endpoint.fetch_count(),
|
||||
1,
|
||||
"endpoint should fetch models when unresolved external API key falls back to ChatGPT auth"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn refresh_available_models_fetches_with_chatgpt_auth_tokens() {
|
||||
let dynamic_slug = "dynamic-model-only-for-test-chatgpt-auth-tokens";
|
||||
let codex_home = tempdir().expect("temp dir");
|
||||
let endpoint = TestModelsEndpoint::new(vec![vec![remote_model(
|
||||
dynamic_slug,
|
||||
"ChatGPT Auth Tokens",
|
||||
/*priority*/ 1,
|
||||
)]]);
|
||||
let auth = chatgpt_auth_tokens_for_tests(codex_home.path()).await;
|
||||
let manager = openai_manager_for_tests_with_auth(
|
||||
codex_home.path().to_path_buf(),
|
||||
endpoint.clone(),
|
||||
Some(AuthManager::from_auth_for_testing(auth)),
|
||||
);
|
||||
|
||||
manager
|
||||
.refresh_available_models(RefreshStrategy::Online, &DEFAULT_HTTP_CLIENT_FACTORY)
|
||||
.await
|
||||
.expect("refresh should fetch with ChatGPT auth tokens");
|
||||
|
||||
assert!(
|
||||
manager
|
||||
.get_remote_models()
|
||||
.await
|
||||
.iter()
|
||||
.any(|candidate| candidate.slug == dynamic_slug),
|
||||
"remote refresh should include models fetched with ChatGPT auth tokens"
|
||||
);
|
||||
assert_eq!(
|
||||
endpoint.fetch_count(),
|
||||
1,
|
||||
"endpoint should fetch models with ChatGPT auth tokens"
|
||||
"endpoint should fetch models when unresolved external API key falls back to cached auth"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1865,9 +1752,8 @@ fn build_available_models_picks_default_after_hiding_hidden_models() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn static_manager_reads_latest_auth_mode() {
|
||||
let auth_manager =
|
||||
AuthManager::from_auth_for_testing(CodexAuth::create_dummy_chatgpt_auth_for_testing());
|
||||
async fn static_manager_hides_api_unsupported_models_for_every_auth() {
|
||||
let auth_manager = AuthManager::from_auth_for_testing(api_key_auth_for_tests());
|
||||
let chatgpt_only_model = {
|
||||
let mut model = remote_model("chatgpt-only", "ChatGPT Only", /*priority*/ 0);
|
||||
model.supported_in_api = false;
|
||||
@@ -1882,15 +1768,15 @@ async fn static_manager_reads_latest_auth_mode() {
|
||||
ModelOrigin::ExplicitConfig,
|
||||
);
|
||||
|
||||
let chatgpt_models = manager
|
||||
let stored_key_models = manager
|
||||
.list_models(RefreshStrategy::Online, DEFAULT_HTTP_CLIENT_FACTORY)
|
||||
.await;
|
||||
assert_eq!(
|
||||
chatgpt_models
|
||||
stored_key_models
|
||||
.iter()
|
||||
.map(|model| model.model.as_str())
|
||||
.collect::<Vec<_>>(),
|
||||
vec!["chatgpt-only", "api-model"]
|
||||
vec!["api-model"]
|
||||
);
|
||||
|
||||
auth_manager
|
||||
|
||||
@@ -110,7 +110,6 @@ pub fn model_info_from_slug(slug: &str) -> ModelInfo {
|
||||
additional_speed_tiers: Vec::new(),
|
||||
service_tiers: Vec::new(),
|
||||
default_service_tier: None,
|
||||
available_access_programs: None,
|
||||
availability_nux: None,
|
||||
upgrade: None,
|
||||
model_messages: Some(local_model_messages()),
|
||||
|
||||
@@ -75,7 +75,6 @@ fn base_instruction_override_is_literal_and_preserves_catalog_messages() {
|
||||
};
|
||||
let token_budget = ModelTokenBudgetConfig {
|
||||
enabled: false,
|
||||
use_history_notes_extension: false,
|
||||
reminder_threshold_tokens: 128,
|
||||
reminder_message_template: "budget reminder".to_string(),
|
||||
guidance_message: "budget guidance".to_string(),
|
||||
|
||||
Reference in New Issue
Block a user