Skip to content

[Prototype, do not merge] feat(samples): add the inbox prototype's synthetic mailbox - #4381

Closed
josemontespg wants to merge 6 commits into
embed/5-markdownfrom
inbox/1-data
Closed

josemontespg wants to merge 6 commits into
embed/5-markdownfrom
inbox/1-data

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

First of four PRs adding samples/community/mcp/a2ui-embed-inbox, an inbox assistant as an MCP App. The agent prepares every email decision that needs the person in one card, with its pick pre-selected and the reason shown, and the person confirms once.

This PR adds the package and the demo data: a synthetic mailbox shaped like Gmail and Calendar, so the sample could read the real APIs later.

Changes

  • Package scaffold (package.json, tsconfig.json, vitest and eslint configs) and the community workspace resolutions for the local @a2ui/* packages.
  • fixtures/mailbox.json: one week for a persona, with 30 threads (labels, headers such as List-Unsubscribe, markup for bills, trips, money requests and signature requests, calendar invites), a calendar, contacts, payees with bill history and per-sender open rates. 12 threads need a decision; the rest are noise.
  • src/mail/: zod types for the mailbox and read-only queries (conflicts, free slots next week, events on a day, engagement).
  • src/format.ts and src/config.ts: plain-language formatting and paths.

Verification

  • yarn install --immutable in samples/community, then yarn build and yarn lint pass.
  • yarn test: 3 tests pass.

@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 adds a new MCP app sample, a2ui-embed-inbox, containing a synthetic mailbox dataset, query utilities, formatting helpers, and unit tests. The review feedback focuses on enhancing the robustness of date and string manipulation, specifically suggesting a simpler implementation for formatWhen, defensive handling of invalid dates in ago, case-insensitive domain matching in messagesFromDomain, a more environment-independent date formatting approach in localDay, and a more flexible timezone offset regex.

Comment on lines +21 to +30
const parts = new Intl.DateTimeFormat('en-US', {
timeZone,
weekday: 'short',
month: 'short',
day: 'numeric',
...(withTime ? {hour: 'numeric', minute: '2-digit'} : {}),
}).formatToParts(new Date(date));
const value = (type: string) => parts.find(part => part.type === type)?.value ?? '';
const day = `${value('weekday')} ${value('month')} ${value('day')}`;
return withTime ? `${day}, ${value('hour')}:${value('minute')} ${value('dayPeriod')}` : day;

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 current implementation of formatWhen manually reconstructs the formatted date string by extracting parts from formatToParts. This is complex and can be fragile if the order of parts or the exact spacing (like non-breaking spaces) varies across different Node.js/ICU versions.

Since the target format is exactly the standard en-US format but without the first comma after the weekday, we can achieve this much more simply and robustly by formatting the date directly and removing the first comma using .replace(',', '').

Suggested change
const parts = new Intl.DateTimeFormat('en-US', {
timeZone,
weekday: 'short',
month: 'short',
day: 'numeric',
...(withTime ? {hour: 'numeric', minute: '2-digit'} : {}),
}).formatToParts(new Date(date));
const value = (type: string) => parts.find(part => part.type === type)?.value ?? '';
const day = `${value('weekday')} ${value('month')} ${value('day')}`;
return withTime ? `${day}, ${value('hour')}:${value('minute')} ${value('dayPeriod')}` : day;
const formatted = new Intl.DateTimeFormat('en-US', {
timeZone,
weekday: 'short',
month: 'short',
day: 'numeric',
...(withTime ? {hour: 'numeric', minute: '2-digit'} : {}),
}).format(new Date(date));
return formatted.replace(',', '');

Comment on lines +60 to +66
export function ago(date: string, now: Date): string {
const hours = Math.max(0, (now.getTime() - Date.parse(date)) / 3_600_000);
if (hours < 1) return 'just now';
if (hours < 24) return `${Math.floor(hours)} ${Math.floor(hours) === 1 ? 'hour' : 'hours'} ago`;
const days = Math.floor(hours / 24);
return days === 1 ? 'yesterday' : `${days} days ago`;
}

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

If an invalid date string is passed to ago, Date.parse(date) will return NaN. This propagates through the math and results in returning "NaN days ago". We should add a defensive check to handle invalid dates gracefully.

Suggested change
export function ago(date: string, now: Date): string {
const hours = Math.max(0, (now.getTime() - Date.parse(date)) / 3_600_000);
if (hours < 1) return 'just now';
if (hours < 24) return `${Math.floor(hours)} ${Math.floor(hours) === 1 ? 'hour' : 'hours'} ago`;
const days = Math.floor(hours / 24);
return days === 1 ? 'yesterday' : `${days} days ago`;
}
export function ago(date: string, now: Date): string {
const parsed = Date.parse(date);
if (isNaN(parsed)) return '';
const hours = Math.max(0, (now.getTime() - parsed) / 3_600_000);
if (hours < 1) return 'just now';
if (hours < 24) return Math.floor(hours) + ' ' + (Math.floor(hours) === 1 ? 'hour' : 'hours') + ' ago';
const days = Math.floor(hours / 24);
return days === 1 ? 'yesterday' : days + ' days ago';
}

Comment on lines +120 to +124
messagesFromDomain(domain: string): Message[] {
return this.mailbox.threads.flatMap(thread =>
thread.messages.filter(message => domainOf(message.from.email) === domain),
);
}

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 domainOf helper returns a lowercased domain, but the domain parameter passed to messagesFromDomain is compared directly without lowercasing. If a caller passes a mixed-case domain (e.g., "Example.com"), the comparison will fail. We should lowercase the input domain parameter to ensure case-insensitive matching.

Suggested change
messagesFromDomain(domain: string): Message[] {
return this.mailbox.threads.flatMap(thread =>
thread.messages.filter(message => domainOf(message.from.email) === domain),
);
}
messagesFromDomain(domain: string): Message[] {
const lowerDomain = domain.toLowerCase();
return this.mailbox.threads.flatMap(thread =>
thread.messages.filter(message => domainOf(message.from.email) === lowerDomain),
);
}

Comment on lines +160 to +167
export function localDay(date: string | Date, timeZone: string): string {
return new Intl.DateTimeFormat('en-CA', {
timeZone,
year: 'numeric',
month: '2-digit',
day: '2-digit',
}).format(new Date(date));
}

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

Relying on the en-CA locale to always format dates as YYYY-MM-DD is risky. In environments with limited ICU support (such as some minimal Docker containers or older Node runtimes), the locale formatting might fallback to a default like MM/DD/YYYY, which would cause localDay to return an unexpected format and break downstream date parsing (e.g., in nextMonday where it splits by -).

Using formatToParts with a standard locale and explicitly extracting the year, month, and day parts is much more robust and environment-independent.

export function localDay(date: string | Date, timeZone: string): string {
  const parts = new Intl.DateTimeFormat('en-US', {
    timeZone,
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
  }).formatToParts(new Date(date));
  const year = parts.find(p => p.type === 'year')?.value ?? '';
  const month = parts.find(p => p.type === 'month')?.value ?? '';
  const day = parts.find(p => p.type === 'day')?.value ?? '';
  return year + '-' + month + '-' + day;
}

const parts = new Intl.DateTimeFormat('en-US', {timeZone, timeZoneName: 'longOffset'})
.formatToParts(date)
.find(part => part.type === 'timeZoneName')?.value;
const match = /GMT([+-])(\d{2}):?(\d{2})?/.exec(parts ?? '');

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 regex /GMT([+-])(\d{2}):?(\d{2})?/ expects exactly two digits for the hour (\d{2}). While standard, some environments or older runtimes might format the timezone offset with a single digit for the hour (e.g., GMT-8 or GMT-8:00). Using \d{1,2} makes the parser more robust against these variations.

Suggested change
const match = /GMT([+-])(\d{2}):?(\d{2})?/.exec(parts ?? '');
const match = /GMT([+-])(\d{1,2}):?(\d{2})?/.exec(parts ?? '');

@josemontespg
josemontespg force-pushed the embed/5-markdown branch 5 times, most recently from 4faaddf to 454e474 Compare December 2, 2026 21:28
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