@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,1731 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { t as HTTPException } from "../../http-exception-CyfxZB6W.js";
|
|
3
|
-
import { n as createRoute } from "../../route-builder-BfQYtclb.js";
|
|
4
|
-
import { handleError } from "./error.js";
|
|
5
|
-
import { a as getEffectiveThreadId, g as MastraFGAPermissions, i as getEffectiveResourceId, n as enforceThreadAccess, p as validateBody, r as getContextResourceId } from "../../utils-BBJlS81s.js";
|
|
6
|
-
import { A as listThreadsNetworkQuerySchema, B as searchMemoryQuerySchema, C as getThreadByIdResponseSchema, D as listMessagesNetworkQuerySchema, G as updateThreadBodySchema, H as threadIdPathParams, I as optionalAgentIdQuerySchema, J as updateWorkingMemoryResponseSchema, K as updateThreadNetworkQuerySchema, L as saveMessagesBodySchema, M as listThreadsResponseSchema, N as memoryConfigResponseSchema, O as listMessagesQuerySchema, P as memoryStatusResponseSchema, R as saveMessagesNetworkQuerySchema, S as getThreadByIdQuerySchema, T as getWorkingMemoryResponseSchema, U as transferThreadBodySchema, V as searchMemoryResponseSchema, W as transferThreadResponseSchema, _ as getMemoryStatusNetworkQuerySchema, a as cloneThreadResponseSchema, b as getObservationalMemoryResponseSchema, c as deleteMessagesBodySchema, d as deleteMessagesResponseSchema, f as deleteThreadNetworkQuerySchema, g as getMemoryConfigQuerySchema, i as cloneThreadBodySchema, j as listThreadsQuerySchema, k as listMessagesResponseSchema, l as deleteMessagesNetworkQuerySchema, m as deleteThreadResponseSchema, n as awaitBufferStatusBodySchema, o as createThreadBodySchema, p as deleteThreadQuerySchema, q as updateWorkingMemoryBodySchema, r as awaitBufferStatusResponseSchema, s as createThreadNetworkQuerySchema, t as agentIdQuerySchema, u as deleteMessagesQuerySchema, v as getMemoryStatusQuerySchema, w as getWorkingMemoryQuerySchema, x as getThreadByIdNetworkQuerySchema, y as getObservationalMemoryQuerySchema, z as saveMessagesResponseSchema } from "../../memory-B58Q2LgU.js";
|
|
7
|
-
import { getGatewayClient, isGatewayAgentAsync, toLocalMessage, toLocalOMRecord, toLocalThread } from "./gateway-memory-client.js";
|
|
8
|
-
import { Agent } from "@mastra/core/agent";
|
|
9
|
-
import { ErrorCategory, MastraError } from "@mastra/core/error";
|
|
10
|
-
import { generateEmptyFromSchema } from "@mastra/core/utils";
|
|
11
|
-
//#region src/server/handlers/memory.ts
|
|
12
|
-
var memory_exports = /* @__PURE__ */ __exportAll({
|
|
13
|
-
AWAIT_BUFFER_STATUS_ROUTE: () => AWAIT_BUFFER_STATUS_ROUTE,
|
|
14
|
-
CLONE_THREAD_ROUTE: () => CLONE_THREAD_ROUTE,
|
|
15
|
-
CREATE_THREAD_NETWORK_ROUTE: () => CREATE_THREAD_NETWORK_ROUTE,
|
|
16
|
-
CREATE_THREAD_ROUTE: () => CREATE_THREAD_ROUTE,
|
|
17
|
-
DELETE_MESSAGES_NETWORK_ROUTE: () => DELETE_MESSAGES_NETWORK_ROUTE,
|
|
18
|
-
DELETE_MESSAGES_ROUTE: () => DELETE_MESSAGES_ROUTE,
|
|
19
|
-
DELETE_THREAD_NETWORK_ROUTE: () => DELETE_THREAD_NETWORK_ROUTE,
|
|
20
|
-
DELETE_THREAD_ROUTE: () => DELETE_THREAD_ROUTE,
|
|
21
|
-
GET_MEMORY_CONFIG_ROUTE: () => GET_MEMORY_CONFIG_ROUTE,
|
|
22
|
-
GET_MEMORY_STATUS_NETWORK_ROUTE: () => GET_MEMORY_STATUS_NETWORK_ROUTE,
|
|
23
|
-
GET_MEMORY_STATUS_ROUTE: () => GET_MEMORY_STATUS_ROUTE,
|
|
24
|
-
GET_OBSERVATIONAL_MEMORY_ROUTE: () => GET_OBSERVATIONAL_MEMORY_ROUTE,
|
|
25
|
-
GET_THREAD_BY_ID_NETWORK_ROUTE: () => GET_THREAD_BY_ID_NETWORK_ROUTE,
|
|
26
|
-
GET_THREAD_BY_ID_ROUTE: () => GET_THREAD_BY_ID_ROUTE,
|
|
27
|
-
GET_WORKING_MEMORY_ROUTE: () => GET_WORKING_MEMORY_ROUTE,
|
|
28
|
-
LIST_MESSAGES_NETWORK_ROUTE: () => LIST_MESSAGES_NETWORK_ROUTE,
|
|
29
|
-
LIST_MESSAGES_ROUTE: () => LIST_MESSAGES_ROUTE,
|
|
30
|
-
LIST_THREADS_NETWORK_ROUTE: () => LIST_THREADS_NETWORK_ROUTE,
|
|
31
|
-
LIST_THREADS_ROUTE: () => LIST_THREADS_ROUTE,
|
|
32
|
-
SAVE_MESSAGES_NETWORK_ROUTE: () => SAVE_MESSAGES_NETWORK_ROUTE,
|
|
33
|
-
SAVE_MESSAGES_ROUTE: () => SAVE_MESSAGES_ROUTE,
|
|
34
|
-
SEARCH_MEMORY_ROUTE: () => SEARCH_MEMORY_ROUTE,
|
|
35
|
-
TRANSFER_THREAD_ROUTE: () => TRANSFER_THREAD_ROUTE,
|
|
36
|
-
UPDATE_THREAD_NETWORK_ROUTE: () => UPDATE_THREAD_NETWORK_ROUTE,
|
|
37
|
-
UPDATE_THREAD_ROUTE: () => UPDATE_THREAD_ROUTE,
|
|
38
|
-
UPDATE_WORKING_MEMORY_ROUTE: () => UPDATE_WORKING_MEMORY_ROUTE,
|
|
39
|
-
getTextContent: () => getTextContent
|
|
40
|
-
});
|
|
41
|
-
function hasFGAUser(requestContext) {
|
|
42
|
-
const user = requestContext?.get("user");
|
|
43
|
-
return !!user && typeof user === "object";
|
|
44
|
-
}
|
|
45
|
-
function shouldFilterThreadsWithFGA(mastra, requestContext) {
|
|
46
|
-
return !!mastra.getServer?.()?.fga && hasFGAUser(requestContext);
|
|
47
|
-
}
|
|
48
|
-
async function filterAccessibleThreads({ mastra, requestContext, threads }) {
|
|
49
|
-
const fgaProvider = mastra.getServer?.()?.fga;
|
|
50
|
-
if (!fgaProvider || !hasFGAUser(requestContext) || threads.length === 0) return threads;
|
|
51
|
-
return fgaProvider.filterAccessible(requestContext.get("user"), threads, "thread", MastraFGAPermissions.MEMORY_READ);
|
|
52
|
-
}
|
|
53
|
-
function paginateThreads({ threads, page, perPage }) {
|
|
54
|
-
const effectivePage = page ?? 0;
|
|
55
|
-
const effectivePerPage = perPage ?? 100;
|
|
56
|
-
if (effectivePerPage === false) return {
|
|
57
|
-
threads,
|
|
58
|
-
page: effectivePage,
|
|
59
|
-
perPage: false,
|
|
60
|
-
total: threads.length,
|
|
61
|
-
hasMore: false
|
|
62
|
-
};
|
|
63
|
-
const start = effectivePage * effectivePerPage;
|
|
64
|
-
const pagedThreads = threads.slice(start, start + effectivePerPage);
|
|
65
|
-
return {
|
|
66
|
-
threads: pagedThreads,
|
|
67
|
-
page: effectivePage,
|
|
68
|
-
perPage: effectivePerPage,
|
|
69
|
-
total: threads.length,
|
|
70
|
-
hasMore: start + pagedThreads.length < threads.length
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
async function enforceDeleteMessagesThreadAccess({ mastra, requestContext, memoryStore, messageIds, effectiveResourceId }) {
|
|
74
|
-
const { messages } = await memoryStore.listMessagesById({ messageIds });
|
|
75
|
-
const threadIds = [...new Set(messages.map((m) => m.threadId).filter(Boolean))];
|
|
76
|
-
if (messages.some((message) => !message.threadId)) throw new HTTPException(403, { message: "Access denied: unable to verify message thread access" });
|
|
77
|
-
for (const threadId of threadIds) {
|
|
78
|
-
const thread = await memoryStore.getThreadById({ threadId });
|
|
79
|
-
if (!thread) throw new HTTPException(403, { message: "Access denied: unable to verify message thread access" });
|
|
80
|
-
await enforceThreadAccess({
|
|
81
|
-
mastra,
|
|
82
|
-
requestContext,
|
|
83
|
-
threadId,
|
|
84
|
-
thread,
|
|
85
|
-
effectiveResourceId,
|
|
86
|
-
permission: MastraFGAPermissions.MEMORY_DELETE
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
function getTextContent(message) {
|
|
91
|
-
if (typeof message.content === "string") return message.content;
|
|
92
|
-
if (message.content && typeof message.content === "object" && "parts" in message.content) return message.content.parts.find((p) => p.type === "text")?.text || "";
|
|
93
|
-
return "";
|
|
94
|
-
}
|
|
95
|
-
async function getMemoryFromContext({ mastra, agentId, requestContext, allowMissingAgent = false }) {
|
|
96
|
-
const logger = mastra.getLogger();
|
|
97
|
-
let agent;
|
|
98
|
-
if (agentId) try {
|
|
99
|
-
agent = mastra.getAgentById(agentId);
|
|
100
|
-
} catch (error) {
|
|
101
|
-
logger.debug("Error getting agent from mastra, searching agents for agent", error);
|
|
102
|
-
}
|
|
103
|
-
if (agentId && !agent) {
|
|
104
|
-
logger.debug("Agent not found in registered agents, trying stored agents", { agentId });
|
|
105
|
-
try {
|
|
106
|
-
const storedAgent = await mastra.getEditor()?.agent.getById(agentId) ?? null;
|
|
107
|
-
if (storedAgent) agent = storedAgent;
|
|
108
|
-
} catch (error) {
|
|
109
|
-
logger.debug("Error getting stored agent", error);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (agentId && !agent) {
|
|
113
|
-
logger.debug("Stored agent not found, searching sub-agents", { agentId });
|
|
114
|
-
const agents = mastra.listAgents();
|
|
115
|
-
if (Object.keys(agents || {}).length) for (const [_, ag] of Object.entries(agents)) try {
|
|
116
|
-
const subAgents = await ag.listAgents({ requestContext });
|
|
117
|
-
if (subAgents[agentId]) {
|
|
118
|
-
agent = subAgents[agentId];
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
} catch (error) {
|
|
122
|
-
logger.debug("Error getting agent from agent", error);
|
|
123
|
-
}
|
|
124
|
-
if (!agent) {
|
|
125
|
-
if (allowMissingAgent) {
|
|
126
|
-
logger.debug("Agent not found in any resolution tier, returning null for storage fallback", { agentId });
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
throw new HTTPException(404, { message: "Agent not found" });
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
if (agent) return await agent?.getMemory({ requestContext });
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Gets the storage from context, used as a fallback when agent memory can't be resolved.
|
|
136
|
-
* This covers both cases where no agentId is provided and where the agentId refers to
|
|
137
|
-
* a stored agent whose memory instance can't be hydrated (e.g. no editor configured).
|
|
138
|
-
*/
|
|
139
|
-
function getStorageFromContext({ mastra }) {
|
|
140
|
-
return mastra.getStorage();
|
|
141
|
-
}
|
|
142
|
-
function agentSupportsMemory(agent) {
|
|
143
|
-
if (!agent) return true;
|
|
144
|
-
const candidate = agent;
|
|
145
|
-
if (typeof candidate.supportsMemory === "function" && !candidate.supportsMemory()) return false;
|
|
146
|
-
if (typeof candidate.hasOwnMemory === "function" && !candidate.hasOwnMemory()) return false;
|
|
147
|
-
return true;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Gets the agent from context for OM processor detection.
|
|
151
|
-
*/
|
|
152
|
-
async function getAgentFromContext({ mastra, agentId, requestContext }) {
|
|
153
|
-
if (!agentId) return null;
|
|
154
|
-
const logger = mastra.getLogger();
|
|
155
|
-
let agent = null;
|
|
156
|
-
try {
|
|
157
|
-
agent = mastra.getAgentById(agentId);
|
|
158
|
-
} catch (error) {
|
|
159
|
-
logger.debug("Error getting agent from mastra", error);
|
|
160
|
-
}
|
|
161
|
-
if (!agent) {
|
|
162
|
-
logger.debug("Agent not found in registered agents, trying stored agents", { agentId });
|
|
163
|
-
try {
|
|
164
|
-
const storedAgent = await mastra.getEditor()?.agent.getById(agentId) ?? null;
|
|
165
|
-
if (storedAgent) agent = storedAgent;
|
|
166
|
-
} catch (error) {
|
|
167
|
-
logger.debug("Error getting stored agent", error);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (!agent) {
|
|
171
|
-
logger.debug("Stored agent not found, searching sub-agents", { agentId });
|
|
172
|
-
const agents = mastra.listAgents();
|
|
173
|
-
if (Object.keys(agents || {}).length) for (const [_, ag] of Object.entries(agents)) try {
|
|
174
|
-
const nestedAgent = (await ag.listAgents({ requestContext }))[agentId];
|
|
175
|
-
if (nestedAgent instanceof Agent) {
|
|
176
|
-
agent = nestedAgent;
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
} catch (error) {
|
|
180
|
-
logger.debug("Error getting agent from agent", error);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return agent;
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Gets Observational Memory configuration from an agent's processors.
|
|
187
|
-
* Returns null if OM is not enabled.
|
|
188
|
-
*/
|
|
189
|
-
async function getOMConfigFromAgent(agent, requestContext) {
|
|
190
|
-
try {
|
|
191
|
-
if (typeof agent.resolveProcessorById !== "function") return null;
|
|
192
|
-
const omProcessor = await agent.resolveProcessorById("observational-memory", requestContext);
|
|
193
|
-
if (!omProcessor) return null;
|
|
194
|
-
if (typeof omProcessor.getResolvedConfig === "function") {
|
|
195
|
-
const resolvedConfig = await omProcessor.getResolvedConfig(requestContext);
|
|
196
|
-
return {
|
|
197
|
-
enabled: true,
|
|
198
|
-
scope: resolvedConfig.scope || "resource",
|
|
199
|
-
shareTokenBudget: resolvedConfig.shareTokenBudget,
|
|
200
|
-
messageTokens: resolvedConfig.observation?.messageTokens,
|
|
201
|
-
observationTokens: resolvedConfig.reflection?.observationTokens,
|
|
202
|
-
observationModel: resolvedConfig.observation?.model,
|
|
203
|
-
reflectionModel: resolvedConfig.reflection?.model,
|
|
204
|
-
observationModelRouting: resolvedConfig.observation?.routing,
|
|
205
|
-
reflectionModelRouting: resolvedConfig.reflection?.routing
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
const processorConfig = omProcessor.config || {};
|
|
209
|
-
return {
|
|
210
|
-
enabled: true,
|
|
211
|
-
scope: processorConfig.scope || "resource",
|
|
212
|
-
shareTokenBudget: processorConfig.shareTokenBudget,
|
|
213
|
-
messageTokens: processorConfig.observation?.messageTokens,
|
|
214
|
-
observationTokens: processorConfig.reflection?.observationTokens,
|
|
215
|
-
observationModel: void 0,
|
|
216
|
-
reflectionModel: void 0,
|
|
217
|
-
observationModelRouting: void 0,
|
|
218
|
-
reflectionModelRouting: void 0
|
|
219
|
-
};
|
|
220
|
-
} catch {
|
|
221
|
-
return null;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Gets Observational Memory status for a specific resource/thread.
|
|
226
|
-
*/
|
|
227
|
-
async function getOMStatus(memoryStorage, resourceId, threadId) {
|
|
228
|
-
try {
|
|
229
|
-
const record = await memoryStorage.getObservationalMemory(threadId ?? null, resourceId);
|
|
230
|
-
if (!record) return { hasRecord: false };
|
|
231
|
-
return {
|
|
232
|
-
hasRecord: true,
|
|
233
|
-
originType: record.originType,
|
|
234
|
-
lastObservedAt: record.lastObservedAt ?? null,
|
|
235
|
-
tokenCount: record.totalTokensObserved,
|
|
236
|
-
observationTokenCount: record.observationTokenCount,
|
|
237
|
-
isObserving: record.isObserving,
|
|
238
|
-
isReflecting: record.isReflecting
|
|
239
|
-
};
|
|
240
|
-
} catch {
|
|
241
|
-
return null;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
const GET_MEMORY_STATUS_ROUTE = createRoute({
|
|
245
|
-
method: "GET",
|
|
246
|
-
path: "/memory/status",
|
|
247
|
-
responseType: "json",
|
|
248
|
-
queryParamSchema: getMemoryStatusQuerySchema,
|
|
249
|
-
responseSchema: memoryStatusResponseSchema,
|
|
250
|
-
summary: "Get memory status",
|
|
251
|
-
description: "Returns the current status of the memory system including configuration and health information",
|
|
252
|
-
tags: ["Memory"],
|
|
253
|
-
requiresAuth: true,
|
|
254
|
-
handler: async ({ mastra, agentId, resourceId, threadId, requestContext }) => {
|
|
255
|
-
try {
|
|
256
|
-
const agent = await getAgentFromContext({
|
|
257
|
-
mastra,
|
|
258
|
-
agentId,
|
|
259
|
-
requestContext
|
|
260
|
-
});
|
|
261
|
-
const isGateway = agent ? await isGatewayAgentAsync(agent) : false;
|
|
262
|
-
if (agent && isGateway) {
|
|
263
|
-
const gwClient = getGatewayClient();
|
|
264
|
-
if (gwClient) {
|
|
265
|
-
let omStatus;
|
|
266
|
-
if (resourceId && threadId) try {
|
|
267
|
-
const { record } = await gwClient.getObservationRecord(threadId, resourceId);
|
|
268
|
-
if (record) omStatus = {
|
|
269
|
-
enabled: true,
|
|
270
|
-
hasRecord: true,
|
|
271
|
-
originType: record.originType,
|
|
272
|
-
lastObservedAt: record.lastObservedAt ? new Date(record.lastObservedAt) : void 0,
|
|
273
|
-
tokenCount: record.totalTokensObserved,
|
|
274
|
-
observationTokenCount: record.observationTokenCount,
|
|
275
|
-
isObserving: record.isObserving,
|
|
276
|
-
isReflecting: record.isReflecting
|
|
277
|
-
};
|
|
278
|
-
else omStatus = {
|
|
279
|
-
enabled: true,
|
|
280
|
-
hasRecord: false
|
|
281
|
-
};
|
|
282
|
-
} catch {
|
|
283
|
-
omStatus = { enabled: true };
|
|
284
|
-
}
|
|
285
|
-
else omStatus = { enabled: true };
|
|
286
|
-
return {
|
|
287
|
-
result: true,
|
|
288
|
-
memoryType: "gateway",
|
|
289
|
-
observationalMemory: omStatus
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
const memory = await getMemoryFromContext({
|
|
294
|
-
mastra,
|
|
295
|
-
agentId,
|
|
296
|
-
requestContext,
|
|
297
|
-
allowMissingAgent: true
|
|
298
|
-
});
|
|
299
|
-
if (memory) {
|
|
300
|
-
let omStatus;
|
|
301
|
-
if (agent) {
|
|
302
|
-
const omConfig = await getOMConfigFromAgent(agent, requestContext);
|
|
303
|
-
if (omConfig?.enabled && resourceId) {
|
|
304
|
-
const omThreadId = omConfig.scope === "resource" ? void 0 : threadId;
|
|
305
|
-
try {
|
|
306
|
-
const memoryStore = await memory.storage.getStore("memory");
|
|
307
|
-
if (memoryStore) {
|
|
308
|
-
const status = await getOMStatus(memoryStore, resourceId, omThreadId);
|
|
309
|
-
if (status) omStatus = {
|
|
310
|
-
enabled: true,
|
|
311
|
-
...status,
|
|
312
|
-
lastObservedAt: status.lastObservedAt ?? void 0
|
|
313
|
-
};
|
|
314
|
-
else omStatus = {
|
|
315
|
-
enabled: true,
|
|
316
|
-
hasRecord: false
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
} catch {
|
|
320
|
-
omStatus = { enabled: true };
|
|
321
|
-
}
|
|
322
|
-
} else if (omConfig?.enabled) omStatus = { enabled: true };
|
|
323
|
-
}
|
|
324
|
-
return {
|
|
325
|
-
result: true,
|
|
326
|
-
memoryType: "local",
|
|
327
|
-
observationalMemory: omStatus
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
if (!agentSupportsMemory(agent)) return { result: false };
|
|
331
|
-
if (getStorageFromContext({ mastra })) return { result: true };
|
|
332
|
-
return { result: false };
|
|
333
|
-
} catch (error) {
|
|
334
|
-
return handleError(error, "Error getting memory status");
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
const GET_MEMORY_CONFIG_ROUTE = createRoute({
|
|
339
|
-
method: "GET",
|
|
340
|
-
path: "/memory/config",
|
|
341
|
-
responseType: "json",
|
|
342
|
-
queryParamSchema: getMemoryConfigQuerySchema,
|
|
343
|
-
responseSchema: memoryConfigResponseSchema,
|
|
344
|
-
summary: "Get memory configuration",
|
|
345
|
-
description: "Returns the memory configuration for a specific agent or the system default",
|
|
346
|
-
tags: ["Memory"],
|
|
347
|
-
requiresAuth: true,
|
|
348
|
-
handler: async ({ mastra, agentId, requestContext }) => {
|
|
349
|
-
try {
|
|
350
|
-
const agent = await getAgentFromContext({
|
|
351
|
-
mastra,
|
|
352
|
-
agentId,
|
|
353
|
-
requestContext
|
|
354
|
-
});
|
|
355
|
-
if (agent && await isGatewayAgentAsync(agent) && getGatewayClient()) return {
|
|
356
|
-
memoryType: "gateway",
|
|
357
|
-
config: { observationalMemory: {
|
|
358
|
-
enabled: true,
|
|
359
|
-
scope: "thread",
|
|
360
|
-
messageTokens: 3e4,
|
|
361
|
-
observationTokens: 4e4
|
|
362
|
-
} }
|
|
363
|
-
};
|
|
364
|
-
const memory = await getMemoryFromContext({
|
|
365
|
-
mastra,
|
|
366
|
-
agentId,
|
|
367
|
-
requestContext,
|
|
368
|
-
allowMissingAgent: true
|
|
369
|
-
});
|
|
370
|
-
if (!memory) return { config: null };
|
|
371
|
-
const config = memory.getMergedThreadConfig({});
|
|
372
|
-
let omConfig;
|
|
373
|
-
if (agent) omConfig = await getOMConfigFromAgent(agent, requestContext) ?? { enabled: false };
|
|
374
|
-
return { config: {
|
|
375
|
-
...config,
|
|
376
|
-
observationalMemory: omConfig
|
|
377
|
-
} };
|
|
378
|
-
} catch (error) {
|
|
379
|
-
return handleError(error, "Error getting memory configuration");
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
});
|
|
383
|
-
const GET_OBSERVATIONAL_MEMORY_ROUTE = createRoute({
|
|
384
|
-
method: "GET",
|
|
385
|
-
path: "/memory/observational-memory",
|
|
386
|
-
responseType: "json",
|
|
387
|
-
queryParamSchema: getObservationalMemoryQuerySchema,
|
|
388
|
-
responseSchema: getObservationalMemoryResponseSchema,
|
|
389
|
-
summary: "Get observational memory data",
|
|
390
|
-
description: "Returns the current observational memory record and optional history for a resource/thread",
|
|
391
|
-
tags: ["Memory"],
|
|
392
|
-
requiresAuth: true,
|
|
393
|
-
handler: async ({ mastra, agentId, resourceId, threadId, from, to, offset, limit, requestContext }) => {
|
|
394
|
-
try {
|
|
395
|
-
const agent = await getAgentFromContext({
|
|
396
|
-
mastra,
|
|
397
|
-
agentId,
|
|
398
|
-
requestContext
|
|
399
|
-
});
|
|
400
|
-
if (!agent) throw new HTTPException(404, { message: "Agent not found" });
|
|
401
|
-
const historyLimit = limit ?? 5;
|
|
402
|
-
const historyOptions = {
|
|
403
|
-
from,
|
|
404
|
-
to,
|
|
405
|
-
offset
|
|
406
|
-
};
|
|
407
|
-
if (await isGatewayAgentAsync(agent)) {
|
|
408
|
-
const gwClient = getGatewayClient();
|
|
409
|
-
if (gwClient && resourceId && threadId) {
|
|
410
|
-
const [recordResult, historyResult] = await Promise.all([gwClient.getObservationRecord(threadId, resourceId), gwClient.getObservationHistory(threadId, {
|
|
411
|
-
resourceId,
|
|
412
|
-
limit: historyLimit,
|
|
413
|
-
from,
|
|
414
|
-
to,
|
|
415
|
-
offset
|
|
416
|
-
})]);
|
|
417
|
-
return {
|
|
418
|
-
record: recordResult.record ? toLocalOMRecord(recordResult.record) : null,
|
|
419
|
-
history: historyResult.records?.length > 0 ? historyResult.records.map(toLocalOMRecord) : void 0
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
return {
|
|
423
|
-
record: null,
|
|
424
|
-
history: void 0
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
const omConfig = await getOMConfigFromAgent(agent, requestContext);
|
|
428
|
-
if (!omConfig?.enabled) throw new HTTPException(400, { message: "Observational Memory is not enabled for this agent" });
|
|
429
|
-
const memory = await getMemoryFromContext({
|
|
430
|
-
mastra,
|
|
431
|
-
agentId,
|
|
432
|
-
requestContext
|
|
433
|
-
});
|
|
434
|
-
if (!memory) throw new HTTPException(400, { message: "Memory is not configured for this agent" });
|
|
435
|
-
let memoryStore;
|
|
436
|
-
try {
|
|
437
|
-
memoryStore = await memory.storage.getStore("memory");
|
|
438
|
-
} catch {
|
|
439
|
-
throw new HTTPException(400, { message: "Memory storage is not initialized" });
|
|
440
|
-
}
|
|
441
|
-
if (!memoryStore) throw new HTTPException(400, { message: "Memory storage is not initialized" });
|
|
442
|
-
const effectiveResourceId = resourceId;
|
|
443
|
-
if (!effectiveResourceId) throw new HTTPException(400, { message: "resourceId is required for observational memory lookup" });
|
|
444
|
-
const omThreadId = omConfig.scope === "resource" ? null : threadId ?? null;
|
|
445
|
-
const record = await memoryStore.getObservationalMemory(omThreadId, effectiveResourceId);
|
|
446
|
-
const history = await memoryStore.getObservationalMemoryHistory(omThreadId, effectiveResourceId, historyLimit, historyOptions);
|
|
447
|
-
return {
|
|
448
|
-
record: record ?? null,
|
|
449
|
-
history: history.length > 0 ? history : void 0
|
|
450
|
-
};
|
|
451
|
-
} catch (error) {
|
|
452
|
-
return handleError(error, "Error getting observational memory");
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
});
|
|
456
|
-
const AWAIT_BUFFER_STATUS_ROUTE = createRoute({
|
|
457
|
-
method: "POST",
|
|
458
|
-
path: "/memory/observational-memory/buffer-status",
|
|
459
|
-
responseType: "json",
|
|
460
|
-
bodySchema: awaitBufferStatusBodySchema,
|
|
461
|
-
responseSchema: awaitBufferStatusResponseSchema,
|
|
462
|
-
summary: "Await observational memory buffering completion",
|
|
463
|
-
description: "Blocks until any in-flight buffering operations complete for the given thread/resource, then returns the updated record",
|
|
464
|
-
tags: ["Memory"],
|
|
465
|
-
requiresAuth: true,
|
|
466
|
-
handler: async ({ mastra, agentId, resourceId, threadId, requestContext }) => {
|
|
467
|
-
try {
|
|
468
|
-
const agent = await getAgentFromContext({
|
|
469
|
-
mastra,
|
|
470
|
-
agentId,
|
|
471
|
-
requestContext
|
|
472
|
-
});
|
|
473
|
-
if (!agent) throw new HTTPException(404, { message: "Agent not found" });
|
|
474
|
-
if (await isGatewayAgentAsync(agent)) {
|
|
475
|
-
const gwClient = getGatewayClient();
|
|
476
|
-
if (gwClient && resourceId && threadId) {
|
|
477
|
-
const maxWaitMs = 3e4;
|
|
478
|
-
const pollIntervalMs = 1e3;
|
|
479
|
-
const deadline = Date.now() + maxWaitMs;
|
|
480
|
-
let record = null;
|
|
481
|
-
while (Date.now() < deadline) {
|
|
482
|
-
const result = await gwClient.getObservationRecord(threadId, resourceId);
|
|
483
|
-
record = result.record ? toLocalOMRecord(result.record) : null;
|
|
484
|
-
if (!record || !record.isBufferingObservation && !record.isBufferingReflection) break;
|
|
485
|
-
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
486
|
-
}
|
|
487
|
-
return { record };
|
|
488
|
-
}
|
|
489
|
-
return { record: null };
|
|
490
|
-
}
|
|
491
|
-
const omConfig = await getOMConfigFromAgent(agent, requestContext);
|
|
492
|
-
if (!omConfig?.enabled) throw new HTTPException(400, { message: "Observational Memory is not enabled for this agent" });
|
|
493
|
-
const omProcessor = await agent.resolveProcessorById("observational-memory", requestContext);
|
|
494
|
-
if (!omProcessor || typeof omProcessor.waitForBuffering !== "function") throw new HTTPException(400, { message: "Observational Memory processor not available" });
|
|
495
|
-
await omProcessor.waitForBuffering(threadId, resourceId);
|
|
496
|
-
const memory = await getMemoryFromContext({
|
|
497
|
-
mastra,
|
|
498
|
-
agentId,
|
|
499
|
-
requestContext
|
|
500
|
-
});
|
|
501
|
-
if (!memory) throw new HTTPException(400, { message: "Memory is not configured for this agent" });
|
|
502
|
-
let memoryStore;
|
|
503
|
-
try {
|
|
504
|
-
memoryStore = await memory.storage.getStore("memory");
|
|
505
|
-
} catch {
|
|
506
|
-
throw new HTTPException(400, { message: "Memory storage is not initialized" });
|
|
507
|
-
}
|
|
508
|
-
if (!memoryStore) throw new HTTPException(400, { message: "Memory storage is not initialized" });
|
|
509
|
-
const effectiveResourceId = resourceId;
|
|
510
|
-
if (!effectiveResourceId) throw new HTTPException(400, { message: "resourceId is required" });
|
|
511
|
-
const omThreadId = omConfig.scope === "resource" ? null : threadId ?? null;
|
|
512
|
-
return { record: await memoryStore.getObservationalMemory(omThreadId, effectiveResourceId) ?? null };
|
|
513
|
-
} catch (error) {
|
|
514
|
-
console.error("Error awaiting buffer status", error);
|
|
515
|
-
return handleError(error, "Error awaiting buffer status");
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
});
|
|
519
|
-
const LIST_THREADS_ROUTE = createRoute({
|
|
520
|
-
method: "GET",
|
|
521
|
-
path: "/memory/threads",
|
|
522
|
-
responseType: "json",
|
|
523
|
-
queryParamSchema: listThreadsQuerySchema,
|
|
524
|
-
responseSchema: listThreadsResponseSchema,
|
|
525
|
-
summary: "List memory threads",
|
|
526
|
-
description: "Returns a paginated list of conversation threads with optional filtering by resource ID and/or metadata",
|
|
527
|
-
tags: ["Memory"],
|
|
528
|
-
requiresAuth: true,
|
|
529
|
-
handler: async ({ mastra, agentId, resourceId, metadata, requestContext, page, perPage, orderBy }) => {
|
|
530
|
-
try {
|
|
531
|
-
const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);
|
|
532
|
-
const agent = await getAgentFromContext({
|
|
533
|
-
mastra,
|
|
534
|
-
agentId,
|
|
535
|
-
requestContext
|
|
536
|
-
});
|
|
537
|
-
const isGateway = agent ? await isGatewayAgentAsync(agent) : false;
|
|
538
|
-
if (agent && isGateway) {
|
|
539
|
-
const gwClient = getGatewayClient();
|
|
540
|
-
if (gwClient) {
|
|
541
|
-
if (shouldFilterThreadsWithFGA(mastra, requestContext)) {
|
|
542
|
-
const initialResult = await gwClient.listThreads({
|
|
543
|
-
resourceId: effectiveResourceId,
|
|
544
|
-
limit: 1,
|
|
545
|
-
offset: 0
|
|
546
|
-
});
|
|
547
|
-
return paginateThreads({
|
|
548
|
-
threads: await filterAccessibleThreads({
|
|
549
|
-
mastra,
|
|
550
|
-
requestContext,
|
|
551
|
-
threads: initialResult.total > 0 ? (await gwClient.listThreads({
|
|
552
|
-
resourceId: effectiveResourceId,
|
|
553
|
-
limit: initialResult.total,
|
|
554
|
-
offset: 0
|
|
555
|
-
})).threads.map(toLocalThread) : []
|
|
556
|
-
}),
|
|
557
|
-
page,
|
|
558
|
-
perPage
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
const effectivePage = page ?? 0;
|
|
562
|
-
const effectivePerPage = perPage ?? 100;
|
|
563
|
-
const offset = effectivePage * effectivePerPage;
|
|
564
|
-
const result = await gwClient.listThreads({
|
|
565
|
-
resourceId: effectiveResourceId,
|
|
566
|
-
limit: effectivePerPage,
|
|
567
|
-
offset
|
|
568
|
-
});
|
|
569
|
-
return {
|
|
570
|
-
threads: result.threads.map(toLocalThread),
|
|
571
|
-
page: effectivePage,
|
|
572
|
-
perPage: effectivePerPage,
|
|
573
|
-
total: result.total,
|
|
574
|
-
hasMore: offset + result.threads.length < result.total
|
|
575
|
-
};
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
const filter = effectiveResourceId || metadata ? {} : void 0;
|
|
579
|
-
if (effectiveResourceId) filter.resourceId = effectiveResourceId;
|
|
580
|
-
if (metadata) filter.metadata = metadata;
|
|
581
|
-
const memory = await getMemoryFromContext({
|
|
582
|
-
mastra,
|
|
583
|
-
agentId,
|
|
584
|
-
requestContext,
|
|
585
|
-
allowMissingAgent: true
|
|
586
|
-
});
|
|
587
|
-
if (memory) {
|
|
588
|
-
const result = await memory.listThreads(shouldFilterThreadsWithFGA(mastra, requestContext) ? {
|
|
589
|
-
filter,
|
|
590
|
-
perPage: false,
|
|
591
|
-
orderBy
|
|
592
|
-
} : {
|
|
593
|
-
filter,
|
|
594
|
-
page,
|
|
595
|
-
perPage,
|
|
596
|
-
orderBy
|
|
597
|
-
});
|
|
598
|
-
if (!shouldFilterThreadsWithFGA(mastra, requestContext)) return result;
|
|
599
|
-
return paginateThreads({
|
|
600
|
-
threads: await filterAccessibleThreads({
|
|
601
|
-
mastra,
|
|
602
|
-
requestContext,
|
|
603
|
-
threads: result.threads
|
|
604
|
-
}),
|
|
605
|
-
page,
|
|
606
|
-
perPage
|
|
607
|
-
});
|
|
608
|
-
}
|
|
609
|
-
const storage = getStorageFromContext({ mastra });
|
|
610
|
-
if (storage) {
|
|
611
|
-
const memoryStore = await storage.getStore("memory");
|
|
612
|
-
if (memoryStore) {
|
|
613
|
-
const result = await memoryStore.listThreads(shouldFilterThreadsWithFGA(mastra, requestContext) ? {
|
|
614
|
-
filter,
|
|
615
|
-
perPage: false,
|
|
616
|
-
orderBy
|
|
617
|
-
} : {
|
|
618
|
-
filter,
|
|
619
|
-
page,
|
|
620
|
-
perPage,
|
|
621
|
-
orderBy
|
|
622
|
-
});
|
|
623
|
-
if (!shouldFilterThreadsWithFGA(mastra, requestContext)) return result;
|
|
624
|
-
return paginateThreads({
|
|
625
|
-
threads: await filterAccessibleThreads({
|
|
626
|
-
mastra,
|
|
627
|
-
requestContext,
|
|
628
|
-
threads: result.threads
|
|
629
|
-
}),
|
|
630
|
-
page,
|
|
631
|
-
perPage
|
|
632
|
-
});
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
636
|
-
} catch (error) {
|
|
637
|
-
return handleError(error, "Error listing threads");
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
});
|
|
641
|
-
const GET_THREAD_BY_ID_ROUTE = createRoute({
|
|
642
|
-
method: "GET",
|
|
643
|
-
path: "/memory/threads/:threadId",
|
|
644
|
-
responseType: "json",
|
|
645
|
-
pathParamSchema: threadIdPathParams,
|
|
646
|
-
queryParamSchema: getThreadByIdQuerySchema,
|
|
647
|
-
responseSchema: getThreadByIdResponseSchema,
|
|
648
|
-
summary: "Get thread by ID",
|
|
649
|
-
description: "Returns details for a specific conversation thread",
|
|
650
|
-
tags: ["Memory"],
|
|
651
|
-
requiresAuth: true,
|
|
652
|
-
handler: async ({ mastra, agentId, threadId, resourceId, requestContext }) => {
|
|
653
|
-
try {
|
|
654
|
-
const effectiveThreadId = getEffectiveThreadId(requestContext, threadId);
|
|
655
|
-
const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);
|
|
656
|
-
validateBody({ threadId: effectiveThreadId });
|
|
657
|
-
const agent = await getAgentFromContext({
|
|
658
|
-
mastra,
|
|
659
|
-
agentId,
|
|
660
|
-
requestContext
|
|
661
|
-
});
|
|
662
|
-
const isGateway = agent ? await isGatewayAgentAsync(agent) : false;
|
|
663
|
-
if (agent && isGateway) {
|
|
664
|
-
const gwClient = getGatewayClient();
|
|
665
|
-
if (gwClient) {
|
|
666
|
-
const result = await gwClient.getThread(effectiveThreadId);
|
|
667
|
-
if (!result) return {
|
|
668
|
-
id: effectiveThreadId,
|
|
669
|
-
resourceId: effectiveResourceId ?? "",
|
|
670
|
-
title: "",
|
|
671
|
-
metadata: {},
|
|
672
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
673
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
674
|
-
};
|
|
675
|
-
const thread = toLocalThread(result.thread);
|
|
676
|
-
await enforceThreadAccess({
|
|
677
|
-
mastra,
|
|
678
|
-
requestContext,
|
|
679
|
-
threadId: effectiveThreadId,
|
|
680
|
-
thread,
|
|
681
|
-
effectiveResourceId
|
|
682
|
-
});
|
|
683
|
-
return thread;
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
const memory = await getMemoryFromContext({
|
|
687
|
-
mastra,
|
|
688
|
-
agentId,
|
|
689
|
-
requestContext,
|
|
690
|
-
allowMissingAgent: true
|
|
691
|
-
});
|
|
692
|
-
if (memory) {
|
|
693
|
-
const thread = await memory.getThreadById({ threadId: effectiveThreadId });
|
|
694
|
-
if (!thread) throw new HTTPException(404, { message: "Thread not found" });
|
|
695
|
-
await enforceThreadAccess({
|
|
696
|
-
mastra,
|
|
697
|
-
requestContext,
|
|
698
|
-
threadId: effectiveThreadId,
|
|
699
|
-
thread,
|
|
700
|
-
effectiveResourceId
|
|
701
|
-
});
|
|
702
|
-
return thread;
|
|
703
|
-
}
|
|
704
|
-
const storage = getStorageFromContext({ mastra });
|
|
705
|
-
if (storage) {
|
|
706
|
-
const memoryStore = await storage.getStore("memory");
|
|
707
|
-
if (memoryStore) {
|
|
708
|
-
const thread = await memoryStore.getThreadById({ threadId: effectiveThreadId });
|
|
709
|
-
if (!thread) throw new HTTPException(404, { message: "Thread not found" });
|
|
710
|
-
await enforceThreadAccess({
|
|
711
|
-
mastra,
|
|
712
|
-
requestContext,
|
|
713
|
-
threadId: effectiveThreadId,
|
|
714
|
-
thread,
|
|
715
|
-
effectiveResourceId
|
|
716
|
-
});
|
|
717
|
-
return thread;
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
721
|
-
} catch (error) {
|
|
722
|
-
return handleError(error, "Error getting thread");
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
});
|
|
726
|
-
const LIST_MESSAGES_ROUTE = createRoute({
|
|
727
|
-
method: "GET",
|
|
728
|
-
path: "/memory/threads/:threadId/messages",
|
|
729
|
-
responseType: "json",
|
|
730
|
-
pathParamSchema: threadIdPathParams,
|
|
731
|
-
queryParamSchema: listMessagesQuerySchema,
|
|
732
|
-
responseSchema: listMessagesResponseSchema,
|
|
733
|
-
summary: "List thread messages",
|
|
734
|
-
description: "Returns a paginated list of messages in a conversation thread",
|
|
735
|
-
tags: ["Memory"],
|
|
736
|
-
requiresAuth: true,
|
|
737
|
-
handler: (async ({ mastra, agentId, threadId, resourceId, perPage, page, orderBy, include, filter, includeSystemReminders, requestContext }) => {
|
|
738
|
-
try {
|
|
739
|
-
const effectiveThreadId = getEffectiveThreadId(requestContext, threadId);
|
|
740
|
-
const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);
|
|
741
|
-
validateBody({ threadId: effectiveThreadId });
|
|
742
|
-
if (!effectiveThreadId) throw new HTTPException(400, { message: "No threadId found" });
|
|
743
|
-
const agent = await getAgentFromContext({
|
|
744
|
-
mastra,
|
|
745
|
-
agentId,
|
|
746
|
-
requestContext
|
|
747
|
-
});
|
|
748
|
-
if (agent && await isGatewayAgentAsync(agent)) {
|
|
749
|
-
const gwClient = getGatewayClient();
|
|
750
|
-
if (gwClient) {
|
|
751
|
-
if (filter?.metadata && Object.keys(filter.metadata).length > 0) throw new HTTPException(501, { message: "Gateway memory message metadata filters are not supported by this gateway endpoint. Remove filter.metadata or query a local memory store." });
|
|
752
|
-
const threadResult = await gwClient.getThread(effectiveThreadId);
|
|
753
|
-
if (threadResult) await enforceThreadAccess({
|
|
754
|
-
mastra,
|
|
755
|
-
requestContext,
|
|
756
|
-
threadId: effectiveThreadId,
|
|
757
|
-
thread: toLocalThread(threadResult.thread),
|
|
758
|
-
effectiveResourceId
|
|
759
|
-
});
|
|
760
|
-
const effectivePage = page ?? 0;
|
|
761
|
-
const effectivePerPage = perPage ?? 100;
|
|
762
|
-
const offset = effectivePage * effectivePerPage;
|
|
763
|
-
const result = await gwClient.listMessages(effectiveThreadId, {
|
|
764
|
-
limit: effectivePerPage,
|
|
765
|
-
offset,
|
|
766
|
-
order: orderBy?.direction?.toLowerCase()
|
|
767
|
-
});
|
|
768
|
-
if (!result) throw new HTTPException(404, { message: "Thread not found" });
|
|
769
|
-
return {
|
|
770
|
-
messages: result.messages.map(toLocalMessage),
|
|
771
|
-
uiMessages: result.messages.map(toLocalMessage)
|
|
772
|
-
};
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
const memory = await getMemoryFromContext({
|
|
776
|
-
mastra,
|
|
777
|
-
agentId,
|
|
778
|
-
requestContext,
|
|
779
|
-
allowMissingAgent: true
|
|
780
|
-
});
|
|
781
|
-
if (memory) {
|
|
782
|
-
const thread = await memory.getThreadById({ threadId: effectiveThreadId });
|
|
783
|
-
if (!thread) throw new HTTPException(404, { message: "Thread not found" });
|
|
784
|
-
await enforceThreadAccess({
|
|
785
|
-
mastra,
|
|
786
|
-
requestContext,
|
|
787
|
-
threadId: effectiveThreadId,
|
|
788
|
-
thread,
|
|
789
|
-
effectiveResourceId
|
|
790
|
-
});
|
|
791
|
-
const result = await memory.recall({
|
|
792
|
-
threadId: effectiveThreadId,
|
|
793
|
-
resourceId: effectiveResourceId,
|
|
794
|
-
perPage,
|
|
795
|
-
page,
|
|
796
|
-
orderBy,
|
|
797
|
-
include,
|
|
798
|
-
filter,
|
|
799
|
-
includeSystemReminders
|
|
800
|
-
});
|
|
801
|
-
const uiMessages = result.uiMessages;
|
|
802
|
-
return {
|
|
803
|
-
...result,
|
|
804
|
-
uiMessages: Array.isArray(uiMessages) ? uiMessages : null
|
|
805
|
-
};
|
|
806
|
-
}
|
|
807
|
-
const storage = getStorageFromContext({ mastra });
|
|
808
|
-
if (storage) {
|
|
809
|
-
const memoryStore = await storage.getStore("memory");
|
|
810
|
-
if (memoryStore) {
|
|
811
|
-
const thread = await memoryStore.getThreadById({ threadId: effectiveThreadId });
|
|
812
|
-
if (!thread) throw new HTTPException(404, { message: "Thread not found" });
|
|
813
|
-
await enforceThreadAccess({
|
|
814
|
-
mastra,
|
|
815
|
-
requestContext,
|
|
816
|
-
threadId: effectiveThreadId,
|
|
817
|
-
thread,
|
|
818
|
-
effectiveResourceId
|
|
819
|
-
});
|
|
820
|
-
return {
|
|
821
|
-
...await memoryStore.listMessages({
|
|
822
|
-
threadId: effectiveThreadId,
|
|
823
|
-
resourceId: effectiveResourceId,
|
|
824
|
-
perPage,
|
|
825
|
-
page,
|
|
826
|
-
orderBy,
|
|
827
|
-
include,
|
|
828
|
-
filter
|
|
829
|
-
}),
|
|
830
|
-
uiMessages: null
|
|
831
|
-
};
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
return {
|
|
835
|
-
messages: [],
|
|
836
|
-
uiMessages: []
|
|
837
|
-
};
|
|
838
|
-
} catch (error) {
|
|
839
|
-
return handleError(error, "Error getting messages");
|
|
840
|
-
}
|
|
841
|
-
})
|
|
842
|
-
});
|
|
843
|
-
const GET_WORKING_MEMORY_ROUTE = createRoute({
|
|
844
|
-
method: "GET",
|
|
845
|
-
path: "/memory/threads/:threadId/working-memory",
|
|
846
|
-
responseType: "json",
|
|
847
|
-
pathParamSchema: threadIdPathParams,
|
|
848
|
-
queryParamSchema: getWorkingMemoryQuerySchema,
|
|
849
|
-
responseSchema: getWorkingMemoryResponseSchema,
|
|
850
|
-
summary: "Get working memory",
|
|
851
|
-
description: "Returns the working memory state for a thread",
|
|
852
|
-
tags: ["Memory"],
|
|
853
|
-
requiresAuth: true,
|
|
854
|
-
handler: async ({ mastra, agentId, threadId, resourceId, requestContext, memoryConfig }) => {
|
|
855
|
-
try {
|
|
856
|
-
const effectiveThreadId = getEffectiveThreadId(requestContext, threadId);
|
|
857
|
-
const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);
|
|
858
|
-
validateBody({ threadId: effectiveThreadId });
|
|
859
|
-
const gwAgent = await getAgentFromContext({
|
|
860
|
-
mastra,
|
|
861
|
-
agentId,
|
|
862
|
-
requestContext
|
|
863
|
-
});
|
|
864
|
-
if (gwAgent && await isGatewayAgentAsync(gwAgent) && getGatewayClient()) return {
|
|
865
|
-
workingMemory: null,
|
|
866
|
-
source: "thread",
|
|
867
|
-
workingMemoryTemplate: null,
|
|
868
|
-
threadExists: true
|
|
869
|
-
};
|
|
870
|
-
const memory = await getMemoryFromContext({
|
|
871
|
-
mastra,
|
|
872
|
-
agentId,
|
|
873
|
-
requestContext,
|
|
874
|
-
allowMissingAgent: true
|
|
875
|
-
});
|
|
876
|
-
if (!memory) return {
|
|
877
|
-
workingMemory: null,
|
|
878
|
-
source: "thread",
|
|
879
|
-
workingMemoryTemplate: null,
|
|
880
|
-
threadExists: false
|
|
881
|
-
};
|
|
882
|
-
const thread = await memory.getThreadById({ threadId: effectiveThreadId });
|
|
883
|
-
const source = memory.getMergedThreadConfig(memoryConfig || {}).workingMemory?.scope !== "thread" && effectiveResourceId ? "resource" : "thread";
|
|
884
|
-
if (thread || source === "resource") await enforceThreadAccess({
|
|
885
|
-
mastra,
|
|
886
|
-
requestContext,
|
|
887
|
-
threadId: effectiveThreadId,
|
|
888
|
-
thread,
|
|
889
|
-
effectiveResourceId
|
|
890
|
-
});
|
|
891
|
-
const threadExists = !!thread;
|
|
892
|
-
const template = await memory.getWorkingMemoryTemplate({ memoryConfig });
|
|
893
|
-
const workingMemoryTemplate = template?.format === "json" ? {
|
|
894
|
-
...template,
|
|
895
|
-
content: JSON.stringify(generateEmptyFromSchema(template.content))
|
|
896
|
-
} : template;
|
|
897
|
-
return {
|
|
898
|
-
workingMemory: await memory.getWorkingMemory({
|
|
899
|
-
threadId: effectiveThreadId,
|
|
900
|
-
resourceId: effectiveResourceId,
|
|
901
|
-
memoryConfig
|
|
902
|
-
}),
|
|
903
|
-
source,
|
|
904
|
-
workingMemoryTemplate,
|
|
905
|
-
threadExists
|
|
906
|
-
};
|
|
907
|
-
} catch (error) {
|
|
908
|
-
return handleError(error, "Error getting working memory");
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
});
|
|
912
|
-
const SAVE_MESSAGES_ROUTE = createRoute({
|
|
913
|
-
method: "POST",
|
|
914
|
-
path: "/memory/save-messages",
|
|
915
|
-
responseType: "json",
|
|
916
|
-
queryParamSchema: agentIdQuerySchema,
|
|
917
|
-
bodySchema: saveMessagesBodySchema,
|
|
918
|
-
responseSchema: saveMessagesResponseSchema,
|
|
919
|
-
summary: "Save messages",
|
|
920
|
-
description: "Saves new messages to memory",
|
|
921
|
-
tags: ["Memory"],
|
|
922
|
-
requiresAuth: true,
|
|
923
|
-
handler: async ({ mastra, agentId, messages, requestContext }) => {
|
|
924
|
-
try {
|
|
925
|
-
const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
|
|
926
|
-
const memory = await getMemoryFromContext({
|
|
927
|
-
mastra,
|
|
928
|
-
agentId,
|
|
929
|
-
requestContext
|
|
930
|
-
});
|
|
931
|
-
if (!memory) throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
932
|
-
if (!messages) throw new HTTPException(400, { message: "Messages are required" });
|
|
933
|
-
if (!Array.isArray(messages)) throw new HTTPException(400, { message: "Messages should be an array" });
|
|
934
|
-
const incomingMessages = messages;
|
|
935
|
-
const resourceIdByThread = /* @__PURE__ */ new Map();
|
|
936
|
-
for (const message of incomingMessages) {
|
|
937
|
-
if (!message.threadId || !message.resourceId) continue;
|
|
938
|
-
const existingResourceId = resourceIdByThread.get(message.threadId);
|
|
939
|
-
if (!existingResourceId) resourceIdByThread.set(message.threadId, message.resourceId);
|
|
940
|
-
else if (existingResourceId !== message.resourceId) throw new HTTPException(400, { message: "All messages for the same threadId must use the same resourceId." });
|
|
941
|
-
}
|
|
942
|
-
const invalidMessages = incomingMessages.filter((message) => !message.threadId || !message.resourceId);
|
|
943
|
-
if (invalidMessages.length > 0) throw new HTTPException(400, { message: `All messages must have threadId and resourceId fields. Found ${invalidMessages.length} invalid message(s).` });
|
|
944
|
-
if (effectiveResourceId) {
|
|
945
|
-
if (incomingMessages.filter((message) => message.resourceId !== effectiveResourceId).length > 0) throw new HTTPException(403, { message: "Access denied: cannot save messages for a different resource" });
|
|
946
|
-
const threadIds = [...new Set(incomingMessages.map((m) => m.threadId).filter(Boolean))];
|
|
947
|
-
for (const threadId of threadIds) await enforceThreadAccess({
|
|
948
|
-
mastra,
|
|
949
|
-
requestContext,
|
|
950
|
-
threadId,
|
|
951
|
-
thread: await memory.getThreadById({ threadId }),
|
|
952
|
-
effectiveResourceId,
|
|
953
|
-
permission: MastraFGAPermissions.MEMORY_WRITE
|
|
954
|
-
});
|
|
955
|
-
} else {
|
|
956
|
-
const threadIds = [...new Set(incomingMessages.map((m) => m.threadId).filter(Boolean))];
|
|
957
|
-
for (const threadId of threadIds) await enforceThreadAccess({
|
|
958
|
-
mastra,
|
|
959
|
-
requestContext,
|
|
960
|
-
threadId,
|
|
961
|
-
thread: await memory.getThreadById({ threadId }),
|
|
962
|
-
effectiveResourceId: resourceIdByThread.get(threadId),
|
|
963
|
-
permission: MastraFGAPermissions.MEMORY_WRITE
|
|
964
|
-
});
|
|
965
|
-
}
|
|
966
|
-
const processedMessages = incomingMessages.map((message) => ({
|
|
967
|
-
...message,
|
|
968
|
-
id: message.id || memory.generateId(),
|
|
969
|
-
createdAt: message.createdAt ? new Date(message.createdAt) : /* @__PURE__ */ new Date()
|
|
970
|
-
}));
|
|
971
|
-
return await memory.saveMessages({
|
|
972
|
-
messages: processedMessages,
|
|
973
|
-
memoryConfig: {}
|
|
974
|
-
});
|
|
975
|
-
} catch (error) {
|
|
976
|
-
return handleError(error, "Error saving messages");
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
});
|
|
980
|
-
const CREATE_THREAD_ROUTE = createRoute({
|
|
981
|
-
method: "POST",
|
|
982
|
-
path: "/memory/threads",
|
|
983
|
-
responseType: "json",
|
|
984
|
-
queryParamSchema: agentIdQuerySchema,
|
|
985
|
-
bodySchema: createThreadBodySchema,
|
|
986
|
-
responseSchema: getThreadByIdResponseSchema,
|
|
987
|
-
summary: "Create thread",
|
|
988
|
-
description: "Creates a new conversation thread",
|
|
989
|
-
tags: ["Memory"],
|
|
990
|
-
requiresAuth: true,
|
|
991
|
-
handler: async ({ mastra, agentId, resourceId, title, metadata, threadId, requestContext }) => {
|
|
992
|
-
try {
|
|
993
|
-
const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);
|
|
994
|
-
const effectiveThreadId = threadId ?? mastra.generateId();
|
|
995
|
-
validateBody({ resourceId: effectiveResourceId });
|
|
996
|
-
const agent = await getAgentFromContext({
|
|
997
|
-
mastra,
|
|
998
|
-
agentId,
|
|
999
|
-
requestContext
|
|
1000
|
-
});
|
|
1001
|
-
if (agent && await isGatewayAgentAsync(agent)) {
|
|
1002
|
-
const gwClient = getGatewayClient();
|
|
1003
|
-
if (gwClient) {
|
|
1004
|
-
const existing = threadId ? await gwClient.getThread(effectiveThreadId) : null;
|
|
1005
|
-
await enforceThreadAccess({
|
|
1006
|
-
mastra,
|
|
1007
|
-
requestContext,
|
|
1008
|
-
threadId: effectiveThreadId,
|
|
1009
|
-
thread: existing ? toLocalThread(existing.thread) : null,
|
|
1010
|
-
effectiveResourceId,
|
|
1011
|
-
permission: MastraFGAPermissions.MEMORY_WRITE
|
|
1012
|
-
});
|
|
1013
|
-
return toLocalThread((await gwClient.createThread({
|
|
1014
|
-
id: effectiveThreadId,
|
|
1015
|
-
resourceId: effectiveResourceId,
|
|
1016
|
-
title,
|
|
1017
|
-
metadata
|
|
1018
|
-
})).thread);
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
const memory = await getMemoryFromContext({
|
|
1022
|
-
mastra,
|
|
1023
|
-
agentId,
|
|
1024
|
-
requestContext
|
|
1025
|
-
});
|
|
1026
|
-
if (!memory) throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
1027
|
-
await enforceThreadAccess({
|
|
1028
|
-
mastra,
|
|
1029
|
-
requestContext,
|
|
1030
|
-
threadId: effectiveThreadId,
|
|
1031
|
-
thread: threadId ? await memory.getThreadById({ threadId: effectiveThreadId }) : null,
|
|
1032
|
-
effectiveResourceId,
|
|
1033
|
-
permission: MastraFGAPermissions.MEMORY_WRITE
|
|
1034
|
-
});
|
|
1035
|
-
return await memory.createThread({
|
|
1036
|
-
resourceId: effectiveResourceId,
|
|
1037
|
-
title,
|
|
1038
|
-
metadata,
|
|
1039
|
-
threadId: effectiveThreadId
|
|
1040
|
-
});
|
|
1041
|
-
} catch (error) {
|
|
1042
|
-
return handleError(error, "Error saving thread to memory");
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
});
|
|
1046
|
-
const UPDATE_THREAD_ROUTE = createRoute({
|
|
1047
|
-
method: "PATCH",
|
|
1048
|
-
path: "/memory/threads/:threadId",
|
|
1049
|
-
responseType: "json",
|
|
1050
|
-
pathParamSchema: threadIdPathParams,
|
|
1051
|
-
queryParamSchema: agentIdQuerySchema,
|
|
1052
|
-
bodySchema: updateThreadBodySchema,
|
|
1053
|
-
responseSchema: getThreadByIdResponseSchema,
|
|
1054
|
-
summary: "Update thread",
|
|
1055
|
-
description: "Updates a conversation thread",
|
|
1056
|
-
tags: ["Memory"],
|
|
1057
|
-
requiresAuth: true,
|
|
1058
|
-
handler: async ({ mastra, agentId, threadId, title, metadata, resourceId, requestContext }) => {
|
|
1059
|
-
try {
|
|
1060
|
-
const effectiveThreadId = getEffectiveThreadId(requestContext, threadId);
|
|
1061
|
-
const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);
|
|
1062
|
-
validateBody({ threadId: effectiveThreadId });
|
|
1063
|
-
const agent = await getAgentFromContext({
|
|
1064
|
-
mastra,
|
|
1065
|
-
agentId,
|
|
1066
|
-
requestContext
|
|
1067
|
-
});
|
|
1068
|
-
if (agent && await isGatewayAgentAsync(agent)) {
|
|
1069
|
-
const gwClient = getGatewayClient();
|
|
1070
|
-
if (gwClient) {
|
|
1071
|
-
const existing = await gwClient.getThread(effectiveThreadId);
|
|
1072
|
-
if (existing) await enforceThreadAccess({
|
|
1073
|
-
mastra,
|
|
1074
|
-
requestContext,
|
|
1075
|
-
threadId: effectiveThreadId,
|
|
1076
|
-
thread: toLocalThread(existing.thread),
|
|
1077
|
-
effectiveResourceId,
|
|
1078
|
-
permission: MastraFGAPermissions.MEMORY_WRITE
|
|
1079
|
-
});
|
|
1080
|
-
const result = await gwClient.updateThread(effectiveThreadId, {
|
|
1081
|
-
title,
|
|
1082
|
-
metadata
|
|
1083
|
-
});
|
|
1084
|
-
if (!result) throw new HTTPException(404, { message: "Thread not found" });
|
|
1085
|
-
return toLocalThread(result.thread);
|
|
1086
|
-
}
|
|
1087
|
-
}
|
|
1088
|
-
const memory = await getMemoryFromContext({
|
|
1089
|
-
mastra,
|
|
1090
|
-
agentId,
|
|
1091
|
-
requestContext
|
|
1092
|
-
});
|
|
1093
|
-
const updatedAt = /* @__PURE__ */ new Date();
|
|
1094
|
-
if (!memory) throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
1095
|
-
const thread = await memory.getThreadById({ threadId: effectiveThreadId });
|
|
1096
|
-
if (!thread) throw new HTTPException(404, { message: "Thread not found" });
|
|
1097
|
-
await enforceThreadAccess({
|
|
1098
|
-
mastra,
|
|
1099
|
-
requestContext,
|
|
1100
|
-
threadId: effectiveThreadId,
|
|
1101
|
-
thread,
|
|
1102
|
-
effectiveResourceId,
|
|
1103
|
-
permission: MastraFGAPermissions.MEMORY_WRITE
|
|
1104
|
-
});
|
|
1105
|
-
const updatedThread = {
|
|
1106
|
-
...thread,
|
|
1107
|
-
title: title !== void 0 ? title : thread.title,
|
|
1108
|
-
metadata: metadata !== void 0 ? metadata : thread.metadata,
|
|
1109
|
-
resourceId: effectiveResourceId || resourceId || thread.resourceId,
|
|
1110
|
-
createdAt: thread.createdAt,
|
|
1111
|
-
updatedAt
|
|
1112
|
-
};
|
|
1113
|
-
const result = await memory.saveThread({ thread: updatedThread });
|
|
1114
|
-
return {
|
|
1115
|
-
...result,
|
|
1116
|
-
resourceId: result.resourceId ?? null
|
|
1117
|
-
};
|
|
1118
|
-
} catch (error) {
|
|
1119
|
-
return handleError(error, "Error updating thread");
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
});
|
|
1123
|
-
const DELETE_THREAD_ROUTE = createRoute({
|
|
1124
|
-
method: "DELETE",
|
|
1125
|
-
path: "/memory/threads/:threadId",
|
|
1126
|
-
responseType: "json",
|
|
1127
|
-
pathParamSchema: threadIdPathParams,
|
|
1128
|
-
queryParamSchema: deleteThreadQuerySchema,
|
|
1129
|
-
responseSchema: deleteThreadResponseSchema,
|
|
1130
|
-
summary: "Delete thread",
|
|
1131
|
-
description: "Deletes a conversation thread",
|
|
1132
|
-
tags: ["Memory"],
|
|
1133
|
-
requiresAuth: true,
|
|
1134
|
-
handler: async ({ mastra, agentId, threadId, resourceId, requestContext }) => {
|
|
1135
|
-
try {
|
|
1136
|
-
const effectiveThreadId = getEffectiveThreadId(requestContext, threadId);
|
|
1137
|
-
const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);
|
|
1138
|
-
validateBody({ threadId: effectiveThreadId });
|
|
1139
|
-
const agent = await getAgentFromContext({
|
|
1140
|
-
mastra,
|
|
1141
|
-
agentId,
|
|
1142
|
-
requestContext
|
|
1143
|
-
});
|
|
1144
|
-
if (agent && await isGatewayAgentAsync(agent)) {
|
|
1145
|
-
const gwClient = getGatewayClient();
|
|
1146
|
-
if (gwClient) {
|
|
1147
|
-
const existing = await gwClient.getThread(effectiveThreadId);
|
|
1148
|
-
if (existing) await enforceThreadAccess({
|
|
1149
|
-
mastra,
|
|
1150
|
-
requestContext,
|
|
1151
|
-
threadId: effectiveThreadId,
|
|
1152
|
-
thread: toLocalThread(existing.thread),
|
|
1153
|
-
effectiveResourceId,
|
|
1154
|
-
permission: MastraFGAPermissions.MEMORY_DELETE
|
|
1155
|
-
});
|
|
1156
|
-
if (!(await gwClient.deleteThread(effectiveThreadId)).ok) throw new HTTPException(404, { message: "Thread not found on gateway" });
|
|
1157
|
-
return { result: "Thread deleted" };
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
const memory = await getMemoryFromContext({
|
|
1161
|
-
mastra,
|
|
1162
|
-
agentId,
|
|
1163
|
-
requestContext
|
|
1164
|
-
});
|
|
1165
|
-
if (!memory) throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
1166
|
-
const thread = await memory.getThreadById({ threadId: effectiveThreadId });
|
|
1167
|
-
if (!thread) throw new HTTPException(404, { message: "Thread not found" });
|
|
1168
|
-
await enforceThreadAccess({
|
|
1169
|
-
mastra,
|
|
1170
|
-
requestContext,
|
|
1171
|
-
threadId: effectiveThreadId,
|
|
1172
|
-
thread,
|
|
1173
|
-
effectiveResourceId,
|
|
1174
|
-
permission: MastraFGAPermissions.MEMORY_DELETE
|
|
1175
|
-
});
|
|
1176
|
-
await memory.deleteThread(effectiveThreadId);
|
|
1177
|
-
return { result: "Thread deleted" };
|
|
1178
|
-
} catch (error) {
|
|
1179
|
-
return handleError(error, "Error deleting thread");
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
});
|
|
1183
|
-
const CLONE_THREAD_ROUTE = createRoute({
|
|
1184
|
-
method: "POST",
|
|
1185
|
-
path: "/memory/threads/:threadId/clone",
|
|
1186
|
-
responseType: "json",
|
|
1187
|
-
pathParamSchema: threadIdPathParams,
|
|
1188
|
-
queryParamSchema: agentIdQuerySchema,
|
|
1189
|
-
bodySchema: cloneThreadBodySchema,
|
|
1190
|
-
responseSchema: cloneThreadResponseSchema,
|
|
1191
|
-
summary: "Clone thread",
|
|
1192
|
-
description: "Creates a copy of a conversation thread with all its messages",
|
|
1193
|
-
tags: ["Memory"],
|
|
1194
|
-
requiresAuth: true,
|
|
1195
|
-
handler: async ({ mastra, agentId, threadId, newThreadId, resourceId, title, metadata, options, requestContext }) => {
|
|
1196
|
-
try {
|
|
1197
|
-
const effectiveThreadId = getEffectiveThreadId(requestContext, threadId);
|
|
1198
|
-
const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);
|
|
1199
|
-
const effectiveNewThreadId = newThreadId ?? mastra.generateId();
|
|
1200
|
-
validateBody({ threadId: effectiveThreadId });
|
|
1201
|
-
const memory = await getMemoryFromContext({
|
|
1202
|
-
mastra,
|
|
1203
|
-
agentId,
|
|
1204
|
-
requestContext
|
|
1205
|
-
});
|
|
1206
|
-
if (!memory) throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
1207
|
-
const sourceThread = await memory.getThreadById({ threadId: effectiveThreadId });
|
|
1208
|
-
if (!sourceThread) throw new HTTPException(404, { message: "Source thread not found" });
|
|
1209
|
-
const cloneResourceId = effectiveResourceId ?? sourceThread.resourceId ?? void 0;
|
|
1210
|
-
await enforceThreadAccess({
|
|
1211
|
-
mastra,
|
|
1212
|
-
requestContext,
|
|
1213
|
-
threadId: effectiveThreadId,
|
|
1214
|
-
thread: sourceThread,
|
|
1215
|
-
effectiveResourceId
|
|
1216
|
-
});
|
|
1217
|
-
await enforceThreadAccess({
|
|
1218
|
-
mastra,
|
|
1219
|
-
requestContext,
|
|
1220
|
-
threadId: effectiveNewThreadId,
|
|
1221
|
-
effectiveResourceId: cloneResourceId,
|
|
1222
|
-
permission: MastraFGAPermissions.MEMORY_WRITE
|
|
1223
|
-
});
|
|
1224
|
-
return await memory.cloneThread({
|
|
1225
|
-
sourceThreadId: effectiveThreadId,
|
|
1226
|
-
newThreadId: effectiveNewThreadId,
|
|
1227
|
-
resourceId: cloneResourceId,
|
|
1228
|
-
title,
|
|
1229
|
-
metadata,
|
|
1230
|
-
options
|
|
1231
|
-
});
|
|
1232
|
-
} catch (error) {
|
|
1233
|
-
return handleError(error, "Error cloning thread");
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
});
|
|
1237
|
-
const TRANSFER_THREAD_ROUTE = createRoute({
|
|
1238
|
-
method: "POST",
|
|
1239
|
-
path: "/memory/threads/:threadId/transfer",
|
|
1240
|
-
responseType: "json",
|
|
1241
|
-
pathParamSchema: threadIdPathParams,
|
|
1242
|
-
queryParamSchema: optionalAgentIdQuerySchema,
|
|
1243
|
-
bodySchema: transferThreadBodySchema,
|
|
1244
|
-
responseSchema: transferThreadResponseSchema,
|
|
1245
|
-
summary: "Transfer thread ownership",
|
|
1246
|
-
description: "Reassigns a thread and all of its messages to a different resource. Requires a privileged (non-resource-scoped) context.",
|
|
1247
|
-
tags: ["Memory"],
|
|
1248
|
-
requiresAuth: true,
|
|
1249
|
-
handler: async ({ mastra, agentId, threadId, resourceId, requestContext }) => {
|
|
1250
|
-
try {
|
|
1251
|
-
const effectiveThreadId = getEffectiveThreadId(requestContext, threadId);
|
|
1252
|
-
validateBody({ threadId: effectiveThreadId });
|
|
1253
|
-
if (getContextResourceId(requestContext)) throw new HTTPException(403, { message: "Thread transfer requires a privileged (non-resource-scoped) context" });
|
|
1254
|
-
const server = mastra.getServer?.();
|
|
1255
|
-
if (server?.auth && !server?.fga) throw new HTTPException(403, { message: "Thread transfer requires explicit authorization. Configure an FGA provider (memory:write) to authorize privileged, non-resource-scoped transfers." });
|
|
1256
|
-
const agent = agentId ? await getAgentFromContext({
|
|
1257
|
-
mastra,
|
|
1258
|
-
agentId,
|
|
1259
|
-
requestContext
|
|
1260
|
-
}) : void 0;
|
|
1261
|
-
if (agent && await isGatewayAgentAsync(agent)) throw new HTTPException(501, { message: "Thread transfer is not supported for gateway agents" });
|
|
1262
|
-
const memory = await getMemoryFromContext({
|
|
1263
|
-
mastra,
|
|
1264
|
-
agentId,
|
|
1265
|
-
requestContext,
|
|
1266
|
-
allowMissingAgent: true
|
|
1267
|
-
});
|
|
1268
|
-
const memoryStore = memory ? void 0 : await getStorageFromContext({ mastra })?.getStore("memory");
|
|
1269
|
-
if (!memory && !memoryStore) throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
1270
|
-
const sourceThread = memory ? await memory.getThreadById({ threadId: effectiveThreadId }) : await memoryStore.getThreadById({ threadId: effectiveThreadId });
|
|
1271
|
-
if (!sourceThread) throw new HTTPException(404, { message: "Thread not found" });
|
|
1272
|
-
await enforceThreadAccess({
|
|
1273
|
-
mastra,
|
|
1274
|
-
requestContext,
|
|
1275
|
-
threadId: effectiveThreadId,
|
|
1276
|
-
thread: sourceThread,
|
|
1277
|
-
effectiveResourceId: void 0,
|
|
1278
|
-
permission: MastraFGAPermissions.MEMORY_WRITE
|
|
1279
|
-
});
|
|
1280
|
-
const result = memory ? await memory.updateThreadResourceId({
|
|
1281
|
-
threadId: effectiveThreadId,
|
|
1282
|
-
resourceId
|
|
1283
|
-
}) : await memoryStore.updateThreadResourceId({
|
|
1284
|
-
threadId: effectiveThreadId,
|
|
1285
|
-
resourceId
|
|
1286
|
-
});
|
|
1287
|
-
return {
|
|
1288
|
-
...result,
|
|
1289
|
-
resourceId: result.resourceId ?? null
|
|
1290
|
-
};
|
|
1291
|
-
} catch (error) {
|
|
1292
|
-
return handleError(error, "Error transferring thread");
|
|
1293
|
-
}
|
|
1294
|
-
}
|
|
1295
|
-
});
|
|
1296
|
-
const UPDATE_WORKING_MEMORY_ROUTE = createRoute({
|
|
1297
|
-
method: "POST",
|
|
1298
|
-
path: "/memory/threads/:threadId/working-memory",
|
|
1299
|
-
responseType: "json",
|
|
1300
|
-
pathParamSchema: threadIdPathParams,
|
|
1301
|
-
queryParamSchema: agentIdQuerySchema,
|
|
1302
|
-
bodySchema: updateWorkingMemoryBodySchema,
|
|
1303
|
-
responseSchema: updateWorkingMemoryResponseSchema,
|
|
1304
|
-
summary: "Update working memory",
|
|
1305
|
-
description: "Updates the working memory state for a thread",
|
|
1306
|
-
tags: ["Memory"],
|
|
1307
|
-
requiresAuth: true,
|
|
1308
|
-
handler: async ({ mastra, agentId, threadId, resourceId, memoryConfig, workingMemory, mode, requestContext }) => {
|
|
1309
|
-
try {
|
|
1310
|
-
const effectiveThreadId = getEffectiveThreadId(requestContext, threadId);
|
|
1311
|
-
const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);
|
|
1312
|
-
validateBody({
|
|
1313
|
-
threadId: effectiveThreadId,
|
|
1314
|
-
workingMemory
|
|
1315
|
-
});
|
|
1316
|
-
const gwAgent = await getAgentFromContext({
|
|
1317
|
-
mastra,
|
|
1318
|
-
agentId,
|
|
1319
|
-
requestContext
|
|
1320
|
-
});
|
|
1321
|
-
if (gwAgent && await isGatewayAgentAsync(gwAgent) && getGatewayClient()) return { success: true };
|
|
1322
|
-
const memory = await getMemoryFromContext({
|
|
1323
|
-
mastra,
|
|
1324
|
-
agentId,
|
|
1325
|
-
requestContext
|
|
1326
|
-
});
|
|
1327
|
-
if (!memory) throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
1328
|
-
const thread = await memory.getThreadById({ threadId: effectiveThreadId });
|
|
1329
|
-
if (!thread) throw new HTTPException(404, { message: "Thread not found" });
|
|
1330
|
-
await enforceThreadAccess({
|
|
1331
|
-
mastra,
|
|
1332
|
-
requestContext,
|
|
1333
|
-
threadId: effectiveThreadId,
|
|
1334
|
-
thread,
|
|
1335
|
-
effectiveResourceId,
|
|
1336
|
-
permission: MastraFGAPermissions.MEMORY_WRITE
|
|
1337
|
-
});
|
|
1338
|
-
if (mode === "merge") {
|
|
1339
|
-
if (!await memory.supportsAtomicWorkingMemoryMerge()) throw new HTTPException(400, { message: "Working memory merge is not supported by the configured storage adapter" });
|
|
1340
|
-
try {
|
|
1341
|
-
await memory.mergeWorkingMemory({
|
|
1342
|
-
threadId: effectiveThreadId,
|
|
1343
|
-
resourceId: effectiveResourceId,
|
|
1344
|
-
workingMemory,
|
|
1345
|
-
memoryConfig
|
|
1346
|
-
});
|
|
1347
|
-
} catch (error) {
|
|
1348
|
-
if (error instanceof MastraError && error.category === ErrorCategory.USER) throw new HTTPException(400, { message: error.message });
|
|
1349
|
-
throw error;
|
|
1350
|
-
}
|
|
1351
|
-
return { success: true };
|
|
1352
|
-
}
|
|
1353
|
-
await memory.updateWorkingMemory({
|
|
1354
|
-
threadId: effectiveThreadId,
|
|
1355
|
-
resourceId: effectiveResourceId,
|
|
1356
|
-
workingMemory,
|
|
1357
|
-
memoryConfig
|
|
1358
|
-
});
|
|
1359
|
-
return { success: true };
|
|
1360
|
-
} catch (error) {
|
|
1361
|
-
return handleError(error, "Error updating working memory");
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1364
|
-
});
|
|
1365
|
-
const DELETE_MESSAGES_ROUTE = createRoute({
|
|
1366
|
-
method: "POST",
|
|
1367
|
-
path: "/memory/messages/delete",
|
|
1368
|
-
responseType: "json",
|
|
1369
|
-
queryParamSchema: deleteMessagesQuerySchema,
|
|
1370
|
-
bodySchema: deleteMessagesBodySchema,
|
|
1371
|
-
responseSchema: deleteMessagesResponseSchema,
|
|
1372
|
-
summary: "Delete messages",
|
|
1373
|
-
description: "Deletes specific messages from memory",
|
|
1374
|
-
tags: ["Memory"],
|
|
1375
|
-
requiresAuth: true,
|
|
1376
|
-
handler: async ({ mastra, agentId, resourceId, messageIds, requestContext }) => {
|
|
1377
|
-
try {
|
|
1378
|
-
const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);
|
|
1379
|
-
if (messageIds === void 0 || messageIds === null) throw new HTTPException(400, { message: "messageIds is required" });
|
|
1380
|
-
let normalizedIds;
|
|
1381
|
-
if (Array.isArray(messageIds)) normalizedIds = messageIds;
|
|
1382
|
-
else if (typeof messageIds === "string") normalizedIds = [messageIds];
|
|
1383
|
-
else normalizedIds = [messageIds];
|
|
1384
|
-
const stringIds = normalizedIds.map((id) => typeof id === "string" ? id : id.id);
|
|
1385
|
-
const memory = await getMemoryFromContext({
|
|
1386
|
-
mastra,
|
|
1387
|
-
agentId,
|
|
1388
|
-
requestContext,
|
|
1389
|
-
allowMissingAgent: true
|
|
1390
|
-
});
|
|
1391
|
-
if (effectiveResourceId && stringIds.length > 0) {
|
|
1392
|
-
const storage = memory?.storage || getStorageFromContext({ mastra });
|
|
1393
|
-
if (!storage) throw new HTTPException(403, { message: "Access denied: unable to verify message ownership" });
|
|
1394
|
-
const memoryStore = await storage.getStore("memory");
|
|
1395
|
-
if (!memoryStore) throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
1396
|
-
await enforceDeleteMessagesThreadAccess({
|
|
1397
|
-
mastra,
|
|
1398
|
-
requestContext,
|
|
1399
|
-
memoryStore,
|
|
1400
|
-
messageIds: stringIds,
|
|
1401
|
-
effectiveResourceId
|
|
1402
|
-
});
|
|
1403
|
-
} else if (stringIds.length > 0) {
|
|
1404
|
-
const storage = memory?.storage || getStorageFromContext({ mastra });
|
|
1405
|
-
if (!storage) throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
1406
|
-
const memoryStore = await storage.getStore("memory");
|
|
1407
|
-
if (!memoryStore) throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
1408
|
-
await enforceDeleteMessagesThreadAccess({
|
|
1409
|
-
mastra,
|
|
1410
|
-
requestContext,
|
|
1411
|
-
memoryStore,
|
|
1412
|
-
messageIds: stringIds
|
|
1413
|
-
});
|
|
1414
|
-
}
|
|
1415
|
-
if (memory) await memory.deleteMessages(normalizedIds);
|
|
1416
|
-
else {
|
|
1417
|
-
const storage = getStorageFromContext({ mastra });
|
|
1418
|
-
if (storage) {
|
|
1419
|
-
const memoryStore = await storage.getStore("memory");
|
|
1420
|
-
if (memoryStore) await memoryStore.deleteMessages(stringIds);
|
|
1421
|
-
else throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
1422
|
-
} else throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
1423
|
-
}
|
|
1424
|
-
const count = Array.isArray(messageIds) ? messageIds.length : 1;
|
|
1425
|
-
return {
|
|
1426
|
-
success: true,
|
|
1427
|
-
message: `${count} message${count === 1 ? "" : "s"} deleted successfully`
|
|
1428
|
-
};
|
|
1429
|
-
} catch (error) {
|
|
1430
|
-
return handleError(error, "Error deleting messages");
|
|
1431
|
-
}
|
|
1432
|
-
}
|
|
1433
|
-
});
|
|
1434
|
-
const SEARCH_MEMORY_ROUTE = createRoute({
|
|
1435
|
-
method: "GET",
|
|
1436
|
-
path: "/memory/search",
|
|
1437
|
-
responseType: "json",
|
|
1438
|
-
queryParamSchema: searchMemoryQuerySchema,
|
|
1439
|
-
responseSchema: searchMemoryResponseSchema,
|
|
1440
|
-
summary: "Search memory",
|
|
1441
|
-
description: "Searches across memory using semantic or text search",
|
|
1442
|
-
tags: ["Memory"],
|
|
1443
|
-
requiresAuth: true,
|
|
1444
|
-
handler: async ({ mastra, agentId, searchQuery, resourceId, threadId, limit = 20, requestContext, memoryConfig }) => {
|
|
1445
|
-
try {
|
|
1446
|
-
const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);
|
|
1447
|
-
const effectiveThreadId = getEffectiveThreadId(requestContext, threadId);
|
|
1448
|
-
validateBody({
|
|
1449
|
-
searchQuery,
|
|
1450
|
-
resourceId: effectiveResourceId
|
|
1451
|
-
});
|
|
1452
|
-
const agent = await getAgentFromContext({
|
|
1453
|
-
mastra,
|
|
1454
|
-
agentId,
|
|
1455
|
-
requestContext
|
|
1456
|
-
});
|
|
1457
|
-
if (agent && await isGatewayAgentAsync(agent) && getGatewayClient()) return {
|
|
1458
|
-
results: [],
|
|
1459
|
-
count: 0,
|
|
1460
|
-
query: searchQuery,
|
|
1461
|
-
searchScope: "resource",
|
|
1462
|
-
searchType: "semantic"
|
|
1463
|
-
};
|
|
1464
|
-
const memory = await getMemoryFromContext({
|
|
1465
|
-
mastra,
|
|
1466
|
-
agentId,
|
|
1467
|
-
requestContext
|
|
1468
|
-
});
|
|
1469
|
-
if (!memory) throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
1470
|
-
const config = memory.getMergedThreadConfig(memoryConfig || {});
|
|
1471
|
-
const hasSemanticRecall = !!config?.semanticRecall;
|
|
1472
|
-
const resourceScope = typeof config?.semanticRecall === "object" ? config?.semanticRecall?.scope !== "thread" : true;
|
|
1473
|
-
const searchResults = [];
|
|
1474
|
-
let accessibleThreadsForResource;
|
|
1475
|
-
let accessibleThreadIds;
|
|
1476
|
-
if (resourceScope && effectiveResourceId && shouldFilterThreadsWithFGA(mastra, requestContext)) {
|
|
1477
|
-
const { threads } = await memory.listThreads({
|
|
1478
|
-
filter: { resourceId: effectiveResourceId },
|
|
1479
|
-
perPage: false,
|
|
1480
|
-
orderBy: {
|
|
1481
|
-
field: "updatedAt",
|
|
1482
|
-
direction: "DESC"
|
|
1483
|
-
}
|
|
1484
|
-
});
|
|
1485
|
-
accessibleThreadsForResource = await filterAccessibleThreads({
|
|
1486
|
-
mastra,
|
|
1487
|
-
requestContext,
|
|
1488
|
-
threads
|
|
1489
|
-
});
|
|
1490
|
-
accessibleThreadIds = new Set(accessibleThreadsForResource.map((thread) => thread.id));
|
|
1491
|
-
if (accessibleThreadsForResource.length === 0) return {
|
|
1492
|
-
results: [],
|
|
1493
|
-
count: 0,
|
|
1494
|
-
query: searchQuery,
|
|
1495
|
-
searchScope: resourceScope ? "resource" : "thread",
|
|
1496
|
-
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
1497
|
-
};
|
|
1498
|
-
}
|
|
1499
|
-
if (effectiveThreadId && !resourceScope) {
|
|
1500
|
-
const thread = await memory.getThreadById({ threadId: effectiveThreadId });
|
|
1501
|
-
if (!thread) return {
|
|
1502
|
-
results: [],
|
|
1503
|
-
count: 0,
|
|
1504
|
-
query: searchQuery,
|
|
1505
|
-
searchScope: resourceScope ? "resource" : "thread",
|
|
1506
|
-
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
1507
|
-
};
|
|
1508
|
-
await enforceThreadAccess({
|
|
1509
|
-
mastra,
|
|
1510
|
-
requestContext,
|
|
1511
|
-
threadId: effectiveThreadId,
|
|
1512
|
-
thread,
|
|
1513
|
-
effectiveResourceId
|
|
1514
|
-
});
|
|
1515
|
-
}
|
|
1516
|
-
let searchThreadId = effectiveThreadId;
|
|
1517
|
-
if (!searchThreadId) {
|
|
1518
|
-
const threads = accessibleThreadsForResource ?? (await memory.listThreads({
|
|
1519
|
-
filter: { resourceId: effectiveResourceId },
|
|
1520
|
-
page: 0,
|
|
1521
|
-
perPage: 1,
|
|
1522
|
-
orderBy: {
|
|
1523
|
-
field: "updatedAt",
|
|
1524
|
-
direction: "DESC"
|
|
1525
|
-
}
|
|
1526
|
-
})).threads;
|
|
1527
|
-
if (threads.length === 0) return {
|
|
1528
|
-
results: [],
|
|
1529
|
-
count: 0,
|
|
1530
|
-
query: searchQuery,
|
|
1531
|
-
searchScope: resourceScope ? "resource" : "thread",
|
|
1532
|
-
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
1533
|
-
};
|
|
1534
|
-
searchThreadId = threads[0].id;
|
|
1535
|
-
}
|
|
1536
|
-
const beforeRange = typeof config.semanticRecall === `boolean` ? 2 : typeof config.semanticRecall?.messageRange === `number` ? config.semanticRecall.messageRange : config.semanticRecall?.messageRange.before || 2;
|
|
1537
|
-
const afterRange = typeof config.semanticRecall === `boolean` ? 2 : typeof config.semanticRecall?.messageRange === `number` ? config.semanticRecall.messageRange : config.semanticRecall?.messageRange.after || 2;
|
|
1538
|
-
if (resourceScope && config.semanticRecall) config.semanticRecall = typeof config.semanticRecall === `boolean` ? {
|
|
1539
|
-
messageRange: 0,
|
|
1540
|
-
topK: 2,
|
|
1541
|
-
scope: "resource"
|
|
1542
|
-
} : {
|
|
1543
|
-
...config.semanticRecall,
|
|
1544
|
-
messageRange: 0
|
|
1545
|
-
};
|
|
1546
|
-
const threadConfig = memory.getMergedThreadConfig(config || {});
|
|
1547
|
-
if (!(threadConfig.lastMessages !== false && (threadConfig.lastMessages || threadConfig.messageHistory)) && !threadConfig.semanticRecall) return {
|
|
1548
|
-
results: [],
|
|
1549
|
-
count: 0,
|
|
1550
|
-
query: searchQuery
|
|
1551
|
-
};
|
|
1552
|
-
const result = await memory.recall({
|
|
1553
|
-
threadId: searchThreadId,
|
|
1554
|
-
resourceId: effectiveResourceId,
|
|
1555
|
-
threadConfig: config,
|
|
1556
|
-
vectorSearchString: threadConfig.semanticRecall && searchQuery ? searchQuery : void 0
|
|
1557
|
-
});
|
|
1558
|
-
const accessibleMessages = accessibleThreadIds ? result.messages.filter((message) => accessibleThreadIds.has(message.threadId || searchThreadId)) : result.messages;
|
|
1559
|
-
if (accessibleMessages.length === 0) return {
|
|
1560
|
-
results: [],
|
|
1561
|
-
count: 0,
|
|
1562
|
-
query: searchQuery,
|
|
1563
|
-
searchScope: resourceScope ? "resource" : "thread",
|
|
1564
|
-
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
1565
|
-
};
|
|
1566
|
-
const threadIds = Array.from(new Set(accessibleMessages.map((m) => m.threadId || searchThreadId).filter(Boolean)));
|
|
1567
|
-
const fetched = await Promise.all(threadIds.map((id) => memory.getThreadById({ threadId: id })));
|
|
1568
|
-
const threadMap = new Map(fetched.filter(Boolean).map((t) => [t.id, t]));
|
|
1569
|
-
for (const msg of accessibleMessages) {
|
|
1570
|
-
const content = getTextContent(msg);
|
|
1571
|
-
const msgThreadId = msg.threadId || searchThreadId;
|
|
1572
|
-
const thread = threadMap.get(msgThreadId);
|
|
1573
|
-
const threadMessages = (await memory.recall({ threadId: msgThreadId })).messages;
|
|
1574
|
-
const messageIndex = threadMessages.findIndex((m) => m.id === msg.id);
|
|
1575
|
-
const searchResult = {
|
|
1576
|
-
id: msg.id,
|
|
1577
|
-
role: msg.role,
|
|
1578
|
-
content,
|
|
1579
|
-
createdAt: msg.createdAt,
|
|
1580
|
-
threadId: msgThreadId,
|
|
1581
|
-
threadTitle: thread?.title || msgThreadId
|
|
1582
|
-
};
|
|
1583
|
-
if (messageIndex !== -1) searchResult.context = {
|
|
1584
|
-
before: threadMessages.slice(Math.max(0, messageIndex - beforeRange), messageIndex).map((m) => ({
|
|
1585
|
-
id: m.id,
|
|
1586
|
-
role: m.role,
|
|
1587
|
-
content: getTextContent(m),
|
|
1588
|
-
createdAt: m.createdAt || /* @__PURE__ */ new Date()
|
|
1589
|
-
})),
|
|
1590
|
-
after: threadMessages.slice(messageIndex + 1, messageIndex + afterRange + 1).map((m) => ({
|
|
1591
|
-
id: m.id,
|
|
1592
|
-
role: m.role,
|
|
1593
|
-
content: getTextContent(m),
|
|
1594
|
-
createdAt: m.createdAt || /* @__PURE__ */ new Date()
|
|
1595
|
-
}))
|
|
1596
|
-
};
|
|
1597
|
-
searchResults.push(searchResult);
|
|
1598
|
-
}
|
|
1599
|
-
const sortedResults = searchResults.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()).slice(0, limit);
|
|
1600
|
-
return {
|
|
1601
|
-
results: sortedResults,
|
|
1602
|
-
count: sortedResults.length,
|
|
1603
|
-
query: searchQuery,
|
|
1604
|
-
searchScope: resourceScope ? "resource" : "thread",
|
|
1605
|
-
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
1606
|
-
};
|
|
1607
|
-
} catch (error) {
|
|
1608
|
-
return handleError(error, "Error searching memory");
|
|
1609
|
-
}
|
|
1610
|
-
}
|
|
1611
|
-
});
|
|
1612
|
-
const GET_MEMORY_STATUS_NETWORK_ROUTE = createRoute({
|
|
1613
|
-
method: "GET",
|
|
1614
|
-
path: "/memory/network/status",
|
|
1615
|
-
responseType: "json",
|
|
1616
|
-
queryParamSchema: getMemoryStatusNetworkQuerySchema,
|
|
1617
|
-
responseSchema: memoryStatusResponseSchema,
|
|
1618
|
-
summary: "Get memory status (network)",
|
|
1619
|
-
description: "Returns the current status of the memory system (network route)",
|
|
1620
|
-
tags: ["Memory - Network"],
|
|
1621
|
-
requiresAuth: true,
|
|
1622
|
-
handler: GET_MEMORY_STATUS_ROUTE.handler
|
|
1623
|
-
});
|
|
1624
|
-
const LIST_THREADS_NETWORK_ROUTE = createRoute({
|
|
1625
|
-
method: "GET",
|
|
1626
|
-
path: "/memory/network/threads",
|
|
1627
|
-
responseType: "json",
|
|
1628
|
-
queryParamSchema: listThreadsNetworkQuerySchema,
|
|
1629
|
-
responseSchema: listThreadsResponseSchema,
|
|
1630
|
-
summary: "List memory threads (network)",
|
|
1631
|
-
description: "Returns a paginated list of conversation threads (network route)",
|
|
1632
|
-
tags: ["Memory - Network"],
|
|
1633
|
-
requiresAuth: true,
|
|
1634
|
-
handler: LIST_THREADS_ROUTE.handler
|
|
1635
|
-
});
|
|
1636
|
-
const GET_THREAD_BY_ID_NETWORK_ROUTE = createRoute({
|
|
1637
|
-
method: "GET",
|
|
1638
|
-
path: "/memory/network/threads/:threadId",
|
|
1639
|
-
responseType: "json",
|
|
1640
|
-
pathParamSchema: threadIdPathParams,
|
|
1641
|
-
queryParamSchema: getThreadByIdNetworkQuerySchema,
|
|
1642
|
-
responseSchema: getThreadByIdResponseSchema,
|
|
1643
|
-
summary: "Get thread by ID (network)",
|
|
1644
|
-
description: "Returns details for a specific conversation thread (network route)",
|
|
1645
|
-
tags: ["Memory - Network"],
|
|
1646
|
-
requiresAuth: true,
|
|
1647
|
-
handler: GET_THREAD_BY_ID_ROUTE.handler
|
|
1648
|
-
});
|
|
1649
|
-
const LIST_MESSAGES_NETWORK_ROUTE = createRoute({
|
|
1650
|
-
method: "GET",
|
|
1651
|
-
path: "/memory/network/threads/:threadId/messages",
|
|
1652
|
-
responseType: "json",
|
|
1653
|
-
pathParamSchema: threadIdPathParams,
|
|
1654
|
-
queryParamSchema: listMessagesNetworkQuerySchema,
|
|
1655
|
-
responseSchema: listMessagesResponseSchema,
|
|
1656
|
-
summary: "List thread messages (network)",
|
|
1657
|
-
description: "Returns a paginated list of messages in a conversation thread (network route)",
|
|
1658
|
-
tags: ["Memory - Network"],
|
|
1659
|
-
requiresAuth: true,
|
|
1660
|
-
handler: LIST_MESSAGES_ROUTE.handler
|
|
1661
|
-
});
|
|
1662
|
-
const SAVE_MESSAGES_NETWORK_ROUTE = createRoute({
|
|
1663
|
-
method: "POST",
|
|
1664
|
-
path: "/memory/network/save-messages",
|
|
1665
|
-
responseType: "json",
|
|
1666
|
-
queryParamSchema: saveMessagesNetworkQuerySchema,
|
|
1667
|
-
bodySchema: saveMessagesBodySchema,
|
|
1668
|
-
responseSchema: saveMessagesResponseSchema,
|
|
1669
|
-
summary: "Save messages (network)",
|
|
1670
|
-
description: "Saves new messages to memory (network route)",
|
|
1671
|
-
tags: ["Memory - Network"],
|
|
1672
|
-
requiresAuth: true,
|
|
1673
|
-
handler: SAVE_MESSAGES_ROUTE.handler
|
|
1674
|
-
});
|
|
1675
|
-
const CREATE_THREAD_NETWORK_ROUTE = createRoute({
|
|
1676
|
-
method: "POST",
|
|
1677
|
-
path: "/memory/network/threads",
|
|
1678
|
-
responseType: "json",
|
|
1679
|
-
queryParamSchema: createThreadNetworkQuerySchema,
|
|
1680
|
-
bodySchema: createThreadBodySchema,
|
|
1681
|
-
responseSchema: getThreadByIdResponseSchema,
|
|
1682
|
-
summary: "Create thread (network)",
|
|
1683
|
-
description: "Creates a new conversation thread (network route)",
|
|
1684
|
-
tags: ["Memory - Network"],
|
|
1685
|
-
requiresAuth: true,
|
|
1686
|
-
handler: CREATE_THREAD_ROUTE.handler
|
|
1687
|
-
});
|
|
1688
|
-
const UPDATE_THREAD_NETWORK_ROUTE = createRoute({
|
|
1689
|
-
method: "PATCH",
|
|
1690
|
-
path: "/memory/network/threads/:threadId",
|
|
1691
|
-
responseType: "json",
|
|
1692
|
-
pathParamSchema: threadIdPathParams,
|
|
1693
|
-
queryParamSchema: updateThreadNetworkQuerySchema,
|
|
1694
|
-
bodySchema: updateThreadBodySchema,
|
|
1695
|
-
responseSchema: getThreadByIdResponseSchema,
|
|
1696
|
-
summary: "Update thread (network)",
|
|
1697
|
-
description: "Updates a conversation thread (network route)",
|
|
1698
|
-
tags: ["Memory - Network"],
|
|
1699
|
-
requiresAuth: true,
|
|
1700
|
-
handler: UPDATE_THREAD_ROUTE.handler
|
|
1701
|
-
});
|
|
1702
|
-
const DELETE_THREAD_NETWORK_ROUTE = createRoute({
|
|
1703
|
-
method: "DELETE",
|
|
1704
|
-
path: "/memory/network/threads/:threadId",
|
|
1705
|
-
responseType: "json",
|
|
1706
|
-
pathParamSchema: threadIdPathParams,
|
|
1707
|
-
queryParamSchema: deleteThreadNetworkQuerySchema,
|
|
1708
|
-
responseSchema: deleteThreadResponseSchema,
|
|
1709
|
-
summary: "Delete thread (network)",
|
|
1710
|
-
description: "Deletes a conversation thread (network route)",
|
|
1711
|
-
tags: ["Memory - Network"],
|
|
1712
|
-
requiresAuth: true,
|
|
1713
|
-
handler: DELETE_THREAD_ROUTE.handler
|
|
1714
|
-
});
|
|
1715
|
-
const DELETE_MESSAGES_NETWORK_ROUTE = createRoute({
|
|
1716
|
-
method: "POST",
|
|
1717
|
-
path: "/memory/network/messages/delete",
|
|
1718
|
-
responseType: "json",
|
|
1719
|
-
queryParamSchema: deleteMessagesNetworkQuerySchema,
|
|
1720
|
-
bodySchema: deleteMessagesBodySchema,
|
|
1721
|
-
responseSchema: deleteMessagesResponseSchema,
|
|
1722
|
-
summary: "Delete messages (network)",
|
|
1723
|
-
description: "Deletes specific messages from memory (network route)",
|
|
1724
|
-
tags: ["Memory - Network"],
|
|
1725
|
-
requiresAuth: true,
|
|
1726
|
-
handler: DELETE_MESSAGES_ROUTE.handler
|
|
1727
|
-
});
|
|
1728
|
-
//#endregion
|
|
1729
|
-
export { AWAIT_BUFFER_STATUS_ROUTE, CLONE_THREAD_ROUTE, CREATE_THREAD_NETWORK_ROUTE, CREATE_THREAD_ROUTE, DELETE_MESSAGES_NETWORK_ROUTE, DELETE_MESSAGES_ROUTE, DELETE_THREAD_NETWORK_ROUTE, DELETE_THREAD_ROUTE, GET_MEMORY_CONFIG_ROUTE, GET_MEMORY_STATUS_NETWORK_ROUTE, GET_MEMORY_STATUS_ROUTE, GET_OBSERVATIONAL_MEMORY_ROUTE, GET_THREAD_BY_ID_NETWORK_ROUTE, GET_THREAD_BY_ID_ROUTE, GET_WORKING_MEMORY_ROUTE, LIST_MESSAGES_NETWORK_ROUTE, LIST_MESSAGES_ROUTE, LIST_THREADS_NETWORK_ROUTE, LIST_THREADS_ROUTE, SAVE_MESSAGES_NETWORK_ROUTE, SAVE_MESSAGES_ROUTE, SEARCH_MEMORY_ROUTE, TRANSFER_THREAD_ROUTE, UPDATE_THREAD_NETWORK_ROUTE, UPDATE_THREAD_ROUTE, UPDATE_WORKING_MEMORY_ROUTE, getTextContent, memory_exports as t };
|
|
1730
|
-
|
|
1731
|
-
//# sourceMappingURL=memory.js.map
|
|
1
|
+
export { t as AWAIT_BUFFER_STATUS_ROUTE, n as CLONE_THREAD_ROUTE, r as CREATE_THREAD_NETWORK_ROUTE, i as CREATE_THREAD_ROUTE, a as DELETE_MESSAGES_NETWORK_ROUTE, o as DELETE_MESSAGES_ROUTE, s as DELETE_THREAD_NETWORK_ROUTE, c as DELETE_THREAD_ROUTE, l as GET_MEMORY_CONFIG_ROUTE, u as GET_MEMORY_STATUS_NETWORK_ROUTE, d as GET_MEMORY_STATUS_ROUTE, f as GET_OBSERVATIONAL_MEMORY_ROUTE, p as GET_THREAD_BY_ID_NETWORK_ROUTE, m as GET_THREAD_BY_ID_ROUTE, h as GET_WORKING_MEMORY_ROUTE, g as LIST_MESSAGES_NETWORK_ROUTE, _ as LIST_MESSAGES_ROUTE, v as LIST_THREADS_NETWORK_ROUTE, y as LIST_THREADS_ROUTE, b as SAVE_MESSAGES_NETWORK_ROUTE, x as SAVE_MESSAGES_ROUTE, S as SEARCH_MEMORY_ROUTE, C as TRANSFER_THREAD_ROUTE, w as UPDATE_THREAD_NETWORK_ROUTE, T as UPDATE_THREAD_ROUTE, E as UPDATE_WORKING_MEMORY_ROUTE, D as getTextContent } from "../../memory-BHtTSzvJ.js";
|