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(desktop): send Pi Gemini API preset models to the native /v1beta root

rbbthl-13b25d3c0038c
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 38c5cd4d04..6510018325 100644
--- a/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.ts
@@ -447,6 +447,30 @@ describe('buildPiNativeProvidersFromConfigs', () => {
},
);
+ it.each(['gemini-3.6-flash', 'gemini-3.5-flash', 'gemini-3.5-flash-lite'])(
+ 'sends the Google Gemini API preset %s to the native /v1beta root', (id) => {
+ const preset = BUNDLED_CATALOG.presets!.find(p => p.id === 'google-gemini-api')!;
+ const config = { id: 'google-gemini-api', name: 'Google Gemini API', runtimes: {
+ pi: { ...preset.runtimes.pi!, catalogPresetId: preset.id, models: [{ id, name: id }] },
+ } };
+ const catalog = { ...BUNDLED_CATALOG, providers: [...BUNDLED_CATALOG.providers, buildUserProvider(config, { presets: [preset] })] };
+ const { providers } = buildPiNativeProvidersFromConfigs([config], () => 'fixture-key', undefined, undefined, catalog);
+ // Discovery keeps the OpenAI-compatible connection root; the native SDK must not inherit it.
+ expect(providers[0].baseUrl).toBe('https://generativelanguage.googleapis.com/v1beta/openai');
+ expect(providers[0].models[0]).toMatchObject({
+ api: 'google-generative-ai', baseUrl: 'https://generativelanguage.googleapis.com/v1beta',
+ });
+ },
+ );
+
+ it('never rewrites a custom Gemini proxy endpoint', () => {
+ const baseUrl = 'https://proxy.example/v1beta/openai';
+ const { providers } = buildPiNativeProvidersFromConfigs([{ id: 'gemini-proxy', name: 'Proxy', runtimes: {
+ pi: piRuntime({ baseUrl, wireProtocol: 'openai-chat', models: [{ id: 'gemini-3.6-flash', name: 'Gemini', piApi: 'google-generative-ai' }] }),
+ } }], () => 'fixture-key');
+ expect(providers[0].models[0].baseUrl ?? providers[0].baseUrl).toBe(baseUrl);
+ });
+
it('carries catalog-generated suppliers through the real Pi launch mapping', () => {
const generatedIds = ['ant-ling', 'baseten', 'cerebras', 'fireworks', 'groq',
'huggingface', 'nvidia', 'together', 'mistral', 'opencode', 'qwen-token-plan',
diff --git a/apps/desktop/src/main/maker-host/pi-host.ts b/apps/desktop/src/main/maker-host/pi-host.ts
index 064b47ff32..418b0ec120 100644
--- a/apps/desktop/src/main/maker-host/pi-host.ts
+++ b/apps/desktop/src/main/maker-host/pi-host.ts
@@ -5,7 +5,7 @@ import { listCindyManagedSkills } from './managed-skills.js';
import { scanLocalCustomizations } from '../skillhub/customizationScanHost';
import { resolveCompanionRuntimeEnvironment } from '../bot-import/runtime.js';
import { readCachedGenericOAuthAccessToken } from './generic-oauth.js';
-import { providerPresetModelRecord, providerModelAdapterId } from '@cindy/model-providers';
+import { providerPresetModelRecord, providerModelAdapterId, providerBaseUrlForApi } from '@cindy/model-providers';
import { mergeByokNativeConfigs } from '../model-access/byokProvider.js';
import { readDisabledSkillPaths } from '../skillhub/activationPreferences';
import { subscriptionAccountKind, subscriptionAccountState, isXaiSubscriptionProviderId } from './subscription-account-auth.js';
@@ -1437,9 +1437,14 @@ export function buildPiNativeProvidersFromConfigs(
// bundled/official rows may lend protocol-compatible capabilities, but never routing.
// A same-origin URL is not the same endpoint: replacing /proxy/v1 with /v1 can bypass
// the user's proxy. Only the model's own explicit route may create a model-level baseUrl.
+ // Exception: Google's official preset keeps /v1beta/openai for discovery, but its native
+ // SDK must call /v1beta. providerBaseUrlForApi only rewrites Google's public endpoints.
+ const nativeGoogleBaseUrl =
+ modelApi === 'google-generative-ai' && !m.route?.requestPath && !rt.requestPath
+ ? providerBaseUrlForApi(rt.baseUrl, modelApi) : undefined;
const modelBaseUrl =
m.api && m.route ? m.route.baseUrl :
- m.route && explicitRouteApi === modelApi ? explicitRoute?.baseUrl : undefined;
+ m.route && explicitRouteApi === modelApi ? explicitRoute?.baseUrl : nativeGoogleBaseUrl;
const spec = {
id: m.id,
...(m.selectedInterface ? { wireId: m.selectedInterface.wireModelId } : {}),