@agent-native/core 0.175.4 → 0.176.0-nightly-20260826203614

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/corpus/README.md +1 -1
  2. package/corpus/templates/clips/.agents/skills/recording/SKILL.md +9 -8
  3. package/corpus/templates/clips/actions/import-loom-recording.ts +1 -1
  4. package/corpus/templates/clips/actions/lib/loom-import-job.ts +52 -35
  5. package/corpus/templates/clips/app/components/clips-avatar.tsx +46 -0
  6. package/corpus/templates/clips/app/components/library/recording-card.tsx +8 -7
  7. package/corpus/templates/clips/app/components/library/space-card.tsx +8 -5
  8. package/corpus/templates/clips/app/components/meetings/attendee-stack.tsx +7 -8
  9. package/corpus/templates/clips/app/components/meetings/transcript-bubbles.tsx +19 -12
  10. package/corpus/templates/clips/app/components/workspace/members-list.tsx +8 -6
  11. package/corpus/templates/clips/app/components/workspace/notifications-list.tsx +8 -6
  12. package/corpus/templates/clips/app/components/workspace/top-creators-table.tsx +8 -6
  13. package/corpus/templates/clips/app/routes/_app.meetings.$meetingId.tsx +8 -7
  14. package/corpus/templates/clips/changelog/2026-08-26-detected-calls-no-longer-duplicate-meetings-or-strand-the-prompt.md +6 -0
  15. package/corpus/templates/clips/desktop/src/overlays/meeting-notification.tsx +39 -22
  16. package/corpus/templates/clips/desktop/src-tauri/src/adhoc_meetings_watcher.rs +1765 -219
  17. package/corpus/templates/clips/desktop/src-tauri/src/lib.rs +4 -0
  18. package/corpus/templates/clips/desktop/src-tauri/src/meetings_watcher.rs +45 -30
  19. package/corpus/templates/clips/desktop/src-tauri/src/notifications.rs +91 -0
  20. package/corpus/templates/clips/server/routes/_agent-native/google/callback.get.ts +16 -0
  21. package/corpus/templates/content/app/components/editor/CommentsSidebar.tsx +44 -22
  22. package/corpus/templates/content/app/components/ui/avatar.tsx +1 -0
  23. package/corpus/templates/design/app/components/visual-editor/ReviewCanvasPins.tsx +4 -1
  24. package/corpus/templates/mail/actions/get-email.ts +68 -21
  25. package/corpus/templates/mail/actions/get-thread.ts +92 -51
  26. package/corpus/templates/mail/app/hooks/use-emails.ts +7 -4
  27. package/corpus/templates/mail/server/lib/mail-connector-catalog.ts +7 -4
  28. package/corpus/templates/plan/app/pages/PlansPage.tsx +23 -15
  29. package/corpus/templates/slides/app/components/comments/SlideCommentsPanel.tsx +18 -7
  30. package/corpus/templates/slides/app/components/ui/avatar.tsx +1 -0
  31. package/corpus/templates/tasks/DEVELOPING.md +8 -0
  32. package/corpus/templates/tasks/drizzle.config.ts +3 -1
  33. package/corpus/templates/tasks/drizzle.local.config.ts +6 -0
  34. package/corpus/templates/tasks/package.json +2 -1
  35. package/corpus/templates/tasks/server/db/migrations/meta/0000_snapshot.json +234 -0
  36. package/corpus/templates/tasks/server/db/migrations/meta/_journal.json +13 -0
  37. package/corpus/templates/tasks/server/db/migrations.ts +110 -0
  38. package/corpus/templates/tasks/server/plugins/db.ts +3 -87
  39. package/dist/client/review/ReviewThreadPanel.js +4 -2
  40. package/dist/collab/client.js +20 -5
  41. package/dist/collab/presence.d.ts +3 -1
  42. package/dist/collab/presence.js +48 -45
  43. package/dist/collab/routes.d.ts +1 -1
  44. package/dist/collab/struct-routes.d.ts +1 -1
  45. package/dist/db/drizzle-config.d.ts +7 -0
  46. package/dist/db/drizzle-config.js +35 -9
  47. package/dist/db/drizzle-migrations.d.ts +28 -0
  48. package/dist/db/drizzle-migrations.js +81 -0
  49. package/dist/db/index.d.ts +1 -1
  50. package/dist/db/migrations.d.ts +13 -1
  51. package/dist/db/migrations.js +60 -31
  52. package/dist/db/schema.js +4 -1
  53. package/dist/deploy/build.d.ts +6 -0
  54. package/dist/deploy/build.js +41 -0
  55. package/dist/observability/routes.d.ts +5 -5
  56. package/dist/provider-api/actions/custom-provider-registration.d.ts +11 -11
  57. package/dist/provider-api/actions/provider-api.d.ts +9 -9
  58. package/dist/secrets/routes.d.ts +9 -9
  59. package/dist/server/agent-engine-api-key-route.d.ts +1 -1
  60. package/dist/server/auth.js +3 -2
  61. package/dist/server/builder-browser.d.ts +0 -4
  62. package/dist/server/builder-browser.js +23 -8
  63. package/dist/server/google-oauth.d.ts +18 -0
  64. package/dist/server/google-oauth.js +3 -3
  65. package/dist/server/realtime-token.d.ts +1 -1
  66. package/dist/server/short-lived-token.d.ts +1 -1
  67. package/dist/server/short-lived-token.js +1 -1
  68. package/dist/server/transcribe-voice.d.ts +1 -1
  69. package/dist/shared/google-profile-image.d.ts +2 -0
  70. package/dist/shared/google-profile-image.js +24 -0
  71. package/dist/shared/index.d.ts +1 -0
  72. package/dist/shared/index.js +1 -0
  73. package/docs/content/creating-templates.mdx +10 -1
  74. package/docs/content/server-database.mdx +46 -2
  75. package/docs/content/server-plugins.mdx +39 -3
  76. package/docs/content/webmcp.mdx +2 -0
  77. package/package.json +3 -2
