{"version":3,"sources":["../src/server/handlers/stored-scorers.ts"],"names":["createRoute","listStoredScorersQuerySchema","listStoredScorersResponseSchema","HTTPException","getStoredResourceScope","scopeStoredResourceMetadata","handleError","storedScorerIdPathParams","statusQuerySchema","getStoredScorerResponseSchema","assertStoredResourceScope","createStoredScorerBodySchema","createStoredScorerResponseSchema","toSlug","updateStoredScorerBodySchema","updateStoredScorerResponseSchema","handleAutoVersioning","deleteStoredScorerResponseSchema"],"mappings":";;;;;;;;;;;AAoBA,IAAM,6BAAA,GAAgC;AAAA,EACpC,MAAA;AAAA,EACA,aAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA,cAAA;AAAA,EACA,YAAA;AAAA,EACA,cAAA;AAAA,EACA;AACF,CAAA;AASO,IAAM,4BAA4BA,6BAAA,CAAY;AAAA,EACnD,MAAA,EAAQ,KAAA;AAAA,EACR,IAAA,EAAM,iBAAA;AAAA,EACN,YAAA,EAAc,MAAA;AAAA,EACd,gBAAA,EAAkBC,8CAAA;AAAA,EAClB,cAAA,EAAgBC,iDAAA;AAAA,EAChB,OAAA,EAAS,gCAAA;AAAA,EACT,WAAA,EAAa,2EAAA;AAAA,EACb,IAAA,EAAM,CAAC,gBAAgB,CAAA;AAAA,EACvB,YAAA,EAAc,IAAA;AAAA,EACd,OAAA,EAAS,OAAO,EAAE,MAAA,EAAQ,IAAA,EAAM,OAAA,EAAS,OAAA,EAAS,MAAA,EAAQ,QAAA,EAAU,QAAA,EAAU,cAAA,EAAe,KAAM;AACjG,IAAA,IAAI;AACF,MAAA,MAAM,OAAA,GAAU,OAAO,UAAA,EAAW;AAElC,MAAA,IAAI,CAAC,OAAA,EAAS;AACZ,QAAA,MAAM,IAAIC,+BAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,6BAA6B,CAAA;AAAA,MACvE;AAEA,MAAA,MAAM,WAAA,GAAc,MAAM,OAAA,CAAQ,QAAA,CAAS,mBAAmB,CAAA;AAC9D,MAAA,IAAI,CAA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c,GAAA,EAAK,EAAE,OAAA,EAAS,6BAA6B,CAAA;AAAA,MACvE;AAEA,MAAA,MAAM,WAAA,GAAc,MAAM,OAAA,CAAQ,QAAA,CAAS,mBAAmB,CAAA;AAC9D,MAAA,IAAI,CAAC,WAAA,EAAa;AAChB,QAAA,MAAM,IAAIA,+BAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,sDAAsD,CAAA;AAAA,MAChG;AAGA,MAAA,MAAM,QAAA,GAAW,MAAM,WAAA,CAAY,OAAA,CAAQ,cAAc,CAAA;AACzD,MAAA,IAAI,CAAC,QAAA,EAAU;AACb,QAAA,MAAM,IAAIA,gCAAc,GAAA,EAAK,EAAE,SAAS,CAAA,iCAAA,EAAoC,cAAc,cAAc,CAAA;AAAA,MAC1G;AACA,MAAAO,2CAAA,CAA0B,QAAA,EAAU,MAAMN,wCAAA,CAAuB,MAAA,EAAQ,cAAc,CAAC,CAAA;AAExF,MAAA,MAAM,WAAA,CAAY,OAAO,cAAc,CAAA;AAGvC,MAAA,MAAA,CAAO,SAAA,EAAU,EAAG,MAAA,CAAO,UAAA,CAAW,cAAc,CAAA;AAEpD,MAAA,OAAO,EAAE,OAAA,EAAS,IAAA,EAAM,OAAA,EAAS,CAAA,kBAAA,EAAqB,cAAc,CAAA,qBAAA,CAAA,EAAwB;AAAA,IAC9F,SAAS,KAAA,EAAO;AACd,MAAA,OAAOE,6BAAA,CAAY,OAAO,yCAAyC,CAAA;AAAA,IACrE;AAAA,EACF;AACF,CAAC","file":"chunk-IRJJ2JJG.cjs","sourcesContent":["import { HTTPException } from '../http-exception';\nimport {\n storedScorerIdPathParams,\n statusQuerySchema,\n listStoredScorersQuerySchema,\n createStoredScorerBodySchema,\n updateStoredScorerBodySchema,\n listStoredScorersResponseSchema,\n getStoredScorerResponseSchema,\n createStoredScorerResponseSchema,\n updateStoredScorerResponseSchema,\n deleteStoredScorerResponseSchema,\n} from '../schemas/stored-scorers';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { assertStoredResourceScope, getStoredResourceScope, scopeStoredResourceMetadata, toSlug } from '../utils';\n\nimport { handleError } from './error';\nimport { handleAutoVersioning } from './version-helpers';\nimport type { VersionedStoreInterface } from './version-helpers';\n\nconst SCORER_SNAPSHOT_CONFIG_FIELDS = [\n 'name',\n 'description',\n 'type',\n 'model',\n 'instructions',\n 'scoreRange',\n 'presetConfig',\n 'defaultSampling',\n] as const;\n\n// ============================================================================\n// Route Definitions\n// ============================================================================\n\n/**\n * GET /stored/scorers - List all stored scorer definitions\n */\nexport const LIST_STORED_SCORERS_ROUTE = createRoute({\n method: 'GET',\n path: '/stored/scorers',\n responseType: 'json',\n queryParamSchema: listStoredScorersQuerySchema,\n responseSchema: listStoredScorersResponseSchema,\n summary: 'List stored scorer definitions',\n description: 'Returns a paginated list of all scorer definitions stored in the database',\n tags: ['Stored Scorers'],\n requiresAuth: true,\n handler: async ({ mastra, page, perPage, orderBy, status, authorId, metadata, requestContext }) => {\n try {\n const storage = mastra.getStorage();\n\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not configured' });\n }\n\n const scorerStore = await storage.getStore('scorerDefinitions');\n if (!scorerStore) {\n throw new HTTPException(500, { message: 'Scorer definitions storage domain is not available' });\n }\n\n const scope = await getStoredResourceScope(mastra, requestContext);\n const result = await scorerStore.listResolved({\n page,\n perPage,\n orderBy,\n status,\n authorId,\n metadata: scopeStoredResourceMetadata(metadata, scope),\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error listing stored scorer definitions');\n }\n },\n});\n\n/**\n * GET /stored/scorers/:storedScorerId - Get a stored scorer definition by ID\n */\nexport const GET_STORED_SCORER_ROUTE = createRoute({\n method: 'GET',\n path: '/stored/scorers/:storedScorerId',\n responseType: 'json',\n pathParamSchema: storedScorerIdPathParams,\n queryParamSchema: statusQuerySchema,\n responseSchema: getStoredScorerResponseSchema,\n summary: 'Get stored scorer definition by ID',\n description:\n 'Returns a specific scorer definition from storage by its unique identifier. Use ?status=draft to resolve with the latest (draft) version, or ?status=published (default) for the active published version.',\n tags: ['Stored Scorers'],\n requiresAuth: true,\n handler: async ({ mastra, storedScorerId, status, requestContext }) => {\n try {\n const storage = mastra.getStorage();\n\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not configured' });\n }\n\n const scorerStore = await storage.getStore('scorerDefinitions');\n if (!scorerStore) {\n throw new HTTPException(500, { message: 'Scorer definitions storage domain is not available' });\n }\n\n const scorer = await scorerStore.getByIdResolved(storedScorerId, { status });\n\n if (!scorer) {\n throw new HTTPException(404, { message: `Stored scorer definition with id ${storedScorerId} not found` });\n }\n assertStoredResourceScope(scorer, await getStoredResourceScope(mastra, requestContext));\n\n return scorer;\n } catch (error) {\n return handleError(error, 'Error getting stored scorer definition');\n }\n },\n});\n\n/**\n * POST /stored/scorers - Create a new stored scorer definition\n */\nexport const CREATE_STORED_SCORER_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/scorers',\n responseType: 'json',\n bodySchema: createStoredScorerBodySchema,\n responseSchema: createStoredScorerResponseSchema,\n summary: 'Create stored scorer definition',\n description: 'Creates a new scorer definition in storage with the provided configuration',\n tags: ['Stored Scorers'],\n requiresAuth: true,\n handler: async ({\n mastra,\n id: providedId,\n authorId,\n metadata,\n name,\n description,\n type,\n model,\n instructions,\n scoreRange,\n presetConfig,\n defaultSampling,\n requestContext,\n }) => {\n try {\n const storage = mastra.getStorage();\n\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not configured' });\n }\n\n const scorerStore = await storage.getStore('scorerDefinitions');\n if (!scorerStore) {\n throw new HTTPException(500, { message: 'Scorer definitions storage domain is not available' });\n }\n\n // Derive ID from name if not explicitly provided\n const id = providedId || toSlug(name);\n\n if (!id) {\n throw new HTTPException(400, {\n message: 'Could not derive scorer definition ID from name. Please provide an explicit id.',\n });\n }\n\n // Check if scorer definition with this ID already exists\n const existing = await scorerStore.getById(id);\n if (existing) {\n throw new HTTPException(409, { message: `Scorer definition with id ${id} already exists` });\n }\n\n await scorerStore.create({\n scorerDefinition: {\n id,\n authorId,\n metadata: scopeStoredResourceMetadata(metadata, await getStoredResourceScope(mastra, requestContext)),\n name,\n description,\n type,\n model,\n instructions,\n scoreRange,\n presetConfig,\n defaultSampling,\n },\n });\n\n // Return the resolved scorer definition (thin record + version config)\n // Use draft status since newly created entities start as drafts\n const resolved = await scorerStore.getByIdResolved(id, { status: 'draft' });\n if (!resolved) {\n throw new HTTPException(500, { message: 'Failed to resolve created scorer definition' });\n }\n\n return resolved;\n } catch (error) {\n return handleError(error, 'Error creating stored scorer definition');\n }\n },\n});\n\n/**\n * PATCH /stored/scorers/:storedScorerId - Update a stored scorer definition\n */\nexport const UPDATE_STORED_SCORER_ROUTE = createRoute({\n method: 'PATCH',\n path: '/stored/scorers/:storedScorerId',\n responseType: 'json',\n pathParamSchema: storedScorerIdPathParams,\n bodySchema: updateStoredScorerBodySchema,\n responseSchema: updateStoredScorerResponseSchema,\n summary: 'Update stored scorer definition',\n description: 'Updates an existing scorer definition in storage with the provided fields',\n tags: ['Stored Scorers'],\n requiresAuth: true,\n handler: async ({\n mastra,\n storedScorerId,\n // Metadata-level fields\n authorId,\n metadata,\n // Config fields (snapshot-level)\n name,\n description,\n type,\n model,\n instructions,\n scoreRange,\n presetConfig,\n defaultSampling,\n requestContext,\n }) => {\n try {\n const storage = mastra.getStorage();\n\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not configured' });\n }\n\n const scorerStore = await storage.getStore('scorerDefinitions');\n if (!scorerStore) {\n throw new HTTPException(500, { message: 'Scorer definitions storage domain is not available' });\n }\n\n // Check if scorer definition exists\n const existing = await scorerStore.getById(storedScorerId);\n if (!existing) {\n throw new HTTPException(404, { message: `Stored scorer definition with id ${storedScorerId} not found` });\n }\n const scope = await getStoredResourceScope(mastra, requestContext);\n assertStoredResourceScope(existing, scope);\n const scopedMetadata =\n metadata !== undefined\n ? scopeStoredResourceMetadata({ ...(existing.metadata ?? {}), ...metadata }, scope)\n : undefined;\n\n // Update the scorer definition with both metadata-level and config-level fields\n const updatedScorer = await scorerStore.update({\n id: storedScorerId,\n authorId,\n ...(scopedMetadata !== undefined ? { metadata: scopedMetadata } : {}),\n name,\n description,\n type,\n model,\n instructions,\n scoreRange,\n presetConfig,\n defaultSampling,\n });\n\n // Build the snapshot config for auto-versioning comparison\n const configFields = {\n name,\n description,\n type,\n model,\n instructions,\n scoreRange,\n presetConfig,\n defaultSampling,\n };\n\n // Filter out undefined values to get only the config fields that were provided\n const providedConfigFields = Object.fromEntries(Object.entries(configFields).filter(([_, v]) => v !== undefined));\n\n // Handle auto-versioning with retry logic for race conditions\n // This creates a new version if there are meaningful config changes.\n // It does NOT update activeVersionId — the version stays as a draft until explicitly published.\n await handleAutoVersioning(\n scorerStore as unknown as VersionedStoreInterface,\n storedScorerId,\n 'scorerDefinitionId',\n SCORER_SNAPSHOT_CONFIG_FIELDS,\n existing,\n updatedScorer,\n providedConfigFields,\n );\n\n // Clear the cached scorer instance so the next request gets the updated config\n const editor = mastra.getEditor();\n if (editor) {\n editor.scorer.clearCache(storedScorerId);\n }\n\n // Return the resolved scorer definition with the latest (draft) version so the UI sees its edits\n const resolved = await scorerStore.getByIdResolved(storedScorerId, { status: 'draft' });\n if (!resolved) {\n throw new HTTPException(500, { message: 'Failed to resolve updated scorer definition' });\n }\n\n return resolved;\n } catch (error) {\n return handleError(error, 'Error updating stored scorer definition');\n }\n },\n});\n\n/**\n * DELETE /stored/scorers/:storedScorerId - Delete a stored scorer definition\n */\nexport const DELETE_STORED_SCORER_ROUTE = createRoute({\n method: 'DELETE',\n path: '/stored/scorers/:storedScorerId',\n responseType: 'json',\n pathParamSchema: storedScorerIdPathParams,\n responseSchema: deleteStoredScorerResponseSchema,\n summary: 'Delete stored scorer definition',\n description: 'Deletes a scorer definition from storage by its unique identifier',\n tags: ['Stored Scorers'],\n requiresAuth: true,\n handler: async ({ mastra, storedScorerId, requestContext }) => {\n try {\n const storage = mastra.getStorage();\n\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not configured' });\n }\n\n const scorerStore = await storage.getStore('scorerDefinitions');\n if (!scorerStore) {\n throw new HTTPException(500, { message: 'Scorer definitions storage domain is not available' });\n }\n\n // Check if scorer definition exists\n const existing = await scorerStore.getById(storedScorerId);\n if (!existing) {\n throw new HTTPException(404, { message: `Stored scorer definition with id ${storedScorerId} not found` });\n }\n assertStoredResourceScope(existing, await getStoredResourceScope(mastra, requestContext));\n\n await scorerStore.delete(storedScorerId);\n\n // Clear the cached scorer instance\n mastra.getEditor()?.scorer.clearCache(storedScorerId);\n\n return { success: true, message: `Scorer definition ${storedScorerId} deleted successfully` };\n } catch (error) {\n return handleError(error, 'Error deleting stored scorer definition');\n }\n },\n});\n"]}