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。

feat(desktop): 辅助模型钉档开放 pi runtime 路由

ZhangYunjind13ec6f76ed1
diff --git a/apps/desktop/src/main/maker-ipc/auxiliary-model-settings.ts b/apps/desktop/src/main/maker-ipc/auxiliary-model-settings.ts
index 398819b7bb..79a9b38d5b 100644
--- a/apps/desktop/src/main/maker-ipc/auxiliary-model-settings.ts
+++ b/apps/desktop/src/main/maker-ipc/auxiliary-model-settings.ts
@@ -124,7 +124,7 @@ export function buildAuxiliaryModelOptions(args: {
if (!decoded) continue;
result.push({
id: pin,
- label: `${decoded.agentKind === 'codex' ? 'Codex' : 'Claude Code'} · ${decoded.model} · ${decoded.providerId}`,
+ label: `${decoded.agentKind === 'codex' ? 'Codex' : decoded.agentKind === 'pi' ? 'Pi' : 'Claude Code'} · ${decoded.model} · ${decoded.providerId}`,
group: decoded.providerId,
providerId: decoded.providerId,
agentKind: decoded.agentKind,
@@ -132,7 +132,7 @@ export function buildAuxiliaryModelOptions(args: {
modelName: decoded.model,
budget: false,
subscription: false,
- agentSuffix: decoded.agentKind === 'codex' ? 'Codex' : 'Claude Code',
+ agentSuffix: decoded.agentKind === 'codex' ? 'Codex' : decoded.agentKind === 'pi' ? 'Pi' : 'Claude Code',
available: false,
});
}
diff --git a/apps/desktop/src/main/utility-model/__tests__/textOneshotPinOptions.test.ts b/apps/desktop/src/main/utility-model/__tests__/textOneshotPinOptions.test.ts
index ea63f56c4a..a0e1554838 100644
--- a/apps/desktop/src/main/utility-model/__tests__/textOneshotPinOptions.test.ts
+++ b/apps/desktop/src/main/utility-model/__tests__/textOneshotPinOptions.test.ts
@@ -42,6 +42,16 @@ describe('encodeCatalogPin / decodeCatalogPin', () => {
agentKind: 'codex',
model: 'codex/gpt-5.5',
});
+ expect(decodeCatalogPin(encodeCatalogPin('custom-1', 'claude-code', 'qwen3:8b'))).toEqual({
+ providerId: 'custom-1',
+ agentKind: 'claude-code',
+ model: 'qwen3:8b',
+ });
+ expect(decodeCatalogPin(encodeCatalogPin('opencode-go', 'pi', 'step-5-preview-free'))).toEqual({
+ providerId: 'opencode-go',
+ agentKind: 'pi',
+ model: 'step-5-preview-free',
+ });
expect(decodeCatalogPin('cat:custom-1:claude-code:qwen3:8b')).toEqual({
providerId: 'custom-1',
agentKind: 'claude-code',
@@ -68,8 +78,8 @@ describe('encodeCatalogPin / decodeCatalogPin', () => {
'cat:xd:codex',
'cat::codex:m',
'cat:xd::m',
- 'cat:xd:pi:m',
'cat:xd:codex:',
+ 'cat:xd:unknown-agent:m',
]) {
expect(decodeCatalogPin(bad), bad).toBeNull();
}
@@ -194,24 +204,30 @@ describe('buildTextOneshotPinOptions', () => {
]);
});
- it('pi-only 供应商与缺 routing 的 agent 不进清单', () => {
+ it('pi 档:缺 routing 不进清单;声明完整的 pi runtime 与 codex 同待遇', () => {
const options = buildTextOneshotPinOptions(
catalogOf(
provider({ id: 'pi-prov', agents: ['pi'], models: { pi: [chat('pi-m')] as never } }),
provider({
- id: 'half',
+ id: 'pi-full',
source: 'user',
- agents: ['codex', 'claude-code'],
- routing: { codex: { upstream: 'https://up.example.com', authStrategy: 'api-key-header' } },
- models: {
- codex: [chat('gpt-m-codex', { group: 'custom:half' })],
- 'claude-code': [chat('m-cc', { group: 'custom:half' })],
- },
+ agents: ['pi'],
+ routing: { pi: { upstream: 'https://up.example.com/v1', authStrategy: 'api-key-header', wireProtocol: 'openai-chat' } },
+ models: { pi: [chat('pi-m', { group: 'custom:pi-full' })] },
+ }),
+ provider({
+ id: 'pi-anthropic',
+ source: 'user',
+ agents: ['pi'],
+ routing: { pi: { upstream: 'https://up.example.com', authStrategy: 'api-key-header', wireProtocol: 'anthropic-messages' } },
+ models: { pi: [chat('pi-m2', { group: 'custom:pi-anthropic' })] },
}),
),
undefined,
);
- expect(options.map((o) => o.id)).toEqual(['cat:half:codex:gpt-m-codex']);
+ expect(options.map((o) => [o.id, o.agentSuffix])).toEqual([
+ ['cat:pi-full:pi:pi-m', 'Pi'],
+ ]);
});
it('自定义供应商:routing 禁用 / 鉴权策略不支持 / 缺上游 → 排除;结构完整 → 收', () => {
@@ -250,9 +266,9 @@ describe('buildTextOneshotPinOptions', () => {
});
it('自定义供应商 wire 与执行侧出线不一致的组合不进清单', () => {
- // 执行侧:claude-code 恒发 anthropic-messages;codex 发不出 anthropic-messages
- // (会被静默当 responses)。配置错线的组合钉上恒失败,清单提前过滤。
- const custom = (id: string, agentKind: 'codex' | 'claude-code', wireProtocol?: string) =>
+ // 执行侧:claude-code 恒发 anthropic-messages;codex 与 pi 发不出
+ // anthropic-messages(会被静默当 responses)。配置错线的组合钉上恒失败,清单提前过滤。
+ const custom = (id: string, agentKind: 'codex' | 'claude-code' | 'pi', wireProtocol?: string) =>
provider({
id,
source: 'user',
@@ -273,6 +289,9 @@ describe('buildTextOneshotPinOptions', () => {
custom('cx-chat', 'codex', 'openai-chat'),
custom('cx-anthropic', 'codex', 'anthropic-messages'),
custom('cx-default', 'codex'),
+ custom('pi-chat', 'pi', 'openai-chat'),
+ custom('pi-anthropic', 'pi', 'anthropic-messages'),
+ custom('pi-default', 'pi'),
),
undefined,
);
@@ -280,6 +299,8 @@ describe('buildTextOneshotPinOptions', () => {
'cat:cc-anthropic:claude-code:m',
'cat:cx-chat:codex:m',
'cat:cx-default:codex:m',
+ 'cat:pi-chat:pi:m',
+ 'cat:pi-default:pi:m',
]);
});
diff --git a/apps/desktop/src/main/utility-model/resolveAuxiliaryModelChain.ts b/apps/desktop/src/main/utility-model/resolveAuxiliaryModelChain.ts
index acda1e2ab1..940222c55f 100644
--- a/apps/desktop/src/main/utility-model/resolveAuxiliaryModelChain.ts
+++ b/apps/desktop/src/main/utility-model/resolveAuxiliaryModelChain.ts
@@ -139,7 +139,9 @@ export function formatAuxiliaryModelRefLabel(ref: string): string {
if (parsed.route.providerId === 'xd') {
return `${parsed.route.model} · Cindy AI`;
}
- const agent = parsed.route.agentKind === 'claude-code' ? 'Claude' : 'Codex';
+ const agent = parsed.route.agentKind === 'claude-code'
+ ? 'Claude'
+ : parsed.route.agentKind === 'pi' ? 'Pi' : 'Codex';
const provider = parsed.route.providerId === 'anthropic' || parsed.route.providerId === 'openai'
? agent
: parsed.route.providerId;
diff --git a/apps/desktop/src/main/utility-model/textOneshotPinOptions.ts b/apps/desktop/src/main/utility-model/textOneshotPinOptions.ts
index a00992f9cf..5eff879ccb 100644
--- a/apps/desktop/src/main/utility-model/textOneshotPinOptions.ts
+++ b/apps/desktop/src/main/utility-model/textOneshotPinOptions.ts
@@ -33,8 +33,12 @@ import {
encodeCatalogModelPin,
} from '../../shared/catalogModelPin.js';
-/** oneshot 可路由的 agent(Pi 的 oneShot 未实现,不进钉档清单)。 */
-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。
+ */
+const ONESHOT_ROUTE_AGENTS = ['codex', 'claude-code', 'pi'] as const;
/**
* 执行侧(requestBuiltinProviderText)可执行的内置供应商。清单侧必须按同一集合过滤——
@@ -56,7 +60,7 @@ export type OneshotRoute = {
/** 目录钉编码:cat:<providerId>:<agentKind>:<modelId>(modelId 可含 '/' 与 ':')。 */
export function encodeCatalogPin(providerId: string, agentKind: AgentKind, model: string): string {
- if (agentKind !== 'codex' && agentKind !== 'claude-code') {
+ if (agentKind !== 'codex' && agentKind !== 'claude-code' && agentKind !== 'pi') {
throw new Error(`unsupported catalog pin agent: ${agentKind}`);
}
return encodeCatalogModelPin({ providerId, agentKind, model });
@@ -74,7 +78,7 @@ export function decodeCatalogPin(
* requestUtilityText 显式路径的静态闸:内置供应商只收执行侧硬编码认的
* 四家(见 ONESHOT_EXECUTABLE_BUILTIN_PROVIDERS);自定义供应商要求 routing
* 未禁用 + 鉴权策略受支持 + 有上游地址 + 声明的 wire 与执行侧该 agent 的
- * 实际出线一致(claude-code 恒发 anthropic-messages;codex 发不出
+ * 实际出线一致(claude-code 恒发 anthropic-messages;codex 与 pi 发不出
* anthropic-messages,会被静默当 responses——配置错线的组合钉上恒失败,
* 不进清单)。
*/
@@ -108,6 +112,7 @@ function isChatModel(model: CatalogModel, provider: Provider): boolean {
const AGENT_LABEL: Record<(typeof ONESHOT_ROUTE_AGENTS)[number], string> = {
codex: 'Codex',
'claude-code': 'Claude Code',
+ pi: 'Pi',
};
/**
@@ -148,7 +153,7 @@ export interface TextOneshotPinOption {
subscription: boolean;
/** 供应商路由描述(渲染层厂牌图标判定用,ProviderLogoMark)。 */
routing?: Provider['routing'];
- /** 该精确路由使用的 Agent('Codex' / 'Claude Code')。 */
+ /** 该精确路由使用的 Agent('Codex' / 'Claude Code' / 'Pi')。 */
agentSuffix: string;
}
@@ -238,7 +243,8 @@ export function buildTextOneshotPinOptions(
/**
* 插件声明的偏好模型 id → 可路由的目录条目。供应商序同钉档清单(用户显式
* 排序优先,缺省 xd 在首),agent 序 codex 先于 claude-code(与
- * inferProviderAgent 同偏好);停用/不可路由/非对话模型跳过。
+ * inferProviderAgent 同偏好),pi 在末(pi 档是路由别名,让位给主 agent);
+ * 停用/不可路由/非对话模型跳过。
* 找不到返回 null = 按未声明处理(回落系统默认链)。
*/
export function resolveOneshotCatalogModel(
diff --git a/apps/desktop/src/shared/auxiliaryModelSettings.ts b/apps/desktop/src/shared/auxiliaryModelSettings.ts
index 3517829cf8..1dc8f9f985 100644
--- a/apps/desktop/src/shared/auxiliaryModelSettings.ts
+++ b/apps/desktop/src/shared/auxiliaryModelSettings.ts
@@ -31,7 +31,7 @@ export interface AuxiliaryModelOption {
label: string;
group: string;
providerId: string;
- agentKind: 'codex' | 'claude-code';
+ agentKind: 'codex' | 'claude-code' | 'pi';
modelId: string;
modelName: string;
/** Follow the same default visibility as the regular model selector. */
@@ -115,7 +115,7 @@ export function isCustomAuxiliaryModelList(models: readonly string[]): boolean {
export function describeAuxiliaryModelRef(ref: string): {
providerId: string;
- agentKind: 'codex' | 'claude-code';
+ agentKind: 'codex' | 'claude-code' | 'pi';
model: string;
} | null {
const parsed = parseAuxiliaryModelRef(ref);
diff --git a/apps/desktop/src/shared/catalogModelPin.ts b/apps/desktop/src/shared/catalogModelPin.ts
index a6c66a84f0..b5d2996c67 100644
--- a/apps/desktop/src/shared/catalogModelPin.ts
+++ b/apps/desktop/src/shared/catalogModelPin.ts
@@ -9,7 +9,7 @@
export const CATALOG_MODEL_PIN_PREFIX = 'cat:';
-export type CatalogModelPinAgentKind = 'codex' | 'claude-code';
+export type CatalogModelPinAgentKind = 'codex' | 'claude-code' | 'pi';
export interface CatalogModelPinRoute {
providerId: string;
@@ -17,7 +17,7 @@ export interface CatalogModelPinRoute {
model: string;
}
-const CATALOG_MODEL_PIN_AGENTS = new Set<CatalogModelPinAgentKind>(['codex', 'claude-code']);
+const CATALOG_MODEL_PIN_AGENTS = new Set<CatalogModelPinAgentKind>(['codex', 'claude-code', 'pi']);
/** Encode an exact provider × runtime × model route. */
export function encodeCatalogModelPin(route: CatalogModelPinRoute): string {