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(bots): 邀请卸载时关闭未答的跟进确认框

zqchris08897952a127
diff --git a/apps/desktop/src/renderer/features/bots/BotFollowUpInvitation.tsx b/apps/desktop/src/renderer/features/bots/BotFollowUpInvitation.tsx
index fccc0f0396..9bf7a05aa9 100644
--- a/apps/desktop/src/renderer/features/bots/BotFollowUpInvitation.tsx
+++ b/apps/desktop/src/renderer/features/bots/BotFollowUpInvitation.tsx
@@ -41,18 +41,24 @@ export function BotFollowUpInvitationCard({ pending, onChoose, consent }: {
const { confirm } = useConfirmDialog();
// 卡片只占一行;读什么、会用模型额度在开启前的确认框里完整说明(与设置页同一确认),确认后才保存。
const scope = consent ?? t('bots.autonomy.consent');
- // 确认框在账号切换后仍可能开着(它挂在账号层之上),回来的结果只认发起时的账号和仍在的卡片;
+ // 确认框挂在账号层之上,卡片卸载(例如切换账号)时一并关掉;回来的结果只认发起时的账号和仍在的卡片。
// 连点只排一个确认框。
const asking = useRef(false);
const mounted = useRef(true);
+ const dialog = useRef<AbortController | null>(null);
useEffect(() => {
mounted.current = true;
- return () => { mounted.current = false; };
+ return () => {
+ mounted.current = false;
+ dialog.current?.abort();
+ };
}, []);
const start = async () => {
if (asking.current || pending) return;
asking.current = true;
const owner = getDataOwnerGeneration();
+ const controller = new AbortController();
+ dialog.current = controller;
try {
const accepted = await confirm({
presentation: 'standard',
@@ -60,10 +66,11 @@ export function BotFollowUpInvitationCard({ pending, onChoose, consent }: {
description: scope,
confirmText: t('bots.autonomy.invitation.start'),
cancelText: t('bots.autonomy.invitation.notNow'),
- });
+ }, controller.signal);
if (accepted && mounted.current && isDataOwnerGenerationCurrent(owner)) await onChoose(true);
} finally {
asking.current = false;
+ if (dialog.current === controller) dialog.current = null;
}
};
return (
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/botAutonomySettings.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/botAutonomySettings.test.tsx
index 11af99ae10..7c35e6ed05 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/botAutonomySettings.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/botAutonomySettings.test.tsx
@@ -152,7 +152,7 @@ it.each([true, false])('invites only after engagement, then persists the choice
await waitFor(() => expect(screen.queryByRole('region')).toBeNull());
expect(host.setSettings).toHaveBeenCalledWith({ schedulerBotId: enable ? 'cindy-default' : null });
// Starting shows scope and usage in the same confirmation as settings before saving; declining needs none.
- if (enable) expect(m.confirm).toHaveBeenCalledWith(expect.objectContaining({ description: 'bots.autonomy.consent' }));
+ if (enable) expect(m.confirm).toHaveBeenCalledWith(expect.objectContaining({ description: 'bots.autonomy.consent' }), expect.any(AbortSignal));
else expect(m.confirm).not.toHaveBeenCalled();
unmount();
render(<BotFollowUpInvitation botId="cindy-default" engaged />);
@@ -183,6 +183,16 @@ it('asks once for a double click and drops a confirmation that returns after the
dataOwnerTesting.reset();
});
+it('closes a pending confirmation when the invitation goes away', async () => {
+ const { unmount } = render(<BotFollowUpInvitation botId="cindy-default" engaged />);
+ m.confirm.mockImplementationOnce(() => new Promise<boolean>(() => {}));
+ fireEvent.click(await screen.findByRole('button', { name: 'bots.autonomy.invitation.start' }));
+ const signal = (m.confirm.mock.calls[0] as unknown as [unknown, AbortSignal])[1];
+ expect(signal.aborted).toBe(false);
+ unmount();
+ expect(signal.aborted).toBe(true);
+});
+
it('keeps the invitation available when saving fails', async () => {
render(<BotFollowUpInvitation botId="cindy-default" engaged />);
const button = await screen.findByRole('button', { name: 'bots.autonomy.invitation.start' });
@@ -219,7 +229,7 @@ it.each([true, false])('remote invitation uses the host-bound choice, enable=%s'
fireEvent.click(screen.getByText(enable ? 'bots.autonomy.invitation.start' : 'bots.autonomy.invitation.notNow'));
await waitFor(() => expect(screen.queryByRole('region')).toBeNull());
// The host-owned scope (not this computer's copy) is what the confirmation shows.
- if (enable) expect(m.confirm).toHaveBeenCalledWith(expect.objectContaining({ description: resource.blocks[0].fallbackMarkdown }));
+ if (enable) expect(m.confirm).toHaveBeenCalledWith(expect.objectContaining({ description: resource.blocks[0].fallbackMarkdown }), expect.any(AbortSignal));
expect(invoke).toHaveBeenLastCalledWith('host-computer', 'maker:remote-resources:invoke', [expect.objectContaining({
resourceRef: ref, actionId: enable ? 'opaque-enable' : 'opaque-dismiss', input: enable ? { enabled: true } : {},
})]);