import { pool } from '../../../db/pool.js'; const TABLE = { page: 'pages', ref: 'refs', task: 'tasks', conversation: 'conversations' }; export const readTool = { name: 'read', description: 'Read a single entity (page, ref, task, conversation) by id for grounding.', input_schema: { type: 'object', properties: { kind: { type: 'string', enum: ['page', 'ref', 'task', 'conversation'] }, id: { type: 'string', description: 'uuid of the entity' } }, required: ['kind', 'id'] }, async handler({ kind, id }, _ctx) { const table = TABLE[kind]; if (!table) return { error: `unknown kind "${kind}"` }; const { rows: [row] } = await pool.query(`SELECT * FROM ${table} WHERE id=$1`, [id]); if (!row) return { error: `${kind} ${id} not found` }; return row; } };