🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat(approval-island): let goal asks be dismissed from the island (#20755)
Arvin Xud8da6cfd4d70
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.jsonindex 57e6f688669..2d98a65f5c4 100644--- a/locales/en-US/chat.json+++ b/locales/en-US/chat.json@@ -424,6 +424,9 @@"gatewayMode.cardTitle": "Agent Gateway Mode","gatewayMode.desc": "Run agents in the cloud through LobeHub's Agent Gateway. Tasks keep running even after you close the page.","globalApproval.collapse": "Collapse",+ "globalApproval.dismiss": "Dismiss",+ "globalApproval.dismissHint": "Hide it here; it stays on Home",+ "globalApproval.dismissed": "Dismissed. You can still handle it from Home.","globalApproval.goToConversation": "Open conversation","globalApproval.moreCount_one": "{{count}} more pending","globalApproval.moreCount_other": "{{count}} more pending",diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.jsonindex b18813a5570..8e0d2577b64 100644--- a/locales/zh-CN/chat.json+++ b/locales/zh-CN/chat.json@@ -424,6 +424,9 @@"gatewayMode.cardTitle": "Agent Gateway 模式","gatewayMode.desc": "通过 LobeHub 的 Agent Gateway 在云端执行 Agent,即使关闭网页,任务也会继续运行。","globalApproval.collapse": "收起",+ "globalApproval.dismiss": "忽略",+ "globalApproval.dismissHint": "只在这里隐藏,首页仍保留",+ "globalApproval.dismissed": "已忽略,可在首页继续处理","globalApproval.goToConversation": "打开会话","globalApproval.moreCount_one": "还有 {{count}} 个待审批","globalApproval.moreCount_other": "还有 {{count}} 个待审批",diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.tsindex 0a80ad9ba7f..a0410f74bda 100644--- a/packages/locales/src/default/chat.ts+++ b/packages/locales/src/default/chat.ts@@ -1467,6 +1467,9 @@ export default {'floatingChatPanel.collapse': 'Collapse chat','floatingChatPanel.expand': 'Expand chat','globalApproval.collapse': 'Collapse',+ 'globalApproval.dismiss': 'Dismiss',+ 'globalApproval.dismissHint': 'Hide it here; it stays on Home',+ 'globalApproval.dismissed': 'Dismissed. You can still handle it from Home.','globalApproval.goToConversation': 'Open conversation','globalApproval.moreCount_one': '{{count}} more pending','globalApproval.moreCount_other': '{{count}} more pending',diff --git a/src/features/GlobalApprovalNotification/GoalClarificationCard.tsx b/src/features/GlobalApprovalNotification/GoalClarificationCard.tsxindex 663da40e21d..60d9c6deb6a 100644--- a/src/features/GlobalApprovalNotification/GoalClarificationCard.tsx+++ b/src/features/GlobalApprovalNotification/GoalClarificationCard.tsx@@ -1,7 +1,7 @@'use client';import { Icon } from '@lobehub/ui';-import { ActionIcon } from '@lobehub/ui/base-ui';+import { ActionIcon, Button } from '@lobehub/ui/base-ui';import { ArrowUpRight, ChevronUp, Target } from 'lucide-react';import { memo, useState } from 'react';import { useTranslation } from 'react-i18next';@@ -16,71 +16,87 @@ import type { GoalClarificationGroup } from './usePendingGoalClarifications';interface GoalClarificationCardProps {group: GoalClarificationGroup;onCollapse?: () => void;+ /** Hide this ask from the island; it keeps waiting in the Home inbox. */+ onDismiss?: () => void;}/*** A goal's clarification round in the island: the same form the goal page* shows, answerable from wherever the user is.*/-const GoalClarificationCard = memo<GoalClarificationCardProps>(({ group, onCollapse }) => {- const { t } = useTranslation('chat');- const navigate = useWorkspaceAwareNavigate();- const [actionsPortalTarget, setActionsPortalTarget] = useState<HTMLDivElement | null>(null);+const GoalClarificationCard = memo<GoalClarificationCardProps>(+ ({ group, onCollapse, onDismiss }) => {+ const { t } = useTranslation('chat');+ const navigate = useWorkspaceAwareNavigate();+ const [actionsPortalTarget, setActionsPortalTarget] = useState<HTMLDivElement | null>(null);- const openGoal = () =>- navigate(- group.agentId ? `/agent/${group.agentId}/goal/${group.goalId}` : `/goal/${group.goalId}`,- );+ const openGoal = () =>+ navigate(+ group.agentId ? `/agent/${group.agentId}/goal/${group.goalId}` : `/goal/${group.goalId}`,+ );- return (- <div data-pending-hotkey-scope className={styles.card}>- <div className={styles.header}>- <Icon icon={Target} size={18} />- {/* The goal's own title leads, the same way a run approval leads with its+ return (+ <div data-pending-hotkey-scope className={styles.card}>+ <div className={styles.header}>+ <Icon icon={Target} size={18} />+ {/* The goal's own title leads, the same way a run approval leads with itsagent — several goals can be waiting, and this is how to tell them apart. */}- <div className={styles.headerMeta} title={group.title}>- <div className={styles.headerSubtitle}>- <span>{group.title}</span>- {t('goalProcess.clarify.islandSubtitle')}+ <div className={styles.headerMeta} title={group.title}>+ <div className={styles.headerSubtitle}>+ <span>{group.title}</span>+ {t('goalProcess.clarify.islandSubtitle')}+ </div></div>- </div>- <ActionIcon- icon={ArrowUpRight}- size="small"- title={t('goalProcess.clarify.openGoal')}- onClick={openGoal}- />- {onCollapse && (<ActionIcon- icon={ChevronUp}+ icon={ArrowUpRight}size="small"- title={t('globalApproval.collapse')}- onClick={onCollapse}+ title={t('goalProcess.clarify.openGoal')}+ onClick={openGoal}/>- )}- </div>+ {onCollapse && (+ <ActionIcon+ icon={ChevronUp}+ size="small"+ title={t('globalApproval.collapse')}+ onClick={onCollapse}+ />+ )}+ </div>- {group.requirement && (- <div className={styles.requestContext}>- <div className={styles.userRequestBody}>- <MarkdownMessage>{group.requirement}</MarkdownMessage>+ {group.requirement && (+ <div className={styles.requestContext}>+ <div className={styles.userRequestBody}>+ <MarkdownMessage>{group.requirement}</MarkdownMessage>+ </div></div>+ )}++ <div className={styles.content}>+ <GoalClarification+ actionsPortalTarget={actionsPortalTarget}+ goalId={group.goalId}+ key={group.goalId}+ pending={group.questions}+ /></div>- )}- <div className={styles.content}>- <GoalClarification- actionsPortalTarget={actionsPortalTarget}- goalId={group.goalId}- key={group.goalId}- pending={group.questions}- />+ <div className={styles.goalActions}>+ {onDismiss && (+ <Button+ size="small"+ title={t('globalApproval.dismissHint')}+ type="text"+ onClick={onDismiss}+ >+ {t('globalApproval.dismiss')}+ </Button>+ )}+ <div className={styles.goalActionsSlot} ref={setActionsPortalTarget} />+ </div></div>-- <div className={styles.actions} ref={setActionsPortalTarget} />- </div>- );-});+ );+ },+);GoalClarificationCard.displayName = 'GoalClarificationCard';diff --git a/src/features/GlobalApprovalNotification/GoalDecisionCard.tsx b/src/features/GlobalApprovalNotification/GoalDecisionCard.tsxindex 7b9ec422c9a..1b0d457f647 100644--- a/src/features/GlobalApprovalNotification/GoalDecisionCard.tsx+++ b/src/features/GlobalApprovalNotification/GoalDecisionCard.tsx@@ -1,6 +1,6 @@'use client';-import { ActionIcon, toast } from '@lobehub/ui/base-ui';+import { ActionIcon, Button, toast } from '@lobehub/ui/base-ui';import { ArrowUpRight, ChevronUp } from 'lucide-react';import { useCallback, useMemo, useState } from 'react';import { useTranslation } from 'react-i18next';@@ -26,6 +26,8 @@ import type { IslandGoalItem } from './usePendingGoalDecisions';interface GoalDecisionCardProps {item: IslandGoalItem;onCollapse?: () => void;+ /** Hide this ask from the island; it keeps waiting in the Home inbox. */+ onDismiss?: () => void;}const SIGN_OFF = { accept: 'signOff', requestChanges: 'requestChanges' } as const;@@ -35,7 +37,7 @@ const SIGN_OFF = { accept: 'signOff', requestChanges: 'requestChanges' } as cons* page asks, answerable from wherever the user is. The goal's own title leads,* the way a run approval leads with its agent — several goals can be waiting.*/-const GoalDecisionCard = ({ item, onCollapse }: GoalDecisionCardProps) => {+const GoalDecisionCard = ({ item, onCollapse, onDismiss }: GoalDecisionCardProps) => {const { t } = useTranslation('chat');const navigate = useWorkspaceAwareNavigate();const decideGoal = useGoalStore((s) => s.decideGoal);@@ -177,7 +179,19 @@ const GoalDecisionCard = ({ item, onCollapse }: GoalDecisionCardProps) => {)}</div>- <div className={styles.actions} ref={setActionsPortalTarget} />+ <div className={styles.goalActions}>+ {onDismiss && (+ <Button+ size="small"+ title={t('globalApproval.dismissHint')}+ type="text"+ onClick={onDismiss}+ >+ {t('globalApproval.dismiss')}+ </Button>+ )}+ <div className={styles.goalActionsSlot} ref={setActionsPortalTarget} />+ </div></div>);};diff --git a/src/features/GlobalApprovalNotification/index.tsx b/src/features/GlobalApprovalNotification/index.tsxindex 8cc50df25bf..74c1c59ca9c 100644--- a/src/features/GlobalApprovalNotification/index.tsx+++ b/src/features/GlobalApprovalNotification/index.tsx@@ -1,9 +1,10 @@'use client';import { TITLE_BAR_HEIGHT } from '@lobechat/desktop-bridge';+import { toast } from '@lobehub/ui/base-ui';import { AnimatePresence } from 'motion/react';import * as m from 'motion/react-m';-import { memo } from 'react';+import { memo, useMemo } from 'react';import { useTranslation } from 'react-i18next';import { isDesktop } from '@/const/version';@@ -14,6 +15,7 @@ import GoalDecisionCard from './GoalDecisionCard';import { styles } from './styles';import { useApprovalIslandCollapse } from './useApprovalIslandCollapse';import { useGlobalPendingApprovals } from './useGlobalPendingApprovals';+import { goalClarificationIslandKey, useIslandDismissals } from './useIslandDismissals';import { usePendingGoalClarifications } from './usePendingGoalClarifications';import { usePendingGoalDecisions } from './usePendingGoalDecisions';@@ -35,10 +37,25 @@ const GlobalApprovalNotification = memo(() => {const groups = useGlobalPendingApprovals();// A goal waiting on its clarification round asks through the same island.// Run approvals go first: a run is blocked mid-turn, a goal has not started.- const goalGroups = usePendingGoalClarifications();+ const pendingGoalGroups = usePendingGoalClarifications();// Then the gates a running goal stopped on, then finished goals awaiting// sign-off — each blocks less than the one before it.- const goalItems = usePendingGoalDecisions();+ const pendingGoalItems = usePendingGoalDecisions();+ // Goal asks the user waved off leave the island but stay in the Home inbox,+ // so they are never lost — a run approval has no such fallback and stays.+ const { dismiss: dismissKey, dismissed } = useIslandDismissals();+ const dismiss = (key: string) => {+ dismissKey(key);+ toast.info({ placement: 'top', title: t('globalApproval.dismissed') });+ };+ const goalGroups = useMemo(+ () => pendingGoalGroups.filter((group) => !dismissed.has(goalClarificationIslandKey(group))),+ [dismissed, pendingGoalGroups],+ );+ const goalItems = useMemo(+ () => pendingGoalItems.filter((item) => !dismissed.has(item.key)),+ [dismissed, pendingGoalItems],+ );const total = groups.length + goalGroups.length + goalItems.length;const [collapsed, setCollapsed] = useApprovalIslandCollapse(total);@@ -104,7 +121,11 @@ const GlobalApprovalNotification = memo(() => {style={{ pointerEvents: 'auto', width: '100%' }}transition={SPRING}>- <GoalClarificationCard group={topGoal} onCollapse={() => setCollapsed(true)} />+ <GoalClarificationCard+ group={topGoal}+ onCollapse={() => setCollapsed(true)}+ onDismiss={() => dismiss(goalClarificationIslandKey(topGoal))}+ /></m.div>)}{topGoalItem && (@@ -117,7 +138,11 @@ const GlobalApprovalNotification = memo(() => {style={{ pointerEvents: 'auto', width: '100%' }}transition={SPRING}>- <GoalDecisionCard item={topGoalItem} onCollapse={() => setCollapsed(true)} />+ <GoalDecisionCard+ item={topGoalItem}+ onCollapse={() => setCollapsed(true)}+ onDismiss={() => dismiss(topGoalItem.key)}+ /></m.div>)}</AnimatePresence>diff --git a/src/features/GlobalApprovalNotification/styles.ts b/src/features/GlobalApprovalNotification/styles.tsindex 3af1e977fcc..5f7a449488b 100644--- a/src/features/GlobalApprovalNotification/styles.ts+++ b/src/features/GlobalApprovalNotification/styles.ts@@ -13,6 +13,23 @@ export const styles = createStaticStyles(({ css, cssVar }) => ({display: none;}`,+ // Goal cards' footer: the dismiss text button on the left, the form's own+ // actions (portal target) filling the rest.+ goalActions: css`+ display: flex;+ gap: 8px;+ align-items: center;++ padding-block: 8px 12px;+ padding-inline: 12px;+ border-block-start: 1px solid ${cssVar.colorBorderSecondary};++ background: color-mix(in srgb, ${cssVar.colorBgElevated} 92%, ${cssVar.colorFillSecondary});+ `,+ goalActionsSlot: css`+ flex: 1;+ min-width: 0;+ `,card: css`pointer-events: auto;diff --git a/src/features/GlobalApprovalNotification/useIslandDismissals.test.ts b/src/features/GlobalApprovalNotification/useIslandDismissals.test.tsnew file mode 100644index 00000000000..c8fdf87d1ba--- /dev/null+++ b/src/features/GlobalApprovalNotification/useIslandDismissals.test.ts@@ -0,0 +1,38 @@+import { describe, expect, it } from 'vitest';++import {+ appendDismissedIslandKey,+ goalClarificationIslandKey,+ MAX_DISMISSED_ISLAND_KEYS,+} from './useIslandDismissals';++const round = (goalId: string, decisionIds: string[]) => ({+ agentId: null,+ goalId,+ questions: decisionIds.map((decisionId) => ({ decisionId }) as any),+ title: goalId,+});++describe('appendDismissedIslandKey', () => {+ it('appends a new key and leaves a known one alone', () => {+ const current = ['a'];+ expect(appendDismissedIslandKey(current, 'b')).toEqual(['a', 'b']);+ expect(appendDismissedIslandKey(current, 'a')).toBe(current);+ });++ it('keeps only the newest keys once the cap is reached', () => {+ const full = Array.from({ length: MAX_DISMISSED_ISLAND_KEYS }, (_, i) => `k${i}`);+ const next = appendDismissedIslandKey(full, 'new');+ expect(next).toHaveLength(MAX_DISMISSED_ISLAND_KEYS);+ expect(next[0]).toBe('k1');+ expect(next.at(-1)).toBe('new');+ });+});++describe('goalClarificationIslandKey', () => {+ it('tells two rounds of the same goal apart', () => {+ expect(goalClarificationIslandKey(round('g1', ['d1', 'd2']))).not.toBe(+ goalClarificationIslandKey(round('g1', ['d3'])),+ );+ });+});diff --git a/src/features/GlobalApprovalNotification/useIslandDismissals.ts b/src/features/GlobalApprovalNotification/useIslandDismissals.tsnew file mode 100644index 00000000000..822c4388bfc--- /dev/null+++ b/src/features/GlobalApprovalNotification/useIslandDismissals.ts@@ -0,0 +1,44 @@+import { useCallback, useMemo } from 'react';++import { useGlobalStore } from '@/store/global';++import type { GoalClarificationGroup } from './usePendingGoalClarifications';++/**+ * Old keys point at asks long since answered, so only the newest ones are worth+ * keeping. The cap holds the array's length steady once reached:+ * `updateSystemStatus` merges arrays by index and could never shrink it.+ */+export const MAX_DISMISSED_ISLAND_KEYS = 200;++export const appendDismissedIslandKey = (current: string[], key: string): string[] =>+ current.includes(key) ? current : [...current, key].slice(-MAX_DISMISSED_ISLAND_KEYS);++/**+ * A clarification round is keyed by its questions, not just its goal: waving+ * off one round must not hide the next round the same goal asks.+ */+export const goalClarificationIslandKey = (group: GoalClarificationGroup): string =>+ `goal-clarify:${group.goalId}:${group.questions.map((q) => q.decisionId).join(',')}`;++/**+ * Asks the user put away from the island. Dismissing only hides the island+ * card; the ask itself stays pending and keeps waiting in the Home inbox.+ */+export const useIslandDismissals = () => {+ const keys = useGlobalStore((s) => s.status.dismissedIslandItemKeys);+ const updateSystemStatus = useGlobalStore((s) => s.updateSystemStatus);++ const dismissed = useMemo(() => new Set(keys), [keys]);++ const dismiss = useCallback(+ (key: string) => {+ const current = useGlobalStore.getState().status.dismissedIslandItemKeys || [];+ const next = appendDismissedIslandKey(current, key);+ if (next !== current) updateSystemStatus({ dismissedIslandItemKeys: next });+ },+ [updateSystemStatus],+ );++ return { dismiss, dismissed };+};diff --git a/src/store/global/initialState.ts b/src/store/global/initialState.tsindex 0ecb92e8068..338af647664 100644--- a/src/store/global/initialState.ts+++ b/src/store/global/initialState.ts@@ -194,6 +194,12 @@ export interface SystemStatus {* so dismissing the current one does not hide future ones.*/dismissedBannerIds?: string[];+ /**+ * Keys of goal asks (clarification rounds, gates, sign-offs) the user waved+ * off the approval island. Only the island honours them — the same ask stays+ * in the Home inbox. Append-only and capped, see `appendDismissedIslandKey`.+ */+ dismissedIslandItemKeys?: string[];/*** Per-agent expanded state of the agent sidebar's top-level sections* (Tasks / Topic), keyed by agentId. Lets each agent remember its own