YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(meetings): merge all Google accounts in Coming up calendar fetch
Louis Beaumont11155db8092c
diff --git a/apps/screenpipe-app-tauri/lib/utils/calendar.test.ts b/apps/screenpipe-app-tauri/lib/utils/calendar.test.tsindex 409b70845..95ea9ae8a 100644--- a/apps/screenpipe-app-tauri/lib/utils/calendar.test.ts+++ b/apps/screenpipe-app-tauri/lib/utils/calendar.test.ts@@ -9,6 +9,7 @@ const mocks = vi.hoisted(() => ({commands: {calendarStatus: vi.fn(),oauthStatus: vi.fn(),+ oauthListInstances: vi.fn(),icsCalendarGetEntries: vi.fn(),icsCalendarGetUpcoming: vi.fn(),},@@ -46,6 +47,11 @@ describe("fetchUpcomingCalendarSnapshot", () => {status: "ok",data: [],});+ // Default: no enumerable Google accounts → single implicit-default call.+ mocks.commands.oauthListInstances.mockResolvedValue({+ status: "ok",+ data: [],+ });});it("uses Google events when OAuth status is connected", async () => {@@ -203,4 +209,106 @@ describe("fetchUpcomingCalendarSnapshot", () => {meeting_url: "https://meet.google.com/abc-defg-hij",});});++ it("merges events across multiple connected Google accounts", async () => {+ // Two accounts connected: the events endpoint 401s on an ambiguous+ // request, so each must be queried with its own `instance`.+ mocks.commands.oauthListInstances.mockResolvedValue({+ status: "ok",+ data: [+ { instance: "[email protected]", display_name: "[email protected]" },+ {+ instance: "[email protected]",+ display_name: "[email protected]",+ },+ ],+ });+ mocks.commands.oauthStatus.mockResolvedValue({+ status: "ok",+ data: { connected: true },+ });+ mocks.localFetch.mockImplementation((url: string) => {+ if (url.startsWith("/connections/google-calendar/events")) {+ if (url.includes("instance=work%40example.com")) {+ return Promise.resolve(+ jsonResponse(true, [+ {+ id: "work-1",+ title: "Work standup",+ start: "2026-06-09T09:00:00-07:00",+ end: "2026-06-09T09:15:00-07:00",+ },+ ]),+ );+ }+ if (url.includes("instance=personal%40example.com")) {+ return Promise.resolve(+ jsonResponse(true, [+ {+ id: "personal-1",+ title: "Dentist",+ start: "2026-06-09T11:00:00-07:00",+ end: "2026-06-09T11:30:00-07:00",+ },+ ]),+ );+ }+ // No instance specified — backend rejects when >1 account connected.+ return Promise.resolve(+ jsonResponse(false, {+ error: "multiple Google Calendar accounts connected",+ }),+ );+ }+ if (url.startsWith("/connections/calendar/events")) {+ return Promise.resolve(+ jsonResponse(false, { error: "AuthorizationDenied" }),+ );+ }+ return Promise.reject(new Error(`unexpected url: ${url}`));+ });++ const snapshot = await fetchUpcomingCalendarSnapshot({ hoursAhead: 8 });++ expect(snapshot.connectedSources).toEqual(["google"]);+ expect(snapshot.failedSources).toEqual([]);+ expect(snapshot.events.map((e) => e.title)).toEqual([+ "Work standup",+ "Dentist",+ ]);+ });++ it("flags Google as failed only when every connected account fails", async () => {+ mocks.commands.oauthListInstances.mockResolvedValue({+ status: "ok",+ data: [+ { instance: "[email protected]", display_name: "[email protected]" },+ {+ instance: "[email protected]",+ display_name: "[email protected]",+ },+ ],+ });+ mocks.commands.oauthStatus.mockResolvedValue({+ status: "ok",+ data: { connected: true },+ });+ mocks.localFetch.mockImplementation((url: string) => {+ if (url.startsWith("/connections/google-calendar/events")) {+ return Promise.resolve(jsonResponse(false, { error: "boom" }));+ }+ if (url.startsWith("/connections/calendar/events")) {+ return Promise.resolve(+ jsonResponse(false, { error: "AuthorizationDenied" }),+ );+ }+ return Promise.reject(new Error(`unexpected url: ${url}`));+ });++ const snapshot = await fetchUpcomingCalendarSnapshot({ hoursAhead: 8 });++ expect(snapshot.connectedSources).toEqual(["google"]);+ expect(snapshot.failedSources).toEqual(["google"]);+ expect(snapshot.events).toEqual([]);+ });});diff --git a/apps/screenpipe-app-tauri/lib/utils/calendar.ts b/apps/screenpipe-app-tauri/lib/utils/calendar.tsindex f97030274..b2afeb014 100644--- a/apps/screenpipe-app-tauri/lib/utils/calendar.ts+++ b/apps/screenpipe-app-tauri/lib/utils/calendar.ts@@ -218,11 +218,13 @@ async function fetchNativeCalendar(async function fetchGoogleCalendar(hoursBack: number,hoursAhead: number,+ instance: string | null,): Promise<CalendarEvent[] | null> {+ const query =+ `hours_back=${hoursBack}&hours_ahead=${hoursAhead}` ++ (instance ? `&instance=${encodeURIComponent(instance)}` : "");try {- const res = await localFetch(- `/connections/google-calendar/events?hours_back=${hoursBack}&hours_ahead=${hoursAhead}`,- );+ const res = await localFetch(`/connections/google-calendar/events?${query}`);if (!res.ok) return null;const body = (await res.json()) as RawGoogleEvent[] | { error?: string };if (!Array.isArray(body)) return null;@@ -260,7 +262,11 @@ async function fetchNativeProvider(};}-async function fetchGoogleProvider(+// Fetch a single Google account. `instance` is the account identifier (email)+// or null for the implicit default — used when only one account is connected+// or when enumeration is unavailable.+async function fetchGoogleInstance(+ instance: string | null,hoursBack: number,hoursAhead: number,): Promise<ProviderCalendarResult> {@@ -268,7 +274,7 @@ async function fetchGoogleProvider(let statusConnected = false;let needsAttention = false;try {- const status = await commands.oauthStatus("google-calendar", null);+ const status = await commands.oauthStatus("google-calendar", instance);if (status.status === "ok") {statusKnown = true;statusConnected = status.data.connected;@@ -293,7 +299,7 @@ async function fetchGoogleProvider(};}- const events = await fetchGoogleCalendar(hoursBack, hoursAhead);+ const events = await fetchGoogleCalendar(hoursBack, hoursAhead, instance);return {source: "google",connected: statusConnected || events !== null,@@ -302,6 +308,48 @@ async function fetchGoogleProvider(};}+async function fetchGoogleProvider(+ hoursBack: number,+ hoursAhead: number,+): Promise<ProviderCalendarResult> {+ // A user can connect more than one Google account (e.g. personal + work).+ // The events endpoint refuses an ambiguous request once >1 account exists+ // ("specify which one with `instance`"), so enumerate the accounts and query+ // each explicitly, then merge. Falls back to a single implicit-default call+ // when enumeration is unavailable or only one account is connected.+ let instances: (string | null)[] | null = null;+ try {+ const list = await commands.oauthListInstances("google-calendar");+ if (list.status === "ok") {+ instances = list.data.map((entry) => entry.instance);+ }+ } catch {+ // Enumeration unavailable — fall through to the single-account path.+ }++ if (instances === null || instances.length <= 1) {+ return fetchGoogleInstance(instances?.[0] ?? null, hoursBack, hoursAhead);+ }++ const results = await Promise.all(+ instances.map((instance) =>+ fetchGoogleInstance(instance, hoursBack, hoursAhead),+ ),+ );++ const connectedResults = results.filter((result) => result.connected);+ return {+ source: "google",+ connected: connectedResults.length > 0,+ // Only flag the source as failing when every connected account failed; one+ // healthy account shouldn't surface a global "calendar needs attention".+ ok:+ connectedResults.length === 0 ||+ connectedResults.some((result) => result.ok),+ events: results.flatMap((result) => result.events),+ };+}+async function fetchIcsProvider(hoursBack: number,hoursAhead: number,