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。

fix(browser): tabs shares the profile matching; settings guides the root official plugin instance

Dash0fbb771781ae
diff --git a/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts b/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts
index 05cc1b851b..1c3f7c8348 100644
--- a/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts
+++ b/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts
@@ -713,6 +713,10 @@ describe('UserBrowserBackend · 读取与动作', () => {
ok: false,
message: expect.stringContaining('匹配多个'),
});
+ expect(await call(b, { action: 'tabs', profile: 'client-aaa' })).toMatchObject({
+ ok: false,
+ message: expect.stringContaining('匹配多个'),
+ });
expect(await call(b, { action: 'open', url: 'https://b.test/', profile: 'client-aaaa' })).toMatchObject({
ok: true,
data: { browser: 'client-aaaa' },
diff --git a/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts b/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts
index 858c57472a..8ba32b76bd 100644
--- a/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts
+++ b/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts
@@ -132,6 +132,12 @@ export function userBrowserCapabilities(
: USER_BROWSER_CAPABILITIES;
}
+/** Connections a profile names: the exact id if there is one, else every id it is a prefix of. */
+function matchProfile<T extends { id: string }>(clients: T[], profile: string): T[] {
+ const exact = clients.filter((c) => c.id === profile);
+ return exact.length ? exact : clients.filter((c) => c.id.startsWith(profile));
+}
+
function actionFailed(
action: BackendRequest['action'],
message: string,
@@ -414,8 +420,7 @@ export class UserBrowserBackend implements BrowserBackend {
if (profile) {
// An exact id wins; an abbreviation must match exactly one connection, or the action could land in
// another signed-in browser.
- const exact = clients.filter((c) => c.id === profile);
- const matches = exact.length ? exact : clients.filter((c) => c.id.startsWith(profile));
+ const matches = matchProfile(clients, profile);
if (matches.length > 1)
return {
ok: false,
@@ -728,9 +733,15 @@ export class UserBrowserBackend implements BrowserBackend {
private async handleTabs(req: BackendRequest): Promise<BackendResult> {
const gate = this.control(req.action);
if (!gate.ok) return gate.result;
- const clients = this.connectedClients(gate.control).filter(
- (c) => !req.profile || c.id === req.profile || c.id.startsWith(req.profile),
- );
+ const connected = this.connectedClients(gate.control);
+ // Same matching as every other action: an exact id wins, an abbreviation must be unique.
+ const clients = req.profile ? matchProfile(connected, req.profile) : connected;
+ if (req.profile && clients.length > 1)
+ return actionFailed(
+ req.action,
+ `浏览器连接 ${req.profile} 匹配多个连接,请写得更完整;用 profiles 查看当前连接`,
+ 'BROWSER_RUNTIME_INVALID_REQUEST',
+ );
if (clients.length === 0)
return actionFailed(req.action, DISCONNECTED_MESSAGE, 'BROWSER_RUNTIME_UNAVAILABLE');
const tabs: Array<Record<string, unknown>> = [];
diff --git a/apps/desktop/src/renderer/components/settings/ComputerUseSection.tsx b/apps/desktop/src/renderer/components/settings/ComputerUseSection.tsx
index 6e505ee147..8f3df4962a 100644
--- a/apps/desktop/src/renderer/components/settings/ComputerUseSection.tsx
+++ b/apps/desktop/src/renderer/components/settings/ComputerUseSection.tsx
@@ -459,8 +459,11 @@ export function ComputerUseSection({ workingDir }: ComputerUseSectionProps) {
);
const navigate = useNavigate();
const userBrowserPlugin =
- useInstalledGhosts().find((ghost) => ghost.manifest.id === RECOMMENDED_PAGE_CONTROL_PLUGIN_ID) ??
- null;
+ // Only the root instance can provide My browser (an organization copy with the same id cannot),
+ // so that is the one the setup steps install, enable and open.
+ useInstalledGhosts().find(
+ (ghost) => ghost.manifest.id === RECOMMENDED_PAGE_CONTROL_PLUGIN_ID && ghost.namespace == null,
+ ) ?? null;
const [userBrowserSetupBusy, setUserBrowserSetupBusy] = useState(false);
// Health can include an automatic embedded-browser recovery and therefore
// take several seconds. Track the latest health owner so a late initial