@mastra/server 1.79.0-alpha.10 → 1.79.0-alpha.12
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/dist/{a2a-CHBSYHxu.js → a2a-BqLB3McP.js} +17 -16
- package/dist/a2a-BqLB3McP.js.map +1 -0
- package/dist/{a2a-B465DD1u.cjs → a2a-Uood_0DN.cjs} +19 -18
- package/dist/a2a-Uood_0DN.cjs.map +1 -0
- package/dist/agent-builder-CuBD1tpv.cjs +728 -0
- package/dist/agent-builder-CuBD1tpv.cjs.map +1 -0
- package/dist/agent-builder-VhM8ADW-.js +627 -0
- package/dist/agent-builder-VhM8ADW-.js.map +1 -0
- package/dist/{agents-X1E7fW3p.js → agents-BHLTMBff.js} +2 -2
- package/dist/{agents-X1E7fW3p.js.map → agents-BHLTMBff.js.map} +1 -1
- package/dist/agents-BOWEUKyV.cjs +3127 -0
- package/dist/agents-BOWEUKyV.cjs.map +1 -0
- package/dist/agents-DRQ3ScbX.js +2828 -0
- package/dist/agents-DRQ3ScbX.js.map +1 -0
- package/dist/{agents-DoNMSCMt.cjs → agents-T-OIM9IK.cjs} +2 -2
- package/dist/{agents-DoNMSCMt.cjs.map → agents-T-OIM9IK.cjs.map} +1 -1
- package/dist/{api-schema-manifest-CWRIJP-B.js → api-schema-manifest-CI90M4sX.js} +3 -3
- package/dist/{api-schema-manifest-CWRIJP-B.js.map → api-schema-manifest-CI90M4sX.js.map} +1 -1
- package/dist/{api-schema-manifest-DUseI2VG.cjs → api-schema-manifest-DIlNfbyw.cjs} +4 -4
- package/dist/{api-schema-manifest-DUseI2VG.cjs.map → api-schema-manifest-DIlNfbyw.cjs.map} +1 -1
- package/dist/{background-tasks-CabImVak.cjs → background-tasks-B3VAKTJh.cjs} +3 -3
- package/dist/{background-tasks-CabImVak.cjs.map → background-tasks-B3VAKTJh.cjs.map} +1 -1
- package/dist/{background-tasks-oBaLtnCn.js → background-tasks-Du2zYOPl.js} +2 -2
- package/dist/{background-tasks-oBaLtnCn.js.map → background-tasks-Du2zYOPl.js.map} +1 -1
- package/dist/{builder-registry-DOkLe8ES.js → builder-registry-DLdu9bWH.js} +3 -3
- package/dist/{builder-registry-DOkLe8ES.js.map → builder-registry-DLdu9bWH.js.map} +1 -1
- package/dist/{builder-registry-D0frV8lQ.cjs → builder-registry-DaFAaMTf.cjs} +3 -3
- package/dist/{builder-registry-D0frV8lQ.cjs.map → builder-registry-DaFAaMTf.cjs.map} +1 -1
- package/dist/{channels-CBIopVWd.cjs → channels-BnVRmnzK.cjs} +6 -3
- package/dist/{channels-CBIopVWd.cjs.map → channels-BnVRmnzK.cjs.map} +1 -1
- package/dist/{channels-BOxgHvzI.js → channels-Db-4pXVZ.js} +6 -3
- package/dist/{channels-BOxgHvzI.js.map → channels-Db-4pXVZ.js.map} +1 -1
- package/dist/conversations-8BWryNlF.js +165 -0
- package/dist/conversations-8BWryNlF.js.map +1 -0
- package/dist/conversations-C5MkQBB8.cjs +194 -0
- package/dist/conversations-C5MkQBB8.cjs.map +1 -0
- package/dist/{conversations-Bj5TLNqF.cjs → conversations-DasqEDCF.cjs} +3 -3
- package/dist/{conversations-Bj5TLNqF.cjs.map → conversations-DasqEDCF.cjs.map} +1 -1
- package/dist/{dist-9c3PXXpk.cjs → dist-B-bEVWlJ.cjs} +4733 -1251
- package/dist/dist-B-bEVWlJ.cjs.map +1 -0
- package/dist/dist-B3kC8Yd0.cjs +3 -0
- package/dist/{dist-CQ3FSKT-.cjs → dist-B9ery9Zw.cjs} +38 -35
- package/dist/{dist-CQ3FSKT-.cjs.map → dist-B9ery9Zw.cjs.map} +1 -1
- package/dist/{dist-BxMmGD3n.js → dist-BBOnrL_A.js} +10 -12
- package/dist/{dist-BxMmGD3n.js.map → dist-BBOnrL_A.js.map} +1 -1
- package/dist/{dist-DOWsEmo6.js → dist-BIrQLUV9.js} +20 -20
- package/dist/{dist-DOWsEmo6.js.map → dist-BIrQLUV9.js.map} +1 -1
- package/dist/dist-BM9J-PTK.js +1 -0
- package/dist/{dist-DC1Pewf5.cjs → dist-Bo3GdQwf.cjs} +21 -21
- package/dist/{dist-DC1Pewf5.cjs.map → dist-Bo3GdQwf.cjs.map} +1 -1
- package/dist/{dist-BwYL7Ykb.js → dist-CREG82cy.js} +37 -34
- package/dist/{dist-BwYL7Ykb.js.map → dist-CREG82cy.js.map} +1 -1
- package/dist/{dist-rDRetJVY.cjs → dist-CeTLA-e5.cjs} +2 -3
- package/dist/{dist-rDRetJVY.cjs.map → dist-CeTLA-e5.cjs.map} +1 -1
- package/dist/{dist-CBRJax5e.js → dist-DLld1qjf.js} +25 -31
- package/dist/{dist-CBRJax5e.js.map → dist-DLld1qjf.js.map} +1 -1
- package/dist/{dist-B_bet8uz.js → dist-DjkPkAzV.js} +2 -3
- package/dist/{dist-B_bet8uz.js.map → dist-DjkPkAzV.js.map} +1 -1
- package/dist/{dist-UKEksCGq.cjs → dist-DsrJXwic.cjs} +11 -13
- package/dist/{dist-UKEksCGq.cjs.map → dist-DsrJXwic.cjs.map} +1 -1
- package/dist/{dist-DGCnbhNe.js → dist-k77XQGUn.js} +4493 -1043
- package/dist/dist-k77XQGUn.js.map +1 -0
- package/dist/{dist-3FPW9nVj.cjs → dist-lT2rqyY9.cjs} +26 -32
- package/dist/{dist-3FPW9nVj.cjs.map → dist-lT2rqyY9.cjs.map} +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/{dynamic-workflows-Rr_6ac1y.js → dynamic-workflows-CTUO0SFu.js} +3 -3
- package/dist/{dynamic-workflows-Rr_6ac1y.js.map → dynamic-workflows-CTUO0SFu.js.map} +1 -1
- package/dist/{dynamic-workflows-DXlkr-jK.cjs → dynamic-workflows-HwPX3mcf.cjs} +3 -3
- package/dist/{dynamic-workflows-DXlkr-jK.cjs.map → dynamic-workflows-HwPX3mcf.cjs.map} +1 -1
- package/dist/{editor-builder-BclcHxN6.cjs → editor-builder-BDtiWw0f.cjs} +2 -2
- package/dist/{editor-builder-BclcHxN6.cjs.map → editor-builder-BDtiWw0f.cjs.map} +1 -1
- package/dist/{editor-builder-D16kc1P6.js → editor-builder-ClFlGXoX.js} +4 -4
- package/dist/{editor-builder-D16kc1P6.js.map → editor-builder-ClFlGXoX.js.map} +1 -1
- package/dist/{editor-builder-s9WqPJgA.js → editor-builder-DnLCfqnY.js} +2 -2
- package/dist/{editor-builder-s9WqPJgA.js.map → editor-builder-DnLCfqnY.js.map} +1 -1
- package/dist/{editor-builder-DXHiPX1A.cjs → editor-builder-DtpP1FtW.cjs} +5 -5
- package/dist/{editor-builder-DXHiPX1A.cjs.map → editor-builder-DtpP1FtW.cjs.map} +1 -1
- package/dist/{helpers-ElhPeCSK.cjs → helpers-CAcEhq38.cjs} +21 -17
- package/dist/{helpers-ElhPeCSK.cjs.map → helpers-CAcEhq38.cjs.map} +1 -1
- package/dist/{helpers-DLhX1fqc.js → helpers-vrqddDd5.js} +21 -17
- package/dist/{helpers-DLhX1fqc.js.map → helpers-vrqddDd5.js.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/logs-CiSw7r0s.cjs +119 -0
- package/dist/logs-CiSw7r0s.cjs.map +1 -0
- package/dist/logs-CxfPk-iL.js +96 -0
- package/dist/logs-CxfPk-iL.js.map +1 -0
- package/dist/mcp-CWDfSu7w.js +474 -0
- package/dist/mcp-CWDfSu7w.js.map +1 -0
- package/dist/mcp-CWGJRqkC.cjs +563 -0
- package/dist/mcp-CWGJRqkC.cjs.map +1 -0
- package/dist/{mcp-DzpwLXEY.js → mcp-Drqt0GqD.js} +79 -4
- package/dist/mcp-Drqt0GqD.js.map +1 -0
- package/dist/{mcp-ShaKO7gA.cjs → mcp-ziWVk7Ol.cjs} +126 -3
- package/dist/mcp-ziWVk7Ol.cjs.map +1 -0
- package/dist/memory-BHtTSzvJ.js +1739 -0
- package/dist/memory-BHtTSzvJ.js.map +1 -0
- package/dist/memory-CwwkVDh1.cjs +1906 -0
- package/dist/memory-CwwkVDh1.cjs.map +1 -0
- package/dist/observability-BBMCMeT-.cjs +502 -0
- package/dist/observability-BBMCMeT-.cjs.map +1 -0
- package/dist/observability-ZRgRcvoX.js +431 -0
- package/dist/observability-ZRgRcvoX.js.map +1 -0
- package/dist/{observability-new-endpoints-BU8JYPfh.js → observability-new-endpoints-fjoZzEtk.js} +10 -9
- package/dist/{observability-new-endpoints-BU8JYPfh.js.map → observability-new-endpoints-fjoZzEtk.js.map} +1 -1
- package/dist/{observability-new-endpoints-AMp9bnMV.cjs → observability-new-endpoints-tG3-odLa.cjs} +11 -10
- package/dist/observability-new-endpoints-tG3-odLa.cjs.map +1 -0
- package/dist/plans-CiPgWBhO.cjs +68 -0
- package/dist/plans-CiPgWBhO.cjs.map +1 -0
- package/dist/plans-DCepEY7n.js +57 -0
- package/dist/plans-DCepEY7n.js.map +1 -0
- package/dist/{probe-image-size-DBGjhUtJ.cjs → probe-image-size-Alv3gwKl.cjs} +194 -184
- package/dist/probe-image-size-Alv3gwKl.cjs.map +1 -0
- package/dist/{probe-image-size-Dmoxv93t.js → probe-image-size-BdfbUHxx.js} +158 -148
- package/dist/probe-image-size-BdfbUHxx.js.map +1 -0
- package/dist/responses-4FwMNxoJ.js +628 -0
- package/dist/responses-4FwMNxoJ.js.map +1 -0
- package/dist/responses-CCRijwDF.cjs +651 -0
- package/dist/responses-CCRijwDF.cjs.map +1 -0
- package/dist/{responses-CKNdSRkS.cjs → responses-CfcIc53b.cjs} +2 -2
- package/dist/{responses-CKNdSRkS.cjs.map → responses-CfcIc53b.cjs.map} +1 -1
- package/dist/{rolldown-runtime-Bd6kNlEP.cjs → rolldown-runtime-BwC_XMyb.cjs} +2 -2
- package/dist/{rolldown-runtime-maW3aOIk.js → rolldown-runtime-D3Hj5m0v.js} +2 -2
- package/dist/{route-builder-BNZs643f.cjs → route-builder-B2Qhhd7C.cjs} +52 -66
- package/dist/route-builder-B2Qhhd7C.cjs.map +1 -0
- package/dist/{route-builder-BfQYtclb.js → route-builder-CjkWxv4E.js} +51 -65
- package/dist/route-builder-CjkWxv4E.js.map +1 -0
- package/dist/{routes-rwufkyUe.js → routes-BC20mdNN.js} +30 -26
- package/dist/routes-BC20mdNN.js.map +1 -0
- package/dist/{routes-Dl6_kWm7.js → routes-CKfXiwRc.js} +5 -3
- package/dist/routes-CKfXiwRc.js.map +1 -0
- package/dist/{routes-DPojsNf1.cjs → routes-DGLJyqjD.cjs} +203 -199
- package/dist/routes-DGLJyqjD.cjs.map +1 -0
- package/dist/{routes-BULZI-PU.cjs → routes-jXksmX9G.cjs} +5 -3
- package/dist/routes-jXksmX9G.cjs.map +1 -0
- package/dist/{schedules-Bj-giFbc.cjs → schedules-GokZKBYg.cjs} +6 -4
- package/dist/schedules-GokZKBYg.cjs.map +1 -0
- package/dist/{schedules-BQYgaz66.js → schedules-_3zPKyqm.js} +5 -3
- package/dist/schedules-_3zPKyqm.js.map +1 -0
- package/dist/{schema-e0VHpMt0-C0452jOk.cjs → schema-CzbEIyhE-20gGIWkz.cjs} +83 -88
- package/dist/schema-CzbEIyhE-20gGIWkz.cjs.map +1 -0
- package/dist/{schema-e0VHpMt0-CVP5Hnxy.js → schema-CzbEIyhE-BsMcj9Ws.js} +82 -87
- package/dist/schema-CzbEIyhE-BsMcj9Ws.js.map +1 -0
- package/dist/scores-D9UgETt_.js +288 -0
- package/dist/scores-D9UgETt_.js.map +1 -0
- package/dist/scores-DRdtS7NT.cjs +329 -0
- package/dist/scores-DRdtS7NT.cjs.map +1 -0
- package/dist/server/a2a/store.cjs +1 -1
- package/dist/server/auth/index.cjs +2 -2
- package/dist/server/auth/index.js +1 -1
- package/dist/server/browser-stream/index.cjs +9 -11
- package/dist/server/browser-stream/index.cjs.map +1 -1
- package/dist/server/browser-stream/index.js +8 -10
- package/dist/server/browser-stream/index.js.map +1 -1
- package/dist/server/handlers/a2a.cjs +2 -2
- package/dist/server/handlers/a2a.js +1 -2
- package/dist/server/handlers/agent-builder.cjs +18 -648
- package/dist/server/handlers/agent-builder.js +1 -627
- package/dist/server/handlers/agent-controller.cjs +5 -5
- package/dist/server/handlers/agent-controller.cjs.map +1 -1
- package/dist/server/handlers/agent-controller.js +11 -9
- package/dist/server/handlers/agent-controller.js.map +1 -1
- package/dist/server/handlers/agent-versions.cjs +15 -8
- package/dist/server/handlers/agent-versions.cjs.map +1 -1
- package/dist/server/handlers/agent-versions.js +14 -7
- package/dist/server/handlers/agent-versions.js.map +1 -1
- package/dist/server/handlers/agents.cjs +51 -2860
- package/dist/server/handlers/agents.js +1 -2806
- package/dist/server/handlers/auth.cjs +14 -12
- package/dist/server/handlers/auth.cjs.map +1 -1
- package/dist/server/handlers/auth.js +20 -16
- package/dist/server/handlers/auth.js.map +1 -1
- package/dist/server/handlers/author-enrichment.cjs +1 -1
- package/dist/server/handlers/authorship.cjs +1 -1
- package/dist/server/handlers/authorship.cjs.map +1 -1
- package/dist/server/handlers/background-tasks.cjs +2 -2
- package/dist/server/handlers/background-tasks.js +1 -2
- package/dist/server/handlers/builder-registry.cjs +2 -2
- package/dist/server/handlers/builder-registry.js +1 -2
- package/dist/server/handlers/channels.cjs +2 -2
- package/dist/server/handlers/channels.js +1 -2
- package/dist/server/handlers/conversations.cjs +6 -171
- package/dist/server/handlers/conversations.js +1 -162
- package/dist/server/handlers/datasets.cjs +2 -2
- package/dist/server/handlers/datasets.cjs.map +1 -1
- package/dist/server/handlers/datasets.js +1 -1
- package/dist/server/handlers/dynamic-workflows.cjs +2 -2
- package/dist/server/handlers/dynamic-workflows.js +1 -2
- package/dist/server/handlers/editor-builder.cjs +2 -2
- package/dist/server/handlers/editor-builder.js +1 -2
- package/dist/server/handlers/error.cjs +18 -13
- package/dist/server/handlers/error.cjs.map +1 -1
- package/dist/server/handlers/error.js +17 -12
- package/dist/server/handlers/error.js.map +1 -1
- package/dist/server/handlers/favorites-enrichment.cjs +2 -2
- package/dist/server/handlers/favorites-enrichment.js +1 -1
- package/dist/server/handlers/gateway-memory-client.cjs +1 -1
- package/dist/server/handlers/logs.cjs +5 -104
- package/dist/server/handlers/logs.js +1 -96
- package/dist/server/handlers/mcp-client-versions.cjs +15 -8
- package/dist/server/handlers/mcp-client-versions.cjs.map +1 -1
- package/dist/server/handlers/mcp-client-versions.js +14 -7
- package/dist/server/handlers/mcp-client-versions.js.map +1 -1
- package/dist/server/handlers/mcp.cjs +16 -289
- package/dist/server/handlers/mcp.d.ts +219 -0
- package/dist/server/handlers/mcp.d.ts.map +1 -1
- package/dist/server/handlers/mcp.js +1 -274
- package/dist/server/handlers/memory.cjs +29 -1763
- package/dist/server/handlers/memory.js +1 -1731
- package/dist/server/handlers/observability-list-query-schemas.cjs +1 -1
- package/dist/server/handlers/observability-new-endpoints.cjs +2 -2
- package/dist/server/handlers/observability-new-endpoints.js +1 -2
- package/dist/server/handlers/observability-shared.cjs +2 -2
- package/dist/server/handlers/observability-shared.js +1 -1
- package/dist/server/handlers/observability-storage-schemas.cjs +1 -1
- package/dist/server/handlers/observability.cjs +14 -445
- package/dist/server/handlers/observability.js +3 -429
- package/dist/server/handlers/plans.cjs +3 -63
- package/dist/server/handlers/plans.js +1 -57
- package/dist/server/handlers/processor-providers.cjs +2 -2
- package/dist/server/handlers/processor-providers.cjs.map +1 -1
- package/dist/server/handlers/processor-providers.js +1 -1
- package/dist/server/handlers/processors.cjs +13 -15
- package/dist/server/handlers/processors.cjs.map +1 -1
- package/dist/server/handlers/processors.js +12 -14
- package/dist/server/handlers/processors.js.map +1 -1
- package/dist/server/handlers/prompt-block-versions.cjs +15 -8
- package/dist/server/handlers/prompt-block-versions.cjs.map +1 -1
- package/dist/server/handlers/prompt-block-versions.js +14 -7
- package/dist/server/handlers/prompt-block-versions.js.map +1 -1
- package/dist/server/handlers/responses.adapter.cjs +1 -1
- package/dist/server/handlers/responses.adapter.cjs.map +1 -1
- package/dist/server/handlers/responses.cjs +5 -632
- package/dist/server/handlers/responses.js +1 -624
- package/dist/server/handlers/responses.storage.cjs +2 -2
- package/dist/server/handlers/schedules-workflows-shim.cjs +1 -1
- package/dist/server/handlers/schedules.cjs +2 -2
- package/dist/server/handlers/schedules.d.ts +16 -0
- package/dist/server/handlers/schedules.d.ts.map +1 -1
- package/dist/server/handlers/schedules.js +1 -2
- package/dist/server/handlers/scorer-versions.cjs +15 -8
- package/dist/server/handlers/scorer-versions.cjs.map +1 -1
- package/dist/server/handlers/scorer-versions.js +14 -7
- package/dist/server/handlers/scorer-versions.js.map +1 -1
- package/dist/server/handlers/scores.cjs +8 -299
- package/dist/server/handlers/scores.js +1 -288
- package/dist/server/handlers/skills-sh-shared.cjs +1 -1
- package/dist/server/handlers/stored-agent-favorites.cjs +4 -4
- package/dist/server/handlers/stored-agent-favorites.js +3 -3
- package/dist/server/handlers/stored-agents.cjs +19 -13
- package/dist/server/handlers/stored-agents.cjs.map +1 -1
- package/dist/server/handlers/stored-agents.js +18 -12
- package/dist/server/handlers/stored-agents.js.map +1 -1
- package/dist/server/handlers/stored-mcp-clients.cjs +8 -6
- package/dist/server/handlers/stored-mcp-clients.cjs.map +1 -1
- package/dist/server/handlers/stored-mcp-clients.js +7 -5
- package/dist/server/handlers/stored-mcp-clients.js.map +1 -1
- package/dist/server/handlers/stored-prompt-blocks.cjs +3 -3
- package/dist/server/handlers/stored-prompt-blocks.js +2 -2
- package/dist/server/handlers/stored-scorers.cjs +3 -3
- package/dist/server/handlers/stored-scorers.js +2 -2
- package/dist/server/handlers/stored-skill-favorites.cjs +4 -4
- package/dist/server/handlers/stored-skill-favorites.js +3 -3
- package/dist/server/handlers/stored-skills.cjs +6 -5
- package/dist/server/handlers/stored-skills.cjs.map +1 -1
- package/dist/server/handlers/stored-skills.js +5 -4
- package/dist/server/handlers/stored-skills.js.map +1 -1
- package/dist/server/handlers/stored-workspaces.cjs +3 -3
- package/dist/server/handlers/stored-workspaces.js +2 -2
- package/dist/server/handlers/system.cjs +3 -3
- package/dist/server/handlers/system.cjs.map +1 -1
- package/dist/server/handlers/system.js +2 -2
- package/dist/server/handlers/test-utils.cjs +1 -1
- package/dist/server/handlers/tool-providers.cjs +2 -2
- package/dist/server/handlers/tool-providers.js +1 -1
- package/dist/server/handlers/tool-schema-overrides.cjs +1 -1
- package/dist/server/handlers/tools.cjs +7 -267
- package/dist/server/handlers/tools.js +1 -257
- package/dist/server/handlers/utils.cjs +2 -2
- package/dist/server/handlers/utils.js +1 -2
- package/dist/server/handlers/validate-agent-instructions.cjs +2 -2
- package/dist/server/handlers/validate-agent-instructions.js +1 -1
- package/dist/server/handlers/validate-avatar.cjs +2 -2
- package/dist/server/handlers/validate-avatar.cjs.map +1 -1
- package/dist/server/handlers/validate-avatar.js +1 -1
- package/dist/server/handlers/validate-avatar.js.map +1 -1
- package/dist/server/handlers/vector.cjs +17 -334
- package/dist/server/handlers/vector.js +1 -314
- package/dist/server/handlers/version-helpers.cjs +1 -1
- package/dist/server/handlers/voice.cjs +9 -35
- package/dist/server/handlers/voice.js +1 -23
- package/dist/server/handlers/workflow-builder.cjs +2 -2
- package/dist/server/handlers/workflow-builder.js +1 -2
- package/dist/server/handlers/workflows.cjs +30 -1293
- package/dist/server/handlers/workflows.js +1 -1257
- package/dist/server/handlers/workspace.cjs +27 -1176
- package/dist/server/handlers/workspace.js +1 -1146
- package/dist/server/handlers.cjs +33 -33
- package/dist/server/handlers.js +17 -17
- package/dist/server/schemas/index.cjs +7 -7
- package/dist/server/schemas/index.js +4 -4
- package/dist/server/schemas/mcp.d.ts +102 -0
- package/dist/server/schemas/mcp.d.ts.map +1 -1
- package/dist/server/schemas/schedules.d.ts +5 -0
- package/dist/server/schemas/schedules.d.ts.map +1 -1
- package/dist/server/server-adapter/index.cjs +5 -5
- package/dist/server/server-adapter/index.cjs.map +1 -1
- package/dist/server/server-adapter/index.js +4 -4
- package/dist/server/server-adapter/index.js.map +1 -1
- package/dist/server/server-adapter/routes/mcp.d.ts +214 -0
- package/dist/server/server-adapter/routes/mcp.d.ts.map +1 -1
- package/dist/tools-CmFSfDMn.js +256 -0
- package/dist/tools-CmFSfDMn.js.map +1 -0
- package/dist/tools-SPJtxG9N.cjs +291 -0
- package/dist/tools-SPJtxG9N.cjs.map +1 -0
- package/dist/{utils-DCgeTrq2.cjs → utils-CF76qzZR.cjs} +12 -17
- package/dist/{utils-DCgeTrq2.cjs.map → utils-CF76qzZR.cjs.map} +1 -1
- package/dist/{utils-DCAUeb6M.js → utils-aoLN3Wfi.js} +11 -16
- package/dist/{utils-DCAUeb6M.js.map → utils-aoLN3Wfi.js.map} +1 -1
- package/dist/{utils-Du-EpvDs.cjs → utils-dDLIDg8O.cjs} +2 -2
- package/dist/{utils-Du-EpvDs.cjs.map → utils-dDLIDg8O.cjs.map} +1 -1
- package/dist/vector-BKDD1kwc.cjs +409 -0
- package/dist/vector-BKDD1kwc.cjs.map +1 -0
- package/dist/vector-TWv4t-4g.js +314 -0
- package/dist/vector-TWv4t-4g.js.map +1 -0
- package/dist/voice-BnGwlZ75.cjs +70 -0
- package/dist/voice-BnGwlZ75.cjs.map +1 -0
- package/dist/voice-DjG8tBAD.js +23 -0
- package/dist/voice-DjG8tBAD.js.map +1 -0
- package/dist/{workflow-builder-Brj3IArM.cjs → workflow-builder-C9-8ZOWF.cjs} +5 -5
- package/dist/{workflow-builder-Brj3IArM.cjs.map → workflow-builder-C9-8ZOWF.cjs.map} +1 -1
- package/dist/{workflow-builder-DOa1Vx6w.js → workflow-builder-CjlLoQvo.js} +10 -8
- package/dist/{workflow-builder-DOa1Vx6w.js.map → workflow-builder-CjlLoQvo.js.map} +1 -1
- package/dist/workflows-DjqeJcdJ.cjs +1446 -0
- package/dist/workflows-DjqeJcdJ.cjs.map +1 -0
- package/dist/workflows-bb-otd2o.js +1273 -0
- package/dist/workflows-bb-otd2o.js.map +1 -0
- package/dist/workspace-B6kzp-bo.js +1154 -0
- package/dist/workspace-B6kzp-bo.js.map +1 -0
- package/dist/workspace-COKR1SxH.cjs +1309 -0
- package/dist/workspace-COKR1SxH.cjs.map +1 -0
- package/package.json +4 -4
- package/dist/a2a-B465DD1u.cjs.map +0 -1
- package/dist/a2a-CHBSYHxu.js.map +0 -1
- package/dist/dist-9c3PXXpk.cjs.map +0 -1
- package/dist/dist-B5OwHWTo.cjs +0 -2294
- package/dist/dist-B5OwHWTo.cjs.map +0 -1
- package/dist/dist-DGCnbhNe.js.map +0 -1
- package/dist/dist-DcoIg_tp.js +0 -2293
- package/dist/dist-DcoIg_tp.js.map +0 -1
- package/dist/mcp-DzpwLXEY.js.map +0 -1
- package/dist/mcp-ShaKO7gA.cjs.map +0 -1
- package/dist/observability-new-endpoints-AMp9bnMV.cjs.map +0 -1
- package/dist/probe-image-size-DBGjhUtJ.cjs.map +0 -1
- package/dist/probe-image-size-Dmoxv93t.js.map +0 -1
- package/dist/route-builder-BNZs643f.cjs.map +0 -1
- package/dist/route-builder-BfQYtclb.js.map +0 -1
- package/dist/routes-BULZI-PU.cjs.map +0 -1
- package/dist/routes-DPojsNf1.cjs.map +0 -1
- package/dist/routes-Dl6_kWm7.js.map +0 -1
- package/dist/routes-rwufkyUe.js.map +0 -1
- package/dist/schedules-BQYgaz66.js.map +0 -1
- package/dist/schedules-Bj-giFbc.cjs.map +0 -1
- package/dist/schema-Drf2W04o.js +0 -2
- package/dist/schema-EQanefYq.cjs +0 -1
- package/dist/schema-e0VHpMt0-C0452jOk.cjs.map +0 -1
- package/dist/schema-e0VHpMt0-CVP5Hnxy.js.map +0 -1
- package/dist/server/handlers/agent-builder.cjs.map +0 -1
- package/dist/server/handlers/agent-builder.js.map +0 -1
- package/dist/server/handlers/agents.cjs.map +0 -1
- package/dist/server/handlers/agents.js.map +0 -1
- package/dist/server/handlers/conversations.cjs.map +0 -1
- package/dist/server/handlers/conversations.js.map +0 -1
- package/dist/server/handlers/logs.cjs.map +0 -1
- package/dist/server/handlers/logs.js.map +0 -1
- package/dist/server/handlers/mcp.cjs.map +0 -1
- package/dist/server/handlers/mcp.js.map +0 -1
- package/dist/server/handlers/memory.cjs.map +0 -1
- package/dist/server/handlers/memory.js.map +0 -1
- package/dist/server/handlers/observability.cjs.map +0 -1
- package/dist/server/handlers/observability.js.map +0 -1
- package/dist/server/handlers/plans.cjs.map +0 -1
- package/dist/server/handlers/plans.js.map +0 -1
- package/dist/server/handlers/responses.cjs.map +0 -1
- package/dist/server/handlers/responses.js.map +0 -1
- package/dist/server/handlers/scores.cjs.map +0 -1
- package/dist/server/handlers/scores.js.map +0 -1
- package/dist/server/handlers/tools.cjs.map +0 -1
- package/dist/server/handlers/tools.js.map +0 -1
- package/dist/server/handlers/vector.cjs.map +0 -1
- package/dist/server/handlers/vector.js.map +0 -1
- package/dist/server/handlers/voice.cjs.map +0 -1
- package/dist/server/handlers/voice.js.map +0 -1
- package/dist/server/handlers/workflows.cjs.map +0 -1
- package/dist/server/handlers/workflows.js.map +0 -1
- package/dist/server/handlers/workspace.cjs.map +0 -1
- package/dist/server/handlers/workspace.js.map +0 -1
- package/dist/sync-Ai_ZDz7U.js +0 -1700
- package/dist/sync-Ai_ZDz7U.js.map +0 -1
- package/dist/sync-BrO5MtSe.cjs +0 -1729
- package/dist/sync-BrO5MtSe.cjs.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("../../rolldown-runtime-
|
|
2
|
+
require("../../rolldown-runtime-BwC_XMyb.cjs");
|
|
3
3
|
const require_http_exception = require("../../http-exception-CKDHupKw.cjs");
|
|
4
|
-
const require_route_builder = require("../../route-builder-
|
|
5
|
-
const require_utils = require("../../utils-
|
|
4
|
+
const require_route_builder = require("../../route-builder-B2Qhhd7C.cjs");
|
|
5
|
+
const require_utils = require("../../utils-CF76qzZR.cjs");
|
|
6
6
|
const require_server_handlers_error = require("./error.cjs");
|
|
7
7
|
const require_version_common = require("../../version-common-DrzXq7Ct.cjs");
|
|
8
8
|
const require_agent_versions = require("../../agent-versions-CzXJWn1T.cjs");
|
|
@@ -99,7 +99,8 @@ const CREATE_AGENT_VERSION_ROUTE = require_route_builder.createRoute({
|
|
|
99
99
|
}
|
|
100
100
|
const latestVersion = await agentsStore.getLatestVersion(agentId);
|
|
101
101
|
if (!agent.activeVersionId && latestVersion) currentConfig = require_server_handlers_version_helpers.extractConfigFromVersion(latestVersion, SNAPSHOT_CONFIG_FIELDS);
|
|
102
|
-
const
|
|
102
|
+
const previousConfig = latestVersion ? require_server_handlers_version_helpers.extractConfigFromVersion(latestVersion, SNAPSHOT_CONFIG_FIELDS) : null;
|
|
103
|
+
const changedFields = require_server_handlers_version_helpers.calculateChangedFields(previousConfig, currentConfig);
|
|
103
104
|
const { versionId } = await require_server_handlers_version_helpers.createVersionWithRetry(agentsStore, agentId, "agentId", currentConfig, changedFields, { changeMessage });
|
|
104
105
|
const version = await agentsStore.getVersion(versionId);
|
|
105
106
|
if (!version) throw new require_http_exception.HTTPException(500, { message: "Failed to retrieve created version" });
|
|
@@ -132,7 +133,8 @@ const GET_AGENT_VERSION_ROUTE = require_route_builder.createRoute({
|
|
|
132
133
|
const version = await agentsStore.getVersion(versionId);
|
|
133
134
|
if (!version) throw new require_http_exception.HTTPException(404, { message: `Version with id ${versionId} not found` });
|
|
134
135
|
if (version.agentId !== agentId) throw new require_http_exception.HTTPException(404, { message: `Version with id ${versionId} not found for agent ${agentId}` });
|
|
135
|
-
|
|
136
|
+
const agent = await agentsStore.getById(agentId);
|
|
137
|
+
require_utils.assertStoredResourceScope(agent, await require_utils.getStoredResourceScope(mastra, requestContext));
|
|
136
138
|
return version;
|
|
137
139
|
} catch (error) {
|
|
138
140
|
return require_server_handlers_error.handleError(error, "Error getting agent version");
|
|
@@ -216,7 +218,9 @@ const RESTORE_AGENT_VERSION_ROUTE = require_route_builder.createRoute({
|
|
|
216
218
|
...restoredConfig
|
|
217
219
|
});
|
|
218
220
|
const latestVersion = await agentsStore.getLatestVersion(agentId);
|
|
219
|
-
const
|
|
221
|
+
const previousConfig = latestVersion ? require_server_handlers_version_helpers.extractConfigFromVersion(latestVersion, SNAPSHOT_CONFIG_FIELDS) : null;
|
|
222
|
+
const changedFields = require_server_handlers_version_helpers.calculateChangedFields(previousConfig, restoredConfig);
|
|
223
|
+
const { versionId: newVersionId } = await require_server_handlers_version_helpers.createVersionWithRetry(agentsStore, agentId, "agentId", restoredConfig, changedFields, { changeMessage: `Restored from version ${versionToRestore.versionNumber}` });
|
|
220
224
|
const newVersion = await agentsStore.getVersion(newVersionId);
|
|
221
225
|
if (!newVersion) throw new require_http_exception.HTTPException(500, { message: "Failed to retrieve created version" });
|
|
222
226
|
await require_server_handlers_version_helpers.enforceRetentionLimit(agentsStore, agentId, "agentId", agent.activeVersionId);
|
|
@@ -284,15 +288,18 @@ const COMPARE_AGENT_VERSIONS_ROUTE = require_route_builder.createRoute({
|
|
|
284
288
|
if (!storage) throw new require_http_exception.HTTPException(500, { message: "Storage is not configured" });
|
|
285
289
|
const agentsStore = await storage.getStore("agents");
|
|
286
290
|
if (!agentsStore) throw new require_http_exception.HTTPException(500, { message: "Agents storage domain is not available" });
|
|
287
|
-
|
|
291
|
+
const agent = await agentsStore.getById(agentId);
|
|
292
|
+
require_utils.assertStoredResourceScope(agent, await require_utils.getStoredResourceScope(mastra, requestContext));
|
|
288
293
|
const fromVersion = await agentsStore.getVersion(from);
|
|
289
294
|
if (!fromVersion) throw new require_http_exception.HTTPException(404, { message: `Version with id ${from} not found` });
|
|
290
295
|
if (fromVersion.agentId !== agentId) throw new require_http_exception.HTTPException(404, { message: `Version with id ${from} not found for agent ${agentId}` });
|
|
291
296
|
const toVersion = await agentsStore.getVersion(to);
|
|
292
297
|
if (!toVersion) throw new require_http_exception.HTTPException(404, { message: `Version with id ${to} not found` });
|
|
293
298
|
if (toVersion.agentId !== agentId) throw new require_http_exception.HTTPException(404, { message: `Version with id ${to} not found for agent ${agentId}` });
|
|
299
|
+
const fromConfig = require_server_handlers_version_helpers.extractConfigFromVersion(fromVersion, SNAPSHOT_CONFIG_FIELDS);
|
|
300
|
+
const toConfig = require_server_handlers_version_helpers.extractConfigFromVersion(toVersion, SNAPSHOT_CONFIG_FIELDS);
|
|
294
301
|
return {
|
|
295
|
-
diffs: require_server_handlers_version_helpers.computeVersionDiffs(
|
|
302
|
+
diffs: require_server_handlers_version_helpers.computeVersionDiffs(fromConfig, toConfig),
|
|
296
303
|
fromVersion,
|
|
297
304
|
toVersion
|
|
298
305
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-versions.cjs","names":["createRoute","agentVersionPathParams","listVersionsQuerySchema","listVersionsResponseSchema","HTTPException","getStoredResourceScope","handleError","createVersionBodySchema","createVersionResponseSchema","extractConfigFromVersion","calculateChangedFields","createVersionWithRetry","enforceRetentionLimit","versionIdPathParams","getVersionResponseSchema","activateVersionResponseSchema","validateAgentInstructionReferences","restoreVersionResponseSchema","deleteVersionResponseSchema","compareVersionsQuerySchema","compareVersionsResponseSchema","computeVersionDiffs"],"sources":["../../../src/server/handlers/agent-versions.ts"],"sourcesContent":["import type { z } from 'zod/v4';\n\nimport { HTTPException } from '../http-exception';\nimport {\n agentVersionPathParams,\n versionIdPathParams,\n listVersionsQuerySchema,\n createVersionBodySchema,\n compareVersionsQuerySchema,\n listVersionsResponseSchema,\n getVersionResponseSchema,\n createVersionResponseSchema,\n activateVersionResponseSchema,\n restoreVersionResponseSchema,\n deleteVersionResponseSchema,\n compareVersionsResponseSchema,\n} from '../schemas/agent-versions';\nimport type { ServerRoute, RouteSchemas, InferParams } from '../server-adapter/routes';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { assertStoredResourceScope, getStoredResourceScope } from '../utils';\n\nimport { handleError } from './error';\nimport { validateAgentInstructionReferences } from './validate-agent-instructions';\nimport {\n extractConfigFromVersion,\n calculateChangedFields,\n computeVersionDiffs,\n createVersionWithRetry,\n enforceRetentionLimit,\n} from './version-helpers';\nimport type { VersionedStoreInterface } from './version-helpers';\n\n/**\n * The config field names that live on version rows (StorageAgentSnapshotType fields).\n * Used to extract config from a version record for comparison and restoration.\n */\nconst SNAPSHOT_CONFIG_FIELDS = [\n 'name',\n 'description',\n 'instructions',\n 'model',\n 'tools',\n 'defaultOptions',\n 'workflows',\n 'agents',\n 'integrationTools',\n 'inputProcessors',\n 'outputProcessors',\n 'memory',\n 'scorers',\n 'requestContextSchema',\n 'mcpClients',\n] as const;\n\n// ============================================================================\n// Route Definitions\n// ============================================================================\n\n/**\n * GET /stored/agents/:agentId/versions - List all versions for an agent\n */\nexport const LIST_AGENT_VERSIONS_ROUTE = createRoute({\n method: 'GET',\n path: '/stored/agents/:agentId/versions',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: agentVersionPathParams,\n queryParamSchema: listVersionsQuerySchema,\n responseSchema: listVersionsResponseSchema,\n summary: 'List agent versions',\n description: 'Returns a paginated list of all versions for a stored agent',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, page, perPage, orderBy, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n // Verify agent exists in code or storage\n const storedAgent = await agentsStore.getById(agentId);\n let codeAgentExists = false;\n try {\n mastra.getAgentById(agentId);\n codeAgentExists = true;\n } catch {\n // Agent not registered in code\n }\n\n if (!storedAgent && !codeAgentExists) {\n throw new HTTPException(404, { message: `Agent with id ${agentId} not found` });\n }\n assertStoredResourceScope(storedAgent, await getStoredResourceScope(mastra, requestContext));\n\n const result = await agentsStore.listVersions({\n agentId,\n page,\n perPage,\n orderBy,\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error listing agent versions');\n }\n },\n});\n\n/**\n * POST /stored/agents/:agentId/versions - Create a new version snapshot\n */\nexport const CREATE_AGENT_VERSION_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/agents/:agentId/versions',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: agentVersionPathParams,\n bodySchema: createVersionBodySchema,\n responseSchema: createVersionResponseSchema,\n summary: 'Create agent version',\n description: 'Creates a new version snapshot of the current agent configuration',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, changeMessage, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n // Get the current agent to find its active version\n const agent = await agentsStore.getById(agentId);\n if (!agent) {\n throw new HTTPException(404, { message: `Agent with id ${agentId} not found` });\n }\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n // Get the current active version to snapshot its config\n let currentConfig: Record<string, unknown> = {};\n if (agent.activeVersionId) {\n const activeVersion = await agentsStore.getVersion(agent.activeVersionId);\n if (activeVersion) {\n currentConfig = extractConfigFromVersion(\n activeVersion as unknown as Record<string, unknown>,\n SNAPSHOT_CONFIG_FIELDS,\n );\n }\n }\n\n // Get the latest version to calculate changed fields\n const latestVersion = await agentsStore.getLatestVersion(agentId);\n\n // If no activeVersionId, fall back to latest version config\n if (!agent.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 // Create the new version with retry logic to handle race conditions\n // Config fields are passed top-level\n const { versionId } = await createVersionWithRetry(\n agentsStore as unknown as VersionedStoreInterface,\n agentId,\n 'agentId',\n currentConfig,\n changedFields,\n { changeMessage },\n );\n\n // Get the created version to return\n const version = await agentsStore.getVersion(versionId);\n if (!version) {\n throw new HTTPException(500, { message: 'Failed to retrieve created version' });\n }\n\n // Enforce retention limit - delete oldest versions if we exceed the max\n await enforceRetentionLimit(\n agentsStore as unknown as VersionedStoreInterface,\n agentId,\n 'agentId',\n agent.activeVersionId,\n );\n\n return version;\n } catch (error) {\n return handleError(error, 'Error creating agent version');\n }\n },\n});\n\n/**\n * GET /stored/agents/:agentId/versions/:versionId - Get a specific version\n */\nexport const GET_AGENT_VERSION_ROUTE = createRoute({\n method: 'GET',\n path: '/stored/agents/:agentId/versions/:versionId',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: versionIdPathParams,\n responseSchema: getVersionResponseSchema,\n summary: 'Get agent version',\n description: 'Returns a specific version of an agent by its version ID',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, versionId, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n const version = await agentsStore.getVersion(versionId);\n\n if (!version) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n\n // Verify the version belongs to the specified agent\n if (version.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found for agent ${agentId}` });\n }\n const agent = await agentsStore.getById(agentId);\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n return version;\n } catch (error) {\n return handleError(error, 'Error getting agent version');\n }\n },\n});\n\n/**\n * POST /stored/agents/:agentId/versions/:versionId/activate - Set a version as active\n */\nexport const ACTIVATE_AGENT_VERSION_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/agents/:agentId/versions/:versionId/activate',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: versionIdPathParams,\n responseSchema: activateVersionResponseSchema,\n summary: 'Activate agent version',\n description: 'Sets a specific version as the active version for the agent',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, versionId, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n // Verify agent exists\n const agent = await agentsStore.getById(agentId);\n if (!agent) {\n throw new HTTPException(404, { message: `Agent with id ${agentId} not found` });\n }\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n // Verify version exists and belongs to this agent\n const version = await agentsStore.getVersion(versionId);\n if (!version) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n if (version.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found for agent ${agentId}` });\n }\n\n await validateAgentInstructionReferences({\n instructions: version.instructions,\n mastra,\n requestContext,\n });\n\n // Update the agent's activeVersionId AND status to 'published'\n await agentsStore.update({\n id: agentId,\n activeVersionId: versionId,\n status: 'published',\n });\n\n // Clear the editor cache so subsequent requests see the new active version\n mastra.getEditor()?.agent.clearCache(agentId);\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 agent version');\n }\n },\n});\n\n/**\n * POST /stored/agents/:agentId/versions/:versionId/restore - Restore agent to a version\n */\nexport const RESTORE_AGENT_VERSION_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/agents/:agentId/versions/:versionId/restore',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: versionIdPathParams,\n responseSchema: restoreVersionResponseSchema,\n summary: 'Restore agent version',\n description: 'Restores the agent configuration from a version, creating a new version',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, versionId, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n // Verify agent exists\n const agent = await agentsStore.getById(agentId);\n if (!agent) {\n throw new HTTPException(404, { message: `Agent with id ${agentId} not found` });\n }\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n // Get the version to restore\n const versionToRestore = await agentsStore.getVersion(versionId);\n if (!versionToRestore) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n if (versionToRestore.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found for agent ${agentId}` });\n }\n\n // Extract the config fields from the version to restore (top-level, no .snapshot)\n const restoredConfig = extractConfigFromVersion(\n versionToRestore as unknown as Record<string, unknown>,\n SNAPSHOT_CONFIG_FIELDS,\n );\n\n // Update the agent with the config from the version to restore\n await agentsStore.update({\n id: agentId,\n ...restoredConfig,\n });\n\n // Get the latest version to calculate changed fields\n const latestVersion = await agentsStore.getLatestVersion(agentId);\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 // Create a new version with retry logic to handle race conditions\n // Config fields are passed top-level\n const { versionId: newVersionId } = await createVersionWithRetry(\n agentsStore as unknown as VersionedStoreInterface,\n agentId,\n 'agentId',\n restoredConfig,\n changedFields,\n {\n changeMessage: `Restored from version ${versionToRestore.versionNumber}`,\n },\n );\n\n // Do NOT auto-activate the restored version - user must explicitly activate it\n\n // Get the created version to return\n const newVersion = await agentsStore.getVersion(newVersionId);\n if (!newVersion) {\n throw new HTTPException(500, { message: 'Failed to retrieve created version' });\n }\n\n // Enforce retention limit - delete oldest versions if we exceed the max\n // Use the agent's existing activeVersionId\n await enforceRetentionLimit(\n agentsStore as unknown as VersionedStoreInterface,\n agentId,\n 'agentId',\n agent.activeVersionId,\n );\n\n // Clear the editor cache so subsequent requests see the restored config\n mastra.getEditor()?.agent.clearCache(agentId);\n\n return newVersion;\n } catch (error) {\n return handleError(error, 'Error restoring agent version');\n }\n },\n});\n\n/**\n * DELETE /stored/agents/:agentId/versions/:versionId - Delete a version\n */\nexport const DELETE_AGENT_VERSION_ROUTE = createRoute({\n method: 'DELETE',\n path: '/stored/agents/:agentId/versions/:versionId',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: versionIdPathParams,\n responseSchema: deleteVersionResponseSchema,\n summary: 'Delete agent version',\n description: 'Deletes a specific version (cannot delete the active version)',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, versionId, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n // Verify agent exists\n const agent = await agentsStore.getById(agentId);\n if (!agent) {\n throw new HTTPException(404, { message: `Agent with id ${agentId} not found` });\n }\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n // Verify version exists and belongs to this agent\n const version = await agentsStore.getVersion(versionId);\n if (!version) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n if (version.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found for agent ${agentId}` });\n }\n\n // Check if this is the active version\n if (agent.activeVersionId === versionId) {\n throw new HTTPException(400, {\n message: 'Cannot delete the active version. Activate a different version first.',\n });\n }\n\n await agentsStore.deleteVersion(versionId);\n\n // Clear the editor cache in case the deleted version affected resolution\n mastra.getEditor()?.agent.clearCache(agentId);\n\n return {\n success: true,\n message: `Version ${version.versionNumber} deleted successfully`,\n };\n } catch (error) {\n return handleError(error, 'Error deleting agent version');\n }\n },\n});\n\n/**\n * GET /stored/agents/:agentId/versions/compare - Compare two versions\n */\nexport const COMPARE_AGENT_VERSIONS_ROUTE: ServerRoute<\n InferParams<typeof agentVersionPathParams, typeof compareVersionsQuerySchema, undefined>,\n z.infer<typeof compareVersionsResponseSchema>,\n 'json',\n RouteSchemas<\n typeof agentVersionPathParams,\n typeof compareVersionsQuerySchema,\n undefined,\n typeof compareVersionsResponseSchema\n >,\n 'GET',\n '/stored/agents/:agentId/versions/compare'\n> = createRoute({\n method: 'GET',\n path: '/stored/agents/:agentId/versions/compare',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: agentVersionPathParams,\n queryParamSchema: compareVersionsQuerySchema,\n responseSchema: compareVersionsResponseSchema,\n summary: 'Compare agent versions',\n description: 'Compares two versions and returns the differences between them',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, from, to, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n const agent = await agentsStore.getById(agentId);\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n // Get both versions\n const fromVersion = await agentsStore.getVersion(from);\n if (!fromVersion) {\n throw new HTTPException(404, { message: `Version with id ${from} not found` });\n }\n if (fromVersion.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${from} not found for agent ${agentId}` });\n }\n\n const toVersion = await agentsStore.getVersion(to);\n if (!toVersion) {\n throw new HTTPException(404, { message: `Version with id ${to} not found` });\n }\n if (toVersion.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${to} not found for agent ${agentId}` });\n }\n\n // Extract config fields from both versions (top-level, no .snapshot)\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 // Compute diffs on the config fields\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 agent versions');\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;AAoCA,MAAM,yBAAyB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CAC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,YAAY,SACxB,MAAM,IAAIA,uBAAAA,cAAc,KAAK,EAAE,SAAS,mBAAmB,GAAG,uBAAuB,UAAU,CAAC;GAgBlG,OAAO;IACL,OAHYiB,wCAAAA,oBAVKZ,wCAAAA,yBACjB,aACA,sBAQyC,GAN1BA,wCAAAA,yBACf,WACA,sBAImD,CAG/C;IACJ;IACA;GACF;EACF,SAAS,OAAO;GACd,OAAOH,8BAAAA,YAAY,OAAO,gCAAgC;EAC5D;CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"agent-versions.cjs","names":["createRoute","agentVersionPathParams","listVersionsQuerySchema","listVersionsResponseSchema","HTTPException","getStoredResourceScope","handleError","createVersionBodySchema","createVersionResponseSchema","extractConfigFromVersion","calculateChangedFields","createVersionWithRetry","enforceRetentionLimit","versionIdPathParams","getVersionResponseSchema","activateVersionResponseSchema","validateAgentInstructionReferences","restoreVersionResponseSchema","deleteVersionResponseSchema","compareVersionsQuerySchema","compareVersionsResponseSchema","computeVersionDiffs"],"sources":["../../../src/server/handlers/agent-versions.ts"],"sourcesContent":["import type { z } from 'zod/v4';\n\nimport { HTTPException } from '../http-exception';\nimport {\n agentVersionPathParams,\n versionIdPathParams,\n listVersionsQuerySchema,\n createVersionBodySchema,\n compareVersionsQuerySchema,\n listVersionsResponseSchema,\n getVersionResponseSchema,\n createVersionResponseSchema,\n activateVersionResponseSchema,\n restoreVersionResponseSchema,\n deleteVersionResponseSchema,\n compareVersionsResponseSchema,\n} from '../schemas/agent-versions';\nimport type { ServerRoute, RouteSchemas, InferParams } from '../server-adapter/routes';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { assertStoredResourceScope, getStoredResourceScope } from '../utils';\n\nimport { handleError } from './error';\nimport { validateAgentInstructionReferences } from './validate-agent-instructions';\nimport {\n extractConfigFromVersion,\n calculateChangedFields,\n computeVersionDiffs,\n createVersionWithRetry,\n enforceRetentionLimit,\n} from './version-helpers';\nimport type { VersionedStoreInterface } from './version-helpers';\n\n/**\n * The config field names that live on version rows (StorageAgentSnapshotType fields).\n * Used to extract config from a version record for comparison and restoration.\n */\nconst SNAPSHOT_CONFIG_FIELDS = [\n 'name',\n 'description',\n 'instructions',\n 'model',\n 'tools',\n 'defaultOptions',\n 'workflows',\n 'agents',\n 'integrationTools',\n 'inputProcessors',\n 'outputProcessors',\n 'memory',\n 'scorers',\n 'requestContextSchema',\n 'mcpClients',\n] as const;\n\n// ============================================================================\n// Route Definitions\n// ============================================================================\n\n/**\n * GET /stored/agents/:agentId/versions - List all versions for an agent\n */\nexport const LIST_AGENT_VERSIONS_ROUTE = createRoute({\n method: 'GET',\n path: '/stored/agents/:agentId/versions',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: agentVersionPathParams,\n queryParamSchema: listVersionsQuerySchema,\n responseSchema: listVersionsResponseSchema,\n summary: 'List agent versions',\n description: 'Returns a paginated list of all versions for a stored agent',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, page, perPage, orderBy, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n // Verify agent exists in code or storage\n const storedAgent = await agentsStore.getById(agentId);\n let codeAgentExists = false;\n try {\n mastra.getAgentById(agentId);\n codeAgentExists = true;\n } catch {\n // Agent not registered in code\n }\n\n if (!storedAgent && !codeAgentExists) {\n throw new HTTPException(404, { message: `Agent with id ${agentId} not found` });\n }\n assertStoredResourceScope(storedAgent, await getStoredResourceScope(mastra, requestContext));\n\n const result = await agentsStore.listVersions({\n agentId,\n page,\n perPage,\n orderBy,\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error listing agent versions');\n }\n },\n});\n\n/**\n * POST /stored/agents/:agentId/versions - Create a new version snapshot\n */\nexport const CREATE_AGENT_VERSION_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/agents/:agentId/versions',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: agentVersionPathParams,\n bodySchema: createVersionBodySchema,\n responseSchema: createVersionResponseSchema,\n summary: 'Create agent version',\n description: 'Creates a new version snapshot of the current agent configuration',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, changeMessage, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n // Get the current agent to find its active version\n const agent = await agentsStore.getById(agentId);\n if (!agent) {\n throw new HTTPException(404, { message: `Agent with id ${agentId} not found` });\n }\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n // Get the current active version to snapshot its config\n let currentConfig: Record<string, unknown> = {};\n if (agent.activeVersionId) {\n const activeVersion = await agentsStore.getVersion(agent.activeVersionId);\n if (activeVersion) {\n currentConfig = extractConfigFromVersion(\n activeVersion as unknown as Record<string, unknown>,\n SNAPSHOT_CONFIG_FIELDS,\n );\n }\n }\n\n // Get the latest version to calculate changed fields\n const latestVersion = await agentsStore.getLatestVersion(agentId);\n\n // If no activeVersionId, fall back to latest version config\n if (!agent.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 // Create the new version with retry logic to handle race conditions\n // Config fields are passed top-level\n const { versionId } = await createVersionWithRetry(\n agentsStore as unknown as VersionedStoreInterface,\n agentId,\n 'agentId',\n currentConfig,\n changedFields,\n { changeMessage },\n );\n\n // Get the created version to return\n const version = await agentsStore.getVersion(versionId);\n if (!version) {\n throw new HTTPException(500, { message: 'Failed to retrieve created version' });\n }\n\n // Enforce retention limit - delete oldest versions if we exceed the max\n await enforceRetentionLimit(\n agentsStore as unknown as VersionedStoreInterface,\n agentId,\n 'agentId',\n agent.activeVersionId,\n );\n\n return version;\n } catch (error) {\n return handleError(error, 'Error creating agent version');\n }\n },\n});\n\n/**\n * GET /stored/agents/:agentId/versions/:versionId - Get a specific version\n */\nexport const GET_AGENT_VERSION_ROUTE = createRoute({\n method: 'GET',\n path: '/stored/agents/:agentId/versions/:versionId',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: versionIdPathParams,\n responseSchema: getVersionResponseSchema,\n summary: 'Get agent version',\n description: 'Returns a specific version of an agent by its version ID',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, versionId, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n const version = await agentsStore.getVersion(versionId);\n\n if (!version) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n\n // Verify the version belongs to the specified agent\n if (version.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found for agent ${agentId}` });\n }\n const agent = await agentsStore.getById(agentId);\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n return version;\n } catch (error) {\n return handleError(error, 'Error getting agent version');\n }\n },\n});\n\n/**\n * POST /stored/agents/:agentId/versions/:versionId/activate - Set a version as active\n */\nexport const ACTIVATE_AGENT_VERSION_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/agents/:agentId/versions/:versionId/activate',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: versionIdPathParams,\n responseSchema: activateVersionResponseSchema,\n summary: 'Activate agent version',\n description: 'Sets a specific version as the active version for the agent',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, versionId, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n // Verify agent exists\n const agent = await agentsStore.getById(agentId);\n if (!agent) {\n throw new HTTPException(404, { message: `Agent with id ${agentId} not found` });\n }\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n // Verify version exists and belongs to this agent\n const version = await agentsStore.getVersion(versionId);\n if (!version) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n if (version.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found for agent ${agentId}` });\n }\n\n await validateAgentInstructionReferences({\n instructions: version.instructions,\n mastra,\n requestContext,\n });\n\n // Update the agent's activeVersionId AND status to 'published'\n await agentsStore.update({\n id: agentId,\n activeVersionId: versionId,\n status: 'published',\n });\n\n // Clear the editor cache so subsequent requests see the new active version\n mastra.getEditor()?.agent.clearCache(agentId);\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 agent version');\n }\n },\n});\n\n/**\n * POST /stored/agents/:agentId/versions/:versionId/restore - Restore agent to a version\n */\nexport const RESTORE_AGENT_VERSION_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/agents/:agentId/versions/:versionId/restore',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: versionIdPathParams,\n responseSchema: restoreVersionResponseSchema,\n summary: 'Restore agent version',\n description: 'Restores the agent configuration from a version, creating a new version',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, versionId, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n // Verify agent exists\n const agent = await agentsStore.getById(agentId);\n if (!agent) {\n throw new HTTPException(404, { message: `Agent with id ${agentId} not found` });\n }\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n // Get the version to restore\n const versionToRestore = await agentsStore.getVersion(versionId);\n if (!versionToRestore) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n if (versionToRestore.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found for agent ${agentId}` });\n }\n\n // Extract the config fields from the version to restore (top-level, no .snapshot)\n const restoredConfig = extractConfigFromVersion(\n versionToRestore as unknown as Record<string, unknown>,\n SNAPSHOT_CONFIG_FIELDS,\n );\n\n // Update the agent with the config from the version to restore\n await agentsStore.update({\n id: agentId,\n ...restoredConfig,\n });\n\n // Get the latest version to calculate changed fields\n const latestVersion = await agentsStore.getLatestVersion(agentId);\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 // Create a new version with retry logic to handle race conditions\n // Config fields are passed top-level\n const { versionId: newVersionId } = await createVersionWithRetry(\n agentsStore as unknown as VersionedStoreInterface,\n agentId,\n 'agentId',\n restoredConfig,\n changedFields,\n {\n changeMessage: `Restored from version ${versionToRestore.versionNumber}`,\n },\n );\n\n // Do NOT auto-activate the restored version - user must explicitly activate it\n\n // Get the created version to return\n const newVersion = await agentsStore.getVersion(newVersionId);\n if (!newVersion) {\n throw new HTTPException(500, { message: 'Failed to retrieve created version' });\n }\n\n // Enforce retention limit - delete oldest versions if we exceed the max\n // Use the agent's existing activeVersionId\n await enforceRetentionLimit(\n agentsStore as unknown as VersionedStoreInterface,\n agentId,\n 'agentId',\n agent.activeVersionId,\n );\n\n // Clear the editor cache so subsequent requests see the restored config\n mastra.getEditor()?.agent.clearCache(agentId);\n\n return newVersion;\n } catch (error) {\n return handleError(error, 'Error restoring agent version');\n }\n },\n});\n\n/**\n * DELETE /stored/agents/:agentId/versions/:versionId - Delete a version\n */\nexport const DELETE_AGENT_VERSION_ROUTE = createRoute({\n method: 'DELETE',\n path: '/stored/agents/:agentId/versions/:versionId',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: versionIdPathParams,\n responseSchema: deleteVersionResponseSchema,\n summary: 'Delete agent version',\n description: 'Deletes a specific version (cannot delete the active version)',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, versionId, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n // Verify agent exists\n const agent = await agentsStore.getById(agentId);\n if (!agent) {\n throw new HTTPException(404, { message: `Agent with id ${agentId} not found` });\n }\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n // Verify version exists and belongs to this agent\n const version = await agentsStore.getVersion(versionId);\n if (!version) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n if (version.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found for agent ${agentId}` });\n }\n\n // Check if this is the active version\n if (agent.activeVersionId === versionId) {\n throw new HTTPException(400, {\n message: 'Cannot delete the active version. Activate a different version first.',\n });\n }\n\n await agentsStore.deleteVersion(versionId);\n\n // Clear the editor cache in case the deleted version affected resolution\n mastra.getEditor()?.agent.clearCache(agentId);\n\n return {\n success: true,\n message: `Version ${version.versionNumber} deleted successfully`,\n };\n } catch (error) {\n return handleError(error, 'Error deleting agent version');\n }\n },\n});\n\n/**\n * GET /stored/agents/:agentId/versions/compare - Compare two versions\n */\nexport const COMPARE_AGENT_VERSIONS_ROUTE: ServerRoute<\n InferParams<typeof agentVersionPathParams, typeof compareVersionsQuerySchema, undefined>,\n z.infer<typeof compareVersionsResponseSchema>,\n 'json',\n RouteSchemas<\n typeof agentVersionPathParams,\n typeof compareVersionsQuerySchema,\n undefined,\n typeof compareVersionsResponseSchema\n >,\n 'GET',\n '/stored/agents/:agentId/versions/compare'\n> = createRoute({\n method: 'GET',\n path: '/stored/agents/:agentId/versions/compare',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: agentVersionPathParams,\n queryParamSchema: compareVersionsQuerySchema,\n responseSchema: compareVersionsResponseSchema,\n summary: 'Compare agent versions',\n description: 'Compares two versions and returns the differences between them',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, from, to, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n const agent = await agentsStore.getById(agentId);\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n // Get both versions\n const fromVersion = await agentsStore.getVersion(from);\n if (!fromVersion) {\n throw new HTTPException(404, { message: `Version with id ${from} not found` });\n }\n if (fromVersion.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${from} not found for agent ${agentId}` });\n }\n\n const toVersion = await agentsStore.getVersion(to);\n if (!toVersion) {\n throw new HTTPException(404, { message: `Version with id ${to} not found` });\n }\n if (toVersion.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${to} not found for agent ${agentId}` });\n }\n\n // Extract config fields from both versions (top-level, no .snapshot)\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 // Compute diffs on the config fields\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 agent versions');\n }\n },\n});\n"],"mappings":";;;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AAmB,KAAK,uBAAuB,UAAU,CAAC;GAGpG,MAAM,YAAY,MAAM,YAAY,WAAW,EAAE;GACjD,IAAI,CAAC,WACH,MAAM,IAAIA,uBAAAA,cAAc,KAAK,EAAE,SAAS,mBAAmB,GAAG,YAAY,CAAC;GAE7E,IAAI,UAAU,YAAY,SACxB,MAAM,IAAIA,uBAAAA,cAAc,KAAK,EAAE,SAAS,mBAAmB,GAAG,uBAAuB,UAAU,CAAC;GAIlG,MAAM,aAAaK,wCAAAA,yBACjB,aACA,sBACF;GACA,MAAM,WAAWA,wCAAAA,yBACf,WACA,sBACF;GAKA,OAAO;IACL,OAHYY,wCAAAA,oBAAoB,YAAY,QAGxC;IACJ;IACA;GACF;EACF,SAAS,OAAO;GACd,OAAOf,8BAAAA,YAAY,OAAO,gCAAgC;EAC5D;CACF;AACF,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as HTTPException } from "../../http-exception-CyfxZB6W.js";
|
|
2
|
-
import { n as createRoute } from "../../route-builder-
|
|
3
|
-
import { i as getStoredResourceScope, n as assertStoredResourceScope } from "../../utils-
|
|
2
|
+
import { n as createRoute } from "../../route-builder-CjkWxv4E.js";
|
|
3
|
+
import { i as getStoredResourceScope, n as assertStoredResourceScope } from "../../utils-aoLN3Wfi.js";
|
|
4
4
|
import { handleError } from "./error.js";
|
|
5
5
|
import { a as createVersionBodySchema, n as compareVersionsQuerySchema, o as deleteVersionResponseSchema, s as listVersionsQuerySchema, t as activateVersionResponseSchema } from "../../version-common-4xFzvCS5.js";
|
|
6
6
|
import { a as getVersionResponseSchema, c as versionIdPathParams, i as createVersionResponseSchema, o as listVersionsResponseSchema, r as compareVersionsResponseSchema, s as restoreVersionResponseSchema, t as agentVersionPathParams } from "../../agent-versions-W600H1ME.js";
|
|
@@ -97,7 +97,8 @@ const CREATE_AGENT_VERSION_ROUTE = createRoute({
|
|
|
97
97
|
}
|
|
98
98
|
const latestVersion = await agentsStore.getLatestVersion(agentId);
|
|
99
99
|
if (!agent.activeVersionId && latestVersion) currentConfig = extractConfigFromVersion(latestVersion, SNAPSHOT_CONFIG_FIELDS);
|
|
100
|
-
const
|
|
100
|
+
const previousConfig = latestVersion ? extractConfigFromVersion(latestVersion, SNAPSHOT_CONFIG_FIELDS) : null;
|
|
101
|
+
const changedFields = calculateChangedFields(previousConfig, currentConfig);
|
|
101
102
|
const { versionId } = await createVersionWithRetry(agentsStore, agentId, "agentId", currentConfig, changedFields, { changeMessage });
|
|
102
103
|
const version = await agentsStore.getVersion(versionId);
|
|
103
104
|
if (!version) throw new HTTPException(500, { message: "Failed to retrieve created version" });
|
|
@@ -130,7 +131,8 @@ const GET_AGENT_VERSION_ROUTE = createRoute({
|
|
|
130
131
|
const version = await agentsStore.getVersion(versionId);
|
|
131
132
|
if (!version) throw new HTTPException(404, { message: `Version with id ${versionId} not found` });
|
|
132
133
|
if (version.agentId !== agentId) throw new HTTPException(404, { message: `Version with id ${versionId} not found for agent ${agentId}` });
|
|
133
|
-
|
|
134
|
+
const agent = await agentsStore.getById(agentId);
|
|
135
|
+
assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));
|
|
134
136
|
return version;
|
|
135
137
|
} catch (error) {
|
|
136
138
|
return handleError(error, "Error getting agent version");
|
|
@@ -214,7 +216,9 @@ const RESTORE_AGENT_VERSION_ROUTE = createRoute({
|
|
|
214
216
|
...restoredConfig
|
|
215
217
|
});
|
|
216
218
|
const latestVersion = await agentsStore.getLatestVersion(agentId);
|
|
217
|
-
const
|
|
219
|
+
const previousConfig = latestVersion ? extractConfigFromVersion(latestVersion, SNAPSHOT_CONFIG_FIELDS) : null;
|
|
220
|
+
const changedFields = calculateChangedFields(previousConfig, restoredConfig);
|
|
221
|
+
const { versionId: newVersionId } = await createVersionWithRetry(agentsStore, agentId, "agentId", restoredConfig, changedFields, { changeMessage: `Restored from version ${versionToRestore.versionNumber}` });
|
|
218
222
|
const newVersion = await agentsStore.getVersion(newVersionId);
|
|
219
223
|
if (!newVersion) throw new HTTPException(500, { message: "Failed to retrieve created version" });
|
|
220
224
|
await enforceRetentionLimit(agentsStore, agentId, "agentId", agent.activeVersionId);
|
|
@@ -282,15 +286,18 @@ const COMPARE_AGENT_VERSIONS_ROUTE = createRoute({
|
|
|
282
286
|
if (!storage) throw new HTTPException(500, { message: "Storage is not configured" });
|
|
283
287
|
const agentsStore = await storage.getStore("agents");
|
|
284
288
|
if (!agentsStore) throw new HTTPException(500, { message: "Agents storage domain is not available" });
|
|
285
|
-
|
|
289
|
+
const agent = await agentsStore.getById(agentId);
|
|
290
|
+
assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));
|
|
286
291
|
const fromVersion = await agentsStore.getVersion(from);
|
|
287
292
|
if (!fromVersion) throw new HTTPException(404, { message: `Version with id ${from} not found` });
|
|
288
293
|
if (fromVersion.agentId !== agentId) throw new HTTPException(404, { message: `Version with id ${from} not found for agent ${agentId}` });
|
|
289
294
|
const toVersion = await agentsStore.getVersion(to);
|
|
290
295
|
if (!toVersion) throw new HTTPException(404, { message: `Version with id ${to} not found` });
|
|
291
296
|
if (toVersion.agentId !== agentId) throw new HTTPException(404, { message: `Version with id ${to} not found for agent ${agentId}` });
|
|
297
|
+
const fromConfig = extractConfigFromVersion(fromVersion, SNAPSHOT_CONFIG_FIELDS);
|
|
298
|
+
const toConfig = extractConfigFromVersion(toVersion, SNAPSHOT_CONFIG_FIELDS);
|
|
292
299
|
return {
|
|
293
|
-
diffs: computeVersionDiffs(
|
|
300
|
+
diffs: computeVersionDiffs(fromConfig, toConfig),
|
|
294
301
|
fromVersion,
|
|
295
302
|
toVersion
|
|
296
303
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-versions.js","names":[],"sources":["../../../src/server/handlers/agent-versions.ts"],"sourcesContent":["import type { z } from 'zod/v4';\n\nimport { HTTPException } from '../http-exception';\nimport {\n agentVersionPathParams,\n versionIdPathParams,\n listVersionsQuerySchema,\n createVersionBodySchema,\n compareVersionsQuerySchema,\n listVersionsResponseSchema,\n getVersionResponseSchema,\n createVersionResponseSchema,\n activateVersionResponseSchema,\n restoreVersionResponseSchema,\n deleteVersionResponseSchema,\n compareVersionsResponseSchema,\n} from '../schemas/agent-versions';\nimport type { ServerRoute, RouteSchemas, InferParams } from '../server-adapter/routes';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { assertStoredResourceScope, getStoredResourceScope } from '../utils';\n\nimport { handleError } from './error';\nimport { validateAgentInstructionReferences } from './validate-agent-instructions';\nimport {\n extractConfigFromVersion,\n calculateChangedFields,\n computeVersionDiffs,\n createVersionWithRetry,\n enforceRetentionLimit,\n} from './version-helpers';\nimport type { VersionedStoreInterface } from './version-helpers';\n\n/**\n * The config field names that live on version rows (StorageAgentSnapshotType fields).\n * Used to extract config from a version record for comparison and restoration.\n */\nconst SNAPSHOT_CONFIG_FIELDS = [\n 'name',\n 'description',\n 'instructions',\n 'model',\n 'tools',\n 'defaultOptions',\n 'workflows',\n 'agents',\n 'integrationTools',\n 'inputProcessors',\n 'outputProcessors',\n 'memory',\n 'scorers',\n 'requestContextSchema',\n 'mcpClients',\n] as const;\n\n// ============================================================================\n// Route Definitions\n// ============================================================================\n\n/**\n * GET /stored/agents/:agentId/versions - List all versions for an agent\n */\nexport const LIST_AGENT_VERSIONS_ROUTE = createRoute({\n method: 'GET',\n path: '/stored/agents/:agentId/versions',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: agentVersionPathParams,\n queryParamSchema: listVersionsQuerySchema,\n responseSchema: listVersionsResponseSchema,\n summary: 'List agent versions',\n description: 'Returns a paginated list of all versions for a stored agent',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, page, perPage, orderBy, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n // Verify agent exists in code or storage\n const storedAgent = await agentsStore.getById(agentId);\n let codeAgentExists = false;\n try {\n mastra.getAgentById(agentId);\n codeAgentExists = true;\n } catch {\n // Agent not registered in code\n }\n\n if (!storedAgent && !codeAgentExists) {\n throw new HTTPException(404, { message: `Agent with id ${agentId} not found` });\n }\n assertStoredResourceScope(storedAgent, await getStoredResourceScope(mastra, requestContext));\n\n const result = await agentsStore.listVersions({\n agentId,\n page,\n perPage,\n orderBy,\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error listing agent versions');\n }\n },\n});\n\n/**\n * POST /stored/agents/:agentId/versions - Create a new version snapshot\n */\nexport const CREATE_AGENT_VERSION_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/agents/:agentId/versions',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: agentVersionPathParams,\n bodySchema: createVersionBodySchema,\n responseSchema: createVersionResponseSchema,\n summary: 'Create agent version',\n description: 'Creates a new version snapshot of the current agent configuration',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, changeMessage, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n // Get the current agent to find its active version\n const agent = await agentsStore.getById(agentId);\n if (!agent) {\n throw new HTTPException(404, { message: `Agent with id ${agentId} not found` });\n }\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n // Get the current active version to snapshot its config\n let currentConfig: Record<string, unknown> = {};\n if (agent.activeVersionId) {\n const activeVersion = await agentsStore.getVersion(agent.activeVersionId);\n if (activeVersion) {\n currentConfig = extractConfigFromVersion(\n activeVersion as unknown as Record<string, unknown>,\n SNAPSHOT_CONFIG_FIELDS,\n );\n }\n }\n\n // Get the latest version to calculate changed fields\n const latestVersion = await agentsStore.getLatestVersion(agentId);\n\n // If no activeVersionId, fall back to latest version config\n if (!agent.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 // Create the new version with retry logic to handle race conditions\n // Config fields are passed top-level\n const { versionId } = await createVersionWithRetry(\n agentsStore as unknown as VersionedStoreInterface,\n agentId,\n 'agentId',\n currentConfig,\n changedFields,\n { changeMessage },\n );\n\n // Get the created version to return\n const version = await agentsStore.getVersion(versionId);\n if (!version) {\n throw new HTTPException(500, { message: 'Failed to retrieve created version' });\n }\n\n // Enforce retention limit - delete oldest versions if we exceed the max\n await enforceRetentionLimit(\n agentsStore as unknown as VersionedStoreInterface,\n agentId,\n 'agentId',\n agent.activeVersionId,\n );\n\n return version;\n } catch (error) {\n return handleError(error, 'Error creating agent version');\n }\n },\n});\n\n/**\n * GET /stored/agents/:agentId/versions/:versionId - Get a specific version\n */\nexport const GET_AGENT_VERSION_ROUTE = createRoute({\n method: 'GET',\n path: '/stored/agents/:agentId/versions/:versionId',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: versionIdPathParams,\n responseSchema: getVersionResponseSchema,\n summary: 'Get agent version',\n description: 'Returns a specific version of an agent by its version ID',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, versionId, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n const version = await agentsStore.getVersion(versionId);\n\n if (!version) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n\n // Verify the version belongs to the specified agent\n if (version.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found for agent ${agentId}` });\n }\n const agent = await agentsStore.getById(agentId);\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n return version;\n } catch (error) {\n return handleError(error, 'Error getting agent version');\n }\n },\n});\n\n/**\n * POST /stored/agents/:agentId/versions/:versionId/activate - Set a version as active\n */\nexport const ACTIVATE_AGENT_VERSION_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/agents/:agentId/versions/:versionId/activate',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: versionIdPathParams,\n responseSchema: activateVersionResponseSchema,\n summary: 'Activate agent version',\n description: 'Sets a specific version as the active version for the agent',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, versionId, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n // Verify agent exists\n const agent = await agentsStore.getById(agentId);\n if (!agent) {\n throw new HTTPException(404, { message: `Agent with id ${agentId} not found` });\n }\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n // Verify version exists and belongs to this agent\n const version = await agentsStore.getVersion(versionId);\n if (!version) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n if (version.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found for agent ${agentId}` });\n }\n\n await validateAgentInstructionReferences({\n instructions: version.instructions,\n mastra,\n requestContext,\n });\n\n // Update the agent's activeVersionId AND status to 'published'\n await agentsStore.update({\n id: agentId,\n activeVersionId: versionId,\n status: 'published',\n });\n\n // Clear the editor cache so subsequent requests see the new active version\n mastra.getEditor()?.agent.clearCache(agentId);\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 agent version');\n }\n },\n});\n\n/**\n * POST /stored/agents/:agentId/versions/:versionId/restore - Restore agent to a version\n */\nexport const RESTORE_AGENT_VERSION_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/agents/:agentId/versions/:versionId/restore',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: versionIdPathParams,\n responseSchema: restoreVersionResponseSchema,\n summary: 'Restore agent version',\n description: 'Restores the agent configuration from a version, creating a new version',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, versionId, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n // Verify agent exists\n const agent = await agentsStore.getById(agentId);\n if (!agent) {\n throw new HTTPException(404, { message: `Agent with id ${agentId} not found` });\n }\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n // Get the version to restore\n const versionToRestore = await agentsStore.getVersion(versionId);\n if (!versionToRestore) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n if (versionToRestore.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found for agent ${agentId}` });\n }\n\n // Extract the config fields from the version to restore (top-level, no .snapshot)\n const restoredConfig = extractConfigFromVersion(\n versionToRestore as unknown as Record<string, unknown>,\n SNAPSHOT_CONFIG_FIELDS,\n );\n\n // Update the agent with the config from the version to restore\n await agentsStore.update({\n id: agentId,\n ...restoredConfig,\n });\n\n // Get the latest version to calculate changed fields\n const latestVersion = await agentsStore.getLatestVersion(agentId);\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 // Create a new version with retry logic to handle race conditions\n // Config fields are passed top-level\n const { versionId: newVersionId } = await createVersionWithRetry(\n agentsStore as unknown as VersionedStoreInterface,\n agentId,\n 'agentId',\n restoredConfig,\n changedFields,\n {\n changeMessage: `Restored from version ${versionToRestore.versionNumber}`,\n },\n );\n\n // Do NOT auto-activate the restored version - user must explicitly activate it\n\n // Get the created version to return\n const newVersion = await agentsStore.getVersion(newVersionId);\n if (!newVersion) {\n throw new HTTPException(500, { message: 'Failed to retrieve created version' });\n }\n\n // Enforce retention limit - delete oldest versions if we exceed the max\n // Use the agent's existing activeVersionId\n await enforceRetentionLimit(\n agentsStore as unknown as VersionedStoreInterface,\n agentId,\n 'agentId',\n agent.activeVersionId,\n );\n\n // Clear the editor cache so subsequent requests see the restored config\n mastra.getEditor()?.agent.clearCache(agentId);\n\n return newVersion;\n } catch (error) {\n return handleError(error, 'Error restoring agent version');\n }\n },\n});\n\n/**\n * DELETE /stored/agents/:agentId/versions/:versionId - Delete a version\n */\nexport const DELETE_AGENT_VERSION_ROUTE = createRoute({\n method: 'DELETE',\n path: '/stored/agents/:agentId/versions/:versionId',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: versionIdPathParams,\n responseSchema: deleteVersionResponseSchema,\n summary: 'Delete agent version',\n description: 'Deletes a specific version (cannot delete the active version)',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, versionId, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n // Verify agent exists\n const agent = await agentsStore.getById(agentId);\n if (!agent) {\n throw new HTTPException(404, { message: `Agent with id ${agentId} not found` });\n }\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n // Verify version exists and belongs to this agent\n const version = await agentsStore.getVersion(versionId);\n if (!version) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n if (version.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found for agent ${agentId}` });\n }\n\n // Check if this is the active version\n if (agent.activeVersionId === versionId) {\n throw new HTTPException(400, {\n message: 'Cannot delete the active version. Activate a different version first.',\n });\n }\n\n await agentsStore.deleteVersion(versionId);\n\n // Clear the editor cache in case the deleted version affected resolution\n mastra.getEditor()?.agent.clearCache(agentId);\n\n return {\n success: true,\n message: `Version ${version.versionNumber} deleted successfully`,\n };\n } catch (error) {\n return handleError(error, 'Error deleting agent version');\n }\n },\n});\n\n/**\n * GET /stored/agents/:agentId/versions/compare - Compare two versions\n */\nexport const COMPARE_AGENT_VERSIONS_ROUTE: ServerRoute<\n InferParams<typeof agentVersionPathParams, typeof compareVersionsQuerySchema, undefined>,\n z.infer<typeof compareVersionsResponseSchema>,\n 'json',\n RouteSchemas<\n typeof agentVersionPathParams,\n typeof compareVersionsQuerySchema,\n undefined,\n typeof compareVersionsResponseSchema\n >,\n 'GET',\n '/stored/agents/:agentId/versions/compare'\n> = createRoute({\n method: 'GET',\n path: '/stored/agents/:agentId/versions/compare',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: agentVersionPathParams,\n queryParamSchema: compareVersionsQuerySchema,\n responseSchema: compareVersionsResponseSchema,\n summary: 'Compare agent versions',\n description: 'Compares two versions and returns the differences between them',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, from, to, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n const agent = await agentsStore.getById(agentId);\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n // Get both versions\n const fromVersion = await agentsStore.getVersion(from);\n if (!fromVersion) {\n throw new HTTPException(404, { message: `Version with id ${from} not found` });\n }\n if (fromVersion.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${from} not found for agent ${agentId}` });\n }\n\n const toVersion = await agentsStore.getVersion(to);\n if (!toVersion) {\n throw new HTTPException(404, { message: `Version with id ${to} not found` });\n }\n if (toVersion.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${to} not found for agent ${agentId}` });\n }\n\n // Extract config fields from both versions (top-level, no .snapshot)\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 // Compute diffs on the config fields\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 agent versions');\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;AAoCA,MAAM,yBAAyB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;AASA,MAAa,4BAA4B,YAAY;CACnD,QAAQ;CACR,MAAM;CACN,cAAc;CACd,cAAc;CACd,iBAAiB;CACjB,kBAAkB;CAClB,gBAAgB;CAChB,SAAS;CACT,aAAa;CACb,MAAM,CAAC,gBAAgB;CACvB,SAAS,OAAO,EAAE,QAAQ,SAAS,MAAM,SAAS,SAAS,qBAAqB;EAC9E,IAAI;GACF,MAAM,UAAU,OAAO,WAAW;GAElC,IAAI,CAAC,SACH,MAAM,IAAI,cAAc,KAAK,EAAE,SAAS,4BAA4B,CAAC;GAGvE,MAAM,cAAc,MAAM,QAAQ,SAAS,QAAQ;GACnD,IAAI,CAAC,aACH,MAAM,IAAI,cAAc,KAAK,EAAE,SAAS,yCAAyC,CAAC;GAIpF,MAAM,cAAc,MAAM,YAAY,QAAQ,OAAO;GACrD,IAAI,kBAAkB;GACtB,IAAI;IACF,OAAO,aAAa,OAAO;IAC3B,kBAAkB;GACpB,QAAQ,CAER;GAEA,IAAI,CAAC,eAAe,CAAC,iBACnB,MAAM,IAAI,cAAc,KAAK,EAAE,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","names":[],"sources":["../../../src/server/handlers/agent-versions.ts"],"sourcesContent":["import type { z } from 'zod/v4';\n\nimport { HTTPException } from '../http-exception';\nimport {\n agentVersionPathParams,\n versionIdPathParams,\n listVersionsQuerySchema,\n createVersionBodySchema,\n compareVersionsQuerySchema,\n listVersionsResponseSchema,\n getVersionResponseSchema,\n createVersionResponseSchema,\n activateVersionResponseSchema,\n restoreVersionResponseSchema,\n deleteVersionResponseSchema,\n compareVersionsResponseSchema,\n} from '../schemas/agent-versions';\nimport type { ServerRoute, RouteSchemas, InferParams } from '../server-adapter/routes';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { assertStoredResourceScope, getStoredResourceScope } from '../utils';\n\nimport { handleError } from './error';\nimport { validateAgentInstructionReferences } from './validate-agent-instructions';\nimport {\n extractConfigFromVersion,\n calculateChangedFields,\n computeVersionDiffs,\n createVersionWithRetry,\n enforceRetentionLimit,\n} from './version-helpers';\nimport type { VersionedStoreInterface } from './version-helpers';\n\n/**\n * The config field names that live on version rows (StorageAgentSnapshotType fields).\n * Used to extract config from a version record for comparison and restoration.\n */\nconst SNAPSHOT_CONFIG_FIELDS = [\n 'name',\n 'description',\n 'instructions',\n 'model',\n 'tools',\n 'defaultOptions',\n 'workflows',\n 'agents',\n 'integrationTools',\n 'inputProcessors',\n 'outputProcessors',\n 'memory',\n 'scorers',\n 'requestContextSchema',\n 'mcpClients',\n] as const;\n\n// ============================================================================\n// Route Definitions\n// ============================================================================\n\n/**\n * GET /stored/agents/:agentId/versions - List all versions for an agent\n */\nexport const LIST_AGENT_VERSIONS_ROUTE = createRoute({\n method: 'GET',\n path: '/stored/agents/:agentId/versions',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: agentVersionPathParams,\n queryParamSchema: listVersionsQuerySchema,\n responseSchema: listVersionsResponseSchema,\n summary: 'List agent versions',\n description: 'Returns a paginated list of all versions for a stored agent',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, page, perPage, orderBy, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n // Verify agent exists in code or storage\n const storedAgent = await agentsStore.getById(agentId);\n let codeAgentExists = false;\n try {\n mastra.getAgentById(agentId);\n codeAgentExists = true;\n } catch {\n // Agent not registered in code\n }\n\n if (!storedAgent && !codeAgentExists) {\n throw new HTTPException(404, { message: `Agent with id ${agentId} not found` });\n }\n assertStoredResourceScope(storedAgent, await getStoredResourceScope(mastra, requestContext));\n\n const result = await agentsStore.listVersions({\n agentId,\n page,\n perPage,\n orderBy,\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error listing agent versions');\n }\n },\n});\n\n/**\n * POST /stored/agents/:agentId/versions - Create a new version snapshot\n */\nexport const CREATE_AGENT_VERSION_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/agents/:agentId/versions',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: agentVersionPathParams,\n bodySchema: createVersionBodySchema,\n responseSchema: createVersionResponseSchema,\n summary: 'Create agent version',\n description: 'Creates a new version snapshot of the current agent configuration',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, changeMessage, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n // Get the current agent to find its active version\n const agent = await agentsStore.getById(agentId);\n if (!agent) {\n throw new HTTPException(404, { message: `Agent with id ${agentId} not found` });\n }\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n // Get the current active version to snapshot its config\n let currentConfig: Record<string, unknown> = {};\n if (agent.activeVersionId) {\n const activeVersion = await agentsStore.getVersion(agent.activeVersionId);\n if (activeVersion) {\n currentConfig = extractConfigFromVersion(\n activeVersion as unknown as Record<string, unknown>,\n SNAPSHOT_CONFIG_FIELDS,\n );\n }\n }\n\n // Get the latest version to calculate changed fields\n const latestVersion = await agentsStore.getLatestVersion(agentId);\n\n // If no activeVersionId, fall back to latest version config\n if (!agent.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 // Create the new version with retry logic to handle race conditions\n // Config fields are passed top-level\n const { versionId } = await createVersionWithRetry(\n agentsStore as unknown as VersionedStoreInterface,\n agentId,\n 'agentId',\n currentConfig,\n changedFields,\n { changeMessage },\n );\n\n // Get the created version to return\n const version = await agentsStore.getVersion(versionId);\n if (!version) {\n throw new HTTPException(500, { message: 'Failed to retrieve created version' });\n }\n\n // Enforce retention limit - delete oldest versions if we exceed the max\n await enforceRetentionLimit(\n agentsStore as unknown as VersionedStoreInterface,\n agentId,\n 'agentId',\n agent.activeVersionId,\n );\n\n return version;\n } catch (error) {\n return handleError(error, 'Error creating agent version');\n }\n },\n});\n\n/**\n * GET /stored/agents/:agentId/versions/:versionId - Get a specific version\n */\nexport const GET_AGENT_VERSION_ROUTE = createRoute({\n method: 'GET',\n path: '/stored/agents/:agentId/versions/:versionId',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: versionIdPathParams,\n responseSchema: getVersionResponseSchema,\n summary: 'Get agent version',\n description: 'Returns a specific version of an agent by its version ID',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, versionId, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n const version = await agentsStore.getVersion(versionId);\n\n if (!version) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n\n // Verify the version belongs to the specified agent\n if (version.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found for agent ${agentId}` });\n }\n const agent = await agentsStore.getById(agentId);\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n return version;\n } catch (error) {\n return handleError(error, 'Error getting agent version');\n }\n },\n});\n\n/**\n * POST /stored/agents/:agentId/versions/:versionId/activate - Set a version as active\n */\nexport const ACTIVATE_AGENT_VERSION_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/agents/:agentId/versions/:versionId/activate',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: versionIdPathParams,\n responseSchema: activateVersionResponseSchema,\n summary: 'Activate agent version',\n description: 'Sets a specific version as the active version for the agent',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, versionId, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n // Verify agent exists\n const agent = await agentsStore.getById(agentId);\n if (!agent) {\n throw new HTTPException(404, { message: `Agent with id ${agentId} not found` });\n }\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n // Verify version exists and belongs to this agent\n const version = await agentsStore.getVersion(versionId);\n if (!version) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n if (version.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found for agent ${agentId}` });\n }\n\n await validateAgentInstructionReferences({\n instructions: version.instructions,\n mastra,\n requestContext,\n });\n\n // Update the agent's activeVersionId AND status to 'published'\n await agentsStore.update({\n id: agentId,\n activeVersionId: versionId,\n status: 'published',\n });\n\n // Clear the editor cache so subsequent requests see the new active version\n mastra.getEditor()?.agent.clearCache(agentId);\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 agent version');\n }\n },\n});\n\n/**\n * POST /stored/agents/:agentId/versions/:versionId/restore - Restore agent to a version\n */\nexport const RESTORE_AGENT_VERSION_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/agents/:agentId/versions/:versionId/restore',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: versionIdPathParams,\n responseSchema: restoreVersionResponseSchema,\n summary: 'Restore agent version',\n description: 'Restores the agent configuration from a version, creating a new version',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, versionId, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n // Verify agent exists\n const agent = await agentsStore.getById(agentId);\n if (!agent) {\n throw new HTTPException(404, { message: `Agent with id ${agentId} not found` });\n }\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n // Get the version to restore\n const versionToRestore = await agentsStore.getVersion(versionId);\n if (!versionToRestore) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n if (versionToRestore.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found for agent ${agentId}` });\n }\n\n // Extract the config fields from the version to restore (top-level, no .snapshot)\n const restoredConfig = extractConfigFromVersion(\n versionToRestore as unknown as Record<string, unknown>,\n SNAPSHOT_CONFIG_FIELDS,\n );\n\n // Update the agent with the config from the version to restore\n await agentsStore.update({\n id: agentId,\n ...restoredConfig,\n });\n\n // Get the latest version to calculate changed fields\n const latestVersion = await agentsStore.getLatestVersion(agentId);\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 // Create a new version with retry logic to handle race conditions\n // Config fields are passed top-level\n const { versionId: newVersionId } = await createVersionWithRetry(\n agentsStore as unknown as VersionedStoreInterface,\n agentId,\n 'agentId',\n restoredConfig,\n changedFields,\n {\n changeMessage: `Restored from version ${versionToRestore.versionNumber}`,\n },\n );\n\n // Do NOT auto-activate the restored version - user must explicitly activate it\n\n // Get the created version to return\n const newVersion = await agentsStore.getVersion(newVersionId);\n if (!newVersion) {\n throw new HTTPException(500, { message: 'Failed to retrieve created version' });\n }\n\n // Enforce retention limit - delete oldest versions if we exceed the max\n // Use the agent's existing activeVersionId\n await enforceRetentionLimit(\n agentsStore as unknown as VersionedStoreInterface,\n agentId,\n 'agentId',\n agent.activeVersionId,\n );\n\n // Clear the editor cache so subsequent requests see the restored config\n mastra.getEditor()?.agent.clearCache(agentId);\n\n return newVersion;\n } catch (error) {\n return handleError(error, 'Error restoring agent version');\n }\n },\n});\n\n/**\n * DELETE /stored/agents/:agentId/versions/:versionId - Delete a version\n */\nexport const DELETE_AGENT_VERSION_ROUTE = createRoute({\n method: 'DELETE',\n path: '/stored/agents/:agentId/versions/:versionId',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: versionIdPathParams,\n responseSchema: deleteVersionResponseSchema,\n summary: 'Delete agent version',\n description: 'Deletes a specific version (cannot delete the active version)',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, versionId, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n\n // Verify agent exists\n const agent = await agentsStore.getById(agentId);\n if (!agent) {\n throw new HTTPException(404, { message: `Agent with id ${agentId} not found` });\n }\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n // Verify version exists and belongs to this agent\n const version = await agentsStore.getVersion(versionId);\n if (!version) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n }\n if (version.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${versionId} not found for agent ${agentId}` });\n }\n\n // Check if this is the active version\n if (agent.activeVersionId === versionId) {\n throw new HTTPException(400, {\n message: 'Cannot delete the active version. Activate a different version first.',\n });\n }\n\n await agentsStore.deleteVersion(versionId);\n\n // Clear the editor cache in case the deleted version affected resolution\n mastra.getEditor()?.agent.clearCache(agentId);\n\n return {\n success: true,\n message: `Version ${version.versionNumber} deleted successfully`,\n };\n } catch (error) {\n return handleError(error, 'Error deleting agent version');\n }\n },\n});\n\n/**\n * GET /stored/agents/:agentId/versions/compare - Compare two versions\n */\nexport const COMPARE_AGENT_VERSIONS_ROUTE: ServerRoute<\n InferParams<typeof agentVersionPathParams, typeof compareVersionsQuerySchema, undefined>,\n z.infer<typeof compareVersionsResponseSchema>,\n 'json',\n RouteSchemas<\n typeof agentVersionPathParams,\n typeof compareVersionsQuerySchema,\n undefined,\n typeof compareVersionsResponseSchema\n >,\n 'GET',\n '/stored/agents/:agentId/versions/compare'\n> = createRoute({\n method: 'GET',\n path: '/stored/agents/:agentId/versions/compare',\n requiresAuth: true,\n responseType: 'json',\n pathParamSchema: agentVersionPathParams,\n queryParamSchema: compareVersionsQuerySchema,\n responseSchema: compareVersionsResponseSchema,\n summary: 'Compare agent versions',\n description: 'Compares two versions and returns the differences between them',\n tags: ['Agent Versions'],\n handler: async ({ mastra, agentId, from, to, 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 agentsStore = await storage.getStore('agents');\n if (!agentsStore) {\n throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n }\n const agent = await agentsStore.getById(agentId);\n assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n // Get both versions\n const fromVersion = await agentsStore.getVersion(from);\n if (!fromVersion) {\n throw new HTTPException(404, { message: `Version with id ${from} not found` });\n }\n if (fromVersion.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${from} not found for agent ${agentId}` });\n }\n\n const toVersion = await agentsStore.getVersion(to);\n if (!toVersion) {\n throw new HTTPException(404, { message: `Version with id ${to} not found` });\n }\n if (toVersion.agentId !== agentId) {\n throw new HTTPException(404, { message: `Version with id ${to} not found for agent ${agentId}` });\n }\n\n // Extract config fields from both versions (top-level, no .snapshot)\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 // Compute diffs on the config fields\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 agent versions');\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;AAoCA,MAAM,yBAAyB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;AASA,MAAa,4BAA4B,YAAY;CACnD,QAAQ;CACR,MAAM;CACN,cAAc;CACd,cAAc;CACd,iBAAiB;CACjB,kBAAkB;CAClB,gBAAgB;CAChB,SAAS;CACT,aAAa;CACb,MAAM,CAAC,gBAAgB;CACvB,SAAS,OAAO,EAAE,QAAQ,SAAS,MAAM,SAAS,SAAS,qBAAqB;EAC9E,IAAI;GACF,MAAM,UAAU,OAAO,WAAW;GAElC,IAAI,CAAC,SACH,MAAM,IAAI,cAAc,KAAK,EAAE,SAAS,4BAA4B,CAAC;GAGvE,MAAM,cAAc,MAAM,QAAQ,SAAS,QAAQ;GACnD,IAAI,CAAC,aACH,MAAM,IAAI,cAAc,KAAK,EAAE,SAAS,yCAAyC,CAAC;GAIpF,MAAM,cAAc,MAAM,YAAY,QAAQ,OAA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