mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Route pet asset downloads through the shared HTTP client (#36008)
## Why Built-in pet downloads used a standalone blocking client, so CDN redirects did not use Codex's configured route handling. ## What changed - Download pet spritesheets asynchronously with a reusable `RouteAwareClientPool`. - Keep cache validation, asset installation, and pet decoding off the async runtime while sharing one asset-and-load path across startup, previews, and selection. - Preserve the download size limit while consuming streamed response chunks, and remove the TUI's direct `reqwest` dependency. ## Testing Add coverage for oversized response chunks, cached built-in assets, pet loads without an existing Tokio runtime, and stale preview and selection completions. GitOrigin-RevId: 725e76f3ddb7e84b7212769892f28dc0add15741
This commit is contained in:
1 parent
ad6fc66b6d
commit
09cf609218
11 files changed
+293
-95
No files matched your search
@@ -9,9 +9,9 @@
|
||||
//! resolving a selected pet id, preparing frames for terminal image protocols,
|
||||
//! rendering the ambient sprite and picker preview, and preserving enough
|
||||
//! metadata for `/pets` to behave like a first-class configuration surface.
|
||||
//! It does not own config persistence or popup orchestration; callers must
|
||||
//! ensure a built-in asset exists before loading it and must persist the final
|
||||
//! selection only after the load succeeds.
|
||||
//! It prepares built-in assets before loading pets, but does not own config
|
||||
//! persistence or popup orchestration; callers must persist the final selection
|
||||
//! only after the load succeeds.
|
||||
|
||||
use std::io::Write;
|
||||
|
||||
@@ -27,6 +27,10 @@ mod sixel;
|
||||
|
||||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use codex_http_client::RouteAwareClientPool;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
|
||||
use crate::tui::FrameRequester;
|
||||
|
||||
pub(crate) use ambient::AmbientPet;
|
||||
pub(crate) use ambient::AmbientPetDraw;
|
||||
@@ -53,20 +57,41 @@ pub(crate) const DISABLED_PET_ID: &str = "disabled";
|
||||
/// Ensure that a selected built-in pet has a locally cached spritesheet.
|
||||
///
|
||||
/// Custom pets are intentionally a no-op here because their source of truth is
|
||||
/// already local. Callers should invoke this before loading a built-in pet for
|
||||
/// preview or selection; skipping it would make first-use preview and
|
||||
/// persistence failures depend on deeper image-loading errors instead of the
|
||||
/// asset-fetch boundary.
|
||||
pub(crate) fn ensure_builtin_pack_for_pet(
|
||||
/// already local. Preparing this before loading keeps first-use preview and
|
||||
/// persistence failures at the asset-fetch boundary rather than surfacing as
|
||||
/// deeper image-loading errors.
|
||||
async fn ensure_builtin_pack_for_pet(
|
||||
pet_id: &str,
|
||||
codex_home: &std::path::Path,
|
||||
http_client: &RouteAwareClientPool,
|
||||
) -> Result<()> {
|
||||
if let Some(pet) = catalog::builtin_pet(pet_id) {
|
||||
asset_pack::ensure_builtin_pet(codex_home, pet)?;
|
||||
asset_pack::ensure_builtin_pet(codex_home, pet, http_client).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Prepare a pet's built-in assets and load its synchronous state off the runtime.
|
||||
pub(crate) async fn load_pet_with_assets(
|
||||
pet_id: String,
|
||||
codex_home: AbsolutePathBuf,
|
||||
frame_requester: FrameRequester,
|
||||
animations_enabled: bool,
|
||||
http_client: &RouteAwareClientPool,
|
||||
) -> Result<AmbientPet> {
|
||||
ensure_builtin_pack_for_pet(&pet_id, &codex_home, http_client).await?;
|
||||
tokio::task::spawn_blocking(move || {
|
||||
AmbientPet::load(
|
||||
Some(&pet_id),
|
||||
&codex_home,
|
||||
frame_requester,
|
||||
animations_enabled,
|
||||
)
|
||||
})
|
||||
.await
|
||||
.context("join pet load task")?
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum PetImageRenderError {
|
||||
Terminal(std::io::Error),
|
||||
|
||||
Reference in new issue
Block a user