{"version":3,"sources":["../src/server/handlers/stored-agent-favorites.ts"],"names":["HTTPException","createRoute","storedAgentIdPathParams","favoriteToggleResponseSchema","requireBuilderFeature","getCallerAuthorId","assertStoredResourceScope","getStoredResourceScope","assertReadAccess","handleError"],"mappings":";;;;;;;;;;;;AAaA,eAAe,oBAAoB,MAAA,EAAqD;AACtF,EAAA,MAAM,OAAA,GAAU,OAAO,UAAA,EAAW;AAClC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,IAAIA,+BAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,6BAA6B,CAAA;AAAA,EACvE;AACA,EAAA,MAAM,UAAA,GAAa,MAAM,OAAA,CAAQ,QAAA,CAAS,QAAQ,CAAA;AAClD,EAAA,IAAI,CAAC,UAAA,EAAY;AACf,IAAA,MAAM,IAAIA,+BAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,0CAA0C,CAAA;AAAA,EACpF;AACA,EAAA,MAAM,cAAA,GAAiB,MAAM,OAAA,CAAQ,QAAA,CAAS,WAAW,CAAA;AACzD,EAAA,IAAI,CAAC,cAAA,EAAgB;AACnB,IAAA,MAAM,IAAIA,+BAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,6CAA6C,CAAA;AAAA,EACvF;AACA,EAAA,OAAO,EAAE,YAAY,cAAA,EAAe;AACtC;AAKO,IAAM,8BAA8BC,6BAAA,CAAY;AAAA,EACrD,MAAA,EAAQ,KAAA;AAAA,EACR,IAAA,EAAM,wCAAA;AAAA,EACN,YAAA,EAAc,MAAA;AAAA,EACd,eAAA,EAAiBC,yCAAA;AAAA,EACjB,cAAA,EAAgBC,8CAAA;AAAA,EAChB,OAAA,EAAS,yBAAA;AAAA,EACT,WAAA,EAAa,sEAAA;AAAA,EACb,IAAA,EAAM,CAAC,eAAe,CAAA;AAAA,EACtB,YAAA,EAAc,IAAA;AAAA,EACd,kBAAA,EAAoB,oBAAA;AAAA,EACpB,SAAS,OAAO,EAAE,M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A,IACT,SAAS,KAAA,EAAO;AACd,MAAA,OAAOC,6BAAA,CAAY,OAAO,iCAAiC,CAAA;AAAA,IAC7D;AAAA,EACF;AACF,CAAC","file":"chunk-EP6T47YP.cjs","sourcesContent":["import { HTTPException } from '../http-exception';\nimport { favoriteToggleResponseSchema } from '../schemas/favorites';\nimport { storedAgentIdPathParams } from '../schemas/stored-agents';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { assertStoredResourceScope, getStoredResourceScope } from '../utils';\n\nimport { assertReadAccess, getCallerAuthorId } from './authorship';\nimport { requireBuilderFeature } from './editor-builder';\nimport { handleError } from './error';\n\n/**\n * Resolves the storage and favorites domains, throwing 500 if unavailable.\n */\nasync function getFavoritesContext(mastra: Parameters[0]) {\n const storage = mastra.getStorage();\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not configured' });\n }\n const agentStore = await storage.getStore('agents');\n if (!agentStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n const favoritesStore = await storage.getStore('favorites');\n if (!favoritesStore) {\n throw new HTTPException(500, { message: 'Favorites storage domain is not available' });\n }\n return { agentStore, favoritesStore };\n}\n\n/**\n * PUT /stored/agents/:storedAgentId/favorite\n */\nexport const FAVORITE_STORED_AGENT_ROUTE = createRoute({\n method: 'PUT',\n path: '/stored/agents/:storedAgentId/favorite',\n responseType: 'json',\n pathParamSchema: storedAgentIdPathParams,\n responseSchema: favoriteToggleResponseSchema,\n summary: 'Favorite a stored agent',\n description: 'Marks the stored agent as favorited by the calling user. Idempotent.',\n tags: ['Stored Agents'],\n requiresAuth: true,\n requiresPermission: 'stored-agents:read',\n handler: async ({ mastra, requestContext, storedAgentId }) => {\n try {\n await requireBuilderFeature(mastra, 'favorites');\n\n const callerId = getCallerAuthorId(requestContext);\n if (!callerId) {\n throw new HTTPException(401, { message: 'Authentication required' });\n }\n\n const { agentStore, favoritesStore } = await getFavoritesContext(mastra);\n\n const agent = await agentStore.getById(storedAgentId);\n if (!agent) {\n throw new HTTPException(404, { message: `Stored agent with id ${storedAgentId} not found` });\n }\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n // Throws 404 if the caller cannot read the agent (private + not owner/admin).\n assertReadAccess({ requestContext, resource: 'stored-agents', resourceId: storedAgentId, record: agent });\n\n const result = await favoritesStore.favorite({\n userId: callerId,\n entityType: 'agent',\n entityId: storedAgentId,\n });\n return result;\n } catch (error) {\n return handleError(error, 'Error favoriting stored agent');\n }\n },\n});\n\n/**\n * DELETE /stored/agents/:storedAgentId/favorite\n */\nexport const UNFAVORITE_STORED_AGENT_ROUTE = createRoute({\n method: 'DELETE',\n path: '/stored/agents/:storedAgentId/favorite',\n responseType: 'json',\n pathParamSchema: storedAgentIdPathParams,\n responseSchema: favoriteToggleResponseSchema,\n summary: 'Unfavorite a stored agent',\n description: 'Removes the caller’s favorite from the stored agent. Idempotent.',\n tags: ['Stored Agents'],\n requiresAuth: true,\n requiresPermission: 'stored-agents:read',\n handler: async ({ mastra, requestContext, storedAgentId }) => {\n try {\n await requireBuilderFeature(mastra, 'favorites');\n\n const callerId = getCallerAuthorId(requestContext);\n if (!callerId) {\n throw new HTTPException(401, { message: 'Authentication required' });\n }\n\n const { agentStore, favoritesStore } = await getFavoritesContext(mastra);\n\n const agent = await agentStore.getById(storedAgentId);\n if (!agent) {\n throw new HTTPException(404, { message: `Stored agent with id ${storedAgentId} not found` });\n }\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n assertReadAccess({ requestContext, resource: 'stored-agents', resourceId: storedAgentId, record: agent });\n\n const result = await favoritesStore.unfavorite({\n userId: callerId,\n entityType: 'agent',\n entityId: storedAgentId,\n });\n return result;\n } catch (error) {\n return handleError(error, 'Error unfavoriting stored agent');\n }\n },\n});\n"]}