'use strict'; var chunkO4O2EJF7_cjs = require('./chunk-O4O2EJF7.cjs'); var chunk3ARFTVAY_cjs = require('./chunk-3ARFTVAY.cjs'); var chunkKGUHJRHZ_cjs = require('./chunk-KGUHJRHZ.cjs'); var chunkTIWGWGIO_cjs = require('./chunk-TIWGWGIO.cjs'); var chunkGZ4HWZWE_cjs = require('./chunk-GZ4HWZWE.cjs'); var chunkZ7LCIYK7_cjs = require('./chunk-Z7LCIYK7.cjs'); var chunkG54X6VE6_cjs = require('./chunk-G54X6VE6.cjs'); var chunk64ITUOXI_cjs = require('./chunk-64ITUOXI.cjs'); // src/server/handlers/stored-agent-favorites.ts async function getFavoritesContext(mastra) { const storage = mastra.getStorage(); if (!storage) { throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "Storage is not configured" }); } const agentStore = await storage.getStore("agents"); if (!agentStore) { throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "Agents storage domain is not available" }); } const favoritesStore = await storage.getStore("favorites"); if (!favoritesStore) { throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "Favorites storage domain is not available" }); } return { agentStore, favoritesStore }; } var FAVORITE_STORED_AGENT_ROUTE = chunkG54X6VE6_cjs.createRoute({ method: "PUT", path: "/stored/agents/:storedAgentId/favorite", responseType: "json", pathParamSchema: chunkTIWGWGIO_cjs.storedAgentIdPathParams, responseSchema: chunkO4O2EJF7_cjs.favoriteToggleResponseSchema, summary: "Favorite a stored agent", description: "Marks the stored agent as favorited by the calling user. Idempotent.", tags: ["Stored Agents"], requiresAuth: true, requiresPermission: "stored-agents:read", handler: async ({ mastra, requestContext, storedAgentId }) => { try { await chunk3ARFTVAY_cjs.requireBuilderFeature(mastra, "favorites"); const callerId = chunkKGUHJRHZ_cjs.getCallerAuthorId(requestContext); if (!callerId) { throw new chunk64ITUOXI_cjs.HTTPException(401, { message: "Authentication required" }); } const { agentStore, favoritesStore } = await getFavoritesContext(mastra); const agent = await agentStore.getById(storedAgentId); if (!agent) { throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Stored agent with id ${storedAgentId} not found` }); } chunkGZ4HWZWE_cjs.assertStoredResourceScope(agent, await chunkGZ4HWZWE_cjs.getStoredResourceScope(mastra, requestContext)); chunkKGUHJRHZ_cjs.assertReadAccess({ requestContext, resource: "stored-agents", resourceId: storedAgentId, record: agent }); const result = await favoritesStore.favorite({ userId: callerId, entityType: "agent", entityId: storedAgentId }); return result; } catch (error) { return chunkZ7LCIYK7_cjs.handleError(error, "Error favoriting stored agent"); } } }); var UNFAVORITE_STORED_AGENT_ROUTE = chunkG54X6VE6_cjs.createRoute({ method: "DELETE", path: "/stored/agents/:storedAgentId/favorite", responseType: "json", pathParamSchema: chunkTIWGWGIO_cjs.storedAgentIdPathParams, responseSchema: chunkO4O2EJF7_cjs.favoriteToggleResponseSchema, summary: "Unfavorite a stored agent", description: "Removes the caller\u2019s favorite from the stored agent. Idempotent.", tags: ["Stored Agents"], requiresAuth: true, requiresPermission: "stored-agents:read", handler: async ({ mastra, requestContext, storedAgentId }) => { try { await chunk3ARFTVAY_cjs.requireBuilderFeature(mastra, "favorites"); const callerId = chunkKGUHJRHZ_cjs.getCallerAuthorId(requestContext); if (!callerId) { throw new chunk64ITUOXI_cjs.HTTPException(401, { message: "Authentication required" }); } const { agentStore, favoritesStore } = await getFavoritesContext(mastra); const agent = await agentStore.getById(storedAgentId); if (!agent) { throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Stored agent with id ${storedAgentId} not found` }); } chunkGZ4HWZWE_cjs.assertStoredResourceScope(agent, await chunkGZ4HWZWE_cjs.getStoredResourceScope(mastra, requestContext)); chunkKGUHJRHZ_cjs.assertReadAccess({ requestContext, resource: "stored-agents", resourceId: storedAgentId, record: agent }); const result = await favoritesStore.unfavorite({ userId: callerId, entityType: "agent", entityId: storedAgentId }); return result; } catch (error) { return chunkZ7LCIYK7_cjs.handleError(error, "Error unfavoriting stored agent"); } } }); exports.FAVORITE_STORED_AGENT_ROUTE = FAVORITE_STORED_AGENT_ROUTE; exports.UNFAVORITE_STORED_AGENT_ROUTE = UNFAVORITE_STORED_AGENT_ROUTE; //# sourceMappingURL=chunk-EP6T47YP.cjs.map //# sourceMappingURL=chunk-EP6T47YP.cjs.map