Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(pi): preserve ChatGPT image modalities (#2699)
zyaoiif906b9529dbf
diff --git a/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.ts b/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.tsindex bf19932b4c..dd478cebb7 100644--- a/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.ts@@ -41,7 +41,8 @@ import {resolvePiCindyGatewayModelSpec,type PiBundledModelInfo,} from '../pi-host.js';-import { setActiveCatalog, setXdGatewayModels } from '../active-catalog.js';+import { getActiveCatalog, setActiveCatalog, setDiscoveredCodexModels, setXdGatewayModels } from '../active-catalog.js';+import { deriveAvailableModels } from '../catalog-to-descriptors.js';type Cfg = Parameters<typeof buildPiNativeProvidersFromConfigs>[0][number];@@ -80,9 +81,51 @@ const piBundledModel = (afterEach(() => {setActiveCatalog(BUNDLED_CATALOG);+ setDiscoveredCodexModels([]);setXdGatewayModels([]);});+describe('ChatGPT image capability authority (#2674)', () => {+ it.each(['gpt-5.6-luna', 'gpt-5.6-sol', 'gpt-5.6-terra'])(+ 'keeps %s visual through the independent Pi catalog despite text-only Codex discovery',+ (id) => {+ setActiveCatalog(BUNDLED_CATALOG);+ setDiscoveredCodexModels([{+ id, name: id, contextWindow: 272_000, efforts: [], defaultEffort: null,+ supportsImageInput: false,+ }]);+ const catalog = getActiveCatalog();+ expect(deriveAvailableModels(catalog, 'pi').find((model) => model.id === `chatgpt/${id}`))+ .toMatchObject({ supportsImageInput: true });+ const native = piBundledModel(id, 'openai-codex-responses', { input: ['text', 'image'] });+ for (const probe of [undefined, new Map([['openai-codex', new Map([[id, native]])]])]) {+ const provider = buildPiSubscriptionNativeProviders(catalog, 'http://127.0.0.1:4567/', probe)+ .providers.find((candidate) => candidate.id === 'openai-codex');+ expect(provider?.models.find((model) => model.id === `chatgpt/${id}`))+ .toMatchObject({ wireId: id, api: 'openai-codex-responses', input: ['text', 'image'] });+ }+ },+ );++ it.each([true, false, undefined])(+ 'preserves explicit image capability %s with and without a native probe',+ (supportsImageInput) => {+ const catalog = structuredClone(BUNDLED_CATALOG);+ const id = 'gpt-5.6-sol';+ catalog.providers.find((provider) => provider.id === 'openai')!.models.pi = [{+ id: `chatgpt/${id}`, name: id, contextWindow: 272_000, efforts: [], defaultEffort: null,+ supportsImageInput,+ }];+ const native = piBundledModel(id, 'openai-codex-responses', { input: ['text', 'image'] });+ for (const probe of [undefined, new Map([['openai-codex', new Map([[id, native]])]])]) {+ const model = buildPiSubscriptionNativeProviders(catalog, 'http://127.0.0.1:4567/', probe)+ .providers.find((provider) => provider.id === 'openai-codex')?.models[0];+ expect(model?.input).toEqual(supportsImageInput === false ? ['text'] : ['text', 'image']);+ }+ },+ );+});+describe('resolvePiCindyGatewayModelApi', () => {it('keeps a Registry-linked Cindy Server protocol above local and Gateway metadata', () => {const catalog = JSON.parse(JSON.stringify(BUNDLED_CATALOG)) as Catalog;diff --git a/apps/desktop/src/main/maker-host/pi-host.ts b/apps/desktop/src/main/maker-host/pi-host.tsindex 3ccd47347a..92c75e8496 100644--- a/apps/desktop/src/main/maker-host/pi-host.ts+++ b/apps/desktop/src/main/maker-host/pi-host.ts@@ -651,6 +651,13 @@ export function buildPiSubscriptionNativeProviders(listedModelIdsByProvider?.get(piProviderId)?? listedPiModelIds(bundledModelsByProvider)?.get(piProviderId);const officialOpenAi = officialOpenAiById.get(wireId);+ // Catalog overrides (including false) keep the same authority when the+ // runtime probe is unavailable and we fall back to the shipped Pi catalog.+ const openAiInputOverride = model.supportsImageInput === undefined+ ? undefined+ : model.supportsImageInput+ ? ['text', 'image'] as Array<'text' | 'image'>+ : ['text'] as Array<'text' | 'image'>;if (sourceProviderId === 'openai' && !bundledModel && !listedIds?.has(wireId)&& officialOpenAi?.api === 'openai-codex-responses') {return {@@ -658,6 +665,7 @@ export function buildPiSubscriptionNativeProviders(id: model.id,wireId,catalogAddition: true,+ ...(openAiInputOverride ? { input: openAiInputOverride } : {}),};}const isKnownMissingXaiModel =@@ -690,11 +698,6 @@ export function buildPiSubscriptionNativeProviders(const isRegistryBaselineOverlay = sourceProviderId === 'openai' && !!bundledModel;const catalogCost = catalogCostForPiNative(model.cost);if (isRegistryBaselineOverlay) {- const input = model.supportsImageInput === undefined- ? [...bundledModel.input]- : model.supportsImageInput- ? ['text', 'image'] as Array<'text' | 'image'>- : ['text'] as Array<'text' | 'image'>;const cost = catalogCost ?? bundledModel.cost;return {id: model.id,@@ -707,7 +710,7 @@ export function buildPiSubscriptionNativeProviders(contextWindow: model.contextWindow,maxTokens: model.maxOutput ?? bundledModel.maxTokens,reasoning: model.efforts.length > 0,- input,+ input: [...(openAiInputOverride ?? bundledModel.input)],thinkingLevelMap: catalogThinkingLevelMap(model.efforts,bundledModel.thinkingLevelMap,diff --git a/packages/maker-core/src/agents/pi/__tests__/pi-provider-routing.test.ts b/packages/maker-core/src/agents/pi/__tests__/pi-provider-routing.test.tsindex 472da415c5..1b572614d1 100644--- a/packages/maker-core/src/agents/pi/__tests__/pi-provider-routing.test.ts+++ b/packages/maker-core/src/agents/pi/__tests__/pi-provider-routing.test.ts@@ -3956,6 +3956,64 @@ describe("Pi provider-aware model routing", () => {await handle.close();});+ it.each([+ { input: ["text", "image"] as Array<"text" | "image">, supported: true },+ { input: ["text"] as Array<"text" | "image">, supported: false },+ { input: undefined, supported: false },+ ])("uses the native ChatGPT image snapshot for models.json, send and steer: $input", async ({ input, supported }) => {+ const modelId = "chatgpt/gpt-5.6-sol";+ const agent = new PiAgent(byomDeps(async () => ({+ providers: [{+ id: "openai-codex", sourceProviderId: "openai", name: "ChatGPT",+ baseUrl: "http://127.0.0.1:9", inheritModels: true,+ models: [{+ id: modelId, wireId: "gpt-5.6-sol", api: "openai-codex-responses", input,+ }],+ }],+ env: {},+ }), [{+ id: modelId, displayName: "Same-id gateway model", contextWindow: 272_000,+ efforts: [], defaultEffort: null, supportsImageInput: !supported,+ }]));+ const handle = await agent.startSession({+ sessionId: "chatgpt-images", workingDir: cwd, model: modelId, providerId: "openai",+ });+ try {+ const config = JSON.parse(readFileSync(+ path.join(captured.env.PI_CODING_AGENT_DIR as string, "models.json"), "utf8",+ ));+ expect(config.providers["openai-codex"].models).toEqual([+ expect.objectContaining({+ id: "gpt-5.6-sol", api: "openai-codex-responses", input: input ?? ["text"],+ }),+ ]);+ const data = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=";+ const imagePath = path.join(cwd, "image.png");+ writeFileSync(imagePath, Buffer.from(data, "base64"));+ const image = { type: "image" as const, path: imagePath };+ for (const content of [[image], [{ type: "text" as const, text: "describe" }, image], [image, image]]) {+ for (const method of ["send", "steer"] as const) {+ captured.requests.length = 0;+ const sent = handle[method]!({ type: "user", content });+ if (supported) {+ await sent;+ expect(captured.requests).toContainEqual(expect.objectContaining({+ type: method === "send" ? "prompt" : "steer",+ images: content.filter((part) => part.type === "image").map(() => ({+ type: "image", mimeType: "image/png", data,+ })),+ }));+ } else {+ await expect(sent).rejects.toMatchObject({ code: "PI_IMAGE_INPUT_UNSUPPORTED" });+ expect(captured.requests).toHaveLength(0);+ }+ }+ }+ } finally {+ await handle.close();+ }+ });+it("guards image prompts by the startup provider-model capability and follows model switches", async () => {const gatewayModels: ModelDescriptor[] = [{