Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/crates/adapters/ai-adapters/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,15 @@ and sends no inference request. This does not verify remote-host behavior.
The image-generation filter uses synthetic HTTP credentials. The ignored Codex
probe requires a real in-app subscription login and generates a billed image;
run it explicitly only when live provider validation is needed.
Set `PROBE_CODEX_IMAGE_OUTPUT_DIR` to save the generated image for visual review.
Set `PROBE_CODEX_IMAGE_OUTPUT_FORMAT=gif` to request GIF output and
`PROBE_CODEX_IMAGE_PROMPT` to describe the subject and looping motion. The probe
checks the GIF signature; inspect frame count and timing in the saved file to
confirm animation.
The probe uses the production standalone subscription Images route and built-in
image model. It does not discover or invoke a chat model. Saved legacy
`/responses` endpoints are translated in memory to `/images/generations`.

```bash
cargo test --locked -p openbitfun-ai-adapters --features image-generation,subscription-auth --lib client::image_generation::tests::probe_codex_subscription_image_generation -- --ignored --exact --nocapture
```
533 changes: 216 additions & 317 deletions src/crates/adapters/ai-adapters/src/client/image_generation.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/crates/assembly/core/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ For image-service selection and compatibility with saved subscription configurat

```bash
cargo test --locked -p openbitfun-core --no-default-features --features agent-runtime,git,tools-image-generation,subscription-auth --lib agentic::image_generation::tests
cargo test --locked -p openbitfun-core --no-default-features --features agent-runtime,git,tools-image-generation --lib agentic::tools::implementations::generate_image_tool::tests
cargo test --locked -p openbitfun-core --no-default-features --features agent-runtime,git,tools-image-generation --lib agentic::tools::product_runtime::materialization::tests::image_tools_follow_independent_compiled_owners
cargo test --locked -p openbitfun-core --no-default-features --features agent-runtime,git,tools-image-analysis --lib agentic::tools::product_runtime::materialization::tests::image_tools_follow_independent_compiled_owners
```
Expand Down
4 changes: 2 additions & 2 deletions src/crates/assembly/core/src/agentic/image_generation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ fn service_with_auth_route(service: &ImageServiceConfig) -> ImageServiceConfig {
service.dialect = ImageDialect::ChatgptCodex;
service.base_url.clear();
service.request_url = None;
// An image-model ID cannot drive a Responses tool call. Resolve a chat
// model from this subscription's live catalog instead.
// The subscription Images adapter owns the image model. Keep the legacy
// model slot empty in the resolved view without rewriting stored data.
service.model_name.clear();
service.params.n = Some(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl Tool for GenerateImageTool {
"service_id": {"type": "string"},
"service": {"type": "string"},
"dialect": {"type": "string"},
"model": {"type": "string"},
"model": {"type": "string", "description": "Model ID requested from the image service."},
"mime_type": {"type": "string"},
"bytes": {"type": "integer", "minimum": 0, "description": "Byte length of the first generated image."},
"summary": {"type": "string"}
Expand Down Expand Up @@ -368,7 +368,7 @@ impl Tool for GenerateImageTool {
"service_id": resolved.service.id,
"service": resolved.service.name,
"dialect": format!("{:?}", resolved.service.dialect),
"model": resolved.service.model_name,
"model": target.requested_model(),
"mime_type": persisted[0].mime,
"bytes": persisted[0].bytes,
"summary": summary,
Expand Down
3 changes: 3 additions & 0 deletions src/crates/contracts/core-types/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ node scripts/check-core-boundaries.mjs
```

For documentation-only changes, run `git diff --check`.

For persisted image dialect values and endpoint compatibility, run
`cargo test --locked -p openbitfun-core-types --lib ai::image_dialect_compatibility`.
29 changes: 22 additions & 7 deletions src/crates/contracts/core-types/src/ai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,11 +920,11 @@ pub enum ImageDialect {
/// `POST {base}/services/aigc/multimodal-generation/generation`.
#[serde(rename = "dashscope_native")]
DashScopeNative,
/// ChatGPT subscription images, driven through Codex CLI's ChatGPT backend:
/// `POST {base}/responses` with an `image_generation` tool, streamed back as
/// SSE `response.output_item.done` items. This is a separate billing and
/// protocol path from [`Self::OpenAiImages`]: it takes the OAuth access token
/// from a Codex subscription login and never reaches the platform image API.
/// ChatGPT subscription images through the Codex subscription backend:
/// `POST {base}/images/generations` with a standalone Images JSON body.
/// This is a separate billing and protocol path from [`Self::OpenAiImages`]:
/// it takes the OAuth access token from a Codex subscription login and never
/// reaches the platform image API.
#[serde(rename = "chatgpt_codex")]
ChatgptCodex,
}
Expand All @@ -935,7 +935,7 @@ impl ImageDialect {
match self {
Self::OpenAiImages => "/images/generations",
Self::DashScopeNative => "/services/aigc/multimodal-generation/generation",
Self::ChatgptCodex => "/responses",
Self::ChatgptCodex => "/images/generations",
}
}

Expand All @@ -944,7 +944,7 @@ impl ImageDialect {
match self {
Self::OpenAiImages => MAX_IMAGES_PER_GENERATION_REQUEST,
Self::DashScopeNative => 6,
// The subscription route returns one image per tool call.
// The subscription route generates one image per request.
Self::ChatgptCodex => 1,
}
}
Expand All @@ -956,6 +956,21 @@ impl ImageDialect {
}
}

#[cfg(test)]
mod image_dialect_compatibility {
use super::ImageDialect;

#[test]
fn subscription_wire_value_survives_the_images_endpoint_upgrade() {
let legacy = r#""chatgpt_codex""#;
let dialect: ImageDialect = serde_json::from_str(legacy).unwrap();
assert_eq!(serde_json::to_string(&dialect).unwrap(), legacy);
assert_eq!(dialect.endpoint_path(), "/images/generations");
assert!(dialect.requires_subscription());
assert_eq!(dialect.max_images_per_request(), 1);
}
}

#[cfg(test)]
mod remote_model_routing_compatibility {
#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('image service authentication routing', () => {
const result = withImageServiceAuth(legacyService, { type: 'subscription', provider: 'codex' });
expect(result).toMatchObject({ id: 'saved-service', dialect: 'chatgpt_codex', model_name: '', params: { n: 1 } });
expect(resolveImageEndpoint(result.base_url, result.request_url, result.dialect))
.toBe('https://chatgpt.com/backend-api/codex/responses');
.toBe('https://chatgpt.com/backend-api/codex/images/generations');
expect(legacyService.request_url).toBe('https://api.openai.com/v1/images/generations');
});

Expand All @@ -36,10 +36,23 @@ describe('image service authentication routing', () => {
expect(resolveImageEndpoint(result.base_url, result.request_url, result.dialect)).toBe('https://api.openai.com/v1/images/generations');
});

it('preserves custom API-key gateways and explicitly chosen subscription models', () => {
it('preserves custom API-key gateways and legacy subscription model slots', () => {
expect(withImageServiceAuth(legacyService, { type: 'api_key' })).toEqual(legacyService);
const auth = { type: 'subscription' as const, provider: 'codex' as const };
const service = { ...withImageServiceAuth(legacyService, auth), model_name: 'account-model' };
expect(withImageServiceAuth(service, auth).model_name).toBe('account-model');
});

it('resolves old subscription endpoints without rewriting serialized settings', () => {
const root = 'https://chatgpt.com/backend-api/codex';
const auth = { type: 'subscription' as const, provider: 'codex' as const };
const saved = JSON.parse(JSON.stringify({ ...withImageServiceAuth(legacyService, auth),
request_url: `${root}/responses`, model_name: 'gpt-6.1-sol' }));
const snapshot = JSON.stringify(saved);
expect(resolveImageEndpoint(saved.base_url, saved.request_url, saved.dialect)).toBe(`${root}/images/generations`);
expect(resolveImageEndpoint(`${root}/responses/`, undefined, 'chatgpt_codex')).toBe(`${root}/images/generations`);
expect(resolveImageEndpoint(`${root}/images/generations`, undefined, 'chatgpt_codex')).toBe(`${root}/images/generations`);
expect(JSON.stringify(saved)).toBe(snapshot);
expect(resolveImageEndpoint(root, `${root}/responses`, 'openai_images')).toBe(`${root}/responses`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ export const IMAGE_DIALECT_PRESETS: readonly ImageDialectPreset[] = [
id: 'chatgpt_codex',
labelKey: 'dialect.chatgptCodex.name',
descriptionKey: 'dialect.chatgptCodex.description',
endpointPath: '/responses',
endpointPath: '/images/generations',
// The login supplies this address; the value here only seeds a new draft.
defaultBaseUrl: 'https://chatgpt.com/backend-api/codex',
// Empty means "discover from the account catalog when sending".
// The subscription adapter owns the image model; legacy chat model IDs stay readable.
defaultModel: '',
sizes: ['1024x1024', '1536x1024', '1024x1536'],
maxImagesPerRequest: 1,
Expand Down Expand Up @@ -121,9 +121,12 @@ export function resolveImageEndpoint(
dialect: ImageDialect,
): string {
const override = requestUrl?.trim();
if (override) return override;
const subscriptionUrl = (url: string) => dialect === 'chatgpt_codex'
? url.replace(/\/responses\/?$/, '/images/generations')
: url;
if (override) return subscriptionUrl(override);

const root = baseUrl.trim().replace(/\/+$/, '');
const root = subscriptionUrl(baseUrl.trim().replace(/\/+$/, ''));
if (!root) return '';
const path = findImageDialectPreset(dialect).endpointPath;
return root.endsWith(path) ? root : `${root}${path}`;
Expand Down
4 changes: 2 additions & 2 deletions src/web-ui/src/infrastructure/config/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ export interface DefaultModelsConfig {
/**
* Image request protocol.
*
* `chatgpt_codex` is the subscription route: it drives a chat model's
* `image_generation` tool over the provider's own backend and never touches the
* `chatgpt_codex` sends standalone Images JSON requests using the subscription
* login over the provider's own backend and never touches the
* API-key image endpoint.
*/
export type ImageDialect = 'openai_images' | 'dashscope_native' | 'chatgpt_codex';
Expand Down
4 changes: 2 additions & 2 deletions src/web-ui/src/locales/en-US/settings/media.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@
"modelName": {
"label": "Image model id",
"hint": "The exact model id the provider expects for image generation, not a chat model.",
"subscriptionPlaceholder": "Empty uses any model the account offers",
"subscriptionHint": "This is the chat model that drives the image tool, not an image model name. Leave it empty to pick one from the account's catalog automatically."
"subscriptionPlaceholder": "Uses the built-in image model",
"subscriptionHint": "Subscription image generation uses a built-in image model. No chat model is needed."
},
"name": {
"label": "Display name",
Expand Down
4 changes: 2 additions & 2 deletions src/web-ui/src/locales/zh-CN/settings/media.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@
"modelName": {
"label": "图像模型 ID",
"hint": "填服务商用于图像生成的确切模型 ID,不是对话模型。",
"subscriptionPlaceholder": "留空则使用账号可用的模型",
"subscriptionHint": "这里填的是驱动图像工具的对话模型,不是图像模型名;留空会按账号可用模型自动选择。"
"subscriptionPlaceholder": "使用内置图像模型",
"subscriptionHint": "订阅生图使用内置图像模型,无需配置对话模型。"
},
"name": {
"label": "显示名称",
Expand Down
4 changes: 2 additions & 2 deletions src/web-ui/src/locales/zh-TW/settings/media.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@
"modelName": {
"label": "圖像模型 ID",
"hint": "填服務商用於圖像生成的正確模型 ID,不是對話模型。",
"subscriptionPlaceholder": "留空則使用帳號可用的模型",
"subscriptionHint": "這裡填的是驅動圖像工具的對話模型,不是圖像模型名稱;留空會依帳號可用模型自動選擇。"
"subscriptionPlaceholder": "使用內建圖像模型",
"subscriptionHint": "訂閱生圖使用內建圖像模型,無需設定對話模型。"
},
"name": {
"label": "顯示名稱",
Expand Down
Loading