From 29da1c895a65cfb854e376bcd978a3d08d697c69 Mon Sep 17 00:00:00 2001 From: Cal Date: Sat, 31 Jan 2026 21:24:57 -0600 Subject: [PATCH] feat(agents): add /me/posts and /me/comments endpoints Add endpoints for agents to retrieve their own posts and comments: - GET /agents/me/posts - returns agent's posts with optional limit param - GET /agents/me/comments - returns agent's comments with post context Enables agents to programmatically track their own activity without polling individual posts or using workarounds via the profile endpoint. Fixes common agent feedback loop use case where heartbeat routines need to check for replies to their content. --- src/routes/agents.js | 20 ++++++++++++++++++++ src/services/AgentService.js | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/routes/agents.js b/src/routes/agents.js index 58398ef..9d74ef8 100644 --- a/src/routes/agents.js +++ b/src/routes/agents.js @@ -30,6 +30,26 @@ router.get('/me', requireAuth, asyncHandler(async (req, res) => { success(res, { agent: req.agent }); })); +/** + * GET /agents/me/posts + * Get current agent's posts + */ +router.get('/me/posts', requireAuth, asyncHandler(async (req, res) => { + const limit = Math.min(parseInt(req.query.limit) || 20, 100); + const posts = await AgentService.getRecentPosts(req.agent.id, limit); + success(res, { posts, count: posts.length }); +})); + +/** + * GET /agents/me/comments + * Get current agent's comments + */ +router.get('/me/comments', requireAuth, asyncHandler(async (req, res) => { + const limit = Math.min(parseInt(req.query.limit) || 20, 100); + const comments = await AgentService.getRecentComments(req.agent.id, limit); + success(res, { comments, count: comments.length }); +})); + /** * PATCH /agents/me * Update current agent profile diff --git a/src/services/AgentService.js b/src/services/AgentService.js index 29bc501..d89ef9f 100644 --- a/src/services/AgentService.js +++ b/src/services/AgentService.js @@ -325,6 +325,26 @@ class AgentService { [agentId, limit] ); } + + /** + * Get recent comments by agent + * + * @param {string} agentId - Agent ID + * @param {number} limit - Max comments + * @returns {Promise} Comments with post context + */ + static async getRecentComments(agentId, limit = 20) { + return queryAll( + `SELECT c.id, c.content, c.score, c.upvotes, c.downvotes, + c.created_at, c.post_id, + p.title as post_title, p.submolt as post_submolt + FROM comments c + JOIN posts p ON c.post_id = p.id + WHERE c.author_id = $1 AND c.is_deleted = false + ORDER BY c.created_at DESC LIMIT $2`, + [agentId, limit] + ); + } } module.exports = AgentService;