diff --git a/apps/x/packages/core/src/knowledge/agent_notes.ts b/apps/x/packages/core/src/knowledge/agent_notes.ts index 433423ac..5ec3e801 100644 --- a/apps/x/packages/core/src/knowledge/agent_notes.ts +++ b/apps/x/packages/core/src/knowledge/agent_notes.ts @@ -7,6 +7,8 @@ import { bus } from '../runs/bus.js'; import { serviceLogger } from '../services/service_logger.js'; import { loadUserConfig, updateUserEmail } from '../config/user_config.js'; import { GoogleClientFactory } from './google-client-factory.js'; +import { useComposioForGoogle, executeAction } from '../composio/client.js'; +import { composioAccountsRepo } from '../composio/repo.js'; import { loadAgentNotesState, saveAgentNotesState, @@ -209,7 +211,30 @@ async function ensureUserEmail(): Promise { return existing.email; } - // Try to get email from Gmail profile + // Try Composio (used when signed in or composio configured) + try { + if (await useComposioForGoogle()) { + const account = composioAccountsRepo.getAccount('gmail'); + if (account && account.status === 'ACTIVE') { + const result = await executeAction('GMAIL_GET_PROFILE', { + connected_account_id: account.id, + user_id: 'rowboat-user', + version: 'latest', + arguments: { user_id: 'me' }, + }); + const email = (result.data as Record)?.emailAddress as string | undefined; + if (email) { + updateUserEmail(email); + console.log(`[AgentNotes] Auto-populated user email via Composio: ${email}`); + return email; + } + } + } + } catch (error) { + console.log('[AgentNotes] Could not fetch email via Composio:', error instanceof Error ? error.message : error); + } + + // Try direct Google OAuth try { const auth = await GoogleClientFactory.getClient(); if (auth) {