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(pi): keep new Gateway Gemini models on the Google protocol

Chris8031878a9ead
diff --git a/apps/desktop/src/main/maker-host/__tests__/piGatewayModelCatalog.test.ts b/apps/desktop/src/main/maker-host/__tests__/piGatewayModelCatalog.test.ts
index 77d651e8db..d38b785f68 100644
--- a/apps/desktop/src/main/maker-host/__tests__/piGatewayModelCatalog.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/piGatewayModelCatalog.test.ts
@@ -186,6 +186,16 @@ describe('Cindy Server Pi Gateway catalog authority', () => {
});
describe('Pi Gateway version-matched local supplement catalog', () => {
+ it.each(['google/gemini-3.8-flash', 'gemini-3.8-flash', 'google/gemini-99-pro-preview[1m]'])(
+ 'keeps new XD Gemini route %s on Google without a per-model registration',
+ (id) => expect(resolveBundledPiGatewayModelProfile(id)).toEqual({ api: 'google-generative-ai' }),
+ );
+
+ it.each(['other/gemini-99-pro', 'google/not-gemini-99', 'google/gemini-99/other'])(
+ 'does not extend the XD Google policy to unrelated identity %s',
+ (id) => expect(resolveBundledPiGatewayModelProfile(id)).toBeUndefined(),
+ );
+
it('returns the exact Kimi native API and complete tool replay compatibility', () => {
expect(resolveBundledPiGatewayModelProfile('moonshotai/kimi-k3')).toMatchObject({
api: 'openai-completions',
diff --git a/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.ts b/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.ts
index 1656d283fe..e88b8c8391 100644
--- a/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.ts
@@ -45,6 +45,17 @@ import { setActiveCatalog, setXdGatewayModels } from '../active-catalog.js';
type Cfg = Parameters<typeof buildPiNativeProvidersFromConfigs>[0][number];
+it.each(['google/gemini-3.8-flash', 'google/gemini-99-pro-preview'])(
+ 'does not pass a misleading Gateway Responses hint to Pi for %s',
+ (id) => {
+ setActiveCatalog(BUNDLED_CATALOG);
+ setXdGatewayModels([{ id, agents: ['pi'], perAgent: { pi: { wireProtocol: 'openai-responses' } } }]);
+ expect(resolvePiCindyGatewayModelApi('xd', id)).toBe('google-generative-ai');
+ expect(resolvePiCindyGatewayModelSpec('xd', id)).toMatchObject({ api: 'google-generative-ai' });
+ expect(resolvePiCindyGatewayModelSpec('xd', id, { remote: true })).toMatchObject({ api: 'google-generative-ai' });
+ },
+);
+
const piRuntime = (over: Partial<NonNullable<Cfg['runtimes']['pi']>> = {}) => ({
baseUrl: 'http://127.0.0.1:11434/v1',
wireProtocol: 'openai-chat' as const,
diff --git a/apps/desktop/src/main/maker-host/pi-gateway-model-catalog.ts b/apps/desktop/src/main/maker-host/pi-gateway-model-catalog.ts
index fc77c8e427..c64a9d19dd 100644
--- a/apps/desktop/src/main/maker-host/pi-gateway-model-catalog.ts
+++ b/apps/desktop/src/main/maker-host/pi-gateway-model-catalog.ts
@@ -74,20 +74,24 @@ const gatewayModelIdsByApi: Record<PiModelApi, ReadonlySet<string>> = {
'z-ai/glm-5.3-flash',
'z-ai/glm-5.3-highspeed',
]),
- 'google-generative-ai': new Set([
- 'gemini-3-flash-preview',
- 'gemini-3.1-pro-preview',
- 'gemini-3.5-flash',
- 'gemini-3.6-flash',
- 'google/gemini-3.6-flash',
- 'google/gemini-3.7-flash',
- ]),
+ 'google-generative-ai': new Set(),
};
function normalizeModelId(modelId: string): string {
return modelId.replace(/\[1m\]$/, '');
}
+/** Cindy's XD Gemini route contract: use Pi's Google adapter, including new releases.
+ * This is a routing policy, not inferred model capability. It applies only to XD identities;
+ * another aggregator's Gemini-like ID must not acquire Google's protocol or serialization data.
+ */
+function googleGatewayIdentity(modelId: string): { provider: string; modelId: string } | undefined {
+ const normalized = normalizeModelId(modelId);
+ return /^(?:google\/)?gemini-[a-z0-9][a-z0-9._:-]*$/i.test(normalized)
+ ? { provider: 'google', modelId: normalized.replace(/^google\//i, '') }
+ : undefined;
+}
+
function piApiFromWireProtocol(protocol: ProviderWireProtocol | undefined): PiModelApi | undefined {
switch (protocol) {
case 'anthropic-messages':
@@ -200,14 +204,6 @@ const gatewayCatalogIdentityOverrides = new Map<string, { provider: string; mode
[`codex/${id}`, { provider: 'openai', modelId: id }] as const,
]),
['codex/gpt-5.5:auto', { provider: 'openai', modelId: 'gpt-5.5' }],
- ...[
- 'gemini-3-flash-preview',
- 'gemini-3.1-pro-preview',
- 'gemini-3.5-flash',
- 'gemini-3.6-flash',
- ].map((id) => [id, { provider: 'google', modelId: id }] as const),
- ['google/gemini-3.6-flash', { provider: 'google', modelId: 'gemini-3.6-flash' }],
- ['google/gemini-3.7-flash', { provider: 'google', modelId: 'gemini-3.7-flash' }],
...['deepseek-v4-flash', 'deepseek-v4-flash-vision-exp', 'deepseek-v4-pro'].map(
(id) => [`deepseek/${id}`, { provider: 'deepseek', modelId: id }] as const,
),
@@ -227,6 +223,7 @@ const gatewayCatalogIdentityOverrides = new Map<string, { provider: string; mode
]);
function authoritativeGatewayApi(modelId: string): PiModelApi | undefined {
+ if (googleGatewayIdentity(modelId)) return 'google-generative-ai';
const normalized = normalizeModelId(modelId);
for (const [api, ids] of Object.entries(gatewayModelIdsByApi) as Array<
[PiModelApi, ReadonlySet<string>]
@@ -241,6 +238,8 @@ export function resolveBundledPiGatewayCatalogIdentity(
modelId: string,
): { provider: string; modelId: string } | undefined {
const normalized = normalizeModelId(modelId);
+ const google = googleGatewayIdentity(normalized);
+ if (google) return google;
const explicit = gatewayCatalogIdentityOverrides.get(normalized);
if (explicit) return explicit;
const direct = rows.find((row) => `${row.provider}/${row.id}` === normalized);
@@ -251,7 +250,7 @@ export function resolveBundledPiGatewayCatalogIdentity(
* Resolve the current Gateway model through Cindy's version-matched Pi table.
*
* Cindy Server's downloaded Catalog is checked before this function. This local table is the
- * second authority and may only resolve exact, allowlisted identities. Cindy AI Gateway metadata
+ * second authority: exact identities plus Cindy's XD Gemini routing policy. Gateway metadata
* is a last-resort hint after both higher-priority sources are absent. Unknown identities fail
* closed instead of guessing a provider or protocol.
*/
diff --git a/apps/desktop/src/renderer/__tests__/gatewayModelArrival.test.tsx b/apps/desktop/src/renderer/__tests__/gatewayModelArrival.test.tsx
index 4118c203b7..29776a7c5a 100644
--- a/apps/desktop/src/renderer/__tests__/gatewayModelArrival.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/gatewayModelArrival.test.tsx
@@ -1,7 +1,7 @@
// @vitest-environment jsdom
import { act, cleanup, render, screen } from '@testing-library/react';
import { afterEach, expect, it, vi } from 'vitest';
-import { BUNDLED_CATALOG, type ProviderView } from '@cindy/model-providers';
+import { BUNDLED_CATALOG, modelProtocolComparison, pickRecommendedAgent, type ProviderView } from '@cindy/model-providers';
import { parseModelsSyncPayload } from '../../main/model-access/modelsSyncRefresh';
import {
getActiveCatalog,
@@ -30,6 +30,33 @@ afterEach(() => {
__resetForTest();
});
+it.each(['google/gemini-3.8-flash', 'google/gemini-99-pro-preview'])(
+ 'projects the actual Responses-hinted Gateway payload for %s as Google on Pi',
+ (id) => {
+ setActiveCatalog(BUNDLED_CATALOG);
+ const parsed = parseModelsSyncPayload({ schemaVersion: 5, accountTier: 'paid', models: [{
+ id, name: id, currency: 'USD', availability: 'available', mode: 'chat',
+ agents: ['claude-code', 'codex', 'pi'], contextWindow: 1_048_576,
+ perAgent: {
+ 'claude-code': { wireProtocol: 'anthropic-messages' },
+ codex: { wireProtocol: 'openai-responses' },
+ pi: { wireProtocol: 'openai-responses' },
+ },
+ }] });
+ if (!parsed.ok) throw new Error(parsed.error);
+ setXdGatewayModels(parsed.models, { authoritative: true });
+ const provider = getActiveCatalog().providers.find((p) => p.id === 'xd')!;
+ const models = Object.fromEntries(provider.agents.map((agent) => [agent, provider.models[agent]?.find((m) => m.id === id)]));
+ const comparison = modelProtocolComparison(provider, models);
+ expect(models.pi).toMatchObject({ id, piApi: 'google-generative-ai', contextWindow: 1_048_576 });
+ expect(comparison.reference).toBe('google-generative-ai');
+ expect(comparison.forAgent('pi')).toMatchObject({ outbound: 'google-generative-ai', mode: 'matching' });
+ expect(comparison.forAgent('codex')?.mode).toBe('compatibility');
+ expect(comparison.forAgent('claude-code')?.mode).toBe('compatibility');
+ expect(pickRecommendedAgent(provider, id, provider.agents)).toBe('pi');
+ },
+);
+
it('shows a just-downloaded Gateway model through the real parser and active catalog without a registry entry or remount', () => {
Object.defineProperty(window, 'electronAPI', { configurable: true, value: {} });
__resetForTest();