Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(desktop): 快问快答可钉后端 + 修派活模型下拉重复项
Lizi1706e6263735
diff --git a/apps/desktop/src/main/cindy-brain/cindyPrefsStore.ts b/apps/desktop/src/main/cindy-brain/cindyPrefsStore.tsindex 6662e759ab..b6041bffea 100644--- a/apps/desktop/src/main/cindy-brain/cindyPrefsStore.ts+++ b/apps/desktop/src/main/cindy-brain/cindyPrefsStore.ts@@ -22,7 +22,15 @@ import { ownerScopedUserDataPath } from '../appSessionState.js';const log = desktopMakerLogger.child('cindy-prefs-store');/** cindy 槽能力键(类目.动作;与身份卡详单同一词汇表,当前包含 video)。 */-export const CINDY_CAPABILITY_KEYS = ['image.generate', 'image.edit', 'video.generate', 'video.edit'] as const;+// text.oneshot(快问快答)与图像/视频同表:每项覆盖记的都是一组供应商×模型。+// 文本类的取值是轻量任务模型链的档位键(codex-gpt-5.4-mini 等),不是媒体目录模型 id。+export const CINDY_CAPABILITY_KEYS = [+ 'image.generate',+ 'image.edit',+ 'video.generate',+ 'video.edit',+ 'text.oneshot',+] as const;export type CindyCapabilityKey = (typeof CINDY_CAPABILITY_KEYS)[number];export interface GhostCindyPrefs {diff --git a/apps/desktop/src/main/cindy-brain/cindySlot.ts b/apps/desktop/src/main/cindy-brain/cindySlot.tsindex 51a7957cab..67574a4c06 100644--- a/apps/desktop/src/main/cindy-brain/cindySlot.ts+++ b/apps/desktop/src/main/cindy-brain/cindySlot.ts@@ -194,7 +194,13 @@ export interface CindySlotDeps {* 不注入 = 能力在运行期不可用,资格审通过也回结构化拒绝(未接线的* 宿主/测试环境天然 fail closed)。*/- oneshotText?(params: { prompt: string; maxTokens: number; timeoutMs: number }): Promise<+ oneshotText?(params: {+ prompt: string;+ maxTokens: number;+ timeoutMs: number;+ /** 用户在插件详情页把 text.oneshot 钉到的轻量档位(供应商×模型);没钉 = 跟随默认链。 */+ pinnedProfileId?: string;+ }): Promise<| { ok: true; text: string; model?: string }| { ok: false; reason: 'no_candidate' | 'timeout' | 'failed'; message: string }>;@@ -922,10 +928,14 @@ export class GhostCindySlot {const prompt = expectJson? `${p.prompt}\n\n(只输出 JSON 本体,不要任何解释、前后缀或代码围栏)`: p.prompt;+ // 选型仍不在意识手里,但用户可以在插件详情页把这项能力钉到某个轻量档位+ // (与 image.*/video.* 的"钉后端"同一张覆盖表、同一条 IPC)。+ const pinnedProfileId = this.deps.getOverride(ghostId, 'text.oneshot') ?? undefined;const outcome = await oneshot({prompt,maxTokens: (p.maxTokens as number | undefined) ?? GHOST_ONESHOT_TEXT_DEFAULT_MAX_TOKENS,timeoutMs: GHOST_ONESHOT_TEXT_TIMEOUT_MS,+ pinnedProfileId,});if (!outcome.ok) {const errorCode =diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.tsindex e5caa538e9..4596e08893 100644--- a/apps/desktop/src/main/cindy-brain/index.ts+++ b/apps/desktop/src/main/cindy-brain/index.ts@@ -175,6 +175,8 @@ import { projectProviderCatalogForBuildRegion } from '../maker-host/provider-accimport { isModelDisabled, isProviderDisabled } from '@cindy/model-providers';import { readModelDisableOverrides } from '../maker-host/model-disable-store.js';import { outboundFetch } from '../maker-host/outbound-fetch.js';+import { getUtilityModelChainProfiles } from '../utility-model/UtilityModelSelection.js';+import { utilityModelPinOptions } from '../../shared/utilityModelProfiles.js';import {CINDY_CAPABILITY_KEYS,readGhostCindyOverrides,@@ -2029,12 +2031,16 @@ export function getGhostCindySlot(): GhostCindySlot {// 模块顶层读 electron app 路径,静态引入会把这条链拽进所有 import 本// 模块的单测(hook-script-generator 同款做法)。失败面折叠成 slot 层// 的三档 reason;attempts 细节只进日志,不给沙箱探测面。- oneshotText: async ({ prompt, maxTokens, timeoutMs }) => {+ oneshotText: async ({ prompt, maxTokens, timeoutMs, pinnedProfileId }) => {const [{ requestUtilityText }, { getMaker }] = await Promise.all([import('../utility-model/oneShotCandidates.js'),import('../maker-host/index.js'),]);- const r = await requestUtilityText(getMaker(), prompt, { maxTokens, timeoutMs });+ const r = await requestUtilityText(getMaker(), prompt, {+ maxTokens,+ timeoutMs,+ pinnedProfileId,+ });if (r.ok) {return { ok: true, text: r.text, model: `${r.providerId}/${r.model}` };}@@ -3602,10 +3608,21 @@ export function registerGhostIpc(): void {standard === undefined ? null : (cfg.models.find((m) => m.id === standard) ?? null),};};+ // 文本类(快问快答)的可选项不来自媒体目录,而是轻量任务模型链的档位表+ // ——每一项就是一组供应商×模型。defaultModel = 当前"跟随默认"实际会用的+ // 那一档(链首),让用户看得见跟的是谁。+ const textChain = getUtilityModelChainProfiles();+ const textOptions = utilityModelPinOptions();+ const textDefaultId = textChain[0]?.id ?? null;event.returnValue = {overrides,image: byKind(getCatalogImageConfig()),video: byKind(getCatalogVideoConfig()),+ text: {+ options: textOptions,+ defaultModel:+ textDefaultId === null ? null : (textOptions.find((o) => o.id === textDefaultId) ?? null),+ },};});// ── 目录级禁用(ghostWorkdirPrefs;插件页的项目范围视图)──diff --git a/apps/desktop/src/main/utility-model/__tests__/oneShotCandidates.test.ts b/apps/desktop/src/main/utility-model/__tests__/oneShotCandidates.test.tsindex 92f10ff50d..35233a8601 100644--- a/apps/desktop/src/main/utility-model/__tests__/oneShotCandidates.test.ts+++ b/apps/desktop/src/main/utility-model/__tests__/oneShotCandidates.test.ts@@ -171,6 +171,52 @@ describe('utility one-shot candidates', () => {});});+ it('pinnedProfileId 钉住某一档时只用它,绕开默认链', async () => {+ // 默认链(mock)是 codex-mini + litellm-mini;钉 deepseek 应当完全绕开它们,+ // 只解析出 deepseek 这一个候选(取自真实档位表,不受链 mock 影响)。+ readKey.mockReturnValue('proxy-key');+ fetchMock.mockResolvedValueOnce({+ ok: true,+ json: async () => ({ choices: [{ message: { content: 'pinned text' } }] }),+ } as never);++ const result = await requestUtilityText(makerMock(false), 'hello', {+ maxTokens: 10,+ pinnedProfileId: 'litellm-deepseek-v4-flash',+ });++ expect(result).toMatchObject({+ ok: true,+ text: 'pinned text',+ providerId: 'litellm-deepseek-v4-flash',+ model: 'deepseek/deepseek-v4-flash',+ });+ // 钉住后链上的 mini 一次都不该被下单+ expect(JSON.parse(String(vi.mocked(fetchMock).mock.calls[0]?.[1]?.body))).toMatchObject({+ model: 'deepseek/deepseek-v4-flash',+ });+ });++ it('不认的 pinnedProfileId 忽略,回落默认链', async () => {+ readKey.mockReturnValue('proxy-key');+ fetchMock.mockResolvedValueOnce({+ ok: true,+ json: async () => ({ choices: [{ message: { content: 'chain text' } }] }),+ } as never);++ const result = await requestUtilityText(makerMock(false), 'hello', {+ maxTokens: 10,+ pinnedProfileId: 'no-such-profile',+ });++ // 回落到链上第一个可用候选(codex 无凭证被跳过 → litellm-mini)+ expect(result).toMatchObject({+ ok: true,+ providerId: 'litellm-gpt-5.4-mini',+ model: 'gpt-5.4-mini',+ });+ });+it('preserves failed candidate and HTTP status diagnostics without response bodies', async () => {readKey.mockReturnValue('proxy-key');const maker = makerMock(true);diff --git a/apps/desktop/src/main/utility-model/oneShotCandidates.ts b/apps/desktop/src/main/utility-model/oneShotCandidates.tsindex 2bee15b098..4369009a16 100644--- a/apps/desktop/src/main/utility-model/oneShotCandidates.ts+++ b/apps/desktop/src/main/utility-model/oneShotCandidates.ts@@ -19,6 +19,7 @@ import { isProviderRouteMutationInProgress } from '../maker-host/provider-route.import { effectiveXdGatewayBaseUrl } from '../model-access/effectiveEndpoint.js';import { readCustomProviderKey } from '../secrets/providerSecretStore.js';import { getUtilityModelChainProfiles } from './UtilityModelSelection.js';+import { getUtilityModelProfile, isUtilityModelProviderKind } from '../../shared/utilityModelProfiles.js';import type { UtilityModelProfile, UtilityModelTransport } from '../../shared/utilityModelProfiles.js';import type {UtilityTextAttempt,@@ -48,6 +49,13 @@ export type UtilityTextRequestOptions = {providerId?: string;agentKind?: AgentKind;model?: string;+ /**+ * 钉住某一个轻量档位(UTILITY_MODEL_PROFILES 的 key,如 codex-gpt-5.4-nano)。+ * 用于插件把 cindy.text.oneshot 的选型钉到一组供应商×模型上——与图像/视频+ * 的"钉后端"同一口径:**钉了就只用它**,不再沿链回落,否则"我钉了 A 却悄悄+ * 用了 B"比直接失败更伤信任。不认的值忽略(回到跟随默认)。+ */+ pinnedProfileId?: string;};/** Internal resolution result keeps skipped candidates visible to diagnostics. */@@ -147,8 +155,18 @@ export function isProviderModelRouteDisabled(providerId: string, modelId: stringasync function resolveUtilityTextCandidates(maker: Maker,capability: UtilityTextCapability,+ pinnedProfileId?: string,): Promise<{ candidates: UtilityTextCandidate[]; attempts: UtilityTextAttempt[] }> {- const profiles = getUtilityModelChainProfiles();+ // 钉住某一档时只拿那一个候选:钉了还沿链回落,等于用户的选择被悄悄换掉。+ // 注意不能从链里筛——默认链只有 4 档,而可钉的档位有 9 个,链外的钉不上。+ const pinned =+ pinnedProfileId && isUtilityModelProviderKind(pinnedProfileId)+ ? getUtilityModelProfile(pinnedProfileId)+ : null;+ if (pinnedProfileId && !pinned) {+ log.warn('utility text pinned profile unknown, falling back to chain', { pinnedProfileId });+ }+ const profiles = pinned ? [pinned] : getUtilityModelChainProfiles();const candidates: UtilityTextCandidate[] = [];const attempts: UtilityTextAttempt[] = [];// 停用轴同样约束 utility one-shot(帮助/摘要/hook 生成):停用的供应商或模型@@ -268,6 +286,7 @@ async function requestDefaultUtilityText(const { candidates, attempts } = await resolveUtilityTextCandidates(maker,opts?.capability ?? { transports: ['codex-responses', 'litellm-chat-completions'] },+ opts?.pinnedProfileId,);if (candidates.length === 0) {return { ok: false, reason: 'no_candidate', attempts };diff --git a/apps/desktop/src/preload/preload.ts b/apps/desktop/src/preload/preload.tsindex 6f62203810..91e9b457cd 100644--- a/apps/desktop/src/preload/preload.ts+++ b/apps/desktop/src/preload/preload.ts@@ -864,6 +864,8 @@ contextBridge.exposeInMainWorld('electronAPI', {*/image: { options: Array<{ id: string; label: string }>; defaultModel: { id: string; label: string } | null };video: { options: Array<{ id: string; label: string }>; defaultModel: { id: string; label: string } | null };+ /** 文本类(快问快答):选项是轻量任务模型链的档位(供应商×模型),不是媒体目录模型。 */+ text: { options: Array<{ id: string; label: string }>; defaultModel: { id: string; label: string } | null };} => ipcRenderer.sendSync('ghosts:cindy-prefs', id),setCindyPref: (id: string, capability: string, model: string | null): Promise<{ overrides: Record<string, string> }> =>ipcRenderer.invoke('ghosts:cindy-prefs:set', id, capability, model),diff --git a/apps/desktop/src/renderer/cindy-brain/CindyCapabilityPrefs.tsx b/apps/desktop/src/renderer/cindy-brain/CindyCapabilityPrefs.tsxindex 86399b4f22..21fac32fb6 100644--- a/apps/desktop/src/renderer/cindy-brain/CindyCapabilityPrefs.tsx+++ b/apps/desktop/src/renderer/cindy-brain/CindyCapabilityPrefs.tsx@@ -82,7 +82,13 @@ export function CindyCapabilityPrefs({{t('settings.ghosts.detail.cindyPrefs.desc')}</p>{capabilities.map((capability) => {- const kind = capability.startsWith('video.') ? prefs.video : prefs.image;+ // 按能力键的类目取对应清单。少一个分支的后果不是少个下拉,而是拿+ // **图像模型清单**去填一个文本能力——用户存进去的值链路根本不认。+ const kind = capability.startsWith('video.')+ ? prefs.video+ : capability.startsWith('text.')+ ? prefs.text+ : prefs.image;// 目录没给这个类目任何模型 = 能力暂不可用:行照旧显示(插件确实申请了// 这项能力),但右侧不给下拉,改一句不可点的灰字,不拿旧型号冒充可选。const defaultModel = kind.defaultModel;diff --git a/apps/desktop/src/renderer/cindy-brain/GhostErrandPrefs.tsx b/apps/desktop/src/renderer/cindy-brain/GhostErrandPrefs.tsxindex b5cbce5c29..43576376e7 100644--- a/apps/desktop/src/renderer/cindy-brain/GhostErrandPrefs.tsx+++ b/apps/desktop/src/renderer/cindy-brain/GhostErrandPrefs.tsx@@ -89,6 +89,31 @@ export function GhostErrandPrefs({// agent 显式选定后才有可配的模型清单;模型选定后强度跟着该模型的支持集走。const models = (capabilities?.availableModels ?? []).filter((m) => m.defaultEnabled !== false);++ /**+ * 下拉里每一项的文案。原来只画 displayName,踩了两个坑:+ * 1. **折扣版与官方版 displayName 同名**(见 ModelDescriptor.group 的注释),+ * 于是列表里出现好几行一模一样的字,用户根本选不中想要的那个;+ * 2. 主机自己的模型选择器每行都带思考强度档(如「Opus 5 超高」),这里没有,+ * 两处看起来不像同一个产品。+ * `<option>` 里画不了徽章,所以把这些信息拼进文字:名字 · 强度 · 折扣。+ */+ const modelOptionLabel = (m: (typeof models)[number]): string => {+ const parts = [m.displayName];+ const effort = m.defaultEffort;+ if (effort) {+ const effortName =+ m.effortDisplayNames?.[effort] ??+ capabilities?.effortLevels.find((e) => e.id === effort)?.displayName ??+ effort;+ parts.push(effortName);+ }+ // 判别与 ModelSelector 保持一致:目录分组优先,回落 id 前缀。+ if (m.group === 'gpt-budget' || m.id.startsWith('codex/')) {+ parts.push(t('newChat.modelSelector.meta.budgetDiscount'));+ }+ return parts.join(' · ');+ };const selectedModel = config.model ? models.find((m) => m.id === config.model) : undefined;const effortOptions = (selectedModel ? selectedModel.efforts : (capabilities?.effortLevels ?? []).map((e) => e.id)@@ -189,7 +214,7 @@ export function GhostErrandPrefs({</option>{models.map((m) => (<option key={m.id} value={m.id}>- {m.displayName}+ {modelOptionLabel(m)}</option>))}</select>,diff --git a/apps/desktop/src/renderer/features/plugin/lib/ghostPluginViewModel.ts b/apps/desktop/src/renderer/features/plugin/lib/ghostPluginViewModel.tsindex 73b423e589..c62e02b780 100644--- a/apps/desktop/src/renderer/features/plugin/lib/ghostPluginViewModel.ts+++ b/apps/desktop/src/renderer/features/plugin/lib/ghostPluginViewModel.ts@@ -196,6 +196,9 @@ export function toGhostPluginDetail(cindyCapabilities: [...(manifest.cindy?.image ?? []).map((action) => `image.${action}`),...(manifest.cindy?.video ?? []).map((action) => `video.${action}`),+ // 文本类(快问快答)同样可钉后端:漏掉它,声明了 cindy.text 的插件在+ // 详情页就没有任何选型入口,只能吃全局轻量链的默认档。+ ...(manifest.cindy?.text ?? []).map((action) => `text.${action}`),],hasErrand: manifest.agent?.errand === true,panelMinWidth: manifest.panel ? (manifest.panel.minWidth ?? 280) : null,diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex fc33c0e9fd..d2f769aa6a 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -2999,7 +2999,8 @@"image.generate": "Image generation","image.edit": "Image editing","video.generate": "Video generation",- "video.edit": "Image-to-video"+ "video.edit": "Image-to-video",+ "text.oneshot": "Quick answer (text)"},"defaultOption": "{{model}} (default)","noModels": "No models available"@@ -8096,4 +8097,4 @@}}}-}\ No newline at end of file+}diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex c8da843f26..95c7d30cba 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -2998,7 +2998,8 @@"image.generate": "画像生成","image.edit": "画像編集","video.generate": "動画生成",- "video.edit": "画像から動画"+ "video.edit": "画像から動画",+ "text.oneshot": "クイック回答(テキスト)"},"defaultOption": "{{model}}(既定)","noModels": "利用可能なモデルなし"@@ -8084,4 +8085,4 @@}}}-}\ No newline at end of file+}diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex e2cf0399ab..2e99444af7 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -2998,7 +2998,8 @@"image.generate": "이미지 생성","image.edit": "이미지 편집","video.generate": "영상 생성",- "video.edit": "이미지로 영상"+ "video.edit": "이미지로 영상",+ "text.oneshot": "빠른 답변(텍스트)"},"defaultOption": "{{model}} (기본값)","noModels": "사용 가능한 모델 없음"@@ -8084,4 +8085,4 @@}}}-}\ No newline at end of file+}diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex 960a0ee1a1..08e1b27332 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -2998,7 +2998,8 @@"image.generate": "出图","image.edit": "改图","video.generate": "生成视频",- "video.edit": "图生视频"+ "video.edit": "图生视频",+ "text.oneshot": "快问快答(文字)"},"defaultOption": "{{model}}(默认)","noModels": "暂无可用模型"@@ -8084,4 +8085,4 @@}}}-}\ No newline at end of file+}diff --git a/apps/desktop/src/renderer/vite-env.d.ts b/apps/desktop/src/renderer/vite-env.d.tsindex 7184337b8b..5698beb541 100644--- a/apps/desktop/src/renderer/vite-env.d.ts+++ b/apps/desktop/src/renderer/vite-env.d.ts@@ -1117,6 +1117,8 @@ interface ElectronAPI {overrides: Record<string, string>;image: { options: Array<{ id: string; label: string }>; defaultModel: { id: string; label: string } | null };video: { options: Array<{ id: string; label: string }>; defaultModel: { id: string; label: string } | null };+ /** 文本类(快问快答):选项是轻量任务模型链的档位(供应商×模型),不是媒体目录模型。 */+ text: { options: Array<{ id: string; label: string }>; defaultModel: { id: string; label: string } | null };};/** 写/清一项覆盖(model=null 即恢复跟随默认);返回该意识最新覆盖表。 */setCindyPref: (diff --git a/apps/desktop/src/shared/utilityModelProfiles.ts b/apps/desktop/src/shared/utilityModelProfiles.tsindex c359031421..c89b0d2be3 100644--- a/apps/desktop/src/shared/utilityModelProfiles.ts+++ b/apps/desktop/src/shared/utilityModelProfiles.ts@@ -185,3 +185,22 @@ export function estimateUtilityModelCostUsd(function normalizeTokenCount(value: number | undefined): number {return Number.isFinite(value) && value && value > 0 ? value : 0;}++/**+ * 快问快答(插件 cindy.text.oneshot)可钉的后端清单。+ *+ * 与图像/视频的"钉后端"同一口径:每一项就是一组**供应商 × 模型**。这里带上+ * 传输通道当后缀——`gpt-5.4-mini` 同时经 Codex 订阅和网关提供,只写模型名会+ * 出现两行同名项、用户选不中(GhostErrandPrefs 踩过同一个坑)。后缀用中立的+ * 通道名而非中文,避免在 shared 层塞 UI 文案。+ */+export function utilityModelPinOptions(): Array<{ id: string; label: string }> {+ return Object.values(UTILITY_MODEL_PROFILES).map((profile) => ({+ id: profile.id,+ label: `${profile.model} · ${utilityTransportLabel(profile.transport)}`,+ }));+}++export function utilityTransportLabel(transport: UtilityModelTransport): string {+ return transport === 'codex-responses' ? 'Codex' : 'Gateway';+}