Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): route remote authorization cancellation to owning host
zqchris6e6de4c1bce9
diff --git a/apps/desktop/src/renderer/features/bots/BotAuthorizationCard.tsx b/apps/desktop/src/renderer/features/bots/BotAuthorizationCard.tsxindex 7b6de2909d..2185f4300e 100644--- a/apps/desktop/src/renderer/features/bots/BotAuthorizationCard.tsx+++ b/apps/desktop/src/renderer/features/bots/BotAuthorizationCard.tsx@@ -2,7 +2,7 @@ import { useState } from 'react';import { useTranslation } from 'react-i18next';import { PluginSetupPrompt } from '@/components/new-chat/PluginSetupPrompt';import { readBotAuthorizationCard } from '../../../shared/botAuthorization';-import { isRemoteSessionSticky } from '@/lib/makerTransport';+import { isRemoteSessionSticky, makerApiForSticky } from '@/lib/makerTransport';import type { PluginSetupCommandInFlight } from '@/lib/makerChatStore';/** Same composable form for Host and plugin accounts, rendered in the transcript. */@@ -38,7 +38,7 @@ function AuthorizationBody({remote={remote}commandInFlight={busy}onCommand={(requestId, action, actionId, values) => {- if (busy) return;+ if (busy || (isRemoteSessionSticky(card.sessionId) && action !== 'cancel')) return;setFailed(false);setBusy({ requestId, action, actionId });const command =@@ -49,7 +49,7 @@ function AuthorizationBody({expectedRevision: card.snapshot.revision,value: values.value,})- : window.electronAPI.maker.resolveInteraction(requestId, {+ : makerApiForSticky(card.sessionId).resolveInteraction(requestId, {kind: 'plugin_setup',action: action === 'cancel' ? 'cancel' : 'run_action',...(actionId ? { actionId } : {}),diff --git a/apps/desktop/src/renderer/features/bots/__tests__/BotAuthorizationCard.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/BotAuthorizationCard.test.tsxnew file mode 100644index 0000000000..e697fe2426--- /dev/null+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotAuthorizationCard.test.tsx@@ -0,0 +1,63 @@+// @vitest-environment jsdom+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';+import { afterEach, beforeEach, expect, it, vi } from 'vitest';+import type { ComponentProps } from 'react';+import { remoteProjectsStore } from '@/features/device-link/remoteProjectsStore';+import { __resetStickySessionOriginForTest } from '@/features/device-link/stickySessionOrigin';+import { BotAuthorizationCardView } from '../BotAuthorizationCard';+import type { PluginSetupPrompt } from '@/components/new-chat/PluginSetupPrompt';++vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));+vi.mock('@/components/new-chat/PluginSetupPrompt', () => ({+ PluginSetupPrompt: ({ onCommand, commandInFlight }: ComponentProps<typeof PluginSetupPrompt>) => <>+ <button disabled={!!commandInFlight} onClick={() => onCommand('request', 'cancel')}>Cancel</button>+ <button disabled={!!commandInFlight} onClick={() => onCommand('request', 'submit_form', 'key', { value: 'fake-secret' })}>Submit</button>+ </>,+}));+const local = vi.fn(async () => ({ accepted: true }));+const submit = vi.fn(async () => ({ accepted: true }));+const invoke = vi.fn(async () => ({ accepted: true }));+const card = { v: 1, sessionId: 'session', createdAt: 1, target: { kind: 'plugin', id: 'p' },+ snapshot: { kind: 'plugin_setup', requestId: 'request', revision: 3, ghost: { id: 'p', name: 'Plugin' }, steps: [] } };+beforeEach(() => {+ remoteProjectsStore.clear();+ remoteProjectsStore.__resetPinnedOriginsForTest();+ __resetStickySessionOriginForTest();+ vi.clearAllMocks();+ window.electronAPI = { maker: { resolveInteraction: local, submitPluginSetupInline: submit },+ deviceLink: { invoke } } as unknown as typeof window.electronAPI;+});+afterEach(cleanup);++it.each([false, true])('routes remote cancellation to its owner, including reconnect=%s', async (reconnect) => {+ remoteProjectsStore.pinSessionOrigin('owner-device', 'session');+ render(<BotAuthorizationCardView sessionId="session" data={card} />);+ if (reconnect) {+ remoteProjectsStore.clear();+ remoteProjectsStore.__resetPinnedOriginsForTest();+ }+ fireEvent.click(screen.getByText('Cancel'));+ await waitFor(() => expect(invoke).toHaveBeenCalledWith('owner-device', 'maker:resolve-interaction', [+ 'request', { kind: 'plugin_setup', action: 'cancel', expectedRevision: 3 },+ ]));+ expect(local).not.toHaveBeenCalled();+});++it('rejects remote secret submissions at the callback boundary', () => {+ remoteProjectsStore.pinSessionOrigin('owner-device', 'session');+ render(<BotAuthorizationCardView sessionId="session" data={card} />);+ fireEvent.click(screen.getByText('Submit'));+ expect(submit).not.toHaveBeenCalled();+ expect(local).not.toHaveBeenCalled();+ expect(invoke).not.toHaveBeenCalled();+});++it('keeps local cancellation and secret submission on the local maker', async () => {+ render(<BotAuthorizationCardView sessionId="session" data={card} />);+ fireEvent.click(screen.getByText('Cancel'));+ await waitFor(() => expect(local).toHaveBeenCalled());+ await waitFor(() => expect((screen.getByText('Submit') as HTMLButtonElement).disabled).toBe(false));+ fireEvent.click(screen.getByText('Submit'));+ await waitFor(() => expect(submit).toHaveBeenCalledWith({ requestId: 'request', actionId: 'key', expectedRevision: 3, value: 'fake-secret' }));+ expect(invoke).not.toHaveBeenCalled();+});