Skip to content

feat(desktop): system-level alerts for pending tool approvals (toast, taskbar flash, sidebar badge, title) - #692

Open
wcy12378 wants to merge 1 commit into
OpenBMB:mainfrom
wcy12378:feat/691-approval-notification
Open

wcy12378 wants to merge 1 commit into
OpenBMB:mainfrom
wcy12378:feat/691-approval-notification

Conversation

@wcy12378

Copy link
Copy Markdown

Problem

On the desktop app (Windows, but applies cross-platform), when an agent run requests a tool approval, there is no system-level reminder: no Windows toast, no taskbar flash, no tray change, and the sidebar session item shows no "waiting for approval" state. A user who leaves PilotDeck in the background only finds out by manually switching back, leaving the run stalled indefinitely (#691).

Solution (combined toast + flash + badge + title, as suggested in the issue)

Renderer (ui/):

  • New useApprovalWaitingAlert hook (wired into ChatInterfaceV2) observes the session's pending permission queue (pendingPermissionRequests):
    • On the idle -> waiting transition while the window is unfocused, it calls the desktop bridge for a native toast + taskbar flash (a focused window already shows the in-app approval banner, so no redundant toast).
    • On waiting -> idle it clears the desktop alert.
    • Broadcasts pilotdeck:approval-waiting (CustomEvent with waiting session ids) and prefixes document.title with the localized ⚠ Waiting for approval (+ count when > 1); both fully restored on resolve or unmount.
  • AppShellV2 listens for the broadcast and passes the set to SidebarV2, which shows an amber awaiting-approval badge (TriangleAlert icon) on the session row — highest priority over processing/unread — so the waiting session stays findable even after navigating away. Includes optimistic-row fallback for requests that arrive before session_created.
  • Graceful degradation: plain-web builds or older desktop builds without the bridge keep the badge + title channels and simply skip the toast/flash.

Desktop main process (apps/desktop/src/):

  • pilotdeck:approval-waiting / pilotdeck:approval-clear IPC handlers:
    • Native Notification (localized zh/en, e.g. "An operation is waiting for your approval."), click focuses/opens the window.
    • flashFrame(true/false) on the taskbar.
    • Tray tooltip becomes PilotDeck — Waiting for approval while waiting.
    • Window focus automatically ends the flashing episode.

i18n: en + zh-CN strings for the title prefix and sidebar badge.

Red-line files untouched

ui/src/shared/modelListApi.ts, ProviderCard.tsx, parseModelConfig.ts, catalogProviders.ts, ui/server/routes/config.js are not modified.

Testing

New unit tests (18 cases, all passing):

> vitest run src/utils/approvalAlert.test.ts src/components/chat/hooks/useApprovalWaitingAlert.test.tsx
 Test Files  2 passed (2)
      Tests  18 passed (18)

Coverage includes: unfocused window notifies the bridge exactly once per episode; focused window skips the toast but still badges + titles; queue drain restores title/badge and calls clear only if a notification was raised; unmount mid-waiting restores everything; optimistic session-id fallback; missing bridge degradation.

Regression + lint + typecheck:

> vitest run ... src/components/app-shell/SidebarV2.test.tsx src/components/app-shell/MainAreaV2.test.tsx
 Test Files  4 passed (4)      Tests  44 passed (44)

> eslint <changed files>          # 0 problems on all new/changed files
> tsc --noEmit (apps/desktop)     # exit 0
> tsc --noEmit (ui)               # 0 errors in all files touched by this PR;
                                  # the repo baseline has pre-existing lucide-react/@types/react
                                  # JSX typing errors (546 on a clean tree, verified via git stash),
                                  # unrelated to this change

Fixes #691

When an agent run needs a tool approval and the PilotDeck window is in
the background, desktop users had no way to know until they switched
back, leaving runs stalled indefinitely (fixes OpenBMB#691).

Renderer:
- add useApprovalWaitingAlert hook observing the pending permission
  queue of the viewed session; on the idle-to-waiting transition while
  the window is unfocused it asks the desktop bridge for a native
  toast + taskbar flash, and clears them when the queue drains
- broadcast pilotdeck:approval-waiting with the waiting session ids and
  prefix the document title ("⚠ Waiting for approval (N)") so the
  taskbar/alt-tab entry reflects the state; restored on resolve/unmount
- AppShellV2 listens for the broadcast and SidebarV2 shows an amber
  awaiting-approval badge on the session row (highest priority over
  processing/unread), so the waiting session stays findable after
  navigating away
- degradation: plain-web builds or older desktop builds without the
  bridge keep the badge + title channels and simply skip the toast

Desktop main process:
- pilotdeck:approval-waiting / pilotdeck:approval-clear IPC: native
  Notification (localized zh/en, click focuses the window), taskbar
  flashFrame, tray tooltip "PilotDeck — Waiting for approval";
  window focus ends the flashing episode

Tests: 18 new vitest cases for the alert utils and hook; existing
SidebarV2/MainAreaV2 suites unaffected.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

【功能建议】等待授权时缺少系统级提醒(托盘图标/任务栏闪烁/Windows 通知)

1 participant