Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(providers): 恢复添加向导中连接已有 llama.cpp 服务的入口 (#5499)
Dashb1e8d7521b2d
diff --git a/apps/desktop/src/renderer/__tests__/addProviderWizardPresetEntry.test.tsx b/apps/desktop/src/renderer/__tests__/addProviderWizardPresetEntry.test.tsxindex 61b6ed06a4..b0df3b9aeb 100644--- a/apps/desktop/src/renderer/__tests__/addProviderWizardPresetEntry.test.tsx+++ b/apps/desktop/src/renderer/__tests__/addProviderWizardPresetEntry.test.tsx@@ -351,13 +351,63 @@ describe('AddProviderWizard — preset 直达', () => {expect(window.electronAPI.maker.llamaCppInstall).not.toHaveBeenCalled();expect(window.electronAPI.maker.llamaCppStart).not.toHaveBeenCalled();});- it('uses the same immediate add flow for llama.cpp deep links', async () => {- const preset = { id: 'llamacpp', name: 'llama.cpp', authMethod: 'none' as const, runtimes: { pi: { baseUrl: 'http://127.0.0.1:8080/v1', baseUrlEditable: true, wireProtocol: 'openai-chat' as const, models: [] } } };+ it('keeps the Codex and Pi addresses of an existing llama.cpp server in sync until one is edited separately', async () => {+ const preset = BUNDLED_CATALOG.presets!.find(p => p.id === 'llamacpp')!;vi.mocked(window.electronAPI.maker.listProviderPresets).mockResolvedValue({ presets: [preset] });+ vi.mocked(window.electronAPI.maker.fetchProviderModels).mockResolvedValue({ ok: true, models: [{ id: 'qwen3-8b', name: 'qwen3-8b' }] });renderWizard('llamacpp');- await waitFor(() => expect(window.electronAPI.maker.llamaCppEnsure).toHaveBeenCalledOnce());- expect(screen.queryByDisplayValue('http://127.0.0.1:8080/v1')).toBeNull();- expect(window.electronAPI.maker.llamaCppStart).not.toHaveBeenCalled();+ const [first] = await screen.findAllByDisplayValue('http://127.0.0.1:8080/v1');+ fireEvent.change(first!, { target: { value: 'http://127.0.0.1:8081/v1' } });+ expect(screen.getAllByDisplayValue('http://127.0.0.1:8081/v1').length).toBeGreaterThan(1);+ expect(screen.queryAllByDisplayValue('http://127.0.0.1:8080/v1')).toHaveLength(0);+ fireEvent.click(screen.getByText('settings.providers.wizard.next'));+ fireEvent.click(await screen.findByText('qwen3-8b'));+ fireEvent.click(screen.getByText('settings.providers.wizard.finish'));+ await waitFor(() => expect(createCustomProvider).toHaveBeenCalledOnce());+ const config = vi.mocked(createCustomProvider).mock.calls[0][0];+ expect(Object.values(config.runtimes).map(rt => rt?.baseUrl)).toEqual(Object.keys(config.runtimes).map(() => 'http://127.0.0.1:8081/v1'));+ expect(config.runtimes.pi?.baseUrl).toBe('http://127.0.0.1:8081/v1');+ });+ it('connects an existing llama.cpp server from the preset deep link without touching the managed runtime', async () => {+ const preset = BUNDLED_CATALOG.presets!.find(p => p.id === 'llamacpp')!;+ vi.mocked(window.electronAPI.maker.listProviderPresets).mockResolvedValue({ presets: [preset] });+ vi.mocked(window.electronAPI.maker.fetchProviderModels).mockResolvedValue({+ ok: true,+ models: [{ id: 'qwen3-8b', name: 'qwen3-8b' }, { id: 'gemma-4', name: 'gemma-4' }, { id: 'glm-5-air', name: 'glm-5-air' }],+ });+ renderWizard('llamacpp');+ expect(await screen.findAllByDisplayValue('http://127.0.0.1:8080/v1')).not.toHaveLength(0);+ fireEvent.click(screen.getByText('settings.providers.wizard.next'));+ fireEvent.click(await screen.findByText('qwen3-8b'));+ fireEvent.click(screen.getByText('settings.providers.wizard.finish'));+ await waitFor(() => expect(createCustomProvider).toHaveBeenCalledOnce());+ const config = vi.mocked(createCustomProvider).mock.calls[0][0];+ expect(config.id).not.toBe('cindy-local-llamacpp');+ expect(config.runtimes.pi?.baseUrl).toBe('http://127.0.0.1:8080/v1');+ expect(config.runtimes.pi?.models.map(m => m.id)).toContain('qwen3-8b');+ expect(window.electronAPI.maker.llamaCppEnsure).not.toHaveBeenCalled();+ });+ it.each([+ ['detected', ['llamacpp'], 'settings.providers.wizard.groupDetectedLocal'],+ ['not detected', [], 'settings.providers.wizard.moreLocal'],+ ])('lists the existing llama.cpp server entry when %s, even with the managed runtime added', async (_label, detectedLocalPresetIds, group) => {+ const preset = BUNDLED_CATALOG.presets!.find(p => p.id === 'llamacpp')!;+ vi.mocked(window.electronAPI.maker.listProviderPresets).mockResolvedValue({ presets: [preset] });+ vi.mocked(window.electronAPI.maker.localModelList).mockResolvedValue({+ status: { runtime: 'ollama', kind: 'absent', appInstalled: false },+ models: [],+ memoryGb: 0,+ detectedLocalPresetIds,+ } as unknown as Awaited<ReturnType<typeof window.electronAPI.maker.localModelList>>);+ const managed = { ...anthropicProvider, id: 'cindy-local-llamacpp', name: 'llama.cpp', source: 'user' } as ProviderView;+ render(<AddProviderWizard providers={[managed]} onOpenCustomForm={vi.fn()} onClose={vi.fn()} onDone={vi.fn()} />);+ const label = await screen.findByText(group);+ const row = await screen.findByRole('button', { name: /llama\.cpp/ });+ expect(label.compareDocumentPosition(row) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();+ expect(screen.queryByText('settings.providers.llamacpp.subtitle')).toBeNull();+ fireEvent.click(row);+ expect(await screen.findAllByDisplayValue('http://127.0.0.1:8080/v1')).not.toHaveLength(0);+ expect(window.electronAPI.maker.llamaCppEnsure).not.toHaveBeenCalled();});it('官方 API 入口逐一显式声明 Pi 协议,不依赖 Claude runtime 派生', () => {expect(OFFICIAL_API_PRESETS.anthropic?.runtimes.pi?.wireProtocol).toBe('anthropic-messages');diff --git a/apps/desktop/src/renderer/components/settings/AddProviderWizard.tsx b/apps/desktop/src/renderer/components/settings/AddProviderWizard.tsxindex 5c7287f8d0..84a0820981 100644--- a/apps/desktop/src/renderer/components/settings/AddProviderWizard.tsx+++ b/apps/desktop/src/renderer/components/settings/AddProviderWizard.tsx@@ -112,6 +112,8 @@ function presetRuntimeBaseUrl(for (const [sourceAgent, endpoint] of Object.entries(edited)) {const source = preset.runtimes[sourceAgent as AgentKind];if (!source || !endpoint) continue;+ // 默认地址相同的运行时指向同一服务(如本机 llama.cpp 的 Codex / Pi),未单独编辑时跟随已编辑的那个。+ if (source.baseUrl === runtime.baseUrl) return endpoint.trim();const bindings = providerEndpointBindings(source.baseUrl, endpoint.trim());if (bindings && source.baseUrl.includes('{')) {return bindProviderEndpoint(runtime.baseUrl, bindings, endpoint.trim());@@ -563,7 +565,8 @@ export function AddProviderWizard({const filteredLocalAdvanced = q? localAdvancedPresets.filter((p) => p.name.toLowerCase().includes(q)): localAdvancedPresets;- const filteredLocalPresets = [...filteredLocalConnect, ...filteredLocalAdvanced].filter(p => p.id !== 'llamacpp');+ // 目录里的 llamacpp 预设是「连接已有服务」(默认 8080);Cindy 托管的 llama.cpp 走下方单独卡片,两者互不影响。+ const filteredLocalPresets = [...filteredLocalConnect, ...filteredLocalAdvanced];const ollamaAlreadyAdded = providers.some((p) => p.id === MANAGED_OLLAMA_PROVIDER_ID);const oauthChoiceIds = new Set(oauthChoices.map((p) => p.id));@@ -669,10 +672,6 @@ export function AddProviderWizard({const pickPreset = useCallback((preset: ProviderPreset, useApiKey = false) => {- if (preset.id === 'llamacpp') {- void connectLlamaCpp();- return;- }const oauth = providerPresetOAuth(preset.id);if (oauth && !useApiKey) {pickOauth({ ...buildUserProvider({@@ -700,7 +699,7 @@ export function AddProviderWizard({setPresetBaseUrls({});setStep(2);},- [i18n.language, onDone, providers, pickOauth, connectLlamaCpp],+ [i18n.language, onDone, providers, pickOauth],);const connectOllama = useCallback(async () => {diff --git a/docs/dev-rules/model-catalog-maintenance.md b/docs/dev-rules/model-catalog-maintenance.mdindex c538128431..96d3926b27 100644--- a/docs/dev-rules/model-catalog-maintenance.md+++ b/docs/dev-rules/model-catalog-maintenance.md@@ -169,8 +169,10 @@ localModels 整域缺失才用随包本地域,显式空不兜底。## llama.cpp 托管接入-客户端的「添加供应商」只展示一个 llama.cpp 主入口,点击立即保存并进入详情,-不等待安装或连接。安装与下载在详情中进行;外部服务走「自定义端点」。+客户端的「添加供应商」有两个 llama.cpp 入口,互不影响:托管入口(`cindy-local-llamacpp`)+点击立即保存并进入详情,不等待安装或连接,安装与下载在详情中进行;目录中的 `llamacpp`+预设用于连接用户已运行的服务(默认 `http://127.0.0.1:8080/v1`,地址可改),出现在+「检测到本机服务」或「更多本机服务」,走普通预设连接流程,不调用托管安装或启动。与 Ollama 共用 `LocalModelDownloadUI.tsx` 的安装提示、目录搜索、模型卡片、量化标签、下载按钮、进度操作与手动下载布局,各运行时只适配传输和状态。实现位于 `apps/desktop/src/main/local-model-runtime/llamaCpp*.ts`,界面为diff --git a/docs/llamacpp-trial.md b/docs/llamacpp-trial.mdindex 4cc5fb6990..998865a216 100644--- a/docs/llamacpp-trial.md+++ b/docs/llamacpp-trial.md@@ -9,7 +9,7 @@点击后立即添加供应商并进入详情,不等待运行环境安装或服务启动。安装和模型下载在详情中进行,安装后不启动服务,也不展示手动启动按钮。模型下载完成后自动加入模型列表;服务已运行时,需手动重启才能使用新增模型,已停止时首次使用自动启动并应用最新配置。下载期间可以取消,分片由 Cindy 自动补齐。「手动下载」位于模型清单下方,停止/重启位于-「管理服务」。已有外部服务可通过「自定义端点」添加。+「管理服务」。已有外部服务在添加向导的「检测到本机服务」或「更多本机服务」中选择 llama.cpp 连接(默认 `http://127.0.0.1:8080/v1`,地址可改),与 Cindy 托管的 llama.cpp 互不影响。只按用户点击下载,不自动下载这张清单里的所有模型。## 当前包装@@ -106,7 +106,7 @@ Global、CN 或不同 `--isolated=@worktree` profile 可以并行运行 Cindy,后续请求可能到达另一 profile 的模型服务;当前实现不保证此时返回 `PORT_CONFLICT`。这不是已修复场景,也不代表支持跨 profile 共用配置或模型目录。试验时需由用户停止先前 profile 的服务后再切换,避免同时启动;需要并行独立服务时,-自行运行不同端口的外部服务并通过「自定义端点」接入。本 PR 不提供跨 profile 端口分配、+自行运行不同端口的外部服务,并在添加向导的本机服务分组中选择 llama.cpp、改为对应地址后接入。本 PR 不提供跨 profile 端口分配、服务租约或模型目录共享,也不将应用多开支持表述为托管模型服务可多开。共享 userData 的多个实例各自持有独立暂存目录,操作结束只清理自己的目录。安装、下载、启动与删除共用既有 profile 锁;另一个实例正在操作时,安装、下载和删除返回忙碌,不删除另一实例的文件。删除检查到其他实例拥有存活服务时保留连接,需先在拥有方停止服务;不会跨窗口中断生成。安装使用独立版本目录和暂存清单。为避免误删仍在下载的文件,不自动扫描清理其他暂存目录;强制退出或崩溃遗留的暂存文件目前不会自动回收。