Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(models): 统一所有来源 OpenAI 模型的 272K 默认上下文 (#5293)
Chris Zhangd54db7c247f0
diff --git a/apps/desktop/src/main/maker-host/__tests__/openAiContextDefaults.test.ts b/apps/desktop/src/main/maker-host/__tests__/openAiContextDefaults.test.tsnew file mode 100644index 0000000000..22605d007d--- /dev/null+++ b/apps/desktop/src/main/maker-host/__tests__/openAiContextDefaults.test.ts@@ -0,0 +1,181 @@+import { afterEach, describe, expect, it } from 'vitest';+import {+ BUNDLED_CATALOG, buildUserProvider, mergeDiscoveredRuntimeModels, parseModelsListResponse,+ type AgentKind, type Catalog, type CustomProviderConfig,+} from '@cindy/model-providers';+import {+ getActiveCatalog, setActiveCatalog, setCustomProviderConfigs, setCustomProviders,+ setDiscoveredCodexModels, setLocalCatalogOverrides,+} from '../active-catalog.js';+import { invocationModelRecord } from '../pi-provider-transport.js';+import { resolveModelDefaultContextWindow } from '../catalog-to-descriptors.js';+import { EMPTY_MODEL_CATALOG_OVERRIDES } from '../model-plane/localCatalogOverrides.js';++const agents: AgentKind[] = ['claude-code', 'codex', 'pi'];+const discovery = (fields = {}) => mergeDiscoveredRuntimeModels([], parseModelsListResponse({ models: [{+ slug: 'gpt-6-astra', context_window: 1_024_000, max_context_window: 1_050_000, ...fields,+}] })!);+function config(models = discovery(), id = 'custom:sub2api'): CustomProviderConfig {+ return { id, name: id, runtimes: Object.fromEntries(agents.map(agent => [agent, {+ baseUrl: 'https://relay.example/v1', wireProtocol: 'openai-responses', models,+ }])) };+}+function row(agent: AgentKind, id = 'gpt-6-astra', provider = 'custom:sub2api') {+ return getActiveCatalog().providers.find(p => p.id === provider)!.models[agent]!.find(m => m.id === id)!;+}+afterEach(() => {+ setCustomProviders([]);+ setDiscoveredCodexModels([]);+ setLocalCatalogOverrides(EMPTY_MODEL_CATALOG_OVERRIDES);+ setActiveCatalog(BUNDLED_CATALOG);+});++describe('all OpenAI routes share the daily context default', () => {+ it('imports and refreshes Sub2API without turning capacity or the default into a user edit', () => {+ setActiveCatalog(BUNDLED_CATALOG);+ const original = config();+ setCustomProviderConfigs([original]);+ const check = () => {+ for (const agent of agents) {+ expect(row(agent)).toMatchObject({ contextWindow: 272_000, contextWindowMax: 1_050_000 });+ expect(resolveModelDefaultContextWindow(getActiveCatalog(), agent, 'custom:sub2api', 'gpt-6-astra')).toBe(272_000);+ expect(row(agent).userModelConfig?.contextWindow).toBeUndefined();+ expect(row(agent).discoveredMetadata?.contextWindow).toBe(1_024_000);+ expect(invocationModelRecord(row(agent), 'https://relay.example/v1', 'openai-responses')?.contextWindow).toBe(1_050_000);+ }+ };+ check();+ const saved = JSON.parse(JSON.stringify(original));+ for (const agent of agents) saved.runtimes[agent].models = mergeDiscoveredRuntimeModels(+ saved.runtimes[agent].models, parseModelsListResponse({ data: [{ id: 'gpt-6-astra' }] })!,+ );+ setCustomProviderConfigs([saved]);+ check();+ setActiveCatalog(structuredClone(BUNDLED_CATALOG), { capabilityEvidence: 'fallback' });+ check();+ expect(original.runtimes.codex!.models[0].discoveredMetadata?.contextWindow).toBe(1_024_000);+ });++ it.each(['user', 'organization', undefined] as const)('covers %s connections, public aliases and future OpenAI families', source => {+ setActiveCatalog(BUNDLED_CATALOG);+ const ids = ['gpt-6-astra', 'openai/gpt-6-astra', 'codex/gpt-7-astra', 'chatgpt/gpt-7-astra', 'o5', 'openai/o5-pro', 'codex-next'];+ const provider = buildUserProvider(config(mergeDiscoveredRuntimeModels([], parseModelsListResponse({ data: ids.map(id => ({+ id, context_window: 872_000,+ })) })!)));+ // Legacy catalogs may omit source; current providers require an explicit source.+ if (source === undefined) Reflect.deleteProperty(provider, 'source');+ else provider.source = source;+ setCustomProviders([provider]);+ for (const agent of agents) for (const id of ids) {+ expect(row(agent, id)).toMatchObject({ contextWindow: 272_000, contextWindowMax: 872_000 });+ }+ });++ it('covers third-party presets and exact Registry deployment identities', () => {+ const catalog = structuredClone(BUNDLED_CATALOG) as Catalog;+ catalog.modelRegistry!.models.push({+ id: 'relay/astra-deployment', name: 'Astra deployment', modelRef: 'openai/gpt-6-astra',+ routes: [{ providerId: 'custom:sub2api', modelId: 'deployment-astra', agents: ['claude-code', 'codex'] }],+ });+ setActiveCatalog(catalog);+ const models = parseModelsListResponse({ data: [{ id: 'deployment-astra' }] })!;+ setCustomProviderConfigs([config(models), {+ id: 'custom:router', name: 'Router',+ runtimes: Object.fromEntries(agents.map(agent => [agent, {+ catalogPresetId: 'openrouter',+ baseUrl: 'https://openrouter.ai/api/v1', wireProtocol: 'openai-chat',+ models: mergeDiscoveredRuntimeModels([], parseModelsListResponse({ data: [{ id: 'openai/gpt-6-astra', context_length: 1_050_000 }] })!),+ }])),+ }]);+ for (const agent of agents) {+ expect(row(agent, 'deployment-astra')).toMatchObject({ contextWindow: 272_000, contextWindowMax: 1_050_000 });+ expect(row(agent, 'openai/gpt-6-astra', 'custom:router')).toMatchObject({ contextWindow: 272_000, contextWindowMax: 1_050_000 });+ }+ });++ it('keeps maximum-only manifests separate from the default', () => {+ setActiveCatalog(BUNDLED_CATALOG);+ setCustomProviderConfigs([config(discovery({ context_window: undefined, max_context_window: 872_000 }))]);+ for (const agent of agents) expect(row(agent)).toMatchObject({ contextWindow: 272_000, contextWindowMax: 872_000 });+ });++ it.each(['user', 'organization'] as const)('keeps known non-OpenAI identities ahead of GPT-like names on %s connections', source => {+ const catalog = structuredClone(BUNDLED_CATALOG) as Catalog;+ catalog.modelRegistry!.baseModels!.push({+ id: 'other/vendor-model', aliases: ['codex-other', 'o99'],+ defaults: { contextWindow: 1_000_000, contextWindowMax: 1_000_000 },+ });+ catalog.modelRegistry!.models.push({+ id: 'relay/other-deployment', name: 'Other vendor', modelRef: 'other/vendor-model',+ routes: [{ providerId: 'custom:sub2api', modelId: 'gpt-6-astra', agents: ['claude-code', 'codex'] }],+ });+ setActiveCatalog(catalog);+ const ids = ['gpt-6-astra', 'codex-other', 'o99'];+ const models = mergeDiscoveredRuntimeModels([], parseModelsListResponse({ data: ids.map(id => ({+ id, context_window: 1_000_000, max_context_window: 1_000_000,+ })) })!);+ const provider = buildUserProvider(config(models), { modelRegistry: catalog.modelRegistry });+ provider.source = source;+ setCustomProviders([provider]);+ for (const agent of agents) for (const id of ids) {+ expect(row(agent, id)).toMatchObject({ contextWindow: 1_000_000, contextWindowMax: 1_000_000 });+ expect(resolveModelDefaultContextWindow(getActiveCatalog(), agent, 'custom:sub2api', id)).toBe(1_000_000);+ }+ });++ it('preserves manual model windows and connection/engine patches, and restores the current default', () => {+ setActiveCatalog(BUNDLED_CATALOG);+ const models = discovery().map(model => ({ ...model, contextWindow: 800_000 }));+ setCustomProviderConfigs([config(models)]);+ for (const agent of agents) expect(row(agent).contextWindow).toBe(800_000);+ setCustomProviderConfigs([config()]);+ setLocalCatalogOverrides({ ...EMPTY_MODEL_CATALOG_OVERRIDES, patches: {+ 'custom%3Asub2api:gpt-6-astra': { base: { contextWindow: 700_000 }, perAgent: { codex: { contextWindow: 900_000 } } },+ } });+ for (const agent of agents) expect(row(agent).contextWindow).toBe(agent === 'codex' ? 900_000 : 700_000);+ setLocalCatalogOverrides({ ...EMPTY_MODEL_CATALOG_OVERRIDES, patches: {+ 'custom%3Asub2api:gpt-6-astra': { agents: ['codex'], base: { contextWindow: 800_000 } },+ } });+ for (const agent of agents) expect(row(agent).contextWindow).toBe(agent === 'codex' ? 800_000 : 272_000);+ setLocalCatalogOverrides(EMPTY_MODEL_CATALOG_OVERRIDES);+ for (const agent of agents) expect(row(agent)).toMatchObject({ contextWindow: 272_000, contextWindowMax: 1_050_000 });+ });++ it('preserves public overrides and local additions after subscription/bridge projection', () => {+ setActiveCatalog(BUNDLED_CATALOG);+ setCustomProviderConfigs([config()]);+ setLocalCatalogOverrides({ ...EMPTY_MODEL_CATALOG_OVERRIDES, baseModels: {+ 'openai/gpt-6-astra': { contextWindow: 800_000 },+ } });+ for (const agent of agents) expect(row(agent).contextWindow).toBe(800_000);+ setLocalCatalogOverrides({ ...EMPTY_MODEL_CATALOG_OVERRIDES, additions: {+ 'openai:gpt-7-astra': { agents: ['codex', 'claude-code', 'pi'], base: {+ name: 'GPT-7 Astra', contextWindow: 800_000, efforts: [], defaultEffort: null,+ } },+ } });+ const openai = getActiveCatalog().providers.find(p => p.id === 'openai')!;+ for (const agent of agents) expect(openai.models[agent]!.find(m => m.id ===+ (agent === 'codex' ? 'gpt-7-astra' : 'chatgpt/gpt-7-astra'))?.contextWindow).toBe(800_000);+ });++ it('preserves smaller OpenAI windows and leaves other vendors, private IDs and media alone', () => {+ setActiveCatalog(BUNDLED_CATALOG);+ const models = parseModelsListResponse({ data: [+ { id: 'gpt-6-astra', context_window: 128_000 },+ { id: 'claude-opus-5', context_window: 1_000_000 },+ { id: 'private/gpt-6-astra', context_window: 1_000_000 },+ { id: 'gpt-image-next', mode: 'image_generation', context_window: 1_000_000 },+ ] })!;+ const provider = buildUserProvider(config(models));+ // Exercise the projection's media guard even when an older catalog kept media in models.+ for (const agent of agents) provider.models[agent]!.push({+ id: 'gpt-image-next', name: 'Image', mode: 'image_generation', contextWindow: 1_000_000,+ efforts: [], defaultEffort: null,+ });+ setCustomProviders([provider]);+ for (const agent of agents) {+ expect(row(agent).contextWindow).toBe(128_000);+ for (const id of ['claude-opus-5', 'private/gpt-6-astra', 'gpt-image-next']) expect(row(agent, id).contextWindow).toBe(1_000_000);+ }+ });+});diff --git a/apps/desktop/src/main/maker-host/active-catalog.ts b/apps/desktop/src/main/maker-host/active-catalog.tsindex 78244e3b27..76804e132d 100644--- a/apps/desktop/src/main/maker-host/active-catalog.ts+++ b/apps/desktop/src/main/maker-host/active-catalog.ts@@ -1661,33 +1661,8 @@ function computeMerged(): Catalog {? null: (clampEffortToSupported(intent, model.efforts) as Effort | null): model.defaultEffort;- // Product working defaults are distinct from the provider's advertised capacity.- // Apply to each built-in GPT route, including subscription and discount aliases.- // Never enlarge smaller models or overwrite BYOM / explicit preference overrides.- const conservativeGptDefault =- (!isCustomRoutedProvider(provider) || !!provider.auth.native) &&- ['openai', 'xd'].includes(metadataProviderId) &&- /^(?:(?:codex|openai|chatgpt)\/)?gpt-/.test(model.id) &&- model.contextWindow > 272_000 &&- model.userModelConfig?.contextWindow === undefined &&- !(- (agent === 'codex' || agent === 'claude-code' || agent === 'pi') &&- hasLocalContextWindowOverride(- localOverrides,- provider.id,- metadataProviderId === 'openai' ? model.id.replace(/^chatgpt\//, '') : model.id,- agent,- metadataProviderId,- )- );return {...model,- ...(conservativeGptDefault- ? {- contextWindow: 272_000,- contextWindowMax: model.contextWindowMax ?? model.contextWindow,- }- : {}),defaultEffort,...(nativeApi !== undefined ? { nativeApi } : {}),};@@ -1762,29 +1737,6 @@ function computeMerged(): Catalog {),);}- if (- (!isCustomRoutedProvider(provider) || !!provider.auth.native) &&- ['openai', 'xd'].includes(metadataProviderId) &&- /^(?:(?:codex|openai|chatgpt)\/)?gpt-/.test(next.id) &&- next.contextWindow > 272_000 &&- next.userModelConfig?.contextWindow === undefined &&- !(- (agent === 'codex' || agent === 'claude-code' || agent === 'pi') &&- hasLocalContextWindowOverride(- localOverrides,- provider.id,- next.id.replace(/^chatgpt\//, ''),- agent,- metadataProviderId,- )- )- ) {- next = {- ...next,- contextWindowMax: Math.max(next.contextWindowMax ?? 0, next.contextWindow),- contextWindow: 272_000,- };- }const identity =findModelRegistryRoute(b.modelRegistry,@@ -1923,6 +1875,39 @@ function computeMerged(): Catalog {}),])) };});+ // One working-default projection after discovery, Registry, custom/organization+ // connections and local additions. Never persist it as discovery or a user edit.+ providers = providers.map(provider => ({+ ...provider,+ models: Object.fromEntries(Object.entries(provider.models).map(([agent, models]) => [+ agent, models?.map(model => {+ if (!(model.contextWindow > 272_000) ||+ (model.mode && model.mode !== 'chat' && model.mode !== 'responses')) return model;+ const metadataProviderId = providerCatalogId(provider);+ const rootId = metadataProviderId === 'openai'+ ? model.id.replace(/^chatgpt\//, '') : model.id;+ const identity = findModelRegistryRoute(+ b.modelRegistry, metadataProviderId, rootId,+ agent === 'pi' ? undefined : agent as RootAgentKind,+ )?.entry.modelRef ?? findBaseModel(b.modelRegistry, rootId)?.id;+ // Known public identities take precedence, including other vendors using+ // GPT-like aliases. Only unresolved GPT/Codex/o-series IDs fall back to+ // family names before the next catalog release; protocol alone never+ // identifies a vendor, and arbitrary private namespaces remain excluded.+ const openAiModel = identity !== undefined+ ? identity.startsWith('openai/')+ : /^(?:(?:codex|openai|chatgpt)\/)?(?:gpt-|codex-|o\d+(?:[.-]|$))/.test(model.id);+ if (!openAiModel || model.userModelConfig?.contextWindow !== undefined ||+ (identity && localOverrides.baseModels?.[identity]?.contextWindow !== undefined) ||+ hasLocalContextWindowOverride(localOverrides, provider.id, rootId,+ agent as AgentKind, metadataProviderId) ||+ (rootId !== model.id && hasLocalContextWindowOverride(localOverrides,+ provider.id, model.id, agent as AgentKind, metadataProviderId))) return model;+ return { ...model, contextWindow: 272_000,+ contextWindowMax: model.contextWindowMax ?? model.contextWindow };+ }),+ ])),+ }));return { ...b, modelRegistry, providers };}diff --git a/apps/desktop/src/main/maker-host/model-plane/localCatalogOverrides.ts b/apps/desktop/src/main/maker-host/model-plane/localCatalogOverrides.tsindex 57de1031ed..389e9eee27 100644--- a/apps/desktop/src/main/maker-host/model-plane/localCatalogOverrides.ts+++ b/apps/desktop/src/main/maker-host/model-plane/localCatalogOverrides.ts@@ -600,8 +600,8 @@ export function hasLocalContextWindowOverride(const entry = overrides[section][`${encodeURIComponent(providerId)}:${modelId}`];return (entry &&- (agent === 'pi'- ? (!entry.agents || entry.agents.includes('pi'))+ (section === 'patches' || agent === 'pi'+ ? (!entry.agents || entry.agents.includes(agent)): entryMembershipAgents(entry, policyProviderId).includes(agent)) &&effectiveFields(entry, agent).contextWindow !== undefined);diff --git a/docs/dev-rules/model-catalog-runtime.md b/docs/dev-rules/model-catalog-runtime.mdindex ec4918b996..2e84096a39 100644--- a/docs/dev-rules/model-catalog-runtime.md+++ b/docs/dev-rules/model-catalog-runtime.md@@ -112,11 +112,15 @@ Registry 的全部模型及其 routes,防止只翻译当前默认启用的几### GPT 日常窗口与 Codex Chat Completions(2026-09-06 用户裁决)-- 内置 OpenAI 订阅与 XD 的 GPT 路由采用至多 272,000 tokens 的日常默认窗口,- 覆盖普通、`codex/`、`openai/`、`chatgpt/` 别名及各引擎。较小模型不扩容。+- 所有来源的 OpenAI 聊天模型采用至多 272,000 tokens 的日常默认窗口,包括内置订阅、XD、+ 自定义 API/Sub2API、第三方预设和组织连接,覆盖 Claude Code、Codex、Pi。+ 覆盖 GPT、Codex、o 系列的原始 ID、`codex/`、`openai/`、`chatgpt/` 别名,以及 Registry+ 明确关联到 OpenAI 公共型号的部署 ID。已解析的公共型号身份优先于名称;只有未解析身份时+ 才按上述系列与命名空间推断,任意私有命名空间不推断。较小模型不扩容;仅有兼容协议不推断厂商。`contextWindowMax` 保留供应商容量;这是客户端工作默认策略,不修改服务端能力声明。- 显式上下文 override 仍优先,可设置 1M;恢复默认删除 override 后采用 272K。- 自定义供应商与非 GPT 模型不套用此默认策略。+ 用户显式模型窗口、公共型号与连接/引擎补丁仍优先;非 OpenAI 模型和媒体模型不套用此策略。+ 导入、刷新、离线回退、组织同步与本地 addition 经同一活动目录出口投影,不把默认值写回发现快照或用户配置。- Codex CLI 0.153.0 已移除原生 Chat Completions。Cindy 的既有转换路径仍可使用,但按 2026-09-07 用户更正,界面恢复「兼容模式」、默认关闭,允许用户手动开启。不新增「支持」协议分类;用户显式开关保持优先。GPT 窗口默认与自动压缩修复不回退。diff --git a/docs/product-rules/model-metadata-precedence.md b/docs/product-rules/model-metadata-precedence.mdindex c7156acd73..3eb7955f6a 100644--- a/docs/product-rules/model-metadata-precedence.md+++ b/docs/product-rules/model-metadata-precedence.md@@ -214,6 +214,6 @@ Server `catalog/providers.json` 是数据正本;客户端 `catalog/model-regis复用当前目录接口与 Registry V4 协商,不增加请求或数据库表。旧 V1/V2/V3 客户端收到展开后的旧字段;不同资料的多条路由在兼容响应中拆成独立条目,保留上游 ID,额外条目使用派生目录 ID。旧协议不支持的公共引用、覆盖指令与图片字段被移除,空默认以缺省表达。-供应商总容量与客户端工作预算分开:既有 GPT 272K 工作预算继续保留;这里的 `contextWindowMax` 指客户端 CatalogModel 投影,不是 Server 字段。Registry 资料中的 contextWindow 与合法 perAgent 工作默认分别维护;用户显式窗口覆盖仍优先。协议和实际执行能力门禁继续由运行时负责,元数据不能解锁未实现协议或伪造可售性。+供应商总容量与客户端工作预算分开:所有来源 OpenAI 聊天模型的至多 272K 工作默认继续保留(含第三方、自定义与组织连接,用户显式设置优先);这里的 `contextWindowMax` 指客户端 CatalogModel 投影,不是 Server 字段。Registry 资料中的 contextWindow 与合法 perAgent 工作默认分别维护;用户显式窗口覆盖仍优先。协议和实际执行能力门禁继续由运行时负责,元数据不能解锁未实现协议或伪造可售性。验收至少覆盖缺字段继承、供应商优先、force 修正、用户最高、显式 false/null/空数组、未知供应商公共识别、刷新与保存、旧版解析、离线与坏快照回退。模型推荐标准另见 [本地模型筛选](local-model-selection.md),仍只按能力、速度和实际运行内存筛选。diff --git a/packages/model-providers/src/__tests__/modelDiscoveryChannels.test.ts b/packages/model-providers/src/__tests__/modelDiscoveryChannels.test.tsindex 076a1313a0..85c2dd8066 100644--- a/packages/model-providers/src/__tests__/modelDiscoveryChannels.test.ts+++ b/packages/model-providers/src/__tests__/modelDiscoveryChannels.test.ts@@ -69,6 +69,19 @@ describe('shared provider discovery', () => {}});+ it('retains maximum-only account capacity below the public working default', () => {+ const models = mergeDiscoveredRuntimeModels([], parseModelsListResponse({ data: [{+ id: 'gpt-6-astra', max_context_window: 872000,+ }] })!);+ for (const agent of ['claude-code', 'codex', 'pi'] as const) {+ const provider = buildUserProvider({ id: 'relay', name: 'Relay', runtimes: {+ [agent]: { baseUrl: 'https://relay.example/v1', models },+ } }, { modelRegistry: BUNDLED_CATALOG.modelRegistry });+ expect(provider.models[agent]?.[0]).toMatchObject({ contextWindow: 872000, contextWindowMax: 872000 });+ expect(provider.models[agent]?.[0].discoveredMetadata).toEqual({ contextWindowMax: 872000 });+ }+ });+it('uses maximum-only discovery as an unverified working fallback without saving it as a report', () => {const discovered = parseModelsListResponse({ data: [{ id: 'private-model', max_context_window: 64000 }] })!;const models = mergeDiscoveredRuntimeModels([], discovered);diff --git a/packages/model-providers/src/modelMetadataLayers.ts b/packages/model-providers/src/modelMetadataLayers.tsindex 4eab3ff9bb..b618ef155b 100644--- a/packages/model-providers/src/modelMetadataLayers.ts+++ b/packages/model-providers/src/modelMetadataLayers.ts@@ -272,6 +272,15 @@ export function resolveModelMetadata(result.contextWindow = result.contextWindowMax;result[inheritedContextWindow] = true;}+ // A maximum-only report can be below a public/preset working default.+ // Tighten that default to this connection's capacity instead of discarding+ // the live maximum. Explicit user/force windows still own their semantics.+ if (currentLive?.contextWindowMax !== undefined && currentLive.contextWindow === undefined &&+ user?.contextWindow === undefined && matched?.route.forceOverrides?.contextWindow === undefined &&+ result.contextWindow !== undefined && result.contextWindow > currentLive.contextWindowMax) {+ result.contextWindow = currentLive.contextWindowMax;+ result[inheritedContextWindow] = true;+ }if (result.contextWindow !== undefined && result.contextWindowMax !== undefined &&result.contextWindowMax < result.contextWindow) {delete result.contextWindowMax;