mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
## Why App-server clients lose metadata supplied by the image backend when Codex turns the response into a completed image generation item. ## What changed Expose the backend's `image_metadata` as optional `imageMetadata` in app-server items and preserve nested values through thread persistence, resume, and legacy history replay and migration. Keep this metadata out of model tool output. Omit empty metadata and discard non-object, oversized, or deeply nested metadata without dropping the generated image. ## Testing Extend coverage for per-image parsing, metadata limits, and round trips through app-server completion, persisted history, and thread resume. GitOrigin-RevId: 7211a9db1149cb05e6176b08b0462ca173ac72d5
95 lines
3.4 KiB
Rust
95 lines
3.4 KiB
Rust
use codex_utils_absolute_path::AbsolutePathBuf;
|
|
use schemars::JsonSchema;
|
|
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
use serde_json::Map;
|
|
use serde_json::Value;
|
|
use serde_with::serde_as;
|
|
use ts_rs::TS;
|
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize, TS, JsonSchema, PartialEq)]
|
|
#[serde(tag = "type", rename_all = "camelCase")]
|
|
#[ts(tag = "type", rename_all = "camelCase")]
|
|
pub enum ImageGenerationFailure {
|
|
UsageLimitExceeded {
|
|
#[serde(rename = "limitId")]
|
|
#[ts(rename = "limitId")]
|
|
limit_id: String,
|
|
#[serde(rename = "resetsAt")]
|
|
#[ts(rename = "resetsAt")]
|
|
#[ts(type = "number | null")]
|
|
resets_at: Option<i64>,
|
|
},
|
|
}
|
|
|
|
/// A local image file successfully read for this exact image-generation request.
|
|
#[derive(Debug, Clone, Deserialize, Serialize, TS, JsonSchema, PartialEq, Eq)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(rename_all = "camelCase")]
|
|
pub struct ImageGenerationInputImage {
|
|
pub path: AbsolutePathBuf,
|
|
/// Lowercase SHA-256 of the file bytes read before image normalization.
|
|
pub sha256: String,
|
|
}
|
|
|
|
// Standalone image-generation item owned by the image extension. This is also
|
|
// the field-level representation exposed by app-server; core and rollout
|
|
// persistence only carry it inside an ExtensionItem envelope.
|
|
#[serde_as]
|
|
#[derive(Debug, Clone, Deserialize, Serialize, TS, JsonSchema, PartialEq)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(rename_all = "camelCase")]
|
|
pub struct ImageGenerationItem {
|
|
pub id: String,
|
|
pub status: String,
|
|
pub revised_prompt: Option<String>,
|
|
#[serde(flatten)]
|
|
pub image: GeneratedImageRef,
|
|
#[serde(default)]
|
|
#[ts(optional)]
|
|
pub transparent_background: Option<bool>,
|
|
#[serde(default)]
|
|
pub failure: Option<ImageGenerationFailure>,
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
#[ts(optional)]
|
|
pub saved_path: Option<AbsolutePathBuf>,
|
|
/// Observed local inputs for a completed generation, absent on older items.
|
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
#[ts(as = "Option<_>", optional)]
|
|
pub input_images: Vec<ImageGenerationInputImage>,
|
|
/// Exact nested ImageGen request ID retained only for in-process analytics.
|
|
///
|
|
/// This is deliberately excluded from the extension/app-server wire shape
|
|
/// and rollout persistence because it is not a client-facing item field.
|
|
#[serde(skip)]
|
|
#[schemars(skip)]
|
|
#[ts(skip)]
|
|
pub imagegen_request_id: Option<String>,
|
|
/// Image generation identifier for the generated image, when provided by the image backend.
|
|
#[serde(default)]
|
|
pub generation_id: Option<String>,
|
|
/// Per-image metadata selected by the backend for the receiving surface.
|
|
#[serde_as(deserialize_as = "serde_with::DefaultOnError")]
|
|
#[serde(default, skip_serializing_if = "Map::is_empty")]
|
|
#[ts(as = "Option<_>", optional)]
|
|
pub image_metadata: Map<String, Value>,
|
|
}
|
|
|
|
/// Either inline generated-image data or its durable attachment-store identity.
|
|
///
|
|
/// `File` must remain first so rollouts written during the migration, which contain both an empty
|
|
/// `result` and a `fileId`, retain the file reference when deserialized.
|
|
#[derive(Debug, Clone, Deserialize, Serialize, TS, JsonSchema, PartialEq)]
|
|
#[serde(untagged)]
|
|
#[ts(untagged)]
|
|
pub enum GeneratedImageRef {
|
|
File {
|
|
#[serde(rename = "fileId")]
|
|
#[ts(rename = "fileId")]
|
|
file_id: String,
|
|
},
|
|
Inline {
|
|
result: String,
|
|
},
|
|
}
|