@@ -375,6 +375,10 @@ pub fn run() {
375
375
  // Granola-style adhoc Zoom/Teams detection — shares session
376
376
  // credentials with the calendar watcher above.
377
377
  adhoc_meetings_watcher::spawn_watcher(app.handle().clone());
378
+ // Retire a stored notification payload once the frontend reports the
379
+ // meeting on screen, so a late-mounting overlay cannot hydrate a
380
+ // question that has already been answered.
381
+ notifications::watch_meeting_notification_acks(app.handle());
378
382
  // Server-controlled desktop capture feature flags — own poll
379
383
  // loop, reuses the calendar watcher's session credentials.
380
384
  remote_flags::spawn_watcher(app.handle().clone());
@@ -414,29 +414,34 @@ async fn tick_once(app: &AppHandle, client: &reqwest::Client) -> Result<(), Stri
414
414
  if let Some(state) = app.try_state::<MeetingsWatcherState>() {
415
415
  state.note_calendar_notify(m.platform.as_deref());
416
416
  }
417
- let app_clone = app.clone();
418
- let id_clone = m.id.clone();
419
- let title_clone = title.clone();
420
- let join_clone = join_url.clone();
421
- let start_clone = m.scheduled_start.clone();
422
- let end_clone = m.scheduled_end.clone();
423
- let platform_clone = m.platform.clone();
424
417
  let auto_start = config.meeting_transcription_mode == MeetingTranscriptionMode::Auto;
425
- tauri::async_runtime::spawn(async move {
426
- let _ = crate::notifications::notify_meeting_starting(
427
- app_clone,
428
- id_clone,
429
- title_clone,
430
- secs_until,
431
- join_clone,
432
- start_clone,
433
- end_clone,
434
- platform_clone,
435
- Some(auto_start),
436
- None,
437
- )
438
- .await;
439
- });
418
+ // Awaited, not spawned. The stored payload has to exist before
419
+ // auto-start is announced below: startup acknowledges itself with
420
+ // `meetings:hide-notification`, and an acknowledgement that arrives
421
+ // before the payload was stored clears nothing, leaving a spawned
422
+ // task free to install a "Take notes?" card over a meeting that is
423
+ // already recording. Ordering it here makes that impossible rather
424
+ // than unlikely, and matches the ad-hoc path.
425
+ if let Err(err) = crate::notifications::notify_meeting_starting(
426
+ app.clone(),
427
+ m.id.clone(),
428
+ title.clone(),
429
+ secs_until,
430
+ join_url.clone(),
431
+ m.scheduled_start.clone(),
432
+ m.scheduled_end.clone(),
433
+ m.platform.clone(),
434
+ Some(auto_start),
435
+ None,
436
+ )
437
+ .await
438
+ {
439
+ dlog!(
440
+ "[clips-tray] calendar notification failed for {}: {}",
441
+ m.id,
442
+ err
443
+ );
444
+ }
440
445
  }
