Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
Merge main and preserve Pi one-shot routing compatibility
xuzini-xzn6121fbc29477
diff --cc apps/desktop/src/main/utility-model/__tests__/auxiliaryDirectRoutes.test.tsindex 13e202f338,0000000000..f5f40d39cfmode 100644,000000..100644--- a/apps/desktop/src/main/utility-model/__tests__/auxiliaryDirectRoutes.test.ts+++ b/apps/desktop/src/main/utility-model/__tests__/auxiliaryDirectRoutes.test.ts@@@ -1,88 -1,0 +1,92 @@@+import { describe, expect, it } from 'vitest';+import { BUNDLED_CATALOG, buildUserProvider, type AgentKind } from '@cindy/model-providers';+import { buildTextOneshotPinOptions, decodeCatalogPin } from '../textOneshotPinOptions.js';+import { resolveDirectTextRoute } from '../directTextRoute.js';+import { normalizeAuxiliaryModelList } from '../../../shared/auxiliaryModelSettings.js';++const modelId = 'deepseek-v4.1-flash';+const preset = BUNDLED_CATALOG.presets!.find((entry) => entry.id === 'opencode-go')!;++function go(agents: AgentKind[] = ['claude-code', 'codex', 'pi'], enabled?: boolean) {+ return buildUserProvider({ id: 'go', name: 'OpenCode Go', runtimes: Object.fromEntries(+ agents.map((agent) => [agent, {+ ...preset.runtimes[agent], catalogPresetId: preset.id,+ models: [{ id: modelId, name: 'DeepSeek', ...(enabled !== undefined ? { defaultEnabled: enabled } : {}) }],+ }]),+ ) }, { presets: BUNDLED_CATALOG.presets });+}++describe('auxiliary direct HTTP admission', () => {+ it.each([['pi'], ['claude-code', 'codex', 'pi']] as AgentKind[][])(+ 'offers Go Flash without enabling chat compatibility (%j)', (...agents) => {+ const provider = go(agents);+ const catalog = { ...BUNDLED_CATALOG, providers: [provider] };+ const before = structuredClone(provider);+ const options = buildTextOneshotPinOptions(catalog, undefined, undefined, () => true, 'auxiliary');+ expect(options).toHaveLength(agents.length);+ expect(options.every((option) => option.defaultEnabled)).toBe(true);+ expect(normalizeAuxiliaryModelList(options.map((option) => option.id))).toEqual(options.map((option) => option.id));+ expect(provider).toEqual(before);+ if (agents.includes('codex')) expect(provider.models.codex![0].defaultEnabled).toBe(false);+ for (const option of options) {+ expect(resolveDirectTextRoute(provider, option.agentKind, provider.models[option.agentKind]![0])).toMatchObject({+ upstream: 'https://opencode.ai/zen/go/v1', wireProtocol: 'openai-chat',+ });+ }+ },+ );++ it('preserves explicit model defaults, disable overrides, credentials and plugin admission', () => {+ const provider = go(['pi'], false);+ const catalog = { ...BUNDLED_CATALOG, providers: [provider] };+ expect(buildTextOneshotPinOptions(catalog, undefined, undefined, () => true, 'auxiliary')[0].defaultEnabled).toBe(false);+ expect(buildTextOneshotPinOptions(catalog, undefined, undefined, () => false, 'auxiliary')).toEqual([]);+ expect(buildTextOneshotPinOptions(catalog, { disabledModels: { [`${provider.id}:${modelId}`]: true } }, undefined, () => true, 'auxiliary')).toEqual([]);+ expect(buildTextOneshotPinOptions(catalog, { disabledProviders: { [provider.id]: true } }, undefined, () => true, 'auxiliary')).toEqual([]);- expect(buildTextOneshotPinOptions(catalog, undefined)).toEqual([]);- expect(decodeCatalogPin('cat:go:pi:deepseek-v4.1-flash')).toBeNull();++ expect(buildTextOneshotPinOptions(catalog, undefined)).toEqual([++ expect.objectContaining({ agentKind: 'pi', defaultEnabled: false }),++ ]);++ expect(decodeCatalogPin('cat:go:pi:deepseek-v4.1-flash')).toEqual({++ providerId: 'go', agentKind: 'pi', model: modelId,++ });+ });++ it.each(['google-generative-ai', 'bedrock-converse-stream', 'azure-openai-responses'] as const)(+ 'does not offer unsupported SDK API %s even when the connection defaults to Chat', (api) => {+ const provider = go(['pi']);+ provider.models.pi![0].api = api;+ expect(buildTextOneshotPinOptions({ ...BUNDLED_CATALOG, providers: [provider] }, undefined, undefined, () => true, 'auxiliary')).toEqual([]);+ },+ );++ it('pairs model protocol, address and path without inheriting the connection path', () => {+ const provider = go(['codex']);+ provider.routing.codex!.requestPath = '/old/chat';+ const model = provider.models.codex![0];+ model.api = 'anthropic-messages';+ model.route = { baseUrl: 'https://messages.example', wireProtocol: 'anthropic-messages', requestPath: '/tenant/messages' };+ expect(resolveDirectTextRoute(provider, 'codex', model)).toMatchObject({+ upstream: 'https://messages.example', wireProtocol: 'anthropic-messages', requestPath: '/tenant/messages',+ });+ delete model.route.requestPath;+ expect(resolveDirectTextRoute(provider, 'codex', model)?.requestPath).toBeUndefined();+ });++ it('inherits the connection path only while the effective address and protocol are unchanged', () => {+ const provider = go(['codex']);+ const routing = provider.routing.codex!;+ routing.requestPath = '/tenant/completions';+ const model = provider.models.codex![0];+ expect(model.route?.baseUrl).toBe(routing.upstream);+ expect(resolveDirectTextRoute(provider, 'codex', model)?.requestPath).toBe('/tenant/completions');+ model.route!.requestPath = '/model/completions';+ expect(resolveDirectTextRoute(provider, 'codex', model)?.requestPath).toBe('/model/completions');+ delete model.route!.requestPath;+ model.route!.baseUrl = 'https://other.example/v1';+ expect(resolveDirectTextRoute(provider, 'codex', model)?.requestPath).toBeUndefined();+ model.route!.baseUrl = routing.upstream;+ model.route!.wireProtocol = 'openai-responses';+ model.api = 'openai-responses';+ expect(resolveDirectTextRoute(provider, 'codex', model)?.requestPath).toBeUndefined();+ });+});diff --cc apps/desktop/src/main/utility-model/__tests__/oneShotCandidates.test.tsindex e61e350073,b826b4000b..b514e39cea--- a/apps/desktop/src/main/utility-model/__tests__/oneShotCandidates.test.ts+++ b/apps/desktop/src/main/utility-model/__tests__/oneShotCandidates.test.ts@@@ -4752,6 -4635,6 +4752,27 @@@ describe('utility one-shot candidates'expect(bodyOf(0)).toMatchObject({ max_output_tokens: 16 });});++++ it('retains the Responses fallback for a Pi connection without a wire override', async () => {++ activeCatalog.mockReturnValue({++ providers: [{++ id: 'custom-pi', name: 'Custom Pi', source: 'user', agents: ['pi'],++ auth: { method: 'apiKey' },++ routing: { pi: { upstream: 'https://custom.example/v1', authStrategy: 'api-key-header' } },++ models: { pi: [{ id: 'pi-model', name: 'Pi Model', contextWindow: 100_000, efforts: [] }] },++ }],++ } as never);++ readCustomKey.mockReturnValue('custom-secret');++ fetchMock.mockResolvedValueOnce(responsesOk('ok') as never);++++ const result = await requestExplicitUtilityText('hello', {++ providerId: 'custom-pi', agentKind: 'pi', model: 'pi-model', disableReasoning: true,++ });++++ expect(result).toMatchObject({ ok: true, text: 'ok' });++ expect(String(fetchMock.mock.calls[0]?.[0])).toBe('https://custom.example/v1/responses');++ expect(bodyOf(0)).toMatchObject({ model: 'pi-model' });++ });it('still turns thinking off first for a custom Pi model with a placeholder effort list', async () => {activeCatalog.mockReturnValue({diff --cc apps/desktop/src/main/utility-model/directTextRoute.tsindex 134a8c473c,0000000000..a3421a91a6mode 100644,000000..100644--- a/apps/desktop/src/main/utility-model/directTextRoute.ts+++ b/apps/desktop/src/main/utility-model/directTextRoute.ts@@@ -1,38 -1,0 +1,38 @@@+import {+ isOpenAiSubscriptionProvider,+ resolvePiModelRoute,+ type AgentKind,+ type CatalogModel,+ type Provider,+ type RoutingDescriptor,+} from '@cindy/model-providers';++/** Subscription adapters own their endpoints and authentication; never treat them as BYOK. */+export function usesDirectTextRoute(provider: Provider): boolean {+ return provider.source !== 'builtin'+ && !isOpenAiSubscriptionProvider(provider)+ && provider.auth.native !== 'claude'+ && provider.auth.native !== 'xai';+}++/** Shared by auxiliary selection and HTTP dispatch. The runtime identifies the stored+ * connection/credential, not an agent process to launch. Reuse the portable API resolver+ * so SDK-only APIs cannot accidentally fall through to Responses. */+export function resolveDirectTextRoute(+ provider: Provider,+ agent: AgentKind,+ model: CatalogModel | undefined,+): RoutingDescriptor | null {+ const routing = provider.routing[agent];+ if (!provider.agents.includes(agent) || !routing || routing.disabled) return null;+ if (!['api-key-header', 'oauth-token', 'none'].includes(routing.authStrategy)) return null;+ const defaultWire = routing.wireProtocol- ?? (agent === 'claude-code' ? 'anthropic-messages' : agent === 'codex' ? 'openai-responses' : undefined);++ ?? (agent === 'claude-code' ? 'anthropic-messages' : 'openai-responses');+ const target = resolvePiModelRoute(model, { baseUrl: routing.upstream, wireProtocol: defaultWire });+ if (!target?.baseUrl.trim()) return null;+ // Retain legacy connection paths when the model restates the same target.+ // An endpoint or protocol switch must not inherit a path for a different API.+ const requestPath = target.requestPath+ ?? (target.baseUrl === routing.upstream && target.wireProtocol === defaultWire ? routing.requestPath : undefined);+ return { ...routing, upstream: target.baseUrl, wireProtocol: target.wireProtocol, requestPath };+}diff --cc apps/desktop/src/main/utility-model/textOneshotPinOptions.tsindex f77184d998,1fb6e05c11..bcaea88371--- a/apps/desktop/src/main/utility-model/textOneshotPinOptions.ts+++ b/apps/desktop/src/main/utility-model/textOneshotPinOptions.ts@@@ -34,8 -33,12 +34,8 @@@ importencodeCatalogModelPin,} from '../../shared/catalogModelPin.js';- /** Legacy plugin pins retain the Agent.oneShot allowlist; auxiliary HTTP routes are resolved separately. */- const ONESHOT_ROUTE_AGENTS = ['codex', 'claude-code'] as const;-/**- * oneshot 可路由的 agent。pi 档的含义是「借用 pi runtime 的路由声明(baseUrl/- * wireProtocol/key)由宿主直连」,不 spawn pi 会话;未声明 wireProtocol 的自定义- * 供应商与 codex 同待遇(走 responses wire),claude-code 仍恒 anthropic-messages。- */++/** Preserve plugin routing support; auxiliary HTTP admission is resolved separately. */+ const ONESHOT_ROUTE_AGENTS = ['codex', 'claude-code', 'pi'] as const;/*** 执行侧(requestBuiltinProviderText)可执行的内置供应商。清单侧必须按同一集合过滤——diff --cc apps/desktop/src/shared/auxiliaryModelSettings.tsindex 96328db470,1dc8f9f985..5cf0b1fc9c--- a/apps/desktop/src/shared/auxiliaryModelSettings.ts+++ b/apps/desktop/src/shared/auxiliaryModelSettings.ts@@@ -32,10 -31,10 +31,10 @@@ export interface AuxiliaryModelOptionlabel: string;group: string;providerId: string;- agentKind: CatalogModelPinAgentKind;+ agentKind: 'codex' | 'claude-code' | 'pi';modelId: string;modelName: string;- /** Follow the same default visibility as the regular model selector. */+ /** Auxiliary default; direct HTTP models do not inherit harness compatibility defaults. */defaultEnabled?: boolean;icon?: string;budget: boolean;diff --cc docs/dev-rules/configuration-and-overrides.mdindex 010989888f,4bd08b1aae..231ef3fd9a--- a/docs/dev-rules/configuration-and-overrides.md+++ b/docs/dev-rules/configuration-and-overrides.md@@@ -61,22 -61,6 +61,23 @@@ token)与 [`engineering-conventions.m[已知实现差异](model-catalog-maintenance.md#visibility)。该说明不是对本节合同的豁免;不得仅因代码仍在筛选就反向修改产品规则,也不能未验证便声称两者已一致。+### 辅助模型的直接调用++辅助模型的自定义 HTTP 连接按实际文本调用能力准入,不继承聊天引擎因兼容模式产生的+默认关闭状态。候选默认可见;连接模型配置中显式保存的 `defaultEnabled` 和用户显示+override 仍然优先。供应商/模型停用、退役、付费准入和凭证检查继续生效。+内置及原生订阅适配器保持原有默认规则。++选择记录继续使用 `cat:<连接>:<配置来源>:<模型>`;新增 `pi` 来源只标识连接与凭证,+不启动 Pi,也不要求其实现 `Agent.oneShot`。已有 Codex / Claude Code 记录及轻量档位+原样读取,不迁移或重排。候选和执行共用逐模型 HTTP 协议解析,未支持的 SDK 协议不列出。- 插件自行钉选的候选范围不扩大;跟随辅助模型链时使用用户已经保存的选择。++插件自行钉选继续沿用既有候选规则(含主干已支持的 Pi 路由);上述直接调用的默认准入++只用于辅助模型。插件跟随辅助模型链时使用用户已经保存的选择。+语音润色继续遵循现有的 OpenAI / Cindy AI 白名单,不因辅助模型候选扩大而新增通道。++实现与回归:`apps/desktop/src/main/utility-model/directTextRoute.ts`、+`__tests__/auxiliaryDirectRoutes.test.ts`、`__tests__/oneShotCandidates.test.ts`。+## 3. 默认值演进与迁移- 默认值变化时,分别说明新用户、未自定义老用户、已自定义老用户的行为。