Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(providers): preserve unknown image input in native bridges

Dantecee7f564fa93
diff --git a/apps/desktop/src/main/maker-host/__tests__/piProviderTransport.test.ts b/apps/desktop/src/main/maker-host/__tests__/piProviderTransport.test.ts
index 73b0fb02e9..45e1fa72be 100644
--- a/apps/desktop/src/main/maker-host/__tests__/piProviderTransport.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/piProviderTransport.test.ts
@@ -294,6 +294,54 @@ it.each(['gemini-3.6-flash', 'gemini-3.5-flash', 'gemini-3.5-flash-lite'])('send
});
+describe('imported Gemini native image capability', () => {
+ const id = 'gemini-4-argon';
+ const preset = BUNDLED_CATALOG.presets!.find(p => p.id === 'google-gemini-api')!;
+ const imported = mergeDiscoveredRuntimeModels([], parseModelsListResponse({ data: [{ id }] })!);
+ const provider = buildUserProvider({ id: 'google-image-import', name: 'Google', runtimes: {
+ pi: { ...preset.runtimes.pi!, catalogPresetId: preset.id, models: imported },
+ } }, { presets: [preset] });
+ it.each([undefined, true, false])('keeps imported Gemini image input consistent for supportsImageInput=%s', async supportsImageInput => {
+ expect(provider.models.pi![0].supportsImageInput).toBeUndefined();
+ expect(provider.models.pi![0].modalities).toBeUndefined();
+ // Compare the same imported model with no declaration and explicit on/off values.
+ const model = { ...provider.models.pi![0], supportsImageInput };
+ const row = invocationModelRecord(model, model.route?.baseUrl ?? provider.routing.pi!.upstream!)!;
+ const requests: Request[] = [];
+ let sent: { contents: Array<{ parts: Array<Record<string, unknown>> }> } | undefined;
+ vi.stubGlobal('fetch', async (input: RequestInfo | URL, init?: RequestInit) => {
+ const request = new Request(input, init); requests.push(request);
+ expect(new URL(request.url).pathname).toBe(`/v1beta/models/${id}:streamGenerateContent`);
+ sent = await request.json() as typeof sent;
+ return new Response(`data: ${JSON.stringify({ candidates: [{ content: { role: 'model', parts: [{ text: 'OK' }] }, finishReason: 'STOP' }] })}\n\n`, { headers: { 'content-type': 'text/event-stream' } });
+ });
+ try {
+ const send = createPiProviderFetch({ row, providerId: provider.id, apiKey: 'fixture-key',
+ fetchImpl: async () => { throw new Error('Google uses its native SDK transport'); } });
+ const response = await send('https://unused.invalid', { body: JSON.stringify({ model: id, input: [{ role: 'user', content: [
+ { type: 'input_text', text: 'describe the image' },
+ // Existing bridge fixture bytes; this checks serialization, not real recognition.
+ { type: 'input_image', image_url: 'data:image/png;base64,aW1hZ2U=' },
+ ] }], max_output_tokens: 128, stream: true }) });
+ expect(await response.text()).toContain('response.completed');
+ expect(requests).toHaveLength(1);
+ const parts = sent!.contents[0].parts;
+ expect(parts.some(part => 'inlineData' in part)).toBe(supportsImageInput !== false);
+ if (supportsImageInput !== false) expect(parts).toContainEqual({ inlineData: { mimeType: 'image/png', data: 'aW1hZ2U=' } });
+ } finally { vi.unstubAllGlobals(); }
+ });
+});
+
+it('keeps explicitly text-only modalities closed despite the unknown-capability fallback', () => {
+ const upstream = 'https://unknown.example/v1';
+ const provider = buildUserProvider({ id: 'unknown', name: 'Unknown', runtimes: {
+ pi: { baseUrl: upstream, wireProtocol: 'google-generative-ai', models: [{ id: 'unknown-model', name: 'Unknown' }] },
+ } });
+ const model = { ...provider.models.pi![0], supportsImageInput: undefined, modalities: { input: ['text'], output: ['text'] } };
+ expect(invocationModelRecord(model, upstream, 'google-generative-ai')!.supportsImageInput).toBe(false);
+});
+
+
it.each(['individual', 'business', 'enterprise'])('sends Copilot Responses editor headers to the %s host', async account => {
const row = PROVIDER_MODEL_CATALOG.providers['github-copilot'].find(row => row.execution.pi.api === 'openai-responses')!;
let captured = false;
diff --git a/apps/desktop/src/main/maker-host/pi-provider-transport.ts b/apps/desktop/src/main/maker-host/pi-provider-transport.ts
index 59cd5f8459..26ac03210a 100644
--- a/apps/desktop/src/main/maker-host/pi-provider-transport.ts
+++ b/apps/desktop/src/main/maker-host/pi-provider-transport.ts
@@ -21,12 +21,16 @@ export function invocationModelRecord(model: CatalogModel, upstream: string, api
?? (selected ? providerPresetModelRecord(model.catalogPresetId, model.id, selected) : undefined)
?? providerModelGenerationRecord(model.id, upstream, selected, model.catalogPresetId);
if (!selected && !known) return undefined;
+ // The active catalog is authoritative; unknown capability must not silently
+ // discard images in native bridges while the Pi runtime allows them.
+ const supportsImageInput = model.supportsImageInput ?? model.modalities?.input.includes('image')
+ ?? known?.supportsImageInput ?? known?.modalities?.input.includes('image') ?? true;
return {
...(known ?? {}), id: model.id, name: model.name, upstream,
contextWindow: model.contextWindowMax ?? model.contextWindow,
maxOutput: model.maxOutput ?? known?.maxOutput,
- modalities: model.modalities ?? known?.modalities ?? { input: ['text'], output: ['text'] },
- supportsImageInput: model.supportsImageInput ?? known?.supportsImageInput ?? false,
+ modalities: model.modalities ?? known?.modalities ?? { input: supportsImageInput ? ['text', 'image'] : ['text'], output: ['text'] },
+ supportsImageInput,
supportsFastMode: model.supportsFastMode,
reasoning: model.efforts.length > 0, efforts: model.efforts, defaultEffort: model.defaultEffort,
execution: { pi: { ...known?.execution.pi, api: selected ?? known!.execution.pi.api,
@@ -204,7 +208,7 @@ function nativeInvocationModel(options: PiProviderTransportOptions, modelId: str
const model: Model<Api> = { id: modelId, name: row.name, provider: providerModelAdapterId(row) ?? options.providerId,
api: row.execution.pi.api, baseUrl: destination, contextWindow: row.contextWindow ?? 200_000,
maxTokens: row.maxOutput ?? Math.min(4096, row.contextWindow ?? 200_000), reasoning: row.reasoning ?? (row.efforts?.length ?? 0) > 0,
- input: row.supportsImageInput ? ['text', 'image'] : ['text'],
+ input: (row.supportsImageInput ?? row.modalities?.input.includes('image') ?? true) ? ['text', 'image'] : ['text'],
cost: { input: row.cost?.input ?? 0, output: row.cost?.output ?? 0,
cacheRead: row.cost?.cacheRead ?? 0, cacheWrite: row.cost?.cacheWrite ?? 0 },
thinkingLevelMap: { ...row.execution.pi.thinkingLevelMap, ...Object.fromEntries(PI_REASONING_EFFORTS.map(level =>
diff --git a/docs/dev-rules/pi-harness.md b/docs/dev-rules/pi-harness.md
index febcb2a408..a361df645b 100644
--- a/docs/dev-rules/pi-harness.md
+++ b/docs/dev-rules/pi-harness.md
@@ -86,6 +86,10 @@ Cindy 以 `pi --mode rpc` spawn pi 二进制(JSONL/stdio),`translator.ts` 把 pi
时仍保持仅文本;此默认值不写回用户配置,也不代表上游接口保证支持图片。活动任务沿用启动时
能力快照。回归见 `pi-provider-routing.test.ts` 与 `piNativeProviders.test.ts`。
+Codex / Claude Code 复用的 `pi-provider-transport.ts` 原生桥接也沿用此缺省口径:
+活动目录的显式图片开关或模态声明优先于原生兜底资料,只有均未声明时才允许图片。
+此行为只决定图片是否进入原生 SDK 请求,不保证上游识图;回归见 `piProviderTransport.test.ts`。
+
Cindy 显式设置:models.json、`settings.json` 的 `transport:sse` 与 `retry.maxRetries=6`
(`retry.provider.maxRetries` 保持 0)、`--append-system-prompt`、`--session-dir`、启动时 RPC
`set_auto_compaction{enabled:true}` / `set_thinking_level`。Pi 原生负责 threshold 与 overflow 压缩;