ytahdn c18385ec02
feat(web-shell): UI improvements, subagent rendering, and scroll-follow rewrite (#4655)
* feat(web-shell): improve UI components and message formatting

- Refine dialog styles, editor layout, and welcome header
- Add tool formatting utilities with tests
- Update message list, shortcuts panel, and agent dialog
- Improve markdown rendering and tool chrome styles
- Enhance input history hook and i18n support

* feat(web-shell): improve /tools, /skills, agents dialog and compact mode

- /tools: show simple list by default, /tools desc opens detail dialog
- /tools, /skills: insert user message before showing results
- AgentsDialog: add onMessage callback for success feedback, add Ctrl+D
  shortcut for delete in manage mode, show shortcut hint in detail view
- AgentsDialog create form: add arrow key hint in footer
- ToolsDialog: hide show-details and disable buttons
- DialogPrimitives: enlarge item prefix indicator, add shortcut style
- Fix compact mode dispatching duplicate status messages
- Update i18n descriptions to align with CLI behavior

* feat(web-shell): virtual scrolling, rendering perf, and Shift+Tab approval mode cycling

- Introduce @tanstack/react-virtual for virtualized message list scrolling,
  reducing DOM node count for long conversations
- Add WeakMap-based JSON stringify cache and reference equality fast path
  in MessageItem memo comparator
- Add useShallowMemo/useStableArray hooks to stabilize pendingApproval,
  floatingTodos, and floatingAgents references
- Add Shiki code highlighting LRU cache (128 entries) with synchronous
  cache-hit path
- Add custom areToolLinePropsEqual comparator for ToolLine memo and narrow
  useEffect deps in ToolGroup
- Align Shift+Tab with CLI: cycle approval modes (plan → default →
  auto-edit → auto → yolo) instead of direct allow_always submission
- Auto-approve pending permission on mode change: yolo approves all,
  auto-edit approves edit tools only (via toolCall.kind from daemon event)
- Add toolKind field to PermissionRequest extracted from toolCall.kind
- Add auto mode status bar indicator with warning color
- Show auto mode entry notice in message area
- Remove mouse hover interaction on ToolApproval to avoid confusion
  with keyboard selection

Generated with AI

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>

* feat(web-shell,webui,sdk): subagent rendering, scroll, and transcript fixes

- Synthesize tool.update in normalizer for Agent permission_request to fix
  orphaned sub-tool blocks when daemon skips emitStart
- Rewrite transcriptToMessages to match agent completions by callId instead
  of stack order, fixing parallel agent merge/cancel/background scenarios
- Add background agent detection: keep status as pending with no endTime
  for agents launched with run_in_background or status:'background'
- Handle cancelled/canceled agent status with proper rawOutput enrichment
  (status + reason fields) and display as failed in UI components
- Improve scroll-to-bottom: track programmatic vs user scrolls, use
  followBottomSignal from submit, fix auto-scroll sticking on user scroll-up
- Add isNavigating to useInputHistory so ArrowUp/Down prioritizes history
  browsing over autocomplete dropdown
- Render Agent tools inline in ToolGroup with summary line (type, description,
  tool count, elapsed, tokens, cancellation reason) and expandable SubAgentPanel
- Support sub-tool approval matching: recurse into subTools tree to find
  pending approval targets within nested agents
- Add i18n keys for approval options and request.cancelled (EN + ZH)
- Bump base font size from 12px to 14px in App and Markdown
- Add maxBlocks config prop to DaemonSessionProvider
- Increase ActiveAgentsPanel MAX_VISIBLE from 5 to 10
- Add virtualizer getItemKey and useAnimationFrameWithResizeObserver
- Extensive test coverage for transcript conversion edge cases

* refactor(web-shell): rewrite scroll-follow logic with 6 clear rules

Replace the previous scroll implementation (5 overlapping effects,
4 fragile refs, rAF-based programmaticScroll flag) with a clean,
predictable design driven by 6 documented rules:

1. Default follow-bottom on content height changes via single
   useLayoutEffect on virtualizer totalSize
2. Scroll-up pauses follow (direction detection in onScroll)
3. Scroll-back-to-bottom (< 30px) resumes follow
4. New user message forces follow on
5. Session restore: suppress scroll during catchingUp, scroll
   once on replay_complete transition
6. Short content (no scrollbar): scrollToBottom is a no-op

- Remove followBottomSignal state and handleEditorSubmit wrapper
  from App.tsx; pass connection.catchingUp to MessageList instead
- Consolidate from 5 effects to 3, from 4 refs to 3
- Add detailed block comment documenting all 6 rules and the
  implementation structure

* fix(web-shell): stabilize daemon transcript rendering

* fix(web-shell): refine agent rendering feedback

* fix(web-shell): address review feedback

* chore(sdk): bump browser bundle size limit to 105KB

The daemon browser SDK bundle grew to ~103KB due to normalizer
enhancements for permission-based subagent rendering.

* fix(web-shell): address review feedback

* fix(web-shell): address review feedback

* fix(webui): avoid duplicate ask user question prompt

* fix(web-shell): sync package lockfile

---------

Co-authored-by: ytahdn <ytahdn@gmail.com>
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-06-01 11:20:41 +08:00

92 lines
2.4 KiB
TypeScript

import type { DaemonTranscriptBlock } from '@qwen-code/webui/daemon-react-sdk';
import type { PermissionRequest, PermissionOptionKind } from './types';
type PermissionTranscriptBlock = Extract<
DaemonTranscriptBlock,
{ kind: 'permission' }
>;
export function extractPendingPermission(
blocks: readonly DaemonTranscriptBlock[],
): PermissionRequest | null {
for (const block of blocks) {
if (!isPermissionBlock(block)) continue;
const perm = block;
if (perm.resolved) continue;
const toolCallRecord = getRecord(perm.toolCall);
const toolCallId =
typeof toolCallRecord?.['toolCallId'] === 'string'
? toolCallRecord['toolCallId']
: typeof toolCallRecord?.['id'] === 'string'
? toolCallRecord['id']
: undefined;
const toolKind =
typeof toolCallRecord?.['kind'] === 'string'
? toolCallRecord['kind']
: undefined;
return {
id: perm.requestId,
sessionId: perm.sessionId,
toolCallId,
title: perm.title,
toolKind,
content: [
{
type: 'text',
text: perm.title || 'Tool permission',
},
],
options: perm.options.map((opt) => ({
id: opt.optionId,
label: opt.label,
kind: getPermissionOptionKind(opt.raw),
})),
rawInput: getPermissionRawInput(perm.toolCall),
};
}
return null;
}
function isPermissionBlock(
block: DaemonTranscriptBlock,
): block is PermissionTranscriptBlock {
return block.kind === 'permission';
}
function getPermissionRawInput(
toolCall: unknown,
): Record<string, unknown> | undefined {
const record = getRecord(toolCall);
if (!record) {
return undefined;
}
const nested =
getRecord(record['rawInput']) ??
getRecord(record['input']) ??
getRecord(record['args']);
return nested ?? record;
}
function getRecord(value: unknown): Record<string, unknown> | undefined {
if (!value || typeof value !== 'object' || Array.isArray(value)) {
return undefined;
}
return value as Record<string, unknown>;
}
function getPermissionOptionKind(
raw: unknown,
): PermissionOptionKind | undefined {
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
return undefined;
}
const kind = (raw as Record<string, unknown>).kind;
return kind === 'allow_once' ||
kind === 'allow_always' ||
kind === 'reject_once' ||
kind === 'reject_always'
? kind
: undefined;
}