@mastra/server 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/{chunk-P4O7OBGH.cjs → chunk-3BKGGOC6.cjs} +3 -3
- package/dist/{chunk-P4O7OBGH.cjs.map → chunk-3BKGGOC6.cjs.map} +1 -1
- package/dist/{chunk-CMYJ32N3.js → chunk-EFKPTKKF.js} +51 -15
- package/dist/chunk-EFKPTKKF.js.map +1 -0
- package/dist/{chunk-NC6UUX6D.js → chunk-KTGIAURI.js} +3 -2
- package/dist/chunk-KTGIAURI.js.map +1 -0
- package/dist/{chunk-NGFAF6WW.cjs → chunk-MJLQLQ6K.cjs} +51 -15
- package/dist/chunk-MJLQLQ6K.cjs.map +1 -0
- package/dist/{chunk-VHBLYGH7.js → chunk-PGB5HYV7.js} +3 -3
- package/dist/{chunk-VHBLYGH7.js.map → chunk-PGB5HYV7.js.map} +1 -1
- package/dist/{chunk-GPRCK7GP.cjs → chunk-ZE4IJKQD.cjs} +3 -2
- package/dist/chunk-ZE4IJKQD.cjs.map +1 -0
- package/dist/{observational-memory-ZNTAIUGT-565A3END.cjs → observational-memory-AJWSMZVP-HI6EWRCH.cjs} +29 -12
- package/dist/observational-memory-AJWSMZVP-HI6EWRCH.cjs.map +1 -0
- package/dist/{observational-memory-ZNTAIUGT-VIXA4SKE.js → observational-memory-AJWSMZVP-J3OYOGXO.js} +29 -12
- package/dist/observational-memory-AJWSMZVP-J3OYOGXO.js.map +1 -0
- package/dist/server/handlers/agent-builder.cjs +16 -16
- package/dist/server/handlers/agent-builder.js +1 -1
- package/dist/server/handlers/prompt-block-versions.cjs +8 -8
- package/dist/server/handlers/prompt-block-versions.d.ts +6 -0
- package/dist/server/handlers/prompt-block-versions.d.ts.map +1 -1
- package/dist/server/handlers/prompt-block-versions.js +1 -1
- package/dist/server/handlers/stored-prompt-blocks.cjs +6 -6
- package/dist/server/handlers/stored-prompt-blocks.d.ts +16 -4
- package/dist/server/handlers/stored-prompt-blocks.d.ts.map +1 -1
- package/dist/server/handlers/stored-prompt-blocks.js +1 -1
- package/dist/server/handlers.cjs +2 -2
- package/dist/server/handlers.js +1 -1
- package/dist/server/schemas/prompt-block-versions.d.ts +27 -0
- package/dist/server/schemas/prompt-block-versions.d.ts.map +1 -1
- package/dist/server/schemas/stored-prompt-blocks.d.ts +44 -4
- package/dist/server/schemas/stored-prompt-blocks.d.ts.map +1 -1
- package/dist/server/server-adapter/index.cjs +30 -30
- package/dist/server/server-adapter/index.js +3 -3
- package/package.json +6 -6
- package/dist/chunk-CMYJ32N3.js.map +0 -1
- package/dist/chunk-GPRCK7GP.cjs.map +0 -1
- package/dist/chunk-NC6UUX6D.js.map +0 -1
- package/dist/chunk-NGFAF6WW.cjs.map +0 -1
- package/dist/docs/SKILL.md +0 -28
- package/dist/docs/assets/SOURCE_MAP.json +0 -6
- package/dist/docs/references/docs-server-custom-adapters.md +0 -374
- package/dist/docs/references/reference-server-create-route.md +0 -260
- package/dist/docs/references/reference-server-mastra-server.md +0 -298
- package/dist/docs/references/reference-server-routes.md +0 -306
- package/dist/observational-memory-ZNTAIUGT-565A3END.cjs.map +0 -1
- package/dist/observational-memory-ZNTAIUGT-VIXA4SKE.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server/schemas/prompt-block-versions.ts","../src/server/handlers/prompt-block-versions.ts"],"names":["listVersionsQuerySchema","compareVersionsQuerySchema","createVersionBodySchema","z","ruleGroupSchema","createListVersionsResponseSchema","activateVersionResponseSchema","deleteVersionResponseSchema","createCompareVersionsResponseSchema","createRoute","HTTPException","handleError","extractConfigFromVersion","calculateChangedFields","createVersionWithRetry","enforceRetentionLimit","computeVersionDiffs"],"mappings":";;;;;;;;;;;;;;AAcO,IAAM,kCAAA,GAAqCA,yCAAA;AAC3C,IAAM,qCAAA,GAAwCC,4CAAA;AAC9C,IAAM,kCAAA,GA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OAAA,EAAS,CAAA,gBAAA,EAAmB,IAAI,CAAA,4BAAA,EAA+B,aAAa,CAAA;AAAA,SAC7E,CAAA;AAAA,MACH;AAEA,MAAA,MAAM,SAAA,GAAY,MAAM,gBAAA,CAAiB,UAAA,CAAW,EAAE,CAAA;AACtD,MAAA,IAAI,CAAC,SAAA,EAAW;AACd,QAAA,MAAM,IAAIA,gCAAc,GAAA,EAAK,EAAE,SAAS,CAAA,gBAAA,EAAmB,EAAE,cAAc,CAAA;AAAA,MAC7E;AACA,MAAA,IAAI,SAAA,CAAU,YAAY,aAAA,EAAe;AACvC,QAAA,MAAM,IAAIA,gCAAc,GAAA,EAAK;AAAA,UAC3B,OAAA,EAAS,CAAA,gBAAA,EAAmB,EAAE,CAAA,4BAAA,EAA+B,aAAa,CAAA;AAAA,SAC3E,CAAA;AAAA,MACH;AAEA,MAAA,MAAM,UAAA,GAAaE,0CAAA;AAAA,QACjB,WAAA;AAAA,QACA;AAAA,OACF;AACA,MAAA,MAAM,QAAA,GAAWA,0CAAA;AAAA,QACf,SAAA;AAAA,QACA;AAAA,OACF;AAEA,MAAA,MAAM,KAAA,GAAQI,qCAAA,CAAoB,UAAA,EAAY,QAAQ,CAAA;AAEtD,MAAA,OAAO;AAAA,QACL,KAAA;AAAA,QACA,WAAA;AAAA,QACA;AAAA,OACF;AAAA,IACF,SAAS,KAAA,EAAO;AACd,MAAA,OAAOL,6BAAA,CAAY,OAAO,uCAAuC,CAAA;AAAA,IACnE;AAAA,EACF;AACF,CAAC","file":"chunk-GPRCK7GP.cjs","sourcesContent":["import z from 'zod';\nimport { ruleGroupSchema } from './rule-group';\nimport {\n listVersionsQuerySchema,\n compareVersionsQuerySchema,\n createVersionBodySchema,\n activateVersionResponseSchema,\n deleteVersionResponseSchema,\n versionDiffEntrySchema,\n createListVersionsResponseSchema,\n createCompareVersionsResponseSchema,\n} from './version-common';\n\n// Re-export shared schemas under domain-specific names\nexport const listPromptBlockVersionsQuerySchema = listVersionsQuerySchema;\nexport const comparePromptBlockVersionsQuerySchema = compareVersionsQuerySchema;\nexport const createPromptBlockVersionBodySchema = createVersionBodySchema;\n\n// ============================================================================\n// Path Parameter Schemas\n// ============================================================================\n\nexport const promptBlockVersionPathParams = z.object({\n promptBlockId: z.string().describe('Unique identifier for the stored prompt block'),\n});\n\nexport const promptBlockVersionIdPathParams = z.object({\n promptBlockId: z.string().describe('Unique identifier for the stored prompt block'),\n versionId: z.string().describe('Unique identifier for the version (UUID)'),\n});\n\n// ============================================================================\n// Response Schemas\n// ============================================================================\n\nexport const promptBlockVersionSchema = z.object({\n id: z.string().describe('Unique identifier for the version (UUID)'),\n blockId: z.string().describe('ID of the prompt block this version belongs to'),\n versionNumber: z.number().describe('Sequential version number (1, 2, 3, ...)'),\n // Snapshot config fields\n name: z.string().describe('Display name of the prompt block'),\n description: z.string().optional().describe('Purpose description'),\n content: z.string().describe('Template content with {{variable}} interpolation'),\n rules: ruleGroupSchema.optional().describe('Rules for conditional inclusion'),\n // Version metadata\n changedFields: z.array(z.string()).optional().describe('Array of field names that changed from the previous version'),\n changeMessage: z.string().optional().describe('Optional message describing the changes'),\n createdAt: z.coerce.date().describe('When this version was created'),\n});\n\nexport const listPromptBlockVersionsResponseSchema = createListVersionsResponseSchema(promptBlockVersionSchema);\n\nexport const getPromptBlockVersionResponseSchema = promptBlockVersionSchema;\n\nexport const createPromptBlockVersionResponseSchema = promptBlockVersionSchema.partial().merge(\n z.object({\n id: z.string(),\n blockId: z.string(),\n versionNumber: z.number(),\n createdAt: z.coerce.date(),\n }),\n);\n\nexport const activatePromptBlockVersionResponseSchema = activateVersionResponseSchema;\n\nexport const restorePromptBlockVersionResponseSchema = promptBlockVersionSchema;\n\nexport const deletePromptBlockVersionResponseSchema = deleteVersionResponseSchema;\n\nexport const comparePromptBlockVersionsResponseSchema = createCompareVersionsResponseSchema(promptBlockVersionSchema);\n\nexport { versionDiffEntrySchema };\n","import { HTTPException } from '../http-exception';\nimport {\n promptBlockVersionPathParams,\n promptBlockVersionIdPathParams,\n listPromptBlockVersionsQuerySchema,\n createPromptBlockVersionBodySchema,\n comparePromptBlockVersionsQuerySchema,\n listPromptBlockVersionsResponseSchema,\n getPromptBlockVersionResponseSchema,\n createPromptBlockVersionResponseSchema,\n activatePromptBlockVersionResponseSchema,\n restorePromptBlockVersionResponseSchema,\n deletePromptBlockVersionResponseSchema,\n comparePromptBlockVersionsResponseSchema,\n} from '../schemas/prompt-block-versions';\nimport { createRoute } from '../server-adapter/routes/route-builder';\n\nimport { handleError } from './error';\nimport {\n extractConfigFromVersion,\n calculateChangedFields,\n computeVersionDiffs,\n createVersionWithRetry,\n enforceRetentionLimit,\n} from './version-helpers';\nimport type { VersionedStoreInterface } from './version-helpers';\n\nconst SNAPSHOT_CONFIG_FIELDS = ['name', 'description', 'content', 'rules'] as const;\n\n/**\n * GET /stored/prompt-blocks/:promptBlockId/versions - List all versions for a prompt block\n */\nexport const LIST_PROMPT_BLOCK_VERSIONS_ROUTE = createRoute({\n method: 'GET',\n path: '/stored/prompt-blocks/:promptBlockId/versions',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: promptBlockVersionPathParams,\n queryParamSchema: listPromptBlockVersionsQuerySchema,\n responseSchema: listPromptBlockVersionsResponseSchema,\n summary: 'List prompt block versions',\n description: 'Returns a paginated list of all versions for a stored prompt block',\n tags: ['Prompt Block Versions'],\n handler: async ({ mastra, promptBlockId, page, perPage, orderBy }) => {\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 promptBlockStore = await storage.getStore('promptBlocks');\n if (!promptBlockStore) {\n throw new HTTPException(500, { message: 'Prompt blocks storage domain is not available' });\n }\n\n const promptBlock = await promptBlockStore.getById(promptBlockId);\n if (!promptBlock) {\n throw new HTTPException(404, { message: `Prompt block with id ${promptBlockId} not found` });\n }\n\n const result = await promptBlockStore.listVersions({\n blockId: promptBlockId,\n page,\n perPage,\n orderBy,\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error listing prompt block versions');\n }\n },\n});\n\n/**\n * POST /stored/prompt-blocks/:promptBlockId/versions - Create a new version snapshot\n */\nexport const CREATE_PROMPT_BLOCK_VERSION_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/prompt-blocks/:promptBlockId/versions',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: promptBlockVersionPathParams,\n bodySchema: createPromptBlockVersionBodySchema,\n responseSchema: createPromptBlockVersionResponseSchema,\n summary: 'Create prompt block version',\n description: 'Creates a new version snapshot of the current prompt block configuration',\n tags: ['Prompt Block Versions'],\n handler: async ({ mastra, promptBlockId, changeMessage }) => {\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 promptBlockStore = await storage.getStore('promptBlocks');\n if (!promptBlockStore) {\n throw new HTTPException(500, { message: 'Prompt blocks storage domain is not available' });\n }\n\n const promptBlock = await promptBlockStore.getById(promptBlockId);\n if (!promptBlock) {\n throw new HTTPException(404, { message: `Prompt block with id ${promptBlockId} not found` });\n }\n\n let currentConfig: Record<string, unknown> = {};\n if (promptBlock.activeVersionId) {\n const activeVersion = await promptBlockStore.getVersion(promptBlock.activeVersionId);\n if (activeVersion) {\n currentConfig = extractConfigFromVersion(\n activeVersion as unknown as Record<string, unknown>,\n SNAPSHOT_CONFIG_FIELDS,\n );\n }\n }\n\n const latestVersion = await promptBlockStore.getLatestVersion(promptBlockId);\n\n // If no activeVersionId, fall back to latest version config\n if (!promptBlock.activeVersionId && latestVersion) {\n currentConfig = extractConfigFromVersion(\n latestVersion as unknown as Record<string, unknown>,\n SNAPSHOT_CONFIG_FIELDS,\n );\n }\n const previousConfig = latestVersion\n ? extractConfigFromVersion(latestVersion as unknown as Record<string, unknown>, SNAPSHOT_CONFIG_FIELDS)\n : null;\n\n const changedFields = calculateChangedFields(previousConfig, currentConfig);\n\n const { versionId } = await createVersionWithRetry(\n promptBlockStore as unknown as VersionedStoreInterface,\n promptBlockId,\n 'blockId',\n currentConfig,\n changedFields,\n { changeMessage },\n );\n\n const version = await promptBlockStore.getVersion(versionId);\n if (!version) {\n throw new HTTPException(500, { message: 'Failed to retrieve created version' });\n }\n\n await enforceRetentionLimit(\n promptBlockStore as unknown as VersionedStoreInterface,\n promptBlockId,\n 'blockId',\n promptBlock.activeVersionId,\n );\n\n return version;\n } catch (error) {\n return handleError(error, 'Error creating prompt block version');\n }\n },\n});\n\n/**\n * GET /stored/prompt-blocks/:promptBlockId/versions/:versionId - Get a specific version\n */\nexport const GET_PROMPT_BLOCK_VERSION_ROUTE = createRoute({\n method: 'GET',\n path: '/stored/prompt-blocks/:promptBlockId/versions/:versionId',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: promptBlockVersionIdPathParams,\n responseSchema: getPromptBlockVersionResponseSchema,\n summary: 'Get prompt block version',\n description: 'Returns a specific version of a prompt block by its version ID',\n tags: ['Prompt Block Versions'],\n handler: async ({ mastra, promptBlockId, versionId }) => {\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 promptBlockStore = await storage.getStore('promptBlocks');\n if (!promptBlockStore) {\n throw new HTTPException(500, { message: 'Prompt blocks storage domain is not available' });\n }\n\n const version = await promptBlockStore.getVersion(versionId);\n\n if (!version) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n\n if (version.blockId !== promptBlockId) {\n throw new HTTPException(404, {\n message: `Version with id ${versionId} not found for prompt block ${promptBlockId}`,\n });\n }\n\n return version;\n } catch (error) {\n return handleError(error, 'Error getting prompt block version');\n }\n },\n});\n\n/**\n * POST /stored/prompt-blocks/:promptBlockId/versions/:versionId/activate - Set a version as active\n */\nexport const ACTIVATE_PROMPT_BLOCK_VERSION_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/prompt-blocks/:promptBlockId/versions/:versionId/activate',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: promptBlockVersionIdPathParams,\n responseSchema: activatePromptBlockVersionResponseSchema,\n summary: 'Activate prompt block version',\n description: 'Sets a specific version as the active version for the prompt block',\n tags: ['Prompt Block Versions'],\n handler: async ({ mastra, promptBlockId, versionId }) => {\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 promptBlockStore = await storage.getStore('promptBlocks');\n if (!promptBlockStore) {\n throw new HTTPException(500, { message: 'Prompt blocks storage domain is not available' });\n }\n\n const promptBlock = await promptBlockStore.getById(promptBlockId);\n if (!promptBlock) {\n throw new HTTPException(404, { message: `Prompt block with id ${promptBlockId} not found` });\n }\n\n const version = await promptBlockStore.getVersion(versionId);\n if (!version) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n if (version.blockId !== promptBlockId) {\n throw new HTTPException(404, {\n message: `Version with id ${versionId} not found for prompt block ${promptBlockId}`,\n });\n }\n\n await promptBlockStore.update({\n id: promptBlockId,\n activeVersionId: versionId,\n status: 'published',\n });\n\n // Clear the editor cache so subsequent requests see the new active version\n mastra.getEditor()?.prompt.clearCache(promptBlockId);\n\n return {\n success: true,\n message: `Version ${version.versionNumber} is now active`,\n activeVersionId: versionId,\n };\n } catch (error) {\n return handleError(error, 'Error activating prompt block version');\n }\n },\n});\n\n/**\n * POST /stored/prompt-blocks/:promptBlockId/versions/:versionId/restore - Restore prompt block to a version\n */\nexport const RESTORE_PROMPT_BLOCK_VERSION_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/prompt-blocks/:promptBlockId/versions/:versionId/restore',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: promptBlockVersionIdPathParams,\n responseSchema: restorePromptBlockVersionResponseSchema,\n summary: 'Restore prompt block version',\n description: 'Restores the prompt block configuration from a version, creating a new version',\n tags: ['Prompt Block Versions'],\n handler: async ({ mastra, promptBlockId, versionId }) => {\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 promptBlockStore = await storage.getStore('promptBlocks');\n if (!promptBlockStore) {\n throw new HTTPException(500, { message: 'Prompt blocks storage domain is not available' });\n }\n\n const promptBlock = await promptBlockStore.getById(promptBlockId);\n if (!promptBlock) {\n throw new HTTPException(404, { message: `Prompt block with id ${promptBlockId} not found` });\n }\n\n const versionToRestore = await promptBlockStore.getVersion(versionId);\n if (!versionToRestore) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n if (versionToRestore.blockId !== promptBlockId) {\n throw new HTTPException(404, {\n message: `Version with id ${versionId} not found for prompt block ${promptBlockId}`,\n });\n }\n\n const restoredConfig = extractConfigFromVersion(\n versionToRestore as unknown as Record<string, unknown>,\n SNAPSHOT_CONFIG_FIELDS,\n );\n\n await promptBlockStore.update({\n id: promptBlockId,\n ...restoredConfig,\n });\n\n const latestVersion = await promptBlockStore.getLatestVersion(promptBlockId);\n const previousConfig = latestVersion\n ? extractConfigFromVersion(latestVersion as unknown as Record<string, unknown>, SNAPSHOT_CONFIG_FIELDS)\n : null;\n\n const changedFields = calculateChangedFields(previousConfig, restoredConfig);\n\n const { versionId: newVersionId } = await createVersionWithRetry(\n promptBlockStore as unknown as VersionedStoreInterface,\n promptBlockId,\n 'blockId',\n restoredConfig,\n changedFields,\n {\n changeMessage: `Restored from version ${versionToRestore.versionNumber}`,\n },\n );\n\n const newVersion = await promptBlockStore.getVersion(newVersionId);\n if (!newVersion) {\n throw new HTTPException(500, { message: 'Failed to retrieve created version' });\n }\n\n await enforceRetentionLimit(\n promptBlockStore as unknown as VersionedStoreInterface,\n promptBlockId,\n 'blockId',\n promptBlock.activeVersionId,\n );\n\n // Clear the editor cache so subsequent requests see the updated config\n mastra.getEditor()?.prompt.clearCache(promptBlockId);\n\n return newVersion;\n } catch (error) {\n return handleError(error, 'Error restoring prompt block version');\n }\n },\n});\n\n/**\n * DELETE /stored/prompt-blocks/:promptBlockId/versions/:versionId - Delete a version\n */\nexport const DELETE_PROMPT_BLOCK_VERSION_ROUTE = createRoute({\n method: 'DELETE',\n path: '/stored/prompt-blocks/:promptBlockId/versions/:versionId',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: promptBlockVersionIdPathParams,\n responseSchema: deletePromptBlockVersionResponseSchema,\n summary: 'Delete prompt block version',\n description: 'Deletes a specific version (cannot delete the active version)',\n tags: ['Prompt Block Versions'],\n handler: async ({ mastra, promptBlockId, versionId }) => {\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 promptBlockStore = await storage.getStore('promptBlocks');\n if (!promptBlockStore) {\n throw new HTTPException(500, { message: 'Prompt blocks storage domain is not available' });\n }\n\n const promptBlock = await promptBlockStore.getById(promptBlockId);\n if (!promptBlock) {\n throw new HTTPException(404, { message: `Prompt block with id ${promptBlockId} not found` });\n }\n\n const version = await promptBlockStore.getVersion(versionId);\n if (!version) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n if (version.blockId !== promptBlockId) {\n throw new HTTPException(404, {\n message: `Version with id ${versionId} not found for prompt block ${promptBlockId}`,\n });\n }\n\n if (promptBlock.activeVersionId === versionId) {\n throw new HTTPException(400, {\n message: 'Cannot delete the active version. Activate a different version first.',\n });\n }\n\n await promptBlockStore.deleteVersion(versionId);\n\n // Clear the editor cache so subsequent requests see the updated config\n mastra.getEditor()?.prompt.clearCache(promptBlockId);\n\n return {\n success: true,\n message: `Version ${version.versionNumber} deleted successfully`,\n };\n } catch (error) {\n return handleError(error, 'Error deleting prompt block version');\n }\n },\n});\n\n/**\n * GET /stored/prompt-blocks/:promptBlockId/versions/compare - Compare two versions\n */\nexport const COMPARE_PROMPT_BLOCK_VERSIONS_ROUTE = createRoute({\n method: 'GET',\n path: '/stored/prompt-blocks/:promptBlockId/versions/compare',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: promptBlockVersionPathParams,\n queryParamSchema: comparePromptBlockVersionsQuerySchema,\n responseSchema: comparePromptBlockVersionsResponseSchema,\n summary: 'Compare prompt block versions',\n description: 'Compares two versions and returns the differences between them',\n tags: ['Prompt Block Versions'],\n handler: async ({ mastra, promptBlockId, from, to }) => {\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 promptBlockStore = await storage.getStore('promptBlocks');\n if (!promptBlockStore) {\n throw new HTTPException(500, { message: 'Prompt blocks storage domain is not available' });\n }\n\n const fromVersion = await promptBlockStore.getVersion(from);\n if (!fromVersion) {\n throw new HTTPException(404, { message: `Version with id ${from} not found` });\n }\n if (fromVersion.blockId !== promptBlockId) {\n throw new HTTPException(404, {\n message: `Version with id ${from} not found for prompt block ${promptBlockId}`,\n });\n }\n\n const toVersion = await promptBlockStore.getVersion(to);\n if (!toVersion) {\n throw new HTTPException(404, { message: `Version with id ${to} not found` });\n }\n if (toVersion.blockId !== promptBlockId) {\n throw new HTTPException(404, {\n message: `Version with id ${to} not found for prompt block ${promptBlockId}`,\n });\n }\n\n const fromConfig = extractConfigFromVersion(\n fromVersion as unknown as Record<string, unknown>,\n SNAPSHOT_CONFIG_FIELDS,\n );\n const toConfig = extractConfigFromVersion(\n toVersion as unknown as Record<string, unknown>,\n SNAPSHOT_CONFIG_FIELDS,\n );\n\n const diffs = computeVersionDiffs(fromConfig, toConfig);\n\n return {\n diffs,\n fromVersion,\n toVersion,\n };\n } catch (error) {\n return handleError(error, 'Error comparing prompt block versions');\n }\n },\n});\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server/schemas/prompt-block-versions.ts","../src/server/handlers/prompt-block-versions.ts"],"names":[],"mappings":";;;;;;;;AAcO,IAAM,kCAAA,GAAqC,uBAAA;AAC3C,IAAM,qCAAA,GAAwC,0BAAA;AAC9C,IAAM,kCAAA,GAAqC,uBAAA;AAM3C,IAAM,4BAAA,GAA+B,EAAE,MAAA,CAAO;AAAA,EACnD,aAAA,EAAe,CAAA,CAAE,MAAA,EAA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EAAE,cAAc,CAAA;AAAA,MAC7E;AACA,MAAA,IAAI,SAAA,CAAU,YAAY,aAAA,EAAe;AACvC,QAAA,MAAM,IAAI,cAAc,GAAA,EAAK;AAAA,UAC3B,OAAA,EAAS,CAAA,gBAAA,EAAmB,EAAE,CAAA,4BAAA,EAA+B,aAAa,CAAA;AAAA,SAC3E,CAAA;AAAA,MACH;AAEA,MAAA,MAAM,UAAA,GAAa,wBAAA;AAAA,QACjB,WAAA;AAAA,QACA;AAAA,OACF;AACA,MAAA,MAAM,QAAA,GAAW,wBAAA;AAAA,QACf,SAAA;AAAA,QACA;AAAA,OACF;AAEA,MAAA,MAAM,KAAA,GAAQ,mBAAA,CAAoB,UAAA,EAAY,QAAQ,CAAA;AAEtD,MAAA,OAAO;AAAA,QACL,KAAA;AAAA,QACA,WAAA;AAAA,QACA;AAAA,OACF;AAAA,IACF,SAAS,KAAA,EAAO;AACd,MAAA,OAAO,WAAA,CAAY,OAAO,uCAAuC,CAAA;AAAA,IACnE;AAAA,EACF;AACF,CAAC","file":"chunk-NC6UUX6D.js","sourcesContent":["import z from 'zod';\nimport { ruleGroupSchema } from './rule-group';\nimport {\n listVersionsQuerySchema,\n compareVersionsQuerySchema,\n createVersionBodySchema,\n activateVersionResponseSchema,\n deleteVersionResponseSchema,\n versionDiffEntrySchema,\n createListVersionsResponseSchema,\n createCompareVersionsResponseSchema,\n} from './version-common';\n\n// Re-export shared schemas under domain-specific names\nexport const listPromptBlockVersionsQuerySchema = listVersionsQuerySchema;\nexport const comparePromptBlockVersionsQuerySchema = compareVersionsQuerySchema;\nexport const createPromptBlockVersionBodySchema = createVersionBodySchema;\n\n// ============================================================================\n// Path Parameter Schemas\n// ============================================================================\n\nexport const promptBlockVersionPathParams = z.object({\n promptBlockId: z.string().describe('Unique identifier for the stored prompt block'),\n});\n\nexport const promptBlockVersionIdPathParams = z.object({\n promptBlockId: z.string().describe('Unique identifier for the stored prompt block'),\n versionId: z.string().describe('Unique identifier for the version (UUID)'),\n});\n\n// ============================================================================\n// Response Schemas\n// ============================================================================\n\nexport const promptBlockVersionSchema = z.object({\n id: z.string().describe('Unique identifier for the version (UUID)'),\n blockId: z.string().describe('ID of the prompt block this version belongs to'),\n versionNumber: z.number().describe('Sequential version number (1, 2, 3, ...)'),\n // Snapshot config fields\n name: z.string().describe('Display name of the prompt block'),\n description: z.string().optional().describe('Purpose description'),\n content: z.string().describe('Template content with {{variable}} interpolation'),\n rules: ruleGroupSchema.optional().describe('Rules for conditional inclusion'),\n // Version metadata\n changedFields: z.array(z.string()).optional().describe('Array of field names that changed from the previous version'),\n changeMessage: z.string().optional().describe('Optional message describing the changes'),\n createdAt: z.coerce.date().describe('When this version was created'),\n});\n\nexport const listPromptBlockVersionsResponseSchema = createListVersionsResponseSchema(promptBlockVersionSchema);\n\nexport const getPromptBlockVersionResponseSchema = promptBlockVersionSchema;\n\nexport const createPromptBlockVersionResponseSchema = promptBlockVersionSchema.partial().merge(\n z.object({\n id: z.string(),\n blockId: z.string(),\n versionNumber: z.number(),\n createdAt: z.coerce.date(),\n }),\n);\n\nexport const activatePromptBlockVersionResponseSchema = activateVersionResponseSchema;\n\nexport const restorePromptBlockVersionResponseSchema = promptBlockVersionSchema;\n\nexport const deletePromptBlockVersionResponseSchema = deleteVersionResponseSchema;\n\nexport const comparePromptBlockVersionsResponseSchema = createCompareVersionsResponseSchema(promptBlockVersionSchema);\n\nexport { versionDiffEntrySchema };\n","import { HTTPException } from '../http-exception';\nimport {\n promptBlockVersionPathParams,\n promptBlockVersionIdPathParams,\n listPromptBlockVersionsQuerySchema,\n createPromptBlockVersionBodySchema,\n comparePromptBlockVersionsQuerySchema,\n listPromptBlockVersionsResponseSchema,\n getPromptBlockVersionResponseSchema,\n createPromptBlockVersionResponseSchema,\n activatePromptBlockVersionResponseSchema,\n restorePromptBlockVersionResponseSchema,\n deletePromptBlockVersionResponseSchema,\n comparePromptBlockVersionsResponseSchema,\n} from '../schemas/prompt-block-versions';\nimport { createRoute } from '../server-adapter/routes/route-builder';\n\nimport { handleError } from './error';\nimport {\n extractConfigFromVersion,\n calculateChangedFields,\n computeVersionDiffs,\n createVersionWithRetry,\n enforceRetentionLimit,\n} from './version-helpers';\nimport type { VersionedStoreInterface } from './version-helpers';\n\nconst SNAPSHOT_CONFIG_FIELDS = ['name', 'description', 'content', 'rules'] as const;\n\n/**\n * GET /stored/prompt-blocks/:promptBlockId/versions - List all versions for a prompt block\n */\nexport const LIST_PROMPT_BLOCK_VERSIONS_ROUTE = createRoute({\n method: 'GET',\n path: '/stored/prompt-blocks/:promptBlockId/versions',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: promptBlockVersionPathParams,\n queryParamSchema: listPromptBlockVersionsQuerySchema,\n responseSchema: listPromptBlockVersionsResponseSchema,\n summary: 'List prompt block versions',\n description: 'Returns a paginated list of all versions for a stored prompt block',\n tags: ['Prompt Block Versions'],\n handler: async ({ mastra, promptBlockId, page, perPage, orderBy }) => {\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 promptBlockStore = await storage.getStore('promptBlocks');\n if (!promptBlockStore) {\n throw new HTTPException(500, { message: 'Prompt blocks storage domain is not available' });\n }\n\n const promptBlock = await promptBlockStore.getById(promptBlockId);\n if (!promptBlock) {\n throw new HTTPException(404, { message: `Prompt block with id ${promptBlockId} not found` });\n }\n\n const result = await promptBlockStore.listVersions({\n blockId: promptBlockId,\n page,\n perPage,\n orderBy,\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error listing prompt block versions');\n }\n },\n});\n\n/**\n * POST /stored/prompt-blocks/:promptBlockId/versions - Create a new version snapshot\n */\nexport const CREATE_PROMPT_BLOCK_VERSION_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/prompt-blocks/:promptBlockId/versions',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: promptBlockVersionPathParams,\n bodySchema: createPromptBlockVersionBodySchema,\n responseSchema: createPromptBlockVersionResponseSchema,\n summary: 'Create prompt block version',\n description: 'Creates a new version snapshot of the current prompt block configuration',\n tags: ['Prompt Block Versions'],\n handler: async ({ mastra, promptBlockId, changeMessage }) => {\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 promptBlockStore = await storage.getStore('promptBlocks');\n if (!promptBlockStore) {\n throw new HTTPException(500, { message: 'Prompt blocks storage domain is not available' });\n }\n\n const promptBlock = await promptBlockStore.getById(promptBlockId);\n if (!promptBlock) {\n throw new HTTPException(404, { message: `Prompt block with id ${promptBlockId} not found` });\n }\n\n let currentConfig: Record<string, unknown> = {};\n if (promptBlock.activeVersionId) {\n const activeVersion = await promptBlockStore.getVersion(promptBlock.activeVersionId);\n if (activeVersion) {\n currentConfig = extractConfigFromVersion(\n activeVersion as unknown as Record<string, unknown>,\n SNAPSHOT_CONFIG_FIELDS,\n );\n }\n }\n\n const latestVersion = await promptBlockStore.getLatestVersion(promptBlockId);\n\n // If no activeVersionId, fall back to latest version config\n if (!promptBlock.activeVersionId && latestVersion) {\n currentConfig = extractConfigFromVersion(\n latestVersion as unknown as Record<string, unknown>,\n SNAPSHOT_CONFIG_FIELDS,\n );\n }\n const previousConfig = latestVersion\n ? extractConfigFromVersion(latestVersion as unknown as Record<string, unknown>, SNAPSHOT_CONFIG_FIELDS)\n : null;\n\n const changedFields = calculateChangedFields(previousConfig, currentConfig);\n\n const { versionId } = await createVersionWithRetry(\n promptBlockStore as unknown as VersionedStoreInterface,\n promptBlockId,\n 'blockId',\n currentConfig,\n changedFields,\n { changeMessage },\n );\n\n const version = await promptBlockStore.getVersion(versionId);\n if (!version) {\n throw new HTTPException(500, { message: 'Failed to retrieve created version' });\n }\n\n await enforceRetentionLimit(\n promptBlockStore as unknown as VersionedStoreInterface,\n promptBlockId,\n 'blockId',\n promptBlock.activeVersionId,\n );\n\n return version;\n } catch (error) {\n return handleError(error, 'Error creating prompt block version');\n }\n },\n});\n\n/**\n * GET /stored/prompt-blocks/:promptBlockId/versions/:versionId - Get a specific version\n */\nexport const GET_PROMPT_BLOCK_VERSION_ROUTE = createRoute({\n method: 'GET',\n path: '/stored/prompt-blocks/:promptBlockId/versions/:versionId',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: promptBlockVersionIdPathParams,\n responseSchema: getPromptBlockVersionResponseSchema,\n summary: 'Get prompt block version',\n description: 'Returns a specific version of a prompt block by its version ID',\n tags: ['Prompt Block Versions'],\n handler: async ({ mastra, promptBlockId, versionId }) => {\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 promptBlockStore = await storage.getStore('promptBlocks');\n if (!promptBlockStore) {\n throw new HTTPException(500, { message: 'Prompt blocks storage domain is not available' });\n }\n\n const version = await promptBlockStore.getVersion(versionId);\n\n if (!version) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n\n if (version.blockId !== promptBlockId) {\n throw new HTTPException(404, {\n message: `Version with id ${versionId} not found for prompt block ${promptBlockId}`,\n });\n }\n\n return version;\n } catch (error) {\n return handleError(error, 'Error getting prompt block version');\n }\n },\n});\n\n/**\n * POST /stored/prompt-blocks/:promptBlockId/versions/:versionId/activate - Set a version as active\n */\nexport const ACTIVATE_PROMPT_BLOCK_VERSION_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/prompt-blocks/:promptBlockId/versions/:versionId/activate',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: promptBlockVersionIdPathParams,\n responseSchema: activatePromptBlockVersionResponseSchema,\n summary: 'Activate prompt block version',\n description: 'Sets a specific version as the active version for the prompt block',\n tags: ['Prompt Block Versions'],\n handler: async ({ mastra, promptBlockId, versionId }) => {\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 promptBlockStore = await storage.getStore('promptBlocks');\n if (!promptBlockStore) {\n throw new HTTPException(500, { message: 'Prompt blocks storage domain is not available' });\n }\n\n const promptBlock = await promptBlockStore.getById(promptBlockId);\n if (!promptBlock) {\n throw new HTTPException(404, { message: `Prompt block with id ${promptBlockId} not found` });\n }\n\n const version = await promptBlockStore.getVersion(versionId);\n if (!version) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n if (version.blockId !== promptBlockId) {\n throw new HTTPException(404, {\n message: `Version with id ${versionId} not found for prompt block ${promptBlockId}`,\n });\n }\n\n await promptBlockStore.update({\n id: promptBlockId,\n activeVersionId: versionId,\n status: 'published',\n });\n\n // Clear the editor cache so subsequent requests see the new active version\n mastra.getEditor()?.prompt.clearCache(promptBlockId);\n\n return {\n success: true,\n message: `Version ${version.versionNumber} is now active`,\n activeVersionId: versionId,\n };\n } catch (error) {\n return handleError(error, 'Error activating prompt block version');\n }\n },\n});\n\n/**\n * POST /stored/prompt-blocks/:promptBlockId/versions/:versionId/restore - Restore prompt block to a version\n */\nexport const RESTORE_PROMPT_BLOCK_VERSION_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/prompt-blocks/:promptBlockId/versions/:versionId/restore',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: promptBlockVersionIdPathParams,\n responseSchema: restorePromptBlockVersionResponseSchema,\n summary: 'Restore prompt block version',\n description: 'Restores the prompt block configuration from a version, creating a new version',\n tags: ['Prompt Block Versions'],\n handler: async ({ mastra, promptBlockId, versionId }) => {\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 promptBlockStore = await storage.getStore('promptBlocks');\n if (!promptBlockStore) {\n throw new HTTPException(500, { message: 'Prompt blocks storage domain is not available' });\n }\n\n const promptBlock = await promptBlockStore.getById(promptBlockId);\n if (!promptBlock) {\n throw new HTTPException(404, { message: `Prompt block with id ${promptBlockId} not found` });\n }\n\n const versionToRestore = await promptBlockStore.getVersion(versionId);\n if (!versionToRestore) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n if (versionToRestore.blockId !== promptBlockId) {\n throw new HTTPException(404, {\n message: `Version with id ${versionId} not found for prompt block ${promptBlockId}`,\n });\n }\n\n const restoredConfig = extractConfigFromVersion(\n versionToRestore as unknown as Record<string, unknown>,\n SNAPSHOT_CONFIG_FIELDS,\n );\n\n await promptBlockStore.update({\n id: promptBlockId,\n ...restoredConfig,\n });\n\n const latestVersion = await promptBlockStore.getLatestVersion(promptBlockId);\n const previousConfig = latestVersion\n ? extractConfigFromVersion(latestVersion as unknown as Record<string, unknown>, SNAPSHOT_CONFIG_FIELDS)\n : null;\n\n const changedFields = calculateChangedFields(previousConfig, restoredConfig);\n\n const { versionId: newVersionId } = await createVersionWithRetry(\n promptBlockStore as unknown as VersionedStoreInterface,\n promptBlockId,\n 'blockId',\n restoredConfig,\n changedFields,\n {\n changeMessage: `Restored from version ${versionToRestore.versionNumber}`,\n },\n );\n\n const newVersion = await promptBlockStore.getVersion(newVersionId);\n if (!newVersion) {\n throw new HTTPException(500, { message: 'Failed to retrieve created version' });\n }\n\n await enforceRetentionLimit(\n promptBlockStore as unknown as VersionedStoreInterface,\n promptBlockId,\n 'blockId',\n promptBlock.activeVersionId,\n );\n\n // Clear the editor cache so subsequent requests see the updated config\n mastra.getEditor()?.prompt.clearCache(promptBlockId);\n\n return newVersion;\n } catch (error) {\n return handleError(error, 'Error restoring prompt block version');\n }\n },\n});\n\n/**\n * DELETE /stored/prompt-blocks/:promptBlockId/versions/:versionId - Delete a version\n */\nexport const DELETE_PROMPT_BLOCK_VERSION_ROUTE = createRoute({\n method: 'DELETE',\n path: '/stored/prompt-blocks/:promptBlockId/versions/:versionId',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: promptBlockVersionIdPathParams,\n responseSchema: deletePromptBlockVersionResponseSchema,\n summary: 'Delete prompt block version',\n description: 'Deletes a specific version (cannot delete the active version)',\n tags: ['Prompt Block Versions'],\n handler: async ({ mastra, promptBlockId, versionId }) => {\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 promptBlockStore = await storage.getStore('promptBlocks');\n if (!promptBlockStore) {\n throw new HTTPException(500, { message: 'Prompt blocks storage domain is not available' });\n }\n\n const promptBlock = await promptBlockStore.getById(promptBlockId);\n if (!promptBlock) {\n throw new HTTPException(404, { message: `Prompt block with id ${promptBlockId} not found` });\n }\n\n const version = await promptBlockStore.getVersion(versionId);\n if (!version) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n if (version.blockId !== promptBlockId) {\n throw new HTTPException(404, {\n message: `Version with id ${versionId} not found for prompt block ${promptBlockId}`,\n });\n }\n\n if (promptBlock.activeVersionId === versionId) {\n throw new HTTPException(400, {\n message: 'Cannot delete the active version. Activate a different version first.',\n });\n }\n\n await promptBlockStore.deleteVersion(versionId);\n\n // Clear the editor cache so subsequent requests see the updated config\n mastra.getEditor()?.prompt.clearCache(promptBlockId);\n\n return {\n success: true,\n message: `Version ${version.versionNumber} deleted successfully`,\n };\n } catch (error) {\n return handleError(error, 'Error deleting prompt block version');\n }\n },\n});\n\n/**\n * GET /stored/prompt-blocks/:promptBlockId/versions/compare - Compare two versions\n */\nexport const COMPARE_PROMPT_BLOCK_VERSIONS_ROUTE = createRoute({\n method: 'GET',\n path: '/stored/prompt-blocks/:promptBlockId/versions/compare',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: promptBlockVersionPathParams,\n queryParamSchema: comparePromptBlockVersionsQuerySchema,\n responseSchema: comparePromptBlockVersionsResponseSchema,\n summary: 'Compare prompt block versions',\n description: 'Compares two versions and returns the differences between them',\n tags: ['Prompt Block Versions'],\n handler: async ({ mastra, promptBlockId, from, to }) => {\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 promptBlockStore = await storage.getStore('promptBlocks');\n if (!promptBlockStore) {\n throw new HTTPException(500, { message: 'Prompt blocks storage domain is not available' });\n }\n\n const fromVersion = await promptBlockStore.getVersion(from);\n if (!fromVersion) {\n throw new HTTPException(404, { message: `Version with id ${from} not found` });\n }\n if (fromVersion.blockId !== promptBlockId) {\n throw new HTTPException(404, {\n message: `Version with id ${from} not found for prompt block ${promptBlockId}`,\n });\n }\n\n const toVersion = await promptBlockStore.getVersion(to);\n if (!toVersion) {\n throw new HTTPException(404, { message: `Version with id ${to} not found` });\n }\n if (toVersion.blockId !== promptBlockId) {\n throw new HTTPException(404, {\n message: `Version with id ${to} not found for prompt block ${promptBlockId}`,\n });\n }\n\n const fromConfig = extractConfigFromVersion(\n fromVersion as unknown as Record<string, unknown>,\n SNAPSHOT_CONFIG_FIELDS,\n );\n const toConfig = extractConfigFromVersion(\n toVersion as unknown as Record<string, unknown>,\n SNAPSHOT_CONFIG_FIELDS,\n );\n\n const diffs = computeVersionDiffs(fromConfig, toConfig);\n\n return {\n diffs,\n fromVersion,\n toVersion,\n };\n } catch (error) {\n return handleError(error, 'Error comparing prompt block versions');\n }\n },\n});\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server/schemas/stored-prompt-blocks.ts","../src/server/handlers/stored-prompt-blocks.ts"],"names":["z","createPagePaginationSchema","ruleGroupSchema","paginationInfoSchema","createRoute","HTTPException","handleError","statusQuerySchema","toSlug","handleAutoVersioning"],"mappings":";;;;;;;;;;;;;;;AASO,IAAM,6BAAA,GAAgCA,mBAAE,MAAA,CAAO;AAAA,EACpD,mBAAA,EAAqBA,kBAAA,CAAE,MAAA,EAAO,CAAE,SAAS,+CAA+C;AAC1F,CAAC,CAAA;AAMD,IAAM,oBAAA,GAAuBA,mBAAE,MAAA,CAAO;AAAA,EACpC,KAAA,EAAOA,mBAAE,IAAA,CAAK,CAAC,aAAa,WAAW,CAAC,EAAE,QAAA,EAAS;AAAA,EACnD,SAAA,EAAWA,mBAAE,IAAA,CAAK,CAAC,OAAO,MAAM,CAAC,EAAE,QAAA;AACrC,CAAC,CAAA;AAIM,IAAM,iCAAA,GA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B,mBAAmB,CAAA,qBAAA;AAAA,OAC9C;AAAA,IACF,SAAS,KAAA,EAAO;AACd,MAAA,OAAOC,6BAAA,CAAY,OAAO,oCAAoC,CAAA;AAAA,IAChE;AAAA,EACF;AACF,CAAC","file":"chunk-NGFAF6WW.cjs","sourcesContent":["import z from 'zod';\n\nimport { paginationInfoSchema, createPagePaginationSchema, statusQuerySchema } from './common';\nimport { ruleGroupSchema } from './rule-group';\n\n// ============================================================================\n// Path Parameter Schemas\n// ============================================================================\n\nexport const storedPromptBlockIdPathParams = z.object({\n storedPromptBlockId: z.string().describe('Unique identifier for the stored prompt block'),\n});\n\n// ============================================================================\n// Query Parameter Schemas\n// ============================================================================\n\nconst storageOrderBySchema = z.object({\n field: z.enum(['createdAt', 'updatedAt']).optional(),\n direction: z.enum(['ASC', 'DESC']).optional(),\n});\n\nexport { statusQuerySchema };\n\nexport const listStoredPromptBlocksQuerySchema = createPagePaginationSchema(100).extend({\n orderBy: storageOrderBySchema.optional(),\n status: z\n .enum(['draft', 'published', 'archived'])\n .optional()\n .default('published')\n .describe('Filter prompt blocks by status (defaults to published)'),\n authorId: z.string().optional().describe('Filter prompt blocks by author identifier'),\n metadata: z.record(z.string(), z.unknown()).optional().describe('Filter prompt blocks by metadata key-value pairs'),\n});\n\n// ============================================================================\n// Body Parameter Schemas\n// ============================================================================\n\nconst snapshotConfigSchema = z.object({\n name: z.string().describe('Display name of the prompt block'),\n description: z.string().optional().describe('Purpose description'),\n content: z.string().describe('Template content with {{variable}} interpolation'),\n rules: ruleGroupSchema.optional().describe('Rules for conditional inclusion'),\n});\n\nexport const createStoredPromptBlockBodySchema = z\n .object({\n id: z.string().optional().describe('Unique identifier. If not provided, derived from name.'),\n authorId: z.string().optional().describe('Author identifier for multi-tenant filtering'),\n metadata: z.record(z.string(), z.unknown()).optional().describe('Additional metadata for the prompt block'),\n })\n .merge(snapshotConfigSchema);\n\nexport const updateStoredPromptBlockBodySchema = z\n .object({\n authorId: z.string().optional(),\n metadata: z.record(z.string(), z.unknown()).optional(),\n })\n .merge(snapshotConfigSchema.partial());\n\n// ============================================================================\n// Response Schemas\n// ============================================================================\n\nexport const storedPromptBlockSchema = z.object({\n id: z.string(),\n status: z.string().describe('Prompt block status: draft, published, or archived'),\n activeVersionId: z.string().optional(),\n authorId: z.string().optional(),\n metadata: z.record(z.string(), z.unknown()).optional(),\n createdAt: z.coerce.date(),\n updatedAt: z.coerce.date(),\n name: z.string().describe('Display name of the prompt block'),\n description: z.string().optional().describe('Purpose description'),\n content: z.string().describe('Template content with {{variable}} interpolation'),\n rules: ruleGroupSchema.optional().describe('Rules for conditional inclusion'),\n});\n\nexport const listStoredPromptBlocksResponseSchema = paginationInfoSchema.extend({\n promptBlocks: z.array(storedPromptBlockSchema),\n});\n\nexport const getStoredPromptBlockResponseSchema = storedPromptBlockSchema;\nexport const createStoredPromptBlockResponseSchema = storedPromptBlockSchema;\n\nexport const updateStoredPromptBlockResponseSchema = z.union([\n z.object({\n id: z.string(),\n status: z.string(),\n activeVersionId: z.string().optional(),\n authorId: z.string().optional(),\n metadata: z.record(z.string(), z.unknown()).optional(),\n createdAt: z.coerce.date(),\n updatedAt: z.coerce.date(),\n }),\n storedPromptBlockSchema,\n]);\n\nexport const deleteStoredPromptBlockResponseSchema = z.object({\n success: z.boolean(),\n message: z.string(),\n});\n","import { HTTPException } from '../http-exception';\nimport {\n storedPromptBlockIdPathParams,\n statusQuerySchema,\n listStoredPromptBlocksQuerySchema,\n createStoredPromptBlockBodySchema,\n updateStoredPromptBlockBodySchema,\n listStoredPromptBlocksResponseSchema,\n getStoredPromptBlockResponseSchema,\n createStoredPromptBlockResponseSchema,\n updateStoredPromptBlockResponseSchema,\n deleteStoredPromptBlockResponseSchema,\n} from '../schemas/stored-prompt-blocks';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { toSlug } from '../utils';\n\nimport { handleError } from './error';\nimport { handleAutoVersioning } from './version-helpers';\nimport type { VersionedStoreInterface } from './version-helpers';\n\nconst PROMPT_BLOCK_SNAPSHOT_CONFIG_FIELDS = ['name', 'description', 'content', 'rules'] as const;\n\n// ============================================================================\n// Route Definitions\n// ============================================================================\n\n/**\n * GET /stored/prompt-blocks - List all stored prompt blocks\n */\nexport const LIST_STORED_PROMPT_BLOCKS_ROUTE = createRoute({\n method: 'GET',\n path: '/stored/prompt-blocks',\n responseType: 'json',\n queryParamSchema: listStoredPromptBlocksQuerySchema,\n responseSchema: listStoredPromptBlocksResponseSchema,\n summary: 'List stored prompt blocks',\n description: 'Returns a paginated list of all prompt blocks stored in the database',\n tags: ['Stored Prompt Blocks'],\n requiresAuth: true,\n handler: async ({ mastra, page, perPage, orderBy, status, authorId, metadata }) => {\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 promptBlockStore = await storage.getStore('promptBlocks');\n if (!promptBlockStore) {\n throw new HTTPException(500, { message: 'Prompt blocks storage domain is not available' });\n }\n\n const result = await promptBlockStore.listResolved({\n page,\n perPage,\n orderBy,\n status,\n authorId,\n metadata,\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error listing stored prompt blocks');\n }\n },\n});\n\n/**\n * GET /stored/prompt-blocks/:storedPromptBlockId - Get a stored prompt block by ID\n */\nexport const GET_STORED_PROMPT_BLOCK_ROUTE = createRoute({\n method: 'GET',\n path: '/stored/prompt-blocks/:storedPromptBlockId',\n responseType: 'json',\n pathParamSchema: storedPromptBlockIdPathParams,\n queryParamSchema: statusQuerySchema,\n responseSchema: getStoredPromptBlockResponseSchema,\n summary: 'Get stored prompt block by ID',\n description:\n 'Returns a specific prompt block 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 Prompt Blocks'],\n requiresAuth: true,\n handler: async ({ mastra, storedPromptBlockId, status }) => {\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 promptBlockStore = await storage.getStore('promptBlocks');\n if (!promptBlockStore) {\n throw new HTTPException(500, { message: 'Prompt blocks storage domain is not available' });\n }\n\n const promptBlock = await promptBlockStore.getByIdResolved(storedPromptBlockId, { status });\n\n if (!promptBlock) {\n throw new HTTPException(404, { message: `Stored prompt block with id ${storedPromptBlockId} not found` });\n }\n\n return promptBlock;\n } catch (error) {\n return handleError(error, 'Error getting stored prompt block');\n }\n },\n});\n\n/**\n * POST /stored/prompt-blocks - Create a new stored prompt block\n */\nexport const CREATE_STORED_PROMPT_BLOCK_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/prompt-blocks',\n responseType: 'json',\n bodySchema: createStoredPromptBlockBodySchema,\n responseSchema: createStoredPromptBlockResponseSchema,\n summary: 'Create stored prompt block',\n description: 'Creates a new prompt block in storage with the provided configuration',\n tags: ['Stored Prompt Blocks'],\n requiresAuth: true,\n handler: async ({ mastra, id: providedId, authorId, metadata, name, description, content, rules }) => {\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 promptBlockStore = await storage.getStore('promptBlocks');\n if (!promptBlockStore) {\n throw new HTTPException(500, { message: 'Prompt blocks 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 prompt block ID from name. Please provide an explicit id.',\n });\n }\n\n // Check if prompt block with this ID already exists\n const existing = await promptBlockStore.getById(id);\n if (existing) {\n throw new HTTPException(409, { message: `Prompt block with id ${id} already exists` });\n }\n\n await promptBlockStore.create({\n promptBlock: {\n id,\n authorId,\n metadata,\n name,\n description,\n content,\n rules,\n },\n });\n\n // Return the resolved prompt block (thin record + version config)\n // Use draft status since newly created entities start as drafts\n const resolved = await promptBlockStore.getByIdResolved(id, { status: 'draft' });\n if (!resolved) {\n throw new HTTPException(500, { message: 'Failed to resolve created prompt block' });\n }\n\n return resolved;\n } catch (error) {\n return handleError(error, 'Error creating stored prompt block');\n }\n },\n});\n\n/**\n * PATCH /stored/prompt-blocks/:storedPromptBlockId - Update a stored prompt block\n */\nexport const UPDATE_STORED_PROMPT_BLOCK_ROUTE = createRoute({\n method: 'PATCH',\n path: '/stored/prompt-blocks/:storedPromptBlockId',\n responseType: 'json',\n pathParamSchema: storedPromptBlockIdPathParams,\n bodySchema: updateStoredPromptBlockBodySchema,\n responseSchema: updateStoredPromptBlockResponseSchema,\n summary: 'Update stored prompt block',\n description: 'Updates an existing prompt block in storage with the provided fields',\n tags: ['Stored Prompt Blocks'],\n requiresAuth: true,\n handler: async ({\n mastra,\n storedPromptBlockId,\n // Metadata-level fields\n authorId,\n metadata,\n // Config fields (snapshot-level)\n name,\n description,\n content,\n rules,\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 promptBlockStore = await storage.getStore('promptBlocks');\n if (!promptBlockStore) {\n throw new HTTPException(500, { message: 'Prompt blocks storage domain is not available' });\n }\n\n // Check if prompt block exists\n const existing = await promptBlockStore.getById(storedPromptBlockId);\n if (!existing) {\n throw new HTTPException(404, { message: `Stored prompt block with id ${storedPromptBlockId} not found` });\n }\n\n // Update the prompt block with both metadata-level and config-level fields\n const updatedPromptBlock = await promptBlockStore.update({\n id: storedPromptBlockId,\n authorId,\n metadata,\n name,\n description,\n content,\n rules,\n });\n\n // Build the snapshot config for auto-versioning comparison\n const configFields = { name, description, content, rules };\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 promptBlockStore as unknown as VersionedStoreInterface,\n storedPromptBlockId,\n 'blockId',\n PROMPT_BLOCK_SNAPSHOT_CONFIG_FIELDS,\n existing,\n updatedPromptBlock,\n providedConfigFields,\n );\n\n // Return the resolved prompt block with the latest (draft) version so the UI sees its edits\n const resolved = await promptBlockStore.getByIdResolved(storedPromptBlockId, { status: 'draft' });\n if (!resolved) {\n throw new HTTPException(500, { message: 'Failed to resolve updated prompt block' });\n }\n\n return resolved;\n } catch (error) {\n return handleError(error, 'Error updating stored prompt block');\n }\n },\n});\n\n/**\n * DELETE /stored/prompt-blocks/:storedPromptBlockId - Delete a stored prompt block\n */\nexport const DELETE_STORED_PROMPT_BLOCK_ROUTE = createRoute({\n method: 'DELETE',\n path: '/stored/prompt-blocks/:storedPromptBlockId',\n responseType: 'json',\n pathParamSchema: storedPromptBlockIdPathParams,\n responseSchema: deleteStoredPromptBlockResponseSchema,\n summary: 'Delete stored prompt block',\n description: 'Deletes a prompt block from storage by its unique identifier',\n tags: ['Stored Prompt Blocks'],\n requiresAuth: true,\n handler: async ({ mastra, storedPromptBlockId }) => {\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 promptBlockStore = await storage.getStore('promptBlocks');\n if (!promptBlockStore) {\n throw new HTTPException(500, { message: 'Prompt blocks storage domain is not available' });\n }\n\n // Check if prompt block exists\n const existing = await promptBlockStore.getById(storedPromptBlockId);\n if (!existing) {\n throw new HTTPException(404, { message: `Stored prompt block with id ${storedPromptBlockId} not found` });\n }\n\n await promptBlockStore.delete(storedPromptBlockId);\n\n return {\n success: true,\n message: `Prompt block ${storedPromptBlockId} deleted successfully`,\n };\n } catch (error) {\n return handleError(error, 'Error deleting stored prompt block');\n }\n },\n});\n"]}
|
package/dist/docs/SKILL.md
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: mastra-server
|
|
3
|
-
description: Documentation for @mastra/server. Use when working with @mastra/server APIs, configuration, or implementation.
|
|
4
|
-
metadata:
|
|
5
|
-
package: "@mastra/server"
|
|
6
|
-
version: "1.6.0"
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## When to use
|
|
10
|
-
|
|
11
|
-
Use this skill whenever you are working with @mastra/server to obtain the domain-specific knowledge.
|
|
12
|
-
|
|
13
|
-
## How to use
|
|
14
|
-
|
|
15
|
-
Read the individual reference documents for detailed explanations and code examples.
|
|
16
|
-
|
|
17
|
-
### Docs
|
|
18
|
-
|
|
19
|
-
- [Custom Adapters](references/docs-server-custom-adapters.md) - Create a custom server adapter for frameworks other than Hono or Express.
|
|
20
|
-
|
|
21
|
-
### Reference
|
|
22
|
-
|
|
23
|
-
- [Reference: createRoute()](references/reference-server-create-route.md) - API reference for createRoute() function used to define type-safe routes with validation and OpenAPI generation.
|
|
24
|
-
- [Reference: MastraServer](references/reference-server-mastra-server.md) - API reference for the MastraServer abstract class used to create server adapters.
|
|
25
|
-
- [Reference: Server Routes](references/reference-server-routes.md) - API reference for HTTP routes registered by Mastra server adapters.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
Read [assets/SOURCE_MAP.json](assets/SOURCE_MAP.json) for source code references.
|
|
@@ -1,374 +0,0 @@
|
|
|
1
|
-
# Custom Adapters
|
|
2
|
-
|
|
3
|
-
Create a custom adapter when you need to run Mastra with a framework other than Hono or Express. This might be necessary if you have specific request/response handling requirements that `@mastra/hono` and `@mastra/express` don't support.
|
|
4
|
-
|
|
5
|
-
A custom adapter translates between Mastra's route definitions and your framework's routing system. You'll implement methods that register middleware, handle requests, and send responses using your framework's APIs.
|
|
6
|
-
|
|
7
|
-
> **Info:** Use any of these prebuilt server adapters:
|
|
8
|
-
>
|
|
9
|
-
> - [@mastra/hono](https://mastra.ai/reference/server/hono-adapter)
|
|
10
|
-
> - [@mastra/express](https://mastra.ai/reference/server/express-adapter)
|
|
11
|
-
> - [@mastra/fastify](https://mastra.ai/reference/server/fastify-adapter)
|
|
12
|
-
> - [@mastra/koa](https://mastra.ai/reference/server/koa-adapter)
|
|
13
|
-
|
|
14
|
-
## Abstract class
|
|
15
|
-
|
|
16
|
-
The `MastraServer` abstract class from `@mastra/server/server-adapter` provides the foundation for all adapters. It handles route registration logic, parameter validation, and other shared functionality. Your custom adapter extends this class and implements the framework-specific parts.
|
|
17
|
-
|
|
18
|
-
The class takes three type parameters that represent your framework's types:
|
|
19
|
-
|
|
20
|
-
```typescript
|
|
21
|
-
import { MastraServer } from '@mastra/server/server-adapter';
|
|
22
|
-
|
|
23
|
-
export class MyFrameworkServer extends MastraServer<
|
|
24
|
-
// Your framework's app type (e.g., FastifyInstance)
|
|
25
|
-
MyApp,
|
|
26
|
-
// Your framework's request type (e.g., FastifyRequest)
|
|
27
|
-
MyRequest,
|
|
28
|
-
// Your framework's response type (e.g., FastifyReply)
|
|
29
|
-
MyResponse
|
|
30
|
-
> {
|
|
31
|
-
// Implement abstract methods
|
|
32
|
-
}
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
These type parameters ensure type safety throughout your adapter implementation and enable proper typing when accessing framework-specific APIs.
|
|
36
|
-
|
|
37
|
-
## Required methods
|
|
38
|
-
|
|
39
|
-
You must implement these six abstract methods. Each handles a specific part of the request lifecycle, from attaching context to sending responses.
|
|
40
|
-
|
|
41
|
-
### registerContextMiddleware()
|
|
42
|
-
|
|
43
|
-
This method runs first and attaches Mastra context to every incoming request. Route handlers need access to the Mastra instance, tools, and other context to function. How you attach this context depends on your framework — Express uses `res.locals`, Hono uses `c.set()`, and other frameworks have their own patterns.
|
|
44
|
-
|
|
45
|
-
```typescript
|
|
46
|
-
registerContextMiddleware(): void {
|
|
47
|
-
this.app.use('*', (req, res, next) => {
|
|
48
|
-
// Attach context to your framework's request/response
|
|
49
|
-
res.locals.mastra = this.mastra;
|
|
50
|
-
res.locals.requestContext = new RequestContext();
|
|
51
|
-
res.locals.tools = this.tools;
|
|
52
|
-
res.locals.abortSignal = createAbortSignal(req);
|
|
53
|
-
next();
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
Context to attach:
|
|
59
|
-
|
|
60
|
-
| Key | Type | Description |
|
|
61
|
-
| ---------------- | ---------------------- | -------------------------------- |
|
|
62
|
-
| `mastra` | `Mastra` | The Mastra instance |
|
|
63
|
-
| `requestContext` | `RequestContext` | Request-scoped context map |
|
|
64
|
-
| `tools` | `Record<string, Tool>` | Available tools |
|
|
65
|
-
| `abortSignal` | `AbortSignal` | Request cancellation signal |
|
|
66
|
-
| `taskStore` | `InMemoryTaskStore` | A2A task storage (if configured) |
|
|
67
|
-
|
|
68
|
-
### registerAuthMiddleware()
|
|
69
|
-
|
|
70
|
-
Register authentication and authorization middleware. This method should check if authentication is configured on the Mastra instance and skip registration entirely if not. When auth is configured, you'll typically register two middleware functions: one for authentication (validating tokens and setting the user) and one for authorization (checking if the user can access the requested resource).
|
|
71
|
-
|
|
72
|
-
```typescript
|
|
73
|
-
registerAuthMiddleware(): void {
|
|
74
|
-
const authConfig = this.mastra.getServer()?.auth;
|
|
75
|
-
if (!authConfig) return;
|
|
76
|
-
|
|
77
|
-
// Register authentication (validate token, set user)
|
|
78
|
-
this.app.use('*', async (req, res, next) => {
|
|
79
|
-
const token = extractToken(req);
|
|
80
|
-
const user = await authConfig.authenticateToken?.(token, req);
|
|
81
|
-
if (!user) {
|
|
82
|
-
return res.status(401).json({ error: 'Unauthorized' });
|
|
83
|
-
}
|
|
84
|
-
res.locals.user = user;
|
|
85
|
-
next();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
// Register authorization (check permissions)
|
|
89
|
-
this.app.use('*', async (req, res, next) => {
|
|
90
|
-
const allowed = await authConfig.authorize?.(
|
|
91
|
-
req.path,
|
|
92
|
-
req.method,
|
|
93
|
-
res.locals.user,
|
|
94
|
-
res
|
|
95
|
-
);
|
|
96
|
-
if (!allowed) {
|
|
97
|
-
return res.status(403).json({ error: 'Forbidden' });
|
|
98
|
-
}
|
|
99
|
-
next();
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
### registerRoute()
|
|
105
|
-
|
|
106
|
-
Register a single route with your framework. This method is called once for each Mastra route during initialization. It receives a `ServerRoute` object containing the path, HTTP method, handler function, and Zod schemas for validation. Your implementation should wire this up to your framework's routing system.
|
|
107
|
-
|
|
108
|
-
```typescript
|
|
109
|
-
async registerRoute(
|
|
110
|
-
app: MyApp,
|
|
111
|
-
route: ServerRoute,
|
|
112
|
-
{ prefix }: { prefix?: string }
|
|
113
|
-
): Promise<void> {
|
|
114
|
-
const path = `${prefix || ''}${route.path}`;
|
|
115
|
-
const method = route.method.toLowerCase();
|
|
116
|
-
|
|
117
|
-
app[method](path, async (req, res) => {
|
|
118
|
-
try {
|
|
119
|
-
// 1. Extract parameters
|
|
120
|
-
const params = await this.getParams(route, req);
|
|
121
|
-
|
|
122
|
-
// 2. Validate with Zod schemas
|
|
123
|
-
const queryParams = await this.parseQueryParams(route, params.queryParams);
|
|
124
|
-
const body = await this.parseBody(route, params.body);
|
|
125
|
-
|
|
126
|
-
// 3. Build handler params
|
|
127
|
-
const handlerParams = {
|
|
128
|
-
...params.urlParams,
|
|
129
|
-
...queryParams,
|
|
130
|
-
...(typeof body === 'object' ? body : {}),
|
|
131
|
-
mastra: this.mastra,
|
|
132
|
-
requestContext: res.locals.requestContext,
|
|
133
|
-
tools: res.locals.tools,
|
|
134
|
-
abortSignal: res.locals.abortSignal,
|
|
135
|
-
taskStore: this.taskStore,
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
// 4. Call handler
|
|
139
|
-
const result = await route.handler(handlerParams);
|
|
140
|
-
|
|
141
|
-
// 5. Send response
|
|
142
|
-
return this.sendResponse(route, res, result);
|
|
143
|
-
} catch (error) {
|
|
144
|
-
const status = error.status ?? error.details?.status ?? 500;
|
|
145
|
-
return res.status(status).json({ error: error.message });
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
### getParams()
|
|
152
|
-
|
|
153
|
-
Extract URL parameters, query parameters, and request body from the incoming request. Different frameworks expose these values in different ways—Express uses `req.params`, `req.query`, and `req.body`, while other frameworks may use different property names or require method calls. This method normalizes the extraction for your framework.
|
|
154
|
-
|
|
155
|
-
```typescript
|
|
156
|
-
async getParams(
|
|
157
|
-
route: ServerRoute,
|
|
158
|
-
request: MyRequest
|
|
159
|
-
): Promise<{
|
|
160
|
-
urlParams: Record<string, string>;
|
|
161
|
-
queryParams: Record<string, string>;
|
|
162
|
-
body: unknown;
|
|
163
|
-
}> {
|
|
164
|
-
return {
|
|
165
|
-
// From route path (e.g., :agentId)
|
|
166
|
-
urlParams: request.params,
|
|
167
|
-
// From URL query string
|
|
168
|
-
queryParams: request.query,
|
|
169
|
-
// From request body
|
|
170
|
-
body: request.body,
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
### sendResponse()
|
|
176
|
-
|
|
177
|
-
Send the response back to the client based on the route's response type. Mastra routes can return different response types: JSON for most API responses, streams for agent generation, and special types for MCP transports. Your implementation should handle each type appropriately for your framework.
|
|
178
|
-
|
|
179
|
-
```typescript
|
|
180
|
-
async sendResponse(
|
|
181
|
-
route: ServerRoute,
|
|
182
|
-
response: MyResponse,
|
|
183
|
-
result: unknown
|
|
184
|
-
): Promise<unknown> {
|
|
185
|
-
switch (route.responseType) {
|
|
186
|
-
case 'json':
|
|
187
|
-
return response.json(result);
|
|
188
|
-
|
|
189
|
-
case 'stream':
|
|
190
|
-
return this.stream(route, response, result);
|
|
191
|
-
|
|
192
|
-
case 'datastream-response':
|
|
193
|
-
// Return AI SDK Response directly
|
|
194
|
-
return result;
|
|
195
|
-
|
|
196
|
-
case 'mcp-http':
|
|
197
|
-
// Handle MCP HTTP transport
|
|
198
|
-
return this.handleMcpHttp(response, result);
|
|
199
|
-
|
|
200
|
-
case 'mcp-sse':
|
|
201
|
-
// Handle MCP SSE transport
|
|
202
|
-
return this.handleMcpSse(response, result);
|
|
203
|
-
|
|
204
|
-
default:
|
|
205
|
-
return response.json(result);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
### stream()
|
|
211
|
-
|
|
212
|
-
Handle streaming responses for agent generation. When an agent generates a response, it produces a stream of chunks that should be sent to the client as they become available. This method reads from the stream, optionally applies redaction to hide sensitive data, and writes chunks to the response in the appropriate format (SSE or newline-delimited JSON).
|
|
213
|
-
|
|
214
|
-
```typescript
|
|
215
|
-
async stream(
|
|
216
|
-
route: ServerRoute,
|
|
217
|
-
response: MyResponse,
|
|
218
|
-
result: unknown
|
|
219
|
-
): Promise<unknown> {
|
|
220
|
-
const isSSE = route.streamFormat === 'sse';
|
|
221
|
-
|
|
222
|
-
// Set streaming headers based on format
|
|
223
|
-
response.setHeader('Content-Type', isSSE ? 'text/event-stream' : 'text/plain');
|
|
224
|
-
response.setHeader('Transfer-Encoding', 'chunked');
|
|
225
|
-
|
|
226
|
-
const reader = result.fullStream.getReader();
|
|
227
|
-
|
|
228
|
-
try {
|
|
229
|
-
while (true) {
|
|
230
|
-
const { done, value } = await reader.read();
|
|
231
|
-
if (done) break;
|
|
232
|
-
|
|
233
|
-
// Apply redaction if enabled
|
|
234
|
-
const chunk = this.streamOptions.redact
|
|
235
|
-
? redactChunk(value)
|
|
236
|
-
: value;
|
|
237
|
-
|
|
238
|
-
// Format based on stream format
|
|
239
|
-
if (isSSE) {
|
|
240
|
-
response.write(`data: ${JSON.stringify(chunk)}\n\n`);
|
|
241
|
-
} else {
|
|
242
|
-
response.write(JSON.stringify(chunk) + '\x1E');
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// Send completion marker (SSE uses data: [DONE], other formats use record separator)
|
|
247
|
-
if (isSSE) {
|
|
248
|
-
response.write('data: [DONE]\n\n');
|
|
249
|
-
}
|
|
250
|
-
response.end();
|
|
251
|
-
} catch (error) {
|
|
252
|
-
reader.cancel();
|
|
253
|
-
throw error;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
## Helper methods
|
|
259
|
-
|
|
260
|
-
The base class provides helper methods you can use in your implementation. These handle common tasks like parameter validation and route registration, so you don't need to reimplement them:
|
|
261
|
-
|
|
262
|
-
| Method | Description |
|
|
263
|
-
| ------------------------------------------------------------------- | ----------------------------------------------------------- |
|
|
264
|
-
| `parsePathParams(route, params)` | Validate path params with Zod schema |
|
|
265
|
-
| `parseQueryParams(route, params)` | Validate query params with Zod schema |
|
|
266
|
-
| `parseBody(route, body)` | Validate body with Zod schema |
|
|
267
|
-
| `mergeRequestContext({ paramsRequestContext, bodyRequestContext })` | Merge request context from multiple sources |
|
|
268
|
-
| `registerRoutes()` | Register all Mastra routes (calls `registerRoute` for each) |
|
|
269
|
-
| `registerOpenAPIRoute(app, config, { prefix })` | Register OpenAPI spec endpoint |
|
|
270
|
-
|
|
271
|
-
The `parse*` methods use Zod schemas defined on each route to validate input and return typed results. If validation fails, they throw an error with details about what went wrong.
|
|
272
|
-
|
|
273
|
-
## Constructor
|
|
274
|
-
|
|
275
|
-
Your adapter's constructor should accept the same options as the base class and pass them to `super()`. You can add additional framework-specific options if needed:
|
|
276
|
-
|
|
277
|
-
```typescript
|
|
278
|
-
constructor(options: {
|
|
279
|
-
app: MyApp;
|
|
280
|
-
mastra: Mastra;
|
|
281
|
-
prefix?: string;
|
|
282
|
-
openapiPath?: string;
|
|
283
|
-
bodyLimitOptions?: BodyLimitOptions;
|
|
284
|
-
streamOptions?: StreamOptions;
|
|
285
|
-
customRouteAuthConfig?: Map<string, boolean>;
|
|
286
|
-
}) {
|
|
287
|
-
super(options);
|
|
288
|
-
}
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
See [Server Adapters](https://mastra.ai/docs/server/server-adapters) for full documentation on each option.
|
|
292
|
-
|
|
293
|
-
## Full example
|
|
294
|
-
|
|
295
|
-
Here's a skeleton implementation showing all the required methods. This uses pseudocode for framework-specific parts—replace with your framework's actual APIs:
|
|
296
|
-
|
|
297
|
-
```typescript
|
|
298
|
-
import { MastraServer, ServerRoute } from '@mastra/server/server-adapter';
|
|
299
|
-
import type { Mastra } from '@mastra/core';
|
|
300
|
-
|
|
301
|
-
export class MyFrameworkServer extends MastraServer<MyApp, MyRequest, MyResponse> {
|
|
302
|
-
constructor(options: { app: MyApp; mastra: Mastra; prefix?: string }) {
|
|
303
|
-
super(options);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
registerContextMiddleware(): void {
|
|
307
|
-
this.app.use('*', (req, res, next) => {
|
|
308
|
-
res.locals.mastra = this.mastra;
|
|
309
|
-
res.locals.requestContext = this.mergeRequestContext({
|
|
310
|
-
paramsRequestContext: req.query.requestContext,
|
|
311
|
-
bodyRequestContext: req.body?.requestContext,
|
|
312
|
-
});
|
|
313
|
-
res.locals.tools = this.tools ?? {};
|
|
314
|
-
res.locals.abortSignal = createAbortSignal(req);
|
|
315
|
-
next();
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
registerAuthMiddleware(): void {
|
|
320
|
-
const authConfig = this.mastra.getServer()?.auth;
|
|
321
|
-
if (!authConfig) return;
|
|
322
|
-
// ... implement auth middleware
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
async registerRoute(app: MyApp, route: ServerRoute, { prefix }: { prefix?: string }): Promise<void> {
|
|
326
|
-
// ... implement route registration
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
async getParams(route: ServerRoute, request: MyRequest) {
|
|
330
|
-
return {
|
|
331
|
-
urlParams: request.params,
|
|
332
|
-
queryParams: request.query,
|
|
333
|
-
body: request.body,
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
async sendResponse(route: ServerRoute, response: MyResponse, result: unknown) {
|
|
338
|
-
if (route.responseType === 'stream') {
|
|
339
|
-
return this.stream(route, response, result);
|
|
340
|
-
}
|
|
341
|
-
return response.json(result);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
async stream(route: ServerRoute, response: MyResponse, result: unknown) {
|
|
345
|
-
// ... implement streaming
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
```
|
|
349
|
-
|
|
350
|
-
## Usage
|
|
351
|
-
|
|
352
|
-
Once your adapter is implemented, use it the same way as the provided adapters:
|
|
353
|
-
|
|
354
|
-
```typescript
|
|
355
|
-
import { MyFrameworkServer } from './my-framework-adapter';
|
|
356
|
-
import { mastra } from './mastra';
|
|
357
|
-
|
|
358
|
-
const app = createMyFrameworkApp();
|
|
359
|
-
const server = new MyFrameworkServer({ app, mastra });
|
|
360
|
-
|
|
361
|
-
await server.init();
|
|
362
|
-
|
|
363
|
-
app.listen(4111);
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
> **Tip:** The existing [@mastra/hono](https://github.com/mastra-ai/mastra/blob/main/server-adapters/hono/src/index.ts) and [@mastra/express](https://github.com/mastra-ai/mastra/blob/main/server-adapters/express/src/index.ts) implementations are good references when building your custom adapter. They show how to handle framework-specific patterns for context storage, middleware registration, and response handling.
|
|
367
|
-
|
|
368
|
-
## Related
|
|
369
|
-
|
|
370
|
-
- [Server Adapters](https://mastra.ai/docs/server/server-adapters) - Overview and shared concepts
|
|
371
|
-
- [Hono Adapter](https://mastra.ai/reference/server/hono-adapter) - Reference implementation
|
|
372
|
-
- [Express Adapter](https://mastra.ai/reference/server/express-adapter) - Reference implementation
|
|
373
|
-
- [MastraServer Reference](https://mastra.ai/reference/server/mastra-server) - Full API reference
|
|
374
|
-
- [createRoute() Reference](https://mastra.ai/reference/server/create-route) - Creating type-safe custom routes
|