import { Client } from '@notionhq/client'; import { logger } from '../utils/logger.js'; const log = logger.child({ module: 'register-gemini-agent' }); /** * ===== SCRIPT CONFIGURATION ===== */ const AGENTS_DATABASE_ID = '2cc12238fd44818dbe64eb12df2d3ef7'; const GEMINI_AGENT_NAME = 'Gemini (Code Weaver)'; /** * This script registers the Gemini AI assistant as a new agent * in the designated Notion 'Agents' database. * * Prerequisites: * 1. Ensure '@notionhq/client' is installed (`npm install @notionhq/client`). * 2. Set your Notion API key in the .env file as `NOTION_API_KEY`. */ async function registerSelfInNotion() { log.info('Starting registration of Gemini agent in Notion...'); const notionApiKey = process.env.NOTION_API_KEY; if (!notionApiKey) { log.error('FATAL: `NOTION_API_KEY` is not set in the environment variables.'); console.error('Please add your Notion integration token to the .env file as `NOTION_API_KEY`.'); return; } const notion = new Client({ auth: notionApiKey }); try { // Check if the agent already exists to prevent duplicates const searchResponse = await notion.databases.query({ database_id: AGENTS_DATABASE_ID, filter: { property: 'Name', title: { equals: GEMINI_AGENT_NAME, }, }, }); if (searchResponse.results.length > 0) { const agentId = searchResponse.results[0].id; log.warn(`Agent "${GEMINI_AGENT_NAME}" already exists with ID: ${agentId}. Aborting creation.`); console.log(`✅ Agent "${GEMINI_AGENT_NAME}" already exists. No action needed.`); return; } log.info(`Agent not found. Proceeding to create new agent entry...`); // Create the new agent page const response = await notion.pages.create({ parent: { database_id: AGENTS_DATABASE_ID }, properties: { 'Name': { type: 'title', title: [{ type: 'text', text: { content: GEMINI_AGENT_NAME } }], }, 'Type': { type: 'select', select: { name: 'AI Assistant' }, }, 'Status': { type: 'select', select: { name: 'Active' }, }, 'Capabilities': { type: 'multi_select', multi_select: [ { name: 'Code Generation' }, { name: 'Code Analysis' }, { name: 'System Architecture' }, { name: 'API Integration' }, { name: 'Autonomous Operation' }, ] }, 'Primary Model': { type: 'rich_text', rich_text: [{ type: 'text', text: { content: 'Google Gemini Family' } }] } }, }); log.info(`Successfully created new agent entry with ID: ${response.id}`); console.log(`✅ Successfully registered "${GEMINI_AGENT_NAME}" in your Notion Agents database!`); console.log(`You can view the new entry here: https://www.notion.so/${response.id.replace(/-/g, '')}`); } catch (error: any) { log.error('Failed to register agent in Notion.', { error: error.message }); if (error.code === 'unauthorized') { console.error('Error: Authentication failed. Is your `NOTION_API_KEY` correct and does the integration have permissions for the database?'); } else { console.error('An error occurred while communicating with Notion:', error.body || error); } } } registerSelfInNotion();