Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): 修正备用模型编号与编辑范围 (#4179)
Chris Zhang3a980ded38a0
diff --git a/apps/desktop/src/renderer/features/bots/BotModelChainEditor.tsx b/apps/desktop/src/renderer/features/bots/BotModelChainEditor.tsxindex f868315be1..5d52b232bf 100644--- a/apps/desktop/src/renderer/features/bots/BotModelChainEditor.tsx+++ b/apps/desktop/src/renderer/features/bots/BotModelChainEditor.tsx@@ -71,7 +71,7 @@ export function BotModelChainEditor({};const move = (index: number, delta: -1 | 1) => {const target = index + delta;- if (target < 0 || target >= routes.length) return;+ if (index < 1 || target < 1 || target >= routes.length) return;const next = [...routes];[next[index], next[target]] = [next[target]!, next[index]!];onChange(next);@@ -139,43 +139,46 @@ export function BotModelChainEditor({</summary>{expanded ? (<div className="space-y-2 pt-2">- {routes.map((route, index) => (- <div key={index} className="flex min-w-0 items-center gap-2">- <span className="w-4 shrink-0 text-11">{index + 1}</span>- {picker(route, index)}- <div className="flex shrink-0 gap-1">- <button- type="button"- disabled={disabled || index === 0}- onClick={() => move(index, -1)}- aria-label={t('bots.modelChain.moveUp')}- className="rounded-lg p-1.5 hover:bg-[var(--surface-hover)] disabled:opacity-30"- >- <ArrowUp size={14} />- </button>- <button- type="button"- disabled={disabled || index === routes.length - 1}- onClick={() => move(index, 1)}- aria-label={t('bots.modelChain.moveDown')}- className="rounded-lg p-1.5 hover:bg-[var(--surface-hover)] disabled:opacity-30"- >- <ArrowDown size={14} />- </button>- {routes.length > 1 ? (+ {routes.slice(1).map((route, fallbackIndex) => {+ const index = fallbackIndex + 1;+ return (+ <div key={index} className="flex min-w-0 items-center gap-2">+ <span className="w-4 shrink-0 text-11">{index}</span>+ {picker(route, index)}+ <div className="flex shrink-0 gap-1"><buttontype="button"- disabled={disabled}- onClick={() => onChange(routes.filter((_, at) => at !== index))}- aria-label={t('bots.modelChain.remove')}- className="rounded-lg p-1.5 hover:bg-[var(--danger-bg-soft)] hover:text-[var(--text-danger)]"+ disabled={disabled || index === 1}+ onClick={() => move(index, -1)}+ aria-label={t('bots.modelChain.moveUp')}+ className="rounded-lg p-1.5 hover:bg-[var(--surface-hover)] disabled:opacity-30">- <Trash2 size={14} />+ <ArrowUp size={14} /></button>- ) : null}+ <button+ type="button"+ disabled={disabled || index === routes.length - 1}+ onClick={() => move(index, 1)}+ aria-label={t('bots.modelChain.moveDown')}+ className="rounded-lg p-1.5 hover:bg-[var(--surface-hover)] disabled:opacity-30"+ >+ <ArrowDown size={14} />+ </button>+ {routes.length > 1 ? (+ <button+ type="button"+ disabled={disabled}+ onClick={() => onChange(routes.filter((_, at) => at !== index))}+ aria-label={t('bots.modelChain.remove')}+ className="rounded-lg p-1.5 hover:bg-[var(--danger-bg-soft)] hover:text-[var(--text-danger)]"+ >+ <Trash2 size={14} />+ </button>+ ) : null}+ </div></div>- </div>- ))}+ );+ })}<buttontype="button"disabled={disabled || routes.length >= BOT_MODEL_CHAIN_MAX || visibleVendors.length === 0}diff --git a/apps/desktop/src/renderer/features/bots/__tests__/botModelChainEditor.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/botModelChainEditor.test.tsxindex 92a51f4847..3ff3aca486 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/botModelChainEditor.test.tsx+++ b/apps/desktop/src/renderer/features/bots/__tests__/botModelChainEditor.test.tsx@@ -1,6 +1,6 @@// @vitest-environment jsdom-import { cleanup, fireEvent, render, screen } from '@testing-library/react';+import { cleanup, fireEvent, render, screen, within } from '@testing-library/react';import { afterEach, describe, expect, it, vi } from 'vitest';const { modelSelectorProps, roster } = vi.hoisted(() => ({@@ -12,6 +12,7 @@ vi.mock('@/hooks/useAvailableAgents', () => ({ useAvailableAgents: () => rostervi.mock('@/components/new-chat/ModelSelector', () => ({ModelSelector: (props: {+ modelId: string;onEffortChange: (effort: string) => void;onFastModeChange: (enabled: boolean) => void;onUnifiedSelect: (selection: {@@ -25,7 +26,7 @@ vi.mock('@/components/new-chat/ModelSelector', () => ({}) => {modelSelectorProps(props);return (- <>+ <div data-testid={`model-selector-${props.modelId}`}><button onClick={() => props.onEffortChange("high")}>set-high-effort</button><button onClick={() => props.onFastModeChange(true)}>enable-fast-mode</button><button@@ -57,7 +58,7 @@ vi.mock('@/components/new-chat/ModelSelector', () => ({>choose-official-claude-model</button>- </>+ </div>);},}));@@ -88,6 +89,71 @@ afterEach(() => {});describe('BotModelChainEditor', () => {+ const primary = { harness: 'codex' as const, model: 'primary-model', providerId: 'openai', effort: 'medium', fastMode: false };+ const firstFallback = { ...primary, model: 'first-fallback' };+ const secondFallback = { ...primary, model: 'second-fallback' };++ function expand(container: HTMLElement) {+ const details = container.querySelector('details')!;+ details.open = true;+ fireEvent(details, new Event('toggle'));+ return within(details);+ }++ it('lists and numbers only fallbacks, and edits the second route without replacing the primary', () => {+ const onChange = vi.fn();+ const view = render(<BotModelChainEditor value={[primary, firstFallback]} onChange={onChange} />);+ const fallbacks = expand(view.container);++ expect(screen.getAllByTestId('model-selector-primary-model')).toHaveLength(1);+ expect(fallbacks.queryByTestId('model-selector-primary-model')).toBeNull();+ expect(fallbacks.getByText('bots.modelChain.options:{"count":1}')).toBeTruthy();+ expect(fallbacks.getByText('1')).toBeTruthy();+ expect(fallbacks.queryByText('2')).toBeNull();+ const picker = within(fallbacks.getByTestId('model-selector-first-fallback'));+ fireEvent.click(picker.getByText('choose-official-codex-model'));+ expect(onChange).toHaveBeenLastCalledWith([primary, {+ harness: 'codex', providerId: 'openai', model: 'gpt-5.6-sol', effort: 'medium', fastMode: true,+ }]);+ fireEvent.click(picker.getByText('set-high-effort'));+ expect(onChange).toHaveBeenLastCalledWith([primary, { ...firstFallback, effort: 'high' }]);+ fireEvent.click(picker.getByText('enable-fast-mode'));+ expect(onChange).toHaveBeenLastCalledWith([primary, { ...firstFallback, fastMode: true }]);+ });++ it('reorders and removes fallbacks while keeping the primary in place', () => {+ const onChange = vi.fn();+ const view = render(<BotModelChainEditor value={[primary, firstFallback, secondFallback]} onChange={onChange} />);+ const fallbacks = expand(view.container);+ const up = fallbacks.getAllByLabelText('bots.modelChain.moveUp');+ expect((up[0] as HTMLButtonElement).disabled).toBe(true);+ fireEvent.click(up[0]!);+ expect(onChange).not.toHaveBeenCalled();+ fireEvent.click(up[1]!);+ expect(onChange).toHaveBeenLastCalledWith([primary, secondFallback, firstFallback]);+ fireEvent.click(fallbacks.getAllByLabelText('bots.modelChain.moveDown')[0]!);+ expect(onChange).toHaveBeenLastCalledWith([primary, secondFallback, firstFallback]);+ fireEvent.click(fallbacks.getAllByLabelText('bots.modelChain.remove')[0]!);+ expect(onChange).toHaveBeenLastCalledWith([primary, secondFallback]);++ view.rerender(<BotModelChainEditor value={[primary, secondFallback]} onChange={onChange} />);+ expect(fallbacks.getByText('1')).toBeTruthy();+ expect(fallbacks.queryByText('2')).toBeNull();+ fireEvent.click(fallbacks.getByLabelText('bots.modelChain.remove'));+ expect(onChange).toHaveBeenLastCalledWith([primary]);+ });++ it('shows no fallback rows for a primary-only chain and appends the first fallback', () => {+ const onChange = vi.fn();+ const view = render(<BotModelChainEditor value={[primary]} onChange={onChange} />);+ const fallbacks = expand(view.container);+ expect(fallbacks.getByText('bots.modelChain.options:{"count":0}')).toBeTruthy();+ expect(fallbacks.queryByTestId('model-selector-primary-model')).toBeNull();+ expect(fallbacks.queryByLabelText('bots.modelChain.remove')).toBeNull();+ fireEvent.click(fallbacks.getByText('bots.modelChain.add'));+ expect(onChange).toHaveBeenLastCalledWith([primary, expect.objectContaining({ model: 'default-model' })]);+ });+it('uses the standard configurable picker for the current harness', () => {render(<BotModelChainEditor