Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
CR6: 到达提示按批次去重,每次显示后都 dismiss
nana64f25228f43f
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/useCompanionArrivalNotice.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/useCompanionArrivalNotice.test.tsxnew file mode 100644index 0000000000..920208ede1--- /dev/null+++ b/apps/desktop/src/renderer/features/bots/__tests__/useCompanionArrivalNotice.test.tsx@@ -0,0 +1,50 @@+// @vitest-environment jsdom+import { renderHook } from '@testing-library/react';+import { beforeEach, describe, expect, it, vi } from 'vitest';++const h = vi.hoisted(() => ({+ notices: undefined as string[] | undefined,+ toast: vi.fn(),+ dismiss: vi.fn(async (_botId: string) => undefined),+ refresh: vi.fn(),+}));+vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));+vi.mock('@/lib/toast', () => ({ toast: { info: h.toast } }));+vi.mock('../companionCloudStore', () => ({+ useCompanionCloud: () => ({ actors: [{ externalId: 'mia', arrivalNotices: h.notices }] }),+ companionCloudApi: () => ({ dismissCompanionArrivalNotices: h.dismiss }),+ refreshCompanionCloud: h.refresh,+}));++import { useCompanionArrivalNotice } from '../useCompanionArrivalNotice';++describe('useCompanionArrivalNotice', () => {+ beforeEach(() => {+ h.toast.mockClear(); h.dismiss.mockClear(); h.refresh.mockClear();+ h.notices = undefined;+ });++ it('shows a notice once and dismisses it, and shows and dismisses a later arrival of the same companion again', () => {+ const view = renderHook(() => useCompanionArrivalNotice('mia', 'Mia'));+ h.notices = ['permissions'];+ view.rerender();+ expect(h.toast).toHaveBeenCalledTimes(1);+ expect(h.dismiss).toHaveBeenCalledTimes(1);+ // The snapshot has not been read back yet: a re-render does not repeat it.+ view.rerender();+ expect(h.toast).toHaveBeenCalledTimes(1);+ expect(h.dismiss).toHaveBeenCalledTimes(1);+ // Main dismissed it; the same companion arrives again in this window.+ h.notices = [];+ view.rerender();+ h.notices = ['permissions'];+ view.rerender();+ expect(h.toast).toHaveBeenCalledTimes(2);+ expect(h.dismiss).toHaveBeenCalledTimes(2);+ // A different set of notices (arrival that adds the model line) is a new batch too.+ h.notices = ['permissions', 'model'];+ view.rerender();+ expect(h.toast).toHaveBeenCalledTimes(4);+ expect(h.dismiss).toHaveBeenCalledTimes(3);+ });+});diff --git a/apps/desktop/src/renderer/features/bots/useCompanionArrivalNotice.ts b/apps/desktop/src/renderer/features/bots/useCompanionArrivalNotice.tsindex b157029d41..ff0b15eb16 100644--- a/apps/desktop/src/renderer/features/bots/useCompanionArrivalNotice.ts+++ b/apps/desktop/src/renderer/features/bots/useCompanionArrivalNotice.ts@@ -4,8 +4,12 @@ import { useTranslation } from 'react-i18next';import { toast } from '@/lib/toast';import { companionCloudApi, refreshCompanionCloud, useCompanionCloud } from './companionCloudStore';-/** Bots whose notice was already shown in this window, so a stale snapshot never repeats it. */-const shown = new Set<string>();+/**+ * The notices shown per bot in this window, so a snapshot still carrying them (before main's+ * dismissal is read back) never repeats the toast. An empty snapshot forgets them: the next arrival+ * of the same companion is a new one and shows again.+ */+const shown = new Map<string, string>();/*** One line after a companion arrived on this computer for what its old setup could not keep (the@@ -17,8 +21,14 @@ export function useCompanionArrivalNotice(botId: string | undefined, name: strinconst { t } = useTranslation();const notices = useCompanionCloud().actors.find((actor) => actor.externalId === botId)?.arrivalNotices;useEffect(() => {- if (!botId || !notices?.length || shown.has(botId)) return;- shown.add(botId);+ if (!botId) return;+ if (!notices?.length) {+ shown.delete(botId);+ return;+ }+ const batch = notices.join(',');+ if (shown.get(botId) === batch) return;+ shown.set(botId, batch);for (const notice of notices) {toast.info(t(notice === 'model' ? 'bots.cloud.arrivalModel' : 'bots.cloud.arrivalPermissions', { name: name ?? '' }));}