441
446
  if config.meeting_transcription_mode == MeetingTranscriptionMode::Auto {
442
447
  let _ = app.emit(
@@ -495,23 +500,33 @@ pub(crate) fn find_matching_calendar_meeting(
495
500
  Some((*meeting).clone())
496
501
  }
497
502
 
498
- pub(crate) fn parse_meetings(body: &serde_json::Value) -> Vec<MeetingItem> {
503
+ /// `parse_meetings`, but able to say "this was not a meetings list at all".
504
+ ///
505
+ /// `None` means no recognized list key and not a bare array — a changed
506
+ /// envelope, or a 200 carrying an error payload. A caller that is about to
507
+ /// *write* based on the answer needs that apart from `Some(vec![])`: an empty
508
+ /// list is a checked "no such meeting", while an unreadable body says nothing,
509
+ /// and treating the second as the first is how a duplicate row gets inserted.
510
+ pub(crate) fn try_parse_meetings(body: &serde_json::Value) -> Option<Vec<MeetingItem>> {
499
511
  let payload = body.get("result").unwrap_or(body);
500
512
  if let Ok(parsed) = serde_json::from_value::<ListMeetingsResponse>(payload.clone()) {
501
513
  if let Some(v) = parsed.upcoming {
502
- return v;
514
+ return Some(v);
503
515
  }
504
516
  if let Some(v) = parsed.meetings {
505
- return v;
517
+ return Some(v);
506
518
  }
507
519
  if let Some(v) = parsed.items {
508
- return v;
520
+ return Some(v);
509
521
  }
510
522
  }
511
- if let Ok(arr) = serde_json::from_value::<Vec<MeetingItem>>(payload.clone()) {
512
- return arr;
513
- }
514
- Vec::new()
523
+ serde_json::from_value::<Vec<MeetingItem>>(payload.clone()).ok()
524
+ }
525
+
526
+ /// Read-only callers, where "no meetings" and "cannot tell" lead to the same
527
+ /// harmless outcome: nothing to remind about, nothing to enrich with.
528
+ pub(crate) fn parse_meetings(body: &serde_json::Value) -> Vec<MeetingItem> {
529
+ try_parse_meetings(body).unwrap_or_default()
515
530
  }
516
531
 
517
532
  #[cfg(test)]
@@ -30,6 +30,10 @@ const NOTIFICATION_H_LOGICAL: u32 = 120;
30
30
  const NOTIFICATION_TOP_MARGIN_LOGICAL: u32 = 44;
31
31
  const NOTIFICATION_RIGHT_MARGIN_LOGICAL: u32 = 0;
32
32
  const DISMISSAL_TOMBSTONE_SECS: i64 = 30 * 60;
33
+ /// How long an answered card stays un-hydratable. Only has to outlive an
34
+ /// overlay boot, but a meeting that is recording has no reason to be asked about
35
+ /// again for a while either.
36
+ const ACK_TOMBSTONE_SECS: i64 = 10 * 60;
33
37
 
34
38
  #[derive(Default)]
35
39
  pub struct MeetingNotificationState(Mutex<MeetingNotificationStateInner>);
@@ -38,6 +42,11 @@ pub struct MeetingNotificationState(Mutex<MeetingNotificationStateInner>);
38
42
  struct MeetingNotificationStateInner {
39
43
  pending: Option<Value>,
40
44
  dismissed_until: HashMap<String, i64>,
45
+ /// meeting id -> unix-seconds until which a stored payload for it must not
46
+ /// be handed out. Clearing `pending` cannot retract a payload an overlay
47
+ /// already took, and `take_pending_meeting_notification` is destructive, so
48
+ /// the acknowledgement has to leave a mark rather than only a deletion.
49
+ acknowledged_until: HashMap<String, i64>,
41
50
  }
42
51
 
43
52
  #[allow(dead_code)]
@@ -193,6 +202,7 @@ pub fn take_pending_meeting_notification(app: AppHandle) -> Result<Option<Value>
193
202
  .map_err(|_| "meeting notification state lock poisoned".to_string())?;
194
203
  let now = chrono::Utc::now().timestamp();
195
204
  state.dismissed_until.retain(|_, until| *until > now);
205
+ state.acknowledged_until.retain(|_, until| *until > now);
196
206
  if state.pending.as_ref().is_some_and(|payload| {
197
207
  state
198
208
  .dismissed_until
@@ -200,6 +210,19 @@ pub fn take_pending_meeting_notification(app: AppHandle) -> Result<Option<Value>
200
210
  }) {
201
211
  state.pending = None;
202
212
  }
213
+ // A meeting whose card was already acknowledged must not be hydrated by an
214
+ // overlay mounting afterwards. Without this the payload survives as a
215
+ // "Take notes?" card over a meeting that is already recording, because the
216
+ // acknowledgement that would have cleared it arrived while this webview was
217
+ // still booting and had nothing listening.
218
+ if state.pending.as_ref().is_some_and(|payload| {
219
+ payload
220
+ .get("meetingId")
221
+ .and_then(Value::as_str)
222
+ .is_some_and(|id| state.acknowledged_until.contains_key(id))
223
+ }) {
224
+ state.pending = None;
225
+ }
203
226
  Ok(state.pending.take())
204
227
  }
205
228
 
@@ -234,6 +257,74 @@ fn notification_key_from_parts(
234
257
  )
235
258
  }
236
259
 
260
+ /// Drop a stored payload for a meeting that no longer needs asking about.
261
+ ///
262
+ /// `pending` exists so an overlay webview that had not mounted yet can still
263
+ /// hydrate the card — and that is also how a stale card outlives the event meant
264
+ /// to clear it. `meetings:hide-notification` is matched against the payload the
265
+ /// overlay already holds, so a hide arriving before the overlay mounts is
266
+ /// dropped, and hydration afterwards shows "Take notes?" over a meeting that is
267
+ /// already recording. A caller that has started capture clears the payload
268
+ /// rather than trusting an event the overlay may not be listening for yet.
269
+ /// Clear the stored payload once the frontend confirms a card is finished with.
270
+ ///
271
+ /// `pending` is the cold-overlay hydration path, so it has to outlive the emit
272
+ /// that dismisses a card in an overlay that is already mounted — otherwise an
273
+ /// overlay mounting late loses the notification entirely. It must not outlive it
274
+ /// indefinitely either: a payload still sitting there after capture has begun
275
+ /// becomes a "Take notes?" card over a meeting that is already recording.
276
+ ///
277
+ /// `meetings:hide-notification` is the frontend's own acknowledgement that
278
+ /// startup got far enough to put the meeting on screen, which makes it the exact
279
+ /// point where the stored copy stops being a recovery path and starts being
280
+ /// wrong. A start that fails emits `meetings:transcription-error` instead and
281
+ /// deliberately leaves the payload in place, so the user keeps a way back to the
282
+ /// detected meeting.
283
+ pub fn watch_meeting_notification_acks(app: &AppHandle) {
284
+ use tauri::Listener;
285
+
286
+ let handle = app.clone();
287
+ app.listen("meetings:hide-notification", move |event| {
288
+ let Some(meeting_id) = serde_json::from_str::<Value>(event.payload())
289
+ .ok()
290
+ .as_ref()
291
+ .and_then(|payload| payload.get("meetingId"))
292
+ .and_then(Value::as_str)
293
+ .map(str::to_string)
294
+ else {
295
+ return;
296
+ };
297
+ acknowledge_meeting_notification(&handle, &meeting_id);
298
+ });
299
+ }
300
+
301
+ /// Record that a meeting card has been answered, and drop any stored copy.
302
+ ///
303
+ /// Both halves are needed. Dropping `pending` handles the overlay that has not
304
+ /// read it yet; the tombstone handles the one that already did, or that reads it
305
+ /// a moment from now — `take_pending_meeting_notification` is destructive, so by
306
+ /// the time an acknowledgement arrives there may be nothing left to delete and
307
+ /// still a payload in flight toward a webview that is about to render it.
308
+ fn acknowledge_meeting_notification(app: &AppHandle, meeting_id: &str) {
309
+ let Some(state) = app.try_state::<MeetingNotificationState>() else {
310
+ return;
311
+ };
312
+ let Ok(mut state) = state.0.lock() else {
313
+ return;
314
+ };
315
+ let now = chrono::Utc::now().timestamp();
316
+ state.acknowledged_until.retain(|_, until| *until > now);
317
+ state
318
+ .acknowledged_until
319
+ .insert(meeting_id.to_string(), now + ACK_TOMBSTONE_SECS);
320
+ if clear_pending_notification(&mut state.pending, meeting_id) {
321
+ dlog!(
322
+ "[clips-tray] cleared pending meeting notification for {}",
323
+ meeting_id
324
+ );
325
+ }
326
+ }
327
+
237
328
  fn clear_pending_notification(pending: &mut Option<Value>, meeting_id: &str) -> bool {
238
329
  let matches = pending
239
330
  .as_ref()
@@ -10,6 +10,8 @@ import {
10
10
  setDesktopExchange,
11
11
  type OAuthStatePayload,
12
12
  } from "@agent-native/core/server";
13
+ import { putSetting } from "@agent-native/core/settings";
14
+ import { isGoogleProfileImageUrl } from "@agent-native/core/shared";
13
15
  import {
14
16
  defineEventHandler,
15
17
  getQuery,
@@ -26,6 +28,19 @@ import {
26
28
  isCalendarConnectState,
27
29
  } from "../../../lib/google-calendar-oauth.js";
28
30
 
31
+ export async function persistGoogleProfileImage(
32
+ email: string,
33
+ picture: unknown,
34
+ ) {
35
+ if (!isGoogleProfileImageUrl(picture)) return;
36
+
37
+ await putSetting(`avatar:${email}`, { image: picture.trim() }).catch(
38
+ (error) => {
39
+ console.warn("[auth] failed to store Google profile image:", error);
40
+ },
41
+ );
42
+ }
43
+
29
44
  async function handleGoogleSignInCallback(
30
45
  event: H3Event,
31
46
  state: OAuthStatePayload,
@@ -104,6 +119,7 @@ async function handleGoogleSignInCallback(
104
119
  "Google account email is not verified. Please verify your email with Google and try again.",
105
120
  );
106
121
  }
122
+ await persistGoogleProfileImage(email, user.picture);
107
123
 
108
124
  const { hasProductionSession } = await resolveOAuthOwner(
109
125
  event,
@@ -1,5 +1,6 @@
1
1
  import { sendToAgentChat } from "@agent-native/core/client/agent-chat";
2
2
  import { emailToName } from "@agent-native/core/client/collab";
3
+ import { useAvatarUrl } from "@agent-native/core/client/hooks";
3
4
  import { useT } from "@agent-native/core/client/i18n";
4
5
  import {
5
6
  InlineMarkdown,
@@ -23,6 +24,11 @@ import {
23
24
  } from "react";
24
25
  import { toast } from "sonner";
25
26
 
27
+ import {
28
+ Avatar as UserAvatar,
29
+ AvatarFallback as UserAvatarFallback,
30
+ AvatarImage as UserAvatarImage,
31
+ } from "@/components/ui/avatar";
26
32
  import {
27
33
  Tooltip,
28
34
  TooltipContent,
@@ -95,6 +101,30 @@ function emailToAvatarColor(email: string) {
95
101
  return `hsl(${hue}, 55%, 55%)`;
96
102
  }
97
103
 
104
+ function CommentAvatar({
105
+ email,
106
+ name,
107
+ className = "h-6 w-6",
108
+ }: {
109
+ email?: string | null;
110
+ name?: string | null;
111
+ className?: string;
112
+ }) {
113
+ const avatarUrl = useAvatarUrl(email);
114
+ const label = name ?? email ?? "";
115
+ return (
116
+ <UserAvatar className={className} title={label}>
117
+ {avatarUrl ? <UserAvatarImage src={avatarUrl} alt={label} /> : null}
118
+ <UserAvatarFallback
119
+ className="text-[11px] font-medium text-primary-foreground"
120
+ style={{ backgroundColor: emailToAvatarColor(email ?? "user") }}
121
+ >
122
+ {emailToInitial(label)}
123
+ </UserAvatarFallback>
124
+ </UserAvatar>
125
+ );
126
+ }
127
+
98
128
  function formatDate(dateStr: string) {
99
129
  const d = new Date(dateStr);
100
130
  return d.toLocaleDateString("en-US", { month: "short", day: "numeric" });
@@ -938,12 +968,10 @@ function ThreadView({
938
968
  {thread.comments.map((c) => (
939
969
  <div key={c.id} className="mb-3 last:mb-0">
940
970
  <div className="flex items-center gap-2 mb-0.5">
941
- <div
942
- className="w-6 h-6 rounded-full flex items-center justify-center text-[11px] font-medium text-white shrink-0"
943
- style={{ backgroundColor: emailToAvatarColor(c.author_email) }}
944
- >
945
- {emailToInitial(c.author_name ?? c.author_email)}
946
- </div>
971
+ <CommentAvatar
972
+ email={c.author_email}
973
+ name={c.author_name ?? c.author_email}
974
+ />
947
975
  <span className="text-[13px] font-semibold text-foreground">
948
976
  {c.author_name ?? c.author_email.split("@")[0]}
949
977
  </span>
@@ -964,16 +992,11 @@ function ThreadView({
964
992
  className="flex items-center gap-2 px-3 pb-3 pt-1"
965
993
  onClick={(e) => e.stopPropagation()}
966
994
  >
967
- <div
968
- className="w-6 h-6 rounded-full flex items-center justify-center text-[11px] font-medium text-white shrink-0 opacity-40"
969
- style={{
970
- backgroundColor: emailToAvatarColor(
971
- thread.comments[0]?.author_email ?? "user",
972
- ),
973
- }}
974
- >
975
- {emailToInitial(thread.comments[0]?.author_name ?? "user")}
976
- </div>
995
+ <CommentAvatar
996
+ email={thread.comments[0]?.author_email}
997
+ name={thread.comments[0]?.author_name ?? "user"}
998
+ className="h-6 w-6 shrink-0 opacity-40"
999
+ />
977
1000
  <div className="flex-1 relative">
978
1001
  <CommentComposer
979
1002
  ref={replyInputRef}
@@ -1024,12 +1047,11 @@ function ResolvedThreadView({
1024
1047
  </p>
1025
1048
  )}
1026
1049
  <div className="flex items-center gap-2">
1027
- <div
1028
- className="flex h-5 w-5 items-center justify-center rounded-full text-[10px] font-medium text-white shrink-0 opacity-80"
1029
- style={{ backgroundColor: emailToAvatarColor(first.author_email) }}
1030
- >
1031
- {emailToInitial(first.author_name ?? first.author_email)}
1032
- </div>
1050
+ <CommentAvatar
1051
+ email={first.author_email}
1052
+ name={first.author_name ?? first.author_email}
1053
+ className="h-5 w-5 shrink-0 opacity-80"
1054
+ />
1033
1055
  <span className="flex-1 truncate text-[13px] text-muted-foreground">
1034
1056
  {renderCommentBody(first.content, first.mentions)}
1035
1057
  </span>
@@ -0,0 +1 @@
1
+ export * from "@agent-native/toolkit/ui/avatar";
@@ -1,4 +1,5 @@
1
1
  import { callAction } from "@agent-native/core/client/hooks";
2
+ import { useAvatarUrl } from "@agent-native/core/client/hooks";
2
3
  import { useT } from "@agent-native/core/client/i18n";
3
4
  import {
4
5
  buildReviewThreads,
@@ -30,7 +31,7 @@ import {
30
31
  } from "react";
31
32
  import { toast } from "sonner";
32
33
 
33
- import { Avatar, AvatarFallback } from "@/components/ui/avatar";
34
+ import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
34
35
  import { Button } from "@/components/ui/button";
35
36
  import {
36
37
  DropdownMenu,
@@ -1407,6 +1408,7 @@ function ReviewThreadPopover({
1407
1408
  }) {
1408
1409
  const t = useT();
1409
1410
  const rootAuthor = reviewAuthorLabel(thread.root, t("review.reviewer"));
1411
+ const avatarUrl = useAvatarUrl(thread.root.authorEmail);
1410
1412
  return (
1411
1413
  <div
1412
1414
  data-review-popover
@@ -1419,6 +1421,7 @@ function ReviewThreadPopover({
1419
1421
  >
1420
1422
  <div className="flex items-start gap-2.5 p-3">
1421
1423
  <Avatar className="size-7 shrink-0">
1424
+ {avatarUrl ? <AvatarImage src={avatarUrl} alt={rootAuthor} /> : null}
1422
1425
  <AvatarFallback className="text-[10px] font-semibold text-muted-foreground">
1423
1426
  {reviewAuthorInitials(rootAuthor)}
1424
1427
  </AvatarFallback>
@@ -4,18 +4,29 @@ import { getUserSetting } from "@agent-native/core/settings";
4
4
  import { z } from "zod";
5
5
 
6
6
  import { gmailGetMessage } from "../server/lib/google-api.js";
7
- import { isConnected, gmailToEmailMessage } from "../server/lib/google-auth.js";
8
- import { getAccessTokens, fetchLabelMap } from "./helpers.js";
7
+ import {
8
+ getClientsWithErrors,
9
+ isConnected,
10
+ gmailToEmailMessage,
11
+ } from "../server/lib/google-auth.js";
12
+ import { fetchLabelMap } from "./helpers.js";
13
+
14
+ const accountCoordinate = z.union([z.string().email(), z.literal("local")]);
9
15
 
10
16
  export default defineAction({
11
17
  description:
12
- "Get a single email by ID, including its full body and metadata.",
18
+ "Read one exact email, including its full body and metadata, without changing UNREAD or any other mailbox label.",
13
19
  schema: z.object({
14
- id: z.string().optional().describe("Email message ID"),
20
+ accountEmail: accountCoordinate.describe(
21
+ 'Connected account email, or "local" for the synthetic mailbox',
22
+ ),
23
+ id: z.string().min(1).describe("Provider-scoped email message ID"),
15
24
  }),
16
25
  http: { method: "GET" },
17
- run: async (args) => {
18
- if (!args.id) throw new Error("--id is required");
26
+ readOnly: true,
27
+ publicAgent: { expose: true, readOnly: true, requiresAuth: true },
28
+ run: async (args, ctx) => {
29
+ const requestedAccount = args.accountEmail.toLowerCase();
19
30
 
20
31
  const ownerEmail = getRequestUserEmail();
21
32
  if (!ownerEmail) throw new Error("no authenticated user");
@@ -23,25 +34,61 @@ export default defineAction({
23
34
  const data = await getUserSetting(ownerEmail, "local-emails");
24
35
  const emails =
25
36
  data && Array.isArray((data as any).emails) ? (data as any).emails : [];
26
- const found = emails.find((e: any) => e.id === args.id);
37
+ const localAccounts = new Set(
38
+ emails.map(
39
+ (email: any) => email.accountEmail?.toLowerCase() ?? "local",
40
+ ),
41
+ );
42
+ if (!localAccounts.has(requestedAccount)) {
43
+ throw new Error("Requested local account is not connected.");
44
+ }
45
+ const found = emails.find(
46
+ (e: any) =>
47
+ e.id === args.id &&
48
+ (e.accountEmail?.toLowerCase() ?? "local") === requestedAccount,
49
+ );
27
50
  if (!found) throw new Error("Email not found.");
28
- return JSON.stringify(found, null, 2);
51
+ const email = { ...found, accountEmail: args.accountEmail };
52
+ return ctx?.caller === "mcp"
53
+ ? {
54
+ accountEmail: args.accountEmail,
55
+ email,
56
+ readOnlyGuarantee: {
57
+ mailboxLabels: "preserved",
58
+ gmailModifyOperations: 0,
59
+ },
60
+ }
61
+ : email;
29
62
  }
30
63
 
31
- const accounts = await getAccessTokens();
32
- if (accounts.length === 0) throw new Error("No Google account connected.");
64
+ const { clients, errors } = await getClientsWithErrors(ownerEmail, [
65
+ requestedAccount,
66
+ ]);
67
+ const account = clients.find(
68
+ ({ email }) => email.toLowerCase() === requestedAccount,
69
+ );
70
+ if (!account) {
71
+ if (errors[0]) throw new Error(errors[0].error);
72
+ throw new Error("Requested Google account is not connected.");
73
+ }
33
74
 
34
- for (const { email, accessToken } of accounts) {
35
- try {
36
- const labelMap = await fetchLabelMap(accessToken);
37
- const msg = await gmailGetMessage(accessToken, args.id, "full");
38
- const parsed = gmailToEmailMessage(msg, email, labelMap);
39
- return JSON.stringify(parsed, null, 2);
40
- } catch (err: any) {
41
- if (err?.message?.includes("404")) continue;
42
- throw new Error(err?.message ?? "Gmail API error");
43
- }
75
+ try {
76
+ const labelMap = await fetchLabelMap(account.accessToken);
77
+ const msg = await gmailGetMessage(account.accessToken, args.id, "full");
78
+ const email = gmailToEmailMessage(msg, account.email, labelMap);
79
+ return ctx?.caller === "mcp"
80
+ ? {
81
+ accountEmail: account.email,
82
+ email,
83
+ readOnlyGuarantee: {
84
+ mailboxLabels: "preserved",
85
+ gmailModifyOperations: 0,
86
+ },
87
+ }
88
+ : email;
89
+ } catch (err: any) {
90
+ if (err?.message?.includes("404")) throw new Error("Email not found.");
91
+ throw new Error(err?.message ?? "Gmail API error");
44
92
  }
45
- throw new Error("Email not found in any connected account.");
46
93
  },
47
94
  });