Repository navigation
[Prototype, do not merge] feat(samples): add the inbox decisions card and catalog - #4383
josemontespg wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces an interactive inbox assistant MCP server using A2UI v1.0, including custom components like Avatar, BusyNote, and a taller TextField, along with card composition logic, validation helpers, and tests. The review feedback highlights two key improvement opportunities: making the initials extraction in avatar.ts Unicode-safe to correctly handle surrogate pairs, and clearing the MutationObserver reference in disconnectedCallback within busy_note.ts to prevent potential memory leaks.
| export function initials(name: string): string { | ||
| const words = name | ||
| .replace(/[^\p{L}\p{N}\s]/gu, ' ') | ||
| .split(/\s+/) | ||
| .filter(Boolean); | ||
| const letters = | ||
| words.length > 1 ? words[0]!.charAt(0) + words[1]!.charAt(0) : (words[0] ?? '').slice(0, 2); | ||
| return letters.toUpperCase() || '?'; | ||
| } |
There was a problem hiding this comment.
The initials function uses charAt(0) and slice(0, 2) directly on strings, which is not Unicode-safe for surrogate pairs (e.g., emojis or non-BMP characters). If a sender's name starts with a surrogate pair, charAt(0) will return an incomplete surrogate, resulting in rendering issues. Consider using a Unicode-aware approach like spreading the string into an array ([...str]) to safely extract characters.
export function initials(name: string): string {
const words = name
.replace(/[^\p{L}\p{N}\s]/gu, ' ')
.split(/\s+/)
.filter(Boolean);
const firstChar = (str: string) => [...str][0] ?? '';
const letters =
words.length > 1
? firstChar(words[0]!) + firstChar(words[1]!)
: [...(words[0] ?? '')].slice(0, 2).join('');
return letters.toUpperCase() || '?';
}| override disconnectedCallback(): void { | ||
| super.disconnectedCallback(); | ||
| this.observer?.disconnect(); | ||
| clearTimeout(this.timer); | ||
| } |
There was a problem hiding this comment.
In disconnectedCallback, the MutationObserver is disconnected, but the reference to this.observer is not cleared. Since the observer's callback closure captures target (the ancestor element), keeping a reference to this.observer on the element instance can prevent target and the entire subtree from being garbage collected if the element instance itself is retained in memory. Setting this.observer = undefined in disconnectedCallback avoids this potential memory leak.
| override disconnectedCallback(): void { | |
| super.disconnectedCallback(); | |
| this.observer?.disconnect(); | |
| clearTimeout(this.timer); | |
| } | |
| override disconnectedCallback(): void { | |
| super.disconnectedCallback(); | |
| this.observer?.disconnect(); | |
| this.observer = undefined; | |
| clearTimeout(this.timer); | |
| } |
Internal M1 proof-of-concept sample for @a2ui/embed (A2UI in MCP Apps), not meant to merge. Builds on #4334.
Summary
Third of four PRs for the inbox decisions sample. This one composes the card from the decision list: a header with the count and a time estimate, tabs by group with counts, compact rows with the pick pre-selected, a Details dialog per item and an Apply button that opens a confirm step.
The layout is per call: only the groups and controls of the decisions found this time. Email text only reaches the card through the data model, never through component properties.
Changes
src/catalog/: the basic catalog withoutIcon, plus an initialsAvatar, aBusyNotestatus line ("Rewriting your reply…" while an action runs), aTextFieldwith a taller multi-line box, and abyChoicefunction so a row's reason and "What happens" lines follow the selected chip.src/compose/card.ts: rows for each decision type, the confirm panel, the "All done" view that lists every applied item with Undo, and a small card when a group has nothing left. The shared data model stays under 12 KiB; applied items keep only what their done row shows.src/compose/summary.ts: the text summary the model reads, with each pick, its reason, the other choices and what was already applied.a2ui-embed.config.ts: builds the app HTML with the catalog.Verification
yarn install --immutableinsamples/community, thenyarn build(tscanda2ui-embed build) andyarn lintpass.yarn test: 51 tests pass, including server-side validation of every card variant.