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): include Pi in subscription model discovery and additions (#4838)

Chris Zhangb9c3609c3848
diff --git a/apps/desktop/src/main/maker-host/__tests__/activeCatalogDiscovery.test.ts b/apps/desktop/src/main/maker-host/__tests__/activeCatalogDiscovery.test.ts
index 803e605022..49543e5623 100644
--- a/apps/desktop/src/main/maker-host/__tests__/activeCatalogDiscovery.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/activeCatalogDiscovery.test.ts
@@ -25,6 +25,7 @@ import {
setDiscoveredCodexModels,
setXaiDiscoveredModels,
setDiscoveredProviderMediaModels,
+ setDiscoveredProviderModels,
clearDiscoveredProviderModels,
} from '../active-catalog.js';
@@ -246,12 +247,32 @@ describe('active-catalog discovered augment', () => {
expect(afterAuth.supportsImageInput).toBeUndefined();
});
- it('Codex discovery 只进入 Codex 与 Claude bridge,不改写 Pi 名单', () => {
+ it('adds newly discovered ChatGPT models to all three Harnesses', () => {
setActiveCatalog(BUNDLED_CATALOG);
setDiscoveredCodexModels([fake('gpt-5.7')]);
expect(openaiIds('codex')).toContain('gpt-5.7');
expect(openaiIds('claude-code')).toContain('chatgpt/gpt-5.7');
- expect(openaiIds('pi')).not.toContain('chatgpt/gpt-5.7');
+ expect(openaiIds('pi')).toContain('chatgpt/gpt-5.7');
+ });
+
+ it.each(['builtin', 'independent'] as const)('adds a discovered Claude model to the %s account Pi catalog', (kind) => {
+ const catalog = bundledWithoutRegistry();
+ const providerId = kind === 'builtin' ? 'anthropic' : 'claude-second';
+ if (kind === 'independent') {
+ catalog.providers.push(buildUserProvider({
+ id: providerId, name: 'Second Claude', auth: { method: 'oauth', native: 'claude' }, runtimes: {},
+ }));
+ }
+ setActiveCatalog(catalog);
+ const discovered = { ...fake('claude-new'), group: 'anthropic' };
+ if (kind === 'builtin') setAnthropicDiscoveredModels([discovered]);
+ else setDiscoveredProviderModels(providerId, 'claude-code', [discovered]);
+ expect(getActiveCatalog().providers.find(p => p.id === providerId)!.models.pi)
+ .toContainEqual(expect.objectContaining({ id: 'claude-new', piApi: 'anthropic-messages' }));
+ if (kind === 'independent') {
+ expect(getActiveCatalog().providers.find(p => p.id === 'anthropic')!.models.pi)
+ .not.toContainEqual(expect.objectContaining({ id: 'claude-new' }));
+ }
});
it('missing Pi declarations use fallback but explicit empty lists remove public Pi membership', () => {
@@ -264,6 +285,7 @@ describe('active-catalog discovered augment', () => {
const empty = bundledWithoutRegistry();
empty.providers.find((provider) => provider.id === 'openai')!.models.pi = [];
setActiveCatalog(empty, { authorityCatalog: empty });
+ setDiscoveredCodexModels([fake('gpt-new')]);
expect(openaiIds('pi')).toEqual([]);
});
@@ -341,19 +363,61 @@ describe('active-catalog discovered augment', () => {
});
});
- it('uses explicit SuperGrok capabilities while Pi retains its independent native facts', () => {
+ it('adds a newly discovered Grok model to Pi without a bundled model or public declaration', () => {
+ setActiveCatalog(BUNDLED_CATALOG);
+ setXaiDiscoveredModels([{
+ id: 'xai/grok-4.7', name: 'Grok 4.7', contextWindow: 500_000,
+ maxOutput: 64_000, efforts: ['xhigh', 'high', 'medium', 'low'], defaultEffort: 'high',
+ }]);
+ const models = () => getActiveCatalog().providers.find(p => p.id === 'xai')!.models.pi!;
+ expect(models().find(model => model.id === 'grok-4.7')).toMatchObject({
+ name: 'Grok 4.7', contextWindow: 500_000, maxOutput: 64_000,
+ efforts: ['low', 'medium', 'high', 'xhigh'], defaultEffort: 'high',
+ piApi: 'openai-responses',
+ });
+ setXaiDiscoveredModels(null);
+ expect(models().some(model => model.id === 'grok-4.7')).toBe(false);
+ });
+
+ it('keeps discovered Pi models scoped to their Grok account', () => {
+ const account = buildUserProvider({
+ id: 'grok-second', name: 'Second Grok', auth: { method: 'oauth', native: 'xai' }, runtimes: {},
+ });
+ setActiveCatalog({ ...BUNDLED_CATALOG, providers: [...BUNDLED_CATALOG.providers, account] });
+ setXaiDiscoveredModels([{ id: 'xai/grok-account-only' }], account.id);
+ const models = (id: string) => getActiveCatalog().providers.find(p => p.id === id)!.models.pi!;
+ expect(models(account.id).some(model => model.id === 'grok-account-only')).toBe(true);
+ expect(models('xai').some(model => model.id === 'grok-account-only')).toBe(false);
+ setXaiDiscoveredModels(null, account.id);
+ expect(models(account.id).some(model => model.id === 'grok-account-only')).toBe(false);
+ });
+
+ it('does not revive explicit empty or retired Pi declarations from account discovery', () => {
+ const catalog = bundledWithoutRegistry();
+ const xai = catalog.providers.find(p => p.id === 'xai')!;
+ xai.models.pi = [{ ...fake('grok-4.7'), status: 'retired', piApi: 'openai-responses' }];
+ setActiveCatalog(catalog, { authorityCatalog: catalog });
+ setXaiDiscoveredModels([{ id: 'xai/grok-4.7' }]);
+ expect(getActiveCatalog().providers.find(p => p.id === 'xai')!.models.pi![0]?.status).toBe('retired');
+ const empty = structuredClone(catalog);
+ empty.providers.find(p => p.id === 'xai')!.models.pi = [];
+ setActiveCatalog(empty, { authorityCatalog: empty });
+ expect(getActiveCatalog().providers.find(p => p.id === 'xai')!.models.pi).toEqual([]);
+ });
+
+ it('uses explicit SuperGrok capabilities across all three Harnesses', () => {
setActiveCatalog(BUNDLED_CATALOG);
setXaiDiscoveredModels([
{ id: 'xai/grok-4.6', efforts: ['low', 'medium', 'high'], defaultEffort: 'medium' },
]);
const xai = getActiveCatalog().providers.find((provider) => provider.id === 'xai');
- // 供应商显式列表覆盖默认;Pi 使用自己的原生能力来源。
+ // 同一账号的实报能力覆盖三个 Harness 的目录默认。
expect(xai?.models['claude-code']?.find((model) => model.id === 'xai/grok-4.6')).toMatchObject({
efforts: ['low', 'medium', 'high'],
defaultEffort: 'medium',
});
expect(xai?.models.pi?.find((model) => model.id === 'grok-4.6')).toMatchObject({
- efforts: ['low', 'medium', 'high', 'xhigh'],
+ efforts: ['low', 'medium', 'high'],
defaultEffort: 'medium',
});
});
@@ -370,11 +434,11 @@ describe('active-catalog discovered augment', () => {
defaultEffort: 'low',
});
expect(xai?.models.pi?.find((model) => model.id === 'grok-4.5')).toMatchObject({
- efforts: ['low', 'medium', 'high'],
- defaultEffort: 'medium',
+ efforts: ['low'],
+ defaultEffort: 'low',
});
expect(xai?.models.pi?.find((model) => model.id === 'grok-4.6')).toMatchObject({
- efforts: ['low', 'medium', 'high', 'xhigh'],
+ efforts: ['low', 'medium', 'high'],
defaultEffort: 'medium',
});
});
@@ -394,7 +458,7 @@ describe('active-catalog discovered augment', () => {
});
expect(xai?.models.pi?.find((model) => model.id === 'grok-4.5')).toMatchObject({
efforts: ['low', 'medium', 'high'],
- defaultEffort: 'medium',
+ defaultEffort: 'high',
});
});
@@ -411,10 +475,10 @@ describe('active-catalog discovered augment', () => {
});
expect(xai?.models.pi?.find((model) => model.id === 'grok-4.5')).toMatchObject({
efforts: ['low', 'medium', 'high'],
- defaultEffort: 'medium',
+ defaultEffort: 'low',
});
expect(xai?.models.pi?.find((model) => model.id === 'grok-4.6')).toMatchObject({
- efforts: ['low', 'medium', 'high', 'xhigh'],
+ efforts: ['low', 'medium', 'high'],
defaultEffort: 'medium',
});
});
@@ -526,7 +590,7 @@ describe('active-catalog discovered augment', () => {
setDiscoveredCodexModels([fake('gpt-5.7', 17), fake('gpt-5.5', 20)]);
expect(openaiIds('codex')).toEqual(['gpt-5.7', 'gpt-5.5']);
expect(openaiIds('claude-code')).toEqual(['chatgpt/gpt-5.7', 'chatgpt/gpt-5.5']);
- expect(openaiIds('pi')).toEqual(piBeforeDiscovery);
+ expect(openaiIds('pi')).toEqual([...piBeforeDiscovery, 'chatgpt/gpt-5.7']);
// 动态快照决定存在性,且明确返回的运行时能力高于 registry 基线。
const openai = getActiveCatalog().providers.find((p) => p.id === 'openai');
expect((openai?.models.codex ?? []).find((m) => m.id === 'gpt-5.5')?.contextWindow).toBe(
diff --git a/apps/desktop/src/main/maker-host/__tests__/modelPlane.test.ts b/apps/desktop/src/main/maker-host/__tests__/modelPlane.test.ts
index f995b48cac..2d13f98c36 100644
--- a/apps/desktop/src/main/maker-host/__tests__/modelPlane.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/modelPlane.test.ts
@@ -365,7 +365,7 @@ describe('registry presence 实体化', () => {
expect(getModelPlaneWarnings()).toEqual([]);
});
- it('没有 Registry entry 时 Codex discovery 也不会产生 Pi 条目', () => {
+ it('account discovery supplies a new Pi member without requiring a Registry entry', () => {
setActiveCatalog(baseCatalog());
setDiscoveredCodexModels([
{
@@ -377,7 +377,9 @@ describe('registry presence 实体化', () => {
},
]);
- expect(models('openai', 'pi').find((m) => m.id === 'chatgpt/gpt-discovered')).toBeUndefined();
+ expect(models('openai', 'pi').find((m) => m.id === 'chatgpt/gpt-discovered')).toMatchObject({
+ piApi: 'openai-responses', contextWindow: 272_000, efforts: ['high'],
+ });
});
it('status 缺失 = metadata-only,不长实体;retired = tombstone,不长实体', () => {
@@ -878,7 +880,7 @@ describe('本地 override(local 永远最高)', () => {
expect(entry?.group).toBeUndefined();
});
- it('本地 membership 可关闭/重开 bridge,但不会改变 Pi', () => {
+ it('explicit local membership limits Harnesses and omitted membership includes Pi', () => {
setActiveCatalog(
baseCatalog([
gpt6Entry({ routes: [{ providerId: 'openai', modelId: 'gpt-6', agents: ['codex'] }] }),
@@ -919,6 +921,48 @@ describe('本地 override(local 永远最高)', () => {
);
expect(models('openai', 'claude-code').map((m) => m.id)).toContain('chatgpt/gpt-6');
expect(models('openai', 'codex').find((m) => m.id === 'gpt-6')?.status).toBe('alpha');
+ expect(models('openai', 'pi').find((m) => m.id === 'chatgpt/gpt-6')?.status).toBe('alpha');
+ });
+
+ it.each([
+ ['openai', 'gpt-manual', 'chatgpt/gpt-manual', 'openai-responses'],
+ ['anthropic', 'claude-manual', 'claude-manual', 'anthropic-messages'],
+ ['xai', 'xai/grok-manual', 'grok-manual', 'openai-responses'],
+ ] as const)('accepts a Pi-only user addition for %s and retains it across refreshes', (providerId, inputId, piId, api) => {
+ setActiveCatalog(baseCatalog());
+ const raw = { additions: {
+ [`${providerId}:${inputId}`]: {
+ agents: ['pi'], base: { name: 'User model', contextWindow: 600_000, maxOutput: 12_345,
+ efforts: ['low', 'high'], defaultEffort: 'high', supportsImageInput: true },
+ perAgent: { pi: { contextWindow: 700_000 } },
+ },
+ } };
+ const parsed = sanitizeModelCatalogOverrides(raw);
+ expect(parsed.invalid).toEqual([]);
+ setLocalCatalogOverrides(parsed.overrides);
+ for (let refresh = 0; refresh < 2; refresh++) {
+ expect(models(providerId, 'pi').find(model => model.id === piId)).toMatchObject({
+ name: 'User model', piApi: api, contextWindow: 700_000, maxOutput: 12_345,
+ efforts: ['low', 'high'], defaultEffort: 'high', supportsImageInput: true,
+ });
+ expect(models(providerId, 'codex').some(model => model.id === inputId)).toBe(false);
+ setActiveCatalog(baseCatalog());
+ }
+ setLocalCatalogOverrides(EMPTY_MODEL_CATALOG_OVERRIDES);
+ expect(models(providerId, 'pi').some(model => model.id === piId)).toBe(false);
+ });
+
+ it('rejects Pi additions for Gateway and preserves older root-only partial additions', () => {
+ const base = { name: 'Local', contextWindow: 500_000 };
+ const parsed = sanitizeModelCatalogOverrides({ additions: {
+ 'xd:fake-model': { agents: ['pi'], base: { ...base, efforts: [], defaultEffort: null } },
+ 'openai:gpt-legacy': { base, perAgent: { codex: { efforts: ['high'], defaultEffort: 'high' } } },
+ } });
+ expect(parsed.invalid).toEqual(['additions:xd:fake-model']);
+ setLocalCatalogOverrides(parsed.overrides);
+ expect(models('openai', 'codex').some(model => model.id === 'gpt-legacy')).toBe(true);
+ expect(models('openai', 'pi').some(model => model.id === 'chatgpt/gpt-legacy')).toBe(false);
+ expect(models('xd', 'pi').some(model => model.id === 'fake-model')).toBe(false);
});
it('dormant patch:宿主不存在时静置,discovery 出现当日生效', () => {
@@ -1042,7 +1086,7 @@ it('preserves the upstream maximum separately from per-harness recommended windo
});
it.each([{ agents: undefined }, { agents: ['codex', 'pi'] }])(
- 'keeps Pi working defaults when a root addition declares agents $agents',
+ 'applies user working defaults to Pi when an addition declares agents $agents',
({ agents }) => {
const catalog = baseCatalog([gpt6Entry()]);
catalog.providers.find((provider) => provider.id === 'openai')!.models.pi = [
@@ -1072,8 +1116,8 @@ it.each([{ agents: undefined }, { agents: ['codex', 'pi'] }])(
contextWindow: 450_000,
});
expect(models('openai', 'pi').find((model) => model.id === 'chatgpt/gpt-6')).toMatchObject({
- name: 'Pi authority',
- contextWindow: 272_000,
+ name: 'Root addition',
+ contextWindow: 450_000,
contextWindowMax: 1_000_000,
});
setLocalCatalogOverrides(
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 5482479458..e084788524 100644
--- a/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.ts
@@ -46,7 +46,8 @@ import {
resolvePiCindyGatewayModelSpec,
type PiBundledModelInfo,
} from '../pi-host.js';
-import { getActiveCatalog, setActiveCatalog, setDiscoveredCodexModels, setXdGatewayModels } from '../active-catalog.js';
+import { getActiveCatalog, setActiveCatalog, setDiscoveredCodexModels, setXdGatewayModels, setXaiDiscoveredModels, setLocalCatalogOverrides } from '../active-catalog.js';
+import { EMPTY_MODEL_CATALOG_OVERRIDES, sanitizeModelCatalogOverrides } from '../model-plane/localCatalogOverrides.js';
import { deriveAvailableModels } from '../catalog-to-descriptors.js';
type Cfg = Parameters<typeof buildPiNativeProvidersFromConfigs>[0][number];
@@ -2554,6 +2555,42 @@ describe('buildPiNativeProvidersFromConfigs', () => {
describe('server metadata reaches every native Pi transport', () => {
+ it.each(['discovery', 'user-addition'] as const)('carries a new Grok model from %s into local and SSH Pi routes', async (source) => {
+ setActiveCatalog(BUNDLED_CATALOG);
+ const addition = {
+ id: 'xai/grok-4.7', name: 'Grok 4.7', contextWindow: 500_000,
+ maxOutput: 64_000, efforts: ['low', 'high', 'xhigh'] as const, defaultEffort: 'high' as const,
+ };
+ if (source === 'discovery') setXaiDiscoveredModels([{ ...addition, efforts: [...addition.efforts] }]);
+ else {
+ const { id, ...base } = addition;
+ const parsed = sanitizeModelCatalogOverrides({ additions: { [`xai:${id}`]: { agents: ['pi'], base } } });
+ expect(parsed.invalid).toEqual([]);
+ setLocalCatalogOverrides(parsed.overrides);
+ }
+ try {
+ const catalog = getActiveCatalog();
+ const result = buildPiSubscriptionNativeProviders(catalog, 'http://127.0.0.1:4567',
+ new Map([['xai', new Map()]]));
+ expect(result.providers.find(p => p.id === 'xai')!.models.find(m => m.id === 'grok-4.7'))
+ .toMatchObject({ wireId: 'grok-4.7', api: 'openai-responses',
+ contextWindow: 500_000, maxTokens: 64_000, reasoning: true,
+ thinkingLevelMap: { high: 'high', xhigh: 'xhigh', medium: null },
+ });
+ const remote = await buildXaiPiNativeProvider('xai/grok-4.7', false, true);
+ expect(remote.providers[0]?.models.find(m => m.id === 'xai/grok-4.7'))
+ .toMatchObject({ wireId: 'grok-4.7', api: 'openai-responses', reasoning: true,
+ contextWindow: 500_000, maxTokens: 64_000,
+ thinkingLevelMap: { high: 'high', xhigh: 'xhigh', medium: null },
+ });
+ expect(remote.providers[0]?.hostProxyForward).toBeDefined();
+ } finally {
+ setXaiDiscoveredModels(null);
+ setLocalCatalogOverrides(EMPTY_MODEL_CATALOG_OVERRIDES);
+ setActiveCatalog(BUNDLED_CATALOG);
+ }
+ });
+
it.each([
['openai', 'openai-codex', 'chatgpt/gpt-fixture', 'gpt-fixture', 'openai-responses', 'openai-codex-responses'],
['anthropic', 'anthropic', 'claude-fixture', 'claude-fixture', 'anthropic-messages', 'anthropic-messages'],
diff --git a/apps/desktop/src/main/maker-host/active-catalog.ts b/apps/desktop/src/main/maker-host/active-catalog.ts
index b8f847a52d..a9179396b4 100644
--- a/apps/desktop/src/main/maker-host/active-catalog.ts
+++ b/apps/desktop/src/main/maker-host/active-catalog.ts
@@ -80,6 +80,7 @@ import {
applyLocalConsumerOverrides,
hasLocalContextWindowOverride,
applyLocalOverridesToRoot,
+ localPiAdditionModels,
hasLocalAddition,
EMPTY_MODEL_CATALOG_OVERRIDES,
resolveLocalBridgeExclusions,
@@ -898,18 +899,19 @@ function applyLayeredConsumer(
function xaiCatalogModelById(
provider: Provider,
id: string,
- agent: RootAgentKind,
+ agent: AgentKind,
): CatalogModel | undefined {
const bundled = BUNDLED_CATALOG.providers.find((entry) => entry.id === 'xai');
+ const catalogId = agent === 'pi' ? normalizePiModelId('xai', id) : id;
return (
- provider.models[agent]?.find((model) => model.id === id) ??
- bundled?.models[agent]?.find((model) => model.id === id)
+ provider.models[agent]?.find((model) => model.id === catalogId) ??
+ bundled?.models[agent]?.find((model) => model.id === catalogId)
);
}
function materializeXaiAccountModels(
provider: Provider,
- agent: RootAgentKind,
+ agent: AgentKind,
discovered: readonly XaiDiscoveredModel[],
): CatalogModel[] {
return discovered.map((entry, index) => {
@@ -986,18 +988,18 @@ function normalizePiModelId(providerId: string, modelId: string): string {
}
/**
- * An explicit per-Harness declaration owns membership, including an empty list.
- * Old snapshots without this field use the bundled declaration. Native runtime
- * catalogs supply transport compatibility, never a second public membership list.
+ * Public Pi declarations seed membership; account discovery can add new models.
+ * Explicit empty declarations disable the runtime. Missing fields use the bundled
+ * declaration, while native SDK capabilities remain independent of sibling Harnesses.
*/
-function declaredPiModels(providerId: string): CatalogModel[] {
+function declaredPiModels(providerId: string, discovered: readonly CatalogModel[] = []): CatalogModel[] {
const bundled =
BUNDLED_CATALOG.providers.find((provider) => provider.id === providerId)?.models.pi ?? [];
const explicit = (piGatewayAuthorityCatalog ?? base)?.providers.find(
(provider) => provider.id === providerId,
)?.models.pi;
const fallbackById = new Map(bundled.map((model) => [normalizePiModelId(providerId, model.id), model]));
- return (explicit ?? bundled).map((model) => {
+ const declared = (explicit ?? bundled).map((model) => {
const id = normalizePiModelId(providerId, model.id);
return {
...fallbackById.get(id), ...model, id,
@@ -1008,6 +1010,27 @@ function declaredPiModels(providerId: string): CatalogModel[] {
} : {}),
};
});
+ // An explicitly disabled Pi runtime stays disabled. Otherwise subscription
+ // discovery provides new account members independently of the SDK's model list.
+ if (explicit?.length === 0 || discovered.length === 0) return declared;
+ const piApi = providerId === 'openai' ? 'openai-responses' as const
+ : providerId === 'anthropic' ? 'anthropic-messages' as const : undefined;
+ if (!piApi) return declared;
+ const byId = new Map(declared.map(model => [model.id, model]));
+ for (const model of discovered) {
+ const id = normalizePiModelId(providerId, model.id);
+ // Codex/Claude SDK limits describe those Harnesses, not Pi. Discovery adds
+ // membership but cannot overwrite an existing Pi model's transport/capabilities.
+ if (byId.has(id)) continue;
+ if (model.status === 'retired' || findModelRegistryRoute(
+ (base ?? BUNDLED_CATALOG).modelRegistry, providerId, model.id,
+ )?.entry.status === 'retired') continue;
+ byId.set(id, {
+ ...model, id, piApi,
+ discoveredMetadata: model.discoveredMetadata ?? catalogModelMetadata(model),
+ });
+ }
+ return [...byId.values()];
}
function projectXdGatewayMediaModels(
@@ -1127,7 +1150,7 @@ function computeMerged(): Catalog {
);
if (normalized.some((p, index) => p !== providers[index])) providers = normalized;
- // 规范 discovery 只进入 Codex root;Claude bridge 从最终 root 重算,Pi 另读自己的目录。
+ // Codex root 消费其发现快照;Pi 后续独立补新型号,不继承 Codex 专属能力。
const withCodexDiscovery = providers.map((p) =>
p.id === 'openai' ? augmentModels(p, 'codex', discoveredCodex, true) : p,
);
@@ -1256,7 +1279,8 @@ function computeMerged(): Catalog {
'claude-code',
projected.models['claude-code'] ?? [],
),
- pi: declaredPiModels('openai'),
+ pi: declaredPiModels('openai', p.id === 'openai'
+ ? discoveredCodex : discoveredByProvider.get(p.id)?.codex ?? []),
},
};
}
@@ -1273,7 +1297,7 @@ function computeMerged(): Catalog {
localOverrides,
'anthropic',
);
- // codex bridge 受 membership 门控且 fast=false(硬约束);Pi 不镜像 Claude root。
+ // Codex bridge 受 membership 门控且 fast=false;Pi 只用原始发现补新型号。
const codexBridge = root
.filter((m) => !excluded.has(m.id))
.map((model) =>
@@ -1294,7 +1318,8 @@ function computeMerged(): Catalog {
...p.models,
'claude-code': root,
codex: codexBridge,
- pi: declaredPiModels('anthropic'),
+ pi: declaredPiModels('anthropic', p.id === 'anthropic'
+ ? anthropicModels : discoveredByProvider.get(p.id)?.['claude-code'] ?? []),
},
};
}
@@ -1330,7 +1355,30 @@ function computeMerged(): Catalog {
delete rest.piApi;
return rest;
};
- const piModels = declaredPiModels('xai');
+ const declaredPi = declaredPiModels('xai');
+ const piWireProtocol = (p.routing.pi ?? bundledXai?.routing.pi)?.wireProtocol;
+ // Discovery is account evidence shared by all Harnesses. Pi's packaged model list
+ // only supplies defaults; new account models can use the declared subscription
+ // transport without waiting for a new Pi binary or a public catalog release.
+ // Keep an explicit empty public declaration disabled and preserve retired entries.
+ const discoveredPi = declaredPi.length > 0 &&
+ (piWireProtocol === 'openai-responses' || piWireProtocol === 'openai-chat')
+ ? materializeXaiAccountModels(
+ { ...p, models: { ...p.models, pi: declaredPi } }, 'pi', accountModels,
+ ).map((model) => ({
+ ...model,
+ id: normalizePiModelId('xai', model.id),
+ piApi: model.piApi ?? (piWireProtocol === 'openai-chat'
+ ? 'openai-completions' as const : 'openai-responses' as const),
+ }))
+ : [];
+ const discoveredPiById = new Map(discoveredPi.map((model) => [model.id, model]));
+ const declaredPiIds = new Set(declaredPi.map((model) => model.id));
+ const piModels = [
+ ...declaredPi.map((model) => model.status === 'retired'
+ ? model : discoveredPiById.get(model.id) ?? model),
+ ...discoveredPi.filter((model) => !declaredPiIds.has(model.id)),
+ ];
return {
...p,
agents: p.agents.includes('pi') ? p.agents : [...p.agents, 'pi' as AgentKind],
@@ -1689,6 +1737,32 @@ function computeMerged(): Catalog {
]),
),
}));
+ // User additions are the highest layer and may explicitly revive a subscription
+ // model. They reuse that connection's transport, never create Gateway/BYOM routes.
+ providers = providers.map(provider => {
+ const catalogId = providerCatalogId(provider);
+ if ((provider.source === 'user' && !provider.auth.native) || !provider.routing.pi) return provider;
+ const additions = localPiAdditionModels(provider.id, localOverrides, catalogId);
+ if (additions.length === 0) return provider;
+ const models = new Map((provider.models.pi ?? []).map(model => [model.id, model]));
+ for (const addition of additions) {
+ const id = normalizePiModelId(catalogId, addition.id);
+ const existing = models.get(id);
+ const wire = provider.routing.pi.wireProtocol;
+ const piApi = existing?.piApi ?? (catalogId === 'openai' ? 'openai-responses'
+ : wire === 'openai-chat' ? 'openai-completions' : wire);
+ if (!isPiModelApi(piApi)) continue;
+ const model: CatalogModel = {
+ ...applyExistingModelLocalPatch(provider.id, 'pi', addition, localOverrides),
+ id, piApi,
+ ...(existing ? { contextWindowMax: Math.max(
+ existing.contextWindowMax ?? existing.contextWindow, addition.contextWindow,
+ ) } : {}),
+ };
+ models.set(id, applyExistingModelLocalPatch(provider.id, 'pi', model, localOverrides));
+ }
+ return { ...provider, models: { ...provider.models, pi: [...models.values()] } };
+ });
const modelRegistry = b.modelRegistry
? { ...b.modelRegistry, localModels: effectiveLocalModels }
: undefined;
diff --git a/apps/desktop/src/main/maker-host/model-plane/localCatalogOverrides.ts b/apps/desktop/src/main/maker-host/model-plane/localCatalogOverrides.ts
index 5238023031..57de1031ed 100644
--- a/apps/desktop/src/main/maker-host/model-plane/localCatalogOverrides.ts
+++ b/apps/desktop/src/main/maker-host/model-plane/localCatalogOverrides.ts
@@ -20,7 +20,7 @@ import {
* - RoutingDescriptor / auth / upstream → 永不属于任何 override 面。
*
* 形状(v1):key = `${encodeURIComponent(providerId)}:${modelId}`(**不含 agent**),一条记录经
- * base + perAgent(claude-code/codex) 表达跨 root 差异 —— 修 xAI Codex 专属
+ * base + perAgent(claude-code/codex/pi) 表达跨引擎差异 —— 修 xAI Codex 专属
* 思考档 = 一条 { perAgent: { codex: { efforts } } } patch,不用双写。
* - additions:完整新实体(base+perAgent 合成后须能力自洽),同 key 整条
* 压过 remote/discovery(不做字段混合),且**显式复活**远端 retired;
@@ -86,7 +86,7 @@ export type ModelCatalogPerAgentOverrideFields = Pick<
>;
export interface ModelCatalogOverrideEntry {
- /** 消费 membership;缺省 = provider policy 的全部 root + wire bridge,且必须含至少一个 root。 */
+ /** 消费 membership;缺省 = provider policy 的全部 root + wire bridge + 能力完整的 Pi;允许仅指定 Pi。 */
agents?: AgentKind[];
base?: ModelCatalogOverrideFields;
perAgent?: Partial<Record<AgentKind, ModelCatalogPerAgentOverrideFields>>;
@@ -245,7 +245,7 @@ function sanitizeEntry(raw: unknown): ModelCatalogOverrideEntry | null {
new Set(v).size !== v.length
)
return null;
- out.agents = v as RootAgentKind[];
+ out.agents = v as AgentKind[];
} else if (k === 'base') {
const fields = sanitizeFields(v);
if (!fields) return null;
@@ -264,7 +264,7 @@ function sanitizeEntry(raw: unknown): ModelCatalogOverrideEntry | null {
return null;
}
}
- const perAgentKeys = Object.keys(out.perAgent ?? {}) as RootAgentKind[];
+ const perAgentKeys = Object.keys(out.perAgent ?? {}) as AgentKind[];
if (out.agents && perAgentKeys.some((agent) => !out.agents!.includes(agent))) return null;
if (out.agents === undefined && out.base === undefined && perAgentKeys.length === 0) return null;
return out;
@@ -282,7 +282,7 @@ function effectiveFields(
function additionModelFor(
modelId: string,
entry: ModelCatalogOverrideEntry,
- agent: RootAgentKind,
+ agent: AgentKind,
): CatalogModel | null {
const f = effectiveFields(entry, agent);
if (!f.name || f.contextWindow === undefined || f.efforts === undefined) return null;
@@ -362,7 +362,7 @@ export function sanitizeModelCatalogOverrides(raw: unknown): SanitizeResult {
invalid.push(`${section}:${key}`);
continue;
}
- let agents = entryRootAgents(entry, parsed.providerId);
+ let agents: AgentKind[] = entryRootAgents(entry, parsed.providerId);
// Independent connections may not exist when this file is read. Retain complete
// dormant additions; only the actual connection's root policy can materialize them.
// Known non-root providers (e.g. the Gateway) remain forbidden.
@@ -373,6 +373,11 @@ export function sanitizeModelCatalogOverrides(raw: unknown): SanitizeResult {
additionModelFor(parsed.modelId, entry, agent) !== null,
);
}
+ if (section === 'additions' &&
+ (MODEL_PLANE_POLICIES.has(parsed.providerId) || !BUILTIN_PROVIDERS.some(p => p.id === parsed.providerId)) &&
+ (entry.agents?.includes('pi') || (!entry.agents && additionModelFor(parsed.modelId, entry, 'pi')))) {
+ agents.push('pi');
+ }
if (section === 'additions' && agents.length === 0) {
invalid.push(`${section}:${key}`);
continue;
@@ -596,15 +601,28 @@ export function hasLocalContextWindowOverride(
return (
entry &&
(agent === 'pi'
- // Pi has an independent catalog: only existing-model patches apply to it.
- // Additions materialize provider roots, even when their membership lists Pi.
- ? section === 'patches' && (!entry.agents || entry.agents.includes('pi'))
+ ? (!entry.agents || entry.agents.includes('pi'))
: entryMembershipAgents(entry, policyProviderId).includes(agent)) &&
effectiveFields(entry, agent).contextWindow !== undefined
);
});
}
+/** Complete user additions may use an existing subscription's Pi transport. */
+export function localPiAdditionModels(
+ providerId: string,
+ overrides: ModelCatalogOverrides,
+ policyProviderId = providerId,
+): CatalogModel[] {
+ if (!MODEL_PLANE_POLICIES.has(policyProviderId)) return [];
+ return Object.entries(overrides.additions).flatMap(([key, entry]) => {
+ const parsed = parseKey(key);
+ if (!parsed || parsed.providerId !== providerId || (entry.agents && !entry.agents.includes('pi'))) return [];
+ const model = additionModelFor(parsed.modelId, entry, 'pi');
+ return model ? [model] : [];
+ });
+}
+
/** User patches affect existing members only, including XD, custom providers and Pi. */
export function applyExistingModelLocalPatch(
providerId: string,
@@ -614,7 +632,11 @@ export function applyExistingModelLocalPatch(
): CatalogModel {
const patch = overrides.patches[`${encodeURIComponent(providerId)}:${model.id}`];
if (!patch || (patch.agents && !patch.agents.includes(agent))) return model;
- const result = overlayFields(model, { ...patch.base, ...patch.perAgent?.[agent] });
+ const fields = { ...patch.base, ...patch.perAgent?.[agent] };
+ const source = agent === 'pi' && fields.contextWindow !== undefined
+ ? { ...model, contextWindowMax: model.contextWindowMax ?? model.contextWindow }
+ : model;
+ const result = overlayFields(source, fields);
return typeof result === 'string'
? model
: model.status === 'retired'
diff --git a/apps/desktop/src/main/maker-host/pi-host.ts b/apps/desktop/src/main/maker-host/pi-host.ts
index 58bc91a3f5..0a3a11fdd5 100644
--- a/apps/desktop/src/main/maker-host/pi-host.ts
+++ b/apps/desktop/src/main/maker-host/pi-host.ts
@@ -1507,27 +1507,14 @@ export async function buildXaiPiNativeProvider(
): Promise<PiNativeProvidersResult> {
const catalogModels =
getActiveCatalog().providers.find((provider) => provider.id === providerId)?.models.pi ?? [];
- const officialById = new Map(
- (officialPiModels('xai') ?? []).map((candidate) => [candidate.id, candidate]),
- );
- const models = catalogModels.map((catalogModel) => ({
- ...(officialById.get(catalogModel.id) ??
- configuredPiModel({
- id: catalogModel.id,
- name: catalogModel.name,
- supportsImageInput:
- catalogModel.supportsImageInput === true ||
- catalogModel.modalities?.input.includes('image') === true,
- reasoning: catalogModel.efforts.length > 0,
- reasoningEfforts: catalogModel.efforts.filter(
- (effort): effort is PiReasoningEffort => effort !== 'ultra',
- ),
- })),
- id: `xai/${catalogModel.id}`,
- wireId: catalogModel.id,
- // Keep the exact API from Pi's catalog. The host forwarder authenticates and forwards both
- // native shapes without sending the request through the Claude Messages bridge.
- api: catalogModel.piApi ?? officialById.get(catalogModel.id)?.api ?? 'openai-responses',
+ // Reuse the subscription projection so SSH and local xAI receive identical
+ // capacity, reasoning and input metadata, including newly discovered models.
+ const projected = buildPiSubscriptionNativeProviders(getActiveCatalog(), getClaudeEndpoint())
+ .providers.find(provider => provider.sourceProviderId === providerId);
+ const models: PiNativeModelSpec[] = (projected?.models ?? []).map(model => ({
+ ...model,
+ id: `xai/${model.wireId ?? model.id}`,
+ wireId: model.wireId ?? model.id,
}));
const aliases = Object.fromEntries(
catalogModels.flatMap((candidate) => [
diff --git a/docs/dev-rules/model-catalog-maintenance.md b/docs/dev-rules/model-catalog-maintenance.md
index 46fc5fe75b..238113c0a8 100644
--- a/docs/dev-rules/model-catalog-maintenance.md
+++ b/docs/dev-rules/model-catalog-maintenance.md
@@ -41,7 +41,7 @@ Catalog (version)
| 接入条目状态、排序、默认开启标记 | Registry `models[]` 顶层 | 显示开关不等于成员资格;见下文默认可见性 |
| 某供应商的上游 ID、支持路由、普通默认 | `models[].routes[]` / `routes[].defaults` | 普通默认不能压过实报 |
| Claude Code / Codex 的工作默认 | `models[].perAgent`,引擎必须被该条目 route 声明 | 不把工作预算当供应商承诺容量 |
-| Pi 公共成员和 Pi 默认资料 | `providers[].models.pi`;公共资料仍按 Registry 合并 | 不从其他引擎名单复制出 Pi 路由 |
+| Pi 公共成员和 Pi 默认资料 | `providers[].models.pi`;订阅账号发现另补新型号,公共资料仍按 Registry 合并 | 复用已实现的订阅传输,不复制其他引擎的专属能力 |
| 经核实的错误实报 | 匹配 route 的 `forceOverrides` + `overrideReason` | 不影响其他供应商,也不压过用户配置 |
| 厂商官方参考价及历史价区间 | `baseModels[].referencePriceGroups[].prices[]`(Registry V5) | 按市场分组,保留币种、标准/Fast、输入区间及生效日期 |
| 接入供应商参考报价 | `routes[].referencePrices[]`;`referencePriceGroup` 指向公共型号的官方价组 | Gateway 实价/折扣仍归其计费控制面,不混填缺失字段 |
diff --git a/docs/product-rules/model-metadata-precedence.md b/docs/product-rules/model-metadata-precedence.md
index 3f3eacdcad..352e43a545 100644
--- a/docs/product-rules/model-metadata-precedence.md
+++ b/docs/product-rules/model-metadata-precedence.md
@@ -54,8 +54,11 @@ OpenAI 本机 Codex 登录与独立授权账号共享 OpenAI 公共目录及桥
现有协议保留两种兼容表示:Codex/Claude Code 的 Registry 根与桥接声明,及
`providers[].models.pi` 的逐 Harness 声明。旧 Registry 的 agents 枚举不能直接加入 Pi;
顶层 Codex/Claude Code 空数组仍由 Registry 实体化,不能解释成关闭。
-Pi 显式列表决定成员(包括空数组与撤下条目);缺字段才使用随包兜底,不把其他 Harness
-的名单复制成 Pi 路由。服务器声明的新模型不要求先出现在 Pi SDK 名单中;有明确原生协议
+Pi 显式列表提供公共成员(包括空数组与退役条目);缺字段才使用随包兜底。订阅账号
+发现的新型号同样进入 Pi,沿已有订阅传输执行,不要求先登记到 Pi SDK。显式空 Pi 列表
+仍关闭该公共入口,退役条目不由发现复活。Codex/Claude SDK 的发现只补 Pi 缺少的型号,
+不覆盖已有 Pi 型号的原生能力;SuperGrok 账号实报能力供三个 Harness 共用,按连接隔离。
+服务器声明的新模型不要求先出现在 Pi SDK 名单中;有明确原生协议
即可构造 models.json。OpenAI 订阅仍使用专用 Codex Responses 认证传输。
旧顶层 Pi 条目的静态资料是旧格式兜底,不能标为账号 discovery;
@@ -93,8 +96,8 @@ Pi 已识别的 OpenAI 订阅连接之间可复用同一运行时:每个账号
| --- | --- | --- |
| OpenAI / Anthropic 订阅的 Registry 根与发现补全 | 按对应静态/Registry 路径保留存在性,连接态另判 | 发现未返回不单独构成否定;不能用顶层 Codex/Claude 空数组禁用 Registry 实体化条目 |
| 通用 OAuth additions-only、自定义连接刷新 | 保留已有配置 | 只新增/更新,不因本次未返回而删除已有成员 |
-| xAI 订阅账号权威发现 | null 表示尚无成功账号快照,走既有静态兼容路径 | 成功空数组也是账号成员快照;不能套 additions-only 规则。Pi 公共名单仍单独声明 |
-| `providers[].models.pi` | 字段缺失才使用随包声明 | 显式 [] 不回填,撤下项不从其他引擎复制回来 |
+| xAI 订阅账号权威发现 | null 表示尚无成功账号快照,走既有静态兼容路径 | 成功空数组也是账号成员快照;不能套 additions-only 规则。Pi 同时使用该账号发现及公共声明 |
+| `providers[].models.pi` | 字段缺失才使用随包声明 | 显式 [] 不回填;非空声明允许账号发现补新型号,退役项不复活 |
| 内置非 Gateway 的媒体数组 | 字段缺失、允许 Registry 派生时才由媒体 routes 补成员 | 显式 [] 不由 Registry 或发现结果复活;非空列表不由 Registry 增补成员,后续账号发现按下一行处理 |
| 已接入的图片/视频账号发现 | 没有发现快照时用静态/远端声明 | 成功快照限定该发现路径的成员,不能绕过目录显式禁用;不推广为全部音频或自定义刷新规则 |
| Gateway 实时 `/models` | 未取得权威响应时保留未知/回退证据标记,不凭缺席下结论 | 成功清单拥有实时成员、可用性和实价;Registry 不增加 Gateway 成员 |
@@ -126,7 +129,7 @@ Pi 已识别的 OpenAI 订阅连接之间可复用同一运行时:每个账号
}
```
-`baseModels` 是按公共 ID 的稀疏补丁;`patches` 支持已有订阅、Cindy AI、自定义供应商模型及 Pi。补丁不能凭空增加账号可用模型,尚未出现的条目静置。原有 `additions` 仍只适用于允许实体化的订阅根,不开放 Gateway 伪造。退役条目仍需完整合法 addition 才能复活。
+`baseModels` 是按公共 ID 的稀疏补丁;`patches` 支持已有订阅、Cindy AI、自定义供应商模型及 Pi。补丁不能凭空增加账号可用模型,尚未出现的条目静置。`additions` 适用于已实现传输的订阅连接,包括 Pi;显式 `agents: ["pi"]` 只新增 Pi 型号,未指定 agents 时完整公共配置也用于 Pi。旧的仅根引擎字段完整的配置仍按原方式加载。新增沿连接原有协议和凭证执行,不开放 Gateway 伪造,也不改用户自定义供应商的配置方式。退役条目仍需完整合法 addition 才能复活。
键中的供应商段使用 `encodeURIComponent` 编码,模型段保持原文。例如旧自定义 xAI 的运行时 ID 是 `custom:xai`,对应键为 `custom%3Axai:grok-model`;`xai:grok-model` 仍指内置 xAI,`custom:xai:grok-model` 仍指供应商 `custom` 的模型 `xai:grok-model`,三者不混用。