Skip to content

[Prototype, do not merge] feat(samples): add the inbox decisions card and catalog - #4383

Closed
josemontespg wants to merge 1 commit into
inbox/2-decisionsfrom
inbox/3-card
Closed

josemontespg wants to merge 1 commit into
inbox/2-decisionsfrom
inbox/3-card

Conversation

@josemontespg

Copy link
Copy Markdown
Collaborator

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 without Icon, plus an initials Avatar, a BusyNote status line ("Rewriting your reply…" while an action runs), a TextField with a taller multi-line box, and a byChoice function 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 --immutable in samples/community, then yarn build (tsc and a2ui-embed build) and yarn lint pass.
  • yarn test: 51 tests pass, including server-side validation of every card variant.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +51 to +59
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() || '?';
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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() || '?';
}

Comment on lines +103 to +107
override disconnectedCallback(): void {
super.disconnectedCallback();
this.observer?.disconnect();
clearTimeout(this.timer);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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);
}

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.

1 participant