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。

Merge main into feat/scheduler-shared-providers

Yuewei-LLa0ab112cc1bc
diff --cc apps/desktop/scripts/fixtures/scheduler-model/ui-page.mjs
index 5149723249,0000000000..75509e165c
mode 100644,000000..100644
--- a/apps/desktop/scripts/fixtures/scheduler-model/ui-page.mjs
+++ b/apps/desktop/scripts/fixtures/scheduler-model/ui-page.mjs
@@@ -1,45 -1,0 +1,45 @@@
+import assert from 'node:assert/strict';
+
+const model = { id: 'claude-sonnet-4-6', name: 'Claude Sonnet 4.6', contextWindow: 200000,
+ efforts: ['low', 'medium', 'high'], defaultEffort: 'high', icon: 'claude' };
+const provider = { id: 'anthropic', name: 'Anthropic', connected: true, remoteInvocationEnabled: true,
+ agents: ['claude-code'], source: 'builtin', auth: { method: 'oauth' },
+ routing: { 'claude-code': { mode: 'direct', wireProtocol: 'anthropic-messages' } },
+ models: { 'claude-code': [model] } };
+const snapshot = JSON.stringify({ providers: [provider], providerOrder: [], loading: false, error: null, unsupported: false });
+const caps = JSON.stringify({ availableModels: [{ ...model, displayName: model.name }],
+ effortLevels: model.efforts.map(id => ({ id, displayName: id })) });
+
+export default {
+ name: 'scheduler-model',
+ entry: './scheduler-model-fixture.tsx',
+ viewport: { width: 720, height: 600 },
+ real: 'Automation ModelEffortChip, unified model picker, selection callback, source icons, themes and translations',
+ notCovered: 'Live device/share discovery, authorization, persistence and task execution; catalog hooks use fixture snapshots',
+ stubs: {
- 'src/renderer/hooks/useModelRouteDevices': `const devices = [{ deviceId: 'shared:fixture', name: 'Shared Anthropic' }]; export const useModelRouteDevices = () => ({ devices });`,
++ 'src/renderer/hooks/useModelRouteDevices': `const devices = [{ deviceId: 'shared:fixture', name: 'Shared Anthropic' }]; export const useModelRouteDevices = ({ leadAgentDeviceId }) => ({ devices, leadAgentDeviceId: leadAgentDeviceId ?? null });`,
+ 'src/renderer/hooks/useProviders': { partial: `const snapshot = ${snapshot}; export const useProviders = () => snapshot;` },
+ 'src/renderer/hooks/useDeviceProviders': { partial: `const snapshot = ${snapshot}; export const useDeviceProviders = () => snapshot;` },
+ 'src/renderer/hooks/useDevicesProviders': { partial: `const snapshot = ${snapshot}; const devices = new Map([['shared:fixture', snapshot]]); export const useDevicesProviders = () => devices;` },
+ 'src/renderer/hooks/useAgentCapabilities': { partial: `const capabilities = ${caps}; export const useAgentCapabilities = () => ({ capabilities, loading: false, error: null });` },
+ 'src/renderer/hooks/useAvailableAgents': { partial: `const agents = ['claude-code']; export const useModelPickerAgents = () => agents;` },
+ },
+ cases: { default: { about: 'Pick the shared source, then return to the local source' } },
+ async check(page, ui) {
+ const trigger = page.getByTestId('automation-model').getByRole('button');
+ await trigger.click();
+ await page.getByRole('button', { name: /Shared Anthropic/ }).click();
+ await ui.capture('shared-catalog');
+ await page.getByText('Claude Sonnet 4.6', { exact: true }).filter({ visible: true }).click();
+ await page.waitForFunction(() => document.querySelector('[data-testid="automation-model"]')?.getAttribute('data-device') === 'shared:fixture');
+ assert.equal(await page.getByTestId('automation-model').getAttribute('data-provider'), 'anthropic');
+ assert.equal(await trigger.locator('[data-remote-source-mark]').count(), 1);
+ await ui.capture('shared-selected');
+ await trigger.click();
+ await page.getByRole('button', { name: 'Anthropic', exact: true }).click();
+ await page.getByText('Claude Sonnet 4.6', { exact: true }).filter({ visible: true }).click();
+ await page.waitForFunction(() => document.querySelector('[data-testid="automation-model"]')?.getAttribute('data-device') === '');
+ assert.equal(await trigger.locator('[data-remote-source-mark]').count(), 0);
+ await ui.capture('local-selected');
+ },
+};
diff --cc apps/desktop/src/renderer/__tests__/controlledTaskRemoteAgentPanel.test.tsx
index 8fe1de4604,6e703c4f35..0c9336768a
--- a/apps/desktop/src/renderer/__tests__/controlledTaskRemoteAgentPanel.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/controlledTaskRemoteAgentPanel.test.tsx
@@@ -159,18 -150,8 +159,19 @@@ vi.mock('@/hooks/useRemoteDeviceUsage'
vi.mock('@/hooks/useRemoteClaudeSubscriptionUsage', () => ({
useRemoteClaudeSubscriptionUsage: () => null,
}));
+vi.mock('@/hooks/useModelRouteDevices', () => ({
- useModelRouteDevices: () => ({
++ useModelRouteDevices: ({ leadAgentDeviceId }: { leadAgentDeviceId?: string | null }) => ({
++ leadAgentDeviceId: leadAgentDeviceId ?? null,
+ devices: [{ deviceId: 'memory-device', name: 'Remote' }],
+ }),
+}));
import { ModelSelectorContent } from '@/components/new-chat/ModelSelector';
+import { ModelRouteSelectorContent } from '@/components/new-chat/ModelRouteSelector';
+import {
+ agentDeviceModelMemoryAccessors,
+ __resetForTest as resetDeviceMemory,
+} from '@/state/agentDeviceModelMemory';
import { __resetForTest as resetEnginePrefs } from '@/state/modelEnginePrefs';
import { __resetForTest as resetFavorites } from '@/state/modelFavorites';
import { __resetForTest as resetRecentModels, listRecentModels } from '@/state/recentModels';
diff --cc apps/desktop/src/renderer/components/new-chat/ModelRouteSelector.tsx
index 89bc5c6385,280166c53e..3ff0df1bf7
--- a/apps/desktop/src/renderer/components/new-chat/ModelRouteSelector.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/ModelRouteSelector.tsx
@@@ -1,50 -1,16 +1,52 @@@
import type { ComponentProps } from 'react';
-import { ModelSelector } from './ModelSelector';
+import { ModelSelector, ModelSelectorContent, type ModelMemoryAccessors } from './ModelSelector';
import { useModelRouteDevices } from '@/hooks/useModelRouteDevices';
+import { agentDeviceModelMemoryAccessors } from '@/state/agentDeviceModelMemory';
-/** Settings consume the same location catalog as ordinary tasks and workers. */
+interface ModelRouteContext {
+ /** The task host; omitted for this computer. */
+ deviceId?: string;
+ /** The selected Agent location; null/omitted means the task host. */
+ agentDeviceId?: string | null;
+ sshRemote?: boolean;
+}
+
+function useModelRouteOptions(
+ { deviceId, agentDeviceId, sshRemote }: ModelRouteContext,
+ modelMemory?: ModelMemoryAccessors,
+) {
+ const locations = useModelRouteDevices({
+ controlledDeviceId: deviceId ?? null,
+ leadAgentDeviceId: agentDeviceId,
+ sshRemote,
+ });
+ const remoteAgent = locations.devices ? {
+ devices: locations.devices,
- selectedDeviceId: agentDeviceId ?? null,
++ selectedDeviceId: locations.leadAgentDeviceId,
+ homeDeviceId: deviceId,
+ deviceModelMemory: agentDeviceModelMemoryAccessors,
+ } : undefined;
+ return {
++ // Read the selected, readable execution location while retaining the home catalog.
++ deviceId: locations.devices ? locations.leadAgentDeviceId ?? deviceId : deviceId,
+ remoteAgent,
+ // Keep remote preferences separate from the task host's model memory.
+ modelMemory: modelMemory ?? (remoteAgent?.selectedDeviceId
+ ? agentDeviceModelMemoryAccessors(remoteAgent.selectedDeviceId)
+ : undefined),
+ };
+}
+
+/** Full control using the common task/worker location catalog. */
export function ModelRouteSelector({ agentDeviceId, sshRemote, deviceId, ...props }:
- ComponentProps<typeof ModelSelector> & { agentDeviceId?: string | null; sshRemote?: boolean }) {
- const locations = useModelRouteDevices({ controlledDeviceId: deviceId ?? null,
- leadAgentDeviceId: agentDeviceId, sshRemote });
- // The trigger and the menu must read the selected, readable execution location.
- // Keep the home location separate for browsing local/controlled-host models.
- const catalogDeviceId = locations.devices ? locations.leadAgentDeviceId ?? deviceId : deviceId;
- return <ModelSelector {...props} deviceId={catalogDeviceId}
- remoteAgent={locations.devices ? { devices: locations.devices,
- selectedDeviceId: locations.leadAgentDeviceId, homeDeviceId: deviceId } : undefined} />;
+ Omit<ComponentProps<typeof ModelSelector>, 'remoteAgent'> & ModelRouteContext) {
+ const options = useModelRouteOptions({ deviceId, agentDeviceId, sshRemote }, props.modelMemory);
- return <ModelSelector {...props} deviceId={deviceId} {...options} />;
++ return <ModelSelector {...props} {...options} />;
+}
+
+/** The same selector inside an existing popover; callbacks retain the full selection. */
+export function ModelRouteSelectorContent({ agentDeviceId, sshRemote, deviceId, ...props }:
+ Omit<ComponentProps<typeof ModelSelectorContent>, 'remoteAgent'> & ModelRouteContext) {
+ const options = useModelRouteOptions({ deviceId, agentDeviceId, sshRemote }, props.modelMemory);
- return <ModelSelectorContent {...props} deviceId={deviceId} {...options} />;
++ return <ModelSelectorContent {...props} {...options} />;
}